Using gpp preprocessor to create more easily svg code
<[email protected]> 04 Feb 2014 02:14:55 -0800
| Newsgroups | gmane.text.xml.svg.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello, i'am a french programmer since years, and i use often macro processors to give some facility to coding.
SVG is not a functional langage, as JavaScript.
I think SVG is very powerful, and can be used alone, in some cases, without JS or external libraries.
So, i found GPP, a simple but powerful macro preprocessor, and write a 60 lines macros definitions to write easy SVG in texte files. GPP support #include and #define statements, so many usual svg definitions can be written in macros.
I give you some samples below :
The two following lines tell to use the macro user file (svg.inc), and create the xml and svg header, with x,y,width, height, and default viewport
#include "svg.inc"
SVG__("svg31",0,0,400,400)
Below is the SVG generated code (with GPP) :
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/D TD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="svg31" x="0" y="0" width="400" height="400" viewbox="0 0 400 400" xml:space="preserve">
The following lines create a <def> zone with some css statements :
DEF__
<!-- Css Defs -->
CSS__
_STY(_st1,_FSS(blue,1,red,2))
_STY(_st2,_FSS(red,0.5,green,4))
_STY(_st3,_FSS(none,1,black,1))
_STY(_st4,_FSS(green,1,yellow,1) _TSS("Comic sans Ms",1cm))
__CSS
__DEF
The _FSS macro define fill and stroke parameters
The _TSS macro define font-family and font-size parameters
The following lines define some graphic elements :
_RCT("rec1",10,10,70,50,_st1,)
_CIR("cir1",120,120,30,_st2,)
_PTH("tri1","M120 20 L200 20 L150 50 L120 20",_st3,)
_TXT("txt1",10,100,_st4,Egc,)
_RCT is a <rect>, _CIR a circle, _PTH a path, _TXT a text
Each element have a style, and can integrate some animate tags as last argument.
I write the code as : source.txt
I use the console command : gpp source.txt -o result.svg
And i load result.svg in internet browser to see the svg file
Errors are very easy to see and correct.
I write some others macros to simplify gradients, filters, and animation tags.
Please, feedback if interested about this subject.
Thank you very much
Greetings to all svg'rs !
Yves