4D-SVG

SVG_New_text

SVG_New_text ( parentSVGObject ; text {; x {; y {; font styleDef {; size {; style {; alignment {; color {; rotation {; lineSpacing {; stretching}}}}}}}}}} ) -> Function result
Parameter Type   Description
parentSVGObject SVG_Ref Reference of parent element
text Text Text to insert
x Real Coordinate on X axis
y Real Coordinate on Y axis
font | styleDef Text Font name or Style definition
size Longint Size of characters in points
style Longint Style of characters
alignment Longint Alignment
color String Text color
rotation Real Angle of rotation of text
lineSpacing Real Line spacing in points
stretching Real Horizontal stretch factor
Function result SVG_Ref Reference of SVG text object

Description

The SVG_New_text command inserts the text in text in the SVG container designated by parentSVGObject and returns its reference. If parentSVGObject is not an SVG document, an error is generated.

Note: Starting with 4D v15, the SVG_New_text command supports simple Styled text (the text can contain different styles, but SPAN attributes must not be nested). See example 5.

The optional x and y parameters can be used to specify the position on the X and Y axis of the upper corner of the first character of text. This point is situated differently according to the alignment value: to the left for a left alignment, to the right for a right alignment or in the center when the text is centered.

The SVG_New_text command accepts two different syntaxes for setting characters:

… where the style_definition parameter contains a complete style definition. If you pass, for instance, “{font-size:48px;fill:red;}”, this definition is added as a style attribute in the form:

style="font-size:48px;fill:red;"  

In this case, any additional parameters are ignored.

Example 1

Simple text using default text properties:

 $SVG:=SVG_New
 $textID:=SVG_New_text($SVG;"Hello world!")

Example 2

Text that is blue, italic, underlined and aligned to the right:

 $SVG:=SVG_New
 $text:="Hello world!\rBonjour le monde!\rHola Mundo!"
 $size:=48
 $font:="helvetica"
 $textID:=SVG_New_text($SVG;$text;400;10;$font;$size;Italic+Underline;Align right;"blue")

Example 3

Vertical text:

 $SVG:=SVG_New
 $textID:=SVG_New_text($SVG;$text;-250;0;"";48;-1;-1;"red";-90)

Example 4

Condensed or expanded text:

 $SVG:=SVG_New
 $textID:=SVG_New_text($SVG;"Hello world (condensed)";0;0;"";-1;-1;-1;"blue";0;1;0,8)
 $textID:=SVG_New_text($SVG;"Hello world (normal)";0;24)
 $textID:=SVG_New_text($SVG;"Hello world (stretched)";0;48;"";-1;-1;-1;"red";0;1;2)

Example 5

Display of multi-style text:

 var $Dom_svg;$Dom_text;$Txt_buffer : Text
  //definition of multi-style text
 $Txt_buffer:="Hello "+\
 "World"+\
 "!
"+\
 "It's "+\
 "Monday"
 $Dom_svg:=SVG_New
 
  //title
 SVG_SET_FONT_COLOR(SVG_New_text($Dom_svg;"_______ svg_Newtext _______";10;30);"blue")
  //text
 $Dom_text:=SVG_New_text($Dom_svg;$Txt_buffer;50;50)
 
 SVGTool_SHOW_IN_VIEWER($Dom_svg)
 SVG_CLEAR($Dom_svg)

See also

SVG_New_textArea
SVG_New_tspan
SVG_New_vertical_text