Skip to content

Commit 3df70cc

Browse files
[Cocoa] Replaceing usages of Display#getDPI from cocoa
Having the scale factor being based on the screen DPI leads to unexpected result e.g. Image too big/small. Having a screen dpi independent factor leads to consistent results.
1 parent 1bc596e commit 3df70cc

File tree

2 files changed

+7
-5
lines changed
  • bundles/org.eclipse.swt
    • Eclipse SWT Printing/cocoa/org/eclipse/swt/printing
    • Eclipse SWT/cocoa/org/eclipse/swt/graphics

2 files changed

+7
-5
lines changed

bundles/org.eclipse.swt/Eclipse SWT Printing/cocoa/org/eclipse/swt/printing/Printer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ public Point getDPI() {
624624
}
625625

626626
Point getIndependentDPI() {
627-
return super.getDPI();
627+
return new Point(72, 72);
628628
}
629629

630630
/**

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Font.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ public boolean equals(Object object) {
244244
*/
245245
public FontData[] getFontData() {
246246
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
247+
final int DOTS_PER_INCH = 72;
247248
NSAutoreleasePool pool = null;
248249
if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
249250
try {
@@ -258,8 +259,8 @@ public FontData[] getFontData() {
258259
if ((traits & OS.NSBoldFontMask) != 0) style |= SWT.BOLD;
259260
if ((extraTraits & OS.NSItalicFontMask) != 0) style |= SWT.ITALIC;
260261
if ((extraTraits & OS.NSBoldFontMask) != 0) style |= SWT.BOLD;
261-
Point dpi = device.dpi, screenDPI = device.getScreenDPI();
262-
FontData data = new FontData(name, (float)handle.pointSize() * screenDPI.y / dpi.y, style);
262+
Point dpi = device.dpi;
263+
FontData data = new FontData(name, (float)handle.pointSize() * DOTS_PER_INCH / dpi.y, style);
263264
data.nsName = nsName;
264265
return new FontData[]{data};
265266
} finally {
@@ -312,8 +313,9 @@ public int hashCode() {
312313
void init(String name, float height, int style, String nsName) {
313314
if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
314315
if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
315-
Point dpi = device.dpi, screenDPI = device.getScreenDPI();
316-
float size = height * dpi.y / screenDPI.y;
316+
final int DOTS_PER_INCH = 72;
317+
Point dpi = device.dpi;
318+
float size = height * dpi.y / DOTS_PER_INCH;
317319
NSFont systemFont = NSFont.systemFontOfSize(size);
318320
NSFont boldSystemFont = NSFont.boldSystemFontOfSize(size);
319321
String systemFontName = systemFont.familyName().getString();

0 commit comments

Comments
 (0)