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

Fix image draw scaling and positioning problem #649

Merged
merged 1 commit into from
Jan 2, 2024
Merged
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
59 changes: 30 additions & 29 deletions build-system/erbui/generators/detail/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,15 +409,15 @@ def generate_image (self, context, module, image):
tree = cairosvg.parser.Tree (file_obj=file)
surface = ContextOnlySurface (tree, context)

width_pt = surface.context_width * 0.75
height_pt = surface.context_height * 0.75
width_pt = surface.context_width
height_pt = surface.context_height

position_x_pt = self.current_position_x * MM_TO_PT - width_pt * 0.5
position_y_pt = self.current_position_y * MM_TO_PT - height_pt * 0.5

with context:
context.translate (position_x_pt, position_y_pt)
context.scale (0.75)
context.scale (surface.context_scale)

surface.draw (tree)

Expand Down Expand Up @@ -556,29 +556,30 @@ def measure_text (self, context, font_path, font_size, text):

class ContextOnlySurface (cairosvg.surface.Surface):
def __init__ (self, tree, context):
self.context = context

# cache stuff
self.markers = {}
self.gradients = {}
self.patterns = {}
self.masks = {}
self.paths = {}
self.filters = {}
self.images = {}
self.tree_cache = {(tree.url, tree.get('id')): tree}

self.dpi = 96 # used in `size` for pt units

# state stuff
self.context_width, self.context_height, viewbox = cairosvg.helpers.node_format (self, tree) # used in `size` for % units

self.font_size = cairosvg.helpers.size(self, '12pt')
self.cursor_position = [0, 0]
self.cursor_d_position = [0, 0]
self.text_path_width = 0
self._old_parent_node = self.parent_node = None
self.stroke_and_fill = True

self.map_rgba = None
self.map_image = None
self.context = context

# cache stuff
self.markers = {}
self.gradients = {}
self.patterns = {}
self.masks = {}
self.paths = {}
self.filters = {}
self.images = {}
self.tree_cache = {(tree.url, tree.get('id')): tree}

self.dpi = 72 # used in `size` for pt units

# state stuff
self.context_width, self.context_height, viewbox = cairosvg.helpers.node_format (self, tree) # used in `size` for % units
self.context_scale = self.context_width / (viewbox [2] - viewbox [0])

self.font_size = cairosvg.helpers.size(self, '12pt')
self.cursor_position = [0, 0]
self.cursor_d_position = [0, 0]
self.text_path_width = 0
self._old_parent_node = self.parent_node = None
self.stroke_and_fill = True

self.map_rgba = None
self.map_image = None
Loading