Skip to content
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

migrate from CairoSVG to svglib #36

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 5 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ numpy>=1.25.2
scipy>=1.11.1
#tox==4.9.0
pyyaml==6.0.1
cairosvg==2.7.0
#cairosvg==2.7.0
pycairo
renderlab
rlPyCairo
svglib
ocp_vscode==2.0.13
GitPython==3.1.40
progress==1.6
Expand Down
25 changes: 18 additions & 7 deletions src/partcad/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import cadquery as cq
import build123d as b3d

import cairosvg
#import cairosvg
from svglib.svglib import svg2rlg
from reportlab.graphics import renderPM

import logging
import tempfile

Expand Down Expand Up @@ -140,12 +143,20 @@ def render_png(
logging.info("Rendering: %s" % filepath)
svg_path = self._get_svg_path()

cairosvg.svg2png(
url=svg_path,
write_to=filepath,
output_width=width,
output_height=height,
)
# cairosvg.svg2png(
# url=svg_path,
# write_to=filepath,
# output_width=width,
# output_height=height,
# )

#NO SCALING POSSIBLE
#could install pymupdf and convert to PDF
#and convert that to PNG with scaling
drawing = svg2rlg(svg_path)
renderPM.drawToFile(drawing,
filepath,
fmt="PNG")

def render_txt(self, filepath=None):
if filepath is None:
Expand Down