Skip to content

Commit

Permalink
alondu skripto, kiu faras pdf kun kartarpagxoj
Browse files Browse the repository at this point in the history
  • Loading branch information
paulwuertz committed Aug 3, 2019
1 parent b90e2a0 commit 3c09342
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## Hellapagos

Traduko de [Hellapagos](http://www.hellapagos.com/)

## Generado

Uzu `python generate.py`. Vi bezonas krome:

* inkscape
* imagemagic, aka `convert`
* mi havis [jena](https://stackoverflow.com/questions/52998331/imagemagick-security-policy-pdf-blocking-conversion) problemo, kun permesojn, sed facile adapteblas
18 changes: 18 additions & 0 deletions generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import jinja2, yaml
import subprocess, textwrap

kartoj = yaml.safe_load(open("kartoj.yaml").read()) # listo de kartoj
for k in kartoj: #trancxu tekston al sammlongaj lineoj
k["titolo"] = textwrap.wrap(k["titolo"], 13)
k["teksto"] = textwrap.wrap(k["teksto"], 23)
kartoj = [k for k in kartoj for i in range(k["kvanto"])] # adpatas la liston por kvanto de karto
pagxoj = [kartoj[i:i+9] for i in range(0, len(kartoj), 9)] #disigas la kartaro en pagxojn po de 9 kartoj

for i, pagxo in enumerate(pagxoj):
template_str = open("templates/sxablono.svg.jinja2").read()
t = jinja2.Template(template_str)
kartoj_offsets = zip(pagxo, [(0,0), (61,0), (122,0), (0,91), (61,91), (122,91), (0,182), (61,182), (122,182)])
r = t.render(kartoj_offsets=kartoj_offsets)
open('svg/{}.svg'.format(i), "w").write(r)
subprocess.check_output(['inkscape','-z', 'svg/{}.svg'.format(i), '-e', 'svg/{}.png'.format(i)])
subprocess.check_output(['convert', 'svg/*.png', 'ludo.pdf'])
32 changes: 32 additions & 0 deletions templates/sxablono.svg.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
{% macro karto(name, value='', type='text', size=20) %}
<input type="{{ type }}" name="{{ name }}" value="{{ value|e }}" size="{{ size }}">
{% endmacro %}

<svg width="210mm" height="297mm" viewBox="0 0 210 297" version="1.1" id="svg8">
<g transform="translate(14, 12.5)" id="layer1">
{% for k, offset in kartoj_offsets %}
{% set oloop=loop %}
<g id="k{{loop.index}}" transform="translate({{ offset[0] }}, {{ offset[1] }})">
<rect y="0" x="0" height="90" width="60" id="k{{loop.index}}-fono"
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
<text id="k{{loop.index}}-titolo" y="5" x="10"
style="font-style:normal;font-weight:normal;font-size:6.5px;line-height:1;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.25">
{% for titolo_lineo in k["titolo"] %}
<tspan y="{{10 + loop.index0*6}}" x="10" id="k{{oloop.index}}-titolo" style="fill:#ffffff;stroke-width:0.25">
{{ titolo_lineo }}
</tspan>
{% endfor %}
</text>
<text id="k{{loop.index}}-teksto" y="40" x="0"
style="font-style:normal;font-weight:normal;font-size:6.5px;line-height:1;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.25">
{% for tekstlineo in k["teksto"] %}
<tspan y="{{60 + loop.index0*4}}" x="5" id="k{{oloop.index}}-par-{{loop.index}}" style="font-size:4px;line-height:0;fill:#ffffff;stroke-width:0.25">
{{ tekstlineo }}
</tspan>
{% endfor %}
</text>
</g>
{% endfor %}
</g>
</svg>

0 comments on commit 3c09342

Please sign in to comment.