| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "Font.h" | 6 #include "Font.h" |
| 7 | 7 |
| 8 #include <pango/pango.h> | |
| 9 #include <pango/pangoft2.h> | |
| 10 | |
| 11 #include "FloatRect.h" | 8 #include "FloatRect.h" |
| 9 #include "GlyphBuffer.h" |
| 10 #include "GraphicsContext.h" |
| 12 #include "NotImplemented.h" | 11 #include "NotImplemented.h" |
| 13 #include "PlatformContextSkia.h" | 12 #include "PlatformContextSkia.h" |
| 14 #include "GraphicsContext.h" | |
| 15 #include "SimpleFontData.h" | 13 #include "SimpleFontData.h" |
| 16 #include "GlyphBuffer.h" | 14 |
| 15 #include "SkCanvas.h" |
| 16 #include "SkPaint.h" |
| 17 #include "SkTemplates.h" |
| 18 #include "SkTypeface.h" |
| 19 #include "SkUtils.h" |
| 17 | 20 |
| 18 namespace WebCore { | 21 namespace WebCore { |
| 19 | 22 |
| 20 // ----------------------------------------------------------------------------- | 23 void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font, |
| 21 // Bitblit a Freetype bitmap onto a canvas at the given location in the given | 24 const GlyphBuffer& glyphBuffer, int from, int numGlyphs, |
| 22 // colour. | 25 const FloatPoint& point) const { |
| 23 // pgc: the Skia canvas | 26 SkCanvas* canvas = gc->platformContext()->canvas(); |
| 24 // bm: A freetype bitmap which is an 8-bit alpha bitmap | |
| 25 // ----------------------------------------------------------------------------- | |
| 26 static void bitBlitAlpha(PlatformGraphicsContext* pgc, FT_Bitmap* bm, | |
| 27 int x, int y, const Color& col) | |
| 28 { | |
| 29 SkPaint paint; | 27 SkPaint paint; |
| 30 paint.setARGB(col.alpha(), col.red(), col.green(), col.blue()); | |
| 31 | 28 |
| 32 // Here we are constructing an SkBitmap by pointing directly into the | 29 font->platformData().setupPaint(&paint); |
| 33 // Freetype bitmap data | 30 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 34 SkBitmap glyph; | 31 paint.setColor(gc->fillColor().rgb()); |
| 35 glyph.setConfig(SkBitmap::kA8_Config, bm->width, bm->rows, bm->pitch); | |
| 36 glyph.setPixels(bm->buffer); | |
| 37 pgc->canvas()->drawBitmap(glyph, x, y, &paint); | |
| 38 } | |
| 39 | 32 |
| 40 void Font::drawGlyphs(GraphicsContext* ctx, const SimpleFontData* sfd, | 33 SkASSERT(sizeof(GlyphBufferGlyph) == sizeof(uint16_t)); // compile-time ass
ert |
| 41 const GlyphBuffer& glyphBuffer, int from, int to, | |
| 42 const FloatPoint& point) const | |
| 43 { | |
| 44 // For now we draw text by getting the Freetype face from Pango and asking | |
| 45 // Freetype to render each glyph as an 8-bit alpha bitmap and drawing that | |
| 46 // to the canvas. This, obviously, ignores kerning, ligatures and other | |
| 47 // things that we should have in the real version. | |
| 48 GlyphBufferGlyph* glyphs = (GlyphBufferGlyph*)glyphBuffer.glyphs(from); | |
| 49 PlatformGraphicsContext* pgc = ctx->platformContext(); | |
| 50 FT_Face face = pango_ft2_font_get_face(sfd->m_font.m_font); | |
| 51 FT_GlyphSlot slot = face->glyph; | |
| 52 | 34 |
| 53 int x = point.x(), y = point.y(); | 35 const GlyphBufferGlyph* glyphs = glyphBuffer.glyphs(from); |
| 36 SkScalar x = SkFloatToScalar(point.x()); |
| 37 SkScalar y = SkFloatToScalar(point.y()); |
| 54 | 38 |
| 55 for (int i = from; i < to; ++i) { | 39 // TODO(port): Android WebCore has patches for PLATFORM(SGL) which involves |
| 56 const FT_Error error = FT_Load_Glyph(face, glyphs[i], FT_LOAD_RENDER); | 40 // this, however we don't have these patches and it's unclear when Android |
| 57 if (error) | 41 // may upstream them. |
| 58 continue; | 42 #if 0 |
| 43 if (glyphBuffer.hasAdjustedWidths()) { |
| 44 const GlyphBufferAdvance* adv = glyphBuffer.advances(from); |
| 45 SkAutoSTMalloc<32, SkPoint> storage(numGlyphs); |
| 46 SkPoint* pos = storage.get(); |
| 59 | 47 |
| 60 bitBlitAlpha(pgc, &slot->bitmap, x + slot->bitmap_left, | 48 for (int i = 0; i < numGlyphs; i++) { |
| 61 y - slot->bitmap_top, ctx->fillColor()); | 49 pos[i].set(x, y); |
| 62 // Freetype works in 1/64ths of a pixel, so we divide by 64 to get the | 50 x += SkFloatToScalar(adv[i].width()); |
| 63 // number of pixels to advance. | 51 y += SkFloatToScalar(adv[i].height()); |
| 64 x += slot->advance.x >> 6; | 52 } |
| 53 canvas->drawPosText(glyphs, numGlyphs << 1, pos, paint); |
| 54 } else { |
| 55 canvas->drawText(glyphs, numGlyphs << 1, x, y, paint); |
| 65 } | 56 } |
| 57 #endif |
| 58 |
| 59 canvas->drawText(glyphs, numGlyphs << 1, x, y, paint); |
| 66 } | 60 } |
| 67 | 61 |
| 68 void Font::drawComplexText(GraphicsContext* context, const TextRun& run, | 62 void Font::drawComplexText(GraphicsContext* context, const TextRun& run, |
| 69 const FloatPoint& point, int from, int to) const | 63 const FloatPoint& point, int from, int to) const |
| 70 { | 64 { |
| 71 notImplemented(); | 65 notImplemented(); |
| 72 } | 66 } |
| 73 | 67 |
| 74 float Font::floatWidthForComplexText(const TextRun& run) const | 68 float Font::floatWidthForComplexText(const TextRun& run) const |
| 75 { | 69 { |
| 76 notImplemented(); | 70 notImplemented(); |
| 77 return 0; | 71 return 0; |
| 78 } | 72 } |
| 79 | 73 |
| 80 int Font::offsetForPositionForComplexText(const TextRun& run, int x, | 74 int Font::offsetForPositionForComplexText(const TextRun& run, int x, |
| 81 bool includePartialGlyphs) const | 75 bool includePartialGlyphs) const |
| 82 { | 76 { |
| 83 notImplemented(); | 77 notImplemented(); |
| 84 return 0; | 78 return 0; |
| 85 } | 79 } |
| 86 | 80 |
| 87 FloatRect Font::selectionRectForComplexText(const TextRun& run, | 81 FloatRect Font::selectionRectForComplexText(const TextRun& run, |
| 88 const IntPoint& point, int h, | 82 const IntPoint& point, int h, |
| 89 int from, int to) const | 83 int from, int to) const |
| 90 { | 84 { |
| 91 notImplemented(); | 85 notImplemented(); |
| 92 return FloatRect(); | 86 return FloatRect(); |
| 93 } | 87 } |
| 94 | 88 |
| 95 } // namespace WebCore | 89 } // namespace WebCore |
| OLD | NEW |