PDA

View Full Version : Drawing a matrix of colored characters




lucmoulinier
Dec 1, 2011, 02:41 AM
Hello !

I need help by a guru in ATSU/text drawing !
I'm porting an app written in C to Mac.
This app draws aligned protein sequences, i.e. a succession of letters (20 letters + '.'). Each letter has a foreground and a background color (F white fg, red bg). The font is ALWAYS the same for all characters and is a fixed font like Courier. My app consists in drawing a matrix of colored characters in a single font, the characters being drawn depend on the position of the scrollbars.
The inner drawing loop is someething like :
y=y0;
for (j=startY;j<startY+linesPerPage;j++) {
x=x0;
for (i=startX;i<startX+charsPerLine;i++) {
c = T[j][i];
fg = FgColor[c];
bg = BgColor[c];
<DrawText(context, layout, c, fg, bg, x, y,font)>
}
}

The routines to draw text are :
Unix :
-with Xft enabled :
XftDrawRect, XftDrawString8
-without Xft :
XDrawImageString
Windows :
- set drawable context SetBkColor(hdc,bg) , SetTextColor(hdc, fg)
- print text : TextOut(hdc,x, y, string, length)

For sake of compatibility, I must use the ATSUI framework.

Can someone explain me how to achieve this ?
- where goes the foreground/background color ? in the style or layout ?
- should I use ATSUDrawText ?
- where should I initialise the layout ?

Thanks for your help ! Please unserstand that I'm primarily a biologist, and that I can't learn all drawing API !! ;-)

Luc



kainjow
Dec 1, 2011, 10:45 PM
For sake of compatibility, I must use the ATSUI framework.

What's the oldest OS you have to support? ATSUDrawText and friends are deprecated as of 10.6, and it's part of QuickDraw, which AFAIK is completely removed when targeting 10.7, so you really should avoid it for any new development.

CoreGraphics has functions for drawing text that aren't deprecated and go back to 10.0, e.g. CGContextShowText().

chown33
Dec 1, 2011, 11:48 PM
If Xft is a standard part of X11, maybe you should build and run your program under X11. Even if Xft is a library added to X11, it could still make sense to build and run under X11.

Main advantage: X11 source-level compatibility.
Main disadvantage: it won't look like a native Mac OS X app.

You have to decide if the disadvantages are an acceptable compromise for the advantages. Especially if you mainly want to use the program, rather than distribute it.

X11.app is located in /Applications/Utilities. It's usually installed by default (10.4 - 10.6). It may not be installed by default on 10.7 Lion. Or it may not be in /Applications/Utilities.

http://developer.apple.com/library/mac/#documentation/Porting/Conceptual/PortingUnix/unix_environments/unix_environments.html