summaryrefslogtreecommitdiff
path: root/docs/pango_layout.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/pango_layout.md')
-rw-r--r--docs/pango_layout.md100
1 files changed, 54 insertions, 46 deletions
diff --git a/docs/pango_layout.md b/docs/pango_layout.md
index a4d8e122..e723c659 100644
--- a/docs/pango_layout.md
+++ b/docs/pango_layout.md
@@ -4,75 +4,74 @@ Title: Complex layout
# Complex layout
-The central object in high-level Pango API is [class@Pango.Layout].
+The central object in high-level Pango API is [class@Pango2.Layout].
It is well-suited for breaking text into lines that fill a rectangular
area, since that is commonly how paragraphs are formatted in books.
But in real-life situations, text does not always fit in a box.
Examples of more complicated requirements are fitting text around
an image, or flowing text between multiple frames.
-For cases like these, it is better to use [class@Pango.LineBreaker]
-directly instead of `PangoLayout` (`PangoLayout` is using a line
-breaker internally). The way `PangoLineBreaker` works is to let
+For cases like these, it is better to use [class@Pango2.LineBreaker]
+directly instead of `Pango2Layout` (`Pango2Layout` is using a line
+breaker internally). The way `Pango2LineBreaker` works is to let
applications access the formatted result one line at a time, place
it, and change parameters such as the line width before requesting
the next one.
-The following example shows how to use `PangoLineBreaker` to
+The following example shows how to use `Pango2LineBreaker` to
produce an unusually shaped paragraph with a hole in the middle.
-## Using GtkLineBreaker
+## Using Pango2LineBreaker
```
-#include <pango/pango.h>
-#include <pango/pangocairo.h>
+#include <pango2/pangocairo.h>
-static PangoLines *
+static Pango2Lines *
format_text (const char *text)
{
- PangoContext *context;
- PangoLineBreaker *breaker;
- PangoLines *lines;
+ Pango2Context *context;
+ Pango2LineBreaker *breaker;
+ Pango2Lines *lines;
int x, y, width;
int inc, m, w, w2;
- context = pango_font_map_create_context (pango_font_map_get_default ());
- breaker = pango_line_breaker_new (context);
+ context = pango2_context_new ();
+ breaker = pango2_line_breaker_new (context);
- pango_line_breaker_add_text (breaker, text, -1, NULL);
+ pango2_line_breaker_add_text (breaker, text, -1, NULL);
- lines = pango_lines_new ();
+ lines = pango2_lines_new ();
m = 200;
w = 10;
w2 = -200;
inc = 40;
- y = 40 * PANGO_SCALE;
- x = (m - w / 2) * PANGO_SCALE;
- width = w * PANGO_SCALE;
+ y = 40 * PANGO2_SCALE;
+ x = (m - w / 2) * PANGO2_SCALE;
+ width = w * PANGO2_SCALE;
- while (pango_line_breaker_has_line (breaker))
+ while (pango2_line_breaker_has_line (breaker))
{
- PangoLine *line;
- PangoRectangle ext;
+ Pango2Line *line;
+ Pango2Rectangle ext;
gboolean ltr;
- line = pango_line_breaker_next_line (breaker,
+ line = pango2_line_breaker_next_line (breaker,
x, width,
- PANGO_WRAP_CHAR,
- PANGO_ELLIPSIZE_NONE);
+ PANGO2_WRAP_CHAR,
+ PANGO2_ELLIPSIZE_NONE);
- pango_line_get_extents (line, NULL, &ext);
- line = pango_line_justify (line, width);
- pango_lines_add_line (lines, line, x, y - ext.y);
+ pango2_line_get_extents (line, NULL, &ext);
+ line = pango2_line_justify (line, width);
+ pango2_lines_add_line (lines, line, x, y - ext.y);
- ltr = pango_line_breaker_get_direction (breaker) == PANGO_DIRECTION_LTR;
+ ltr = pango2_line_breaker_get_direction (breaker) == PANGO2_DIRECTION_LTR;
- if (w2 > 0 && ltr && x <= m * PANGO_SCALE)
- x = (m + w2 / 2) * PANGO_SCALE;
- else if (w2 > 0 && !ltr && x > m * PANGO_SCALE)
- x = (m - w2 / 2) * PANGO_SCALE;
+ if (w2 > 0 && ltr && x <= m * PANGO2_SCALE)
+ x = (m + w2 / 2) * PANGO2_SCALE;
+ else if (w2 > 0 && !ltr && x > m * PANGO2_SCALE)
+ x = (m - w2 / 2) * PANGO2_SCALE;
else
{
y += ext.height;
@@ -83,14 +82,14 @@ format_text (const char *text)
inc = - inc;
if (w2 > 0)
- width = ((w - w2) / 2) * PANGO_SCALE;
+ width = ((w - w2) / 2) * PANGO2_SCALE;
else
- width = w * PANGO_SCALE;
+ width = w * PANGO2_SCALE;
if (ltr)
- x = (m - w / 2) * PANGO_SCALE;
+ x = (m - w / 2) * PANGO2_SCALE;
else
- x = (m + w / 2) * PANGO_SCALE;
+ x = (m + w / 2) * PANGO2_SCALE;
}
}
@@ -101,18 +100,18 @@ format_text (const char *text)
}
static void
-draw_lines (cairo_t *cr, PangoLines *lines)
+draw_lines (cairo_t *cr, Pango2Lines *lines)
{
- for (int i = 0; i < pango_lines_get_line_count (lines); i++)
+ for (int i = 0; i < pango2_lines_get_line_count (lines); i++)
{
- PangoLine *line = pango_lines_get_lines (lines)[i];
+ Pango2Line *line = pango2_lines_get_lines (lines)[i];
int x, y;
- pango_lines_get_line_position (lines, i, &x, &y);
+ pango2_lines_get_line_position (lines, i, &x, &y);
cairo_save (cr);
- cairo_move_to (cr, x / (double)PANGO_SCALE, y / (double)PANGO_SCALE);
- pango_cairo_show_line (cr, line);
+ cairo_move_to (cr, x / (double)PANGO2_SCALE, y / (double)PANGO2_SCALE);
+ pango2_cairo_show_line (cr, line);
cairo_restore (cr);
}
}
@@ -121,12 +120,13 @@ int
main (int argc, char *argv[])
{
const char *filename;
- PangoLines *lines;
+ Pango2Lines *lines;
cairo_surface_t *surface;
cairo_t *cr;
char *text;
gsize length;
GError *error = NULL;
+ cairo_status_t status;
if (argc != 3)
{
@@ -152,8 +152,16 @@ main (int argc, char *argv[])
draw_lines (cr, lines);
g_object_unref (lines);
- cairo_surface_write_to_png (surface, filename);
- g_print ("Output written to %s\n", filename);
+#ifdef CAIRO_HAS_PNG_FUNCTIONS
+ status = cairo_surface_write_to_png (surface, filename);
+#else
+ status = CAIRO_STATUS_PNG_ERROR; /* Not technically correct, but... */
+#endif
+
+ if (status != CAIRO_STATUS_SUCCESS)
+ g_printerr ("Could not save png to '%s'\n", filename);
+ else
+ g_print ("Output written to %s\n", filename);
cairo_surface_destroy (surface);
cairo_destroy (cr);