TIP 119: Angled Text on a Canvas

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2017 Conference, Houston/TX, US, Oct 16-20
Send your abstracts to tclconference@googlegroups.com
by Aug 21.
Author:         Simon Geard <simon.geard@ntlworld.com>
Author:		Donal K. Fellows <donal.k.fellows@manchester.ac.uk>
State:          Final
Type:           Project
Vote:           Done
Created:        18-Nov-2002
Post-History:   
Tcl-Version:    8.6

Abstract

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.

Rationale

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.

Implementation

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.

Reference Implementation

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 http://sf.net/tracker/?func=detail&aid=1611359&group_id=12997&atid=312997 ) 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.

Implementation Notes

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.

Classic X11: Uses a general monochrome pixmap rotation engine.

X11 + Xft: Generates rotated versions of the fonts by installing a rotation matrix, caching them in the subfont management engine.

Win32: Generates rotated versions of the fonts using the built-in font rotation suport, caching them in the subfont management engine.

MacOS X: Applies the rotation to the Current Transformation Matrix immediately before rendering.

Copyright

This document has been placed in the public domain.

History