PIKApp/app/text/pikatextlayout-render.c

82 lines
2.5 KiB
C

/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* PikaText
* Copyright (C) 2002-2003 Sven Neumann <sven@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <pango/pangocairo.h>
#include "text-types.h"
#include "pikatextlayout.h"
#include "pikatextlayout-render.h"
void
pika_text_layout_render (PikaTextLayout *layout,
cairo_t *cr,
PikaTextDirection base_dir,
gboolean path)
{
PangoLayout *pango_layout;
cairo_matrix_t trafo;
gint x, y;
gint width, height;
g_return_if_fail (PIKA_IS_TEXT_LAYOUT (layout));
g_return_if_fail (cr != NULL);
cairo_save (cr);
pika_text_layout_get_offsets (layout, &x, &y);
cairo_translate (cr, x, y);
pika_text_layout_get_transform (layout, &trafo);
cairo_transform (cr, &trafo);
if (base_dir == PIKA_TEXT_DIRECTION_TTB_RTL ||
base_dir == PIKA_TEXT_DIRECTION_TTB_RTL_UPRIGHT)
{
pika_text_layout_get_size (layout, &width, &height);
cairo_translate (cr, width, 0);
cairo_rotate (cr, G_PI_2);
}
if (base_dir == PIKA_TEXT_DIRECTION_TTB_LTR ||
base_dir == PIKA_TEXT_DIRECTION_TTB_LTR_UPRIGHT)
{
pika_text_layout_get_size (layout, &width, &height);
cairo_translate (cr, 0, height);
cairo_rotate (cr, -G_PI_2);
}
pango_layout = pika_text_layout_get_pango_layout (layout);
if (path)
pango_cairo_layout_path (cr, pango_layout);
else
pango_cairo_show_layout (cr, pango_layout);
cairo_restore (cr);
}