freetype_FreeType2
import { freetype_FreeType2 } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
Native object: release it with using or delete(). Factories can return null; check before calling methods. Inherits Algorithm.
freetype free type2 value in the OpenCV API.
Constructors and members
clone
Create another handle to the same native object. This retains the object without copying its pixels or algorithm state; dispose both handles separately.
clone(): this;The this result.
loadFontData
Load font data.
The function loadFontData loads font data from file.
loadFontData(fontFileName: EmbindString, idx: number): void;fontFileNameFontFile Name
idxface_index to select a font faces in a single file.
loadFontData1
Load font data.
The function loadFontData loads font data from file.
loadFontData1(bytes: ucharVector, index: number): void;bytesFontFile Name
indexface_index to select a font faces in a single file.
setSplitNumber
Set Split Number from Bezier-curve to line
The function setSplitNumber set the number of split points from bezier-curve to line. If you want to draw large glyph, large is better. If you want to draw small glyph, small is better.
setSplitNumber(num: number): void;numnumber of split points from bezier-curve to line
putText
Draws a text string.
The function putText renders the specified text string in the image. Symbols that cannot be rendered using the specified font are replaced by "Tofu" or non-drawn.
putText(img: Mat, text: EmbindString, org: Point, fontHeight: number, color: Scalar, thickness: number, line_type: number, bottomLeftOrigin: boolean): void;imgInput/output value, modified by the native operation. Image. (Only 8UC1/8UC3/8UC4 2D mat is supported.)
textText string to be drawn.
orgBottom-left/Top-left corner of the text string in the image.
fontHeightDrawing font size by pixel unit.
colorText color.
thicknessThickness of the lines used to draw a text when negative, the glyph is filled. Otherwise, the glyph is drawn with this thickness.
line_typeLine type. See the line for details.
bottomLeftOriginWhen true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner.
getTextSize
Calculates the width and height of a text string.
The function getTextSize calculates and returns the approximate size of a box that contains the specified text. That is, the following code renders some text, the tight box surrounding it, and the baseline: :
String text = "Funny text inside the box";
int fontHeight = 60;
int thickness = -1;
int linestyle = LINE_8;
Mat img(600, 800, CV_8UC3, Scalar::all(0));
int baseline=0;
cv::Ptr<cv::freetype::FreeType2> ft2;
ft2 = cv::freetype::createFreeType2();
ft2->loadFontData( "./mplus-1p-regular.ttf", 0 );
Size textSize = ft2->getTextSize(text,
fontHeight,
thickness,
&baseline);
if(thickness > 0){
baseline += thickness;
}
// center the text
Point textOrg((img.cols - textSize.width) / 2,
(img.rows + textSize.height) / 2);
// draw the box
rectangle(img, textOrg + Point(0, baseline),
textOrg + Point(textSize.width, -textSize.height),
Scalar(0,255,0),1,8);
// ... and the baseline first
line(img, textOrg + Point(0, thickness),
textOrg + Point(textSize.width, thickness),
Scalar(0, 0, 255),1,8);
// then put the text itself
ft2->putText(img, text, textOrg, fontHeight,
Scalar::all(255), thickness, linestyle, true );
See: cv::putText
getTextSize(text: EmbindString, fontHeight: number, thickness: number): freetype_FreeType2_getTextSizeResult;textInput text string.
fontHeightDrawing font size by pixel unit.
thicknessThickness of lines used to render the text. See putText for details.
The size of a box that contains the specified text. Scalar output parameters are returned as named fields in this object. Release returned native handles with using or delete(), including handles nested in results.
These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.