mirror of
https://gitlab.gnome.org/GNOME/gimp
synced 2024-10-20 19:43:01 +00:00
app/text/Makefile.am app/text/gimptextlayout-private.h new files that
2003-07-06 Sven Neumann <sven@gimp.org> * app/text/Makefile.am * app/text/gimptextlayout-private.h * app/text/gimptextlayout-render.[ch]: new files that implement text rendering. Right now it's basically code copied from PangoFT2 but having it here will allow me to implement text transformations. * app/text/gimptextlayout.[ch] * app/text/gimptextlayer.c: changed accordingly.
This commit is contained in:
parent
47021d0a22
commit
7cf24c4f86
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2003-07-06 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/text/Makefile.am
|
||||
* app/text/gimptextlayout-private.h
|
||||
* app/text/gimptextlayout-render.[ch]: new files that implement
|
||||
text rendering. Right now it's basically code copied from PangoFT2
|
||||
but having it here will allow me to implement text transformations.
|
||||
|
||||
* app/text/gimptextlayout.[ch]
|
||||
* app/text/gimptextlayer.c: changed accordingly.
|
||||
|
||||
2003-07-06 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* etc/ps-menurc: an updated version from Eric Pierce.
|
||||
|
|
|
@ -32,7 +32,10 @@ libapptext_a_sources = \
|
|||
gimptextlayer.c \
|
||||
gimptextlayer.h \
|
||||
gimptextlayout.c \
|
||||
gimptextlayout.h
|
||||
gimptextlayout.h \
|
||||
gimptextlayout-private.h\
|
||||
gimptextlayout-render.c \
|
||||
gimptextlayout-render.h
|
||||
|
||||
libapptext_a_built_sources = text-enums.c
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "gimptext.h"
|
||||
#include "gimptextlayer.h"
|
||||
#include "gimptextlayout.h"
|
||||
#include "gimptextlayout-render.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
||||
|
|
41
app/text/gimptextlayout-private.h
Normal file
41
app/text/gimptextlayout-private.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/* The GIMP -- an 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__
|
||||
|
||||
|
||||
struct _GimpTextLayout
|
||||
{
|
||||
GObject object;
|
||||
|
||||
GimpText *text;
|
||||
PangoLayout *layout;
|
||||
PangoRectangle extents;
|
||||
};
|
||||
|
||||
struct _GimpTextLayoutClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
|
||||
#endif /* __GIMP_TEXT_LAYOUT_PRIVATE_H__ */
|
295
app/text/gimptextlayout-render.c
Normal file
295
app/text/gimptextlayout-render.c
Normal file
|
@ -0,0 +1,295 @@
|
|||
/* The GIMP -- an 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.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <pango/pangoft2.h>
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
|
||||
#include "text-types.h"
|
||||
|
||||
#include "base/pixel-region.h"
|
||||
#include "base/tile-manager.h"
|
||||
|
||||
#include "gimptext.h"
|
||||
#include "gimptextlayout.h"
|
||||
#include "gimptextlayout-private.h"
|
||||
#include "gimptextlayout-render.h"
|
||||
|
||||
|
||||
/* Define to 1 to use the native PangoFT2 render routine. */
|
||||
#define USE_PANGOFT2_RENDER 0
|
||||
|
||||
|
||||
/* This file duplicates quite a lot of code from pangoft2.c.
|
||||
* At some point all this should be folded back into Pango.
|
||||
*/
|
||||
|
||||
static void gimp_text_render_layout (GimpTextLayout *text_layout,
|
||||
FT_Bitmap *bitmap,
|
||||
gint x,
|
||||
gint y);
|
||||
static void gimp_text_render_layout_line (GimpTextLayout *text_layout,
|
||||
FT_Bitmap *bitmap,
|
||||
PangoLayoutLine *line,
|
||||
gint x,
|
||||
gint y);
|
||||
static void gimp_text_render (GimpTextLayout *text_layout,
|
||||
FT_Bitmap *bitmap,
|
||||
PangoFont *font,
|
||||
PangoGlyphString *glyphs,
|
||||
gint x,
|
||||
gint y);
|
||||
static gint gimp_text_layout_get_load_flags (GimpTextLayout *text_layout);
|
||||
|
||||
|
||||
TileManager *
|
||||
gimp_text_layout_render (GimpTextLayout *layout,
|
||||
gint width,
|
||||
gint height)
|
||||
{
|
||||
TileManager *mask;
|
||||
FT_Bitmap bitmap;
|
||||
PixelRegion maskPR;
|
||||
gint i;
|
||||
gint x, y;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_TEXT_LAYOUT (layout), NULL);
|
||||
|
||||
gimp_text_layout_get_offsets (layout, &x, &y);
|
||||
|
||||
bitmap.width = width;
|
||||
bitmap.rows = height;
|
||||
bitmap.pitch = width;
|
||||
if (bitmap.pitch & 3)
|
||||
bitmap.pitch += 4 - (bitmap.pitch & 3);
|
||||
|
||||
bitmap.buffer = g_malloc0 (bitmap.rows * bitmap.pitch);
|
||||
|
||||
#if USE_PANGOFT2_RENDER
|
||||
pango_ft2_render_layout (&bitmap, layout->layout, x, y);
|
||||
#else
|
||||
gimp_text_render_layout (layout, &bitmap, x, y);
|
||||
#endif
|
||||
|
||||
mask = tile_manager_new (width, height, 1);
|
||||
pixel_region_init (&maskPR, mask, 0, 0, width, height, TRUE);
|
||||
|
||||
for (i = 0; i < height; i++)
|
||||
pixel_region_set_row (&maskPR,
|
||||
0, i, width, bitmap.buffer + i * bitmap.pitch);
|
||||
|
||||
g_free (bitmap.buffer);
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_text_render_layout (GimpTextLayout *text_layout,
|
||||
FT_Bitmap *bitmap,
|
||||
gint x,
|
||||
gint y)
|
||||
{
|
||||
PangoLayout *layout = text_layout->layout;
|
||||
PangoLayoutIter *iter;
|
||||
|
||||
g_return_if_fail (bitmap != NULL);
|
||||
g_return_if_fail (PANGO_IS_LAYOUT (layout));
|
||||
|
||||
iter = pango_layout_get_iter (layout);
|
||||
|
||||
do
|
||||
{
|
||||
PangoRectangle rect;
|
||||
PangoLayoutLine *line;
|
||||
gint baseline;
|
||||
|
||||
line = pango_layout_iter_get_line (iter);
|
||||
|
||||
pango_layout_iter_get_line_extents (iter, NULL, &rect);
|
||||
baseline = pango_layout_iter_get_baseline (iter);
|
||||
|
||||
gimp_text_render_layout_line (text_layout,
|
||||
bitmap,
|
||||
line,
|
||||
x + PANGO_PIXELS (rect.x),
|
||||
y + PANGO_PIXELS (baseline));
|
||||
}
|
||||
while (pango_layout_iter_next_line (iter));
|
||||
|
||||
pango_layout_iter_free (iter);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_text_render_layout_line (GimpTextLayout *text_layout,
|
||||
FT_Bitmap *bitmap,
|
||||
PangoLayoutLine *line,
|
||||
gint x,
|
||||
gint y)
|
||||
{
|
||||
PangoRectangle rect;
|
||||
GSList *list;
|
||||
gint x_off = 0;
|
||||
|
||||
for (list = line->runs; list; list = list->next)
|
||||
{
|
||||
PangoLayoutRun *run = list->data;
|
||||
|
||||
pango_glyph_string_extents (run->glyphs, run->item->analysis.font,
|
||||
NULL, &rect);
|
||||
gimp_text_render (text_layout, bitmap,
|
||||
run->item->analysis.font, run->glyphs,
|
||||
x + PANGO_PIXELS (x_off), y);
|
||||
|
||||
x_off += rect.width;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_text_render (GimpTextLayout *text_layout,
|
||||
FT_Bitmap *bitmap,
|
||||
PangoFont *font,
|
||||
PangoGlyphString *glyphs,
|
||||
gint x,
|
||||
gint y)
|
||||
{
|
||||
PangoGlyphInfo *gi;
|
||||
FT_Face face;
|
||||
gint flags;
|
||||
gint i;
|
||||
gint x_position = 0;
|
||||
gint ix, iy, ixoff, iyoff, y_start, y_limit, x_start, x_limit;
|
||||
const guchar *src;
|
||||
guchar *dest;
|
||||
|
||||
face = pango_ft2_font_get_face (font);
|
||||
flags = gimp_text_layout_get_load_flags (text_layout);
|
||||
|
||||
for (i = 0, gi = glyphs->glyphs; i < glyphs->num_glyphs; i++, gi++)
|
||||
{
|
||||
if (gi->glyph)
|
||||
{
|
||||
FT_Load_Glyph (face, (FT_UInt) gi->glyph, flags);
|
||||
FT_Render_Glyph (face->glyph,
|
||||
(flags & FT_LOAD_TARGET_MONO ?
|
||||
ft_render_mode_mono : ft_render_mode_normal));
|
||||
|
||||
ixoff = x + PANGO_PIXELS (x_position + gi->geometry.x_offset);
|
||||
iyoff = y + PANGO_PIXELS (gi->geometry.y_offset);
|
||||
|
||||
x_start = MAX (0, - (ixoff + face->glyph->bitmap_left));
|
||||
x_limit = MIN (face->glyph->bitmap.width,
|
||||
bitmap->width - (ixoff + face->glyph->bitmap_left));
|
||||
|
||||
y_start = MAX (0, - (iyoff - face->glyph->bitmap_top));
|
||||
y_limit = MIN (face->glyph->bitmap.rows,
|
||||
bitmap->rows - (iyoff - face->glyph->bitmap_top));
|
||||
|
||||
src = face->glyph->bitmap.buffer +
|
||||
y_start * face->glyph->bitmap.pitch;
|
||||
|
||||
dest = bitmap->buffer +
|
||||
(y_start + iyoff - face->glyph->bitmap_top) * bitmap->pitch +
|
||||
x_start + ixoff + face->glyph->bitmap_left;
|
||||
|
||||
switch (face->glyph->bitmap.pixel_mode)
|
||||
{
|
||||
case ft_pixel_mode_grays:
|
||||
src += x_start;
|
||||
for (iy = y_start; iy < y_limit; iy++)
|
||||
{
|
||||
const guchar *s = src;
|
||||
guchar *d = dest;
|
||||
|
||||
for (ix = x_start; ix < x_limit; ix++)
|
||||
{
|
||||
switch (*s)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 0xff:
|
||||
*d = 0xff;
|
||||
default:
|
||||
*d = MIN ((gushort) *d + (const gushort) *s, 0xff);
|
||||
break;
|
||||
}
|
||||
|
||||
s++;
|
||||
d++;
|
||||
}
|
||||
|
||||
dest += bitmap->pitch;
|
||||
src += face->glyph->bitmap.pitch;
|
||||
}
|
||||
break;
|
||||
|
||||
case ft_pixel_mode_mono:
|
||||
src += x_start / 8;
|
||||
for (iy = y_start; iy < y_limit; iy++)
|
||||
{
|
||||
const guchar *s = src;
|
||||
guchar *d = dest;
|
||||
|
||||
for (ix = x_start; ix < x_limit; ix++)
|
||||
{
|
||||
if ((*s) & (1 << (7 - (ix % 8))))
|
||||
*d |= 0xff;
|
||||
|
||||
if ((ix % 8) == 7)
|
||||
s++;
|
||||
d++;
|
||||
}
|
||||
|
||||
dest += bitmap->pitch;
|
||||
src += face->glyph->bitmap.pitch;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
x_position += glyphs->glyphs[i].geometry.width;
|
||||
}
|
||||
}
|
||||
|
||||
static gint
|
||||
gimp_text_layout_get_load_flags (GimpTextLayout *text_layout)
|
||||
{
|
||||
GimpText *text = text_layout->text;
|
||||
gint flags;
|
||||
|
||||
if (text->antialias)
|
||||
flags = FT_LOAD_NO_BITMAP;
|
||||
else
|
||||
flags = FT_LOAD_TARGET_MONO;
|
||||
|
||||
if (!text->hinting)
|
||||
flags |= FT_LOAD_NO_HINTING;
|
||||
|
||||
if (text->autohint)
|
||||
flags |= FT_LOAD_FORCE_AUTOHINT;
|
||||
|
||||
return flags;
|
||||
}
|
31
app/text/gimptextlayout-render.h
Normal file
31
app/text/gimptextlayout-render.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/* The GIMP -- an 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_RENDER_H__
|
||||
#define __GIMP_TEXT_LAYOUT_RENDER_H__
|
||||
|
||||
|
||||
TileManager * gimp_text_layout_render (GimpTextLayout *layout,
|
||||
gint width,
|
||||
gint height);
|
||||
|
||||
|
||||
#endif /* __GIMP_TEXT_LAYOUT_RENDER_H__ */
|
|
@ -28,28 +28,11 @@
|
|||
|
||||
#include "text-types.h"
|
||||
|
||||
#include "base/pixel-region.h"
|
||||
#include "base/tile-manager.h"
|
||||
|
||||
#include "core/gimpimage.h"
|
||||
|
||||
#include "gimptext.h"
|
||||
#include "gimptextlayout.h"
|
||||
|
||||
|
||||
struct _GimpTextLayout
|
||||
{
|
||||
GObject object;
|
||||
|
||||
GimpText *text;
|
||||
PangoLayout *layout;
|
||||
PangoRectangle extents;
|
||||
};
|
||||
|
||||
struct _GimpTextLayoutClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
#include "gimptextlayout-private.h"
|
||||
|
||||
|
||||
static void gimp_text_layout_class_init (GimpTextLayoutClass *klass);
|
||||
|
@ -261,43 +244,6 @@ gimp_text_layout_get_offsets (GimpTextLayout *layout,
|
|||
*y = layout->extents.y;
|
||||
}
|
||||
|
||||
TileManager *
|
||||
gimp_text_layout_render (GimpTextLayout *layout,
|
||||
gint width,
|
||||
gint height)
|
||||
{
|
||||
TileManager *mask;
|
||||
FT_Bitmap bitmap;
|
||||
PixelRegion maskPR;
|
||||
gint i;
|
||||
gint x, y;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_TEXT_LAYOUT (layout), NULL);
|
||||
|
||||
gimp_text_layout_get_offsets (layout, &x, &y);
|
||||
|
||||
bitmap.width = width;
|
||||
bitmap.rows = height;
|
||||
bitmap.pitch = width;
|
||||
if (bitmap.pitch & 3)
|
||||
bitmap.pitch += 4 - (bitmap.pitch & 3);
|
||||
|
||||
bitmap.buffer = g_malloc0 (bitmap.rows * bitmap.pitch);
|
||||
|
||||
pango_ft2_render_layout (&bitmap, layout->layout, x, y);
|
||||
|
||||
mask = tile_manager_new (width, height, 1);
|
||||
pixel_region_init (&maskPR, mask, 0, 0, width, height, TRUE);
|
||||
|
||||
for (i = 0; i < height; i++)
|
||||
pixel_region_set_row (&maskPR,
|
||||
0, i, width, bitmap.buffer + i * bitmap.pitch);
|
||||
|
||||
g_free (bitmap.buffer);
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_text_layout_position (GimpTextLayout *layout)
|
||||
{
|
||||
|
@ -310,7 +256,7 @@ gimp_text_layout_position (GimpTextLayout *layout)
|
|||
layout->extents.x = 0;
|
||||
layout->extents.width = 0;
|
||||
layout->extents.height = 0;
|
||||
|
||||
|
||||
pango_layout_get_pixel_extents (layout->layout, &ink, &logical);
|
||||
|
||||
#ifdef VERBOSE
|
||||
|
|
|
@ -41,9 +41,6 @@ gboolean gimp_text_layout_get_size (GimpTextLayout *layout,
|
|||
void gimp_text_layout_get_offsets (GimpTextLayout *layout,
|
||||
gint *x,
|
||||
gint *y);
|
||||
TileManager * gimp_text_layout_render (GimpTextLayout *layout,
|
||||
gint width,
|
||||
gint height);
|
||||
|
||||
|
||||
#endif /* __GIMP_TEXT_LAYOUT_H__ */
|
||||
|
|
Loading…
Reference in a new issue