Re: Fighting with the size of a font



Here is just a small complete example for the question I had.
There is one more question - Im drawing the string at x=0; y=0,
but the string doesnt start at y=0, its lower .... why ? 
And even starting at a lower y-Position + according to get_pixel_size the height is 25, the string fits in my 20 pixel big row.



#include <gtkmm.h>

class MyWindow : public Gtk::Window
{
  public :
    MyWindow() : Gtk::Window(Gtk::WINDOW_TOPLEVEL)
    {
      realize();
      set_size_request(100, 100);
      set_resizable(false); 
      set_position(Gtk::WIN_POS_CENTER);
    }
    
  protected :
    bool on_expose_event(GdkEventExpose* event)
    {
      Glib::RefPtr<Gdk::GC> gc_               = Gdk::GC::create(get_window());
      Glib::RefPtr<Pango::Context> pango      = get_pango_context();
      Glib::RefPtr<Pango::Layout> pangoLayout = Pango::Layout::create(pango);
      
      int windowWidth, windowHeight;
      get_window()->get_size(windowWidth, windowHeight);
      Gdk::Color white;
      white.set("#FFFFFF");
      gc_->set_rgb_fg_color(white);
      get_window()->draw_rectangle(gc_, true, 0, 20, windowWidth, windowHeight);
      
      std::string markupText = 
        "<span font_family='Sans normal' foreground='black' size='12800'>TEXT text 123</span>";
      pangoLayout->set_markup(markupText);
      
      int width, height;
      pangoLayout->get_pixel_size(width, height);
      
      get_window()->draw_layout(gc_, 0, 0, pangoLayout);
   }
};

int main(int argc, char *argv[])
{
    Gtk::Main kit(argc, argv);

    MyWindow aWindow;
    aWindow.show_all();

    Gtk::Main::run(aWindow);
    return 0;
}



-------- Original-Nachricht --------
Datum: Wed, 14 Feb 2007 09:27:09 +0100
Von: thom_schu gmx de
An: gtkmm-list gnome org
CC: 
Betreff: Fighting with the size of a font

> Hi there,
> with the code :
> 
> markupText = "<span font_family='Sans normal' foreground='black'
> size='12800'>" + text + "</span>";
> pangoLayout->set_markup(markupText);
> int width, height;
> pangoLayout->get_pixel_size(width, height);
> 
> I expected a height of 12,5, but the height is 25.
> 
> And what does the 25 mean. I thought it is the height of the font in
> pixel.
> But I have a Row with a height of 20 pixel and the string fits into this
> row, although get_pixel_size tells me the height of the font is 25.
> (but its not 12,5 either, because the string almost fills the whole row,
> so it must be around 20)
> 
> thanks
> -- 
> Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten 
> Browser-Versionen downloaden: http://www.gmx.net/de/go/browser
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list

-- 
"Feel free" - 5 GB Mailbox, 50 FreeSMS/Monat ...
Jetzt GMX ProMail testen: www.gmx.net/de/go/mailfooter/promail-out



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]