Skip to content

Commit

Permalink
Reuse static get_rgb() and other tiny fixes in export script
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Jun 20, 2017
1 parent f89a87b commit 4f60bd1
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions omero_figure/scripts/omero/figure_scripts/Figure_To_Pdf.py
Expand Up @@ -421,13 +421,6 @@ def get_panel_coords(self, shape_x, shape_y):

return {'x': shape_x, 'y': shape_y}

def get_rgb(self, color):
# Convert from E.g. '#ff0000' to (255, 0, 0)
red = int(color[1:3], 16)
green = int(color[3:5], 16)
blue = int(color[5:7], 16)
return (red, green, blue)

def draw_arrow(self, shape):

start = self.get_panel_coords(shape['x1'], shape['y1'])
Expand All @@ -438,7 +431,7 @@ def draw_arrow(self, shape):
y2 = end['y']
head_size = ((shape['strokeWidth'] * 5) + 9) * self.scale
stroke_width = shape['strokeWidth'] * self.scale
rgb = self.get_rgb(shape['strokeColor'])
rgb = ShapeToPdfExport.get_rgb(shape['strokeColor'])

# Do some trigonometry to get the line angle can calculate arrow points
dx = x2 - x1
Expand Down Expand Up @@ -478,7 +471,7 @@ def draw_line(self, shape):
x2 = end['x']
y2 = end['y']
stroke_width = shape['strokeWidth'] * self.scale
rgb = self.get_rgb(shape['strokeColor'])
rgb = ShapeToPdfExport.get_rgb(shape['strokeColor'])

self.draw.line([(x1, y1), (x2, y2)], fill=rgb, width=int(stroke_width))

Expand All @@ -494,7 +487,7 @@ def draw_rectangle(self, shape):
cx = centre['x']
cy = centre['y']
scale_w = w * self.scale
rgb = self.get_rgb(shape['strokeColor'])
rgb = ShapeToPdfExport.get_rgb(shape['strokeColor'])

# To support rotation, draw rect on temp canvas, rotate and paste
width = int((shape['width'] + w) * self.scale)
Expand Down Expand Up @@ -524,7 +517,7 @@ def draw_ellipse(self, shape):
rx = self.scale * shape['radiusX']
ry = self.scale * shape['radiusY']
rotation = (shape['rotation'] + self.panel['rotation']) * -1
rgb = self.get_rgb(shape['strokeColor'])
rgb = ShapeToPdfExport.get_rgb(shape['strokeColor'])

width = int((rx * 2) + w)
height = int((ry * 2) + w)
Expand Down Expand Up @@ -867,7 +860,7 @@ def draw_labels(self, panel, page):
pos = l['position']
l['size'] = int(l['size']) # make sure 'size' is number
# If page is black and label is black, make label white
page_color = self.figure_json.get('page_color').lower()
page_color = self.figure_json.get('page_color', 'ffffff').lower()
label_color = l['color'].lower()
label_on_page = pos in ('left', 'right', 'top',
'bottom', 'leftvert')
Expand Down Expand Up @@ -1532,7 +1525,6 @@ def create_figure(self):
"""
tiff_width = self.scale_coords(self.page_width)
tiff_height = self.scale_coords(self.page_height)
page_color = self.figure_json.get('page_color')
rgb = (255, 255, 255)
page_color = self.figure_json.get('page_color')
if page_color is not None:
Expand Down

0 comments on commit 4f60bd1

Please sign in to comment.