Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2008, 2009, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, 2009, 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 15 matching lines...) Expand all Loading... | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/platform/graphics/SimpleFontData.h" | 32 #include "core/platform/graphics/SimpleFontData.h" |
| 33 | 33 |
| 34 #include <unicode/normlzr.h> | 34 #include <unicode/normlzr.h> |
| 35 #include "SkPaint.h" | 35 #include "SkPaint.h" |
| 36 #include "SkPath.h" | |
| 36 #include "SkTypeface.h" | 37 #include "SkTypeface.h" |
| 37 #include "SkTypes.h" | 38 #include "SkTypes.h" |
| 38 #include "core/platform/graphics/FloatRect.h" | 39 #include "core/platform/graphics/FloatRect.h" |
| 39 #include "core/platform/graphics/FontDescription.h" | 40 #include "core/platform/graphics/FontDescription.h" |
| 40 #include "core/platform/graphics/chromium/VDMXParser.h" | 41 #include "core/platform/graphics/chromium/VDMXParser.h" |
| 41 #include "wtf/unicode/Unicode.h" | 42 #include "wtf/unicode/Unicode.h" |
| 42 | 43 |
| 43 #if OS(WIN) | 44 #if OS(WIN) |
| 44 #include "core/platform/win/HWndDC.h" | 45 #include "core/platform/win/HWndDC.h" |
| 45 #endif | 46 #endif |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 } | 207 } |
| 207 | 208 |
| 208 return true; | 209 return true; |
| 209 } | 210 } |
| 210 | 211 |
| 211 void SimpleFontData::determinePitch() | 212 void SimpleFontData::determinePitch() |
| 212 { | 213 { |
| 213 m_treatAsFixedPitch = platformData().isFixedPitch(); | 214 m_treatAsFixedPitch = platformData().isFixedPitch(); |
| 214 } | 215 } |
| 215 | 216 |
| 217 static inline void getSkiaBoundsForGlyph(SkPaint& paint, Glyph glyph, SkRect& bo unds) | |
| 218 { | |
| 219 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | |
| 220 | |
| 221 SkPath path; | |
| 222 paint.getTextPath(&glyph, sizeof(glyph), 0, 0, &path); | |
| 223 bounds = path.getBounds(); | |
| 224 | |
| 225 // FIXME(eae): getBounds currently returns an empty rect for bitmap | |
| 226 // fonts so fall back on the old behavior. Once fixed in Skia this | |
| 227 // fallback can go away. | |
|
leviw_travelin_and_unemployed
2013/09/30 22:47:00
Is there a crbug for this? If not please file.
| |
| 228 if (bounds.isEmpty()) | |
| 229 paint.measureText(&glyph, 2, &bounds); | |
| 230 | |
| 231 if (!paint.isSubpixelText()) { | |
| 232 SkIRect ir; | |
| 233 bounds.round(&ir); | |
| 234 bounds.set(ir); | |
| 235 } | |
| 236 } | |
| 237 | |
| 216 FloatRect SimpleFontData::platformBoundsForGlyph(Glyph glyph) const | 238 FloatRect SimpleFontData::platformBoundsForGlyph(Glyph glyph) const |
| 217 { | 239 { |
| 218 if (!m_platformData.size()) | 240 if (!m_platformData.size()) |
| 219 return FloatRect(); | 241 return FloatRect(); |
| 220 | 242 |
| 221 SkASSERT(sizeof(glyph) == 2); // compile-time assert | 243 SkASSERT(sizeof(glyph) == 2); // compile-time assert |
| 222 | 244 |
| 223 SkPaint paint; | 245 SkPaint paint; |
| 224 | |
| 225 m_platformData.setupPaint(&paint); | 246 m_platformData.setupPaint(&paint); |
| 226 | 247 |
| 227 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | |
| 228 SkRect bounds; | 248 SkRect bounds; |
| 229 paint.measureText(&glyph, 2, &bounds); | 249 getSkiaBoundsForGlyph(paint, glyph, bounds); |
| 230 if (!paint.isSubpixelText()) { | |
| 231 SkIRect ir; | |
| 232 bounds.round(&ir); | |
| 233 bounds.set(ir); | |
| 234 } | |
| 235 return FloatRect(bounds); | 250 return FloatRect(bounds); |
| 236 } | 251 } |
| 237 | 252 |
| 238 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const | 253 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const |
| 239 { | 254 { |
| 240 if (!m_platformData.size()) | 255 if (!m_platformData.size()) |
| 241 return 0; | 256 return 0; |
| 242 | 257 |
| 243 SkASSERT(sizeof(glyph) == 2); // compile-time assert | 258 SkASSERT(sizeof(glyph) == 2); // compile-time assert |
| 244 | 259 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 275 paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); | 290 paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); |
| 276 if (paint.textToGlyphs(&normalizedCharacters[0], normalizedLength * 2, 0)) { | 291 if (paint.textToGlyphs(&normalizedCharacters[0], normalizedLength * 2, 0)) { |
| 277 addResult.iterator->value = true; | 292 addResult.iterator->value = true; |
| 278 return true; | 293 return true; |
| 279 } | 294 } |
| 280 return false; | 295 return false; |
| 281 } | 296 } |
| 282 #endif | 297 #endif |
| 283 | 298 |
| 284 } // namespace WebCore | 299 } // namespace WebCore |
| OLD | NEW |