REBOL3 - SVG RENDERER (SVG RENDER IN DRAW AGG [web-public])

Return to Index Page
Most recent messages (300 max) are listed first.

#UserMessageDate
149shadwolfokay thank you for the link in my idea my SVG/REBOL graph render should be easy to use and render basical graphs using a psecial graph dialect but ofcourse it will be enhanced afterward...10-Nov-06 18:04
148shadwolfsur i do ^^10-Nov-06 18:02
147NormandIf any person is interested in developping graphs in Rebol they may find the following links of interest: www.combinatorica.com which have the source code in mathematica for calculating graphs and depicting them. There is also the C library at www.graphviz.org and the many little languages drivers.1-Jul-06 17:29
146Pekrwould following news help us to get AGG - SVG compatible gradients? It regards AGG 2.4, new branch of AGG, and I am sure we will get it ported to REBOL too ...

"New utility class template is added, gradient_lut. It allows you to easily create a color LUT for gradients from a set of color stops as they are defined in SVG, section Gradients and Patterns."

20-Jun-06 19:29
145Thřr.4-Apr-06 19:01
144shadwolfwould be fun i think2-Feb-06 3:01
143shadwolfgraph [ line "apple" red 5 12 12 8 line "banana" green 1 2 3 4 6 ]2-Feb-06 3:01
142shadwolfsome thing like2-Feb-06 2:59
141shadwolfyou have that in php and in ruby or php for example why not rebol starting from the point that rebol dialectal ability is incredible it's a pitty to not take advantage of it and show ppl hat rebol can apport on this particular application and this gives a good way to compare rebol to the other scripting language2-Feb-06 2:58
140shadwolfas svg or as png in a simple and easy way2-Feb-06 2:54
139shadwolfon a project like an svg graph system save.png take really all it's sens imagine a way to make easyly graphs with your rebol GCI to display graph stats in your web pages for example2-Feb-06 2:53
138shadwolfso for me it's new lol but more serriously until AGG was not available i think the use of save/png to-image was really not meaning2-Feb-06 2:51
137shadwolfAnton i discover it recently ^^2-Feb-06 2:50
136AntonView 1.2.1 has save/png, it's not very new...2-Feb-06 2:19
135shadwolfif some one is interressed to make it and need informations i'm ready to help ^^2-Feb-06 2:16
134shadwolfhum new rebol/view have save/png hability woooooooooooopy so there is nothing that prevent us to make a graph /AGG/SVG/PNG dialect ^^2-Feb-06 2:15
133shadwolfsurfing around on internet i found another common application for SVG -> graphs representation. The idea is inspired by a ruby project http://www.germane-software.com/software/SVG/SVG::Graph/#N10034. To do this in rebol we need teh ability to save data in an image PNG. The way we can use a thing like this could be to use a simple rebol draw based dialect to write the graphs if we are in REBOL/view application the graph is isealy shown if we need to show the graph in webrowser we can have 2 external sources SVG and PNG. For importing graphs from another application the SVG is the best way. So our REBOL::SVG::GRAPH would be able to import graphi content from a SVG file, output SVG and PNG files, render graphs to REBOL/view draw pane, propose a simple way to implement graphs using a rebol dialect.24-Jan-06 20:13
132shadwolfJoe hum inkscape is not able to show this svgz file that's strange ... I will try to investigate why this happend ...4-Jan-06 1:22
131Joeshadwolf, a good example to use with your svg renderer is the word map with political borders (public domain license) http://www.mappinghacks.com/maps/world_borders.svgz3-Jan-06 11:31
130AshleyWhen I find some spare time. ;) Next week or two hopefully.3-Jan-06 6:13
129JaimeVargasAshely when are you updating RebGUI?3-Jan-06 3:08
128AshleyOne other big advantage is that there is a lot of high-quality SVG in the public domain, and it's growing fast.3-Jan-06 2:58
127shadwolffor me to be honnest the advantages of using SVG instead of images are a lot this is a quick list of my thoughts on what can be done with SVG format. - easier embeding of graphical content - resizing auto ith not grphics quality loss - cheap but sharp skining - graphical content of an User Interface very low because rebol is pretty able to work with compression of text content ( compress/decompress) A little sample to enlight this compressed SVG file with blender logo -> less than 500 octets (any size can be applyed with no graphic loss (aliasing, color loose, blur, pixelisation etc..) ) a fixed jped for same content will use around 50ko. This means less datas in memory to as graphic pixel tables are very heavy in VM memory - Dynamic graphical content. some thing like text scrolling or efffect like Flash ones but with a reduction of 1000 of the data and memory use SVG use a labeling system for each graphical content that compose the image we can provided a tiny system to handle easy animation and show/hide of graphical content using raw rebol commands -> this will make pretty easier the realisation of dynamic animations in rebol ViD content and as any REBOL/View face is DRaw/AGG capable the effects that we can create isn the futur with this idea will have no limits -> this means too to have a pretty fast and ell designed SVG engine (that's my actual path on research)2-Jan-06 23:48
126shadwolfbut this not means i'm not anymore interrested by the project or that the project is dead. I found like you pretty hudge hopes on the integration of High scalable grphics in rebol ^^2-Jan-06 23:35
125shadwolfty ashley ^^ time i wasn't giving notice of my progress but mainly because Gradeint and transform problem where dependent on AGG an not on my script.2-Jan-06 23:33
124AshleyWell done, keep up the good progress! ;)2-Jan-06 2:13
123shadwolfIn the futur i hope we will use a lot svg in dynamic drawing composition.1-Jan-06 6:03
122shadwolfI still take as SVG workshop / reference software INKSCAPE pretty good LGPL sofware available for all OS.1-Jan-06 6:02
121shadwolfwell last thing i can say is that SVG rendering engine is very high on my task list ( task number one) i worked on the adding of some other new drawing primitive (image rect, circles). I will continue to work on the close support of all SVG datas that can have a meaning in AGG context. SVG rendering engine is a 2 weeks of work only!!! ... until i fall on the gradient and transforms problems so this ensure us advancing on this project will be very fast once we solve bugs in REBOL/View related to AGG (wich is in progress actually)1-Jan-06 6:00
120shadwolftransform problem are on their way to be solve gradient too by cyphre and Carl those two things are the most blockant problems until they are not completly solved we can't expect to have a full working SVG rendering engine -> most of SVG imagines use transform effects and gradients this means that if we want to get a pretty good and reliable SVG engine we have to fixe those two issue. SVR rendering engine is a good and hudge test upon AGG integration to REBOL/View and it allows us to embetter it !!!

