のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

platformWidthForGlyph

   127 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const
    128 {
    129     SkASSERT(sizeof(glyph) == 2);   // compile-time assert
    130 
    131     SkPaint  paint;
    132 
    133     m_platformData.setupPaint(&paint);
    134 
    135     float advanceWidth;
    136     if (EmojiFont::IsEmojiGlyph(glyph))
    137         advanceWidth = EmojiFont::GetAdvanceWidth(glyph, paint);
    138     else {
    139         paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
    140         advanceWidth = SkScalarToFloat(paint.measureText(&glyph, 2));
    141     }
    142     return advanceWidth;
    143 }
    828     SkScalar measureText(const void* text, size_t length) const {
    829         return this->measureText(text, length, NULL, 0);
    830     }
  979 SkScalar SkPaint::measureText(const void* textData, size_t length,
    980                               SkRect* bounds, SkScalar zoom) const {
    981     const char* text = (const char*)textData;
    982     SkASSERT(text != NULL || length == 0);
    983 
    984     SkScalar                            scale = 0;
    985     SkAutoRestorePaintTextSizeAndFrame  restore(this);
    986 
    987     if (this->isLinearText()) {
    988         scale = fTextSize / kCanonicalTextSizeForPaths;
    989         // this gets restored by restore
    990         ((SkPaint*)this)->setTextSize(SkIntToScalar(kCanonicalTextSizeForPaths));
    991     }
    992 
    993     SkMatrix zoomMatrix, *zoomPtr = NULL;
    994     if (zoom) {
    995         zoomMatrix.setScale(zoom, zoom);
    996         zoomPtr = &zoomMatrix;
    997     }
    998 
    999     SkAutoGlyphCache    autoCache(*this, zoomPtr);
   1000     SkGlyphCache*       cache = autoCache.getCache();
   1001 
   1002     SkScalar width = 0;
   1003 
   1004     if (length > 0) {
   1005         int tempCount;
   1006 
   1007         width = this->measure_text(cache, text, length, &tempCount, bounds);
   1008         if (scale) {
   1009             width = SkScalarMul(width, scale);
   1010             if (bounds) {
   1011                 bounds->fLeft = SkScalarMul(bounds->fLeft, scale);
   1012                 bounds->fTop = SkScalarMul(bounds->fTop, scale);
   1013                 bounds->fRight = SkScalarMul(bounds->fRight, scale);
   1014                 bounds->fBottom = SkScalarMul(bounds->fBottom, scale);
   1015             }
   1016         }
   1017     }
   1018     return width;
   1019 }