3

I am using Windows 10, Delphi 7. Trying to make Pdf document with SynPDF using it's canvas directly. I need to draw in the rectangle only that part of the text that corresponds to the length of the rectangle, the rest cut off. I am using DrawText (and DrawTextEx) functions to write text in the given rectangle with alignment (TA_LEFT, TA_RIGHT, TA_CENTER). The problem: these functions draw the text, but do not take into account the given boundaries - they do not clip(crop) this text.

var 
  R: TRect;
  s: String;
begin
    R:= Rect(50, 50, 120, 75);
    Canvas.Brush.Color:=clYellow;
    Canvas.Rectangle(R);  
    Canvas.Font.Name:='Arial';
    Canvas.Font.Size:=10;
    Canvas.Font.Style:=[];
    Canvas.Brush.Style:= bsClear;
    s:='Sample for text clipping';        
    DrawText(Canvas.Handle, PChar(s), -1, R, TA_LEFT or 
            {DT_END_ELLIPSIS or }DT_VCENTER or DT_SINGLELINE);
end;

If I add DT_END_ELLIPSIS it works correctly but adds three dots - I do not need dots. What I am doing wrong? Or I need to use other functions for my task?

Unfortunately, I'm not allowed (by StackOverflow) to add a photo with the result...

Viktor
  • 43
  • 4
  • 1
    You can use [Canvas.TextRect](http://docwiki.embarcadero.com/Libraries/en/Vcl.Graphics.TCanvas.TextRect). – whosrdaddy Aug 02 '18 at 12:36
  • Can you check if this works with a standard Windows canvas on screen? It might be a feature of SynPDF, as the Windows Docs state that DrawText actually does clipping unless DT_NOCLIP is given. – Uwe Raabe Aug 02 '18 at 12:43
  • 1
    @whosrdaddy I tried Canvas.TextRect it works! Although it is less convenient than DrawText. Than you! – Viktor Aug 02 '18 at 14:14
  • @UweRaabe I checked if DrawText works on Windows Canvas - and it works perfectly (so and TextRect). Now I am sure where to dig! I even can not tell why I did not try it before... Most likely the problem is in SynPDF. – Viktor Aug 02 '18 at 14:16
  • 1
    There is a Version of SynPdf that should work. Look at: https://synopse.info/forum/viewtopic.php?pid=27877#p27877 – Fritzw Aug 03 '18 at 10:46
  • @Fritzw Thanks! It works! But I'm not sure if I downloaded the right version. I downloaded SynPDF.pas, which is at the very beginning of the post, the link to which you gave me. – Viktor Aug 03 '18 at 17:07
  • Yes these is the version – Fritzw Aug 04 '18 at 07:21

0 Answers0