aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormitchell <unknown>2018-05-25 13:33:38 -0400
committermitchell <unknown>2018-05-25 13:33:38 -0400
commit43566e4211e18057662ff5d8c8d3996b73090d43 (patch)
tree0b501aa992e9ccdcc36b25d10d72a51785a9a515
parent7a4fd484cc8229d3518039c82d950b4fa7f673cb (diff)
downloadscintilla-mirror-43566e4211e18057662ff5d8c8d3996b73090d43.tar.gz
Backport: Modernize Platform.h (3) - update Surface to delete WidthChar, use size_t for Polygon and delete the standard copy and assignment methods.
Backport of changeset 6940:89fd29243232.
-rw-r--r--cocoa/PlatCocoa.h3
-rw-r--r--cocoa/PlatCocoa.mm17
-rw-r--r--curses/ScintillaCurses.cxx5
-rw-r--r--gtk/PlatGTK.cxx20
-rw-r--r--include/Platform.h13
-rw-r--r--qt/ScintillaEditBase/PlatQt.cpp12
-rw-r--r--qt/ScintillaEditBase/PlatQt.h5
-rw-r--r--qt/ScintillaEditBase/ScintillaEditBase.h2
-rw-r--r--src/Indicator.cxx3
-rw-r--r--src/ViewStyle.cxx5
-rw-r--r--win32/PlatWin.cxx41
11 files changed, 35 insertions, 91 deletions
diff --git a/cocoa/PlatCocoa.h b/cocoa/PlatCocoa.h
index 843128a6c..00b4ce2ae 100644
--- a/cocoa/PlatCocoa.h
+++ b/cocoa/PlatCocoa.h
@@ -89,7 +89,7 @@ public:
int DeviceHeightFont(int points) override;
void MoveTo(int x_, int y_) override;
void LineTo(int x_, int y_) override;
- void Polygon(Scintilla::Point *pts, int npts, ColourDesired fore, ColourDesired back) override;
+ void Polygon(Scintilla::Point *pts, size_t npts, ColourDesired fore, ColourDesired back) override;
void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back) override;
void FillRectangle(PRectangle rc, ColourDesired back) override;
void FillRectangle(PRectangle rc, Surface &surfacePattern) override;
@@ -106,7 +106,6 @@ public:
void DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore) override;
void MeasureWidths(Font &font_, const char *s, int len, XYPOSITION *positions) override;
XYPOSITION WidthText(Font &font_, const char *s, int len) override;
- XYPOSITION WidthChar(Font &font_, char ch) override;
XYPOSITION Ascent(Font &font_) override;
XYPOSITION Descent(Font &font_) override;
XYPOSITION InternalLeading(Font &font_) override;
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm
index 405cdee8e..fe1873ffa 100644
--- a/cocoa/PlatCocoa.mm
+++ b/cocoa/PlatCocoa.mm
@@ -405,13 +405,13 @@ void SurfaceImpl::LineTo(int x_, int y_)
//--------------------------------------------------------------------------------------------------
-void SurfaceImpl::Polygon(Scintilla::Point *pts, int npts, ColourDesired fore,
+void SurfaceImpl::Polygon(Scintilla::Point *pts, size_t npts, ColourDesired fore,
ColourDesired back)
{
// Allocate memory for the array of points.
std::vector<CGPoint> points(npts);
- for (int i = 0;i < npts;i++)
+ for (size_t i = 0;i < npts;i++)
{
// Quartz floating point issues: plot the MIDDLE of the pixels
points[i].x = pts[i].x + 0.5;
@@ -984,19 +984,6 @@ XYPOSITION SurfaceImpl::WidthText(Font &font_, const char *s, int len) {
return 1;
}
-XYPOSITION SurfaceImpl::WidthChar(Font &font_, char ch) {
- char str[2] = { ch, '\0' };
- if (font_.GetID())
- {
- CFStringEncoding encoding = EncodingFromCharacterSet(unicodeMode, FontCharacterSet(font_));
- textLayout->setText(str, 1, encoding, *TextStyleFromFont(font_));
-
- return textLayout->MeasureStringWidth();
- }
- else
- return 1;
-}
-
// This string contains a good range of characters to test for size.
const char sizeString[] = "`~!@#$%^&*()-_=+\\|[]{};:\"\'<,>.?/1234567890"
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
diff --git a/curses/ScintillaCurses.cxx b/curses/ScintillaCurses.cxx
index 21c7a8c02..1a04912a1 100644
--- a/curses/ScintillaCurses.cxx
+++ b/curses/ScintillaCurses.cxx
@@ -279,7 +279,8 @@ public:
* Line markers that Scintilla would normally draw as polygons are handled in
* `DrawLineMarker()`.
*/
- void Polygon(Point *pts, int npts, ColourDesired fore, ColourDesired back) {
+ void Polygon(Point *pts, size_t npts, ColourDesired fore,
+ ColourDesired back) {
wattr_set(win, 0, term_color_pair(back, COLOR_WHITE), NULL); // invert
if (pts[0].y < pts[npts - 1].y) // up arrow
mvwaddstr(win, pts[0].y, pts[npts - 1].x + 1, "▲");
@@ -447,8 +448,6 @@ public:
if (!UTF8IsTrailByte((unsigned char)s[i])) width += grapheme_width(s + i);
return width;
}
- /** Returns 1 since curses characters always have a width of 1. */
- XYPOSITION WidthChar(Font &font_, char ch) { return 1; }
/** Returns 0 since curses characters have no ascent. */
XYPOSITION Ascent(Font &font_) { return 0; }
/** Returns 0 since curses characters have no descent. */
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx
index 04ba90d7c..539402b01 100644
--- a/gtk/PlatGTK.cxx
+++ b/gtk/PlatGTK.cxx
@@ -153,7 +153,7 @@ public:
int DeviceHeightFont(int points) override;
void MoveTo(int x_, int y_) override;
void LineTo(int x_, int y_) override;
- void Polygon(Point *pts, int npts, ColourDesired fore, ColourDesired back) override;
+ void Polygon(Point *pts, size_t npts, ColourDesired fore, ColourDesired back) override;
void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back) override;
void FillRectangle(PRectangle rc, ColourDesired back) override;
void FillRectangle(PRectangle rc, Surface &surfacePattern) override;
@@ -170,7 +170,6 @@ public:
void DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore) override;
void MeasureWidths(Font &font_, const char *s, int len, XYPOSITION *positions) override;
XYPOSITION WidthText(Font &font_, const char *s, int len) override;
- XYPOSITION WidthChar(Font &font_, char ch) override;
XYPOSITION Ascent(Font &font_) override;
XYPOSITION Descent(Font &font_) override;
XYPOSITION InternalLeading(Font &font_) override;
@@ -425,12 +424,12 @@ void SurfaceImpl::LineTo(int x_, int y_) {
y = y_;
}
-void SurfaceImpl::Polygon(Point *pts, int npts, ColourDesired fore,
+void SurfaceImpl::Polygon(Point *pts, size_t npts, ColourDesired fore,
ColourDesired back) {
PLATFORM_ASSERT(context);
PenColour(back);
cairo_move_to(context, pts[0].x + 0.5, pts[0].y + 0.5);
- for (int i = 1; i < npts; i++) {
+ for (size_t i = 1; i < npts; i++) {
cairo_line_to(context, pts[i].x + 0.5, pts[i].y + 0.5);
}
cairo_close_path(context);
@@ -865,17 +864,6 @@ XYPOSITION SurfaceImpl::WidthText(Font &font_, const char *s, int len) {
}
}
-XYPOSITION SurfaceImpl::WidthChar(Font &font_, char ch) {
- if (font_.GetID()) {
- if (PFont(font_)->pfd) {
- return WidthText(font_, &ch, 1);
- }
- return 1;
- } else {
- return 1;
- }
-}
-
// Ascent and descent determined by Pango font metrics.
XYPOSITION SurfaceImpl::Ascent(Font &font_) {
@@ -917,7 +905,7 @@ XYPOSITION SurfaceImpl::Height(Font &font_) {
}
XYPOSITION SurfaceImpl::AverageCharWidth(Font &font_) {
- return WidthChar(font_, 'n');
+ return WidthText(font_, "n", 1);
}
void SurfaceImpl::SetClip(PRectangle rc) {
diff --git a/include/Platform.h b/include/Platform.h
index 97c4fca1d..d049ccc45 100644
--- a/include/Platform.h
+++ b/include/Platform.h
@@ -257,12 +257,12 @@ public:
* A surface abstracts a place to draw.
*/
class Surface {
-private:
- // Private so Surface objects can not be copied
- Surface(const Surface &) {}
- Surface &operator=(const Surface &) { return *this; }
public:
- Surface() {}
+ Surface() noexcept = default;
+ Surface(const Surface &) = delete;
+ Surface(Surface &&) = delete;
+ Surface &operator=(const Surface &) = delete;
+ Surface &operator=(Surface &&) = delete;
virtual ~Surface() {}
static Surface *Allocate(int technology);
@@ -277,7 +277,7 @@ public:
virtual int DeviceHeightFont(int points)=0;
virtual void MoveTo(int x_, int y_)=0;
virtual void LineTo(int x_, int y_)=0;
- virtual void Polygon(Point *pts, int npts, ColourDesired fore, ColourDesired back)=0;
+ virtual void Polygon(Point *pts, size_t npts, ColourDesired fore, ColourDesired back)=0;
virtual void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back)=0;
virtual void FillRectangle(PRectangle rc, ColourDesired back)=0;
virtual void FillRectangle(PRectangle rc, Surface &surfacePattern)=0;
@@ -293,7 +293,6 @@ public:
virtual void DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore)=0;
virtual void MeasureWidths(Font &font_, const char *s, int len, XYPOSITION *positions)=0;
virtual XYPOSITION WidthText(Font &font_, const char *s, int len)=0;
- virtual XYPOSITION WidthChar(Font &font_, char ch)=0;
virtual XYPOSITION Ascent(Font &font_)=0;
virtual XYPOSITION Descent(Font &font_)=0;
virtual XYPOSITION InternalLeading(Font &font_)=0;
diff --git a/qt/ScintillaEditBase/PlatQt.cpp b/qt/ScintillaEditBase/PlatQt.cpp
index ac8fbc9cc..26890e4b7 100644
--- a/qt/ScintillaEditBase/PlatQt.cpp
+++ b/qt/ScintillaEditBase/PlatQt.cpp
@@ -269,7 +269,7 @@ void SurfaceImpl::LineTo(int x_, int y_)
}
void SurfaceImpl::Polygon(Point *pts,
- int npts,
+ size_t npts,
ColourDesired fore,
ColourDesired back)
{
@@ -277,11 +277,11 @@ void SurfaceImpl::Polygon(Point *pts,
BrushColour(back);
std::vector<QPoint> qpts(npts);
- for (int i = 0; i < npts; i++) {
+ for (size_t i = 0; i < npts; i++) {
qpts[i] = QPoint(pts[i].x, pts[i].y);
}
- GetPainter()->drawPolygon(&qpts[0], npts);
+ GetPainter()->drawPolygon(&qpts[0], static_cast<int>(npts));
}
void SurfaceImpl::RectangleDraw(PRectangle rc,
@@ -494,12 +494,6 @@ XYPOSITION SurfaceImpl::WidthText(Font &font, const char *s, int len)
return metrics.width(string);
}
-XYPOSITION SurfaceImpl::WidthChar(Font &font, char ch)
-{
- QFontMetricsF metrics(*FontPointer(font), device);
- return metrics.width(ch);
-}
-
XYPOSITION SurfaceImpl::Ascent(Font &font)
{
QFontMetricsF metrics(*FontPointer(font), device);
diff --git a/qt/ScintillaEditBase/PlatQt.h b/qt/ScintillaEditBase/PlatQt.h
index 653399dbc..4d762bccf 100644
--- a/qt/ScintillaEditBase/PlatQt.h
+++ b/qt/ScintillaEditBase/PlatQt.h
@@ -11,6 +11,8 @@
#ifndef PLATQT_H
#define PLATQT_H
+#include <cstddef>
+
#include "Platform.h"
#include <QUrl>
@@ -78,7 +80,7 @@ public:
int DeviceHeightFont(int points) override;
void MoveTo(int x_, int y_) override;
void LineTo(int x_, int y_) override;
- void Polygon(Point *pts, int npts, ColourDesired fore,
+ void Polygon(Point *pts, size_t npts, ColourDesired fore,
ColourDesired back) override;
void RectangleDraw(PRectangle rc, ColourDesired fore,
ColourDesired back) override;
@@ -103,7 +105,6 @@ public:
void MeasureWidths(Font &font, const char *s, int len,
XYPOSITION *positions) override;
XYPOSITION WidthText(Font &font, const char *s, int len) override;
- XYPOSITION WidthChar(Font &font, char ch) override;
XYPOSITION Ascent(Font &font) override;
XYPOSITION Descent(Font &font) override;
XYPOSITION InternalLeading(Font &font) override;
diff --git a/qt/ScintillaEditBase/ScintillaEditBase.h b/qt/ScintillaEditBase/ScintillaEditBase.h
index 20acf3086..5ab9dc115 100644
--- a/qt/ScintillaEditBase/ScintillaEditBase.h
+++ b/qt/ScintillaEditBase/ScintillaEditBase.h
@@ -12,6 +12,8 @@
#ifndef SCINTILLAEDITBASE_H
#define SCINTILLAEDITBASE_H
+#include <cstddef>
+
#include "Platform.h"
#include "Scintilla.h"
diff --git a/src/Indicator.cxx b/src/Indicator.cxx
index f9d0ca04a..35b2c3e5b 100644
--- a/src/Indicator.cxx
+++ b/src/Indicator.cxx
@@ -16,6 +16,7 @@
#include "Platform.h"
#include "Scintilla.h"
+#include "StringCopy.h"
#include "IntegerRectangle.h"
#include "Indicator.h"
#include "XPM.h"
@@ -189,7 +190,7 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r
Point(ix + pixelHeight, iy + pixelHeight), // Right
Point(ix, iy) // Top
};
- surface->Polygon(pts, 3, sacDraw.fore, sacDraw.fore);
+ surface->Polygon(pts, ELEMENTS(pts), sacDraw.fore, sacDraw.fore);
}
} else { // Either INDIC_PLAIN or unknown
surface->MoveTo(irc.left, ymid);
diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx
index d57ad48bd..2b87c8a51 100644
--- a/src/ViewStyle.cxx
+++ b/src/ViewStyle.cxx
@@ -79,7 +79,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.WidthChar(font, ' ');
+ spaceWidth = surface.WidthText(font, " ", 1);
}
ViewStyle::ViewStyle() : markers(MARKER_MAX + 1), indicators(INDIC_MAX + 1) {
@@ -365,7 +365,8 @@ void ViewStyle::Refresh(Surface &surface, int tabInChars) {
controlCharWidth = 0.0;
if (controlCharSymbol >= 32) {
- controlCharWidth = surface.WidthChar(styles[STYLE_CONTROLCHAR].font, static_cast<char>(controlCharSymbol));
+ const char cc[2] = { static_cast<char>(controlCharSymbol), '\0' };
+ controlCharWidth = surface.WidthText(styles[STYLE_CONTROLCHAR].font, cc, 1);
}
CalculateMarginWidthAndMask();
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index d00c4debd..d7d626742 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -554,7 +554,7 @@ public:
int DeviceHeightFont(int points) override;
void MoveTo(int x_, int y_) override;
void LineTo(int x_, int y_) override;
- void Polygon(Point *pts, int npts, ColourDesired fore, ColourDesired back) override;
+ void Polygon(Point *pts, size_t npts, ColourDesired fore, ColourDesired back) override;
void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back) override;
void FillRectangle(PRectangle rc, ColourDesired back) override;
void FillRectangle(PRectangle rc, Surface &surfacePattern) override;
@@ -571,7 +571,6 @@ public:
void DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore) override;
void MeasureWidths(Font &font_, const char *s, int len, XYPOSITION *positions) override;
XYPOSITION WidthText(Font &font_, const char *s, int len) override;
- XYPOSITION WidthChar(Font &font_, char ch) override;
XYPOSITION Ascent(Font &font_) override;
XYPOSITION Descent(Font &font_) override;
XYPOSITION InternalLeading(Font &font_) override;
@@ -720,15 +719,15 @@ void SurfaceGDI::LineTo(int x_, int y_) {
::LineTo(hdc, x_, y_);
}
-void SurfaceGDI::Polygon(Point *pts, int npts, ColourDesired fore, ColourDesired back) {
+void SurfaceGDI::Polygon(Point *pts, size_t npts, ColourDesired fore, ColourDesired back) {
PenColour(fore);
BrushColor(back);
std::vector<POINT> outline;
- for (int i=0; i<npts; i++) {
+ for (size_t i=0; i<npts; i++) {
POINT pt = {static_cast<LONG>(pts[i].x), static_cast<LONG>(pts[i].y)};
outline.push_back(pt);
}
- ::Polygon(hdc, &outline[0], npts);
+ ::Polygon(hdc, &outline[0], static_cast<int>(npts));
}
void SurfaceGDI::RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back) {
@@ -1009,13 +1008,6 @@ void SurfaceGDI::MeasureWidths(Font &font_, const char *s, int len, XYPOSITION *
std::fill(positions+i, positions + len, lastPos);
}
-XYPOSITION SurfaceGDI::WidthChar(Font &font_, char ch) {
- SetFont(font_);
- SIZE sz;
- ::GetTextExtentPoint32A(hdc, &ch, 1, &sz);
- return static_cast<XYPOSITION>(sz.cx);
-}
-
XYPOSITION SurfaceGDI::Ascent(Font &font_) {
SetFont(font_);
TEXTMETRIC tm;
@@ -1123,7 +1115,7 @@ public:
int DeviceHeightFont(int points) override;
void MoveTo(int x_, int y_) override;
void LineTo(int x_, int y_) override;
- void Polygon(Point *pts, int npts, ColourDesired fore, ColourDesired back) override;
+ void Polygon(Point *pts, size_t npts, ColourDesired fore, ColourDesired back) override;
void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back) override;
void FillRectangle(PRectangle rc, ColourDesired back) override;
void FillRectangle(PRectangle rc, Surface &surfacePattern) override;
@@ -1140,7 +1132,6 @@ public:
void DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore) override;
void MeasureWidths(Font &font_, const char *s, int len, XYPOSITION *positions) override;
XYPOSITION WidthText(Font &font_, const char *s, int len) override;
- XYPOSITION WidthChar(Font &font_, char ch) override;
XYPOSITION Ascent(Font &font_) override;
XYPOSITION Descent(Font &font_) override;
XYPOSITION InternalLeading(Font &font_) override;
@@ -1354,7 +1345,7 @@ void SurfaceD2D::LineTo(int x_, int y_) {
}
}
-void SurfaceD2D::Polygon(Point *pts, int npts, ColourDesired fore, ColourDesired back) {
+void SurfaceD2D::Polygon(Point *pts, size_t npts, ColourDesired fore, ColourDesired back) {
if (pRenderTarget) {
ID2D1Factory *pFactory = 0;
pRenderTarget->GetFactory(&pFactory);
@@ -1365,7 +1356,7 @@ void SurfaceD2D::Polygon(Point *pts, int npts, ColourDesired fore, ColourDesired
hr = geometry->Open(&sink);
if (SUCCEEDED(hr)) {
sink->BeginFigure(D2D1::Point2F(pts[0].x + 0.5f, pts[0].y + 0.5f), D2D1_FIGURE_BEGIN_FILLED);
- for (int i=1; i<npts; i++) {
+ for (size_t i=1; i<npts; i++) {
sink->AddLine(D2D1::Point2F(pts[i].x + 0.5f, pts[i].y + 0.5f));
}
sink->EndFigure(D2D1_FIGURE_END_CLOSED);
@@ -1698,24 +1689,6 @@ void SurfaceD2D::MeasureWidths(Font &font_, const char *s, int len, XYPOSITION *
}
}
-XYPOSITION SurfaceD2D::WidthChar(Font &font_, char ch) {
- FLOAT width = 1.0;
- SetFont(font_);
- if (pIDWriteFactory && pTextFormat) {
- // Create a layout
- IDWriteTextLayout *pTextLayout = 0;
- const WCHAR wch = ch;
- const HRESULT hr = pIDWriteFactory->CreateTextLayout(&wch, 1, pTextFormat, 1000.0, 1000.0, &pTextLayout);
- if (SUCCEEDED(hr)) {
- DWRITE_TEXT_METRICS textMetrics;
- if (SUCCEEDED(pTextLayout->GetMetrics(&textMetrics)))
- width = textMetrics.widthIncludingTrailingWhitespace;
- pTextLayout->Release();
- }
- }
- return width;
-}
-
XYPOSITION SurfaceD2D::Ascent(Font &font_) {
SetFont(font_);
return ceil(yAscent);