のねのBlog

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

drawGlyphs

    190 void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font,
    191                       const GlyphBuffer& glyphBuffer,  int from, int numGlyphs,
    192                       const FloatPoint& point) const
    193 {
    194     // compile-time assert
    195     SkASSERT(sizeof(GlyphBufferGlyph) == sizeof(uint16_t));
    196 
    197     if (numGlyphs == 1 && glyphBuffer.glyphAt(from) == 0x3) {
    198         // Webkit likes to draw end text control command for some reason
    199         // Just ignore it
    200         return;
    201     }
    202 
    203     SkPaint paint;
    204     if (!setupForText(&paint, gc, font)) {
    205         return;
    206     }
    207 
    208     SkScalar                    x = SkFloatToScalar(point.x());
    209     SkScalar                    y = SkFloatToScalar(point.y());
    210     const GlyphBufferGlyph*     glyphs = glyphBuffer.glyphs(from);
    211     const GlyphBufferAdvance*   adv = glyphBuffer.advances(from);
    212     SkAutoSTMalloc<32, SkPoint> storage(numGlyphs), storage2(numGlyphs), storage3(numGlyphs);
    213     SkPoint*                    pos = storage.get();
    214 
    215     SkCanvas* canvas = gc->platformContext()->recordingCanvas();
    216 
    217     /*  We need an array of [x,y,x,y,x,y,...], but webkit is giving us
    218         point.xy + [width, height, width, height, ...], so we have to convert
    219      */
    220 
    221     if (font->platformData().orientation() == Vertical) {
    222         float yOffset = SkFloatToScalar(font->fontMetrics().floatAscent(IdeographicBaseline) - font->fontMetrics().floatAscent());
    223         gc->platformContext()->setTextOffset(FloatSize(0.0f, -yOffset)); // compensate for offset in bounds calculation
    224         y += yOffset;
    225     }
    226 
    227     if (EmojiFont::IsAvailable()) {
    228         // set filtering, to make scaled images look nice(r)
    229         paint.setFilterBitmap(true);
    230 
    231         SkMatrix rotator;
    232         rotator.reset();
    233         if (font->platformData().orientation() == Vertical) {
    234             canvas->save();
    235             canvas->rotate(-90);
    236             rotator.setRotate(90);
    237         }
    238 
    239         int localIndex = 0;
    240         int localCount = 0;
    241         for (int i = 0; i < numGlyphs; i++) {
    242             if (EmojiFont::IsEmojiGlyph(glyphs[i])) {
    243                 if (localCount) {
    244                     rotator.mapPoints(&pos[localIndex], localCount);
    245                     canvas->drawPosText(&glyphs[localIndex],
    246                                      localCount * sizeof(uint16_t),
    247                                      &pos[localIndex], paint);
    248                 }
    249                 EmojiFont::Draw(canvas, glyphs[i], x, y, paint);
    250                 // reset local index/count track for "real" glyphs
    251                 localCount = 0;
    252                 localIndex = i + 1;
    253             } else {
    254                 pos[i].set(x, y);
    255                 localCount += 1;
    256             }
    257             x += SkFloatToScalar(adv[i].width());
    258             y += SkFloatToScalar(adv[i].height());
    259         }
    260 
    261         // draw the last run of glyphs (if any)
    262         if (localCount) {
    263             rotator.mapPoints(&pos[localIndex], localCount);
    264             canvas->drawPosText(&glyphs[localIndex],
    265                              localCount * sizeof(uint16_t),
    266                              &pos[localIndex], paint);
    267 
    268         }
    269 
    270         if (font->platformData().orientation() == Vertical)
    271             canvas->restore();
    272     } else {
    273         for (int i = 0; i < numGlyphs; i++) {
    274             pos[i].set(x, y);
    275             y += SkFloatToScalar(adv[i].height());
    276             x += SkFloatToScalar(adv[i].width());
    277         }
    278 
    279         if (font->platformData().orientation() == Vertical) {
    280             canvas->save();
    281             canvas->rotate(-90);
    282             SkMatrix rotator;
    283             rotator.reset();
    284             rotator.setRotate(90);
    285             rotator.mapPoints(pos, numGlyphs);
    286         }
    287         canvas->drawPosText(glyphs,
    288             numGlyphs * sizeof(uint16_t), pos, paint);
    289 
    290         if (font->platformData().orientation() == Vertical)
    291             canvas->restore();
    292     }
    293 
    294     if (font->platformData().orientation() == Vertical)
    295         gc->platformContext()->setTextOffset(FloatSize()); // reset to undo above
    296 }
||<  
></blockquote><

*1367583297*[android][skia]selectionRectForComplexText
><blockquote cite="http://tools.oesf.biz/android-4.2.0_r1.0/xref/external/webkit/Source/WebCore/platform/graphics/android/fonts/FontAndroid.cpp#349" title="Cross Reference: /external/webkit/Source/WebCore/platform/graphics/android/fonts/FontAndroid.cpp"><
>|cpp|

FloatRect Font::selectionRectForComplexText(const TextRun& run,
    306                                 const FloatPoint& point, int h, int, int) const
    307 {
    308     SkPaint              paint;
    309     SkScalar             width, left;
    310     SkPaint::FontMetrics metrics;
    311 
    312     primaryFont()->platformData().setupPaint(&paint);
    313 
    314     width = paint.measureText(run.characters(), run.length() << 1);  <===============
    315     SkScalar spacing = paint.getFontMetrics(&metrics);
    316 
    317     return FloatRect(point.x(),
    318                      point.y(),
    319                      roundf(SkScalarToFloat(width)),
    320                      roundf(SkScalarToFloat(spacing)));
    321 }
    323 void Font::drawComplexText(GraphicsContext* gc, TextRun const& run,
    324                            FloatPoint const& point, int, int) const
    325 {
    326     SkCanvas*   canvas = gc->platformContext()->mCanvas;
    327     SkPaint     paint;
    328 
    329     if (!setupForText(&paint, gc, primaryFont())) {
    330         return;
    331     }
    332 
    333     // go to chars, instead of glyphs, which was set by setupForText()
    334     paint.setTextEncoding(SkPaint::kUTF16_TextEncoding);
    335 
    336     canvas->drawText(run.characters(), run.length() << 1,
    337                      SkFloatToScalar(point.x()), SkFloatToScalar(point.y()),
    338                      paint);
    339 }