OLD | NEW |
1 /* | 1 /* |
2 * (C) 1999 Lars Knoll (knoll@kde.org) | 2 * (C) 1999 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv
ed. | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv
ed. |
4 * Copyright (C) 2007-2009 Torch Mobile, Inc. | 4 * Copyright (C) 2007-2009 Torch Mobile, Inc. |
5 * Copyright (C) 2011 Google Inc. All rights reserved. | 5 * Copyright (C) 2011 Google Inc. All rights reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 return i > pos && U16_IS_TRAIL(ch) ? i - 1 : i; | 218 return i > pos && U16_IS_TRAIL(ch) ? i - 1 : i; |
219 lastIsLetterOrNumber = isLetterOrNumber; | 219 lastIsLetterOrNumber = isLetterOrNumber; |
220 } | 220 } |
221 | 221 |
222 lastLastCh = lastCh; | 222 lastLastCh = lastCh; |
223 lastCh = ch; | 223 lastCh = ch; |
224 } | 224 } |
225 return len; | 225 return len; |
226 } | 226 } |
227 | 227 |
| 228 static inline bool shouldKeepAfter(UChar lastCh, UChar ch, UChar nextCh) |
| 229 { |
| 230 UChar preCh = U_MASK(u_charType(ch)) & U_GC_M_MASK ? lastCh : ch; |
| 231 return U_MASK(u_charType(preCh)) & (U_GC_L_MASK | U_GC_N_MASK) |
| 232 && !WTF::Unicode::hasLineBreakingPropertyComplexContext(preCh) |
| 233 && U_MASK(u_charType(nextCh)) & (U_GC_L_MASK | U_GC_N_MASK) |
| 234 && !WTF::Unicode::hasLineBreakingPropertyComplexContext(nextCh); |
| 235 } |
| 236 |
| 237 static inline int nextBreakablePositionKeepAllInternal(LazyLineBreakIterator& la
zyBreakIterator, const UChar* str, unsigned length, int pos) |
| 238 { |
| 239 int len = static_cast<int>(length); |
| 240 int nextBreak = -1; |
| 241 |
| 242 UChar lastLastCh = pos > 1 ? str[pos - 2] : static_cast<UChar>(lazyBreakIter
ator.secondToLastCharacter()); |
| 243 UChar lastCh = pos > 0 ? str[pos - 1] : static_cast<UChar>(lazyBreakIterator
.lastCharacter()); |
| 244 unsigned priorContextLength = lazyBreakIterator.priorContextLength(); |
| 245 for (int i = pos; i < len; i++) { |
| 246 UChar ch = str[i]; |
| 247 |
| 248 if (isBreakableSpace(ch) || shouldBreakAfter(lastLastCh, lastCh, ch)) |
| 249 return i; |
| 250 |
| 251 if (!shouldKeepAfter(lastLastCh, lastCh, ch) && (needsLineBreakIterator(
ch) || needsLineBreakIterator(lastCh))) { |
| 252 if (nextBreak < i) { |
| 253 // Don't break if positioned at start of primary context and the
re is no prior context. |
| 254 if (i || priorContextLength) { |
| 255 TextBreakIterator* breakIterator = lazyBreakIterator.get(pri
orContextLength); |
| 256 if (breakIterator) { |
| 257 nextBreak = breakIterator->following(i - 1 + priorContex
tLength); |
| 258 if (nextBreak >= 0) { |
| 259 nextBreak -= priorContextLength; |
| 260 } |
| 261 } |
| 262 } |
| 263 } |
| 264 if (i == nextBreak && !isBreakableSpace(lastCh)) |
| 265 return i; |
| 266 } |
| 267 |
| 268 lastLastCh = lastCh; |
| 269 lastCh = ch; |
| 270 } |
| 271 |
| 272 return len; |
| 273 } |
| 274 |
228 int LazyLineBreakIterator::nextBreakablePositionIgnoringNBSP(int pos) | 275 int LazyLineBreakIterator::nextBreakablePositionIgnoringNBSP(int pos) |
229 { | 276 { |
230 if (m_string.is8Bit()) | 277 if (m_string.is8Bit()) |
231 return nextBreakablePosition<LChar>(*this, m_string.characters8(), m_str
ing.length(), pos); | 278 return nextBreakablePosition<LChar>(*this, m_string.characters8(), m_str
ing.length(), pos); |
232 return nextBreakablePosition<UChar>(*this, m_string.characters16(), m_string
.length(), pos); | 279 return nextBreakablePosition<UChar>(*this, m_string.characters16(), m_string
.length(), pos); |
233 } | 280 } |
234 | 281 |
235 int LazyLineBreakIterator::nextBreakablePositionBreakAll(int pos) | 282 int LazyLineBreakIterator::nextBreakablePositionBreakAll(int pos) |
236 { | 283 { |
237 if (m_string.is8Bit()) | 284 if (m_string.is8Bit()) |
238 return nextBreakablePositionBreakAllInternal<LChar>(*this, m_string.char
acters8(), m_string.length(), pos); | 285 return nextBreakablePositionBreakAllInternal<LChar>(*this, m_string.char
acters8(), m_string.length(), pos); |
239 return nextBreakablePositionBreakAllInternal<UChar>(*this, m_string.characte
rs16(), m_string.length(), pos); | 286 return nextBreakablePositionBreakAllInternal<UChar>(*this, m_string.characte
rs16(), m_string.length(), pos); |
240 } | 287 } |
241 | 288 |
| 289 int LazyLineBreakIterator::nextBreakablePositionKeepAll(int pos) |
| 290 { |
| 291 if (m_string.is8Bit()) |
| 292 return nextBreakablePosition<LChar>(*this, m_string.characters8(), m_str
ing.length(), pos); |
| 293 return nextBreakablePositionKeepAllInternal(*this, m_string.characters16(),
m_string.length(), pos); |
| 294 } |
242 | 295 |
243 } // namespace blink | 296 } // namespace blink |
OLD | NEW |