Skip to content

Commit

Permalink
Fixed issue where forlayer would set _n improperly (#443)
Browse files Browse the repository at this point in the history
Fixes #434
  • Loading branch information
abey79 authored Mar 31, 2022
1 parent e5929a1 commit 11ebcf1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Release date: UNRELEASED

### Bug fixes

* Fixed issue with `forlayer` where the `_n` variable was set improperly (#443)
* Fixed issue with `write` where layer opacity was included in the `stroke` attribute instead of using `stroke-opacity`, which, although compliant, was not compatible with Inkscape (#429)


Expand Down
15 changes: 15 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,21 @@ def test_forlayer_command_property_accessor():
assert doc.layers[i + 1].property("test2") == i


def test_forlayer_vars():
vpype_cli.execute(
"""
repeat 5
random -l new
end
eval 'cnt=0'
forlayer
eval 'assert _lid==cnt+1'
eval 'assert _i==cnt;cnt += 1'
eval 'assert _n==5'
end"""
)


def test_pagerotate():
doc = vpype_cli.execute("random pagesize a4 pagerotate")
assert doc.page_size == pytest.approx((1122.5196850393702, 793.7007874015749))
Expand Down
5 changes: 3 additions & 2 deletions vpype_cli/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,14 @@ def forlayer(state: State, processors: Iterable[ProcessorType]) -> None:
orig_doc = state.document
new_doc: vp.Document = orig_doc.clone()

for i, lid in enumerate(list(orig_doc.layers)):
lids = list(orig_doc.layers)
for i, lid in enumerate(lids):
with state.temp_document(keep_layer=False) as doc:
doc.add(orig_doc.pop(lid), lid, with_metadata=True)
variables = {
"_lid": lid,
"_i": i,
"_n": len(doc.layers),
"_n": len(lids),
"_name": doc.layers[lid].property(vp.METADATA_FIELD_NAME) or "",
"_color": doc.layers[lid].property(vp.METADATA_FIELD_COLOR),
"_pen_width": doc.layers[lid].property(vp.METADATA_FIELD_PEN_WIDTH),
Expand Down

0 comments on commit 11ebcf1

Please sign in to comment.