diff options
| -rw-r--r-- | src/FontQuality.h | 2 | ||||
| -rw-r--r-- | win32/PlatWin.cxx | 37 | ||||
| -rw-r--r-- | win32/ScintillaWin.cxx | 42 | 
3 files changed, 50 insertions, 31 deletions
| diff --git a/src/FontQuality.h b/src/FontQuality.h index dc6f28b4c..45600c35e 100644 --- a/src/FontQuality.h +++ b/src/FontQuality.h @@ -12,4 +12,4 @@  #define SC_EFF_QUALITY_LCD_OPTIMIZED     3  #define SCWIN_TECH_GDI 0 -#define SCWIN_TECH_DIRECTWRITE 0 +#define SCWIN_TECH_DIRECTWRITE 1 diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 54b455111..2849144e1 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -236,16 +236,17 @@ bool LoadD2D() {  }  struct FormatAndMetrics { +	int technology;  	HFONT hfont;  	IDWriteTextFormat *pTextFormat;  	int extraFontFlag;  	FLOAT yAscent;  	FLOAT yDescent; -	FormatAndMetrics(IDWriteTextFormat *pTextFormat_, int extraFontFlag_, FLOAT yAscent_, FLOAT yDescent_) :  -		hfont(0), pTextFormat(pTextFormat_), extraFontFlag(extraFontFlag_), yAscent(yAscent_), yDescent(yDescent_) { -	}  	FormatAndMetrics(HFONT hfont_, int extraFontFlag_) :  -		hfont(hfont_), pTextFormat(0), extraFontFlag(extraFontFlag_), yAscent(2), yDescent(1) { +		technology(SCWIN_TECH_GDI), hfont(hfont_), pTextFormat(0), extraFontFlag(extraFontFlag_), yAscent(2), yDescent(1) { +	} +	FormatAndMetrics(IDWriteTextFormat *pTextFormat_, int extraFontFlag_, FLOAT yAscent_, FLOAT yDescent_) :  +		technology(SCWIN_TECH_DIRECTWRITE), hfont(0), pTextFormat(pTextFormat_), extraFontFlag(extraFontFlag_), yAscent(yAscent_), yDescent(yDescent_) {  	}  	~FormatAndMetrics() {  		if (hfont) @@ -261,15 +262,19 @@ struct FormatAndMetrics {  };  HFONT FormatAndMetrics::HFont() { -	LOGFONTW lf; -	memset(&lf, 0, sizeof(lf)); +	if (technology == SCWIN_TECH_GDI) { +		return hfont; +	} else { +		LOGFONTW lf; +		memset(&lf, 0, sizeof(lf)); -	HRESULT hr = pTextFormat->GetFontFamilyName(lf.lfFaceName, LF_FACESIZE); -	if (SUCCEEDED(hr)) { -		lf.lfWeight = pTextFormat->GetFontWeight(); -		lf.lfItalic = pTextFormat->GetFontStyle() == DWRITE_FONT_STYLE_ITALIC; -		lf.lfHeight = -static_cast<int>(pTextFormat->GetFontSize()); -		return ::CreateFontIndirectW(&lf); +		HRESULT hr = pTextFormat->GetFontFamilyName(lf.lfFaceName, LF_FACESIZE); +		if (SUCCEEDED(hr)) { +			lf.lfWeight = pTextFormat->GetFontWeight(); +			lf.lfItalic = pTextFormat->GetFontStyle() == DWRITE_FONT_STYLE_ITALIC; +			lf.lfHeight = -static_cast<int>(pTextFormat->GetFontSize()); +			return ::CreateFontIndirectW(&lf); +		}  	}  	return 0;  } @@ -315,7 +320,7 @@ static D2D1_TEXT_ANTIALIAS_MODE DWriteMapFontQuality(int extraFontFlag) {  static void SetLogFont(LOGFONTA &lf, const char *faceName, int characterSet, float size, int weight, bool italic, int extraFontFlag) {  	memset(&lf, 0, sizeof(lf));  	// The negative is to allow for leading -	lf.lfHeight = -(abs(static_cast<int>(size))); +	lf.lfHeight = -(abs(static_cast<int>(size + 0.5)));  	lf.lfWeight = weight;  	lf.lfItalic = static_cast<BYTE>(italic ? 1 : 0);  	lf.lfCharSet = static_cast<BYTE>(characterSet); @@ -717,6 +722,7 @@ void SurfaceGDI::BrushColor(ColourAllocated back) {  void SurfaceGDI::SetFont(Font &font_) {  	if (font_.GetID() != font) {  		FormatAndMetrics *pfm = reinterpret_cast<FormatAndMetrics *>(font_.GetID()); +		PLATFORM_ASSERT(pfm->technology == SCWIN_TECH_GDI);  		if (fontOld) {  			::SelectObject(hdc, pfm->hfont);  		} else { @@ -1395,6 +1401,7 @@ void SurfaceD2D::D2DPenColour(ColourAllocated fore, int alpha) {  void SurfaceD2D::SetFont(Font &font_) {  	FormatAndMetrics *pfm = reinterpret_cast<FormatAndMetrics *>(font_.GetID()); +	PLATFORM_ASSERT(pfm->technology == SCWIN_TECH_DIRECTWRITE);  	pTextFormat = pfm->pTextFormat;  	yAscent = pfm->yAscent;  	yDescent = pfm->yDescent; @@ -2306,8 +2313,8 @@ void ListBoxX::SetFont(Font &font) {  			::DeleteObject(fontCopy);  			fontCopy = 0;  		} -		FormatAndMetrics *pfabl = reinterpret_cast<FormatAndMetrics *>(font.GetID()); -		fontCopy = pfabl->HFont(); +		FormatAndMetrics *pfm = reinterpret_cast<FormatAndMetrics *>(font.GetID()); +		fontCopy = pfm->HFont();  		::SendMessage(lb, WM_SETFONT, reinterpret_cast<WPARAM>(fontCopy), 0);  	}  } diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 525621b2c..bfc4c1b43 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -1146,6 +1146,7 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam  					}  					technology = wParam;  					// Invalidate all cached information including layout. +					DropGraphics(true);  					InvalidateStyleRedraw();  				}  			} @@ -2379,30 +2380,41 @@ void ScintillaWin::RealizeWindowPalette(bool) {   * This paint will not be abandoned.   */  void ScintillaWin::FullPaint() { -	//HDC hdc = ::GetDC(MainHWND()); -	//FullPaintDC(hdc); -	//::ReleaseDC(MainHWND(), hdc); -	FullPaintDC(0); +	if (technology == SC_TECHNOLOGY_DEFAULT) { +		HDC hdc = ::GetDC(MainHWND()); +		FullPaintDC(hdc); +		::ReleaseDC(MainHWND(), hdc); +	} else { +		FullPaintDC(0); +	}  }  /**   * Redraw all of text area on the specified DC.   * This paint will not be abandoned.   */ -void ScintillaWin::FullPaintDC(HDC) { +void ScintillaWin::FullPaintDC(HDC hdc) {  	paintState = painting;  	rcPaint = GetClientRectangle();  	paintingAllText = true; -	EnsureRenderTarget(); -	AutoSurface surfaceWindow(pRenderTarget, this); -	if (surfaceWindow) { -		pRenderTarget->BeginDraw(); -		Paint(surfaceWindow, rcPaint); -		surfaceWindow->Release(); -		HRESULT hr = pRenderTarget->EndDraw(); -		if (hr == D2DERR_RECREATE_TARGET) { -			DropRenderTarget(); -        } +	if (technology == SC_TECHNOLOGY_DEFAULT) { +		AutoSurface surfaceWindow(hdc, this); +		if (surfaceWindow) { +			Paint(surfaceWindow, rcPaint); +			surfaceWindow->Release(); +		} +	} else { +		EnsureRenderTarget(); +		AutoSurface surfaceWindow(pRenderTarget, this); +		if (surfaceWindow) { +			pRenderTarget->BeginDraw(); +			Paint(surfaceWindow, rcPaint); +			surfaceWindow->Release(); +			HRESULT hr = pRenderTarget->EndDraw(); +			if (hr == D2DERR_RECREATE_TARGET) { +				DropRenderTarget(); +			} +		}  	}  	paintState = notPainting;  } | 
