Skip to content

Commit 881812b

Browse files
Add support for encoding in the compiler, add basic example to package:vector_graphics (#8)
1 parent 542f437 commit 881812b

File tree

13 files changed

+287
-8
lines changed

13 files changed

+287
-8
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
**/ios/Flutter/.last_build_id
26+
.dart_tool/
27+
.flutter-plugins
28+
.flutter-plugins-dependencies
29+
.packages
30+
.pub-cache/
31+
.pub/
32+
/build/
33+
34+
# Web related
35+
lib/generated_plugin_registrant.dart
36+
37+
# Symbolication related
38+
app.*.symbols
39+
40+
# Obfuscation related
41+
app.*.map.json
42+
43+
# Android Studio will place build artifacts here
44+
/android/app/debug
45+
/android/app/profile
46+
/android/app/release
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# example
2+
3+
An example of using package:vector_graphics to draw vector assets
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:flutter_lints/flutter.yaml
236 Bytes
Binary file not shown.
Binary file not shown.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter/services.dart';
3+
import 'package:vector_graphics/vector_graphics.dart';
4+
5+
void main() {
6+
runApp(const MyApp());
7+
}
8+
9+
class MyApp extends StatelessWidget {
10+
const MyApp({Key? key}) : super(key: key);
11+
12+
@override
13+
Widget build(BuildContext context) {
14+
return MaterialApp(
15+
title: 'Vector Graphics Demo',
16+
theme: ThemeData(
17+
primarySwatch: Colors.blue,
18+
),
19+
home: Scaffold(
20+
body: Center(
21+
child: VectorGraphic(
22+
bytesLoader: AssetBytesLoader(
23+
assetName: 'assets/tiger.bin', assetBundle: rootBundle),
24+
),
25+
),
26+
),
27+
);
28+
}
29+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: example
2+
description: An example of the vector_graphics package
3+
publish_to: 'none'
4+
5+
environment:
6+
sdk: ">=2.16.0 <3.0.0"
7+
8+
dependencies:
9+
flutter:
10+
sdk: flutter
11+
vector_graphics: 0.0.1
12+
13+
14+
dev_dependencies:
15+
flutter_test:
16+
sdk: flutter
17+
flutter_lints: ^1.0.0
18+
19+
20+
flutter:
21+
uses-material-design: true
22+
assets:
23+
- assets/bars.bin
24+
- assets/tiger.bin # ghostscript tiger
25+
26+
27+
# Comment out before publishing
28+
dependency_overrides:
29+
vector_graphics_codec:
30+
path: ../../vector_graphics_codec
31+
vector_graphics:
32+
path: ../

packages/vector_graphics_codec/lib/vector_graphics_codec.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class VectorGraphicsCodec {
1717
static const int _lineToTag = 33;
1818
static const int _cubicToTag = 34;
1919
static const int _closeTag = 35;
20+
static const int _finishPathTag = 36;
2021

2122
static const int _version = 1;
2223
static const int _magicNumber = 0x00882d62;
@@ -74,6 +75,9 @@ class VectorGraphicsCodec {
7475
case _closeTag:
7576
_readClose(buffer, listener);
7677
continue;
78+
case _finishPathTag:
79+
listener?.onPathFinished();
80+
continue;
7781
default:
7882
throw StateError('Unknown type tag $type');
7983
}
@@ -95,7 +99,7 @@ class VectorGraphicsCodec {
9599

96100
/// Encode a draw vertices command in the current buffer.
97101
///
98-
/// The [indices ] are the index buffer used and is optional.
102+
/// The [indices] are the index buffer used and is optional.
99103
void writeDrawVertices(
100104
VectorGraphicsBuffer buffer,
101105
Float32List vertices,
@@ -305,6 +309,7 @@ class VectorGraphicsCodec {
305309
if (buffer._currentPathId == -1) {
306310
throw StateError('There is no active Path.');
307311
}
312+
buffer._putUint8(_finishPathTag);
308313
buffer._currentPathId = -1;
309314
}
310315

packages/vector_graphics_codec/test/vector_graphics_codec_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ void main() {
8383
const OnPathMoveTo(1, 2),
8484
const OnPathLineTo(2, 3),
8585
const OnPathClose(),
86+
const OnPathFinished(),
8687
OnDrawPath(pathId, paintId),
8788
]);
8889
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'dart:io';
2+
import 'dart:typed_data';
3+
4+
import 'package:vector_graphics_compiler/vector_graphics_compiler.dart';
5+
6+
Future<void> main(List<String> args) async {
7+
if (args.length != 2) {
8+
print('Usage: vector_graphics_compiler input.svg output.bin');
9+
exit(1);
10+
}
11+
final String xml = File(args[0]).readAsStringSync();
12+
final File outputFile = File(args[1]);
13+
final Uint8List bytes = await encodeSVG(xml, args[0]);
14+
15+
outputFile.writeAsBytesSync(bytes);
16+
}

0 commit comments

Comments
 (0)