jkunstle / rpms / vim

Forked from rpms/vim 3 years ago
Clone

Blame SOURCES/7.4.393

073263
To: vim_dev@googlegroups.com
073263
Subject: Patch 7.4.393
073263
Fcc: outbox
073263
From: Bram Moolenaar <Bram@moolenaar.net>
073263
Mime-Version: 1.0
073263
Content-Type: text/plain; charset=UTF-8
073263
Content-Transfer-Encoding: 8bit
073263
------------
073263
073263
Patch 7.4.393
073263
Problem:    Text drawing on newer MS-Windows systems is suboptimal.  Some
073263
	    multi-byte characters are not displayed, even though the same font
073263
	    in Notepad can display them. (Srinath Avadhanula)
073263
Solution:   Add the 'renderoptions' option to enable Direct-X drawing. (Taro
073263
	    Muraoka)
073263
Files:	    runtime/doc/eval.txt, runtime/doc/options.txt,
073263
	    runtime/doc/various.txt, src/Make_cyg.mak, src/Make_ming.mak,
073263
	    src/Make_mvc.mak, src/eval.c, src/gui_dwrite.cpp,
073263
	    src/gui_dwrite.h, src/gui_w32.c, src/gui_w48.c, src/option.c,
073263
	    src/option.h, src/version.c, src/vim.h, src/proto/gui_w32.pro
073263
073263
073263
*** ../vim-7.4.392/runtime/doc/eval.txt	2014-06-25 18:15:18.442838249 +0200
073263
--- runtime/doc/eval.txt	2014-08-06 14:35:24.871243363 +0200
073263
***************
073263
*** 6606,6611 ****
073263
--- 6622,6628 ----
073263
  dialog_gui		Compiled with GUI dialog support.
073263
  diff			Compiled with |vimdiff| and 'diff' support.
073263
  digraphs		Compiled with support for digraphs.
073263
+ directx			Compiled with support for Direct-X and 'renderoptions'.
073263
  dnd			Compiled with support for the "~ register |quote_~|.
073263
  dos16			16 bits DOS version of Vim.
073263
  dos32			32 bits DOS (DJGPP) version of Vim.
073263
***************
073263
*** 6744,6750 ****
073263
  writebackup		Compiled with 'writebackup' default on.
073263
  xfontset		Compiled with X fontset support |xfontset|.
073263
  xim			Compiled with X input method support |xim|.
073263
! xpm_w32			Compiled with pixmap support for Win32.
073263
  xsmp			Compiled with X session management support.
073263
  xsmp_interact		Compiled with interactive X session management support.
073263
  xterm_clipboard		Compiled with support for xterm clipboard.
073263
--- 6761,6769 ----
073263
  writebackup		Compiled with 'writebackup' default on.
073263
  xfontset		Compiled with X fontset support |xfontset|.
073263
  xim			Compiled with X input method support |xim|.
073263
! xpm			Compiled with pixmap support.
073263
! xpm_w32			Compiled with pixmap support for Win32. (Only for
073263
! 			backward compatibility. Use "xpm" instead.)
073263
  xsmp			Compiled with X session management support.
073263
  xsmp_interact		Compiled with interactive X session management support.
073263
  xterm_clipboard		Compiled with support for xterm clipboard.
073263
*** ../vim-7.4.392/runtime/doc/options.txt	2014-07-02 19:59:35.446375136 +0200
073263
--- runtime/doc/options.txt	2014-08-06 14:36:59.591242682 +0200
073263
***************
073263
*** 5647,5652 ****
073263
--- 5650,5726 ----
073263
  	this option at the default "on".  Only switch it off when working with
073263
  	old Vi scripts.
073263
  
073263
+                                                *'renderoptions'* *'rop'*
073263
+ 'renderoptions' 'rop'	string  (default: empty)
073263
+ 			global
073263
+ 			{not in Vi}
073263
+ 			{only available when compiled with GUI and DIRECTX on
073263
+ 			MS-Windows}
073263
+ 	Select a text renderer and set its options.  The options depend on the
073263
+ 	renderer.
073263
+ 
073263
+ 	Syntax: >
073263
+ 		set rop=type:{renderer}(,{name}:{value})*
073263
+ <
073263
+ 	Currently, only one optional renderer is available.
073263
+ 
073263
+ 	render	behavior    ~
073263
+ 	directx	Vim will draw text using DirectX (DirectWrite).  It makes
073263
+ 		drawn glyphs more beautiful than default GDI.
073263
+ 		It requires 'encoding' is "utf-8", and only works on
073263
+ 		MS-Windows Vista or newer version.
073263
+ 
073263
+ 		Options:
073263
+ 		  name	    meaning		type	value       ~
073263
+ 		  gamma	    gamma		float	1.0 - 2.2 (maybe)
073263
+ 		  contrast  enhancedContrast	float	(unknown)
073263
+ 		  level	    clearTypeLevel	float	(unknown)
073263
+ 		  geom	    pixelGeometry	int	0 - 2 (see below)
073263
+ 		  renmode   renderingMode	int	0 - 6 (see below)
073263
+ 		  taamode   textAntialiasMode	int	0 - 3 (see below)
073263
+ 
073263
+ 		See this URL for detail:
073263
+ 		  http://msdn.microsoft.com/en-us/library/dd368190.aspx
073263
+ 
073263
+ 		For geom: structure of a device pixel.
073263
+ 		  0 - DWRITE_PIXEL_GEOMETRY_FLAT
073263
+ 		  1 - DWRITE_PIXEL_GEOMETRY_RGB
073263
+ 		  2 - DWRITE_PIXEL_GEOMETRY_BGR
073263
+ 
073263
+ 		See this URL for detail:
073263
+ 		  http://msdn.microsoft.com/en-us/library/dd368114.aspx
073263
+ 
073263
+ 		For renmode: method of rendering glyphs.
073263
+ 		  0 - DWRITE_RENDERING_MODE_DEFAULT
073263
+ 		  1 - DWRITE_RENDERING_MODE_ALIASED
073263
+ 		  2 - DWRITE_RENDERING_MODE_GDI_CLASSIC
073263
+ 		  3 - DWRITE_RENDERING_MODE_GDI_NATURAL
073263
+ 		  4 - DWRITE_RENDERING_MODE_NATURAL
073263
+ 		  5 - DWRITE_RENDERING_MODE_NATURAL_SYMMETRIC
073263
+ 		  6 - DWRITE_RENDERING_MODE_OUTLINE
073263
+ 
073263
+ 		See this URL for detail:
073263
+ 		  http://msdn.microsoft.com/en-us/library/dd368118.aspx
073263
+ 
073263
+ 		For taamode: antialiasing mode used for drawing text.
073263
+ 		  0 - D2D1_TEXT_ANTIALIAS_MODE_DEFAULT
073263
+ 		  1 - D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE
073263
+ 		  2 - D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE
073263
+ 		  3 - D2D1_TEXT_ANTIALIAS_MODE_ALIASED
073263
+ 
073263
+ 		See this URL for detail:
073263
+ 		  http://msdn.microsoft.com/en-us/library/dd368170.aspx
073263
+ 
073263
+ 		Example: >
073263
+ 		  set encoding=utf-8
073263
+ 		  set gfn=Ricty_Diminished:h12:cSHIFTJIS
073263
+ 		  set rop=type:directx
073263
+ <
073263
+ 		If select a raster font (Courier, Terminal or FixedSys) to
073263
+ 		'guifont', it fallbacks to be drawn by GDI automatically.
073263
+ 
073263
+ 	Other render types are currently not supported.
073263
+ 
073263
  						*'report'*
073263
  'report'		number	(default 2)
073263
  			global
073263
*** ../vim-7.4.392/runtime/doc/various.txt	2013-08-10 13:25:06.000000000 +0200
073263
--- runtime/doc/various.txt	2014-08-06 14:37:28.843242472 +0200
073263
***************
073263
*** 320,325 ****
073263
--- 337,343 ----
073263
  N  *+dialog_con_gui*	Support for |:confirm| with GUI and console dialog.
073263
  N  *+diff*		|vimdiff| and 'diff'
073263
  N  *+digraphs*		|digraphs| *E196*
073263
+ m  *+directx*		Win32 GUI only: DirectX and |'renderoptions'|
073263
     *+dnd*		Support for DnD into the "~ register |quote_~|.
073263
  B  *+emacs_tags*	|emacs-tags| files
073263
  N  *+eval*		expression evaluation |eval.txt|
073263
***************
073263
*** 426,431 ****
073263
--- 445,451 ----
073263
  m  *+writebackup*	|'writebackup'| is default on
073263
  m  *+xim*		X input method |xim|
073263
     *+xfontset*		X fontset support |xfontset|
073263
+    *+xpm*		pixmap support
073263
  m  *+xpm_w32*		Win32 GUI only: pixmap support |w32-xpm-support|
073263
     *+xsmp*		XSMP (X session management) support
073263
     *+xsmp_interact*	interactive XSMP (X session management) support
073263
*** ../vim-7.4.392/src/Make_cyg.mak	2013-12-11 15:06:36.000000000 +0100
073263
--- src/Make_cyg.mak	2014-08-06 14:21:57.455249166 +0200
073263
***************
073263
*** 8,13 ****
073263
--- 8,14 ----
073263
  # Cygwin application use the Makefile (just like on Unix).
073263
  #
073263
  # GUI		no or yes: set to yes if you want the GUI version (yes)
073263
+ # DIRECTX	no or yes: set to yes if you want use DirectWrite (no)
073263
  # PERL		define to path to Perl dir to get Perl support (not defined)
073263
  #   PERL_VER	  define to version of Perl being used (56)
073263
  #   DYNAMIC_PERL  no or yes: set to yes to load the Perl DLL dynamically (yes)
073263
***************
073263
*** 88,93 ****
073263
--- 89,98 ----
073263
  ARCH = i386
073263
  endif
073263
  
073263
+ ifndef DIRECTX
073263
+ DIRECTX = no
073263
+ endif
073263
+ 
073263
  ifndef WINVER
073263
  WINVER = 0x0500
073263
  endif
073263
***************
073263
*** 470,475 ****
073263
--- 475,489 ----
073263
  endif
073263
  
073263
  ##############################
073263
+ ifeq (yes, $(DIRECTX))
073263
+ # Only allow DIRECTX for a GUI build.
073263
+ DEFINES += -DFEAT_DIRECTX -DDYNAMIC_DIRECTX
073263
+ EXTRA_OBJS += $(OUTDIR)/gui_dwrite.o
073263
+ EXTRA_LIBS += -ld2d1 -ldwrite
073263
+ USE_STDCPLUS = yes
073263
+ endif
073263
+ 
073263
+ ##############################
073263
  ifdef XPM
073263
  # Only allow XPM for a GUI build.
073263
  DEFINES += -DFEAT_XPM_W32
073263
***************
073263
*** 495,505 ****
073263
  DEFINES += -DFEAT_OLE
073263
  EXTRA_OBJS += $(OUTDIR)/if_ole.o
073263
  EXTRA_LIBS += -loleaut32
