Skip to content
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
13 changes: 3 additions & 10 deletions packages/vector_graphics/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: example
description: An example of the vector_graphics package
publish_to: 'none'
publish_to: none

resolution: workspace

environment:
sdk: ^3.7.0
Expand All @@ -12,22 +14,13 @@ dependencies:
vector_graphics: any
vector_graphics_compiler: any


dev_dependencies:
flutter_test:
sdk: flutter

flutter:
uses-material-design: true

dependency_overrides:
vector_graphics:
path: ../
vector_graphics_codec:
path: ../../vector_graphics_codec
vector_graphics_compiler:
path: ../../vector_graphics_compiler

platforms:
android:
ios:
Expand Down
3 changes: 3 additions & 0 deletions packages/vector_graphics/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ repository: https://github.com/flutter/packages/tree/main/packages/vector_graphi
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+vector_graphics%22
version: 1.1.19

workspace:
- example

environment:
sdk: ^3.7.0
flutter: ">=3.29.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/vector_graphics_compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.0

* Add build hook helper to allow for transforming assets through hooks.

## 1.1.19

* Updates allowed version range of `xml` to include up to 6.6.1.
Expand Down
208 changes: 102 additions & 106 deletions packages/vector_graphics_compiler/bin/vector_graphics_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,110 +9,107 @@ import 'dart:io';
import 'package:args/args.dart';
import 'package:path/path.dart' as p;
import 'package:vector_graphics_compiler/src/svg/colors.dart';
import 'package:vector_graphics_compiler/src/util/isolate_processor.dart';
import 'package:vector_graphics_compiler/vector_graphics_compiler.dart';

import 'util/isolate_processor.dart';

final ArgParser argParser =
ArgParser()
..addOption(
'current-color',
help:
'The value (in ARGB format or a named SVG color) of the '
'"currentColor" attribute.',
valueHelp: '0xFF000000',
defaultsTo: '0xFF000000',
)
..addOption(
'font-size',
help: 'The basis for font size based values (i.e. em, ex).',
valueHelp: '14',
defaultsTo: '14',
)
..addOption(
'x-height',
help:
'The x-height or corpus size of the font. If unspecified, defaults '
'to half of font-size.',
valueHelp: '7',
)
..addOption(
'libtessellator',
help: 'The path to a libtessellator dynamic library',
valueHelp: 'path/to/libtessellator.dylib',
hide: true,
)
..addOption(
'libpathops',
help: 'The path to a libpathops dynamic library',
valueHelp: 'path/to/libpath_ops.dylib',
hide: true,
)
..addFlag(
'tessellate',
help:
'Convert path fills into a tessellated shape. This will improve '
'raster times at the cost of slightly larger file sizes.',
)
..addFlag(
'optimize-masks',
help: 'Allows for masking optimizer to be enabled or disabled',
defaultsTo: true,
)
..addFlag(
'optimize-clips',
help: 'Allows for clipping optimizer to be enabled or disabled',
defaultsTo: true,
)
..addFlag(
'optimize-overdraw',
help: 'Allows for overdraw optimizer to be enabled or disabled',
defaultsTo: true,
)
..addOption(
'input-dir',
help:
'The path to a directory containing one or more SVGs. '
'Only includes files that end with .svg. '
'Cannot be combined with --input or --output.',
)
..addOption(
'out-dir',
help:
'The output directory path '
'use it with --input-dir to specific the output dirictory',
)
..addOption(
'input',
abbr: 'i',
help: 'The path to a file containing a single SVG',
)
..addOption(
'concurrency',
abbr: 'k',
help:
'The maximum number of SVG processing isolates to spawn at once. '
'If not provided, defaults to the number of cores.',
)
..addFlag(
'dump-debug',
help:
'Dump a human readable debugging format alongside the compiled asset',
hide: true,
)
..addOption(
'output',
abbr: 'o',
help:
'The path to a file where the resulting vector_graphic will be written.\n'
'If not provided, defaults to <input-file>.vec',
)
..addFlag(
'use-half-precision-control-points',
help:
'Convert path control points into IEEE 754-2008 half precision floating point values.\n'
'This reduces file size at the cost of lost precision at larger values.',
);
final ArgParser argParser = ArgParser()
..addOption(
'current-color',
help:
'The value (in ARGB format or a named SVG color) of the '
'"currentColor" attribute.',
valueHelp: '0xFF000000',
defaultsTo: '0xFF000000',
)
..addOption(
'font-size',
help: 'The basis for font size based values (i.e. em, ex).',
valueHelp: '14',
defaultsTo: '14',
)
..addOption(
'x-height',
help:
'The x-height or corpus size of the font. If unspecified, defaults '
'to half of font-size.',
valueHelp: '7',
)
..addOption(
'libtessellator',
help: 'The path to a libtessellator dynamic library',
valueHelp: 'path/to/libtessellator.dylib',
hide: true,
)
..addOption(
'libpathops',
help: 'The path to a libpathops dynamic library',
valueHelp: 'path/to/libpath_ops.dylib',
hide: true,
)
..addFlag(
'tessellate',
help:
'Convert path fills into a tessellated shape. This will improve '
'raster times at the cost of slightly larger file sizes.',
)
..addFlag(
'optimize-masks',
help: 'Allows for masking optimizer to be enabled or disabled',
defaultsTo: true,
)
..addFlag(
'optimize-clips',
help: 'Allows for clipping optimizer to be enabled or disabled',
defaultsTo: true,
)
..addFlag(
'optimize-overdraw',
help: 'Allows for overdraw optimizer to be enabled or disabled',
defaultsTo: true,
)
..addOption(
'input-dir',
help:
'The path to a directory containing one or more SVGs. '
'Only includes files that end with .svg. '
'Cannot be combined with --input or --output.',
)
..addOption(
'out-dir',
help:
'The output directory path '
'use it with --input-dir to specific the output dirictory',
)
..addOption(
'input',
abbr: 'i',
help: 'The path to a file containing a single SVG',
)
..addOption(
'concurrency',
abbr: 'k',
help:
'The maximum number of SVG processing isolates to spawn at once. '
'If not provided, defaults to the number of cores.',
)
..addFlag(
'dump-debug',
help: 'Dump a human readable debugging format alongside the compiled asset',
hide: true,
)
..addOption(
'output',
abbr: 'o',
help:
'The path to a file where the resulting vector_graphic will be written.\n'
'If not provided, defaults to <input-file>.vec',
)
..addFlag(
'use-half-precision-control-points',
help:
'Convert path control points into IEEE 754-2008 half precision floating point values.\n'
'This reduces file size at the cost of lost precision at larger values.',
);

