< prev index next >
src/java.desktop/windows/native/libawt/windows/awt_Font.cpp
Print this page
@@ -396,10 +396,42 @@
*p = 0;
}
}
+static int ScaleUpX(float x) {
+ int deviceIndex = AwtWin32GraphicsDevice::DeviceIndexForWindow(
+ ::GetDesktopWindow());
+ Devices::InstanceAccess devices;
+ AwtWin32GraphicsDevice *device = devices->GetDevice(deviceIndex);
+ return device == NULL ? x : device->ScaleUpX(x);
+}
+
+static int ScaleUpY(int y) {
+ int deviceIndex = AwtWin32GraphicsDevice::DeviceIndexForWindow(
+ ::GetDesktopWindow());
+ Devices::InstanceAccess devices;
+ AwtWin32GraphicsDevice *device = devices->GetDevice(deviceIndex);
+ return device == NULL ? y : device->ScaleUpY(y);
+}
+
+static int ScaleDownX(int x) {
+ int deviceIndex = AwtWin32GraphicsDevice::DeviceIndexForWindow(
+ ::GetDesktopWindow());
+ Devices::InstanceAccess devices;
+ AwtWin32GraphicsDevice *device = devices->GetDevice(deviceIndex);
+ return device == NULL ? x : device->ScaleDownX(x);
+}
+
+static int ScaleDownY(int y) {
+ int deviceIndex = AwtWin32GraphicsDevice::DeviceIndexForWindow(
+ ::GetDesktopWindow());
+ Devices::InstanceAccess devices;
+ AwtWin32GraphicsDevice *device = devices->GetDevice(deviceIndex);
+ return device == NULL ? y : device->ScaleDownY(y);
+}
+
static HFONT CreateHFont_sub(LPCWSTR name, int style, int height,
int angle=0, float awScale=1.0f)
{
LOGFONTW logFont;
@@ -422,11 +454,11 @@
logFont.lfWeight = (style & java_awt_Font_BOLD) ? FW_BOLD : FW_NORMAL;
logFont.lfItalic = (style & java_awt_Font_ITALIC) != 0;
logFont.lfUnderline = 0;//(style & java_awt_Font_UNDERLINE) != 0;
// Get point size
- logFont.lfHeight = -height;
+ logFont.lfHeight = ScaleUpY(-height);
// Set font name
WCHAR tmpname[80];
wcscpy(tmpname, name);
WCHAR* delimit = wcschr(tmpname, L',');
@@ -449,11 +481,11 @@
oldFont = (HFONT)::SelectObject(hDC, oldFont);
if (oldFont != NULL) { // should be the same as hFont
VERIFY(::DeleteObject(oldFont));
}
avgWidth = tm.tmAveCharWidth;
- logFont.lfWidth = (LONG)((fabs)(avgWidth*awScale));
+ logFont.lfWidth = (LONG) ScaleUpX((fabs) (avgWidth * awScale));
hFont = ::CreateFontIndirect(&logFont);
DASSERT(hFont != NULL);
VERIFY(::ReleaseDC(0, hDC));
}
@@ -533,23 +565,24 @@
awtFont->m_ascent = metrics.tmAscent;
int ascent = metrics.tmAscent;
int descent = metrics.tmDescent;
int leading = metrics.tmExternalLeading;
- env->SetIntField(fontMetrics, AwtFont::ascentID, ascent);
- env->SetIntField(fontMetrics, AwtFont::descentID, descent);
- env->SetIntField(fontMetrics, AwtFont::leadingID, leading);
- env->SetIntField(fontMetrics, AwtFont::heightID, metrics.tmAscent +
- metrics.tmDescent + leading);
- env->SetIntField(fontMetrics, AwtFont::maxAscentID, ascent);
- env->SetIntField(fontMetrics, AwtFont::maxDescentID, descent);
+
+ env->SetIntField(fontMetrics, AwtFont::ascentID, ScaleDownY(ascent));
+ env->SetIntField(fontMetrics, AwtFont::descentID, ScaleDownY(descent));
+ env->SetIntField(fontMetrics, AwtFont::leadingID, ScaleDownX(leading));
+ env->SetIntField(fontMetrics, AwtFont::heightID,
+ ScaleDownY(metrics.tmAscent + metrics.tmDescent + leading));
+ env->SetIntField(fontMetrics, AwtFont::maxAscentID, ScaleDownY(ascent));
+ env->SetIntField(fontMetrics, AwtFont::maxDescentID, ScaleDownY(descent));
int maxHeight = ascent + descent + leading;
- env->SetIntField(fontMetrics, AwtFont::maxHeightID, maxHeight);
+ env->SetIntField(fontMetrics, AwtFont::maxHeightID, ScaleDownY(maxHeight));
int maxAdvance = metrics.tmMaxCharWidth;
- env->SetIntField(fontMetrics, AwtFont::maxAdvanceID, maxAdvance);
+ env->SetIntField(fontMetrics, AwtFont::maxAdvanceID, ScaleDownX(maxAdvance));
awtFont->m_overhang = metrics.tmOverhang;
jint intWidths[256];
memset(intWidths, 0, 256 * sizeof(int));
@@ -816,10 +849,11 @@
HDC hDC = ::GetDC(0); DASSERT(hDC != NULL);
jobject font = env->GetObjectField(self, AwtFont::fontID);
long ret = AwtFont::getMFStringWidth(hDC, font, str);
+ ret = ScaleDownX(ret);
VERIFY(::ReleaseDC(0, hDC));
return ret;
CATCH_BAD_ALLOC_RET(0);
}
@@ -922,11 +956,11 @@
}
throw;
}
env->ReleasePrimitiveArrayCritical(str, pStrBody, 0);
- return result;
+ return ScaleDownX(result);
CATCH_BAD_ALLOC_RET(0);
}
< prev index next >