Add variable font C API#185
Merged
mattleibow merged 7 commits intoApr 26, 2026
Merged
Conversation
Expose SkTypeface variable font functionality through the C API: - sk_typeface_get_variation_design_position: query current axis coordinates - sk_typeface_get_variation_design_parameters: query axis metadata (tag, min, default, max, hidden) - sk_typeface_clone_with_arguments: create typeface clone with specific variation coordinates Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace reinterpret_cast between C and C++ structs with field-by-field copy. The structs have identical layout so the cast worked in practice, but accessing memory through an unrelated type is undefined behavior per the C++ standard. Compilers optimize the copy loop to the same code. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add sk_fourbytetag_t typedef (uint32_t) matching SkFourByteTag - Use sk_fourbytetag_t in variation axis/coordinate C structs - Add AsVariationPositionCoordinate/ToVariationPositionCoordinate for layout-compatible Coordinate struct (verified by static_assert) - Add ToVariationAxis for Axis conversion (handles isHidden() getter) - Add AsSkFontArguments helper for clone_with_arguments - Simplify sk_typeface.cpp: remove manual copy loops, use reinterpret_cast for coordinates, use helpers for parameters and font arguments Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Replace manual reinterpret_cast functions with DEF_MAP macro for VariationPosition::Coordinate (generates As*/To* automatically) - Move static_assert to sk_structs.cpp following existing pattern - Use AsVariationPositionCoordinate() in sk_typeface.cpp instead of inline reinterpret_cast Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
mattleibow
added a commit
to ramezgerges/SkiaSharp
that referenced
this pull request
Apr 26, 2026
Update externals/skia to include the merged variable font C API (mono/skia#185) at the tip of the skiasharp branch. Changes: https://github.com/mono/skia/compare/0afa08b9ac..b6a88e589f Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
mattleibow
added a commit
to mono/SkiaSharp
that referenced
this pull request
Apr 26, 2026
Add variable font support to SkiaSharp and HarfBuzzSharp (#3703) Changes: mono/skia#185 Add OpenType Font Variations support, enabling runtime axis querying, typeface cloning at specific design coordinates, and full HarfBuzz variation APIs. Variable fonts (e.g. Inter, Roboto Flex) expose continuous design axes like weight, width, and optical size — this PR lets consumers query and manipulate those axes from managed code. ~~ SKTypeface ~~ * VariationDesignParameters / GetVariationDesignParameters(Span<>) — query axis metadata (tag, min, default, max, isHidden) * VariationDesignPosition / GetVariationDesignPosition(Span<>) — query the current axis coordinate values * Clone(ReadOnlySpan<SKFontVariationPositionCoordinate>) — create a typeface at a specific design position * Clone(SKFontArguments) — full control over position and collection index ~~ New types ~~ * SKFourByteTag — four-byte tag struct with Parse/ToString, implicit uint conversion, and char constructor (matches HarfBuzzSharp.Tag) * SKFontVariationAxis — generated struct: Tag, Min, Default, Max, IsHidden * SKFontVariationPositionCoordinate — generated struct: Axis + Value * SKFontArguments — ref struct accepting spans, arrays, or stackalloc ~~ HarfBuzzSharp.Face ~~ * HasVariationData, VariationAxisCount, VariationAxisInfos * TryFindVariationAxis(Tag, out info) * NamedInstanceCount, named instance design coords and name lookups ~~ HarfBuzzSharp.Font ~~ * SetVariations, SetVariationCoordsDesign, SetVariationCoordsNormalized * VariationCoordsNormalized property and Span overload * SetVariationNamedInstance Every property has a matching Span overload for allocation-free use via stackalloc. Input validation (negative instance indices, null checks) throws ArgumentOutOfRangeException or ArgumentNullException at the managed boundary. Includes 151 tests covering axis values, tag round-trips, span/property equivalence, static font graceful handling, clone + render verification, and HarfBuzz named instances. Gallery sample demonstrates Inter with weight and optical size sliders. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Matthew Leibowitz <mattleibow@live.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ramezgerges
added a commit
to ramezgerges/skia
that referenced
this pull request
Apr 26, 2026
Brings in the latest mono/skia 'skiasharp' branch updates on top of the m147 work-in-progress: * Add variable font C API for typeface variation queries and cloning (mono#185) * Add sk_fontmgr_legacy_create_typeface C API (mono#198, mono#195) — replaces the old sk_default_fontmgr.{cpp,h} with a single C entry point that forwards to SkFontMgr::legacyMakeTypeface(). Fixes the Android default-typeface SIGSEGV. * Use int32_t instead of long for SkManagedStream move offset (mono#186) — fail-loud on overflow instead of silent truncation of platform-dependent C long. * Update libpng to 1.6.58 * Update libexpat to 2.7.5 Conflict resolutions: - DEPS: keep m147's freetype roll, take origin/skiasharp's libexpat 2.7.5 (and libpng 1.6.58 auto-merged the same way). - src/c/sk_default_fontmgr.cpp: accept origin/skiasharp's deletion; their legacyMakeTypeface refactor obviates our m147 carry of that file. - src/c/sk_typeface.cpp: re-apply our m139 SkFontScanner fix to the Android and FontConfig SkFontMgr_New_* call sites, which moved into this file as part of their refactor. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
mattleibow
added a commit
that referenced
this pull request
Apr 26, 2026
Add color font palette support to C API (#197) Requires: mono/SkiaSharp#3742 Extends the variable font C API (merged in #185) with color palette support, enabling SkiaSharp to clone typefaces with specific palette selections and per-color overrides for COLRv1/COLR fonts. New C API surface: * sk_fontarguments_palette_override_t — struct mapping to SkFontArguments::Palette::Override (index + color) * sk_typeface_clone_with_arguments — extended from 4 to 7 parameters, adding paletteIndex, paletteOverrides, and paletteOverrideCount Supporting changes: * DEF_MAP for Palette::Override (reinterpret_cast, layout-compatible) * static_assert in sk_structs.cpp for ABI verification * AsSkFontArguments helper updated to call setPalette() Co-authored-by: Ramez Gerges <ramezragaa@proton.me> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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 of Change
Add C API surface for SkTypeface variable font (OpenType Font Variations) functionality, exposing variation axis queries and typeface cloning with specific variation coordinates.
API Changes
New functions (
sk_typeface.h/sk_typeface.cpp)sk_typeface_get_variation_design_positionSkTypeface::getVariationDesignPositionsk_typeface_get_variation_design_parametersSkTypeface::getVariationDesignParameterssk_typeface_clone_with_argumentsSkTypeface::makeClone(SkFontArguments)New types
sk_fontarguments_variation_position_coordinate_taxis(uint32 tag),value(float)sk_fontarguments_variation_axis_ttag,min,def,max(floats),isHidden(bool)Behavioral Changes
None.
Required SkiaSharp PR
Requires mono/SkiaSharp#3703
PR Checklist
skiasharpat time of PR