Commit fdb4e856 by Einar Andersen

Merge branch 'master' of gitlab.constantvzw.org:osp/work.colorlab

parents c49496bc 47961cbf
......@@ -6,6 +6,8 @@ import json
from chiplotle import *
from chiplotle.hpgl import commands
DRAW_GRID = False
##################
## VIRTUAL ##
#################
......@@ -53,6 +55,7 @@ def header(input_text):
return header_text
<<<<<<< HEAD
def body(input_text, text_box, char_width, char_height, line_height):
text = input_text
fixed_text = ""
......@@ -69,38 +72,61 @@ def body(input_text, text_box, char_width, char_height, line_height):
width_counter = 0
width_counter += len(word) * (char_width + char_width * 0.25)
body_text = shapes.label(fixed_text, units_to_cm(char_width), units_to_cm(char_height), -0.1, line_spacing)
=======
def line_length(txt, char_width):
return len(txt) * char_width * 1.3
def make_label (text, char_width, char_height, offset):
line = shapes.label(text, units_to_cm(char_width), units_to_cm(char_height), -.1, 1)
transforms.offset(line, (0, -offset))
return line
def make_labels (lines, char_width, char_height, line_height):
return Group([make_label(line, char_width, char_height, i * line_height) for i, line in enumerate(lines)])
def makeLines (text, width, char_width, prefix = ""):
lines = []
buff = prefix
separator = " "
for word in text.split(" "):
word += separator
if line_length(buff + word, char_width) < width:
buff += word
else:
lines.append(buff)
buff = prefix + word
>>>>>>> 47961cbfff9e384c33d95896eb828c9c56aa392b
if buff:
lines.append(buff)
return body_text
return lines
def body(input_text, width, char_width, char_height, line_height):
return make_labels(makeLines(input_text, width, char_width), char_width, char_height, line_height)
def list_body(input_text, text_box, char_width, char_height, line_height):
lines = []
text = input_text
indent = " "
fixed_text = ""
line_spacing = ((line_height)/(char_height * 2.0))-1.0
for line in text.split('"newline"'):
width_counter = 0
line_spacing = (line_height - (2 * char_height))/float(2 * char_height)
for line in text.split('"newline"'):
sentence = line.split(": ")
identifier = sentence[0].upper()
content = indent + sentence[1]
if len(identifier + content) * (char_width + char_width * 0.25) > text_box:
fixed_content = ""
width_counter = len(identifier) * (char_width + char_width * 0.25)
for word in content.split(" "):
word = word + " "
if width_counter + len(word) * (char_width + char_width * 0.25) < text_box:
fixed_content += word
width_counter += len(word) * (char_width + char_width * 0.25)
else:
fixed_content += "\r\n" + indent + word
width_counter = 0
width_counter += len(word) * (char_width + char_width * 0.25)
content = fixed_content
fixed_text += identifier + ":"
fixed_text += content + "\r\n"
list_body_text = shapes.label(fixed_text, units_to_cm(char_width), units_to_cm(char_height), -0.1, line_spacing)
return list_body_text
if line_length(identifier + content, char_width) > text_box:
tmp = makeLines(identifier + content, text_box, char_width)
lines.append(tmp[0])
lines += makeLines("".join(tmp[1:]), text_box, char_width, indent)
else:
lines.append(identifier + ":" + content)
return make_labels(lines, char_width, char_height, line_height)
with open("formatted_content.json", "r") as read_file:
......@@ -109,18 +135,44 @@ with open("formatted_content.json", "r") as read_file:
plotter.set_origin_bottom_left()
width = plotter.margins.hard.width
height = plotter.margins.hard.height
left = plotter.margins.hard.left
right = plotter.margins.hard.right
top = plotter.margins.hard.top
bottom = plotter.margins.hard.bottom
print(width)
print(height)
x_unit = width/3.0/3.0/8.0
y_unit = height/2.0/3.0/8.0
x_unit = width / 72.0
y_unit = height / 48.0
print(x_unit)
print(y_unit)
def x (c):
return c * x_unit
def y (c):
return c * y_unit
if DRAW_GRID:
from chiplotle.geometry.shapes.line import line
g = Group()
## add horizontal lines
for i in range(48):
g.append(line((left, y(i)), (right, y(i))))
## add vertical lines
for i in range(72):
g.append(line((x(i), top), (x(i), bottom)))
plotter.select_pen(2)
plotter.write(g)
plotter.select_pen(1)
x_movement = 2 * (32*x_unit)
y_movement = 0
......@@ -162,10 +214,17 @@ pig_header = header(p_header)
transforms.offset(bio_header, ((base_x + 1) * x_unit, (base_y + 20) * y_unit))
transforms.offset(pig_header, ((base_x + 13) * x_unit, (base_y + 16) * y_unit))
<<<<<<< HEAD
bio_body = body(b_body, 13 * x_unit, pigment_char_width, pigment_char_height, pigment_line_height)
pig_body = body(p_body, 10 * x_unit, pigment_char_width, pigment_char_height, pigment_line_height)
transforms.offset(bio_body, ((base_x + 1) * x_unit, (base_y + 19) * y_unit))
transforms.offset(pig_body, ((base_x + 13) * x_unit, (base_y + 15) * y_unit))
=======
bio_body = body(b_body, 10*x_unit, 0.28 * x_unit, 0.3 * y_unit, 0.5 * y_unit)
pig_body = body(p_body, 10*x_unit, 0.28 * x_unit, 0.3 * y_unit, 0.5 * y_unit)
transforms.offset(bio_body, (3 * x_unit, 19*y_unit))
transforms.offset(pig_body, (14 * x_unit, 18*y_unit))
>>>>>>> 47961cbfff9e384c33d95896eb828c9c56aa392b
main_text = body(text, 10 * x_unit, main_char_width, main_char_height, main_char_line_height)
transforms.offset(main_text, ((base_x + 1) * x_unit, (base_y + 12) * y_unit))
......@@ -276,6 +335,7 @@ dunaliella_page.append(list_txt)
plotter.write(dunaliella_page)
##############
<<<<<<< HEAD
base_x = 0
base_y = 24
......@@ -298,6 +358,16 @@ bio_header = header(b_header)
pig_header = header(p_header)
transforms.offset(bio_header, ((base_x + 1) * x_unit, (base_y + 20) * y_unit))
transforms.offset(pig_header, ((base_x + 13) * x_unit, (base_y + 18) * y_unit))
=======
# bio_header = header(b_header)
# pig_header = header(p_header)
# transforms.offset(bline_hio_header, ((base_x + 3) * x_unit, (base_y + 20) * y_unit))
# transforms.offset(pline_hig_header, ((base_x + 14) * x_unit, (base_y + 20) * y_unit))
# bio_body = body(b_bline_hody, 10*x_unit, 0.3 * x_unit, 0.3 * y_unit)
# pig_body = body(p_bline_hody, 10*x_unit, 0.3 * x_unit, 0.3 * y_unit)
# transforms.offset(bline_hio_body, ((base_x + 3) * x_unit, (base_y + 19)*y_unit))
# transforms.offset(pig_body, ((base_x + 14) * x_unit, (base_y + 19)*y_unit))
>>>>>>> 47961cbfff9e384c33d95896eb828c9c56aa392b
bio_body = body(b_body, 10*x_unit, pigment_char_width, pigment_char_height, pigment_line_height)
pig_body = body(p_body, 10*x_unit, pigment_char_width, pigment_char_height, pigment_line_height)
......@@ -412,11 +482,13 @@ haematococcus_page.append(list_txt)
plotter.write(haematococcus_page)
<<<<<<< HEAD
###########
=======
>>>>>>> 47961cbfff9e384c33d95896eb828c9c56aa392b
plotter.select_pen(0)
io.view(plotter)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment