Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 1 | // Copyright 2019 Google LLC. |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 2 | #include "modules/skparagraph/src/ParagraphImpl.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 3 | #include "modules/skparagraph/src/TextWrapper.h" |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 4 | |
| 5 | namespace skia { |
| 6 | namespace textlayout { |
| 7 | |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 8 | namespace { |
| 9 | SkScalar littleRound(SkScalar a) { |
| 10 | // This rounding is done to match Flutter tests. Must be removed.. |
| 11 | return SkScalarRoundToScalar(a * 100.0)/100.0; |
| 12 | } |
| 13 | } |
| 14 | |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 15 | // Since we allow cluster clipping when they don't fit |
| 16 | // we have to work with stretches - parts of clusters |
| 17 | void TextWrapper::lookAhead(SkScalar maxWidth, Cluster* endOfClusters) { |
| 18 | fWords.startFrom(fEndLine.startCluster(), fEndLine.startPos()); |
| 19 | fClusters.startFrom(fEndLine.startCluster(), fEndLine.startPos()); |
| 20 | fClip.startFrom(fEndLine.startCluster(), fEndLine.startPos()); |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 21 | |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 22 | for (auto cluster = fEndLine.endCluster(); cluster < endOfClusters; ++cluster) { |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 23 | // TODO: Trying to deal with flutter rounding problem. Must be removed... |
| 24 | auto width = fWords.width() + fClusters.width() + cluster->width(); |
| 25 | auto roundedWidth = littleRound(width); |
| 26 | if (cluster->isHardBreak()) { |
| 27 | } else if (maxWidth == 0.0f) { |
| 28 | // Do nothing |
| 29 | } else if (roundedWidth > maxWidth) { |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 30 | if (cluster->isWhitespaces()) { |
Julia Lavrova | 6e6333f | 2019-06-17 10:34:10 -0400 | [diff] [blame] | 31 | // It's the end of the word |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 32 | fClusters.extend(cluster); |
Julia Lavrova | 6e6333f | 2019-06-17 10:34:10 -0400 | [diff] [blame] | 33 | fMinIntrinsicWidth = SkTMax(fMinIntrinsicWidth, getClustersTrimmedWidth()); |
| 34 | fWords.extend(fClusters); |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 35 | break; |
| 36 | } |
| 37 | if (cluster->width() > maxWidth) { |
Julia Lavrova | 90bfd1c | 2019-12-04 11:43:32 -0500 | [diff] [blame^] | 38 | fClusters.extend(cluster); |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 39 | fTooLongCluster = true; |
| 40 | fTooLongWord = true; |
| 41 | break; |
| 42 | } |
| 43 | |
| 44 | // Walk further to see if there is a too long word, cluster or glyph |
| 45 | SkScalar nextWordLength = fClusters.width(); |
| 46 | for (auto further = cluster; further != endOfClusters; ++further) { |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 47 | if (further->isSoftBreak() || further->isHardBreak() || further->isWhitespaces()) { |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 48 | break; |
| 49 | } |
| 50 | nextWordLength += further->width(); |
| 51 | } |
| 52 | if (nextWordLength > maxWidth) { |
| 53 | // If the word is too long we can break it right now and hope it's enough |
Julia Lavrova | 90bfd1c | 2019-12-04 11:43:32 -0500 | [diff] [blame^] | 54 | fMinIntrinsicWidth = SkTMax(fMinIntrinsicWidth, nextWordLength); |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 55 | fTooLongWord = true; |
| 56 | } |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 57 | break; |
| 58 | } |
| 59 | |
| 60 | fClusters.extend(cluster); |
| 61 | |
| 62 | // Keep adding clusters/words |
| 63 | if (fClusters.endOfWord()) { |
| 64 | fMinIntrinsicWidth = SkTMax(fMinIntrinsicWidth, getClustersTrimmedWidth()); |
| 65 | fWords.extend(fClusters); |
| 66 | } |
| 67 | |
| 68 | if ((fHardLineBreak = cluster->isHardBreak())) { |
| 69 | // Stop at the hard line break |
| 70 | break; |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | void TextWrapper::moveForward() { |
| 76 | do { |
| 77 | if (fWords.width() > 0) { |
| 78 | fEndLine.extend(fWords); |
| 79 | } else if (fClusters.width() > 0) { |
| 80 | fEndLine.extend(fClusters); |
| 81 | fTooLongWord = false; |
Julia Lavrova | 90bfd1c | 2019-12-04 11:43:32 -0500 | [diff] [blame^] | 82 | fTooLongCluster = false; |
Julia Lavrova | 2e30fde | 2019-10-09 09:43:02 -0400 | [diff] [blame] | 83 | } else if (fClip.width() > 0 || (fTooLongWord && fTooLongCluster)) { |
Julia Lavrova | 90bfd1c | 2019-12-04 11:43:32 -0500 | [diff] [blame^] | 84 | // Flutter: forget the clipped cluster but keep the metrics |
| 85 | fEndLine.metrics().add(fClip.metrics()); |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 86 | fTooLongWord = false; |
| 87 | fTooLongCluster = false; |
| 88 | } else { |
| 89 | break; |
| 90 | } |
| 91 | } while (fTooLongWord || fTooLongCluster); |
| 92 | } |
| 93 | |
| 94 | // Special case for start/end cluster since they can be clipped |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 95 | void TextWrapper::trimEndSpaces(TextAlign align) { |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 96 | // Remember the breaking position |
| 97 | fEndLine.saveBreak(); |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 98 | // Skip all space cluster at the end |
| 99 | //bool left = align == TextAlign::kStart || align == TextAlign::kLeft; |
| 100 | bool right = align == TextAlign::kRight || align == TextAlign::kEnd; |
Julia Lavrova | 6e6333f | 2019-06-17 10:34:10 -0400 | [diff] [blame] | 101 | for (auto cluster = fEndLine.endCluster(); |
| 102 | cluster >= fEndLine.startCluster() && cluster->isWhitespaces(); |
| 103 | --cluster) { |
Julia Lavrova | 526df26 | 2019-08-21 17:49:44 -0400 | [diff] [blame] | 104 | if ((cluster->run()->leftToRight()) || |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 105 | (right && !cluster->run()->leftToRight()) || |
| 106 | align == TextAlign::kJustify || align == TextAlign::kCenter) { |
| 107 | fEndLine.trim(cluster); |
| 108 | continue; |
| 109 | } else { |
| 110 | break; |
| 111 | } |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 112 | } |
Julia Lavrova | 2e30fde | 2019-10-09 09:43:02 -0400 | [diff] [blame] | 113 | fEndLine.trim(); |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | SkScalar TextWrapper::getClustersTrimmedWidth() { |
| 117 | // Move the end of the line to the left |
| 118 | SkScalar width = fClusters.width(); |
| 119 | auto cluster = fClusters.endCluster(); |
| 120 | for (; cluster > fClusters.startCluster() && cluster->isWhitespaces(); --cluster) { |
| 121 | width -= cluster->width(); |
| 122 | } |
| 123 | if (cluster >= fClusters.startCluster()) { |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 124 | if (cluster->isWhitespaces()) { |
| 125 | width -= cluster->width(); |
| 126 | } else { |
| 127 | width -= (cluster->width() - cluster->trimmedWidth(cluster->endPos())); |
| 128 | } |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 129 | } |
| 130 | return width; |
| 131 | } |
| 132 | |
| 133 | // Trim the beginning spaces in case of soft line break |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 134 | std::tuple<Cluster*, size_t, SkScalar> TextWrapper::trimStartSpaces(Cluster* endOfClusters) { |
| 135 | |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 136 | if (fHardLineBreak) { |
| 137 | // End of line is always end of cluster, but need to skip \n |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 138 | auto width = fEndLine.width(); |
| 139 | auto cluster = fEndLine.endCluster() + 1; |
| 140 | while (cluster < fEndLine.breakCluster() && cluster->isWhitespaces()) { |
| 141 | width += cluster->width(); |
| 142 | ++cluster; |
| 143 | } |
Julia Lavrova | af89d39 | 2019-08-09 15:19:26 -0400 | [diff] [blame] | 144 | return std::make_tuple(fEndLine.breakCluster() + 1, 0, width); |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 145 | } |
| 146 | |
Julia Lavrova | c222856 | 2019-08-08 16:51:27 -0400 | [diff] [blame] | 147 | auto width = fEndLine.withWithGhostSpaces(); //fEndLine.width(); |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 148 | auto cluster = fEndLine.breakCluster() + 1; |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 149 | while (cluster < endOfClusters && cluster->isWhitespaces()) { |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 150 | width += cluster->width(); |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 151 | ++cluster; |
| 152 | } |
Julia Lavrova | af89d39 | 2019-08-09 15:19:26 -0400 | [diff] [blame] | 153 | return std::make_tuple(cluster, 0, width); |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | void TextWrapper::breakTextIntoLines(ParagraphImpl* parent, |
| 157 | SkScalar maxWidth, |
| 158 | const AddLineToParagraph& addLine) { |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 159 | fHeight = 0; |
Julia Lavrova | 90bfd1c | 2019-12-04 11:43:32 -0500 | [diff] [blame^] | 160 | fMinIntrinsicWidth = std::numeric_limits<SkScalar>::min(); |
| 161 | fMaxIntrinsicWidth = std::numeric_limits<SkScalar>::min(); |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 162 | |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 163 | auto span = parent->clusters(); |
Julia Lavrova | 526df26 | 2019-08-21 17:49:44 -0400 | [diff] [blame] | 164 | if (span.size() == 0) { |
| 165 | return; |
| 166 | } |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 167 | auto maxLines = parent->paragraphStyle().getMaxLines(); |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 168 | auto& ellipsisStr = parent->paragraphStyle().getEllipsis(); |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 169 | auto align = parent->paragraphStyle().effective_align(); |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 170 | |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 171 | SkScalar softLineMaxIntrinsicWidth = 0; |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 172 | fEndLine = TextStretch(span.begin(), span.begin(), parent->strutForceHeight()); |
| 173 | auto end = span.end() - 1; |
| 174 | auto start = span.begin(); |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 175 | InternalLineMetrics maxRunMetrics; |
| 176 | auto needEllipsis = false; |
| 177 | auto endlessLine = maxLines == std::numeric_limits<size_t>::max(); |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 178 | while (fEndLine.endCluster() != end) { |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 179 | |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 180 | reset(); |
| 181 | |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 182 | fEndLine.metrics().clean(); |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 183 | lookAhead(maxWidth, end); |
| 184 | moveForward(); |
| 185 | |
| 186 | // Do not trim end spaces on the naturally last line of the left aligned text |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 187 | trimEndSpaces(align); |
| 188 | |
| 189 | // For soft line breaks add to the line all the spaces next to it |
| 190 | Cluster* startLine; |
| 191 | size_t pos; |
| 192 | SkScalar widthWithSpaces; |
| 193 | std::tie(startLine, pos, widthWithSpaces) = trimStartSpaces(end); |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 194 | |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 195 | needEllipsis = |
| 196 | fEndLine.endCluster() < end - 1 && |
| 197 | SkScalarIsFinite(maxWidth) && |
| 198 | !ellipsisStr.isEmpty(); |
| 199 | |
| 200 | auto exceededLines = !endlessLine && fLineNumber >= maxLines; |
| 201 | |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 202 | // TODO: perform ellipsis work here |
Julia Lavrova | 916a904 | 2019-08-08 16:51:27 -0400 | [diff] [blame] | 203 | |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 204 | // If the line is empty with the hard line break, let's take the paragraph font (flutter???) |
| 205 | if (fHardLineBreak && fEndLine.width() == 0) { |
Jason Simmons | 22bb52e | 2019-12-05 17:56:59 -0800 | [diff] [blame] | 206 | fEndLine.setMetrics(parent->getEmptyMetrics()); |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 207 | } |
| 208 | |
Julia Lavrova | 916a904 | 2019-08-08 16:51:27 -0400 | [diff] [blame] | 209 | // Deal with placeholder clusters == runs[@size==1] |
| 210 | for (auto cluster = fEndLine.startCluster(); cluster <= fEndLine.endCluster(); ++cluster) { |
| 211 | if (cluster->run()->placeholder() != nullptr) { |
| 212 | SkASSERT(cluster->run()->size() == 1); |
| 213 | // Update the placeholder metrics so we can get the placeholder positions later |
| 214 | // and the line metrics (to make sure the placeholder fits) |
| 215 | cluster->run()->updateMetrics(&fEndLine.metrics()); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | // Before we update the line metrics with struts, |
| 220 | // let's save it for GetRectsForRange(RectHeightStyle::kMax) |
| 221 | maxRunMetrics = fEndLine.metrics(); |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 222 | maxRunMetrics.fForceStrut = false; |
Julia Lavrova | 916a904 | 2019-08-08 16:51:27 -0400 | [diff] [blame] | 223 | |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 224 | if (parent->strutEnabled()) { |
| 225 | // Make sure font metrics are not less than the strut |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 226 | parent->strutMetrics().updateLineMetrics(fEndLine.metrics()); |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 227 | } |
Julia Lavrova | 916a904 | 2019-08-08 16:51:27 -0400 | [diff] [blame] | 228 | |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 229 | // TODO: keep start/end/break info for text and runs but in a better way that below |
Julia Lavrova | 526df26 | 2019-08-21 17:49:44 -0400 | [diff] [blame] | 230 | TextRange text(fEndLine.startCluster()->textRange().start, fEndLine.endCluster()->textRange().end); |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 231 | TextRange textWithSpaces(fEndLine.startCluster()->textRange().start, startLine->textRange().start); |
Julia Lavrova | 2e30fde | 2019-10-09 09:43:02 -0400 | [diff] [blame] | 232 | if (startLine == end) { |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 233 | textWithSpaces.end = parent->text().size(); |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 234 | } |
Julia Lavrova | c222856 | 2019-08-08 16:51:27 -0400 | [diff] [blame] | 235 | ClusterRange clusters(fEndLine.startCluster() - start, fEndLine.endCluster() - start + 1); |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 236 | ClusterRange clustersWithGhosts(fEndLine.startCluster() - start, startLine - start); |
| 237 | addLine(text, textWithSpaces, clusters, clustersWithGhosts, widthWithSpaces, |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 238 | fEndLine.startPos(), |
| 239 | fEndLine.endPos(), |
| 240 | SkVector::Make(0, fHeight), |
| 241 | SkVector::Make(fEndLine.width(), fEndLine.metrics().height()), |
| 242 | fEndLine.metrics(), |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 243 | needEllipsis && exceededLines && !fHardLineBreak); |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 244 | |
Julia Lavrova | 916a904 | 2019-08-08 16:51:27 -0400 | [diff] [blame] | 245 | parent->lines().back().setMaxRunMetrics(maxRunMetrics); |
| 246 | |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 247 | softLineMaxIntrinsicWidth += widthWithSpaces; |
| 248 | fMaxIntrinsicWidth = SkMaxScalar(fMaxIntrinsicWidth, softLineMaxIntrinsicWidth); |
| 249 | if (fHardLineBreak) { |
| 250 | softLineMaxIntrinsicWidth = 0; |
| 251 | } |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 252 | // Start a new line |
| 253 | fHeight += fEndLine.metrics().height(); |
Julia Lavrova | 916a904 | 2019-08-08 16:51:27 -0400 | [diff] [blame] | 254 | if (!fHardLineBreak || startLine != end) { |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 255 | fEndLine.clean(); |
| 256 | } |
| 257 | fEndLine.startFrom(startLine, pos); |
| 258 | parent->fMaxWidthWithTrailingSpaces = SkMaxScalar(parent->fMaxWidthWithTrailingSpaces, widthWithSpaces); |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 259 | |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 260 | if (exceededLines || (needEllipsis && endlessLine && !fHardLineBreak)) { |
| 261 | fHardLineBreak = false; |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 262 | break; |
| 263 | } |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 264 | |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 265 | ++fLineNumber; |
| 266 | } |
| 267 | |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 268 | // We finished formatting the text but we need to scan the rest for some numbers |
Julia Lavrova | 90bfd1c | 2019-12-04 11:43:32 -0500 | [diff] [blame^] | 269 | if (fEndLine.breakCluster() != nullptr) { |
| 270 | auto lastWordLength = 0.0f; |
| 271 | auto cluster = fEndLine.breakCluster(); |
| 272 | if (cluster != end) { |
| 273 | ++cluster; |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 274 | } |
Julia Lavrova | 90bfd1c | 2019-12-04 11:43:32 -0500 | [diff] [blame^] | 275 | while (cluster != end || cluster->endPos() < end->endPos()) { |
| 276 | fExceededMaxLines = true; |
| 277 | if (cluster->isHardBreak()) { |
| 278 | fMaxIntrinsicWidth = SkTMax(fMaxIntrinsicWidth, softLineMaxIntrinsicWidth); |
| 279 | softLineMaxIntrinsicWidth = 0; |
| 280 | |
| 281 | fMinIntrinsicWidth = SkTMax(fMinIntrinsicWidth, lastWordLength); |
| 282 | lastWordLength = 0; |
| 283 | } else if (cluster->isWhitespaces()) { |
| 284 | SkASSERT(cluster->isWhitespaces()); |
| 285 | softLineMaxIntrinsicWidth += cluster->width(); |
| 286 | fMinIntrinsicWidth = SkTMax(fMinIntrinsicWidth, lastWordLength); |
| 287 | lastWordLength = 0; |
| 288 | } else { |
| 289 | softLineMaxIntrinsicWidth += cluster->width(); |
| 290 | lastWordLength += cluster->width(); |
| 291 | } |
| 292 | ++cluster; |
| 293 | } |
| 294 | fMinIntrinsicWidth = SkTMax(fMinIntrinsicWidth, lastWordLength); |
| 295 | fMaxIntrinsicWidth = SkTMax(fMaxIntrinsicWidth, softLineMaxIntrinsicWidth); |
| 296 | // In case we could not place a single cluster on the line |
| 297 | fHeight = SkTMax(fHeight, fEndLine.metrics().height()); |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 298 | } |
| 299 | |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 300 | if (fHardLineBreak) { |
Julia Lavrova | 916a904 | 2019-08-08 16:51:27 -0400 | [diff] [blame] | 301 | |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 302 | // Last character is a line break |
| 303 | if (parent->strutEnabled()) { |
| 304 | // Make sure font metrics are not less than the strut |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 305 | parent->strutMetrics().updateLineMetrics(fEndLine.metrics()); |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 306 | } |
Julia Lavrova | 5207f35 | 2019-06-21 12:22:32 -0400 | [diff] [blame] | 307 | TextRange empty(fEndLine.breakCluster()->textRange().start, fEndLine.breakCluster()->textRange().start); |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 308 | TextRange hardBreak(fEndLine.breakCluster()->textRange().end, fEndLine.breakCluster()->textRange().end); |
Julia Lavrova | 526df26 | 2019-08-21 17:49:44 -0400 | [diff] [blame] | 309 | ClusterRange clusters(fEndLine.breakCluster() - start, fEndLine.endCluster() - start); |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 310 | addLine(empty, hardBreak, clusters, clusters, |
| 311 | 0, |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 312 | 0, |
| 313 | 0, |
| 314 | SkVector::Make(0, fHeight), |
| 315 | SkVector::Make(0, fEndLine.metrics().height()), |
| 316 | fEndLine.metrics(), |
Julia Lavrova | f3ed273 | 2019-09-05 14:35:17 -0400 | [diff] [blame] | 317 | needEllipsis); |
| 318 | fHeight += fEndLine.metrics().height(); |
Julia Lavrova | 916a904 | 2019-08-08 16:51:27 -0400 | [diff] [blame] | 319 | parent->lines().back().setMaxRunMetrics(maxRunMetrics); |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | |
| 323 | } // namespace textlayout |
| 324 | } // namespace skia |