API reference
API reference
Select your platform
No SDKs available
No versions available

TextOutlineExtractor Object

Extracts 2D vector contours from text strings using Android's Paint and Path APIs.
The extraction pipeline:
  1. Configure Paint with font and size
  2. Call Paint.getTextPath() to get the vector outline
  3. Use Path.approximate() to convert curves to line segments
  4. Split into individual closed contours
  5. Classify contours as outer boundaries or holes using the odd-even nesting depth rule
  6. Group holes with their parent outer contours using containment testing

Signature

object TextOutlineExtractor

Methods

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: List
Returns
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:
  1. The fraction resets to 0 (explicit new sub-path), OR
  2. The fraction equals the previous fraction (moveTo — zero-length jump between sub-paths, common in multi-stroke glyphs like 'H' which uses 3 rectangles)
Signature
fun splitIntoContours(data: FloatArray, scale: Float): List<Contour>
Parameters
data: FloatArray
scale: Float
Returns
List