https://git.reactos.org/?p=reactos.git;a=commitdiff;h=c8749d379beeb3a078c296...
commit c8749d379beeb3a078c296feca1f4cdb3e9d11f1 Author: Katayama Hirofumi MZ katayama.hirofumi.mz@gmail.com AuthorDate: Thu Aug 30 21:34:03 2018 +0900 Commit: Hermès BÉLUSCA - MAÏTO hermes.belusca-maito@reactos.org CommitDate: Thu Aug 30 14:34:03 2018 +0200
[WIN32SS][FONT] Fix GetTextFace function and related (#829)
Google Chrome with -no-sandbox parameter in ReactOS wouldn't display the web page because first-chance exception raised. CORE-14926
- Remove FullName, Style, and FaceName members from TEXTOBJ structure. - Add TextFace member into TEXTOBJ structure. - Add MatchFontName() and MatchFontNames() helper functions. - Fix GetTextFace() and related. --- win32ss/gdi/ntgdi/freetype.c | 75 ++++++++++++++++++++++++++++++++++++++------ win32ss/gdi/ntgdi/text.c | 4 +-- win32ss/gdi/ntgdi/text.h | 4 +-- 3 files changed, 69 insertions(+), 14 deletions(-)
diff --git a/win32ss/gdi/ntgdi/freetype.c b/win32ss/gdi/ntgdi/freetype.c index 5275b36576..e172c5c537 100644 --- a/win32ss/gdi/ntgdi/freetype.c +++ b/win32ss/gdi/ntgdi/freetype.c @@ -4667,6 +4667,53 @@ IntFontType(PFONTGDI Font) } }
+static BOOL +MatchFontName(PSHARED_FACE SharedFace, LPCWSTR lfFaceName, FT_UShort NameID, FT_UShort LangID) +{ + NTSTATUS Status; + UNICODE_STRING Name1, Name2; + + if (lfFaceName[0] == UNICODE_NULL) + return FALSE; + + RtlInitUnicodeString(&Name1, lfFaceName); + + RtlInitUnicodeString(&Name2, NULL); + Status = IntGetFontLocalizedName(&Name2, SharedFace, NameID, LangID); + + if (NT_SUCCESS(Status)) + { + if (RtlCompareUnicodeString(&Name1, &Name2, TRUE) == 0) + { + RtlFreeUnicodeString(&Name2); + return TRUE; + } + + RtlFreeUnicodeString(&Name2); + } + + return FALSE; +} + +static BOOL +MatchFontNames(PSHARED_FACE SharedFace, LPCWSTR lfFaceName) +{ + if (MatchFontName(SharedFace, lfFaceName, TT_NAME_ID_FONT_FAMILY, LANG_ENGLISH) || + MatchFontName(SharedFace, lfFaceName, TT_NAME_ID_FULL_NAME, LANG_ENGLISH)) + { + return TRUE; + } + if (PRIMARYLANGID(gusLanguageID) != LANG_ENGLISH) + { + if (MatchFontName(SharedFace, lfFaceName, TT_NAME_ID_FONT_FAMILY, gusLanguageID) || + MatchFontName(SharedFace, lfFaceName, TT_NAME_ID_FULL_NAME, gusLanguageID)) + { + return TRUE; + } + } + return FALSE; +} + NTSTATUS FASTCALL TextIntRealizeFont(HFONT FontHandle, PTEXTOBJ pTextObj) @@ -4731,22 +4778,32 @@ TextIntRealizeFont(HFONT FontHandle, PTEXTOBJ pTextObj) } else { - UNICODE_STRING FaceName; + UNICODE_STRING Name; PFONTGDI FontGdi = ObjToGDI(TextObj->Font, FONT); + PSHARED_FACE SharedFace = FontGdi->SharedFace;
IntLockFreeType(); IntRequestFontSize(NULL, FontGdi, pLogFont->lfWidth, pLogFont->lfHeight); IntUnLockFreeType();
- RtlInitUnicodeString(&FaceName, NULL); - IntGetFontLocalizedName(&FaceName, FontGdi->SharedFace, TT_NAME_ID_FONT_FAMILY, gusLanguageID); - - /* truncated copy */ - FaceName.Length = (USHORT)min(FaceName.Length, (LF_FACESIZE - 1) * sizeof(WCHAR)); - FaceName.MaximumLength = (USHORT)(FaceName.Length + sizeof(UNICODE_NULL)); - RtlCopyMemory(TextObj->FaceName, FaceName.Buffer, FaceName.MaximumLength); + TextObj->TextFace[0] = UNICODE_NULL; + if (MatchFontNames(SharedFace, SubstitutedLogFont.lfFaceName)) + { + RtlStringCchCopyW(TextObj->TextFace, _countof(TextObj->TextFace), pLogFont->lfFaceName); + } + else + { + RtlInitUnicodeString(&Name, NULL); + Status = IntGetFontLocalizedName(&Name, SharedFace, TT_NAME_ID_FONT_FAMILY, gusLanguageID); + if (NT_SUCCESS(Status)) + { + /* truncated copy */ + Name.Length = (USHORT)min(Name.Length, (LF_FACESIZE - 1) * sizeof(WCHAR)); + RtlStringCbCopyNW(TextObj->TextFace, Name.Length + sizeof(WCHAR), Name.Buffer, Name.Length);
- RtlFreeUnicodeString(&FaceName); + RtlFreeUnicodeString(&Name); + } + }
// Need hdev, when freetype is loaded need to create DEVOBJ for // Consumer and Producer. diff --git a/win32ss/gdi/ntgdi/text.c b/win32ss/gdi/ntgdi/text.c index ec0503fa46..2ea694103a 100644 --- a/win32ss/gdi/ntgdi/text.c +++ b/win32ss/gdi/ntgdi/text.c @@ -513,12 +513,12 @@ NtGdiGetTextFaceW(
TextObj = RealizeFontInit(hFont); ASSERT(TextObj != NULL); - fLen = wcslen(TextObj->FaceName) + 1; + fLen = wcslen(TextObj->TextFace) + 1;
if (FaceName != NULL) { Count = min(Count, fLen); - Status = MmCopyToCaller(FaceName, TextObj->FaceName, Count * sizeof(WCHAR)); + Status = MmCopyToCaller(FaceName, TextObj->TextFace, Count * sizeof(WCHAR)); if (!NT_SUCCESS(Status)) { TEXTOBJ_UnlockText(TextObj); diff --git a/win32ss/gdi/ntgdi/text.h b/win32ss/gdi/ntgdi/text.h index cd8b5b22f0..830ceb1100 100644 --- a/win32ss/gdi/ntgdi/text.h +++ b/win32ss/gdi/ntgdi/text.h @@ -64,9 +64,7 @@ typedef struct _LFONT LFTYPE lft; FLONG fl; FONTOBJ *Font; - WCHAR FullName[LF_FULLFACESIZE]; - WCHAR Style[LF_FACESIZE]; - WCHAR FaceName[LF_FACESIZE]; + WCHAR TextFace[LF_FACESIZE]; DWORD dwOffsetEndArray; // Fixed: ENUMLOGFONTEXDVW logfont;