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

Two SVG bugs #114

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 13 additions & 5 deletions chalk/backend/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,17 @@ def visit_text(
return self.dwg.text(
shape.text,
transform=f"translate({dx}, 0)",
style=f"""text-align:center; text-anchor:middle; dominant-baseline:middle;
font-family:sans-serif; font-weight: bold;
font-size:{shape.font_size}px;
vector-effect: non-scaling-stroke;""",
style=";".join(
[
"text-align:center",
"text-anchor:middle",
"dominant-baseline:middle",
"font-family:sans-serif",
"font-weight: bold",
f"font-size:{shape.font_size}px",
"vector-effect: non-scaling-stroke",
]
),
)

raise NotImplementedError("Text is not implemented")
Expand All @@ -190,7 +197,8 @@ def visit_image(
dx = -shape.width / 2
dy = -shape.height / 2
return self.dwg.image(
href=shape.url_path, transform=f"translate({dx}, {dy})"
href=shape.url_path,
transform=f"translate({dx}, {dy}) scale(0.05, 0.05)",
)


Expand Down
8 changes: 6 additions & 2 deletions chalk/shapes/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from chalk.shapes.shape import Shape
from chalk.transform import P2, BoundingBox, origin
from chalk.types import Diagram
from chalk.visitor import A, ShapeVisitor


def from_pil(
Expand Down Expand Up @@ -43,8 +44,8 @@ def __post_init__(self) -> None:
out = open(self.local_path, "rb") # type:ignore

self.im = PIL.Image.open(out)
self.height = self.im.height
self.width = self.im.width
self.height = self.im.height * 0.05
self.width = self.im.width * 0.05

def get_bounding_box(self) -> BoundingBox:
left = origin.x - self.width / 2
Expand All @@ -53,6 +54,9 @@ def get_bounding_box(self) -> BoundingBox:
br = P2(left + self.width, top + self.height)
return BoundingBox([tl, br])

def accept(self, visitor: ShapeVisitor[A], **kwargs: Any) -> A:
return visitor.visit_image(self, **kwargs)


def image(local_path: str, url_path: Optional[str]) -> Diagram:
from chalk.core import Primitive
Expand Down
Binary file modified examples/output/arrows.pdf
Binary file not shown.
Binary file modified examples/output/arrows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/output/arrows.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/output/escher-square-limit.pdf
Binary file not shown.
Binary file modified examples/output/hanoi.pdf
Binary file not shown.
Binary file modified examples/output/hex-variation.pdf
Binary file not shown.
Binary file modified examples/output/hilbert.pdf
Binary file not shown.
Binary file modified examples/output/intro-01.pdf
Binary file not shown.
Binary file modified examples/output/intro-02.pdf
Binary file not shown.
Binary file modified examples/output/intro-03.pdf
Binary file not shown.
Binary file modified examples/output/intro-04.pdf
Binary file not shown.
Binary file modified examples/output/lenet.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/output/lenet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/output/logo.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/output/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/output/path.pdf
Binary file not shown.
Binary file modified examples/output/path.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading