[MacRuby-devel] How to set up and retrieve returned buffer from CTFrameGetLineOrigins?

Matt Aimonetti mattaimonetti at gmail.com
Thu May 6 20:08:52 PDT 2010


Duly noted ;)

Sent from my iPhone

On May 6, 2010, at 20:06, "Jordan K. Hubbard" <jkh at apple.com> wrote:

>
> On May 6, 2010, at 8:03 PM, Laurent Sansonetti wrote:
>
>> You're right, the Pointer class must be used. Sorry about the lack  
>> of documentation. Here is a snippet that might work:
>>
>> # n must be defined
>> origins = Pointer.new(CGPoint.type, n) # this builds a pointer to n  
>> times CGPoint
>> CTFrameGetLineOrigins(frame, CFRange.new(0, n), origins)
>>
>>> 2. How to access the individual CGPoints in the returned buffer?  
>>> This is not an Objective-C / MacRuby array object. It is just an  
>>> address to a buffer. Easy to do in C, but how to do in MacRuby?
>>
>> Using Pointer#[] you can simply dereference a given slot in the  
>> pointer, as in C.
>>
>> n.times { |i| p origins[i] } # should print nth points
>>
>> Let me know if this works or not for you.
>
> If it does, I can see this being a useful entry in Matt's book!
>
> - Jordan
>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


More information about the MacRuby-devel mailing list