UnsafeMutablePointer 作为 PyObjC 中的输出参数

UnsafeMutablePointer as an output argument in PyObjC

在 PyObjC 中,当函数为空时,我可以将 None 作为输出参数传递,然后我将在 returned 值中获得输出参数,但是当涉及到一个函数时非无效我找不到它是如何完成的例子。我想要做的是从一个已经启动的 NSLayoutManager 实例中获取以下函数中的 GlyphBuffer。这是 Objective c 中的语法:

NSInteger numGlyphs = [layoutManager numberOfGlyphs];
NSGlyph *glyphs = (NSGlyph *)malloc(sizeof(NSGlyph) * (numGlyphs + 1)); 
[layoutManager getGlyphs:glyphs range:NSMakeRange(0, numGlyphs)];
[textStorage removeLayoutManager:layoutManager];

如您所见,字形是一个长度为 return 的 NSGlyph 数组,由 layoutManager numberOfGlyphs 编辑。我在 python:

中使用了以下方法
layoutManager.getGlyphsInRange_glyphs_properties_characterIndexes_bidiLevels_ (glyphsRange, None, None, None, None)

但我没有在 return 中获取字形缓冲区,因为该函数不是空的,而是 return 描述的 here 中字形缓冲区的字形数量。字形缓冲区应该是一个 UnsafeMutablePointer。我找不到将 NSGlyph 数组传递给第二个参数的方法。当我通过一个列表时,我得到一个回溯:

ValueError: depythonifying 'pointer', got 'list'

有谁知道这是否可行以及如何实现?

谢谢

查看此博客

http://michaellynn.github.io/2015/08/08/learn-you-a-better-pyobjc-bridgesupport-signature/

它应该有一些例子来说明如何完成你正在寻找的东西。

因为我试图在 LayoutManager 中提取字形的位置,所以我使用了 LayoutManager 的 locationForGlyphAtIndex 方法,它对我的​​目的来说效果很好。