TextBlob::RunHandler impl
| 47 | |
| 48 | // TextBlob::RunHandler impl |
| 49 | void commitRunBuffer(TextBlob::RunInfo& info) override |
| 50 | { |
| 51 | if (info.clusters && info.glyphCount > 0) { |
| 52 | float advanceX = 0.0f; |
| 53 | |
| 54 | os::Paint paint; |
| 55 | paint.style(os::Paint::Fill); |
| 56 | |
| 57 | for (int i = 0; i < info.glyphCount; ++i) { |
| 58 | int utf8Begin, utf8End; |
| 59 | |
| 60 | // LTR |
| 61 | if (!info.rtl) { |
| 62 | utf8Begin = info.utf8Range.begin + info.clusters[i]; |
| 63 | utf8End = (i + 1 < info.glyphCount ? info.utf8Range.begin + info.clusters[i + 1] : |
| 64 | info.utf8Range.end); |
| 65 | } |
| 66 | // RTL |
| 67 | else { |
| 68 | utf8Begin = info.utf8Range.begin + info.clusters[i]; |
| 69 | utf8End = (i == 0 ? info.utf8Range.end : info.utf8Range.begin + info.clusters[i - 1]); |
| 70 | } |
| 71 | |
| 72 | const std::string utf8text = m_text.substr(utf8Begin, utf8End - utf8Begin); |
| 73 | |
| 74 | gfx::RectF bounds = info.getGlyphBounds(i); |
| 75 | bounds.offset(m_origin); |
| 76 | |
| 77 | advanceX += bounds.w; |
| 78 | |
| 79 | if (m_delegate) { |
| 80 | const std::wstring widetext = base::from_utf8(utf8text); |
| 81 | codepoint_t codepoint = 0; |
| 82 | if (!widetext.empty()) { |
| 83 | // On macOS and Linux wchar_t has 32-bits |
| 84 | if constexpr (sizeof(wchar_t) >= 4) { |
| 85 | codepoint = widetext[0]; |
| 86 | } |
| 87 | // On Windows wchar_t has 16-bits (wide strings are UTF-16 strings) |
| 88 | else if constexpr (sizeof(wchar_t) == 2) { |
| 89 | codepoint = base::utf16_to_codepoint(widetext.size() > 1 ? widetext[1] : widetext[0], |
| 90 | widetext.size() > 1 ? widetext[0] : 0); |
| 91 | } |
| 92 | else { |
| 93 | codepoint = 0; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | m_delegate->preProcessChar(utf8Begin, codepoint, m_fg, m_bg, bounds); |
| 98 | } |
| 99 | |
| 100 | if (m_delegate) |
| 101 | m_delegate->preDrawChar(bounds); |
| 102 | |
| 103 | if (m_surface && info.font) { |
| 104 | if (info.font->type() == FontType::SpriteSheet) { |
| 105 | const auto* spriteFont = static_cast<const SpriteSheetFont*>(info.font.get()); |
| 106 | const os::Surface* sheet = spriteFont->sheetSurface(); |
nothing calls this directly
no test coverage detected