[futurebasic] Re: [FB] Font smoothing

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 2003 : Group Archive : Group : All Groups

From: Robert Purves <robert.purves@...>
Date: Sun, 16 Nov 2003 19:59:26 +1300
Waverly wrote:

>>> I recall their being a discussion about font smoothing.  Is there a  
>>> way to turn font smoothing on per window, per applications or is it 
>>> just on or off?
>>> W.
>>
>> RP  has a method which requires Tlbx CoreGraphics.Incl
>> See Antialiased Text in 10.1.5  Example, RP's donations , OSX folder
>> rc

> Thanks I'll check it out.


If you are drawing text with DrawText (or FB print), and want it drawn 
the OS X way via CoreGraphics, you can use either SwapQDTextFlags which 
was available in 10.1.5 but required some clumsy extra code,  or the 
preferred newer QDSwapTextFlags as in the demo below.

QDSwapTextFlags affects all windows in the app.

There is also
toolbox fn QDSwapPortTextFlags( CGrafPtr port, UInt32 newFlags ) = 
UInt32
which works the same as QDSwapTextFlags but on a per-port basis.  You 
can pass 0 for the port; this means "the current port".


An alternative approach that may be more suitable for your (unstated) 
needs is DrawThemeTextBox.


Robert P.


'-----------------

'~'A
'                       Runtime : Rntm Appearance.Incl
'                           CPU : Carbon
'~'B

/*
Antialiased text in OS X 10.2 or higher.
Robert P.  16 November 2003
*/


// AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER
toolbox fn QDSwapTextFlags( UInt32 newFlags ) = UInt32

_kQDUseTrueTypeScalerGlyphs   = (1 << 0)
_kQDUseCGTextRendering        = (1 << 1)
_kQDUseCGTextMetrics          = (1 << 2)

dim as UInt32  cgFlags, oldFlags, dummy

if ( system( _sysVers ) < 1020 ) then stop "Needs 10.2 or higher"
window 1, "untitled ABCXYZabcxyz!@#$%^&* CGText"
//  same font as window titles in OS X
text _sysFont, 13, , _srcOr
print

print "untitled ABCXYZabcxyz!@#$%^&* default" // default
print

cgFlags = _kQDUseTrueTypeScalerGlyphs || _kQDUseCGTextRendering¬
               || _kQDUseCGTextMetrics
oldFlags = fn QDSwapTextFlags( cgFlags )
print "untitled ABCXYZabcxyz!@#$%^&* CGText"
print

dummy = fn QDSwapTextFlags( oldFlags ) // restore default
print "untitled ABCXYZabcxyz!@#$%^&* default"

do
HandleEvents
until 0


/*
(These limitations apply to the obsolete SwapQDTextFlags. Unclear
if any have been removed in the newer QDSwapTextFlags    RP)

Limitations:

SrcOr is the only supported text transfer mode. In all other cases, we
fall back to the old QuickdrawText rendering.  Developers who need
special transfer mode effects need to draw the text into an offscreen
and use CopyBits (which is basically what QuickDrawText does, too, for
the other transfer modes).

Similarly, only bold and italic are supported as algorithmic styles
(when there is no intrinsic font for the type face). Outline and shadow
are not supported.

Underlines always are continuous lines, whereas QuickdrawText spares out
descenders.
*/
'-----------------------