SVG handling now completely in JS
All checks were successful
docker-image / docker (push) Successful in 9m42s
All checks were successful
docker-image / docker (push) Successful in 9m42s
This commit is contained in:
parent
c3316e3086
commit
990f98f1e3
3 changed files with 0 additions and 247 deletions
|
@ -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')
|
|
@ -1,127 +0,0 @@
|
|||
<?xml version="1.0" ?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" style="height: 0; width: 0; position: absolute;">
|
||||
<symbol id="x41" viewBox="0 0 5.100 15.699999">
|
||||
<g id="x41-0" transform="translate(0.000 0)">
|
||||
<path d="M 1.6757133,1.4711956 V 0.0197877 H 0.85412223 Z"/>
|
||||
<path d="m 1.6820624,1.9503833 -1.66855387,0.00131 0.0063,-0.4804985 0.8223243,-1.451396 0.83358937,1.451398 z"/>
|
||||
<path d="M 0.01350853,1.9516941 1.6820626,1.9503873 1.6886758,2.436732 0.87500133,3.9227533 0.01979853,2.436732 Z"/>
|
||||
<path d="m 0.01979993,3.9227491 v -1.486021 l 0.8552028,1.486021 z"/>
|
||||
<path d="M 0.87500273,3.9227491 1.688677,2.4367281 v 1.486021 z"/>
|
||||
<path d="M 0.87500273,3.9227491 H 0.01979993 V 5.0929905 Z"/>
|
||||
<path d="M 1.688677,5.0867989 V 3.9227491 H 0.87500273 Z"/>
|
||||
<path d="m 1.6886766,5.5798543 4e-7,-0.4930554 -0.81367427,-1.1640498 -0.8552028,1.1702414 -2e-7,0.4868638 z"/>
|
||||
<path d="M 1.6886766,5.5798547 0.86881113,6.7461891 0.01979973,5.5798547 Z"/>
|
||||
<path d="m 0.01979973,5.5798543 0.8490114,1.1663348 -0.8490114,1.1663345 z"/>
|
||||
<path d="M 1.6886766,5.5798543 V 7.9125236 L 0.86881113,6.7461891 Z"/>
|
||||
<path d="M 1.6886766,7.9125236 0.86881113,6.7461891 0.01979973,7.9125236 Z"/>
|
||||
<rect width="1.6688768" height="1.0757513" x="0.019799877" y="7.9125233"/>
|
||||
<path d="M 0.01979973,8.9882748 1.6883538,8.9876458 0.85617373,9.9475398 Z"/>
|
||||
<path d="m 0.01979973,8.9882748 0.836374,0.959268 -0.8363738,0.9866772 z"/>
|
||||
<path d="M 1.688354,8.9876498 0.85592763,9.9472508 1.688354,10.935528 Z"/>
|
||||
<path d="M 0.85617373,9.9475428 1.6883538,10.935527 0.01979993,10.934227 Z"/>
|
||||
<path d="m 1.6883538,10.935528 -1.66855387,-0.0013 0.00629,0.480497 0.8223243,1.451396 0.83358937,-1.451397 z"/>
|
||||
<path d="m 0.02609143,11.414717 v 1.451396 h 0.8223243 z"/>
|
||||
<path d="m 1.6820047,11.414717 v 1.451408 H 0.86041373 Z"/>
|
||||
<rect width="1.6688769" height="1.0673051" x="0.019799877" y="12.866271"/>
|
||||
<path d="M 1.688677,14.473684 V 13.933575 H 0.01979993 v 1.728568 h 0.8344386 z"/>
|
||||
<path d="m 1.688677,14.473684 v 1.188457 H 0.85423853 Z"/>
|
||||
</g>
|
||||
<g id="x41-1" transform="translate(1.700 0)">
|
||||
<path d="M 0.01979999,1.4711941 V 0.0198 h 0.82232429 z"/>
|
||||
<path d="M 1.6757133,1.4711956 V 0.0197877 H 0.85412223 Z"/>
|
||||
<path d="m 1.6820624,1.9503833 -1.66855387,0.00131 0.0063,-0.4804985 0.8223243,-1.451396 0.83358937,1.451398 z"/>
|
||||
<path d="M 1.6886766,5.5798547 0.86881113,6.7461891 0.01979973,5.5798547 Z"/>
|
||||
<path d="m 0.01979973,5.5798543 0.8490114,1.1663348 -0.8490114,1.1663345 z"/>
|
||||
<path d="M 1.6886766,5.5798543 V 7.9125236 L 0.86881113,6.7461891 Z"/>
|
||||
<path d="M 1.6886766,7.9125236 0.86881113,6.7461891 0.01979973,7.9125236 Z"/>
|
||||
</g>
|
||||
<g id="x41-2" transform="translate(3.400 0)">
|
||||
<path d="M 0.01979999,1.4711941 V 0.0198 h 0.82232429 z"/>
|
||||
<path d="m 1.6820624,1.9503833 -1.66855387,0.00131 0.0063,-0.4804985 0.8223243,-1.451396 0.83358937,1.451398 z"/>
|
||||
<path d="M 0.01350853,1.9516941 1.6820626,1.9503873 1.6886758,2.436732 0.87500133,3.9227533 0.01979853,2.436732 Z"/>
|
||||
<path d="m 0.01979993,3.9227491 v -1.486021 l 0.8552028,1.486021 z"/>
|
||||
<path d="M 0.87500273,3.9227491 1.688677,2.4367281 v 1.486021 z"/>
|
||||
<path d="M 0.87500273,3.9227491 H 0.01979993 V 5.0929905 Z"/>
|
||||
<path d="M 1.688677,5.0867989 V 3.9227491 H 0.87500273 Z"/>
|
||||
<path d="m 1.6886766,5.5798543 4e-7,-0.4930554 -0.81367427,-1.1640498 -0.8552028,1.1702414 -2e-7,0.4868638 z"/>
|
||||
<path d="M 1.6886766,5.5798547 0.86881113,6.7461891 0.01979973,5.5798547 Z"/>
|
||||
<path d="m 0.01979973,5.5798543 0.8490114,1.1663348 -0.8490114,1.1663345 z"/>
|
||||
<path d="M 1.6886766,5.5798543 V 7.9125236 L 0.86881113,6.7461891 Z"/>
|
||||
<path d="M 1.6886766,7.9125236 0.86881113,6.7461891 0.01979973,7.9125236 Z"/>
|
||||
<rect width="1.6688768" height="1.0757513" x="0.019799877" y="7.9125233"/>
|
||||
<path d="M 0.01979973,8.9882748 1.6883538,8.9876458 0.85617373,9.9475398 Z"/>
|
||||
<path d="m 0.01979973,8.9882748 0.836374,0.959268 -0.8363738,0.9866772 z"/>
|
||||
<path d="M 1.688354,8.9876498 0.85592763,9.9472508 1.688354,10.935528 Z"/>
|
||||
<path d="M 0.85617373,9.9475428 1.6883538,10.935527 0.01979993,10.934227 Z"/>
|
||||
<path d="m 1.6883538,10.935528 -1.66855387,-0.0013 0.00629,0.480497 0.8223243,1.451396 0.83358937,-1.451397 z"/>
|
||||
<path d="m 0.02609143,11.414717 v 1.451396 h 0.8223243 z"/>
|
||||
<path d="m 1.6820047,11.414717 v 1.451408 H 0.86041373 Z"/>
|
||||
<rect width="1.6688769" height="1.0673051" x="0.019799877" y="12.866271"/>
|
||||
<path d="M 1.688677,14.473684 V 13.933575 H 0.01979993 v 1.728568 h 0.8344386 z"/>
|
||||
<path d="m 1.688677,14.473684 v 1.188457 H 0.85423853 Z"/>
|
||||
</g>
|
||||
</symbol>
|
||||
<symbol id="x42" viewBox="0 0 5.100 15.699999">
|
||||
<g id="x42-0" transform="translate(0.000 0)">
|
||||
<path d="M 0.01979999,1.4711941 V 0.0198 h 0.82232429 z"/>
|
||||
<path d="M 1.6757133,1.4711956 V 0.0197877 H 0.85412223 Z"/>
|
||||
<path d="m 1.6820624,1.9503833 -1.66855387,0.00131 0.0063,-0.4804985 0.8223243,-1.451396 0.83358937,1.451398 z"/>
|
||||
<path d="M 0.01350853,1.9516941 1.6820626,1.9503873 1.6886758,2.436732 0.87500133,3.9227533 0.01979853,2.436732 Z"/>
|
||||
<path d="m 0.01979993,3.9227491 v -1.486021 l 0.8552028,1.486021 z"/>
|
||||
<path d="M 0.87500273,3.9227491 1.688677,2.4367281 v 1.486021 z"/>
|
||||
<path d="M 0.87500273,3.9227491 H 0.01979993 V 5.0929905 Z"/>
|
||||
<path d="M 1.688677,5.0867989 V 3.9227491 H 0.87500273 Z"/>
|
||||
<path d="m 1.6886766,5.5798543 4e-7,-0.4930554 -0.81367427,-1.1640498 -0.8552028,1.1702414 -2e-7,0.4868638 z"/>
|
||||
<path d="M 1.6886766,5.5798547 0.86881113,6.7461891 0.01979973,5.5798547 Z"/>
|
||||
<path d="m 0.01979973,5.5798543 0.8490114,1.1663348 -0.8490114,1.1663345 z"/>
|
||||
<path d="M 1.6886766,5.5798543 V 7.9125236 L 0.86881113,6.7461891 Z"/>
|
||||
<path d="M 1.6886766,7.9125236 0.86881113,6.7461891 0.01979973,7.9125236 Z"/>
|
||||
<rect width="1.6688768" height="1.0757513" x="0.019799877" y="7.9125233"/>
|
||||
<path d="M 0.01979973,8.9882748 1.6883538,8.9876458 0.85617373,9.9475398 Z"/>
|
||||
<path d="m 0.01979973,8.9882748 0.836374,0.959268 -0.8363738,0.9866772 z"/>
|
||||
<path d="M 1.688354,8.9876498 0.85592763,9.9472508 1.688354,10.935528 Z"/>
|
||||
<path d="M 0.85617373,9.9475428 1.6883538,10.935527 0.01979993,10.934227 Z"/>
|
||||
<path d="m 1.6883538,10.935528 -1.66855387,-0.0013 0.00629,0.480497 0.8223243,1.451396 0.83358937,-1.451397 z"/>
|
||||
<path d="m 0.02609143,11.414717 v 1.451396 h 0.8223243 z"/>
|
||||
<path d="m 1.6820047,11.414717 v 1.451408 H 0.86041373 Z"/>
|
||||
<rect width="1.6688769" height="1.0673051" x="0.019799877" y="12.866271"/>
|
||||
<path d="M 1.688677,14.473684 V 13.933575 H 0.01979993 v 1.728568 h 0.8344386 z"/>
|
||||
<path d="m 1.688677,14.473684 v 1.188457 H 0.85423853 Z"/>
|
||||
</g>
|
||||
<g id="x42-1" transform="translate(1.700 0)">
|
||||
<path d="M 0.01979999,1.4711941 V 0.0198 h 0.82232429 z"/>
|
||||
<path d="M 1.6757133,1.4711956 V 0.0197877 H 0.85412223 Z"/>
|
||||
<path d="m 1.6820624,1.9503833 -1.66855387,0.00131 0.0063,-0.4804985 0.8223243,-1.451396 0.83358937,1.451398 z"/>
|
||||
<path d="M 1.6886766,5.5798547 0.86881113,6.7461891 0.01979973,5.5798547 Z"/>
|
||||
<path d="m 0.01979973,5.5798543 0.8490114,1.1663348 -0.8490114,1.1663345 z"/>
|
||||
<path d="M 1.6886766,5.5798543 V 7.9125236 L 0.86881113,6.7461891 Z"/>
|
||||
<path d="M 1.6886766,7.9125236 0.86881113,6.7461891 0.01979973,7.9125236 Z"/>
|
||||
<rect width="1.6688769" height="1.0673051" x="0.019799877" y="12.866271"/>
|
||||
<path d="M 1.688677,14.473684 V 13.933575 H 0.01979993 v 1.728568 h 0.8344386 z"/>
|
||||
<path d="m 1.688677,14.473684 v 1.188457 H 0.85423853 Z"/>
|
||||
</g>
|
||||
<g id="x42-2" transform="translate(3.400 0)">
|
||||
<path d="M 0.01979999,1.4711941 V 0.0198 h 0.82232429 z"/>
|
||||
<path d="m 1.6820624,1.9503833 -1.66855387,0.00131 0.0063,-0.4804985 0.8223243,-1.451396 0.83358937,1.451398 z"/>
|
||||
<path d="M 0.01350853,1.9516941 1.6820626,1.9503873 1.6886758,2.436732 0.87500133,3.9227533 0.01979853,2.436732 Z"/>
|
||||
<path d="m 0.01979993,3.9227491 v -1.486021 l 0.8552028,1.486021 z"/>
|
||||
<path d="M 0.87500273,3.9227491 1.688677,2.4367281 v 1.486021 z"/>
|
||||
<path d="M 0.87500273,3.9227491 H 0.01979993 V 5.0929905 Z"/>
|
||||
<path d="M 1.688677,5.0867989 V 3.9227491 H 0.87500273 Z"/>
|
||||
<path d="m 1.6886766,5.5798543 4e-7,-0.4930554 -0.81367427,-1.1640498 -0.8552028,1.1702414 -2e-7,0.4868638 z"/>
|
||||
<path d="M 1.6886766,5.5798547 0.86881113,6.7461891 0.01979973,5.5798547 Z"/>
|
||||
<path d="m 0.01979973,5.5798543 0.8490114,1.1663348 -0.8490114,1.1663345 z"/>
|
||||
<path d="M 1.6886766,7.9125236 0.86881113,6.7461891 0.01979973,7.9125236 Z"/>
|
||||
<rect width="1.6688768" height="1.0757513" x="0.019799877" y="7.9125233"/>
|
||||
<path d="M 0.01979973,8.9882748 1.6883538,8.9876458 0.85617373,9.9475398 Z"/>
|
||||
<path d="m 0.01979973,8.9882748 0.836374,0.959268 -0.8363738,0.9866772 z"/>
|
||||
<path d="M 1.688354,8.9876498 0.85592763,9.9472508 1.688354,10.935528 Z"/>
|
||||
<path d="M 0.85617373,9.9475428 1.6883538,10.935527 0.01979993,10.934227 Z"/>
|
||||
<path d="m 1.6883538,10.935528 -1.66855387,-0.0013 0.00629,0.480497 0.8223243,1.451396 0.83358937,-1.451397 z"/>
|
||||
<path d="m 0.02609143,11.414717 v 1.451396 h 0.8223243 z"/>
|
||||
<path d="m 1.6820047,11.414717 v 1.451408 H 0.86041373 Z"/>
|
||||
<rect width="1.6688769" height="1.0673051" x="0.019799877" y="12.866271"/>
|
||||
<path d="M 1.688677,14.473684 V 13.933575 H 0.01979993 v 1.728568 h 0.8344386 z"/>
|
||||
</g>
|
||||
</symbol>
|
||||
</svg>
|
Before Width: | Height: | Size: 9.4 KiB |
|
@ -1,21 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Font Test</title>
|
||||
<link rel=stylesheet type="text/css" href="main.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Font Test</h1>
|
||||
<p>
|
||||
<svg class="char">
|
||||
<use href="font.svg#x41"/>
|
||||
</svg>
|
||||
<svg class="char">
|
||||
<use href="font.svg#x42"/>
|
||||
</svg>
|
||||
<svg class="char">
|
||||
<use href="font.svg#x41"/>
|
||||
</svg>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue