From 3fe056899ac8ad4882f59e196aaa56cd31c2e547 Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 14 May 2018 14:39:55 +1000 Subject: Modernize Platform.h (4) - update Surface to use string_view for text arguments. --- qt/ScintillaEditBase/PlatQt.cpp | 46 ++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'qt/ScintillaEditBase/PlatQt.cpp') diff --git a/qt/ScintillaEditBase/PlatQt.cpp b/qt/ScintillaEditBase/PlatQt.cpp index 26890e4b7..0a4609acc 100644 --- a/qt/ScintillaEditBase/PlatQt.cpp +++ b/qt/ScintillaEditBase/PlatQt.cpp @@ -92,6 +92,10 @@ const char *CharacterSetID(int characterSet) } } +QString UnicodeFromText(QTextCodec *codec, std::string_view text) { + return codec->toUnicode(text.data(), static_cast(text.length())); +} + class FontAndCharacterSet { public: int characterSet; @@ -387,8 +391,7 @@ void SurfaceImpl::Copy(PRectangle rc, Point from, Surface &surfaceSource) void SurfaceImpl::DrawTextNoClip(PRectangle rc, Font &font, XYPOSITION ybase, - const char *s, - int len, + std::string_view text, ColourDesired fore, ColourDesired back) { @@ -397,35 +400,33 @@ void SurfaceImpl::DrawTextNoClip(PRectangle rc, GetPainter()->setBackground(QColorFromCA(back)); GetPainter()->setBackgroundMode(Qt::OpaqueMode); - QString su = codec->toUnicode(s, len); + QString su = UnicodeFromText(codec, text); GetPainter()->drawText(QPointF(rc.left, ybase), su); } void SurfaceImpl::DrawTextClipped(PRectangle rc, Font &font, XYPOSITION ybase, - const char *s, - int len, + std::string_view text, ColourDesired fore, ColourDesired back) { SetClip(rc); - DrawTextNoClip(rc, font, ybase, s, len, fore, back); + DrawTextNoClip(rc, font, ybase, text, fore, back); GetPainter()->setClipping(false); } void SurfaceImpl::DrawTextTransparent(PRectangle rc, Font &font, XYPOSITION ybase, - const char *s, - int len, + std::string_view text, ColourDesired fore) { SetFont(font); PenColour(fore); GetPainter()->setBackgroundMode(Qt::TransparentMode); - QString su = codec->toUnicode(s, len); + QString su = UnicodeFromText(codec, text); GetPainter()->drawText(QPointF(rc.left, ybase), su); } @@ -435,14 +436,13 @@ void SurfaceImpl::SetClip(PRectangle rc) } void SurfaceImpl::MeasureWidths(Font &font, - const char *s, - int len, + std::string_view text, XYPOSITION *positions) { if (!font.GetID()) return; SetCodec(font); - QString su = codec->toUnicode(s, len); + QString su = UnicodeFromText(codec, text); QTextLayout tlay(su, *FontPointer(font), GetPaintDevice()); tlay.beginLayout(); QTextLine tl = tlay.createLine(); @@ -450,13 +450,13 @@ void SurfaceImpl::MeasureWidths(Font &font, if (unicodeMode) { int fit = su.size(); int ui=0; - int i=0; + size_t i=0; while (ui 0) lastPos = positions[i-1]; - while (i(text.length()); i++) { positions[i] = tl.cursorToX(i+1); } } } -XYPOSITION SurfaceImpl::WidthText(Font &font, const char *s, int len) +XYPOSITION SurfaceImpl::WidthText(Font &font, std::string_view text) { QFontMetricsF metrics(*FontPointer(font), device); SetCodec(font); - QString string = codec->toUnicode(s, len); - return metrics.width(string); + QString su = UnicodeFromText(codec, text); + return metrics.width(su); } XYPOSITION SurfaceImpl::Ascent(Font &font) -- cgit v1.2.3