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); |
| 105 |
| 106 // FIXME: Only needed to support the HFONT based paintSkiaText |
| 107 // version where a new typeface is created from the HFONT. |
| 108 // As such it can go away once the direct-GDI code path is removed. |
| 109 #if ENABLE(GDI_FONTS_ON_WINDOWS) |
| 110 paint.setTypeface(face); |
| 111 #endif |
135 | 112 |
136 bool didFill = false; | 113 bool didFill = false; |
137 | 114 |
138 if ((textMode & TextModeFill) && (SkColorGetA(paint.getColor()) || paint.get
Looper())) { | 115 if ((textMode & TextModeFill) && (SkColorGetA(paint.getColor()) || paint.get
Looper())) { |
139 skiaDrawText(context, origin, textRect, &paint, &glyphs[0], &advances[0]
, &offsets[0], numGlyphs); | 116 skiaDrawText(context, origin, textRect, &paint, &glyphs[0], &advances[0]
, &offsets[0], numGlyphs); |
140 didFill = true; | 117 didFill = true; |
141 } | 118 } |
142 | 119 |
143 // Stroking on top (if necessary). | 120 // Stroking on top (if necessary). |
144 if ((textMode & TextModeStroke) | 121 if ((textMode & TextModeStroke) |
145 && context->strokeStyle() != NoStroke | 122 && context->strokeStyle() != NoStroke |
146 && context->strokeThickness() > 0) { | 123 && context->strokeThickness() > 0) { |
147 | 124 |
148 paint.reset(); | 125 paint.reset(); |
149 context->setupPaintForStroking(&paint); | 126 context->setupPaintForStroking(&paint); |
150 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 127 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
151 setupPaintForFont(&paint, context, face, size, textFlags); | 128 data.setupPaint(&paint, context); |
| 129 #if ENABLE(GDI_FONTS_ON_WINDOWS) |
| 130 paint.setTypeface(face); |
| 131 #endif |
152 | 132 |
153 if (didFill) { | 133 if (didFill) { |
154 // If there is a shadow and we filled above, there will already be | 134 // 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 | 135 // 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. | 136 // and it will go on top of the fill. |
157 // | 137 // |
158 // Note that this isn't strictly correct, since the stroke could be | 138 // 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" | 139 // 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 | 140 // 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 | 141 // with a shadow. But this is a lot of extra work for something |
162 // that isn't normally an issue. | 142 // that isn't normally an issue. |
163 paint.setLooper(0); | 143 paint.setLooper(0); |
164 } | 144 } |
165 | 145 |
166 skiaDrawText(context, origin, textRect, &paint, &glyphs[0], &advances[0]
, &offsets[0], numGlyphs); | 146 skiaDrawText(context, origin, textRect, &paint, &glyphs[0], &advances[0]
, &offsets[0], numGlyphs); |
167 } | 147 } |
168 } | 148 } |
169 | 149 |
170 ////////////////////////////////////////////////////////////////////////////////
/////////// | 150 ////////////////////////////////////////////////////////////////////////////////
/////////// |
171 | 151 |
172 void paintSkiaText(GraphicsContext* context, | 152 void paintSkiaText(GraphicsContext* context, |
173 const FontPlatformData& data, | 153 const FontPlatformData& data, |
174 int numGlyphs, | 154 int numGlyphs, |
175 const WORD* glyphs, | 155 const WORD* glyphs, |
176 const int* advances, | 156 const int* advances, |
177 const GOFFSET* offsets, | 157 const GOFFSET* offsets, |
178 const SkPoint& origin, | 158 const SkPoint& origin, |
179 const SkRect& textRect) | 159 const SkRect& textRect) |
180 { | 160 { |
181 paintSkiaText(context, data.hfont(), data.typeface(), data.size(), data.pain
tTextFlags(), | 161 paintSkiaText(context, data, data.typeface(), data.size(), data.paintTextFla
gs(), |
182 numGlyphs, glyphs, advances, offsets, origin, textRect); | 162 numGlyphs, glyphs, advances, offsets, origin, textRect); |
183 } | 163 } |
184 | 164 |
185 void paintSkiaText(GraphicsContext* context, | 165 void paintSkiaText(GraphicsContext* context, |
186 HFONT hfont, | 166 const FontPlatformData& data, |
187 int numGlyphs, | 167 HFONT hfont, |
188 const WORD* glyphs, | 168 int numGlyphs, |
189 const int* advances, | 169 const WORD* glyphs, |
190 const GOFFSET* offsets, | 170 const int* advances, |
191 const SkPoint& origin, | 171 const GOFFSET* offsets, |
192 const SkRect& textRect) | 172 const SkPoint& origin, |
| 173 const SkRect& textRect) |
193 { | 174 { |
194 int size; | 175 int size; |
195 int paintTextFlags; | 176 int paintTextFlags; |
| 177 |
| 178 // Ensure font load for printing, because PDF device needs it. |
| 179 if (context->isPrintingDevice()) |
| 180 FontPlatformData::ensureFontLoaded(hfont); |
| 181 |
196 RefPtr<SkTypeface> face = CreateTypefaceFromHFont(hfont, &size, &paintTextFl
ags); | 182 RefPtr<SkTypeface> face = CreateTypefaceFromHFont(hfont, &size, &paintTextFl
ags); |
197 paintSkiaText(context, hfont, face.get(), size, paintTextFlags, numGlyphs, g
lyphs, advances, offsets, origin, textRect); | 183 paintSkiaText(context, data, face.get(), size, paintTextFlags, numGlyphs, gl
yphs, advances, offsets, origin, textRect); |
198 } | 184 } |
199 | 185 |
200 } // namespace WebCore | 186 } // namespace WebCore |
OLD | NEW |