On May 11, 2006, at 4:21 PM, Andrea Suraci wrote:
Hi all,
I am trying to get the width of a text in Quartz through declares.
As per the tech note <http://developer.apple.com/qa/qa2001/
qa1051.html>, it is achieved by storing the current text position
p1.x, drawing the text in invisible mode, and taking the difference
between the new text position p2 and the old, that is textWidth =
(p2.X - p1.X)
The problem is with the function used to get the current text
position:
CGPoint CGContextGetTextPosition (
CGContextRef context
);
which returns a CGPoint.
Starting from Seth's great articles on ResExcellence, I translated
it to:
Declare Function CGContextGetTextPosition Lib
"Carbon" (CGContextRef as Integer) As CGPoint
where CGPoint is a 8-byte structure.
Nothing of what I tried so far seems to work as return type,
CGPoint, Memoryblock, Ptr, etc.
You can't declare a function to return a struct of size greater than
four bytes. Instead you use the following trick -- declare the
function with the return value as the first parameter. I explain
this in chapter 2 of my declares book at <http://www.declareSub.com/
>; see the section Platform-Specific Information: Macintosh.
Try this --
Declare Sub CGContextGetTextPosition Lib "Carbon" (returnValue as
Ptr, context as Integer)
Then call it as follows.
dim theContext as Integer = ...
dim thePoint as new MemoryBlock(8)
CGContextGetTextPosition thePoint, theContext
Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>