diff options
author | Neil <nyamatongwe@gmail.com> | 2014-06-22 12:50:03 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2014-06-22 12:50:03 +1000 |
commit | 068bfb9213d810b1551cdc48fdfd216060253103 (patch) | |
tree | 961424276d263ea442f98112aa3bc26dafa92bef /src | |
parent | 318fb4b54beb34a036bfe405127c9329b67ea95f (diff) | |
download | scintilla-mirror-068bfb9213d810b1551cdc48fdfd216060253103.tar.gz |
Drawing and measuring should not change ViewStyle which is set by the container
so mark ViewStyle parameters as const.
Provide a FontAlias copy constructor and use it to work around non-const Font
arguments to Surface when sourced from const ViewStyle.
Diffstat (limited to 'src')
-rw-r--r-- | src/Editor.cxx | 54 | ||||
-rw-r--r-- | src/Editor.h | 20 | ||||
-rw-r--r-- | src/Indicator.cxx | 2 | ||||
-rw-r--r-- | src/Indicator.h | 2 | ||||
-rw-r--r-- | src/PositionCache.cxx | 8 | ||||
-rw-r--r-- | src/PositionCache.h | 2 | ||||
-rw-r--r-- | src/Style.cxx | 4 | ||||
-rw-r--r-- | src/Style.h | 2 |
8 files changed, 52 insertions, 42 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx index 18eafa271..49fa40910 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -1739,7 +1739,7 @@ int Editor::SubstituteMarkerIfEmpty(int markerCheck, int markerDefault) const { return markerCheck; } -bool ValidStyledText(ViewStyle &vs, size_t styleOffset, const StyledText &st) { +bool ValidStyledText(const ViewStyle &vs, size_t styleOffset, const StyledText &st) { if (st.multipleStyles) { for (size_t iStyle=0; iStyle<st.length; iStyle++) { if (!vs.ValidStyle(styleOffset + st.styles[iStyle])) @@ -1752,7 +1752,7 @@ bool ValidStyledText(ViewStyle &vs, size_t styleOffset, const StyledText &st) { return true; } -static int WidthStyledText(Surface *surface, ViewStyle &vs, int styleOffset, +static int WidthStyledText(Surface *surface, const ViewStyle &vs, int styleOffset, const char *text, const unsigned char *styles, size_t len) { int width = 0; size_t start = 0; @@ -1761,14 +1761,15 @@ static int WidthStyledText(Surface *surface, ViewStyle &vs, int styleOffset, size_t endSegment = start; while ((endSegment+1 < len) && (static_cast<size_t>(styles[endSegment+1]) == style)) endSegment++; - width += static_cast<int>(surface->WidthText(vs.styles[style + styleOffset].font, text + start, + FontAlias fontText = vs.styles[style + styleOffset].font; + width += static_cast<int>(surface->WidthText(fontText, text + start, static_cast<int>(endSegment - start + 1))); start = endSegment + 1; } return width; } -static int WidestLineWidth(Surface *surface, ViewStyle &vs, int styleOffset, const StyledText &st) { +static int WidestLineWidth(Surface *surface, const ViewStyle &vs, int styleOffset, const StyledText &st) { int widthMax = 0; size_t start = 0; while (start < st.length) { @@ -1777,7 +1778,8 @@ static int WidestLineWidth(Surface *surface, ViewStyle &vs, int styleOffset, con if (st.multipleStyles) { widthSubLine = WidthStyledText(surface, vs, styleOffset, st.text + start, st.styles + start, lenLine); } else { - widthSubLine = static_cast<int>(surface->WidthText(vs.styles[styleOffset + st.style].font, + FontAlias fontText = vs.styles[styleOffset + st.style].font; + widthSubLine = static_cast<int>(surface->WidthText(fontText, st.text + start, static_cast<int>(lenLine))); } if (widthSubLine > widthMax) @@ -1787,7 +1789,7 @@ static int WidestLineWidth(Surface *surface, ViewStyle &vs, int styleOffset, con return widthMax; } -void DrawStyledText(Surface *surface, ViewStyle &vs, int styleOffset, PRectangle rcText, int ascent, +void DrawStyledText(Surface *surface, const ViewStyle &vs, int styleOffset, PRectangle rcText, int ascent, const StyledText &st, size_t start, size_t length) { if (st.multipleStyles) { @@ -1799,12 +1801,13 @@ void DrawStyledText(Surface *surface, ViewStyle &vs, int styleOffset, PRectangle while (end < length-1 && st.styles[start+end+1] == style) end++; style += styleOffset; - int width = static_cast<int>(surface->WidthText(vs.styles[style].font, + FontAlias fontText = vs.styles[style].font; + int width = static_cast<int>(surface->WidthText(fontText, st.text + start + i, static_cast<int>(end - i + 1))); PRectangle rcSegment = rcText; rcSegment.left = static_cast<XYPOSITION>(x); rcSegment.right = static_cast<XYPOSITION>(x + width + 1); - surface->DrawTextNoClip(rcSegment, vs.styles[style].font, + surface->DrawTextNoClip(rcSegment, fontText, static_cast<XYPOSITION>(ascent), st.text + start + i, static_cast<int>(end - i + 1), vs.styles[style].fore, @@ -1814,7 +1817,8 @@ void DrawStyledText(Surface *surface, ViewStyle &vs, int styleOffset, PRectangle } } else { size_t style = st.style + styleOffset; - surface->DrawTextNoClip(rcText, vs.styles[style].font, + FontAlias fontText = vs.styles[style].font; + surface->DrawTextNoClip(rcText, fontText, rcText.top + vs.maxAscent, st.text + start, static_cast<int>(length), vs.styles[style].fore, @@ -2162,8 +2166,7 @@ LineLayout *Editor::RetrieveLineLayout(int lineNumber) { * Copy the given @a line and its styles from the document into local arrays. * Also determine the x position at which each character starts. */ -void Editor::LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayout *ll, int width) { -//void LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayout *ll, int width, Document *pdoc, PositionCache &posCache, SpecialRepresentations &reprs) { +void Editor::LayoutLine(int line, Surface *surface, const ViewStyle &vstyle, LineLayout *ll, int width) { if (!ll) return; @@ -2387,13 +2390,13 @@ void Editor::LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayou } } -ColourDesired Editor::SelectionBackground(ViewStyle &vsDraw, bool main) const { +ColourDesired Editor::SelectionBackground(const ViewStyle &vsDraw, bool main) const { return main ? (primarySelection ? vsDraw.selColours.back : vsDraw.selBackground2) : vsDraw.selAdditionalBackground; } -ColourDesired Editor::TextBackground(ViewStyle &vsDraw, bool overrideBackground, +ColourDesired Editor::TextBackground(const ViewStyle &vsDraw, bool overrideBackground, ColourDesired background, int inSelection, bool inHotspot, int styleMain, int i, LineLayout *ll) const { if (inSelection == 1) { if (vsDraw.selColours.back.isSet && (vsDraw.selAlpha == SC_ALPHA_NOALPHA)) { @@ -2475,12 +2478,12 @@ static void SimpleAlphaRectangle(Surface *surface, PRectangle rc, ColourDesired } } -void DrawTextBlob(Surface *surface, ViewStyle &vsDraw, PRectangle rcSegment, +void DrawTextBlob(Surface *surface, const ViewStyle &vsDraw, PRectangle rcSegment, const char *s, ColourDesired textBack, ColourDesired textFore, bool twoPhaseDraw) { if (!twoPhaseDraw) { surface->FillRectangle(rcSegment, textBack); } - Font &ctrlCharsFont = vsDraw.styles[STYLE_CONTROLCHAR].font; + FontAlias ctrlCharsFont = vsDraw.styles[STYLE_CONTROLCHAR].font; int normalCharHeight = static_cast<int>(surface->Ascent(ctrlCharsFont) - surface->InternalLeading(ctrlCharsFont)); PRectangle rcCChar = rcSegment; @@ -2499,7 +2502,7 @@ void DrawTextBlob(Surface *surface, ViewStyle &vsDraw, PRectangle rcSegment, textBack, textFore); } -void Editor::DrawEOL(Surface *surface, ViewStyle &vsDraw, PRectangle rcLine, LineLayout *ll, +void Editor::DrawEOL(Surface *surface, const ViewStyle &vsDraw, PRectangle rcLine, LineLayout *ll, int line, int lineEnd, int xStart, int subLine, XYACCUMULATOR subLineStart, bool overrideBackground, ColourDesired background, bool drawWrapMarkEnd, ColourDesired wrapColour) { @@ -2650,7 +2653,7 @@ void Editor::DrawEOL(Surface *surface, ViewStyle &vsDraw, PRectangle rcLine, Lin } } -void Editor::DrawIndicator(int indicNum, int startPos, int endPos, Surface *surface, ViewStyle &vsDraw, +void Editor::DrawIndicator(int indicNum, int startPos, int endPos, Surface *surface, const ViewStyle &vsDraw, int xStart, PRectangle rcLine, LineLayout *ll, int subLine) { const XYPOSITION subLineStart = ll->positions[ll->LineStart(subLine)]; PRectangle rcIndic( @@ -2661,7 +2664,7 @@ void Editor::DrawIndicator(int indicNum, int startPos, int endPos, Surface *surf vsDraw.indicators[indicNum].Draw(surface, rcIndic, rcLine); } -void Editor::DrawIndicators(Surface *surface, ViewStyle &vsDraw, int line, int xStart, +void Editor::DrawIndicators(Surface *surface, const ViewStyle &vsDraw, int line, int xStart, PRectangle rcLine, LineLayout *ll, int subLine, int lineEnd, bool under) { // Draw decorators const int posLineStart = pdoc->LineStart(line); @@ -2710,7 +2713,7 @@ void Editor::DrawIndicators(Surface *surface, ViewStyle &vsDraw, int line, int x } } -void Editor::DrawAnnotation(Surface *surface, ViewStyle &vsDraw, int line, int xStart, +void Editor::DrawAnnotation(Surface *surface, const ViewStyle &vsDraw, int line, int xStart, PRectangle rcLine, LineLayout *ll, int subLine) { int indent = static_cast<int>(pdoc->GetLineIndentation(line) * vsDraw.spaceWidth); PRectangle rcSegment = rcLine; @@ -2767,7 +2770,7 @@ void Editor::DrawAnnotation(Surface *surface, ViewStyle &vsDraw, int line, int x } } -void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVisible, int xStart, +void Editor::DrawLine(Surface *surface, const ViewStyle &vsDraw, int line, int lineVisible, int xStart, PRectangle rcLine, LineLayout *ll, int subLine) { if (subLine >= ll->lines) { @@ -2780,7 +2783,7 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis // Using one font for all control characters so it can be controlled independently to ensure // the box goes around the characters tightly. Seems to be no way to work out what height // is taken by an individual character - internal leading gives varying results. - Font &ctrlCharsFont = vsDraw.styles[STYLE_CONTROLCHAR].font; + FontAlias ctrlCharsFont = vsDraw.styles[STYLE_CONTROLCHAR].font; // See if something overrides the line background color: Either if caret is on the line // and background color is set for that, or if a marker is defined that forces its background @@ -3007,7 +3010,7 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis if (rcSegment.Intersects(rcLine)) { int styleMain = ll->styles[i]; ColourDesired textFore = vsDraw.styles[styleMain].fore; - Font &textFont = vsDraw.styles[styleMain].font; + FontAlias textFont = vsDraw.styles[styleMain].font; //hotspot foreground if (ll->hsStart != -1 && iDoc >= ll->hsStart && iDoc < hsEnd) { if (vsDraw.hotspotColours.fore.isSet) @@ -3253,7 +3256,7 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis } } -void Editor::DrawBlockCaret(Surface *surface, ViewStyle &vsDraw, LineLayout *ll, int subLine, +void Editor::DrawBlockCaret(Surface *surface, const ViewStyle &vsDraw, LineLayout *ll, int subLine, int xStart, int offset, int posCaret, PRectangle rcCaret, ColourDesired caretColour) { int lineStart = ll->LineStart(subLine); @@ -3312,7 +3315,8 @@ void Editor::DrawBlockCaret(Surface *surface, ViewStyle &vsDraw, LineLayout *ll, // This character is where the caret block is, we override the colours // (inversed) for drawing the caret here. int styleMain = ll->styles[offsetFirstChar]; - surface->DrawTextClipped(rcCaret, vsDraw.styles[styleMain].font, + FontAlias fontText = vsDraw.styles[styleMain].font; + surface->DrawTextClipped(rcCaret, fontText, rcCaret.top + vsDraw.maxAscent, ll->chars + offsetFirstChar, numCharsToDraw, vsDraw.styles[styleMain].back, caretColour); @@ -3386,7 +3390,7 @@ void Editor::RefreshPixMaps(Surface *surfaceWindow) { } } -void Editor::DrawCarets(Surface *surface, ViewStyle &vsDraw, int lineDoc, int xStart, +void Editor::DrawCarets(Surface *surface, const ViewStyle &vsDraw, int lineDoc, int xStart, PRectangle rcLine, LineLayout *ll, int subLine) { // When drag is active it is the only caret drawn bool drawDrag = posDrag.IsValid(); diff --git a/src/Editor.h b/src/Editor.h index 15a0fcf04..4826a1852 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -435,27 +435,27 @@ protected: // ScintillaBase subclass needs access to much of Editor int SubstituteMarkerIfEmpty(int markerCheck, int markerDefault) const; void PaintSelMargin(Surface *surface, PRectangle &rc); LineLayout *RetrieveLineLayout(int lineNumber); - void LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayout *ll, + void LayoutLine(int line, Surface *surface, const ViewStyle &vstyle, LineLayout *ll, int width=LineLayout::wrapWidthInfinite); - ColourDesired SelectionBackground(ViewStyle &vsDraw, bool main) const; - ColourDesired TextBackground(ViewStyle &vsDraw, bool overrideBackground, ColourDesired background, int inSelection, bool inHotspot, int styleMain, int i, LineLayout *ll) const; + ColourDesired SelectionBackground(const ViewStyle &vsDraw, bool main) const; + ColourDesired TextBackground(const ViewStyle &vsDraw, bool overrideBackground, ColourDesired background, int inSelection, bool inHotspot, int styleMain, int i, LineLayout *ll) const; void DrawIndentGuide(Surface *surface, int lineVisible, int lineHeight, int start, PRectangle rcSegment, bool highlight); static void DrawWrapMarker(Surface *surface, PRectangle rcPlace, bool isEndMarker, ColourDesired wrapColour); - void DrawEOL(Surface *surface, ViewStyle &vsDraw, PRectangle rcLine, LineLayout *ll, + void DrawEOL(Surface *surface, const ViewStyle &vsDraw, PRectangle rcLine, LineLayout *ll, int line, int lineEnd, int xStart, int subLine, XYACCUMULATOR subLineStart, bool overrideBackground, ColourDesired background, bool drawWrapMark, ColourDesired wrapColour); - static void DrawIndicator(int indicNum, int startPos, int endPos, Surface *surface, ViewStyle &vsDraw, + static void DrawIndicator(int indicNum, int startPos, int endPos, Surface *surface, const ViewStyle &vsDraw, int xStart, PRectangle rcLine, LineLayout *ll, int subLine); - void DrawIndicators(Surface *surface, ViewStyle &vsDraw, int line, int xStart, + void DrawIndicators(Surface *surface, const ViewStyle &vsDraw, int line, int xStart, PRectangle rcLine, LineLayout *ll, int subLine, int lineEnd, bool under); - void DrawAnnotation(Surface *surface, ViewStyle &vsDraw, int line, int xStart, + void DrawAnnotation(Surface *surface, const ViewStyle &vsDraw, int line, int xStart, PRectangle rcLine, LineLayout *ll, int subLine); - void DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVisible, int xStart, + void DrawLine(Surface *surface, const ViewStyle &vsDraw, int line, int lineVisible, int xStart, PRectangle rcLine, LineLayout *ll, int subLine); - void DrawBlockCaret(Surface *surface, ViewStyle &vsDraw, LineLayout *ll, int subLine, + void DrawBlockCaret(Surface *surface, const ViewStyle &vsDraw, LineLayout *ll, int subLine, int xStart, int offset, int posCaret, PRectangle rcCaret, ColourDesired caretColour); - void DrawCarets(Surface *surface, ViewStyle &vsDraw, int line, int xStart, + void DrawCarets(Surface *surface, const ViewStyle &vsDraw, int line, int xStart, PRectangle rcLine, LineLayout *ll, int subLine); void RefreshPixMaps(Surface *surfaceWindow); void Paint(Surface *surfaceWindow, PRectangle rcArea); diff --git a/src/Indicator.cxx b/src/Indicator.cxx index e51067a38..d8ad64ed6 100644 --- a/src/Indicator.cxx +++ b/src/Indicator.cxx @@ -23,7 +23,7 @@ static PRectangle PixelGridAlign(const PRectangle &rc) { return PRectangle::FromInts(int(rc.left + 0.5), int(rc.top), int(rc.right + 0.5), int(rc.bottom)); } -void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &rcLine) { +void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &rcLine) const { surface->PenColour(fore); int ymid = static_cast<int>(rc.bottom + rc.top) / 2; if (style == INDIC_SQUIGGLE) { diff --git a/src/Indicator.h b/src/Indicator.h index 0284a855b..beda8214b 100644 --- a/src/Indicator.h +++ b/src/Indicator.h @@ -23,7 +23,7 @@ public: int outlineAlpha; Indicator() : style(INDIC_PLAIN), under(false), fore(ColourDesired(0,0,0)), fillAlpha(30), outlineAlpha(50) { } - void Draw(Surface *surface, const PRectangle &rc, const PRectangle &rcLine); + void Draw(Surface *surface, const PRectangle &rc, const PRectangle &rcLine) const; }; #ifdef SCI_NAMESPACE diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index 0d2033bb9..2badeffbc 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -637,7 +637,7 @@ void PositionCache::SetSize(size_t size_) { pces.resize(size_); } -void PositionCache::MeasureWidths(Surface *surface, ViewStyle &vstyle, unsigned int styleNumber, +void PositionCache::MeasureWidths(Surface *surface, const ViewStyle &vstyle, unsigned int styleNumber, const char *s, unsigned int len, XYPOSITION *positions, Document *pdoc) { allClear = false; @@ -667,7 +667,8 @@ void PositionCache::MeasureWidths(Surface *surface, ViewStyle &vstyle, unsigned XYPOSITION xStartSegment = 0; while (startSegment < len) { unsigned int lenSegment = pdoc->SafeSegment(s + startSegment, len - startSegment, BreakFinder::lengthEachSubdivision); - surface->MeasureWidths(vstyle.styles[styleNumber].font, s + startSegment, lenSegment, positions + startSegment); + FontAlias fontStyle = vstyle.styles[styleNumber].font; + surface->MeasureWidths(fontStyle, s + startSegment, lenSegment, positions + startSegment); for (unsigned int inSeg = 0; inSeg < lenSegment; inSeg++) { positions[startSegment + inSeg] += xStartSegment; } @@ -675,7 +676,8 @@ void PositionCache::MeasureWidths(Surface *surface, ViewStyle &vstyle, unsigned startSegment += lenSegment; } } else { - surface->MeasureWidths(vstyle.styles[styleNumber].font, s, len, positions); + FontAlias fontStyle = vstyle.styles[styleNumber].font; + surface->MeasureWidths(fontStyle, s, len, positions); } if (probe < pces.size()) { // Store into cache diff --git a/src/PositionCache.h b/src/PositionCache.h index 614c81d38..53b407b71 100644 --- a/src/PositionCache.h +++ b/src/PositionCache.h @@ -189,7 +189,7 @@ public: void Clear(); void SetSize(size_t size_); size_t GetSize() const { return pces.size(); } - void MeasureWidths(Surface *surface, ViewStyle &vstyle, unsigned int styleNumber, + void MeasureWidths(Surface *surface, const ViewStyle &vstyle, unsigned int styleNumber, const char *s, unsigned int len, XYPOSITION *positions, Document *pdoc); }; diff --git a/src/Style.cxx b/src/Style.cxx index 8b5b42dbf..4297fa7cc 100644 --- a/src/Style.cxx +++ b/src/Style.cxx @@ -19,6 +19,10 @@ using namespace Scintilla; FontAlias::FontAlias() { } +FontAlias::FontAlias(const FontAlias &other) { + SetID(other.fid); +} + FontAlias::~FontAlias() { SetID(0); // ~Font will not release the actual font resource since it is now 0 diff --git a/src/Style.h b/src/Style.h index 4bd79de14..e8359e110 100644 --- a/src/Style.h +++ b/src/Style.h @@ -34,10 +34,10 @@ struct FontSpecification { // Just like Font but only has a copy of the FontID so should not delete it class FontAlias : public Font { // Private so FontAlias objects can not be copied - FontAlias(const FontAlias &); FontAlias &operator=(const FontAlias &); public: FontAlias(); + FontAlias(const FontAlias &); virtual ~FontAlias(); void MakeAlias(Font &fontOrigin); void ClearFont(); |