Blame SOURCES/7.4.393

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