Font methods, rotating text

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Font methods, rotating text

Louis Sumberg-2
Here are a couple of methods to make it easier to rotate text.  I see that
most of this is in a newsgroup post by Bill Schwabb (5/7/98 re: vertical
text).

Font>>angle
    "Answer a <number> identifying the angle rotation, in degrees, of the
receiver."
    ^logfont lfEscapement / 10

Font>>angle: aNumber
    "Set the <number> angle rotation character effect, where aNumber is in
degrees."
    aNumber = self angle
        ifFalse:
            [logfont lfEscapement: (10 * aNumber) asInteger.
            "Cause the receiver to be re-realized"
            self free]

The implementation uses the Windows logfont lfEscapement attribute, which is
in tenths of a degree, hence the 10 in both methods.  Here's an example you
can try from a workspace -- evaluate all of the following:

canvas := Shell show view extent: 300@325; canvas.
canvas font: (Font name: 'Arial' pointSize: 12).
(15 to: 360 by: 90) do: [:angle |
    canvas
        font: (canvas font angle: angle);
        text: angle displayString, ' degrees rotation' at: 150@150]

Note the second line changes the font to Arial, which is a TrueType font.
This is because rotation, just like many other font attributes, can only be
set for TrueType fonts.  For example, if you change 'Arial' to 'System' or
'MS Sans Serif', the example won't work.  Set it to 'Times New Roman' and it
does.

The following method tells you if an installed font is TrueType or not.  By
installed I mean a Canvas instance's font.

Canvas>>hasTrueTypeFont
    "Answer true if the receiver's font is a TrueType font, else false."
    ^(self textMetrics tmPitchAndFamily bitAnd: 4) = 4

To test this, evaluate and display the following in a workspace:

canvas := Shell show view extent: 300@325; canvas.
canvas hasTrueTypeFont. "returns false"
canvas font: (Font name: 'Arial' pointSize: 12).
canvas hasTrueTypeFont. "returns true"

-- Louis