TIP: | 119 |
Title: | Angled Text on a Canvas |
Version: | $Revision: 1.8 $ |
Authors: |
Simon Geard <simon dot geard at ntlworld dot com> Donal K. Fellows <donal dot k dot fellows at manchester dot ac dot uk> |
State: | Final |
Type: | Project |
Tcl-Version: | 8.6 |
Vote: | Done |
Created: | Monday, 18 November 2002 |
The current text object on a canvas does not support the creation of text strings at an arbitrary angle. For some applications this is limitation is sufficiently serious to disqualify Tk from use. This TIP removes this restriction.
Using a Tk canvas to display e.g. an engineering drawing from a CAD application is limited - such applications will output angled text and there is simply no way of displaying such text on a canvas.
Another consideration is the competition. Both Qt and Java canvas objects support angled text on their canvas object - most new users would I believe be surprised to discover that this functionality is not supported.
Due to the internal architecture of Tk a side effect of this work would be to enable buttons (and possibly other widgets) to have their text written at an angle as well. This TIP does not expose that functionality.
At the command level there would be an extra attribute, -angle, added to the canvas's text object:
<canvas> create text <x> <y> -text <str> ?-angle <angle>? ...
where the angle is specified in degrees. Manipulation of the angle would be done in the usual way through the itemconfigure and itemcget subcommands:
<canvas> itemconfigure <tag> -angle <angle>
Note that PostScript naturally supports rotation of text.
I have done an initial assessment of the amount of work required and have and have created a patch to implement it in Tk 8.4.5 . This initial work was fairly straightforward but the internal housekeeping work maintaining and interacting with an angled box will be more substantial. The patch (uploaded to SourceForge [1]) is for X only. It doesn't use any X extensions and should work for X11R3 and above. I don't know how it would be done on non-X systems but hopefully they'll (Win & MacOS at least) provide native tools to make their implementation straightforward as well.
The implementation was tricky to develop, because it was wholly different on each rendering platform (X11 is two, depending on which font rendering engine is used). This delayed implementation of this TIP for a whole release.
Uses a general monochrome pixmap rotation engine.
Generates rotated versions of the fonts by installing a rotation matrix, caching them in the subfont management engine.
Generates rotated versions of the fonts using the built-in font rotation suport, caching them in the subfont management engine.
Applies the rotation to the Current Transformation Matrix immediately before rendering.
This document has been placed in the public domain.
[Index] [History] [HTML Format] [Source Format] [LaTeX Format] [Text Format] [XML Format] [*roff Format (experimental)] [RTF Format (experimental)]
TIP AutoGenerator - written by Donal K. Fellows