asc2svg

asc2svg was intended to be an ASCII diagrams to SVG, like `ditaa` and Svgbob
Log | Files | Refs

commit a40b457e2fa3637ce60a37e91c438cdf13301bfb
parent 3053fb05850ba451985b2563b54f2f22abbdb29e
Author: bkopf <vetlehaf@stud.ntnu.no>
Date:   Sat, 17 Nov 2018 13:40:50 +0100

Add str method to Figure ++

Diffstat:
Ma2svg.py | 21++++++++++++++-------
Mascii.txt | 8++++----
2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/a2svg.py b/a2svg.py @@ -54,6 +54,14 @@ class Figure: #new_element.process() self._processed[y][x] = True + def __str__(self): + figure_string = "" + for row in self._figarray: + for cell in row: + figure_string += cell + figure_string += '\n' + return figure_string + """ Checks if a joint belongs to a rectangle. @@ -111,7 +119,6 @@ class Figure: """Return SVG text of the entire figure""" - # <rect x="80" y="3" width="80" height="12" fill="white" stroke="black"></rect> def draw_svg(self): svg_text = "" for el in self._elements: @@ -165,7 +172,10 @@ class Rectangle: return svg_text +class Text: + pass +# Not sure if Joint is useful in this code class Joint: def __init__(self, position): # (pos should be a tuple) @@ -188,6 +198,8 @@ class Joint: def get_connected(self): return self._connected +# The best alternative here is to use a *polyline* +# https://www.w3schools.com/graphics/svg_polyline.asp class Line: def __init__(self, start_pos, vertical=False): self._start = start_pos @@ -203,18 +215,13 @@ class Line: class Arrow(): pass -def print_farray(figure_array): - for row in figure_array: - for cell in row: - print(cell, end="") - print() - with open("ascii.txt") as f: ascii_text = f.readlines() f.close() drawing = Figure(ascii_text) +print(drawing) drawing.process() for el in drawing.get_elements(): el.extract_text(drawing) diff --git a/ascii.txt b/ascii.txt @@ -7,14 +7,14 @@ +----------------+ | | | - +---------------------+ + +-----------+---------+ +----->| unexpected | | +---------------------+ | -+----------------+ +----------------------+ ++-------+--------+ +----------------------+ | Block 1 | | Additional block | -+----------------+ +----------+-----------+ - | | ++-------+--------+ +----------+-----------+ + | v | +----------------------+ +--------->| Second block | +----------------------+