mirror of https://github.com/GNOME/gimp.git
app, devel-docs, libgimp: updating gimp_text_layer_[gs]et_font() and new…
… function gimp_font_get_pango_font_description(). Also updating file-pdf-save which is the only plug-in using these right now. Note that I am not fully happy with the new function gimp_font_get_pango_font_description() because I experienced some weird behavior in file-pdf-save which is that some fonts were wrong if this is called after pango_cairo_font_map_set_resolution(). But let's say this is a first step looking for improvements.
This commit is contained in:
parent
faae47a9a8
commit
ea55b7a11a
|
@ -255,26 +255,26 @@ text_layer_get_font_invoker (GimpProcedure *procedure,
|
|||
gboolean success = TRUE;
|
||||
GimpValueArray *return_vals;
|
||||
GimpTextLayer *layer;
|
||||
gchar *font = NULL;
|
||||
GimpFont *font = NULL;
|
||||
|
||||
layer = g_value_get_object (gimp_value_array_index (args, 0));
|
||||
|
||||
if (success)
|
||||
{
|
||||
GimpFont *font_obj;
|
||||
|
||||
g_object_get (gimp_text_layer_get_text (layer),
|
||||
"font", &font_obj,
|
||||
"font", &font,
|
||||
NULL);
|
||||
font = g_strdup (gimp_font_get_lookup_name (font_obj));
|
||||
g_object_unref (font_obj);
|
||||
/* The GimpText keeps a reference. Therefore unref before returning the
|
||||
* pointer so that we don't leak a reference.
|
||||
*/
|
||||
g_object_unref (font);
|
||||
}
|
||||
|
||||
return_vals = gimp_procedure_get_return_values (procedure, success,
|
||||
error ? *error : NULL);
|
||||
|
||||
if (success)
|
||||
g_value_take_string (gimp_value_array_index (return_vals, 1), font);
|
||||
g_value_set_object (gimp_value_array_index (return_vals, 1), font);
|
||||
|
||||
return return_vals;
|
||||
}
|
||||
|
@ -289,10 +289,10 @@ text_layer_set_font_invoker (GimpProcedure *procedure,
|
|||
{
|
||||
gboolean success = TRUE;
|
||||
GimpTextLayer *layer;
|
||||
const gchar *font;
|
||||
GimpFont *font;
|
||||
|
||||
layer = g_value_get_object (gimp_value_array_index (args, 0));
|
||||
font = g_value_get_string (gimp_value_array_index (args, 1));
|
||||
font = g_value_get_object (gimp_value_array_index (args, 1));
|
||||
|
||||
if (success)
|
||||
{
|
||||
|
@ -1182,7 +1182,7 @@ register_text_layer_procs (GimpPDB *pdb)
|
|||
"gimp-text-layer-get-font");
|
||||
gimp_procedure_set_static_help (procedure,
|
||||
"Get the font from a text layer as string.",
|
||||
"This procedure returns the name of the font from a text layer.",
|
||||
"This procedure returns the font from a text layer.",
|
||||
NULL);
|
||||
gimp_procedure_set_static_attribution (procedure,
|
||||
"Marcus Heese <heese@cip.ifi.lmu.de>",
|
||||
|
@ -1195,12 +1195,11 @@ register_text_layer_procs (GimpPDB *pdb)
|
|||
FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_procedure_add_return_value (procedure,
|
||||
gimp_param_spec_string ("font",
|
||||
"font",
|
||||
"The font which is used in the specified text layer.",
|
||||
FALSE, FALSE, FALSE,
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_param_spec_font ("font",
|
||||
"font",
|
||||
"The font which is used in the specified text layer.",
|
||||
FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_pdb_register_procedure (pdb, procedure);
|
||||
g_object_unref (procedure);
|
||||
|
||||
|
@ -1225,12 +1224,11 @@ register_text_layer_procs (GimpPDB *pdb)
|
|||
FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
gimp_param_spec_string ("font",
|
||||
"font",
|
||||
"The new font to use",
|
||||
FALSE, FALSE, FALSE,
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_param_spec_font ("font",
|
||||
"font",
|
||||
"The new font to use",
|
||||
FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_pdb_register_procedure (pdb, procedure);
|
||||
g_object_unref (procedure);
|
||||
|
||||
|
|
|
@ -61,6 +61,11 @@ search_index = true
|
|||
description = "A 2D graphics library with support for multiple output devices"
|
||||
docs_url = "https://www.cairographics.org/manual/"
|
||||
|
||||
[dependencies."Pango-1.0"]
|
||||
name = "Pango"
|
||||
description = "Internationalized text layout and rendering"
|
||||
docs_url = "https://docs.gtk.org/Pango/"
|
||||
|
||||
[theme]
|
||||
name = "basic"
|
||||
show_index_summary = true
|
||||
|
|
|
@ -8,4 +8,5 @@ baseURLs = [
|
|||
[ 'GdkPixbuf', 'https://docs.gtk.org/gdk-pixbuf/' ],
|
||||
[ 'Gio', 'https://docs.gtk.org/gio/' ],
|
||||
[ 'Gtk', 'https://docs.gtk.org/gtk3/' ],
|
||||
[ 'Pango', 'https://docs.gtk.org/Pango/' ],
|
||||
]
|
||||
|
|
|
@ -294,6 +294,7 @@ EXPORTS
|
|||
gimp_floating_sel_remove
|
||||
gimp_floating_sel_to_layer
|
||||
gimp_font_get_by_name
|
||||
gimp_font_get_pango_font_description
|
||||
gimp_font_get_type
|
||||
gimp_fonts_close_popup
|
||||
gimp_fonts_get_list
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <glib-object.h>
|
||||
#include <gegl.h>
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
#include <pango/pango.h>
|
||||
|
||||
#include <libgimpbase/gimpbase.h>
|
||||
#include <libgimpcolor/gimpcolor.h>
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <pango/pangofc-fontmap.h>
|
||||
|
||||
#include "gimp.h"
|
||||
|
||||
#include "gimpfont.h"
|
||||
|
@ -40,3 +42,45 @@ static void gimp_font_class_init (GimpFontClass *klass)
|
|||
static void gimp_font_init (GimpFont *font)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_font_get_pango_font_description:
|
||||
* @font: (transfer none): the [class@Gimp.Font]
|
||||
*
|
||||
* Returns a [class@Pango.Font.Description] representing @font.
|
||||
*
|
||||
* Returns: (transfer full): a %PangoFontDescription representing @font.
|
||||
*
|
||||
* Since: 3.0
|
||||
**/
|
||||
PangoFontDescription *
|
||||
gimp_font_get_pango_font_description (GimpFont *font)
|
||||
{
|
||||
PangoFontDescription *desc = NULL;
|
||||
gchar *name = NULL;
|
||||
gchar *collection_id = NULL;
|
||||
gboolean is_internal;
|
||||
|
||||
is_internal = _gimp_resource_get_identifiers (GIMP_RESOURCE (font),
|
||||
&name, &collection_id);
|
||||
/* TODO: we can't create fonts from internal fonts right now, but it should
|
||||
* actually be possible because these are in fact alias to non-internal fonts.
|
||||
* See #9985.
|
||||
*/
|
||||
if (! is_internal)
|
||||
{
|
||||
gchar *expanded_path;
|
||||
|
||||
expanded_path = gimp_config_path_expand (collection_id, FALSE, NULL);
|
||||
if (expanded_path != NULL &&
|
||||
FcConfigAppFontAddFile (FcConfigGetCurrent (), (const FcChar8 *) expanded_path))
|
||||
desc = pango_font_description_from_string (name);
|
||||
|
||||
g_free (expanded_path);
|
||||
}
|
||||
|
||||
g_free (name);
|
||||
g_free (collection_id);
|
||||
|
||||
return desc;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,9 @@ G_BEGIN_DECLS
|
|||
G_DECLARE_FINAL_TYPE (GimpFont, gimp_font, GIMP, FONT, GimpResource)
|
||||
|
||||
|
||||
PangoFontDescription * gimp_font_get_pango_font_description (GimpFont *font);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GIMP_FONT_H__ */
|
||||
|
|
|
@ -121,6 +121,7 @@ static GimpLayer *
|
|||
gimp_text_layer_copy (GimpLayer *layer)
|
||||
{
|
||||
GimpTextLayer *new_layer;
|
||||
GimpFont *font;
|
||||
gchar *text;
|
||||
gchar *fontname;
|
||||
gdouble size;
|
||||
|
@ -129,7 +130,8 @@ gimp_text_layer_copy (GimpLayer *layer)
|
|||
g_return_val_if_fail (GIMP_IS_TEXT_LAYER (layer), NULL);
|
||||
|
||||
text = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
|
||||
fontname = gimp_text_layer_get_font (GIMP_TEXT_LAYER (layer));
|
||||
font = gimp_text_layer_get_font (GIMP_TEXT_LAYER (layer));
|
||||
fontname = gimp_resource_get_name (GIMP_RESOURCE (font));
|
||||
size = gimp_text_layer_get_font_size (GIMP_TEXT_LAYER (layer), &unit);
|
||||
new_layer = gimp_text_layer_new (gimp_item_get_image (GIMP_ITEM (layer)),
|
||||
text, fontname, size, unit);
|
||||
|
|
|
@ -254,20 +254,19 @@ gimp_text_layer_set_markup (GimpTextLayer *layer,
|
|||
*
|
||||
* Get the font from a text layer as string.
|
||||
*
|
||||
* This procedure returns the name of the font from a text layer.
|
||||
* This procedure returns the font from a text layer.
|
||||
*
|
||||
* Returns: (transfer full):
|
||||
* Returns: (transfer none):
|
||||
* The font which is used in the specified text layer.
|
||||
* The returned value must be freed with g_free().
|
||||
*
|
||||
* Since: 2.6
|
||||
**/
|
||||
gchar *
|
||||
GimpFont *
|
||||
gimp_text_layer_get_font (GimpTextLayer *layer)
|
||||
{
|
||||
GimpValueArray *args;
|
||||
GimpValueArray *return_vals;
|
||||
gchar *font = NULL;
|
||||
GimpFont *font = NULL;
|
||||
|
||||
args = gimp_value_array_new_from_types (NULL,
|
||||
GIMP_TYPE_TEXT_LAYER, layer,
|
||||
|
@ -279,7 +278,7 @@ gimp_text_layer_get_font (GimpTextLayer *layer)
|
|||
gimp_value_array_unref (args);
|
||||
|
||||
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
|
||||
font = GIMP_VALUES_DUP_STRING (return_vals, 1);
|
||||
font = GIMP_VALUES_GET_FONT (return_vals, 1);
|
||||
|
||||
gimp_value_array_unref (return_vals);
|
||||
|
||||
|
@ -301,7 +300,7 @@ gimp_text_layer_get_font (GimpTextLayer *layer)
|
|||
**/
|
||||
gboolean
|
||||
gimp_text_layer_set_font (GimpTextLayer *layer,
|
||||
const gchar *font)
|
||||
GimpFont *font)
|
||||
{
|
||||
GimpValueArray *args;
|
||||
GimpValueArray *return_vals;
|
||||
|
@ -309,7 +308,7 @@ gimp_text_layer_set_font (GimpTextLayer *layer,
|
|||
|
||||
args = gimp_value_array_new_from_types (NULL,
|
||||
GIMP_TYPE_TEXT_LAYER, layer,
|
||||
G_TYPE_STRING, font,
|
||||
GIMP_TYPE_FONT, font,
|
||||
G_TYPE_NONE);
|
||||
|
||||
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
|
||||
|
|
|
@ -43,9 +43,9 @@ gboolean gimp_text_layer_set_text (GimpTextLayer
|
|||
gchar* gimp_text_layer_get_markup (GimpTextLayer *layer);
|
||||
gboolean gimp_text_layer_set_markup (GimpTextLayer *layer,
|
||||
const gchar *markup);
|
||||
gchar* gimp_text_layer_get_font (GimpTextLayer *layer);
|
||||
GimpFont* gimp_text_layer_get_font (GimpTextLayer *layer);
|
||||
gboolean gimp_text_layer_set_font (GimpTextLayer *layer,
|
||||
const gchar *font);
|
||||
GimpFont *font);
|
||||
gdouble gimp_text_layer_get_font_size (GimpTextLayer *layer,
|
||||
GimpUnit *unit);
|
||||
gboolean gimp_text_layer_set_font_size (GimpTextLayer *layer,
|
||||
|
|
|
@ -344,6 +344,8 @@ libgimp = library('gimp-'+ gimp_api_version,
|
|||
gegl,
|
||||
gexiv2,
|
||||
drmingw,
|
||||
pango,
|
||||
pangoft2,
|
||||
],
|
||||
sources: [
|
||||
pdbgen
|
||||
|
@ -465,6 +467,7 @@ else
|
|||
'Gio-2.0',
|
||||
'GLib-2.0',
|
||||
'GObject-2.0',
|
||||
'Pango-1.0',
|
||||
]
|
||||
|
||||
gir_args = [
|
||||
|
|
|
@ -413,7 +413,7 @@ endif
|
|||
conf.set_quoted('MYPAINT_BRUSHES_DIR', mypaint_brushes_dir)
|
||||
|
||||
pango_minver = '1.50.0'
|
||||
pangocairo = dependency('pango', version: '>='+pango_minver)
|
||||
pango = dependency('pango', version: '>='+pango_minver)
|
||||
pangocairo = dependency('pangocairo', version: '>='+pango_minver)
|
||||
pangoft2 = dependency('pangoft2', version: '>='+pango_minver)
|
||||
rsvg_minver = '2.40.6'
|
||||
|
|
|
@ -231,7 +231,7 @@ sub text_layer_get_font {
|
|||
$blurb = 'Get the font from a text layer as string.';
|
||||
|
||||
$help = <<'HELP';
|
||||
This procedure returns the name of the font from a text layer.
|
||||
This procedure returns the font from a text layer.
|
||||
HELP
|
||||
|
||||
&marcus_pdb_misc('2008', '2.6');
|
||||
|
@ -242,20 +242,20 @@ HELP
|
|||
);
|
||||
|
||||
@outargs = (
|
||||
{ name => 'font', type => 'string',
|
||||
{ name => 'font', type => 'font',
|
||||
desc => 'The font which is used in the specified text layer.' }
|
||||
);
|
||||
|
||||
%invoke = (
|
||||
code => <<'CODE'
|
||||
{
|
||||
GimpFont *font_obj;
|
||||
|
||||
g_object_get (gimp_text_layer_get_text (layer),
|
||||
"font", &font_obj,
|
||||
"font", &font,
|
||||
NULL);
|
||||
font = g_strdup (gimp_font_get_lookup_name (font_obj));
|
||||
g_object_unref (font_obj);
|
||||
/* The GimpText keeps a reference. Therefore unref before returning the
|
||||
* pointer so that we don't leak a reference.
|
||||
*/
|
||||
g_object_unref (font);
|
||||
}
|
||||
CODE
|
||||
);
|
||||
|
@ -273,7 +273,7 @@ HELP
|
|||
@inargs = (
|
||||
{ name => 'layer', type => 'text_layer',
|
||||
desc => 'The text layer' },
|
||||
{ name => 'font', type => 'string',
|
||||
{ name => 'font', type => 'font',
|
||||
desc => 'The new font to use' }
|
||||
);
|
||||
|
||||
|
|
|
@ -641,7 +641,7 @@ get_missing_fonts (GList *layers)
|
|||
}
|
||||
else if (gimp_item_is_text_layer (GIMP_ITEM (layer)))
|
||||
{
|
||||
gchar *font_family;
|
||||
GimpFont *gimp_font;
|
||||
PangoFontDescription *font_description;
|
||||
PangoFontDescription *font_description2;
|
||||
PangoFontMap *fontmap;
|
||||
|
@ -651,8 +651,8 @@ get_missing_fonts (GList *layers)
|
|||
fontmap = pango_cairo_font_map_new_for_font_type (CAIRO_FONT_TYPE_FT);
|
||||
context = pango_font_map_create_context (fontmap);
|
||||
|
||||
font_family = gimp_text_layer_get_font (GIMP_TEXT_LAYER (layer));
|
||||
font_description = pango_font_description_from_string (font_family);
|
||||
gimp_font = gimp_text_layer_get_font (GIMP_TEXT_LAYER (layer));
|
||||
font_description = gimp_font_get_pango_font_description (gimp_font);
|
||||
|
||||
font = pango_font_map_load_font (fontmap, context, font_description);
|
||||
font_description2 = pango_font_describe (font);
|
||||
|
@ -669,7 +669,6 @@ get_missing_fonts (GList *layers)
|
|||
g_object_unref (font);
|
||||
pango_font_description_free (font_description);
|
||||
pango_font_description_free (font_description2);
|
||||
g_free (font_family);
|
||||
g_object_unref (context);
|
||||
g_object_unref (fontmap);
|
||||
}
|
||||
|
@ -1599,7 +1598,6 @@ drawText (GimpLayer *layer,
|
|||
GimpImageType type = gimp_drawable_type (GIMP_DRAWABLE (layer));
|
||||
gchar *text = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
|
||||
gchar *markup = gimp_text_layer_get_markup (GIMP_TEXT_LAYER (layer));
|
||||
gchar *font_family;
|
||||
gchar *language;
|
||||
cairo_font_options_t *options;
|
||||
gint x;
|
||||
|
@ -1614,6 +1612,7 @@ drawText (GimpLayer *layer,
|
|||
GimpTextDirection dir;
|
||||
PangoLayout *layout;
|
||||
PangoContext *context;
|
||||
GimpFont *font;
|
||||
PangoFontDescription *font_description;
|
||||
gdouble indent;
|
||||
gdouble line_spacing;
|
||||
|
@ -1676,6 +1675,15 @@ drawText (GimpLayer *layer,
|
|||
*/
|
||||
fontmap = pango_cairo_font_map_new_for_font_type (CAIRO_FONT_TYPE_FT);
|
||||
|
||||
/* Font */
|
||||
font = gimp_text_layer_get_font (GIMP_TEXT_LAYER (layer));
|
||||
font_description = gimp_font_get_pango_font_description (font);
|
||||
|
||||
/* This function breaks rendering with some fonts if it's called before
|
||||
* gimp_font_get_pango_font_description(). I'm still unsure why yet it
|
||||
* probably means there is a bug somewhere we must fix. Until then, let's make
|
||||
* sure we keep this order. XXX
|
||||
*/
|
||||
pango_cairo_font_map_set_resolution (PANGO_CAIRO_FONT_MAP (fontmap), y_res);
|
||||
|
||||
context = pango_font_map_create_context (fontmap);
|
||||
|
@ -1687,7 +1695,7 @@ drawText (GimpLayer *layer,
|
|||
language = gimp_text_layer_get_language (GIMP_TEXT_LAYER (layer));
|
||||
if (language)
|
||||
pango_context_set_language (context,
|
||||
pango_language_from_string(language));
|
||||
pango_language_from_string (language));
|
||||
|
||||
/* Text Direction */
|
||||
dir = gimp_text_layer_get_base_direction (GIMP_TEXT_LAYER (layer));
|
||||
|
@ -1737,14 +1745,6 @@ drawText (GimpLayer *layer,
|
|||
layout = pango_layout_new (context);
|
||||
pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR);
|
||||
|
||||
/* Font */
|
||||
font_family = gimp_text_layer_get_font (GIMP_TEXT_LAYER (layer));
|
||||
|
||||
/* We need to find a way to convert GIMP's returned font name to a
|
||||
* normal Pango name... Hopefully GIMP 2.8 with Pango will fix it.
|
||||
*/
|
||||
font_description = pango_font_description_from_string (font_family);
|
||||
|
||||
/* Font Size */
|
||||
size = gimp_text_layer_get_font_size (GIMP_TEXT_LAYER (layer), &unit);
|
||||
size = gimp_units_to_pixels (size, unit, y_res);
|
||||
|
@ -1825,7 +1825,6 @@ drawText (GimpLayer *layer,
|
|||
pango_cairo_show_layout (cr, layout);
|
||||
|
||||
g_free (text);
|
||||
g_free (font_family);
|
||||
g_free (language);
|
||||
|
||||
g_object_unref (layout);
|
||||
|
|
|
@ -21,7 +21,7 @@ common_plugins_list = [
|
|||
{ 'name': 'destripe', },
|
||||
{ 'name': 'file-cel', },
|
||||
{ 'name': 'file-compressor',
|
||||
'deps': [ gegl, gdk_pixbuf, cairo, gio, liblzma, bz2, zlib, ],
|
||||
'deps': [ gegl, gdk_pixbuf, cairo, gio, liblzma, pango, bz2, zlib, ],
|
||||
},
|
||||
{ 'name': 'file-csource', },
|
||||
{ 'name': 'file-desktop-link',
|
||||
|
|
Loading…
Reference in New Issue