073263
! ifeq (yes, $(STATIC_STDCPLUS))
073263
! EXTRA_LIBS += -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic
073263
! else
073263
! EXTRA_LIBS += -lstdc++
073263
! endif
073263
  endif
073263
  
073263
  ##############################
073263
--- 509,515 ----
073263
  DEFINES += -DFEAT_OLE
073263
  EXTRA_OBJS += $(OUTDIR)/if_ole.o
073263
  EXTRA_LIBS += -loleaut32
073263
! USE_STDCPLUS = yes
073263
  endif
073263
  
073263
  ##############################
073263
***************
073263
*** 513,518 ****
073263
--- 523,537 ----
073263
  DIRSLASH = \\
073263
  endif
073263
  
073263
+ ##############################
073263
+ ifeq (yes, $(USE_STDCPLUS))
073263
+ ifeq (yes, $(STATIC_STDCPLUS))
073263
+ EXTRA_LIBS += -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic
073263
+ else
073263
+ EXTRA_LIBS += -lstdc++
073263
+ endif
073263
+ endif
073263
+ 
073263
  #>>>>> end of choices
073263
  ###########################################################################
073263
  
073263
***************
073263
*** 643,648 ****
073263
--- 662,670 ----
073263
  $(OUTDIR)/gui_w32.o:	gui_w32.c gui_w48.c $(INCL)
073263
  	$(CC) -c $(CFLAGS) gui_w32.c -o $(OUTDIR)/gui_w32.o
073263
  
073263
+ $(OUTDIR)/gui_dwrite.o:	gui_dwrite.cpp $(INCL) gui_dwrite.h
073263
+ 	$(CC) -c $(CFLAGS) gui_dwrite.cpp -o $(OUTDIR)/gui_dwrite.o
073263
+ 
073263
  $(OUTDIR)/if_cscope.o:	if_cscope.c $(INCL) if_cscope.h
073263
  	$(CC) -c $(CFLAGS) if_cscope.c -o $(OUTDIR)/if_cscope.o
073263
  
073263
*** ../vim-7.4.392/src/Make_ming.mak	2014-01-06 15:44:59.000000000 +0100
073263
--- src/Make_ming.mak	2014-08-06 14:21:57.455249166 +0200
073263
***************
073263
*** 31,36 ****
073263
--- 31,38 ----
073263
  OPTIMIZE=MAXSPEED
073263
  # set to yes to make gvim, no for vim
073263
  GUI=yes
073263
+ # set to yes if you want to use DirectWrite (DirectX)
073263
+ DIRECTX=no
073263
  # FEATURES=[TINY | SMALL  | NORMAL | BIG | HUGE]
073263
  # Set to TINY to make minimal version (few features).
073263
  FEATURES=BIG
073263
***************
073263
*** 456,461 ****
073263
--- 458,471 ----
073263
  endif
073263
  endif
073263
  
073263
+ # DirectWrite (DirectX)
073263
+ ifeq ($(DIRECTX),yes)
073263
+ # Only allow DirectWrite for a GUI build.
073263
+ ifeq (yes, $(GUI))
073263
+ DEFINES += -DFEAT_DIRECTX -DDYNAMIC_DIRECTX
073263
+ endif
073263
+ endif
073263
+ 
073263
  # Only allow XPM for a GUI build.
073263
  ifeq (yes, $(GUI))
073263
  
073263
***************
073263
*** 593,598 ****
073263
--- 603,616 ----
073263
  LIB += -lwsock32
073263
  endif
073263
  endif
073263
+ ifeq ($(DIRECTX),yes)
073263
+ # Only allow DIRECTX for a GUI build.
073263
+ ifeq (yes, $(GUI))
073263
+ OBJ += $(OUTDIR)/gui_dwrite.o
073263
+ LIB += -ld2d1 -ldwrite
073263
+ USE_STDCPLUS = yes
073263
+ endif
073263
+ endif
073263
  ifdef XPM
073263
  # Only allow XPM for a GUI build.
073263
  ifeq (yes, $(GUI))
073263
***************
073263
*** 650,660 ****
073263
  ifeq (yes, $(OLE))
073263
  LIB += -loleaut32
073263
  OBJ += $(OUTDIR)/if_ole.o
073263
! ifeq (yes, $(STATIC_STDCPLUS))
073263
! LIB += -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic
073263
! else
073263
! LIB += -lstdc++
073263
! endif
073263
  endif
073263
  
073263
  ifeq (yes, $(MBYTE))
073263
--- 668,674 ----
073263
  ifeq (yes, $(OLE))
073263
  LIB += -loleaut32
073263
  OBJ += $(OUTDIR)/if_ole.o
073263
! USE_STDCPLUS = yes
073263
  endif
073263
  
073263
  ifeq (yes, $(MBYTE))
073263
***************
073263
*** 678,683 ****
073263
--- 692,705 ----
073263
  DEFINES+=-DDYNAMIC_ICONV
073263
  endif
073263
  
073263
+ ifeq (yes, $(USE_STDCPLUS))
073263
+ ifeq (yes, $(STATIC_STDCPLUS))
073263
+ LIB += -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic
073263
+ else
073263
+ LIB += -lstdc++
073263
+ endif
073263
+ endif
073263
+ 
073263
  all: $(TARGET) vimrun.exe xxd/xxd.exe install.exe uninstal.exe GvimExt/gvimext.dll
073263
  
073263
  vimrun.exe: vimrun.c
073263
***************
073263
*** 751,756 ****
073263
--- 773,781 ----
073263
  $(OUTDIR)/gui_w32.o:	gui_w32.c gui_w48.c $(INCL)
073263
  	$(CC) -c $(CFLAGS) gui_w32.c -o $(OUTDIR)/gui_w32.o
073263
  
073263
+ $(OUTDIR)/gui_dwrite.o:	gui_dwrite.cpp $(INCL) gui_dwrite.h
073263
+ 	$(CC) -c $(CFLAGS) gui_dwrite.cpp -o $(OUTDIR)/gui_dwrite.o
073263
+ 
073263
  $(OUTDIR)/if_cscope.o:	if_cscope.c $(INCL) if_cscope.h
073263
  	$(CC) -c $(CFLAGS) if_cscope.c -o $(OUTDIR)/if_cscope.o
073263
  
073263
*** ../vim-7.4.392/src/Make_mvc.mak	2014-05-22 16:29:03.374353200 +0200
073263
--- src/Make_mvc.mak	2014-08-06 14:21:57.455249166 +0200
073263
***************
073263
*** 24,29 ****
073263
--- 24,32 ----
073263
  #
073263
  #	GUI interface: GUI=yes (default is no)
073263
  #
073263
+ #	GUI with DirectWrite(DirectX): DIRECTX=yes
073263
+ #	  (default is no, requires GUI=yes)
073263
+ #
073263
  #	OLE interface: OLE=yes (usually with GUI=yes)
073263
  #
073263
  #	Multibyte support: MBYTE=yes (default is no)
073263
***************
073263
*** 168,173 ****
073263
--- 171,179 ----
073263
  !else
073263
  OBJDIR = .\ObjC
073263
  !endif
073263
+ !if "$(DIRECTX)" == "yes"
073263
+ OBJDIR = $(OBJDIR)X
073263
+ !endif
073263
  !if "$(OLE)" == "yes"
073263
  OBJDIR = $(OBJDIR)O
073263
  !endif
073263
***************
073263
*** 292,297 ****
073263
--- 298,310 ----
073263
  NETBEANS_LIB	= WSock32.lib
073263
  !endif
073263
  
073263
+ # DirectWrite(DirectX)
073263
+ !if "$(DIRECTX)" == "yes"
073263
+ DIRECTX_DEFS	= -DFEAT_DIRECTX -DDYNAMIC_DIRECTX
073263
+ DIRECTX_INCL	= gui_dwrite.h
073263
+ DIRECTX_OBJ	= $(OUTDIR)\gui_dwrite.obj
073263
+ !endif
073263
+ 
073263
  !ifndef XPM
073263
  # XPM is not set, use the included xpm files, depending on the architecture.
073263
  !if "$(CPU)" == "AMD64"
073263
***************
073263
*** 642,647 ****
073263
--- 655,666 ----
073263
  SUBSYSTEM = console
073263
  !endif
073263
  
073263
+ !if "$(GUI)" == "yes" && "$(DIRECTX)" == "yes"
073263
+ CFLAGS = $(CFLAGS) $(DIRECTX_DEFS)
073263
+ GUI_INCL = $(GUI_INCL) $(DIRECTX_INCL)
073263
+ GUI_OBJ = $(GUI_OBJ) $(DIRECTX_OBJ)
073263
+ !endif
073263
+ 
073263
  # iconv.dll library (dynamically loaded)
073263
  !ifndef ICONV
073263
  ICONV = yes
073263
***************
073263
*** 1107,1112 ****
073263
--- 1126,1133 ----
073263
  
073263
  $(OUTDIR)/gui_w32.obj:	$(OUTDIR) gui_w32.c gui_w48.c $(INCL) $(GUI_INCL)
073263
  
073263
+ $(OUTDIR)/gui_dwrite.obj:	$(OUTDIR) gui_dwrite.cpp $(INCL) $(GUI_INCL)
073263
+ 
073263
  $(OUTDIR)/if_cscope.obj: $(OUTDIR) if_cscope.c  $(INCL)
073263
  
073263
  $(OUTDIR)/if_lua.obj: $(OUTDIR) if_lua.c  $(INCL)
073263
*** ../vim-7.4.392/src/eval.c	2014-08-06 13:36:56.091268582 +0200
073263
--- src/eval.c	2014-08-06 14:21:57.459249166 +0200
073263
***************
073263
*** 12464,12469 ****
073263
--- 12464,12472 ----
073263
  #ifdef FEAT_DIGRAPHS
073263
  	"digraphs",
073263
  #endif
073263
+ #ifdef FEAT_DIRECTX
073263
+ 	"directx",
073263
+ #endif
073263
  #ifdef FEAT_DND
073263
  	"dnd",
073263
  #endif
