Skip to content

Commit

Permalink
Expose tools to modify SVG path data: #95
Browse files Browse the repository at this point in the history
  • Loading branch information
zathras committed May 1, 2024
1 parent cf478e3 commit 899b202
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 54 deletions.
3 changes: 3 additions & 0 deletions lib/dom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ export 'src/svg_graph.dart'
SvgFontWeight,
SvgFontSize;

export 'src/path_noui.dart' show PathParser, PathBuilder, StringPathBuilder;

export 'src/common_noui.dart'
show
ParseError,
SIFillType,
SIStrokeJoin,
SIStrokeCap,
Expand Down
6 changes: 3 additions & 3 deletions lib/src/common_noui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ abstract class SIBuilder<PathDataT, IM> extends SIVisitor<PathDataT, IM, void> {
/// will return null, and the scalable image will re-use the previously
/// built, equivalent path.
///
PathBuilder? startPath(SIPaint paint, Object key);
EnhancedPathBuilder? startPath(SIPaint paint, Object key);
}

class SIImageData {
Expand Down Expand Up @@ -496,10 +496,10 @@ class SIColorVisitor {
/// Mixin for SIBuilder that builds paths from strings
///
mixin SIStringPathMaker {
void makePath(String pathData, PathBuilder pb,
void makePath(String pathData, EnhancedPathBuilder pb,
{required void Function(String) warn}) {
try {
PathParser(pb, pathData).parse();
RealPathParser(pb, pathData).parse();
} catch (e) {
warn(e.toString());
// As per the SVG spec, paths shall be parsed up to the first error,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/compact.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ class _ExportedIDContext {
}

mixin _SICompactPathBuilder {
void makePath(CompactChildData pathData, PathBuilder pb,
void makePath(CompactChildData pathData, EnhancedPathBuilder pb,
{required void Function(String) warn}) {
CompactPathParser(pathData, pb).parse();
}
Expand Down
8 changes: 4 additions & 4 deletions lib/src/compact_noui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ class CompactChildData {
}

// This is the dual of _CompactPathBuilder
class CompactPathParser extends AbstractPathParser {
class CompactPathParser extends AbstractPathParser<EnhancedPathBuilder> {
final ByteBufferDataInputStream children;
final FloatBufferInputStream args;
bool _nextNybble = false;
Expand Down Expand Up @@ -1527,7 +1527,7 @@ abstract class SIGenericCompactBuilder<PathDataT, IM>
}

@override
PathBuilder? startPath(SIPaint paint, Object? key) {
EnhancedPathBuilder? startPath(SIPaint paint, Object? key) {
final int? pathNumber = _pathShare[key];
final int? paintNumber = _paintShare[paint];
children.writeByte(PATH_CODE |
Expand All @@ -1550,7 +1550,7 @@ abstract class SIGenericCompactBuilder<PathDataT, IM>
}
}

void makePath(PathDataT pathData, PathBuilder pb,
void makePath(PathDataT pathData, EnhancedPathBuilder pb,
{required void Function(String) warn});

PathDataT immutableKey(PathDataT pathData);
Expand Down Expand Up @@ -1657,7 +1657,7 @@ enum _PathCommand {
arcToPointEllipseLargeCW
}

class CompactPathBuilder<PathDataT, IM> extends PathBuilder {
class CompactPathBuilder<PathDataT, IM> extends EnhancedPathBuilder {
final DataOutputSink _children;
final FloatSink _args;

Expand Down
4 changes: 2 additions & 2 deletions lib/src/dag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ abstract class SIGenericDagBuilder<PathDataT, IM>
}

@override
PathBuilder? startPath(SIPaint paint, Object key) {
EnhancedPathBuilder? startPath(SIPaint paint, Object key) {
final p = paths[key];
if (p != null) {
final sip = _daggerize(SIPath(p, paint));
Expand All @@ -726,7 +726,7 @@ abstract class SIGenericDagBuilder<PathDataT, IM>
});
}

void makePath(PathDataT pathData, PathBuilder pb,
void makePath(PathDataT pathData, EnhancedPathBuilder pb,
{required void Function(String) warn});

@override
Expand Down
4 changes: 2 additions & 2 deletions lib/src/path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import 'common_noui.dart';
import 'dart:math' show pi;

///
/// Buidler of a Flutter UI path. See [PathBuilder] for usage.
/// Buidler of a Flutter UI path. See [EnhancedPathBuilder] for usage.
///
class UIPathBuilder implements PathBuilder {
class UIPathBuilder implements EnhancedPathBuilder {
final void Function(UIPathBuilder)? _onEnd;

UIPathBuilder({void Function(UIPathBuilder)? onEnd}) : _onEnd = onEnd;
Expand Down
Loading

0 comments on commit 899b202

Please sign in to comment.