Last active
December 11, 2015 11:29
-
-
Save k-takata/4594418 to your computer and use it in GitHub Desktop.
additional patch No.8 for vim-kaoriya-vim-mq-ex / patch-direct_write.diff
(load DirectWrite components dynamically)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/src/Make_cyg.mak b/src/Make_cyg.mak | |
| --- a/src/Make_cyg.mak | |
| +++ b/src/Make_cyg.mak | |
| @@ -92,12 +92,6 @@ | |
| ifndef DIRECTX | |
| DIRECTX = no | |
| endif | |
| -ifeq ($(DIRECTX),yes) | |
| -# DirectWrite requires that WINVER is 0x0600 or above | |
| -ifndef WINVER | |
| -WINVER = 0x0600 | |
| -endif | |
| -endif | |
| ifndef WINVER | |
| WINVER = 0x0500 | |
| diff --git a/src/Make_ming.mak b/src/Make_ming.mak | |
| --- a/src/Make_ming.mak | |
| +++ b/src/Make_ming.mak | |
| @@ -33,12 +33,6 @@ | |
| GUI=yes | |
| # set to yes if you want to use DirectWrite (DirectX) | |
| DIRECTX=no | |
| -ifeq ($(DIRECTX),yes) | |
| -# DirectWrite requires that WINVER is 0x0600 or above | |
| -ifndef WINVER | |
| -WINVER = 0x0600 | |
| -endif | |
| -endif | |
| # FEATURES=[TINY | SMALL | NORMAL | BIG | HUGE] | |
| # Set to TINY to make minimal version (few features). | |
| FEATURES=BIG | |
| diff --git a/src/Make_mvc.mak b/src/Make_mvc.mak | |
| --- a/src/Make_mvc.mak | |
| +++ b/src/Make_mvc.mak | |
| @@ -25,7 +25,7 @@ | |
| # GUI interface: GUI=yes (default is no) | |
| # | |
| # GUI with DirectWrite(DirectX): DIRECTX=yes | |
| -# (default is no, requires GUI=yes and WINVER=0x0600) | |
| +# (default is no, requires GUI=yes) | |
| # | |
| # OLE interface: OLE=yes (usually with GUI=yes) | |
| # | |
| @@ -297,23 +297,12 @@ | |
| !endif | |
| # DirectWrite(DirectX) | |
| -!ifndef DIRECTX | |
| -DIRECTX = no | |
| -!endif | |
| !if "$(DIRECTX)" == "yes" | |
| -# DirectWrite requires that WINVER is 0x0600 or above | |
| -!ifndef WINVER | |
| -WINVER = 0x0600 | |
| -!endif | |
| -!if $(WINVER) < 0x0600 | |
| -!error DirectWrite (DirectX) requires WINVER is 0x0600 or above. | |
| -!else | |
| DIRECTX_DEFS = -DUSE_DIRECT_X | |
| DIRECTX_INCL = gui_dwrite.h | |
| DIRECTX_LIB = d2d1.lib dwrite.lib | |
| DIRECTX_OBJ = $(OUTDIR)\gui_dwrite.obj | |
| !endif | |
| -!endif | |
| !ifndef XPM | |
| # XPM is not set, use the included xpm files, depending on the architecture. | |
| diff --git a/src/gui_dwrite.cpp b/src/gui_dwrite.cpp | |
| --- a/src/gui_dwrite.cpp | |
| +++ b/src/gui_dwrite.cpp | |
| @@ -2,10 +2,6 @@ | |
| #define WIN32_LEAN_AND_MEAN | |
| -#if WINVER < 0x0600 | |
| -# error WINVER must be 0x0600 or above to use DirectWrite(Direct/X). | |
| -#endif | |
| - | |
| #include <windows.h> | |
| #include <crtdbg.h> | |
| #include <assert.h> | |
| @@ -16,12 +12,29 @@ | |
| #include "gui_dwrite.h" | |
| +extern "C" { | |
| +#include "vim.h" | |
| +} | |
| + | |
| #ifdef __MINGW32__ | |
| # define __maybenull SAL__maybenull | |
| # define __in SAL__in | |
| # define __out SAL__out | |
| #endif | |
| +static HINSTANCE hD2d1DLL = NULL; | |
| +static HINSTANCE hDWriteDLL = NULL; | |
| + | |
| +typedef int (WINAPI *PGETUSERDEFAULTLOCALENAME)(LPWSTR, int); | |
| +typedef HRESULT (WINAPI *PD2D1CREATEFACTORY)(D2D1_FACTORY_TYPE, | |
| + REFIID, const D2D1_FACTORY_OPTIONS *, void **); | |
| +typedef HRESULT (WINAPI *PDWRITECREATEFACTORY)(DWRITE_FACTORY_TYPE, | |
| + REFIID, IUnknown **); | |
| + | |
| +static PGETUSERDEFAULTLOCALENAME pGetUserDefaultLocaleName = NULL; | |
| +static PD2D1CREATEFACTORY pD2D1CreateFactory = NULL; | |
| +static PDWRITECREATEFACTORY pDWriteCreateFactory = NULL; | |
| + | |
| template <class T> inline void SafeRelease(T **ppT) | |
| { | |
| if (*ppT) | |
| @@ -311,8 +324,9 @@ | |
| mDpiScaleY = ::GetDeviceCaps(screen, LOGPIXELSY) / 96.0f; | |
| ::ReleaseDC(0, screen); | |
| - hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, | |
| - &mD2D1Factory); | |
| + hr = pD2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, | |
| + __uuidof(ID2D1Factory), NULL, | |
| + reinterpret_cast<void**>(&mD2D1Factory)); | |
| _RPT2(_CRT_WARN, "D2D1CreateFactory: hr=%p p=%p\n", hr, mD2D1Factory); | |
| if (SUCCEEDED(hr)) | |
| @@ -338,7 +352,7 @@ | |
| if (SUCCEEDED(hr)) | |
| { | |
| - hr = DWriteCreateFactory( | |
| + hr = pDWriteCreateFactory( | |
| DWRITE_FACTORY_TYPE_SHARED, | |
| __uuidof(IDWriteFactory), | |
| reinterpret_cast<IUnknown**>(&mDWriteFactory)); | |
| @@ -448,7 +462,7 @@ | |
| wchar_t localeName[LOCALE_NAME_MAX_LENGTH]; | |
| if (SUCCEEDED(hr)) | |
| { | |
| - if (GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH) == 0) | |
| + if (pGetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH) == 0) | |
| hr = HRESULT_FROM_WIN32(GetLastError()); | |
| } | |
| @@ -642,6 +656,27 @@ | |
| DWriteContext * | |
| DWriteContext_Open(void) | |
| { | |
| + hD2d1DLL = vimLoadLib(const_cast<char*>("d2d1.dll")); | |
| + hDWriteDLL = vimLoadLib(const_cast<char*>("dwrite.dll")); | |
| + if (!hD2d1DLL || !hDWriteDLL) | |
| + { | |
| + DWriteContext_Close(NULL); | |
| + return NULL; | |
| + } | |
| + | |
| + pGetUserDefaultLocaleName = (PGETUSERDEFAULTLOCALENAME)GetProcAddress( | |
| + GetModuleHandle("kernel32.dll"), "GetUserDefaultLocaleName"); | |
| + pD2D1CreateFactory = (PD2D1CREATEFACTORY)GetProcAddress(hD2d1DLL, | |
| + "D2D1CreateFactory"); | |
| + pDWriteCreateFactory = (PDWRITECREATEFACTORY)GetProcAddress(hDWriteDLL, | |
| + "DWriteCreateFactory"); | |
| + if (!pGetUserDefaultLocaleName || !pD2D1CreateFactory || | |
| + !pDWriteCreateFactory) | |
| + { | |
| + DWriteContext_Close(NULL); | |
| + return NULL; | |
| + } | |
| + | |
| return new DWriteContext(); | |
| } | |
| @@ -705,6 +740,16 @@ | |
| DWriteContext_Close(DWriteContext *ctx) | |
| { | |
| delete ctx; | |
| + | |
| + if (hD2d1DLL) | |
| + FreeLibrary(hD2d1DLL); | |
| + if (hDWriteDLL) | |
| + FreeLibrary(hDWriteDLL); | |
| + hD2d1DLL = NULL; | |
| + hDWriteDLL = NULL; | |
| + pGetUserDefaultLocaleName = NULL; | |
| + pD2D1CreateFactory = NULL; | |
| + pDWriteCreateFactory = NULL; | |
| } | |
| void | |
| diff --git a/src/gui_w32.c b/src/gui_w32.c | |
| --- a/src/gui_w32.c | |
| +++ b/src/gui_w32.c | |
| @@ -2479,7 +2479,7 @@ | |
| /* Quick hack to enable DirectWrite. To use DirectWrite (antialias), it is | |
| * required that unicode drawing routine, currently. So this forces it | |
| * enabled. */ | |
| - if (p_antialias && enc_utf8) | |
| + if (p_antialias && s_dwc && enc_utf8) | |
| n = 0; /* Keep n < len, to enter block for unicode. */ | |
| #endif | |
| @@ -2542,7 +2542,7 @@ | |
| ++clen; | |
| } | |
| #if defined(USE_DIRECT_X) | |
| - if (p_antialias) | |
| + if (p_antialias && s_dwc) | |
| { | |
| DWriteContext_DrawText(s_dwc, s_hdc, unicodebuf, wlen, | |
| TEXT_X(col), TEXT_Y(row), FILL_X(cells), FILL_Y(1), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment