Hi,
Thanks for your answer. I think I have a wrong version of awesome (awesome debian/3.4.6-1 (Hooch)) because I didn't manage to install oopango and the textbox.lua is not the same as in your message. Anyway, I will use the function cr:show_text(), thank for the tip. It's for writing vertical text from bottom to top. It's quite easy with : cr:translate(w/2,h/2) cr:rotate(-math.pi/2) Browing the oocairo lib, I found theses functions : scaled_font_create, font_options_create, toy_font_face_create Do you know where I can find documentation on theses functions. I think I can change the font with them but didn't find how to do ! Forget that, I just found "man lua-oocairo" if someone has the same question ! I will read that now! I don't know if the text API is buggy but I had fun with it when I used it with Conky (http://wlourf.deviantart.com/gallery/28062900#/d36njc0 it's an example, not a conky). I've just had problems with "cairo_text_extents" method which is difficult too understand (for me). Thank again! ----- Mail original ----- > De : Uli Schlachter <psyc...@znc.in> > À : awesome@naquadah.org > Cc : > Envoyé le : Samedi 23 Juillet 2011 9h20 > Objet : Re: text with oocairo > > On 23.07.2011 00:24, W Wlourf wrote: >> I'm looking for an example for drawing a text with oocairo. Is it > possible ? > > Let's look at what awesome is doing (wibox/widget/textbox.lua): > > The "magic" starts in the function draw(). I'll inline all the > various functions > here, in the code there is more than one function, because similar code is > needed for getting the text extents: > > local l = oopango.cairo.layout_create(cr) -- We are drawing to this context > l:set_alignment("left") -- Align left (not right or center) > l:set_ellipsize("end") -- Shorten the text at the end if too long > l:set_wrap("word_char") -- Try wrapping at words, but use chars if > necessary > l;set_width(width) -- Available width for the text > l:set_height(height) -- Available height > l:set_font_description(beautiful.get_font("font name here, leave empty for > default") > if markup then > l:set_markup(text) > else > l:set_text(text) > end > > [Here comes some magic to align text vertically, can be found at the end of > setup_layout() if you really care] > > oopango.cairo.update_layout(cr, layout) > oopango.cairo.show_layout(cr, layout) > > And the text is drawn. :-) > > All the various set_foo() calls can be skipped to use the defaults. So if you > just want to say "Hi": > > local l = oopango.cairo.layout_create(cr) > l:set_text("Hi") > oopango.cairo.update_layout(cr, layout) > oopango.cairo.show_layout(cr, layout) > > > The difference between set_markup and set_text is that set_text doesn't > interpret pango markup. This means that <b>Hi</b> would be drawn > as-is by > set_text() while set_markup() would show "Hi" in bold. > > For the other set_foo() calls, check out the pango documentation: > > http://developer.gnome.org/pango/stable/pango-Layout-Objects.html > > This is what beautiful.get_font() basically does: > > return oopango.font_description_from_string(name) > > This is pango_font_description_from_string() in the C API: > > http://developer.gnome.org/pango/stable/pango-Fonts.html#pango-font-description-from-string > > > I hope this helps you with drawing text with oopango. May I ask what you are > trying to do? > > Uli > > P.S.: There was an API change in oopango. Your version might use > oopango.cairo_update_layout and oopango.cairo_show_layout instead of the above > version with an extra dot. > > P.P.S.: You asked about drawing text with oocairo. The cairo devs say their > text > API is only a toy and shouldn't be used, because it got lots of > shortcomings. If > you *really* want to draw text with oocairo, use: > cr:show_text("Hi") > > P.P.P.S: All the text drawing uses the current point for the text position. So > use cr:move_to(x, y) for positioning the text. > > -- > - Buck, when, exactly, did you lose your mind? > - Three months ago. I woke up one morning married to a pineapple. > An ugly pineapple... But I loved her. > > -- > To unsubscribe, send mail to awesome-unsubscr...@naquadah.org. > -- To unsubscribe, send mail to awesome-unsubscr...@naquadah.org.