diff options
author | Andrew Haines <andrewd207@aol.com> | 2014-03-30 20:39:23 +0100 |
---|---|---|
committer | Graeme Geldenhuys <graemeg@gmail.com> | 2014-03-30 20:39:23 +0100 |
commit | fd68cfe060b6c51ef515e61931474e1a088e1ca9 (patch) | |
tree | 4b4994a92dd6a4b5c27ed469771bafff14d1274f /docview/components/richtext | |
parent | dea8b1fa3e7f734163dd841c73a8dd6bd99abf22 (diff) | |
download | fpGUI-fd68cfe060b6c51ef515e61931474e1a088e1ca9.tar.xz |
Richview resize/render speed
while testing richview I noticed it's fairly slow, though only if there
are font changes in the content. So I added a font cache to the richview
fontmanager and now there is almost no delay to render content in the
richview. Big, big speed improvement.
Diffstat (limited to 'docview/components/richtext')
-rw-r--r-- | docview/components/richtext/CanvasFontManager.pas | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/docview/components/richtext/CanvasFontManager.pas b/docview/components/richtext/CanvasFontManager.pas index fe0123d3..edeb8cb9 100644 --- a/docview/components/richtext/CanvasFontManager.pas +++ b/docview/components/richtext/CanvasFontManager.pas @@ -35,7 +35,7 @@ type private FWidget: TfpgWidget; FCanvas: TfpgCanvas; - FFont: TfpgFont; + FFontCache: TFPList; function GetCurrentFont: TfpgFont; procedure SetDefaultFont(const AValue: TfpgFont); protected @@ -235,14 +235,20 @@ begin FWidget := AWidget; FDefaultFont := fpgGetFont(DefaultTopicFont); FCanvas.Font := FDefaultFont; - FFont := nil; + FFontCache := TFPList.Create; end; destructor TCanvasFontManager.Destroy; +var + i: Integer; begin FCanvas.Font := fpgApplication.DefaultFont; FDefaultFont.Free; - FFont.Free; + + for i := 0 to FFontCache.Count-1 do + TObject(FFontCache.Items[i]).Free; + FFontCache.Free; + inherited Destroy; end; @@ -262,6 +268,11 @@ end; // Set the current font for the canvas to match the given // spec, creating or re-using fonts as needed. procedure TCanvasFontManager.SetFont(const AFontDesc: TfpgString); +const + MAX_FONT_CACHE = 10; +var + i: Integer; + Tmp: TfpgFont; begin if FCanvas.Font.FontDesc = AFontDesc then Exit; // nothing to do so exit @@ -272,10 +283,25 @@ begin Exit; end; - if Assigned(FFont) then - FFont.Free; - FFont := fpgGetFont(AFontDesc); - FCanvas.Font := FFont; + for i := 0 to FFontCache.Count-1 do + begin + Tmp := TfpgFont(FFontCache.Items[i]); + if Tmp.FontDesc = AFontDesc then + begin + FFontCache.Move(i, 0); + FCanvas.Font := Tmp; + Exit; + end; + end; + + Tmp := fpgGetFont(AFontDesc); + FFontCache.Insert(0, Tmp); + if FFontCache.Count > MAX_FONT_CACHE then + begin + TObject(FFontCache.Items[MAX_FONT_CACHE]).Free; + FFontCache.Delete(MAX_FONT_CACHE); + end; + FCanvas.Font := Tmp; end; function TCanvasFontManager.CharWidth( const C: TfpgChar ): longint; |