PIKApp/libpika/pikatexttool_pdb.c

182 lines
6.7 KiB
C
Raw Normal View History

2023-09-26 00:35:21 +02:00
/* LIBPIKA - The PIKA Library
* Copyright (C) 1995-2003 Peter Mattis and Spencer Kimball
*
* pikatexttool_pdb.c
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
/* NOTE: This file is auto-generated by pdbgen.pl */
#include "config.h"
#include "stamp-pdbgen.h"
#include "pika.h"
/**
* SECTION: pikatexttool
* @title: pikatexttool
* @short_description: Functions for controlling the text tool.
*
* Functions for controlling the text tool.
**/
/**
* pika_text_fontname:
* @image: The image.
* @drawable: (nullable): The affected drawable: (%NULL for a new text layer).
* @x: The x coordinate for the left of the text bounding box.
* @y: The y coordinate for the top of the text bounding box.
* @text: The text to generate (in UTF-8 encoding).
* @border: The size of the border.
* @antialias: Antialiasing.
* @size: The size of text in either pixels or points.
* @size_type: The units of specified size.
* @fontname: The name of the font.
*
* Add text at the specified location as a floating selection or a new
* layer.
*
* This tool requires a fontname matching an installed PangoFT2 font.
* You can specify the fontsize in units of pixels or points, and the
* appropriate metric is specified using the size_type argument. The x
* and y parameters together control the placement of the new text by
* specifying the upper left corner of the text bounding box. If the
* specified drawable parameter is valid, the text will be created as a
* floating selection attached to the drawable. If the drawable
* parameter is not valid (%NULL), the text will appear as a new layer.
* Finally, a border can be specified around the final rendered text.
* The border is measured in pixels. Parameter size-type is not used
* and is currently ignored. If you need to display a font in points,
* divide the size in points by 72.0 and multiply it by the image's
* vertical resolution.
*
* Returns: (nullable) (transfer none):
* The new text layer or %NULL if no layer was created.
**/
PikaLayer *
pika_text_fontname (PikaImage *image,
PikaDrawable *drawable,
gdouble x,
gdouble y,
const gchar *text,
gint border,
gboolean antialias,
gdouble size,
PikaSizeType size_type,
const gchar *fontname)
{
PikaValueArray *args;
PikaValueArray *return_vals;
PikaLayer *text_layer = NULL;
args = pika_value_array_new_from_types (NULL,
PIKA_TYPE_IMAGE, image,
PIKA_TYPE_DRAWABLE, drawable,
G_TYPE_DOUBLE, x,
G_TYPE_DOUBLE, y,
G_TYPE_STRING, text,
G_TYPE_INT, border,
G_TYPE_BOOLEAN, antialias,
G_TYPE_DOUBLE, size,
PIKA_TYPE_SIZE_TYPE, size_type,
G_TYPE_STRING, fontname,
G_TYPE_NONE);
return_vals = pika_pdb_run_procedure_array (pika_get_pdb (),
"pika-text-fontname",
args);
pika_value_array_unref (args);
if (PIKA_VALUES_GET_ENUM (return_vals, 0) == PIKA_PDB_SUCCESS)
text_layer = PIKA_VALUES_GET_LAYER (return_vals, 1);
pika_value_array_unref (return_vals);
return text_layer;
}
/**
* pika_text_get_extents_fontname:
* @text: The text to generate (in UTF-8 encoding).
* @size: The size of text in either pixels or points.
* @size_type: The units of specified size.
* @fontname: The name of the font.
* @width: (out): The width of the specified font.
* @height: (out): The height of the specified font.
* @ascent: (out): The ascent of the specified font.
* @descent: (out): The descent of the specified font.
*
* Get extents of the bounding box for the specified text.
*
* This tool returns the width and height of a bounding box for the
* specified text string with the specified font information. Ascent
* and descent for the specified font are returned as well. Parameter
* size-type is not used and is currently ignored. If you need to
* display a font in points, divide the size in points by 72.0 and
* multiply it by the vertical resolution of the image you are taking
* into account.
*
* Returns: TRUE on success.
**/
gboolean
pika_text_get_extents_fontname (const gchar *text,
gdouble size,
PikaSizeType size_type,
const gchar *fontname,
gint *width,
gint *height,
gint *ascent,
gint *descent)
{
PikaValueArray *args;
PikaValueArray *return_vals;
gboolean success = TRUE;
args = pika_value_array_new_from_types (NULL,
G_TYPE_STRING, text,
G_TYPE_DOUBLE, size,
PIKA_TYPE_SIZE_TYPE, size_type,
G_TYPE_STRING, fontname,
G_TYPE_NONE);
return_vals = pika_pdb_run_procedure_array (pika_get_pdb (),
"pika-text-get-extents-fontname",
args);
pika_value_array_unref (args);
*width = 0;
*height = 0;
*ascent = 0;
*descent = 0;
success = PIKA_VALUES_GET_ENUM (return_vals, 0) == PIKA_PDB_SUCCESS;
if (success)
{
*width = PIKA_VALUES_GET_INT (return_vals, 1);
*height = PIKA_VALUES_GET_INT (return_vals, 2);
*ascent = PIKA_VALUES_GET_INT (return_vals, 3);
*descent = PIKA_VALUES_GET_INT (return_vals, 4);
}
pika_value_array_unref (return_vals);
return success;
}