WPTextObject replace content, retain aspect ratio

  • I use WPTextObject as placeholder in a template and repace the content with

    wpView.RTFData.LoopAllObj(nil, ObjCallback);

    and

    obj.ObjRef.LoadFromFile(...);

    (thanks once more for pointing me at this cool functionality).

    I am now working on retaining the aspect ratio of the content I insert as this may vary I would like to scale it that it fits into the rectangle given by the object in the template. Currently it is stretched to completely fill the area. Is there an easy way to achieve this?

  • Found a solution on my own as I can modify the size of the object via obj.width/height. Didn't find that attributes in obj.objRef... Perhaps this saves someone valuable time:

    Before changing the contents the systems saves the files into tempdir that is transported to that snipped wia attribute url. In case the file does not exist, a small transparent png is loaded.

    • Offizieller Beitrag

    ObjRef does not have Width and Height since one TWPObject can be used by several TWPTextObject at the same time, by principle.

    TWPTextObject exposes the Width and Height properties which control the width and height of the object rectangle in twips. It also implements the function ScaleWH:

    function TWPTextObj.ScaleWHScreen(dw, dh: Integer; res : Integer = 96): Boolean;

    You can set one of the values to 0 or to the required value. The other value will be calculated to match the aspect ratio.