DrawChar() vs. CGShowTextAtPoint()
DrawChar() vs. CGShowTextAtPoint()
- Subject: DrawChar() vs. CGShowTextAtPoint()
- From: Matheau Dakoske <email@hidden>
- Date: Tue, 16 Sep 2003 13:17:34 -0700
I'm moving an application that currently uses Carbon QuickDraw to show
ASCII characters 32-255 on a grid. This app is being moved to Cocoa and
I would like to use CoreGraphics (or the Cocoa Framework) instead.
I'm finding it difficult to mimic the behavior of QD's DrawChar() or
DrawText() using CGShowTextAtPoint(). Can anyone let me know if this is
even possible or where I might find more information on how to do this?
I realize that I'm running into an encoding problem, and that
QuickDraw's method is both limited and in many cases incorrect. But for
the time-being, getting QD's functionality out of CG would be ideal.
I've included a link to view the results of these fruitless efforts and
some sample code (which has been simplified for easier reading) below.
Results of the following code snippets can be viewed here:
http://www.code-line.com/software/charproblems/
// QUICKDRAW CODE FOR DRAWING CHARACTERS
TextFont(famID);
TextFace(0);
TextSize([font pointSize]);
int i, j, x, y;
for (i = 0; i < numRows; i++) {
for (j = 0; j < numCols; j++) {
x = j * cellWidth;
y = i * cellHeight;
MoveTo(x, y);
DrawChar(i * 8 + j + 32);
}
}
}
//CORE GRAPHICS CODE FOR DRAWING CHARACTERS
CGContextRef cgRef = (CGContextRef)[[NSGraphicsContext
currentContext] graphicsPort];
CGContextSelectFont(cgRef, [[font fontName] cString], [font
pointSize], kCGEncodingMacRoman); //Also tried kCGEncodingFontSpecific
int i, j;
float x, y;
char c;
for (i = 0; i < numRows; i++) {
for (j = 0; j < numCols; j++) {
x = j * cellWidth;
y = i * cellHeight;
c = (char) i * 8 + j + 32;
CGContextShowTextAtPoint(cgRef, x, y, &c, 1);
}
}
}
I'd like to consider using NSAttributedString's "drawAtPoint:" to do
this as well, but I've found it has a few major problems for this
application:
1) The location of individual characters' baselines are
difficult/impossible to predict.
2) I can't seem to turn font substitution off.
3) I can't seem to get strings to draw themselves using special fonts
such as Webdings.
Any insight?
Thanks in advance,
Matheau
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.