Server side support for BFont::IsFullAndHalfFixed().

Check a range of characters to see if they have the same width.

Change-Id: I9cef12f78d1e1d01acc6284eae90dbfb86166fc6
Reviewed-on: https://review.haiku-os.org/47
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
This commit is contained in:
Stefano Ceccherini 2014-02-21 22:39:26 +01:00 committed by Jérôme Duval
parent 20694a0458
commit d9eeaa720a
2 changed files with 24 additions and 2 deletions

View File

@ -37,7 +37,8 @@ FontStyle::FontStyle(node_ref& nodeRef, const char* path, FT_Face face)
fFamily(NULL),
fID(0),
fBounds(0, 0, 0, 0),
fFace(_TranslateStyleToFace(face->style_name))
fFace(_TranslateStyleToFace(face->style_name)),
fFullAndHalfFixed(false)
{
fName.Truncate(B_FONT_STYLE_LENGTH);
// make sure this style can be found using the Be API
@ -50,6 +51,26 @@ FontStyle::FontStyle(node_ref& nodeRef, const char* path, FT_Face face)
// calculate it because height = ascending + descending + leading
fHeight.leading = (double)(face->height - face->ascender + face->descender)
/ face->units_per_EM;
if (IsFixedWidth())
return;
// manually check if all applicable chars are the same width
FT_Int32 loadFlags = FT_LOAD_NO_SCALE | FT_LOAD_TARGET_NORMAL;
if (FT_Load_Char(face, (uint32)' ', loadFlags) != 0)
return;
int firstWidth = face->glyph->advance.x;
for (uint32 c = ' ' + 1; c <= 0x7e; c++) {
if (FT_Load_Char(face, c, loadFlags) != 0)
return;
if (face->glyph->advance.x != firstWidth)
return;
}
fFullAndHalfFixed = true;
}

View File

@ -82,7 +82,7 @@ class FontStyle : public ReferenceCounting, public Hashable {
\return false (for now)
*/
bool IsFullAndHalfFixed() const
{ return false; };
{ return fFullAndHalfFixed; };
/*!
\fn bool FontStyle::IsScalable(void)
@ -171,6 +171,7 @@ class FontStyle : public ReferenceCounting, public Hashable {
font_height fHeight;
uint16 fFace;
bool fFullAndHalfFixed;
};
#endif // FONT_STYLE_H_