gdk-Pango-Interaction         package:RGtk2         R Documentation

_P_a_n_g_o _I_n_t_e_r_a_c_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

     Using Pango in GDK

_M_e_t_h_o_d_s _a_n_d _F_u_n_c_t_i_o_n_s:

     '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)'

_H_i_e_r_a_r_c_h_y:

     GObject
        +----PangoRenderer
              +----GdkPangoRenderer 

_D_e_t_a_i_l_e_d _D_e_s_c_r_i_p_t_i_o_n:

     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()


_S_t_r_u_c_t_u_r_e_s:


     '_G_d_k_P_a_n_g_o_R_e_n_d_e_r_e_r' '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


     '_G_d_k_P_a_n_g_o_A_t_t_r_E_m_b_o_s_s_e_d' A Pango text attribute containing a
          embossed bitmap to be used when rendering the text.

          '_e_m_b_o_s_s_e_d' [logical] the 'PangoAttribute'.


     '_G_d_k_P_a_n_g_o_A_t_t_r_S_t_i_p_p_l_e' A Pango text attribute containing a stipple
          bitmap to be used when rendering the text.

          '_s_t_i_p_p_l_e' ['GdkBitmap'] the 'PangoAttribute'.


_C_o_n_v_e_n_i_e_n_t _C_o_n_s_t_r_u_c_t_i_o_n:

     'gdkPangoRenderer' is the equivalent of 'gdkPangoRendererNew'.

_P_r_o_p_e_r_t_i_e_s:


     '_s_c_r_e_e_n' ['_G_d_k_S_c_r_e_e_n' : _R_e_a_d / _W_r_i_t_e / _C_o_n_s_t_r_u_c_t _O_n_l_y] the
          GdkScreen for the renderer.


_A_u_t_h_o_r(_s):

     Derived by RGtkGen from GTK+ documentation

_R_e_f_e_r_e_n_c_e_s:

     <URL:
     http://developer.gnome.org/doc/API/2.0/gdk/gdk-Pango-Interaction.html>

