[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ft] how to FT_Set_Pixel_Sizes / design height / maximum height
From: |
Anson |
Subject: |
[ft] how to FT_Set_Pixel_Sizes / design height / maximum height |
Date: |
Tue, 14 Jun 2005 09:54:56 +0100 |
I am looking at the documentation of FT_Set_Pixel_Sizes. It says:
/* The values of `pixel_width' and `pixel_height' correspond to the */
/* pixel values of the _typographic_ character size, which are NOT */
/* necessarily the same as the dimensions of the glyph `bitmap */
/* cells'. */
/* */
/* The `character size' is really the size of an abstract square */
/* called the `EM', used to design the font. However, depending */
/* on the font design, glyphs will be smaller or greater than the */
/* EM. */
/* */
/* This means that setting the pixel size to, say, 8x8 doesn't */
/* guarantee in any way that you will get glyph bitmaps that all fit */
/* within an 8x8 cell (sometimes even far from it). */
I was told that such pixel width/height is usually called "design
height", like the point size we specify in WinWord. What we want to
do is to create a "tallest/biggest" font within a user-supplied
(maximum) height. The problem is that if we call FT_Set_Pixel_Sizes
with height 30 for instance, the maximum height of the resultant font
we get could be as high as 42 (measured on screen.) So I have a
method DeriveDesignHeightFromMaxHeight (which works like below) to
call before actually creating the font.
While this approach seems to work, I find myself a bit silly to have
to do this. Is there a better way to limit the maximum height of a
font to be created?
Any feedback would be very helpful!
Many thanks,
Anson
-- my_funny_function_starts--
int DeriveDesignHeightFromMaxHeight(const FT_Face& aFace, int aMaxHeightInPixel)
{
const int boundingBoxHeightInFontUnit = aFace->bbox.yMax - aFace->bbox.yMin;
int designHeightInPixels = ( ( aMaxHeightInPixel *
aFace->units_per_EM ) / boundingBoxHeightInFontUnit );
const int maxHeightInFontUnit = aMaxHeightInPixel << 6;
FT_Set_Pixel_Sizes( aFace, designHeightInPixels, designHeightInPixels );
int currentMaxHeightInFontUnit = FT_MulFix(
boundingBoxHeightInFontUnit, aFace->size->metrics.y_scale );
while ( currentMaxHeightInFontUnit < maxHeightInFontUnit )
{
designHeightInPixels++;
FT_Set_Pixel_Sizes( aFace, designHeightInPixels, designHeightInPixels );
currentMaxHeightInFontUnit = FT_MulFix(
boundingBoxHeightInFontUnit, aFace->size->metrics.y_scale );
}
while ( currentMaxHeightInFontUnit > maxHeightInFontUnit )
{
designHeightInPixels--;
FT_Set_Pixel_Sizes( aFace, designHeightInPixels, designHeightInPixels );
currentMaxHeightInFontUnit = FT_MulFix(
boundingBoxHeightInFontUnit, aFace->size->metrics.y_scale );
}
return designHeightInPixels;
}
-- my_funny_function_ends--
- [ft] how to FT_Set_Pixel_Sizes / design height / maximum height,
Anson <=