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 <luigi-rosso@users.noreply.github.com>
This commit is contained in:
luigi-rosso
2023-06-26 17:36:43 +00:00
parent 4893a3e79e
commit 93c1ca86e2
6 changed files with 10 additions and 8 deletions

View File

@ -1 +1 @@
59858e3330db2d56f9db570df8bcb8f6af23b154
31d9a54243e694ede76dc133cf209d7b67c13708

View File

@ -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;

View File

@ -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;

View File

@ -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) {}

View File

@ -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) =>

View File

@ -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