From 16d4fd2f99a7b10fb631e1935c520b8ce7cc814b Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Mon, 8 Aug 2011 17:07:34 +0200 Subject: richview: minor refactoring of code and fixing of one memory leak. --- docview/components/richtext/RichTextLayoutUnit.pas | 40 +++++++++++----------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'docview') diff --git a/docview/components/richtext/RichTextLayoutUnit.pas b/docview/components/richtext/RichTextLayoutUnit.pas index 1e593854..d6b86a69 100644 --- a/docview/components/richtext/RichTextLayoutUnit.pas +++ b/docview/components/richtext/RichTextLayoutUnit.pas @@ -293,6 +293,18 @@ Var DoWrap: boolean; // Nested procedure + procedure CreateDefaultCurrentLine; + begin + CurrentLine := TLayoutLine.Create; + CurrentLine.Style := Style; + CurrentLine.Height := 0; + CurrentLine.MaxDescender := 0; + CurrentLine.MaxTextHeight := 0; + CurrentLine.Width := 0; + CurrentLine.LinkIndex := CurrentLinkIndex; + CurrentLine.Wrapped := false; + end; + Procedure DoLine( EndPoint: PChar; NextLine: PChar; EndX: longint ); begin // check if the max font @@ -306,15 +318,8 @@ Var Assert( CurrentLine.Height > 0 ); // we must have set the line height! AddLineStart( CurrentLine ); - CurrentLine := TLayoutLine.Create; + CreateDefaultCurrentLine; CurrentLine.Text := NextLine; - CurrentLine.Style := Style; - CurrentLine.Height := 0; - CurrentLine.MaxDescender := 0; - CurrentLine.MaxTextHeight := 0; - CurrentLine.Width := 0; - CurrentLine.LinkIndex := CurrentLinkIndex; - CurrentLine.Wrapped := false; assert( CurrentLinkIndex >= -1 ); assert( CurrentLinkIndex < FLinks.Count ); @@ -333,18 +338,6 @@ ProfileEvent('DEBUG: TRichTextLayout.Layout >>>>'); Style := GetDefaultStyle( FRichTextSettings ); ApplyStyle( Style, FFontManager ); CurrentLinkIndex := -1; - P := FText; // P is the current search position - - CurrentLine := TLayoutLine.Create; - CurrentLine.Text := P; - CurrentLine.Style := Style; - CurrentLine.Height := 0; - CurrentLine.MaxDescender := 0; - CurrentLine.MaxTextHeight := 0; - CurrentLine.Width := 0; - CurrentLine.LinkIndex := -1; - CurrentLine.Wrapped := false; - WordStartX := Style.LeftMargin; WordX := 0; WrapX := FLayoutWidth - FRichTextSettings.Margins.Right; @@ -352,6 +345,13 @@ ProfileEvent('DEBUG: TRichTextLayout.Layout >>>>'); WordStarted := false; DisplayedCharsSinceFontChange := false; + P := FText; // P is the current search position + + if FText = '' then + exit; + CreateDefaultCurrentLine; + CurrentLine.Text := P; + repeat CurrentElement := ExtractNextTextElement( P, NextP ); assert( NextP > P ); -- cgit v1.2.3-70-g09d2