text extension problem

View: New views
4 Messages — Rating Filter:   Alert me  

text extension problem

by Ricchetti, Andrea :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hi o all,

 

I’m a very new user in the “pango cairo world”

I’ve got a problem trying to get  the extension of a text usig Pango - Cairo.

I’ve made this function but the text of dimension returned is not correct, is small than the right (pixel) size.

 

void CPangoCairoWrapper::GetTextExtension(int *width, int *height)

{

            PangoAttribute *pa;

            PangoAttrList *pal;

 

            pal = pango_layout_get_attributes(m_pa_pLayout);

 

            if(!pal)

            {

                        pal = pango_attr_list_new();

                        pango_layout_set_attributes(m_pa_pLayout,pal);

                        pango_attr_list_unref(pal);

            };

 

            pa = pango_attr_size_new(m_sFontSize * PANGO_SCALE);

            pa = pango_attr_weight_new(m_pangoWeight);  

            pango_attr_list_change(pal, pa);

            pango_layout_set_attributes(m_pa_pLayout, pal);

 

            pango_layout_get_pixel_size(m_pa_pLayout, width, height);

};

 

where m_ … are member variable appropriately set.

I mean

 

PangoFontDescription   *m_pa_pFontDescr;

PangoLayout                 *m_pa_pLayout;

short                             m_sFontSize;

PangoWeight                m_pangoWeight;

 

Where

 

m_pa_pLayout  = pango_cairo_create_layout(m_ca_pCairo);

m_pa_pFontDescr = pango_font_description_new ();

 

m_strFont = "Sans"

m_sFontSize = 15;

m_pangoWeight = PANGO_WEIGHT_BOLD;

 

I’ve got also set font description and other things

 

pango_layout_set_text(m_pa_pLayout, “TEST”, -1);

pango_font_description_set_weight(m_pa_pFontDescr, PANGO_WEIGHT_BOLD);

pango_font_description_set_family(m_pa_pFontDescr,”Sans”);

pango_font_description_set_size(m_pa_pFontDescr, m_sFontSize*PANGO_SCALE);     

 

 

Could you tell me where is the error or if is a other, correct way, to get the text extension using pango –cairo.

 

Thanks in advance

Best regards

Andrea Ricchetti


_______________________________________________
gtk-i18n-list mailing list
gtk-i18n-list@...
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list

Re: text extension problem

by David E. Hollingsworth-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


pango_layout_get_size() returns the logical (layout) size.  It sounds
like you want the ink size (which pixels will be touched when
rendered).  To get the exact ink bounds, call
pango_layout_get_extents(), passing in a non-null ink_rect and a null
logical_rect.  pango_layout_get_pixel_extents() is a convenience
function that expands the result to pixel boundaries.  Look at the
implementations in pango-layout.c and you'll see the relationship
between these functions.

  --deh!

--
"I've just found the silverware and I'm sticking a fork in that square!" - N.H.
_______________________________________________
gtk-i18n-list mailing list
gtk-i18n-list@...
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list

R: text extension problem

by Ricchetti, Andrea :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I've try what you have suggested, but the value that I got from "your" function are the same of my function.
I've made some test, and I've found that the correct width and height value are these from

cairo_image_surface_create (CA_GetFormat(), _TextBoxWidth, _TextBoxHeight);

the base function that I've to invoked. I've made a program where these value (_TextBoxWidth, _TextBoxHeight) are output value.

Is this a correct way?

Thanks in advance.
Andrea

-----Messaggio originale-----
Da: David E. Hollingsworth [mailto:deh@...]
Inviato: martedì 4 agosto 2009 19.21
A: Ricchetti, Andrea
Cc: gtk-i18n-list@...
Oggetto: Re: text extension problem


pango_layout_get_size() returns the logical (layout) size.  It sounds
like you want the ink size (which pixels will be touched when
rendered).  To get the exact ink bounds, call
pango_layout_get_extents(), passing in a non-null ink_rect and a null
logical_rect.  pango_layout_get_pixel_extents() is a convenience
function that expands the result to pixel boundaries.  Look at the
implementations in pango-layout.c and you'll see the relationship
between these functions.

  --deh!

--
"I've just found the silverware and I'm sticking a fork in that square!" - N.H.
_______________________________________________
gtk-i18n-list mailing list
gtk-i18n-list@...
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list

Re: R: text extension problem

by David E. Hollingsworth-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


"Ricchetti, Andrea" <Andrea.Ricchetti@...> writes:

> I've made some test, and I've found that the correct width and
> height value are these from
>
> cairo_image_surface_create (CA_GetFormat(), _TextBoxWidth, _TextBoxHeight);

Perhaps someone else knows what you mean.  I'm not sure that I
understand.

It sounds like you want Pango to return the width & height that were
used to determine how the text was laid out (wrapped).  You can get
this from pango_layout_get_width() and pango_layout_get_height().  But
it seems like you must have set those values previously yourself.

There are three rectangles involved: the one used to lay out the text
(get_width/ get_height), the result of that layout (get_extents,
logical_rect or get_size), and the one that describes which pixels
will get painted (get_extents, ink_rect).  Each of these are in
PangoUnits, so they have fractional pixel values, and you might want
the values rounded up to whole pixels.  If what you want isn't one of
those 6 rectangles, then I don't know what it could be.

  --deh!

--
"I've just found the silverware and I'm sticking a fork in that square!" - N.H.
_______________________________________________
gtk-i18n-list mailing list
gtk-i18n-list@...
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list