diff options
-rw-r--r-- | src/DBCS.h | 6 | ||||
-rw-r--r-- | src/Document.cxx | 2 | ||||
-rw-r--r-- | src/EditView.cxx | 24 | ||||
-rw-r--r-- | src/Editor.cxx | 16 | ||||
-rw-r--r-- | src/LineMarker.cxx | 2 | ||||
-rw-r--r-- | src/MarginView.cxx | 2 | ||||
-rw-r--r-- | src/PositionCache.cxx | 2 | ||||
-rw-r--r-- | src/Selection.cxx | 4 | ||||
-rw-r--r-- | src/Selection.h | 1 | ||||
-rw-r--r-- | win32/PlatWin.cxx | 8 | ||||
-rw-r--r-- | win32/ScintillaWin.cxx | 18 | ||||
-rw-r--r-- | win32/SurfaceD2D.cxx | 3 | ||||
-rw-r--r-- | win32/makefile | 1 |
13 files changed, 48 insertions, 41 deletions
diff --git a/src/DBCS.h b/src/DBCS.h index 12bbaf986..ba6230649 100644 --- a/src/DBCS.h +++ b/src/DBCS.h @@ -31,11 +31,9 @@ bool IsDBCSValidSingleByte(int codePage, int ch) noexcept; // Calculate a number from a DBCS byte pair that can be used to index into an array or map. // Should only be called with genuine DBCS character pairs which means that ch1 has top bit set. constexpr uint16_t DBCSIndex(char ch1, char ch2) noexcept { - constexpr unsigned int highStart = 0x80U; - constexpr unsigned int byteMultiply = 0x100U; - const unsigned char uch1 = ch1; + const unsigned char uch1 = ch1 & 0x7F; const unsigned char uch2 = ch2; - return ((uch1 - highStart) * byteMultiply) + uch2; + return (uch1 << 8) | uch2; } struct DBCSPair { diff --git a/src/Document.cxx b/src/Document.cxx index ddcf43276..8f6806824 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -120,7 +120,7 @@ void ActionDuration::AddSample(size_t numberActions, double durationOfActions) n // Most recent value contributes 25% to smoothed value. constexpr double alpha = 0.25; - const double durationOne = durationOfActions / numberActions; + const double durationOne = durationOfActions / static_cast<double>(numberActions); duration = std::clamp(alpha * durationOne + (1.0 - alpha) * duration, minDuration, maxDuration); } diff --git a/src/EditView.cxx b/src/EditView.cxx index 8215f7b68..e8c8562ec 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -670,8 +670,8 @@ Point EditView::LocationFromPosition(Surface *surface, const EditModel &model, S pt.y = static_cast<XYPOSITION>(subLine*vs.lineHeight); } } - pt.y += (lineVisible - topLine) * vs.lineHeight; - pt.x += pos.VirtualSpace() * vs.styles[ll->EndLineStyle()].spaceWidth; + pt.y += static_cast<XYPOSITION>((lineVisible - topLine) * vs.lineHeight); + pt.x += pos.VirtualSpaceWidth(vs.styles[ll->EndLineStyle()].spaceWidth); } return pt; } @@ -958,7 +958,7 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle XYPOSITION virtualSpace = 0; if (lastSubLine) { const XYPOSITION spaceWidth = vsDraw.styles[ll->EndLineStyle()].spaceWidth; - virtualSpace = model.sel.VirtualSpaceFor(model.pdoc->LineEnd(line)) * spaceWidth; + virtualSpace = static_cast<XYPOSITION>(model.sel.VirtualSpaceFor(model.pdoc->LineEnd(line))) * spaceWidth; } const XYPOSITION xEol = ll->positions[lineEnd] - subLineStart; @@ -977,9 +977,9 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle if (!portion.Empty()) { const XYPOSITION spaceWidth = vsDraw.styles[ll->EndLineStyle()].spaceWidth; rcSegment.left = xStart + ll->positions[portion.start.Position() - posLineStart] - - subLineStart+portion.start.VirtualSpace() * spaceWidth; + subLineStart + portion.start.VirtualSpaceWidth(spaceWidth); rcSegment.right = xStart + ll->positions[portion.end.Position() - posLineStart] - - subLineStart+portion.end.VirtualSpace() * spaceWidth; + subLineStart + portion.end.VirtualSpaceWidth(spaceWidth); rcSegment.left = (rcSegment.left > rcLine.left) ? rcSegment.left : rcLine.left; rcSegment.right = (rcSegment.right < rcLine.right) ? rcSegment.right : rcLine.right; surface->FillRectangleAligned(rcSegment, Fill( @@ -1149,8 +1149,8 @@ void EditView::DrawFoldDisplayText(Surface *surface, const EditModel &model, con } const XYPOSITION spaceWidth = vsDraw.styles[ll->EndLineStyle()].spaceWidth; - const XYPOSITION virtualSpace = model.sel.VirtualSpaceFor( - model.pdoc->LineEnd(line)) * spaceWidth; + const XYPOSITION virtualSpace = static_cast<XYPOSITION>(model.sel.VirtualSpaceFor( + model.pdoc->LineEnd(line))) * spaceWidth; rcSegment.left = xStart + ll->positions[ll->numCharsInLine] - subLineStart + virtualSpace + vsDraw.aveCharWidth; rcSegment.right = rcSegment.left + static_cast<XYPOSITION>(widthFoldDisplayText); @@ -1267,8 +1267,8 @@ void EditView::DrawEOLAnnotationText(Surface *surface, const EditModel &model, c leftBoxSpace + rightBoxSpace); const XYPOSITION spaceWidth = vsDraw.styles[ll->EndLineStyle()].spaceWidth; - const XYPOSITION virtualSpace = model.sel.VirtualSpaceFor( - model.pdoc->LineEnd(line)) * spaceWidth; + const XYPOSITION virtualSpace = static_cast<XYPOSITION>(model.sel.VirtualSpaceFor( + model.pdoc->LineEnd(line))) * spaceWidth; rcSegment.left = xStart + ll->positions[ll->numCharsInLine] - subLineStart + virtualSpace + vsDraw.aveCharWidth; @@ -1518,7 +1518,7 @@ void EditView::DrawCarets(Surface *surface, const EditModel &model, const ViewSt } const int offset = static_cast<int>(posCaret.Position() - posLineStart); const XYPOSITION spaceWidth = vsDraw.styles[ll->EndLineStyle()].spaceWidth; - const XYPOSITION virtualOffset = posCaret.VirtualSpace() * spaceWidth; + const XYPOSITION virtualOffset = posCaret.VirtualSpaceWidth(spaceWidth); if (ll->InLine(offset, subLine) && offset <= ll->numCharsBeforeEOL) { XYPOSITION xposCaret = ll->positions[offset] + virtualOffset - ll->positions[ll->LineStart(subLine)]; if (model.BidirectionalEnabled() && (posCaret.VirtualSpace() == 0)) { @@ -1785,7 +1785,9 @@ void DrawTranslucentSelection(Surface *surface, const EditModel &model, const Vi const ColourRGBA selectionBack = SelectionBackground( model, vsDraw, model.sel.RangeType(r)); const XYPOSITION spaceWidth = vsDraw.styles[ll->EndLineStyle()].spaceWidth; - const Interval intervalVirtual{ portion.start.VirtualSpace() * spaceWidth, portion.end.VirtualSpace() * spaceWidth }; + const Interval intervalVirtual{ + portion.start.VirtualSpaceWidth(spaceWidth), + portion.end.VirtualSpaceWidth(spaceWidth) }; if (model.BidirectionalEnabled()) { const SelectionSegment portionInSubLine = portionInLine.Subtract(lineRange.start); diff --git a/src/Editor.cxx b/src/Editor.cxx index 1557ce75e..ead69617d 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -267,7 +267,7 @@ PointDocument Editor::DocumentPointFromView(Point ptView) const { ptDocument.y += ptOrigin.y; } else { ptDocument.x += xOffset; - ptDocument.y += topLine * vs.lineHeight; + ptDocument.y += static_cast<double>(topLine * vs.lineHeight); } return ptDocument; } @@ -1113,9 +1113,9 @@ void Editor::MoveCaretInsideView(bool ensureVisible) { false, false, UserVirtualSpace()), Selection::SelTypes::none, ensureVisible); } else if ((pt.y + vs.lineHeight - 1) > rcClient.bottom) { - const ptrdiff_t yOfLastLineFullyDisplayed = static_cast<ptrdiff_t>(rcClient.top) + (LinesOnScreen() - 1) * vs.lineHeight; + const ptrdiff_t yOfLastLineFullyDisplayed = static_cast<ptrdiff_t>(rcClient.top) + ((LinesOnScreen() - 1) * vs.lineHeight); MovePositionTo(SPositionFromLocation( - Point::FromInts(lastXChosen - xOffset, static_cast<int>(rcClient.top + yOfLastLineFullyDisplayed)), + Point::FromInts(lastXChosen - xOffset, static_cast<int>(rcClient.top + static_cast<XYPOSITION>(yOfLastLineFullyDisplayed))), false, false, UserVirtualSpace()), Selection::SelTypes::none, ensureVisible); } @@ -1607,7 +1607,7 @@ bool Editor::WrapBlock(Surface *surface, Sci::Line lineToWrap, Sci::Line lineToW // Multiply duration by number of threads to produce (near) equivalence to duration if single threaded const double durationShortLines = epWrapping.Duration(true); - const double durationShortLinesThreads = durationShortLines * threads; + const double durationShortLinesThreads = durationShortLines * static_cast<double>(threads); // Wrap all the long lines in the main thread. // LayoutLine may then multi-thread over segments in each line. @@ -3366,7 +3366,7 @@ SelectionPosition Editor::PositionUpOrDown(SelectionPosition spStart, int direct // There is an equivalent case when moving down which skips // over a line. Point ptNew = LocationFromPosition(posNew.Position()); - while ((posNew.Position() > spStart.Position()) && (ptNew.y > newY)) { + while ((posNew.Position() > spStart.Position()) && (ptNew.y > static_cast<XYPOSITION>(newY))) { posNew.Add(-1); posNew.SetVirtualSpace(0); ptNew = LocationFromPosition(posNew.Position()); @@ -4175,7 +4175,7 @@ void Editor::Indent(bool forwards, bool lineIndent) { sel.Range(r) = SelectionRange(caretPosition + lengthInserted); } else { int numSpaces = (pdoc->tabInChars) - - (pdoc->GetColumn(caretPosition) % (pdoc->tabInChars)); + static_cast<int>((pdoc->GetColumn(caretPosition) % (pdoc->tabInChars))); if (numSpaces < 1) numSpaces = pdoc->tabInChars; const std::string spaceText(numSpaces, ' '); @@ -7487,7 +7487,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { break; case Message::MarkerSetStrokeWidth: if (wParam <= MarkerMax) - vs.markers[wParam].strokeWidth = lParam / 100.0f; + vs.markers[wParam].strokeWidth = static_cast<XYPOSITION>(lParam) / 100.0f; InvalidateStyleData(); RedrawSelMargin(); break; @@ -8181,7 +8181,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { case Message::IndicSetStrokeWidth: if (wParam <= IndicatorMax && lParam >= 0 && lParam <= 1000) { - vs.indicators[wParam].strokeWidth = lParam / 100.0f; + vs.indicators[wParam].strokeWidth = static_cast<XYPOSITION>(lParam) / 100.0; InvalidateStyleRedraw(); } break; diff --git a/src/LineMarker.cxx b/src/LineMarker.cxx index 0afa64f2b..faa32d9aa 100644 --- a/src/LineMarker.cxx +++ b/src/LineMarker.cxx @@ -196,7 +196,7 @@ void LineMarker::DrawFoldingMark(Surface *surface, const PRectangle &rcWhole, Fo // To centre +/-, odd strokeWidth -> odd symbol width, even -> even const XYPOSITION widthSymbol = ((std::lround(minDimension * pixelDivisions) % 2) == (std::lround(widthStroke * pixelDivisions) % 2)) ? - minDimension : minDimension - 1.0f / pixelDivisions; + minDimension : minDimension - (1.0 / static_cast<XYPOSITION>(pixelDivisions)); const Point centre = PixelAlign(rcWhole.Centre(), pixelDivisions); diff --git a/src/MarginView.cxx b/src/MarginView.cxx index 348b5dd05..09b01959e 100644 --- a/src/MarginView.cxx +++ b/src/MarginView.cxx @@ -278,7 +278,7 @@ void MarginView::PaintOneMargin(Surface *surface, PRectangle rc, PRectangle rcOn const Point ptOrigin = model.GetVisibleOriginInMain(); const Sci::Line lineStartPaint = static_cast<Sci::Line>(rcOneMargin.top + ptOrigin.y) / vs.lineHeight; Sci::Line visibleLine = model.TopLineOfMain() + lineStartPaint; - XYPOSITION yposScreen = lineStartPaint * vs.lineHeight - ptOrigin.y; + XYPOSITION yposScreen = static_cast<XYPOSITION>(lineStartPaint * vs.lineHeight) - ptOrigin.y; // Work out whether the top line is whitespace located after a // lessening of fold level which implies a 'fold tail' but which should not // be displayed until the last of a sequence of whitespace. diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index df5e5acf9..89276d2a0 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -1133,7 +1133,7 @@ void PositionCache::MeasureWidths(Surface *surface, const ViewStyle &vstyle, uns if (AllGraphicASCII(sv)) { const XYPOSITION monospaceCharacterWidth = style.monospaceCharacterWidth; for (size_t i = 0; i < sv.length(); i++) { - positions[i] = monospaceCharacterWidth * (i+1); + positions[i] = monospaceCharacterWidth * static_cast<XYPOSITION>(i+1); } return; } diff --git a/src/Selection.cxx b/src/Selection.cxx index 0de60a958..795570ee2 100644 --- a/src/Selection.cxx +++ b/src/Selection.cxx @@ -96,6 +96,10 @@ bool SelectionPosition::operator >=(const SelectionPosition &other) const noexce return *this > other; } +double SelectionPosition::VirtualSpaceWidth(double spaceWidth) const noexcept { + return static_cast<double>(virtualSpace) * spaceWidth; +} + std::string SelectionPosition::ToString() const { std::string result = std::to_string(position); if (virtualSpace) { diff --git a/src/Selection.h b/src/Selection.h index 8ffcbb0bb..6779ee7ce 100644 --- a/src/Selection.h +++ b/src/Selection.h @@ -50,6 +50,7 @@ public: Sci::Position VirtualSpace() const noexcept { return virtualSpace; } + [[nodiscard]] double VirtualSpaceWidth(double spaceWidth) const noexcept; void SetVirtualSpace(Sci::Position virtualSpace_) noexcept { PLATFORM_ASSERT(virtualSpace_ < 800000000); if (virtualSpace_ >= 0) diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 02f31cc5e..ff47c28ab 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -168,7 +168,7 @@ float GetDeviceScaleFactorWhenGdiScalingActive(HWND hWnd) noexcept { const HMONITOR hMonitor = MonitorFromWindowHandleScaling(hRootWnd); DEVICE_SCALE_FACTOR deviceScaleFactor; if (S_OK == fnGetScaleFactorForMonitor(hMonitor, &deviceScaleFactor)) - return static_cast<int>(deviceScaleFactor) / 100.f; + return static_cast<float>(static_cast<int>(deviceScaleFactor)) / 100.f; } } return 1.f; @@ -404,6 +404,8 @@ class CursorHelper { DWORD *pixels = nullptr; const int width; const int height; + const float scale; + static constexpr float baseSize = 32.0f; static constexpr float arrow[][2] = { { 32.0f - 12.73606f,32.0f - 19.04075f }, @@ -418,7 +420,7 @@ class CursorHelper { public: ~CursorHelper() = default; - CursorHelper(int width_, int height_) noexcept : width{width_}, height{height_} { + CursorHelper(int width_, int height_) noexcept : width{width_}, height{height_}, scale{ static_cast<float>(width) / baseSize } { // https://learn.microsoft.com/en-us/windows/win32/menurc/using-cursors#creating-a-cursor bm.Create({}, width, height, &pixels); } @@ -470,7 +472,6 @@ public: // Draw something on the bitmap section. constexpr size_t nPoints = std::size(arrow); D2D1_POINT_2F points[nPoints]{}; - const FLOAT scale = width/32.0f; for (size_t i = 0; i < nPoints; i++) { points[i].x = arrow[i][0] * scale; points[i].y = arrow[i][1] * scale; @@ -519,7 +520,6 @@ public: // Draw something on the DIB section. constexpr size_t nPoints = std::size(arrow); POINT points[nPoints]{}; - const float scale = width/32.0f; for (size_t i = 0; i < nPoints; i++) { points[i].x = std::lround(arrow[i][0] * scale); points[i].y = std::lround(arrow[i][1] * scale); diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index d6ae32736..f31d1291f 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -874,7 +874,7 @@ void ScintillaWin::CreateRenderTarget() { const RECT rc = GetClientRect(hw); const int integralDeviceScaleFactor = GetFirstIntegralMultipleDeviceScaleFactor(); - const FLOAT dpiTarget = dpiDefault * integralDeviceScaleFactor; + const FLOAT dpiTarget = dpiDefault * static_cast<float>(integralDeviceScaleFactor); const D2D1_RENDER_TARGET_PROPERTIES drtp = D2D1::RenderTargetProperties( D2D1_RENDER_TARGET_TYPE_DEFAULT, @@ -1009,7 +1009,7 @@ void ScintillaWin::DisplayCursor(Window::Cursor c) { c = static_cast<Window::Cursor>(cursorMode); } if (c == Window::Cursor::reverseArrow) { - ::SetCursor(reverseArrowCursor.Load(static_cast<UINT>(dpi * deviceScaleFactor))); + ::SetCursor(reverseArrowCursor.Load(static_cast<UINT>(static_cast<float>(dpi) * deviceScaleFactor))); } else { wMain.SetCursor(c); } @@ -2809,11 +2809,11 @@ constexpr int minTrailByte = 0x30; // CreateFoldMap creates a fold map by calling platform APIs so will differ between platforms. void CreateFoldMap(int codePage, FoldMap *foldingMap) { - for (int byte1 = highByteFirst; byte1 <= highByteLast; byte1++) { - const char ch1 = byte1 & 0xFF; // & 0xFF avoids warnings but has no real effect. + for (unsigned char byte1 = highByteLast; byte1 >= highByteFirst; byte1--) { + const char ch1 = byte1; if (DBCSIsLeadByte(codePage, ch1)) { - for (int byte2 = minTrailByte; byte2 <= highByteLast; byte2++) { - const char ch2 = byte2 & 0xFF; + for (unsigned char byte2 = highByteLast; byte2 >= minTrailByte; byte2--) { + const char ch2 = byte2; if (DBCSIsTrailByte(codePage, ch2)) { const DBCSPair pair{ ch1, ch2 }; const uint16_t index = DBCSIndex(ch1, ch2); @@ -3426,8 +3426,8 @@ LRESULT ScintillaWin::ImeOnReconvert(LPARAM lParam) { return 0; // No selection asks IME to fill target fields with its own value. - const int tgWlen = rc->dwTargetStrLen; - const int tgWstart = rc->dwTargetStrOffset / sizeof(wchar_t); + const size_t tgWlen = rc->dwTargetStrLen; + const size_t tgWstart = rc->dwTargetStrOffset / sizeof(wchar_t); std::string tgCompStart = StringEncode(rcFeed.substr(0, tgWstart), codePage); std::string tgComp = StringEncode(rcFeed.substr(tgWstart, tgWlen), codePage); @@ -3945,7 +3945,7 @@ void ScintillaWin::CTPaint(HWND hWnd) { // Create a Direct2D render target. - const FLOAT dpiTarget = dpiDefault * scaleFactor; + const FLOAT dpiTarget = dpiDefault * static_cast<float>(scaleFactor); const D2D1_RENDER_TARGET_PROPERTIES drtp = D2D1::RenderTargetProperties( D2D1_RENDER_TARGET_TYPE_DEFAULT, diff --git a/win32/SurfaceD2D.cxx b/win32/SurfaceD2D.cxx index fa8383a84..223d35fcf 100644 --- a/win32/SurfaceD2D.cxx +++ b/win32/SurfaceD2D.cxx @@ -1382,7 +1382,8 @@ HRESULT MeasurePositions(TextPositions &poses, const TextWide &tbuf, IDWriteText int ti=0; for (unsigned int ci=0; ci<count; ci++) { for (unsigned int inCluster=0; inCluster<clusterMetrics[ci].length; inCluster++) { - poses.buffer[ti++] = position + clusterMetrics[ci].width * (inCluster + 1) / clusterMetrics[ci].length; + const float proportion = static_cast<float>(inCluster + 1) / clusterMetrics[ci].length; + poses.buffer[ti++] = position + clusterMetrics[ci].width * proportion; } position += clusterMetrics[ci].width; } diff --git a/win32/makefile b/win32/makefile index 72634889f..5db9e6625 100644 --- a/win32/makefile +++ b/win32/makefile @@ -23,6 +23,7 @@ else # MinGW GCC LIBSMINGW = -lstdc++ STRIPOPTION = -s +WARNINGS += -Wconversion endif ARFLAGS = rc RANLIB ?= ranlib |