src/macosx/native/sun/awt/CGraphicsDevice.m
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -154,18 +154,16 @@
*/
JNIEXPORT jdouble JNICALL
Java_sun_awt_CGraphicsDevice_nativeGetXResolution
(JNIEnv *env, jclass class, jint displayID)
{
- // TODO: this is the physically correct answer, but we probably want
- // to use NSScreen API instead...
+ // CGDisplayScreenSize can return 0 if displayID is invalid
CGSize size = CGDisplayScreenSize(displayID);
CGRect rect = CGDisplayBounds(displayID);
// 1 inch == 25.4 mm
jfloat inches = size.width / 25.4f;
- jfloat dpi = rect.size.width / inches;
- return dpi;
+ return inches > 0 ? rect.size.width / inches : 72;
}
/*
* Class: sun_awt_CGraphicsDevice
* Method: nativeGetYResolution
@@ -173,18 +171,16 @@
*/
JNIEXPORT jdouble JNICALL
Java_sun_awt_CGraphicsDevice_nativeGetYResolution
(JNIEnv *env, jclass class, jint displayID)
{
- // TODO: this is the physically correct answer, but we probably want
- // to use NSScreen API instead...
+ // CGDisplayScreenSize can return 0 if displayID is invalid
CGSize size = CGDisplayScreenSize(displayID);
CGRect rect = CGDisplayBounds(displayID);
// 1 inch == 25.4 mm
jfloat inches = size.height / 25.4f;
- jfloat dpi = rect.size.height / inches;
- return dpi;
+ return inches > 0 ? rect.size.height / inches : 72;
}
/*
* Class: sun_awt_CGraphicsDevice
* Method: nativeGetScreenInsets