Pango Interaction
Using Pango in GDK
gdkPangoRendererNew(screen)
gdkPangoRendererGetDefault(screen)
gdkPangoRendererSetDrawable(object, drawable = NULL)
gdkPangoRendererSetGc(object, gc = NULL)
gdkPangoRendererSetStipple(object, part, stipple)
gdkPangoRendererSetOverrideColor(object, part, color = NULL)
gdkPangoContextGet()
gdkPangoContextGetForScreen(screen)
gdkPangoContextSetColormap(context, colormap)
gdkPangoAttrEmbossColorNew(color)
gdkPangoAttrEmbossedNew(embossed)
gdkPangoAttrStippleNew(stipple)
gdkPangoLayoutGetClipRegion(layout, x.origin, index.ranges)
gdkPangoLayoutLineGetClipRegion(line, x.origin, index.ranges)
gdkPangoRenderer(screen)
GObject +----PangoRenderer +----GdkPangoRenderer
Pango is the text layout system used by GDK and GTK+. The functions and types in this section are used to render Pango objects to GDK. drawables, and also extend the set of Pango attributes to include stippling and embossing.
Creating a PangoLayout
object is the first step in rendering text,
and requires getting a handle to a PangoContext
. For GTK+ programs,
you'll usually want to use gtkWidgetGetPangoContext
, or
gtkWidgetCreatePangoLayout
, rather than using the lowlevel
gdkPangoContextGetForScreen
. Once you have a PangoLayout
, you
can set the text and attributes of it with Pango functions like
pangoLayoutSetText
and get its size with pangoLayoutGetSize
.
(Note that Pango uses a fixed point system internally, so converting
between Pango units and pixels using PANGO_SCALE or the pangoPixels()
function.)
Rendering a Pango layout is done most simply with gdkDrawLayout
;
you can also draw pieces of the layout with gdkDrawLayout
or
gdkDrawGlyphs
. GdkPangoRenderer
is a subclass of PangoRenderer
that is used internally to implement these functions. Using it
directly or subclassing it can be useful in some cases. See the
GdkPangoRenderer
documentation for details.
Using GdkPangoRenderer
to draw transformed text
window <- NULL RADIUS <- 150 N.WORDS <- 10 FONT <- "Sans Bold 27" rotated.text.expose.event <- function(widget, event, data) { ## matrix describing font transformation, initialize to identity matrix <- pangoMatrixInit() width <- widget[["allocation"]][["width"]] height <- widget[["allocation"]][["height"]] ## Get the default renderer for the screen, and set it up for drawing renderer <- gdkPangoRendererGetDefault(widget$getScreen()) renderer$setDrawable(widget[["window"]]) renderer$setGc(widget[["style"]][["blackGc"]]) ## Set up a transformation matrix so that the user space coordinates for ## the centered square where we draw are [-RADIUS, RADIUS], [-RADIUS, RADIUS] ## We first center, then change the scale device.radius <- min(width, height) / 2. matrix$translate(device.radius + (width - 2 * device.radius) / 2, device.radius + (height - 2 * device.radius) / 2) matrix$scale(device.radius / RADIUS, device.radius / RADIUS) ## Create a PangoLayout, set the font and text context <- widget$createPangoContext() layout <- pangoLayoutNew(context) layout$setText("Text") desc <- pangoFontDescriptionFromString(FONT) layout$setFontDescription(desc) # Draw the layout N.WORDS times in a circle for (i in 1:N.WORDS) { rotated.matrix <- matrix$copy() angle <- (360 * i) / N.WORDS color <- list() ## Gradient from red at angle 60 to blue at angle 300 color$red <- 65535 * (1 + cos((angle - 60) * pi / 180)) / 2 color$green <- 0 color$blue <- 65535 - color$red renderer$setOverrideColor("foreground", color) rotated.matrix$rotate(angle) context$setMatrix(rotated.matrix) ## Inform Pango to re-layout the text with the new transformation matrix layout$contextChanged() size <- layout$getSize() renderer$drawLayout(layout, - size$width / 2, - RADIUS * 1024) } ## Clean up default renderer, since it is shared renderer$setOverrideColor("foreground", NULL) renderer$setDrawable(NULL) renderer$setGc(NULL) return(FALSE) } white <- c( 0, "0xffff", "0xffff", "0xffff" ) window <- gtkWindowNew("toplevel") window$setTitle("Rotated Text") drawing.area <- gtkDrawingAreaNew() window$add(drawing.area) # This overrides the background color from the theme drawing.area$modifyBg("normal", white) gSignalConnect(drawing.area, "expose-event", rotated.text.expose.event) window$setDefaultSize(2 * RADIUS, 2 * RADIUS) window$showAll()
GdkPangoRenderer
GdkPangoRenderer
is a subclass of PangoRenderer
used for rendering
Pango objects into GDK drawables. The default renderer for a particular
screen is obtained with gdkPangoRendererGetDefault
; Pango
functions like pangoRendererDrawLayout
and
pangoRendererDrawLayoutLine
are then used to draw objects with
the renderer.
In most simple cases, applications can just use gdkDrawLayout
, and
don't need to directly use GdkPangoRenderer
at all. Using the
GdkPangoRenderer
directly is most useful when working with a
transformation such as a rotation, because the Pango drawing functions
take user space coordinates (coordinates before the transformation)
instead of device coordinates.
In certain cases it can be useful to subclass GdkPangoRenderer
. Examples
of reasons to do this are to add handling of custom attributes by
overriding 'prepare_run' or to do custom drawing of embedded objects
by overriding 'draw_shape'.
Since 2.6
GdkPangoAttrEmbossed
A Pango text attribute containing a embossed bitmap to be used when rendering the text.
embossed
[logical] the PangoAttribute
.
GdkPangoAttrStipple
A Pango text attribute containing a stipple bitmap to be used when rendering the text.
stipple
[GdkBitmap
] the PangoAttribute
.
gdkPangoRenderer
is the equivalent of gdkPangoRendererNew
.
screen
[GdkScreen
: * : Read / Write / Construct Only]the GdkScreen for the renderer.
Derived by RGtkGen from GTK+ documentation
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.