MCPcopy Create free account
hub / github.com/TypesettingTools/Aegisub / SetDisplayText

Method SetDisplayText

src/audio_karaoke.cpp:339–404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

337}
338
339void AudioKaraoke::SetDisplayText() {
340 wxMemoryDC dc;
341 dc.SetFont(split_font);
342
343 auto get_char_width = [&](std::string_view character) -> int {
344 if (auto it = char_widths.find(character); it != char_widths.end())
345 return it->second;
346
347 const auto size = dc.GetTextExtent(to_wx(character));
348 char_height = std::max(char_height, size.GetHeight());
349 char_widths.emplace(character, size.GetWidth());
350 return size.GetWidth();
351 };
352
353 char_width = get_char_width(" ");
354
355 // Width in pixels of each character in this string
356 std::vector<int> str_char_widths;
357
358 spaced_text.clear();
359 char_to_byte.clear();
360 syl_start_points.clear();
361 for (auto const& syl : *kara) {
362 // The last (and only the last) syllable needs the width of the final
363 // character in the syllable, so we unconditionally add it at the end
364 // of this loop, then remove the extra ones here
365 if (!char_to_byte.empty())
366 char_to_byte.pop_back();
367
368 syl_start_points.push_back(spaced_text.size());
369
370 // Add a space between each syllable to avoid crowding
371 spaced_text.emplace_back(wxS(" "));
372 str_char_widths.push_back(char_width);
373 char_to_byte.push_back(1);
374
375 size_t syl_idx = 1;
376 agi::BreakIterator characters;
377 characters.set_text(syl.text);
378 for (; !characters.done(); characters.next()) {
379 // Calculate the width in pixels of this character
380 const auto character = characters.current();
381 const int width = get_char_width(character);
382 char_width = std::max(char_width, width);
383 str_char_widths.push_back(width);
384
385 spaced_text.emplace_back(to_wx(character));
386 char_to_byte.push_back(syl_idx);
387 syl_idx += character.size();
388 }
389
390 char_to_byte.push_back(syl_idx);
391 }
392
393 // Center each character within the space available to it
394 char_x.resize(str_char_widths.size());
395 for (size_t i = 0; i < str_char_widths.size(); ++i)
396 char_x[i] = i * char_width + (char_width - str_char_widths[i]) / 2;

Callers

nothing calls this directly

Calls 13

SetFontMethod · 0.80
pop_backMethod · 0.80
push_backMethod · 0.80
set_textMethod · 0.80
doneMethod · 0.80
currentMethod · 0.80
to_wxFunction · 0.70
endMethod · 0.45
GetHeightMethod · 0.45
GetWidthMethod · 0.45
clearMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected