aboutsummaryrefslogtreecommitdiffhomepage
path: root/qt/ScintillaEditBase/PlatQt.cpp
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2018-05-14 14:39:55 +1000
committerNeil <nyamatongwe@gmail.com>2018-05-14 14:39:55 +1000
commit3fe056899ac8ad4882f59e196aaa56cd31c2e547 (patch)
treedcbd61fefbf0dad1472713d890b7c9d6fc8d4814 /qt/ScintillaEditBase/PlatQt.cpp
parentc4aa7826f3d2178e39e5bff2f6886d7d3d3f46d7 (diff)
downloadscintilla-mirror-3fe056899ac8ad4882f59e196aaa56cd31c2e547.tar.gz
Modernize Platform.h (4) - update Surface to use string_view for text arguments.
Diffstat (limited to 'qt/ScintillaEditBase/PlatQt.cpp')
-rw-r--r--qt/ScintillaEditBase/PlatQt.cpp46
1 files changed, 23 insertions, 23 deletions
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<int>(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<fit) {
- const unsigned char uch = s[i];
+ const unsigned char uch = text[i];
const unsigned int byteCount = UTF8BytesOfLead[uch];
const int codeUnits = UTF16LengthFromUTF8ByteCount(byteCount);
qreal xPosition = tl.cursorToX(ui+codeUnits);
- for (unsigned int bytePos=0; (bytePos<byteCount) && (i<len); bytePos++) {
+ for (size_t bytePos=0; (bytePos<byteCount) && (i<text.length()); bytePos++) {
positions[i++] = xPosition;
}
ui += codeUnits;
@@ -464,34 +464,34 @@ void SurfaceImpl::MeasureWidths(Font &font,
XYPOSITION lastPos = 0;
if (i > 0)
lastPos = positions[i-1];
- while (i<len) {
+ while (i<text.length()) {
positions[i++] = lastPos;
}
} else if (codePage) {
// DBCS
int ui = 0;
- for (int i=0; i<len;) {
- size_t lenChar = DBCSIsLeadByte(codePage, s[i]) ? 2 : 1;
+ for (size_t i=0; i<text.length();) {
+ size_t lenChar = DBCSIsLeadByte(codePage, text[i]) ? 2 : 1;
qreal xPosition = tl.cursorToX(ui+1);
- for (unsigned int bytePos=0; (bytePos<lenChar) && (i<len); bytePos++) {
+ for (unsigned int bytePos=0; (bytePos<lenChar) && (i<text.length()); bytePos++) {
positions[i++] = xPosition;
}
ui++;
}
} else {
// Single byte encoding
- for (int i=0; i<len; i++) {
+ for (int i=0; i<static_cast<int>(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)