diff options
author | Khaled Hosny <khaledhosny@eglug.org> | 2013-03-06 22:43:23 +0000 |
---|---|---|
committer | Khaled Hosny <khaledhosny@eglug.org> | 2013-03-06 22:43:23 +0000 |
commit | 2fb851202b1da73113b967586b130f59ee5491dd (patch) | |
tree | a85b08eb844b14e9b567c8cb73752ac40019c9c9 /Build/source/texk/web2c/xetexdir/XeTeXFontInst_Mac.cpp | |
parent | 6eaf934f7aad57a32b0166d28dabff1fccf151d6 (diff) |
Sync XeTeX
git-svn-id: svn://tug.org/texlive/trunk@29299 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/xetexdir/XeTeXFontInst_Mac.cpp')
-rw-r--r-- | Build/source/texk/web2c/xetexdir/XeTeXFontInst_Mac.cpp | 152 |
1 files changed, 7 insertions, 145 deletions
diff --git a/Build/source/texk/web2c/xetexdir/XeTeXFontInst_Mac.cpp b/Build/source/texk/web2c/xetexdir/XeTeXFontInst_Mac.cpp index 741ab5be0f3..f0e0fa47543 100644 --- a/Build/source/texk/web2c/xetexdir/XeTeXFontInst_Mac.cpp +++ b/Build/source/texk/web2c/xetexdir/XeTeXFontInst_Mac.cpp @@ -44,16 +44,10 @@ authorization from the copyright holders. #include "XeTeX_ext.h" XeTeXFontInst_Mac::XeTeXFontInst_Mac(CTFontDescriptorRef descriptor, float pointSize, int &status) - : XeTeXFontInst(pointSize, status) + : XeTeXFontInst(NULL, 0, pointSize, status) , fDescriptor(descriptor) , fFontRef(0) - , fFirstCharCode(-1) - , fLastCharCode(-1) { - if (status != 0) { - return; - } - initialize(status); } @@ -65,62 +59,8 @@ XeTeXFontInst_Mac::~XeTeXFontInst_Mac() CFRelease(fFontRef); } -static hb_bool_t _get_glyph(hb_font_t*, void* font, hb_codepoint_t ch, hb_codepoint_t vs, hb_codepoint_t* glyph, void*) -{ - *glyph = mapCharToGlyphFromCTFont((CTFontRef) font, ch, vs); - return !!glyph; -} - -static hb_position_t _get_glyph_h_advance(hb_font_t*, void* font, hb_codepoint_t glyph, void*) -{ - CGGlyph cgGlyph = glyph; - float advance = CTFontGetAdvancesForGlyphs((CTFontRef) font, kCTFontHorizontalOrientation, &cgGlyph, 0, 1); - return advance * 64; -} - -static hb_position_t _get_glyph_v_advance(hb_font_t*, void* font, hb_codepoint_t glyph, void*) -{ - CGGlyph cgGlyph = glyph; - float advance = CTFontGetAdvancesForGlyphs((CTFontRef) font, kCTFontVerticalOrientation, &cgGlyph, 0, 1); - return advance * 64; -} - -static hb_bool_t _get_glyph_extents(hb_font_t*, void* font, hb_codepoint_t glyph, hb_glyph_extents_t* extents, void*) -{ - GlyphBBox bbox; - getGlyphBBoxFromCTFont((CTFontRef) font, glyph, &bbox); - extents->x_bearing = bbox.xMin; - extents->y_bearing = bbox.yMax; - extents->width = bbox.xMax - bbox.xMin; - extents->height = bbox.yMax - bbox.yMin; - - return true; -} - -static hb_font_funcs_t* _get_font_funcs() -{ - static hb_font_funcs_t* _font_funcs = 0; - _font_funcs = hb_font_funcs_create(); - hb_font_funcs_set_glyph_func(_font_funcs, _get_glyph, 0, 0); - hb_font_funcs_set_glyph_h_advance_func(_font_funcs, _get_glyph_h_advance, 0, 0); - hb_font_funcs_set_glyph_v_advance_func(_font_funcs, _get_glyph_v_advance, 0, 0); - hb_font_funcs_set_glyph_extents_func(_font_funcs, _get_glyph_extents, 0, 0); - hb_font_funcs_make_immutable(_font_funcs); - - return _font_funcs; -} - -static hb_blob_t* _get_font_table(hb_face_t*, hb_tag_t tag, void* userData) -{ - XeTeXFontInst* font = (XeTeXFontInst*) userData; - uint32_t length; - const void *table = font->getFontTable((OTTag) tag, &length); - if (!table || !length) - return 0; - return hb_blob_create((const char*) table, length, HB_MEMORY_MODE_READONLY, NULL, NULL); -} - -void XeTeXFontInst_Mac::initialize(int &status) +void +XeTeXFontInst_Mac::initialize(int &status) { if (fDescriptor == 0) { status = 1; @@ -142,92 +82,14 @@ void XeTeXFontInst_Mac::initialize(int &status) CFRelease(attributes); fFontRef = CTFontCreateWithFontDescriptor(fDescriptor, fPointSize * 72.0 / 72.27, NULL); if (fFontRef) { - fFilename = getFileNameFromCTFont(fFontRef); + char *pathname; + int index; + pathname = getFileNameFromCTFont(fFontRef, &index); - /* for HarfBuzz */ - hb_face_t* lFace = hb_face_create_for_tables(_get_font_table, this, 0); - hb_face_set_upem (lFace, fUnitsPerEM); - hbFont = hb_font_create(lFace); - hb_font_set_funcs(hbFont, _get_font_funcs(), (void*) fFontRef, 0); - hb_font_set_scale(hbFont, fPointSize, fPointSize); - hb_font_set_ppem(hbFont, fPointSize, fPointSize); + XeTeXFontInst::initialize(pathname, index, status); } else { status = 1; CFRelease(fDescriptor); fDescriptor = 0; } - - XeTeXFontInst::initialize(status); -} - -const void *XeTeXFontInst_Mac::readTable(OTTag tag, uint32_t *length) const -{ - if (!fFontRef) { - *length = 0; - return NULL; - } - CFDataRef tableData = CTFontCopyTable(fFontRef, tag, 0); - if (!tableData) { - *length = 0; - return NULL; - } - *length = CFDataGetLength(tableData); - UInt8* table = (UInt8*) xmalloc(*length * sizeof(UInt8)); - if (table != NULL) - CFDataGetBytes(tableData, CFRangeMake(0, *length), table); - - return table; -} - -void XeTeXFontInst_Mac::getGlyphBounds(GlyphID gid, GlyphBBox* bbox) -{ - getGlyphBBoxFromCTFont(fFontRef, gid, bbox); -} - -GlyphID -XeTeXFontInst_Mac::mapCharToGlyph(UChar32 ch) const -{ - return mapCharToGlyphFromCTFont(fFontRef, ch, 0); -} - -GlyphID -XeTeXFontInst_Mac::mapGlyphToIndex(const char* glyphName) const -{ - GlyphID rval = XeTeXFontInst::mapGlyphToIndex(glyphName); - if (rval) - return rval; - return GetGlyphIDFromCTFont(fFontRef, glyphName); -} - -const char* -XeTeXFontInst_Mac::getGlyphName(GlyphID gid, int& nameLen) -{ - const char* rval = XeTeXFontInst::getGlyphName(gid, nameLen); - if (rval) - return rval; - return GetGlyphNameFromCTFont(fFontRef, gid, &nameLen); -} - -UChar32 -XeTeXFontInst_Mac::getFirstCharCode() -{ - if (fFirstCharCode == -1) { - int ch = 0; - while (mapCharToGlyph(ch) == 0 && ch < 0x10ffff) - ++ch; - fFirstCharCode = ch; - } - return fFirstCharCode; -} - -UChar32 -XeTeXFontInst_Mac::getLastCharCode() -{ - if (fLastCharCode == -1) { - int ch = 0x10ffff; - while (mapCharToGlyph(ch) == 0 && ch > 0) - --ch; - fLastCharCode = ch; - } - return fLastCharCode; } |