Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: Source/platform/fonts/harfbuzz/HarfBuzzShaper.cpp

Issue 276573010: Adding Locale (language attribute) information to font and using the (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Comment fix and reverting to Old code Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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, CString newLocale);
Inactive 2014/05/23 19:34:26 You really don't want to copy a CString (passed by
h.joshi 2014/05/24 01:27:00 Okey, did that after the previous comment related
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 CString locale;
Inactive 2014/05/23 19:34:26 String
h.joshi 2014/05/24 01:27:00 ditto
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, CString newLocale)
Inactive 2014/05/23 19:34:26 const String&
h.joshi 2014/05/24 01:27:00 ditto
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
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 CString locale = m_font->fontDescription().locale().latin1();
Inactive 2014/05/23 19:34:26 You should probably store m_font->fontDescription(
h.joshi 2014/05/24 01:27:00 Okey, will be making String related changes.
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*>(&currentF ontData->platformData()); 806 FontPlatformData* platformData = const_cast<FontPlatformData*>(&currentF 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
811 hb_buffer_set_language(harfBuzzBuffer.get(), hb_language_from_string(loc ale.data(), locale.length()));
808 hb_buffer_set_script(harfBuzzBuffer.get(), currentRun->script()); 812 hb_buffer_set_script(harfBuzzBuffer.get(), currentRun->script());
809 hb_buffer_set_direction(harfBuzzBuffer.get(), currentRun->rtl() ? HB_DIR ECTION_RTL : HB_DIRECTION_LTR); 813 hb_buffer_set_direction(harfBuzzBuffer.get(), currentRun->rtl() ? HB_DIR ECTION_RTL : HB_DIRECTION_LTR);
810 814
811 hb_segment_properties_t props; 815 hb_segment_properties_t props;
812 hb_buffer_get_segment_properties(harfBuzzBuffer.get(), &props); 816 hb_buffer_get_segment_properties(harfBuzzBuffer.get(), &props);
813 817
814 const UChar* src = m_normalizedBuffer.get() + currentRun->startIndex(); 818 const UChar* src = m_normalizedBuffer.get() + currentRun->startIndex();
815 std::wstring key(src, src + currentRun->numCharacters()); 819 std::wstring key(src, src + currentRun->numCharacters());
816 820
817 CachedShapingResults* cachedResults = runCache.find(key); 821 CachedShapingResults* cachedResults = runCache.find(key);
818 if (cachedResults) { 822 if (cachedResults) {
819 if (cachedResults->dir == props.direction && cachedResults->font == *m_font) { 823 if (cachedResults->dir == props.direction && cachedResults->font == *m_font && cachedResults->locale == locale) {
Inactive 2014/05/23 19:34:26 Compare Strings here.
820 currentRun->applyShapeResult(cachedResults->buffer); 824 currentRun->applyShapeResult(cachedResults->buffer);
821 setGlyphPositionsForHarfBuzzRun(currentRun, cachedResults->buffe r); 825 setGlyphPositionsForHarfBuzzRun(currentRun, cachedResults->buffe r);
822 826
823 hb_buffer_clear_contents(harfBuzzBuffer.get()); 827 hb_buffer_clear_contents(harfBuzzBuffer.get());
824 828
825 runCache.moveToBack(cachedResults); 829 runCache.moveToBack(cachedResults);
826 830
827 continue; 831 continue;
828 } 832 }
829 833
(...skipping 15 matching lines...) Expand all
845 849
846 if (m_font->fontDescription().orientation() == Vertical) 850 if (m_font->fontDescription().orientation() == Vertical)
847 face->setScriptForVerticalGlyphSubstitution(harfBuzzBuffer.get()); 851 face->setScriptForVerticalGlyphSubstitution(harfBuzzBuffer.get());
848 852
849 HarfBuzzScopedPtr<hb_font_t> harfBuzzFont(face->createFont(), hb_font_de stroy); 853 HarfBuzzScopedPtr<hb_font_t> harfBuzzFont(face->createFont(), hb_font_de stroy);
850 854
851 hb_shape(harfBuzzFont.get(), harfBuzzBuffer.get(), m_features.isEmpty() ? 0 : m_features.data(), m_features.size()); 855 hb_shape(harfBuzzFont.get(), harfBuzzBuffer.get(), m_features.isEmpty() ? 0 : m_features.data(), m_features.size());
852 currentRun->applyShapeResult(harfBuzzBuffer.get()); 856 currentRun->applyShapeResult(harfBuzzBuffer.get());
853 setGlyphPositionsForHarfBuzzRun(currentRun, harfBuzzBuffer.get()); 857 setGlyphPositionsForHarfBuzzRun(currentRun, harfBuzzBuffer.get());
854 858
855 runCache.insert(key, new CachedShapingResults(harfBuzzBuffer.get(), m_fo nt, props.direction)); 859 runCache.insert(key, new CachedShapingResults(harfBuzzBuffer.get(), m_fo nt, props.direction, locale));
Inactive 2014/05/23 19:34:26 Pass String here.
h.joshi 2014/05/24 01:27:00 ditto
856 860
857 harfBuzzBuffer.set(hb_buffer_create()); 861 harfBuzzBuffer.set(hb_buffer_create());
858 } 862 }
859 863
860 return true; 864 return true;
861 } 865 }
862 866
863 void HarfBuzzShaper::setGlyphPositionsForHarfBuzzRun(HarfBuzzRun* currentRun, hb _buffer_t* harfBuzzBuffer) 867 void HarfBuzzShaper::setGlyphPositionsForHarfBuzzRun(HarfBuzzRun* currentRun, hb _buffer_t* harfBuzzBuffer)
864 { 868 {
865 const SimpleFontData* currentFontData = currentRun->fontData(); 869 const SimpleFontData* currentFontData = currentRun->fontData();
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 point.x() + fromX, point.x() + toX, 1120 point.x() + fromX, point.x() + toX,
1117 point.y(), height); 1121 point.y(), height);
1118 } 1122 }
1119 1123
1120 return Font::pixelSnappedSelectionRect( 1124 return Font::pixelSnappedSelectionRect(
1121 point.x() + toX, point.x() + fromX, 1125 point.x() + toX, point.x() + fromX,
1122 point.y(), height); 1126 point.y(), height);
1123 } 1127 }
1124 1128
1125 } // namespace WebCore 1129 } // namespace WebCore
OLDNEW
« Source/platform/fonts/FontDescription.cpp ('K') | « Source/platform/fonts/FontDescription.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698