Pango rotation



Hi all,

I am currently using cairomm (c++ bindings to cairo) to render some
graphs, but wanted to start including pangomm support for more
complicated text. One of the things I wanted to do was rotate text,
but I can't seem to get it to work. I first tried to use gravity to do
it and later also tried it with
layout->get_context()->set_matrix(...). I also tried setting it after
update_from_cairo_context, because I thought that might unset the
rotation, but that didn't seem to help either.

Furthermore I am interested in centering the text (instead of left
aligned). I tried to do this with set_alignment, but this also didn't
seem to work. I solved that by using get_pixel_size, but would still
be interested if this can be done in a better way.

I hope someone can help me. For sample code see below.

Cheers, BlackEdder

#include <string>
#include <iostream>
#include <cairomm/cairommconfig.h>
#include <cairomm/context.h>
#include <cairomm/surface.h>

#include <pangomm/init.h>
#include <pangomm/context.h>
#include <pangomm/layout.h>
int main()
{
    Cairo::RefPtr<Cairo::ImageSurface> surface =
        Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 600, 400);
    Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
    Pango::init();
    Glib::RefPtr<Pango::Layout> pangoLayout = Pango::Layout::create (cr);
    cr->move_to(300,200);
    cr->set_source_rgb(0, 0, 0);
    pangoLayout->get_context()->set_base_gravity( Pango::GRAVITY_WEST );
    pangoLayout->set_alignment( Pango::ALIGN_CENTER );
    pangoLayout->set_text("text");
    pangoLayout->update_from_cairo_context(cr);  //gets cairo cursor position
    pangoLayout->add_to_cairo_context(cr);       //adds text to cairos
stack of stuff to be drawn
    cr->stroke();
    std::string filename = "image.png";
    surface->write_to_png(filename);
    std::cout << "Wrote png file \"" << filename << "\"" << std::endl;
}


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