new grayscale output for testing laser, not working, will change to new design
This commit is contained in:
@@ -681,9 +681,21 @@ def _clipped_shapes(shapes, width, height):
|
||||
|
||||
def write_svg_vector(
|
||||
output_path, texture_width, texture_height, width_mm, height_mm,
|
||||
mesh_polygons, patch_shapes, cross_rects, cross_color, uv_map
|
||||
mesh_polygons, patch_shapes, cross_rects, cross_color, uv_map,
|
||||
background=None,
|
||||
):
|
||||
"""Write editable grouped SVG geometry; no raster data is embedded."""
|
||||
"""Write editable grouped SVG geometry; no raster data is embedded.
|
||||
|
||||
``background`` is the page fill. Left as ``None`` it is the black production ground; the
|
||||
laser-engraving variant passes white, because a laser cuts what is dark and an
|
||||
unengraved sheet must be light.
|
||||
"""
|
||||
if background is None:
|
||||
background_fill = "#000000"
|
||||
else:
|
||||
background_fill = "#" + "".join(
|
||||
f"{round(_clamp_channel(channel) * 255):02x}" for channel in background[:3]
|
||||
)
|
||||
lines = [
|
||||
'<?xml version="1.0" encoding="UTF-8"?>',
|
||||
(
|
||||
@@ -705,7 +717,7 @@ def write_svg_vector(
|
||||
(
|
||||
f' <rect id="background-fill" x="0" y="0" '
|
||||
f'width="{texture_width}" height="{texture_height}" '
|
||||
f'fill="#000000" stroke="none"/>'
|
||||
f'fill="{background_fill}" stroke="none"/>'
|
||||
),
|
||||
" </g>",
|
||||
' <g id="mesh">',
|
||||
@@ -785,15 +797,26 @@ def _build_pdf(objects):
|
||||
|
||||
def write_pdf_vector(
|
||||
output_path, texture_width, texture_height, width_mm, height_mm,
|
||||
mesh_polygons, patch_shapes, cross_rects, cross_color
|
||||
mesh_polygons, patch_shapes, cross_rects, cross_color,
|
||||
background=None,
|
||||
):
|
||||
"""Write native vector PDF paths at the configured physical page size."""
|
||||
"""Write native vector PDF paths at the configured physical page size.
|
||||
|
||||
``background`` as for `write_svg_vector`. The default emits the original literal command
|
||||
so existing documents stay byte-identical.
|
||||
"""
|
||||
page_width_pt = float(width_mm) * 72.0 / 25.4
|
||||
page_height_pt = float(height_mm) * 72.0 / 25.4
|
||||
scale_x = page_width_pt / float(texture_width)
|
||||
scale_y = page_height_pt / float(texture_height)
|
||||
|
||||
content = ["q", "% background", "0 0 0 rg"]
|
||||
if background is None:
|
||||
background_command = "0 0 0 rg"
|
||||
else:
|
||||
background_command = _pdf_set_fill(
|
||||
(background[0], background[1], background[2], 1.0)
|
||||
)
|
||||
content = ["q", "% background", background_command]
|
||||
content.append(
|
||||
f"0 0 {_format_number(page_width_pt)} {_format_number(page_height_pt)} re f"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user