Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :
Old 02-06-2021, 05:37 AM   #1
Human being with feelings
stw's Avatar
Join Date: Apr 2012
Posts: 277
Default Center alligned text on mac

I just ran into a text allignment prob on mac.
Multi line text was not center alligned correctly for each line. Allignment was based on the widest text line and used for all other lines of an ITextControl. This is not the behaviour one would expect (and ugly as well). Win builds allign correctly.

I made a change at which corrects that. Maybe it's useful for someone else as well.

int DrawText(HDC ctx, const char *buf, int buflen, RECT *r, int align)


if (lines)
      int n=CFArrayGetCount(lines);
      int x;
        CTLineRef l = (CTLineRef)CFArrayGetValueAtIndex(lines,x);
        if (l)
          CGFloat asc=0,desc=0,lead=0;
          float lw=CTLineGetTypographicBounds(l,&asc,&desc,&lead);
          xo = r->left + (r->right-r->left)/2 - lw/2;    // add this line

          if (bgc)
            CGContextSetFillColorWithColor(ct->ctx, bgc);
            CGContextFillRect(ct->ctx, CGRectMake(xo,yo,lw,asc+desc+lead));
          CGContextSetTextPosition(ct->ctx, xo, yo + asc);
          yo += floor(asc+desc+lead+0.5);          
stw is offline   Reply With Quote
Old 02-10-2021, 01:55 PM   #2
Human being with feelings
Join Date: Apr 2018
Posts: 389

Thank you for posting this fix.
Nonlinear is offline   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -7. The time now is 09:11 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.