MCPcopy Create free account
hub / github.com/comaps/comaps / GetSingleTextLineRuns

Function GetSingleTextLineRuns

libs/drape/harfbuzz_shaping.cpp:139–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137}
138
139void GetSingleTextLineRuns(TextSegments & segments)
140{
141 auto const & text = segments.m_text;
142 auto const textLength = static_cast<int32_t>(text.length());
143
144 // Deliberately not checking for nullptr.
145 thread_local UBiDi * const bidi = ubidi_open();
146 UErrorCode error = U_ZERO_ERROR;
147 ::ubidi_setPara(bidi, text.data(), textLength, UBIDI_DEFAULT_LTR, nullptr, &error);
148 if (U_FAILURE(error))
149 {
150 LOG(LERROR, ("ubidi_setPara failed with code", error));
151 segments.m_segments.emplace_back(0, 0, HB_SCRIPT_UNKNOWN, HB_DIRECTION_INVALID);
152 return;
153 }
154
155 // Split the original text by logical runs, then each logical run by common script and each sequence at special
156 // characters and style boundaries. This invariant holds: bidiRunStart <= scriptRunStart <= breakingRunStart
157 // <= breakingRunEnd <= scriptRunStart <= bidiRunEnd. AB: Breaking runs are dropped now, they may not be needed.
158 for (int32_t bidiRunStart = 0; bidiRunStart < textLength;)
159 {
160 // Determine the longest logical run (e.g. same bidi direction) from this point.
161 int32_t bidiRunBreak = 0;
162 UBiDiLevel bidiLevel = 0;
163 ::ubidi_getLogicalRun(bidi, bidiRunStart, &bidiRunBreak, &bidiLevel);
164 int32_t const bidiRunEnd = bidiRunBreak;
165 ASSERT_LESS(bidiRunStart, bidiRunEnd, ());
166
167 for (int32_t scriptRunStart = bidiRunStart; scriptRunStart < bidiRunEnd;)
168 {
169 // Find the longest sequence of characters that have at least one common UScriptCode value.
170 UScriptCode script = USCRIPT_INVALID_CODE;
171 size_t const scriptRunEnd =
172 ScriptInterval(segments.m_text, scriptRunStart, bidiRunEnd - scriptRunStart, script) + scriptRunStart;
173 ASSERT_LESS(scriptRunStart, base::asserted_cast<int32_t>(scriptRunEnd), ());
174
175 // TODO(AB): May need to break on different unicode blocks, parentheses, and control chars (spaces).
176
177 // TODO(AB): Support vertical layouts if necessary.
178 segments.m_segments.emplace_back(scriptRunStart, scriptRunEnd - scriptRunStart, ICUScriptToHarfbuzzScript(script),
179 bidiLevel & 0x01 ? HB_DIRECTION_RTL : HB_DIRECTION_LTR);
180
181 // Move to the next script sequence.
182 scriptRunStart = static_cast<int32_t>(scriptRunEnd);
183 }
184 // Move to the next direction sequence.
185 bidiRunStart = bidiRunEnd;
186 }
187}
188
189void ReorderRTL(TextSegments & segments)
190{

Callers 1

GetTextSegmentsFunction · 0.85

Calls 5

ScriptIntervalFunction · 0.85
lengthMethod · 0.80
dataMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected