Skip to content

Commit

Permalink
1.15
Browse files Browse the repository at this point in the history
updated
  • Loading branch information
silight-jp committed Oct 23, 2016
1 parent 9d1cbbc commit c479d22
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 84 deletions.
Binary file modified bin/Release/EasyHK32.dll
Binary file not shown.
Binary file modified bin/Release/EasyHK64.dll
Binary file not shown.
1 change: 1 addition & 0 deletions readmeEN.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ How to use
Good Luck!

Version History
2016/10/07 1.15 Bug fix and speed up.
2016/10/05 1.14 Bug fix for High DPI.
Bug fix for text including space.
Add FontSubstitutes experimentally.
Expand Down
Binary file modified readmeJP.txt
Binary file not shown.
8 changes: 4 additions & 4 deletions resource32.rc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,14,0,0
PRODUCTVERSION 1,14,0,0
FILEVERSION 1,15,0,0
PRODUCTVERSION 1,15,0,0
FILEFLAGSMASK 0x0L
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -31,12 +31,12 @@ BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", "MacTypePatch for DirectWrite Hook"
VALUE "FileVersion", "1.14.0.0"
VALUE "FileVersion", "1.15.0.0"
VALUE "InternalName", "EasyHK32.dll"
VALUE "LegalCopyright", "Copyright (C) 2016 silight"
VALUE "OriginalFilename", "EasyHK32.dll"
VALUE "ProductName", "MacTypePatch for DirectWrite Hook"
VALUE "ProductVersion", "1.14.0.0"
VALUE "ProductVersion", "1.15.0.0"
END
END
BLOCK "VarFileInfo"
Expand Down
8 changes: 4 additions & 4 deletions resource64.rc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,14,0,0
PRODUCTVERSION 1,14,0,0
FILEVERSION 1,15,0,0
PRODUCTVERSION 1,15,0,0
FILEFLAGSMASK 0x0L
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -31,12 +31,12 @@ BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", "MacTypePatch for DirectWrite Hook"
VALUE "FileVersion", "1.14.0.0"
VALUE "FileVersion", "1.15.0.0"
VALUE "InternalName", "EasyHK64.dll"
VALUE "LegalCopyright", "Copyright (C) 2016 silight"
VALUE "OriginalFilename", "EasyHK64.dll"
VALUE "ProductName", "MacTypePatch for DirectWrite Hook"
VALUE "ProductVersion", "1.14.0.0"
VALUE "ProductVersion", "1.15.0.0"
END
END
BLOCK "VarFileInfo"
Expand Down
250 changes: 174 additions & 76 deletions src/mactype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace Dummy