Once we get a fully working engine with basic human understandable algorithm i will start the optimisation process using parse (but to be franck i don't know how parse will react in front svg row data or how will be the time to dev this parse based SVG engine ... in all cases I think the actual engine have teached me a lot arrounf the SVG to AGG adaptation process so i hope the translation to parse and parse/rules will not be too hard and too long)

1-Jan-06 5:53
119shadwolfFor ppl interrested in SVG rendering engine. My tonight work and test on the engine is resumed in the AGG topic. To resume before matrix bug as causing bad scale and bad position. Now we have good position but still bad scale i post screen cap samples and we can see that the evolution is good betwin View 1.3.1 and 1.3.21-Jan-06 5:45
118shadwolfpersonnaly I'm working with InkScape a very good SVG software...5-Aug-05 11:15
117shadwolfGood list ;)5-Aug-05 11:15
116RobertFYI: Ed Pegg writes "I did a survey of all available vector-based drawing programs, in anticipation of SVG in the next Firefox. I found 29 different vector drawing programs. Of these, 14 were free or open source. More than I expected. Did I miss any good ones?" http://developers.slashdot.org/article.pl?sid=05/08/02/0117224&from=rss5-Aug-05 6:24
115shadwolfFeatures still on the work table are: - SVG Transformation translation (mostly matrix) - SVG Gradient translation (linear partern radiant) - SVG drawing primitives (some drawing primitives are not supported actually ) - SVG Animation translation (don't know if this is a usefull and suitable fonctionnality tellme what do you think about it)22-Jul-05 9:31
114shadwolfand I'm close to have found a solution to one of my problems regarding to the transformation matrix11-Jul-05 21:58
113shadwolfI'm hard working on the matrix support ..11-Jul-05 21:56
112AshleyRelease 15 of the OpenClipart library is out: http://www.openclipart.org/downloads/index.php ... over 4,000 high-quality *public domain* SVG images!11-Jul-05 14:41
111shadwolfChanlog: * Cleaner Code (near 200 lines saved) * support new draw primitives Ellipse, Path Arc, rect * recursiv G block parsing have been improved

Still not supported * transformation information (matrix,scale, rotate, skew) * gradient information (linear, radiant etc...) * circle, text, line, polyline, polygones

5-Jul-05 3:29
110shadwolfhttp://shadwolf.free.fr/svg-demo-shad05.r5-Jul-05 3:24
109shadwolfhere is the new version5-Jul-05 3:22
108shadwolfI have improved the svg rendering engine5-Jul-05 3:22
107shadwolf************5-Jul-05 3:21
106shadwolfI improve some more the rendering now the file gnome-keyboard-dev.svg is fully and perfectly rendererd. I put a red pen-fill color for identify all primitives that needs fill:url related gradient3-Jul-05 3:06
105shadwolfcorrected ;)3-Jul-05 2:12
104shadwolfI need to handle others drawing primitivs too3-Jul-05 2:07
103shadwolfstill lot of work on it gradients and transform handling can be very code consummer3-Jul-05 2:06
102shadwolfmy actual code is about 587 lines of code and it's not ended3-Jul-05 2:05
101shadwolfthis could be a good promotion point to insert SVG rendering into the rebplug for firefox once it's completed and optimised ;)3-Jul-05 2:05
100shadwolfbut what I need are high level information and formation on draw agg and this I know very little people that can respond in this point :)3-Jul-05 2:03
99shadwolfso you have to remaining choice (3 in fact ) 1) using IE but then your not my pal any more, 2) installing Inkscape and relate it to svg file 3) help me finishing the SVG viewer using REBOL !!! ;))3-Jul-05 2:02
98GrahamI got the Adobe plugin to work with firefox eventually.3-Jul-05 1:59
97shadwolfmaybe they saw a boggus open door in this plugin and disable it's support (this can be the case for a 1.0.4)3-Jul-05 1:59
96shadwolfGRaham same for me adobe plugin works well with IE but not with firefox3-Jul-05 1:58
95shadwolfso we can see in my code 2 approch for retrieving information one for top level second for g tags (groups can be recursiv)3-Jul-05 1:58
94GrahamFirefox is supposed to be able to support SVG ( a subset at least ) without plugins, but I couldn't get it to work. I had to download Adobe's plugin.3-Jul-05 1:57
93shadwolfhahaha ;)3-Jul-05 1:57
92shadwolfoups I make it only for groups ;)3-Jul-05 1:57
91shadwolfnow supports rect tag ;)3-Jul-05 1:56
90shadwolfhttp://shadwolf.free.fr/svg-demo-shad04.r3-Jul-05 1:56
89AshleyNo argument here. ;)3-Jul-05 1:21
88shadwolfbut you know now my way to work I prefer easy and powerfull /flexible code than hudge monolitic code ;)3-Jul-05 1:20
87shadwolfHandling SVG as REBOL object! tree makes it really really easier to set recursivity and code writing ( as all can be exploded into small fonctions I hope the resulting code once terminated won't be so deficult to read3-Jul-05 1:19
86shadwolfI like the XML primitive draw explorer like a tree view of the compoun of your draw this is particularly good to write SVG renderer3-Jul-05 1:18
85shadwolfI psent lot of time using it (more than 80 hours since this last weeks ) all SVG files that I could found exists3-Jul-05 1:17
84shadwolfI like particularly the capability of generating light weight SVG files (plein text) the drawing tools are simple powerfull very well thinked and pretty good3-Jul-05 1:16
83shadwolfAll this to say that it doesn't fall from the sky ;)3-Jul-05 1:15
82shadwolfInkscape is the successor project of sodipodi (for example you can see reference to sodipodi into teh SVG output files ...) Sodipodi was abandonned by the dev team so some of them retakes it and continue the adventure with inkscape3-Jul-05 1:14
81AshleyI've spent quite a bit of time looking at Inkscape (http://www.inkscape.org/) and it seems to be the only / best SVG game in town (their command-line driven SVG to PNG conversion seems to be particularly well regarded). Looking forward to their 0.42 release as it supports OS/X as well.

The Clip Art site that they link to (http://www.openclipart.org/) is also a treasure trove of Public Domain files (which solves the GPL concerns I had with many of the dedicated KDE / Gnome icon sets). I'm also looking forward to their release 15 which seems to be just around the corner.

Lots of good news in the SVG world, I wonder how long before mainstream browsers start supporting it? (without plugins).

3-Jul-05 1:12
80AshleyGood progress! If you change:

"stroke-width" [line-width: to decimal! val]

to

"stroke-width" [line-width: to-unit val]

then it'll run all your sample SVG icon files as well. Wish I knew the answers to your AGG questions, but like you I'm waiting on more documentation / examples.

3-Jul-05 0:53
79shadwolfwhat is not supported are radial / linear Gradient (content and border), transformations (local/global I'm still pending for informations on it) and all other shapes than path (like rect for example)2-Jul-05 21:18
78shadwolfthis script support recursive G block (objects /list) and path (object list)2-Jul-05 21:13
77shadwolftry to load all the files that Ashley provides with his svg-demo2-Jul-05 21:13
76shadwolfhttp://shadwolf.free.fr/svg-demo-shad04.r2-Jul-05 21:12
75shadwolfOkay so here is the first version of my work on SVG to rebol objects tree structure2-Jul-05 21:12
74shadwolf***********2-Jul-05 21:10
73shadwolfso in Rebol tree object the g block can be a bloc of sub object or an object ;)2-Jul-05 16:27
72shadwolfhum xpdf.svg file shows me a problem with the use of xml-to-object ... if you have serveral g block at the same level all g block are compacted into the same reference2-Jul-05 16:26
71shadwolfI don't know how to treat linearGradient too2-Jul-05 15:17
70shadwolfI still not soleve my matrix problems so until now I don't implement it into the actual code2-Jul-05 15:15
69shadwolfthe recursivity treatement for g block are also easier to do2-Jul-05 15:14
68shadwolfI'm still working full time on the S VG renderer. I'm close to be at the same level than the previous code but as I'm working with objects the code seems to be more fast ...2-Jul-05 15:13
67shadwolf***************2-Jul-05 15:12
66shadwolfat this point code have not drastically change ... like 40% is the same code1-Jul-05 10:55
65shadwolfI solve this issue regarding object retriving information I will enhance this pont to make it recursif retriever1-Jul-05 10:55
64shadwolfand the windows where the draw block is shown1-Jul-05 0:02
63shadwolfin this file we have xml-to-object function load-svg function (mostly empty there is where to put the data conversion and draw block construction) and the widget that start the program1-Jul-05 0:01
62shadwolfhttp://shadwolf.free.fr/svg-demo-shad03.r30-Jun-05 22:32
61shadwolfwrong adress30-Jun-05 22:32
60shadwolfoups sorry30-Jun-05 22:32
59shadwolfshadwolf.free.fr/svg-demo-shad04.r30-Jun-05 22:31
58shadwolfI give you the code maybe this will be more clear30-Jun-05 22:30
57shadwolfso to build the path we start xml/svg "/ " g or path if g we seek 3 thing transform field and path field or sub g field30-Jun-05 22:29
56shadwolfor maybe build the path xml/svg/path then attribute to a temporary var the foreach ob xml/svg/path [ ob processing ]30-Jun-05 22:24
55shadwolfI I want to interrogate the first shape description on the top level ( out of group blocks) I have to build a path like that xml/svg/path/1/d30-Jun-05 22:22
54shadwolffor example my object is set into xml global variable30-Jun-05 22:20
53shadwolfmy point is to make a recursif capapble code30-Jun-05 22:20
52shadwolfand fill the draw block with this data30-Jun-05 22:19
51shadwolfthen construc path to get data then translate this data to a draw equivalent exploitable datas30-Jun-05 22:19
50shadwolfthis means to interogate the content of the objet a gived level30-Jun-05 22:18
49shadwolfI make a base code but now I have to find a good code to exploit the relevent datas from the object tree30-Jun-05 22:18
48shadwolfthis in the goal to improve drastically the performance and be more performant on some key issues like recursivity etc...29-Jun-05 20:37
47shadwolfopkay so we are planning on the opportinity to use a REBOL tree object! structure to represente SVG datas :)29-Jun-05 20:36
46shadwolfit says author hahah ;)29-Jun-05 20:35
45BrianWshadwolf, I'm not the author - just a guy who made it available in the Rebol library :-)29-Jun-05 19:36
44shadwolfokay good stuf in it Vincent and I are planning to use the xml-to-object.r script from Brian Wisti to enbetter and make a more sophisticate support for our actual work upon SVG parsing translation and rendering into a VID window29-Jun-05 17:14
43AshleyYes, to-unit is called from svg-size; and also from "path d", stroke-width, fill-width, etc ... probably anywhere in SVG where we "expect" an integer or decimal! ;)27-Jun-05 3:19
42shadwolf??26-Jun-05 20:10
41shadwolfin svg-size26-Jun-05 20:10
40shadwolfwhere do I plug the to-unit function ?26-Jun-05 20:06
39shadwolfso you avac primitive(fill:url) ->LinearGRadient (coords) -> LinearGradient (colors order)26-Jun-05 20:03
38shadwolflinearGradient for example are splitted the first one contain the coordonates systeme and tranfromation informations the second one countains the colors involved and their order in the gradient26-Jun-05 20:02
37shadwolfI read most of the documentation but then make the link to AGG data structure is rather difficult26-Jun-05 19:59
36shadwolfsee chapter 7.1026-Jun-05 19:59
35shadwolfhttp://www.w3.org/TR/SVG/coords.html26-Jun-05 19:58
34shadwolfthe page where I found the conversion rules26-Jun-05 19:58
33shadwolfI copy past the conversion units into the script becaus I know that could be usefull but AS I was working on lineargradient and as it's a complicated part of the format SVG I had no time to make a conversion algorithm I glad to see that you make it :)26-Jun-05 19:53
32shadwolfAshley yes !!! You noticed right I found them deep hided in the SVG format documentation on W3C dedicated pages to SVG format ....26-Jun-05 19:52
31AshleyNoticed you found some conversion numbers (where from?? ;) ), so here's a simple func to make use of them:

to-unit: func [s [string!]] [ switch/default skip tail s -2 [ "pt" [1.25 * to decimal! copy/part s -2 + length? s] "pc" [15 * to decimal! copy/part s -2 + length? s] "mm" [3.543307 * to decimal! copy/part s -2 + length? s] "cm" [35.43307 * to decimal! copy/part s -2 + length? s] "in" [90 * to decimal! copy/part s -2 + length? s] "px" [to decimal! copy/part s -2 + length? s] ][ to decimal! s ] ]

26-Jun-05 1:38
30shadwolfhttp://shadwolf.free.fr/svg-demo02.zip24-Jun-05 23:00
29shadwolfif you wants to write the "in" AGG/draw code that is based on my rebol linear gradient list there is the code and a sample file from InkScape24-Jun-05 23:00
28shadwolfI think I handle web the creation of the rebol list of linear gradient24-Jun-05 22:59
27shadwolfhow to apply a matrix tranformation only over a grendient definition ?24-Jun-05 20:35
26shadwolfand I have some asks24-Jun-05 20:34
25shadwolfI'm working hard on the translation of the linearGradient informations from SVG files to AGG24-Jun-05 20:33
24shadwolfdrawing primitives have a xlink:href field that point to the appropiate main lineargradient (countainer)24-Jun-05 12:26
23shadwolfyes DideC you are right the most problem will be to create tht tree structure to store all the LinearGradient définition and there childs then retrieve the approprieted informations24-Jun-05 12:25
22DideCI suppose 'fill-pen is what you need. Can render gradient in many way.24-Jun-05 7:25
21shadwolffor example the implementation of the LIneargradient I dont have any idea about how to translate it to AGG24-Jun-05 1:56
20shadwolfyes it' quite a nightmare for a AGG newbie as I'm ...24-Jun-05 1:55
19VincentThanks Ashley: there's still a lot of work to do - as SVG is quite flexible24-Jun-05 1:43
18shadwolfmatrix intervention of cyphre could be very educationnal and help me a lot to see what I'm messing in my code24-Jun-05 1:41
17shadwolfgroupe title rename done24-Jun-05 1:40
16shadwolfokay I have imporved matrix support it seems to be good for scale-x: 1 scale-y: 1 if cyphre can see the code of the matrix gestion and makes some fix optimisation it could allow us to advance more with the rest of the SVG word format24-Jun-05 1:39
15AshleyThanks for taking this up and running with it guys, you're making great progress (far better than I could have). Feel free to take ownership of the code and refactor it as needed.