073263
*** ../vim-7.4.392/src/gui_dwrite.cpp	2014-08-06 14:49:19.663237363 +0200
073263
--- src/gui_dwrite.cpp	2014-08-06 14:39:48.775241466 +0200
073263
***************
073263
*** 0 ****
073263
--- 1,901 ----
073263
+ /* vi:set ts=8 sts=4 sw=4 noet: */
073263
+ /*
073263
+  * Author: MURAOKA Taro <koron.kaoriya@gmail.com>
073263
+  *
073263
+  * Contributors:
073263
+  *  - Ken Takata
073263
+  *
073263
+  * Copyright (C) 2013 MURAOKA Taro <koron.kaoriya@gmail.com>
073263
+  * THIS FILE IS DISTRIBUTED UNDER THE VIM LICENSE.
073263
+  */
073263
+ 
073263
+ #define WIN32_LEAN_AND_MEAN
073263
+ 
073263
+ #ifndef DYNAMIC_DIRECTX
073263
+ # if WINVER < 0x0600
073263
+ #  error WINVER must be 0x0600 or above to use DirectWrite(DirectX)
073263
+ # endif
073263
+ #endif
073263
+ 
073263
+ #include <windows.h>
073263
+ #include <crtdbg.h>
073263
+ #include <assert.h>
073263
+ #include <math.h>
073263
+ #include <d2d1.h>
073263
+ #include <d2d1helper.h>
073263
+ #include <dwrite.h>
073263
+ 
073263
+ #include "gui_dwrite.h"
073263
+ 
073263
+ #ifdef __MINGW32__
073263
+ # define __maybenull	SAL__maybenull
073263
+ # define __in		SAL__in
073263
+ # define __out		SAL__out
073263
+ #endif
073263
+ 
073263
+ #ifdef DYNAMIC_DIRECTX
073263
+ extern "C" HINSTANCE vimLoadLib(char *name);
073263
+ 
073263
+ typedef int (WINAPI *PGETUSERDEFAULTLOCALENAME)(LPWSTR, int);
073263
+ typedef HRESULT (WINAPI *PD2D1CREATEFACTORY)(D2D1_FACTORY_TYPE,
073263
+ 	REFIID, const D2D1_FACTORY_OPTIONS *, void **);
073263
+ typedef HRESULT (WINAPI *PDWRITECREATEFACTORY)(DWRITE_FACTORY_TYPE,
073263
+ 	REFIID, IUnknown **);
073263
+ 
073263
+ static HINSTANCE hD2D1DLL = NULL;
073263
+ static HINSTANCE hDWriteDLL = NULL;
073263
+ 
073263
+ static PGETUSERDEFAULTLOCALENAME pGetUserDefaultLocaleName = NULL;
073263
+ static PD2D1CREATEFACTORY pD2D1CreateFactory = NULL;
073263
+ static PDWRITECREATEFACTORY pDWriteCreateFactory = NULL;
073263
+ 
073263
+ #define GetUserDefaultLocaleName	(*pGetUserDefaultLocaleName)
073263
+ #define D2D1CreateFactory		(*pD2D1CreateFactory)
073263
+ #define DWriteCreateFactory		(*pDWriteCreateFactory)
073263
+ 
073263
+     static void
073263
+ unload(HINSTANCE &hinst)
073263
+ {
073263
+     if (hinst != NULL)
073263
+     {
073263
+ 	FreeLibrary(hinst);
073263
+ 	hinst = NULL;
073263
+     }
073263
+ }
073263
+ #endif // DYNAMIC_DIRECTX
073263
+ 
073263
+ template <class T> inline void SafeRelease(T **ppT)
073263
+ {
073263
+     if (*ppT)
073263
+     {
073263
+ 	(*ppT)->Release();
073263
+ 	*ppT = NULL;
073263
+     }
073263
+ }
073263
+ 
073263
+ struct GdiTextRendererContext
073263
+ {
073263
+     // const fields.
073263
+     COLORREF color;
073263
+     FLOAT cellWidth;
073263
+ 
073263
+     // working fields.
073263
+     FLOAT offsetX;
073263
+ };
073263
+ 
073263
+     static DWRITE_PIXEL_GEOMETRY
073263
+ ToPixelGeometry(int value)
073263
+ {
073263
+     switch (value)
073263
+     {
073263
+ 	default:
073263
+ 	case 0:
073263
+ 	    return DWRITE_PIXEL_GEOMETRY_FLAT;
073263
+ 	case 1:
073263
+ 	    return DWRITE_PIXEL_GEOMETRY_RGB;
073263
+ 	case 2:
073263
+ 	    return DWRITE_PIXEL_GEOMETRY_BGR;
073263
+     }
073263
+ }
073263
+ 
073263
+     static int
073263
+ ToInt(DWRITE_PIXEL_GEOMETRY value)
073263
+ {
073263
+     switch (value)
073263
+     {
073263
+ 	case DWRITE_PIXEL_GEOMETRY_FLAT:
073263
+ 	    return 0;
073263
+ 	case DWRITE_PIXEL_GEOMETRY_RGB:
073263
+ 	    return 1;
073263
+ 	case DWRITE_PIXEL_GEOMETRY_BGR:
073263
+ 	    return 2;
073263
+ 	default:
073263
+ 	    return -1;
073263
+     }
073263
+ }
073263
+ 
073263
+     static DWRITE_RENDERING_MODE
073263
+ ToRenderingMode(int value)
073263
+ {
073263
+     switch (value)
073263
+     {
073263
+ 	default:
073263
+ 	case 0:
073263
+ 	    return DWRITE_RENDERING_MODE_DEFAULT;
073263
+ 	case 1:
073263
+ 	    return DWRITE_RENDERING_MODE_ALIASED;
073263
+ 	case 2:
073263
+ 	    return DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC;
073263
+ 	case 3:
073263
+ 	    return DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL;
073263
+ 	case 4:
073263
+ 	    return DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL;
073263
+ 	case 5:
073263
+ 	    return DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC;
073263
+ 	case 6:
073263
+ 	    return DWRITE_RENDERING_MODE_OUTLINE;
073263
+     }
073263
+ }
073263
+ 
073263
+     static D2D1_TEXT_ANTIALIAS_MODE
073263
+ ToTextAntialiasMode(int value)
073263
+ {
073263
+     switch (value)
073263
+     {
073263
+ 	default:
073263
+ 	case 0:
073263
+ 	    return D2D1_TEXT_ANTIALIAS_MODE_DEFAULT;
073263
+ 	case 1:
073263
+ 	    return D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE;
073263
+ 	case 2:
073263
+ 	    return D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE;
073263
+ 	case 3:
073263
+ 	    return D2D1_TEXT_ANTIALIAS_MODE_ALIASED;
073263
+     }
073263
+ }
073263
+ 
073263
+     static int
073263
+ ToInt(DWRITE_RENDERING_MODE value)
073263
+ {
073263
+     switch (value)
073263
+     {
073263
+ 	case DWRITE_RENDERING_MODE_DEFAULT:
073263
+ 	    return 0;
073263
+ 	case DWRITE_RENDERING_MODE_ALIASED:
073263
+ 	    return 1;
073263
+ 	case DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC:
073263
+ 	    return 2;
073263
+ 	case DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL:
073263
+ 	    return 3;
073263
+ 	case DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL:
073263
+ 	    return 4;
073263
+ 	case DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC:
073263
+ 	    return 5;
073263
+ 	case DWRITE_RENDERING_MODE_OUTLINE:
073263
+ 	    return 6;
073263
+ 	default:
073263
+ 	    return -1;
073263
+     }
073263
+ }
073263
+ 
073263
+ class AdjustedGlyphRun : public DWRITE_GLYPH_RUN
073263
+ {
073263
+ private:
073263
+     FLOAT mDelta;
073263
+     FLOAT *mAdjustedAdvances;
073263
+ 
073263
+ public:
073263
+     AdjustedGlyphRun(
073263
+ 	    const DWRITE_GLYPH_RUN *glyphRun,
073263
+ 	    FLOAT cellWidth) :
073263
+ 	DWRITE_GLYPH_RUN(*glyphRun),
073263
+ 	mDelta(0.0f),
073263
+ 	mAdjustedAdvances(new FLOAT[glyphRun->glyphCount])
073263
+     {
073263
+ 	assert(cellWidth != 0.0f);
073263
+ 	for (UINT32 i = 0; i < glyphRun->glyphCount; ++i)
073263
+ 	{
073263
+ 	    FLOAT orig = glyphRun->glyphAdvances[i];
073263
+ 	    FLOAT adjusted = adjustToCell(orig, cellWidth);
073263
+ 	    mAdjustedAdvances[i] = adjusted;
073263
+ 	    mDelta += adjusted - orig;
073263
+ 	}
073263
+ 	glyphAdvances = mAdjustedAdvances;
073263
+     }
073263
+ 
073263
+     ~AdjustedGlyphRun(void)
073263
+     {
073263
+ 	delete[] mAdjustedAdvances;
073263
+     }
073263
+ 
073263
+     FLOAT getDelta(void) const
073263
+     {
073263
+ 	return mDelta;
073263
+     }
073263
+ 
073263
+     static FLOAT adjustToCell(FLOAT value, FLOAT cellWidth)
073263
+     {
073263
+ 	int cellCount = (int)floor(value / cellWidth + 0.5f);
073263
+ 	if (cellCount < 1)
073263
+ 	    cellCount = 1;
073263
+ 	return cellCount * cellWidth;
073263
+     }
073263
+ };
073263
+ 
073263
+ class GdiTextRenderer : public IDWriteTextRenderer
073263
+ {
073263
+ public:
073263
+     GdiTextRenderer(
073263
+ 	    IDWriteBitmapRenderTarget* bitmapRenderTarget,
073263
+ 	    IDWriteRenderingParams* renderingParams) :
073263
+ 	cRefCount_(0),
073263
+ 	pRenderTarget_(bitmapRenderTarget),
073263
+ 	pRenderingParams_(renderingParams)
073263
+     {
073263
+ 	pRenderTarget_->AddRef();
073263
+ 	pRenderingParams_->AddRef();
073263
+ 	AddRef();
073263
+     }
073263
+ 
073263
+     ~GdiTextRenderer()
073263
+     {
073263
+ 	SafeRelease(&pRenderTarget_);
073263
+ 	SafeRelease(&pRenderingParams_);
073263
+     }
073263
+ 
073263
+     IFACEMETHOD(IsPixelSnappingDisabled)(
073263
+ 	__maybenull void* clientDrawingContext,
073263
+ 	__out BOOL* isDisabled)
073263
+     {
073263
+ 	*isDisabled = FALSE;
073263
+ 	return S_OK;
073263
+     }
073263
+ 
073263
+     IFACEMETHOD(GetCurrentTransform)(
073263
+ 	__maybenull void* clientDrawingContext,
073263
+ 	__out DWRITE_MATRIX* transform)
073263
+     {
073263
+ 	//forward the render target's transform
073263
+ 	pRenderTarget_->GetCurrentTransform(transform);
073263
+ 	return S_OK;
073263
+     }
073263
+ 
073263
+     IFACEMETHOD(GetPixelsPerDip)(
073263
+ 	__maybenull void* clientDrawingContext,
073263
+ 	__out FLOAT* pixelsPerDip)
073263
+     {
073263
+ 	*pixelsPerDip = pRenderTarget_->GetPixelsPerDip();
073263
+ 	return S_OK;
073263
+     }
073263
+ 
073263
+     IFACEMETHOD(DrawGlyphRun)(
073263
+ 	__maybenull void* clientDrawingContext,
073263
+ 	FLOAT baselineOriginX,
073263
+ 	FLOAT baselineOriginY,
073263
+ 	DWRITE_MEASURING_MODE measuringMode,
073263
+ 	__in DWRITE_GLYPH_RUN const* glyphRun,
073263
+ 	__in DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription,
073263
+ 	IUnknown* clientDrawingEffect)
073263
+     {
073263
+ 	HRESULT hr = S_OK;
073263
+ 
073263
+ 	GdiTextRendererContext *context =
073263
+ 	    reinterpret_cast<GdiTextRendererContext*>(clientDrawingContext);
073263
+ 
073263
+ 	AdjustedGlyphRun adjustedGlyphRun(glyphRun, context->cellWidth);
073263
+ 
073263
+ 	// Pass on the drawing call to the render target to do the real work.
073263
+ 	RECT dirtyRect = {0};
073263
+ 
073263
+ 	hr = pRenderTarget_->DrawGlyphRun(
073263
+ 		baselineOriginX + context->offsetX,
073263
+ 		baselineOriginY,
073263
+ 		measuringMode,
073263
+ 		&adjustedGlyphRun,
073263
+ 		pRenderingParams_,
073263
+ 		context->color,
073263
+ 		&dirtyRect);
073263
+ 
073263
+ 	context->offsetX += adjustedGlyphRun.getDelta();
073263
+ 
073263
+ 	return hr;
073263
+     }
073263
+ 
073263
+     IFACEMETHOD(DrawUnderline)(
073263
+ 	__maybenull void* clientDrawingContext,
073263
+ 	FLOAT baselineOriginX,
073263
+ 	FLOAT baselineOriginY,
073263
+ 	__in DWRITE_UNDERLINE const* underline,
073263
+ 	IUnknown* clientDrawingEffect)
073263
+     {
073263
+ 	return E_NOTIMPL;
073263
+     }
073263
+ 
073263
+     IFACEMETHOD(DrawStrikethrough)(
073263
+ 	__maybenull void* clientDrawingContext,
073263
+ 	FLOAT baselineOriginX,
073263
+ 	FLOAT baselineOriginY,
073263
+ 	__in DWRITE_STRIKETHROUGH const* strikethrough,
073263
+ 	IUnknown* clientDrawingEffect)
073263
+     {
073263
+ 	return E_NOTIMPL;
073263
+     }
073263
+ 
073263
+     IFACEMETHOD(DrawInlineObject)(
073263
+ 	__maybenull void* clientDrawingContext,
073263
+ 	FLOAT originX,
073263
+ 	FLOAT originY,
073263
+ 	IDWriteInlineObject* inlineObject,
073263
+ 	BOOL isSideways,
073263
+ 	BOOL isRightToLeft,
073263
+ 	IUnknown* clientDrawingEffect)
073263
+     {
073263
+ 	return E_NOTIMPL;
073263
+     }
073263
+ 
073263
+ public:
073263
+     IFACEMETHOD_(unsigned long, AddRef) ()
073263
+     {
073263
+ 	return InterlockedIncrement(&cRefCount_);
073263
+     }
073263
+ 
073263
+     IFACEMETHOD_(unsigned long, Release) ()
073263
+     {
073263
+ 	long newCount = InterlockedDecrement(&cRefCount_);
073263
+ 
073263
+ 	if (newCount == 0)
073263
+ 	{
073263
+ 	    delete this;
073263
+ 	    return 0;
073263
+ 	}
073263
+ 	return newCount;
073263
+     }
073263
+ 
073263
+     IFACEMETHOD(QueryInterface)(
073263
+ 	IID const& riid,
073263
+ 	void** ppvObject)
073263
+     {
073263
+ 	if (__uuidof(IDWriteTextRenderer) == riid)
073263
+ 	{
073263
+ 	    *ppvObject = this;
073263
+ 	}
073263
+ 	else if (__uuidof(IDWritePixelSnapping) == riid)
073263
+ 	{
073263
+ 	    *ppvObject = this;
073263
+ 	}
073263
+ 	else if (__uuidof(IUnknown) == riid)
073263
+ 	{
073263
+ 	    *ppvObject = this;
073263
+ 	}
073263
+ 	else
073263
+ 	{
073263
+ 	    *ppvObject = NULL;
073263
+ 	    return E_FAIL;
073263
+ 	}
073263
+ 
073263
+ 	return S_OK;
073263
+     }
073263
+ 
073263
+ private:
073263
+     unsigned long cRefCount_;
073263
+     IDWriteBitmapRenderTarget* pRenderTarget_;
073263
+     IDWriteRenderingParams* pRenderingParams_;
073263
+ };
073263
+ 
073263
+ struct DWriteContext {
073263
+     FLOAT mDpiScaleX;
073263
+     FLOAT mDpiScaleY;
073263
+     bool mDrawing;
073263
+ 
073263
+     ID2D1Factory *mD2D1Factory;
073263
+ 
073263
+     ID2D1DCRenderTarget *mRT;
073263
+     ID2D1SolidColorBrush *mBrush;
073263
+ 
073263
+     IDWriteFactory *mDWriteFactory;
073263
+     IDWriteGdiInterop *mGdiInterop;
073263
+     IDWriteRenderingParams *mRenderingParams;
073263
+     IDWriteTextFormat *mTextFormat;
073263
+ 
073263
+     HFONT mLastHFont;
073263
+     DWRITE_FONT_WEIGHT mFontWeight;
073263
+     DWRITE_FONT_STYLE mFontStyle;
073263
+ 
073263
+     D2D1_TEXT_ANTIALIAS_MODE mTextAntialiasMode;
073263
+ 
073263
+     // METHODS
073263
+ 
073263
+     DWriteContext();
073263
+ 
073263
+     virtual ~DWriteContext();
073263
+ 
073263
+     HRESULT SetLOGFONT(const LOGFONTW &logFont, float fontSize);
073263
+ 
073263
+     void SetFont(HFONT hFont);
073263
+ 
073263
+     void SetFont(const LOGFONTW &logFont);
073263
+ 
073263
+     void DrawText(HDC hdc, const WCHAR* text, int len,
073263
+ 	int x, int y, int w, int h, int cellWidth, COLORREF color);
073263
+ 
073263
+     float PixelsToDipsX(int x);
073263
+ 
073263
+     float PixelsToDipsY(int y);
073263
+ 
073263
+     void SetRenderingParams(
073263
+ 	    const DWriteRenderingParams *params);
073263
+ 
073263
+     DWriteRenderingParams *GetRenderingParams(
073263
+ 	    DWriteRenderingParams *params);
073263
+ };
073263
+ 
073263
+ DWriteContext::DWriteContext() :
073263
+     mDpiScaleX(1.f),
073263
+     mDpiScaleY(1.f),
073263
+     mDrawing(false),
073263
+     mD2D1Factory(NULL),
073263
+     mRT(NULL),
073263
+     mBrush(NULL),
073263
+     mDWriteFactory(NULL),
073263
+     mGdiInterop(NULL),
073263
+     mRenderingParams(NULL),
073263
+     mTextFormat(NULL),
073263
+     mLastHFont(NULL),
073263
+     mFontWeight(DWRITE_FONT_WEIGHT_NORMAL),
073263
+     mFontStyle(DWRITE_FONT_STYLE_NORMAL),
073263
+     mTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_DEFAULT)
073263
+ {
073263
+     HRESULT hr;
073263
+ 
073263
+     HDC screen = ::GetDC(0);
073263
+     mDpiScaleX = ::GetDeviceCaps(screen, LOGPIXELSX) / 96.0f;
073263
+     mDpiScaleY = ::GetDeviceCaps(screen, LOGPIXELSY) / 96.0f;
073263
+     ::ReleaseDC(0, screen);
073263
+ 
073263
+     hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED,
073263
+ 	    __uuidof(ID2D1Factory), NULL,
073263
+ 	    reinterpret_cast<void**>(&mD2D1Factory));
073263
+     _RPT2(_CRT_WARN, "D2D1CreateFactory: hr=%p p=%p\n", hr, mD2D1Factory);
073263
+ 
073263
+     if (SUCCEEDED(hr))
073263
+     {
073263
+ 	D2D1_RENDER_TARGET_PROPERTIES props = {
073263
+ 	    D2D1_RENDER_TARGET_TYPE_DEFAULT,
073263
+ 	    { DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE },
073263
+ 	    0, 0,
073263
+ 	    D2D1_RENDER_TARGET_USAGE_NONE,
073263
+ 	    D2D1_FEATURE_LEVEL_DEFAULT
073263
+ 	};
073263
+ 	hr = mD2D1Factory->CreateDCRenderTarget(&props, &mRT);
073263
+ 	_RPT2(_CRT_WARN, "CreateDCRenderTarget: hr=%p p=%p\n", hr, mRT);
073263
+     }
073263
+ 
073263
+     if (SUCCEEDED(hr))
073263
+     {
073263
+ 	hr = mRT->CreateSolidColorBrush(
073263
+ 		D2D1::ColorF(D2D1::ColorF::Black),
073263
+ 		&mBrush);
073263
+ 	_RPT2(_CRT_WARN, "CreateSolidColorBrush: hr=%p p=%p\n", hr, mBrush);
073263
+     }
073263
+ 
073263
+     if (SUCCEEDED(hr))
073263
+     {
073263
+ 	hr = DWriteCreateFactory(
073263
+ 		DWRITE_FACTORY_TYPE_SHARED,
073263
+ 		__uuidof(IDWriteFactory),
073263
+ 		reinterpret_cast<IUnknown**>(&mDWriteFactory));
073263
+ 	_RPT2(_CRT_WARN, "DWriteCreateFactory: hr=%p p=%p\n", hr,
073263
+ 		mDWriteFactory);
073263
+     }
073263
+ 
073263
+     if (SUCCEEDED(hr))
073263
+     {
073263
+ 	hr = mDWriteFactory->GetGdiInterop(&mGdiInterop);
073263
+ 	_RPT2(_CRT_WARN, "GetGdiInterop: hr=%p p=%p\n", hr, mGdiInterop);
073263
+     }
073263
+ 
073263
+     if (SUCCEEDED(hr))
073263
+     {
073263
+ 	hr = mDWriteFactory->CreateRenderingParams(&mRenderingParams);
073263
+ 	_RPT2(_CRT_WARN, "CreateRenderingParams: hr=%p p=%p\n", hr,
073263
+ 		mRenderingParams);
073263
+     }
073263
+ }
073263
+ 
073263
+ DWriteContext::~DWriteContext()
073263
+ {
073263
+     SafeRelease(&mTextFormat);
073263
+     SafeRelease(&mRenderingParams);
073263
+     SafeRelease(&mGdiInterop);
073263
+     SafeRelease(&mDWriteFactory);
073263
+     SafeRelease(&mBrush);
073263
+     SafeRelease(&mRT);
073263
+     SafeRelease(&mD2D1Factory);
073263
+ }
073263
+ 
073263
+     HRESULT
073263
+ DWriteContext::SetLOGFONT(const LOGFONTW &logFont, float fontSize)
073263
+ {
073263
+     // Most of this function is copy from: http://msdn.microsoft.com/en-us/library/windows/desktop/dd941783(v=vs.85).aspx
073263
+     HRESULT hr = S_OK;
073263
+ 
073263
+     IDWriteFont *font = NULL;
073263
+     IDWriteFontFamily *fontFamily = NULL;
073263
+     IDWriteLocalizedStrings *localizedFamilyNames = NULL;
073263
+ 
073263
+     if (SUCCEEDED(hr))
073263
+     {
073263
+ 	hr = mGdiInterop->CreateFontFromLOGFONT(&logFont, &font);
073263
+     }
073263
+ 
073263
+     // Get the font family to which this font belongs.
073263
+     if (SUCCEEDED(hr))
073263
+     {
073263
+ 	hr = font->GetFontFamily(&fontFamily);
073263
+     }
073263
+ 
073263
+     // Get the family names. This returns an object that encapsulates one or
073263
+     // more names with the same meaning but in different languages.
073263
+     if (SUCCEEDED(hr))
073263
+     {
073263
+ 	hr = fontFamily->GetFamilyNames(&localizedFamilyNames);
073263
+     }
073263
+ 
073263
+     // Get the family name at index zero. If we were going to display the name
073263
+     // we'd want to try to find one that matched the use locale, but for
073263
+     // purposes of creating a text format object any language will do.
073263
+ 
073263
+     wchar_t familyName[100];
073263
+     if (SUCCEEDED(hr))
073263
+     {
073263
+ 	hr = localizedFamilyNames->GetString(0, familyName,
073263
+ 		ARRAYSIZE(familyName));
073263
+     }
073263
+ 
073263
+     if (SUCCEEDED(hr))
073263
+     {
073263
+ 	// If no font size was passed in use the lfHeight of the LOGFONT.
073263
+ 	if (fontSize == 0)
073263
+ 	{
073263
+ 	    // Convert from pixels to DIPs.
073263
+ 	    fontSize = PixelsToDipsY(logFont.lfHeight);
073263
+ 	    if (fontSize < 0)
073263
+ 	    {
073263
+ 		// Negative lfHeight represents the size of the em unit.
073263
+ 		fontSize = -fontSize;
073263
+ 	    }
073263
+ 	    else
073263
+ 	    {
073263
+ 		// Positive lfHeight represents the cell height (ascent +
073263
+ 		// descent).
073263
+ 		DWRITE_FONT_METRICS fontMetrics;
073263
+ 		font->GetMetrics(&fontMetrics);
073263
+ 
073263
+ 		// Convert the cell height (ascent + descent) from design units
073263
+ 		// to ems.
073263
+ 		float cellHeight = static_cast<float>(
073263
+ 			fontMetrics.ascent + fontMetrics.descent)
073263
+ 					       / fontMetrics.designUnitsPerEm;
073263
+ 
073263
+ 		// Divide the font size by the cell height to get the font em
073263
+ 		// size.
073263
+ 		fontSize /= cellHeight;
073263
+ 	    }
073263
+ 	}
073263
+     }
073263
+ 
073263
+     // The text format includes a locale name. Ideally, this would be the
073263
+     // language of the text, which may or may not be the same as the primary
073263
+     // language of the user. However, for our purposes the user locale will do.
073263
+     wchar_t localeName[LOCALE_NAME_MAX_LENGTH];
073263
+     if (SUCCEEDED(hr))
073263
+     {
073263
+ 	if (GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH) == 0)
073263
+ 	    hr = HRESULT_FROM_WIN32(GetLastError());
073263
+     }
073263
+ 
073263
+     if (SUCCEEDED(hr))
073263
+     {
073263
+ 	// Create the text format object.
073263
+ 	hr = mDWriteFactory->CreateTextFormat(
073263
+ 		familyName,
073263
+ 		NULL, // no custom font collection
073263
+ 		font->GetWeight(),
073263
+ 		font->GetStyle(),
073263
+ 		font->GetStretch(),
073263
+ 		fontSize,
073263
+ 		localeName,
073263
+ 		&mTextFormat);
073263
+     }
073263
+ 
073263
+     if (SUCCEEDED(hr))
073263
+     {
073263
+ 	mFontWeight = static_cast<DWRITE_FONT_WEIGHT>(logFont.lfWeight);
073263
+ 	mFontStyle = logFont.lfItalic ? DWRITE_FONT_STYLE_ITALIC
073263
+ 	    : DWRITE_FONT_STYLE_NORMAL;
073263
+     }
073263
+ 
073263
+     SafeRelease(&localizedFamilyNames);
073263
+     SafeRelease(&fontFamily);
073263
+     SafeRelease(&font);
073263
+ 
073263
+     return hr;
073263
+ }
073263
+ 
073263
+     void
073263
+ DWriteContext::SetFont(HFONT hFont)
073263
+ {
073263
+     if (mLastHFont != hFont)
073263
+     {
073263
+ 	LOGFONTW lf;
073263
+ 	if (GetObjectW(hFont, sizeof(lf), &lf))
073263
+ 	{
073263
+ 	    SetFont(lf);
073263
+ 	    mLastHFont = hFont;
073263
+ 	}
073263
+     }
073263
+ }
073263
+ 
073263
+     void
073263
+ DWriteContext::SetFont(const LOGFONTW &logFont)
073263
+ {
073263
+     SafeRelease(&mTextFormat);
073263
+     mLastHFont = NULL;
073263
+ 
073263
+     HRESULT hr = SetLOGFONT(logFont, 0.f);
073263
+ 
073263
+     if (SUCCEEDED(hr))
073263
+ 	hr = mTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
073263
+ 
073263
+     if (SUCCEEDED(hr))
073263
+ 	hr = mTextFormat->SetParagraphAlignment(
073263
+ 		DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
073263
+ 
073263
+     if (SUCCEEDED(hr))
073263
+ 	hr = mTextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
073263
+ }
073263
+ 
073263
+     void
073263
+ DWriteContext::DrawText(HDC hdc, const WCHAR* text, int len,
073263
+ 	int x, int y, int w, int h, int cellWidth, COLORREF color)
073263
+ {
073263
+     HRESULT hr = S_OK;
073263
+     IDWriteBitmapRenderTarget *bmpRT = NULL;
073263
+ 
073263
+     // Skip when any fonts are not set.
073263
+     if (mTextFormat == NULL)
073263
+ 	return;
073263
+ 
073263
+     // Check possibility of zero divided error.
073263
+     if (cellWidth == 0 || mDpiScaleX == 0.0f || mDpiScaleY == 0.0f)
073263
+ 	return;
073263
+ 
073263
+     if (SUCCEEDED(hr))
073263
+ 	hr = mGdiInterop->CreateBitmapRenderTarget(hdc, w, h, &bmpRT);
073263
+ 
073263
+     if (SUCCEEDED(hr))
073263
+     {
073263
+ 	IDWriteTextLayout *textLayout = NULL;
073263
+ 
073263
+ 	HDC memdc = bmpRT->GetMemoryDC();
073263
+ 	BitBlt(memdc, 0, 0, w, h, hdc, x, y, SRCCOPY);
073263
+ 
073263
+ 	hr = mDWriteFactory->CreateGdiCompatibleTextLayout(
073263
+ 		text, len, mTextFormat, PixelsToDipsX(w),
073263
+ 		PixelsToDipsY(h), mDpiScaleX, NULL, TRUE, &textLayout);
073263
+ 
073263
+ 	if (SUCCEEDED(hr))
073263
+ 	{
073263
+ 	    DWRITE_TEXT_RANGE textRange = { 0, len };
073263
+ 	    textLayout->SetFontWeight(mFontWeight, textRange);
073263
+ 	    textLayout->SetFontStyle(mFontStyle, textRange);
073263
+ 	}
073263
+ 
073263
+ 	if (SUCCEEDED(hr))
073263
+ 	{
073263
+ 	    GdiTextRenderer *renderer = new GdiTextRenderer(bmpRT,
073263
+ 		    mRenderingParams);
073263
+ 	    GdiTextRendererContext data = {
073263
+ 		color,
073263
+ 		PixelsToDipsX(cellWidth),
073263
+ 		0.0f
073263
+ 	    };
073263
+ 	    textLayout->Draw(&data, renderer, 0, 0);
073263
+ 	    SafeRelease(&renderer);
073263
+ 	}
073263
+ 
073263
+ 	BitBlt(hdc, x, y, w, h, memdc, 0, 0, SRCCOPY);
073263
+ 
073263
+ 	SafeRelease(&textLayout);
073263
+     }
073263
+ 
073263
+     SafeRelease(&bmpRT);
073263
+ }
073263
+ 
073263
+     float
073263
+ DWriteContext::PixelsToDipsX(int x)
073263
+ {
073263
+     return x / mDpiScaleX;
073263
+ }
073263
+ 
073263
+     float
073263
+ DWriteContext::PixelsToDipsY(int y)
073263
+ {
073263
+     return y / mDpiScaleY;
073263
+ }
073263
+ 
073263
+     void
073263
+ DWriteContext::SetRenderingParams(
073263
+ 	const DWriteRenderingParams *params)
073263
+ {
073263
+     if (mDWriteFactory == NULL)
073263
+ 	return;
073263
+ 
073263
+     IDWriteRenderingParams *renderingParams = NULL;
073263
+     D2D1_TEXT_ANTIALIAS_MODE textAntialiasMode =
073263
+ 	D2D1_TEXT_ANTIALIAS_MODE_DEFAULT;
073263
+     HRESULT hr;
073263
+     if (params != NULL)
073263
+     {
073263
+ 	hr = mDWriteFactory->CreateCustomRenderingParams(params->gamma,
073263
+ 		params->enhancedContrast, params->clearTypeLevel,
073263
+ 		ToPixelGeometry(params->pixelGeometry),
073263
+ 		ToRenderingMode(params->renderingMode), &renderingParams);
073263
+ 	textAntialiasMode = ToTextAntialiasMode(params->textAntialiasMode);
073263
+     }
073263
+     else
073263
+ 	hr = mDWriteFactory->CreateRenderingParams(&renderingParams);
073263
+     if (SUCCEEDED(hr) && renderingParams != NULL)
073263
+     {
073263
+ 	SafeRelease(&mRenderingParams);
073263
+ 	mRenderingParams = renderingParams;
073263
+ 	mTextAntialiasMode = textAntialiasMode;
073263
+     }
073263
+ }
073263
+ 
073263
+     DWriteRenderingParams *
073263
+ DWriteContext::GetRenderingParams(
073263
+ 	DWriteRenderingParams *params)
073263
+ {
073263
+     if (params != NULL && mRenderingParams != NULL)
073263
+     {
073263
+ 	params->gamma = mRenderingParams->GetGamma();
073263
+ 	params->enhancedContrast = mRenderingParams->GetEnhancedContrast();
073263
+ 	params->clearTypeLevel = mRenderingParams->GetClearTypeLevel();
073263
+ 	params->pixelGeometry = ToInt(mRenderingParams->GetPixelGeometry());
073263
+ 	params->renderingMode = ToInt(mRenderingParams->GetRenderingMode());
073263
+ 	params->textAntialiasMode = mTextAntialiasMode;
073263
+     }
073263
+     return params;
073263
+ }
073263
+ 
073263
+ ////////////////////////////////////////////////////////////////////////////
073263
+ // PUBLIC C INTERFACES
073263
+ 
073263
+     void
073263
+ DWrite_Init(void)
073263
+ {
073263
+ #ifdef DYNAMIC_DIRECTX
073263
+     // Load libraries.
073263
+     hD2D1DLL = vimLoadLib(const_cast<char*>("d2d1.dll"));
073263
+     hDWriteDLL = vimLoadLib(const_cast<char*>("dwrite.dll"));
073263
+     if (hD2D1DLL == NULL || hDWriteDLL == NULL)
073263
+     {
073263
+ 	DWrite_Final();
073263
+ 	return;
073263
+     }
073263
+     // Get address of procedures.
073263
+     pGetUserDefaultLocaleName = (PGETUSERDEFAULTLOCALENAME)GetProcAddress(
073263
+ 	    GetModuleHandle("kernel32.dll"), "GetUserDefaultLocaleName");
073263
+     pD2D1CreateFactory = (PD2D1CREATEFACTORY)GetProcAddress(hD2D1DLL,
073263
+ 	    "D2D1CreateFactory");
073263
+     pDWriteCreateFactory = (PDWRITECREATEFACTORY)GetProcAddress(hDWriteDLL,
073263
+ 	    "DWriteCreateFactory");
073263
+ #endif
073263
+ }
073263
+ 
073263
+     void
073263
+ DWrite_Final(void)
073263
+ {
073263
+ #ifdef DYNAMIC_DIRECTX
073263
+     pGetUserDefaultLocaleName = NULL;
073263
+     pD2D1CreateFactory = NULL;
073263
+     pDWriteCreateFactory = NULL;
073263
+     unload(hDWriteDLL);
073263
+     unload(hD2D1DLL);
073263
+ #endif
073263
+ }
073263
+ 
073263
+     DWriteContext *
073263
+ DWriteContext_Open(void)
073263
+ {
073263
+ #ifdef DYNAMIC_DIRECTX
073263
+     if (pGetUserDefaultLocaleName == NULL || pD2D1CreateFactory == NULL
073263
+ 	    || pDWriteCreateFactory == NULL)
073263
+ 	return NULL;
073263
+ #endif
073263
+     return new DWriteContext();
073263
+ }
073263
+ 
073263
+     void
073263
+ DWriteContext_BeginDraw(DWriteContext *ctx)
073263
+ {
073263
+     if (ctx != NULL && ctx->mRT != NULL)
073263
+     {
073263
+ 	ctx->mRT->BeginDraw();
073263
+ 	ctx->mRT->SetTransform(D2D1::IdentityMatrix());
073263
+ 	ctx->mDrawing = true;
073263
+     }
073263
+ }
073263
+ 
073263
+     void
073263
+ DWriteContext_BindDC(DWriteContext *ctx, HDC hdc, RECT *rect)
073263
+ {
073263
+     if (ctx != NULL && ctx->mRT != NULL)
073263
+     {
073263
+ 	ctx->mRT->BindDC(hdc, rect);
073263
+ 	ctx->mRT->SetTextAntialiasMode(ctx->mTextAntialiasMode);
073263
+     }
073263
+ }
073263
+ 
073263
+     void
073263
+ DWriteContext_SetFont(DWriteContext *ctx, HFONT hFont)
073263
+ {
073263
+     if (ctx != NULL)
073263
+     {
073263
+ 	ctx->SetFont(hFont);
073263
+     }
073263
+ }
073263
+ 
073263
+     void
073263
+ DWriteContext_DrawText(
073263
+ 	DWriteContext *ctx,
073263
+ 	HDC hdc,
073263
+ 	const WCHAR* text,
073263
+ 	int len,
073263
+ 	int x,
073263
+ 	int y,
073263
+ 	int w,
073263
+ 	int h,
073263
+ 	int cellWidth,
073263
+ 	COLORREF color)
073263
+ {
073263
+     if (ctx != NULL)
073263
+ 	ctx->DrawText(hdc, text, len, x, y, w, h, cellWidth, color);
073263
+ }
073263
+ 
073263
+     void
073263
+ DWriteContext_EndDraw(DWriteContext *ctx)
073263
+ {
073263
+     if (ctx != NULL && ctx->mRT != NULL)
073263
+     {
073263
+ 	ctx->mRT->EndDraw();
073263
+ 	ctx->mDrawing = false;
073263
+     }
073263
+ }
073263
+ 
073263
+     void
073263
+ DWriteContext_Close(DWriteContext *ctx)
073263
+ {
073263
+     delete ctx;
073263
+ }
073263
+ 
073263
+     void
073263
+ DWriteContext_SetRenderingParams(
073263
+ 	DWriteContext *ctx,
073263
+ 	const DWriteRenderingParams *params)
073263
+ {
073263
+     if (ctx != NULL)
073263
+ 	ctx->SetRenderingParams(params);
073263
+ }
073263
+ 
073263
+     DWriteRenderingParams *
073263
+ DWriteContext_GetRenderingParams(
073263
+ 	DWriteContext *ctx,
073263
+ 	DWriteRenderingParams *params)
073263
+ {
073263
+     if (ctx != NULL)
073263
+ 	return ctx->GetRenderingParams(params);
073263
+     else
073263
+ 	return NULL;
073263
+ }
073263
*** ../vim-7.4.392/src/gui_dwrite.h	2014-08-06 14:49:19.667237363 +0200
073263
--- src/gui_dwrite.h	2014-08-06 14:21:57.459249166 +0200
073263
***************
073263
*** 0 ****
073263
--- 1,85 ----
073263
+ /* vi:set ts=8 sts=4 sw=4 noet: */
073263
+ /*
073263
+  * Author: MURAOKA Taro <koron.kaoriya@gmail.com>
073263
+  *
073263
+  * Contributors:
073263
+  *  - Ken Takata
073263
+  *
073263
+  * Copyright (C) 2013 MURAOKA Taro <koron.kaoriya@gmail.com>
073263
+  * THIS FILE IS DISTRIBUTED UNDER THE VIM LICENSE.
073263
+  */
073263
+ 
073263
+ #ifndef GUI_DWRITE_H
073263
+ #define GUI_DWRITE_H
073263
+ 
073263
+ #ifdef __cplusplus
073263
+ extern "C" {
073263
+ #endif
073263
+ 
073263
+ typedef struct DWriteContext DWriteContext;
073263
+ 
073263
+ typedef struct DWriteRenderingParams {
073263
+     float gamma;
073263
+     float enhancedContrast;
073263
+     float clearTypeLevel;
073263
+     /*
073263
+      * pixelGeometry:
073263
+      *	0 - DWRITE_PIXEL_GEOMETRY_FLAT
073263
+      *	1 - DWRITE_PIXEL_GEOMETRY_RGB
073263
+      *	2 - DWRITE_PIXEL_GEOMETRY_BGR
073263
+      */
073263
+     int pixelGeometry;
073263
+     /*
073263
+      * renderingMode:
073263
+      *	0 - DWRITE_RENDERING_MODE_DEFAULT
073263
+      *	1 - DWRITE_RENDERING_MODE_ALIASED
073263
+      *	2 - DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC
073263
+      *	3 - DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL
073263
+      *	4 - DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL
073263
+      *	5 - DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC
073263
+      *	6 - DWRITE_RENDERING_MODE_OUTLINE
073263
+      */
073263
+     int renderingMode;
073263
+     /*
073263
+      * antialiasMode:
073263
+      *	0 - D2D1_TEXT_ANTIALIAS_MODE_DEFAULT
073263
+      *	1 - D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE
073263
+      *	2 - D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE
073263
+      *	3 - D2D1_TEXT_ANTIALIAS_MODE_ALIASED
073263
+      */
073263
+     int textAntialiasMode;
073263
+ } DWriteRenderingParams;
073263
+ 
073263
+ void DWrite_Init(void);
073263
+ void DWrite_Final(void);
073263
+ 
073263
+ DWriteContext *DWriteContext_Open(void);
073263
+ void DWriteContext_BeginDraw(DWriteContext *ctx);
073263
+ void DWriteContext_BindDC(DWriteContext *ctx, HDC hdc, RECT *rect);
073263
+ void DWriteContext_SetFont(DWriteContext *ctx, HFONT hFont);
073263
+ void DWriteContext_DrawText(
073263
+ 	DWriteContext *ctx,
073263
+ 	HDC hdc,
073263
+ 	const WCHAR* text,
073263
+ 	int len,
073263
+ 	int x,
073263
+ 	int y,
073263
+ 	int w,
073263
+ 	int h,
073263
+ 	int cellWidth,
073263
+ 	COLORREF color);
073263
+ void DWriteContext_EndDraw(DWriteContext *ctx);
073263
+ void DWriteContext_Close(DWriteContext *ctx);
073263
+ 
073263
+ void DWriteContext_SetRenderingParams(
073263
+ 	DWriteContext *ctx,
073263
+ 	const DWriteRenderingParams *params);
073263
+ 
073263
+ DWriteRenderingParams *DWriteContext_GetRenderingParams(
073263
+ 	DWriteContext *ctx,
073263
+ 	DWriteRenderingParams *params);
073263
+ 
073263
+ #ifdef __cplusplus
073263
+ }
073263
+ #endif
073263
+ #endif/*GUI_DWRITE_H*/
073263
*** ../vim-7.4.392/src/gui_w32.c	2013-08-04 16:15:37.000000000 +0200
073263
--- src/gui_w32.c	2014-08-06 14:45:43.495238916 +0200
073263
***************
073263
*** 25,30 ****
073263
--- 25,169 ----
073263
  
073263
  #include "vim.h"
073263
  
073263
+ #if defined(FEAT_DIRECTX)
073263
+ # include "gui_dwrite.h"
073263
+ #endif
073263
+ 
073263
+ #if defined(FEAT_DIRECTX) || defined(PROTO)
073263
+ static DWriteContext *s_dwc = NULL;
073263
+ static int s_directx_enabled = 0;
073263
+ static int s_directx_load_attempted = 0;
073263
+ # define IS_ENABLE_DIRECTX() (s_directx_enabled && s_dwc != NULL)
073263
+ 
073263
+     int
073263
+ directx_enabled(void)
073263
+ {
073263
+     if (s_dwc != NULL)
073263
+ 	return 1;
073263
+     else if (s_directx_load_attempted)
073263
+ 	return 0;
073263
+     /* load DirectX */
073263
+     DWrite_Init();
073263
+     s_directx_load_attempted = 1;
073263
+     s_dwc = DWriteContext_Open();
073263
+     return s_dwc != NULL ? 1 : 0;
073263
+ }
073263
+ #endif
073263
+ 
073263
+ #if defined(FEAT_RENDER_OPTIONS) || defined(PROTO)
073263
+     int
073263
+ gui_mch_set_rendering_options(char_u *s)
073263
+ {
073263
+ #ifdef FEAT_DIRECTX
073263
+     int	    retval = FAIL;
073263
+     char_u  *p, *q;
073263
+ 
073263
+     int	    dx_enable = 0;
073263
+     int	    dx_flags = 0;
073263
+     float   dx_gamma = 0.0f;
073263
+     float   dx_contrast = 0.0f;
073263
+     float   dx_level = 0.0f;
073263
+     int	    dx_geom = 0;
073263
+     int	    dx_renmode = 0;
073263
+     int	    dx_taamode = 0;
073263
+ 
073263
+     /* parse string as rendering options. */
073263
+     for (p = s; p != NULL && *p != NUL; )
073263
+     {
073263
+ 	char_u  item[256];
073263
+ 	char_u  name[128];
073263
+ 	char_u  value[128];
073263
+ 
073263
+ 	copy_option_part(&p, item, sizeof(item), ","); 
073263
+ 	if (p == NULL)
073263
+ 	    break;
073263
+ 	q = &item[0];
073263
+ 	copy_option_part(&q, name, sizeof(name), ":");
073263
+ 	if (q == NULL)
073263
+ 	    return FAIL;
073263
+ 	copy_option_part(&q, value, sizeof(value), ":");
073263
+ 
073263
+ 	if (STRCMP(name, "type") == 0)
073263
+ 	{
073263
+ 	    if (STRCMP(value, "directx") == 0)
073263
+ 		dx_enable = 1;
073263
+ 	    else
073263
+ 		return FAIL;
073263
+ 	}
073263
+ 	else if (STRCMP(name, "gamma") == 0)
073263
+ 	{
073263
+ 	    dx_flags |= 1 << 0;
073263
+ 	    dx_gamma = (float)atof(value);
073263
+ 	}
073263
+ 	else if (STRCMP(name, "contrast") == 0)
073263
+ 	{
073263
+ 	    dx_flags |= 1 << 1;
073263
+ 	    dx_contrast = (float)atof(value);
073263
+ 	}
073263
+ 	else if (STRCMP(name, "level") == 0)
073263
+ 	{
073263
+ 	    dx_flags |= 1 << 2;
073263
+ 	    dx_level = (float)atof(value);
073263
+ 	}
073263
+ 	else if (STRCMP(name, "geom") == 0)
073263
+ 	{
073263
+ 	    dx_flags |= 1 << 3;
073263
+ 	    dx_geom = atoi(value);
073263
+ 	    if (dx_geom < 0 || dx_geom > 2)
073263
+ 		return FAIL;
073263
+ 	}
073263
+ 	else if (STRCMP(name, "renmode") == 0)
073263
+ 	{
073263
+ 	    dx_flags |= 1 << 4;
073263
+ 	    dx_renmode = atoi(value);
073263
+ 	    if (dx_renmode < 0 || dx_renmode > 6)
073263
+ 		return FAIL;
073263
+ 	}
073263
+ 	else if (STRCMP(name, "taamode") == 0)
073263
+ 	{
073263
+ 	    dx_flags |= 1 << 5;
073263
+ 	    dx_taamode = atoi(value);
073263
+ 	    if (dx_taamode < 0 || dx_taamode > 3)
073263
+ 		return FAIL;
073263
+ 	}
073263
+ 	else
073263
+ 	    return FAIL;
073263
+     }
073263
+ 
073263
+     /* Enable DirectX/DirectWrite */
073263
+     if (dx_enable)
073263
+     {
073263
+ 	if (!directx_enabled())
073263
+ 	    return FAIL;
073263
+ 	DWriteContext_SetRenderingParams(s_dwc, NULL);
073263
+ 	if (dx_flags)
073263
+ 	{
073263
+ 	    DWriteRenderingParams param;
073263
+ 	    DWriteContext_GetRenderingParams(s_dwc, ¶m;;
073263
+ 	    if (dx_flags & (1 << 0))
073263
+ 		param.gamma = dx_gamma;
073263
+ 	    if (dx_flags & (1 << 1))
073263
+ 		param.enhancedContrast = dx_contrast;
073263
+ 	    if (dx_flags & (1 << 2))
073263
+ 		param.clearTypeLevel = dx_level;
073263
+ 	    if (dx_flags & (1 << 3))
073263
+ 		param.pixelGeometry = dx_geom;
073263
+ 	    if (dx_flags & (1 << 4))
073263
+ 		param.renderingMode = dx_renmode;
073263
+ 	    if (dx_flags & (1 << 5))
073263
+ 		param.textAntialiasMode = dx_taamode;
073263
+ 	    DWriteContext_SetRenderingParams(s_dwc, ¶m;;
073263
+ 	}
073263
+     }
073263
+     s_directx_enabled = dx_enable;
073263
+ 
073263
+     return OK;
073263
+ #else
073263
+     return FAIL;
073263
+ #endif
073263
+ }
073263
+ #endif
073263
+ 
073263
  /*
073263
   * These are new in Windows ME/XP, only defined in recent compilers.
073263
   */
073263
***************
073263
*** 1624,1629 ****
073263
--- 1763,1773 ----
073263
      set_vim_var_nr(VV_WINDOWID, HandleToLong(s_hwnd));
073263
  #endif
073263
  
073263
+ #ifdef FEAT_RENDER_OPTIONS
073263
+     if (p_rop)
073263
+ 	(void)gui_mch_set_rendering_options(p_rop);
073263
+ #endif
073263
+ 
073263
  theend:
073263
      /* Display any pending error messages */
073263
      display_errors();
073263
***************
073263
*** 1695,1703 ****
073263
  
073263
      /* compute the size of the outside of the window */
073263
      win_width = width + (GetSystemMetrics(SM_CXFRAME) +
073263
!                          GetSystemMetrics(SM_CXPADDEDBORDER)) * 2;
073263
      win_height = height + (GetSystemMetrics(SM_CYFRAME) +
073263
!                            GetSystemMetrics(SM_CXPADDEDBORDER)) * 2
073263
  			+ GetSystemMetrics(SM_CYCAPTION)
073263
  #ifdef FEAT_MENU
073263
  			+ gui_mswin_get_menu_height(FALSE)
073263
--- 1839,1847 ----
073263
  
073263
      /* compute the size of the outside of the window */
073263
      win_width = width + (GetSystemMetrics(SM_CXFRAME) +
073263
! 			 GetSystemMetrics(SM_CXPADDEDBORDER)) * 2;
073263
      win_height = height + (GetSystemMetrics(SM_CYFRAME) +
073263
! 			   GetSystemMetrics(SM_CXPADDEDBORDER)) * 2
073263
  			+ GetSystemMetrics(SM_CYCAPTION)
073263
  #ifdef FEAT_MENU
073263
  			+ gui_mswin_get_menu_height(FALSE)
073263
***************
073263
*** 2239,2244 ****
073263
--- 2383,2391 ----
073263
  #endif
073263
      HPEN	hpen, old_pen;
073263
      int		y;
073263
+ #ifdef FEAT_DIRECTX
073263
+     int		font_is_ttf_or_vector = 0;
073263
+ #endif
073263
  
073263
  #ifndef MSWIN16_FASTTEXT
073263
      /*
073263
***************
073263
*** 2326,2331 ****
073263
--- 2473,2492 ----
073263
      SetTextColor(s_hdc, gui.currFgColor);
073263
      SelectFont(s_hdc, gui.currFont);
073263
  
073263
+ #ifdef FEAT_DIRECTX
073263
+     if (IS_ENABLE_DIRECTX())
073263
+     {
073263
+ 	TEXTMETRIC tm;
073263
+ 
073263
+ 	GetTextMetrics(s_hdc, &tm;;
073263
+ 	if (tm.tmPitchAndFamily & (TMPF_TRUETYPE | TMPF_VECTOR))
073263
+ 	{
073263
+ 	    font_is_ttf_or_vector = 1;
073263
+ 	    DWriteContext_SetFont(s_dwc, (HFONT)gui.currFont);
073263
+ 	}
073263
+     }
073263
+ #endif
073263
+ 
073263
      if (pad_size != Columns || padding == NULL || padding[0] != gui.char_width)
073263
      {
073263
  	vim_free(padding);
073263
***************
073263
*** 2360,2365 ****
073263
--- 2521,2534 ----
073263
  	    if (text[n] >= 0x80)
073263
  		break;
073263
  
073263
+ #if defined(FEAT_DIRECTX)
073263
+     /* Quick hack to enable DirectWrite.  To use DirectWrite (antialias), it is
073263
+      * required that unicode drawing routine, currently.  So this forces it
073263
+      * enabled. */
073263
+     if (enc_utf8 && IS_ENABLE_DIRECTX())
073263
+ 	n = 0; /* Keep n < len, to enter block for unicode. */
073263
+ #endif
073263
+ 
073263
      /* Check if the Unicode buffer exists and is big enough.  Create it
073263
       * with the same length as the multi-byte string, the number of wide
073263
       * characters is always equal or smaller. */
073263
***************
073263
*** 2418,2425 ****
073263
  	    i += utfc_ptr2len_len(text + i, len - i);
073263
  	    ++clen;
073263
  	}
073263
! 	ExtTextOutW(s_hdc, TEXT_X(col), TEXT_Y(row),
073263
! 			   foptions, pcliprect, unicodebuf, wlen, unicodepdy);
073263
  	len = cells;	/* used for underlining */
073263
      }
073263
      else if ((enc_codepage > 0 && (int)GetACP() != enc_codepage) || enc_latin9)
073263
--- 2587,2603 ----
073263
  	    i += utfc_ptr2len_len(text + i, len - i);
073263
  	    ++clen;
073263
  	}
