From 93c1ca86e2d09eeaa93b6b2cc36e80e23a760d49 Mon Sep 17 00:00:00 2001 From: luigi-rosso Date: Mon, 26 Jun 2023 17:36:43 +0000 Subject: [PATCH] Feature options on Fonts Adds runtime and editor support for setting feature flags on a Font. The biggest change to the font engine is that the feature options are now stored on the Font object itself instead of hard-coded during shaping. This is nice as it requires no extra data to be piped through for individual run styling. It also means that we generalized the concept of creating a variable font as configuring a version of the font (see withOptions replacing makeVariation) so that variable axis and feature settings are treated as options to a Font configuration. This also allows us to track existing variations and options on the configured Font such that any further call to "withOptions" on that already configured Font will propagate previous changes if not overridden. This fortuitously also fixes an issue the modifiers were exhibiting where a variation set on the TextStyle that wasn't part of the modifier set would be lost. Diffs= 31d9a5424 Feature options on Fonts (#5479) 8b7587241 Runtime/interpolate states cpp (#5437) Co-authored-by: Luigi Rosso --- .rive_head | 2 +- lib/src/rive_core/text/text_modifier_group.dart | 6 ++++-- lib/src/rive_core/text/text_style.dart | 4 ++-- lib/src/rive_core/text/text_style_axis.dart | 2 +- lib/src/rive_core/text/text_variation_modifier.dart | 2 +- pubspec.yaml | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.rive_head b/.rive_head index 57a5c15..c5fb219 100644 --- a/.rive_head +++ b/.rive_head @@ -1 +1 @@ -59858e3330db2d56f9db570df8bcb8f6af23b154 +31d9a54243e694ede76dc133cf209d7b67c13708 diff --git a/lib/src/rive_core/text/text_modifier_group.dart b/lib/src/rive_core/text/text_modifier_group.dart index a47ec9a..94593df 100644 --- a/lib/src/rive_core/text/text_modifier_group.dart +++ b/lib/src/rive_core/text/text_modifier_group.dart @@ -148,8 +148,10 @@ class TextModifierGroup extends TextModifierGroupBase { } if (axisVariations.isNotEmpty) { - var varFont = font.makeVariation(axisVariations.entries - .map((entry) => FontAxisCoord(entry.key, entry.value))); + var varFont = font.withOptions( + axisVariations.entries + .map((entry) => FontAxisCoord(entry.key, entry.value)), + []); if (varFont != null) { _cleanupFonts.add(varFont); font = varFont; diff --git a/lib/src/rive_core/text/text_style.dart b/lib/src/rive_core/text/text_style.dart index 42d12dc..b38677c 100644 --- a/lib/src/rive_core/text/text_style.dart +++ b/lib/src/rive_core/text/text_style.dart @@ -65,8 +65,8 @@ class TextStyle extends TextStyleBase TextVariationHelper? _variationHelper; TextVariationHelper? get variationHelper => _variationHelper; - Font? _makeVariableFont() => asset?.font?.makeVariation( - _variations.map((axis) => FontAxisCoord(axis.tag, axis.axisValue))); + Font? _makeVariableFont() => asset?.font?.withOptions( + _variations.map((axis) => FontAxisCoord(axis.tag, axis.axisValue)), []); Font? get font => _variationHelper?.font ?? asset?.font; diff --git a/lib/src/rive_core/text/text_style_axis.dart b/lib/src/rive_core/text/text_style_axis.dart index 225e49d..f5a1ce3 100644 --- a/lib/src/rive_core/text/text_style_axis.dart +++ b/lib/src/rive_core/text/text_style_axis.dart @@ -9,7 +9,7 @@ class TextStyleAxis extends TextStyleAxisBase { @override bool validate() => super.validate() && parent is TextStyle; - String get tagName => FontAxis.tagToName(tag); + String get tagName => FontTag.tagToName(tag); @override void update(int dirt) {} diff --git a/lib/src/rive_core/text/text_variation_modifier.dart b/lib/src/rive_core/text/text_variation_modifier.dart index 4378c81..9ef0a83 100644 --- a/lib/src/rive_core/text/text_variation_modifier.dart +++ b/lib/src/rive_core/text/text_variation_modifier.dart @@ -7,7 +7,7 @@ import 'package:rive_common/rive_text.dart'; export 'package:rive/src/generated/text/text_variation_modifier_base.dart'; class TextVariationModifier extends TextVariationModifierBase { - String get tagName => FontAxis.tagToName(axisTag); + String get tagName => FontTag.tagToName(axisTag); @override void axisTagChanged(int from, int to) => diff --git a/pubspec.yaml b/pubspec.yaml index d46a367..864bc27 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ dependencies: http: ^0.13.3 meta: ^1.3.0 plugin_platform_interface: ^2.0.2 - rive_common: ^0.0.10 + rive_common: 0.1.0 dev_dependencies: flutter_test: sdk: flutter