aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMarko Njezic <unknown>2012-01-18 21:53:42 +0100
committerMarko Njezic <unknown>2012-01-18 21:53:42 +0100
commit4d0bdd15b57bff55cfcc58eb4ab91ccdf55d1c51 (patch)
tree10f4d2a8642d7c9c8b2d801591184714a5fe5a87 /src
parentf68be5f8dda0925786c1130f1ed2da9f7bbc2e6c (diff)
downloadscintilla-mirror-4d0bdd15b57bff55cfcc58eb4ab91ccdf55d1c51.tar.gz
Change wrapIndent, wrapAddIndent, aveCharWidth to support fractional values.
This improves sub-pixel alignment of indented wrapped lines and sub-pixel positioning that uses aveCharWidth in calculations. Added type casts to certain places to make it clear that loss of precision occurs due to assignment of float to int.
Diffstat (limited to 'src')
-rw-r--r--src/Editor.cxx23
-rw-r--r--src/Editor.h2
-rw-r--r--src/PositionCache.h2
-rw-r--r--src/ViewStyle.h2
4 files changed, 15 insertions, 14 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 6919d91d7..b1947c151 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -567,21 +567,22 @@ SelectionPosition Editor::SPositionFromLineX(int lineDoc, int x) {
int lineStart = ll->LineStart(subLine);
int lineEnd = ll->LineLastVisible(subLine);
XYPOSITION subLineStart = ll->positions[lineStart];
+ XYPOSITION newX = x;
if (ll->wrapIndent != 0) {
if (lineStart != 0) // Wrapped
- x -= ll->wrapIndent;
+ newX -= ll->wrapIndent;
}
- int i = ll->FindBefore(x + subLineStart, lineStart, lineEnd);
+ int i = ll->FindBefore(newX + subLineStart, lineStart, lineEnd);
while (i < lineEnd) {
- if ((x + subLineStart) < ((ll->positions[i] + ll->positions[i + 1]) / 2)) {
+ if ((newX + subLineStart) < ((ll->positions[i] + ll->positions[i + 1]) / 2)) {
retVal = pdoc->MovePositionOutsideChar(i + posLineStart, 1);
return SelectionPosition(retVal);
}
i++;
}
const XYPOSITION spaceWidth = vs.styles[ll->EndLineStyle()].spaceWidth;
- int spaceOffset = (x + subLineStart - ll->positions[lineEnd] + spaceWidth / 2) / spaceWidth;
+ int spaceOffset = (newX + subLineStart - ll->positions[lineEnd] + spaceWidth / 2) / spaceWidth;
return SelectionPosition(lineEnd + posLineStart, spaceOffset);
}
return SelectionPosition(retVal);
@@ -1354,7 +1355,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const bool useMargin, con
newXY.xOffset = pt.x + xOffset - rcClient.right + 1;
if (vs.caretStyle == CARETSTYLE_BLOCK) {
// Ensure we can see a good portion of the block caret
- newXY.xOffset += vs.aveCharWidth;
+ newXY.xOffset += static_cast<int>(vs.aveCharWidth);
}
}
if (newXY.xOffset < 0) {
@@ -2304,7 +2305,7 @@ void Editor::LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayou
ll->lines = 1;
} else {
if (wrapVisualFlags & SC_WRAPVISUALFLAG_END) {
- width -= vstyle.aveCharWidth; // take into account the space for end wrap mark
+ width -= static_cast<int>(vstyle.aveCharWidth); // take into account the space for end wrap mark
}
ll->wrapIndent = wrapAddIndent;
if (wrapIndentMode != SC_WRAPINDENT_FIXED)
@@ -2318,7 +2319,7 @@ void Editor::LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayou
if (ll->wrapIndent > width - static_cast<int>(vstyle.aveCharWidth) * 15)
ll->wrapIndent = wrapAddIndent;
// Check for wrapIndent minimum
- if ((wrapVisualFlags & SC_WRAPVISUALFLAG_START) && (ll->wrapIndent < static_cast<int>(vstyle.aveCharWidth)))
+ if ((wrapVisualFlags & SC_WRAPVISUALFLAG_START) && (ll->wrapIndent < vstyle.aveCharWidth))
ll->wrapIndent = vstyle.aveCharWidth; // Indent to show start visual
ll->lines = 0;
// Calculate line start positions based upon width.
@@ -2874,7 +2875,7 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis
DrawWrapMarker(surface, rcPlace, false, wrapColour);
}
- xStart += ll->wrapIndent;
+ xStart += static_cast<int>(ll->wrapIndent);
}
}
@@ -2882,7 +2883,7 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis
((vsDraw.selAlpha == SC_ALPHA_NOALPHA) || (vsDraw.selAdditionalAlpha == SC_ALPHA_NOALPHA));
// Does not take margin into account but not significant
- int xStartVisible = subLineStart - xStart;
+ int xStartVisible = static_cast<int>(subLineStart) - xStart;
ll->psel = &sel;
@@ -3288,7 +3289,7 @@ void Editor::DrawBlockCaret(Surface *surface, ViewStyle &vsDraw, LineLayout *ll,
// Adjust caret position to take into account any word wrapping symbols.
if ((ll->wrapIndent != 0) && (lineStart != 0)) {
- int wordWrapCharWidth = ll->wrapIndent;
+ XYPOSITION wordWrapCharWidth = ll->wrapIndent;
rcCaret.left += wordWrapCharWidth;
rcCaret.right += wordWrapCharWidth;
}
@@ -3395,7 +3396,7 @@ void Editor::DrawCarets(Surface *surface, ViewStyle &vsDraw, int lineDoc, int xS
bool caretAtEOF = false;
bool caretAtEOL = false;
bool drawBlockCaret = false;
- int widthOverstrikeCaret;
+ XYPOSITION widthOverstrikeCaret;
int caretWidthOffset = 0;
PRectangle rcCaret = rcLine;
diff --git a/src/Editor.h b/src/Editor.h
index 90a109cc3..0923f4051 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -264,7 +264,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
int wrapVisualFlags;
int wrapVisualFlagsLocation;
int wrapVisualStartIndent;
- int wrapAddIndent; // This will be added to initial indent of line
+ XYPOSITION wrapAddIndent; // This will be added to initial indent of line
int wrapIndentMode; // SC_WRAPINDENT_FIXED, _SAME, _INDENT
bool convertPastes;
diff --git a/src/PositionCache.h b/src/PositionCache.h
index bd27783c9..08ecee10a 100644
--- a/src/PositionCache.h
+++ b/src/PositionCache.h
@@ -51,7 +51,7 @@ public:
// Wrapped line support
int widthLine;
int lines;
- int wrapIndent; // In pixels
+ XYPOSITION wrapIndent; // In pixels
LineLayout(int maxLineLength_);
virtual ~LineLayout();
diff --git a/src/ViewStyle.h b/src/ViewStyle.h
index 4ee7f2a3e..3803a6cb2 100644
--- a/src/ViewStyle.h
+++ b/src/ViewStyle.h
@@ -71,7 +71,7 @@ public:
int lineHeight;
unsigned int maxAscent;
unsigned int maxDescent;
- unsigned int aveCharWidth;
+ XYPOSITION aveCharWidth;
XYPOSITION spaceWidth;
bool selforeset;
ColourDesired selforeground;