[Pythonmac-SIG] PyObjC and Quartz - CGContextShowGlyphsAtPoint

Ronald Oussoren ronaldoussoren at mac.com
Mon Apr 29 08:50:25 CEST 2013


On 29 Apr, 2013, at 1:13, Rand Dvorak <randdvorak at gmail.com> wrote:

> 
> Hello, 
> 
> I was wondering if any would could help with a issue I'm having with some PyObjC and Quartz.  I have a class the creates a pdf contact sheet from a list of images.  I have the need to include bar codes along with each image.  On the sheet is text with the filename of each image and I need to add a barcoded filename along with it.  To this end I downloaded some barcode fonts and am trying to use CGContextDrawTextAtPoint(...) to draw the barcode but am not having any luck.  Through some research I determined that I need to call CGContextDrawGlyphsAtPoint(...) instead, but cannot figure how to get the glyphs to to draw.  I tried just using the bare string, but am getting this error.   
> 
>     CGContextShowGlyphsAtPoint(c, 5, 5, self.string.cStringUsingEncoding_(NSUTF8StringEncoding), len(self.string))
> ValueError: depythonifying 'unsigned short', got 'str'
> 
> Any ideas on how to achieve what I am trying to accomplish here?  Any info would be much appreciated.

A glyph array is different from a character array, you need to convert the string to a character array before calling CGContextShowGlyphsAtPoint. One of the examples in this stackoverflow question shows how to do this in Objective-C: http://stackoverflow.com/questions/4386367/drawing-text-with-core-graphics (look for CTFontGetGlyphsForCharacters).

Ronald

> 
> Thanks,
> 
> Rand
> 
> 
> _______________________________________________
> Pythonmac-SIG maillist  -  Pythonmac-SIG at python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig
> unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG



More information about the Pythonmac-SIG mailing list