OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "skia/ext/vector_platform_device_emf_win.h" | |
6 | |
7 #include <string> | |
vandebo (ex-Chrome)
2012/11/01 20:24:23
nit: string goes in second 3, and windows.h goes i
| |
5 #include <windows.h> | 8 #include <windows.h> |
6 | 9 |
7 #include "skia/ext/vector_platform_device_emf_win.h" | 10 #include "base/logging.h" |
8 | |
9 #include "skia/ext/bitmap_platform_device.h" | 11 #include "skia/ext/bitmap_platform_device.h" |
10 #include "skia/ext/skia_utils_win.h" | 12 #include "skia/ext/skia_utils_win.h" |
13 #include "third_party/skia/include/core/SkFontHost.h" | |
11 #include "third_party/skia/include/core/SkPathEffect.h" | 14 #include "third_party/skia/include/core/SkPathEffect.h" |
12 #include "third_party/skia/include/core/SkTemplates.h" | 15 #include "third_party/skia/include/core/SkTemplates.h" |
13 #include "third_party/skia/include/core/SkUtils.h" | 16 #include "third_party/skia/include/core/SkUtils.h" |
14 #include "third_party/skia/include/ports/SkTypeface_win.h" | 17 #include "third_party/skia/include/ports/SkTypeface_win.h" |
15 | 18 |
16 namespace skia { | 19 namespace skia { |
17 | 20 |
18 #define CHECK_FOR_NODRAW_ANNOTATION(paint) \ | 21 #define CHECK_FOR_NODRAW_ANNOTATION(paint) \ |
19 do { if (paint.isNoDrawAnnotation()) { return; } } while (0) | 22 do { if (paint.isNoDrawAnnotation()) { return; } } while (0) |
20 | 23 |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 // encoding is not UTF8 (in which case ExtTextOut can't be used). | 362 // encoding is not UTF8 (in which case ExtTextOut can't be used). |
360 static UINT getTextOutOptions(const SkPaint& paint) { | 363 static UINT getTextOutOptions(const SkPaint& paint) { |
361 if (SkPaint::kGlyphID_TextEncoding == paint.getTextEncoding()) { | 364 if (SkPaint::kGlyphID_TextEncoding == paint.getTextEncoding()) { |
362 return ETO_GLYPH_INDEX; | 365 return ETO_GLYPH_INDEX; |
363 } else { | 366 } else { |
364 SkASSERT(SkPaint::kUTF16_TextEncoding == paint.getTextEncoding()); | 367 SkASSERT(SkPaint::kUTF16_TextEncoding == paint.getTextEncoding()); |
365 return 0; | 368 return 0; |
366 } | 369 } |
367 } | 370 } |
368 | 371 |
372 bool EnsureExtTextOut(HDC hdc, int x, int y, UINT options, const RECT * lprect, | |
vandebo (ex-Chrome)
2012/11/01 20:24:23
lprect is always passed in as 0, omit it from this
| |
373 LPCWSTR text, unsigned int characters, const int * lpDx, | |
374 SkTypeface* const typeface) { | |
375 bool success = ExtTextOut(hdc, x, y, options, lprect, text, characters, lpDx); | |
376 if (!success) { | |
377 if (typeface) { | |
378 SkFontHost::EnsureTypefaceCharactersAccessible(*typeface, | |
vandebo (ex-Chrome)
2012/11/01 20:24:23
Maybe this should return a bool. If it didn't do
| |
379 text, | |
380 characters); | |
381 success = ExtTextOut(hdc, x, y, options, lprect, text, characters, lpDx); | |
382 if (!success) { | |
383 LOGFONT lf; | |
384 SkLOGFONTFromTypeface(typeface, &lf); | |
385 VLOG(1) << "SkFontHost::EnsureTypefaceCharactersAccessible FAILED for " | |
386 << " FaceName = " << lf.lfFaceName | |
387 << " and characters: " << std::wstring(text, characters); | |
388 } | |
389 } else { | |
390 VLOG(1) << "ExtTextOut FAILED for default FaceName " | |
391 << " and characters: " << std::wstring(text, characters); | |
392 } | |
393 } | |
394 return success; | |
395 } | |
396 | |
369 void VectorPlatformDeviceEmf::drawText(const SkDraw& draw, | 397 void VectorPlatformDeviceEmf::drawText(const SkDraw& draw, |
370 const void* text, | 398 const void* text, |
371 size_t byteLength, | 399 size_t byteLength, |
372 SkScalar x, | 400 SkScalar x, |
373 SkScalar y, | 401 SkScalar y, |
374 const SkPaint& paint) { | 402 const SkPaint& paint) { |
375 SkGDIFontSetup setup; | 403 SkGDIFontSetup setup; |
404 bool useDrawPath = true; | |
405 | |
376 if (SkPaint::kUTF8_TextEncoding != paint.getTextEncoding() | 406 if (SkPaint::kUTF8_TextEncoding != paint.getTextEncoding() |
377 && setup.useGDI(hdc_, paint)) { | 407 && setup.useGDI(hdc_, paint)) { |
378 UINT options = getTextOutOptions(paint); | 408 UINT options = getTextOutOptions(paint); |
379 UINT count = byteLength >> 1; | 409 UINT count = byteLength >> 1; |
380 ExtTextOut(hdc_, SkScalarRound(x), SkScalarRound(y + getAscent(paint)), | 410 useDrawPath = !EnsureExtTextOut(hdc_, SkScalarRound(x), |
381 options, 0, reinterpret_cast<const wchar_t*>(text), count, NULL); | 411 SkScalarRound(y + getAscent(paint)), options, 0, |
382 } else { | 412 reinterpret_cast<const wchar_t*>(text), count, NULL, |
413 paint.getTypeface()); | |
414 } | |
415 | |
416 if (useDrawPath) { | |
383 SkPath path; | 417 SkPath path; |
384 paint.getTextPath(text, byteLength, x, y, &path); | 418 paint.getTextPath(text, byteLength, x, y, &path); |
385 drawPath(draw, path, paint); | 419 drawPath(draw, path, paint); |
386 } | 420 } |
387 } | 421 } |
388 | 422 |
389 static size_t size_utf8(const char* text) { | 423 static size_t size_utf8(const char* text) { |
390 return SkUTF8_CountUTF8Bytes(text); | 424 return SkUTF8_CountUTF8Bytes(text); |
391 } | 425 } |
392 | 426 |
393 static size_t size_utf16(const char* text) { | 427 static size_t size_utf16(const char* text) { |
394 uint16_t c = *reinterpret_cast<const uint16_t*>(text); | 428 uint16_t c = *reinterpret_cast<const uint16_t*>(text); |
395 return SkUTF16_IsHighSurrogate(c) ? 4 : 2; | 429 return SkUTF16_IsHighSurrogate(c) ? 4 : 2; |
396 } | 430 } |
397 | 431 |
398 static size_t size_glyphid(const char* text) { | 432 static size_t size_glyphid(const char* text) { |
399 return 2; | 433 return 2; |
400 } | 434 } |
401 | 435 |
402 void VectorPlatformDeviceEmf::drawPosText(const SkDraw& draw, | 436 void VectorPlatformDeviceEmf::drawPosText(const SkDraw& draw, |
403 const void* text, | 437 const void* text, |
404 size_t len, | 438 size_t len, |
405 const SkScalar pos[], | 439 const SkScalar pos[], |
406 SkScalar constY, | 440 SkScalar constY, |
407 int scalarsPerPos, | 441 int scalarsPerPos, |
408 const SkPaint& paint) { | 442 const SkPaint& paint) { |
409 SkGDIFontSetup setup; | 443 SkGDIFontSetup setup; |
444 bool useDrawText = true; | |
445 | |
410 if (2 == scalarsPerPos | 446 if (2 == scalarsPerPos |
411 && SkPaint::kUTF8_TextEncoding != paint.getTextEncoding() | 447 && SkPaint::kUTF8_TextEncoding != paint.getTextEncoding() |
412 && setup.useGDI(hdc_, paint)) { | 448 && setup.useGDI(hdc_, paint)) { |
413 int startX = SkScalarRound(pos[0]); | 449 int startX = SkScalarRound(pos[0]); |
414 int startY = SkScalarRound(pos[1] + getAscent(paint)); | 450 int startY = SkScalarRound(pos[1] + getAscent(paint)); |
415 const int count = len >> 1; | 451 const int count = len >> 1; |
416 SkAutoSTMalloc<64, INT> storage(count); | 452 SkAutoSTMalloc<64, INT> storage(count); |
417 INT* advances = storage.get(); | 453 INT* advances = storage.get(); |
418 for (int i = 0; i < count - 1; ++i) { | 454 for (int i = 0; i < count - 1; ++i) { |
419 advances[i] = SkScalarRound(pos[2] - pos[0]); | 455 advances[i] = SkScalarRound(pos[2] - pos[0]); |
420 pos += 2; | 456 pos += 2; |
421 } | 457 } |
422 ExtTextOut(hdc_, startX, startY, getTextOutOptions(paint), 0, | 458 useDrawText = !EnsureExtTextOut(hdc_, startX, startY, |
423 reinterpret_cast<const wchar_t*>(text), count, advances); | 459 getTextOutOptions(paint), 0, reinterpret_cast<const wchar_t*>(text), |
424 } else { | 460 count, advances, paint.getTypeface()); |
461 } | |
462 | |
463 if (useDrawText) { | |
425 size_t (*bytesPerCodePoint)(const char*); | 464 size_t (*bytesPerCodePoint)(const char*); |
426 switch (paint.getTextEncoding()) { | 465 switch (paint.getTextEncoding()) { |
427 case SkPaint::kUTF8_TextEncoding: | 466 case SkPaint::kUTF8_TextEncoding: |
428 bytesPerCodePoint = size_utf8; | 467 bytesPerCodePoint = size_utf8; |
429 break; | 468 break; |
430 case SkPaint::kUTF16_TextEncoding: | 469 case SkPaint::kUTF16_TextEncoding: |
431 bytesPerCodePoint = size_utf16; | 470 bytesPerCodePoint = size_utf16; |
432 break; | 471 break; |
433 default: | 472 default: |
434 SkASSERT(SkPaint::kGlyphID_TextEncoding == paint.getTextEncoding()); | 473 SkASSERT(SkPaint::kGlyphID_TextEncoding == paint.getTextEncoding()); |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
865 pixels, | 904 pixels, |
866 reinterpret_cast<const BITMAPINFO*>(&hdr), | 905 reinterpret_cast<const BITMAPINFO*>(&hdr), |
867 DIB_RGB_COLORS, | 906 DIB_RGB_COLORS, |
868 SRCCOPY); | 907 SRCCOPY); |
869 } | 908 } |
870 EndPlatformPaint(); | 909 EndPlatformPaint(); |
871 Cleanup(); | 910 Cleanup(); |
872 } | 911 } |
873 | 912 |
874 } // namespace skia | 913 } // namespace skia |
OLD | NEW |