app: fix publically reported layout offset for a couple of cases

Move the code that adjusts the layout's x-offset for fixed-width text
boxes and RTL, centered- and right justified text. It was living in
gimp_text_layout_render() and was correctly applied at rendering time,
so everything looked fine. Move it to gimp_text_layout_position() so
it becomes part of the layout's permanent properties, is reported by
gimp_text_layout_get_offsets() and thus used by the text tool which
can draw cursor and selection at the right place.
This commit is contained in:
Michael Natterer 2010-03-11 20:50:16 +01:00
parent 4ba8de7625
commit 13cbdabcc3
2 changed files with 27 additions and 29 deletions

View File

@ -24,10 +24,6 @@
#include "text-types.h"
#include "base/pixel-region.h"
#include "base/tile-manager.h"
#include "gimptext.h"
#include "gimptextlayout.h"
#include "gimptextlayout-render.h"
@ -47,36 +43,13 @@ gimp_text_layout_render (GimpTextLayout *layout,
gimp_text_layout_get_offsets (layout, &x, &y);
pango_layout = gimp_text_layout_get_pango_layout (layout);
/* If the width of the layout is > 0, then the text-box is FIXED and
* the layout position should be offset if the alignment is centered
* or right-aligned, also adjust for RTL text direction.
*/
if (pango_layout_get_width (pango_layout) > 0)
{
PangoAlignment align = pango_layout_get_alignment (pango_layout);
gint width;
pango_layout_get_pixel_size (pango_layout, &width, NULL);
if ((base_dir == GIMP_TEXT_DIRECTION_LTR && align == PANGO_ALIGN_RIGHT) ||
(base_dir == GIMP_TEXT_DIRECTION_RTL && align == PANGO_ALIGN_LEFT))
{
x += PANGO_PIXELS (pango_layout_get_width (pango_layout)) - width;
}
else if (align == PANGO_ALIGN_CENTER)
{
x += (PANGO_PIXELS (pango_layout_get_width (pango_layout))
- width) / 2;
}
}
cairo_translate (cr, x, y);
gimp_text_layout_get_transform (layout, &trafo);
cairo_transform (cr, &trafo);
pango_layout = gimp_text_layout_get_pango_layout (layout);
if (path)
pango_cairo_layout_path (cr, pango_layout);
else

View File

@ -507,6 +507,31 @@ gimp_text_layout_position (GimpTextLayout *layout)
layout->extents.width = x2 - x1;
layout->extents.height = y2 - y1;
/* If the width of the layout is > 0, then the text-box is FIXED and
* the layout position should be offset if the alignment is centered
* or right-aligned, also adjust for RTL text direction.
*/
if (pango_layout_get_width (layout->layout) > 0)
{
PangoAlignment align = pango_layout_get_alignment (layout->layout);
GimpTextDirection base_dir = layout->text->base_dir;
gint width;
pango_layout_get_pixel_size (layout->layout, &width, NULL);
if ((base_dir == GIMP_TEXT_DIRECTION_LTR && align == PANGO_ALIGN_RIGHT) ||
(base_dir == GIMP_TEXT_DIRECTION_RTL && align == PANGO_ALIGN_LEFT))
{
layout->extents.x +=
PANGO_PIXELS (pango_layout_get_width (layout->layout)) - width;
}
else if (align == PANGO_ALIGN_CENTER)
{
layout->extents.x +=
(PANGO_PIXELS (pango_layout_get_width (layout->layout)) - width) / 2;
}
}
if (layout->text->border > 0)
{
gint border = layout->text->border;