Esempio n. 1
0
void QFontEngineMac::getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics)
{
    ATSUStyle unscaledStyle;
    ATSUCreateAndCopyStyle(style, &unscaledStyle);

    int emSquare = properties().emSquare.toInt();
    
    const int maxAttributeCount = 4;
    ATSUAttributeTag tags[maxAttributeCount + 1];
    ByteCount sizes[maxAttributeCount + 1];
    ATSUAttributeValuePtr values[maxAttributeCount + 1];
    int attributeCount = 0;

    Fixed size = FixRatio(emSquare, 1);
    tags[attributeCount] = kATSUSizeTag;
    sizes[attributeCount] = sizeof(size);
    values[attributeCount] = &size;
    ++attributeCount;
    
    Q_ASSERT(attributeCount < maxAttributeCount + 1);
    OSStatus err = ATSUSetAttributes(unscaledStyle, attributeCount, tags, sizes, values);
    Q_ASSERT(err == noErr);
    Q_UNUSED(err);

    GlyphID atsuGlyph = glyph;
    ATSGlyphScreenMetrics atsuMetrics;
    ATSUGlyphGetScreenMetrics(unscaledStyle, 1, &atsuGlyph, 0,
                              /* iForcingAntiAlias =*/ false,
                              /* iAntiAliasSwitch =*/true,
                              &atsuMetrics);

    metrics->width = int(atsuMetrics.width);
    metrics->height = int(atsuMetrics.height);
    metrics->x = QFixed::fromReal(atsuMetrics.topLeft.x);
    metrics->y = -QFixed::fromReal(atsuMetrics.topLeft.y);
    metrics->xoff = QFixed::fromReal(atsuMetrics.deviceAdvance.x);
    metrics->yoff = QFixed::fromReal(atsuMetrics.deviceAdvance.y);

    QFixedPoint p;
    ::addGlyphsToPath(unscaledStyle, &glyph, &p, 1, path);

    ATSUDisposeStyle(unscaledStyle);
}
Esempio n. 2
0
static cairo_status_t
_cairo_atsui_font_glyph_bbox(void *abstract_font,
                             const cairo_glyph_t *glyphs,
                             int num_glyphs, cairo_box_t *bbox)
{
    cairo_atsui_font_t *font = abstract_font;
    cairo_fixed_t x1, y1, x2, y2;
    int i;

    bbox->p1.x = bbox->p1.y = CAIRO_MAXSHORT << 16;
    bbox->p2.x = bbox->p2.y = CAIRO_MINSHORT << 16;


    for (i = 0; i < num_glyphs; i++) {
        GlyphID theGlyph = glyphs[i].index;

	ATSGlyphScreenMetrics metrics;
	ATSUGlyphGetScreenMetrics(font->style, 
				  1, &theGlyph, 0, true, true, &metrics);

	x1 = _cairo_fixed_from_double(glyphs[i].x + metrics.topLeft.x);
	y1 = _cairo_fixed_from_double(glyphs[i].y - metrics.topLeft.y);
	x2 = x1 + _cairo_fixed_from_double(metrics.height);
	y2 = y1 + _cairo_fixed_from_double(metrics.width);

        if (x1 < bbox->p1.x)
            bbox->p1.x = x1;

        if (y1 < bbox->p1.y)
            bbox->p1.y = y1;

        if (x2 > bbox->p2.x)
            bbox->p2.x = x2;

        if (y2 > bbox->p2.y)
            bbox->p2.y = y2;
    }

    return CAIRO_STATUS_SUCCESS;
}
Esempio n. 3
0
glyph_metrics_t QFontEngineMac::boundingBox(glyph_t glyph)
{
    GlyphID atsuGlyph = glyph;

    ATSGlyphScreenMetrics metrics;

    ATSUGlyphGetScreenMetrics(style, 1, &atsuGlyph, 0,
                              /* iForcingAntiAlias =*/ false,
                              /* iAntiAliasSwitch =*/true,
                              &metrics);

    // ### check again

    glyph_metrics_t gm;
    gm.width = int(metrics.width);
    gm.height = int(metrics.height);
    gm.x = QFixed::fromReal(metrics.topLeft.x);
    gm.y = -QFixed::fromReal(metrics.topLeft.y);
    gm.xoff = QFixed::fromReal(metrics.deviceAdvance.x);
    gm.yoff = QFixed::fromReal(metrics.deviceAdvance.y);

    return gm;
}