Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD letter spacing to parser #237

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/vector_graphics_compiler/lib/src/paint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,7 @@ class TextConfig {
this.decoration,
this.decorationStyle,
this.decorationColor,
this.letterSpacing,
);

/// The text to be rendered.
Expand All @@ -1354,6 +1355,9 @@ class TextConfig {
/// The decoration style to apply to the text.
final TextDecorationStyle decorationStyle;

/// The space between letters.
final double letterSpacing;

/// The color to use for the decoration, if any.
final Color decorationColor;

Expand All @@ -1367,6 +1371,7 @@ class TextConfig {
decoration,
decorationStyle,
decorationColor,
letterSpacing,
);

@override
Expand All @@ -1379,7 +1384,8 @@ class TextConfig {
other.fontWeight == fontWeight &&
other.decoration == decoration &&
other.decorationStyle == decorationStyle &&
other.decorationColor == decorationColor;
other.decorationColor == decorationColor &&
other.letterSpacing == letterSpacing;
}

@override
Expand All @@ -1392,7 +1398,9 @@ class TextConfig {
'$fontSize, '
'$decoration, '
'$decorationStyle, '
'$decorationColor,)';
'$decorationColor, '
'$letterSpacing'
')';
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/vector_graphics_compiler/lib/src/svg/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ class TextNode extends AttributedNode {
attributes.textDecoration ?? TextDecoration.none,
attributes.textDecorationStyle ?? TextDecorationStyle.solid,
attributes.textDecorationColor ?? Color.opaqueBlack,
attributes.letterSpacing ?? 0,
);
}

Expand Down
121 changes: 66 additions & 55 deletions packages/vector_graphics_compiler/lib/src/svg/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,26 @@ class _Elements {
final String id = parserState.buildUrlIri();
parserState.patternIds.add(id);
final SvgAttributes newAttributes = SvgAttributes._(
raw: attributes.raw,
id: attributes.id,
href: attributes.href,
transform: attributes.transform,
color: attributes.color,
stroke: attributes.stroke,
fill: attributes.fill,
fillRule: attributes.fillRule,
clipRule: attributes.clipRule,
clipPathId: attributes.clipPathId,
blendMode: attributes.blendMode,
fontFamily: attributes.fontFamily,
fontWeight: attributes.fontWeight,
fontSize: attributes.fontSize,
x: DoubleOrPercentage.fromString(rawX),
y: DoubleOrPercentage.fromString(rawY),
width: patternWidth,
height: patternHeight);
raw: attributes.raw,
id: attributes.id,
href: attributes.href,
transform: attributes.transform,
color: attributes.color,
stroke: attributes.stroke,
fill: attributes.fill,
fillRule: attributes.fillRule,
clipRule: attributes.clipRule,
clipPathId: attributes.clipPathId,
blendMode: attributes.blendMode,
fontFamily: attributes.fontFamily,
fontWeight: attributes.fontWeight,
fontSize: attributes.fontSize,
x: DoubleOrPercentage.fromString(rawX),
y: DoubleOrPercentage.fromString(rawY),
width: patternWidth,
height: patternHeight,
letterSpacing: attributes.letterSpacing,
);

final ParentNode group = ParentNode(newAttributes);
parserState.addGroup(parserState._currentStartElement!, group);
Expand Down Expand Up @@ -1659,43 +1661,45 @@ class SvgParser {
final String? rawDy = attributeMap['dy'];

return SvgAttributes._(
raw: attributeMap,
id: id,
x: DoubleOrPercentage.fromString(rawX),
y: DoubleOrPercentage.fromString(rawY),
dx: DoubleOrPercentage.fromString(rawDx),
dy: DoubleOrPercentage.fromString(rawDy),
href: attributeMap['href'],
color: attributeMap['color']?.toLowerCase() == 'none'
? const ColorOrNone.none()
: ColorOrNone.color(color),
stroke: _parseStrokeAttributes(
attributeMap,
opacity,
color,
id,
),
fill: _parseFillAttributes(
attributeMap,
opacity,
color,
id,
),
fillRule: parseRawFillRule(attributeMap['fill-rule']),
clipRule: parseRawFillRule(attributeMap['clip-rule']),
clipPathId: attributeMap['clip-path'],
blendMode: _blendModes[attributeMap['mix-blend-mode']],
transform:
parseTransform(attributeMap['transform']) ?? AffineMatrix.identity,
fontFamily: attributeMap['font-family'],
fontWeight: parseFontWeight(attributeMap['font-weight']),
fontSize: parseFontSize(attributeMap['font-size']),
textDecoration: parseTextDecoration(attributeMap['text-decoration']),
textDecorationStyle:
parseTextDecorationStyle(attributeMap['text-decoration-style']),
textDecorationColor: parseColor(attributeMap['text-decoration-color'],
attributeName: 'text-decoration-color', id: id),
textAnchorMultiplier: parseTextAnchor(attributeMap['text-anchor']));
raw: attributeMap,
id: id,
x: DoubleOrPercentage.fromString(rawX),
y: DoubleOrPercentage.fromString(rawY),
dx: DoubleOrPercentage.fromString(rawDx),
dy: DoubleOrPercentage.fromString(rawDy),
href: attributeMap['href'],
color: attributeMap['color']?.toLowerCase() == 'none'
? const ColorOrNone.none()
: ColorOrNone.color(color),
stroke: _parseStrokeAttributes(
attributeMap,
opacity,
color,
id,
),
fill: _parseFillAttributes(
attributeMap,
opacity,
color,
id,
),
fillRule: parseRawFillRule(attributeMap['fill-rule']),
clipRule: parseRawFillRule(attributeMap['clip-rule']),
clipPathId: attributeMap['clip-path'],
blendMode: _blendModes[attributeMap['mix-blend-mode']],
transform:
parseTransform(attributeMap['transform']) ?? AffineMatrix.identity,
fontFamily: attributeMap['font-family'],
fontWeight: parseFontWeight(attributeMap['font-weight']),
fontSize: parseFontSize(attributeMap['font-size']),
textDecoration: parseTextDecoration(attributeMap['text-decoration']),
textDecorationStyle:
parseTextDecorationStyle(attributeMap['text-decoration-style']),
textDecorationColor: parseColor(attributeMap['text-decoration-color'],
attributeName: 'text-decoration-color', id: id),
textAnchorMultiplier: parseTextAnchor(attributeMap['text-anchor']),
letterSpacing: parseDoubleWithUnits(attributeMap['letter-spacing']),
);
}
}

Expand Down Expand Up @@ -1872,6 +1876,7 @@ class SvgAttributes {
this.dy,
this.width,
this.height,
this.letterSpacing,
});

/// For use in tests to construct arbitrary attributes.
Expand Down Expand Up @@ -1901,6 +1906,7 @@ class SvgAttributes {
this.dy,
this.width,
this.height,
this.letterSpacing,
});

/// The empty set of properties.
Expand Down Expand Up @@ -2056,6 +2062,9 @@ class SvgAttributes {
/// The relative y translation.
final DoubleOrPercentage? dy;

/// The space between the letters.
final double? letterSpacing;

/// A copy of these attributes after absorbing a saveLayer.
///
/// Specifically, this will null out `blendMode` and any opacity related
Expand Down Expand Up @@ -2086,6 +2095,7 @@ class SvgAttributes {
y: y,
width: width,
height: height,
letterSpacing: letterSpacing,
);
}

Expand Down Expand Up @@ -2131,6 +2141,7 @@ class SvgAttributes {
y: y,
dx: dx,
dy: dy,
letterSpacing: letterSpacing ?? parent.letterSpacing,
);
}
}
Expand Down
Loading