From 6d2e993c228451e803c5c303428069c3af955850 Mon Sep 17 00:00:00 2001 From: skalogryz Date: Fri, 6 Mar 2015 16:41:17 +0000 Subject: [PATCH] richmemo: * introduced GetFontParams(TFont) to convert TFont to TFontParams (resolving font data). Using GetFontData(AFont.Reference.Handle) to resolve the passed font information (to handle uninitialized fonts). TFont.Handle is deprecated. * corrected the TFontParams parameter passing in InsertFontText function git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4001 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/richmemo/richmemo.pas | 34 ++++++++++++++++++++------- components/richmemo/richmemoutils.pas | 4 ++-- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/components/richmemo/richmemo.pas b/components/richmemo/richmemo.pas index 225a7a393..cfa493c80 100644 --- a/components/richmemo/richmemo.pas +++ b/components/richmemo/richmemo.pas @@ -245,6 +245,7 @@ function GetFontParams(styles: TFontStyles): TFontParams; overload; function GetFontParams(color: TColor; styles: TFontStyles): TFontParams; overload; function GetFontParams(const Name: String; color: TColor; styles: TFontStyles): TFontParams; overload; function GetFontParams(const Name: String; Size: Integer; color: TColor; styles: TFontStyles): TFontParams; overload; +function GetFontParams(AFont: TFont): TFontParams; overload; procedure InitParaMetric(var m: TParaMetric); procedure InitParaNumbering(var n: TParaNumbering); @@ -289,6 +290,29 @@ begin Result.Style := styles; end; +function GetFontParams(AFont: TFont): TFontParams; overload; +var + data : TFontData; +begin + InitFontParams(Result); + if not Assigned(AFont) then Exit; + + if AFont.Reference.Handle <> 0 then begin + data:=GetFontData(AFont.Reference.Handle); + if data.Height<0 + then Result.Size:=round(abs(data.Height)/ScreenInfo.PixelsPerInchY*72) + else Result.Size:=data.Height; + Result.Name:=data.Name; + Result.Color:=AFont.Color; + Result.Style:=data.Style; + end else begin + Result.Name := AFont.Name; + Result.Color := AFont.Color; + Result.Size := AFont.Size; + Result.Style := AFont.Style; + end; +end; + procedure InitParaMetric(var m: TParaMetric); begin FillChar(m, sizeof(m), 0); @@ -441,15 +465,9 @@ end; procedure TCustomRichMemo.SetTextAttributes(TextStart, TextLen: Integer; AFont: TFont); -var - params : TFontParams; begin - InitFontParams(params); - params.Name := AFont.Name; - params.Color := AFont.Color; - params.Size := AFont.Size; - params.Style := AFont.Style; - SetTextAttributes(TextStart, TextLen, {TextStyleAll,} params); + if not Assigned(AFont) then Exit; + SetTextAttributes(TextStart, TextLen, GetFontParams(AFont)); end; procedure TCustomRichMemo.SetTextAttributes(TextStart, TextLen: Integer; diff --git a/components/richmemo/richmemoutils.pas b/components/richmemo/richmemoutils.pas index de121c5e5..28e16a580 100644 --- a/components/richmemo/richmemoutils.pas +++ b/components/richmemo/richmemoutils.pas @@ -54,12 +54,12 @@ procedure InsertStyledText(const ARichMemo: TCustomRichMemo; const TextUTF8: Str InsPos : Integer = -1 ); procedure InsertColorStyledText(const ARichMemo: TCustomRichMemo; const TextUTF8: String; AColor: TColor; AStyle: TFontStyles; InsPos : Integer = -1 ); -procedure InsertFontText(const ARichMemo: TCustomRichMemo; const TextUTF8: String; prms: TFontParams; +procedure InsertFontText(const ARichMemo: TCustomRichMemo; const TextUTF8: String; const prms: TFontParams; InsPos : Integer = -1 ); implementation -procedure InsertFontText(const ARichMemo: TCustomRichMemo; const TextUTF8: String; prms: TFontParams; +procedure InsertFontText(const ARichMemo: TCustomRichMemo; const TextUTF8: String; const prms: TFontParams; InsPos : Integer = -1 ); var len : Integer;