Visitar URL original
Migrate PathOps Lib to VectorGraphics (#99) · flutter/packages@28b73e5 · GitHub
Skip to content

Commit 28b73e5

Browse files
Migrate PathOps Lib to VectorGraphics (#99)
Adds support for consumption of path_ops in the compiler.
1 parent e0bd5b8 commit 28b73e5

5 files changed

Lines changed: 555 additions & 0 deletions

File tree

‎packages/vector_graphics_compiler/bin/vector_graphics_compiler.dart‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,22 @@ final ArgParser argParser = ArgParser()
1515
valueHelp: 'path/to/libtessellator.dylib',
1616
hide: true,
1717
)
18+
..addOption(
19+
'libpathops',
20+
help: 'The path to a libpathops dynamic library',
21+
valueHelp: 'path/to/libpath_ops.dylib',
22+
hide: true,
23+
)
1824
..addFlag(
1925
'tessellate',
2026
help: 'Convert path fills into a tessellated shape. This will improve '
2127
'raster times at the cost of slightly larger file sizes.',
2228
)
29+
..addFlag(
30+
'path-ops',
31+
help: 'Allows for path_ops library to be used when'
32+
'calculating path intersections.',
33+
)
2334
..addOption('input',
2435
abbr: 'i',
2536
help: 'The path to a file containing a single SVG',
@@ -51,6 +62,16 @@ Future<void> main(List<String> args) async {
5162
}
5263
}
5364

65+
if (results['pathops'] == true) {
66+
if (results.wasParsed('libpathops')) {
67+
initializeLibPathOps(results['libpathops'] as String);
68+
} else {
69+
if (!initializePathOpsFromFlutterCache()) {
70+
exit(1);
71+
}
72+
}
73+
}
74+
5475
final String inputFilePath = results['input'] as String;
5576
final String xml = File(inputFilePath).readAsStringSync();
5677
final File outputFile =
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import 'dart:io';
2+
import 'svg/path_ops.dart';
3+
4+
/// Look up the location of the pathops from flutter's artifact cache.
5+
bool initializePathOpsFromFlutterCache() {
6+
final Directory cacheRoot;
7+
if (Platform.resolvedExecutable.contains('flutter_tester')) {
8+
cacheRoot = File(Platform.resolvedExecutable).parent.parent.parent.parent;
9+
} else if (Platform.resolvedExecutable.contains('dart')) {
10+
cacheRoot = File(Platform.resolvedExecutable).parent.parent.parent;
11+
} else {
12+
print('Unknown executable: ${Platform.resolvedExecutable}');
13+
return false;
14+
}
15+
16+
final String platform;
17+
final String executable;
18+
if (Platform.isWindows) {
19+
platform = 'windows-x64';
20+
executable = 'path_ops.dll';
21+
} else if (Platform.isMacOS) {
22+
platform = 'darwin-x64';
23+
executable = 'libpath_ops.dylib';
24+
} else if (Platform.isLinux) {
25+
platform = 'linux-x64';
26+
executable = 'libpath_ops.so';
27+
} else {
28+
print('path_ops not supported on ${Platform.localeName}');
29+
return false;
30+
}
31+
final String pathops =
32+
'${cacheRoot.path}/artifacts/engine/$platform/$executable';
33+
if (!File(pathops).existsSync()) {
34+
print('Could not locate libpathops at $pathops.');
35+
print('Ensure you are on a supported version of flutter and then run ');
36+
print('"flutter precache".');
37+
return false;
38+
}
39+
initializeLibPathOps(pathops);
40+
return true;
41+
}

0 commit comments

Comments
 (0)