diff options
author | Neil <nyamatongwe@gmail.com> | 2021-03-19 16:15:16 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2021-03-19 16:15:16 +1100 |
commit | 8b8a02b4bd250d28bc0f42287ca3d167b7210f39 (patch) | |
tree | d8d42a94f5abdaf1247db4fc5bf766c9a72cfbe9 /qt/ScintillaEditBase/PlatQt.cpp | |
parent | 09534ab81f72ce766c8d13ea13216dd589d41a1c (diff) | |
download | scintilla-mirror-8b8a02b4bd250d28bc0f42287ca3d167b7210f39.tar.gz |
UTF-8 text drawing and measurement.
Move SurfaceGDI::WidthText to match declaration order.
Diffstat (limited to 'qt/ScintillaEditBase/PlatQt.cpp')
-rw-r--r-- | qt/ScintillaEditBase/PlatQt.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/qt/ScintillaEditBase/PlatQt.cpp b/qt/ScintillaEditBase/PlatQt.cpp index 6a26d47c4..a1adf0a0d 100644 --- a/qt/ScintillaEditBase/PlatQt.cpp +++ b/qt/ScintillaEditBase/PlatQt.cpp @@ -557,6 +557,87 @@ XYPOSITION SurfaceImpl::WidthText(const Font *font, std::string_view text) return metrics.width(su); } +void SurfaceImpl::DrawTextNoClipUTF8(PRectangle rc, + const Font *font, + XYPOSITION ybase, + std::string_view text, + ColourDesired fore, + ColourDesired back) +{ + SetFont(font); + PenColour(fore); + + GetPainter()->setBackground(QColorFromCA(back)); + GetPainter()->setBackgroundMode(Qt::OpaqueMode); + QString su = QString::fromUtf8(text.data(), static_cast<int>(text.length())); + GetPainter()->drawText(QPointF(rc.left, ybase), su); +} + +void SurfaceImpl::DrawTextClippedUTF8(PRectangle rc, + const Font *font, + XYPOSITION ybase, + std::string_view text, + ColourDesired fore, + ColourDesired back) +{ + SetClip(rc); + DrawTextNoClip(rc, font, ybase, text, fore, back); + PopClip(); +} + +void SurfaceImpl::DrawTextTransparentUTF8(PRectangle rc, + const Font *font, + XYPOSITION ybase, + std::string_view text, + ColourDesired fore) +{ + SetFont(font); + PenColour(fore); + + GetPainter()->setBackgroundMode(Qt::TransparentMode); + QString su = QString::fromUtf8(text.data(), static_cast<int>(text.length())); + GetPainter()->drawText(QPointF(rc.left, ybase), su); +} + +void SurfaceImpl::MeasureWidthsUTF8(const Font *font, + std::string_view text, + XYPOSITION *positions) +{ + if (!font) + return; + QString su = QString::fromUtf8(text.data(), static_cast<int>(text.length())); + QTextLayout tlay(su, *FontPointer(font), GetPaintDevice()); + tlay.beginLayout(); + QTextLine tl = tlay.createLine(); + tlay.endLayout(); + int fit = su.size(); + int ui=0; + size_t i=0; + while (ui<fit) { + const unsigned char uch = text[i]; + const unsigned int byteCount = UTF8BytesOfLead[uch]; + const int codeUnits = UTF16LengthFromUTF8ByteCount(byteCount); + qreal xPosition = tl.cursorToX(ui+codeUnits); + for (size_t bytePos=0; (bytePos<byteCount) && (i<text.length()); bytePos++) { + positions[i++] = xPosition; + } + ui += codeUnits; + } + XYPOSITION lastPos = 0; + if (i > 0) + lastPos = positions[i-1]; + while (i<text.length()) { + positions[i++] = lastPos; + } +} + +XYPOSITION SurfaceImpl::WidthTextUTF8(const Font *font, std::string_view text) +{ + QFontMetricsF metrics(*FontPointer(font), device); + QString su = QString::fromUtf8(text.data(), static_cast<int>(text.length())); + return metrics.width(su); +} + XYPOSITION SurfaceImpl::Ascent(const Font *font) { QFontMetricsF metrics(*FontPointer(font), device); |