|
8 | 8 | import zlib |
9 | 9 |
|
10 | 10 | import bpy |
| 11 | +from lxml import etree |
11 | 12 | import pytest |
12 | 13 |
|
13 | 14 | from typst_importer.image_import import extract_svg_images |
@@ -63,6 +64,32 @@ def test_preprocessing_extracts_embedded_use_image_with_viewport_geometry(): |
63 | 64 | assert max(ys) == pytest.approx(65.0) |
64 | 65 |
|
65 | 66 |
|
| 67 | +def test_preprocessing_preserves_visible_overflow_for_typst_image_symbols(): |
| 68 | + data_uri = _data_uri() |
| 69 | + svg = f'''<svg xmlns="{SVG_NS}" width="100" height="20"> |
| 70 | + <defs><symbol id="emoji" overflow="visible"> |
| 71 | + <image transform="translate(0 -80)" width="100" height="100" |
| 72 | + preserveAspectRatio="none" href="{data_uri}"/> |
| 73 | + </symbol></defs> |
| 74 | + <use href="#emoji" transform="scale(0.2 -0.2)"/> |
| 75 | + </svg>''' |
| 76 | + |
| 77 | + processed = preprocess_svg(svg) |
| 78 | + root = etree.fromstring(processed.encode("utf-8")) |
| 79 | + image = root.xpath("//*[local-name()='image']")[0] |
| 80 | + image_viewport = next( |
| 81 | + ancestor |
| 82 | + for ancestor in image.iterancestors() |
| 83 | + if etree.QName(ancestor).localname == "svg" and ancestor is not root |
| 84 | + ) |
| 85 | + |
| 86 | + # Typst positions the full bitmap outside the symbol's nominal viewport. |
| 87 | + # The symbol therefore relies on visible overflow; putting this property |
| 88 | + # only on an outer group clips the emoji to a thin horizontal strip. |
| 89 | + assert image_viewport.get("overflow") == "visible" |
| 90 | + assert image.get("href") == data_uri |
| 91 | + |
| 92 | + |
66 | 93 | def test_external_images_are_contained_to_the_typst_source_folder(tmp_path: Path): |
67 | 94 | source_dir = tmp_path / "source" |
68 | 95 | source_dir.mkdir() |
@@ -117,8 +144,12 @@ def test_typst_image_becomes_a_packed_textured_plane(tmp_path: Path): |
117 | 144 | curves = [obj for obj in collection.objects if obj.type == "CURVE"] |
118 | 145 | assert len(curves) == 1 |
119 | 146 | assert plane.get("svg_paint_index") > curves[0].get("svg_paint_index") |
120 | | - assert plane.dimensions.x == pytest.approx(curves[0].dimensions.x, abs=2e-6) |
121 | | - assert plane.dimensions.y == pytest.approx(curves[0].dimensions.y, abs=2e-6) |
| 147 | + # Curve geometry is rescaled in place. Updating the dependency graph keeps |
| 148 | + # Blender from returning its stale, pre-scale dimensions and ensures this |
| 149 | + # comparison catches image planes that miss the same import scale. |
| 150 | + bpy.context.view_layer.update() |
| 151 | + assert plane.dimensions.x == pytest.approx(curves[0].dimensions.x, rel=1e-3) |
| 152 | + assert plane.dimensions.y == pytest.approx(curves[0].dimensions.y, rel=1e-3) |
122 | 153 | material = plane.data.materials[0] |
123 | 154 | texture = next( |
124 | 155 | node |
|
0 commit comments