From 68d7f5faf99f421c8bb7b89b6d4cb571bc993162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C4=B0hsan=20G=C3=B6rgel?= Date: Tue, 14 Jul 2026 22:12:02 +0300 Subject: [PATCH 1/2] [vector_graphics_compiler] Fall back to normal weight for unrecognized font-weight --- .../vector_graphics_compiler/CHANGELOG.md | 8 ++++++ .../lib/src/svg/parser.dart | 11 +++++++- .../vector_graphics_compiler/pubspec.yaml | 2 +- .../test/parser_test.dart | 28 +++++++++++++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/packages/vector_graphics_compiler/CHANGELOG.md b/packages/vector_graphics_compiler/CHANGELOG.md index 578be6722575..236e16b8eeab 100644 --- a/packages/vector_graphics_compiler/CHANGELOG.md +++ b/packages/vector_graphics_compiler/CHANGELOG.md @@ -1,3 +1,11 @@ +## 1.3.0 + +* An unrecognized `font-weight` value now falls back to normal weight with a + warning (and still throws when `warningsAsErrors` is set) instead of always + throwing, following the CSS behavior of ignoring an invalid `font-weight`. + This lets the compiler tolerate non-standard values such as `regular` emitted + by some SVG generators. + ## 1.2.6 * Fixes `linux-arm64` host support by selecting the Flutter engine diff --git a/packages/vector_graphics_compiler/lib/src/svg/parser.dart b/packages/vector_graphics_compiler/lib/src/svg/parser.dart index cbf90242b236..e2e493360c47 100644 --- a/packages/vector_graphics_compiler/lib/src/svg/parser.dart +++ b/packages/vector_graphics_compiler/lib/src/svg/parser.dart @@ -1295,6 +1295,10 @@ class SvgParser { } /// Parse the raw font weight string. + /// + /// An unrecognized value falls back to [normalFontWeight] with a warning, + /// following the CSS behavior of ignoring an invalid `font-weight`, or throws + /// a [StateError] when warnings are treated as errors. FontWeight? parseFontWeight(String? fontWeight) { if (fontWeight == null) { return null; @@ -1325,7 +1329,12 @@ class SvgParser { return FontWeight.w900; } - throw StateError('Invalid "font-weight": $fontWeight'); + final errorMessage = 'Invalid "font-weight": $fontWeight'; + if (_warningsAsErrors) { + throw StateError(errorMessage); + } + print('Warning: $errorMessage. Defaulting to normal.'); + return normalFontWeight; } /// Converts a SVG Color String (either a # prefixed color string or a named color) to a [Color]. diff --git a/packages/vector_graphics_compiler/pubspec.yaml b/packages/vector_graphics_compiler/pubspec.yaml index db216b088853..d841e67afdf6 100644 --- a/packages/vector_graphics_compiler/pubspec.yaml +++ b/packages/vector_graphics_compiler/pubspec.yaml @@ -2,7 +2,7 @@ name: vector_graphics_compiler description: A compiler to convert SVGs to the binary format used by `package:vector_graphics`. repository: https://github.com/flutter/packages/tree/main/packages/vector_graphics_compiler issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+vector_graphics%22 -version: 1.2.6 +version: 1.3.0 executables: vector_graphics_compiler: diff --git a/packages/vector_graphics_compiler/test/parser_test.dart b/packages/vector_graphics_compiler/test/parser_test.dart index c0b04d07f9a1..40d4e5c9f8e3 100644 --- a/packages/vector_graphics_compiler/test/parser_test.dart +++ b/packages/vector_graphics_compiler/test/parser_test.dart @@ -414,6 +414,34 @@ ${[for (var i = 2; i <= 30; i++) ' + Regular text +'''); + + expect(instructions.text.single.fontWeight, FontWeight.w400); + }); + + test('Unrecognized font-weight falls back to normal', () { + final VectorInstructions instructions = parseWithoutOptimizers(''' + + Some text +'''); + + expect(instructions.text.single.fontWeight, FontWeight.w400); + }); + + test('Unrecognized font-weight throws when warnings are errors', () { + expect( + () => parseWithoutOptimizers(''' + + Some text +''', warningsAsErrors: true), + throwsStateError, + ); + }); + test('Fill rule inheritence', () { final VectorInstructions instructions = parseWithoutOptimizers(inheritFillRule); From 7eb79ed664a3f498f2e66ddc04205f71b64130d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C4=B0hsan=20G=C3=B6rgel?= Date: Wed, 15 Jul 2026 18:31:01 +0300 Subject: [PATCH 2/2] Preserve inherited weight for invalid font values --- packages/vector_graphics_compiler/CHANGELOG.md | 10 +++++----- .../lib/src/svg/parser.dart | 10 +++++----- .../test/parser_test.dart | 15 +++++++++++++-- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/packages/vector_graphics_compiler/CHANGELOG.md b/packages/vector_graphics_compiler/CHANGELOG.md index 236e16b8eeab..aea39915b176 100644 --- a/packages/vector_graphics_compiler/CHANGELOG.md +++ b/packages/vector_graphics_compiler/CHANGELOG.md @@ -1,10 +1,10 @@ ## 1.3.0 -* An unrecognized `font-weight` value now falls back to normal weight with a - warning (and still throws when `warningsAsErrors` is set) instead of always - throwing, following the CSS behavior of ignoring an invalid `font-weight`. - This lets the compiler tolerate non-standard values such as `regular` emitted - by some SVG generators. +* An unrecognized `font-weight` value is now ignored with a warning (and still + throws when `warningsAsErrors` is set) instead of always throwing. This + preserves an inherited weight, or the initial normal weight at the root, and + lets the compiler tolerate non-standard values such as `regular` emitted by + some SVG generators. ## 1.2.6 diff --git a/packages/vector_graphics_compiler/lib/src/svg/parser.dart b/packages/vector_graphics_compiler/lib/src/svg/parser.dart index e2e493360c47..99f07f81e359 100644 --- a/packages/vector_graphics_compiler/lib/src/svg/parser.dart +++ b/packages/vector_graphics_compiler/lib/src/svg/parser.dart @@ -1296,9 +1296,9 @@ class SvgParser { /// Parse the raw font weight string. /// - /// An unrecognized value falls back to [normalFontWeight] with a warning, - /// following the CSS behavior of ignoring an invalid `font-weight`, or throws - /// a [StateError] when warnings are treated as errors. + /// An unrecognized value is ignored with a warning so that inheritance can + /// determine the effective weight, or throws a [StateError] when warnings are + /// treated as errors. FontWeight? parseFontWeight(String? fontWeight) { if (fontWeight == null) { return null; @@ -1333,8 +1333,8 @@ class SvgParser { if (_warningsAsErrors) { throw StateError(errorMessage); } - print('Warning: $errorMessage. Defaulting to normal.'); - return normalFontWeight; + print('Warning: $errorMessage. Ignoring invalid value.'); + return null; } /// Converts a SVG Color String (either a # prefixed color string or a named color) to a [Color]. diff --git a/packages/vector_graphics_compiler/test/parser_test.dart b/packages/vector_graphics_compiler/test/parser_test.dart index 40d4e5c9f8e3..770035269be5 100644 --- a/packages/vector_graphics_compiler/test/parser_test.dart +++ b/packages/vector_graphics_compiler/test/parser_test.dart @@ -414,7 +414,7 @@ ${[for (var i = 2; i <= 30; i++) ' Regular text @@ -423,7 +423,7 @@ ${[for (var i = 2; i <= 30; i++) ' Some text @@ -432,6 +432,17 @@ ${[for (var i = 2; i <= 30; i++) ' + + Some text + +'''); + + expect(instructions.text.single.fontWeight, FontWeight.w700); + }); + test('Unrecognized font-weight throws when warnings are errors', () { expect( () => parseWithoutOptimizers('''