object TextOutlineExtractor
extractContours
(
text
, fontSizeMeters
, fontFamily
, letterSpacingMeters
, curveSegments
)
|
Extracts all contour groups from the given text string.
Signature
fun extractContours(text: String, fontSizeMeters: Float, fontFamily: String, letterSpacingMeters: Float, curveSegments: Int): List<ContourGroup> Parameters text: String
The text to extract outlines from
fontSizeMeters: Float
Desired font height in meters
fontFamily: String
Android font family name
letterSpacingMeters: Float
Additional spacing between characters in meters
curveSegments: Int
Quality of Bezier curve approximation (higher = smoother)
Returns List
List of ContourGroups, each representing a filled region with optional holes
|
extractSingleGlyphContours
(
paint
, char
, tolerance
, scaleFactor
)
|
Extracts contours for a single character at the origin (x=0, y=0).
Unlike TextOutlineExtractor.extractContours, this method does not apply any positional offset, making the result reusable across different text strings. Use TextOutlineExtractor.offsetContourGroups to position the cached result at the correct x-offset for assembly.
Signature
fun extractSingleGlyphContours(paint: Paint, char: Char, tolerance: Float, scaleFactor: Float): List<ContourGroup> Parameters paint: Paint
Pre-configured Paint with typeface and text size set
char: Char
The character to extract contours for
tolerance: Float
Curve approximation tolerance (from Path.approximate)
scaleFactor: Float
Scale factor to convert from pixel coordinates to meters
Returns List
List of ContourGroups for the glyph, positioned at origin
|
groupContours
(
contours
)
|
Groups contours into outer boundaries and their holes using winding direction.
TrueType fonts use the non-zero winding rule. After the Y-flip applied in TextOutlineExtractor.splitIntoContours (which reverses winding), outer contours have negative signed area (clockwise) and holes have positive signed area (counter-clockwise).
This winding-based classification correctly handles cases where two same-winding contours overlap (e.g., the stem and bowl of 'd'), which the previous odd-even depth approach misclassified.
Each hole is assigned to its smallest containing outer (by absolute area). For output, outer contours are ensured CCW and holes CW (as expected by the earcut triangulator).
Signature
fun groupContours(contours: List<Contour>): List<ContourGroup> Parameters contours: ListReturns List |
offsetContourGroups
(
groups
, dx
)
|
Returns a copy of contour groups with all Point2D x-coordinates shifted by TextOutlineExtractor.offsetContourGroups.
This is used to position cached per-glyph contours at the correct horizontal offset when assembling a full text string from individually cached glyphs.
Signature
fun offsetContourGroups(groups: List<ContourGroup>, dx: Float): List<ContourGroup> Parameters groups: List
The contour groups to offset (not modified)
dx: Float
The horizontal offset to apply (in scaled coordinates, e.g. meters)
Returns List
New list of ContourGroups with shifted coordinates
|
splitIntoContours
(
data
, scale
)
|
Splits the raw approximate() output into individual closed contours. is a flat float array of (fraction, x, y) triplets. A new contour starts when:
Signature
fun splitIntoContours(data: FloatArray, scale: Float): List<Contour> Parameters data: FloatArrayscale: FloatReturns List |