TextOut and DrawText EndEllipsis does not work on OSX lazarus / 39-Graphics ---------------------------------------------------------------------- apeoperaio · 2018-03-23 08:11 I am trying to use EndEllipsis when I draw a text on a canvas. It works as expected on windows but not on osx (carbon), not tested on linux yet. Here my code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormPaint(Sender: TObject);var  strtext: string;  ts: TTextStyle;  TextBox: TRect;begin  strtext:= 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor.';   ts:= Canvas.TextStyle;  ts.EndEllipsis:= True;  TextBox := Rect(0, 0, 50, High(Integer));  Canvas.TextRect(TextBox, 0, 0, strtext, ts);    Canvas.TextOut(0,0,strtext);   TextBox := Rect(0, 20, 50, High(Integer));  DrawText(Canvas.Handle, PChar(strtext), Length(strtext),    TextBox, DT_END_ELLIPSIS or DT_CALCRECT);   DrawText(Canvas.Handle, PChar(strtext), Length(strtext),    TextBox, DT_END_ELLIPSIS);end;   Any hints? ---------------------------------------------------------------------- wp · 2018-03-23 09:17 I don't have access to OSX, so this answer might be wrong. Use the canvas method TextRect which respects the TextStyle of the canvas, and TTextStyle has a field for text ellipsis: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.PaintBox1Paint(Sender: TObject);var  ts: TTextStyle;  R: TRect;begin  ts := Paintbox1.Canvas.TextStyle;  ts.EndEllipsis := true;  ts.WordBreak := false;  Paintbox1.Canvas.TextStyle := ts;  R := Rect(0, 0, Paintbox1.Width, Paintbox1.Height);  Paintbox1.Canvas.TextRect(R, R.Left, R.Top, 'this is a long, long, long text', ts);end; This is the declaration of TTextStyle in unit graphics: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  { Reflects text style when drawn in a rectangle }   TTextLayout = (tlTop, tlCenter, tlBottom);  TTextStyle = packed record    Alignment : TAlignment;  // TextRect Only: horizontal alignment     Layout    : TTextLayout; // TextRect Only: vertical alignment     SingleLine: boolean;     // If WordBreak is false then process #13, #10 as                           // standard chars and perform no Line breaking.   Clipping  : boolean;     // TextRect Only: Clip Text to passed Rectangle     ExpandTabs: boolean;     // Replace #9 by apropriate amount of spaces (default is usually 8)     ShowPrefix: boolean;     // TextRect Only: Process first single '&' per                           //    line as an underscore and draw '&&' as '&'     Wordbreak : boolean;     // TextRect Only: If line of text is too long                           //    too fit between left and right boundaries                           //    try to break into multiple lines between                           //    words                             //    See also EndEllipsis.     Opaque    : boolean;     // TextRect: Fills background with current Brush                             // TextOut : Fills background with current                             //          foreground color     SystemFont: Boolean;     // Use the system font instead of Canvas Font        RightToLeft: Boolean;    //For RightToLeft text reading (Text Direction)     EndEllipsis: Boolean;    // TextRect Only: If line of text is too long                           //    to fit between left and right boundaries                           //    truncates the text and adds "..."                           //    If Wordbreak is set as well, Workbreak will                           //    dominate.  end; ---------------------------------------------------------------------- howardpc · 2018-03-23 11:58 DT_END_ELLIPSIS has no effect on Linux (gtk2), so it is no surprise that Carbon/Cocoa also lacks this functionality. Presumably it is just waiting for someone with the requisite widgetset knowledge to implement it. ---------------------------------------------------------------------- apeoperaio · 2018-03-23 12:20 Quote from: howardpc on March 23, 2018, 12:58:55 pmDT_END_ELLIPSIS has no effect on Linux (gtk2), so it is no surprise that Carbon/Cocoa also lacks this functionality. Presumably it is just waiting for someone with the requisite widgetset knowledge to implement it. Thanks for the info. ---------------------------------------------------------------------- balazsszekely · 2018-03-23 12:58 Did you try Canvas.TextWidth? If the width is bigger then the client area copy a sub string then add an ellipsis. You should also take into account the width of '...'