-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
117 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 0.0.3 | ||
|
||
- Implemented `drawTo` method. | ||
|
||
## 0.0.2 | ||
|
||
- Added a screenshot. | ||
|
34 changes: 34 additions & 0 deletions
34
flutter_kanjivg/lib/src/extensions/kvg_data_extension.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'dart:ui' as ui; | ||
|
||
import 'package:kanjivg/kanjivg.dart'; | ||
import 'package:vector_graphics_compiler/vector_graphics_compiler.dart' | ||
as compiler; | ||
|
||
/// Extension methods for the [KvgData] class. | ||
extension KvgDataExtension on KvgData { | ||
/// Creates a [ui.Path] object from the paths of this [KvgData] instance. | ||
ui.Path createPath() { | ||
final path = ui.Path(); | ||
for (final data in paths) { | ||
final pathData = compiler.parseSvgPathData(data); | ||
for (final command in pathData.commands) { | ||
if (command is compiler.LineToCommand) { | ||
path.lineTo(command.x, command.y); | ||
} else if (command is compiler.MoveToCommand) { | ||
path.moveTo(command.x, command.y); | ||
} else if (command is compiler.CubicToCommand) { | ||
path.cubicTo( | ||
command.x1, | ||
command.y1, | ||
command.x2, | ||
command.y2, | ||
command.x3, | ||
command.y3, | ||
); | ||
} | ||
} | ||
} | ||
|
||
return path; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'dart:ui'; | ||
import 'package:vector_graphics_compiler/vector_graphics_compiler.dart' | ||
as compiler; | ||
|
||
/// Extension methods for the [Path] class. | ||
extension PathExtension on Path { | ||
/// Draws a command on this path. | ||
void drawCommand(compiler.PathCommand command) { | ||
if (command is compiler.LineToCommand) { | ||
lineTo(command.x, command.y); | ||
} else if (command is compiler.MoveToCommand) { | ||
moveTo(command.x, command.y); | ||
} else if (command is compiler.CubicToCommand) { | ||
cubicTo( | ||
command.x1, | ||
command.y1, | ||
command.x2, | ||
command.y2, | ||
command.x3, | ||
command.y3, | ||
); | ||
} | ||
} | ||
|
||
/// Draws a collection of commands on this path. | ||
void drawCommands(Iterable<compiler.PathCommand> commands) => | ||
commands.forEach(drawCommand); | ||
|
||
/// Total length of this path. | ||
double computeLength() => computeMetrics() | ||
.fold<double>(0, (previous, metric) => previous + metric.length); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters