| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/RunSegmenter.h" | 5 #include "platform/fonts/shaping/RunSegmenter.h" |
| 6 | 6 |
| 7 #include "platform/fonts/Character.h" | 7 #include "platform/fonts/Character.h" |
| 8 #include "platform/fonts/ScriptRunIterator.h" | 8 #include "platform/fonts/ScriptRunIterator.h" |
| 9 #include "platform/fonts/SmallCapsIterator.h" | 9 #include "platform/fonts/SmallCapsIterator.h" |
| 10 #include "platform/fonts/SymbolsIterator.h" |
| 10 #include "platform/fonts/UTF16TextIterator.h" | 11 #include "platform/fonts/UTF16TextIterator.h" |
| 11 #include "wtf/Assertions.h" | 12 #include "wtf/Assertions.h" |
| 12 | 13 |
| 13 namespace blink { | 14 namespace blink { |
| 14 | 15 |
| 15 RunSegmenter::RunSegmenter(const UChar* buffer, unsigned bufferSize, FontOrienta
tion runOrientation, FontVariant variant) | 16 RunSegmenter::RunSegmenter(const UChar* buffer, unsigned bufferSize, FontOrienta
tion runOrientation, FontVariant variant) |
| 16 : m_bufferSize(bufferSize) | 17 : m_bufferSize(bufferSize) |
| 17 , m_candidateRange({ 0, 0, USCRIPT_INVALID_CODE, OrientationIterator::Orient
ationKeep, SmallCapsIterator::SmallCapsSameCase }) | 18 , m_candidateRange({ 0, 0, USCRIPT_INVALID_CODE, OrientationIterator::Orient
ationKeep, SmallCapsIterator::SmallCapsSameCase }) |
| 18 , m_scriptRunIterator(adoptPtr(new ScriptRunIterator(buffer, bufferSize))) | 19 , m_scriptRunIterator(adoptPtr(new ScriptRunIterator(buffer, bufferSize))) |
| 19 , m_orientationIterator(runOrientation == FontOrientation::VerticalMixed ? a
doptPtr(new OrientationIterator(buffer, bufferSize, runOrientation)) : nullptr) | 20 , m_orientationIterator(runOrientation == FontOrientation::VerticalMixed ? a
doptPtr(new OrientationIterator(buffer, bufferSize, runOrientation)) : nullptr) |
| 20 , m_smallCapsIterator(variant == FontVariantSmallCaps ? adoptPtr(new SmallCa
psIterator(buffer, bufferSize)) : nullptr) | 21 , m_smallCapsIterator(variant == FontVariantSmallCaps ? adoptPtr(new SmallCa
psIterator(buffer, bufferSize)) : nullptr) |
| 22 , m_symbolsIterator(adoptPtr(new SymbolsIterator(buffer, bufferSize))) |
| 21 , m_lastSplit(0) | 23 , m_lastSplit(0) |
| 22 , m_scriptRunIteratorPosition(0) | 24 , m_scriptRunIteratorPosition(0) |
| 23 , m_orientationIteratorPosition(runOrientation == FontOrientation::VerticalM
ixed ? 0 : m_bufferSize) | 25 , m_orientationIteratorPosition(runOrientation == FontOrientation::VerticalM
ixed ? 0 : m_bufferSize) |
| 24 , m_smallCapsIteratorPosition(variant == FontVariantSmallCaps ? 0 : m_buffer
Size) | 26 , m_smallCapsIteratorPosition(variant == FontVariantSmallCaps ? 0 : m_buffer
Size) |
| 27 , m_symbolsIteratorPosition(0) |
| 25 , m_atEnd(false) | 28 , m_atEnd(false) |
| 26 { | 29 { |
| 27 } | 30 } |
| 28 | 31 |
| 29 void RunSegmenter::consumeScriptIteratorPastLastSplit() | 32 void RunSegmenter::consumeScriptIteratorPastLastSplit() |
| 30 { | 33 { |
| 31 ASSERT(m_scriptRunIterator); | 34 ASSERT(m_scriptRunIterator); |
| 32 if (m_scriptRunIteratorPosition <= m_lastSplit && m_scriptRunIteratorPositio
n < m_bufferSize) { | 35 if (m_scriptRunIteratorPosition <= m_lastSplit && m_scriptRunIteratorPositio
n < m_bufferSize) { |
| 33 while (m_scriptRunIterator->consume(m_scriptRunIteratorPosition, m_candi
dateRange.script)) { | 36 while (m_scriptRunIterator->consume(m_scriptRunIteratorPosition, m_candi
dateRange.script)) { |
| 34 if (m_scriptRunIteratorPosition > m_lastSplit) | 37 if (m_scriptRunIteratorPosition > m_lastSplit) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 50 void RunSegmenter::consumeSmallCapsIteratorPastLastSplit() | 53 void RunSegmenter::consumeSmallCapsIteratorPastLastSplit() |
| 51 { | 54 { |
| 52 if (m_smallCapsIterator && m_smallCapsIteratorPosition <= m_lastSplit && m_s
mallCapsIteratorPosition < m_bufferSize) { | 55 if (m_smallCapsIterator && m_smallCapsIteratorPosition <= m_lastSplit && m_s
mallCapsIteratorPosition < m_bufferSize) { |
| 53 while (m_smallCapsIterator->consume(&m_smallCapsIteratorPosition, &m_can
didateRange.smallCapsBehavior)) { | 56 while (m_smallCapsIterator->consume(&m_smallCapsIteratorPosition, &m_can
didateRange.smallCapsBehavior)) { |
| 54 if (m_smallCapsIteratorPosition > m_lastSplit) | 57 if (m_smallCapsIteratorPosition > m_lastSplit) |
| 55 return; | 58 return; |
| 56 } | 59 } |
| 57 } | 60 } |
| 58 } | 61 } |
| 59 | 62 |
| 63 void RunSegmenter::consumeSymbolsIteratorPastLastSplit() |
| 64 { |
| 65 ASSERT(m_symbolsIterator); |
| 66 if (m_symbolsIteratorPosition <= m_lastSplit && m_symbolsIteratorPosition <
m_bufferSize) { |
| 67 while (m_symbolsIterator->consume(&m_symbolsIteratorPosition, &m_candida
teRange.fontFallbackPriority)) { |
| 68 if (m_symbolsIteratorPosition > m_lastSplit) |
| 69 return; |
| 70 } |
| 71 } |
| 72 } |
| 73 |
| 60 bool RunSegmenter::consume(RunSegmenterRange* nextRange) | 74 bool RunSegmenter::consume(RunSegmenterRange* nextRange) |
| 61 { | 75 { |
| 62 if (m_atEnd || !m_bufferSize) | 76 if (m_atEnd || !m_bufferSize) |
| 63 return false; | 77 return false; |
| 64 | 78 |
| 65 consumeScriptIteratorPastLastSplit(); | 79 consumeScriptIteratorPastLastSplit(); |
| 66 consumeOrientationIteratorPastLastSplit(); | 80 consumeOrientationIteratorPastLastSplit(); |
| 67 consumeSmallCapsIteratorPastLastSplit(); | 81 consumeSmallCapsIteratorPastLastSplit(); |
| 82 consumeSymbolsIteratorPastLastSplit(); |
| 68 | 83 |
| 69 if (m_scriptRunIteratorPosition <= m_orientationIteratorPosition | 84 if (m_scriptRunIteratorPosition <= m_orientationIteratorPosition |
| 70 && m_scriptRunIteratorPosition <= m_smallCapsIteratorPosition) { | 85 && m_scriptRunIteratorPosition <= m_smallCapsIteratorPosition |
| 86 && m_scriptRunIteratorPosition <= m_symbolsIteratorPosition) { |
| 71 m_lastSplit = m_scriptRunIteratorPosition; | 87 m_lastSplit = m_scriptRunIteratorPosition; |
| 72 } | 88 } |
| 73 | 89 |
| 74 if (m_orientationIteratorPosition <= m_scriptRunIteratorPosition | 90 if (m_orientationIteratorPosition <= m_scriptRunIteratorPosition |
| 75 && m_orientationIteratorPosition <= m_smallCapsIteratorPosition) { | 91 && m_orientationIteratorPosition <= m_smallCapsIteratorPosition |
| 92 && m_orientationIteratorPosition <= m_symbolsIteratorPosition) { |
| 76 m_lastSplit = m_orientationIteratorPosition; | 93 m_lastSplit = m_orientationIteratorPosition; |
| 77 } | 94 } |
| 78 | 95 |
| 79 if (m_smallCapsIteratorPosition <= m_scriptRunIteratorPosition | 96 if (m_smallCapsIteratorPosition <= m_scriptRunIteratorPosition |
| 80 && m_smallCapsIteratorPosition <= m_orientationIteratorPosition) { | 97 && m_smallCapsIteratorPosition <= m_orientationIteratorPosition |
| 98 && m_smallCapsIteratorPosition <= m_symbolsIteratorPosition) { |
| 81 m_lastSplit = m_smallCapsIteratorPosition; | 99 m_lastSplit = m_smallCapsIteratorPosition; |
| 82 } | 100 } |
| 83 | 101 |
| 102 if (m_symbolsIteratorPosition <= m_scriptRunIteratorPosition |
| 103 && m_symbolsIteratorPosition <= m_orientationIteratorPosition |
| 104 && m_symbolsIteratorPosition <= m_smallCapsIteratorPosition) { |
| 105 m_lastSplit = m_symbolsIteratorPosition; |
| 106 } |
| 107 |
| 84 m_candidateRange.start = m_candidateRange.end; | 108 m_candidateRange.start = m_candidateRange.end; |
| 85 m_candidateRange.end = m_lastSplit; | 109 m_candidateRange.end = m_lastSplit; |
| 86 *nextRange = m_candidateRange; | 110 *nextRange = m_candidateRange; |
| 87 | 111 |
| 88 m_atEnd = m_lastSplit == m_bufferSize; | 112 m_atEnd = m_lastSplit == m_bufferSize; |
| 89 return true; | 113 return true; |
| 90 } | 114 } |
| 91 | 115 |
| 92 | 116 |
| 93 } // namespace blink | 117 } // namespace blink |
| OLD | NEW |