namespace Impl
{
static BOOL WINAPI ExtTextOutW(
static BOOL WINAPI ExtTextOutW_BugFix3(
HDC hdc,
int X,
int Y,
Expand All @@ -124,98 +124,196 @@ namespace Impl
UINT cbCount,
CONST INT *lpDx
) {
auto lock = globalMutex.getLock();

// no support printer
if (GetDeviceCaps(hdc, TECHNOLOGY) != DT_RASDISPLAY) {
return Orig::ExtTextOutW(hdc, X, Y, fuOptions, lprc, lpString, cbCount, lpDx);
}

// do recurse
if (!(fuOptions & ETO_GLYPH_INDEX) && !(fuOptions & ETO_IGNORELANGUAGE)) {
return Orig::ExtTextOutW(hdc, X, Y, fuOptions, lprc, lpString, cbCount, lpDx);
}

// bug fix
if (lpString && lpDx) {
// support opaque
if (fuOptions & ETO_OPAQUE) {
Orig::ExtTextOutW(hdc, X, Y, fuOptions, lprc, NULL, 0, NULL);
fuOptions &= ~ETO_OPAQUE;
// bug fix of vertical text
if (fuOptions & ETO_PDY) {
int tx = X, ty = Y, dx = 0, dy = 0;
LPCWSTR tStr = lpString;
UINT tCount = 0;
CONST INT *tDx = lpDx;
for (size_t i = 0; i < cbCount; i++) {
tCount++;
if (i < cbCount - 1) {
dx += lpDx[2 * i];
dy += lpDx[2 * i + 1];
if (dy == 0) continue;
}
Dummy::ExtTextOutW(hdc, tx, ty, fuOptions, lprc, tStr, tCount, tDx);
tx += dx;
ty -= dy;
dx = 0;
dy = 0;
tStr = &lpString[i + 1];
tCount = 0;
tDx = &lpDx[2 * i + 2];
}
return TRUE;
}
return Dummy::ExtTextOutW(hdc, X, Y, fuOptions, lprc, lpString, cbCount, lpDx);
}

// bug fix of space
thread_local bool inBugFix = false;
if (!inBugFix && cbCount > 1 && (GetTextAlign(hdc) & 0x7) == (TA_NOUPDATECP & TA_LEFT) && fuOptions & ETO_GLYPH_INDEX) {
inBugFix = true;

UINT16 space;
DWORD count = GetGlyphIndicesW(hdc, L" ", 1, &space, GGI_MARK_NONEXISTING_GLYPHS);
if (count == 1) {
size_t begin = 0;
int px = X, py = Y, nx = X, ny = Y;
for (size_t i = 0; i < cbCount; i++) {
if (lpString[i] == space || i == cbCount - 1) {
int count = i - begin;
if (count > 0) {
Impl::ExtTextOutW(
hdc,
px,
py,
fuOptions,
lprc,
&lpString[begin],
count,
&lpDx[fuOptions & ETO_PDY ? 2 * begin : begin]
);
static BOOL WINAPI ExtTextOutW_BugFix2(
HDC hdc,
int X,
int Y,
UINT fuOptions,
CONST RECT *lprc,
LPCWSTR lpString,
UINT cbCount,
CONST INT *lpDx
) {
// space bug fix
if (cbCount > 1 && (GetTextAlign(hdc) & 0x7) == (TA_NOUPDATECP & TA_LEFT)) {
bool isSucceeded = true;
UINT16 space = L' ';
if (fuOptions & ETO_GLYPH_INDEX) {
isSucceeded = GetGlyphIndicesW(hdc, L" ", 1, &space, GGI_MARK_NONEXISTING_GLYPHS) == 1;
}
if (isSucceeded) {
WCHAR* textStr = new WCHAR[cbCount];
WCHAR* spaceStr = new WCHAR[cbCount];
UINT textCount = 0;
UINT spaceCount = 0;
INT* textDx = new INT[cbCount * 2 + 2];
INT* spaceDx = new INT[cbCount * 2 + 2];
int textX = 0, textY = 0, spaceX = 0, spaceY = 0;
if (textStr && spaceStr && textDx && spaceDx) {
if (fuOptions & ETO_PDY) {
for (size_t i = 0; i < cbCount; i++) {
if (lpString[i] == space) {
spaceStr[spaceCount] = lpString[i];
spaceDx[2 * spaceCount] = spaceX;
spaceDx[2 * spaceCount + 1] = spaceY;
spaceX = 0;
spaceY = 0;
spaceCount++;
} else {
textStr[textCount] = lpString[i];
textDx[2 * textCount] = textX;
textDx[2 * textCount + 1] = textY;
textX = 0;
textY = 0;
textCount++;
}
textX += lpDx[2 * i];
textY += lpDx[2 * i + 1];
spaceX += lpDx[2 * i];
spaceY += lpDx[2 * i + 1];
}
spaceDx[2 * spaceCount] = spaceX;
spaceDx[2 * spaceCount + 1] = spaceY;
textDx[2 * textCount] = textX;
textDx[2 * textCount + 1] = textY;
if (spaceCount) {
ExtTextOutW_BugFix3(hdc, X + spaceDx[0], Y - spaceDx[1], fuOptions, lprc, spaceStr, spaceCount, spaceDx + 2);
}
if (textCount) {
ExtTextOutW_BugFix3(hdc, X + textDx[0], Y - textDx[1], fuOptions, lprc, textStr, textCount, textDx + 2);
}
} else {
for (size_t i = 0; i < cbCount; i++) {
if (lpString[i] == space) {
spaceStr[spaceCount] = lpString[i];
spaceDx[spaceCount] = spaceX;
spaceX = 0;
spaceCount++;
} else {
textStr[textCount] = lpString[i];
textDx[textCount] = textX;
textX = 0;
textCount++;
}
Dummy::ExtTextOutW(hdc, nx, ny, fuOptions, lprc, &lpString[i], 1, &lpDx[i]);
textX += lpDx[i];
spaceX += lpDx[i];
}
if (fuOptions & ETO_PDY) {
nx += lpDx[2 * i];
ny += lpDx[2 * i + 1];
} else {
nx += lpDx[i];
spaceDx[spaceCount] = spaceX;
textDx[textCount] = textX;
if (spaceCount) {
ExtTextOutW_BugFix3(hdc, X + spaceDx[0], Y, fuOptions, lprc, spaceStr, spaceCount, spaceDx + 1);
}
if (lpString[i] == space) {
px = nx;
py = ny;
begin = i + 1;
if (textCount) {
ExtTextOutW_BugFix3(hdc, X + textDx[0], Y, fuOptions, lprc, textStr, textCount, textDx + 1);
}
}
}

inBugFix = false;
return TRUE;
if (textStr) delete[] textStr;
if (spaceStr) delete[] spaceStr;
if (textDx) delete[] textDx;
if (spaceDx) delete[] spaceDx;

if (textStr && spaceStr && textDx && spaceDx) {
return TRUE;
}
}
}
return ExtTextOutW_BugFix3(hdc, X, Y, fuOptions, lprc, lpString, cbCount, lpDx);
}

// bug fix of vertical text
if (fuOptions & ETO_PDY) {
int tx = X, ty = Y, dx = 0, dy = 0;
LPCWSTR tStr = lpString;
UINT tCount = 0;
CONST INT *tDx = lpDx;
for (size_t i = 0; i < cbCount; i++) {
tCount++;
if (i < cbCount - 1) {
dx += lpDx[2 * i];
dy += lpDx[2 * i + 1];
if (dy == 0) continue;
static BOOL WINAPI ExtTextOutW_BugFix1(
HDC hdc,
int X,
int Y,
UINT fuOptions,
CONST RECT *lprc,
LPCWSTR lpString,
UINT cbCount,
CONST INT *lpDx
) {
// use lpDx in ExtTextOutW_BugFix2
if (!lpDx && !(fuOptions & ETO_PDY)) {
INT* dx = new INT[cbCount]{};
if (dx) {
SIZE size = { };
BOOL isSucceeded = fuOptions & ETO_GLYPH_INDEX ?
GetTextExtentExPointI(hdc, (LPWORD)lpString, cbCount, 0, nullptr, dx, &size) :
GetTextExtentExPointW(hdc, lpString, cbCount, 0, nullptr, dx, &size);
if (isSucceeded) {
for (size_t i = cbCount - 1; i > 0; i--) {
dx[i] -= dx[i - 1];
}
Dummy::ExtTextOutW(hdc, tx, ty, fuOptions, lprc, tStr, tCount, tDx);
tx += dx;
ty -= dy;
dx = 0;
dy = 0;
tStr = &lpString[i + 1];
tCount = 0;
tDx = &lpDx[2 * i + 2];
BOOL ret = ExtTextOutW_BugFix2(hdc, X, Y, fuOptions, lprc, lpString, cbCount, dx);
delete[] dx;
return ret;
}
return TRUE;
}

}
return ExtTextOutW_BugFix2(hdc, X, Y, fuOptions, lprc, lpString, cbCount, lpDx);
}

static BOOL WINAPI ExtTextOutW(
HDC hdc,
int X,
int Y,
UINT fuOptions,
CONST RECT *lprc,
LPCWSTR lpString,
UINT cbCount,
CONST INT *lpDx
) {
auto lock = globalMutex.getLock();

// invalid arguments
bool invalidArguments = !hdc || !lpString || !cbCount;

return Dummy::ExtTextOutW(hdc, X, Y, fuOptions, lprc, lpString, cbCount, lpDx);
// no support printer
bool noDisplay = GetDeviceCaps(hdc, TECHNOLOGY) != DT_RASDISPLAY;

// need recurse
bool needRecurse = !(fuOptions & ETO_GLYPH_INDEX) && !(fuOptions & ETO_IGNORELANGUAGE);

if (invalidArguments || noDisplay || needRecurse) {
return Orig::ExtTextOutW(hdc, X, Y, fuOptions, lprc, lpString, cbCount, lpDx);
}

// draw opaque background
if (fuOptions & ETO_OPAQUE) {
Orig::ExtTextOutW(hdc, X, Y, fuOptions, lprc, NULL, 0, NULL);
fuOptions &= ~ETO_OPAQUE;
}

return ExtTextOutW_BugFix1(hdc, X, Y, fuOptions, lprc, lpString, cbCount, lpDx);
}

static DWORD WINAPI GetGlyphOutlineA(
Expand Down

0 comments on commit c479d22

Please sign in to comment.