OpBpath *MacOpSVGFont::GetGlyphOutline(uni_char uc) { static OpGlyphCallbackStruct data; data.path = new OpBpath(); if(m_font) { GlyphID glyph = 0; #ifdef USE_CG_SHOW_GLYPHS glyph = ((MacOpFont*)m_font)->GetGlyphID((UniChar)uc); #else #if 0 if(!mGlyphInfoArray) { ((MacOpFont*)m_font)->GetGlyphs(m_text, mGlyphInfoArray); } if(mGlyphInfoArray) glyph = mGlyphInfoArray->glyphs[gnum].glyphID; #endif #endif OSStatus result = noErr; if(kATSQuadCurveType != mCurveType) ATSUGlyphGetCubicPaths(((MacOpFont*)m_font)->GetATSUStyle(1.0), glyph, mMoveToUPP, mLineToUPP, mCurveToUPP, mClosePathUPP, &data, &result); else ATSUGlyphGetQuadraticPaths(((MacOpFont*)m_font)->GetATSUStyle(1.0), glyph, mQuadNewPathUPP, mQuadLineUPP, mQuadCurveUPP, mQuadClosePathUPP, &data, &result); } return data.path; }
static void addGlyphsToPath(ATSUStyle style, glyph_t *glyphs, QFixedPoint *positions, int numGlyphs, QPainterPath *path) { if (!numGlyphs) return; OSStatus e; QMacFontPath fontpath(0, 0, path); ATSCubicMoveToUPP moveTo = NewATSCubicMoveToUPP(QMacFontPath::moveTo); ATSCubicLineToUPP lineTo = NewATSCubicLineToUPP(QMacFontPath::lineTo); ATSCubicCurveToUPP cubicTo = NewATSCubicCurveToUPP(QMacFontPath::cubicTo); ATSCubicClosePathUPP closePath = NewATSCubicClosePathUPP(QMacFontPath::closePath); for (int i = 0; i < numGlyphs; ++i) { GlyphID glyph = glyphs[i]; fontpath.setPosition(positions[i].x.toReal(), positions[i].y.toReal()); ATSUGlyphGetCubicPaths(style, glyph, moveTo, lineTo, cubicTo, closePath, &fontpath, &e); } DisposeATSCubicMoveToUPP(moveTo); DisposeATSCubicLineToUPP(lineTo); DisposeATSCubicCurveToUPP(cubicTo); DisposeATSCubicClosePathUPP(closePath); }
void GetGlyphBBox_AAT(ATSUStyle style, UInt16 gid, GlyphBBox* bbox) /* returns glyph bounding box in TeX points */ { ATSCurveType curveType; OSStatus status; bbox->xMin = 65536.0; bbox->yMin = 65536.0; bbox->xMax = -65536.0; bbox->yMax = -65536.0; status = ATSUGetNativeCurveType(style, &curveType); if (status == noErr) { OSStatus cbStatus; if (curveType == kATSCubicCurveType) { static ATSCubicMoveToUPP cubicMoveToProc; static ATSCubicLineToUPP cubicLineToProc; static ATSCubicCurveToUPP cubicCurveToProc; static ATSCubicClosePathUPP cubicClosePathProc; if (cubicMoveToProc == NULL) { cubicMoveToProc = NewATSCubicMoveToUPP(&CubicMoveTo); cubicLineToProc = NewATSCubicLineToUPP(&CubicLineTo); cubicCurveToProc = NewATSCubicCurveToUPP(&CubicCurveTo); cubicClosePathProc = NewATSCubicClosePathUPP(&CubicClosePath); } status = ATSUGlyphGetCubicPaths(style, gid, cubicMoveToProc, cubicLineToProc, cubicCurveToProc, cubicClosePathProc, bbox, &cbStatus); } else { static ATSQuadraticNewPathUPP quadraticNewPathProc; static ATSQuadraticLineUPP quadraticLineProc; static ATSQuadraticCurveUPP quadraticCurveProc; static ATSQuadraticClosePathUPP quadraticClosePathProc; if (quadraticNewPathProc == NULL) { quadraticNewPathProc = NewATSQuadraticNewPathUPP(&QuadraticNewPath); quadraticLineProc = NewATSQuadraticLineUPP(&QuadraticLine); quadraticCurveProc = NewATSQuadraticCurveUPP(&QuadraticCurve); quadraticClosePathProc = NewATSQuadraticClosePathUPP(&QuadraticClosePath); } status = ATSUGlyphGetQuadraticPaths(style, gid, quadraticNewPathProc, quadraticLineProc, quadraticCurveProc, quadraticClosePathProc, bbox, &cbStatus); } } if (status != noErr || bbox->xMin == 65536.0) bbox->xMin = bbox->yMin = bbox->xMax = bbox->yMax = 0; else { // convert PS to TeX points and flip y-axis float tmp = bbox->yMin; bbox->yMin = -bbox->yMax * 72.27 / 72.0; bbox->yMax = -tmp * 72.27 / 72.0; bbox->xMin *= 72.27 / 72.0; bbox->xMax *= 72.27 / 72.0; } }
static cairo_status_t _cairo_atsui_font_glyph_path(void *abstract_font, cairo_glyph_t *glyphs, int num_glyphs, cairo_path_fixed_t *path) { int i; cairo_atsui_font_t *font = abstract_font; OSStatus err; cairo_ATSUI_glyph_path_callback_info_t info; static ATSCubicMoveToUPP moveProc = NULL; static ATSCubicLineToUPP lineProc = NULL; static ATSCubicCurveToUPP curveProc = NULL; static ATSCubicClosePathUPP closePathProc = NULL; if (moveProc == NULL) { moveProc = NewATSCubicMoveToUPP(MyATSCubicMoveToCallback); lineProc = NewATSCubicLineToUPP(MyATSCubicLineToCallback); curveProc = NewATSCubicCurveToUPP(MyATSCubicCurveToCallback); closePathProc = NewATSCubicClosePathUPP(MyCubicClosePathProc); } info.path = path; for (i = 0; i < num_glyphs; i++) { GlyphID theGlyph = glyphs[i].index; info.scale = font->scale; info.scale.x0 = glyphs[i].x; info.scale.y0 = glyphs[i].y; err = ATSUGlyphGetCubicPaths(font->unscaled_style, theGlyph, moveProc, lineProc, curveProc, closePathProc, (void *) &info, &err); } return CAIRO_STATUS_SUCCESS; }