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 invalid panel dx/dy offsets #294

Merged
merged 3 commits into from Jul 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 17 additions & 5 deletions omero_figure/scripts/omero/figure_scripts/Figure_To_Pdf.py
Expand Up @@ -632,7 +632,7 @@ def __init__(self, conn, script_params, export_images=False):
# Since unicode can't be wrapped by rstring
figure_json_string = figure_json_string.decode('utf8')
self.figure_json = self.version_transform_json(
json.loads(figure_json_string))
self._fix_figure_json(json.loads(figure_json_string)))

n = datetime.now()
# time-stamp name by default: Figure_2013-10-29_22-43-53.pdf
Expand All @@ -645,6 +645,18 @@ def __init__(self, conn, script_params, export_images=False):
self.page_width = self.figure_json['paper_width']
self.page_height = self.figure_json['paper_height']

def _fix_figure_json(self, figure_json):
"""Ensure that the figure JSON is proper.
"""
# In some cases, dx and dy end up missing or set to null.
# See issue #257 (missing) and #292 (null value).
for panel in figure_json['panels']:
for key in ['dx', 'dy']:
offset = panel.get(key)
if offset is None:
panel[key] = DEFAULT_OFFSET
return figure_json

def version_transform_json(self, figure_json):

v = figure_json.get('version')
Expand Down Expand Up @@ -884,8 +896,8 @@ def get_crop_region(self, panel):
zoom = float(panel['zoom'])
frame_w = panel['width']
frame_h = panel['height']
dx = panel.get('dx', DEFAULT_OFFSET)
dy = panel.get('dy', DEFAULT_OFFSET)
dx = panel['dx']
dy = panel['dy']
orig_w = panel['orig_width']
orig_h = panel['orig_height']

Expand Down Expand Up @@ -1319,8 +1331,8 @@ def get_panel_image(self, image, panel, orig_name=None):
# Need to crop around centre before rotating...
cx = size_x/2
cy = size_y/2
dx = panel.get('dx', DEFAULT_OFFSET)
dy = panel.get('dy', DEFAULT_OFFSET)
dx = panel['dx']
dy = panel['dy']

cx += dx
cy += dy
Expand Down