Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ public Point getDPI() {
}

Point getIndependentDPI() {
return super.getDPI();
return new Point(72, 72);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,18 @@ public int getDepth () {
* @exception SWTException <ul>
* <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
* </ul>
*
* @deprecated <p>This method returns a single global DPI value
* that does not reflect per-monitor DPI settings on modern operating systems.
* In environments with different scaling factors across monitors, it may provide
* a misleading or meaningless result, as it does not correspond to the actual DPI
* of any specific monitor.</p>
*
* <p>Note: While deprecated for general {@code Device} instances like {@code Display},
* this method may still be validly used when called on a {@code Printer} instance,
* where a single global DPI value is meaningful and expected.</p>
*/
@Deprecated
public Point getDPI () {
checkDevice ();
return getScreenDPI();
Expand Down Expand Up @@ -611,8 +622,9 @@ protected void init () {
/* Initialize the system font slot */
boolean smallFonts = System.getProperty("org.eclipse.swt.internal.carbon.smallFonts") != null;
double systemFontSize = smallFonts ? NSFont.smallSystemFontSize() : NSFont.systemFontSize();
Point dpi = this.dpi = getDPI(), screenDPI = getScreenDPI();
NSFont font = NSFont.systemFontOfSize(systemFontSize * dpi.y / screenDPI.y);
final int DOTS_PER_INCH = 72;
Point dpi = this.dpi = getDPI();
NSFont font = NSFont.systemFontOfSize(systemFontSize * dpi.y / DOTS_PER_INCH);
font.retain();
systemFont = Font.cocoa_new(this, font);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public boolean equals(Object object) {
*/
public FontData[] getFontData() {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
final int DOTS_PER_INCH = 72;
NSAutoreleasePool pool = null;
if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
try {
Expand All @@ -258,8 +259,8 @@ public FontData[] getFontData() {
if ((traits & OS.NSBoldFontMask) != 0) style |= SWT.BOLD;
if ((extraTraits & OS.NSItalicFontMask) != 0) style |= SWT.ITALIC;
if ((extraTraits & OS.NSBoldFontMask) != 0) style |= SWT.BOLD;
Point dpi = device.dpi, screenDPI = device.getScreenDPI();
FontData data = new FontData(name, (float)handle.pointSize() * screenDPI.y / dpi.y, style);
Point dpi = device.dpi;
FontData data = new FontData(name, (float)handle.pointSize() * DOTS_PER_INCH / dpi.y, style);
data.nsName = nsName;
return new FontData[]{data};
} finally {
Expand Down Expand Up @@ -312,8 +313,9 @@ public int hashCode() {
void init(String name, float height, int style, String nsName) {
if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
Point dpi = device.dpi, screenDPI = device.getScreenDPI();
float size = height * dpi.y / screenDPI.y;
final int DOTS_PER_INCH = 72;
Point dpi = device.dpi;
float size = height * dpi.y / DOTS_PER_INCH;
NSFont systemFont = NSFont.systemFontOfSize(size);
NSFont boldSystemFont = NSFont.boldSystemFontOfSize(size);
String systemFontName = systemFont.familyName().getString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,18 @@ public int getDepth () {
* @exception SWTException <ul>
* <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
* </ul>
*
* @deprecated <p>This method returns a single global DPI value
* that does not reflect per-monitor DPI settings on modern operating systems.
* In environments with different scaling factors across monitors, it may provide
* a misleading or meaningless result, as it does not correspond to the actual DPI
* of any specific monitor.</p>
*
* <p>Note: While deprecated for general {@code Device} instances like {@code Display},
* this method may still be validly used when called on a {@code Printer} instance,
* where a single global DPI value is meaningful and expected.</p>
*/
@Deprecated
public Point getDPI () {
checkDevice ();
return getScreenDPI();
Expand Down Expand Up @@ -641,6 +652,7 @@ public boolean getWarnings () {
* @see #create
*/
protected void init () {
final int DOTS_PER_INCH = 96;
if (debug) {
if (xDisplay != 0) {
/* Create the warning and error callbacks */
Expand Down Expand Up @@ -723,10 +735,9 @@ protected void init () {
}
}
defaultFont = OS.pango_font_description_copy (defaultFont);
Point dpi = getDPI(), screenDPI = getScreenDPI();
if (dpi.y != screenDPI.y) {
if (this.dpi.y != DOTS_PER_INCH) {
int size = OS.pango_font_description_get_size(defaultFont);
OS.pango_font_description_set_size(defaultFont, size * dpi.y / screenDPI.y);
OS.pango_font_description_set_size(defaultFont, size * this.dpi.y / DOTS_PER_INCH);
}
systemFont = Font.gtk_new (this, defaultFont);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ public boolean equals(Object object) {
*/
public FontData[] getFontData() {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);

final int DOTS_PER_INCH = 96;
long family = OS.pango_font_description_get_family(handle);
int length = C.strlen(family);
byte[] buffer = new byte[length];
C.memmove(buffer, family, length);
String name = new String(Converter.mbcsToWcs(buffer));
float height = (float)OS.pango_font_description_get_size(handle) / OS.PANGO_SCALE;
Point dpi = device.dpi, screenDPI = device.getScreenDPI();
float size = height * screenDPI.y / dpi.y;
Point dpi = device.dpi;
float size = height * DOTS_PER_INCH / dpi.y;
int pangoStyle = OS.pango_font_description_get_style(handle);
int pangoWeight = OS.pango_font_description_get_weight(handle);
int style = SWT.NORMAL;
Expand Down Expand Up @@ -254,8 +254,9 @@ public int hashCode() {
void init(String name, float height, int style, byte[] fontString) {
if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
Point dpi = device.dpi, screenDPI = device.getScreenDPI();
float size = height * dpi.y / screenDPI.y;
final int DOTS_PER_INCH = 96;
Point dpi = device.dpi;
float size = height * dpi.y / DOTS_PER_INCH;
if (fontString != null) {
handle = OS.pango_font_description_from_string (fontString);
if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5043,7 +5043,8 @@ String debugInfoForIndex(long index) {
}

void dpiChanged(int newScaleFactor) {
DPIUtil.setDeviceZoom (DPIUtil.mapDPIToZoom(getDPI().x * newScaleFactor));
final int DOTS_PER_INCH = 96;
DPIUtil.setDeviceZoom (DPIUtil.mapDPIToZoom(DOTS_PER_INCH * newScaleFactor));
Shell[] shells = getShells();
for (int i = 0; i < shells.length; i++) {
shells[i].layout(true, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,18 @@ public int getDepth () {
* @exception SWTException <ul>
* <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
* </ul>
*
* @deprecated <p>This method returns a single global DPI value
* that does not reflect per-monitor DPI settings on modern operating systems.
* In environments with different scaling factors across monitors, it may provide
* a misleading or meaningless result, as it does not correspond to the actual DPI
* of any specific monitor.</p>
*
* <p>Note: While deprecated for general {@code Device} instances like {@code Display},
* this method may still be validly used when called on a {@code Printer} instance,
* where a single global DPI value is meaningful and expected.</p>
*/
@Deprecated
public Point getDPI () {
checkDevice ();
long hDC = internal_new_GC (null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1165,16 +1165,16 @@ void menuPrint() {
if (image == null) return;

try {
final int DOTS_PER_INCH = 96;
// Ask the user to specify the printer.
PrintDialog dialog = new PrintDialog(shell, SWT.NONE);
if (printerData != null) dialog.setPrinterData(printerData);
printerData = dialog.open();
if (printerData == null) return;

Printer printer = new Printer(printerData);
Point screenDPI = display.getDPI();
Point printerDPI = printer.getDPI();
int scaleFactor = printerDPI.x / screenDPI.x;
int scaleFactor = printerDPI.x / DOTS_PER_INCH;
Rectangle trim = printer.computeTrim(0, 0, 0, 0);
if (printer.startJob(currentName)) {
if (printer.startPage()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public void getName(AccessibleEvent e) {
}

private static void performPrintAction(final Display display, final Shell shell) {
final int DOTS_PER_INCH = 96;
Rectangle r = composite.getBounds();
Point p = shell.toDisplay(r.x, r.y);
org.eclipse.swt.graphics.Image snapshotImage
Expand All @@ -159,9 +160,8 @@ private static void performPrintAction(final Display display, final Shell shell)
data = dialog.open();
if (data != null) {
Printer printer = new Printer(data);
Point screenDPI = display.getDPI();
Point printerDPI = printer.getDPI();
int scaleFactor = printerDPI.x / screenDPI.x;
int scaleFactor = printerDPI.x / DOTS_PER_INCH;
Rectangle trim = printer.computeTrim(0, 0, 0, 0);
if (printer.startJob("Print Image")) {
ImageData imageData = snapshotImage.getImageData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public int getGcStyle() {

createSeparator(shell);

new Label (shell, SWT.NONE).setText ("5. 50x50 box\n(Display#getDPI(): " + display.getDPI().x + ")");
new Label (shell, SWT.NONE).setText ("5. 50x50 box");
Label box= new Label (shell, SWT.NONE);
box.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
box.setLayoutData (new GridData (50, 50));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void main (String [] args) {
gridData.horizontalSpan = 2;
canvas.setLayoutData (gridData);

new Label (shell, SWT.NONE).setText ("5. 50x50 box\n(Display#getDPI(): " + display.getDPI().x + ")");
new Label(shell, SWT.NONE).setText("5. 50x50 box");
Label box= new Label (shell, SWT.NONE);
box.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
box.setLayoutData (new GridData (50, 50));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,7 @@ public void test_wake() {
/* custom */
boolean disposeExecRan;

@SuppressWarnings("deprecation")
@Test
public void test_getDPI() {
Display display = new Display();
Expand Down
Loading