-
-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for global and per-layer metadata #359
Conversation
Codecov Report
@@ Coverage Diff @@
## master #359 +/- ##
==========================================
+ Coverage 92.35% 92.55% +0.19%
==========================================
Files 50 53 +3
Lines 3992 4457 +465
Branches 552 621 +69
==========================================
+ Hits 3687 4125 +438
- Misses 203 222 +19
- Partials 102 110 +8
Continue to review full report at Codecov.
|
Not sure if I should make this a feature request somewhere else, but it might make sense to add support for changing the background color of the SVG as part of this, since this will enable stroke color changes. |
@EmmaSimon can you elaborate? Why would the background color be important to change stroke color? |
@abey79 Er, sorry, I phrased that weird. I just meant that I want the ability to change background color, in addition to stroke color. |
@EmmaSimon I've not planned "global" metadata yet, but that might be a good reason to think about it. I have a rather strict policy favouring feature that make sens for plotter application but custom background color makes sense to prefix plots on colored paper. |
Right, that was my reasoning, stroke color drastically changes how plots can look, and paper color drastically changes how stroke color looks! So it would be nice to see that while you're designing the sketch. |
bc3bead
to
7360235
Compare
- `stat` prints layers' metadata - added test to check that command preserve metadata - vpype_cli: __all__ set to () for all commands (no import in module) API change: - Model: added a structure with a list of system properties and their types. - LineCollection: added `set_property()`, which enforce type for system properties. - Document: changed `add()` to always initialize layers with new LineCollection instance (to avoid shared metadata). - Document: added `swap_content()` to swap two layers' content while preserving metadata. - Document: added `replace()` to replace a layer's content while preserving metadata
- renamed bundled config file to vpype_config.toml - reverted __all__ in vpype_cli (it broke docs) - viewer: uses color/pen_width when available (GUI WIP) - doc: added cookbook on pen configurations - doc: added missing commands to the reference - updated PR template
- added vpype/metadata.py - added vp.Color object (for "vp:color") - fix: viewer use of color
- added vp.Document.clear_metadata() api - removed metadata for some viewer tests
- added tests for `read -m` - added multi-layer test case for `read`
…ear` - removed commands `metadata`, `clearprops` - added global metadata by refactoring metadata-related implementation into a _MetadataMixin class - vp.Document's page_size is now stored as a global property - added a warning when a layer passed to `--layer` doesn't exist - renamed metadata to properties in `stat` (and other user facing texts)
- moved svg whitelist to metadata.py
- write_svg() can now restore svg metadata - updated `write` to support SVG restore - removed some attribute from the SVG whitelist - globally common svg metadata is now saved as global metadata rather than in each layer metadata - fixed bug in Document.extend() - added doc in `read`
- fixed tests
- added test for the above - updated CHANGELOG.md & README.md - updated copyright dates to 2022 - minor fix for the API documentation
- `propset` now accepts units for int and float
260668c
to
838166d
Compare
@EmmaSimon as you might have seen, everything is ready for custom background colour support. I won't however include it in the present PR. |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Description
This PR introduce per-layer and global metadata to the vpype pipeline. Metadata takes the form of a free-form set of properties identified by a string. Supported types include
str
,int
,float
, andvpype.Color
(ascolor
in the UI).Low-level inspection, modification and deletion of both global and layer properties can be done with a new set of low-level commands prefixed by
prop-
:Properties whose name is prefixed by
vp:
are used by vpype for a number of features, some of which are newly introduced in this PR. Such properties are referred to as "system properties".Layer system properties:
vp:color
(color
): the color to be used for the layervp:pen_width
(float
): the pen width to be used for the layervp:name
(float
): the name of the layer (in theinkscape:label
SVG attribute sense)Global system properties:
vp:page_size
: the page size (formerly stored as an instance attribute to thevp.Document
classThe
show
andwrite
command now take into account the above layer system properties. The page size related commands (pagesize
andlayout
) now act on thevp:page_size
global system property.New, high-level commands are introduced to interact with the new layer system properties:
name
: sets the name of a given layercolor
: changes the color for a given layerpenwidth
: changes the pen-width of a given layerpens
: apply a pre-defined set of per-layer name, color, and/or pen width to the pipelines, based on a template defined in a config file (rgb
andcmyk
templates are bundled in the new config file)In addition to populating the system properties (when possible), the
read
command now extracts a number of SVG attributes and stores them as properties (prefixed withsvg:
). Optionally, thewrite
command can attempt to restore those properties when possible. Note: since properties are per layer, SVG attributes are saved only if they are shared by all the geometries contained in a given layer.The layer operation commands are updated to handle metadata:
--prob
is not used, thelcopy
andlmove
commands now copy the source layer's properties to the destination layer (possibly overwriting existing properties).--prob
is not used, thelswap
command now swaps the layer properties as well.--no-prop
option.API changes:
vpype.Document
andvpype.LineCollection
have been extended to support operation on their metadata (through the use of a mix-in class)Other changes:
vpype_config.toml
(since it's no longer specific to HPGL features)stat
command now display all the metadata in the pipeline--layer
doesn't existFixes #145 and #213
TODO:
read_[multilayer_]svg()
read -m
write_svg()
test: add viewer tests depending on metadata(Fix failing viewer tests on M1 mac and add metadata-specific viewer tests #375)propset
must accept units for float/int valuesChecklist
black
andisort
)mypy vpype vpype_cli tests
returns no errorpytest
succeedshelp
make clean && make html
indocs/
)