[Lazarus] Lazarus Equivalent of GetCharABCWidths API call

Hess, Philip J pjhess at purdue.edu
Mon Feb 18 19:46:36 CET 2008


Hi Dominique,

You would implement TCarbonWidgetset.GetCharABCWidths in
carbonwinapi.inc. Then recompile carbon widgetset.

Then add LclIntf to your uses section. When you compile an app with the
Carbon widgetset it will now use the implemented function.

ABCStructs is used in winapi.inc, etc. so yes, it's a standard LCL
structure.

Two alternative strategies that do not involve modifying the Carbon
widgetset:

(1) You could determine why you need this function and rewrite the code
so that you don't need it anymore. I believe this is Felipe's
suggestion, although this requires that you understand what the code is
doing. If you're porting code, this may be more difficult than the next
strategy...

(2) Add a function named GetCharABCWidths to your unit or to a general
"Win API collection point" unit used by your units so that your code
calls that function instead of the LclIntf function. (Be sure to put
this unit in your uses _after_ LclIntf or Windows.) Then implement your
function however you want so that it works in a general way without
dependence on the underlying widgetset.

Using one of these strategies will also protect you in the event that
this function is removed from LclIntf. Sudden changes frequently occur
to the LCL so the less dependence on obscure Win API functions, the
better.

In one of my projects I used strategy (2) above to implement about 50
Win API functions in a platform-independent way, primarily using
existing LclIntf functions and RTL functions. This way I don't have to
implement them on each widgetset or, what's probably even more
difficult, persuade the Laz developers to add them to LclIntf and then
support them.

Thanks.

-Phil



-----Original Message-----
From: lazarus-bounces at lazarus.freepascal.org
[mailto:lazarus-bounces at lazarus.freepascal.org] On Behalf Of Dominique
Louis
Sent: Sunday, February 17, 2008 4:32 PM
To: General mailing list
Subject: Re: [Lazarus] Lazarus Equivalent of GetCharABCWidths API call

Hi Philip,
   So am I right in saying that ABCStructs is available as a native lcl 
struct?

I mainly need this for Mac OS X for now, but will need it for Linux 
further down the line.

So use TCarbonWidgetSet what unit do I need to include and do you have a

small example of using GetCharABCWidths in Mac OS X?

Thanks,


Dominique.

Hess, Philip J wrote:
> Hi Dominique,
> 
> The portable equivalent is in LclIntf, but it's not implemented in all
widgetsets. Last fall I was playing around with this function for
Carbon. Not sure where I left it but here's what I came up with. Maybe
you could implement it for non-win32 widgetsets.
> 
> Thanks.
> 
> function TCarbonWidgetSet.GetCharABCWidths(DC: HDC; p2, p3: UINT;
>   const ABCStructs): Boolean;
> type
>   TABCArray = array[0..255] of TABC;
>   PABCArray = ^TABCArray;
> var
>   ABCPtr   : PABCArray;
>   CharNum  : Integer;
>   CharStr  : string;
>   CharSize : TSize;
> begin
>   ABCPtr := PABCArray(@ABCStructs);
>   for CharNum := p2 to p3 do
>     begin
>     CharStr := Chr(CharNum);
>     GetTextExtentPoint(DC, PChar(CharStr), 1, CharSize);
>     ABCPtr^[CharNum-p2].abcA := 0;
>     ABCPtr^[CharNum-p2].abcB := CharSize.cx;
>     ABCPtr^[CharNum-p2].abcC := 0;
>     end;
>   Result := True;
> end;
> 
> 
> -----Original Message-----
> From: lazarus-bounces at lazarus.freepascal.org on behalf of Dominique
Louis
> Sent: Sun 2/17/2008 1:40 PM
> To: General mailing list
> Subject: [Lazarus] Lazarus Equivalent of GetCharABCWidths API call
>  
> Hi All,
>    What is the portable equivalent of the Win32 GetCharABCWidths API
call?
> 
> Would Canvas.TextWidth be enough?
> 
> Thanks,
> 
> 
> Dominique.


_______________________________________________
Lazarus mailing list
Lazarus at lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus




More information about the Lazarus mailing list