/* vi:set ts=8 sts=4 sw=4 noet: */
/*
* Author: MURAOKA Taro <koron.kaoriya@gmail.com>
*
* Contributors:
* - Ken Takata
* - Yasuhiro Matsumoto
*
* Copyright (C) 2013 MURAOKA Taro <koron.kaoriya@gmail.com>
* THIS FILE IS DISTRIBUTED UNDER THE VIM LICENSE.
*/
#define WIN32_LEAN_AND_MEAN
#ifndef DYNAMIC_DIRECTX
# if WINVER < 0x0600
# error WINVER must be 0x0600 or above to use DirectWrite(DirectX)
# endif
#endif
#include <windows.h>
#include <crtdbg.h>
#include <assert.h>
#include <math.h>
#include <d2d1.h>
#include <d2d1helper.h>
// Disable these macros to compile with old VC and newer SDK (V8.1 or later).
#if defined(_MSC_VER) && (_MSC_VER < 1700)
# define _COM_Outptr_ __out
# define _In_reads_(s)
# define _In_reads_opt_(s)
# define _Maybenull_
# define _Out_writes_(s)
# define _Out_writes_opt_(s)
# define _Out_writes_to_(x, y)
# define _Out_writes_to_opt_(x, y)
# define _Outptr_
#endif
#ifdef FEAT_DIRECTX_COLOR_EMOJI
# include <dwrite_2.h>
#else
# include <dwrite.h>
#endif
#include "gui_dwrite.h"
#ifdef __MINGW32__
# define __maybenull SAL__maybenull
# define __in SAL__in
# define __out SAL__out
#endif
#ifdef __MINGW32__
# define UNUSED __attribute__((unused))
#else
# define UNUSED
#endif
#if (defined(_MSC_VER) && (_MSC_VER >= 1700)) || (__cplusplus >= 201103L)
# define FINAL final
#else
# define FINAL
#endif
#ifdef DYNAMIC_DIRECTX
extern "C" HINSTANCE vimLoadLib(const char *name);
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 HINSTANCE hD2D1DLL = NULL;
static HINSTANCE hDWriteDLL = NULL;
static PGETUSERDEFAULTLOCALENAME pGetUserDefaultLocaleName = NULL;
static PD2D1CREATEFACTORY pD2D1CreateFactory = NULL;
static PDWRITECREATEFACTORY pDWriteCreateFactory = NULL;
#define GetUserDefaultLocaleName (*pGetUserDefaultLocaleName)
#define D2D1CreateFactory (*pD2D1CreateFactory)
#define DWriteCreateFactory (*pDWriteCreateFactory)
static void
unload(HINSTANCE &hinst)
{
if (hinst != NULL)
{
FreeLibrary(hinst);
hinst = NULL;
}
}
#endif // DYNAMIC_DIRECTX
template <class T> inline void SafeRelease(T **ppT)
{
if (*ppT)
{
(*ppT)->Release();
*ppT = NULL;
}
}
static DWRITE_PIXEL_GEOMETRY
ToPixelGeometry(int value)
{
switch (value)