void draw_clock (void *obj, cairo_t *c) { Clock *clock = obj; PangoLayout *layout; layout = pango_cairo_create_layout (c); // draw layout pango_layout_set_font_description (layout, time1_font_desc); pango_layout_set_width (layout, clock->area.width * PANGO_SCALE); pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER); pango_layout_set_text (layout, buf_time, strlen(buf_time)); cairo_set_source_rgba (c, clock->font.color[0], clock->font.color[1], clock->font.color[2], clock->font.alpha); pango_cairo_update_layout (c, layout); draw_text(layout, c, 0, clock->time1_posy, &clock->font, ((Panel*)clock->area.panel)->font_shadow); if (time2_format) { pango_layout_set_font_description (layout, time2_font_desc); pango_layout_set_indent(layout, 0); pango_layout_set_text (layout, buf_date, strlen(buf_date)); pango_layout_set_width (layout, clock->area.width * PANGO_SCALE); pango_cairo_update_layout (c, layout); draw_text(layout, c, 0, clock->time2_posy, &clock->font, ((Panel*)clock->area.panel)->font_shadow); } g_object_unref (layout); }
void content_draw (GtkWidget *widget, cairo_t *cr) { PangoContext *context; PangoLayout *title_layout; PangoLayout *sub_layout; PangoFontDescription *desc; int width, height; int sub_width; width = gdk_window_get_width (gtk_widget_get_window (widget)); height = gdk_window_get_height (gtk_widget_get_window (widget)); cairo_translate (cr, width / 2, height / 2); context = gdk_pango_context_get_for_screen (gtk_widget_get_screen (widget)); title_layout = pango_layout_new (context); pango_layout_set_text (title_layout, _("This session is locked"), -1); desc = pango_font_description_from_string (TITLE_FONT); pango_layout_set_font_description (title_layout, desc); pango_font_description_free (desc); cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0); pango_cairo_update_layout (cr, title_layout); pango_layout_get_size (title_layout, &width, &height); cairo_save (cr); /* Adjust the translation to the middle left of the icon */ cairo_translate (cr, - width / PANGO_SCALE / 2 - height / PANGO_SCALE, - height / PANGO_SCALE / 2); draw_lock_icon (cr, height / PANGO_SCALE); cairo_restore (cr); cairo_move_to (cr, - width / PANGO_SCALE / 2 + height / PANGO_SCALE, - height / PANGO_SCALE); pango_cairo_show_layout (cr, title_layout); g_object_unref (title_layout); sub_layout = pango_layout_new (context); pango_layout_set_text (sub_layout, _("You'll be redirected to the unlock dialog automatically in a few seconds"), -1); pango_layout_set_wrap (sub_layout, PANGO_WRAP_WORD_CHAR); pango_layout_set_width (sub_layout, width + 2 * height); desc = pango_font_description_from_string (MESSAGE_FONT); pango_layout_set_font_description (sub_layout, desc); pango_font_description_free (desc); cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, 1.0); pango_cairo_update_layout (cr, sub_layout); pango_layout_get_size (sub_layout, &sub_width, NULL); cairo_move_to (cr, - (width + 2 * height) / PANGO_SCALE / 2, height / PANGO_SCALE); cairo_scale (cr, (width + 2 * height) / (gdouble)sub_width, (width + 2 * height) / (gdouble)sub_width); pango_cairo_show_layout (cr, sub_layout); g_object_unref (sub_layout); g_object_unref (context); }
static void rotate_text(cairo_t *cairo, PangoLayout *layout, int x_center, int y_center, double radians) { cairo_translate(cairo, x_center, y_center); cairo_rotate(cairo, radians); /* Inform Pango to re-layout the text with the new transformation */ pango_cairo_update_layout(cairo, layout); }
void draw_execp(void *obj, cairo_t *c) { Execp *execp = obj; PangoLayout *layout = pango_cairo_create_layout(c); if (execp->backend->has_icon && execp->backend->icon) { imlib_context_set_image(execp->backend->icon); // Render icon render_image(execp->area.pix, execp->frontend->iconx, execp->frontend->icony); } // draw layout pango_layout_set_font_description(layout, execp->backend->font_desc); pango_layout_set_width(layout, execp->frontend->textw * PANGO_SCALE); pango_layout_set_alignment(layout, execp->backend->centered ? PANGO_ALIGN_CENTER : PANGO_ALIGN_LEFT); pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); if (!execp->backend->has_markup) pango_layout_set_text(layout, execp->backend->text, strlen(execp->backend->text)); else pango_layout_set_markup(layout, execp->backend->text, strlen(execp->backend->text)); pango_cairo_update_layout(c, layout); draw_text(layout, c, execp->frontend->textx, execp->frontend->texty, &execp->backend->font_color, panel_config.font_shadow); g_object_unref(layout); }
void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, int *baseline, double scale, bool markup, const char *fmt, ...) { va_list args; va_start(args, fmt); // Add one since vsnprintf excludes null terminator. int length = vsnprintf(NULL, 0, fmt, args) + 1; va_end(args); char *buf = malloc(length); if (buf == NULL) { sway_log(SWAY_ERROR, "Failed to allocate memory"); return; } va_start(args, fmt); vsnprintf(buf, length, fmt, args); va_end(args); PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup); pango_cairo_update_layout(cairo, layout); pango_layout_get_pixel_size(layout, width, height); if (baseline) { *baseline = pango_layout_get_baseline(layout) / PANGO_SCALE; } g_object_unref(layout); free(buf); }
void ly_3lrc_widget_draw_text_midx (cairo_t *cr, gchar *text, gchar *font, gint width_x, gint height_y) { PangoLayout *layout; PangoFontDescription *desc; int width, height; layout = pango_cairo_create_layout (cr); pango_layout_set_text (layout, text, -1); desc = pango_font_description_from_string (font); pango_layout_set_font_description (layout, desc); pango_font_description_free (desc); pango_cairo_update_layout (cr, layout); pango_layout_get_size (layout, &width, &height); if(width_x-(double)width/PANGO_SCALE>0) cairo_move_to (cr, (width_x - (double)width / PANGO_SCALE) / 2, height_y); else cairo_move_to (cr, 0, height_y); pango_cairo_show_layout (cr, layout); g_object_unref (layout); }
static void preview_got_page_size (GtkPrintOperationPreview *preview, GtkPrintContext *context, GtkPageSetup *page_setup, gpointer data) { PreviewOp *pop = data; GtkPaperSize *paper_size; double w, h; cairo_t *cr; gdouble dpi_x, dpi_y; paper_size = gtk_page_setup_get_paper_size (page_setup); w = gtk_paper_size_get_width (paper_size, GTK_UNIT_INCH); h = gtk_paper_size_get_height (paper_size, GTK_UNIT_INCH); cr = gdk_cairo_create (pop->area->window); dpi_x = pop->area->allocation.width/w; dpi_y = pop->area->allocation.height/h; if (fabs (dpi_x - pop->dpi_x) > 0.001 || fabs (dpi_y - pop->dpi_y) > 0.001) { gtk_print_context_set_cairo_context (context, cr, dpi_x, dpi_y); pop->dpi_x = dpi_x; pop->dpi_y = dpi_y; } pango_cairo_update_layout (cr, pop->data->layout); cairo_destroy (cr); }
void draw_taskbarname(void* obj, cairo_t* c) { Taskbarname* taskbar_name = obj; Taskbar* taskbar = taskbar_name->area.parent; PangoLayout* layout; color_T* config_text = (taskbar->desktop == server.desktop) ? &taskbarname_active_font : &taskbarname_font; int state = (taskbar->desktop == server.desktop) ? TASKBAR_ACTIVE : TASKBAR_NORMAL; taskbar_name->state_pix[state] = taskbar_name->area.pix; // draw content layout = pango_cairo_create_layout(c); pango_layout_set_font_description(layout, taskbarname_font_desc); pango_layout_set_width(layout, taskbar_name->area.width * PANGO_SCALE); pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); pango_layout_set_text(layout, taskbar_name->name, strlen(taskbar_name->name)); { double colors[4]; color_extract_components_to_array(config_text, colors); cairo_set_source_rgba(c, colors[0], colors[1], colors[2], colors[3]); } pango_cairo_update_layout(c, layout); cairo_move_to(c, 0, taskbar_name->posy); pango_cairo_show_layout(c, layout); g_object_unref(layout); // printf("draw_taskbarname %s ******************************\n", // taskbar_name->name); }
void pango_printf(cairo_t *cairo, const char *font, double scale, bool markup, const char *fmt, ...) { va_list args; va_start(args, fmt); // Add one since vsnprintf excludes null terminator. int length = vsnprintf(NULL, 0, fmt, args) + 1; va_end(args); char *buf = malloc(length); if (buf == NULL) { sway_log(SWAY_ERROR, "Failed to allocate memory"); return; } va_start(args, fmt); vsnprintf(buf, length, fmt, args); va_end(args); PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup); cairo_font_options_t *fo = cairo_font_options_create(); cairo_get_font_options(cairo, fo); pango_cairo_context_set_font_options(pango_layout_get_context(layout), fo); cairo_font_options_destroy(fo); pango_cairo_update_layout(cairo, layout); pango_cairo_show_layout(cairo, layout); g_object_unref(layout); free(buf); }
void ui_insert_text(char *s, int x, int y, int h, int w, double *rgba, enum alignment align) { PangoTabArray *tabs; int height; pango_layout_set_width(ui->w[ui->cur].pangolayout, w * PANGO_SCALE); switch (align) { case RIGHT: pango_layout_set_alignment(ui->w[ui->cur].pangolayout, PANGO_ALIGN_RIGHT); break; case CENTER: pango_layout_set_alignment(ui->w[ui->cur].pangolayout, PANGO_ALIGN_CENTER); break; default: pango_layout_set_alignment(ui->w[ui->cur].pangolayout, PANGO_ALIGN_LEFT); } tabs = pango_tab_array_new_with_positions(1, TRUE, PANGO_TAB_LEFT, config.tabs); pango_layout_set_wrap(ui->w[ui->cur].pangolayout, PANGO_WRAP_WORD_CHAR); pango_layout_set_ellipsize(ui->w[ui->cur].pangolayout, PANGO_ELLIPSIZE_END); pango_layout_set_font_description(ui->w[ui->cur].pangolayout, ui->w[ui->cur].pangofont); pango_layout_set_tabs(ui->w[ui->cur].pangolayout, tabs); pango_layout_set_markup(ui->w[ui->cur].pangolayout, s, -1); cairo_set_source_rgba(ui->w[ui->cur].c, rgba[0], rgba[1], rgba[2], rgba[3]); pango_cairo_update_layout(ui->w[ui->cur].c, ui->w[ui->cur].pangolayout); pango_layout_get_pixel_size(ui->w[ui->cur].pangolayout, NULL, &height); /* use (h - height) / 2 to center-align vertically */ cairo_move_to(ui->w[ui->cur].c, x, y + (h - height) / 2); pango_cairo_show_layout(ui->w[ui->cur].c, ui->w[ui->cur].pangolayout); pango_tab_array_free(tabs); }
static void _paint_text (OlScrollWindow *scroll, cairo_t *cr) { ol_log_func (); ol_assert (OL_IS_SCROLL_WINDOW (scroll)); ol_assert (cr != NULL); GtkWidget *widget = GTK_WIDGET (scroll); OlScrollWindowPrivate *priv = OL_SCROLL_WINDOW_GET_PRIVATE (scroll); gint width, height; PangoRectangle extent; PangoLayout *layout; gint x, y; gdk_drawable_get_size (gtk_widget_get_window (widget), &width, &height); /* set the font */ cairo_save (cr); cairo_set_source_rgb (cr, priv->inactive_color.r, priv->inactive_color.g, priv->inactive_color.b); layout = _get_pango (scroll, cr); pango_layout_set_text (layout, priv->text, -1); pango_layout_get_pixel_extents (layout, NULL, &extent); pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER); x = (width - extent.width) / 2; y = (height - extent.height) / 2; if (x < 0) x = 0; if (y < 0) y = 0; cairo_move_to (cr, x, y); pango_cairo_update_layout (cr, layout); pango_cairo_show_layout (cr, layout); }
static void get_characters(cairo_t *cr, char **c, char **data, uint32_t *data_length, uint32_t line_length, PangoFontDescription *font_description) { /* Case we should stop the loop: * 1) End of the line: "\0". * 2) New text modification (%C, %B, ...). * 3) End of text modification (%). * 4) New type (%I, ...) * 5) End of the line. */ *data = *c; PangoLayout *layout; layout = pango_cairo_create_layout(cr); pango_layout_set_font_description(layout, font_description); pango_layout_set_text(layout, *data, -1); pango_cairo_update_layout(cr, layout); int begin_length; /* Get the line length, from the data pointer, * until the '\0' character. */ pango_layout_get_pixel_size(layout, &begin_length, NULL); int end_length; /* Get the line length from the '*c' pointer, * until the end of the line. */ while (**c != '\0' && **c != '%' && !(**c == '\\' && *(*c + 1) == '%')) { (*c)++; pango_layout_set_text(layout, *c, -1); pango_cairo_update_layout(cr, layout); pango_layout_get_pixel_size(layout, &end_length, NULL); *data_length = (begin_length - end_length); if (line_length < *data_length) { /* data_length - extents.x_advance let us know the * length of the current line. */ (*c)--; if (**c == **data) *data = NULL; break; } } g_object_unref(layout); }
void GuiSolidLabelElementRenderer::Render(Rect bounds) { if(cairoContext) { cairo_save(cairoContext); Color color = element->GetColor(); FontProperties font = element->GetFont(); cairo_set_source_rgba(cairoContext, 1.0 * color.r / 255, 1.0 * color.g / 255, 1.0 * color.b / 255, 1.0 * color.a / 255 ); if(element->GetWrapLine()) pango_layout_set_width(layout, bounds.Width() * PANGO_SCALE); pango_cairo_update_layout(cairoContext, layout); int layoutWidth, layoutHeight; int plotX1, plotY1; pango_layout_get_pixel_size( layout, &layoutWidth, &layoutHeight); switch(element->GetHorizontalAlignment()) { case Alignment::Left: plotX1 = bounds.x1; break; case Alignment::Center: plotX1 = bounds.x1 + (bounds.Width() - layoutWidth) / 2; break; case Alignment::Right: plotX1 = bounds.x1 + (bounds.Width() - layoutWidth); break; } switch(element->GetVerticalAlignment()) { case Alignment::Top: plotY1 = bounds.y1; break; case Alignment::Center: plotY1 = bounds.y1 + (bounds.Height() - layoutHeight) / 2; break; case Alignment::Bottom: plotY1 = bounds.y1 + (bounds.Height() - layoutHeight); break; } cairo_move_to(cairoContext, plotX1, plotY1); pango_cairo_layout_path(cairoContext, layout); cairo_fill(cairoContext); cairo_restore(cairoContext); } }
static void text_entry_redraw_handler(struct widget *widget, void *data) { struct text_entry *entry = data; cairo_surface_t *surface; struct rectangle allocation; cairo_t *cr; surface = window_get_surface(entry->window); widget_get_allocation(entry->widget, &allocation); cr = cairo_create(surface); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_push_group(cr); cairo_translate(cr, allocation.x, allocation.y); cairo_set_source_rgba(cr, 1, 1, 1, 1); cairo_rectangle(cr, 0, 0, allocation.width, allocation.height); cairo_fill(cr); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); if (entry->active) { cairo_rectangle(cr, 0, 0, allocation.width, allocation.height); cairo_set_line_width (cr, 3); cairo_set_source_rgba(cr, 0, 0, 1, 1.0); cairo_stroke(cr); } cairo_set_source_rgba(cr, 0, 0, 0, 1); cairo_translate(cr, text_offset_left, allocation.height / 2); if (!entry->layout) entry->layout = pango_cairo_create_layout(cr); else pango_cairo_update_layout(cr, entry->layout); text_entry_update_layout(entry); pango_cairo_show_layout(cr, entry->layout); text_entry_draw_cursor(entry, cr); cairo_pop_group_to_source(cr); cairo_paint(cr); cairo_destroy(cr); cairo_surface_destroy(surface); }
/* subfunction of gtk_plot_cairo_draw_string(). */ static gint drawstring(GtkPlotPC *pc, gint angle, gint dx, gint dy, GtkPSFont *psfont, gint height, const gchar *text) { cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo; PangoLayout *layout = GTK_PLOT_CAIRO(pc)->layout; PangoFontDescription *font; PangoRectangle rect; PangoFontMap *map; gint ret_value; gint dpi_cairo, dpi_screen; GdkScreen *screen = gdk_screen_get_default(); if(!text || strlen(text) == 0) return 0; cairo_save(cairo); map = pango_cairo_font_map_get_default(); dpi_cairo = pango_cairo_font_map_get_resolution(PANGO_CAIRO_FONT_MAP(map)); dpi_screen = gdk_screen_get_resolution(screen); height *= (double)dpi_screen/(double)dpi_cairo; font = gtk_psfont_get_font_description(psfont, height); pango_layout_set_font_description(GTK_PLOT_CAIRO(pc)->layout, font); pango_layout_set_text(GTK_PLOT_CAIRO(pc)->layout, text, strlen(text)); pango_layout_get_extents(GTK_PLOT_CAIRO(pc)->layout, NULL, &rect); if (psfont->i18n_latinfamily && psfont->vertical) { /* vertical-writing CJK postscript fonts. */ return rect.height; } else { /* horizontal writing */ if(angle == 90) // cairo_translate(cairo, dx, dy-PANGO_PIXELS(rect.width)); cairo_translate(cairo, dx, dy); else if(angle == 270) cairo_translate(cairo, dx+PANGO_PIXELS(rect.height), dy); else if(angle == 180) cairo_translate(cairo, dx-PANGO_PIXELS(rect.width), dy); else cairo_translate(cairo, dx, dy); } cairo_rotate(cairo, -angle * G_PI / 180); pango_cairo_update_layout(cairo, layout); pango_cairo_show_layout(cairo, layout); cairo_restore(cairo); pango_font_description_free(font); ret_value = (angle == 0 || angle == 180) ? rect.width : rect.height; return PANGO_PIXELS(rect.width); }
static gboolean on_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data) { cairo_t *cr = gdk_cairo_create (widget->window); PangoLayout *p=pango_cairo_create_layout(cr); PangoFontDescription *desc=pango_font_description_from_string("Courier 12"); pango_layout_set_font_description(p,desc); pango_font_description_free(desc); int w,h; pango_layout_set_text(p,"0",1); pango_layout_get_size(p,&w,&h); w/=PANGO_SCALE; h/=PANGO_SCALE; if(cursor<20*80 && cursor>=0) { cairo_save(cr); cairo_set_source_rgb(cr,0,0.8,0); cairo_rectangle(cr,(cursor%80+1)*w,(cursor/80+1)*h,w,h); cairo_fill(cr); cairo_restore(cr); } cairo_move_to(cr,w,h); int i; for(i=0;i<20;i++) { pango_layout_set_text(p,viewbuf+80*i,80); pango_cairo_update_layout(cr,p); pango_cairo_show_layout(cr,p); cairo_rel_move_to(cr,0,h); } cairo_move_to(cr,w*81+w/2,h); cairo_rel_line_to(cr,0,h*20); cairo_line_to(cr,w,h*21); cairo_stroke(cr); for(i=0;i<512;i++) { #ifndef VIEWA4 int32_t v=sounds[lastsound][i*8]; cairo_rectangle(cr,w+i,h*30, 1,5*h*(v/32767.0)); #else int32_t v=resample(lastsound,51,i); cairo_rectangle(cr,w+i,h*30, 1,5*h*(v/32767.0)); #endif } cairo_fill(cr); g_object_unref(p); cairo_destroy(cr); return FALSE; }
Ptr<ISubtitlesItem> CPangoCairoRenderer::render(Ptr<ISubtitlesItem> i_item) { Ptr<CSubtitlesTextItem> text = i_item; if (text.isNull() || i_item->getType() != SUBTITLES_TYPE_TEXT) { return Ptr<ISubtitlesItem>(); } Ptr<CCairoSurface> surface = new CCairoSurface(m_displaySize.Height, m_displaySize.Width, SURFACE_FORMAT_ARGB32); cairo_t * cairo = cairo_create(surface->getSurface()); cairo_set_source_rgba(cairo, 0.0, 0.0, 0.0, 0.0); cairo_paint(cairo); PangoLayout * layout = pango_cairo_create_layout(cairo); pango_layout_set_width(layout, m_displaySize.Width*PANGO_SCALE); pango_layout_set_wrap(layout, PANGO_WRAP_WORD); pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); pango_layout_set_text(layout, text->getText().c_str(), -1); PangoFontDescription * font = pango_font_description_from_string(m_font.c_str()); pango_layout_set_font_description(layout, font); pango_font_description_free(font); cairo_set_source_rgb(cairo, 1.0, 1.0, 1.0); pango_cairo_update_layout(cairo, layout); pango_cairo_show_layout(cairo, layout); CValue<CRectangle> rect = getPixelRectangle(layout); cairo_destroy(cairo); g_object_unref(layout); if (rect.isValid()) { Ptr<CCairoSurface> textSurface = new CCairoSurface(*surface, rect.getValue()); CSize size = rect.getValue().Size; CPoint position = computePosition(size); CRectangle newRect(position, size); return new CSubtitlesGraphicsItem(textSurface, newRect, text->getBeginTime(), text->getEndTime()); } return Ptr<ISubtitlesItem>(); }
static void draw_text (cairo_t *cr, std::string text) { #define RADIUS 300 #define N_WORDS 10 #define FONT "Alice 27" PangoLayout *layout; PangoFontDescription *desc; //int i; /* Center coordinates on the middle of the region we are drawing */ cairo_translate (cr, RADIUS, RADIUS); /* Create a PangoLayout, set the font and text */ layout = pango_cairo_create_layout (cr); pango_layout_set_text (layout, text.c_str(), -1); desc = pango_font_description_from_string (FONT); pango_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; //double angle = (360. * i) / N_WORDS; double angle = 0; double red; cairo_save (cr); /* Gradient from red at angle == 60 to blue at angle == 240 */ red = (1 + cos ((angle - 60) * G_PI / 180.)) / 2; cairo_set_source_rgb (cr, red, 0, 1.0 - red); 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_layout_get_size (layout, &width, &height); cairo_move_to (cr, - ((double)width / PANGO_SCALE) / 2, - RADIUS); pango_cairo_show_layout (cr, layout); cairo_restore (cr); } /* free the layout object */ g_object_unref (layout); }
static PyObject * _pango_cairo_update_show_layout(PyObject *self, PyObject *args) { cairo_t * cairo; PangoLayout *layout; if (!PyArg_ParseTuple(args, "ll", &cairo, &layout)) return NULL; pango_cairo_update_layout(cairo, layout); pango_cairo_show_layout(cairo, layout); Py_RETURN_NONE; }
static void draw (cairo_t *cr, PangoLayout *layout, unsigned int i) { cairo_set_source_rgba (cr, 1, 1, 1, 1); cairo_paint (cr); cairo_set_source_rgba (cr, 1, 1, 1, 0); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_identity_matrix (cr); cairo_scale (cr, (100 + i) / 100., (100 + i) / 100.); pango_cairo_update_layout (cr, layout); pango_cairo_show_layout (cr, layout); }
void ly_3lrc_widget_draw_text (cairo_t *cr, gchar *text, gchar *font) { PangoLayout *layout; PangoFontDescription *desc; layout = pango_cairo_create_layout (cr); pango_layout_set_text (layout, text, -1); desc = pango_font_description_from_string (font); pango_layout_set_font_description (layout, desc); pango_font_description_free (desc); pango_cairo_update_layout (cr, layout); pango_cairo_show_layout (cr, layout); g_object_unref (layout); }
static void br_cairo_draw_tooltip(duc_graph *g, double x, double y, char *text) { struct cairo_backend_data *bd = g->backend_data; cairo_t *cr = bd->cr; char font[32]; snprintf(font, sizeof font, "Arial, Sans, %d", FONT_SIZE_TOOLTIP); PangoLayout *layout = pango_cairo_create_layout(cr); PangoFontDescription *desc = pango_font_description_from_string(font); pango_layout_set_text(layout, text, -1); pango_layout_set_font_description(layout, desc); pango_font_description_free(desc); pango_cairo_update_layout(cr, layout); int w,h; pango_layout_get_size(layout, &w, &h); w /= PANGO_SCALE; h /= PANGO_SCALE; /* shadow box */ int i; for(i=1; i<3; i++) { cairo_rectangle(cr, x - w - 10 + i, y - h - 10 + i, w + 10 + i, h + 10 + i); cairo_set_source_rgba(cr, 0, 0, 0, 0.25); cairo_fill(cr); } /* tooltip box */ cairo_rectangle(cr, x - w - 10 + 0.5, y - h - 10 + 0.5, w + 10, h + 10); cairo_set_source_rgba(cr, 1, 1, 1, 1); cairo_fill_preserve(cr); cairo_set_source_rgba(cr, 0, 0, 0, 1); cairo_stroke(cr); /* black text */ cairo_move_to(cr, x - w - 5, y - h - 5); pango_cairo_layout_path(cr, layout); g_object_unref(layout); cairo_set_source_rgb(cr, 0, 0, 0); cairo_set_line_width(cr, 1); cairo_fill(cr); }
PangoLayout* TextView::initPango(cairo_t* cr, Text* t) { PangoLayout* layout = pango_cairo_create_layout(cr); // Additional Feature: add autowrap and text field size for // the next xournal release (with new fileformat...) // pango_layout_set_wrap pango_cairo_context_set_resolution(pango_layout_get_context(layout), textDpi); pango_cairo_update_layout(cr, layout); pango_context_set_matrix(pango_layout_get_context(layout), NULL); updatePangoFont(layout, t); return layout; }
void iupDrawText(IdrawCanvas* dc, const char* text, int len, int x, int y, unsigned char r, unsigned char g, unsigned char b, const char* font) { PangoLayout* fontlayout = (PangoLayout*)iupgtkGetPangoLayout(font); pango_layout_set_text(fontlayout, iupgtkStrConvertToUTF8(text), len); cairo_set_source_rgba(dc->image_cr, iupCOLOR8ToDouble(r), iupCOLOR8ToDouble(g), iupCOLOR8ToDouble(b), 1.0); pango_cairo_update_layout(dc->image_cr, fontlayout); cairo_move_to(dc->image_cr, x, y); pango_cairo_show_layout(dc->image_cr, fontlayout); }
void pango_printf(cairo_t *cairo, const char *font, int32_t scale, bool markup, const char *fmt, ...) { char *buf = malloc(2048); va_list args; va_start(args, fmt); if (vsnprintf(buf, 2048, fmt, args) >= 2048) { strcpy(buf, "[buffer overflow]"); } va_end(args); PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup); pango_cairo_update_layout(cairo, layout); pango_cairo_show_layout(cairo, layout); g_object_unref(layout); free(buf); }
//------------------------------------------------------------------ void ofxPangoCairo::rendertext(cairo_t *cr) { PangoLayout *layout; PangoFontDescription *desc; cairo_translate(cr, 10, 20); layout = pango_cairo_create_layout(cr); pango_layout_set_text(layout, "Hello World!", -1); desc = pango_font_description_from_string("Sans Bold 100"); pango_layout_set_font_description(layout, desc); pango_font_description_free(desc); cairo_set_source_rgb(cr, 0.0, 0.0, 1.0); pango_cairo_update_layout(cr, layout); pango_cairo_show_layout(cr, layout); /* g_object_unref(layout); */ }
static PangoLayout *get_pangolayout(struct qp_graph *gr, cairo_t *cr) { if(!gr->pangolayout) { gr->pangolayout = pango_cairo_create_layout(cr); qp_graph_set_grid_font(gr); } else { pango_cairo_update_layout(cr, gr->pangolayout); } if((gr->font_antialias_set && gr->qp->shape) || (!gr->font_antialias_set && !gr->qp->shape)) { /* Doing a lot of crap just to set one bit */ cairo_font_options_t *fopt; PangoContext *pc; fopt = cairo_font_options_create(); if(gr->qp->shape) { cairo_font_options_set_antialias(fopt, CAIRO_ANTIALIAS_NONE); gr->font_antialias_set = 0; } else { cairo_font_options_set_antialias(fopt, CAIRO_ANTIALIAS_DEFAULT); gr->font_antialias_set = 1; } pc = pango_layout_get_context(gr->pangolayout); pango_cairo_context_set_font_options(pc, fopt); cairo_font_options_destroy(fopt); } return gr->pangolayout; }
gdouble planner_print_job_get_extents (PlannerPrintJob *job, char *text) { PangoLayout *layout = gtk_print_context_create_pango_layout (job->pc); PlannerPrintJobPriv *priv; PangoRectangle ink; priv = job->priv; pango_layout_set_font_description (layout, priv->current_font); pango_layout_set_text (layout, text, -1); pango_cairo_update_layout (gtk_print_context_get_cairo_context(job->pc), layout); pango_layout_context_changed (layout); pango_layout_get_extents (layout, &ink, NULL); g_object_unref (layout); return ((gdouble)ink.width / PANGO_SCALE); }
static void br_cairo_draw_text(duc_graph *g, double x, double y, double size, char *text) { struct cairo_backend_data *bd = g->backend_data; cairo_t *cr = bd->cr; char font[32]; snprintf(font, sizeof font, "Arial, Sans, %.0f", size); PangoLayout *layout = pango_cairo_create_layout(cr); PangoFontDescription *desc = pango_font_description_from_string(font); pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); pango_layout_set_text(layout, text, -1); pango_layout_set_font_description(layout, desc); pango_font_description_free(desc); pango_cairo_update_layout(cr, layout); int w,h; pango_layout_get_size(layout, &w, &h); x -= ((double)w / PANGO_SCALE / 2); y -= ((double)h / PANGO_SCALE / 2); cairo_move_to(cr, x, y); pango_cairo_layout_path(cr, layout); g_object_unref(layout); /* light grey background */ cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL); cairo_set_source_rgba(cr, 1, 1, 1, 0.6); cairo_set_line_width(cr, 3); cairo_stroke_preserve(cr); /* black text */ cairo_set_source_rgb(cr, 0, 0, 0); cairo_set_line_width(cr, 1); cairo_fill(cr); }
void draw_password_mask(void) { cairo_t *cr = cairo_create(lualock.pw_surface); cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); cairo_paint(cr); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); draw_password_field(cr); PangoLayout *layout = pango_cairo_create_layout(cr); pango_layout_set_font_description(layout, lualock.style.font_desc); cairo_set_source_rgba(cr, lualock.style.r, lualock.style.g, lualock.style.b, lualock.style.a); cairo_move_to(cr, lualock.style.off_x, lualock.style.off_y); gchar *password_mask = get_password_mask(); pango_layout_set_text(layout, password_mask, -1); free(password_mask); pango_cairo_update_layout(cr, layout); pango_cairo_layout_path(cr, layout); cairo_fill(cr); g_object_unref(layout); cairo_destroy(cr); }