Commit 2409d06d authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

app/text/Makefile.am removed this header file.

2008-11-04  Sven Neumann  <sven@gimp.org>

	* app/text/Makefile.am
	* app/text/gimptext-private.h: removed this header file.

	* app/text/gimptextlayout.[ch]: added getters to access the
	resolution, text and PangoLayout.

	* app/text/gimptextlayout-render.c
	* app/tools/gimptexttool.c: use the new getters instead of 
poking
	into the GimpTextLayout struct.


svn path=/trunk/; revision=27543
parent 7dc80b79
2008-11-04 Sven Neumann <sven@gimp.org>
* app/text/Makefile.am
* app/text/gimptext-private.h: removed this header file.
* app/text/gimptextlayout.[ch]: added getters to access the
resolution, text and PangoLayout.
* app/text/gimptextlayout-render.c
* app/tools/gimptexttool.c: use the new getters instead of poking
into the GimpTextLayout struct.
2008-11-04 Sven Neumann <sven@gimp.org>
* app/text/Makefile.am
......
......@@ -32,7 +32,6 @@ libapptext_a_sources = \
gimptext-compat.h \
gimptext-parasite.c \
gimptext-parasite.h \
gimptext-private.h \
gimptext-vectors.c \
gimptext-vectors.h \
gimptext-xlfd.c \
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpText
* Copyright (C) 2002-2003 Sven Neumann <sven@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_TEXT_LAYOUT_PRIVATE_H__
#define __GIMP_TEXT_LAYOUT_PRIVATE_H__
/* The purpose of this extra header file is to hide any Pango or
* Cairo types from the rest of the gimp core.
*/
struct _GimpTextLayout
{
GObject object;
GimpText *text;
gdouble xres;
gdouble yres;
PangoLayout *layout;
PangoRectangle extents;
};
struct _GimpTextLayoutClass
{
GObjectClass parent_class;
};
#endif /* __GIMP_TEXT_LAYOUT_PRIVATE_H__ */
......@@ -29,7 +29,6 @@
#include "base/tile-manager.h"
#include "gimptext.h"
#include "gimptext-private.h"
#include "gimptextlayout.h"
#include "gimptextlayout-render.h"
......@@ -43,6 +42,7 @@ gimp_text_layout_render (GimpTextLayout *layout,
cairo_t *cr,
gboolean path)
{
PangoLayout *pango_layout;
cairo_matrix_t trafo;
gint x, y;
......@@ -51,26 +51,28 @@ 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*/
if (pango_layout_get_width (layout->layout) > 0)
if (pango_layout_get_width (pango_layout) > 0)
{
gint width;
pango_layout_get_pixel_size (layout->layout, &width, NULL);
pango_layout_get_pixel_size (pango_layout, &width, NULL);
switch (pango_layout_get_alignment (layout->layout))
switch (pango_layout_get_alignment (pango_layout))
{
case PANGO_ALIGN_LEFT:
break;
case PANGO_ALIGN_RIGHT:
x += PANGO_PIXELS (pango_layout_get_width (layout->layout)) - width;
x += PANGO_PIXELS (pango_layout_get_width (pango_layout)) - width;
break;
case PANGO_ALIGN_CENTER:
x += (PANGO_PIXELS (pango_layout_get_width (layout->layout))
x += (PANGO_PIXELS (pango_layout_get_width (pango_layout))
- width) / 2;
break;
}
......@@ -82,9 +84,9 @@ gimp_text_layout_render (GimpTextLayout *layout,
cairo_transform (cr, &trafo);
if (path)
pango_cairo_layout_path (cr, layout->layout);
pango_cairo_layout_path (cr, pango_layout);
else
pango_cairo_show_layout (cr, layout->layout);
pango_cairo_show_layout (cr, pango_layout);
}
......@@ -92,8 +94,14 @@ static void
gimp_text_layout_render_trafo (GimpTextLayout *layout,
cairo_matrix_t *trafo)
{
GimpText *text = layout->text;
const gdouble norm = 1.0 / layout->yres * layout->xres;
GimpText *text = gimp_text_layout_get_text (layout);
gdouble xres;
gdouble yres;
gdouble norm;
gimp_text_layout_get_resolution (layout, &xres, &yres);
norm = 1.0 / yres * xres;
trafo->xx = text->transformation.coeff[0][0] * norm;
trafo->xy = text->transformation.coeff[0][1] * 1.0;
......
......@@ -32,10 +32,21 @@
#include "core/gimpunit.h"
#include "gimptext.h"
#include "gimptext-private.h"
#include "gimptextlayout.h"
struct _GimpTextLayout
{
GObject object;
GimpText *text;
gdouble xres;
gdouble yres;
PangoLayout *layout;
PangoRectangle extents;
};
static void gimp_text_layout_finalize (GObject *object);
static void gimp_text_layout_position (GimpTextLayout *layout);
......@@ -228,6 +239,7 @@ gimp_text_layout_get_size (GimpTextLayout *layout,
if (width)
*width = layout->extents.width;
if (height)
*height = layout->extents.height;
......@@ -243,10 +255,41 @@ gimp_text_layout_get_offsets (GimpTextLayout *layout,
if (x)
*x = layout->extents.x;
if (y)
*y = layout->extents.y;
}
void
gimp_text_layout_get_resolution (GimpTextLayout *layout,
gdouble *xres,
gdouble *yres)
{
g_return_if_fail (GIMP_IS_TEXT_LAYOUT (layout));
if (xres)
*xres = layout->xres;
if (yres)
*yres = layout->yres;
}
GimpText *
gimp_text_layout_get_text (GimpTextLayout *layout)
{
g_return_val_if_fail (GIMP_IS_TEXT_LAYOUT (layout), NULL);
return layout->text;
}
PangoLayout *
gimp_text_layout_get_pango_layout (GimpTextLayout *layout)
{
g_return_val_if_fail (GIMP_IS_TEXT_LAYOUT (layout), NULL);
return layout->layout;
}
static void
gimp_text_layout_position (GimpTextLayout *layout)
{
......
......@@ -30,17 +30,28 @@
typedef struct _GimpTextLayoutClass GimpTextLayoutClass;
GType gimp_text_layout_get_type (void) G_GNUC_CONST;
GimpTextLayout * gimp_text_layout_new (GimpText *text,
GimpImage *image);
gboolean gimp_text_layout_get_size (GimpTextLayout *layout,
gint *width,
gint *heigth);
void gimp_text_layout_get_offsets (GimpTextLayout *layout,
gint *x,
gint *y);
struct _GimpTextLayoutClass
{
GObjectClass parent_class;
};
GType gimp_text_layout_get_type (void) G_GNUC_CONST;
GimpTextLayout * gimp_text_layout_new (GimpText *text,
GimpImage *image);
gboolean gimp_text_layout_get_size (GimpTextLayout *layout,
gint *width,
gint *heigth);
void gimp_text_layout_get_offsets (GimpTextLayout *layout,
gint *x,
gint *y);
void gimp_text_layout_get_resolution (GimpTextLayout *layout,
gdouble *xres,
gdouble *yres);
GimpText * gimp_text_layout_get_text (GimpTextLayout *layout);
PangoLayout * gimp_text_layout_get_pango_layout (GimpTextLayout *layout);
#endif /* __GIMP_TEXT_LAYOUT_H__ */
......@@ -44,7 +44,6 @@
#include "text/gimptextlayer.h"
#include "text/gimptextlayout.h"
#include "text/gimptextundo.h"
#include "text/gimptext-private.h"
#include "vectors/gimpvectors-warp.h"
......@@ -794,18 +793,21 @@ gimp_text_tool_key_press (GimpTool *tool,
case GDK_Down:
case GDK_KP_Down:
{
gint line;
gint line_index;
gint trailing;
PangoLayout *layout;
PangoLayoutLine *layout_line;
PangoLayoutIter *layout_iter;
PangoRectangle logical;
gint line;
gint line_index;
gint trailing;
gint i;
layout = gimp_text_layout_get_pango_layout (text_tool->layout);
line = gtk_text_iter_get_line (&selection);
line_index = gtk_text_iter_get_line_index (&selection);
layout_iter = pango_layout_get_iter (text_tool->layout->layout);
layout_iter = pango_layout_get_iter (layout);
for (i = 0; i < line; i++)
pango_layout_iter_next_line (layout_iter);
......@@ -844,8 +846,7 @@ gimp_text_tool_key_press (GimpTool *tool,
line++;
}
layout_line = pango_layout_get_line_readonly (text_tool->layout->layout,
line);
layout_line = pango_layout_get_line_readonly (layout, line);
if (! layout_line)
{
......@@ -865,7 +866,7 @@ gimp_text_tool_key_press (GimpTool *tool,
break;
}
layout_iter = pango_layout_get_iter (text_tool->layout->layout);
layout_iter = pango_layout_get_iter (layout);
for (i = 0; i < line; i++)
pango_layout_iter_next_line (layout_iter);
......@@ -1032,6 +1033,7 @@ gimp_text_tool_draw (GimpDrawTool *draw_tool)
gint y1, y2;
gint logical_off_x = 0;
gint logical_off_y = 0;
PangoLayout *layout;
PangoRectangle ink_extents;
PangoRectangle logical_extents;
GtkTextIter start;
......@@ -1064,8 +1066,9 @@ gimp_text_tool_draw (GimpDrawTool *draw_tool)
cliprect.height = y2 - y1;
gimp_draw_tool_set_clip_rect (draw_tool, &cliprect, FALSE);
pango_layout_get_pixel_extents (text_tool->layout->layout,
&ink_extents, &logical_extents);
layout = gimp_text_layout_get_pango_layout (text_tool->layout);
pango_layout_get_pixel_extents (layout, &ink_extents, &logical_extents);
if (ink_extents.x < 0)
logical_off_x = -ink_extents.x;
......@@ -1099,7 +1102,7 @@ gimp_text_tool_draw (GimpDrawTool *draw_tool)
g_free (string);
pango_layout_index_to_pos (text_tool->layout->layout, cursorx, &crect);
pango_layout_index_to_pos (layout, cursorx, &crect);
crect.x = PANGO_PIXELS (crect.x) + logical_off_x;
crect.y = PANGO_PIXELS (crect.y) + logical_off_y;
......@@ -1148,7 +1151,7 @@ gimp_text_tool_draw_preedit (GimpDrawTool *draw_tool,
max = min + text_tool->preedit_len;
layout = text_tool->layout->layout;
layout = gimp_text_layout_get_pango_layout (text_tool->layout);
line_iter = pango_layout_get_iter (layout);
i = 0;
......@@ -1243,7 +1246,7 @@ gimp_text_tool_draw_selection (GimpDrawTool *draw_tool,
max = strlen (string);
g_free (string);
layout = text_tool->layout->layout;
layout = gimp_text_layout_get_pango_layout (text_tool->layout);
line_iter = pango_layout_get_iter (layout);
i = 0;
......@@ -2229,15 +2232,16 @@ gimp_text_tool_xy_to_offset (GimpTextTool *text_tool,
gdouble x,
gdouble y)
{
PangoRectangle ink_extents;
GtkTextIter start, end;
PangoLayout *layout;
PangoRectangle ink_extents;
gchar *string;
gint offset;
gint trailing;
/* adjust to offset of logical rect */
pango_layout_get_pixel_extents (text_tool->layout->layout,
&ink_extents, NULL);
layout = gimp_text_layout_get_pango_layout (text_tool->layout);
pango_layout_get_pixel_extents (layout, &ink_extents, NULL);
if (ink_extents.x < 0)
x += ink_extents.x;
......@@ -2249,7 +2253,7 @@ gimp_text_tool_xy_to_offset (GimpTextTool *text_tool,
string = gtk_text_buffer_get_text (text_tool->text_buffer,
&start, &end, TRUE);
pango_layout_xy_to_index (text_tool->layout->layout,
pango_layout_xy_to_index (layout,
x * PANGO_SCALE,
y * PANGO_SCALE,
&offset, &trailing);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment