| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/fonts/shaping/ShapeResultSpacing.h" | 5 #include "platform/fonts/shaping/ShapeResultSpacing.h" |
| 6 | 6 |
| 7 #include "platform/fonts/FontDescription.h" | 7 #include "platform/fonts/FontDescription.h" |
| 8 #include "platform/text/TextRun.h" | 8 #include "platform/text/TextRun.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 if (!--m_expansionOpportunityCount) { | 63 if (!--m_expansionOpportunityCount) { |
| 64 float remaining = m_expansion; | 64 float remaining = m_expansion; |
| 65 m_expansion = 0; | 65 m_expansion = 0; |
| 66 return remaining; | 66 return remaining; |
| 67 } | 67 } |
| 68 | 68 |
| 69 m_expansion -= m_expansionPerOpportunity; | 69 m_expansion -= m_expansionPerOpportunity; |
| 70 return m_expansionPerOpportunity; | 70 return m_expansionPerOpportunity; |
| 71 } | 71 } |
| 72 | 72 |
| 73 bool ShapeResultSpacing::isFirstRun(const TextRun& run) const |
| 74 { |
| 75 if (&run == &m_textRun) |
| 76 return true; |
| 77 return run.is8Bit() |
| 78 ? run.characters8() == m_textRun.characters8() |
| 79 : run.characters16() == m_textRun.characters16(); |
| 80 } |
| 81 |
| 73 float ShapeResultSpacing::computeSpacing(const TextRun& run, size_t index, | 82 float ShapeResultSpacing::computeSpacing(const TextRun& run, size_t index, |
| 74 float& offset) | 83 float& offset) |
| 75 { | 84 { |
| 76 if (run.is8Bit()) | 85 UChar32 character = run[index]; |
| 77 return computeSpacing(run.characters8(), run.length(), index, offset); | 86 bool treatAsSpace = (Character::treatAsSpace(character) |
| 78 return computeSpacing(run.characters16(), run.length(), index, offset); | 87 || (m_normalizeSpace && Character::isNormalizedCanvasSpaceCharacter(char
acter))) |
| 88 && (character != '\t' || !m_allowTabs); |
| 89 if (treatAsSpace && character != noBreakSpaceCharacter) |
| 90 character = spaceCharacter; |
| 91 |
| 92 float spacing = 0; |
| 93 if (m_letterSpacing && !Character::treatAsZeroWidthSpace(character)) |
| 94 spacing += m_letterSpacing; |
| 95 |
| 96 if (treatAsSpace && (index || !isFirstRun(run) || character == noBreakSpaceC
haracter)) |
| 97 spacing += m_wordSpacing; |
| 98 |
| 99 if (!hasExpansion()) |
| 100 return spacing; |
| 101 |
| 102 if (treatAsSpace) |
| 103 return spacing + nextExpansion(); |
| 104 |
| 105 if (run.is8Bit() || m_textJustify != TextJustify::TextJustifyAuto) |
| 106 return spacing; |
| 107 |
| 108 // isCJKIdeographOrSymbol() has expansion opportunities both before and |
| 109 // after each character. |
| 110 // http://www.w3.org/TR/jlreq/#line_adjustment |
| 111 if (U16_IS_LEAD(character) && index + 1 < run.length() && U16_IS_TRAIL(run[i
ndex + 1])) |
| 112 character = U16_GET_SUPPLEMENTARY(character, run[index + 1]); |
| 113 if (!Character::isCJKIdeographOrSymbol(character)) { |
| 114 m_isAfterExpansion = false; |
| 115 return spacing; |
| 116 } |
| 117 |
| 118 if (!m_isAfterExpansion) { |
| 119 // Take the expansion opportunity before this ideograph. |
| 120 float expandBefore = nextExpansion(); |
| 121 if (expandBefore) { |
| 122 offset += expandBefore; |
| 123 spacing += expandBefore; |
| 124 } |
| 125 if (!hasExpansion()) |
| 126 return spacing; |
| 127 } |
| 128 |
| 129 return spacing + nextExpansion(); |
| 79 } | 130 } |
| 80 | 131 |
| 81 } // namespace blink | 132 } // namespace blink |
| OLD | NEW |