diff options
author | mitchell <unknown> | 2019-03-31 23:20:01 -0400 |
---|---|---|
committer | mitchell <unknown> | 2019-03-31 23:20:01 -0400 |
commit | 2c20e36f4ec739fd0887aceda589fce2c1757342 (patch) | |
tree | 7a00c34eab91ecec5e28a45df72f22d3c99d8701 | |
parent | de07b9abd6711d657c170de23871ddb5503a1011 (diff) | |
download | scintilla-mirror-2c20e36f4ec739fd0887aceda589fce2c1757342.tar.gz |
Backport: Use generic versions of ceil, floor, round, lround, trunc from <cmath>.
Backport of changeset 7329:2662ef098d93, but without std::round and std::lround,
since older Mac OSX SDKs may not have them.
-rw-r--r-- | cocoa/InfoBar.mm | 4 | ||||
-rw-r--r-- | cocoa/PlatCocoa.mm | 13 | ||||
-rw-r--r-- | cocoa/ScintillaCocoa.mm | 4 | ||||
-rw-r--r-- | cocoa/ScintillaView.mm | 6 | ||||
-rw-r--r-- | gtk/PlatGTK.cxx | 4 | ||||
-rw-r--r-- | gtk/ScintillaGTK.cxx | 8 | ||||
-rw-r--r-- | src/CallTip.cxx | 2 | ||||
-rw-r--r-- | src/EditView.cxx | 10 | ||||
-rw-r--r-- | src/Indicator.cxx | 8 | ||||
-rw-r--r-- | win32/PlatWin.cxx | 30 |
10 files changed, 48 insertions, 41 deletions
diff --git a/cocoa/InfoBar.mm b/cocoa/InfoBar.mm index c7061e6f7..19f2c6943 100644 --- a/cocoa/InfoBar.mm +++ b/cocoa/InfoBar.mm @@ -10,6 +10,8 @@ * This file is dual licensed under LGPL v2.1 and the Scintilla license (http://www.scintilla.org/License.txt). */ +#include <cmath> + #import "InfoBar.h" //-------------------------------------------------------------------------------------------------- @@ -36,7 +38,7 @@ if (heightDelta > 0) { newRect.size.height -= heightDelta; - newRect.origin.y += ceil(heightDelta / 2); + newRect.origin.y += std::ceil(heightDelta / 2); } } diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index 65481c252..9ba85bc66 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -17,6 +17,7 @@ #include <cassert> #include <cstring> #include <cstdio> +#include <cmath> #include <stdexcept> #include <vector> @@ -455,8 +456,8 @@ void SurfaceImpl::FillRectangle(PRectangle rc, ColourDesired back) { FillColour(back); // Snap rectangle boundaries to nearest int - rc.left = lround(rc.left); - rc.right = lround(rc.right); + rc.left = std::round(rc.left); + rc.right = std::round(rc.right); CGRect rect = PRectangleToCGRect(rc); CGContextFillRect(gc, rect); } @@ -646,8 +647,8 @@ void Scintilla::SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, Colou { if ( gc ) { // Snap rectangle boundaries to nearest int - rc.left = lround(rc.left); - rc.right = lround(rc.right); + rc.left = std::round(rc.left); + rc.right = std::round(rc.right); // Set the Fill color to match CGContextSetRGBFillColor( gc, fill.GetRed() / 255.0, fill.GetGreen() / 255.0, fill.GetBlue() / 255.0, alphaFill / 255.0 ); CGContextSetRGBStrokeColor( gc, outline.GetRed() / 255.0, outline.GetGreen() / 255.0, outline.GetBlue() / 255.0, alphaOutline / 255.0 ); @@ -1064,7 +1065,7 @@ XYPOSITION SurfaceImpl::AverageCharWidth(Font &font_) { const int sizeStringLength = ELEMENTS( sizeString ); XYPOSITION width = WidthText( font_, sizeString, sizeStringLength ); - return round(width / sizeStringLength); + return std::round(width / sizeStringLength); } void SurfaceImpl::SetClip(PRectangle rc) { @@ -1651,7 +1652,7 @@ void ListBoxImpl::SetFont(Font& font_) font.SetID(new QuartzTextStyle(*style)); NSFont *pfont = (NSFont *)style->getFontRef(); [[colText dataCell] setFont: pfont]; - CGFloat itemHeight = ceil([pfont boundingRectForFont].size.height); + CGFloat itemHeight = std::ceil([pfont boundingRectForFont].size.height); [table setRowHeight:itemHeight]; } diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index d262e79b2..3eaf17665 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -14,6 +14,8 @@ * This file is dual licensed under LGPL v2.1 and the Scintilla license (http://www.scintilla.org/License.txt). */ +#include <cmath> + #include <vector> #import <Cocoa/Cocoa.h> @@ -2622,7 +2624,7 @@ void ScintillaCocoa::ShowFindIndicatorForRange(NSRange charRange, BOOL retaining layerFindIndicator = [[FindHighlightLayer alloc] init]; [content setWantsLayer: YES]; layerFindIndicator.geometryFlipped = content.layer.geometryFlipped; - if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_8) + if (std::floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_8) { // Content layer is unflipped on 10.9, but the indicator shows wrong unless flipped layerFindIndicator.geometryFlipped = YES; diff --git a/cocoa/ScintillaView.mm b/cocoa/ScintillaView.mm index 5ff9457d4..d1816a25d 100644 --- a/cocoa/ScintillaView.mm +++ b/cocoa/ScintillaView.mm @@ -9,6 +9,8 @@ * This file is dual licensed under LGPL v2.1 and the Scintilla license (http://www.scintilla.org/License.txt). */ +#include <cmath> + #include <vector> #import "Platform.h" @@ -811,14 +813,14 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) // Only snap for positions inside the document - allow outside // for overshoot. long lineHeight = mOwner.backend->WndProc(SCI_TEXTHEIGHT, 0, 0); - rc.origin.y = roundf(static_cast<XYPOSITION>(rc.origin.y) / lineHeight) * lineHeight; + rc.origin.y = std::round(static_cast<XYPOSITION>(rc.origin.y) / lineHeight) * lineHeight; } // Snap to whole points - on retina displays this avoids visual debris // when scrolling horizontally. if ((rc.origin.x > 0) && (NSMaxX(rc) < contentRect.size.width)) { // Only snap for positions inside the document - allow outside // for overshoot. - rc.origin.x = roundf(static_cast<XYPOSITION>(rc.origin.x)); + rc.origin.x = std::round(static_cast<XYPOSITION>(rc.origin.x)); } return rc; } diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index 26e1b5f58..d9485c048 100644 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -453,8 +453,8 @@ void SurfaceImpl::RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired void SurfaceImpl::FillRectangle(PRectangle rc, ColourDesired back) { PenColour(back); if (context && (rc.left < maxCoordinate)) { // Protect against out of range - rc.left = lround(rc.left); - rc.right = lround(rc.right); + rc.left = std::round(rc.left); + rc.right = std::round(rc.right); cairo_rectangle(context, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); cairo_fill(context); diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index 24d2ef212..129da2b07 100644 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -1680,8 +1680,8 @@ gint ScintillaGTK::PressThis(GdkEventButton *event) { evbtn = gdk_event_copy(reinterpret_cast<GdkEvent *>(event)); buttonMouse = event->button; Point pt; - pt.x = floor(event->x); - pt.y = floor(event->y); + pt.x = std::floor(event->x); + pt.y = std::floor(event->y); PRectangle rcClient = GetClientRectangle(); //Platform::DebugPrintf("Press %0d,%0d in %0d,%0d %0d,%0d\n", // pt.x, pt.y, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom); @@ -1810,12 +1810,12 @@ gint ScintillaGTK::ScrollEvent(GtkWidget *widget, GdkEventScroll *event) { sciThis->smoothScrollY += event->delta_y * smoothScrollFactor; sciThis->smoothScrollX += event->delta_x * smoothScrollFactor;; if (ABS(sciThis->smoothScrollY) >= 1.0) { - const int scrollLines = trunc(sciThis->smoothScrollY); + const int scrollLines = std::trunc(sciThis->smoothScrollY); sciThis->ScrollTo(sciThis->topLine + scrollLines); sciThis->smoothScrollY -= scrollLines; } if (ABS(sciThis->smoothScrollX) >= 1.0) { - const int scrollPixels = trunc(sciThis->smoothScrollX); + const int scrollPixels = std::trunc(sciThis->smoothScrollX); sciThis->HorizontalScrollTo(sciThis->xOffset + scrollPixels); sciThis->smoothScrollX -= scrollPixels; } diff --git a/src/CallTip.cxx b/src/CallTip.cxx index 2dcf91ea6..18c4549bb 100644 --- a/src/CallTip.cxx +++ b/src/CallTip.cxx @@ -176,7 +176,7 @@ int CallTip::PaintContents(Surface *surfaceWindow, bool draw) { PRectangle rcClient(1.0f, 1.0f, rcClientSize.right - 1, rcClientSize.bottom - 1); // To make a nice small call tip window, it is only sized to fit most normal characters without accents - const int ascent = static_cast<int>(lround(surfaceWindow->Ascent(font) - surfaceWindow->InternalLeading(font))); + const int ascent = static_cast<int>(round(surfaceWindow->Ascent(font) - surfaceWindow->InternalLeading(font))); // For each line... // Draw the definition in three parts: before highlight, highlighted, after highlight diff --git a/src/EditView.cxx b/src/EditView.cxx index 24be8b974..558a16b38 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -648,7 +648,7 @@ Range EditView::RangeDisplayLine(Surface *surface, const EditModel &model, Sci:: SelectionPosition EditView::SPositionFromLocation(Surface *surface, const EditModel &model, PointDocument pt, bool canReturnInvalid, bool charPosition, bool virtualSpace, const ViewStyle &vs) { pt.x = pt.x - vs.textStart; - Sci::Line visibleLine = static_cast<int>(floor(pt.y / vs.lineHeight)); + Sci::Line visibleLine = static_cast<int>(std::floor(pt.y / vs.lineHeight)); if (!canReturnInvalid && (visibleLine < 0)) visibleLine = 0; const Sci::Line lineDoc = model.pcs->DocFromDisplay(visibleLine); @@ -815,7 +815,7 @@ static void DrawTextBlob(Surface *surface, const ViewStyle &vsDraw, PRectangle r surface->FillRectangle(rcSegment, textBack); } FontAlias ctrlCharsFont = vsDraw.styles[STYLE_CONTROLCHAR].font; - const int normalCharHeight = static_cast<int>(ceil(vsDraw.styles[STYLE_CONTROLCHAR].capitalHeight)); + const int normalCharHeight = static_cast<int>(std::ceil(vsDraw.styles[STYLE_CONTROLCHAR].capitalHeight)); PRectangle rcCChar = rcSegment; rcCChar.left = rcCChar.left + 1; rcCChar.top = rcSegment.top + vsDraw.maxAscent - normalCharHeight; @@ -1711,7 +1711,7 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi indentCount <= (ll->positions[i + 1] - epsilon) / indentWidth; indentCount++) { if (indentCount > 0) { - const XYPOSITION xIndent = floor(indentCount * indentWidth); + const XYPOSITION xIndent = std::floor(indentCount * indentWidth); DrawIndentGuide(surface, lineVisible, vsDraw.lineHeight, xIndent + xStart, rcSegment, (ll->xHighlightGuide == xIndent)); } @@ -1791,7 +1791,7 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi indentCount <= (ll->positions[cpos + ts.start + 1] - epsilon) / indentWidth; indentCount++) { if (indentCount > 0) { - const XYPOSITION xIndent = floor(indentCount * indentWidth); + const XYPOSITION xIndent = std::floor(indentCount * indentWidth); DrawIndentGuide(surface, lineVisible, vsDraw.lineHeight, xIndent + xStart, rcSegment, (ll->xHighlightGuide == xIndent)); } @@ -1868,7 +1868,7 @@ void EditView::DrawIndentGuidesOverEmpty(Surface *surface, const EditModel &mode } for (int indentPos = model.pdoc->IndentSize(); indentPos < indentSpace; indentPos += model.pdoc->IndentSize()) { - const XYPOSITION xIndent = floor(indentPos * vsDraw.spaceWidth); + const XYPOSITION xIndent = std::floor(indentPos * vsDraw.spaceWidth); if (xIndent < xStartText) { DrawIndentGuide(surface, lineVisible, vsDraw.lineHeight, xIndent + xStart, rcLine, (ll->xHighlightGuide == xIndent)); diff --git a/src/Indicator.cxx b/src/Indicator.cxx index 544bd571d..24cd40820 100644 --- a/src/Indicator.cxx +++ b/src/Indicator.cxx @@ -25,8 +25,8 @@ using namespace Scintilla; static PRectangle PixelGridAlign(const PRectangle &rc) { // Move left and right side to nearest pixel to avoid blurry visuals - return PRectangle(round(rc.left), floor(rc.top), - round(rc.right), floor(rc.bottom)); + return PRectangle(round(rc.left), std::floor(rc.top), + round(rc.right), std::floor(rc.bottom)); } void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &rcLine, const PRectangle &rcCharacter, DrawState drawState, int value) const { @@ -201,10 +201,10 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r surface->FillRectangle(rcComposition, sacDraw.fore); } else if (sacDraw.style == INDIC_POINT || sacDraw.style == INDIC_POINTCHARACTER) { if (rcCharacter.Width() >= 0.1) { - const XYPOSITION pixelHeight = floor(rc.Height() - 1.0f); // 1 pixel onto next line if multiphase + const XYPOSITION pixelHeight = std::floor(rc.Height() - 1.0f); // 1 pixel onto next line if multiphase const XYPOSITION x = (sacDraw.style == INDIC_POINT) ? (rcCharacter.left) : ((rcCharacter.right + rcCharacter.left) / 2); const XYPOSITION ix = round(x); - const XYPOSITION iy = floor(rc.top + 1.0f); + const XYPOSITION iy = std::floor(rc.top + 1.0f); Point pts[] = { Point(ix - pixelHeight, iy + pixelHeight), // Left Point(ix + pixelHeight, iy + pixelHeight), // Right diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 2c54cd8dd..a60c81b50 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -278,7 +278,7 @@ D2D1_TEXT_ANTIALIAS_MODE DWriteMapFontQuality(int extraFontFlag) noexcept { void SetLogFont(LOGFONTW &lf, const char *faceName, int characterSet, float size, int weight, bool italic, int extraFontFlag) { lf = LOGFONTW(); // The negative is to allow for leading - lf.lfHeight = -(abs(lround(size))); + lf.lfHeight = -(abs(std::lround(size))); lf.lfWeight = weight; lf.lfItalic = italic ? 1 : 0; lf.lfCharSet = static_cast<BYTE>(characterSet); @@ -745,10 +745,10 @@ void SurfaceGDI::DrawRGBAImage(PRectangle rc, int width, int height, const unsig if (rc.Width() > 0) { HDC hMemDC = ::CreateCompatibleDC(hdc); if (rc.Width() > width) - rc.left += floor((rc.Width() - width) / 2); + rc.left += std::floor((rc.Width() - width) / 2); rc.right = rc.left + width; if (rc.Height() > height) - rc.top += floor((rc.Height() - height) / 2); + rc.top += std::floor((rc.Height() - height) / 2); rc.bottom = rc.top + height; const BITMAPINFO bpih = {{sizeof(BITMAPINFOHEADER), width, height, 1, 32, BI_RGB, 0, 0, 0, 0, 0}, @@ -1265,7 +1265,7 @@ void SurfaceD2D::Polygon(Point *pts, size_t npts, ColourDesired fore, ColourDesi void SurfaceD2D::RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back) { if (pRenderTarget) { - const D2D1_RECT_F rectangle1 = D2D1::RectF(round(rc.left) + 0.5f, rc.top+0.5f, round(rc.right) - 0.5f, rc.bottom-0.5f); + const D2D1_RECT_F rectangle1 = D2D1::RectF(std::round(rc.left) + 0.5f, rc.top+0.5f, std::round(rc.right) - 0.5f, rc.bottom-0.5f); D2DPenColour(back); pRenderTarget->FillRectangle(&rectangle1, pBrush); D2DPenColour(fore); @@ -1276,7 +1276,7 @@ void SurfaceD2D::RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired void SurfaceD2D::FillRectangle(PRectangle rc, ColourDesired back) { if (pRenderTarget) { D2DPenColour(back); - const D2D1_RECT_F rectangle1 = D2D1::RectF(round(rc.left), rc.top, round(rc.right), rc.bottom); + const D2D1_RECT_F rectangle1 = D2D1::RectF(std::round(rc.left), rc.top, std::round(rc.right), rc.bottom); pRenderTarget->FillRectangle(&rectangle1, pBrush); } } @@ -1326,23 +1326,23 @@ void SurfaceD2D::AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fil if (pRenderTarget) { if (cornerSize == 0) { // When corner size is zero, draw square rectangle to prevent blurry pixels at corners - const D2D1_RECT_F rectFill = D2D1::RectF(round(rc.left) + 1.0f, rc.top + 1.0f, round(rc.right) - 1.0f, rc.bottom - 1.0f); + const D2D1_RECT_F rectFill = D2D1::RectF(std::round(rc.left) + 1.0f, rc.top + 1.0f, std::round(rc.right) - 1.0f, rc.bottom - 1.0f); D2DPenColour(fill, alphaFill); pRenderTarget->FillRectangle(rectFill, pBrush); - const D2D1_RECT_F rectOutline = D2D1::RectF(round(rc.left) + 0.5f, rc.top + 0.5f, round(rc.right) - 0.5f, rc.bottom - 0.5f); + const D2D1_RECT_F rectOutline = D2D1::RectF(std::round(rc.left) + 0.5f, rc.top + 0.5f, std::round(rc.right) - 0.5f, rc.bottom - 0.5f); D2DPenColour(outline, alphaOutline); pRenderTarget->DrawRectangle(rectOutline, pBrush); } else { const float cornerSizeF = static_cast<float>(cornerSize); D2D1_ROUNDED_RECT roundedRectFill = { - D2D1::RectF(round(rc.left) + 1.0f, rc.top + 1.0f, round(rc.right) - 1.0f, rc.bottom - 1.0f), + D2D1::RectF(std::round(rc.left) + 1.0f, rc.top + 1.0f, std::round(rc.right) - 1.0f, rc.bottom - 1.0f), cornerSizeF, cornerSizeF}; D2DPenColour(fill, alphaFill); pRenderTarget->FillRoundedRectangle(roundedRectFill, pBrush); D2D1_ROUNDED_RECT roundedRect = { - D2D1::RectF(round(rc.left) + 0.5f, rc.top + 0.5f, round(rc.right) - 0.5f, rc.bottom - 0.5f), + D2D1::RectF(std::round(rc.left) + 0.5f, rc.top + 0.5f, std::round(rc.right) - 0.5f, rc.bottom - 0.5f), cornerSizeF, cornerSizeF}; D2DPenColour(outline, alphaOutline); pRenderTarget->DrawRoundedRectangle(roundedRect, pBrush); @@ -1391,7 +1391,7 @@ void SurfaceD2D::GradientRectangle(PRectangle rc, const std::vector<ColourStop> hr = pRenderTarget->CreateLinearGradientBrush( lgbp, pGradientStops, &pBrushLinear); if (SUCCEEDED(hr)) { - const D2D1_RECT_F rectangle = D2D1::RectF(round(rc.left), rc.top, round(rc.right), rc.bottom); + const D2D1_RECT_F rectangle = D2D1::RectF(std::round(rc.left), rc.top, std::round(rc.right), rc.bottom); pRenderTarget->FillRectangle(&rectangle, pBrushLinear); pBrushLinear->Release(); } @@ -1402,10 +1402,10 @@ void SurfaceD2D::GradientRectangle(PRectangle rc, const std::vector<ColourStop> void SurfaceD2D::DrawRGBAImage(PRectangle rc, int width, int height, const unsigned char *pixelsImage) { if (pRenderTarget) { if (rc.Width() > width) - rc.left += floor((rc.Width() - width) / 2); + rc.left += std::floor((rc.Width() - width) / 2); rc.right = rc.left + width; if (rc.Height() > height) - rc.top += floor((rc.Height() - height) / 2); + rc.top += std::floor((rc.Height() - height) / 2); rc.bottom = rc.top + height; std::vector<unsigned char> image(height * width * 4); @@ -1629,17 +1629,17 @@ void SurfaceD2D::MeasureWidths(Font &font_, const char *s, int len, XYPOSITION * XYPOSITION SurfaceD2D::Ascent(Font &font_) { SetFont(font_); - return ceil(yAscent); + return std::ceil(yAscent); } XYPOSITION SurfaceD2D::Descent(Font &font_) { SetFont(font_); - return ceil(yDescent); + return std::ceil(yDescent); } XYPOSITION SurfaceD2D::InternalLeading(Font &font_) { SetFont(font_); - return floor(yInternalLeading); + return std::floor(yInternalLeading); } XYPOSITION SurfaceD2D::Height(Font &font_) { |