8288516: Enhance font creation
Reviewed-by: psadhukhan, azvegint, rhalade, mschoene
This commit is contained in:
parent
ba86c23eaf
commit
5aae8226fc
src/java.desktop/windows/native
@ -25,6 +25,7 @@
|
||||
|
||||
#include "awt.h"
|
||||
#include <math.h>
|
||||
#include <strsafe.h>
|
||||
#include "jlong.h"
|
||||
#include "awt_Font.h"
|
||||
#include "awt_Toolkit.h"
|
||||
@ -287,7 +288,6 @@ AwtFont* AwtFont::Create(JNIEnv *env, jobject font, jint angle, jfloat awScale)
|
||||
return NULL;
|
||||
}
|
||||
LPCWSTR textComponentFontName = JNU_GetStringPlatformChars(env, jTextComponentFontName, NULL);
|
||||
|
||||
awtFont->m_textInput = -1;
|
||||
for (int i = 0; i < cfnum; i++) {
|
||||
// nativeName is a pair of platform fontname and its charset
|
||||
@ -463,7 +463,7 @@ static HFONT CreateHFont_sub(LPCWSTR name, int style, int height,
|
||||
|
||||
// Set font name
|
||||
WCHAR tmpname[80];
|
||||
wcscpy(tmpname, name);
|
||||
StringCchCopy(tmpname, 80, name);
|
||||
WCHAR* delimit = wcschr(tmpname, L',');
|
||||
if (delimit != NULL)
|
||||
*delimit = L'\0'; // terminate the string after the font name.
|
||||
@ -471,7 +471,7 @@ static HFONT CreateHFont_sub(LPCWSTR name, int style, int height,
|
||||
strip_tail(tmpname,L""); //strip possible trailing whitespace
|
||||
strip_tail(tmpname,L"Italic");
|
||||
strip_tail(tmpname,L"Bold");
|
||||
wcscpy(&(logFont.lfFaceName[0]), tmpname);
|
||||
StringCchCopy(&(logFont.lfFaceName[0]), LF_FACESIZE, tmpname);
|
||||
HFONT hFont = ::CreateFontIndirect(&logFont);
|
||||
DASSERT(hFont != NULL);
|
||||
// get a expanded or condensed version if its specified.
|
||||
@ -502,7 +502,7 @@ HFONT AwtFont::CreateHFont(LPCWSTR name, int style, int height,
|
||||
// 80 > (max face name(=30) + strlen("CHINESEBIG5_CHARSET"))
|
||||
// longName doesn't have to be printable. So, it is OK not to convert.
|
||||
|
||||
wsprintf(longName, L"%ls-%d-%d", name, style, height);
|
||||
StringCchPrintf(longName, 80, L"%ls-%d-%d", name, style, height);
|
||||
|
||||
HFONT hFont = NULL;
|
||||
|
||||
@ -1750,12 +1750,12 @@ LPSTR CCombinedSegTable::GetCodePageSubkey()
|
||||
lpszCP++; // cf lpszCP = "932"
|
||||
|
||||
char szSubKey[KEYLEN];
|
||||
strcpy(szSubKey, "EUDC\\");
|
||||
StringCchCopyA(szSubKey, KEYLEN, "EUDC\\");
|
||||
if ((strlen(szSubKey) + strlen(lpszCP)) >= KEYLEN) {
|
||||
return NULL;
|
||||
}
|
||||
strcpy(&(szSubKey[strlen(szSubKey)]), lpszCP);
|
||||
strcpy(m_szCodePageSubkey, szSubKey);
|
||||
StringCchCatA(szSubKey, KEYLEN, lpszCP);
|
||||
StringCchCopyA(m_szCodePageSubkey, KEYLEN, szSubKey);
|
||||
return m_szCodePageSubkey;
|
||||
}
|
||||
|
||||
@ -1780,7 +1780,7 @@ void CCombinedSegTable::GetEUDCFileName(LPWSTR lpszFileName, int cchFileName)
|
||||
|
||||
// get EUDC font file name
|
||||
WCHAR szFamilyName[80];
|
||||
wcscpy(szFamilyName, GetFontName());
|
||||
StringCchCopy(szFamilyName, 80, GetFontName());
|
||||
WCHAR* delimit = wcschr(szFamilyName, L',');
|
||||
if (delimit != NULL)
|
||||
*delimit = L'\0';
|
||||
@ -1799,7 +1799,7 @@ void CCombinedSegTable::GetEUDCFileName(LPWSTR lpszFileName, int cchFileName)
|
||||
if (m_fTTEUDCFileExist == FALSE)
|
||||
return;
|
||||
if (wcslen(m_szDefaultEUDCFile) > 0) {
|
||||
wcscpy(lpszFileName, m_szDefaultEUDCFile);
|
||||
StringCchCopy(lpszFileName, cchFileName, m_szDefaultEUDCFile);
|
||||
return;
|
||||
}
|
||||
char szDefault[] = "SystemDefaultEUDCFont";
|
||||
@ -1825,7 +1825,7 @@ void CCombinedSegTable::GetEUDCFileName(LPWSTR lpszFileName, int cchFileName)
|
||||
VERIFY(::MultiByteToWideChar(CP_ACP, 0,
|
||||
(LPCSTR)szFileName, -1, lpszFileName, cchFileName) != 0);
|
||||
if (fUseDefault)
|
||||
wcscpy(m_szDefaultEUDCFile, lpszFileName);
|
||||
StringCchCopy(m_szDefaultEUDCFile, _MAX_PATH, lpszFileName);
|
||||
}
|
||||
|
||||
void CCombinedSegTable::Create(LPCWSTR name)
|
||||
|
@ -24,6 +24,7 @@
|
||||
*/
|
||||
|
||||
#include "awt.h"
|
||||
#include <strsafe.h>
|
||||
#include <math.h>
|
||||
#include <windef.h>
|
||||
#include <wtypes.h>
|
||||
@ -2408,7 +2409,7 @@ static jboolean jFontToWFontW(JNIEnv *env, HDC printDC, jstring fontName,
|
||||
size_t nameLen = wcslen(fontNameW);
|
||||
if (nameLen < (sizeof(lf.lfFaceName) / sizeof(lf.lfFaceName[0]))) {
|
||||
|
||||
wcscpy(lf.lfFaceName, fontNameW);
|
||||
StringCchCopyW(lf.lfFaceName, LF_FACESIZE, fontNameW);
|
||||
|
||||
lf.lfCharSet = DEFAULT_CHARSET;
|
||||
lf.lfPitchAndFamily = 0;
|
||||
|
@ -24,6 +24,7 @@
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <strsafe.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <jni.h>
|
||||
@ -63,20 +64,20 @@ JNIEXPORT jstring JNICALL Java_sun_awt_Win32FontManager_getFontPath(JNIEnv *env,
|
||||
end = strrchr(sysdir,'\\');
|
||||
if (end && (stricmp(end,"\\System") || stricmp(end,"\\System32"))) {
|
||||
*end = 0;
|
||||
strcat(sysdir, "\\Fonts");
|
||||
StringCchCatA(sysdir, BSIZE, "\\Fonts");
|
||||
}
|
||||
|
||||
GetWindowsDirectory(windir, BSIZE);
|
||||
if (strlen(windir) > BSIZE-7) {
|
||||
*windir = 0;
|
||||
} else {
|
||||
strcat(windir, "\\Fonts");
|
||||
StringCchCatA(windir, BSIZE, "\\Fonts");
|
||||
}
|
||||
|
||||
strcpy(fontpath,sysdir);
|
||||
StringCchCopyA(fontpath, BSIZE*2, sysdir);
|
||||
if (stricmp(sysdir,windir)) {
|
||||
strcat(fontpath,";");
|
||||
strcat(fontpath,windir);
|
||||
StringCchCatA(fontpath, BSIZE*2, ";");
|
||||
StringCchCatA(fontpath, BSIZE*2, windir);
|
||||
}
|
||||
|
||||
return JNU_NewStringPlatform(env, fontpath);
|
||||
@ -152,7 +153,7 @@ static int DifferentFamily(wchar_t *family, wchar_t* fullName) {
|
||||
info.isDifferent = 0;
|
||||
|
||||
memset(&lfw, 0, sizeof(lfw));
|
||||
wcscpy(lfw.lfFaceName, fullName);
|
||||
StringCchCopyW(lfw.lfFaceName, LF_FACESIZE, fullName);
|
||||
lfw.lfCharSet = DEFAULT_CHARSET;
|
||||
EnumFontFamiliesExW(screenDC, &lfw,
|
||||
(FONTENUMPROCW)CheckFontFamilyProcW,
|
||||
@ -349,7 +350,7 @@ static int CALLBACK EnumFamilyNamesW(
|
||||
}
|
||||
|
||||
memset(&lfw, 0, sizeof(lfw));
|
||||
wcscpy(lfw.lfFaceName, lpelfe->elfLogFont.lfFaceName);
|
||||
StringCchCopyW(lfw.lfFaceName, LF_FACESIZE, lpelfe->elfLogFont.lfFaceName);
|
||||
lfw.lfCharSet = lpelfe->elfLogFont.lfCharSet;
|
||||
EnumFontFamiliesExW(screenDC, &lfw,
|
||||
(FONTENUMPROCW)EnumFontFacesInFamilyProcW,
|
||||
@ -653,7 +654,7 @@ Java_sun_awt_Win32FontManager_populateFontFileNameMap0
|
||||
/* Enumerate fonts via GDI to build maps of fonts and families */
|
||||
memset(&lfw, 0, sizeof(lfw));
|
||||
lfw.lfCharSet = DEFAULT_CHARSET; /* all charsets */
|
||||
wcscpy(lfw.lfFaceName, L""); /* one face per family (CHECK) */
|
||||
StringCchCopyW(lfw.lfFaceName, LF_FACESIZE, L""); /* one face per family (CHECK) */
|
||||
EnumFontFamiliesExW(screenDC, &lfw,
|
||||
(FONTENUMPROCW)EnumFamilyNamesW,
|
||||
(LPARAM)(&fmi), 0L);
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <math.h>
|
||||
#include <strsafe.h>
|
||||
#include <windows.h>
|
||||
#include <winuser.h>
|
||||
|
||||
@ -236,7 +237,7 @@ Java_sun_font_FileFontStrike__1getGlyphImageFromWindows
|
||||
name[nameLen] = '\0';
|
||||
|
||||
if (nameLen < (sizeof(lf.lfFaceName) / sizeof(lf.lfFaceName[0]))) {
|
||||
wcscpy(lf.lfFaceName, name);
|
||||
StringCchCopyW(lf.lfFaceName, LF_FACESIZE, name);
|
||||
} else {
|
||||
FREE_AND_RETURN;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user