static void test_file (const gchar *filename, GString *string) { gchar *contents; gchar *markup; gsize length; GError *error = NULL; PangoLayout *layout; gchar *p; gint width = 0; gint ellipsize_at = 0; PangoEllipsizeMode ellipsize = PANGO_ELLIPSIZE_NONE; PangoWrapMode wrap = PANGO_WRAP_WORD; PangoFontDescription *desc; if (!g_file_get_contents (filename, &contents, &length, &error)) { fprintf (stderr, "%s\n", error->message); g_error_free (error); return; } p = strchr (contents, '\n'); g_assert (p); markup = p + 1; *p = '\0'; parse_params (contents, &width, &ellipsize_at, &ellipsize, &wrap); layout = pango_layout_new (context); desc = pango_font_description_from_string ("Cantarell 11"); pango_layout_set_font_description (layout, desc); pango_font_description_free (desc); pango_layout_set_markup (layout, markup, length); g_free (contents); if (width != 0) pango_layout_set_width (layout, width * PANGO_SCALE); pango_layout_set_ellipsize (layout, ellipsize); pango_layout_set_wrap (layout, wrap); g_string_append (string, pango_layout_get_text (layout)); g_string_append (string, "\n---\n\n"); g_string_append_printf (string, "wrapped: %d\n", pango_layout_is_wrapped (layout)); g_string_append_printf (string, "ellipsized: %d\n", pango_layout_is_ellipsized (layout)); g_string_append_printf (string, "lines: %d\n", pango_layout_get_line_count (layout)); if (width != 0) g_string_append_printf (string, "width: %d\n", pango_layout_get_width (layout)); g_string_append (string, "\n---\n\n"); dump_attrs (pango_layout_get_attributes (layout), string); g_string_append (string, "\n---\n\n"); dump_lines (layout, string); g_string_append (string, "\n---\n\n"); dump_runs (layout, string); g_object_unref (layout); }
void cairox_paint_pango_text(cairo_t *cr, CairoxTextParameters *p, PangoLayout *layout, const char *buffer) { int x, y, w, h; if (strlen(buffer) == 0) { return; } cairo_save(cr); cairo_translate(cr, p->x, p->y); cairo_rotate(cr, -p->angle * M_PI / 180.0); pango_layout_set_text(layout, buffer, strlen(buffer)); if (p->x_align == PANGOX_XALIGN_CENTER) { pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); if ((w = pango_layout_get_width(layout)) <= 0) { pango_layout_get_size(layout, &w, &h); } x = - w/((double) PANGO_SCALE*2.0); } else if (p->x_align == PANGOX_XALIGN_RIGHT) { pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT); if ((w = pango_layout_get_width(layout)) <= 0) { pango_layout_get_size(layout, &w, &h); } x = - w/((double) PANGO_SCALE); } else { pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); x = 0; } if (p->y_align == PANGOX_YALIGN_BOTTOM) { pango_layout_get_size(layout, &w, &h); y = - h/((double) PANGO_SCALE); } else if (p->y_align == PANGOX_YALIGN_CENTER) { pango_layout_get_size(layout, &w, &h); y = - h/((double) PANGO_SCALE*2.0); } else { y = 0; } #if FALSE double x0, y0; /* Calculate the background rectangle coordinates: */ pango_layout_get_size(layout, &w, &h); if (p->x_align == PANGOX_XALIGN_LEFT) { x0 = -1.0; y0 = y - 1.0; } else if (p->x_align == PANGOX_XALIGN_RIGHT) { x0 = -(w / (double) PANGO_SCALE)-1; y0 = y - 1.0; } else { x0 = -(w / (PANGO_SCALE*2.0))-1; y0 = y - 1.0; } cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5); cairo_rectangle(cr, x0, y0, (w / (double) PANGO_SCALE)+2, (h / (double) PANGO_SCALE)+2); cairo_fill(cr); #endif cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); cairo_move_to(cr, x-1, y-1); pango_cairo_show_layout(cr, layout); cairo_move_to(cr, x, y-1); pango_cairo_show_layout(cr, layout); cairo_move_to(cr, x+1, y-1); pango_cairo_show_layout(cr, layout); cairo_move_to(cr, x-1, y); pango_cairo_show_layout(cr, layout); cairo_move_to(cr, x+1, y); pango_cairo_show_layout(cr, layout); cairo_move_to(cr, x-1, y+1); pango_cairo_show_layout(cr, layout); cairo_move_to(cr, x, y+1); pango_cairo_show_layout(cr, layout); cairo_move_to(cr, x+1, y+1); pango_cairo_show_layout(cr, layout); cairo_set_source_rgba(cr, p->foreground.r, p->foreground.g, p->foreground.b, 1.0); cairo_move_to(cr, x, y); pango_cairo_show_layout(cr, layout); cairo_stroke(cr); cairo_restore(cr); }
static VALUE rg_width(VALUE self) { return INT2NUM(pango_layout_get_width(_SELF(self))); }
/*----------------------------------------------------------------------------*/ void viewPaintScore(GtkWidget* widget, int p) { /* display the score */ //g_message("in viewPaintScore"); int r, c; char out[16]; out[0] = 0; int middle = m_ScoreRect[p].x+m_ScoreRect[p].width/2; int xpos = 0; strcpy(out, "Score"); PangoLayout* pl = gtk_widget_create_pango_layout(widget, out); int width = pango_layout_get_width(pl); //printf("width=%d\n", width); xpos = middle - width/2; gdk_draw_layout(pixmap, lightGreyGC, xpos, m_ScoreRect[p].y+5, pl); g_object_unref(pl); if (gameEngineData[p].m_Score == 0) { strcpy(out, " "); pl = gtk_widget_create_pango_layout(widget, out); width = pango_layout_get_width(pl); xpos = middle - width/2; gdk_draw_layout(pixmap, lightGreyGC, xpos, m_ScoreRect[p].y+25, pl); g_object_unref(pl); } sprintf(out, " %d ", (int)gameEngineData[p].m_Score); pl = gtk_widget_create_pango_layout(widget, out); width = pango_layout_get_width(pl); xpos = middle - width/2; gdk_draw_layout(pixmap, lightGreyGC, xpos, m_ScoreRect[p].y+25, pl); g_object_unref(pl); strcpy(out, "Level"); pl = gtk_widget_create_pango_layout(widget, out); width = pango_layout_get_width(pl); xpos = middle - width/2; gdk_draw_layout(pixmap, lightGreyGC, xpos, m_ScoreRect[p].y+45, pl); g_object_unref(pl); sprintf(out, " %d ", gameEngineData[p].m_Level); pl = gtk_widget_create_pango_layout(widget, out); width = pango_layout_get_width(pl); xpos = middle - width/2; gdk_draw_layout(pixmap, lightGreyGC, xpos, m_ScoreRect[p].y+65, pl); g_object_unref(pl); strcpy(out, "Lines"); pl = gtk_widget_create_pango_layout(widget, out); width = pango_layout_get_width(pl); xpos = middle - width/2; gdk_draw_layout(pixmap, lightGreyGC, xpos, m_ScoreRect[p].y+85, pl); g_object_unref(pl); sprintf(out, " %d ", gameEngineData[p].m_Lines); pl = gtk_widget_create_pango_layout(widget, out); width = pango_layout_get_width(pl); xpos = middle - width/2; gdk_draw_layout(pixmap, lightGreyGC, xpos, m_ScoreRect[p].y+105, pl); g_object_unref(pl); /* display the preview */ GdkRectangle rect; int icolor; int bs = 10; if (GameGetPreview(&gameEngineData[p], &icolor)) { rect.x = m_ScoreRect[p].x+16; rect.y = m_ScoreRect[p].y+130; rect.width = 1 + (bs+2)*4; rect.height = 1 + (bs+2)*4; viewPaintBlackBlock(widget, &rect); unsigned long pv = GameGetPreview(&gameEngineData[p], &icolor); icolor++; unsigned long mask; for (r=0; r<5; r++) { for (c=0; c<5; c++) { rect.x = m_ScoreRect[p].x+16+c*bs+1; rect.y = m_ScoreRect[p].y+130+r*bs+1; rect.width = bs-2; rect.height = bs-2; mask = 0x80000000>>(r*5+c); if (pv&mask) { switch (userData.m_PieceStyle) { case 0: viewPaintFlatBlock(widget, (char)icolor, &rect); break; case 1: viewPaint3DBlock(widget, (char)icolor, &rect); break; case 2: viewPaintPyrimidBlock(widget, (char)icolor, &rect); break; } } else viewPaintBlackBlock(widget, &rect); } } }