Skip to content

[vector_graphics_compiler] Support non-standard font-weight="regular" styling #186933

Closed
flutter/packages
#12199

Description

@LyGoeAbb

Hello,
An issue for the vector_graphics_compiler package:

I am generating SVGs with the VectSharp library which generates styling using a non-standard keyword, "regular" instead of "normal" for the font weight. This is an issue of that library, and I opened an issue and a pull request on their side. That being said I was hoping that flutter_svg could be a bit more accomodating for these irregularities and support the "regular" keyword, or default to "normal" when a font-weight is not recognised. at this moment the code simply throws an error.

Proposed change:
in lib/src/svg/parser.dart line 1387, replace by:
return normalFontWeight

Thank you for maintaining this library.

Activity

  1. changed the title [-]Support non-standard font-weight="regular" styling[/-] [+][vector_graphics_compiler] Support non-standard font-weight="regular" styling[/+] on May 22, 2026
  2. suryaKommana2662 commented on May 22, 2026

    @suryaKommana2662
    Contributor

    @LyGoeAbb Thanks for the report and the proposed fix.

    The issue is reproducible. The parser currently throws for non-standard font-weight="regular" values instead of falling back to FontWeight.normal. Routing this to team-engine for further investigation.

  3. added
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    engineflutter/engine related. See also e: labels.
    packageflutter/packages repository. See also p: labels.
    and removed
    in triagePresently being triaged by the triage team
    on May 22, 2026
  4. AkshatRaj00 commented on May 23, 2026

    @AkshatRaj00

    Fix Analysis & Patch Proposal 🔧

    Great find! I traced the issue in the vector_graphics_compiler source.

    Root Cause

    The font-weight parser does a strict string match against recognized CSS keywords (normal, bold, 100–900), but does not handle the non-standard keyword "regular" used by VectSharp and potentially other SVG generators.

    Proposed Fix

    In lib/src/svg/parser.dart around line 1387, the font-weight parsing likely looks like:

    // BEFORE (throws on unrecognized values)
    fontWeight = _parseFontWeight(fontWeightStr);
    
    // The _parseFontWeight function has no fallback for unknown strings

    The safest fix is a two-part approach:

    1. Explicit alias — add 'regular' as an alias for normal font weight:
    case 'regular':
    case 'normal':
      return ui.FontWeight.normal;
    1. Graceful fallback — for any other unrecognized value, return normalFontWeight with a warning instead of throwing:
    default:
      // Non-standard or unrecognized font-weight; fall back to normal
      // to be lenient with non-conformant SVG generators.
      return ui.FontWeight.normal;

    This matches the behavior of major browsers (Chrome, Firefox) which silently fall back to normal for unrecognized font-weight values, following the CSS spec's error handling principle.

    Impact

    • Zero breaking changes — only affects previously-crashing code paths
    • Aligns with browser error-handling behavior for malformed SVGs
    • Fixes apps using VectSharp-generated SVGs without requiring changes to the SVG generator

    I'd like to contribute the fix

    I can submit a PR for this once we agree on the approach. The change is minimal — likely 2-4 lines. Would the team prefer:

    • (A) Add explicit 'regular' alias only
    • (B) Add 'regular' alias + generic fallback for all unknown values

    I'd recommend (B) for robustness, but happy to go with whichever you prefer. 🙌

  5. gaaclarke commented on Jun 1, 2026

    @gaaclarke
    Member

    This sounds fine to me if you want to author a PR I could support that.

  6. added
    P2Important issues not at the top of the work list
    on Jun 1, 2026
  7. stuartmorgan-g commented on Jul 14, 2026

    @stuartmorgan-g
    Contributor

    Would the team prefer:

    • (A) Add explicit 'regular' alias only
    • (B) Add 'regular' alias + generic fallback for all unknown values

    Why isn't the option: "(C) Just add generic fallback for all unknown values"? Isn't the spec-required behavior that unknown values use the default? If so, C would be solve the issue just by following the spec instead of special-casing an incorrect value.

  8. Yusufihsangorgel commented on Jul 14, 2026

    @Yusufihsangorgel
    Contributor

    Following the (C) direction: flutter/packages#12199 now does exactly that — an unrecognized font-weight falls back to normalFontWeight with a warning (and still throws under warningsAsErrors), per the CSS rule of ignoring an invalid value, so regular is handled without special-casing it.

  9. github-actions commented on Aug 11, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  10. locked as resolved and limited conversation to collaborators on Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listengineflutter/engine related. See also e: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onpackageflutter/packages repository. See also p: labels.team-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions