OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007 Apple 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include <windows.h> | 27 #include <windows.h> |
28 | 28 |
29 #include "ChromiumBridge.h" | 29 #include "ChromiumBridge.h" |
30 #include "Font.h" | 30 #include "Font.h" |
31 #include "FontFallbackList.h" | 31 #include "FontFallbackList.h" |
32 #include "GlyphBuffer.h" | 32 #include "GlyphBuffer.h" |
33 #include "PlatformContextSkia.h" | 33 #include "PlatformContextSkia.h" |
34 #include "SimpleFontData.h" | 34 #include "SimpleFontData.h" |
35 #include "UniscribeStateTextRun.h" | 35 #include "UniscribeHelperTextRun.h" |
36 | 36 |
37 #include "base/gfx/platform_canvas_win.h" | 37 #include "base/gfx/platform_canvas_win.h" |
38 #include "base/gfx/skia_utils.h" | 38 #include "base/gfx/skia_utils.h" |
39 #include "graphics/SkiaUtils.h" | 39 #include "graphics/SkiaUtils.h" |
40 | 40 |
41 | 41 |
42 namespace WebCore { | 42 namespace WebCore { |
43 | 43 |
44 void Font::drawGlyphs(GraphicsContext* graphicsContext, | 44 void Font::drawGlyphs(GraphicsContext* graphicsContext, |
45 const SimpleFontData* font, | 45 const SimpleFontData* font, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 SelectObject(hdc, oldFont); | 127 SelectObject(hdc, oldFont); |
128 context->canvas()->endPlatformPaint(); | 128 context->canvas()->endPlatformPaint(); |
129 } | 129 } |
130 | 130 |
131 FloatRect Font::selectionRectForComplexText(const TextRun& run, | 131 FloatRect Font::selectionRectForComplexText(const TextRun& run, |
132 const IntPoint& point, | 132 const IntPoint& point, |
133 int h, | 133 int h, |
134 int from, | 134 int from, |
135 int to) const | 135 int to) const |
136 { | 136 { |
137 UniscribeStateTextRun state(run, *this); | 137 UniscribeHelperTextRun state(run, *this); |
138 float left = static_cast<float>(point.x() + state.CharacterToX(from)); | 138 float left = static_cast<float>(point.x() + state.CharacterToX(from)); |
139 float right = static_cast<float>(point.x() + state.CharacterToX(to)); | 139 float right = static_cast<float>(point.x() + state.CharacterToX(to)); |
140 | 140 |
141 // If the text is RTL, left will actually be after right. | 141 // If the text is RTL, left will actually be after right. |
142 if (left < right) { | 142 if (left < right) { |
143 return FloatRect(left, static_cast<float>(point.y()), | 143 return FloatRect(left, static_cast<float>(point.y()), |
144 right - left, static_cast<float>(h)); | 144 right - left, static_cast<float>(h)); |
145 } | 145 } |
146 return FloatRect(right, static_cast<float>(point.y()), | 146 return FloatRect(right, static_cast<float>(point.y()), |
147 left - right, static_cast<float>(h)); | 147 left - right, static_cast<float>(h)); |
148 } | 148 } |
149 | 149 |
150 void Font::drawComplexText(GraphicsContext* graphicsContext, | 150 void Font::drawComplexText(GraphicsContext* graphicsContext, |
151 const TextRun& run, | 151 const TextRun& run, |
152 const FloatPoint& point, | 152 const FloatPoint& point, |
153 int from, | 153 int from, |
154 int to) const | 154 int to) const |
155 { | 155 { |
156 PlatformGraphicsContext* context = graphicsContext->platformContext(); | 156 PlatformGraphicsContext* context = graphicsContext->platformContext(); |
157 UniscribeStateTextRun state(run, *this); | 157 UniscribeHelperTextRun state(run, *this); |
158 | 158 |
159 SkColor color = context->fillColor(); | 159 SkColor color = context->fillColor(); |
160 uint8 alpha = SkColorGetA(color); | 160 uint8 alpha = SkColorGetA(color); |
161 // Skip 100% transparent text; no need to draw anything. | 161 // Skip 100% transparent text; no need to draw anything. |
162 if (!alpha) | 162 if (!alpha) |
163 return; | 163 return; |
164 | 164 |
165 HDC hdc = context->canvas()->beginPlatformPaint(); | 165 HDC hdc = context->canvas()->beginPlatformPaint(); |
166 | 166 |
167 // TODO(maruel): http://b/700464 SetTextColor doesn't support transparency. | 167 // TODO(maruel): http://b/700464 SetTextColor doesn't support transparency. |
168 // Enforce non-transparent color. | 168 // Enforce non-transparent color. |
169 color = SkColorSetRGB(SkColorGetR(color), | 169 color = SkColorSetRGB(SkColorGetR(color), |
170 SkColorGetG(color), | 170 SkColorGetG(color), |
171 SkColorGetB(color)); | 171 SkColorGetB(color)); |
172 SetTextColor(hdc, gfx::SkColorToCOLORREF(color)); | 172 SetTextColor(hdc, gfx::SkColorToCOLORREF(color)); |
173 SetBkMode(hdc, TRANSPARENT); | 173 SetBkMode(hdc, TRANSPARENT); |
174 | 174 |
175 // Uniscribe counts the coordinates from the upper left, while WebKit uses | 175 // Uniscribe counts the coordinates from the upper left, while WebKit uses |
176 // the baseline, so we have to subtract off the ascent. | 176 // the baseline, so we have to subtract off the ascent. |
177 state.Draw(hdc, | 177 state.Draw(hdc, |
178 static_cast<int>(point.x()), | 178 static_cast<int>(point.x()), |
179 static_cast<int>(point.y() - ascent()), | 179 static_cast<int>(point.y() - ascent()), |
180 from, | 180 from, |
181 to); | 181 to); |
182 context->canvas()->endPlatformPaint(); | 182 context->canvas()->endPlatformPaint(); |
183 } | 183 } |
184 | 184 |
185 float Font::floatWidthForComplexText(const TextRun& run) const | 185 float Font::floatWidthForComplexText(const TextRun& run) const |
186 { | 186 { |
187 UniscribeStateTextRun state(run, *this); | 187 UniscribeHelperTextRun state(run, *this); |
188 return static_cast<float>(state.Width()); | 188 return static_cast<float>(state.Width()); |
189 } | 189 } |
190 | 190 |
191 int Font::offsetForPositionForComplexText(const TextRun& run, int x, bool includ
ePartialGlyphs) const | 191 int Font::offsetForPositionForComplexText(const TextRun& run, int x, |
| 192 bool includePartialGlyphs) const |
192 { | 193 { |
193 // Mac code ignores includePartialGlyphs, and they don't know what it's | 194 // Mac code ignores includePartialGlyphs, and they don't know what it's |
194 // supposed to do, so we just ignore it as well. | 195 // supposed to do, so we just ignore it as well. |
195 UniscribeStateTextRun state(run, *this); | 196 UniscribeHelperTextRun state(run, *this); |
196 int char_index = state.XToCharacter(x); | 197 int char_index = state.XToCharacter(x); |
197 | 198 |
198 // XToCharacter will return -1 if the position is before the first | 199 // XToCharacter will return -1 if the position is before the first |
199 // character (we get called like this sometimes). | 200 // character (we get called like this sometimes). |
200 if (char_index < 0) | 201 if (char_index < 0) |
201 char_index = 0; | 202 char_index = 0; |
202 return char_index; | 203 return char_index; |
203 } | 204 } |
204 | 205 |
205 } // namespace WebCore | 206 } // namespace WebCore |
OLD | NEW |