diff options
| -rw-r--r-- | win32/PlatWin.cxx | 45 | ||||
| -rw-r--r-- | win32/PlatWin.h | 3 | ||||
| -rw-r--r-- | win32/ScintillaWin.cxx | 30 | 
3 files changed, 74 insertions, 4 deletions
| diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 3317dc0d3..a2654ff78 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -26,8 +26,15 @@  #include <commctrl.h>  #include <richedit.h>  #include <windowsx.h> + +#if defined(_MSC_VER) +#define USE_D2D 1 +#endif + +#if defined(USE_D2D)  #include <d2d1.h>  #include <dwrite.h> +#endif  #include "Platform.h"  #include "UniConversion.h" @@ -197,6 +204,7 @@ void Palette::Allocate(Window &) {  	}  } +#if defined(USE_D2D)  IDWriteFactory *pIDWriteFactory = 0;  ID2D1Factory *pD2DFactory = 0; @@ -234,26 +242,37 @@ bool LoadD2D() {  	triedLoadingD2D = true;  	return pIDWriteFactory && pD2DFactory;  } +#endif  struct FormatAndMetrics {  	int technology;  	HFONT hfont; +#if defined(USE_D2D)  	IDWriteTextFormat *pTextFormat; +#endif  	int extraFontFlag;  	FLOAT yAscent;  	FLOAT yDescent;  	FormatAndMetrics(HFONT hfont_, int extraFontFlag_) :  -		technology(SCWIN_TECH_GDI), hfont(hfont_), pTextFormat(0), extraFontFlag(extraFontFlag_), yAscent(2), yDescent(1) { +		technology(SCWIN_TECH_GDI), hfont(hfont_),  +#if defined(USE_D2D) +		pTextFormat(0), +#endif +		extraFontFlag(extraFontFlag_), yAscent(2), yDescent(1) {  	} +#if defined(USE_D2D)  	FormatAndMetrics(IDWriteTextFormat *pTextFormat_, int extraFontFlag_, FLOAT yAscent_, FLOAT yDescent_) :   		technology(SCWIN_TECH_DIRECTWRITE), hfont(0), pTextFormat(pTextFormat_), extraFontFlag(extraFontFlag_), yAscent(yAscent_), yDescent(yDescent_) {  	} +#endif  	~FormatAndMetrics() {  		if (hfont)  			::DeleteObject(hfont); +#if defined(USE_D2D)  		if (pTextFormat) -		pTextFormat->Release(); +			pTextFormat->Release();  		pTextFormat = 0; +#endif  		extraFontFlag = 0;  		yAscent = 2;  		yDescent = 1; @@ -262,6 +281,7 @@ struct FormatAndMetrics {  };  HFONT FormatAndMetrics::HFont() { +#if defined(USE_D2D)  	if (technology == SCWIN_TECH_GDI) {  		return hfont;  	} else { @@ -277,6 +297,9 @@ HFONT FormatAndMetrics::HFont() {  		}  	}  	return 0; +#else +	return hfont; +#endif  }  #ifndef CLEARTYPE_QUALITY @@ -300,6 +323,7 @@ static BYTE Win32MapFontQuality(int extraFontFlag) {  	}  } +#if defined(USE_D2D)  static D2D1_TEXT_ANTIALIAS_MODE DWriteMapFontQuality(int extraFontFlag) {  	switch (extraFontFlag & SC_EFF_QUALITY_MASK) { @@ -316,6 +340,7 @@ static D2D1_TEXT_ANTIALIAS_MODE DWriteMapFontQuality(int extraFontFlag) {  			return D2D1_TEXT_ANTIALIAS_MODE_DEFAULT;  	}  } +#endif  static void SetLogFont(LOGFONTA &lf, const char *faceName, int characterSet, float size, int weight, bool italic, int extraFontFlag) {  	memset(&lf, 0, sizeof(lf)); @@ -374,10 +399,11 @@ FontCached::FontCached(const FontParameters &fp) :  		HFONT hfont = ::CreateFontIndirectA(&lf);  		fid = reinterpret_cast<void *>(new FormatAndMetrics(hfont, fp.extraFontFlag));  	} else { +#if defined(USE_D2D)  		IDWriteTextFormat *pTextFormat;  		const int faceSize = 200;  		WCHAR wszFace[faceSize]; -		UTF16FromUTF8(fp.faceName, strlen(fp.faceName)+1, wszFace, faceSize); +		UTF16FromUTF8(fp.faceName, static_cast<unsigned int>(strlen(fp.faceName))+1, wszFace, faceSize);  		FLOAT fHeight = fp.size;  		DWRITE_FONT_STYLE style = fp.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL;  		HRESULT hr = pIDWriteFactory->CreateTextFormat(wszFace, NULL, @@ -405,6 +431,7 @@ FontCached::FontCached(const FontParameters &fp) :  			}  			fid = reinterpret_cast<void *>(new FormatAndMetrics(pTextFormat, fp.extraFontFlag, yAscent, yDescent));  		} +#endif  	}  	usage = 1;  } @@ -1190,6 +1217,8 @@ void SurfaceGDI::SetDBCSMode(int codePage_) {  namespace Scintilla {  #endif +#if defined(USE_D2D) +  class SurfaceD2D : public Surface {  	bool unicodeMode;  	int x, y; @@ -1825,7 +1854,8 @@ XYPOSITION SurfaceD2D::AverageCharWidth(Font &font_) {  		// Create a layout  		IDWriteTextLayout *pTextLayout = 0;  		const WCHAR wszAllAlpha[] = L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; -		HRESULT hr = pIDWriteFactory->CreateTextLayout(wszAllAlpha, wcslen(wszAllAlpha), pTextFormat, 1000.0, 1000.0, &pTextLayout); +		HRESULT hr = pIDWriteFactory->CreateTextLayout(wszAllAlpha, static_cast<UINT32>(wcslen(wszAllAlpha)),  +			pTextFormat, 1000.0, 1000.0, &pTextLayout);  		if (SUCCEEDED(hr)) {  			DWRITE_TEXT_METRICS textMetrics;  			pTextLayout->GetMetrics(&textMetrics); @@ -1859,12 +1889,17 @@ void SurfaceD2D::SetDBCSMode(int codePage_) {  	// No action on window as automatically handled by system.  	codePage = codePage_;  } +#endif  Surface *Surface::Allocate(int technology) { +#if defined(USE_D2D)  	if (technology == SCWIN_TECH_GDI)  		return new SurfaceGDI;  	else  		return new SurfaceD2D; +#else +	return new SurfaceGDI; +#endif  }  Window::~Window() { @@ -2475,6 +2510,7 @@ void ListBoxX::Draw(DRAWITEMSTRUCT *pDrawItem) {  					delete surfaceItem;  					::SetTextAlign(pDrawItem->hDC, TA_TOP);  				} else { +#if defined(USE_D2D)  					D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties(  						D2D1_RENDER_TARGET_TYPE_DEFAULT,  						D2D1::PixelFormat( @@ -2502,6 +2538,7 @@ void ListBoxX::Draw(DRAWITEMSTRUCT *pDrawItem) {  						pDCRT->EndDraw();  						pDCRT->Release();  					} +#endif  				}  			}  		} diff --git a/win32/PlatWin.h b/win32/PlatWin.h index dc3f8e432..38068ad02 100644 --- a/win32/PlatWin.h +++ b/win32/PlatWin.h @@ -8,6 +8,9 @@  extern bool IsNT();  extern void Platform_Initialise(void *hInstance);  extern void Platform_Finalise(); + +#if defined(_MSC_VER)  extern bool LoadD2D();  extern ID2D1Factory *pD2DFactory;  extern IDWriteFactory *pIDWriteFactory; +#endif diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index a3c141aff..75993b8ed 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -24,8 +24,14 @@  #include <richedit.h>  #include <windowsx.h> +#if defined(_MSC_VER) +#define USE_D2D 1 +#endif + +#if defined(USE_D2D)  #include <d2d1.h>  #include <dwrite.h> +#endif  #include "Platform.h" @@ -196,7 +202,9 @@ class ScintillaWin :  	static HINSTANCE hInstance; +#if defined(USE_D2D)  	ID2D1HwndRenderTarget *pRenderTarget; +#endif  	ScintillaWin(HWND hwnd);  	ScintillaWin(const ScintillaWin &); @@ -353,7 +361,9 @@ ScintillaWin::ScintillaWin(HWND hwnd) {  	sysCaretWidth = 0;  	sysCaretHeight = 0; +#if defined(USE_D2D)  	pRenderTarget = 0; +#endif  	keysAlwaysUnicode = false; @@ -397,6 +407,7 @@ void ScintillaWin::Finalise() {  }  void ScintillaWin::EnsureRenderTarget() { +#if defined(USE_D2D)  	if (pD2DFactory && !pRenderTarget) {  		RECT rc;  		HWND hw = MainHWND(); @@ -420,13 +431,16 @@ void ScintillaWin::EnsureRenderTarget() {  			&pRenderTarget);  #endif  	} +#endif  }  void ScintillaWin::DropRenderTarget() { +#if defined(USE_D2D)  	if (pRenderTarget) {  		pRenderTarget->Release();  		pRenderTarget = 0;  	} +#endif  }  HWND ScintillaWin::MainHWND() { @@ -554,6 +568,7 @@ LRESULT ScintillaWin::WndPaint(uptr_t wParam) {  			surfaceWindow->Release();  		}  	} else { +#if defined(USE_D2D)  		EnsureRenderTarget();  		AutoSurface surfaceWindow(pRenderTarget, this);  		if (surfaceWindow) { @@ -573,6 +588,7 @@ LRESULT ScintillaWin::WndPaint(uptr_t wParam) {  				DropRenderTarget();  			}  		} +#endif  	}  	if (hRgnUpdate) {  		::DeleteRgn(hRgnUpdate); @@ -1147,9 +1163,13 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam  			if ((wParam == SC_TECHNOLOGY_DEFAULT) || (wParam == SC_TECHNOLOGY_DIRECTWRITE)) {  				if (technology != static_cast<int>(wParam)) {  					if (static_cast<int>(wParam) == SC_TECHNOLOGY_DIRECTWRITE) { +#if defined(USE_D2D)  						if (!LoadD2D())  							// Failed to load Direct2D or DirectWrite so no effect  							return 0; +#else +						return 0; +#endif  					}  					technology = wParam;  					// Invalidate all cached information including layout. @@ -2411,6 +2431,7 @@ void ScintillaWin::FullPaintDC(HDC hdc) {  			surfaceWindow->Release();  		}  	} else { +#if defined(USE_D2D)  		EnsureRenderTarget();  		AutoSurface surfaceWindow(pRenderTarget, this);  		if (surfaceWindow) { @@ -2422,6 +2443,7 @@ void ScintillaWin::FullPaintDC(HDC hdc) {  				DropRenderTarget();  			}  		} +#endif  	}  	paintState = notPainting;  } @@ -2795,29 +2817,37 @@ sptr_t PASCAL ScintillaWin::CTWndProc(  				::BeginPaint(hWnd, &ps);  				Surface *surfaceWindow = Surface::Allocate(sciThis->technology);  				if (surfaceWindow) { +#if defined(USE_D2D)  					ID2D1HwndRenderTarget *pCTRenderTarget = 0; +#endif  					RECT rc;  					GetClientRect(hWnd, &rc);  					// Create a Direct2D render target.  					if (sciThis->technology == SC_TECHNOLOGY_DEFAULT) {  						surfaceWindow->Init(ps.hdc, hWnd);  					} else { +#if defined(USE_D2D)  						pD2DFactory->CreateHwndRenderTarget(  							D2D1::RenderTargetProperties(),  							D2D1::HwndRenderTargetProperties(hWnd, D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top)),  							&pCTRenderTarget);  						surfaceWindow->Init(pCTRenderTarget, hWnd);  						pCTRenderTarget->BeginDraw(); +#endif  					}  					surfaceWindow->SetUnicodeMode(SC_CP_UTF8 == sciThis->ct.codePage);  					surfaceWindow->SetDBCSMode(sciThis->ct.codePage);  					sciThis->ct.PaintCT(surfaceWindow); +#if defined(USE_D2D)  					if (pCTRenderTarget)  						pCTRenderTarget->EndDraw(); +#endif  					surfaceWindow->Release();  					delete surfaceWindow; +#if defined(USE_D2D)  					if (pCTRenderTarget)  						pCTRenderTarget->Release(); +#endif  				}  				::EndPaint(hWnd, &ps);  				return 0; | 
