Hi All,
4D v15.2 Mac
Here is what I discovered. The issue I am having appears to be do to incorrect
results from the following lines of a routine:
$Dom_Ref:=SVG_New
$tDom_Text:=SVG_New_text
($Dom_Ref;$text_t;$ptr_W->;$ptr_H->;$fontName;$fontSize;$fontStyle;$fontAlign)
$pic:=SVG_Export_to_picture ($tDom_Text)
SVG_CLEAR ($Dom_Ref)
PICTURE PROPERTIES($pic;$ptr_W->;$ptr_H->)
I am not getting accurate width nor height from this approach.
BUT I am getting very close numbers from:
hmFree_GetStringWidth
TEXT_WidthHeight_Get - Old Miyako code I found in the NUG that I wrapped (see
code below).
I ran test code and here’s an example of the results I am getting:
$fontName:="Tahoma"
$fontStyle:=Plain
$fontAlign:=Align center
$display_t:="10"
hm_W = hmFree_GetStringWidth
svg_W = SVG_String_WidthHeight_Get
ut_W = TEXT_WidthHeight_Get
Size hm_W svg_W ut_W
7 8 4 8
8 9 5 9
9 10 5 10
10 11 6 11
11 12 7 13
12 13 7 14
13 14 8 15
14 15 8 16
15 16 9 17
16 17 9 18
17 19 10 19
18 20 10 20
19 21 11 21
20 22 11 22
21 23 12 23
22 24 13 25
23 25 13 26
24 26 14 27
25 27 14 28
26 28 15 29
Notice that “hm_W" and “ut_W" are very close, at most, off by a pixel. I’m
guessing rounding maybe.
Thought this might help others who are trying to place text at a particular
point in a chart and are maybe not seeing what they are expecting to see.
John…
------------------------------
C_TEXT($1;$2)
C_REAL($3)
C_TEXT($4;$5;$6)
C_POINTER($7;$8)
C_LONGINT($0)
If (Count parameters>7)
$content:=$1
$font_family:=$2
$font_size:=$3
$font_style:=$4 // normal | italic | oblique | inherit
$font_weight:=$5 // normal | bold | bolder | lighter | 100 | 200 | 300 | 400
| 500 | 600 | 700 | 800 | 900 | inherit
$font_decoration:=$6 // none | underline | overline | line-through | blink |
inherit
C_LONGINT($width_l;$height_l;$baseline_l)
C_PICTURE($picture_px)
$svg:=DOM Create XML Ref("svg")
$text:=DOM Create XML
element($svg;"text";"x";0;"y";$font_size;"font-family";$font_family;"font-size";$font_size;"font-weight";$font_weight;"font-style";$font_style;"text-decoration";$font_decoration)
DOM SET XML ELEMENT VALUE($text;$content)
SVG EXPORT TO PICTURE($svg;$picture_px)
PICTURE PROPERTIES($picture_px;$width_l;$height_l)
$7->:=$width_l
$8->:=$height_l+2
DOM SET XML ATTRIBUTE($text;"y";"0")
SVG EXPORT TO PICTURE($svg;$picture_px)
PICTURE PROPERTIES($picture_px;$width_l;$height_l)
$baseline_l:=$height_l+2
DOM CLOSE XML($svg)
$0:=$baseline_l
End if
> Hey Miyako,
>
> Further info from previous post...
>
> The more I experiment the more I think the width of the text is not correct.
>
> If I include these lines:
>
> SVG_SET_ATTRIBUTES ($text_svgRef;"text-align";"center")
> SVG_SET_ATTRIBUTES ($text_svgRef;"display-align";"center”)
>
> In a text string of “19˚” the 9 shows up approx. centered.
>
> If I exclude these two lines then.
>
> In a text string of “19˚” the 1 shows up approx. right aligned.
>
> So I am baffled and there’s little 4D example sir using the TextArea and
> modifying attributes. Of course I am reviewing the SVG spec and trying
> properties from there. But…
>
> So there’s something I don’t understand I think.
>
> Appreciate,
> John...
>
>> Hi Miyako,
>>
>> So if I understand how to replace “text” with “TextArea”…
>>
>> Here’s an existing code fragment with various height/width adjustments
>>
>> $fontAlign_D:=Align center
>>
>> $pnt_X:=$ctr_X+(($ctr_X*$radius)*Cos($Angle))
>> $pnt_Y:=$ctr_Y-(($ctr_Y*$radius)*Sin($Angle))
>>
>> $display_t:=$Degree+”˚” ` example: 16˚
>>
>> In this example the X and Y of the point are:
>>
>> inX_D=577
>> inY_D=276
>>
>> SVG_String_WidthHeight_Get (display_t; ->$width;
>> ->$height; $fontName; $fontSize_D; $fontStyle_D; $fontAlign_D)
>>
>> ` set new Y coord based upon returned height dimensions
>> $inY_D:=$inY_D-($height/2)
>>
>> $text_svgRef:=SVG_New_text
>> ($domSvg_ptr->;$cuspDegree+"˚";$inX_D;$inY_D;$fontName;$fontSize_D;$fontStyle_D;$fontAlign_D)
>>
>> The XML looks like:
>>
>> <text fill="#000000" font-family="Tahoma" font-size="14" font-style="normal"
>> font-weight="normal" stroke="#000000" text-anchor="middle"
>> text-decoration="none" x="577" y="282">16˚</text>
>>
>> Notice the Y value is changed to 282. This works pretty good!
>>
>> ----------------------------------------------
>>
>> When switched from SVG_New_text to SVG_New_textArea:
>>
>> $display_t:=$Degree+”˚” ` example: 22˚
>>
>> In this example the X and Y of the point are:
>>
>> inX_D=577
>> inY_D=276
>>
>> $text_svgRef:=SVG_New_textArea
>> ($domSvg_ptr->;$display_t;$inX_D;$inY_D;$width;$height;$fontName;$fontSize_D;$fontStyle_D;$fontAlign_D)
>> SVG_SET_ATTRIBUTES ($text_svgRef;"display-align";"center")
>> SVG_SET_ATTRIBUTES ($text_svgRef;"text-align";"center”)
>>
>> First issue I noticed was the degree symbol (˚) {ctrl+k} is missing.
>> Although the correct string is in the xml.
>>
>> <textArea display-align="center" fill="#000000" font-family="Tahoma"
>> font-size="14" font-style="normal" font-weight="normal" height="-13"
>> stroke="#000000" text-align="center" text-decoration="none" width="-28"
>> x="577" y="276">16˚</textAre>
>>
>> First notice that the Y value remains at 276???
>>
>> I thought it must be an encoding issue. So I tried different characters and
>> none of them are being displayed.
>>
>> Then I thought what if the width or height is not large enough to allow it
>> to display? By playing with the width I could see all the characters are
>> there. BUT I cannot reliably get the text centered on the point.
>>
>> So then I removed the following two lines:
>>
>> SVG_SET_ATTRIBUTES ($text_svgRef;"display-align";"center")
>> SVG_SET_ATTRIBUTES ($text_svgRef;"text-align";"center”)
>>
>> And the values are exactly the same. So this code has not affect therefore I
>> must not be setting the attributes correctly.
>>
>> Any idea as to what I am doing wrong?
>>
>> Appreciate,
>> John...
>>
>>> HI Miyako,
>>>
>>> Thanks for the info.
>>>
>>>> Ref: have you considered using <TextArea> instead of <text>?
>>>
>>> I haven’t but I will now. <grin>
>>>
>>> I’ll see if there’s a difference.
>>>
>>> Thanks for tips.
>>>
>>> John…
>>>
>>>
>>>> in general, it is best to instruct the rendering engine to decide how to
>>>> align objects,
>>>> rather than to compute the exact coordinates yourself.
>>>>
>>>> "text-anchor" (start, middle, end) should take care of horizontal align in
>>>> <text>,
>>>> but vertical align is going to be difficult since 4D does not support
>>>> "dominant-baseline" or "alignment-baseline".
>>>> if you decide to go down the "y" or "dy" route, well, I guess it's going
>>>> to be an uphill struggle.
>>>>
>>>> have you considered using <TextArea> instead of <text>?
>>>>
>>>> you have "display-align" (before, center, after) for vertical align and
>>>> "text-align" (start, center, end) for horizontal align.
>>>>
>>>> p.s.
>>>>
>>>> I love how they say start/end, before/after instead of left/right (because
>>>> of right to left scripts)
>>>> and decisively use middle instead of center with respect to the subject
>>>> (align or anchor)...
>>>
>>
>
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ: http://lists.4d.com/faqnug.html
Archive: http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub: mailto:[email protected]
**********************************************************************