void validateOptions(ArgResults results) {
if (results.wasParsed('input-dir') &&
Expand All @@ -137,10 +134,9 @@ SvgTheme _parseTheme(ArgResults results) {
return SvgTheme(
currentColor: currentColor,
fontSize: double.tryParse(results['font-size'] as String) ?? 14,
xHeight:
results.wasParsed('x-height')
? double.tryParse(results['x-height'] as String)
: null,
xHeight: results.wasParsed('x-height')
? double.tryParse(results['x-height'] as String)
: null,
);
}

Expand Down
45 changes: 45 additions & 0 deletions packages/vector_graphics_compiler/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.build/
.buildlog/
.history
.svn/
.swiftpm/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins-dependencies
.pub-cache/
.pub/
/build/
/coverage/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
30 changes: 30 additions & 0 deletions packages/vector_graphics_compiler/example/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "260e8f022510f454d23ee9f563a5092ae4e64289"
channel: "[user-branch]"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 260e8f022510f454d23ee9f563a5092ae4e64289
base_revision: 260e8f022510f454d23ee9f563a5092ae4e64289
- platform: web
create_revision: 260e8f022510f454d23ee9f563a5092ae4e64289
base_revision: 260e8f022510f454d23ee9f563a5092ae4e64289

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
buildFlags:
_pluginToolsConfigGlobalKey:
- "--no-tree-shake-icons"
- "--dart-define=buildmode=testing"
configs:
- "--enable-dart-data-assets"
9 changes: 9 additions & 0 deletions packages/vector_graphics_compiler/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Vector Graphics Compiler - Build Hooks Example

A Flutter showcase for how to replace asset transformers with hooks.

To run execute:
```bash
flutter config --enable-dart-data-assets
flutter run
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions packages/vector_graphics_compiler/example/hook/build.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:hooks/hooks.dart';
import 'package:vector_graphics_compiler/build.dart';

void main(List<String> args) {
build(args, (BuildInput input, BuildOutputBuilder output) async {
await compileSvg(
input,
output,
name: 'example_file',
file: input.packageRoot.resolve('assets/example.svg'),
options: const Options(dumpDebug: true, concurrency: 2),
);
});
}
Loading