From f88ad3864ccdf534e46cc004b377b2c08d318a04 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/ViewStyle.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/ViewStyle.h') diff --git a/src/ViewStyle.h b/src/ViewStyle.h index 6ca488dff..cf45be41f 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -39,6 +39,19 @@ public: const char *Save(const char *name); }; +class FontRealised : public Font, public FontSpecification, public FontMeasurements { + // Private so FontRealised objects can not be copied + FontRealised(const FontRealised &); + FontRealised &operator=(const FontRealised &); +public: + FontRealised *frNext; + FontRealised(const FontSpecification &fs); + virtual ~FontRealised(); + void Realise(Surface &surface, int zoomLevel); + FontRealised *Find(const FontSpecification &fs); + void FindMaxAscentDescent(unsigned int &maxAscent, unsigned int &maxDescent); +}; + enum IndentView {ivNone, ivReal, ivLookForward, ivLookBoth}; enum WhiteSpaceVisibility {wsInvisible=0, wsVisibleAlways=1, wsVisibleAfterIndent=2}; @@ -48,6 +61,7 @@ enum WhiteSpaceVisibility {wsInvisible=0, wsVisibleAlways=1, wsVisibleAfterInden class ViewStyle { public: FontNames fontNames; + FontRealised *frFirst; size_t stylesSize; Style *styles; LineMarker markers[MARKER_MAX + 1]; @@ -119,6 +133,7 @@ public: ViewStyle(const ViewStyle &source); ~ViewStyle(); void Init(size_t stylesSize_=64); + void CreateFont(const FontSpecification &fs); void RefreshColourPalette(Palette &pal, bool want); void Refresh(Surface &surface); void AllocStyles(size_t sizeNew); -- cgit v1.2.3