073263
! #if defined(FEAT_DIRECTX)
073263
! 	if (IS_ENABLE_DIRECTX() && font_is_ttf_or_vector)
073263
! 	{
073263
! 	    DWriteContext_DrawText(s_dwc, s_hdc, unicodebuf, wlen,
073263
! 		    TEXT_X(col), TEXT_Y(row), FILL_X(cells), FILL_Y(1),
073263
! 		    gui.char_width, gui.currFgColor);
073263
! 	}
073263
! 	else
073263
! #endif
073263
! 	    ExtTextOutW(s_hdc, TEXT_X(col), TEXT_Y(row),
073263
! 		    foptions, pcliprect, unicodebuf, wlen, unicodepdy);
073263
  	len = cells;	/* used for underlining */
073263
      }
073263
      else if ((enc_codepage > 0 && (int)GetACP() != enc_codepage) || enc_latin9)
073263
***************
073263
*** 2549,2562 ****
073263
  
073263
      *screen_w = workarea_rect.right - workarea_rect.left
073263
  		- (GetSystemMetrics(SM_CXFRAME) +
073263
!                    GetSystemMetrics(SM_CXPADDEDBORDER)) * 2;
073263
  
073263
      /* FIXME: dirty trick: Because the gui_get_base_height() doesn't include
073263
       * the menubar for MSwin, we subtract it from the screen height, so that
073263
       * the window size can be made to fit on the screen. */
