Drawing a matrix of colored characters

Discussion in 'Mac Programming' started by lucmoulinier, Dec 1, 2011.

  1. lucmoulinier macrumors newbie

    Nov 30, 2011
    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 :
    for (j=startY;j<startY+linesPerPage;j++) {
    for (i=startX;i<startX+charsPerLine;i++) {
    c = T[j];
    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 :
    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 !! ;-)

  2. kainjow Moderator emeritus


    Jun 15, 2000
    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().
  3. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    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.


Share This Page