Message-ID: <44EE235F.2050809 at tin.it> Date: Fri, 25 Aug 2006 00:08:31 +0200 From: Stalkern 2 MIME-Version: 1.0 To: lablgtk at math.nagoya-u.ac.jp Subject: Re: how to put text in a drawing_area ? References: <16685.28897.429085.9744 at soggy.deldotd.com> <20040826.165052.74190188.garrigue at kurims.kyoto-u.ac.jp> In-Reply-To: <20040826.165052.74190188.garrigue at kurims.kyoto-u.ac.jp> Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-8859-1 Content-Length: 4256 Jacques GARRIGUE wrote: > From: briand at aracnet.com > >> Seems like a very simple thing and in fact gDraw.mli contains the >> following comment : >> >> >> (** Functions for drawing points, lines, arcs, and text >> at gtkdoc gdk gdk-Drawing-Primitives *) >> >> >> However there is no text method and I can't seem to trace out a link >> to the regular text widgets, nor can I find anything in the examples >> directory... > > You need to use the #put_layout method. > But for that you must first create a layout with: > > let layout = area#misc#pango_context#create_layout in > > Then you write in the layout, before drawing it: > > Pango.Layout.set_text layout "my text"; > drawable#put_layout layout ~x:10 ~y:10 > > Hope this helps. > > Jacques > > P.S. maybe we could add a simpler utility method... > Hello to everybody I'm plotting some stuff and of course I'm attempting to write the name of the Y values _vertically_ (not very original, is it?). The Gnome Developers' API says clearly "There is no way to draw scaled or rotated text with GDK." (http://developer.gnome.org/doc/GGAD/z132.html). However, a simple "rotation" like the one that I'm looking for can be done by swapping coords rather simply. Here is code in GTK/Python, by John Hunter (http://www.daa.com.au/pipermail/pygtk/2004-September/008660.html) ---->8---->8---->8---->8---->8---->8---->8---->8---->8---->8---->8---- def draw_text_rotated(self, x=50, y=100): """ Draw the text rotated 90 degrees """ gc = self.drawable.new_gc() inkRect, logicalRect = self.layout.get_pixel_extents() rect = inkRect l, b, w, h = rect # save the background imageBack = self.drawable.get_image(x, y, w, h) imageVert = self.drawable.get_image(x, y, h, w) # transform the vertical image, write it onto the renderer, # and draw the layout onto it imageFlip = gtk.gdk.Image(type=gtk.gdk.IMAGE_NORMAL, visual=self.drawable.get_visual(), width=w, height=h) if imageFlip is None or imageBack is None or imageVert is None: print >> sys.stderr, "Could not renderer vertical text", s return imageFlip.set_colormap(self.drawable.get_colormap()) for i in range(w): for j in range(h): imageFlip.put_pixel(i, j, imageVert.get_pixel(j,w-i-1) ) self.drawable.draw_image(gc, imageFlip, 0, 0, x, y, w, h) self.drawable.draw_layout(gc, x, y-b, self.layout) # now get that image and flip it vertical imageIn = self.drawable.get_image(x, y, w, h) imageOut = gtk.gdk.Image(type=gtk.gdk.IMAGE_NORMAL, visual=self.drawable.get_visual(), width=h, height=w) imageOut.set_colormap(self.drawable.get_colormap()) for i in range(w): for j in range(h): imageOut.put_pixel(j, i, imageIn.get_pixel(w-i-1,j) ) # draw the old background and the flipped text self.drawable.draw_image(gc, imageBack, 0, 0, x, y, w, h) self.drawable.draw_image(gc, imageOut, 0, 0, x, y, h, w) return True ----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<---- I don't see very much Pango here, but I've thought that one could draw to a temporary Gdk.image by means of a Pango layout, then use the get_pixel and put_pixel functions available for Gdk.images as the code above suggests, then put the "pseudo-rotated" image to the drawable with the plot. However, I'm in trouble: _I'm unable to bring the Pango.layout onto a Gdk.image. _if I bring the Pango.layout to a Gdk.pixmap, I'm in trouble with getting and putting pixel without too much overkill. Does anybody know what direction should I turn myself to, before getting sick with this? I've thought about the nice label rotation features available as of GTK+ 2.6, but I need the whole plot to be an image and I'm (still?) unable to bring a Gtk.label to a drawable. I hereby swear that it is not my fault if Y axes are plotted vertically, but of Mister Descartes AFAIK :-) ...thanks in advance for any hint! Ernesto