wxpdfdocument: GetLineHeight() returns 0 -> why?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

wxpdfdocument: GetLineHeight() returns 0 -> why?

Frédéric Bron
Hi,
GetLineHeight() returs 0, why?
Is it because I have not yet written anything?
How can I get the height of a text? I found GetStringWidth(s) to get
the width of a written text but I do not know how to get the height.
Thanks,
Frédéric

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: wxpdfdocument: GetLineHeight() returns 0 -> why?

Ulrich Telle
Hi Frédéric,

> GetLineHeight() returs 0, why?
> Is it because I have not yet written anything?

Right. wxPdfDocument tries to derive a line height from the first text
output (and keeps track of the last line height used). However, you can
always override the line height to suit your needs.

> How can I get the height of a text?

The text height is implicitly given by the font size. Before you start
to output text to PDF you have to select a font and to set a font size
in points.

For the line height you should always add some extra space, so that the
text stays readable. Using something like

SetLineHeight(GetFontSize()*1.25 / GetScaleFactor());

is usually a good compromise (that is, 25% more than the font size).

> I found GetStringWidth(s) to get
> the width of a written text but I do not know how to get the height.

As said above the text height is given by the font size. The text height
(font size) doesn't vary, while the text width depends on the actual
characters in the text when using a variable spaced font.

Regards,

Ulrich

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: wxpdfdocument: GetLineHeight() returns 0 -> why?

Frédéric Bron
> SetLineHeight(GetFontSize()*1.25 / GetScaleFactor());
> is usually a good compromise (that is, 25% more than the font size).

I tried in LibreOffice Writer 3 different fonts and found the
following default spacing:
120%, 127% and 135%. So your 125% is fine.

Measuring the line spacing is easy: I measure the distance between the
bottom of the "p" letter of two adjacent lines. To measure the
character height, I measure the distance between the bottom of the "p"
and the top of the "l" on the same line.

So, not the same spacing for all fonts. Does this mean that a
"standard" line spacing is encoded in the font itself? If so, could we
get it somehow?

Frédéric

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: wxpdfdocument: GetLineHeight() returns 0 -> why?

Ulrich Telle
Hi Frédéric,

> Measuring the line spacing is easy: I measure the distance between the
> bottom of the "p" letter of two adjacent lines. To measure the
> character height, I measure the distance between the bottom of the "p"
> and the top of the "l" on the same line.
>
> So, not the same spacing for all fonts. Does this mean that a
> "standard" line spacing is encoded in the font itself? If so, could we
> get it somehow?

Yes. After a font has been loaded, you can get a wxPdfFont instance from
the wxPdfFontManager. The wxPdfFont class allows you to access the font
description (method GetDescription returning a wxPdfFontDescription
instance).

The wxPdfFontDescription class allows you to access several font
attributes (like ascender, descender, bounding box and so on - read the
wxPdfDocument documentation for details).

Most data are given in raw format. That is, you will have to scale the
values to your needs.

Example:

ascenderInPoints = ascender / 1000 * fontSizeInPoints

Regards,

Ulrich

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: wxpdfdocument: GetLineHeight() returns 0 -> why?

Frédéric Bron
> The wxPdfFontDescription class allows you to access several font attributes
> (like ascender, descender, bounding box and so on).

Thanks. I understand that the line spacing is defined by*:
linespace = ascent - descent + linegap
I see that I can get ascent and descent with GetAscent() and GetDescent().

The missing 'linegap' can be obtained with
GetOpenTypeMetrics()
with either hheaLineGap or os2sTypoLineGap,.

Does this mean that I can compute the line spacing only if I use
OpenType font? Therefore, if I want to use a TrueType font, I may have
to convert it to OpenType before?

Regards,

Frédéric

*: https://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: wxpdfdocument: GetLineHeight() returns 0 -> why?

Ulrich Telle
Hi Frédéric,

>> The wxPdfFontDescription class allows you to access several font attributes
>> (like ascender, descender, bounding box and so on).
>
> Thanks. I understand that the line spacing is defined by*:
> linespace = ascent - descent + linegap
> I see that I can get ascent and descent with GetAscent() and GetDescent().
>
> The missing 'linegap' can be obtained with
> GetOpenTypeMetrics()
> with either hheaLineGap or os2sTypoLineGap,.
>
> Does this mean that I can compute the line spacing only if I use
> OpenType font? Therefore, if I want to use a TrueType font, I may have
> to convert it to OpenType before?

"OpenType" is a generic term. An OpenType font can be a font with
TrueType or PostScript outlines. Usually most TrueType fonts define the
font table 'hhea' which includes the line gap information.

You might want to take a look at the implementation of method
wxPdfDCImpl::CalculateFontMetrics in file pdfdc29.inc. You could use the
same approach for determining the external leading.

Regards,

Ulrich

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users