Native SWF Vector Font Extraction to XML#53
Open
MasterAlexS wants to merge 4 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces a zero-dependency native Haxe pipeline for extracting embedded vector fonts directly from parsed SWF files into XML.
The Motivation
Using external TTF compilers (or Java-based tools) during the build process is cumbersome. Furthermore, relying on standard OpenFL
TextFieldsto render these generated.ttffiles on native targets (especially Linux via FreeType) often results in inaccurate baseline alignments and slightly off-centered text compared to Flash.By extracting the raw vector commands and metrics directly, developers can write their own custom text renderers (using
graphics.drawPath()) to achieve 100% pixel-perfect text rendering across all platforms, completely bypassing OS-level text rendering quirks.Technical Implementation
The extraction pipeline bypasses the complex
.ttfgeneration and hooks directly intoShapeCommandExporterto extractDefineFont2andDefineFont3geometries.GlyphCommandenums and parsing them later, the SVG commands (M,L,Q) are generated on-the-fly usingStringBuf.sys.thread): Native extraction processes multiple font tags concurrently using background threads withMutex/Locksynchronization. This scales perfectly on large SWFs with multiple embedded fonts.1.33333333333333). Coordinates are rounded to 4 decimal places, which maintains flawless visual fidelity while significantly reducing the output XML file size.haxe.io.Path.join()and we handle duplicate embedded font names by appending numeric suffixes (FontName_2.xml).Testing
I have built a separate OpenFL test application that parses these generated XMLs. It uses pre-calculated
openfl.Vector<Int>andVector<Float>structures at runtime to pass the metrics directly tographics.moveTo()andcurveTo(). The results demonstrate perfectly crisp, baseline-accurate rendering on native Linux targets.Usage via Neko: