Metody tworzenia plików SVG Programy do tworzenia grafiki SVG można z grubsza podzielić na 4 grupy: programy specjalizowane przeznaczone przede wszystkim do obróbki grafiki SVG: Inkscape Karbon14 Sodipodi Adobe Illustrator Corel Draw (>10) programy z możliwością eksportu do formatu SVG: OpenOffice Draw StarOffice Draw- od wersji 6.0 Mayura Draw Gnuplot Maxima CAS edytory tekstu ( najlepiej podświetlające składnię XML ) programy napisane w innych językach bezpośrednio tworzące plik svg C
Programy bezpośrednio tworzące pliki SVG C
/*
c console program based on : cpp code by Claudio Rocchini
http://commons.wikimedia.org/wiki/File:Poincare_halfplane_eptagonal_hb.svg
http://validator.w3.org/ The uploaded document "circle.svg" was successfully checked as SVG 1.1. This means that the resource in question identified itself as "SVG 1.1" and that we successfully performed a formal validation using an SGML, HTML5 and/or XML Parser(s) (depending on the markup language used).
*/
#include #include #include
const double PI = 3.1415926535897932384626433832795;
const int iXmax = 1000, iYmax = 1000, radius=100, cx=200, cy=200; const char *black="#FFFFFF", /* hexadecimal number as a string for svg color*/ *white="#000000";
FILE * fp;
void draw_circle(FILE * FileP,int radius,int cx,int cy) { fprintf(FileP,"\n", cx,cy,radius,white,black); }
void beginSVG(
int main(){ FILE * fp; char *filename="circle.svg"; fp = fopen(filename,"w"); char *comment = "";
fprintf(fp, "\n" "%s \n " "\n" "\n", comment,iXmax,iYmax);
draw_circle(fp,radius,cx,cy);
fprintf(fp,"\n"); fclose(fp); printf(" file %s saved \n",filename ); getchar(); return 0; }
Maxima CAS
BeginSVG(file_name,cm_width,cm_height,i_width,i_height):= block( destination : openw (file_name), printf(destination, "~%"), printf(destination, "~%"), printf(destination,"~%", cm_width,cm_height,i_width,i_height), return(destination) ); CircleSVG(dest,center_x,center_y,_radius):=printf(dest,"~%", center_x,center_y,_radius); CloseSVG(destination):= ( printf(destination,"~%"), close (destination) ); /* ---------------------------------------------------- */ cmWidth:10; cmHeight:10; iWidth:800; iHeight:600; radius:200; centerX:400; centerY:300; f_name:"b.svg"; /* ------------------------------------------------------*/ f:BeginSVG(f_name,cmWidth,cmHeight,iWidth,iHeight); CircleSVG(f,centerX,centerY,radius); CloseSVG(f);
Matlab
Przykład oparty na kodzie napisanym przez Guillaume JACQUENOT :2D Apollonian gasket with four identical circles by Guillaume JACQUENOT ł
filename = [filename '.svg']; fid = fopen(filename,'w'); fprintf(fid,'\n'); fprintf(fid,'\n'); fprintf(fid,'\n'); fprintf(fid,'\n'); fprintf(fid,'\n'); fclose(fid);
Sprawdzenie kodu
Po utworzeniu pliku dobrze jest sprawdzić czy jest zgodny ze specyfikacją za pomocą walidatorawalidator W3.org
Optymalizacja kodu
Nawet poprawny składniowo kod może być poprawiany. Na przykład za pomocą grupowania podobnych elementów
Źródła