OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 Google Inc. All rights reserved. | 2 * Copyright (c) 2012 Google Inc. All rights reserved. |
3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. | 3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 m_features.append(feature); | 535 m_features.append(feature); |
536 } | 536 } |
537 } | 537 } |
538 | 538 |
539 bool HarfBuzzShaper::shape(GlyphBuffer* glyphBuffer) | 539 bool HarfBuzzShaper::shape(GlyphBuffer* glyphBuffer) |
540 { | 540 { |
541 if (!collectHarfBuzzRuns()) | 541 if (!collectHarfBuzzRuns()) |
542 return false; | 542 return false; |
543 | 543 |
544 m_totalWidth = 0; | 544 m_totalWidth = 0; |
545 // WebKit doesn't set direction when calulating widths. Leave the direction
setting to | 545 if (!shapeHarfBuzzRuns()) |
546 // HarfBuzz when we are calculating widths (except when directionalOverride(
) is set). | |
547 if (!shapeHarfBuzzRuns(glyphBuffer || m_run.directionalOverride())) | |
548 return false; | 546 return false; |
549 | 547 |
550 if (!RuntimeEnabledFeatures::subpixelFontScalingEnabled()) | 548 if (!RuntimeEnabledFeatures::subpixelFontScalingEnabled()) |
551 m_totalWidth = roundf(m_totalWidth); | 549 m_totalWidth = roundf(m_totalWidth); |
552 | 550 |
553 if (glyphBuffer && !fillGlyphBuffer(glyphBuffer)) | 551 if (glyphBuffer && !fillGlyphBuffer(glyphBuffer)) |
554 return false; | 552 return false; |
555 | 553 |
556 return true; | 554 return true; |
557 } | 555 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 | 625 |
628 static const uint16_t* toUint16(const UChar* src) | 626 static const uint16_t* toUint16(const UChar* src) |
629 { | 627 { |
630 // FIXME: This relies on undefined behavior however it works on the | 628 // FIXME: This relies on undefined behavior however it works on the |
631 // current versions of all compilers we care about and avoids making | 629 // current versions of all compilers we care about and avoids making |
632 // a copy of the string. | 630 // a copy of the string. |
633 COMPILE_ASSERT(sizeof(UChar) == sizeof(uint16_t), UChar_is_the_same_size_as_
uint16_t); | 631 COMPILE_ASSERT(sizeof(UChar) == sizeof(uint16_t), UChar_is_the_same_size_as_
uint16_t); |
634 return reinterpret_cast<const uint16_t*>(src); | 632 return reinterpret_cast<const uint16_t*>(src); |
635 } | 633 } |
636 | 634 |
637 bool HarfBuzzShaper::shapeHarfBuzzRuns(bool shouldSetDirection) | 635 bool HarfBuzzShaper::shapeHarfBuzzRuns() |
638 { | 636 { |
639 HarfBuzzScopedPtr<hb_buffer_t> harfBuzzBuffer(hb_buffer_create(), hb_buffer_
destroy); | 637 HarfBuzzScopedPtr<hb_buffer_t> harfBuzzBuffer(hb_buffer_create(), hb_buffer_
destroy); |
640 | 638 |
641 hb_buffer_set_unicode_funcs(harfBuzzBuffer.get(), hb_icu_get_unicode_funcs()
); | 639 hb_buffer_set_unicode_funcs(harfBuzzBuffer.get(), hb_icu_get_unicode_funcs()
); |
642 HarfBuzzRunCache& runCache = harfBuzzRunCache(); | 640 HarfBuzzRunCache& runCache = harfBuzzRunCache(); |
643 | 641 |
644 for (unsigned i = 0; i < m_harfBuzzRuns.size(); ++i) { | 642 for (unsigned i = 0; i < m_harfBuzzRuns.size(); ++i) { |
645 unsigned runIndex = m_run.rtl() ? m_harfBuzzRuns.size() - i - 1 : i; | 643 unsigned runIndex = m_run.rtl() ? m_harfBuzzRuns.size() - i - 1 : i; |
646 HarfBuzzRun* currentRun = m_harfBuzzRuns[runIndex].get(); | 644 HarfBuzzRun* currentRun = m_harfBuzzRuns[runIndex].get(); |
647 const SimpleFontData* currentFontData = currentRun->fontData(); | 645 const SimpleFontData* currentFontData = currentRun->fontData(); |
648 if (currentFontData->isSVGFont()) | 646 if (currentFontData->isSVGFont()) |
649 return false; | 647 return false; |
650 | 648 |
651 FontPlatformData* platformData = const_cast<FontPlatformData*>(¤tF
ontData->platformData()); | 649 FontPlatformData* platformData = const_cast<FontPlatformData*>(¤tF
ontData->platformData()); |
652 HarfBuzzFace* face = platformData->harfBuzzFace(); | 650 HarfBuzzFace* face = platformData->harfBuzzFace(); |
653 if (!face) | 651 if (!face) |
654 return false; | 652 return false; |
655 | 653 |
656 hb_buffer_set_script(harfBuzzBuffer.get(), currentRun->script()); | 654 hb_buffer_set_script(harfBuzzBuffer.get(), currentRun->script()); |
657 if (shouldSetDirection) | 655 hb_buffer_set_direction(harfBuzzBuffer.get(), currentRun->rtl() ? HB_DIR
ECTION_RTL : HB_DIRECTION_LTR); |
658 hb_buffer_set_direction(harfBuzzBuffer.get(), currentRun->rtl() ? HB
_DIRECTION_RTL : HB_DIRECTION_LTR); | |
659 else | |
660 // Leaving direction to HarfBuzz to guess is *really* bad, but will
do for now. | |
661 hb_buffer_guess_segment_properties(harfBuzzBuffer.get()); | |
662 | 656 |
663 hb_segment_properties_t props; | 657 hb_segment_properties_t props; |
664 hb_buffer_get_segment_properties(harfBuzzBuffer.get(), &props); | 658 hb_buffer_get_segment_properties(harfBuzzBuffer.get(), &props); |
665 | 659 |
666 const UChar* src = m_normalizedBuffer.get() + currentRun->startIndex(); | 660 const UChar* src = m_normalizedBuffer.get() + currentRun->startIndex(); |
667 std::wstring key(src, src + currentRun->numCharacters()); | 661 std::wstring key(src, src + currentRun->numCharacters()); |
668 | 662 |
669 CachedShapingResults* cachedResults = runCache.find(key); | 663 CachedShapingResults* cachedResults = runCache.find(key); |
670 if (cachedResults) { | 664 if (cachedResults) { |
671 if (cachedResults->dir == props.direction && cachedResults->font ==
*m_font) { | 665 if (cachedResults->dir == props.direction && cachedResults->font ==
*m_font) { |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 if (!foundToX) | 880 if (!foundToX) |
887 toX = m_run.rtl() ? 0 : m_totalWidth; | 881 toX = m_run.rtl() ? 0 : m_totalWidth; |
888 | 882 |
889 // Using floorf() and roundf() as the same as mac port. | 883 // Using floorf() and roundf() as the same as mac port. |
890 if (fromX < toX) | 884 if (fromX < toX) |
891 return FloatRect(floorf(point.x() + fromX), point.y(), roundf(toX - from
X), height); | 885 return FloatRect(floorf(point.x() + fromX), point.y(), roundf(toX - from
X), height); |
892 return FloatRect(floorf(point.x() + toX), point.y(), roundf(fromX - toX), he
ight); | 886 return FloatRect(floorf(point.x() + toX), point.y(), roundf(fromX - toX), he
ight); |
893 } | 887 } |
894 | 888 |
895 } // namespace WebCore | 889 } // namespace WebCore |
OLD | NEW |