[Pythonmac-SIG] PyObjC and Quartz - CGContextShowGlyphsAtPoint

Rand Dvorak randdvorak at gmail.com
Mon Apr 29 16:15:03 CEST 2013


See the second message with more specifics and code, I was able to get it working by translating this objective-c code:  

http://www.gogo-robot.com/2009/06/07/two-awkward-things-about-iphone-development/

into this code:

def draw(self,c):
	length = len(self.string)
	glyphs = objc.allocateBuffer(length)
	chars = objc.allocateBuffer(length + 1)
	self.string.getCString_maxLength_encoding_(chars, length + 1, NSASCIIStringEncoding)
	for i in range(length):
		glyphs[i] = chr(ord(chars[i]) - 29)
	CGContextSaveGState(c)
	CGContextSetFont(c, self.font)
	CGContextSetFontSize(c, self.size)
	CGContextSetRGBFillColor(c, 0, 0, 0, 1)
	CGContextSetRGBStrokeColor (c, 0, 0, 0, 1)
	CGContextSetTextMatrix (c, self.xform)
	CGContextShowGlyphsAtPoint(c, 0, 0, glyphs, length)
	CGContextRestoreGState(c)

changing:
	CGContextShowGlyphsAtPoint(c, 0, 0, glyphs, length)

to:
	CGContextShowGlyphsAtPoint(c, 0, 0, tuple(map(ord, glyphs)), length)

Sadly, CTFontGetGlyphsForCharacters(...), doesn't seem to be in the bridgesupport on 10.6 and I still need to support it.  A CGGlyph is apparently an unsigned short, so a char array returned by objc.allocateBuffer() seems to suffice.

Thanks for your help.  



	
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythonmac-sig/attachments/20130429/28c99769/attachment.html>


More information about the Pythonmac-SIG mailing list