Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Gtk+/Gnome Application Development
Prev Home Next

Text Item

GnomeCanvasText displays a text string. You can specify the coordinates of the string as an ordered pair; these coordinates will represent the location of the text's anchor. For example, if the "anchor" argument is set to GTK_ANCHOR_NORTH, the text item's coordinates will represent the location of the top-center of the item. That is, the text will be centered around the X position and begin just below the Y position. Possible anchor values are:










Affine transformation of GnomeCanvasText is not implemented very well. Because the X font model is inflexible and limited, there is no good way to rotate and otherwise transform rendered text. In antialiased mode the canvas item implements this in the only way it can: it draws the entire font to a GdkPixmap, then copies the pixmap to a GdkImage, then reads individual pixels out of the image into a client-side bitmap, then copies the characters to be displayed from the entire-font bitmap into a temporary buffer, then uses libart_lgpl to apply any affine transformations to this buffer, then copies the transformed buffer to the canvas RGB buffer. Finally the canvas copies the RGB buffer to the screen. Needless to say this is slower than molasses: an entire bitmap goes over the network more than once. Moreover, scaling and rotating fonts as bitmaps leads to a low quality image. If you try to use GnomeCanvasText with antialiased mode, you will probably notice this; if your canvas is slow to update, suspect the text item.

There are plans to fix the text item, using a new font abstraction called GnomeFont. However, Gnome 1.0 lacks this feature.

There is not a good solution to the problem; if your application allows it, you can get dramatic speed increases by creating your own text item that caches the entire-font bitmaps. However, if you don't reuse the same fonts often, caching will be useless. Another possibility is to abandon X fonts and use Type 1 fonts with a rasterization library like t1lib, but this limits the fonts available to you and adds a library dependency. You could also use True Type fonts with the FreeType library, or use the Display PostScript extension to X (XDPS).

Unfortunately, your best bet is probably to wait for the GnomeFont feature in a future version of the Gnome libraries.

Table 5. GnomeCanvasText Arguments

Name Type Read/Write Description
text gchar* Both String to display
x double Both X coordinate of the anchor point
y double Both Y coordinate of the anchor point
anchor GtkAnchorType Both Location of anchor point
font gchar* Write-only Font name for gdk_font_load()
fontset gchar* Write-only Fontset name for gdk_fontset_load()
font_gdk GdkFont* Both Font for rendering the text
justification GtkJustification Both Justification (multiline text only)
fill_color gchar* Write-only Fill color; string for gdk_color_parse(), or NULL for transparent
fill_color_gdk GdkColor* Both Fill color; specified as already-allocated GdkColor
fill_color_rgba guint32 Both Fill color; specified as 32-bit value packing red, green, blue, and alpha into bytes 1, 2, 3, and 4; alpha of 255 is opaque, 0 is invisible
fill_stipple GdkBitmap* Both Stipple to use when drawing text; GDK mode only
clip_width double Both Width of clip rectangle in canvas units
clip_height double Both Height of clip rectangle in canvas units
clip gboolean Both Enables or disables clipping
x_offset double Both Horizontal offset to add to X position
y_offset double Both Vertical offset to add to Y position
text_width double Read-only Width of rendered text
text_height double Read-only Height of rendered text
Gtk+/Gnome Application Development
Prev Home Next

  Published under free license. Design by Interspire