diff --git a/buba/create_font.py b/buba/create_font.py deleted file mode 100644 index 166efd4..0000000 --- a/buba/create_font.py +++ /dev/null @@ -1,99 +0,0 @@ -""" -Create an SVG "font" by using the base segments from geascript-proportional.svg and creating a SVG with 256 symbols in it. -""" -import os -from xml.dom import minidom, Node -from xml.dom.minidom import getDOMImplementation, Element - -fontspec = { - '41': [ - '.##### ###### ###### ######', - '###... ...### #..... ......', - '#.#### ###### ###### ######', - ], - '42': [ - '###### ###### ###### ######', - '###... ...### #..... ...###', - '#.#### #####. ###### #####.', - ], -} - - -class Design: - def __init__(self, filename): - self.dom = minidom.parse(filename) - (_, _, self.width, self.height) = [float(x) for x in - self.dom.documentElement.getAttribute("viewBox").split(' ')] - - r = {} - for n in self.dom.getElementsByTagName("g")[0].childNodes: - if n.nodeType == Node.ELEMENT_NODE: - self.remove_namespaced_attributes(n) - self.remove_style_attributes(n) - id = n.getAttribute("id") - r[id] = n - self.segments = r - - self.symbols = getDOMImplementation().createDocument(None, "svg", None) - self.svg = self.symbols.documentElement - self.svg.setAttribute("xmlns", "http://www.w3.org/2000/svg") - self.svg.setAttribute("style", "height: 0; width: 0; position: absolute;") - - def remove_namespaced_attributes(self, node:Element): - if node.nodeType != Node.ELEMENT_NODE: - return - for a in list(node._attrsNS.values()): - if a.prefix is not None: - node.removeAttributeNode(a) - for child in node.childNodes: - self.remove_namespaced_attributes(child) - - def remove_style_attributes(self, node:Element): - if node.nodeType != Node.ELEMENT_NODE: - return - if node.hasAttribute("style"): - node.removeAttribute("style") - for child in node.childNodes: - self.remove_namespaced_attributes(child) - - def make_symbol(self, codepoint): - """ - Use the spec to copy all segments into a new symbol. - :param codepoint: - :return: - """ - spec = fontspec[f"{codepoint:02x}"] - symbol = self.symbols.createElement("symbol") - self.svg.appendChild(symbol) - symbol.setAttribute("id", f"x{codepoint:02x}") - symbol.setAttribute("viewBox", f"0 0 {self.width * len(spec):.3f} {self.height}") - for strip_index, strip in enumerate(spec): - i = 1 - g = self.symbols.createElement("g") - symbol.appendChild(g) - g.setAttribute("id", f"x{codepoint:02x}-{strip_index}") - g.setAttribute("transform", f"translate({self.width * strip_index:.3f} 0)") - for segment in list(strip): - if segment == '#': - clone = self.segments[f"seg{i:02d}"].cloneNode(True) - clone.removeAttribute("id") - g.appendChild(clone) - # clone - pass - elif segment == '.': - # no not clone this one - pass - else: - continue - i += 1 - - -if __name__ == '__main__': - here = os.path.abspath(os.path.dirname(__file__)) - design = Design(os.path.join(here, 'design/geascript-proportional.svg')) - - design.make_symbol(0x41) - design.make_symbol(0x42) - - with open("static/font.svg", "w") as symbolsfile: - design.symbols.writexml(symbolsfile, addindent=' ', newl='\n') diff --git a/buba/static/font.svg b/buba/static/font.svg deleted file mode 100644 index 45a6cf7..0000000 --- a/buba/static/font.svg +++ /dev/null @@ -1,127 +0,0 @@ - - diff --git a/buba/static/fonttest.html b/buba/static/fonttest.html deleted file mode 100644 index c699fbd..0000000 --- a/buba/static/fonttest.html +++ /dev/null @@ -1,21 +0,0 @@ - - -
-- - - -
- - \ No newline at end of file