From 8d7937803d186c9a5ad3e256fc93503ba861ee78 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Wed, 30 Mar 2011 10:27:05 +1100 Subject: 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. --- src/Style.h | 61 ++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 17 deletions(-) (limited to 'src/Style.h') 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);} }; -- cgit v1.2.3