From d8ab6b738ebd46d572aca8aec1c3adef86d4c56d Mon Sep 17 00:00:00 2001 From: skalogryz Date: Sun, 26 Jul 2020 17:50:22 +0000 Subject: [PATCH] richmemo: fix font matching logic, preventing infinite loop. updating GetTextAttribute policy for cases when there's no text git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7570 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/richmemo/cocoa/cocoarichmemo.pas | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/components/richmemo/cocoa/cocoarichmemo.pas b/components/richmemo/cocoa/cocoarichmemo.pas index b76e1aacf..ed1cab4f0 100644 --- a/components/richmemo/cocoa/cocoarichmemo.pas +++ b/components/richmemo/cocoa/cocoarichmemo.pas @@ -247,6 +247,16 @@ begin if not Assigned(view) then Exit; txt:=view.textStorage; + if (txt.length = 0) then begin + // there's no text! using the control information + Params.Name := txt.font.displayName.UTF8String; + Params.Size := Round(txt.font.pointSize); + Params.HasBkClr := false; + exit; + end; + + if (TextStart >= txt.length) then + TextStart := txt.length; dict:=GetDict(txt, textStart); ReadNSFontParams(dict, prm); if Assigned(prm.font) then begin @@ -335,6 +345,7 @@ begin trt:=trt and (not fallback[i]); fd:=fd.fontDescriptorWithSymbolicTraits(trt); fdd:=fd.matchingFontDescriptorWithMandatoryKeys(nil); + inc(i); end; Result:=fdd; finally