Skip to content

fixing devision by 0 and improving cache call #1314

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

Closed
wants to merge 1 commit 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
43 changes: 22 additions & 21 deletions src/ezdxf/addons/drawing/frontend.py
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a valid fix and I will implement this.

Original file line number Diff line number Diff line change
Expand Up @@ -766,27 +766,28 @@ def draw_image_entity(self, entity: DXFGraphic, properties: Properties) -> None:
elif show_filename_if_missing:
default_cap_height = 20
text = image_def.dxf.filename
font = self.pipeline.text_engine.get_font(
self.get_font_face(properties)
)
text_width = font.text_width_ex(text, default_cap_height)
image_size = image.dxf.image_size
desired_width = image_size.x * 0.75
scale = desired_width / text_width
translate = Matrix44.translate(
(image_size.x - desired_width) / 2,
(image_size.y - default_cap_height * scale) / 2,
0,
)
transform = (
Matrix44.scale(scale) @ translate @ image.get_wcs_transform()
)
self.pipeline.draw_text(
text,
transform,
properties,
default_cap_height,
)
if text.strip():
font = self.pipeline.text_engine.get_font(
self.get_font_face(properties)
)
text_width = font.text_width_ex(text, default_cap_height)
image_size = image.dxf.image_size
desired_width = image_size.x * 0.75
scale = desired_width / text_width
translate = Matrix44.translate(
(image_size.x - desired_width) / 2,
(image_size.y - default_cap_height * scale) / 2,
0,
)
transform = (
Matrix44.scale(scale) @ translate @ image.get_wcs_transform()
)
self.pipeline.draw_text(
text,
transform,
properties,
default_cap_height,
)

points = [v.vec2 for v in image.boundary_path_wcs()]
self.pipeline.draw_solid_lines(list(zip(points, points[1:])), properties)
Expand Down
17 changes: 8 additions & 9 deletions src/ezdxf/fonts/ttfonts.py
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just an opinion and I will ignore this.

Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,14 @@ def get_glyph_path(self, char: str) -> GlyphPath:

def get_glyph_width(self, char: str) -> float:
"""Returns the raw glyph width, without any scaling applied."""
try:
return self._glyph_width_cache[char]
except KeyError:
pass
width = 0.0
try:
width = self.get_generic_glyph(char).width
except KeyError:
pass
width = self._glyph_width_cache.get(char , 0.0)
if width:
return width
glyph = self._glyph_width_cache.get(char,None)
if glyph:
width = width.width
else:
width = 0.0
self._glyph_width_cache[char] = width
return width

Expand Down
Loading