在PyObjC中,当函数为void时,我可以传递None作为输出参数,然后在返回值中获取输出参数,但是当涉及到非void的函数时,我找不到它是如何完成的示例。我要做的是从已经启动的NSLayoutManager实例中获取下面函数中的GlyphBuffer。以下是目标c中的语法:
NSInteger numGlyphs = [layoutManager numberOfGlyphs];
NSGlyph *glyphs = (NSGlyph *)malloc(sizeof(NSGlyph) * (numGlyphs + 1));
[layoutManager getGlyphs:glyphs range:NSMakeRange(0, numGlyphs)];
[textStorage removeLayoutManager:layoutManager];
如您所见,glyphs是一个NSGlyphs数组,其长度由layoutManager numberOfGlyphs返回。我在python中使用了以下方法:
layoutManager.getGlyphsInRange_glyphs_properties_characterIndexes_bidiLevels_ (glyphsRange, None, None, None, None)
但是我没有得到glyph buffer作为返回,因为函数不是void,而是返回glyphBuffer中glyph的数量,如here所述。glyph缓冲区应该是不可配置的指针。我找不到将NSGlyph数组传递给第二个参数的方法。当我通过一个列表时,我得到一个回溯:
ValueError: depythonifying 'pointer', got 'list'
有人知道这是否可能,以及如何做到吗?你知道吗
谢谢
因为我试图在LayoutManager中提取glyphs的位置,所以我使用了LayoutManager的locationForGlyphAtIndex方法,它对我的目的起到了很好的作用。你知道吗
签出此博客
http://michaellynn.github.io/2015/08/08/learn-you-a-better-pyobjc-bridgesupport-signature/
它应该有一些例子,说明如何实现你所寻找的。你知道吗
相关问题 更多 >
编程相关推荐