Canvas.TextWidth on Report Script?

Hi,

I'm needing to reduce the font size when the Memo Text Width is greater than the Memo Width.

So, I thought I could do it by calculating the width of the text with each smaller font size than the actual one (for..downto). The questions are: Can I access the Canvas object of a particular memo and can I make a call for TextWidth Canvas function (the less I need to use Delphi for this, the better it is)?

Thanks in advance and sorry for the "terrific" english. :-P

Best Regards.

Comments

  • edited 6:19AM
    I found a solution. ;)

    Put this sample code on the OnBeforePrint of the Memo Object:
    Procedure Marcas1OnBeforePrint(Sender: TfrxComponent);
    Var wWidth : Extended;
    Begin
        Marcas1.Memo.Clear;
        Marcas1.Memo.Add( 'Here comes some text. It must be the string itself... expressions will be evaluated only after this event, so that they aren't useful here.' );
    
        Repeat
            wWidth := Marcas1.CalcWidth;
    
            If wWidth > 660 Then
                Marcas1.Font.Size := Marcas1.Font.Size - 1;
        Until wWidth <= 660;
    End;
    

    Marcas1 is the name of the Memo object.

    Btw, I don't know if it's possible to evaluate the Memo expression in place of adding a new string. But I think that should be possible. There is a GetData procedure, but it's not accessible through script. Is there anyway to do it?

    Thanks again.
  • gordkgordk St.Catherines On. Canada.
    edited 6:19AM
    hi Gabriel it will depend upon how acurate and how automated you want to be
    ie
    working in pixels
    a memo with width of 248 and default character spacing etc., will display
    about 35 characters arial 10 regular.
    in the obp of the band you can get the length of the string datafield
    if the length is greater than the known val reduce font size.

    build a smal array say 3 or 4 entries of char val font size.
    to get the values for the array initially
    manually look at the data in the memo using different font sizes and count the characters. average no of characters may also vary depending upon character set used.
    ;)
  • edited 6:19AM
    gordk, thank you very much... I'll try to implement something like that later. ;)

    Best Regards.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.