OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 SkScalar* xpos = storage.get(); | 78 SkScalar* xpos = storage.get(); |
79 for (int i = 0; i < numGlyphs; i++) { | 79 for (int i = 0; i < numGlyphs; i++) { |
80 xpos[i] = x; | 80 xpos[i] = x; |
81 x += SkIntToScalar(advances[i]); | 81 x += SkIntToScalar(advances[i]); |
82 } | 82 } |
83 context->drawPosTextH(glyphs, numGlyphs * sizeof(uint16_t), | 83 context->drawPosTextH(glyphs, numGlyphs * sizeof(uint16_t), |
84 xpos, y, textRect, *paint); | 84 xpos, y, textRect, *paint); |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 static void setupPaintForFont(SkPaint* paint, GraphicsContext* context, | 88 static void paintSkiaText(GraphicsContext* context, |
89 SkTypeface* face, float size, uint32_t textFlags) | 89 const FontPlatformData& data, |
90 { | 90 SkTypeface* face, float size, uint32_t textFlags, |
91 paint->setTextSize(SkFloatToScalar(size)); | 91 int numGlyphs, |
92 paint->setTypeface(face); | 92 const WORD* glyphs, |
93 | 93 const int* advances, |
94 if (!context->couldUseLCDRenderedText()) { | 94 const GOFFSET* offsets, |
95 textFlags &= ~SkPaint::kLCDRenderText_Flag; | 95 const SkPoint& origin, |
96 // If we *just* clear our request for LCD, then GDI seems to | 96 const SkRect& textRect) |
97 // sometimes give us AA text, and sometimes give us BW text. Since the | |
98 // original intent was LCD, we want to force AA (rather than BW), so we | |
99 // add a special bit to tell Skia to do its best to avoid the BW: by | |
100 // drawing LCD offscreen and downsampling that to AA. | |
101 textFlags |= SkPaint::kGenA8FromLCD_Flag; | |
102 } | |
103 | |
104 static const uint32_t textFlagsMask = SkPaint::kAntiAlias_Flag | | |
105 SkPaint::kLCDRenderText_Flag | | |
106 SkPaint::kGenA8FromLCD_Flag; | |
107 | |
108 // now copy in just the text flags | |
109 SkASSERT(!(textFlags & ~textFlagsMask)); | |
110 uint32_t flags = paint->getFlags(); | |
111 flags &= ~textFlagsMask; | |
112 flags |= textFlags; | |
113 paint->setFlags(flags); | |
114 } | |
115 | |
116 static void paintSkiaText(GraphicsContext* context, HFONT hfont, | |
117 SkTypeface* face, float size, uint32_t textFlags, | |
118 int numGlyphs, | |
119 const WORD* glyphs, | |
120 const int* advances, | |
121 const GOFFSET* offsets, | |
122 const SkPoint& origin, | |
123 const SkRect& textRect) | |
124 { | 97 { |
125 TextDrawingModeFlags textMode = context->textDrawingMode(); | 98 TextDrawingModeFlags textMode = context->textDrawingMode(); |
126 // Ensure font load for printing, because PDF device needs it. | |
127 if (context->isPrintingDevice()) | |
128 FontPlatformData::ensureFontLoaded(hfont); | |
129 | 99 |
130 // Filling (if necessary). This is the common case. | 100 // Filling (if necessary). This is the common case. |
131 SkPaint paint; | 101 SkPaint paint; |
132 context->setupPaintForFilling(&paint); | 102 context->setupPaintForFilling(&paint); |
133 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 103 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
134 setupPaintForFont(&paint, context, face, size, textFlags); | 104 data.setupPaint(&paint, context); |
135 | 105 |
136 bool didFill = false; | 106 bool didFill = false; |
137 | 107 |
138 if ((textMode & TextModeFill) && (SkColorGetA(paint.getColor()) || paint.get Looper())) { | 108 if ((textMode & TextModeFill) && (SkColorGetA(paint.getColor()) || paint.get Looper())) { |
139 skiaDrawText(context, origin, textRect, &paint, &glyphs[0], &advances[0] , &offsets[0], numGlyphs); | 109 skiaDrawText(context, origin, textRect, &paint, &glyphs[0], &advances[0] , &offsets[0], numGlyphs); |
140 didFill = true; | 110 didFill = true; |
141 } | 111 } |
142 | 112 |
143 // Stroking on top (if necessary). | 113 // Stroking on top (if necessary). |
144 if ((textMode & TextModeStroke) | 114 if ((textMode & TextModeStroke) |
145 && context->strokeStyle() != NoStroke | 115 && context->strokeStyle() != NoStroke |
146 && context->strokeThickness() > 0) { | 116 && context->strokeThickness() > 0) { |
147 | 117 |
148 paint.reset(); | 118 paint.reset(); |
149 context->setupPaintForStroking(&paint); | 119 context->setupPaintForStroking(&paint); |
150 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 120 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
151 setupPaintForFont(&paint, context, face, size, textFlags); | 121 data.setupPaint(&paint, context); |
152 | 122 |
153 if (didFill) { | 123 if (didFill) { |
154 // If there is a shadow and we filled above, there will already be | 124 // If there is a shadow and we filled above, there will already be |
155 // a shadow. We don't want to draw it again or it will be too dark | 125 // a shadow. We don't want to draw it again or it will be too dark |
156 // and it will go on top of the fill. | 126 // and it will go on top of the fill. |
157 // | 127 // |
158 // Note that this isn't strictly correct, since the stroke could be | 128 // Note that this isn't strictly correct, since the stroke could be |
159 // very thick and the shadow wouldn't account for this. The "right" | 129 // very thick and the shadow wouldn't account for this. The "right" |
160 // thing would be to draw to a new layer and then draw that layer | 130 // thing would be to draw to a new layer and then draw that layer |
161 // with a shadow. But this is a lot of extra work for something | 131 // with a shadow. But this is a lot of extra work for something |
162 // that isn't normally an issue. | 132 // that isn't normally an issue. |
163 paint.setLooper(0); | 133 paint.setLooper(0); |
164 } | 134 } |
165 | 135 |
166 skiaDrawText(context, origin, textRect, &paint, &glyphs[0], &advances[0] , &offsets[0], numGlyphs); | 136 skiaDrawText(context, origin, textRect, &paint, &glyphs[0], &advances[0] , &offsets[0], numGlyphs); |
167 } | 137 } |
168 } | 138 } |
169 | 139 |
170 //////////////////////////////////////////////////////////////////////////////// /////////// | 140 //////////////////////////////////////////////////////////////////////////////// /////////// |
171 | 141 |
172 void paintSkiaText(GraphicsContext* context, | 142 void paintSkiaText(GraphicsContext* context, |
173 const FontPlatformData& data, | 143 const FontPlatformData& data, |
174 int numGlyphs, | 144 int numGlyphs, |
175 const WORD* glyphs, | 145 const WORD* glyphs, |
176 const int* advances, | 146 const int* advances, |
177 const GOFFSET* offsets, | 147 const GOFFSET* offsets, |
178 const SkPoint& origin, | 148 const SkPoint& origin, |
179 const SkRect& textRect) | 149 const SkRect& textRect) |
180 { | 150 { |
181 paintSkiaText(context, data.hfont(), data.typeface(), data.size(), data.pain tTextFlags(), | 151 paintSkiaText(context, data, data.typeface(), data.size(), data.paintTextFla gs(), |
182 numGlyphs, glyphs, advances, offsets, origin, textRect); | 152 numGlyphs, glyphs, advances, offsets, origin, textRect); |
183 } | 153 } |
184 | 154 |
185 void paintSkiaText(GraphicsContext* context, | 155 void paintSkiaText(GraphicsContext* context, |
186 HFONT hfont, | 156 const FontPlatformData& data, |
187 int numGlyphs, | 157 HFONT hfont, |
188 const WORD* glyphs, | 158 int numGlyphs, |
189 const int* advances, | 159 const WORD* glyphs, |
190 const GOFFSET* offsets, | 160 const int* advances, |
191 const SkPoint& origin, | 161 const GOFFSET* offsets, |
192 const SkRect& textRect) | 162 const SkPoint& origin, |
163 const SkRect& textRect) | |
193 { | 164 { |
194 int size; | 165 int size; |
195 int paintTextFlags; | 166 int paintTextFlags; |
167 | |
168 // Ensure font load for printing, because PDF device needs it. | |
169 if (context->isPrintingDevice()) | |
170 FontPlatformData::ensureFontLoaded(hfont); | |
bungeman-chromium
2013/09/25 17:01:04
Is there a reason for this? We don't need the font
| |
171 | |
196 RefPtr<SkTypeface> face = CreateTypefaceFromHFont(hfont, &size, &paintTextFl ags); | 172 RefPtr<SkTypeface> face = CreateTypefaceFromHFont(hfont, &size, &paintTextFl ags); |
197 paintSkiaText(context, hfont, face.get(), size, paintTextFlags, numGlyphs, g lyphs, advances, offsets, origin, textRect); | 173 paintSkiaText(context, data, face.get(), size, paintTextFlags, numGlyphs, gl yphs, advances, offsets, origin, textRect); |
198 } | 174 } |
199 | 175 |
200 } // namespace WebCore | 176 } // namespace WebCore |
OLD | NEW |