diff options
| author | nyamatongwe <unknown> | 2009-11-02 04:51:51 +0000 | 
|---|---|---|
| committer | nyamatongwe <unknown> | 2009-11-02 04:51:51 +0000 | 
| commit | c563199dde32ce1d04e95c478dbd6a3e352f5d4d (patch) | |
| tree | 517893f316edf898a972316bbcd3b7b64c82de0f | |
| parent | dde4d3e2775b52a8b678d209c2299ec637210a03 (diff) | |
| download | scintilla-mirror-c563199dde32ce1d04e95c478dbd6a3e352f5d4d.tar.gz | |
Added setting for font quality to allow application to choose anti-aliased,
non-anti-aliased or lcd-optimized text.
| -rw-r--r-- | cocoa/PlatCocoa.mm | 2 | ||||
| -rw-r--r-- | doc/ScintillaDoc.html | 10 | ||||
| -rw-r--r-- | gtk/PlatGTK.cxx | 2 | ||||
| -rw-r--r-- | include/Platform.h | 2 | ||||
| -rw-r--r-- | include/Scintilla.h | 7 | ||||
| -rw-r--r-- | include/Scintilla.iface | 15 | ||||
| -rw-r--r-- | macosx/PlatMacOSX.cxx | 2 | ||||
| -rw-r--r-- | src/Editor.cxx | 9 | ||||
| -rw-r--r-- | src/FontQuality.h | 12 | ||||
| -rw-r--r-- | src/Style.cxx | 2 | ||||
| -rw-r--r-- | src/Style.h | 2 | ||||
| -rw-r--r-- | src/ViewStyle.cxx | 2 | ||||
| -rw-r--r-- | src/ViewStyle.h | 2 | ||||
| -rw-r--r-- | win32/PlatWin.cxx | 57 | 
14 files changed, 102 insertions, 24 deletions
| diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index 49be5ed69..5d6d43b09 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -153,7 +153,7 @@ Font::~Font()   * TODO: rewrite to use NSFont.   */  void Font::Create(const char *faceName, int characterSet, int size, bool bold, bool italic,  -                  bool extraFontFlag) +                  int extraFontFlag)  {    // TODO: How should I handle the characterSet request?    Release(); diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 05149c9b5..a1f0b38a8 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -2873,6 +2873,8 @@ struct TextToFind {       <a class="message" href="#SCI_GETBUFFEREDDRAW">SCI_GETBUFFEREDDRAW</a><br />       <a class="message" href="#SCI_SETTWOPHASEDRAW">SCI_SETTWOPHASEDRAW(bool twoPhase)</a><br />       <a class="message" href="#SCI_GETTWOPHASEDRAW">SCI_GETTWOPHASEDRAW</a><br /> +     <a class="message" href="#SCI_SETFONTQUALITY">SCI_SETFONTQUALITY(int fontQuality)</a><br /> +     <a class="message" href="#SCI_GETFONTQUALITY">SCI_GETFONTQUALITY</a><br />       <a class="message" href="#SCI_SETCODEPAGE">SCI_SETCODEPAGE(int codePage)</a><br />       <a class="message" href="#SCI_GETCODEPAGE">SCI_GETCODEPAGE</a><br />       <a class="message" href="#SCI_SETKEYSUNICODE">SCI_SETKEYSUNICODE(bool keysUnicode)</a><br /> @@ -2934,6 +2936,14 @@ struct TextToFind {       transparent mode. Two phase drawing may flicker more than single phase       unless buffered drawing is on. The default is for drawing to be two phase.</p> +    <p><b id="SCI_SETFONTQUALITY">SCI_SETFONTQUALITY(int fontQuality)</b><br /> +     <b id="SCI_GETFONTQUALITY">SCI_GETFONTQUALITY</b><br /> +     Manage font quality (antialiasing method). Currently, the following values are available on Windows: +     <code>SC_EFF_QUALITY_DEFAULT</code> (backward compatible), +     <code>SC_EFF_QUALITY_NON_ANTIALIASED</code>, +     <code>SC_EFF_QUALITY_ANTIALIASED</code>, +     <code>SC_EFF_QUALITY_LCD_OPTIMIZED</code>.</p> +      <p><b id="SCI_SETCODEPAGE">SCI_SETCODEPAGE(int codePage)</b><br />       <b id="SCI_GETCODEPAGE">SCI_GETCODEPAGE</b><br />       Scintilla has some support for Japanese, Chinese and Korean DBCS. Use this message with diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index c094763fc..0924bb5a8 100644 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -666,7 +666,7 @@ Font::Font() : fid(0) {}  Font::~Font() {}  void Font::Create(const char *faceName, int characterSet, int size, -	bool bold, bool italic, bool) { +	bool bold, bool italic, int) {  	Release();  	fid = FontCached::FindOrCreate(faceName, characterSet, size, bold, italic);  } diff --git a/include/Platform.h b/include/Platform.h index 1d4df4884..b5d6d9bf8 100644 --- a/include/Platform.h +++ b/include/Platform.h @@ -295,7 +295,7 @@ public:  	virtual ~Font();  	virtual void Create(const char *faceName, int characterSet, int size, -		bool bold, bool italic, bool extraFontFlag=false); +		bool bold, bool italic, int extraFontFlag=0);  	virtual void Release();  	FontID GetID() { return fid; } diff --git a/include/Scintilla.h b/include/Scintilla.h index c7d30ca3a..e38d74cba 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -478,6 +478,13 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,  #define SCI_APPENDTEXT 2282  #define SCI_GETTWOPHASEDRAW 2283  #define SCI_SETTWOPHASEDRAW 2284 +#define SC_EFF_QUALITY_MASK 0xF +#define SC_EFF_QUALITY_DEFAULT 0 +#define SC_EFF_QUALITY_NON_ANTIALIASED 1 +#define SC_EFF_QUALITY_ANTIALIASED 2 +#define SC_EFF_QUALITY_LCD_OPTIMIZED 3 +#define SCI_SETFONTQUALITY 2611 +#define SCI_GETFONTQUALITY 2612  #define SCI_TARGETFROMSELECTION 2287  #define SCI_LINESJOIN 2288  #define SCI_LINESSPLIT 2289 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index c524b7195..8f7c545eb 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1205,6 +1205,21 @@ get bool GetTwoPhaseDraw=2283(,)  # and then the foreground. This avoids chopping off characters that overlap the next run.  set void SetTwoPhaseDraw=2284(bool twoPhase,) +# Control font anti-aliasing. + +enu FontQuality=SC_EFF_ +val SC_EFF_QUALITY_MASK=0xF +val SC_EFF_QUALITY_DEFAULT=0 +val SC_EFF_QUALITY_NON_ANTIALIASED=1 +val SC_EFF_QUALITY_ANTIALIASED=2 +val SC_EFF_QUALITY_LCD_OPTIMIZED=3 + +# Choose the quality level for text from the FontQuality enumeration. +set void SetFontQuality=2611(int fontQuality,) + +# Retrieve the quality level for text. +get int GetFontQuality=2612(,) +  # Make the target range start and end be the same as the selection range start and end.  fun void TargetFromSelection=2287(,) diff --git a/macosx/PlatMacOSX.cxx b/macosx/PlatMacOSX.cxx index eb262da33..d16913d78 100644 --- a/macosx/PlatMacOSX.cxx +++ b/macosx/PlatMacOSX.cxx @@ -75,7 +75,7 @@ Font::~Font() { Release(); }  void Font::Create(const char *faceName, int /*characterSet*/, -                  int size, bool bold, bool italic, bool /*extraFontFlag*/) { +                  int size, bool bold, bool italic, int /*extraFontFlag*/) {      // TODO: How should I handle the characterSet request?      Release(); diff --git a/src/Editor.cxx b/src/Editor.cxx index 727429921..a68046b90 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -7001,6 +7001,15 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {  		InvalidateStyleRedraw();  		break; +	case SCI_SETFONTQUALITY: +		vs.extraFontFlag &= ~SC_EFF_QUALITY_MASK; +		vs.extraFontFlag |= (wParam & SC_EFF_QUALITY_MASK); +		InvalidateStyleRedraw(); +		break; + +	case SCI_GETFONTQUALITY: +		return (vs.extraFontFlag & SC_EFF_QUALITY_MASK); +  	case SCI_SETTABWIDTH:  		if (wParam > 0) {  			pdoc->tabInChars = wParam; diff --git a/src/FontQuality.h b/src/FontQuality.h new file mode 100644 index 000000000..2c8d548a8 --- /dev/null +++ b/src/FontQuality.h @@ -0,0 +1,12 @@ +// Scintilla source code edit control +/** @file FontQuality.h + ** Definitions to control font anti-aliasing. + **/ +// Copyright 1998-2009 by Neil Hodgson <neilh@scintilla.org> +// The License.txt file describes the conditions under which this software may be distributed. + +#define SC_EFF_QUALITY_MASK            0xF +#define SC_EFF_QUALITY_DEFAULT           0 +#define SC_EFF_QUALITY_NON_ANTIALIASED   1 +#define SC_EFF_QUALITY_ANTIALIASED       2 +#define SC_EFF_QUALITY_LCD_OPTIMIZED     3 diff --git a/src/Style.cxx b/src/Style.cxx index ad081a66d..4314dec0a 100644 --- a/src/Style.cxx +++ b/src/Style.cxx @@ -126,7 +126,7 @@ bool Style::EquivalentFontTo(const Style *other) const {  	return strcmp(fontName, other->fontName) == 0;  } -void Style::Realise(Surface &surface, int zoomLevel, Style *defaultStyle, bool extraFontFlag) { +void Style::Realise(Surface &surface, int zoomLevel, Style *defaultStyle, int extraFontFlag) {  	sizeZoomed = size + zoomLevel;  	if (sizeZoomed <= 2)	// Hangs if sizeZoomed <= 1  		sizeZoomed = 2; diff --git a/src/Style.h b/src/Style.h index 1caecaee7..0be3d4f07 100644 --- a/src/Style.h +++ b/src/Style.h @@ -53,7 +53,7 @@ public:  		   bool visible_, bool changeable_, bool hotspot_);  	void ClearTo(const Style &source);  	bool EquivalentFontTo(const Style *other) const; -	void Realise(Surface &surface, int zoomLevel, Style *defaultStyle = 0, bool extraFontFlag = false); +	void Realise(Surface &surface, int zoomLevel, Style *defaultStyle = 0, int extraFontFlag = 0);  	bool IsProtected() const { return !(changeable && visible);};  }; diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index 3dff07b9b..8e9c4a463 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -247,7 +247,7 @@ void ViewStyle::Init(size_t stylesSize_) {  	viewIndentationGuides = ivNone;  	viewEOL = false;  	showMarkedLines = true; -	extraFontFlag = false; +	extraFontFlag = 0;  	extraAscent = 0;  	extraDescent = 0;  	marginStyleOffset = 0; diff --git a/src/ViewStyle.h b/src/ViewStyle.h index 1a85cf43f..22e365b02 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -106,7 +106,7 @@ public:  	int caretStyle;  	int caretWidth;  	bool someStylesProtected; -	bool extraFontFlag; +	int extraFontFlag;  	int extraAscent;  	int extraDescent;  	int marginStyleOffset; diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index fefd523a1..1305b3f66 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -22,6 +22,7 @@  #include "PlatformRes.h"  #include "UniConversion.h"  #include "XPM.h" +#include "FontQuality.h"  #ifndef IDC_HAND  #define IDC_HAND MAKEINTRESOURCE(32649) @@ -179,13 +180,35 @@ void Palette::Allocate(Window &) {  	}  } -static void SetLogFont(LOGFONTA &lf, const char *faceName, int characterSet, int size, bool bold, bool italic) { +#ifndef CLEARTYPE_QUALITY +#define CLEARTYPE_QUALITY 5 +#endif + +static BYTE Win32MapFontQuality(int extraFontFlag) { +	switch (extraFontFlag & SC_EFF_QUALITY_MASK) { + +		case SC_EFF_QUALITY_NON_ANTIALIASED: +			return NONANTIALIASED_QUALITY; + +		case SC_EFF_QUALITY_ANTIALIASED: +			return ANTIALIASED_QUALITY; + +		case SC_EFF_QUALITY_LCD_OPTIMIZED: +			return CLEARTYPE_QUALITY; + +		default: +			return SC_EFF_QUALITY_DEFAULT; +	} +} + +static void SetLogFont(LOGFONTA &lf, const char *faceName, int characterSet, int size, bool bold, bool italic, int extraFontFlag) {  	memset(&lf, 0, sizeof(lf));  	// The negative is to allow for leading  	lf.lfHeight = -(abs(size));  	lf.lfWeight = bold ? FW_BOLD : FW_NORMAL;  	lf.lfItalic = static_cast<BYTE>(italic ? 1 : 0);  	lf.lfCharSet = static_cast<BYTE>(characterSet); +	lf.lfQuality = Win32MapFontQuality(extraFontFlag);  	strncpy(lf.lfFaceName, faceName, sizeof(lf.lfFaceName));  } @@ -194,10 +217,11 @@ static void SetLogFont(LOGFONTA &lf, const char *faceName, int characterSet, int   * If one font is the same as another, its hash will be the same, but if the hash is the   * same then they may still be different.   */ -static int HashFont(const char *faceName, int characterSet, int size, bool bold, bool italic) { +static int HashFont(const char *faceName, int characterSet, int size, bool bold, bool italic, int extraFontFlag) {  	return  		size ^  		(characterSet << 10) ^ +		((extraFontFlag & SC_EFF_QUALITY_MASK) << 9) ^  		(bold ? 0x10000000 : 0) ^  		(italic ? 0x20000000 : 0) ^  		faceName[0]; @@ -208,33 +232,34 @@ class FontCached : Font {  	int usage;  	LOGFONTA lf;  	int hash; -	FontCached(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_); +	FontCached(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_, int extraFontFlag_);  	~FontCached() {} -	bool SameAs(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_); +	bool SameAs(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_, int extraFontFlag_);  	virtual void Release();  	static FontCached *first;  public: -	static FontID FindOrCreate(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_); +	static FontID FindOrCreate(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_, int extraFontFlag_);  	static void ReleaseId(FontID fid_);  };  FontCached *FontCached::first = 0; -FontCached::FontCached(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_) : +FontCached::FontCached(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_, int extraFontFlag_) :  	next(0), usage(0), hash(0) { -	SetLogFont(lf, faceName_, characterSet_, size_, bold_, italic_); -	hash = HashFont(faceName_, characterSet_, size_, bold_, italic_); +	SetLogFont(lf, faceName_, characterSet_, size_, bold_, italic_, extraFontFlag_); +	hash = HashFont(faceName_, characterSet_, size_, bold_, italic_, extraFontFlag_);  	fid = ::CreateFontIndirectA(&lf);  	usage = 1;  } -bool FontCached::SameAs(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_) { +bool FontCached::SameAs(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_, int extraFontFlag_) {  	return  		(lf.lfHeight == -(abs(size_))) &&  		(lf.lfWeight == (bold_ ? FW_BOLD : FW_NORMAL)) &&  		(lf.lfItalic == static_cast<BYTE>(italic_ ? 1 : 0)) &&  		(lf.lfCharSet == characterSet_) && +		(lf.lfQuality == Win32MapFontQuality(extraFontFlag_)) &&  		0 == strcmp(lf.lfFaceName,faceName_);  } @@ -244,19 +269,19 @@ void FontCached::Release() {  	fid = 0;  } -FontID FontCached::FindOrCreate(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_) { +FontID FontCached::FindOrCreate(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_, int extraFontFlag_) {  	FontID ret = 0;  	::EnterCriticalSection(&crPlatformLock); -	int hashFind = HashFont(faceName_, characterSet_, size_, bold_, italic_); +	int hashFind = HashFont(faceName_, characterSet_, size_, bold_, italic_, extraFontFlag_);  	for (FontCached *cur=first; cur; cur=cur->next) {  		if ((cur->hash == hashFind) && -			cur->SameAs(faceName_, characterSet_, size_, bold_, italic_)) { +			cur->SameAs(faceName_, characterSet_, size_, bold_, italic_, extraFontFlag_)) {  			cur->usage++;  			ret = cur->fid;  		}  	}  	if (ret == 0) { -		FontCached *fc = new FontCached(faceName_, characterSet_, size_, bold_, italic_); +		FontCached *fc = new FontCached(faceName_, characterSet_, size_, bold_, italic_, extraFontFlag_);  		if (fc) {  			fc->next = first;  			first = fc; @@ -296,14 +321,14 @@ Font::~Font() {  #define FONTS_CACHED  void Font::Create(const char *faceName, int characterSet, int size, -	bool bold, bool italic, bool) { +	bool bold, bool italic, int extraFontFlag) {  	Release();  #ifndef FONTS_CACHED  	LOGFONT lf; -	SetLogFont(lf, faceName, characterSet, size, bold, italic); +	SetLogFont(lf, faceName, characterSet, size, bold, italic, extraFontFlag);  	fid = ::CreateFontIndirect(&lf);  #else -	fid = FontCached::FindOrCreate(faceName, characterSet, size, bold, italic); +	fid = FontCached::FindOrCreate(faceName, characterSet, size, bold, italic, extraFontFlag);  #endif  } | 
