diff options
Diffstat (limited to 'Build/source/texk/web2c/xetexdir/XeTeXFontInst_FT2.cpp')
-rw-r--r-- | Build/source/texk/web2c/xetexdir/XeTeXFontInst_FT2.cpp | 129 |
1 files changed, 50 insertions, 79 deletions
diff --git a/Build/source/texk/web2c/xetexdir/XeTeXFontInst_FT2.cpp b/Build/source/texk/web2c/xetexdir/XeTeXFontInst_FT2.cpp index fde74d657dd..e7862e7d84f 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeXFontInst_FT2.cpp +++ b/Build/source/texk/web2c/xetexdir/XeTeXFontInst_FT2.cpp @@ -1,9 +1,9 @@ /****************************************************************************\ Part of the XeTeX typesetting system - copyright (c) 1994-2008 by SIL International - copyright (c) 2009 by Jonathan Kew + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew - Written by Jonathan Kew + SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -48,12 +48,11 @@ authorization from the copyright holders. FT_Library gFreeTypeLibrary = 0; -XeTeXFontInst_FT2::XeTeXFontInst_FT2(const char* pathname, int index, float pointSize, LEErrorCode &status) +XeTeXFontInst_FT2::XeTeXFontInst_FT2(const char* pathname, int index, float pointSize, int &status) : XeTeXFontInst(pointSize, status) , face(0) - , fFreeTypeOnly(false) { - if (LE_FAILURE(status)) { + if (status != 0) { return; } @@ -69,7 +68,7 @@ XeTeXFontInst_FT2::XeTeXFontInst_FT2(const char* pathname, int index, float poin err = FT_New_Face(gFreeTypeLibrary, (char*)pathname, index, &face); if (err != 0) { - status = LE_FONT_FILE_NOT_FOUND_ERROR; + status = 1; return; } @@ -84,13 +83,15 @@ XeTeXFontInst_FT2::XeTeXFontInst_FT2(const char* pathname, int index, float poin strcpy(p, ".afm"); // else replace extension with .afm FT_Attach_File(face, afm); // ignore error code; AFM might not exist delete[] afm; - fFreeTypeOnly = true; } initialize(status); - if (LE_FAILURE(status)) + if (status != 0) return; + + FT_Set_Pixel_Sizes(face, pointSize, 0); + hbFont = hb_ft_font_create(face, NULL); char buf[20]; if (index > 0) @@ -107,27 +108,26 @@ XeTeXFontInst_FT2::~XeTeXFontInst_FT2() FT_Done_Face(face); face = 0; } + hb_font_destroy(hbFont); } -void XeTeXFontInst_FT2::initialize(LEErrorCode &status) +void XeTeXFontInst_FT2::initialize(int &status) { if (face == 0) { - status = LE_FONT_FILE_NOT_FOUND_ERROR; + status = 1; return; } XeTeXFontInst::initialize(status); - if (LE_FAILURE(status)) { + if (status != 0) { /* font can ONLY be used via FreeType APIs, not direct table access */ - fFreeTypeOnly = true; - status = LE_NO_ERROR; + status = 0; /* fill in fields that XeTeXFontInst::initialize failed to get for us */ fUnitsPerEM = face->units_per_EM; - fAscent = yUnitsToPoints(face->ascender); - fDescent = yUnitsToPoints(face->descender); -// fLeading = ; + fAscent = unitsToPoints(face->ascender); + fDescent = unitsToPoints(face->descender); fItalicAngle = 0; PS_FontInfoRec font_info; if (FT_Get_PS_Font_Info(face, &font_info) == 0) { @@ -139,7 +139,7 @@ void XeTeXFontInst_FT2::initialize(LEErrorCode &status) return; } -const void *XeTeXFontInst_FT2::readTable(LETag tag, le_uint32 *length) const +const void *XeTeXFontInst_FT2::readTable(OTTag tag, uint32_t *length) const { *length = 0; FT_ULong tmpLength = 0; @@ -147,11 +147,11 @@ const void *XeTeXFontInst_FT2::readTable(LETag tag, le_uint32 *length) const if (err != 0) return NULL; - void* table = LE_NEW_ARRAY(char, tmpLength); + void* table = xmalloc(tmpLength * sizeof(char)); if (table != NULL) { err = FT_Load_Sfnt_Table(face, tag, 0, (FT_Byte*)table, &tmpLength); if (err != 0) { - LE_DELETE_ARRAY(table); + free((void *) table); return NULL; } *length = tmpLength; @@ -161,7 +161,7 @@ const void *XeTeXFontInst_FT2::readTable(LETag tag, le_uint32 *length) const } void -XeTeXFontInst_FT2::getGlyphBounds(LEGlyphID gid, GlyphBBox* bbox) +XeTeXFontInst_FT2::getGlyphBounds(GlyphID gid, GlyphBBox* bbox) { bbox->xMin = bbox->yMin = bbox->xMax = bbox->yMax = 0.0; @@ -174,73 +174,52 @@ XeTeXFontInst_FT2::getGlyphBounds(LEGlyphID gid, GlyphBBox* bbox) if (err == 0) { FT_BBox ft_bbox; FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_UNSCALED, &ft_bbox); - bbox->xMin = ft_bbox.xMin * fPointSize / fUnitsPerEM; - bbox->yMin = ft_bbox.yMin * fPointSize / fUnitsPerEM; - bbox->xMax = ft_bbox.xMax * fPointSize / fUnitsPerEM; - bbox->yMax = ft_bbox.yMax * fPointSize / fUnitsPerEM; + bbox->xMin = unitsToPoints(ft_bbox.xMin); + bbox->yMin = unitsToPoints(ft_bbox.yMin); + bbox->xMax = unitsToPoints(ft_bbox.xMax); + bbox->yMax = unitsToPoints(ft_bbox.yMax); FT_Done_Glyph(glyph); } } -LEGlyphID -XeTeXFontInst_FT2::mapCharToGlyph(LEUnicode32 ch) const +GlyphID +XeTeXFontInst_FT2::mapCharToGlyph(UChar32 ch) const { - if (!fFreeTypeOnly) - return XeTeXFontInst::mapCharToGlyph(ch); - return FT_Get_Char_Index(face, ch); } -le_uint16 +uint16_t XeTeXFontInst_FT2::getNumGlyphs() const { return face->num_glyphs; } void -XeTeXFontInst_FT2::getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const +XeTeXFontInst_FT2::getGlyphAdvance(GlyphID glyph, realpoint &advance) const { - if (!fFreeTypeOnly) - XeTeXFontInst::getGlyphAdvance(glyph, advance); + FT_Error err = FT_Load_Glyph(face, glyph, FT_LOAD_NO_SCALE); + if (err != 0) { + advance.x = advance.y = 0; + } else { - FT_Error err = FT_Load_Glyph(face, glyph, FT_LOAD_NO_SCALE); - if (err != 0) { - advance.fX = advance.fY = 0; - } - else { - advance.fX = fVertical ? 0 : face->glyph->metrics.horiAdvance * fPointSize / fUnitsPerEM; - advance.fY = fVertical ? face->glyph->metrics.vertAdvance * fPointSize / fUnitsPerEM : 0; - } + advance.x = fVertical ? 0 : unitsToPoints(face->glyph->metrics.horiAdvance); + advance.y = fVertical ? unitsToPoints(face->glyph->metrics.vertAdvance) : 0; } } -LEGlyphID +GlyphID XeTeXFontInst_FT2::mapGlyphToIndex(const char* glyphName) const { - LEGlyphID rval = FT_Get_Name_Index(face, const_cast<char*>(glyphName)); + GlyphID rval = FT_Get_Name_Index(face, const_cast<char*>(glyphName)); if (rval == 0) rval = XeTeXFontInst::mapGlyphToIndex(glyphName); return rval; } -void -XeTeXFontInst_FT2::getKernPair(LEGlyphID leftGlyph, LEGlyphID rightGlyph, LEPoint &kern) const -{ - FT_Vector kerning; - if (FT_Get_Kerning(face, leftGlyph, rightGlyph, FT_KERNING_UNSCALED, &kerning) == 0) { - kern.fX = kerning.x; - kern.fY = kerning.y; - } - else - kern.fX = kern.fY = 0; -} - const char* -XeTeXFontInst_FT2::getGlyphName(LEGlyphID gid, int& nameLen) +XeTeXFontInst_FT2::getGlyphName(GlyphID gid, int& nameLen) { - if (!fFreeTypeOnly) - return XeTeXFontInst::getGlyphName(gid, nameLen); - else if (FT_HAS_GLYPH_NAMES(face)) { + if (FT_HAS_GLYPH_NAMES(face)) { static char buffer[256]; FT_Get_Glyph_Name(face, gid, buffer, 256); nameLen = strlen(buffer); @@ -252,30 +231,22 @@ XeTeXFontInst_FT2::getGlyphName(LEGlyphID gid, int& nameLen) } } -LEUnicode32 +UChar32 XeTeXFontInst_FT2::getFirstCharCode() { - if (!fFreeTypeOnly) - return XeTeXFontInst::getFirstCharCode(); - else { - FT_UInt gindex; - return FT_Get_First_Char(face, &gindex); - } + FT_UInt gindex; + return FT_Get_First_Char(face, &gindex); } -LEUnicode32 +UChar32 XeTeXFontInst_FT2::getLastCharCode() { - if (!fFreeTypeOnly) - return XeTeXFontInst::getLastCharCode(); - else { - FT_UInt gindex; - LEUnicode32 ch = FT_Get_First_Char(face, &gindex); - LEUnicode32 prev = ch; - while (gindex != 0) { - prev = ch; - ch = FT_Get_Next_Char(face, ch, &gindex); - } - return prev; + FT_UInt gindex; + UChar32 ch = FT_Get_First_Char(face, &gindex); + UChar32 prev = ch; + while (gindex != 0) { + prev = ch; + ch = FT_Get_Next_Char(face, ch, &gindex); } + return prev; } |