@@ -8,8 +8,12 @@ namespace textlayout {
88namespace {
99 SkScalar relax (SkScalar a) {
1010 // This rounding is done to match Flutter tests. Must be removed..
11- auto threshold = SkIntToScalar (1 << 12 );
12- return SkScalarRoundToScalar (a * threshold)/threshold;
11+ if (SkScalarIsFinite (a)) {
12+ auto threshold = SkIntToScalar (1 << 12 );
13+ return SkScalarRoundToScalar (a * threshold)/threshold;
14+ } else {
15+ return a;
16+ }
1317 }
1418}
1519
@@ -31,19 +35,15 @@ class ParagraphCacheValue {
3135public:
3236 ParagraphCacheValue (const ParagraphImpl* paragraph)
3337 : fKey (ParagraphCacheKey(paragraph))
34- , fInternalState (paragraph->fState )
3538 , fRuns (paragraph->fRuns )
36- , fClusters (paragraph->fClusters )
37- , fUnresolvedGlyphs (paragraph->fUnresolvedGlyphs ){ }
39+ , fClusters (paragraph->fClusters ) { }
3840
3941 // Input == key
4042 ParagraphCacheKey fKey ;
4143
42- // Shaped results:
43- InternalState fInternalState ;
44+ // Shaped results
4445 SkTArray<Run, false > fRuns ;
4546 SkTArray<Cluster, true > fClusters ;
46- size_t fUnresolvedGlyphs ;
4747};
4848
4949uint32_t ParagraphCache::KeyHash::mix (uint32_t hash, uint32_t data) const {
@@ -56,21 +56,20 @@ uint32_t ParagraphCache::KeyHash::mix(uint32_t hash, uint32_t data) const {
5656uint32_t ParagraphCache::KeyHash::operator ()(const ParagraphCacheKey& key) const {
5757 uint32_t hash = 0 ;
5858 for (auto & ph : key.fPlaceholders ) {
59- if (&ph == &key.fPlaceholders .back ()) {
60- // Skip the last "dummy" placeholder
61- break ;
59+ if (ph.fRange .width () == 0 ) {
60+ continue ;
6261 }
6362 hash = mix (hash, SkGoodHash ()(ph.fRange .start ));
6463 hash = mix (hash, SkGoodHash ()(ph.fRange .end ));
65- hash = mix (hash, SkGoodHash ()(relax (ph.fStyle .fBaselineOffset )));
66- hash = mix (hash, SkGoodHash ()(ph.fStyle .fBaseline ));
64+ hash = mix (hash, SkGoodHash ()(relax (ph.fStyle .fHeight )));
65+ hash = mix (hash, SkGoodHash ()(relax ( ph.fStyle .fWidth ) ));
6766 hash = mix (hash, SkGoodHash ()(ph.fStyle .fAlignment ));
67+ hash = mix (hash, SkGoodHash ()(ph.fStyle .fBaseline ));
6868 if (ph.fStyle .fAlignment == PlaceholderAlignment::kBaseline ) {
6969 hash = mix (hash, SkGoodHash ()(relax (ph.fStyle .fBaselineOffset )));
7070 }
71- hash = mix (hash, SkGoodHash ()(relax (ph.fStyle .fHeight )));
72- hash = mix (hash, SkGoodHash ()(relax (ph.fStyle .fWidth )));
7371 }
72+
7473 for (auto & ts : key.fTextStyles ) {
7574 if (ts.fStyle .isPlaceholder ()) {
7675 continue ;
@@ -79,22 +78,34 @@ uint32_t ParagraphCache::KeyHash::operator()(const ParagraphCacheKey& key) const
7978 hash = mix (hash, SkGoodHash ()(relax (ts.fStyle .getWordSpacing ())));
8079 hash = mix (hash, SkGoodHash ()(ts.fStyle .getLocale ()));
8180 hash = mix (hash, SkGoodHash ()(relax (ts.fStyle .getHeight ())));
82- hash = mix (hash, SkGoodHash ()(ts.fRange ));
8381 for (auto & ff : ts.fStyle .getFontFamilies ()) {
8482 hash = mix (hash, SkGoodHash ()(ff));
8583 }
8684 for (auto & ff : ts.fStyle .getFontFeatures ()) {
87- hash = mix (hash, SkGoodHash ()(ff));
85+ hash = mix (hash, SkGoodHash ()(ff.fValue ));
86+ hash = mix (hash, SkGoodHash ()(ff.fName ));
8887 }
8988 hash = mix (hash, SkGoodHash ()(ts.fStyle .getFontStyle ()));
9089 hash = mix (hash, SkGoodHash ()(relax (ts.fStyle .getFontSize ())));
91- hash = mix (hash, SkGoodHash ()(ts.fRange .start ));
92- hash = mix (hash, SkGoodHash ()(ts.fRange .end ));
90+ hash = mix (hash, SkGoodHash ()(ts.fRange ));
9391 }
9492
9593 hash = mix (hash, SkGoodHash ()(relax (key.fParagraphStyle .getHeight ())));
9694 hash = mix (hash, SkGoodHash ()(key.fParagraphStyle .getTextDirection ()));
9795
96+ auto & strutStyle = key.fParagraphStyle .getStrutStyle ();
97+ if (strutStyle.getStrutEnabled ()) {
98+ hash = mix (hash, SkGoodHash ()(relax (strutStyle.getHeight ())));
99+ hash = mix (hash, SkGoodHash ()(relax (strutStyle.getLeading ())));
100+ hash = mix (hash, SkGoodHash ()(relax (strutStyle.getFontSize ())));
101+ hash = mix (hash, SkGoodHash ()(strutStyle.getHeightOverride ()));
102+ hash = mix (hash, SkGoodHash ()(strutStyle.getFontStyle ()));
103+ hash = mix (hash, SkGoodHash ()(strutStyle.getForceStrutHeight ()));
104+ for (auto & ff : strutStyle.getFontFamilies ()) {
105+ hash = mix (hash, SkGoodHash ()(ff));
106+ }
107+ }
108+
98109 hash = mix (hash, SkGoodHash ()(key.fText ));
99110 return hash;
100111}
@@ -114,13 +125,17 @@ bool operator==(const ParagraphCacheKey& a, const ParagraphCacheKey& b) {
114125 }
115126
116127 // There is no need to compare default paragraph styles - they are included into fTextStyles
117- if (!SkScalarNearlyEqual (a.fParagraphStyle .getHeight (), b.fParagraphStyle .getHeight ())) {
128+ if (!nearlyEqual (a.fParagraphStyle .getHeight (), b.fParagraphStyle .getHeight ())) {
118129 return false ;
119130 }
120131 if (a.fParagraphStyle .getTextDirection () != b.fParagraphStyle .getTextDirection ()) {
121132 return false ;
122133 }
123134
135+ if (!(a.fParagraphStyle .getStrutStyle () == b.fParagraphStyle .getStrutStyle ())) {
136+ return false ;
137+ }
138+
124139 for (size_t i = 0 ; i < a.fTextStyles .size (); ++i) {
125140 auto & tsa = a.fTextStyles [i];
126141 auto & tsb = b.fTextStyles [i];
@@ -137,9 +152,12 @@ bool operator==(const ParagraphCacheKey& a, const ParagraphCacheKey& b) {
137152 return false ;
138153 }
139154 }
140- for (size_t i = 0 ; i < a.fPlaceholders .size () - 1 ; ++i) {
155+ for (size_t i = 0 ; i < a.fPlaceholders .size (); ++i) {
141156 auto & tsa = a.fPlaceholders [i];
142157 auto & tsb = b.fPlaceholders [i];
158+ if (tsa.fRange .width () == 0 && tsb.fRange .width () == 0 ) {
159+ continue ;
160+ }
143161 if (!(tsa.fStyle .equals (tsb.fStyle ))) {
144162 return false ;
145163 }
@@ -175,7 +193,6 @@ ParagraphCache::~ParagraphCache() { }
175193
176194void ParagraphCache::updateFrom (const ParagraphImpl* paragraph, Entry* entry) {
177195
178- entry->fValue ->fInternalState = paragraph->state ();
179196 for (size_t i = 0 ; i < paragraph->fRuns .size (); ++i) {
180197 auto & run = paragraph->fRuns [i];
181198 if (run.fSpaced ) {
@@ -185,6 +202,7 @@ void ParagraphCache::updateFrom(const ParagraphImpl* paragraph, Entry* entry) {
185202}
186203
187204void ParagraphCache::updateTo (ParagraphImpl* paragraph, const Entry* entry) {
205+
188206 paragraph->fRuns .reset ();
189207 paragraph->fRuns = entry->fValue ->fRuns ;
190208 for (auto & run : paragraph->fRuns ) {
@@ -197,8 +215,7 @@ void ParagraphCache::updateTo(ParagraphImpl* paragraph, const Entry* entry) {
197215 cluster.setMaster (paragraph);
198216 }
199217
200- paragraph->fState = entry->fValue ->fInternalState ;
201- paragraph->fUnresolvedGlyphs = entry->fValue ->fUnresolvedGlyphs ;
218+ paragraph->fState = kMarked ;
202219}
203220
204221void ParagraphCache::printStatistics () {
0 commit comments