Get Glyph bounding box based on font size

Hello,

I want to get the bounding box of a glyph based on font size (i don’t need to render it on an image)
This bounding box should be in pixel.
How can i get this ? The documentation of Aspose.Font is very light… :frowning:

Thanks

@tfipsrd

We are checking the related information at our end and will get back to you shortly.

@tfipsrd

Bounding box of glyph does not depend upon font size. Coordinates of Glyph are related to so-called em square.

From specification, em square is “an imaginary square that is used to size and align glyphs. The dimensions of the em square typically are those of the full body height of a font plus some extra spacing to prevent lines of text from colliding when typeset without extra leading.”

Coordinates of the glyph are described in font units or FUnits.

From the specification: “Since the number of units per em does not vary with the point size at which the font is displayed, the absolute size of a FUnit varies as the point size varies. Because FUnits are relative to the em square, a given location on a glyph will have the same coordinate location in FUnits regardless of the point size at which the font is rendered”

So the size of font does not affect coordinates of the glyph, it is used to scale glyph coordinates from font coordinate system to appropriate graphical device.

Maybe you want to get a bounding box of the glyph with scaled coordinates - related to the font size. But font-size value is not enough for this case. The actual coordinate value depends on graphical device, such device characteristics as dots per inch. Let this characteristic be variable DotsPerInch.

In this case, first we must divide this DotsPerInch value on font’s internal dots per inch (this value always 72), so we get such a variable - ResDotsPerInch = DotsPerInch/72.

And then every coordinate can be calculated for font size as:

ScaledCoordinate = OriginalCoordinate*FontSize*ResDotsPerInch

I don’t understand this.

For now base on the render example, i can get the glyphs bounding box in pixels (from top left). But for this I have to render the glyph, and get the Path bounds. And this step is slow…

If i use font.Metrics.GetGlyphBBox(GlyphId) i get a FontBBox.
Using fhis FontBBox, i want to transform it to a rectangle (from the baseline) in pixel (using FontSize and ResDotsPerInch )

The api documentation of Aspose.Font is very light :frowning:

Can you help me with this ?

Thanks

@tfipsrd

We are gathering the related information and will get back to you in a while.

@tfipsrd

The bug was found in method font.Metrics.GetGlyphBBox(GlyphId) as this method does not always return BBox related to GlyphId. In many cases, it returns BBox related to the whole font, not for glyph specified. This bug has been logged as FONTNET-183 in our issue tracking system and we will surely inform you as soon as it is resolved. Please give us some time.

To get a FontBBox related to a special glyph, better use property glyph.GlyphBBox.

To get rectangle coordinates scaled for desired font size mentioned calculation - ScaledCoordinate = OriginalCoordinateFontSizeResDotsPerInch needed to be upgraded with such metric as font’s unitsPerEm - this value can be obtained by property font.Metrics.UnitsPerEM.

Every coordinate for rectangle can be calculated using code like this:

xLeft = (bbox.XMin  FontSize  ResDotsPerInch)/font.Metrics.UnitsPerEM;
xRight = (bbox.XMax  FontSize  ResDotsPerInch) / font.Metrics.UnitsPerEM;
yBottom = (bbox.YMin  FontSize  ResDotsPerInch) / font.Metrics.UnitsPerEM;
yTop = (bbox.YMax  FontSize  ResDotsPerInch) / font.Metrics.UnitsPerEM; 

Ok thanks i got it.

Another question is, how can i compute the nextline baseline?
I tried this but without luck (it seems not enough) :
font.Metrics.GetTypoDescender(fontSize) + font.Metrics.GetTypoAscender(fontSize) + font.Metrics.GetTypoLineGap(fontSize)) * dpi / 72

@tfipsrd

An investigation ticket as FONTNET-184 has been logged in our issue tracking system for this inquiry. We will look into its details and share our feedback with you as soon as it is resolved. Please give us some time.