From 3b7c6a085a7e8d2b91ce063349ed9829eee72385 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 27 Apr 2022 15:54:04 +0200 Subject: add mappdf script --- maps/map1.pdf | Bin 0 -> 78962 bytes maps/map1.svg | 1558 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ maps/mappdf.py | 56 ++ maps/readme.md | 17 +- maps/tiles/0.svg | 3 + maps/tiles/1.svg | 11 + maps/tiles/2.svg | 11 + maps/tiles/3.svg | 11 + maps/tiles/4.svg | 11 + maps/tiles/5.svg | 11 + maps/tiles/6.svg | 11 + maps/tiles/7.svg | 11 + maps/tiles/8.svg | 11 + maps/tiles/9.svg | 11 + maps/tiles/a.svg | 11 + maps/tiles/b.svg | 11 + maps/tiles/c.svg | 11 + maps/tiles/d.svg | 11 + maps/tiles/e.svg | 11 + maps/tiles/f.svg | 11 + 20 files changed, 1797 insertions(+), 2 deletions(-) create mode 100644 maps/map1.pdf create mode 100644 maps/map1.svg create mode 100755 maps/mappdf.py create mode 100644 maps/tiles/0.svg create mode 100644 maps/tiles/1.svg create mode 100644 maps/tiles/2.svg create mode 100644 maps/tiles/3.svg create mode 100644 maps/tiles/4.svg create mode 100644 maps/tiles/5.svg create mode 100644 maps/tiles/6.svg create mode 100644 maps/tiles/7.svg create mode 100644 maps/tiles/8.svg create mode 100644 maps/tiles/9.svg create mode 100644 maps/tiles/a.svg create mode 100644 maps/tiles/b.svg create mode 100644 maps/tiles/c.svg create mode 100644 maps/tiles/d.svg create mode 100644 maps/tiles/e.svg create mode 100644 maps/tiles/f.svg diff --git a/maps/map1.pdf b/maps/map1.pdf new file mode 100644 index 0000000..a87deef Binary files /dev/null and b/maps/map1.pdf differ diff --git a/maps/map1.svg b/maps/map1.svg new file mode 100644 index 0000000..4b6e46b --- /dev/null +++ b/maps/map1.svg @@ -0,0 +1,1558 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maps/mappdf.py b/maps/mappdf.py new file mode 100755 index 0000000..4f4a45d --- /dev/null +++ b/maps/mappdf.py @@ -0,0 +1,56 @@ +import sys +from struct import unpack +import svgutils.transform as sg +import svgutils.compose as sc + +SVG_TILE_SIZE = 24 +DPI = 96 +INCH = 2.54 +ROBOT_SIZE = 9.5 +ROBOT_SIZE_UNIT = "cm" + +RESIZE_FACTOR = ROBOT_SIZE / (SVG_TILE_SIZE / DPI * INCH) + +def read_tiles(): + tiles = [] + for x in range(16): + tile = open(f"./tiles/{x:x}.svg", "r") + tiles.append(tile.read()) + tile.close() + return tiles + +def mappdf(filename): + file = open(filename, 'rb') + contents = file.read() + file.close() + tiles = read_tiles() + + width, height = unpack('>HH', contents[0:4]) + + target = sg.SVGFigure() + target.set_size((f"{width * SVG_TILE_SIZE}px", f"{height * SVG_TILE_SIZE}px")) + + for y in range(height): + for x in range(width): + nibble = x + y * width + byte = int(nibble / 2) + shift = byte * 2 - nibble + 1 + num = (contents[4 + byte] & (0xf << 4 * shift)) >> 4 * shift + + tile = sg.fromstring(tiles[num]).getroot() + tile.moveto(x * SVG_TILE_SIZE, y * SVG_TILE_SIZE) + target.append(tile) + + target.save(f"{filename}.svg") + target_scaled = sc.SVG(f"{filename}.svg") + target_scaled.scale(RESIZE_FACTOR) + target = sc.Figure(width * SVG_TILE_SIZE * RESIZE_FACTOR, height * SVG_TILE_SIZE * RESIZE_FACTOR, target_scaled) + target.save(f"{filename}.svg") + print(f"inkscape --export-pdf={filename}.pdf {filename}.svg") + + +if __name__ == "__main__": + if len(sys.argv) > 1: + mappdf(sys.argv[1]) + else: + exit(1) diff --git a/maps/readme.md b/maps/readme.md index 85f94b0..2629b4a 100644 --- a/maps/readme.md +++ b/maps/readme.md @@ -27,6 +27,19 @@ notation for the map. google drive ocr works well enough to read out the red characters if you turn off path visibility in the figma document. figma also allows pdf export so you can print the maps, but the tiles are 24x24 pixels, not robot-sized (one tile is supposed to have about the same width and height -as the robot's diameter). but maybe i'll make another script that stitches -together the map tiles as svg, and then converts the whole thing to pdf. +as the robot's diameter). + +## exporting maps as pdf or svg + +```sh +# generate svg file +python3 mappdf.py [file] + +# render svg as pdf +inkscape --export-pdf=map.pdf [file].svg + +# (optional) convert to tiles for printing at home +# loop up map size using pdfinfo on map.pdf file +pdfposter map.pdf tiles.pdf -m a4 -p [map size] +``` diff --git a/maps/tiles/0.svg b/maps/tiles/0.svg new file mode 100644 index 0000000..fcdfaaa --- /dev/null +++ b/maps/tiles/0.svg @@ -0,0 +1,3 @@ + + + diff --git a/maps/tiles/1.svg b/maps/tiles/1.svg new file mode 100644 index 0000000..171df35 --- /dev/null +++ b/maps/tiles/1.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/maps/tiles/2.svg b/maps/tiles/2.svg new file mode 100644 index 0000000..e3eb06b --- /dev/null +++ b/maps/tiles/2.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/maps/tiles/3.svg b/maps/tiles/3.svg new file mode 100644 index 0000000..1e0dbad --- /dev/null +++ b/maps/tiles/3.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/maps/tiles/4.svg b/maps/tiles/4.svg new file mode 100644 index 0000000..a85e022 --- /dev/null +++ b/maps/tiles/4.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/maps/tiles/5.svg b/maps/tiles/5.svg new file mode 100644 index 0000000..fdbcd25 --- /dev/null +++ b/maps/tiles/5.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/maps/tiles/6.svg b/maps/tiles/6.svg new file mode 100644 index 0000000..181d7e2 --- /dev/null +++ b/maps/tiles/6.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/maps/tiles/7.svg b/maps/tiles/7.svg new file mode 100644 index 0000000..ca8166b --- /dev/null +++ b/maps/tiles/7.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/maps/tiles/8.svg b/maps/tiles/8.svg new file mode 100644 index 0000000..9da7e0d --- /dev/null +++ b/maps/tiles/8.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/maps/tiles/9.svg b/maps/tiles/9.svg new file mode 100644 index 0000000..d499439 --- /dev/null +++ b/maps/tiles/9.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/maps/tiles/a.svg b/maps/tiles/a.svg new file mode 100644 index 0000000..e787a43 --- /dev/null +++ b/maps/tiles/a.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/maps/tiles/b.svg b/maps/tiles/b.svg new file mode 100644 index 0000000..9cd38e6 --- /dev/null +++ b/maps/tiles/b.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/maps/tiles/c.svg b/maps/tiles/c.svg new file mode 100644 index 0000000..2f5d16b --- /dev/null +++ b/maps/tiles/c.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/maps/tiles/d.svg b/maps/tiles/d.svg new file mode 100644 index 0000000..1ad64ea --- /dev/null +++ b/maps/tiles/d.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/maps/tiles/e.svg b/maps/tiles/e.svg new file mode 100644 index 0000000..9c9759a --- /dev/null +++ b/maps/tiles/e.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/maps/tiles/f.svg b/maps/tiles/f.svg new file mode 100644 index 0000000..a13b768 --- /dev/null +++ b/maps/tiles/f.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + -- cgit v1.2.3