OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 Google Inc. All rights reserved. | 2 * Copyright (c) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 paint->setHinting(SkPaint::kNo_Hinting); | 76 paint->setHinting(SkPaint::kNo_Hinting); |
77 } | 77 } |
78 | 78 |
79 // TODO: This needs to be split into helper functions to better scope the | 79 // TODO: This needs to be split into helper functions to better scope the |
80 // inputs/outputs, and reduce duplicate code. | 80 // inputs/outputs, and reduce duplicate code. |
81 // This issue is tracked in https://bugs.webkit.org/show_bug.cgi?id=62989 | 81 // This issue is tracked in https://bugs.webkit.org/show_bug.cgi?id=62989 |
82 void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font, | 82 void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font, |
83 const GlyphBuffer& glyphBuffer, unsigned from, unsigned numGlyphs, | 83 const GlyphBuffer& glyphBuffer, unsigned from, unsigned numGlyphs, |
84 const FloatPoint& point, const FloatRect& textRect) const | 84 const FloatPoint& point, const FloatRect& textRect) const |
85 { | 85 { |
86 COMPILE_ASSERT(sizeof(GlyphBufferGlyph) == sizeof(uint16_t), GlyphBufferGlyp
hSize_equals_uint16_t); | |
87 | |
88 bool shouldSmoothFonts = true; | 86 bool shouldSmoothFonts = true; |
89 bool shouldAntialias = true; | 87 bool shouldAntialias = true; |
90 | 88 |
91 switch (fontDescription().fontSmoothing()) { | 89 switch (fontDescription().fontSmoothing()) { |
92 case Antialiased: | 90 case Antialiased: |
93 shouldSmoothFonts = false; | 91 shouldSmoothFonts = false; |
94 break; | 92 break; |
95 case SubpixelAntialiased: | 93 case SubpixelAntialiased: |
96 break; | 94 break; |
97 case NoSmoothing: | 95 case NoSmoothing: |
98 shouldAntialias = false; | 96 shouldAntialias = false; |
99 shouldSmoothFonts = false; | 97 shouldSmoothFonts = false; |
100 break; | 98 break; |
101 case AutoSmoothing: | 99 case AutoSmoothing: |
102 // For the AutoSmooth case, don't do anything! Keep the default settings
. | 100 // For the AutoSmooth case, don't do anything! Keep the default settings
. |
103 break; | 101 break; |
104 } | 102 } |
105 | 103 |
106 if (isRunningLayoutTest()) { | 104 if (isRunningLayoutTest()) { |
107 shouldSmoothFonts = false; | 105 shouldSmoothFonts = false; |
108 shouldAntialias = shouldAntialias && isFontAntialiasingEnabledForTest(); | 106 shouldAntialias = shouldAntialias && isFontAntialiasingEnabledForTest(); |
109 } | 107 } |
110 | 108 |
111 const GlyphBufferGlyph* glyphs = glyphBuffer.glyphs(from); | 109 const Glyph* glyphs = glyphBuffer.glyphs(from); |
112 SkScalar x = SkFloatToScalar(point.x()); | 110 SkScalar x = SkFloatToScalar(point.x()); |
113 SkScalar y = SkFloatToScalar(point.y()); | 111 SkScalar y = SkFloatToScalar(point.y()); |
114 | 112 |
115 if (font->platformData().orientation() == Vertical) | 113 if (font->platformData().orientation() == Vertical) |
116 y += SkFloatToScalar(font->fontMetrics().floatAscent(IdeographicBaseline
) - font->fontMetrics().floatAscent()); | 114 y += SkFloatToScalar(font->fontMetrics().floatAscent(IdeographicBaseline
) - font->fontMetrics().floatAscent()); |
117 // FIXME: text rendering speed: | 115 // FIXME: text rendering speed: |
118 // Android has code in their WebCore fork to special case when the | 116 // Android has code in their WebCore fork to special case when the |
119 // GlyphBuffer has no advances other than the defaults. In that case the | 117 // GlyphBuffer has no advances other than the defaults. In that case the |
120 // text drawing can proceed faster. However, it's unclear when those | 118 // text drawing can proceed faster. However, it's unclear when those |
121 // patches may be upstreamed to WebKit so we always use the slower path | 119 // patches may be upstreamed to WebKit so we always use the slower path |
(...skipping 18 matching lines...) Expand all Loading... |
140 } | 138 } |
141 TextDrawingModeFlags textMode = gc->textDrawingMode(); | 139 TextDrawingModeFlags textMode = gc->textDrawingMode(); |
142 | 140 |
143 // We draw text up to two times (once for fill, once for stroke). | 141 // We draw text up to two times (once for fill, once for stroke). |
144 if (textMode & TextModeFill) { | 142 if (textMode & TextModeFill) { |
145 SkPaint paint = gc->fillPaint(); | 143 SkPaint paint = gc->fillPaint(); |
146 setupPaint(&paint, font, this, shouldAntialias, shouldSmoothFonts); | 144 setupPaint(&paint, font, this, shouldAntialias, shouldSmoothFonts); |
147 gc->adjustTextRenderMode(&paint); | 145 gc->adjustTextRenderMode(&paint); |
148 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 146 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
149 | 147 |
150 gc->drawPosText(glyphs, numGlyphs * sizeof(uint16_t), pos, textRect, pai
nt); | 148 gc->drawPosText(glyphs, numGlyphs * sizeof(Glyph), pos, textRect, paint)
; |
151 } | 149 } |
152 | 150 |
153 if ((textMode & TextModeStroke) | 151 if ((textMode & TextModeStroke) |
154 && gc->strokeStyle() != NoStroke | 152 && gc->strokeStyle() != NoStroke |
155 && gc->strokeThickness() > 0) { | 153 && gc->strokeThickness() > 0) { |
156 | 154 |
157 SkPaint paint = gc->strokePaint(); | 155 SkPaint paint = gc->strokePaint(); |
158 setupPaint(&paint, font, this, shouldAntialias, shouldSmoothFonts); | 156 setupPaint(&paint, font, this, shouldAntialias, shouldSmoothFonts); |
159 gc->adjustTextRenderMode(&paint); | 157 gc->adjustTextRenderMode(&paint); |
160 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 158 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
161 | 159 |
162 if (textMode & TextModeFill) { | 160 if (textMode & TextModeFill) { |
163 // If we also filled, we don't want to draw shadows twice. | 161 // If we also filled, we don't want to draw shadows twice. |
164 // See comment in FontHarfBuzz.cpp::paintGlyphs() for more details. | 162 // See comment in FontHarfBuzz.cpp::paintGlyphs() for more details. |
165 paint.setLooper(0); | 163 paint.setLooper(0); |
166 } | 164 } |
167 | 165 |
168 gc->drawPosText(glyphs, numGlyphs * sizeof(uint16_t), pos, textRect, pai
nt); | 166 gc->drawPosText(glyphs, numGlyphs * sizeof(Glyph), pos, textRect, paint)
; |
169 } | 167 } |
170 if (font->platformData().orientation() == Vertical) | 168 if (font->platformData().orientation() == Vertical) |
171 gc->restore(); | 169 gc->restore(); |
172 } | 170 } |
173 | 171 |
174 } // namespace WebCore | 172 } // namespace WebCore |
OLD | NEW |