2022-02-04 00:18:54 +01:00
|
|
|
/*
|
|
|
|
* Copyright © 2022 Google, Inc.
|
|
|
|
*
|
|
|
|
* This is part of HarfBuzz, a text shaping library.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, without written agreement and without
|
|
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose, provided that the
|
|
|
|
* above copyright notice and the following two paragraphs appear in
|
|
|
|
* all copies of this software.
|
|
|
|
*
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
|
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
|
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
*
|
|
|
|
* Google Author(s): Behdad Esfahbod
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HELPER_CAIRO_USER_HH
|
|
|
|
#define HELPER_CAIRO_USER_HH
|
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2022-02-04 00:18:54 +01:00
|
|
|
#include "font-options.hh"
|
|
|
|
|
|
|
|
#include <cairo.h>
|
|
|
|
#include <hb.h>
|
|
|
|
|
2022-02-05 20:31:05 +01:00
|
|
|
#include "hb-blob.hh"
|
2022-12-18 07:52:39 +01:00
|
|
|
#include "hb-cairo-utils.h"
|
|
|
|
|
2022-12-23 19:32:31 +01:00
|
|
|
static bool debug = false;
|
|
|
|
static int level = 0;
|
|
|
|
|
|
|
|
static void
|
|
|
|
print (const char *format,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
if (!debug)
|
|
|
|
return;
|
|
|
|
|
|
|
|
printf ("%*s", 2 * level, "");
|
|
|
|
|
|
|
|
va_start (args, format);
|
|
|
|
vprintf (format, args);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
printf ("\n");
|
|
|
|
}
|
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
static const cairo_user_data_key_t _hb_font_cairo_user_data_key = {0};
|
2022-02-05 20:31:05 +01:00
|
|
|
|
2022-02-04 00:18:54 +01:00
|
|
|
static void
|
|
|
|
move_to (hb_draw_funcs_t *dfuncs,
|
|
|
|
cairo_t *cr,
|
|
|
|
hb_draw_state_t *st,
|
|
|
|
float to_x, float to_y,
|
|
|
|
void *)
|
|
|
|
{
|
2022-12-23 19:32:31 +01:00
|
|
|
print ("move to %f %f",
|
|
|
|
(double) to_x, (double) to_y);
|
2022-02-08 23:33:09 +01:00
|
|
|
cairo_move_to (cr,
|
|
|
|
(double) to_x, (double) to_y);
|
2022-02-04 00:18:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
line_to (hb_draw_funcs_t *dfuncs,
|
|
|
|
cairo_t *cr,
|
|
|
|
hb_draw_state_t *st,
|
|
|
|
float to_x, float to_y,
|
|
|
|
void *)
|
|
|
|
{
|
2022-12-23 19:32:31 +01:00
|
|
|
print ("line to %f %f",
|
|
|
|
(double) to_x, (double) to_y);
|
2022-02-08 23:33:09 +01:00
|
|
|
cairo_line_to (cr,
|
|
|
|
(double) to_x, (double) to_y);
|
2022-02-04 00:18:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cubic_to (hb_draw_funcs_t *dfuncs,
|
|
|
|
cairo_t *cr,
|
|
|
|
hb_draw_state_t *st,
|
|
|
|
float control1_x, float control1_y,
|
|
|
|
float control2_x, float control2_y,
|
|
|
|
float to_x, float to_y,
|
|
|
|
void *)
|
|
|
|
{
|
2022-12-23 19:32:31 +01:00
|
|
|
print ("cubic to %f %f",
|
|
|
|
(double) control1_x, (double) control1_y,
|
|
|
|
(double) control2_x, (double) control2_y,
|
|
|
|
(double) to_x, (double) to_y);
|
2022-02-08 23:33:09 +01:00
|
|
|
cairo_curve_to (cr,
|
|
|
|
(double) control1_x, (double) control1_y,
|
|
|
|
(double) control2_x, (double) control2_y,
|
|
|
|
(double) to_x, (double) to_y);
|
2022-02-04 00:18:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
close_path (hb_draw_funcs_t *dfuncs,
|
|
|
|
cairo_t *cr,
|
|
|
|
hb_draw_state_t *st,
|
|
|
|
void *)
|
|
|
|
{
|
2022-12-23 19:32:31 +01:00
|
|
|
print ("close path");
|
2022-02-04 00:18:54 +01:00
|
|
|
cairo_close_path (cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static hb_draw_funcs_t *
|
2022-12-18 07:52:39 +01:00
|
|
|
get_cairo_draw_funcs (void)
|
2022-02-04 00:18:54 +01:00
|
|
|
{
|
|
|
|
static hb_draw_funcs_t *funcs;
|
|
|
|
|
|
|
|
if (!funcs)
|
|
|
|
{
|
|
|
|
funcs = hb_draw_funcs_create ();
|
|
|
|
hb_draw_funcs_set_move_to_func (funcs, (hb_draw_move_to_func_t) move_to, nullptr, nullptr);
|
|
|
|
hb_draw_funcs_set_line_to_func (funcs, (hb_draw_line_to_func_t) line_to, nullptr, nullptr);
|
|
|
|
hb_draw_funcs_set_cubic_to_func (funcs, (hb_draw_cubic_to_func_t) cubic_to, nullptr, nullptr);
|
|
|
|
hb_draw_funcs_set_close_path_func (funcs, (hb_draw_close_path_func_t) close_path, nullptr, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return funcs;
|
|
|
|
}
|
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
#ifdef HAVE_CAIRO_USER_FONT_FACE_SET_RENDER_COLOR_GLYPH_FUNC
|
2022-02-04 00:18:54 +01:00
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
static void
|
|
|
|
push_transform (hb_paint_funcs_t *funcs,
|
|
|
|
void *paint_data,
|
|
|
|
float xx, float yx,
|
|
|
|
float xy, float yy,
|
|
|
|
float dx, float dy,
|
|
|
|
void *user_data)
|
2022-02-04 00:18:54 +01:00
|
|
|
{
|
2022-12-21 08:11:36 +01:00
|
|
|
cairo_t *cr = (cairo_t *)paint_data;
|
2022-12-18 07:52:39 +01:00
|
|
|
cairo_matrix_t m;
|
2022-02-04 00:18:54 +01:00
|
|
|
|
2022-12-23 19:32:31 +01:00
|
|
|
print ("start transform %f %f %f %f %f %f",
|
|
|
|
(double) xx, (double) yx,
|
|
|
|
(double) xy, (double) yy,
|
|
|
|
(double) dx, (double) dy);
|
|
|
|
level++;
|
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
cairo_save (cr);
|
2022-12-23 19:32:31 +01:00
|
|
|
cairo_matrix_init (&m, (double) xx, (double) yx,
|
|
|
|
(double) xy, (double) yy,
|
|
|
|
(double) dx, (double) dy);
|
2022-12-21 08:11:36 +01:00
|
|
|
cairo_transform (cr, &m);
|
2022-12-18 07:52:39 +01:00
|
|
|
}
|
2022-02-04 00:18:54 +01:00
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
static void
|
|
|
|
pop_transform (hb_paint_funcs_t *funcs,
|
|
|
|
void *paint_data,
|
|
|
|
void *user_data)
|
|
|
|
{
|
2022-12-21 08:11:36 +01:00
|
|
|
cairo_t *cr = (cairo_t *)paint_data;
|
2022-02-04 00:18:54 +01:00
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
cairo_restore (cr);
|
2022-12-23 19:32:31 +01:00
|
|
|
|
|
|
|
level--;
|
|
|
|
print ("end transform");
|
2022-02-04 00:18:54 +01:00
|
|
|
}
|
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
static void
|
|
|
|
push_clip_glyph (hb_paint_funcs_t *funcs,
|
|
|
|
void *paint_data,
|
|
|
|
hb_codepoint_t glyph,
|
2022-12-21 22:43:19 +01:00
|
|
|
hb_font_t *font,
|
2022-12-18 07:52:39 +01:00
|
|
|
void *user_data)
|
|
|
|
{
|
2022-12-21 08:11:36 +01:00
|
|
|
cairo_t *cr = (cairo_t *)paint_data;
|
2022-12-18 07:52:39 +01:00
|
|
|
|
2022-12-23 19:32:31 +01:00
|
|
|
print ("start clip glyph %u", glyph);
|
|
|
|
level++;
|
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
cairo_save (cr);
|
|
|
|
cairo_new_path (cr);
|
2022-12-21 22:43:19 +01:00
|
|
|
hb_font_draw_glyph (font, glyph, get_cairo_draw_funcs (), cr);
|
2022-12-18 07:52:39 +01:00
|
|
|
cairo_close_path (cr);
|
|
|
|
cairo_clip (cr);
|
|
|
|
}
|
2022-02-05 20:31:05 +01:00
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
static void
|
|
|
|
push_clip_rectangle (hb_paint_funcs_t *funcs,
|
|
|
|
void *paint_data,
|
|
|
|
float xmin, float ymin, float xmax, float ymax,
|
|
|
|
void *user_data)
|
2022-02-05 20:31:05 +01:00
|
|
|
{
|
2022-12-21 08:11:36 +01:00
|
|
|
cairo_t *cr = (cairo_t *)paint_data;
|
2022-02-05 20:31:05 +01:00
|
|
|
|
2022-12-23 19:32:31 +01:00
|
|
|
print ("start clip rectangle %f %f %f %f",
|
|
|
|
(double) xmin, (double) ymin,
|
|
|
|
(double) xmax, (double) ymax);
|
|
|
|
level++;
|
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
cairo_save (cr);
|
2022-12-21 15:49:42 +01:00
|
|
|
cairo_rectangle (cr,
|
2022-12-23 19:32:31 +01:00
|
|
|
(double) xmin, (double) ymin,
|
|
|
|
(double) (xmax - xmin), (double) (ymax - ymin));
|
2022-12-18 07:52:39 +01:00
|
|
|
cairo_clip (cr);
|
|
|
|
}
|
2022-02-05 20:31:05 +01:00
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
static void
|
|
|
|
pop_clip (hb_paint_funcs_t *funcs,
|
|
|
|
void *paint_data,
|
|
|
|
void *user_data)
|
|
|
|
{
|
2022-12-21 08:11:36 +01:00
|
|
|
cairo_t *cr = (cairo_t *)paint_data;
|
2022-12-18 07:52:39 +01:00
|
|
|
|
|
|
|
cairo_restore (cr);
|
2022-12-23 19:32:31 +01:00
|
|
|
|
|
|
|
level--;
|
|
|
|
print ("end clip");
|
2022-02-05 20:31:05 +01:00
|
|
|
}
|
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
static void
|
|
|
|
push_group (hb_paint_funcs_t *funcs,
|
|
|
|
void *paint_data,
|
|
|
|
void *user_data)
|
2022-02-05 20:31:05 +01:00
|
|
|
{
|
2022-12-21 08:11:36 +01:00
|
|
|
cairo_t *cr = (cairo_t *)paint_data;
|
2022-02-05 20:31:05 +01:00
|
|
|
|
2022-12-23 19:32:31 +01:00
|
|
|
print ("push group");
|
|
|
|
level++;
|
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
cairo_save (cr);
|
|
|
|
cairo_push_group (cr);
|
|
|
|
}
|
2022-02-05 20:31:05 +01:00
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
static void
|
|
|
|
pop_group (hb_paint_funcs_t *funcs,
|
|
|
|
void *paint_data,
|
|
|
|
hb_paint_composite_mode_t mode,
|
|
|
|
void *user_data)
|
|
|
|
{
|
2022-12-21 08:11:36 +01:00
|
|
|
cairo_t *cr = (cairo_t *)paint_data;
|
2022-02-05 20:31:05 +01:00
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
cairo_pop_group_to_source (cr);
|
|
|
|
cairo_set_operator (cr, hb_paint_composite_mode_to_cairo (mode));
|
|
|
|
cairo_paint (cr);
|
2022-02-05 20:31:05 +01:00
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
cairo_restore (cr);
|
2022-12-23 19:32:31 +01:00
|
|
|
|
|
|
|
level--;
|
|
|
|
print ("pop group mode %d", mode);
|
2022-12-18 07:52:39 +01:00
|
|
|
}
|
2022-02-05 20:31:05 +01:00
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
static void
|
|
|
|
paint_color (hb_paint_funcs_t *funcs,
|
|
|
|
void *paint_data,
|
2022-12-22 00:39:27 +01:00
|
|
|
hb_bool_t use_foreground,
|
2022-12-21 22:18:46 +01:00
|
|
|
hb_color_t color,
|
2022-12-18 07:52:39 +01:00
|
|
|
void *user_data)
|
|
|
|
{
|
2022-12-21 08:11:36 +01:00
|
|
|
cairo_t *cr = (cairo_t *)paint_data;
|
2022-12-18 07:52:39 +01:00
|
|
|
|
2022-12-23 19:32:31 +01:00
|
|
|
print ("solid (fg %d) %d %d %d %d",
|
|
|
|
use_foreground,
|
|
|
|
hb_color_get_red (color),
|
|
|
|
hb_color_get_green (color),
|
|
|
|
hb_color_get_blue (color),
|
|
|
|
hb_color_get_alpha (color));
|
|
|
|
|
2022-12-21 22:18:46 +01:00
|
|
|
cairo_set_source_rgba (cr,
|
|
|
|
hb_color_get_red (color) / 255.,
|
|
|
|
hb_color_get_green (color) / 255.,
|
|
|
|
hb_color_get_blue (color) / 255.,
|
|
|
|
hb_color_get_alpha (color) / 255.);
|
2022-12-18 07:52:39 +01:00
|
|
|
cairo_paint (cr);
|
|
|
|
}
|
2022-02-05 20:31:05 +01:00
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
static void
|
|
|
|
paint_image (hb_paint_funcs_t *funcs,
|
|
|
|
void *paint_data,
|
|
|
|
hb_blob_t *blob,
|
2022-12-22 20:16:55 +01:00
|
|
|
unsigned width,
|
|
|
|
unsigned height,
|
2022-12-18 07:52:39 +01:00
|
|
|
hb_tag_t format,
|
2022-12-22 16:12:47 +01:00
|
|
|
float slant,
|
2022-12-18 07:52:39 +01:00
|
|
|
hb_glyph_extents_t *extents,
|
|
|
|
void *user_data)
|
|
|
|
{
|
2022-12-21 08:11:36 +01:00
|
|
|
cairo_t *cr = (cairo_t *)paint_data;
|
2022-02-05 20:31:05 +01:00
|
|
|
|
2022-12-23 19:32:31 +01:00
|
|
|
char buf[5] = { 0, };
|
|
|
|
|
|
|
|
hb_tag_to_string (format, buf);
|
|
|
|
print ("image type %s size %u %u slant %f extents %d %d %d %d\n",
|
|
|
|
buf, width, height, (double) slant,
|
|
|
|
extents->x_bearing, extents->y_bearing, extents->width, extents->height);
|
|
|
|
|
2022-12-22 20:16:55 +01:00
|
|
|
hb_cairo_paint_glyph_image (cr, blob, width, height, format, slant, extents);
|
2022-12-18 07:52:39 +01:00
|
|
|
}
|
2022-02-05 20:31:05 +01:00
|
|
|
|
2022-12-23 19:32:31 +01:00
|
|
|
static void
|
|
|
|
print_color_line (hb_color_line_t *color_line)
|
|
|
|
{
|
|
|
|
hb_color_stop_t *stops;
|
|
|
|
unsigned int len;
|
|
|
|
|
|
|
|
len = hb_color_line_get_color_stops (color_line, 0, NULL, NULL);
|
|
|
|
stops = (hb_color_stop_t *)alloca (len * sizeof (hb_color_stop_t));
|
|
|
|
hb_color_line_get_color_stops (color_line, 0, &len, stops);
|
|
|
|
|
|
|
|
print ("colors extend %d", hb_color_line_get_extend (color_line));
|
|
|
|
level += 1;
|
|
|
|
for (unsigned int i = 0; i < len; i++)
|
|
|
|
print ("%f (fg %d) %d %d %d %d",
|
|
|
|
(double) stops[i].offset,
|
|
|
|
stops[i].is_foreground,
|
|
|
|
hb_color_get_red (stops[i].color),
|
|
|
|
hb_color_get_green (stops[i].color),
|
|
|
|
hb_color_get_blue (stops[i].color),
|
|
|
|
hb_color_get_alpha (stops[i].color));
|
|
|
|
level -= 1;
|
|
|
|
}
|
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
static void
|
|
|
|
paint_linear_gradient (hb_paint_funcs_t *funcs,
|
|
|
|
void *paint_data,
|
|
|
|
hb_color_line_t *color_line,
|
|
|
|
float x0, float y0,
|
|
|
|
float x1, float y1,
|
|
|
|
float x2, float y2,
|
|
|
|
void *user_data)
|
|
|
|
{
|
2022-12-21 08:11:36 +01:00
|
|
|
cairo_t *cr = (cairo_t *)paint_data;
|
2022-02-05 20:31:05 +01:00
|
|
|
|
2022-12-23 19:32:31 +01:00
|
|
|
print ("linear gradient");
|
|
|
|
level += 1;
|
|
|
|
print ("p0 %f %f", (double) x0, (double) y0);
|
|
|
|
print ("p1 %f %f", (double) x1, (double) y1);
|
|
|
|
print ("p2 %f %f", (double) x2, (double) y2);
|
|
|
|
|
|
|
|
print_color_line (color_line);
|
|
|
|
level -= 1;
|
|
|
|
|
2022-12-21 22:43:19 +01:00
|
|
|
hb_cairo_paint_linear_gradient (cr, color_line, x0, y0, x1, y1, x2, y2);
|
2022-12-18 07:52:39 +01:00
|
|
|
}
|
2022-02-05 20:31:05 +01:00
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
static void
|
|
|
|
paint_radial_gradient (hb_paint_funcs_t *funcs,
|
|
|
|
void *paint_data,
|
|
|
|
hb_color_line_t *color_line,
|
|
|
|
float x0, float y0, float r0,
|
|
|
|
float x1, float y1, float r1,
|
|
|
|
void *user_data)
|
|
|
|
{
|
2022-12-21 08:11:36 +01:00
|
|
|
cairo_t *cr = (cairo_t *)paint_data;
|
2022-12-18 07:52:39 +01:00
|
|
|
|
2022-12-23 19:32:31 +01:00
|
|
|
print ("radial gradient");
|
|
|
|
level += 1;
|
|
|
|
print ("p0 %f %f radius %f", (double) x0, (double) y0, (double) r0);
|
|
|
|
print ("p1 %f %f radius %f", (double) x1, (double) y1, (double) r1);
|
|
|
|
|
|
|
|
print_color_line (color_line);
|
|
|
|
level -= 1;
|
|
|
|
|
2022-12-21 22:43:19 +01:00
|
|
|
hb_cairo_paint_radial_gradient (cr, color_line, x0, y0, r0, x1, y1, r1);
|
2022-02-08 23:15:37 +01:00
|
|
|
}
|
2022-12-18 07:52:39 +01:00
|
|
|
|
|
|
|
static void
|
|
|
|
paint_sweep_gradient (hb_paint_funcs_t *funcs,
|
|
|
|
void *paint_data,
|
|
|
|
hb_color_line_t *color_line,
|
|
|
|
float x0, float y0,
|
|
|
|
float start_angle, float end_angle,
|
|
|
|
void *user_data)
|
|
|
|
{
|
2022-12-21 08:11:36 +01:00
|
|
|
cairo_t *cr = (cairo_t *)paint_data;
|
2022-12-18 07:52:39 +01:00
|
|
|
|
2022-12-23 19:32:31 +01:00
|
|
|
print ("sweep gradient");
|
|
|
|
level++;
|
|
|
|
print ("center %f %f", (double) x0, (double) y0);
|
|
|
|
print ("angles %f %f", (double) start_angle, (double) end_angle);
|
|
|
|
|
|
|
|
print_color_line (color_line);
|
|
|
|
level--;
|
|
|
|
|
2022-12-21 22:43:19 +01:00
|
|
|
hb_cairo_paint_sweep_gradient (cr, color_line, x0, y0, start_angle, end_angle);
|
2022-12-18 07:52:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static hb_paint_funcs_t *
|
2022-12-21 15:49:42 +01:00
|
|
|
get_cairo_paint_funcs ()
|
2022-12-18 07:52:39 +01:00
|
|
|
{
|
|
|
|
static hb_paint_funcs_t *funcs;
|
|
|
|
|
|
|
|
if (!funcs)
|
|
|
|
{
|
|
|
|
funcs = hb_paint_funcs_create ();
|
|
|
|
|
|
|
|
hb_paint_funcs_set_push_transform_func (funcs, push_transform, nullptr, nullptr);
|
|
|
|
hb_paint_funcs_set_pop_transform_func (funcs, pop_transform, nullptr, nullptr);
|
|
|
|
hb_paint_funcs_set_push_clip_glyph_func (funcs, push_clip_glyph, nullptr, nullptr);
|
|
|
|
hb_paint_funcs_set_push_clip_rectangle_func (funcs, push_clip_rectangle, nullptr, nullptr);
|
|
|
|
hb_paint_funcs_set_pop_clip_func (funcs, pop_clip, nullptr, nullptr);
|
|
|
|
hb_paint_funcs_set_push_group_func (funcs, push_group, nullptr, nullptr);
|
|
|
|
hb_paint_funcs_set_pop_group_func (funcs, pop_group, nullptr, nullptr);
|
|
|
|
hb_paint_funcs_set_color_func (funcs, paint_color, nullptr, nullptr);
|
|
|
|
hb_paint_funcs_set_image_func (funcs, paint_image, nullptr, nullptr);
|
|
|
|
hb_paint_funcs_set_linear_gradient_func (funcs, paint_linear_gradient, nullptr, nullptr);
|
|
|
|
hb_paint_funcs_set_radial_gradient_func (funcs, paint_radial_gradient, nullptr, nullptr);
|
|
|
|
hb_paint_funcs_set_sweep_gradient_func (funcs, paint_sweep_gradient, nullptr, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return funcs;
|
|
|
|
}
|
|
|
|
|
2022-02-08 23:15:37 +01:00
|
|
|
#endif
|
|
|
|
|
2022-12-18 21:59:56 +01:00
|
|
|
#ifdef HAVE_CAIRO_USER_FONT_FACE_SET_RENDER_COLOR_GLYPH_FUNC
|
2022-12-18 21:15:49 +01:00
|
|
|
static cairo_status_t
|
|
|
|
render_color_glyph (cairo_scaled_font_t *scaled_font,
|
|
|
|
unsigned long glyph,
|
|
|
|
cairo_t *cr,
|
|
|
|
cairo_text_extents_t *extents);
|
2022-12-18 21:59:56 +01:00
|
|
|
#endif
|
2022-12-18 21:15:49 +01:00
|
|
|
|
2022-02-08 23:15:37 +01:00
|
|
|
static cairo_status_t
|
2022-12-18 07:52:39 +01:00
|
|
|
render_glyph (cairo_scaled_font_t *scaled_font,
|
|
|
|
unsigned long glyph,
|
|
|
|
cairo_t *cr,
|
|
|
|
cairo_text_extents_t *extents)
|
2022-02-08 23:15:37 +01:00
|
|
|
{
|
2022-12-18 21:15:49 +01:00
|
|
|
#ifdef HAVE_CAIRO_USER_FONT_FACE_SET_RENDER_COLOR_GLYPH_FUNC
|
|
|
|
static char *p = getenv ("HB_DRAW");
|
|
|
|
if (p && atoi (p) >= 2)
|
|
|
|
return render_color_glyph (scaled_font, glyph, cr, extents);
|
|
|
|
#endif
|
|
|
|
|
2022-02-08 23:15:37 +01:00
|
|
|
hb_font_t *font = (hb_font_t *) (cairo_font_face_get_user_data (cairo_scaled_font_get_font_face (scaled_font),
|
|
|
|
&_hb_font_cairo_user_data_key));
|
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
hb_position_t x_scale, y_scale;
|
|
|
|
hb_font_get_scale (font, &x_scale, &y_scale);
|
|
|
|
cairo_scale (cr, +1./x_scale, -1./y_scale);
|
|
|
|
|
2022-12-21 15:49:42 +01:00
|
|
|
hb_font_draw_glyph (font, glyph, get_cairo_draw_funcs (), cr);
|
2022-12-18 07:52:39 +01:00
|
|
|
cairo_fill (cr);
|
|
|
|
|
2022-02-08 23:15:37 +01:00
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
#ifdef HAVE_CAIRO_USER_FONT_FACE_SET_RENDER_COLOR_GLYPH_FUNC
|
|
|
|
|
2022-02-08 23:15:37 +01:00
|
|
|
static cairo_status_t
|
|
|
|
render_color_glyph (cairo_scaled_font_t *scaled_font,
|
|
|
|
unsigned long glyph,
|
|
|
|
cairo_t *cr,
|
|
|
|
cairo_text_extents_t *extents)
|
|
|
|
{
|
2022-12-18 07:52:39 +01:00
|
|
|
hb_font_t *font = (hb_font_t *) (cairo_font_face_get_user_data (cairo_scaled_font_get_font_face (scaled_font),
|
|
|
|
&_hb_font_cairo_user_data_key));
|
2022-12-21 21:18:02 +01:00
|
|
|
unsigned int palette = 0;
|
|
|
|
#ifdef CAIRO_COLOR_PALETTE_DEFAULT
|
|
|
|
cairo_font_options_t *options = cairo_font_options_create ();
|
|
|
|
cairo_scaled_font_get_font_options (scaled_font, options);
|
|
|
|
palette = cairo_font_options_get_color_palette (options);
|
|
|
|
cairo_font_options_destroy (options);
|
|
|
|
#endif
|
|
|
|
|
2022-12-21 21:02:41 +01:00
|
|
|
hb_color_t color = HB_COLOR (0, 0, 0, 255);
|
|
|
|
cairo_pattern_t *pattern = cairo_get_source (cr);
|
|
|
|
|
|
|
|
if (cairo_pattern_get_type (pattern) == CAIRO_PATTERN_TYPE_SOLID)
|
|
|
|
{
|
|
|
|
double r, g, b, a;
|
|
|
|
cairo_pattern_get_rgba (pattern, &r, &g, &b, &a);
|
|
|
|
color = HB_COLOR ((int)(b * 255.), (int)(g * 255.), (int) (r * 255.), (int)(a * 255.));
|
|
|
|
}
|
2022-02-08 23:15:37 +01:00
|
|
|
|
2022-12-18 07:52:39 +01:00
|
|
|
hb_position_t x_scale, y_scale;
|
|
|
|
hb_font_get_scale (font, &x_scale, &y_scale);
|
|
|
|
cairo_scale (cr, +1./x_scale, -1./y_scale);
|
2022-02-08 23:15:37 +01:00
|
|
|
|
2022-12-23 19:32:31 +01:00
|
|
|
if (getenv ("HB_PAINT_DEBUG"))
|
|
|
|
debug = atoi (getenv ("HB_PAINT_DEBUG"));
|
|
|
|
|
2022-12-21 21:18:02 +01:00
|
|
|
hb_font_paint_glyph (font, glyph, get_cairo_paint_funcs (), cr, palette, color);
|
2022-12-18 07:52:39 +01:00
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
2022-02-05 20:31:05 +01:00
|
|
|
}
|
2022-02-08 23:15:37 +01:00
|
|
|
|
2022-02-05 20:31:05 +01:00
|
|
|
#endif
|
|
|
|
|
2022-02-04 00:18:54 +01:00
|
|
|
static inline cairo_font_face_t *
|
|
|
|
helper_cairo_create_user_font_face (const font_options_t *font_opts)
|
|
|
|
{
|
|
|
|
cairo_font_face_t *cairo_face = cairo_user_font_face_create ();
|
2022-02-05 20:31:05 +01:00
|
|
|
|
2022-02-04 00:18:54 +01:00
|
|
|
cairo_font_face_set_user_data (cairo_face,
|
|
|
|
&_hb_font_cairo_user_data_key,
|
|
|
|
hb_font_reference (font_opts->font),
|
|
|
|
(cairo_destroy_func_t) hb_font_destroy);
|
2022-02-05 20:31:05 +01:00
|
|
|
|
|
|
|
cairo_user_font_face_set_render_glyph_func (cairo_face, render_glyph);
|
2022-12-18 07:52:39 +01:00
|
|
|
|
2022-02-05 20:31:05 +01:00
|
|
|
#ifdef HAVE_CAIRO_USER_FONT_FACE_SET_RENDER_COLOR_GLYPH_FUNC
|
2022-02-08 23:15:37 +01:00
|
|
|
hb_face_t *face = hb_font_get_face (font_opts->font);
|
2022-12-18 07:52:39 +01:00
|
|
|
if (hb_ot_color_has_png (face) || hb_ot_color_has_layers (face) || hb_ot_color_has_paint (face))
|
|
|
|
{
|
2022-02-05 20:31:05 +01:00
|
|
|
cairo_user_font_face_set_render_color_glyph_func (cairo_face, render_color_glyph);
|
2022-12-18 07:52:39 +01:00
|
|
|
}
|
2022-02-05 20:31:05 +01:00
|
|
|
#endif
|
|
|
|
|
2022-02-04 00:18:54 +01:00
|
|
|
return cairo_face;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
helper_cairo_user_font_face_has_data (cairo_font_face_t *font_face)
|
|
|
|
{
|
|
|
|
return cairo_font_face_get_user_data (font_face, &_hb_font_cairo_user_data_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
helper_cairo_user_scaled_font_has_color (cairo_scaled_font_t *scaled_font)
|
|
|
|
{
|
|
|
|
/* Ignoring SVG for now, since we cannot render it. */
|
|
|
|
hb_font_t *font = (hb_font_t *) (cairo_font_face_get_user_data (cairo_scaled_font_get_font_face (scaled_font),
|
|
|
|
&_hb_font_cairo_user_data_key));
|
2022-02-08 23:15:37 +01:00
|
|
|
hb_face_t *face = hb_font_get_face (font);
|
2022-12-18 07:52:39 +01:00
|
|
|
return hb_ot_color_has_png (face) || hb_ot_color_has_layers (face) || hb_ot_color_has_paint (face);
|
2022-02-04 00:18:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|