Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-06

fpVectorial text related question

8 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Leonardo M. Ramé

Hi, I would like to know how can I measure text in fpVectorial. I need to draw a segment with text in the middle of the segment and I can't find any helper function to do that.

Example. Here's more or less what I want to draw:

|---- 10cm ----|

As you see, the text "10cm" is in the middle of the segment, to do that, I usually use this function:

lText := '10cm';
lTextWidth := GetTextWidth(lText);
lSegmentWidth := 1000;
lTextPosX := (lSegmentWidth / 2) - (lTextWidth / 2);

Also, I whould like to be able to draw the text rotated to follow the angle of the segment. Is this possible?.

Thanks in advance,
Leonardo M. Ram?
http://leonardorame.blogspot.com

Reply by email

Felipe Monteiro de Carvalho
to Leonardo M. Ramé
Leonardo M. Ram? wrote
Hi, I would like to know how can I measure text in fpVectorial. I need to draw a segment with text in the middle of the segment and I can't find any helper function to do that.

It is impossible to measure text in vectorial graphics because the rendering font is not known. Note how, for example, AutoCAD and SVG don't support it. There are two possible work arounds:

1> Try to make a clever guess based on the font info and add an extra safety spacing
2> Add script capabilities

Example. Here's more or less what I want to draw: |---- 10cm ----|

That looks like a Dimension. There is an element dedicated to that: TvAlignedDimension

Maybe that's what you want to draw?

Also, I whould like to be able to draw the text rotated to follow the angle of the segment. Is this possible?

We can simply add a new element to represent that. Some questions come from that: As double-precision degrees or as integer 1/16 of degrees? Rotating in which direction for positive values? Which output do you use? fpvtocanvas? Or image formats?

Felipe Monteiro de Carvalho

Reply by email

Alexander Klenin
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 12 lines
On Mon, Jun 6, 2011 at 1:32 AM, Leonardo M. Ram? wrote: > Hi, I would like to know how can I measure text in fpVectorial. I need > to draw a segment with text in the middle of the segment and I can't > find any helper function to do that. It is impossible to measure text in vectorial graphics because the rendering font is not known. Note how, for example, AutoCAD and SVG don't support it. There are two possible work arounds: 1> Try to make a clever guess based on the font info and add an extra safety spacing 2> Add script capabilities

How about adding a capability to measure text, implemented only for those back-ends that support it, like screen and printer? Yet another alternative would be to introduce text-based distance units, similar to "en" and "em" in HTML/SVG.

Alexander S. Klenin

Reply by email

Felipe Monteiro de Carvalho
to Alexander Klenin
Alexander Klenin wrote
How about adding a capability to measure text, implemented only for those back-ends that support it, like screen and printer?

The font size value not known before actually starting the rendering, but the document is created before that. Think about this: You create a document in Windows and render in Linux. Will it work if you dependended on measures from fonts from Windows which are not present in Linux?

Yet another alternative would be to introduce text-based distance units, similar to "en" and "em" in HTML/SVG.

That seams interresting, but for which font would that refer to? One can have multiple fonts in the same drawing, theorically. Or should we restrict to only one font?

Felipe Monteiro de Carvalho

Reply by email

Leonardo M. Ramé
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 17 lines
On Mon, Jun 6, 2011 at 2:14 PM, Alexander Klenin wrote: > How about adding a capability to measure text, implemented only for those > back-ends that support it, like screen and printer? The font size value not known before actually starting the rendering, but the document is created before that. Think about this: You create a document in Windows and render in Linux. Will it work if you dependended on measures from fonts from Windows which are not present in Linux? > Yet another alternative would be to introduce text-based distance units, > similar to "en" and "em" in HTML/SVG. That seams interresting, but for which font would that refer to? One can have multiple fonts in the same drawing, theorically. Or should we restrict to only one font?

I think it should be added a SetFont method to set the current font. This font can then be used to AddText and GetMeasuerements.

Reply by email

Leonardo M. Ramé
to Felipe Monteiro de Carvalho: It is impossible to measure text in vectorial graphics because the rendering font is not…
Felipe Monteiro de Carvalho wrote 21 lines
On Mon, Jun 6, 2011 at 1:32 AM, Leonardo M. Ram? wrote: > Hi, I would like to know how can I measure text in fpVectorial. I need > to draw a segment with text in the middle of the segment and I can't > find any helper function to do that. It is impossible to measure text in vectorial graphics because the rendering font is not known. Note how, for example, AutoCAD and SVG don't support it. There are two possible work arounds: 1> Try to make a clever guess based on the font info and add an extra safety spacing 2> Add script capabilities > Example. Here's more or less what I want to draw: > > |---- 10cm ----| That looks like a Dimension. There is an element dedicated to that: TvAlignedDimension Maybe that's what you want to draw?

How can I use TvAlignedDimension?, any example?, how it looks?

Show quoted text 7 lines
> Also, I whould like to be able to draw the text rotated to follow the > angle of the segment. Is this possible? We can simply add a new element to represent that. Some questions come from that: As double-precision degrees or as integer 1/16 of degrees? Rotating in which direction for positive values? Which output do you use? fpvtocanvas? Or image formats?

Well, the angle of the text must be the same of the segment below it, I don't know if it's double-precision or 1/16 int. Regarding the rotation, it must allow rotating 360 degrees clockwise. The output is fpvtocanvas.

Reply by email

Felipe Monteiro de Carvalho
to Leonardo M. Ramé: How can I use TvAlignedDimension?, any example?, how it looks? Well, the angle of the…
Leonardo M. Ram? wrote
Well, the angle of the text must be the same of the segment below it, I don't know if it's double-precision or 1/16 int. Regarding the rotation, it must allow rotating 360 degrees clockwise. The output is fpvtocanvas.

I implemented it in rev1667 as double-precision. Please test.

Felipe Monteiro de Carvalho

Reply by email