Recent

Author Topic: Font size.  (Read 1943 times)

michoux

  • Full Member
  • ***
  • Posts: 113
Font size.
« on: February 11, 2023, 12:45:21 pm »
Is there any way to change the font size of memo object on report.

I send data with following to report.
Code: Pascal  [Select][+][-]
  1. frVariables.Variable['ime'] := ime;    

Sometimes the string is to long and I would like to change the font size.

dseligo

  • Hero Member
  • *****
  • Posts: 1406
Re: Font size.
« Reply #1 on: February 11, 2023, 02:03:19 pm »
I do that like this:
Memo contains '[s1]' (this is what gets printed) and I put this script portion:
Code: Text  [Select][+][-]
  1. begin
  2.   FontStyle:=[[s1Style]];
  3.   FontSize:=[[s1Size]];
  4.   Visible:=[v1];
  5.   Adjust:=[a1];
  6.   Left:=[s1Left];
  7.   Width:=[s1Width];
  8. end

In OnGetValue event of the report I have this (and some more stuff, like code for other memo's and the code if I want to draw horizontal line and similar):
Code: Pascal  [Select][+][-]
  1.   if ParName='s1' then ParValue:=aZaglavlje[aZaglavljeBrojac].s1;
  2.   if ParName='v1' then ParValue:=aZaglavlje[aZaglavljeBrojac].v1;
  3.   if ParName='a1' then ParValue:=aZaglavlje[aZaglavljeBrojac].a1;
  4.   if ParName='s1Left' then ParValue:=aZaglavlje[aZaglavljeBrojac].s1Left;
  5.   if ParName='s1Width' then ParValue:=aZaglavlje[aZaglavljeBrojac].s1Width;
  6.   if ParName='s1Size' then ParValue:=aZaglavlje[aZaglavljeBrojac].s1Size;
  7.   if ParName='s1Style' then ParValue:=aZaglavlje[aZaglavljeBrojac].s1Style;

Of course, if you need to adjust this only at start of the report, you don't need to use OnGetValue event, you could just set variables.

I think you could also find Memo object and set size directly (I know you can set text, I didn't try if you could also set size).
I use it like this:
Code: Pascal  [Select][+][-]
  1. var obj:TfrObject;
  2. ...
  3.  
  4.   obj := frRacun.FindObject(sPolje);
  5.   If obj = nil then begin
  6.     If bJaviGresku then MessageDlg('Polje "'+sPolje+'" ne postoji na izvještaju.', mtError, [mbOK], 0);
  7.     Exit;
  8.   end;
  9.   obj.Memo.Text := sTekst;
  10.  
  11.   If obj is TfrMemoView then
  12.     (obj as TfrMemoView).Font.Size := 12; // I didn't try this
  13.  

Thaddy

  • Hero Member
  • *****
  • Posts: 16158
  • Censorship about opinions does not belong here.
Re: Font size.
« Reply #2 on: February 11, 2023, 03:23:22 pm »
Note that the font size can vary between positive values - the size in points - and negative values - the size in pixels. Depending on what you want there is an easy conversion formula like so:
Code: Pascal  [Select][+][-]
  1. Height:= -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
  2. // and the other way around:
  3. PointSize := MulDiv(-Height, 72, GetDeviceCaps(hDC, LogPixelsY);

Height = lfHeight in LOGFONT structure.
I have only used this code on Windows, not sure if Lazarus supports this in a cross-platform way.

So remember, when working with fonts, define what you want!
« Last Edit: February 11, 2023, 03:25:55 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

michoux

  • Full Member
  • ***
  • Posts: 113
Re: Font size.
« Reply #3 on: February 11, 2023, 11:21:02 pm »
I did following.


Code: Pascal  [Select][+][-]
  1.  
  2. procedure TFormMain.frReport1EnterRect(Memo: TStringList; View: TfrView);
  3. var
  4.   Ms: TMemoryStream;
  5. begin
  6.  
  7.   if (View is TfrMemoView) then
  8.   begin
  9.      if (View as TfrMemoView).Name = 'Memo3' then
  10.       begin
  11.         (View as TfrMemoView).Font.Bold:=true;
  12.         (View as TfrMemoView).Font.size:=8;
  13.       end;
  14.   end;                
  15. ....
  16.  
  17.  

 

TinyPortal © 2005-2018