normalizeSvgText function

Uint8List normalizeSvgText(
  1. Uint8List bytes
)

bytes rewritten around two gaps in the SVG compiler under flutter_svg, both of which every shields.io badge runs into. Anything else is left as written, and rewritten bytes are kept, so a rebuild does not parse again.

  • An embedded SVG image — <image href="data:image/svg+xml;…">, how a badge carries its logo= icon — is dropped by the compiler, which only decodes bitmaps there. It is replaced with the embedded SVG's own content, in a group placed and scaled the way its viewBox would be.
  • Text in a uniformly scaled group — font-size="110" inside scale(.1) — has its position scaled by the compiler but not its size, so it came out ten times too large. A group holding only text has the scale folded into the text itself: positions, font size and spacing multiplied, and the transform removed, so the result does not depend on the compiler's handling either way.

Implementation

Uint8List normalizeSvgText(Uint8List bytes) {
  final cached = _normalized[bytes];
  if (cached != null) {
    return cached;
  }
  final result = _normalize(bytes);
  _normalized[bytes] = result;
  return result;
}