aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CallTip.cxx6
-rw-r--r--src/EditView.cxx59
-rw-r--r--src/EditView.h2
-rw-r--r--src/Editor.cxx2
-rw-r--r--src/LineMarker.cxx8
-rw-r--r--src/MarginView.cxx4
-rw-r--r--src/PositionCache.cxx4
-rw-r--r--src/ViewStyle.cxx4
8 files changed, 43 insertions, 46 deletions
diff --git a/src/CallTip.cxx b/src/CallTip.cxx
index 2eab1146f..437933af9 100644
--- a/src/CallTip.cxx
+++ b/src/CallTip.cxx
@@ -154,13 +154,13 @@ void CallTip::DrawChunk(Surface *surface, int &x, const char *s,
} else if (IsTabCharacter(s[startSeg])) {
xEnd = NextTabPos(x);
} else {
- xEnd = x + static_cast<int>(lround(surface->WidthText(font, s + startSeg, endSeg - startSeg)));
+ std::string_view segText(s + startSeg, endSeg - startSeg);
+ xEnd = x + static_cast<int>(lround(surface->WidthText(font, segText)));
if (draw) {
rcClient.left = static_cast<XYPOSITION>(x);
rcClient.right = static_cast<XYPOSITION>(xEnd);
surface->DrawTextTransparent(rcClient, font, static_cast<XYPOSITION>(ytext),
- s+startSeg, endSeg - startSeg,
- highlight ? colourSel : colourUnSel);
+ segText, highlight ? colourSel : colourUnSel);
}
}
x = xEnd;
diff --git a/src/EditView.cxx b/src/EditView.cxx
index a63b666e5..b406747fb 100644
--- a/src/EditView.cxx
+++ b/src/EditView.cxx
@@ -96,8 +96,8 @@ static int WidthStyledText(Surface *surface, const ViewStyle &vs, int styleOffse
while ((endSegment + 1 < len) && (styles[endSegment + 1] == style))
endSegment++;
FontAlias fontText = vs.styles[style + styleOffset].font;
- width += static_cast<int>(surface->WidthText(fontText, text + start,
- static_cast<int>(endSegment - start + 1)));
+ std::string_view sv(text + start, endSegment - start + 1);
+ width += static_cast<int>(surface->WidthText(fontText, sv));
start = endSegment + 1;
}
return width;
@@ -113,8 +113,8 @@ int WidestLineWidth(Surface *surface, const ViewStyle &vs, int styleOffset, cons
widthSubLine = WidthStyledText(surface, vs, styleOffset, st.text + start, st.styles + start, lenLine);
} else {
FontAlias fontText = vs.styles[styleOffset + st.style].font;
- widthSubLine = static_cast<int>(surface->WidthText(fontText,
- st.text + start, static_cast<int>(lenLine)));
+ std::string_view text(st.text + start, lenLine);
+ widthSubLine = static_cast<int>(surface->WidthText(fontText, text));
}
if (widthSubLine > widthMax)
widthMax = widthSubLine;
@@ -124,18 +124,18 @@ int WidestLineWidth(Surface *surface, const ViewStyle &vs, int styleOffset, cons
}
void DrawTextNoClipPhase(Surface *surface, PRectangle rc, const Style &style, XYPOSITION ybase,
- const char *s, int len, DrawPhase phase) {
+ std::string_view text, DrawPhase phase) {
FontAlias fontText = style.font;
if (phase & drawBack) {
if (phase & drawText) {
// Drawing both
- surface->DrawTextNoClip(rc, fontText, ybase, s, len,
+ surface->DrawTextNoClip(rc, fontText, ybase, text,
style.fore, style.back);
} else {
surface->FillRectangle(rc, style.back);
}
} else if (phase & drawText) {
- surface->DrawTextTransparent(rc, fontText, ybase, s, len, style.fore);
+ surface->DrawTextTransparent(rc, fontText, ybase, text, style.fore);
}
}
@@ -152,22 +152,21 @@ void DrawStyledText(Surface *surface, const ViewStyle &vs, int styleOffset, PRec
end++;
style += styleOffset;
FontAlias fontText = vs.styles[style].font;
- const int width = static_cast<int>(surface->WidthText(fontText,
- st.text + start + i, static_cast<int>(end - i + 1)));
+ std::string_view text(st.text + start + i, end - i + 1);
+ const int width = static_cast<int>(surface->WidthText(fontText, text));
PRectangle rcSegment = rcText;
rcSegment.left = static_cast<XYPOSITION>(x);
rcSegment.right = static_cast<XYPOSITION>(x + width + 1);
DrawTextNoClipPhase(surface, rcSegment, vs.styles[style],
- rcText.top + vs.maxAscent, st.text + start + i,
- static_cast<int>(end - i + 1), phase);
+ rcText.top + vs.maxAscent, text, phase);
x += width;
i = end + 1;
}
} else {
const size_t style = st.style + styleOffset;
DrawTextNoClipPhase(surface, rcText, vs.styles[style],
- rcText.top + vs.maxAscent, st.text + start,
- static_cast<int>(length), phase);
+ rcText.top + vs.maxAscent,
+ std::string_view(st.text + start, length), phase);
}
}
@@ -803,7 +802,7 @@ static void SimpleAlphaRectangle(Surface *surface, PRectangle rc, ColourDesired
}
static void DrawTextBlob(Surface *surface, const ViewStyle &vsDraw, PRectangle rcSegment,
- const char *s, ColourDesired textBack, ColourDesired textFore, bool fillBackground) {
+ std::string_view text, ColourDesired textBack, ColourDesired textFore, bool fillBackground) {
if (rcSegment.Empty())
return;
if (fillBackground) {
@@ -823,7 +822,7 @@ static void DrawTextBlob(Surface *surface, const ViewStyle &vsDraw, PRectangle r
rcChar.left++;
rcChar.right--;
surface->DrawTextClipped(rcChar, ctrlCharsFont,
- rcSegment.top + vsDraw.maxAscent, s, static_cast<int>(s ? strlen(s) : 0),
+ rcSegment.top + vsDraw.maxAscent, text,
textBack, textFore);
}
@@ -1103,10 +1102,9 @@ void EditView::DrawFoldDisplayText(Surface *surface, const EditModel &model, con
return;
PRectangle rcSegment = rcLine;
- const char *foldDisplayText = model.pcs->GetFoldDisplayText(line);
- const int lengthFoldDisplayText = static_cast<int>(strlen(foldDisplayText));
+ const std::string_view foldDisplayText = model.pcs->GetFoldDisplayText(line);
FontAlias fontText = vsDraw.styles[STYLE_FOLDDISPLAYTEXT].font;
- const int widthFoldDisplayText = static_cast<int>(surface->WidthText(fontText, foldDisplayText, lengthFoldDisplayText));
+ const int widthFoldDisplayText = static_cast<int>(surface->WidthText(fontText, foldDisplayText));
int eolInSelection = 0;
int alpha = SC_ALPHA_NOALPHA;
@@ -1154,11 +1152,11 @@ void EditView::DrawFoldDisplayText(Surface *surface, const EditModel &model, con
if (phasesDraw != phasesOne) {
surface->DrawTextTransparent(rcSegment, textFont,
rcSegment.top + vsDraw.maxAscent, foldDisplayText,
- lengthFoldDisplayText, textFore);
+ textFore);
} else {
surface->DrawTextNoClip(rcSegment, textFont,
rcSegment.top + vsDraw.maxAscent, foldDisplayText,
- lengthFoldDisplayText, textFore, textBack);
+ textFore, textBack);
}
}
@@ -1309,9 +1307,9 @@ static void DrawBlockCaret(Surface *surface, const EditModel &model, const ViewS
// (inversed) for drawing the caret here.
const int styleMain = ll->styles[offsetFirstChar];
FontAlias fontText = vsDraw.styles[styleMain].font;
+ std::string_view text(&ll->chars[offsetFirstChar], numCharsToDraw);
surface->DrawTextClipped(rcCaret, fontText,
- rcCaret.top + vsDraw.maxAscent, &ll->chars[offsetFirstChar],
- static_cast<int>(numCharsToDraw), vsDraw.styles[styleMain].back,
+ rcCaret.top + vsDraw.maxAscent, text, vsDraw.styles[styleMain].back,
caretColour);
}
@@ -1735,23 +1733,22 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi
const char cc[2] = { static_cast<char>(vsDraw.controlCharSymbol), '\0' };
surface->DrawTextNoClip(rcSegment, ctrlCharsFont,
rcSegment.top + vsDraw.maxAscent,
- cc, 1, textBack, textFore);
+ cc, textBack, textFore);
} else {
- DrawTextBlob(surface, vsDraw, rcSegment, ts.representation->stringRep.c_str(),
+ DrawTextBlob(surface, vsDraw, rcSegment, ts.representation->stringRep,
textBack, textFore, phasesDraw == phasesOne);
}
}
} else {
// Normal text display
if (vsDraw.styles[styleMain].visible) {
+ std::string_view text(&ll->chars[ts.start], i - ts.start + 1);
if (phasesDraw != phasesOne) {
surface->DrawTextTransparent(rcSegment, textFont,
- rcSegment.top + vsDraw.maxAscent, &ll->chars[ts.start],
- static_cast<int>(i - ts.start + 1), textFore);
+ rcSegment.top + vsDraw.maxAscent, text, textFore);
} else {
surface->DrawTextNoClip(rcSegment, textFont,
- rcSegment.top + vsDraw.maxAscent, &ll->chars[ts.start],
- static_cast<int>(i - ts.start + 1), textFore, textBack);
+ rcSegment.top + vsDraw.maxAscent, text, textFore, textBack);
}
}
if (vsDraw.viewWhitespace != wsInvisible ||
@@ -2271,7 +2268,7 @@ Sci::Position EditView::FormatRange(bool draw, const Sci_RangeToFormat *pfr, Sur
int lineNumberWidth = 0;
if (lineNumberIndex >= 0) {
lineNumberWidth = static_cast<int>(surfaceMeasure->WidthText(vsPrint.styles[STYLE_LINENUMBER].font,
- "99999" lineNumberPrintSpace, 5 + static_cast<int>(strlen(lineNumberPrintSpace))));
+ "99999" lineNumberPrintSpace));
vsPrint.ms[lineNumberIndex].width = lineNumberWidth;
vsPrint.Refresh(*surfaceMeasure, model.pdoc->tabInChars); // Recalculate fixedColumnWidth
}
@@ -2352,10 +2349,10 @@ Sci::Position EditView::FormatRange(bool draw, const Sci_RangeToFormat *pfr, Sur
rcNumber.right = rcNumber.left + lineNumberWidth;
// Right justify
rcNumber.left = rcNumber.right - surfaceMeasure->WidthText(
- vsPrint.styles[STYLE_LINENUMBER].font, number.c_str(), static_cast<int>(number.length()));
+ vsPrint.styles[STYLE_LINENUMBER].font, number);
surface->FlushCachedState();
surface->DrawTextNoClip(rcNumber, vsPrint.styles[STYLE_LINENUMBER].font,
- static_cast<XYPOSITION>(ypos + vsPrint.maxAscent), number.c_str(), static_cast<int>(number.length()),
+ static_cast<XYPOSITION>(ypos + vsPrint.maxAscent), number,
vsPrint.styles[STYLE_LINENUMBER].fore,
vsPrint.styles[STYLE_LINENUMBER].back);
}
diff --git a/src/EditView.h b/src/EditView.h
index f649f7c87..51e2a1e53 100644
--- a/src/EditView.h
+++ b/src/EditView.h
@@ -36,7 +36,7 @@ enum DrawPhase {
bool ValidStyledText(const ViewStyle &vs, size_t styleOffset, const StyledText &st);
int WidestLineWidth(Surface *surface, const ViewStyle &vs, int styleOffset, const StyledText &st);
void DrawTextNoClipPhase(Surface *surface, PRectangle rc, const Style &style, XYPOSITION ybase,
- const char *s, int len, DrawPhase phase);
+ std::string_view text, DrawPhase phase);
void DrawStyledText(Surface *surface, const ViewStyle &vs, int styleOffset, PRectangle rcText,
const StyledText &st, size_t start, size_t length, DrawPhase phase);
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 80cdbc97a..36ebc5cea 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -1792,7 +1792,7 @@ int Editor::TextWidth(int style, const char *text) {
RefreshStyleData();
AutoSurface surface(this);
if (surface) {
- return static_cast<int>(surface->WidthText(vs.styles[style].font, text, static_cast<int>(strlen(text))));
+ return static_cast<int>(surface->WidthText(vs.styles[style].font, text));
} else {
return 1;
}
diff --git a/src/LineMarker.cxx b/src/LineMarker.cxx
index a2f7e299e..53231d778 100644
--- a/src/LineMarker.cxx
+++ b/src/LineMarker.cxx
@@ -9,6 +9,7 @@
#include <cmath>
#include <stdexcept>
+#include <string>
#include <string_view>
#include <vector>
#include <map>
@@ -377,14 +378,13 @@ void LineMarker::Draw(Surface *surface, PRectangle &rcWhole, Font &fontForCharac
DrawMinus(surface, centreX, centreY, blobSize, colourTail);
} else if (markType >= SC_MARK_CHARACTER) {
- char character[1];
- character[0] = static_cast<char>(markType - SC_MARK_CHARACTER);
- const XYPOSITION width = surface->WidthText(fontForCharacter, character, 1);
+ std::string character(1, static_cast<char>(markType - SC_MARK_CHARACTER));
+ const XYPOSITION width = surface->WidthText(fontForCharacter, character);
PRectangle rcText = rc;
rcText.left += (rc.Width() - width) / 2;
rcText.right = rc.left + width;
surface->DrawTextClipped(rcText, fontForCharacter, rcText.bottom - 2,
- character, 1, fore, back);
+ character, fore, back);
} else if (markType == SC_MARK_DOTDOTDOT) {
XYPOSITION right = static_cast<XYPOSITION>(centreX - 6);
diff --git a/src/MarginView.cxx b/src/MarginView.cxx
index f9d566b44..6604657f6 100644
--- a/src/MarginView.cxx
+++ b/src/MarginView.cxx
@@ -393,11 +393,11 @@ void MarginView::PaintMargin(Surface *surface, Sci::Line topLine, PRectangle rc,
}
PRectangle rcNumber = rcMarker;
// Right justify
- const XYPOSITION width = surface->WidthText(fontLineNumber, sNumber.c_str(), static_cast<int>(sNumber.length()));
+ const XYPOSITION width = surface->WidthText(fontLineNumber, sNumber);
const XYPOSITION xpos = rcNumber.right - width - vs.marginNumberPadding;
rcNumber.left = xpos;
DrawTextNoClipPhase(surface, rcNumber, vs.styles[STYLE_LINENUMBER],
- rcNumber.top + vs.maxAscent, sNumber.c_str(), static_cast<int>(sNumber.length()), drawAll);
+ rcNumber.top + vs.maxAscent, sNumber, drawAll);
} else if (vs.wrapVisualFlags & SC_WRAPVISUALFLAG_MARGIN) {
PRectangle rcWrapMarker = rcMarker;
rcWrapMarker.right -= wrapMarkerPaddingRight;
diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx
index 9769202c6..bf5560678 100644
--- a/src/PositionCache.cxx
+++ b/src/PositionCache.cxx
@@ -691,7 +691,7 @@ void PositionCache::MeasureWidths(Surface *surface, const ViewStyle &vstyle, uns
while (startSegment < len) {
const unsigned int lenSegment = pdoc->SafeSegment(s + startSegment, len - startSegment, BreakFinder::lengthEachSubdivision);
FontAlias fontStyle = vstyle.styles[styleNumber].font;
- surface->MeasureWidths(fontStyle, s + startSegment, lenSegment, positions + startSegment);
+ surface->MeasureWidths(fontStyle, std::string_view(s + startSegment, lenSegment), positions + startSegment);
for (unsigned int inSeg = 0; inSeg < lenSegment; inSeg++) {
positions[startSegment + inSeg] += xStartSegment;
}
@@ -700,7 +700,7 @@ void PositionCache::MeasureWidths(Surface *surface, const ViewStyle &vstyle, uns
}
} else {
FontAlias fontStyle = vstyle.styles[styleNumber].font;
- surface->MeasureWidths(fontStyle, s, len, positions);
+ surface->MeasureWidths(fontStyle, std::string_view(s, len), positions);
}
if (probe < pces.size()) {
// Store into cache
diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx
index 1a95450ce..2700fb016 100644
--- a/src/ViewStyle.cxx
+++ b/src/ViewStyle.cxx
@@ -80,7 +80,7 @@ void FontRealised::Realise(Surface &surface, int zoomLevel, int technology, cons
descent = static_cast<unsigned int>(surface.Descent(font));
capitalHeight = surface.Ascent(font) - surface.InternalLeading(font);
aveCharWidth = surface.AverageCharWidth(font);
- spaceWidth = surface.WidthText(font, " ", 1);
+ spaceWidth = surface.WidthText(font, " ");
}
ViewStyle::ViewStyle() : markers(MARKER_MAX + 1), indicators(INDIC_MAX + 1) {
@@ -367,7 +367,7 @@ void ViewStyle::Refresh(Surface &surface, int tabInChars) {
controlCharWidth = 0.0;
if (controlCharSymbol >= 32) {
const char cc[2] = { static_cast<char>(controlCharSymbol), '\0' };
- controlCharWidth = surface.WidthText(styles[STYLE_CONTROLCHAR].font, cc, 1);
+ controlCharWidth = surface.WidthText(styles[STYLE_CONTROLCHAR].font, cc);
}
CalculateMarginWidthAndMask();