PIKApp/libpika/pikatexttool_pdb.c

177 lines
6.3 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.
**/
/**
2023-10-30 23:55:30 +01:00
* pika_text_font:
2023-09-26 00:35:21 +02:00
* @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.
2023-10-30 23:55:30 +01:00
* @size: The size of text in pixels.
* @font: The font.
2023-09-26 00:35:21 +02:00
*
* Add text at the specified location as a floating selection or a new
* layer.
*
2023-10-30 23:55:30 +01:00
* 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.
* The size is always in pixels. 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.
2023-09-26 00:35:21 +02:00
*
* Returns: (nullable) (transfer none):
* The new text layer or %NULL if no layer was created.
**/
PikaLayer *
2023-10-30 23:55:30 +01:00
pika_text_font (PikaImage *image,
PikaDrawable *drawable,
gdouble x,
gdouble y,
const gchar *text,
gint border,
gboolean antialias,
gdouble size,
PikaFont *font)
2023-09-26 00:35:21 +02:00
{
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,
2023-10-30 23:55:30 +01:00
PIKA_TYPE_FONT, font,
2023-09-26 00:35:21 +02:00
G_TYPE_NONE);
2023-10-30 23:55:30 +01:00
return_vals = _pika_pdb_run_procedure_array (pika_get_pdb (),
"pika-text-font",
args);
2023-09-26 00:35:21 +02:00
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;
}
/**
2023-10-30 23:55:30 +01:00
* pika_text_get_extents_font:
2023-09-26 00:35:21 +02:00
* @text: The text to generate (in UTF-8 encoding).
* @size: The size of text in either pixels or points.
2023-10-30 23:55:30 +01:00
* @font: The name of the font.
* @width: (out): The width of the glyph extents.
* @height: (out): The height of the glyph extents.
* @ascent: (out): The ascent of the glyph extents.
* @descent: (out): The descent of the glyph extents.
2023-09-26 00:35:21 +02:00
*
* Get extents of the bounding box for the specified text.
*
* This tool returns the width and height of a bounding box for the
2023-10-30 23:55:30 +01:00
* specified text rendered with the specified font information. Ascent
* and descent of the glyph extents are returned as well.
* The ascent is the distance from the baseline to the highest point of
* the character. This is positive if the glyph ascends above the
* baseline. The descent is the distance from the baseline to the
* lowest point of the character. This is positive if the glyph
* descends below the baseline.
* The size is always in pixels. If you need to set 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.
2023-09-26 00:35:21 +02:00
*
* Returns: TRUE on success.
**/
gboolean
2023-10-30 23:55:30 +01:00
pika_text_get_extents_font (const gchar *text,
gdouble size,
PikaFont *font,
gint *width,
gint *height,
gint *ascent,
gint *descent)
2023-09-26 00:35:21 +02:00
{
PikaValueArray *args;
PikaValueArray *return_vals;
gboolean success = TRUE;
args = pika_value_array_new_from_types (NULL,
G_TYPE_STRING, text,
G_TYPE_DOUBLE, size,
2023-10-30 23:55:30 +01:00
PIKA_TYPE_FONT, font,
2023-09-26 00:35:21 +02:00
G_TYPE_NONE);
2023-10-30 23:55:30 +01:00
return_vals = _pika_pdb_run_procedure_array (pika_get_pdb (),
"pika-text-get-extents-font",
args);
2023-09-26 00:35:21 +02:00
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;
}