MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetParagraphLayout

Method GetParagraphLayout

src/os/windows/string_uniscribe.cpp:277–317  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

275}
276
277/* static */ std::unique_ptr<ParagraphLayouter> UniscribeParagraphLayoutFactory::GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &font_mapping)
278{
279 int32_t length = buff_end - buff;
280 /* Can't layout an empty string. */
281 if (length == 0) return nullptr;
282
283 /* Can't layout our in-built sprite fonts. */
284 for (auto const &[position, font] : font_mapping) {
285 if (font->fc->IsBuiltInFont()) return nullptr;
286 }
287
288 /* Itemize text. */
289 std::vector<SCRIPT_ITEM> items = UniscribeItemizeString(buff, length);
290 if (items.empty()) return nullptr;
291
292 /* Build ranges from the items and the font map. A range is a run of text
293 * that is part of a single item and formatted using a single font style. */
294 std::vector<UniscribeRun> ranges;
295
296 int cur_pos = 0;
297 std::vector<SCRIPT_ITEM>::iterator cur_item = items.begin();
298 for (auto const &[position, font] : font_mapping) {
299 while (cur_pos < position && cur_item != items.end() - 1) {
300 /* Add a range that spans the intersection of the remaining item and font run. */
301 int stop_pos = std::min(position, (cur_item + 1)->iCharPos);
302 assert(stop_pos - cur_pos > 0);
303 ranges.emplace_back(cur_pos, stop_pos - cur_pos, font, cur_item->a);
304
305 /* Shape the range. */
306 if (!UniscribeShapeRun(buff, ranges.back())) {
307 return nullptr;
308 }
309
310 /* If we are at the end of the current item, advance to the next item. */
311 if (stop_pos == (cur_item + 1)->iCharPos) cur_item++;
312 cur_pos = stop_pos;
313 }
314 }
315
316 return std::make_unique<UniscribeParagraphLayout>(std::move(ranges), buff);
317}
318
319/* virtual */ std::unique_ptr<const ParagraphLayouter::Line> UniscribeParagraphLayout::NextLine(int max_width)
320{

Callers

nothing calls this directly

Calls 6

UniscribeItemizeStringFunction · 0.85
UniscribeShapeRunFunction · 0.85
IsBuiltInFontMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected