Recent

Author Topic: TextOut and DrawText EndEllipsis does not work on OSX  (Read 3326 times)

apeoperaio

  • Sr. Member
  • ****
  • Posts: 273
TextOut and DrawText EndEllipsis does not work on OSX
« on: March 23, 2018, 09:11:28 am »
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][+][-]
  1. procedure TForm1.FormPaint(Sender: TObject);
  2. var
  3.   strtext: string;
  4.   ts: TTextStyle;
  5.   TextBox: TRect;
  6. begin
  7.   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.';
  8.  
  9.   ts:= Canvas.TextStyle;
  10.   ts.EndEllipsis:= True;
  11.   TextBox := Rect(0, 0, 50, High(Integer));
  12.   Canvas.TextRect(TextBox, 0, 0, strtext, ts);
  13.  
  14.  
  15.   Canvas.TextOut(0,0,strtext);
  16.  
  17.   TextBox := Rect(0, 20, 50, High(Integer));
  18.   DrawText(Canvas.Handle, PChar(strtext), Length(strtext),
  19.     TextBox, DT_END_ELLIPSIS or DT_CALCRECT);
  20.  
  21.   DrawText(Canvas.Handle, PChar(strtext), Length(strtext),
  22.     TextBox, DT_END_ELLIPSIS);
  23. end;  

Any hints?

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TextOut and DrawText EndEllipsis does not work on OSX
« Reply #1 on: March 23, 2018, 10:17:57 am »
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][+][-]
  1. procedure TForm1.PaintBox1Paint(Sender: TObject);
  2. var
  3.   ts: TTextStyle;
  4.   R: TRect;
  5. begin
  6.   ts := Paintbox1.Canvas.TextStyle;
  7.   ts.EndEllipsis := true;
  8.   ts.WordBreak := false;
  9.   Paintbox1.Canvas.TextStyle := ts;
  10.   R := Rect(0, 0, Paintbox1.Width, Paintbox1.Height);
  11.   Paintbox1.Canvas.TextRect(R, R.Left, R.Top, 'this is a long, long, long text', ts);
  12. end;  

This is the declaration of TTextStyle in unit graphics:

Code: Pascal  [Select][+][-]
  1. type
  2.   { Reflects text style when drawn in a rectangle }
  3.  
  4.   TTextLayout = (tlTop, tlCenter, tlBottom);
  5.   TTextStyle = packed record
  6.     Alignment : TAlignment;  // TextRect Only: horizontal alignment
  7.  
  8.     Layout    : TTextLayout; // TextRect Only: vertical alignment
  9.  
  10.     SingleLine: boolean;     // If WordBreak is false then process #13, #10 as
  11.                              // standard chars and perform no Line breaking.
  12.  
  13.     Clipping  : boolean;     // TextRect Only: Clip Text to passed Rectangle
  14.  
  15.     ExpandTabs: boolean;     // Replace #9 by apropriate amount of spaces (default is usually 8)
  16.  
  17.     ShowPrefix: boolean;     // TextRect Only: Process first single '&' per
  18.                              //    line as an underscore and draw '&&' as '&'
  19.  
  20.     Wordbreak : boolean;     // TextRect Only: If line of text is too long
  21.                              //    too fit between left and right boundaries
  22.                              //    try to break into multiple lines between
  23.                              //    words
  24.                              //    See also EndEllipsis.
  25.  
  26.     Opaque    : boolean;     // TextRect: Fills background with current Brush
  27.                              // TextOut : Fills background with current
  28.                              //            foreground color
  29.  
  30.     SystemFont: Boolean;     // Use the system font instead of Canvas Font
  31.    
  32.     RightToLeft: Boolean;    //For RightToLeft text reading (Text Direction)
  33.  
  34.     EndEllipsis: Boolean;    // TextRect Only: If line of text is too long
  35.                              //    to fit between left and right boundaries
  36.                              //    truncates the text and adds "..."
  37.                              //    If Wordbreak is set as well, Workbreak will
  38.                              //    dominate.
  39.   end;

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TextOut and DrawText EndEllipsis does not work on OSX
« Reply #2 on: March 23, 2018, 12:58:55 pm »
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

  • Sr. Member
  • ****
  • Posts: 273
Re: TextOut and DrawText EndEllipsis does not work on OSX
« Reply #3 on: March 23, 2018, 01:20:15 pm »
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.

Thanks for the info.

balazsszekely

  • Guest
Re: TextOut and DrawText EndEllipsis does not work on OSX
« Reply #4 on: March 23, 2018, 01:58:20 pm »
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 '...'

 

TinyPortal © 2005-2018