[pango/pango2: 107/195] Port examples to PangoSimpleLayout
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/pango2: 107/195] Port examples to PangoSimpleLayout
- Date: Mon, 6 Jun 2022 04:14:42 +0000 (UTC)
commit 9f5a03911be382dc2399734072c17d1269d902ef
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Jan 19 07:20:55 2022 -0500
Port examples to PangoSimpleLayout
examples/cairoshape.c | 94 +++++++-------
examples/cairosimple.c | 25 ++--
examples/cairotwisted.c | 325 ++++++++++++++++++++++++------------------------
3 files changed, 223 insertions(+), 221 deletions(-)
---
diff --git a/examples/cairoshape.c b/examples/cairoshape.c
index d288db14..4c1de86b 100644
--- a/examples/cairoshape.c
+++ b/examples/cairoshape.c
@@ -2,7 +2,7 @@
* inside a text layout, positioned by Pango. This has become possibly
* using the following API added in Pango 1.18:
*
- * pango_cairo_context_set_shape_renderer ()
+ * pango_cairo_context_set_shape_renderer ()
*
* This examples uses a small parser to convert shapes in the format of
* SVG paths to cairo instructions. You can typically extract these from
@@ -52,8 +52,8 @@ static MiniSvg GnomeFootLogo = {
static void
mini_svg_render (MiniSvg *shape,
- cairo_t *cr,
- gboolean do_path)
+ cairo_t *cr,
+ gboolean do_path)
{
double x, y;
const char *p;
@@ -68,33 +68,33 @@ mini_svg_render (MiniSvg *shape,
{
case 'M':
{
- sscanf (p, "%lf,%lf %n", &x, &y, &len); p += len;
- cairo_move_to (cr, x, y);
- break;
- }
+ sscanf (p, "%lf,%lf %n", &x, &y, &len); p += len;
+ cairo_move_to (cr, x, y);
+ break;
+ }
case 'L':
{
- sscanf (p, "%lf,%lf %n", &x, &y, &len); p += len;
- cairo_line_to (cr, x, y);
- break;
- }
+ sscanf (p, "%lf,%lf %n", &x, &y, &len); p += len;
+ cairo_line_to (cr, x, y);
+ break;
+ }
case 'C':
{
- double x1, y1, x2, y2, x3, y3;
- sscanf (p, "%lf,%lf %lf,%lf %lf,%lf %n", &x1, &y1, &x2, &y2, &x3, &y3, &len); p += len;
- cairo_curve_to (cr, x1, y1, x2, y2, x3, y3);
- break;
- }
+ double x1, y1, x2, y2, x3, y3;
+ sscanf (p, "%lf,%lf %lf,%lf %lf,%lf %n", &x1, &y1, &x2, &y2, &x3, &y3, &len); p += len;
+ cairo_curve_to (cr, x1, y1, x2, y2, x3, y3);
+ break;
+ }
case 'z':
{
- cairo_close_path (cr);
- break;
- }
+ cairo_close_path (cr);
+ break;
+ }
default:
{
- g_warning ("Invalid MiniSvg operation '%c'", *op);
- break;
- }
+ g_warning ("Invalid MiniSvg operation '%c'", *op);
+ break;
+ }
}
if (!do_path)
@@ -103,9 +103,9 @@ mini_svg_render (MiniSvg *shape,
static void
mini_svg_shape_renderer (cairo_t *cr,
- PangoAttrShape *attr,
- gboolean do_path,
- gpointer data G_GNUC_UNUSED)
+ PangoAttrShape *attr,
+ gboolean do_path,
+ gpointer data G_GNUC_UNUSED)
{
MiniSvg *shape = (MiniSvg *) attr->data;
double scale_x, scale_y;
@@ -114,30 +114,30 @@ mini_svg_shape_renderer (cairo_t *cr,
scale_y = (double) attr->ink_rect.height / (PANGO_SCALE * shape->height);
cairo_rel_move_to (cr,
- (double) attr->ink_rect.x / PANGO_SCALE,
- (double) attr->ink_rect.y / PANGO_SCALE);
+ (double) attr->ink_rect.x / PANGO_SCALE,
+ (double) attr->ink_rect.y / PANGO_SCALE);
cairo_scale (cr, scale_x, scale_y);
mini_svg_render (shape, cr, do_path);
}
-static PangoLayout *
+static PangoSimpleLayout *
get_layout (cairo_t *cr)
{
- PangoLayout *layout;
+ PangoSimpleLayout *layout;
PangoAttrList *attrs;
PangoRectangle ink_rect = {1 * PANGO_SCALE, -11 * PANGO_SCALE, 8 * PANGO_SCALE, 10 * PANGO_SCALE};
PangoRectangle logical_rect = {0 * PANGO_SCALE, -12 * PANGO_SCALE, 10 * PANGO_SCALE, 12 * PANGO_SCALE};
const char *p;
- /* Create a PangoLayout, set the font and text */
- layout = pango_cairo_create_layout (cr);
+ /* Create a PangoSimpleLayout, set the font and text */
+ layout = pango_cairo_create_simple_layout (cr);
- pango_cairo_context_set_shape_renderer (pango_layout_get_context (layout),
- mini_svg_shape_renderer, NULL, NULL);
+ pango_cairo_context_set_shape_renderer (pango_simple_layout_get_context (layout),
+ mini_svg_shape_renderer, NULL, NULL);
- pango_layout_set_text (layout, text, -1);
+ pango_simple_layout_set_text (layout, text, -1);
attrs = pango_attr_list_new ();
@@ -147,9 +147,9 @@ get_layout (cairo_t *cr)
PangoAttribute *attr;
attr = pango_attr_shape_new_with_data (&ink_rect,
- &logical_rect,
- &GnomeFootLogo,
- NULL, NULL);
+ &logical_rect,
+ &GnomeFootLogo,
+ NULL, NULL);
attr->start_index = p - text;
attr->end_index = attr->start_index + strlen (BULLET);
@@ -157,7 +157,7 @@ get_layout (cairo_t *cr)
pango_attr_list_insert (attrs, attr);
}
- pango_layout_set_attributes (layout, attrs);
+ pango_simple_layout_set_attributes (layout, attrs);
pango_attr_list_unref (attrs);
return layout;
@@ -166,22 +166,24 @@ get_layout (cairo_t *cr)
static void
draw_text (cairo_t *cr, int *width, int *height)
{
-
- PangoLayout *layout = get_layout (cr);
+ PangoSimpleLayout *layout = get_layout (cr);
+ PangoLines *lines = pango_simple_layout_get_lines (layout);
/* Adds a fixed 10-pixel margin on the sides. */
if (width || height)
{
- pango_layout_get_pixel_size (layout, width, height);
+ PangoRectangle ext;
+ pango_lines_get_extents (lines, NULL, &ext);
+ pango_extents_to_pixels (&ext, NULL);
if (width)
- *width += 20;
+ *width = ext.width + 20;
if (height)
- *height += 20;
+ *height = ext.height + 20;
}
cairo_move_to (cr, 10, 10);
- pango_cairo_show_layout (cr, layout);
+ pango_cairo_show_lines (cr, lines);
g_object_unref (layout);
}
@@ -205,7 +207,7 @@ int main (int argc, char **argv)
/* First create and use a 0x0 surface, to measure how large
* the final surface needs to be */
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- 0, 0);
+ 0, 0);
cr = cairo_create (surface);
draw_text (cr, &width, &height);
cairo_destroy (cr);
@@ -213,7 +215,7 @@ int main (int argc, char **argv)
/* Now create the final surface and draw to it. */
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- width, height);
+ width, height);
cr = cairo_create (surface);
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
diff --git a/examples/cairosimple.c b/examples/cairosimple.c
index 881bac56..3d7a5428 100644
--- a/examples/cairosimple.c
+++ b/examples/cairosimple.c
@@ -17,7 +17,8 @@ draw_text (cairo_t *cr)
*/
#define TWEAKABLE_SCALE ((double) 0.1)
- PangoLayout *layout;
+ PangoSimpleLayout *layout;
+ PangoLines *lines;
PangoFontDescription *desc;
int i;
@@ -25,23 +26,23 @@ draw_text (cairo_t *cr)
*/
cairo_translate (cr, RADIUS / TWEAKABLE_SCALE, RADIUS / TWEAKABLE_SCALE);
- /* Create a PangoLayout, set the font and text */
- layout = pango_cairo_create_layout (cr);
+ /* Create a PangoSimpleLayout, set the font and text */
+ layout = pango_cairo_create_simple_layout (cr);
- pango_layout_set_text (layout, "Test\nسَلام", -1);
+ pango_simple_layout_set_text (layout, "Test\nسَلام", -1);
desc = pango_font_description_from_string (FONT_WITH_MANUAL_SIZE);
- pango_font_description_set_absolute_size(desc, FONT_SIZE * DEVICE_DPI * PANGO_SCALE / (72.0 *
TWEAKABLE_SCALE));
+ pango_font_description_set_absolute_size (desc, FONT_SIZE * DEVICE_DPI * PANGO_SCALE / (72.0 *
TWEAKABLE_SCALE));
//pango_font_description_set_size(desc, 27 * PANGO_SCALE / TWEAKABLE_SCALE);
printf("PANGO_SCALE = %d\n", PANGO_SCALE);
- pango_layout_set_font_description (layout, desc);
+ pango_simple_layout_set_font_description (layout, desc);
pango_font_description_free (desc);
/* Draw the layout N_WORDS times in a circle */
for (i = 0; i < N_WORDS; i++)
{
- int width, height;
+ PangoRectangle ext;
double angle = (360. * i) / N_WORDS;
double red;
@@ -54,11 +55,13 @@ draw_text (cairo_t *cr)
cairo_rotate (cr, angle * G_PI / 180.);
/* Inform Pango to re-layout the text with the new transformation */
- pango_cairo_update_layout (cr, layout);
+ pango_cairo_update_simple_layout (cr, layout);
- pango_layout_get_size (layout, &width, &height);
- cairo_move_to (cr,( - (((double)width) / PANGO_SCALE) / 2.0) , (- RADIUS) / TWEAKABLE_SCALE);
- pango_cairo_show_layout (cr, layout);
+ lines = pango_simple_layout_get_lines (layout);
+
+ pango_lines_get_extents (lines, NULL, &ext);
+ cairo_move_to (cr,( - (((double)ext.width) / PANGO_SCALE) / 2.0) , (- RADIUS) / TWEAKABLE_SCALE);
+ pango_cairo_show_lines (cr, lines);
cairo_restore (cr);
}
diff --git a/examples/cairotwisted.c b/examples/cairotwisted.c
index 1572c89a..8323453a 100644
--- a/examples/cairotwisted.c
+++ b/examples/cairotwisted.c
@@ -43,17 +43,17 @@ _fancy_cairo_stroke (cairo_t *cr, cairo_bool_t preserve)
switch (data->header.type) {
case CAIRO_PATH_MOVE_TO:
case CAIRO_PATH_LINE_TO:
- cairo_move_to (cr, data[1].point.x, data[1].point.y);
- break;
+ cairo_move_to (cr, data[1].point.x, data[1].point.y);
+ break;
case CAIRO_PATH_CURVE_TO:
- cairo_line_to (cr, data[1].point.x, data[1].point.y);
- cairo_move_to (cr, data[2].point.x, data[2].point.y);
- cairo_line_to (cr, data[3].point.x, data[3].point.y);
- break;
+ cairo_line_to (cr, data[1].point.x, data[1].point.y);
+ cairo_move_to (cr, data[2].point.x, data[2].point.y);
+ cairo_line_to (cr, data[3].point.x, data[3].point.y);
+ break;
case CAIRO_PATH_CLOSE_PATH:
- break;
+ break;
default:
- g_assert_not_reached ();
+ g_assert_not_reached ();
}
}
cairo_stroke (cr);
@@ -66,25 +66,25 @@ _fancy_cairo_stroke (cairo_t *cr, cairo_bool_t preserve)
data = &path->data[i];
switch (data->header.type) {
case CAIRO_PATH_MOVE_TO:
- cairo_move_to (cr, data[1].point.x, data[1].point.y);
- break;
+ cairo_move_to (cr, data[1].point.x, data[1].point.y);
+ break;
case CAIRO_PATH_LINE_TO:
- cairo_rel_line_to (cr, 0, 0);
- cairo_move_to (cr, data[1].point.x, data[1].point.y);
- break;
+ cairo_rel_line_to (cr, 0, 0);
+ cairo_move_to (cr, data[1].point.x, data[1].point.y);
+ break;
case CAIRO_PATH_CURVE_TO:
- cairo_rel_line_to (cr, 0, 0);
- cairo_move_to (cr, data[1].point.x, data[1].point.y);
- cairo_rel_line_to (cr, 0, 0);
- cairo_move_to (cr, data[2].point.x, data[2].point.y);
- cairo_rel_line_to (cr, 0, 0);
- cairo_move_to (cr, data[3].point.x, data[3].point.y);
- break;
+ cairo_rel_line_to (cr, 0, 0);
+ cairo_move_to (cr, data[1].point.x, data[1].point.y);
+ cairo_rel_line_to (cr, 0, 0);
+ cairo_move_to (cr, data[2].point.x, data[2].point.y);
+ cairo_rel_line_to (cr, 0, 0);
+ cairo_move_to (cr, data[3].point.x, data[3].point.y);
+ break;
case CAIRO_PATH_CLOSE_PATH:
- cairo_rel_line_to (cr, 0, 0);
- break;
+ cairo_rel_line_to (cr, 0, 0);
+ break;
default:
- g_assert_not_reached ();
+ g_assert_not_reached ();
}
}
cairo_rel_line_to (cr, 0, 0);
@@ -95,21 +95,21 @@ _fancy_cairo_stroke (cairo_t *cr, cairo_bool_t preserve)
data = &path->data[i];
switch (data->header.type) {
case CAIRO_PATH_MOVE_TO:
- cairo_move_to (cr, data[1].point.x, data[1].point.y);
- break;
+ cairo_move_to (cr, data[1].point.x, data[1].point.y);
+ break;
case CAIRO_PATH_LINE_TO:
- cairo_line_to (cr, data[1].point.x, data[1].point.y);
- break;
+ cairo_line_to (cr, data[1].point.x, data[1].point.y);
+ break;
case CAIRO_PATH_CURVE_TO:
- cairo_curve_to (cr, data[1].point.x, data[1].point.y,
- data[2].point.x, data[2].point.y,
- data[3].point.x, data[3].point.y);
- break;
+ cairo_curve_to (cr, data[1].point.x, data[1].point.y,
+ data[2].point.x, data[2].point.y,
+ data[3].point.x, data[3].point.y);
+ break;
case CAIRO_PATH_CLOSE_PATH:
- cairo_close_path (cr);
- break;
+ cairo_close_path (cr);
+ break;
default:
- g_assert_not_reached ();
+ g_assert_not_reached ();
}
}
cairo_stroke (cr);
@@ -160,9 +160,9 @@ two_points_distance (cairo_path_data_t *a, cairo_path_data_t *b)
*/
static double
curve_length (double x0, double y0,
- double x1, double y1,
- double x2, double y2,
- double x3, double y3)
+ double x1, double y1,
+ double x2, double y2,
+ double x3, double y3)
{
cairo_surface_t *surface;
cairo_t *cr;
@@ -185,18 +185,18 @@ curve_length (double x0, double y0,
switch (data->header.type) {
case CAIRO_PATH_MOVE_TO:
- current_point = data[1];
- break;
+ current_point = data[1];
+ break;
case CAIRO_PATH_LINE_TO:
- length += two_points_distance (¤t_point, &data[1]);
- current_point = data[1];
- break;
+ length += two_points_distance (¤t_point, &data[1]);
+ current_point = data[1];
+ break;
default:
case CAIRO_PATH_CURVE_TO:
case CAIRO_PATH_CLOSE_PATH:
- g_assert_not_reached ();
+ g_assert_not_reached ();
}
}
cairo_path_destroy (path);
@@ -228,32 +228,32 @@ parametrize_path (cairo_path_t *path)
parametrization[i] = 0.0;
switch (data->header.type) {
case CAIRO_PATH_MOVE_TO:
- last_move_to = data[1];
- current_point = data[1];
- break;
+ last_move_to = data[1];
+ current_point = data[1];
+ break;
case CAIRO_PATH_CLOSE_PATH:
- /* Make it look like it's a line_to to last_move_to */
- data = (&last_move_to) - 1;
+ /* Make it look like it's a line_to to last_move_to */
+ data = (&last_move_to) - 1;
G_GNUC_FALLTHROUGH;
case CAIRO_PATH_LINE_TO:
- parametrization[i] = two_points_distance (¤t_point, &data[1]);
- current_point = data[1];
- break;
+ parametrization[i] = two_points_distance (¤t_point, &data[1]);
+ current_point = data[1];
+ break;
case CAIRO_PATH_CURVE_TO:
- /* naive curve-length, treating bezier as three line segments:
- parametrization[i] = two_points_distance (¤t_point, &data[1])
- + two_points_distance (&data[1], &data[2])
- + two_points_distance (&data[2], &data[3]);
- */
- parametrization[i] = curve_length (current_point.point.x, current_point.point.y,
- data[1].point.x, data[1].point.y,
- data[2].point.x, data[2].point.y,
- data[3].point.x, data[3].point.y);
-
- current_point = data[3];
- break;
+ /* naive curve-length, treating bezier as three line segments:
+ parametrization[i] = two_points_distance (¤t_point, &data[1])
+ + two_points_distance (&data[1], &data[2])
+ + two_points_distance (&data[2], &data[3]);
+ */
+ parametrization[i] = curve_length (current_point.point.x, current_point.point.y,
+ data[1].point.x, data[1].point.y,
+ data[2].point.x, data[2].point.y,
+ data[3].point.x, data[3].point.y);
+
+ current_point = data[3];
+ break;
default:
- g_assert_not_reached ();
+ g_assert_not_reached ();
}
}
@@ -285,7 +285,7 @@ transform_path (cairo_path_t *path, transform_point_func_t f, void *closure)
case CAIRO_PATH_CLOSE_PATH:
break;
default:
- g_assert_not_reached ();
+ g_assert_not_reached ();
}
}
}
@@ -321,7 +321,7 @@ typedef struct {
*/
static void
point_on_path (parametrized_path_t *param,
- double *x, double *y)
+ double *x, double *y)
{
int i;
double ratio, the_y = *y, the_x = *x, dx, dy;
@@ -330,26 +330,26 @@ point_on_path (parametrized_path_t *param,
parametrization_t *parametrization = param->parametrization;
for (i=0; i + path->data[i].header.length < path->num_data &&
- (the_x > parametrization[i] ||
- path->data[i].header.type == CAIRO_PATH_MOVE_TO);
+ (the_x > parametrization[i] ||
+ path->data[i].header.type == CAIRO_PATH_MOVE_TO);
i += path->data[i].header.length) {
the_x -= parametrization[i];
data = &path->data[i];
switch (data->header.type) {
case CAIRO_PATH_MOVE_TO:
- current_point = data[1];
+ current_point = data[1];
last_move_to = data[1];
- break;
+ break;
case CAIRO_PATH_LINE_TO:
- current_point = data[1];
- break;
+ current_point = data[1];
+ break;
case CAIRO_PATH_CURVE_TO:
- current_point = data[3];
- break;
+ current_point = data[3];
+ break;
case CAIRO_PATH_CLOSE_PATH:
- break;
+ break;
default:
- g_assert_not_reached ();
+ g_assert_not_reached ();
}
}
data = &path->data[i];
@@ -364,74 +364,74 @@ point_on_path (parametrized_path_t *param,
G_GNUC_FALLTHROUGH;
case CAIRO_PATH_LINE_TO:
{
- ratio = the_x / parametrization[i];
- /* Line polynomial */
- *x = current_point.point.x * (1 - ratio) + data[1].point.x * ratio;
- *y = current_point.point.y * (1 - ratio) + data[1].point.y * ratio;
-
- /* Line gradient */
- dx = -(current_point.point.x - data[1].point.x);
- dy = -(current_point.point.y - data[1].point.y);
-
- /*optimization for: ratio = the_y / sqrt (dx * dx + dy * dy);*/
- ratio = the_y / parametrization[i];
- *x += -dy * ratio;
- *y += dx * ratio;
+ ratio = the_x / parametrization[i];
+ /* Line polynomial */
+ *x = current_point.point.x * (1 - ratio) + data[1].point.x * ratio;
+ *y = current_point.point.y * (1 - ratio) + data[1].point.y * ratio;
+
+ /* Line gradient */
+ dx = -(current_point.point.x - data[1].point.x);
+ dy = -(current_point.point.y - data[1].point.y);
+
+ /*optimization for: ratio = the_y / sqrt (dx * dx + dy * dy);*/
+ ratio = the_y / parametrization[i];
+ *x += -dy * ratio;
+ *y += dx * ratio;
}
break;
case CAIRO_PATH_CURVE_TO:
{
- /* FIXME the formulas here are not exactly what we want, because the
- * Bezier parametrization is not uniform. But I don't know how to do
- * better. The caller can do slightly better though, by flattening the
- * Bezier and avoiding this branch completely. That has its own cost
- * though, as large y values magnify the flattening error drastically.
- */
+ /* FIXME the formulas here are not exactly what we want, because the
+ * Bezier parametrization is not uniform. But I don't know how to do
+ * better. The caller can do slightly better though, by flattening the
+ * Bezier and avoiding this branch completely. That has its own cost
+ * though, as large y values magnify the flattening error drastically.
+ */
double ratio_1_0, ratio_0_1;
- double ratio_2_0, ratio_0_2;
- double ratio_3_0, ratio_2_1, ratio_1_2, ratio_0_3;
- double _1__4ratio_1_0_3ratio_2_0, _2ratio_1_0_3ratio_2_0;
-
- ratio = the_x / parametrization[i];
-
- ratio_1_0 = ratio;
- ratio_0_1 = 1 - ratio;
-
- ratio_2_0 = ratio_1_0 * ratio_1_0; /* ratio * ratio */
- ratio_0_2 = ratio_0_1 * ratio_0_1; /* (1 - ratio) * (1 - ratio) */
-
- ratio_3_0 = ratio_2_0 * ratio_1_0; /* ratio * ratio * ratio */
- ratio_2_1 = ratio_2_0 * ratio_0_1; /* ratio * ratio * (1 - ratio) */
- ratio_1_2 = ratio_1_0 * ratio_0_2; /* ratio * (1 - ratio) * (1 - ratio) */
- ratio_0_3 = ratio_0_1 * ratio_0_2; /* (1 - ratio) * (1 - ratio) * (1 - ratio) */
-
- _1__4ratio_1_0_3ratio_2_0 = 1 - 4 * ratio_1_0 + 3 * ratio_2_0;
- _2ratio_1_0_3ratio_2_0 = 2 * ratio_1_0 - 3 * ratio_2_0;
-
- /* Bezier polynomial */
- *x = current_point.point.x * ratio_0_3
- + 3 * data[1].point.x * ratio_1_2
- + 3 * data[2].point.x * ratio_2_1
- + data[3].point.x * ratio_3_0;
- *y = current_point.point.y * ratio_0_3
- + 3 * data[1].point.y * ratio_1_2
- + 3 * data[2].point.y * ratio_2_1
- + data[3].point.y * ratio_3_0;
-
- /* Bezier gradient */
- dx =-3 * current_point.point.x * ratio_0_2
- + 3 * data[1].point.x * _1__4ratio_1_0_3ratio_2_0
- + 3 * data[2].point.x * _2ratio_1_0_3ratio_2_0
- + 3 * data[3].point.x * ratio_2_0;
- dy =-3 * current_point.point.y * ratio_0_2
- + 3 * data[1].point.y * _1__4ratio_1_0_3ratio_2_0
- + 3 * data[2].point.y * _2ratio_1_0_3ratio_2_0
- + 3 * data[3].point.y * ratio_2_0;
-
- ratio = the_y / sqrt (dx * dx + dy * dy);
- *x += -dy * ratio;
- *y += dx * ratio;
+ double ratio_2_0, ratio_0_2;
+ double ratio_3_0, ratio_2_1, ratio_1_2, ratio_0_3;
+ double _1__4ratio_1_0_3ratio_2_0, _2ratio_1_0_3ratio_2_0;
+
+ ratio = the_x / parametrization[i];
+
+ ratio_1_0 = ratio;
+ ratio_0_1 = 1 - ratio;
+
+ ratio_2_0 = ratio_1_0 * ratio_1_0; /* ratio * ratio */
+ ratio_0_2 = ratio_0_1 * ratio_0_1; /* (1 - ratio) * (1 - ratio) */
+
+ ratio_3_0 = ratio_2_0 * ratio_1_0; /* ratio * ratio * ratio */
+ ratio_2_1 = ratio_2_0 * ratio_0_1; /* ratio * ratio * (1 - ratio) */
+ ratio_1_2 = ratio_1_0 * ratio_0_2; /* ratio * (1 - ratio) * (1 - ratio) */
+ ratio_0_3 = ratio_0_1 * ratio_0_2; /* (1 - ratio) * (1 - ratio) * (1 - ratio) */
+
+ _1__4ratio_1_0_3ratio_2_0 = 1 - 4 * ratio_1_0 + 3 * ratio_2_0;
+ _2ratio_1_0_3ratio_2_0 = 2 * ratio_1_0 - 3 * ratio_2_0;
+
+ /* Bezier polynomial */
+ *x = current_point.point.x * ratio_0_3
+ + 3 * data[1].point.x * ratio_1_2
+ + 3 * data[2].point.x * ratio_2_1
+ + data[3].point.x * ratio_3_0;
+ *y = current_point.point.y * ratio_0_3
+ + 3 * data[1].point.y * ratio_1_2
+ + 3 * data[2].point.y * ratio_2_1
+ + data[3].point.y * ratio_3_0;
+
+ /* Bezier gradient */
+ dx =-3 * current_point.point.x * ratio_0_2
+ + 3 * data[1].point.x * _1__4ratio_1_0_3ratio_2_0
+ + 3 * data[2].point.x * _2ratio_1_0_3ratio_2_0
+ + 3 * data[3].point.x * ratio_2_0;
+ dy =-3 * current_point.point.y * ratio_0_2
+ + 3 * data[1].point.y * _1__4ratio_1_0_3ratio_2_0
+ + 3 * data[2].point.y * _2ratio_1_0_3ratio_2_0
+ + 3 * data[3].point.y * ratio_2_0;
+
+ ratio = the_y / sqrt (dx * dx + dy * dy);
+ *x += -dy * ratio;
+ *y += dx * ratio;
}
break;
default:
@@ -453,7 +453,7 @@ map_path_onto (cairo_t *cr, cairo_path_t *path)
cairo_new_path (cr);
transform_path (current_path,
- (transform_point_func_t) point_on_path, ¶m);
+ (transform_point_func_t) point_on_path, ¶m);
cairo_append_path (cr, current_path);
@@ -466,13 +466,13 @@ typedef void (*draw_path_func_t) (cairo_t *cr);
static void
draw_text (cairo_t *cr,
- double x,
- double y,
- const char *font,
- const char *text)
+ double x,
+ double y,
+ const char *font,
+ const char *text)
{
- PangoLayout *layout;
- PangoLayoutLine *line;
+ PangoSimpleLayout *layout;
+ PangoLine *line;
PangoFontDescription *desc;
cairo_font_options_t *font_options;
@@ -484,31 +484,28 @@ draw_text (cairo_t *cr,
cairo_set_font_options (cr, font_options);
cairo_font_options_destroy (font_options);
- layout = pango_cairo_create_layout (cr);
+ layout = pango_cairo_create_simple_layout (cr);
desc = pango_font_description_from_string (font);
- pango_layout_set_font_description (layout, desc);
+ pango_simple_layout_set_font_description (layout, desc);
pango_font_description_free (desc);
- pango_layout_set_text (layout, text, -1);
+ pango_simple_layout_set_text (layout, text, -1);
- /* Use pango_layout_get_line() instead of pango_layout_get_line_readonly()
- * for older versions of pango
- */
- line = pango_layout_get_line_readonly (layout, 0);
+ line = pango_lines_get_line (pango_simple_layout_get_lines (layout), 0, NULL, NULL);
cairo_move_to (cr, x, y);
- pango_cairo_layout_line_path (cr, line);
+ pango_cairo_line_path (cr, line);
g_object_unref (layout);
}
static void
draw_twisted (cairo_t *cr,
- double x,
- double y,
- const char *font,
- const char *text)
+ double x,
+ double y,
+ const char *font,
+ const char *text)
{
cairo_path_t *path;
@@ -560,9 +557,9 @@ draw_dream (cairo_t *cr)
fancy_cairo_stroke_preserve (cr);
draw_twisted (cr,
- 0, 0,
- "Serif 72",
- "It was a dream... Oh Just a dream...");
+ 0, 0,
+ "Serif 72",
+ "It was a dream... Oh Just a dream...");
}
static void
@@ -579,9 +576,9 @@ draw_wow (cairo_t *cr)
fancy_cairo_stroke_preserve (cr);
draw_twisted (cr,
- -20, -150,
- "Serif 60",
- "WOW!");
+ -20, -150,
+ "Serif 60",
+ "WOW!");
}
int main (int argc, char **argv)
@@ -600,7 +597,7 @@ int main (int argc, char **argv)
filename = argv[1];
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- 1000, 800);
+ 1000, 800);
cr = cairo_create (surface);
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]