073263
      *screen_h = workarea_rect.bottom - workarea_rect.top
073263
  		- (GetSystemMetrics(SM_CYFRAME) +
073263
!                    GetSystemMetrics(SM_CXPADDEDBORDER)) * 2
073263
  		- GetSystemMetrics(SM_CYCAPTION)
073263
  #ifdef FEAT_MENU
073263
  		- gui_mswin_get_menu_height(FALSE)
073263
--- 2727,2740 ----
073263
  
073263
      *screen_w = workarea_rect.right - workarea_rect.left
073263
  		- (GetSystemMetrics(SM_CXFRAME) +
073263
! 		   GetSystemMetrics(SM_CXPADDEDBORDER)) * 2;
073263
  
073263
      /* FIXME: dirty trick: Because the gui_get_base_height() doesn't include
073263
       * the menubar for MSwin, we subtract it from the screen height, so that
073263
       * the window size can be made to fit on the screen. */
073263
      *screen_h = workarea_rect.bottom - workarea_rect.top
073263
  		- (GetSystemMetrics(SM_CYFRAME) +
073263
! 		   GetSystemMetrics(SM_CXPADDEDBORDER)) * 2
073263
  		- GetSystemMetrics(SM_CYCAPTION)
073263
  #ifdef FEAT_MENU
