< prev index next >

src/java.desktop/windows/native/libawt/windows/awt_Font.cpp

Print this page




 389 }
 390 
 391 static void strip_tail(wchar_t* text, wchar_t* tail) { // strips tail and any possible whitespace before it from the end of text
 392     if (wcslen(text)<=wcslen(tail)) {
 393         return;
 394     }
 395     wchar_t* p = text+wcslen(text)-wcslen(tail);
 396     if (!wcscmp(p, tail)) {
 397         while(p>text && iswspace(*(p-1)))
 398             p--;
 399         *p = 0;
 400     }
 401 
 402 }
 403 
 404 static int ScaleUpX(float x) {
 405     int deviceIndex = AwtWin32GraphicsDevice::DeviceIndexForWindow(
 406         ::GetDesktopWindow());
 407     Devices::InstanceAccess devices;
 408     AwtWin32GraphicsDevice *device = devices->GetDevice(deviceIndex);
 409     return device == NULL ? x : device->ScaleUpX(x);
 410 }
 411 
 412 static int ScaleUpY(int y) {
 413     int deviceIndex = AwtWin32GraphicsDevice::DeviceIndexForWindow(
 414         ::GetDesktopWindow());
 415     Devices::InstanceAccess devices;
 416     AwtWin32GraphicsDevice *device = devices->GetDevice(deviceIndex);
 417     return device == NULL ? y : device->ScaleUpY(y);
 418 }
 419 
 420 static int ScaleDownX(int x) {
 421     int deviceIndex = AwtWin32GraphicsDevice::DeviceIndexForWindow(
 422         ::GetDesktopWindow());
 423     Devices::InstanceAccess devices;
 424     AwtWin32GraphicsDevice *device = devices->GetDevice(deviceIndex);
 425     return device == NULL ? x : device->ScaleDownX(x);
 426 }
 427 
 428 static int ScaleDownY(int y) {
 429     int deviceIndex = AwtWin32GraphicsDevice::DeviceIndexForWindow(


 469         *delimit = L'\0';  // terminate the string after the font name.
 470     // strip "Bold" and "Italic" from the end of the name
 471     strip_tail(tmpname,L""); //strip possible trailing whitespace
 472     strip_tail(tmpname,L"Italic");
 473     strip_tail(tmpname,L"Bold");
 474     wcscpy(&(logFont.lfFaceName[0]), tmpname);
 475     HFONT hFont = ::CreateFontIndirect(&logFont);
 476     DASSERT(hFont != NULL);
 477     // get a expanded or condensed version if its specified.
 478     if (awScale != 1.0f) {
 479         HDC hDC = ::GetDC(0);
 480         HFONT oldFont = (HFONT)::SelectObject(hDC, hFont);
 481         TEXTMETRIC tm;
 482         DWORD avgWidth;
 483         GetTextMetrics(hDC, &tm);
 484         oldFont = (HFONT)::SelectObject(hDC, oldFont);
 485         if (oldFont != NULL) { // should be the same as hFont
 486             VERIFY(::DeleteObject(oldFont));
 487         }
 488         avgWidth = tm.tmAveCharWidth;
 489         logFont.lfWidth = (LONG) ScaleUpX((fabs) (avgWidth * awScale));
 490         hFont = ::CreateFontIndirect(&logFont);
 491         DASSERT(hFont != NULL);
 492         VERIFY(::ReleaseDC(0, hDC));
 493     }
 494 
 495     return hFont;
 496 }
 497 
 498 HFONT AwtFont::CreateHFont(WCHAR* name, int style, int height,
 499                            int angle, float awScale)
 500 {
 501     WCHAR longName[80];
 502     // 80 > (max face name(=30) + strlen("CHINESEBIG5_CHARSET"))
 503     // longName doesn't have to be printable.  So, it is OK not to convert.
 504 
 505     wsprintf(longName, L"%ls-%d-%d", name, style, height);
 506 
 507     HFONT hFont = NULL;
 508 
 509     // only cache & share unrotated, unexpanded/uncondensed fonts




 389 }
 390 
 391 static void strip_tail(wchar_t* text, wchar_t* tail) { // strips tail and any possible whitespace before it from the end of text
 392     if (wcslen(text)<=wcslen(tail)) {
 393         return;
 394     }
 395     wchar_t* p = text+wcslen(text)-wcslen(tail);
 396     if (!wcscmp(p, tail)) {
 397         while(p>text && iswspace(*(p-1)))
 398             p--;
 399         *p = 0;
 400     }
 401 
 402 }
 403 
 404 static int ScaleUpX(float x) {
 405     int deviceIndex = AwtWin32GraphicsDevice::DeviceIndexForWindow(
 406         ::GetDesktopWindow());
 407     Devices::InstanceAccess devices;
 408     AwtWin32GraphicsDevice *device = devices->GetDevice(deviceIndex);
 409     return static_cast<int>(device == NULL ? x : device->ScaleUpX(static_cast<int>(x)));
 410 }
 411 
 412 static int ScaleUpY(int y) {
 413     int deviceIndex = AwtWin32GraphicsDevice::DeviceIndexForWindow(
 414         ::GetDesktopWindow());
 415     Devices::InstanceAccess devices;
 416     AwtWin32GraphicsDevice *device = devices->GetDevice(deviceIndex);
 417     return device == NULL ? y : device->ScaleUpY(y);
 418 }
 419 
 420 static int ScaleDownX(int x) {
 421     int deviceIndex = AwtWin32GraphicsDevice::DeviceIndexForWindow(
 422         ::GetDesktopWindow());
 423     Devices::InstanceAccess devices;
 424     AwtWin32GraphicsDevice *device = devices->GetDevice(deviceIndex);
 425     return device == NULL ? x : device->ScaleDownX(x);
 426 }
 427 
 428 static int ScaleDownY(int y) {
 429     int deviceIndex = AwtWin32GraphicsDevice::DeviceIndexForWindow(


 469         *delimit = L'\0';  // terminate the string after the font name.
 470     // strip "Bold" and "Italic" from the end of the name
 471     strip_tail(tmpname,L""); //strip possible trailing whitespace
 472     strip_tail(tmpname,L"Italic");
 473     strip_tail(tmpname,L"Bold");
 474     wcscpy(&(logFont.lfFaceName[0]), tmpname);
 475     HFONT hFont = ::CreateFontIndirect(&logFont);
 476     DASSERT(hFont != NULL);
 477     // get a expanded or condensed version if its specified.
 478     if (awScale != 1.0f) {
 479         HDC hDC = ::GetDC(0);
 480         HFONT oldFont = (HFONT)::SelectObject(hDC, hFont);
 481         TEXTMETRIC tm;
 482         DWORD avgWidth;
 483         GetTextMetrics(hDC, &tm);
 484         oldFont = (HFONT)::SelectObject(hDC, oldFont);
 485         if (oldFont != NULL) { // should be the same as hFont
 486             VERIFY(::DeleteObject(oldFont));
 487         }
 488         avgWidth = tm.tmAveCharWidth;
 489         logFont.lfWidth = (LONG) ScaleUpX(static_cast<float>((fabs) (avgWidth * awScale)));
 490         hFont = ::CreateFontIndirect(&logFont);
 491         DASSERT(hFont != NULL);
 492         VERIFY(::ReleaseDC(0, hDC));
 493     }
 494 
 495     return hFont;
 496 }
 497 
 498 HFONT AwtFont::CreateHFont(WCHAR* name, int style, int height,
 499                            int angle, float awScale)
 500 {
 501     WCHAR longName[80];
 502     // 80 > (max face name(=30) + strlen("CHINESEBIG5_CHARSET"))
 503     // longName doesn't have to be printable.  So, it is OK not to convert.
 504 
 505     wsprintf(longName, L"%ls-%d-%d", name, style, height);
 506 
 507     HFONT hFont = NULL;
 508 
 509     // only cache & share unrotated, unexpanded/uncondensed fonts


< prev index next >