Logo Search packages:      
Sourcecode: chromium-browser version File versions  Download package

SkScalar SkPaint::measureText ( const void *  text,
size_t  length,
SkRect *  bounds,
SkScalar  scale = 0 
) const

Return the width of the text.

Parameters:
text The text to be measured
length Number of bytes of text to measure
bounds If not NULL, returns the bounds of the text, relative to (0, 0).
scale If not 0, return width as if the canvas were scaled by this value
Returns:
The advance width of the text

Definition at line 794 of file SkPaint.cpp.

References isLinearText(), NULL, SkMatrix::setScale(), SkIntToScalar, and SkScalarMul.

Referenced by measureText().

{
    const char* text = (const char*)textData;
    SkASSERT(text != NULL || length == 0);

    SkScalar                            scale = 0;
    SkAutoRestorePaintTextSizeAndFrame  restore(this);

    if (this->isLinearText())
    {
        scale = fTextSize / kCanonicalTextSizeForPaths;
        // this gets restored by restore
        ((SkPaint*)this)->setTextSize(SkIntToScalar(kCanonicalTextSizeForPaths));
    }
    
    SkMatrix    zoomMatrix, *zoomPtr = NULL;
    if (zoom)
    {
        zoomMatrix.setScale(zoom, zoom);
        zoomPtr = &zoomMatrix;
    }

    SkAutoGlyphCache    autoCache(*this, zoomPtr);
    SkGlyphCache*       cache = autoCache.getCache();

    SkScalar width = 0;
    
    if (length > 0)
    {
        int tempCount;

        width = this->measure_text(cache, text, length, &tempCount, bounds);
        if (scale)
        {
            width = SkScalarMul(width, scale);
            if (bounds)
            {
                bounds->fLeft = SkScalarMul(bounds->fLeft, scale);
                bounds->fTop = SkScalarMul(bounds->fTop, scale);
                bounds->fRight = SkScalarMul(bounds->fRight, scale);
                bounds->fBottom = SkScalarMul(bounds->fBottom, scale);
            }
        }
    }
    return width;
}


Generated by  Doxygen 1.6.0   Back to index