073263
  		- gui_mswin_get_menu_height(FALSE)
073263
***************
073263
*** 3188,3200 ****
073263
  	GetWindowRect(s_hwnd, &rect);
073263
  	maxDialogWidth = rect.right - rect.left
073263
  				   - (GetSystemMetrics(SM_CXFRAME) +
073263
!                                       GetSystemMetrics(SM_CXPADDEDBORDER)) * 2;
073263
  	if (maxDialogWidth < DLG_MIN_MAX_WIDTH)
073263
  	    maxDialogWidth = DLG_MIN_MAX_WIDTH;
073263
  
073263
  	maxDialogHeight = rect.bottom - rect.top
073263
  				   - (GetSystemMetrics(SM_CYFRAME) +
073263
!                                       GetSystemMetrics(SM_CXPADDEDBORDER)) * 4
073263
  				   - GetSystemMetrics(SM_CYCAPTION);
073263
  	if (maxDialogHeight < DLG_MIN_MAX_HEIGHT)
073263
  	    maxDialogHeight = DLG_MIN_MAX_HEIGHT;
073263
--- 3366,3378 ----
073263
  	GetWindowRect(s_hwnd, &rect);
073263
  	maxDialogWidth = rect.right - rect.left
073263
  				   - (GetSystemMetrics(SM_CXFRAME) +
073263
! 				      GetSystemMetrics(SM_CXPADDEDBORDER)) * 2;
073263
  	if (maxDialogWidth < DLG_MIN_MAX_WIDTH)
