--- old/src/java.desktop/windows/native/libawt/windows/awt_DesktopProperties.cpp 2016-01-29 10:46:19.569647200 -0800 +++ new/src/java.desktop/windows/native/libawt/windows/awt_DesktopProperties.cpp 2016-01-29 10:46:19.324571700 -0800 @@ -35,6 +35,8 @@ #include #include +#include "math.h" + // WDesktopProperties fields jfieldID AwtDesktopProperties::pDataID = 0; jmethodID AwtDesktopProperties::setBooleanPropertyID = 0; @@ -79,6 +81,18 @@ } } +float getInvScale() { + HWND hWnd = ::GetDesktopWindow(); + HDC hDC = ::GetDC(hWnd); + int dpi = ::GetDeviceCaps(hDC, LOGPIXELSY); + ::ReleaseDC(hWnd, hDC); + return dpi == 0.0f ? 1.0f : 96.0f / dpi; +} + +int rescale(int x, float invScale){ + return invScale == 1.0f ? x : (int)round(x * invScale); +} + void AwtDesktopProperties::GetSystemProperties() { HDC dc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL); @@ -87,7 +101,7 @@ SetFontProperty(dc, ANSI_FIXED_FONT, TEXT("win.ansiFixed.font")); SetFontProperty(dc, ANSI_VAR_FONT, TEXT("win.ansiVar.font")); SetFontProperty(dc, DEVICE_DEFAULT_FONT, TEXT("win.deviceDefault.font")); - SetFontProperty(dc, DEFAULT_GUI_FONT, TEXT("win.defaultGUI.font")); + SetFontProperty(dc, DEFAULT_GUI_FONT, TEXT("win.defaultGUI.font"), getInvScale()); SetFontProperty(dc, OEM_FIXED_FONT, TEXT("win.oemFixed.font")); SetFontProperty(dc, SYSTEM_FONT, TEXT("win.system.font")); SetFontProperty(dc, SYSTEM_FIXED_FONT, TEXT("win.systemFixed.font")); @@ -266,31 +280,33 @@ } VERIFY( SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncmetrics.cbSize, &ncmetrics, FALSE) ); - SetFontProperty( TEXT("win.frame.captionFont"), ncmetrics.lfCaptionFont ); - SetIntegerProperty( TEXT("win.frame.captionHeight"), ncmetrics.iCaptionHeight ); - SetIntegerProperty( TEXT("win.frame.captionButtonWidth"), ncmetrics.iCaptionWidth ); - SetIntegerProperty( TEXT("win.frame.captionButtonHeight"), ncmetrics.iCaptionHeight ); - SetFontProperty( TEXT("win.frame.smallCaptionFont"), ncmetrics.lfSmCaptionFont ); - SetIntegerProperty( TEXT("win.frame.smallCaptionHeight"), ncmetrics.iSmCaptionHeight ); - SetIntegerProperty( TEXT("win.frame.smallCaptionButtonWidth"), ncmetrics.iSmCaptionWidth ); - SetIntegerProperty( TEXT("win.frame.smallCaptionButtonHeight"), ncmetrics.iSmCaptionHeight ); - SetIntegerProperty( TEXT("win.frame.sizingBorderWidth"), ncmetrics.iBorderWidth ); + float invScale = getInvScale(); + + SetFontProperty(TEXT("win.frame.captionFont"), ncmetrics.lfCaptionFont, invScale); + SetIntegerProperty(TEXT("win.frame.captionHeight"), rescale(ncmetrics.iCaptionHeight, invScale)); + SetIntegerProperty(TEXT("win.frame.captionButtonWidth"), rescale(ncmetrics.iCaptionWidth, invScale)); + SetIntegerProperty(TEXT("win.frame.captionButtonHeight"), rescale(ncmetrics.iCaptionHeight, invScale)); + SetFontProperty(TEXT("win.frame.smallCaptionFont"), ncmetrics.lfSmCaptionFont, invScale); + SetIntegerProperty(TEXT("win.frame.smallCaptionHeight"), rescale(ncmetrics.iSmCaptionHeight, invScale)); + SetIntegerProperty(TEXT("win.frame.smallCaptionButtonWidth"), rescale(ncmetrics.iSmCaptionWidth, invScale)); + SetIntegerProperty(TEXT("win.frame.smallCaptionButtonHeight"), rescale(ncmetrics.iSmCaptionHeight, invScale)); + SetIntegerProperty(TEXT("win.frame.sizingBorderWidth"), rescale(ncmetrics.iBorderWidth, 1.0f / invScale)); // menu properties - SetFontProperty( TEXT("win.menu.font"), ncmetrics.lfMenuFont ); - SetIntegerProperty( TEXT("win.menu.height"), ncmetrics.iMenuHeight ); - SetIntegerProperty( TEXT("win.menu.buttonWidth"), ncmetrics.iMenuWidth ); + SetFontProperty(TEXT("win.menu.font"), ncmetrics.lfMenuFont, invScale); + SetIntegerProperty(TEXT("win.menu.height"), rescale(ncmetrics.iMenuHeight, invScale)); + SetIntegerProperty(TEXT("win.menu.buttonWidth"), rescale(ncmetrics.iMenuWidth, invScale)); // scrollbar properties - SetIntegerProperty( TEXT("win.scrollbar.width"), ncmetrics.iScrollWidth ); - SetIntegerProperty( TEXT("win.scrollbar.height"), ncmetrics.iScrollHeight ); + SetIntegerProperty(TEXT("win.scrollbar.width"), rescale(ncmetrics.iScrollWidth, invScale)); + SetIntegerProperty(TEXT("win.scrollbar.height"), rescale(ncmetrics.iScrollHeight, invScale)); // status bar and tooltip properties - SetFontProperty( TEXT("win.status.font"), ncmetrics.lfStatusFont ); - SetFontProperty( TEXT("win.tooltip.font"), ncmetrics.lfStatusFont ); + SetFontProperty(TEXT("win.status.font"), ncmetrics.lfStatusFont, invScale); + SetFontProperty(TEXT("win.tooltip.font"), ncmetrics.lfStatusFont, invScale); // message box properties - SetFontProperty( TEXT("win.messagebox.font"), ncmetrics.lfMessageFont ); + SetFontProperty(TEXT("win.messagebox.font"), ncmetrics.lfMessageFont, invScale); } void AwtDesktopProperties::GetIconParameters() { @@ -302,10 +318,11 @@ iconmetrics.cbSize = sizeof(iconmetrics); VERIFY( SystemParametersInfo(SPI_GETICONMETRICS, iconmetrics.cbSize, &iconmetrics, FALSE) ); - SetIntegerProperty(TEXT("win.icon.hspacing"), iconmetrics.iHorzSpacing); - SetIntegerProperty(TEXT("win.icon.vspacing"), iconmetrics.iVertSpacing); + float invScale = getInvScale(); + SetIntegerProperty(TEXT("win.icon.hspacing"), rescale(iconmetrics.iHorzSpacing, invScale)); + SetIntegerProperty(TEXT("win.icon.vspacing"), rescale(iconmetrics.iVertSpacing, invScale)); SetBooleanProperty(TEXT("win.icon.titleWrappingOn"), iconmetrics.iTitleWrap != 0); - SetFontProperty(TEXT("win.icon.font"), iconmetrics.lfFont); + SetFontProperty(TEXT("win.icon.font"), iconmetrics.lfFont, invScale); } /* Windows settings for these are also in the registry @@ -718,6 +735,7 @@ } void AwtDesktopProperties::SetIntegerProperty(LPCTSTR propName, int value) { + jstring key = JNU_NewStringPlatform(GetEnv(), propName); if (key == NULL) { throw std::bad_alloc(); @@ -752,8 +770,13 @@ } void AwtDesktopProperties::SetFontProperty(HDC dc, int fontID, - LPCTSTR propName) { - HGDIOBJ font = GetStockObject(fontID); + LPCTSTR propName) { + AwtDesktopProperties::SetFontProperty(dc, fontID, propName, 1.0f); +} + +void AwtDesktopProperties::SetFontProperty(HDC dc, int fontID, + LPCTSTR propName, float invScale) { + HGDIOBJ font = GetStockObject(fontID); if (font != NULL && SelectObject(dc, font) != NULL) { int length = GetTextFace(dc, 0, NULL); @@ -789,8 +812,8 @@ throw std::bad_alloc(); } - jint pointSize = metrics.tmHeight - - metrics.tmInternalLeading; + jint pointSize = rescale(metrics.tmHeight - + metrics.tmInternalLeading, invScale); jint style = java_awt_Font_PLAIN; if (metrics.tmWeight >= FW_BOLD) { @@ -819,6 +842,11 @@ } void AwtDesktopProperties::SetFontProperty(LPCTSTR propName, const LOGFONT & font) { + AwtDesktopProperties::SetFontProperty(propName, font, 1.0f); +} + +void AwtDesktopProperties::SetFontProperty(LPCTSTR propName, const LOGFONT & font, + float invScale) { jstring fontName; jint pointSize; jint style; @@ -836,7 +864,7 @@ ReleaseDC(NULL, hdc); #endif // Java uses point sizes, but assumes 1 pixel = 1 point - pointSize = -font.lfHeight; + pointSize = rescale(-font.lfHeight, invScale); // convert Windows font style to Java style style = java_awt_Font_PLAIN;