aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2021-03-19 14:46:09 +1100
committerNeil <nyamatongwe@gmail.com>2021-03-19 14:46:09 +1100
commit4b553e8fce75afd0ad0df2e752edafe739db44dc (patch)
tree2104a370f939a18bbc843169840ffb34ddbaab52
parent6b444111ecfe47a3f94293c3959cf197e3415735 (diff)
downloadscintilla-mirror-4b553e8fce75afd0ad0df2e752edafe739db44dc.tar.gz
Add Surface::PixelDivisions which detects 'retina' displays that use
multiple display pixels per logical pixel. Likely will only return >1 for Apple displays. Can be used for finer placement of elements.
-rw-r--r--cocoa/PlatCocoa.h1
-rw-r--r--cocoa/PlatCocoa.mm17
-rwxr-xr-xgtk/PlatGTK.cxx6
-rw-r--r--include/Scintilla.h1
-rw-r--r--include/Scintilla.iface1
-rw-r--r--qt/ScintillaEditBase/PlatQt.cpp6
-rw-r--r--qt/ScintillaEditBase/PlatQt.h1
-rw-r--r--src/Platform.h1
-rw-r--r--win32/PlatWin.cxx12
9 files changed, 46 insertions, 0 deletions
diff --git a/cocoa/PlatCocoa.h b/cocoa/PlatCocoa.h
index 18d339536..870b61aa3 100644
--- a/cocoa/PlatCocoa.h
+++ b/cocoa/PlatCocoa.h
@@ -88,6 +88,7 @@ public:
void CopyImageRectangle(Surface &surfaceSource, PRectangle srcRect, PRectangle dstRect);
int LogPixelsY() override;
+ int PixelDivisions() override;
int DeviceHeightFont(int points) override;
void MoveTo(int x_, int y_) override;
void LineTo(int x_, int y_) override;
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm
index 33c24397f..b662c25e6 100644
--- a/cocoa/PlatCocoa.mm
+++ b/cocoa/PlatCocoa.mm
@@ -321,6 +321,7 @@ void GetPositions(CTLineRef line, std::vector<CGFloat> &positions) {
const int SupportsCocoa[] = {
SC_SUPPORTS_LINE_DRAWS_FINAL,
+ SC_SUPPORTS_PIXEL_DIVISIONS,
};
}
@@ -556,6 +557,22 @@ int SurfaceImpl::LogPixelsY() {
//--------------------------------------------------------------------------------------------------
/**
+ * Returns the number of device pixels per logical pixel.
+ * 1 for older displays and 2 for retina displays. Potentially 3 for some phones.
+ */
+int SurfaceImpl::PixelDivisions() {
+ if (gc) {
+ const CGSize szDevice = CGContextConvertSizeToDeviceSpace(gc, CGSizeMake(1.0, 1.0));
+ const int devicePixels = std::round(szDevice.width);
+ assert(devicePixels == 1 || devicePixels == 2);
+ return devicePixels;
+ }
+ return 1;
+}
+
+//--------------------------------------------------------------------------------------------------
+
+/**
* Converts the logical font height in points into a device height.
* For Cocoa, points are always used for the result even on retina displays.
*/
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx
index 19b25294b..33a0b8917 100755
--- a/gtk/PlatGTK.cxx
+++ b/gtk/PlatGTK.cxx
@@ -155,6 +155,7 @@ public:
bool Initialised() override;
void PenColour(ColourDesired fore) override;
int LogPixelsY() override;
+ int PixelDivisions() override;
int DeviceHeightFont(int points) override;
void MoveTo(int x_, int y_) override;
void LineTo(int x_, int y_) override;
@@ -395,6 +396,11 @@ int SurfaceImpl::LogPixelsY() {
return 72;
}
+int SurfaceImpl::PixelDivisions() {
+ // GTK uses device pixels.
+ return 1;
+}
+
int SurfaceImpl::DeviceHeightFont(int points) {
const int logPix = LogPixelsY();
return (points * logPix + logPix / 2) / 72;
diff --git a/include/Scintilla.h b/include/Scintilla.h
index d586e8fe8..da104a552 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -1019,6 +1019,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_EOLANNOTATIONSETSTYLEOFFSET 2747
#define SCI_EOLANNOTATIONGETSTYLEOFFSET 2748
#define SC_SUPPORTS_LINE_DRAWS_FINAL 0
+#define SC_SUPPORTS_PIXEL_DIVISIONS 1
#define SCI_SUPPORTSFEATURE 2750
#define SCI_STARTRECORD 3001
#define SCI_STOPRECORD 3002
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index 44d00500b..6868dec0b 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -2877,6 +2877,7 @@ get int EOLAnnotationGetStyleOffset=2748(,)
enu Supports=SC_SUPPORTS_
val SC_SUPPORTS_LINE_DRAWS_FINAL=0
+val SC_SUPPORTS_PIXEL_DIVISIONS=1
# Get whether a feature is supported
get int SupportsFeature=2750(Supports feature,)
diff --git a/qt/ScintillaEditBase/PlatQt.cpp b/qt/ScintillaEditBase/PlatQt.cpp
index b7d0e3a53..1b8f75c02 100644
--- a/qt/ScintillaEditBase/PlatQt.cpp
+++ b/qt/ScintillaEditBase/PlatQt.cpp
@@ -263,6 +263,12 @@ int SurfaceImpl::LogPixelsY()
return device->logicalDpiY();
}
+int SurfaceImpl::PixelDivisions()
+{
+ // Qt uses device pixels.
+ return 1;
+}
+
int SurfaceImpl::DeviceHeightFont(int points)
{
return points;
diff --git a/qt/ScintillaEditBase/PlatQt.h b/qt/ScintillaEditBase/PlatQt.h
index ae0994b32..7b43e0b02 100644
--- a/qt/ScintillaEditBase/PlatQt.h
+++ b/qt/ScintillaEditBase/PlatQt.h
@@ -94,6 +94,7 @@ public:
bool Initialised() override;
void PenColour(ColourDesired fore) override;
int LogPixelsY() override;
+ int PixelDivisions() override;
int DeviceHeightFont(int points) override;
void MoveTo(int x_, int y_) override;
void LineTo(int x_, int y_) override;
diff --git a/src/Platform.h b/src/Platform.h
index 8075f0ec6..382ae30ee 100644
--- a/src/Platform.h
+++ b/src/Platform.h
@@ -184,6 +184,7 @@ public:
virtual bool Initialised()=0;
virtual void PenColour(ColourDesired fore)=0;
virtual int LogPixelsY()=0;
+ virtual int PixelDivisions()=0;
virtual int DeviceHeightFont(int points)=0;
virtual void MoveTo(int x_, int y_)=0;
virtual void LineTo(int x_, int y_)=0;
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index 452bb49bc..014c09793 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -482,6 +482,7 @@ public:
bool Initialised() override;
void PenColour(ColourDesired fore) override;
int LogPixelsY() override;
+ int PixelDivisions() override;
int DeviceHeightFont(int points) override;
void MoveTo(int x_, int y_) override;
void LineTo(int x_, int y_) override;
@@ -637,6 +638,11 @@ int SurfaceGDI::LogPixelsY() {
return logPixelsY;
}
+int SurfaceGDI::PixelDivisions() {
+ // Win32 uses device pixels.
+ return 1;
+}
+
int SurfaceGDI::DeviceHeightFont(int points) {
return ::MulDiv(points, LogPixelsY(), 72);
}
@@ -1170,6 +1176,7 @@ public:
void PenColour(ColourDesired fore) override;
void D2DPenColour(ColourDesired fore, int alpha=255);
int LogPixelsY() override;
+ int PixelDivisions() override;
int DeviceHeightFont(int points) override;
void MoveTo(int x_, int y_) override;
void LineTo(int x_, int y_) override;
@@ -1367,6 +1374,11 @@ int SurfaceD2D::LogPixelsY() {
return logPixelsY;
}
+int SurfaceD2D::PixelDivisions() {
+ // Win32 uses device pixels.
+ return 1;
+}
+
int SurfaceD2D::DeviceHeightFont(int points) {
return ::MulDiv(points, LogPixelsY(), 72);
}