073263
  	    maxDialogWidth = DLG_MIN_MAX_WIDTH;
073263
  
073263
  	maxDialogHeight = rect.bottom - rect.top
073263
  				   - (GetSystemMetrics(SM_CYFRAME) +
073263
! 				      GetSystemMetrics(SM_CXPADDEDBORDER)) * 4
073263
  				   - GetSystemMetrics(SM_CYCAPTION);
073263
  	if (maxDialogHeight < DLG_MIN_MAX_HEIGHT)
073263
  	    maxDialogHeight = DLG_MIN_MAX_HEIGHT;
073263
***************
073263
*** 3351,3361 ****
073263
      /* Restrict the size to a maximum.  Causes a scrollbar to show up. */
073263
      if (dlgheight > maxDialogHeight)
073263
      {
073263
!         msgheight = msgheight - (dlgheight - maxDialogHeight);
073263
!         dlgheight = maxDialogHeight;
073263
!         scroll_flag = WS_VSCROLL;
073263
!         /* Make sure scrollbar doesn't appear in the middle of the dialog */
073263
!         messageWidth = dlgwidth - DLG_ICON_WIDTH - 3 * dlgPaddingX;
073263
      }
073263
  
073263
      add_word(PixelToDialogY(dlgheight));
073263
--- 3529,3539 ----
073263
      /* Restrict the size to a maximum.  Causes a scrollbar to show up. */