Two minor improvements are:

unless closed? [insert tail shape reduce ['move 0x0]]

which is Gabriele's fix to the shape close problem, and:

feel: make feel [ redraw: func [face act pos] [ if act = 'draw [insert clear face/effect/draw load-svg face/data face/size] ] ]

which cleans the sample feel code up a bit. I'd also remove "VID" from the title of this group as DRAW AGG is tied to View. ;)

24-Jun-05 1:02
14shadwolfcan be found on http://shadwolf.free.fr/svg-demo-shadwolf.r23-Jun-05 23:18
13shadwolfsupport MLHVCSQT commands23-Jun-05 23:18
12shadwolfNew D field for "path" flag processing and translation made by Vincent23-Jun-05 23:15
11shadwolfso my version of the script supports in the SVG <g> block with in this block header transform matrix and in block <G> path with or without in it tranform matrix. I have a little problem with this point. Then I add the support for path d field coded in the format of INKSCAPE SVG PLAIN TEXT (the SVG light weight version available under inkscape )23-Jun-05 21:04
10shadwolfI allways use as reference script for my work the blender.svg file provided in ashley's archive svg-demo.zip23-Jun-05 20:59
9shadwolfmy FTP tis back from death so here is my last script http://shadwolf.free.fr/svg-demo-shadwolf.r23-Jun-05 20:58
8shadwolfcorrected thank you vincent ;)23-Jun-05 18:21
7shadwolfREBOL [ Title: "SVG Demo" Owner: "Ashley G. Trüter" Version: 0.0.1 Date: 21-Jun-2005 Purpose: "Loads and displays a resizeable SVG file." History: { 0.0.1 Initial release } Notes: { Tested on very simple SVG icons Only a few basic styles / attributes / commands supported Does not handle sizes in units other than pixels (e.g. pt, in, cm, mm, etc) SVG path has an optional close command, "z" ... AGG shape equivalent auto-closes load-svg function needs to be totally refactored / optimized ... *sample only* } ]

; The following commands are available for path data: ; ; M = moveto ; L = lineto ; H = horizontal lineto ; V = vertical lineto ; C = curveto ; S = smooth curveto ; Q = quadratic Belzier curve ; T = smooth quadratic Belzier curveto ; A = elliptical Arc ; Z = closepath

;print: none ; comment out this line to enable debug messages

load-svg: function [svg-file [file! string!] size [pair!]] [ id defs x y to-color to-byte draw-blk append-style svg-size scale-x scale-y ][ xml: either string? svg-file [parse-xml svg-file] [ unless %.svg = suffix? svg-file [to error! "File has an invalid suffix!"] parse-xml read svg-file ] unless xml/3/1/1 = "svg" [to error! "Could not find SVG header!"] ;unless find ["id" "xmlns"] xml/3/1/2/1 [to error! "Could not find ID header!"] ;unless xml/3/1/3/1/1 = "defs" [to error! "Could not find DEFS header!"]

id: xml/3/1/2 defs: xml/3/1/3

; ; --- Parse SVG id ;

svg-size: either find ["32pt" "48pt" "72pt"] select id "width" [ switch select id "width" [ "72pt" [120x120] "48pt" [80x80] "32pt" [60x60] ] ][ as-pair to integer! any [select id "width" "100"] to integer! any [select id "height" "100"] ]

x: to integer! any [select id "x" "0"] y: to integer! any [select id "y" "0"]

scale-x: size/x / svg-size/x scale-y: size/y / svg-size/y

; ; --- Helper functions ;

to-color: func [s [string!]] [ ; converts a string in the form "#FFFFFF" to a 4-byte tuple to tuple! load rejoin ["#{" next s "00}"] ]

to-byte: func [s [string!]] [ ; converts a string with a value 0-1 to an inverted byte 255 - to integer! 255 * to decimal! s ]

; ; --- Parse SVG defs ;

draw-blk: copy []

append-style: function [ command [string!] blk [block!] ][ x xy pen-color fill-color line-width mode size radius shape closed? matrix transf-command ][ xy: 0x0 size: 0x0 line-width: 1 matrice: make block! [] radius: none transf-command: none foreach [attr val] blk [ switch attr [ "transform" [print "tranform have been found" ;probe val halt val: parse val "()," transf-command: first val probe transf-command switch transf-command [ "matrix" [ foreach word val [ if not find word "matrix" [ insert tail matrice to-decimal word ] ] ] ] ] "style" [ foreach [attr val] parse val ":;" [ switch/default attr [ "font-size" [ ] "stroke" [ switch/default first val [ #"#" [pen-color: to-color val] #"n" [pen-color: none] ][ print ["Unknown stroke:" val] ] ] "stroke-width" [line-width: to decimal! val] "fill" [ fill-color: switch/default first val [ #"#" [to-color val] #"n" [none] ][ print ["Unknown fill value:" val] none ] ] "fill-rule" [ mode: switch/default val [ "evenodd" ['even-odd] ][ print ["Unknown fill-rule value:" val] none ] ] "stroke-opacity" [pen-color: any [pen-color 0.0.0.0] pen-color/4: to-byte val] "fill-opacity" [fill-color: any [fill-color 0.0.0.0] fill-color/4: to-byte val] "stroke-linejoin" [ insert tail draw-blk switch/default val [ "miter" [compose [line-join miter]] "round" [compose [line-join round]] "bevel" [compose [line-join bevel]] ][ print ["Unknown stroke-linejoin value:" val] none ] ] "stroke-linecap" [ insert tail draw-blk 'line-cap insert tail draw-blk to word! val ] ][ print ["Unknown style:" attr] ] ] ] "x" [xy/x: scale-x * val] "y" [xy/y: scale-y * val] "width" [size/x: scale-x * val] "height" [size/y: scale-y * val] "rx" [print "rx"] "ry" [radius: to decimal! val] "d" [ shape: copy [] x: none closed?: false if all [x not number? token] [ insert tail shape x * either token = 'V [scale-y][scale-x] x: none ] foreach token load val [ switch/default token [ M [insert tail shape 'move] C [insert tail shape 'curve] S [insert tail shape 'curv] L [insert tail shape 'line] Q [insert tail shape 'qcurve] T [insert tail shape 'qcurv] z [closed?: true] H [insert tail shape 'hline] V [insert tail shape 'vline] A [insert tail shape 'arc] ][ unless number? token [print ["Unknown path command:" token]] either x [insert tail shape as-pair x scale-y * token x: none] [x: scale-x * token] ] ] ] ] ] insert tail draw-blk compose [ pen (pen-color) fill-pen (fill-color) fill-rule (mode) line-width (line-width * min scale-x scale-y) ] switch command [ "rect" [ insert tail draw-blk compose [box (xy) (xy + size)] if radius [insert tail draw-blk radius] ] "path" [ unless closed? [print "Path closed"] either transf-command <> none [ switch transf-command [ "matrix" [insert tail draw-blk compose/only [ (to-word transf-command) (matrice) shape (shape) reset-matrix]] ] ][ insert tail draw-blk compose/only [shape (shape)] ] ] "g" [ print "Write here how to handle G insertion to Draw block" insert tail draw-blk probe compose/only [reset-matrix (to-word transf-command) (matrice)] ] ] ] probe defs foreach blk defs [ switch first blk [ "rect" [append-style first blk second blk] "path" [append-style first blk second blk] "g" [ print "key word" probe first blk print "matrix and style in G" probe second blk append-style first blk second blk ;print "what to draw in G" probe third blk foreach blk2 third blk [ probe blk2 switch first blk2[ "path" [append-style first blk2 second blk2] ] ] ] ] ] probe draw-blk draw-blk ]

view make face [ offset: 100x100 size: 200x200 action: request-file/filter/only "*.svg" text: rejoin ["SVG Demo [" last split-path action "]"] data: read action color: white effect: compose/only [draw (load-svg data size)] edge: font: para: none feel: make feel [ detect: func [face event] [ if event/type = 'resize [ insert clear face/effect/draw load-svg face/data face/size show face ] if event/type = 'close [quit] ] ] options: [resize] ]

23-Jun-05 18:21
6VincentOops too fast:

commands Q S T -> OK commands H &t V -> need to add (just before "foreach token load val [") : if all [x not number? token] [ insert tail shape x * either token = 'V [scale-y][scale-x] x: none ] command A -> not yet solved sign issues

23-Jun-05 18:20
5shadwolfREBOL [ Title: "SVG Demo" Owner: "Ashley G. Trüter" Version: 0.0.1 Date: 21-Jun-2005 Purpose: "Loads and displays a resizeable SVG file." History: { 0.0.1 Initial release } Notes: { Tested on very simple SVG icons Only a few basic styles / attributes / commands supported Does not handle sizes in units other than pixels (e.g. pt, in, cm, mm, etc) SVG path has an optional close command, "z" ... AGG shape equivalent auto-closes load-svg function needs to be totally refactored / optimized ... *sample only* } ]

; The following commands are available for path data: ; ; M = moveto ; L = lineto ; H = horizontal lineto ; V = vertical lineto ; C = curveto ; S = smooth curveto ; Q = quadratic Belzier curve ; T = smooth quadratic Belzier curveto ; A = elliptical Arc ; Z = closepath

;print: none ; comment out this line to enable debug messages

load-svg: function [svg-file [file! string!] size [pair!]] [ id defs x y to-color to-byte draw-blk append-style svg-size scale-x scale-y ][ xml: either string? svg-file [parse-xml svg-file] [ unless %.svg = suffix? svg-file [to error! "File has an invalid suffix!"] parse-xml read svg-file ] unless xml/3/1/1 = "svg" [to error! "Could not find SVG header!"] ;unless find ["id" "xmlns"] xml/3/1/2/1 [to error! "Could not find ID header!"] ;unless xml/3/1/3/1/1 = "defs" [to error! "Could not find DEFS header!"]

id: xml/3/1/2 defs: xml/3/1/3

; ; --- Parse SVG id ;

svg-size: either find ["32pt" "48pt" "72pt"] select id "width" [ switch select id "width" [ "72pt" [120x120] "48pt" [80x80] "32pt" [60x60] ] ][ as-pair to integer! any [select id "width" "100"] to integer! any [select id "height" "100"] ]

x: to integer! any [select id "x" "0"] y: to integer! any [select id "y" "0"]

scale-x: size/x / svg-size/x scale-y: size/y / svg-size/y

; ; --- Helper functions ;

to-color: func [s [string!]] [ ; converts a string in the form "#FFFFFF" to a 4-byte tuple to tuple! load rejoin ["#{" next s "00}"] ]

to-byte: func [s [string!]] [ ; converts a string with a value 0-1 to an inverted byte 255 - to integer! 255 * to decimal! s ]

; ; --- Parse SVG defs ;

draw-blk: copy []

append-style: function [ command [string!] blk [block!] ][ x xy pen-color fill-color line-width mode size radius shape closed? matrix transf-command ][ xy: 0x0 size: 0x0 line-width: 1 matrice: make block! [] radius: none transf-command: none foreach [attr val] blk [ switch attr [ "transform" [print "tranform have been found" ;probe val halt val: parse val "()," transf-command: first val probe transf-command switch transf-command [ "matrix" [ foreach word val [ if not find word "matrix" [ insert tail matrice to-decimal word ] ] ] ] ] "style" [ foreach [attr val] parse val ":;" [ switch/default attr [ "font-size" [ ] "stroke" [ switch/default first val [ #"#" [pen-color: to-color val] #"n" [pen-color: none] ][ print ["Unknown stroke:" val] ] ] "stroke-width" [line-width: to decimal! val] "fill" [ fill-color: switch/default first val [ #"#" [to-color val] #"n" [none] ][ print ["Unknown fill value:" val] none ] ] "fill-rule" [ mode: switch/default val [ "evenodd" ['even-odd] ][ print ["Unknown fill-rule value:" val] none ] ] "stroke-opacity" [pen-color: any [pen-color 0.0.0.0] pen-color/4: to-byte val] "fill-opacity" [fill-color: any [fill-color 0.0.0.0] fill-color/4: to-byte val] "stroke-linejoin" [ insert tail draw-blk switch/default val [ "miter" [compose [line-join miter]] "round" [compose [line-join round]] "bevel" [compose [line-join bevel]] ][ print ["Unknown stroke-linejoin value:" val] none ] ] "stroke-linecap" [ insert tail draw-blk 'line-cap insert tail draw-blk to word! val ] ][ print ["Unknown style:" attr] ] ] ] "x" [xy/x: scale-x * val] "y" [xy/y: scale-y * val] "width" [size/x: scale-x * val] "height" [size/y: scale-y * val] "rx" [print "rx"] "ry" [radius: to decimal! val] "d" [ shape: copy [] x: none closed?: false foreach token load val [ switch/default token [ M [insert tail shape 'move] C [insert tail shape 'curve] S [insert tail shape 'curv] L [insert tail shape 'line] Q [insert tail shape 'qcurve] T [insert tail shape 'qcurv] z [closed?: true] H [insert tail shape 'hline] V [insert tail shape 'vline] A [insert tail shape 'arc] ][ unless number? token [print ["Unknown path command:" token]] either x [insert tail shape as-pair x scale-y * token x: none] [x: scale-x * token] ] ] ] ] ] insert tail draw-blk compose [ pen (pen-color) fill-pen (fill-color) fill-rule (mode) line-width (line-width * min scale-x scale-y) ] switch command [ "rect" [ insert tail draw-blk compose [box (xy) (xy + size)] if radius [insert tail draw-blk radius] ] "path" [ unless closed? [print "Path closed"] either transf-command <> none [ switch transf-command [ "matrix" [insert tail draw-blk compose/only [ (to-word transf-command) (matrice) shape (shape) reset-matrix]] ] ][ insert tail draw-blk compose/only [shape (shape)] ] ] "g" [ print "Write here how to handle G insertion to Draw block" insert tail draw-blk probe compose/only [reset-matrix (to-word transf-command) (matrice)] ] ] ] probe defs foreach blk defs [ switch first blk [ "rect" [append-style first blk second blk] "path" [append-style first blk second blk] "g" [ print "key word" probe first blk print "matrix and style in G" probe second blk append-style first blk second blk ;print "what to draw in G" probe third blk foreach blk2 third blk [ probe blk2 switch first blk2[ "path" [append-style first blk2 second blk2] ] ] ] ] ] probe draw-blk draw-blk ]

view make face [ offset: 100x100 size: 200x200 action: request-file/filter/only "*.svg" text: rejoin ["SVG Demo [" last split-path action "]"] data: read action color: white effect: compose/only [draw (load-svg data size)] edge: font: para: none feel: make feel [ detect: func [face event] [ if event/type = 'resize [ insert clear face/effect/draw load-svg face/data face/size show face ] if event/type = 'close [quit] ] ] options: [resize] ]

23-Jun-05 17:49
4shadwolfVincent add some path rendering commands S Q T H A V23-Jun-05 17:49
3shadwolfAS reference take the file blender.svg from svg-demo.zip package maide by ashley23-Jun-05 17:30
2shadwolfREBOL [ Title: "SVG Demo" Owner: "Ashley G. Trüter" Version: 0.0.1 Date: 21-Jun-2005 Purpose: "Loads and displays a resizeable SVG file." History: { 0.0.1 Initial release } Notes: { Tested on very simple SVG icons Only a few basic styles / attributes / commands supported Does not handle sizes in units other than pixels (e.g. pt, in, cm, mm, etc) SVG path has an optional close command, "z" ... AGG shape equivalent auto-closes load-svg function needs to be totally refactored / optimized ... *sample only* } ]

; The following commands are available for path data: ; ; M = moveto ; L = lineto ; H = horizontal lineto ; V = vertical lineto ; C = curveto ; S = smooth curveto ; Q = quadratic Belzier curve ; T = smooth quadratic Belzier curveto ; A = elliptical Arc ; Z = closepath

;print: none ; comment out this line to enable debug messages

load-svg: function [svg-file [file! string!] size [pair!]] [ id defs x y to-color to-byte draw-blk append-style svg-size scale-x scale-y ][ xml: either string? svg-file [parse-xml svg-file] [ unless %.svg = suffix? svg-file [to error! "File has an invalid suffix!"] parse-xml read svg-file ] unless xml/3/1/1 = "svg" [to error! "Could not find SVG header!"] ;unless find ["id" "xmlns"] xml/3/1/2/1 [to error! "Could not find ID header!"] ;unless xml/3/1/3/1/1 = "defs" [to error! "Could not find DEFS header!"]

id: xml/3/1/2 defs: xml/3/1/3

; ; --- Parse SVG id ;

svg-size: either find ["32pt" "48pt" "72pt"] select id "width" [ switch select id "width" [ "72pt" [120x120] "48pt" [80x80] "32pt" [60x60] ] ][ as-pair to integer! any [select id "width" "100"] to integer! any [select id "height" "100"] ]

x: to integer! any [select id "x" "0"] y: to integer! any [select id "y" "0"]

scale-x: size/x / svg-size/x scale-y: size/y / svg-size/y

; ; --- Helper functions ;

to-color: func [s [string!]] [ ; converts a string in the form "#FFFFFF" to a 4-byte tuple to tuple! load rejoin ["#{" next s "00}"] ]

to-byte: func [s [string!]] [ ; converts a string with a value 0-1 to an inverted byte 255 - to integer! 255 * to decimal! s ]

; ; --- Parse SVG defs ;

draw-blk: copy []

append-style: function [ command [string!] blk [block!] ][ x xy pen-color fill-color line-width mode size radius shape closed? matrix transf-command ][ xy: 0x0 size: 0x0 line-width: 1 matrice: make block! [] radius: none transf-command: none foreach [attr val] blk [ switch attr [ "transform" [print "tranform have been found" ;probe val halt val: parse val "()," transf-command: first val probe transf-command switch transf-command [ "matrix" [ foreach word val [ if not find word "matrix" [ insert tail matrice to-decimal word ] ] ] ] ] "style" [ foreach [attr val] parse val ":;" [ switch/default attr [ "font-size" [ ] "stroke" [ switch/default first val [ #"#" [pen-color: to-color val] #"n" [pen-color: none] ][ print ["Unknown stroke:" val] ] ] "stroke-width" [line-width: to decimal! val] "fill" [ fill-color: switch/default first val [ #"#" [to-color val] #"n" [none] ][ print ["Unknown fill value:" val] none ] ] "fill-rule" [ mode: switch/default val [ "evenodd" ['even-odd] ][ print ["Unknown fill-rule value:" val] none ] ] "stroke-opacity" [pen-color: any [pen-color 0.0.0.0] pen-color/4: to-byte val] "fill-opacity" [fill-color: any [fill-color 0.0.0.0] fill-color/4: to-byte val] "stroke-linejoin" [ insert tail draw-blk switch/default val [ "miter" [compose [line-join miter]] "round" [compose [line-join round]] "bevel" [compose [line-join bevel]] ][ print ["Unknown stroke-linejoin value:" val] none ] ] "stroke-linecap" [ insert tail draw-blk 'line-cap insert tail draw-blk to word! val ] ][ print ["Unknown style:" attr] ] ] ] "x" [xy/x: scale-x * val] "y" [xy/y: scale-y * val] "width" [size/x: scale-x * val] "height" [size/y: scale-y * val] "rx" [print "rx"] "ry" [radius: to decimal! val] "d" [ shape: copy [] x: none closed?: false foreach token load val [ switch/default token [ M [insert tail shape 'move] C [insert tail shape 'curve] L [insert tail shape 'line] z [closed?: true] ][ unless number? token [print ["Unknown path command:" token]] either x [insert tail shape as-pair x scale-y * token x: none] [x: scale-x * token] ] ] ] ] ] insert tail draw-blk compose [ pen (pen-color) fill-pen (fill-color) fill-rule (mode) line-width (line-width * min scale-x scale-y) ] switch command [ "rect" [ insert tail draw-blk compose [box (xy) (xy + size)] if radius [insert tail draw-blk radius] ] "path" [ unless closed? [print "Path closed"] either transf-command <> none [ switch transf-command [ "matrix" [insert tail draw-blk compose/only [ (to-word transf-command) (matrice) shape (shape) reset-matrix]] ] ][ insert tail draw-blk compose/only [shape (shape)] ] ] "g" [ print "Write here how to handle G insertion to Draw block" insert tail draw-blk probe compose/only [reset-matrix (to-word transf-command) (matrice)] ] ] ] probe defs foreach blk defs [ switch first blk [ "rect" [append-style first blk second blk] "path" [append-style first blk second blk] "g" [ print "key word" probe first blk print "matrix and style in G" probe second blk append-style first blk second blk ;print "what to draw in G" probe third blk foreach blk2 third blk [ probe blk2 switch first blk2[ "path" [append-style first blk2 second blk2] ] ] ] ] ] probe draw-blk draw-blk ]

view make face [ offset: 100x100 size: 200x200 action: request-file/filter/only "*.svg" text: rejoin ["SVG Demo [" last split-path action "]"] data: read action color: white effect: compose/only [draw (load-svg data size)] edge: font: para: none feel: make feel [ detect: func [face event] [ if event/type = 'resize [ insert clear face/effect/draw load-svg face/data face/size show face ] if event/type = 'close [quit] ] ] options: [resize] ]

23-Jun-05 17:29
1shadwolfMy actual source code that render path and <g> bloack transformation matrix23-Jun-05 17:29

Return to Index Page