Ascii art to SVG


par .

L’objectif avoué de cet article est de fournir dans une première phase une ébauche d’un script permettant :

  • de traiter en entrée un fichier de type ascii
  • de fournir en sortie un fichier SVG

Dans une seconde partie ce devra être réécrit en langage C et s’intégrer au projet jp2a.

a2svg
#!/bin/bash
#var init
i=0
y=0
yoffset=15
in=${1}
out= »/tmp/filename »
header=’
<?xml version= »1.0″ encoding= »UTF-8″ standalone= »no »?>
<!– Created with a2svg –>
<svg
xmlns:dc= »http://purl.org/dc/elements/1.1/ »
xmlns:cc= »http://web.resource.org/cc/ »
xmlns:rdf= »http://www.w3.org/1999/02/22-rdf-syntax-ns# »
xmlns:svg= »http://www.w3.org/2000/svg »
xmlns= »http://www.w3.org/2000/svg »
xmlns:sodipodi= »http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd »
xmlns:inkscape= »http://www.inkscape.org/namespaces/inkscape »
width= »744.09448819″
height= »1052.3622047″
id= »svg2″
sodipodi:version= »0.32″
inkscape:version= »0.45.1″
sodipodi:docbase= »${out} »
sodipodi:docname= »b.svg »
inkscape:output_extension= »org.inkscape.output.svg.inkscape »>
<defs
id= »defs4″ />
<sodipodi:namedview
id= »base »
pagecolor= »#ffffff »
bordercolor= »#666666″
borderopacity= »1.0″
gridtolerance= »10000″
guidetolerance= »10″
objecttolerance= »10″
inkscape:pageopacity= »0.0″
inkscape:pageshadow= »2″
inkscape:zoom= »0.7″
inkscape:cx= »240.75603″
inkscape:cy= »698.47464″
inkscape:document-units= »px »
inkscape:current-layer= »layer1″
inkscape:window-width= »1280″
inkscape:window-height= »999″
inkscape:window-x= »1280″
inkscape:window-y= »0″ />
<metadata
id= »metadata7″>
<rdf:RDF>
<cc:Work
rdf:about= »">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource= »http://purl.org/dc/dcmitype/StillImage » />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label= »Layer 1″
inkscape:groupmode= »layer »
id= »layer1″>
<text
xml:space= »preserve »
style= »font-size:12px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Courier 10 Pitch »
x= »0″
y= »‘${yoffset}’ »
id= »text0″>’
footer=’</text></g></svg>’
echo ${header}
while read line
do
i=$((i+2))
y=$((y+${yoffset}))
echo « <tspan
sodipodi:role=\ »line\ »
id=\ »tspan${i}\ »
x=\ »0\ »
y=\ »${y}\ »>${line}</tspan> »
done < ${in}
echo ${footer}
Exemple:

./a2svg file.ascii > file.svg



Laisser un commentaire