KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: SVG Text can be a Defined Symbol
PRODUCT: 4D | VERSION: 12 | PLATFORM: Mac & Win
Published On: May 20, 2011

Just like shapes and lines, text in SVG can be a pre-defined symbol.

The advantage of defining text as a symbol is that it is created once and can be replicated countless times in multiple locations on an SVG image. Consider the image below:



It is created from the code below:

$SVG_T:=SVG_New (400;200)

$MyPat_T:=SVG_Define_pattern ($$SVG_T;"myGrid";20;20;0;0;"userSpaceOnUse")
$Use_T:=SVG_New_rect ($MyPat_T;0;0;20;20;0;0;"black";"beige";0.5)
SVG_SET_OPACITY ($Use_T;-1;20)

$Symbol_T:=SVG_Define_symbol ($SVG_T;"RefText")
SVG_New_text ($Symbol_T;"This is Referenced text";0;0\
    ;"Lucida Grande,Verdana";18;Plain;Align left;"red")

SVG_New_rect ($$SVG_T;0;0;400;400;0;0;"";"url(#myGrid)";1)

SVG_Use ($SVG_T"RefText";20;20)
SVG_Use ($SVG_T;"RefText";60;60)
SVG_Use ($SVG_T"RefText";100;100)
SVG_Use ($SVG_T;"RefText";140;140)


Notice that the text is defined once using SVG_Define_symbol and then referenced or used four times with SVG_Use. This is far more efficient and managable than repeating the use of SVG_New_text.