PyObjC on Snow Leopard and Xcode 3.2.  I've been trying to draw some text into 
a PDF context with a custom barcode font.  I've tried translating this source, 
found here to Python:

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

And here is the relevant code for drawing the barcode:

class Barcode(Graphic):
                initialized = NO
                def __init__(self, rect, string, size):
                                self.string = string
                                self.font = None
                                self.size = size
                                if not self.initialized:
                                        fontpath = 
NSBundle.mainBundle().pathForResource_ofType_("FRE3OF9X", "TTF")
                                        datap = 
CGDataProviderCreateWithFilename(fontpath.UTF8String())
                                        self.font = 
CGFontCreateWithDataProvider(datap)
                                        #CGDataProviderRelease(datap)
                                        self.initialized = YES
                                Graphic.__init__(self, rect)
                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)

Getting this error:

CGContextShowGlyphsAtPoint(c, 0, 0, glyphs, length)
ValueError: depythonifying 'unsigned short', got 'str'

Can anybody point me in the right direction in how to properly prepare a data 
structure to pass to the CGContextShowGlyphsAtPoint(..) function.  Can I use 
ctypes?




Any help appreciated. Thanks.



_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG

Reply via email to