2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2002-10-10 22:30:01 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2003-01-31 17:22:42 +08:00
|
|
|
* GimpText
|
|
|
|
* Copyright (C) 2002-2003 Sven Neumann <sven@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2002-10-10 22:30:01 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2002-10-10 22:30:01 +08:00
|
|
|
* (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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2002-10-10 22:30:01 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2003-02-25 02:54:24 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2011-04-28 21:50:39 +08:00
|
|
|
#include <cairo.h>
|
2012-03-22 04:58:40 +08:00
|
|
|
#include <gegl.h>
|
2012-05-03 09:36:22 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2003-03-29 00:15:07 +08:00
|
|
|
#include <pango/pango.h>
|
2002-10-10 22:30:01 +08:00
|
|
|
|
2003-10-01 19:52:52 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2007-03-09 21:00:01 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2003-01-31 17:22:42 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2003-01-31 17:22:42 +08:00
|
|
|
|
2004-09-27 20:30:04 +08:00
|
|
|
#include "text-types.h"
|
2002-10-10 22:30:01 +08:00
|
|
|
|
2023-08-02 04:32:10 +08:00
|
|
|
#include "gimpfont.h"
|
|
|
|
|
2022-10-04 03:45:52 +08:00
|
|
|
#include "core/gimp.h"
|
2014-08-12 19:57:57 +08:00
|
|
|
#include "core/gimp-memsize.h"
|
|
|
|
#include "core/gimp-utils.h"
|
2022-10-04 03:45:52 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
|
|
|
#include "core/gimpdashpattern.h"
|
|
|
|
#include "core/gimpdatafactory.h"
|
2003-10-26 08:03:16 +08:00
|
|
|
#include "core/gimpstrokeoptions.h"
|
2022-10-04 03:45:52 +08:00
|
|
|
#include "core/gimppattern.h"
|
2003-10-26 08:03:16 +08:00
|
|
|
|
2002-10-10 22:30:01 +08:00
|
|
|
#include "gimptext.h"
|
|
|
|
|
2003-02-05 21:03:44 +08:00
|
|
|
|
2002-10-10 22:30:01 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2022-10-13 08:16:44 +08:00
|
|
|
PROP_GIMP,
|
2002-10-10 22:30:01 +08:00
|
|
|
PROP_TEXT,
|
2010-02-26 07:11:25 +08:00
|
|
|
PROP_MARKUP,
|
2002-10-10 22:30:01 +08:00
|
|
|
PROP_FONT,
|
2003-01-31 21:36:27 +08:00
|
|
|
PROP_FONT_SIZE,
|
2003-10-26 08:03:16 +08:00
|
|
|
PROP_UNIT,
|
2003-03-28 01:24:53 +08:00
|
|
|
PROP_ANTIALIAS,
|
2008-10-27 15:59:32 +08:00
|
|
|
PROP_HINT_STYLE,
|
2003-10-25 23:25:17 +08:00
|
|
|
PROP_KERNING,
|
2003-02-25 02:54:24 +08:00
|
|
|
PROP_LANGUAGE,
|
2003-03-29 00:15:07 +08:00
|
|
|
PROP_BASE_DIR,
|
2003-01-31 17:22:42 +08:00
|
|
|
PROP_COLOR,
|
2003-10-26 08:03:16 +08:00
|
|
|
PROP_OUTLINE,
|
2003-02-05 17:51:26 +08:00
|
|
|
PROP_JUSTIFICATION,
|
|
|
|
PROP_INDENTATION,
|
2003-01-31 21:36:27 +08:00
|
|
|
PROP_LINE_SPACING,
|
2003-10-25 23:25:17 +08:00
|
|
|
PROP_LETTER_SPACING,
|
2003-04-10 05:19:12 +08:00
|
|
|
PROP_BOX_MODE,
|
2003-03-28 01:24:53 +08:00
|
|
|
PROP_BOX_WIDTH,
|
2003-04-10 05:19:12 +08:00
|
|
|
PROP_BOX_HEIGHT,
|
|
|
|
PROP_BOX_UNIT,
|
2003-07-08 00:22:45 +08:00
|
|
|
PROP_TRANSFORMATION,
|
2003-10-26 08:03:16 +08:00
|
|
|
PROP_OFFSET_X,
|
|
|
|
PROP_OFFSET_Y,
|
2008-10-27 15:59:32 +08:00
|
|
|
PROP_BORDER,
|
2022-10-04 03:45:52 +08:00
|
|
|
|
|
|
|
PROP_OUTLINE_STYLE, /* fill-options */
|
|
|
|
PROP_OUTLINE_FOREGROUND, /* context */
|
|
|
|
PROP_OUTLINE_PATTERN, /* context */
|
|
|
|
PROP_OUTLINE_WIDTH, /* stroke-options */
|
|
|
|
PROP_OUTLINE_UNIT,
|
|
|
|
PROP_OUTLINE_CAP_STYLE,
|
|
|
|
PROP_OUTLINE_JOIN_STYLE,
|
|
|
|
PROP_OUTLINE_MITER_LIMIT,
|
|
|
|
PROP_OUTLINE_ANTIALIAS, /* fill-options */
|
|
|
|
PROP_OUTLINE_DASH_OFFSET,
|
|
|
|
PROP_OUTLINE_DASH_INFO,
|
2008-10-27 15:59:32 +08:00
|
|
|
/* for backward compatibility */
|
2022-10-13 08:16:44 +08:00
|
|
|
PROP_HINTING
|
2002-10-10 22:30:01 +08:00
|
|
|
};
|
|
|
|
|
2010-03-03 00:44:31 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CHANGED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
2003-02-25 02:54:24 +08:00
|
|
|
|
2022-10-04 03:45:52 +08:00
|
|
|
static void gimp_text_config_iface_init (GimpConfigInterface *iface);
|
|
|
|
static gboolean gimp_text_serialize_property (GimpConfig *config,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GimpConfigWriter *writer);
|
|
|
|
static gboolean gimp_text_deserialize_property (GimpConfig *config,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GScanner *scanner,
|
|
|
|
GTokenType *expected);
|
2010-03-03 00:44:31 +08:00
|
|
|
|
|
|
|
static void gimp_text_finalize (GObject *object);
|
|
|
|
static void gimp_text_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_text_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_text_dispatch_properties_changed (GObject *object,
|
|
|
|
guint n_pspecs,
|
|
|
|
GParamSpec **pspecs);
|
|
|
|
static gint64 gimp_text_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size);
|
2002-10-10 22:30:01 +08:00
|
|
|
|
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GimpText, gimp_text, GIMP_TYPE_OBJECT,
|
2022-10-04 03:45:52 +08:00
|
|
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG,
|
|
|
|
gimp_text_config_iface_init))
|
2002-10-10 22:30:01 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
#define parent_class gimp_text_parent_class
|
2002-10-10 22:30:01 +08:00
|
|
|
|
2010-03-03 00:44:31 +08:00
|
|
|
static guint text_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2002-10-10 22:30:01 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_class_init (GimpTextClass *klass)
|
|
|
|
{
|
2005-12-11 03:24:36 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
app, libgimp, pdb, plug-ins: GimpText* using GeglColor.
One of the big improvement in this commit is that text layers are now much
better at space accuracy. They were already space-aware, yet rendered as sRGB u8
only before being converted to the image's space. It means that text layers had
the following limitations:
* Any color out of sRGB gamut were trimmed.
* Precision was always 8-bit (even if the image was high-bit depth).
Now GimpTextLayout keeps track of its source space (for RGB and CMYK only, this
won't be as easy when we will support more backend, since Cairo has only RGB
support for image data) and the image TRC (in case it bypasses the color space's
TRB) and it draws within this gamut and space.
It means first that we are not limited to sRGB colors; we will draw text main
color in the full image gamut, with still 2 remaining limitations:
* Unbounded colors are impossible because Pango format (to color text) uses
hexadecimal (so even with half/float images, you can't draw out-of-gamut text
unfortunately).
* Main color precision is still 8-bit, yet a tiny bit better than before as we
at least follow TRC (so we avoid some of the precision loss when converting,
even though the bit-depth is still the biggest loss).
The outline color on the other hand is drawn through Cairo API entirely, in
float. This means that the outline color will now be without any precision loss.
Note that this depends on CAIRO_FORMAT_RGBA128F which is only available since
Cairo 1.17.2 which is not in Debian bookworm (our current baseline for GIMP
3.0). It means that the old precision will still happen with older Cairo
version, as determined by #if code at compilation.
2023-11-18 05:36:31 +08:00
|
|
|
GeglColor *black = gegl_color_new ("black");
|
|
|
|
GeglColor *gray = gegl_color_new ("gray");
|
2003-08-25 20:24:51 +08:00
|
|
|
GimpMatrix2 identity;
|
|
|
|
gchar *language;
|
2022-10-04 03:45:52 +08:00
|
|
|
GParamSpec *array_spec;
|
2002-10-10 22:30:01 +08:00
|
|
|
|
2010-03-03 00:44:31 +08:00
|
|
|
text_signals[CHANGED] =
|
|
|
|
g_signal_new ("changed",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpTextClass, changed),
|
2020-01-12 18:06:05 +08:00
|
|
|
NULL, NULL, NULL,
|
2010-03-03 00:44:31 +08:00
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
object_class->finalize = gimp_text_finalize;
|
|
|
|
object_class->get_property = gimp_text_get_property;
|
|
|
|
object_class->set_property = gimp_text_set_property;
|
|
|
|
object_class->dispatch_properties_changed = gimp_text_dispatch_properties_changed;
|
2003-08-25 20:24:51 +08:00
|
|
|
|
2010-03-03 00:44:31 +08:00
|
|
|
gimp_object_class->get_memsize = gimp_text_get_memsize;
|
2002-10-10 22:30:01 +08:00
|
|
|
|
2003-07-08 00:22:45 +08:00
|
|
|
gimp_matrix2_identity (&identity);
|
2003-01-31 17:22:42 +08:00
|
|
|
|
2016-02-12 06:44:07 +08:00
|
|
|
GIMP_CONFIG_PROP_STRING (object_class, PROP_TEXT,
|
|
|
|
"text",
|
|
|
|
NULL, NULL,
|
|
|
|
NULL,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_STRING (object_class, PROP_MARKUP,
|
|
|
|
"markup",
|
|
|
|
NULL, NULL,
|
|
|
|
NULL,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
|
|
|
|
2023-08-02 04:32:10 +08:00
|
|
|
GIMP_CONFIG_PROP_FONT (object_class, PROP_FONT,
|
|
|
|
"font", NULL, NULL,
|
|
|
|
GIMP_CONFIG_PARAM_FLAGS);
|
2016-02-12 06:44:07 +08:00
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_FONT_SIZE,
|
|
|
|
"font-size",
|
|
|
|
NULL, NULL,
|
|
|
|
0.0, 8192.0, 24.0,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
2003-02-25 02:54:24 +08:00
|
|
|
|
2016-02-12 06:44:07 +08:00
|
|
|
/* We use the name "font-size-unit" for backward compatibility.
|
2003-10-26 20:07:05 +08:00
|
|
|
* The unit is also used for other sizes in the text object.
|
2003-10-26 08:03:16 +08:00
|
|
|
*/
|
2016-02-12 06:44:07 +08:00
|
|
|
GIMP_CONFIG_PROP_UNIT (object_class, PROP_UNIT,
|
|
|
|
"font-size-unit",
|
|
|
|
NULL, NULL,
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-26 02:55:21 +08:00
|
|
|
TRUE, FALSE, gimp_unit_pixel (),
|
2016-02-12 06:44:07 +08:00
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_ANTIALIAS,
|
|
|
|
"antialias",
|
|
|
|
NULL, NULL,
|
|
|
|
TRUE,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_ENUM (object_class, PROP_HINT_STYLE,
|
|
|
|
"hint-style",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_TYPE_TEXT_HINT_STYLE,
|
|
|
|
GIMP_TEXT_HINT_STYLE_MEDIUM,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS |
|
|
|
|
GIMP_CONFIG_PARAM_DEFAULTS);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_KERNING,
|
|
|
|
"kerning",
|
|
|
|
NULL, NULL,
|
|
|
|
FALSE,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS |
|
|
|
|
GIMP_CONFIG_PARAM_DEFAULTS);
|
|
|
|
|
|
|
|
language = gimp_get_default_language (NULL);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_STRING (object_class, PROP_LANGUAGE,
|
|
|
|
"language",
|
|
|
|
NULL, NULL,
|
|
|
|
language,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
g_free (language);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_ENUM (object_class, PROP_BASE_DIR,
|
|
|
|
"base-direction",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_TYPE_TEXT_DIRECTION,
|
|
|
|
GIMP_TEXT_DIRECTION_LTR,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
|
|
|
|
app, libgimp, pdb, plug-ins: GimpText* using GeglColor.
One of the big improvement in this commit is that text layers are now much
better at space accuracy. They were already space-aware, yet rendered as sRGB u8
only before being converted to the image's space. It means that text layers had
the following limitations:
* Any color out of sRGB gamut were trimmed.
* Precision was always 8-bit (even if the image was high-bit depth).
Now GimpTextLayout keeps track of its source space (for RGB and CMYK only, this
won't be as easy when we will support more backend, since Cairo has only RGB
support for image data) and the image TRC (in case it bypasses the color space's
TRB) and it draws within this gamut and space.
It means first that we are not limited to sRGB colors; we will draw text main
color in the full image gamut, with still 2 remaining limitations:
* Unbounded colors are impossible because Pango format (to color text) uses
hexadecimal (so even with half/float images, you can't draw out-of-gamut text
unfortunately).
* Main color precision is still 8-bit, yet a tiny bit better than before as we
at least follow TRC (so we avoid some of the precision loss when converting,
even though the bit-depth is still the biggest loss).
The outline color on the other hand is drawn through Cairo API entirely, in
float. This means that the outline color will now be without any precision loss.
Note that this depends on CAIRO_FORMAT_RGBA128F which is only available since
Cairo 1.17.2 which is not in Debian bookworm (our current baseline for GIMP
3.0). It means that the old precision will still happen with older Cairo
version, as determined by #if code at compilation.
2023-11-18 05:36:31 +08:00
|
|
|
GIMP_CONFIG_PROP_COLOR (object_class, PROP_COLOR,
|
|
|
|
"color",
|
|
|
|
NULL, NULL,
|
2024-04-20 05:02:29 +08:00
|
|
|
FALSE, black,
|
app, libgimp, pdb, plug-ins: GimpText* using GeglColor.
One of the big improvement in this commit is that text layers are now much
better at space accuracy. They were already space-aware, yet rendered as sRGB u8
only before being converted to the image's space. It means that text layers had
the following limitations:
* Any color out of sRGB gamut were trimmed.
* Precision was always 8-bit (even if the image was high-bit depth).
Now GimpTextLayout keeps track of its source space (for RGB and CMYK only, this
won't be as easy when we will support more backend, since Cairo has only RGB
support for image data) and the image TRC (in case it bypasses the color space's
TRB) and it draws within this gamut and space.
It means first that we are not limited to sRGB colors; we will draw text main
color in the full image gamut, with still 2 remaining limitations:
* Unbounded colors are impossible because Pango format (to color text) uses
hexadecimal (so even with half/float images, you can't draw out-of-gamut text
unfortunately).
* Main color precision is still 8-bit, yet a tiny bit better than before as we
at least follow TRC (so we avoid some of the precision loss when converting,
even though the bit-depth is still the biggest loss).
The outline color on the other hand is drawn through Cairo API entirely, in
float. This means that the outline color will now be without any precision loss.
Note that this depends on CAIRO_FORMAT_RGBA128F which is only available since
Cairo 1.17.2 which is not in Debian bookworm (our current baseline for GIMP
3.0). It means that the old precision will still happen with older Cairo
version, as determined by #if code at compilation.
2023-11-18 05:36:31 +08:00
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
2016-02-12 06:44:07 +08:00
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_ENUM (object_class, PROP_OUTLINE,
|
|
|
|
"outline",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_TYPE_TEXT_OUTLINE,
|
|
|
|
GIMP_TEXT_OUTLINE_NONE,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS |
|
|
|
|
GIMP_CONFIG_PARAM_DEFAULTS);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_ENUM (object_class, PROP_JUSTIFICATION,
|
|
|
|
"justify",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_TYPE_TEXT_JUSTIFICATION,
|
|
|
|
GIMP_TEXT_JUSTIFY_LEFT,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_INDENTATION,
|
|
|
|
"indent",
|
|
|
|
NULL, NULL,
|
|
|
|
-8192.0, 8192.0, 0.0,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS |
|
|
|
|
GIMP_CONFIG_PARAM_DEFAULTS);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_LINE_SPACING,
|
|
|
|
"line-spacing",
|
|
|
|
NULL, NULL,
|
|
|
|
-8192.0, 8192.0, 0.0,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS |
|
|
|
|
GIMP_CONFIG_PARAM_DEFAULTS);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_LETTER_SPACING,
|
|
|
|
"letter-spacing",
|
|
|
|
NULL, NULL,
|
|
|
|
-8192.0, 8192.0, 0.0,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS |
|
|
|
|
GIMP_CONFIG_PARAM_DEFAULTS);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_ENUM (object_class, PROP_BOX_MODE,
|
|
|
|
"box-mode",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_TYPE_TEXT_BOX_MODE,
|
|
|
|
GIMP_TEXT_BOX_DYNAMIC,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_BOX_WIDTH,
|
|
|
|
"box-width",
|
|
|
|
NULL, NULL,
|
|
|
|
0.0, GIMP_MAX_IMAGE_SIZE, 0.0,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS |
|
|
|
|
GIMP_CONFIG_PARAM_DEFAULTS);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_BOX_HEIGHT,
|
|
|
|
"box-height",
|
|
|
|
NULL, NULL,
|
|
|
|
0.0, GIMP_MAX_IMAGE_SIZE, 0.0,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS |
|
|
|
|
GIMP_CONFIG_PARAM_DEFAULTS);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_UNIT (object_class, PROP_BOX_UNIT,
|
|
|
|
"box-unit",
|
|
|
|
NULL, NULL,
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-26 02:55:21 +08:00
|
|
|
TRUE, FALSE, gimp_unit_pixel (),
|
2016-02-12 06:44:07 +08:00
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_MATRIX2 (object_class, PROP_TRANSFORMATION,
|
|
|
|
"transformation",
|
|
|
|
NULL, NULL,
|
|
|
|
&identity,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS |
|
|
|
|
GIMP_CONFIG_PARAM_DEFAULTS);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_OFFSET_X,
|
|
|
|
"offset-x",
|
|
|
|
NULL, NULL,
|
|
|
|
-G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS |
|
|
|
|
GIMP_CONFIG_PARAM_DEFAULTS);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_OFFSET_Y,
|
|
|
|
"offset-y",
|
|
|
|
NULL, NULL,
|
|
|
|
-G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS |
|
|
|
|
GIMP_CONFIG_PARAM_DEFAULTS);
|
2003-10-26 08:03:16 +08:00
|
|
|
|
2003-01-31 21:36:27 +08:00
|
|
|
/* border does only exist to implement the old text API */
|
2005-12-11 03:24:36 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_BORDER,
|
|
|
|
g_param_spec_int ("border", NULL, NULL,
|
|
|
|
0, GIMP_MAX_IMAGE_SIZE, 0,
|
|
|
|
G_PARAM_CONSTRUCT |
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_WRITABLE));
|
2002-10-11 01:07:46 +08:00
|
|
|
|
2022-10-04 03:45:52 +08:00
|
|
|
GIMP_CONFIG_PROP_ENUM (object_class, PROP_OUTLINE_STYLE,
|
2023-06-24 07:13:15 +08:00
|
|
|
"outline-custom-style", NULL, NULL,
|
|
|
|
GIMP_TYPE_CUSTOM_STYLE,
|
|
|
|
GIMP_CUSTOM_STYLE_SOLID_COLOR,
|
2022-10-04 03:45:52 +08:00
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
|
|
|
GIMP_CONFIG_PROP_OBJECT (object_class, PROP_OUTLINE_PATTERN,
|
|
|
|
"outline-pattern", NULL, NULL,
|
|
|
|
GIMP_TYPE_PATTERN,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
app, libgimp, pdb, plug-ins: GimpText* using GeglColor.
One of the big improvement in this commit is that text layers are now much
better at space accuracy. They were already space-aware, yet rendered as sRGB u8
only before being converted to the image's space. It means that text layers had
the following limitations:
* Any color out of sRGB gamut were trimmed.
* Precision was always 8-bit (even if the image was high-bit depth).
Now GimpTextLayout keeps track of its source space (for RGB and CMYK only, this
won't be as easy when we will support more backend, since Cairo has only RGB
support for image data) and the image TRC (in case it bypasses the color space's
TRB) and it draws within this gamut and space.
It means first that we are not limited to sRGB colors; we will draw text main
color in the full image gamut, with still 2 remaining limitations:
* Unbounded colors are impossible because Pango format (to color text) uses
hexadecimal (so even with half/float images, you can't draw out-of-gamut text
unfortunately).
* Main color precision is still 8-bit, yet a tiny bit better than before as we
at least follow TRC (so we avoid some of the precision loss when converting,
even though the bit-depth is still the biggest loss).
The outline color on the other hand is drawn through Cairo API entirely, in
float. This means that the outline color will now be without any precision loss.
Note that this depends on CAIRO_FORMAT_RGBA128F which is only available since
Cairo 1.17.2 which is not in Debian bookworm (our current baseline for GIMP
3.0). It means that the old precision will still happen with older Cairo
version, as determined by #if code at compilation.
2023-11-18 05:36:31 +08:00
|
|
|
GIMP_CONFIG_PROP_COLOR (object_class, PROP_OUTLINE_FOREGROUND,
|
|
|
|
"outline-foreground", NULL, NULL,
|
2024-04-20 05:02:29 +08:00
|
|
|
FALSE, gray,
|
app, libgimp, pdb, plug-ins: GimpText* using GeglColor.
One of the big improvement in this commit is that text layers are now much
better at space accuracy. They were already space-aware, yet rendered as sRGB u8
only before being converted to the image's space. It means that text layers had
the following limitations:
* Any color out of sRGB gamut were trimmed.
* Precision was always 8-bit (even if the image was high-bit depth).
Now GimpTextLayout keeps track of its source space (for RGB and CMYK only, this
won't be as easy when we will support more backend, since Cairo has only RGB
support for image data) and the image TRC (in case it bypasses the color space's
TRB) and it draws within this gamut and space.
It means first that we are not limited to sRGB colors; we will draw text main
color in the full image gamut, with still 2 remaining limitations:
* Unbounded colors are impossible because Pango format (to color text) uses
hexadecimal (so even with half/float images, you can't draw out-of-gamut text
unfortunately).
* Main color precision is still 8-bit, yet a tiny bit better than before as we
at least follow TRC (so we avoid some of the precision loss when converting,
even though the bit-depth is still the biggest loss).
The outline color on the other hand is drawn through Cairo API entirely, in
float. This means that the outline color will now be without any precision loss.
Note that this depends on CAIRO_FORMAT_RGBA128F which is only available since
Cairo 1.17.2 which is not in Debian bookworm (our current baseline for GIMP
3.0). It means that the old precision will still happen with older Cairo
version, as determined by #if code at compilation.
2023-11-18 05:36:31 +08:00
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
2022-10-04 03:45:52 +08:00
|
|
|
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_OUTLINE_WIDTH,
|
|
|
|
"outline-width", NULL, NULL,
|
|
|
|
0.0, 8192.0, 4.0,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS |
|
|
|
|
GIMP_CONFIG_PARAM_DEFAULTS);
|
|
|
|
GIMP_CONFIG_PROP_ENUM (object_class, PROP_OUTLINE_CAP_STYLE,
|
|
|
|
"outline-cap-style", NULL, NULL,
|
|
|
|
GIMP_TYPE_CAP_STYLE, GIMP_CAP_BUTT,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
|
|
|
GIMP_CONFIG_PROP_ENUM (object_class, PROP_OUTLINE_JOIN_STYLE,
|
|
|
|
"outline-join-style", NULL, NULL,
|
|
|
|
GIMP_TYPE_JOIN_STYLE, GIMP_JOIN_MITER,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
|
|
|
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_OUTLINE_MITER_LIMIT,
|
|
|
|
"outline-miter-limit",
|
|
|
|
NULL, NULL,
|
|
|
|
0.0, 100.0, 10.0,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
|
|
|
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_OUTLINE_ANTIALIAS,
|
|
|
|
"outline-antialias", NULL, NULL,
|
|
|
|
TRUE,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
|
|
|
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_OUTLINE_DASH_OFFSET,
|
|
|
|
"outline-dash-offset", NULL, NULL,
|
|
|
|
0.0, 2000.0, 0.0,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
array_spec = g_param_spec_double ("outline-dash-length", NULL, NULL,
|
|
|
|
0.0, 2000.0, 1.0, GIMP_PARAM_READWRITE);
|
|
|
|
g_object_class_install_property (object_class, PROP_OUTLINE_DASH_INFO,
|
|
|
|
gimp_param_spec_value_array ("outline-dash-info",
|
|
|
|
NULL, NULL,
|
|
|
|
array_spec,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS |
|
|
|
|
GIMP_CONFIG_PARAM_FLAGS));
|
|
|
|
|
2008-10-27 15:59:32 +08:00
|
|
|
/* the old hinting options have been replaced by 'hint-style' */
|
2016-02-12 06:44:07 +08:00
|
|
|
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_HINTING,
|
|
|
|
"hinting",
|
|
|
|
NULL, NULL,
|
|
|
|
TRUE,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
2022-10-04 03:45:52 +08:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_GIMP,
|
|
|
|
g_param_spec_object ("gimp", NULL, NULL,
|
|
|
|
GIMP_TYPE_GIMP,
|
|
|
|
GIMP_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
app, libgimp, pdb, plug-ins: GimpText* using GeglColor.
One of the big improvement in this commit is that text layers are now much
better at space accuracy. They were already space-aware, yet rendered as sRGB u8
only before being converted to the image's space. It means that text layers had
the following limitations:
* Any color out of sRGB gamut were trimmed.
* Precision was always 8-bit (even if the image was high-bit depth).
Now GimpTextLayout keeps track of its source space (for RGB and CMYK only, this
won't be as easy when we will support more backend, since Cairo has only RGB
support for image data) and the image TRC (in case it bypasses the color space's
TRB) and it draws within this gamut and space.
It means first that we are not limited to sRGB colors; we will draw text main
color in the full image gamut, with still 2 remaining limitations:
* Unbounded colors are impossible because Pango format (to color text) uses
hexadecimal (so even with half/float images, you can't draw out-of-gamut text
unfortunately).
* Main color precision is still 8-bit, yet a tiny bit better than before as we
at least follow TRC (so we avoid some of the precision loss when converting,
even though the bit-depth is still the biggest loss).
The outline color on the other hand is drawn through Cairo API entirely, in
float. This means that the outline color will now be without any precision loss.
Note that this depends on CAIRO_FORMAT_RGBA128F which is only available since
Cairo 1.17.2 which is not in Debian bookworm (our current baseline for GIMP
3.0). It means that the old precision will still happen with older Cairo
version, as determined by #if code at compilation.
2023-11-18 05:36:31 +08:00
|
|
|
g_object_unref (black);
|
|
|
|
g_object_unref (gray);
|
2002-10-10 22:30:01 +08:00
|
|
|
}
|
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
static void
|
|
|
|
gimp_text_init (GimpText *text)
|
|
|
|
{
|
2024-02-16 23:25:34 +08:00
|
|
|
text->color = gegl_color_new ("black");
|
|
|
|
text->outline_foreground = gegl_color_new ("gray");
|
2005-12-11 03:24:36 +08:00
|
|
|
}
|
|
|
|
|
2022-10-04 03:45:52 +08:00
|
|
|
static void
|
|
|
|
gimp_text_config_iface_init (GimpConfigInterface *iface)
|
|
|
|
{
|
|
|
|
iface->serialize_property = gimp_text_serialize_property;
|
|
|
|
iface->deserialize_property = gimp_text_deserialize_property;
|
|
|
|
}
|
|
|
|
|
2002-10-10 22:30:01 +08:00
|
|
|
static void
|
|
|
|
gimp_text_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GimpText *text = GIMP_TEXT (object);
|
|
|
|
|
2019-05-27 23:47:55 +08:00
|
|
|
g_clear_pointer (&text->text, g_free);
|
|
|
|
g_clear_pointer (&text->markup, g_free);
|
|
|
|
g_clear_pointer (&text->language, g_free);
|
2023-08-02 04:32:10 +08:00
|
|
|
g_clear_object (&text->font);
|
app, libgimp, pdb, plug-ins: GimpText* using GeglColor.
One of the big improvement in this commit is that text layers are now much
better at space accuracy. They were already space-aware, yet rendered as sRGB u8
only before being converted to the image's space. It means that text layers had
the following limitations:
* Any color out of sRGB gamut were trimmed.
* Precision was always 8-bit (even if the image was high-bit depth).
Now GimpTextLayout keeps track of its source space (for RGB and CMYK only, this
won't be as easy when we will support more backend, since Cairo has only RGB
support for image data) and the image TRC (in case it bypasses the color space's
TRB) and it draws within this gamut and space.
It means first that we are not limited to sRGB colors; we will draw text main
color in the full image gamut, with still 2 remaining limitations:
* Unbounded colors are impossible because Pango format (to color text) uses
hexadecimal (so even with half/float images, you can't draw out-of-gamut text
unfortunately).
* Main color precision is still 8-bit, yet a tiny bit better than before as we
at least follow TRC (so we avoid some of the precision loss when converting,
even though the bit-depth is still the biggest loss).
The outline color on the other hand is drawn through Cairo API entirely, in
float. This means that the outline color will now be without any precision loss.
Note that this depends on CAIRO_FORMAT_RGBA128F which is only available since
Cairo 1.17.2 which is not in Debian bookworm (our current baseline for GIMP
3.0). It means that the old precision will still happen with older Cairo
version, as determined by #if code at compilation.
2023-11-18 05:36:31 +08:00
|
|
|
g_clear_object (&text->color);
|
|
|
|
g_clear_object (&text->outline_foreground);
|
2002-10-10 22:30:01 +08:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2003-01-31 17:22:42 +08:00
|
|
|
static void
|
|
|
|
gimp_text_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpText *text = GIMP_TEXT (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_TEXT:
|
|
|
|
g_value_set_string (value, text->text);
|
|
|
|
break;
|
2010-02-26 07:11:25 +08:00
|
|
|
case PROP_MARKUP:
|
|
|
|
g_value_set_string (value, text->markup);
|
|
|
|
break;
|
2003-01-31 17:22:42 +08:00
|
|
|
case PROP_FONT:
|
2023-08-02 04:32:10 +08:00
|
|
|
g_value_set_object (value, text->font);
|
2003-01-31 17:22:42 +08:00
|
|
|
break;
|
2003-01-31 21:36:27 +08:00
|
|
|
case PROP_FONT_SIZE:
|
|
|
|
g_value_set_double (value, text->font_size);
|
2003-01-31 17:22:42 +08:00
|
|
|
break;
|
2003-10-26 08:03:16 +08:00
|
|
|
case PROP_UNIT:
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-26 02:55:21 +08:00
|
|
|
g_value_set_object (value, text->unit);
|
2003-01-31 17:22:42 +08:00
|
|
|
break;
|
2003-03-28 01:24:53 +08:00
|
|
|
case PROP_ANTIALIAS:
|
|
|
|
g_value_set_boolean (value, text->antialias);
|
|
|
|
break;
|
2008-10-27 15:59:32 +08:00
|
|
|
case PROP_HINT_STYLE:
|
|
|
|
g_value_set_enum (value, text->hint_style);
|
|
|
|
break;
|
2003-10-25 23:25:17 +08:00
|
|
|
case PROP_KERNING:
|
|
|
|
g_value_set_boolean (value, text->kerning);
|
|
|
|
break;
|
2003-03-29 00:15:07 +08:00
|
|
|
case PROP_BASE_DIR:
|
|
|
|
g_value_set_enum (value, text->base_dir);
|
|
|
|
break;
|
2003-02-25 02:54:24 +08:00
|
|
|
case PROP_LANGUAGE:
|
|
|
|
g_value_set_string (value, text->language);
|
|
|
|
break;
|
2003-01-31 17:22:42 +08:00
|
|
|
case PROP_COLOR:
|
app, libgimp, pdb, plug-ins: GimpText* using GeglColor.
One of the big improvement in this commit is that text layers are now much
better at space accuracy. They were already space-aware, yet rendered as sRGB u8
only before being converted to the image's space. It means that text layers had
the following limitations:
* Any color out of sRGB gamut were trimmed.
* Precision was always 8-bit (even if the image was high-bit depth).
Now GimpTextLayout keeps track of its source space (for RGB and CMYK only, this
won't be as easy when we will support more backend, since Cairo has only RGB
support for image data) and the image TRC (in case it bypasses the color space's
TRB) and it draws within this gamut and space.
It means first that we are not limited to sRGB colors; we will draw text main
color in the full image gamut, with still 2 remaining limitations:
* Unbounded colors are impossible because Pango format (to color text) uses
hexadecimal (so even with half/float images, you can't draw out-of-gamut text
unfortunately).
* Main color precision is still 8-bit, yet a tiny bit better than before as we
at least follow TRC (so we avoid some of the precision loss when converting,
even though the bit-depth is still the biggest loss).
The outline color on the other hand is drawn through Cairo API entirely, in
float. This means that the outline color will now be without any precision loss.
Note that this depends on CAIRO_FORMAT_RGBA128F which is only available since
Cairo 1.17.2 which is not in Debian bookworm (our current baseline for GIMP
3.0). It means that the old precision will still happen with older Cairo
version, as determined by #if code at compilation.
2023-11-18 05:36:31 +08:00
|
|
|
g_value_set_object (value, text->color);
|
2003-01-31 17:22:42 +08:00
|
|
|
break;
|
2003-10-26 08:03:16 +08:00
|
|
|
case PROP_OUTLINE:
|
|
|
|
g_value_set_enum (value, text->outline);
|
|
|
|
break;
|
2003-02-05 17:51:26 +08:00
|
|
|
case PROP_JUSTIFICATION:
|
|
|
|
g_value_set_enum (value, text->justify);
|
2003-02-05 16:29:12 +08:00
|
|
|
break;
|
2003-02-05 17:51:26 +08:00
|
|
|
case PROP_INDENTATION:
|
|
|
|
g_value_set_double (value, text->indent);
|
2003-01-31 17:22:42 +08:00
|
|
|
break;
|
|
|
|
case PROP_LINE_SPACING:
|
|
|
|
g_value_set_double (value, text->line_spacing);
|
|
|
|
break;
|
2003-10-25 23:25:17 +08:00
|
|
|
case PROP_LETTER_SPACING:
|
|
|
|
g_value_set_double (value, text->letter_spacing);
|
|
|
|
break;
|
2003-04-10 05:19:12 +08:00
|
|
|
case PROP_BOX_MODE:
|
|
|
|
g_value_set_enum (value, text->box_mode);
|
2003-02-05 17:51:26 +08:00
|
|
|
break;
|
2003-03-28 01:24:53 +08:00
|
|
|
case PROP_BOX_WIDTH:
|
2003-04-10 05:19:12 +08:00
|
|
|
g_value_set_double (value, text->box_width);
|
|
|
|
break;
|
|
|
|
case PROP_BOX_HEIGHT:
|
|
|
|
g_value_set_double (value, text->box_height);
|
|
|
|
break;
|
2003-10-26 20:07:05 +08:00
|
|
|
case PROP_BOX_UNIT:
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-26 02:55:21 +08:00
|
|
|
g_value_set_object (value, text->box_unit);
|
2003-03-28 01:24:53 +08:00
|
|
|
break;
|
2003-07-08 00:22:45 +08:00
|
|
|
case PROP_TRANSFORMATION:
|
|
|
|
g_value_set_boxed (value, &text->transformation);
|
|
|
|
break;
|
2003-10-26 08:03:16 +08:00
|
|
|
case PROP_OFFSET_X:
|
|
|
|
g_value_set_double (value, text->offset_x);
|
|
|
|
break;
|
|
|
|
case PROP_OFFSET_Y:
|
|
|
|
g_value_set_double (value, text->offset_y);
|
|
|
|
break;
|
2022-10-04 03:45:52 +08:00
|
|
|
case PROP_OUTLINE_STYLE:
|
|
|
|
g_value_set_enum (value, text->outline_style);
|
|
|
|
break;
|
|
|
|
case PROP_OUTLINE_FOREGROUND:
|
app, libgimp, pdb, plug-ins: GimpText* using GeglColor.
One of the big improvement in this commit is that text layers are now much
better at space accuracy. They were already space-aware, yet rendered as sRGB u8
only before being converted to the image's space. It means that text layers had
the following limitations:
* Any color out of sRGB gamut were trimmed.
* Precision was always 8-bit (even if the image was high-bit depth).
Now GimpTextLayout keeps track of its source space (for RGB and CMYK only, this
won't be as easy when we will support more backend, since Cairo has only RGB
support for image data) and the image TRC (in case it bypasses the color space's
TRB) and it draws within this gamut and space.
It means first that we are not limited to sRGB colors; we will draw text main
color in the full image gamut, with still 2 remaining limitations:
* Unbounded colors are impossible because Pango format (to color text) uses
hexadecimal (so even with half/float images, you can't draw out-of-gamut text
unfortunately).
* Main color precision is still 8-bit, yet a tiny bit better than before as we
at least follow TRC (so we avoid some of the precision loss when converting,
even though the bit-depth is still the biggest loss).
The outline color on the other hand is drawn through Cairo API entirely, in
float. This means that the outline color will now be without any precision loss.
Note that this depends on CAIRO_FORMAT_RGBA128F which is only available since
Cairo 1.17.2 which is not in Debian bookworm (our current baseline for GIMP
3.0). It means that the old precision will still happen with older Cairo
version, as determined by #if code at compilation.
2023-11-18 05:36:31 +08:00
|
|
|
g_value_set_object (value, text->outline_foreground);
|
2022-10-04 03:45:52 +08:00
|
|
|
break;
|
|
|
|
case PROP_OUTLINE_PATTERN:
|
|
|
|
g_value_set_object (value, text->outline_pattern);
|
|
|
|
break;
|
|
|
|
case PROP_OUTLINE_WIDTH:
|
|
|
|
g_value_set_double (value, text->outline_width);
|
|
|
|
break;
|
|
|
|
case PROP_OUTLINE_CAP_STYLE:
|
|
|
|
g_value_set_enum (value, text->outline_cap_style);
|
|
|
|
break;
|
|
|
|
case PROP_OUTLINE_JOIN_STYLE:
|
|
|
|
g_value_set_enum (value, text->outline_join_style);
|
|
|
|
break;
|
|
|
|
case PROP_OUTLINE_MITER_LIMIT:
|
|
|
|
g_value_set_double (value, text->outline_miter_limit);
|
|
|
|
break;
|
|
|
|
case PROP_OUTLINE_ANTIALIAS:
|
|
|
|
g_value_set_boolean (value, text->outline_antialias);
|
|
|
|
break;
|
|
|
|
case PROP_OUTLINE_DASH_OFFSET:
|
|
|
|
g_value_set_double (value, text->outline_dash_offset);
|
|
|
|
break;
|
|
|
|
case PROP_OUTLINE_DASH_INFO:
|
|
|
|
{
|
|
|
|
GimpValueArray *value_array;
|
|
|
|
|
|
|
|
value_array = gimp_dash_pattern_to_value_array (text->outline_dash_info);
|
|
|
|
g_value_take_boxed (value, value_array);
|
|
|
|
}
|
|
|
|
break;
|
2008-10-27 15:59:32 +08:00
|
|
|
case PROP_HINTING:
|
|
|
|
g_value_set_boolean (value,
|
|
|
|
text->hint_style != GIMP_TEXT_HINT_STYLE_NONE);
|
|
|
|
break;
|
2022-10-04 03:45:52 +08:00
|
|
|
case PROP_GIMP:
|
|
|
|
g_value_set_object (value, text->gimp);
|
|
|
|
break;
|
2003-01-31 17:22:42 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-10 22:30:01 +08:00
|
|
|
static void
|
|
|
|
gimp_text_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2003-07-08 00:22:45 +08:00
|
|
|
GimpText *text = GIMP_TEXT (object);
|
|
|
|
GimpMatrix2 *matrix;
|
2002-10-10 22:30:01 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_TEXT:
|
2003-01-31 17:22:42 +08:00
|
|
|
g_free (text->text);
|
|
|
|
text->text = g_value_dup_string (value);
|
2010-03-03 04:54:24 +08:00
|
|
|
if (text->text && text->markup)
|
|
|
|
{
|
2019-05-27 23:47:55 +08:00
|
|
|
g_clear_pointer (&text->markup, g_free);
|
2010-03-03 04:54:24 +08:00
|
|
|
g_object_notify (object, "markup");
|
|
|
|
}
|
2002-10-10 22:30:01 +08:00
|
|
|
break;
|
2010-02-26 07:11:25 +08:00
|
|
|
case PROP_MARKUP:
|
|
|
|
g_free (text->markup);
|
|
|
|
text->markup = g_value_dup_string (value);
|
2010-03-03 04:54:24 +08:00
|
|
|
if (text->markup && text->text)
|
|
|
|
{
|
2019-05-27 23:47:55 +08:00
|
|
|
g_clear_pointer (&text->text, g_free);
|
2010-03-03 04:54:24 +08:00
|
|
|
g_object_notify (object, "text");
|
|
|
|
}
|
2010-02-26 07:11:25 +08:00
|
|
|
break;
|
2002-10-10 22:30:01 +08:00
|
|
|
case PROP_FONT:
|
2007-07-12 17:11:03 +08:00
|
|
|
{
|
2023-08-02 04:32:10 +08:00
|
|
|
GimpFont *font = g_value_get_object (value);
|
2007-07-20 23:10:24 +08:00
|
|
|
|
2023-08-02 04:32:10 +08:00
|
|
|
if (font != text->font)
|
|
|
|
g_set_object (&text->font, font);
|
2007-07-12 17:11:03 +08:00
|
|
|
}
|
2002-10-10 22:30:01 +08:00
|
|
|
break;
|
2003-01-31 21:36:27 +08:00
|
|
|
case PROP_FONT_SIZE:
|
|
|
|
text->font_size = g_value_get_double (value);
|
2002-10-10 22:30:01 +08:00
|
|
|
break;
|
2003-10-26 08:03:16 +08:00
|
|
|
case PROP_UNIT:
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-26 02:55:21 +08:00
|
|
|
text->unit = g_value_get_object (value);
|
2002-10-10 22:30:01 +08:00
|
|
|
break;
|
2003-03-28 01:24:53 +08:00
|
|
|
case PROP_ANTIALIAS:
|
|
|
|
text->antialias = g_value_get_boolean (value);
|
|
|
|
break;
|
2008-10-27 15:59:32 +08:00
|
|
|
case PROP_HINT_STYLE:
|
|
|
|
text->hint_style = g_value_get_enum (value);
|
|
|
|
break;
|
2003-10-25 23:25:17 +08:00
|
|
|
case PROP_KERNING:
|
|
|
|
text->kerning = g_value_get_boolean (value);
|
|
|
|
break;
|
2003-02-25 02:54:24 +08:00
|
|
|
case PROP_LANGUAGE:
|
|
|
|
g_free (text->language);
|
|
|
|
text->language = g_value_dup_string (value);
|
|
|
|
break;
|
2003-03-29 00:15:07 +08:00
|
|
|
case PROP_BASE_DIR:
|
|
|
|
text->base_dir = g_value_get_enum (value);
|
|
|
|
break;
|
2003-01-31 17:22:42 +08:00
|
|
|
case PROP_COLOR:
|
app, libgimp, pdb, plug-ins: GimpText* using GeglColor.
One of the big improvement in this commit is that text layers are now much
better at space accuracy. They were already space-aware, yet rendered as sRGB u8
only before being converted to the image's space. It means that text layers had
the following limitations:
* Any color out of sRGB gamut were trimmed.
* Precision was always 8-bit (even if the image was high-bit depth).
Now GimpTextLayout keeps track of its source space (for RGB and CMYK only, this
won't be as easy when we will support more backend, since Cairo has only RGB
support for image data) and the image TRC (in case it bypasses the color space's
TRB) and it draws within this gamut and space.
It means first that we are not limited to sRGB colors; we will draw text main
color in the full image gamut, with still 2 remaining limitations:
* Unbounded colors are impossible because Pango format (to color text) uses
hexadecimal (so even with half/float images, you can't draw out-of-gamut text
unfortunately).
* Main color precision is still 8-bit, yet a tiny bit better than before as we
at least follow TRC (so we avoid some of the precision loss when converting,
even though the bit-depth is still the biggest loss).
The outline color on the other hand is drawn through Cairo API entirely, in
float. This means that the outline color will now be without any precision loss.
Note that this depends on CAIRO_FORMAT_RGBA128F which is only available since
Cairo 1.17.2 which is not in Debian bookworm (our current baseline for GIMP
3.0). It means that the old precision will still happen with older Cairo
version, as determined by #if code at compilation.
2023-11-18 05:36:31 +08:00
|
|
|
g_set_object (&text->color, g_value_get_object (value));;
|
2003-01-31 17:22:42 +08:00
|
|
|
break;
|
2003-10-26 08:03:16 +08:00
|
|
|
case PROP_OUTLINE:
|
|
|
|
text->outline = g_value_get_enum (value);
|
|
|
|
break;
|
2003-02-05 17:51:26 +08:00
|
|
|
case PROP_JUSTIFICATION:
|
|
|
|
text->justify = g_value_get_enum (value);
|
2003-02-05 16:29:12 +08:00
|
|
|
break;
|
2003-02-05 17:51:26 +08:00
|
|
|
case PROP_INDENTATION:
|
|
|
|
text->indent = g_value_get_double (value);
|
2002-10-10 22:30:01 +08:00
|
|
|
break;
|
|
|
|
case PROP_LINE_SPACING:
|
|
|
|
text->line_spacing = g_value_get_double (value);
|
|
|
|
break;
|
2003-10-25 23:25:17 +08:00
|
|
|
case PROP_LETTER_SPACING:
|
|
|
|
text->letter_spacing = g_value_get_double (value);
|
|
|
|
break;
|
2003-04-10 05:19:12 +08:00
|
|
|
case PROP_BOX_MODE:
|
|
|
|
text->box_mode = g_value_get_enum (value);
|
2003-02-05 17:51:26 +08:00
|
|
|
break;
|
2003-03-28 01:24:53 +08:00
|
|
|
case PROP_BOX_WIDTH:
|
2003-04-10 05:19:12 +08:00
|
|
|
text->box_width = g_value_get_double (value);
|
|
|
|
break;
|
|
|
|
case PROP_BOX_HEIGHT:
|
|
|
|
text->box_height = g_value_get_double (value);
|
|
|
|
break;
|
|
|
|
case PROP_BOX_UNIT:
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-26 02:55:21 +08:00
|
|
|
text->box_unit = g_value_get_object (value);
|
2003-03-28 01:24:53 +08:00
|
|
|
break;
|
2003-07-08 00:22:45 +08:00
|
|
|
case PROP_TRANSFORMATION:
|
|
|
|
matrix = g_value_get_boxed (value);
|
|
|
|
text->transformation = *matrix;
|
|
|
|
break;
|
2003-10-26 08:03:16 +08:00
|
|
|
case PROP_OFFSET_X:
|
|
|
|
text->offset_x = g_value_get_double (value);
|
|
|
|
break;
|
|
|
|
case PROP_OFFSET_Y:
|
|
|
|
text->offset_y = g_value_get_double (value);
|
|
|
|
break;
|
2022-10-04 03:45:52 +08:00
|
|
|
case PROP_OUTLINE_STYLE:
|
|
|
|
text->outline_style = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_OUTLINE_FOREGROUND:
|
app, libgimp, pdb, plug-ins: GimpText* using GeglColor.
One of the big improvement in this commit is that text layers are now much
better at space accuracy. They were already space-aware, yet rendered as sRGB u8
only before being converted to the image's space. It means that text layers had
the following limitations:
* Any color out of sRGB gamut were trimmed.
* Precision was always 8-bit (even if the image was high-bit depth).
Now GimpTextLayout keeps track of its source space (for RGB and CMYK only, this
won't be as easy when we will support more backend, since Cairo has only RGB
support for image data) and the image TRC (in case it bypasses the color space's
TRB) and it draws within this gamut and space.
It means first that we are not limited to sRGB colors; we will draw text main
color in the full image gamut, with still 2 remaining limitations:
* Unbounded colors are impossible because Pango format (to color text) uses
hexadecimal (so even with half/float images, you can't draw out-of-gamut text
unfortunately).
* Main color precision is still 8-bit, yet a tiny bit better than before as we
at least follow TRC (so we avoid some of the precision loss when converting,
even though the bit-depth is still the biggest loss).
The outline color on the other hand is drawn through Cairo API entirely, in
float. This means that the outline color will now be without any precision loss.
Note that this depends on CAIRO_FORMAT_RGBA128F which is only available since
Cairo 1.17.2 which is not in Debian bookworm (our current baseline for GIMP
3.0). It means that the old precision will still happen with older Cairo
version, as determined by #if code at compilation.
2023-11-18 05:36:31 +08:00
|
|
|
g_set_object (&text->outline_foreground, g_value_get_object (value));;
|
2022-10-04 03:45:52 +08:00
|
|
|
break;
|
|
|
|
case PROP_OUTLINE_PATTERN:
|
|
|
|
{
|
|
|
|
GimpPattern *pattern = g_value_get_object (value);
|
|
|
|
|
|
|
|
if (text->outline_pattern != pattern)
|
|
|
|
{
|
|
|
|
if (text->outline_pattern)
|
|
|
|
g_object_unref (text->outline_pattern);
|
|
|
|
|
|
|
|
text->outline_pattern = pattern ? g_object_ref (pattern) : pattern;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PROP_OUTLINE_WIDTH:
|
|
|
|
text->outline_width = g_value_get_double (value);
|
|
|
|
break;
|
|
|
|
case PROP_OUTLINE_CAP_STYLE:
|
|
|
|
text->outline_cap_style = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_OUTLINE_JOIN_STYLE:
|
|
|
|
text->outline_join_style = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_OUTLINE_MITER_LIMIT:
|
|
|
|
text->outline_miter_limit = g_value_get_double (value);
|
|
|
|
break;
|
|
|
|
case PROP_OUTLINE_ANTIALIAS:
|
|
|
|
text->outline_antialias = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case PROP_OUTLINE_DASH_OFFSET:
|
|
|
|
text->outline_dash_offset = g_value_get_double (value);
|
|
|
|
break;
|
|
|
|
case PROP_OUTLINE_DASH_INFO:
|
|
|
|
{
|
|
|
|
GimpValueArray *value_array = g_value_get_boxed (value);
|
|
|
|
text->outline_dash_info = gimp_dash_pattern_from_value_array (value_array);
|
|
|
|
}
|
|
|
|
break;
|
2003-01-31 21:36:27 +08:00
|
|
|
case PROP_BORDER:
|
|
|
|
text->border = g_value_get_int (value);
|
|
|
|
break;
|
2008-10-27 15:59:32 +08:00
|
|
|
case PROP_HINTING:
|
2011-04-16 21:17:22 +08:00
|
|
|
/* interpret "hinting" only if "hint-style" has its default
|
|
|
|
* value, so we don't overwrite a serialized new hint-style with
|
|
|
|
* a compat "hinting" that is only there for old GIMP versions
|
|
|
|
*/
|
|
|
|
if (text->hint_style == GIMP_TEXT_HINT_STYLE_MEDIUM)
|
|
|
|
text->hint_style = (g_value_get_boolean (value) ?
|
|
|
|
GIMP_TEXT_HINT_STYLE_MEDIUM :
|
|
|
|
GIMP_TEXT_HINT_STYLE_NONE);
|
2008-10-27 15:59:32 +08:00
|
|
|
break;
|
2022-10-04 03:45:52 +08:00
|
|
|
case PROP_GIMP:
|
2023-06-23 04:23:05 +08:00
|
|
|
text->gimp = g_value_get_object (value);
|
2022-10-04 03:45:52 +08:00
|
|
|
break;
|
2002-10-10 22:30:01 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-02-25 02:54:24 +08:00
|
|
|
|
2010-03-03 00:44:31 +08:00
|
|
|
static void
|
|
|
|
gimp_text_dispatch_properties_changed (GObject *object,
|
|
|
|
guint n_pspecs,
|
|
|
|
GParamSpec **pspecs)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispatch_properties_changed (object,
|
|
|
|
n_pspecs, pspecs);
|
|
|
|
|
|
|
|
g_signal_emit (object, text_signals[CHANGED], 0);
|
|
|
|
}
|
|
|
|
|
2003-11-17 01:51:36 +08:00
|
|
|
static gint64
|
2003-08-25 20:24:51 +08:00
|
|
|
gimp_text_get_memsize (GimpObject *object,
|
2003-11-17 01:51:36 +08:00
|
|
|
gint64 *gui_size)
|
2003-08-25 20:24:51 +08:00
|
|
|
{
|
2005-12-11 03:24:36 +08:00
|
|
|
GimpText *text = GIMP_TEXT (object);
|
2003-11-17 01:51:36 +08:00
|
|
|
gint64 memsize = 0;
|
2003-08-25 20:24:51 +08:00
|
|
|
|
2007-11-17 02:19:30 +08:00
|
|
|
memsize += gimp_string_get_memsize (text->text);
|
2010-02-26 07:11:25 +08:00
|
|
|
memsize += gimp_string_get_memsize (text->markup);
|
2007-11-17 02:19:30 +08:00
|
|
|
memsize += gimp_string_get_memsize (text->language);
|
2003-08-25 20:24:51 +08:00
|
|
|
|
|
|
|
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
|
|
|
|
gui_size);
|
|
|
|
}
|
2005-03-20 09:56:58 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
gimp_text_get_transformation (GimpText *text,
|
|
|
|
GimpMatrix3 *matrix)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_TEXT (text));
|
|
|
|
g_return_if_fail (matrix != NULL);
|
|
|
|
|
|
|
|
matrix->coeff[0][0] = text->transformation.coeff[0][0];
|
|
|
|
matrix->coeff[0][1] = text->transformation.coeff[0][1];
|
|
|
|
matrix->coeff[0][2] = text->offset_x;
|
|
|
|
|
|
|
|
matrix->coeff[1][0] = text->transformation.coeff[1][0];
|
|
|
|
matrix->coeff[1][1] = text->transformation.coeff[1][1];
|
|
|
|
matrix->coeff[1][2] = text->offset_y;
|
|
|
|
|
|
|
|
matrix->coeff[2][0] = 0.0;
|
|
|
|
matrix->coeff[2][1] = 0.0;
|
2014-08-16 05:05:05 +08:00
|
|
|
matrix->coeff[2][2] = 1.0;
|
2005-03-20 09:56:58 +08:00
|
|
|
}
|
2022-10-04 03:45:52 +08:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_text_serialize_property (GimpConfig *config,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GimpConfigWriter *writer)
|
|
|
|
{
|
|
|
|
if (property_id == PROP_OUTLINE_PATTERN)
|
|
|
|
{
|
|
|
|
GimpObject *serialize_obj = g_value_get_object (value);
|
|
|
|
|
|
|
|
gimp_config_writer_open (writer, pspec->name);
|
|
|
|
|
|
|
|
if (serialize_obj)
|
|
|
|
gimp_config_writer_string (writer, gimp_object_get_name (serialize_obj));
|
|
|
|
else
|
|
|
|
gimp_config_writer_print (writer, "NULL", 4);
|
|
|
|
|
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
|
2023-08-16 01:57:52 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (property_id == PROP_MARKUP)
|
|
|
|
{
|
|
|
|
gchar *markup = (gchar*)g_value_get_string (value);
|
|
|
|
GRegex *regex;
|
|
|
|
GimpText *text;
|
|
|
|
GimpContainer *container;
|
|
|
|
PangoAttrList *attr_list;
|
|
|
|
GimpFont *font;
|
|
|
|
guint length;
|
|
|
|
GSList *list = NULL;
|
|
|
|
GSList *fonts = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_TEXT (config), FALSE);
|
|
|
|
|
|
|
|
if (markup == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
text = GIMP_TEXT (config);
|
|
|
|
container = gimp_data_factory_get_container (text->gimp->font_factory);
|
|
|
|
|
|
|
|
/*lookupname format is "gimpfont%d" we keep only the "font%d" part
|
|
|
|
* this is to avoid problems when deserializing
|
|
|
|
* e.g. if there are 2 fonts with lookupname gimpfont17 and gimpfont23
|
|
|
|
* we might replace the first with a font whose lookupname is gimpfont23,
|
|
|
|
* and we might replace the original gimpfont23 with say gimpfont29
|
|
|
|
* this means that all occurences of gimpfont23 turned into gimpfont29
|
|
|
|
*/
|
|
|
|
regex = g_regex_new ("\"gimpfont(\\d+)\"", 0, 0, NULL);
|
|
|
|
markup = g_regex_replace (regex, markup, -1, 0, "\"font\\1\"", 0, NULL);
|
|
|
|
|
|
|
|
gimp_config_writer_open (writer, "markup");
|
|
|
|
gimp_config_writer_string (writer, markup);
|
|
|
|
|
|
|
|
pango_parse_markup (markup, -1, 0, &attr_list, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
list = pango_attr_list_get_attributes (attr_list);
|
|
|
|
length = g_slist_length (list);
|
|
|
|
|
|
|
|
for (guint i = 0; i < length; ++i)
|
|
|
|
{
|
|
|
|
PangoAttrFontDesc *attr_font_desc = pango_attribute_as_font_desc ((PangoAttribute*)g_slist_nth_data (list, i));
|
|
|
|
|
|
|
|
if (attr_font_desc != NULL)
|
|
|
|
{
|
|
|
|
gchar *altered_font_name = pango_font_description_to_string (attr_font_desc->desc);
|
|
|
|
gchar *font_name = g_strdup_printf ("gimp%s", altered_font_name);
|
|
|
|
|
2023-09-12 03:31:33 +08:00
|
|
|
if (g_slist_find_custom (fonts, (gconstpointer) font_name, (GCompareFunc) g_strcmp0) == NULL)
|
2023-08-16 01:57:52 +08:00
|
|
|
{
|
|
|
|
fonts = g_slist_prepend (fonts, (gpointer) font_name);
|
|
|
|
|
2024-04-18 09:26:19 +08:00
|
|
|
if (g_str_has_prefix (altered_font_name, "font"))
|
|
|
|
font = GIMP_FONT (gimp_container_search (container,
|
|
|
|
(GimpContainerSearchFunc) gimp_font_match_by_lookup_name,
|
|
|
|
(gpointer) font_name));
|
|
|
|
/* in case the font is an alias its lookupname is that alias and doesn't conform to the format "gimpfont%d"*/
|
|
|
|
else
|
|
|
|
font = GIMP_FONT (gimp_container_search (container,
|
|
|
|
(GimpContainerSearchFunc) gimp_font_match_by_lookup_name,
|
|
|
|
(gpointer) altered_font_name));
|
2023-08-16 01:57:52 +08:00
|
|
|
|
|
|
|
gimp_config_writer_open (writer, "markupfont");
|
2024-04-18 09:26:19 +08:00
|
|
|
/*lookupname format is "gimpfont%d" we keep only the "font%d",
|
|
|
|
* and in case the font is an alias, we keep its name (see the above comments)*/
|
2023-08-16 01:57:52 +08:00
|
|
|
gimp_config_writer_string (writer, font_name+4);
|
|
|
|
|
|
|
|
gimp_config_writer_open (writer, "font");
|
|
|
|
GIMP_CONFIG_GET_IFACE (GIMP_CONFIG (font))->serialize (GIMP_CONFIG (font),
|
|
|
|
writer,
|
|
|
|
NULL);
|
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_free (font_name);
|
|
|
|
}
|
|
|
|
g_free (altered_font_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
|
|
|
|
g_slist_free_full (fonts, (GDestroyNotify) g_free);
|
|
|
|
g_slist_free_full (list, (GDestroyNotify) pango_attribute_destroy);
|
|
|
|
pango_attr_list_unref (attr_list);
|
|
|
|
g_free (markup);
|
|
|
|
g_regex_unref (regex);
|
|
|
|
|
2022-10-04 03:45:52 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_text_deserialize_property (GimpConfig *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GScanner *scanner,
|
|
|
|
GTokenType *expected)
|
|
|
|
{
|
|
|
|
if (property_id == PROP_OUTLINE_PATTERN)
|
|
|
|
{
|
|
|
|
gchar *object_name;
|
|
|
|
|
|
|
|
if (gimp_scanner_parse_identifier (scanner, "NULL"))
|
|
|
|
{
|
|
|
|
g_value_set_object (value, NULL);
|
|
|
|
}
|
|
|
|
else if (gimp_scanner_parse_string (scanner, &object_name))
|
|
|
|
{
|
|
|
|
GimpText *text = GIMP_TEXT (object);
|
|
|
|
GimpContainer *container;
|
|
|
|
GimpObject *deserialize_obj;
|
|
|
|
|
|
|
|
if (! object_name)
|
|
|
|
object_name = g_strdup ("");
|
|
|
|
|
|
|
|
container = gimp_data_factory_get_container (text->gimp->pattern_factory);
|
|
|
|
|
|
|
|
deserialize_obj = gimp_container_get_child_by_name (container,
|
|
|
|
object_name);
|
|
|
|
|
|
|
|
g_value_set_object (value, deserialize_obj);
|
|
|
|
|
|
|
|
g_free (object_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*expected = G_TOKEN_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (property_id == PROP_OUTLINE_DASH_INFO)
|
|
|
|
{
|
|
|
|
if (gimp_scanner_parse_identifier (scanner, "NULL"))
|
|
|
|
{
|
|
|
|
g_value_take_boxed (value, NULL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2023-08-16 01:57:52 +08:00
|
|
|
else if (property_id == PROP_MARKUP)
|
|
|
|
{
|
2023-09-22 21:24:22 +08:00
|
|
|
gchar *markup = NULL;
|
2023-08-16 01:57:52 +08:00
|
|
|
GString *markup_str;
|
|
|
|
GimpFont *dummy_object = g_object_new (GIMP_TYPE_FONT, NULL);
|
|
|
|
|
|
|
|
gimp_scanner_parse_string (scanner, &markup);
|
|
|
|
|
|
|
|
markup_str = g_string_new (markup);
|
|
|
|
|
|
|
|
/* This is for backward compatibility with older xcf files.*/
|
|
|
|
if (g_scanner_peek_next_token (scanner) == G_TOKEN_STRING)
|
2023-09-12 03:31:33 +08:00
|
|
|
{
|
|
|
|
while (g_scanner_peek_next_token (scanner) == G_TOKEN_STRING)
|
|
|
|
{
|
2023-09-22 21:24:22 +08:00
|
|
|
gchar *markup_fontname = NULL;
|
2023-09-12 03:31:33 +08:00
|
|
|
gchar *replaced_markup;
|
|
|
|
gchar *new_markup;
|
|
|
|
GimpFont *font;
|
|
|
|
|
|
|
|
gimp_scanner_parse_string (scanner, &markup_fontname);
|
|
|
|
|
|
|
|
font = GIMP_FONT (GIMP_CONFIG_GET_IFACE (dummy_object)->deserialize_create (GIMP_TYPE_FONT,
|
|
|
|
scanner,
|
|
|
|
-1,
|
|
|
|
NULL));
|
|
|
|
replaced_markup = g_markup_printf_escaped (" font=\"%s\"", markup_fontname);
|
|
|
|
new_markup = g_strdup_printf (" gimpfont=\"%s\"", gimp_font_get_lookup_name (font));
|
|
|
|
g_string_replace (markup_str, replaced_markup, new_markup, 0);
|
|
|
|
|
|
|
|
g_free (markup_fontname);
|
|
|
|
g_free (replaced_markup);
|
|
|
|
g_free (new_markup);
|
|
|
|
g_object_unref (font);
|
|
|
|
}
|
|
|
|
/* We avoid the edge case when actual fonts are called "gimpfont%d"
|
|
|
|
* and their replacement name chains to each other by marking already
|
|
|
|
* processed font as "gimpfont=". Then we clean up this fake attribute
|
|
|
|
* name in the end.
|
|
|
|
* This is not a problem with the new format as font are stored as
|
|
|
|
* "font%d" (see comment in gimp_text_serialize_property()).
|
|
|
|
*/
|
|
|
|
g_string_replace (markup_str, " gimpfont=\"", " font=\"", 0);
|
|
|
|
}
|
2023-08-16 01:57:52 +08:00
|
|
|
else
|
2023-09-12 03:31:33 +08:00
|
|
|
{
|
|
|
|
while (g_scanner_peek_next_token (scanner) == G_TOKEN_LEFT_PAREN)
|
|
|
|
{
|
2023-09-22 21:24:22 +08:00
|
|
|
gchar *lookupname = NULL;
|
2023-09-12 03:31:33 +08:00
|
|
|
gchar *replaced_markup;
|
|
|
|
gchar *new_markup;
|
|
|
|
GimpFont *font;
|
|
|
|
|
|
|
|
g_scanner_get_next_token (scanner); /* ( */
|
|
|
|
g_scanner_get_next_token (scanner); /* "lookupname" */
|
|
|
|
gimp_scanner_parse_string (scanner, &lookupname);
|
|
|
|
|
|
|
|
g_scanner_get_next_token (scanner); /* ) */
|
|
|
|
g_scanner_get_next_token (scanner); /* font */
|
|
|
|
|
|
|
|
font = GIMP_FONT (GIMP_CONFIG_GET_IFACE (dummy_object)->deserialize_create (GIMP_TYPE_FONT,
|
|
|
|
scanner,
|
|
|
|
-1,
|
|
|
|
NULL));
|
|
|
|
g_scanner_get_next_token (scanner); /* ) */
|
|
|
|
g_scanner_get_next_token (scanner); /* ) */
|
|
|
|
|
|
|
|
replaced_markup = g_markup_printf_escaped (" font=\"%s\"", lookupname);
|
|
|
|
new_markup = g_strdup_printf (" font=\"%s\"", gimp_font_get_lookup_name (font));
|
|
|
|
g_string_replace (markup_str, replaced_markup, new_markup, 0);
|
|
|
|
|
|
|
|
g_free (lookupname);
|
|
|
|
g_free (replaced_markup);
|
|
|
|
g_free (new_markup);
|
|
|
|
g_object_unref (font);
|
|
|
|
}
|
|
|
|
}
|
2023-08-16 01:57:52 +08:00
|
|
|
|
|
|
|
g_value_set_string (value, markup_str->str);
|
|
|
|
|
|
|
|
g_object_unref (dummy_object);
|
|
|
|
g_string_free (markup_str, TRUE);
|
2023-09-22 21:24:22 +08:00
|
|
|
g_free (markup);
|
2023-08-16 01:57:52 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2022-10-04 03:45:52 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|