073263
      if (dlgheight > maxDialogHeight)
073263
      {
073263
! 	msgheight = msgheight - (dlgheight - maxDialogHeight);
073263
! 	dlgheight = maxDialogHeight;
073263
! 	scroll_flag = WS_VSCROLL;
073263
! 	/* Make sure scrollbar doesn't appear in the middle of the dialog */
073263
! 	messageWidth = dlgwidth - DLG_ICON_WIDTH - 3 * dlgPaddingX;
073263
      }
073263
  
073263
      add_word(PixelToDialogY(dlgheight));
073263
*** ../vim-7.4.392/src/gui_w48.c	2014-03-23 15:12:29.923264336 +0100
073263
--- src/gui_w48.c	2014-08-06 14:21:57.463249166 +0200
073263
***************
073263
*** 2785,2790 ****
073263
--- 2785,2794 ----
073263
  
073263
  	out_flush();	    /* make sure all output has been processed */
073263
  	(void)BeginPaint(hwnd, &ps);
073263
+ #if defined(FEAT_DIRECTX)
073263
+ 	if (IS_ENABLE_DIRECTX())
073263
+ 	    DWriteContext_BeginDraw(s_dwc);
073263
+ #endif
073263
  
073263
  #ifdef FEAT_MBYTE
073263
  	/* prevent multi-byte characters from misprinting on an invalid
073263
***************
073263
*** 2800,2808 ****
073263
--- 2804,2823 ----
073263
  #endif
073263
  
073263
  	if (!IsRectEmpty(&ps.rcPaint))
073263
+ 	{
073263
+ #if defined(FEAT_DIRECTX)
073263
+ 	    if (IS_ENABLE_DIRECTX())
073263
+ 		DWriteContext_BindDC(s_dwc, s_hdc, &ps.rcPaint);
073263
+ #endif
073263
  	    gui_redraw(ps.rcPaint.left, ps.rcPaint.top,
073263
  		    ps.rcPaint.right - ps.rcPaint.left + 1,
073263
  		    ps.rcPaint.bottom - ps.rcPaint.top + 1);
073263
+ 	}
073263
+ 
073263
+ #if defined(FEAT_DIRECTX)
073263
+ 	if (IS_ENABLE_DIRECTX())
073263
+ 	    DWriteContext_EndDraw(s_dwc);
073263
+ #endif
073263
  	EndPaint(hwnd, &ps);
073263
      }
073263
  }
073263
***************
073263
*** 3043,3048 ****
073263
--- 3058,3069 ----
073263
      void
073263
  gui_mch_exit(int rc)
073263
  {
073263
+ #if defined(FEAT_DIRECTX)
073263
+     DWriteContext_Close(s_dwc);
073263
+     DWrite_Final();
073263
+     s_dwc = NULL;
073263
+ #endif
073263
+ 
073263
      ReleaseDC(s_textArea, s_hdc);
073263
      DeleteObject(s_brush);
073263
  
073263
*** ../vim-7.4.392/src/option.c	2014-06-25 14:44:04.458358774 +0200
073263
--- src/option.c	2014-08-06 14:33:24.503244228 +0200
073263
***************
073263
*** 2124,2129 ****
073263
--- 2124,2138 ----
073263
      {"remap",	    NULL,   P_BOOL|P_VI_DEF,
073263
  			    (char_u *)&p_remap, PV_NONE,
073263
  			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
073263
+     {"renderoptions", "rop", P_STRING|P_COMMA|P_RCLR|P_VI_DEF,
073263
+ #ifdef FEAT_RENDER_OPTIONS
073263
+ 			    (char_u *)&p_rop, PV_NONE,
073263
+ 			    {(char_u *)"", (char_u *)0L}
073263
+ #else
073263
+ 			    (char_u *)NULL, PV_NONE,
073263
+ 			    {(char_u *)NULL, (char_u *)0L}
073263
+ #endif
073263
+ 			    SCRIPTID_INIT},
073263
      {"report",	    NULL,   P_NUM|P_VI_DEF,
073263
  			    (char_u *)&p_report, PV_NONE,
073263
  			    {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
073263
***************
073263
*** 6999,7004 ****
073263
--- 7008,7021 ----
073263
      }
073263
  #endif
073263
  
073263
+ #if defined(FEAT_RENDER_OPTIONS)
073263
+     else if (varp == &p_rop && gui.in_use)
073263
+     {
073263
+ 	if (!gui_mch_set_rendering_options(p_rop))
073263
+ 	    errmsg = e_invarg;
073263
+     }
073263
+ #endif
073263
+ 
073263
      /* Options that are a list of flags. */
073263
      else
073263
      {
073263
*** ../vim-7.4.392/src/option.h	2014-06-25 14:39:35.110348584 +0200
073263
--- src/option.h	2014-08-06 14:23:25.419248534 +0200
073263
***************
073263
*** 655,660 ****
073263
--- 655,663 ----
073263
  #endif
073263
  EXTERN int	p_remap;	/* 'remap' */
073263
  EXTERN long	p_re;		/* 'regexpengine' */
073263
+ #ifdef FEAT_RENDER_OPTIONS
073263
+ EXTERN char_u	*p_rop;		/* 'renderoptions' */
073263
+ #endif
073263
  EXTERN long	p_report;	/* 'report' */
073263
  #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
073263
  EXTERN long	p_pvh;		/* 'previewheight' */
073263
*** ../vim-7.4.392/src/version.c	2014-08-06 13:36:56.091268582 +0200
073263
--- src/version.c	2014-08-06 14:29:39.183245847 +0200
073263
***************
073263
*** 189,194 ****
073263
--- 189,201 ----
073263
  #else
073263
  	"-digraphs",
073263
  #endif
073263
+ #ifdef FEAT_GUI_W32
073263
+ # ifdef FEAT_DIRECTX
073263
+ 	"+directx",
073263
+ # else
073263
+ 	"-directx",
073263
+ # endif
073263
+ #endif
073263
  #ifdef FEAT_DND
073263
  	"+dnd",
073263
  #else
073263
*** ../vim-7.4.392/src/vim.h	2014-04-02 19:54:58.275599459 +0200
073263
--- src/vim.h	2014-08-06 14:21:57.467249166 +0200
073263
***************
073263
*** 134,139 ****
073263
--- 134,146 ----
073263
  # endif
073263
  #endif
073263
  
073263
+ /* Check support for rendering options */
073263
+ #ifdef FEAT_GUI
073263
+ # if defined(FEAT_DIRECTX)
073263
+ #  define FEAT_RENDER_OPTIONS
073263
+ # endif
073263
+ #endif
073263
+ 
073263
  /* Visual Studio 2005 has 'deprecated' many of the standard CRT functions */
073263
  #if _MSC_VER >= 1400
073263
  # define _CRT_SECURE_NO_DEPRECATE
073263
*** ../vim-7.4.392/src/proto/gui_w32.pro	2013-08-10 13:37:36.000000000 +0200
073263
--- src/proto/gui_w32.pro	2014-08-06 14:33:04.155244374 +0200
073263
***************
073263
*** 1,4 ****
073263
--- 1,6 ----
073263
  /* gui_w32.c */
073263
+ int directx_enabled __ARGS((void));
073263
+ int gui_mch_set_rendering_options __ARGS((char_u *s));
073263
  void gui_mch_set_blinking __ARGS((long wait, long on, long off));
073263
  void gui_mch_stop_blink __ARGS((void));
073263
  void gui_mch_start_blink __ARGS((void));
073263
*** ../vim-7.4.392/src/version.c	2014-08-06 13:36:56.091268582 +0200
073263
--- src/version.c	2014-08-06 14:29:39.183245847 +0200
073263
***************
073263
*** 736,737 ****
073263
--- 743,746 ----
073263
  {   /* Add new patch number below this line */
073263
+ /**/
073263
+     393,
073263
  /**/
073263
073263
-- 
073263
A consultant is a person who takes your money and annoys your employees while
073263
tirelessly searching for the best way to extend the consulting contract.
073263
				(Scott Adams - The Dilbert principle)
073263
073263
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
073263
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
073263
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
073263
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///