summaryrefslogtreecommitdiff
path: root/forms
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2024-02-16 19:17:15 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2024-02-16 19:17:15 +0100
commita1bea40c6752f865d92351bce51b15f009902cfe (patch)
tree991fc7be805b8261e2f2905ecefb69a4a95faf5e /forms
parent0e7ea5ca80ad8cfd61a3591b2dea303df6c8238c (diff)
Start writing a colour chart index
Diffstat (limited to 'forms')
-rwxr-xr-xforms/colour_chart.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/forms/colour_chart.py b/forms/colour_chart.py
index efcd7d0..bbdf021 100755
--- a/forms/colour_chart.py
+++ b/forms/colour_chart.py
@@ -2,6 +2,7 @@
import argparse
import math
+import operator
import fpdf
import strictyaml
@@ -10,6 +11,7 @@ import strictyaml
class Chart:
COLUMNS=4
ROWS=16
+ INDEX_COLS=6
def __init__(self):
self.parser = self.get_parser()
@@ -42,6 +44,14 @@ class Chart:
]
return(cells)
+ def get_index(self):
+ index = [
+ (c["label"], i // self.ROWS)
+ for i, c in enumerate(self.data["colours"])
+ ]
+ index.sort(key=operator.itemgetter(0))
+ return index
+
def write_pdf(self, fname):
pdf = fpdf.FPDF(format="A5")
pdf.add_font(
@@ -78,6 +88,21 @@ class Chart:
pdf.cell(16, 8, cell["label"], )
pdf.ln(10)
+ pdf.set_font("FreeSerif", size=10)
+ with pdf.text_columns(
+ ncols=self.INDEX_COLS,
+ balance=True,
+ gutter=4,
+ text_align="RIGHT",
+ ) as cols:
+ for c in self.get_index():
+ pdf.set_font("FreeSerif", size=10)
+ cols.write(str(c[0]))
+ cols.write(" ")
+ pdf.set_font("FreeSans", "B", size=10)
+ cols.write(str(c[1]))
+ cols.ln()
+
pdf.output(fname)