Chromium Code Reviews| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 | 79 |
| 80 | 80 |
| 81 static const unsigned cHarfBuzzCacheMaxSize = 256; | 81 static const unsigned cHarfBuzzCacheMaxSize = 256; |
| 82 | 82 |
| 83 struct CachedShapingResultsLRUNode; | 83 struct CachedShapingResultsLRUNode; |
| 84 struct CachedShapingResults; | 84 struct CachedShapingResults; |
| 85 typedef std::map<std::wstring, CachedShapingResults*> CachedShapingResultsMap; | 85 typedef std::map<std::wstring, CachedShapingResults*> CachedShapingResultsMap; |
| 86 typedef std::list<CachedShapingResultsLRUNode*> CachedShapingResultsLRU; | 86 typedef std::list<CachedShapingResultsLRUNode*> CachedShapingResultsLRU; |
| 87 | 87 |
| 88 struct CachedShapingResults { | 88 struct CachedShapingResults { |
| 89 CachedShapingResults(hb_buffer_t* harfBuzzBuffer, const Font* runFont, hb_di rection_t runDir); | 89 CachedShapingResults(hb_buffer_t* harfBuzzBuffer, const Font* runFont, hb_di rection_t runDir, hb_language_t newLocale); |
| 90 ~CachedShapingResults(); | 90 ~CachedShapingResults(); |
| 91 | 91 |
| 92 hb_buffer_t* buffer; | 92 hb_buffer_t* buffer; |
| 93 Font font; | 93 Font font; |
| 94 hb_direction_t dir; | 94 hb_direction_t dir; |
| 95 hb_language_t locale; | |
| 95 CachedShapingResultsLRU::iterator lru; | 96 CachedShapingResultsLRU::iterator lru; |
| 96 }; | 97 }; |
| 97 | 98 |
| 98 struct CachedShapingResultsLRUNode { | 99 struct CachedShapingResultsLRUNode { |
| 99 CachedShapingResultsLRUNode(const CachedShapingResultsMap::iterator& cacheEn try); | 100 CachedShapingResultsLRUNode(const CachedShapingResultsMap::iterator& cacheEn try); |
| 100 ~CachedShapingResultsLRUNode(); | 101 ~CachedShapingResultsLRUNode(); |
| 101 | 102 |
| 102 CachedShapingResultsMap::iterator entry; | 103 CachedShapingResultsMap::iterator entry; |
| 103 }; | 104 }; |
| 104 | 105 |
| 105 CachedShapingResults::CachedShapingResults(hb_buffer_t* harfBuzzBuffer, const Fo nt* fontData, hb_direction_t dirData) | 106 CachedShapingResults::CachedShapingResults(hb_buffer_t* harfBuzzBuffer, const Fo nt* fontData, hb_direction_t dirData, hb_language_t newLocale) |
| 106 : buffer(harfBuzzBuffer) | 107 : buffer(harfBuzzBuffer) |
| 107 , font(*fontData) | 108 , font(*fontData) |
| 108 , dir(dirData) | 109 , dir(dirData) |
| 110 , locale(newLocale) | |
| 109 { | 111 { |
| 110 } | 112 } |
| 111 | 113 |
| 112 CachedShapingResults::~CachedShapingResults() | 114 CachedShapingResults::~CachedShapingResults() |
| 113 { | 115 { |
| 114 hb_buffer_destroy(buffer); | 116 hb_buffer_destroy(buffer); |
| 115 } | 117 } |
| 116 | 118 |
| 117 CachedShapingResultsLRUNode::CachedShapingResultsLRUNode(const CachedShapingResu ltsMap::iterator& cacheEntry) | 119 CachedShapingResultsLRUNode::CachedShapingResultsLRUNode(const CachedShapingResu ltsMap::iterator& cacheEntry) |
| 118 : entry(cacheEntry) | 120 : entry(cacheEntry) |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 785 // a copy of the string. | 787 // a copy of the string. |
| 786 COMPILE_ASSERT(sizeof(UChar) == sizeof(uint16_t), UChar_is_the_same_size_as_ uint16_t); | 788 COMPILE_ASSERT(sizeof(UChar) == sizeof(uint16_t), UChar_is_the_same_size_as_ uint16_t); |
| 787 return reinterpret_cast<const uint16_t*>(src); | 789 return reinterpret_cast<const uint16_t*>(src); |
| 788 } | 790 } |
| 789 | 791 |
| 790 bool HarfBuzzShaper::shapeHarfBuzzRuns() | 792 bool HarfBuzzShaper::shapeHarfBuzzRuns() |
| 791 { | 793 { |
| 792 HarfBuzzScopedPtr<hb_buffer_t> harfBuzzBuffer(hb_buffer_create(), hb_buffer_ destroy); | 794 HarfBuzzScopedPtr<hb_buffer_t> harfBuzzBuffer(hb_buffer_create(), hb_buffer_ destroy); |
| 793 | 795 |
| 794 HarfBuzzRunCache& runCache = harfBuzzRunCache(); | 796 HarfBuzzRunCache& runCache = harfBuzzRunCache(); |
| 797 const hb_language_t localeStr = m_font->fontDescription().locale(); | |
|
Inactive
2014/05/22 13:52:02
no longer needs to be const if you update the gett
| |
| 795 | 798 |
| 796 for (unsigned i = 0; i < m_harfBuzzRuns.size(); ++i) { | 799 for (unsigned i = 0; i < m_harfBuzzRuns.size(); ++i) { |
| 797 unsigned runIndex = m_run.rtl() ? m_harfBuzzRuns.size() - i - 1 : i; | 800 unsigned runIndex = m_run.rtl() ? m_harfBuzzRuns.size() - i - 1 : i; |
| 798 HarfBuzzRun* currentRun = m_harfBuzzRuns[runIndex].get(); | 801 HarfBuzzRun* currentRun = m_harfBuzzRuns[runIndex].get(); |
| 799 const SimpleFontData* currentFontData = currentRun->fontData(); | 802 const SimpleFontData* currentFontData = currentRun->fontData(); |
| 800 if (currentFontData->isSVGFont()) | 803 if (currentFontData->isSVGFont()) |
| 801 return false; | 804 return false; |
| 802 | 805 |
| 803 FontPlatformData* platformData = const_cast<FontPlatformData*>(¤tF ontData->platformData()); | 806 FontPlatformData* platformData = const_cast<FontPlatformData*>(¤tF ontData->platformData()); |
| 804 HarfBuzzFace* face = platformData->harfBuzzFace(); | 807 HarfBuzzFace* face = platformData->harfBuzzFace(); |
| 805 if (!face) | 808 if (!face) |
| 806 return false; | 809 return false; |
| 807 | 810 hb_buffer_set_language(harfBuzzBuffer.get(), localeStr); |
| 808 hb_buffer_set_script(harfBuzzBuffer.get(), currentRun->script()); | 811 hb_buffer_set_script(harfBuzzBuffer.get(), currentRun->script()); |
| 809 hb_buffer_set_direction(harfBuzzBuffer.get(), currentRun->rtl() ? HB_DIR ECTION_RTL : HB_DIRECTION_LTR); | 812 hb_buffer_set_direction(harfBuzzBuffer.get(), currentRun->rtl() ? HB_DIR ECTION_RTL : HB_DIRECTION_LTR); |
| 810 | 813 |
| 811 hb_segment_properties_t props; | 814 hb_segment_properties_t props; |
| 812 hb_buffer_get_segment_properties(harfBuzzBuffer.get(), &props); | 815 hb_buffer_get_segment_properties(harfBuzzBuffer.get(), &props); |
| 813 | 816 |
| 814 const UChar* src = m_normalizedBuffer.get() + currentRun->startIndex(); | 817 const UChar* src = m_normalizedBuffer.get() + currentRun->startIndex(); |
| 815 std::wstring key(src, src + currentRun->numCharacters()); | 818 std::wstring key(src, src + currentRun->numCharacters()); |
| 816 | 819 |
| 817 CachedShapingResults* cachedResults = runCache.find(key); | 820 CachedShapingResults* cachedResults = runCache.find(key); |
| 818 if (cachedResults) { | 821 if (cachedResults) { |
| 819 if (cachedResults->dir == props.direction && cachedResults->font == *m_font) { | 822 if (cachedResults->dir == props.direction && cachedResults->font == *m_font && cachedResults->locale == localeStr) { |
| 820 currentRun->applyShapeResult(cachedResults->buffer); | 823 currentRun->applyShapeResult(cachedResults->buffer); |
| 821 setGlyphPositionsForHarfBuzzRun(currentRun, cachedResults->buffe r); | 824 setGlyphPositionsForHarfBuzzRun(currentRun, cachedResults->buffe r); |
| 822 | 825 |
| 823 hb_buffer_clear_contents(harfBuzzBuffer.get()); | 826 hb_buffer_clear_contents(harfBuzzBuffer.get()); |
| 824 | 827 |
| 825 runCache.moveToBack(cachedResults); | 828 runCache.moveToBack(cachedResults); |
| 826 | 829 |
| 827 continue; | 830 continue; |
| 828 } | 831 } |
| 829 | 832 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 845 | 848 |
| 846 if (m_font->fontDescription().orientation() == Vertical) | 849 if (m_font->fontDescription().orientation() == Vertical) |
| 847 face->setScriptForVerticalGlyphSubstitution(harfBuzzBuffer.get()); | 850 face->setScriptForVerticalGlyphSubstitution(harfBuzzBuffer.get()); |
| 848 | 851 |
| 849 HarfBuzzScopedPtr<hb_font_t> harfBuzzFont(face->createFont(), hb_font_de stroy); | 852 HarfBuzzScopedPtr<hb_font_t> harfBuzzFont(face->createFont(), hb_font_de stroy); |
| 850 | 853 |
| 851 hb_shape(harfBuzzFont.get(), harfBuzzBuffer.get(), m_features.isEmpty() ? 0 : m_features.data(), m_features.size()); | 854 hb_shape(harfBuzzFont.get(), harfBuzzBuffer.get(), m_features.isEmpty() ? 0 : m_features.data(), m_features.size()); |
| 852 currentRun->applyShapeResult(harfBuzzBuffer.get()); | 855 currentRun->applyShapeResult(harfBuzzBuffer.get()); |
| 853 setGlyphPositionsForHarfBuzzRun(currentRun, harfBuzzBuffer.get()); | 856 setGlyphPositionsForHarfBuzzRun(currentRun, harfBuzzBuffer.get()); |
| 854 | 857 |
| 855 runCache.insert(key, new CachedShapingResults(harfBuzzBuffer.get(), m_fo nt, props.direction)); | 858 runCache.insert(key, new CachedShapingResults(harfBuzzBuffer.get(), m_fo nt, props.direction, localeStr)); |
| 856 | 859 |
| 857 harfBuzzBuffer.set(hb_buffer_create()); | 860 harfBuzzBuffer.set(hb_buffer_create()); |
| 858 } | 861 } |
| 859 | 862 |
| 860 return true; | 863 return true; |
| 861 } | 864 } |
| 862 | 865 |
| 863 void HarfBuzzShaper::setGlyphPositionsForHarfBuzzRun(HarfBuzzRun* currentRun, hb _buffer_t* harfBuzzBuffer) | 866 void HarfBuzzShaper::setGlyphPositionsForHarfBuzzRun(HarfBuzzRun* currentRun, hb _buffer_t* harfBuzzBuffer) |
| 864 { | 867 { |
| 865 const SimpleFontData* currentFontData = currentRun->fontData(); | 868 const SimpleFontData* currentFontData = currentRun->fontData(); |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1116 point.x() + fromX, point.x() + toX, | 1119 point.x() + fromX, point.x() + toX, |
| 1117 point.y(), height); | 1120 point.y(), height); |
| 1118 } | 1121 } |
| 1119 | 1122 |
| 1120 return Font::pixelSnappedSelectionRect( | 1123 return Font::pixelSnappedSelectionRect( |
| 1121 point.x() + toX, point.x() + fromX, | 1124 point.x() + toX, point.x() + fromX, |
| 1122 point.y(), height); | 1125 point.y(), height); |
| 1123 } | 1126 } |
| 1124 | 1127 |
| 1125 } // namespace WebCore | 1128 } // namespace WebCore |
| OLD | NEW |