From 8b8a02b4bd250d28bc0f42287ca3d167b7210f39 Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 19 Mar 2021 16:15:16 +1100 Subject: UTF-8 text drawing and measurement. Move SurfaceGDI::WidthText to match declaration order. --- qt/ScintillaEditBase/PlatQt.cpp | 81 +++++++++++++++++++++++++++++++++++++++++ qt/ScintillaEditBase/PlatQt.h | 11 ++++++ 2 files changed, 92 insertions(+) (limited to 'qt/ScintillaEditBase') 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(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(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(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 0) + lastPos = positions[i-1]; + while (i(text.length())); + return metrics.width(su); +} + XYPOSITION SurfaceImpl::Ascent(const Font *font) { QFontMetricsF metrics(*FontPointer(font), device); diff --git a/qt/ScintillaEditBase/PlatQt.h b/qt/ScintillaEditBase/PlatQt.h index c690e7697..a743a4be5 100644 --- a/qt/ScintillaEditBase/PlatQt.h +++ b/qt/ScintillaEditBase/PlatQt.h @@ -126,6 +126,17 @@ public: void MeasureWidths(const Font *font, std::string_view text, XYPOSITION *positions) override; XYPOSITION WidthText(const Font *font, std::string_view text) override; + + void DrawTextNoClipUTF8(PRectangle rc, const Font *font_, XYPOSITION ybase, + std::string_view text, ColourDesired fore, ColourDesired back) override; + void DrawTextClippedUTF8(PRectangle rc, const Font *font_, XYPOSITION ybase, + std::string_view text, ColourDesired fore, ColourDesired back) override; + void DrawTextTransparentUTF8(PRectangle rc, const Font *font_, XYPOSITION ybase, + std::string_view text, ColourDesired fore) override; + void MeasureWidthsUTF8(const Font *font_, std::string_view text, + XYPOSITION *positions) override; + XYPOSITION WidthTextUTF8(const Font *font_, std::string_view text) override; + XYPOSITION Ascent(const Font *font) override; XYPOSITION Descent(const Font *font) override; XYPOSITION InternalLeading(const Font *font) override; -- cgit v1.2.3