WPCubed Product Support

Insert signature in two ways with same proportions

I insert a signature file through mail merge:

procedure TfrmWordProcessor.WPRichText1MailMergeGetText(Sender: TObject;                                                        const inspname: string;                                                        Contents: TWPMMInsertTextContents);var  Index: integer;  FilePath: string;  SignatureWidth: integer;  SignatureHeight: integer;begin  Index := StrToIntDef(inspname,-1);  if Index = fDMWordProcessor.BRUGER_SIGNATUR then  begin    FilePath := ParseEnvironmentStrings(GetSystValue(scPaths,'SignaturePath','.\'));    if FileExists(FilePath) then    begin      SignatureWidth := GetSystValue(ScSystem,'SignaturWidth',0); // in twips, 0 = "as is".      SignatureHeight := GetSystValue(ScSystem,'SignaturHeight',0);      Contents.LoadImageFromFile(FilePath,SignatureWidth,SignatureHeight);    end;  end  else    Contents.WideStringValue := fDMWordProcessor.GetString(StrToIntDef(inspname,-1));end;

This piece of code inserts the signature without actually using the SignatureHeight, thus maintaining the proportions of the image.

I also insert the image through an action:

procedure TfrmWordProcessor.aUserSignatureExecute(Sender: TObject);var  FilePath: string;  SignatureWidth: integer;  SignatureHeight: integer;  image: TWPOImage;begin  FilePath := ParseEnvironmentStrings(GetSystValue(scPaths,'SignaturePath','.\'));  if FileExists(FilePath) then  begin    SignatureWidth := GetSystValue(ScSystem,'SignaturWidth',0); // in twips, 0 = "as is".    SignatureHeight := GetSystValue(ScSystem,'SignaturHeight',0);    image := TWPOImage.Create(WPRichText1);    Image.LoadFromFile(FilePath);//    Image.WidthTW := SignatureWidth;//    Image.HeightTW := SignatureHeight;    WPRichText1.TextObjects.Insert(Image,SignatureWidth,SignatureHeight,DM.UserData.Name);  end;end;

This method apparently make use of the SignatureHeight and the results differ. How do I make the two methods produce the same result?

Followup. I ended up using this. But is there a better solution?

SignatureWidth := GetSystValue(ScSystem,'SignaturWidth',0); // in twips, 0 = "as is".

    // To make dimension adjustments proportional
    if Image.ContentsWidth = image.ContentsHeight then
      SignatureHeight := SignatureWidth
    else 
      SignatureHeight := muldiv(SignatureWidth,image.ContentsHeight,Image.ContentsWidth);
#1 ♥ 0
3.5k Views 2 users read 2 min
support

You can use

Image.ScaleWH(w, h: Integer; UseContentsSize: Boolean)

w or h is ignored if negative.

Basically it will resize the image to the aspec

if UseContentsSize=true it will use the aspect ratio of the contents instead of the currtent Width/Height.

Sou You need to call

Image.ScaleWH( SignatureWidth, SignatureHeight, true )

#2 ♥ 0
This category is archived. No new posts are possible.