のねの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 }
     43 SkPaint::SkPaint() {
     44     // since we may have padding, we zero everything so that our memcmp() call
     45     // in operator== will work correctly.
     46     // with this, we can skip 0 and null individual initializations
     47     sk_bzero(this, sizeof(*this));
     48 
     63     fTextSize   = SkPaintDefaults_TextSize;
     64     fTextScaleX = SK_Scalar1;
     65     fColor      = SK_ColorBLACK;
     66     fMiterLimit = SkPaintDefaults_MiterLimit;
     67     fFlags      = SkPaintDefaults_Flags;
     68     fCapType    = kDefault_Cap;
     69     fJoinType   = kDefault_Join;
     70     fTextAlign  = kLeft_Align;
     71     fStyle      = kFill_Style;
     72     fTextEncoding = kUTF8_TextEncoding;
     73     fHinting    = SkPaintDefaults_Hinting;
     74 #ifdef SK_BUILD_FOR_ANDROID
     75     fLanguage = SkLanguage();
     76     fFontVariant = kDefault_Variant;
     77     fGenerationID = 0;
     78 #endif
     79 }
     77 FontPlatformData::FontPlatformData()
     78     : m_typeface(NULL), m_textSize(0), m_emSizeInFontUnits(0), m_fakeBold(false), m_fakeItalic(false),
     79       m_orientation(Horizontal), m_textOrientation(TextOrientationVerticalRight)
     80 {
     81     inc_count();
     82     trace(1);
     83 }
||<  
></blockquote><
><blockquote cite="http://tools.oesf.biz/android-4.2.0_r1.0/xref/external/webkit/Source/WebCore/platform/graphics/android/fonts/FontPlatformDataAndroid.cpp#203" title="Cross Reference: /external/webkit/Source/WebCore/platform/graphics/android/fonts/FontPlatformDataAndroid.cpp"><
>|cpp|
    203 void FontPlatformData::setupPaint(SkPaint* paint) const
    204 {
    205     if (hashTableDeletedFontValue() == m_typeface)
    206         paint->setTypeface(0);
    207     else
    208         paint->setTypeface(m_typeface);
    209 
    210     paint->setAntiAlias(true);
    211     paint->setSubpixelText(true);
    212     paint->setHinting(SkPaint::kSlight_Hinting);
    213     paint->setTextSize(SkFloatToScalar(m_textSize));
    214     paint->setFakeBoldText(m_fakeBold);
    215     paint->setTextSkewX(m_fakeItalic ? -SK_Scalar1/4 : 0);
    216     paint->setLanguage(s_defaultLanguage);
    217 #ifndef SUPPORT_COMPLEX_SCRIPTS
    218     paint->setTextEncoding(SkPaint::kUTF16_TextEncoding);
    219 #endif
    220 }
     52         static bool IsEmojiGlyph(uint16_t index) {
     53             return index >= kGlyphBase;
     54         }

     70     private:
     71         enum {
     72             /*  this is our internal trick to embedded private emoji glyph IDs
     73                 along side normal glyphs IDs that come from real fonts. The
     74                 assumption is that normal fonts never will report a glyph ID
     75                 above 20K or 30K, so 64000 should always be a safe starting
     76                 index. We also assume the the number of emoji will not overflow
     77                 16bits starting at 64000 i.e. 65535 - 64000 > total emoji count
     78              */
     79             kGlyphBase = 64000 <== 0xFA00
     80         };
    162 SkScalar EmojiFont::GetAdvanceWidth(uint16_t glyphID, const SkPaint& paint) {
    163     if (glyphID < kGlyphBase) {
    164         SkDebugf("-------- bad glyph passed to EmojiFont::GetAdvanceWidth %d\n",
    165                  glyphID);
    166         return 0;
    167     }
    168 
    169     const SkBitmap* bitmap = get_bitmap(glyphID - kGlyphBase);
    170     if (NULL == bitmap) {
    171         return 0;
    172     }
    173 
    174     // assume that our advance width is always the pointsize
    175     return paint.getTextSize();
    176 }
     98 /*  Return the bitmap associated with the local index, or NULL if none is
     99     available. Note that this will try to cache the bitmap the first time it
    100     creates it.
    101  */
    102 static const SkBitmap* get_bitmap(int index) {
    103     EncodeDataRec* rec = get_encoderec(index);
    104     SkBitmap* bitmap = NULL;
    105     if (rec) {
    106         bitmap = rec->fBitmap;
    107         if (NULL == bitmap) {
    108             bitmap = new SkBitmap;
    109             if (!SkImageDecoder::DecodeMemory(rec->fData, rec->fSize, bitmap)) {
    110                 delete bitmap;
    111                 // we failed, so mark us to not try again
    112                 rec->fSize = NOT_AVAILABLE_ENCODE_SIZE;
    113                 return NULL;
    114             }
    115             // cache the answer
    116             rec->fBitmap = bitmap;
    117             // todo: we never know if/when to let go of this cached bitmap
    118             // tho, since the pixels are managed separately, and are purged,
    119             // the "leak" may not be too important
    120         }
    121     }
    122     return bitmap;
    123 }
    694     /** Return the paint's text size.
    695         @return the paint's text size.
    696     */
    697     SkScalar getTextSize() const { return fTextSize; }