aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Style.h
diff options
context:
space:
mode:
authornyamatongwe <unknown>2011-03-30 10:27:05 +1100
committernyamatongwe <unknown>2011-03-30 10:27:05 +1100
commitf88ad3864ccdf534e46cc004b377b2c08d318a04 (patch)
tree2efa44a4ecfe7b1b864c2c049d1bc6397b779bc3 /src/Style.h
parentef7f8a349a89dd7d72d62f7a162cb3e553ca4ba6 (diff)
downloadscintilla-mirror-f88ad3864ccdf534e46cc004b377b2c08d318a04.tar.gz
Optimize font use by only allocating platform font resources for unique fonts
and using aliases of these in the Style objects. Font measurement is also performed once for each unique font and the results copied into each style. No change is needed in callers. On PLAT_WX, the font ascent is cached in the Font object when Ascent is called but this is not copied into the aliases as ascent is protected. Therefore the code that copies the FontID into the alias also calls Ascent to ensure the ascent value is cached.
Diffstat (limited to 'src/Style.h')
-rw-r--r--src/Style.h61
1 files changed, 44 insertions, 17 deletions
diff --git a/src/Style.h b/src/Style.h
index c1f87e1b3..460dad490 100644
--- a/src/Style.h
+++ b/src/Style.h
@@ -12,18 +12,53 @@
namespace Scintilla {
#endif
+struct FontSpecification {
+ const char *fontName;
+ bool bold;
+ bool italic;
+ int size;
+ int characterSet;
+ int extraFontFlag;
+ FontSpecification() :
+ fontName(0),
+ bold(false),
+ italic(false),
+ size(10),
+ characterSet(0),
+ extraFontFlag(0) {
+ }
+ bool EqualTo(const FontSpecification &other) const;
+};
+
+// Just like Font but only has a copy of the FontID so should not delete it
+class FontAlias : public Font {
+ // Private so FontAlias objects can not be copied
+ FontAlias(const FontAlias &);
+ FontAlias &operator=(const FontAlias &);
+public:
+ FontAlias();
+ virtual ~FontAlias();
+ void ClearFont();
+};
+
+struct FontMeasurements {
+ unsigned int lineHeight;
+ unsigned int ascent;
+ unsigned int descent;
+ unsigned int externalLeading;
+ unsigned int aveCharWidth;
+ unsigned int spaceWidth;
+ int sizeZoomed;
+ FontMeasurements();
+ void Clear();
+};
+
/**
*/
-class Style {
+class Style : public FontSpecification, public FontMeasurements {
public:
ColourPair fore;
ColourPair back;
- bool aliasOfDefaultFont;
- bool bold;
- bool italic;
- int size;
- const char *fontName;
- int characterSet;
bool eolFilled;
bool underline;
enum ecaseForced {caseMixed, caseUpper, caseLower};
@@ -32,14 +67,7 @@ public:
bool changeable;
bool hotspot;
- Font font;
- int sizeZoomed;
- unsigned int lineHeight;
- unsigned int ascent;
- unsigned int descent;
- unsigned int externalLeading;
- unsigned int aveCharWidth;
- unsigned int spaceWidth;
+ FontAlias font;
Style();
Style(const Style &source);
@@ -52,8 +80,7 @@ public:
bool underline_, ecaseForced caseForce_,
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, int extraFontFlag = 0);
+ void Copy(Font &font_, const FontMeasurements &fm_);
bool IsProtected() const { return !(changeable && visible);}
};