示例#1
0
static void
draw_header (GtkPrintContext * cnt, gint pn, gint pc)
{
  cairo_t *cr;
  PangoFontDescription *desc;
  PangoLayout *layout;
  gint pw, tw, th;
  gchar *page;

  cr = gtk_print_context_get_cairo_context (cnt);
  pw = gtk_print_context_get_width (cnt);

  layout = gtk_print_context_create_pango_layout (cnt);

  desc = pango_font_description_from_string (HEADER_FONT);
  pango_layout_set_font_description (layout, desc);
  pango_font_description_free (desc);

  pango_layout_set_text (layout, options.common_data.uri, -1);
  pango_layout_get_pixel_size (layout, &tw, &th);
  if (tw > pw)
    {
      pango_layout_set_width (layout, pw);
      pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_START);
      pango_layout_get_pixel_size (layout, &tw, &th);
    }

  cairo_move_to (cr, (pw - tw) / 2, (HEADER_HEIGHT - th) / 2);
  pango_cairo_show_layout (cr, layout);

  page = g_strdup_printf ("%d/%d", pn, pc);
  pango_layout_set_text (layout, page, -1);
  g_free (page);

  pango_layout_set_width (layout, -1);
  pango_layout_get_pixel_size (layout, &tw, &th);
  cairo_move_to (cr, pw - tw - 4, (HEADER_HEIGHT - th) / 2);
  pango_cairo_show_layout (cr, layout);

  g_object_unref (layout);

  cairo_move_to (cr, 0.0, HEADER_HEIGHT);
  cairo_line_to (cr, pw, HEADER_HEIGHT);

  cairo_set_source_rgb (cr, 0, 0, 0);
  cairo_set_line_width (cr, 1);
  cairo_stroke (cr);
}
示例#2
0
void SetUpStatusBarStuff (GtkWidget* aWindow)
{
	_String			   fName = baseDirectory & "GTKResources/striped.xpm";
	statusBarLayout			 = pango_layout_new (screenPContext);
	statusBarFontDesc		 = pango_font_description_new ();
	stripedFill				 = gdk_pixmap_create_from_xpm (GDK_DRAWABLE(aWindow->window), NULL, NULL, fName.sData);
	stripedFillGC			 = gdk_gc_new (GDK_DRAWABLE(aWindow->window));
	if (stripedFill)
	{
		gdk_gc_set_fill (stripedFillGC,GDK_TILED);
		gdk_gc_set_tile	(stripedFillGC,stripedFill);
	}
	else
	{
		printf ("Failed to load a status bar .xpm from %s\n", fName.sData);
	}
	
	gdk_gc_set_line_attributes		  (stripedFillGC, 1, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER);
	GdkColor saveFG = {0,0,0,0};
	gdk_gc_set_foreground			  (stripedFillGC, &saveFG);

	pango_font_description_set_family (statusBarFontDesc, statusBarFont.face.sData);
	pango_font_description_set_style  (statusBarFontDesc, (statusBarFont.style & HY_FONT_ITALIC) ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL);
	pango_font_description_set_weight (statusBarFontDesc, (statusBarFont.style & HY_FONT_BOLD) ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL);
	pango_font_description_set_size   (statusBarFontDesc, statusBarFont.size*PANGO_SCALE);
	pango_layout_set_font_description (statusBarLayout, statusBarFontDesc ); // ref ?
	pango_layout_set_width			  (statusBarLayout, -1);
	
	redButtonIcon = (GdkPixbuf*)ProcureIconResource(4000);
	yellowButtonIcon = (GdkPixbuf*)ProcureIconResource(4001);
	greenButtonIcon = (GdkPixbuf*)ProcureIconResource(4002);
	orangeButtonIcon = (GdkPixbuf*)ProcureIconResource(4003);
	
}
示例#3
0
GtGraphics* gt_graphics_cairo_new_from_context(cairo_t *context,
                                               unsigned int width,
                                               unsigned int height)
{
  GtGraphics *g;
  GtGraphicsCairo *gc;
  char buf[64];
  g = gt_graphics_create(gt_graphics_cairo_class());
  gc = gt_graphics_cairo_cast(g);
  gc->width = width;
  gc->height = height;
  gc->margin_x = gc->margin_y = 20;
  gc->from_context = true;
  gc->cr = context;
  gc->layout = pango_cairo_create_layout(gc->cr);
  pango_layout_set_width(gc->layout, -1);
  gt_assert(gc->layout);
  snprintf(buf, 64, "Sans %d", TEXT_SIZE_DEFAULT);
  gc->desc = pango_font_description_from_string(buf);
  pango_layout_set_font_description(gc->layout, gc->desc);
  pango_font_description_free(gc->desc);
  cairo_set_line_join(context, CAIRO_LINE_JOIN_ROUND);
  cairo_set_line_cap(context, CAIRO_LINE_CAP_ROUND);
  return g;
}
示例#4
0
static
void mw_paint_tip(GtkWidget *widget, GdkEventExpose *event)
{
	GtkStyle *style;
	GdkWindow *window;
	char *tooltiptext = get_tooltip_text();

	if(tooltiptext == NULL) tooltiptext = g_strdup("oeps");
	pango_layout_set_markup(layout, tooltiptext, strlen(tooltiptext));
	pango_layout_set_wrap(layout, PANGO_WRAP_WORD);
	pango_layout_set_width(layout, 300000);
	style = gtk_widget_get_style (tipwindow);
	window = gtk_widget_get_window (tipwindow);

	gtk_paint_flat_box (style, window, GTK_STATE_NORMAL, GTK_SHADOW_OUT,
			NULL, tipwindow, "tooltip", 0, 0, -1, -1);


	gtk_paint_layout (style, window, GTK_STATE_NORMAL, TRUE,
			NULL, tipwindow, "tooltip", 4, 4, layout);
	/*
	   g_object_unref(layout);
	   */
	g_free(tooltiptext);
	return;
}
示例#5
0
文件: tooltip.c 项目: alaricljs/tint2
void tooltip_update()
{
	if (!g_tooltip.tooltip_text) {
		tooltip_hide(0);
		return;
	}

	tooltip_update_geometry();
	if (just_shown) {
		if (!panel_horizontal)
			y -= height / 2; // center vertically
		just_shown = FALSE;
	}
	tooltip_adjust_geometry();
	XMoveResizeWindow(server.display, g_tooltip.window, x, y, width, height);

	// Stuff for drawing the tooltip
	cairo_surface_t *cs = cairo_xlib_surface_create(server.display, g_tooltip.window, server.visual, width, height);
	cairo_t *c = cairo_create(cs);
	Color bc = g_tooltip.bg->fill_color;
	Border b = g_tooltip.bg->border;
	if (server.real_transparency) {
		clear_pixmap(g_tooltip.window, 0, 0, width, height);
		draw_rect(c, b.width, b.width, width - 2 * b.width, height - 2 * b.width, b.radius - b.width / 1.571);
		cairo_set_source_rgba(c, bc.rgb[0], bc.rgb[1], bc.rgb[2], bc.alpha);
	} else {
		cairo_rectangle(c, 0., 0, width, height);
		cairo_set_source_rgb(c, bc.rgb[0], bc.rgb[1], bc.rgb[2]);
	}
	cairo_fill(c);
	cairo_set_line_width(c, b.width);
	if (server.real_transparency)
		draw_rect(c, b.width / 2.0, b.width / 2.0, width - b.width, height - b.width, b.radius);
	else
		cairo_rectangle(c, b.width / 2.0, b.width / 2.0, width - b.width, height - b.width);
	cairo_set_source_rgba(c, b.color.rgb[0], b.color.rgb[1], b.color.rgb[2], b.color.alpha);
	cairo_stroke(c);

	Color fc = g_tooltip.font_color;
	cairo_set_source_rgba(c, fc.rgb[0], fc.rgb[1], fc.rgb[2], fc.alpha);
	PangoLayout *layout = pango_cairo_create_layout(c);
	pango_layout_set_font_description(layout, g_tooltip.font_desc);
	pango_layout_set_wrap(layout, PANGO_WRAP_WORD);
	pango_layout_set_text(layout, g_tooltip.tooltip_text, -1);
	PangoRectangle r1, r2;
	pango_layout_get_pixel_extents(layout, &r1, &r2);
	pango_layout_set_width(layout, width * PANGO_SCALE);
	pango_layout_set_height(layout, height * PANGO_SCALE);
	pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
	// I do not know why this is the right way, but with the below cairo_move_to it seems to be centered (horiz. and
	// vert.)
	cairo_move_to(c,
				  -r1.x / 2 + g_tooltip.bg->border.width + g_tooltip.paddingx,
				  -r1.y / 2 + 1 + g_tooltip.bg->border.width + g_tooltip.paddingy);
	pango_cairo_show_layout(c, layout);

	g_object_unref(layout);
	cairo_destroy(c);
	cairo_surface_destroy(cs);
}
示例#6
0
文件: tooltip.c 项目: alaricljs/tint2
void tooltip_update_geometry()
{
	Panel *panel = g_tooltip.panel;
	int screen_width = server.monitors[panel->monitor].x + server.monitors[panel->monitor].width;

	cairo_surface_t *cs = cairo_xlib_surface_create(server.display, g_tooltip.window, server.visual, width, height);
	cairo_t *c = cairo_create(cs);
	PangoLayout *layout = pango_cairo_create_layout(c);

	pango_layout_set_font_description(layout, g_tooltip.font_desc);
	PangoRectangle r1, r2;
	pango_layout_set_text(layout, "1234567890", -1);
	pango_layout_get_pixel_extents(layout, &r1, &r2);
	int max_width = MIN(r2.width * 7, screen_width * 2 / 3);
	pango_layout_set_width(layout, max_width * PANGO_SCALE);

	pango_layout_set_text(layout, g_tooltip.tooltip_text, -1);
	pango_layout_set_wrap(layout, PANGO_WRAP_WORD);
	pango_layout_get_pixel_extents(layout, &r1, &r2);
	width = 2 * g_tooltip.bg->border.width + 2 * g_tooltip.paddingx + r2.width;
	height = 2 * g_tooltip.bg->border.width + 2 * g_tooltip.paddingy + r2.height;

	if (panel_horizontal && panel_position & BOTTOM)
		y = panel->posy - height;
	else if (panel_horizontal && panel_position & TOP)
		y = panel->posy + panel->area.height;
	else if (panel_position & LEFT)
		x = panel->posx + panel->area.width;
	else
		x = panel->posx - width;

	g_object_unref(layout);
	cairo_destroy(c);
	cairo_surface_destroy(cs);
}
示例#7
0
static void
gtk_label_layoutable_size_allocate (GtkLayoutable        *layoutable,
                                    GtkAllocation        *allocation)
{
  GtkLabel *label = GTK_LABEL (layoutable);

  if (gtk_label_get_line_wrap (label))
    {
      PangoLayout *layout;
      PangoRectangle rect;

      /* Make it span the entire line.  */
      layout = gtk_label_get_layout (label);
      pango_layout_set_width (layout, allocation->width * PANGO_SCALE);
      pango_layout_get_extents (layout, NULL, &rect);

      allocation->width = rect.width / PANGO_SCALE + label->misc.xpad * 2;
      allocation->height = rect.height / PANGO_SCALE + label->misc.ypad * 2;

      gtk_misc_set_alignment (&label->misc, 0.0, 0.0);
      gtk_widget_size_allocate (GTK_WIDGET (label), allocation);
    }

  else
    (gtk_label_parent_layoutable_iface->size_allocate) (layoutable, allocation);
}
示例#8
0
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);
}
示例#9
0
/**
 * draw a cell of a model
 *
 * \param context           the GtkPrintContext
 * \param line_position     the position to insert the column
 * \param column_position   the position to insert the data
 *
 * \return the new column_position
 * */
static gint print_tree_view_list_draw_cell ( GtkPrintContext *context,
                        gint line_position,
                        gint column_position,
                        gint column,
                        const gchar *text )
{
    PangoLayout *layout;

    /* draw first the column */
    column_position = print_tree_view_list_draw_column ( column_position, line_position );

    cairo_move_to (cr, column_position, line_position);

    /* create the new layout */
    layout = gtk_print_context_create_pango_layout (context);
    pango_layout_set_text ( layout, text, -1 );
    pango_layout_set_font_description ( layout, gsb_data_print_config_get_font_transactions () );
    pango_layout_set_width ( layout,columns_width[column] );
    pango_layout_set_alignment ( layout, alignment[column] );
    pango_layout_set_ellipsize ( layout, PANGO_ELLIPSIZE_END );

    pango_cairo_show_layout ( cr, layout );
    g_object_unref ( layout );

    return column_position;
}
示例#10
0
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);
}
static PangoLayout *
create_layout_with_attrs (GtkWidget *widget,
                          GdTwoLinesRenderer *self,
                          PangoEllipsizeMode ellipsize)
{
  PangoLayout *layout;
  gint wrap_width;
  PangoWrapMode wrap_mode;
  PangoAlignment alignment;

  g_object_get (self,
                "wrap-width", &wrap_width,
                "wrap-mode", &wrap_mode,
                "alignment", &alignment,
                NULL);

  layout = pango_layout_new (gtk_widget_get_pango_context (widget));

  pango_layout_set_ellipsize (layout, ellipsize);
  pango_layout_set_wrap (layout, wrap_mode);
  pango_layout_set_alignment (layout, alignment);

  if (wrap_width != -1)
    pango_layout_set_width (layout, wrap_width * PANGO_SCALE);

  return layout;
}
示例#12
0
/* Handle a size allocation by re-laying-out each paragraph to
 * the new width, setting the new size for the layout and
 * then queing a redraw
 */
void
size_allocate (GtkWidget *layout, GtkAllocation *allocation)
{
  GList *tmp_list;
  guint height = 0;
  PangoDirection base_dir = pango_context_get_base_dir (context);

  tmp_list = paragraphs;
  while (tmp_list)
    {
      Paragraph *para = tmp_list->data;
      PangoRectangle logical_rect;
	  
      tmp_list = tmp_list->next;

      pango_layout_set_alignment (para->layout,
				  base_dir == PANGO_DIRECTION_LTR ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT);
      pango_layout_set_width (para->layout, layout->allocation.width * PANGO_SCALE);

      pango_layout_get_extents (para->layout, NULL, &logical_rect);
      para->height = PANGO_PIXELS (logical_rect.height);
      
      height += para->height;
    }

  gtk_layout_set_size (GTK_LAYOUT (layout), allocation->width, height);

  if (GTK_LAYOUT (layout)->yoffset + allocation->height > height)
    gtk_adjustment_set_value (GTK_LAYOUT (layout)->vadjustment, (float)(height - allocation->height));
}
示例#13
0
static void
e_contact_output (GtkPrintContext *context,
                  PangoFontDescription *font,
                  gdouble x,
                  gdouble y,
                  gdouble width,
                  const gchar *text)
{
	PangoLayout *layout;
	gdouble indent;
	cairo_t *cr;

	layout = gtk_print_context_create_pango_layout (context);

	if (width == -1 || get_font_width (context, font, text) <= width)
		indent = .0;
	else
		indent = get_font_width (context, font, "     ");

	pango_layout_set_font_description (layout, font);
	pango_layout_set_text (layout, text, -1);
	pango_layout_set_width (layout, pango_units_from_double (width));
	pango_layout_set_indent (layout, pango_units_from_double (indent));
	pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR);

	cr = gtk_print_context_get_cairo_context (context);

	cairo_save (cr);
	cairo_move_to (cr, x, y);
	pango_cairo_show_layout (cr, layout);
	cairo_restore (cr);

	g_object_unref (layout);
}
示例#14
0
void ZDrawSongInfo(IDirectFB *dfb, IDirectFBSurface *dfbsurface, const gchar *title, const gchar *artist, 
		gint w, gint h, DFBColor *color, DFBColor *strokeColor, double strokeWidth, const PangoFontDescription *desc)
{
	cairo_t *cr = NULL;
	cairo_surface_t *surface = NULL;
	cairo_surface_t *cairosurface = NULL;
	PangoLayout *layout = NULL;
	
	if(!dfb || !dfbsurface)
		return;
	
	/* prepare layout */
	layout = pango_layout_new(gdk_pango_context_get());
	pango_layout_set_single_paragraph_mode (layout, TRUE);
	pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
	pango_layout_set_width(layout, w* PANGO_SCALE);
	pango_layout_set_font_description(layout, desc);
	
	surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
	cr = cairo_create(surface);
	
	/* Draw title */
	if(title) {
		pango_layout_set_text(layout, title, -1);
		cairo_move_to(cr, 0, 0);
		pango_cairo_layout_path(cr, layout);
		ZCairoSetDFBColor(cr, strokeColor);
		cairo_set_line_width(cr, strokeWidth);
		cairo_stroke_preserve(cr);
		
		ZCairoSetDFBColor(cr, color);
		cairo_fill(cr);
	}
	
	/* Draw artist */
	if(artist) {
		pango_layout_set_text(layout, artist, -1);
		cairo_move_to(cr, 0, h/2);
		pango_cairo_layout_path(cr, layout);
		ZCairoSetDFBColor(cr, strokeColor);
		cairo_set_line_width(cr, strokeWidth);
		cairo_stroke_preserve(cr);
		
		ZCairoSetDFBColor(cr, color);
		cairo_fill(cr);
	}
	
	g_object_unref(layout);
	cairo_destroy(cr);
	
	/* Draw cairo_surface to dfbsurface */
	/* create surface */
	cairosurface = cairo_directfb_surface_create(dfb, dfbsurface);
	cr = cairo_create(cairosurface);
	cairo_set_source_surface(cr, surface, 0, 0);
	cairo_paint(cr);
	cairo_destroy(cr);
	cairo_surface_destroy(surface);
	cairo_surface_destroy(cairosurface);
}
示例#15
0
TextAsset::Size
TextAsset::computeSizeOfText(cairo_t* cairoContext,
                             const std::string textString,
                             int bounds,
                             PangoFontDescription* font,
                             Rect* tight,
                             float* lineHeightOut)
{
    PangoLayout* layout = pango_cairo_create_layout(cairoContext);

    // Kerning
    PangoAttrList* attr_list = pango_attr_list_new();
    PangoAttribute* spacing_attr = pango_attr_letter_spacing_new(pango_units_from_double(_kern));
    pango_attr_list_insert(attr_list, spacing_attr);
    pango_layout_set_attributes(layout, attr_list);

    pango_cairo_context_set_resolution(pango_layout_get_context(layout), DISPLAY_RESOLUTION);
    pango_layout_set_text(layout, textString.c_str(), (int)textString.length());
    pango_layout_set_alignment(layout, _alignment);
    pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);

    const Size maxTextureSize(bounds, 1024);
    pango_layout_set_width(layout, pango_units_from_double(maxTextureSize.width));
    pango_layout_set_height(layout, pango_units_from_double(maxTextureSize.height));
    pango_layout_set_font_description(layout, font);
    applyLeading(cairoContext, layout, font);

    PangoRectangle estimateSize;
    PangoRectangle ink;
    pango_layout_get_pixel_extents(layout, &ink, &estimateSize);

    // If the text is right or center aligned the offsets will contain all the
    // leading space.  We ignore that for the size because drawText will draw
    // in the larger box.  The tight box below will get the offsets so we know
    // where to draw so the text lands in the same tight box.
    Size res(estimateSize.width, estimateSize.height);

    if (tight != NULL) {
        float lineHeight;
        float xHeight = charHeight(cairoContext, font, 'x', &lineHeight);
        if (lineHeightOut != NULL) {
            *lineHeightOut = lineHeight;
        }
        const float capHeight = charHeight(cairoContext, font, 'Y');
        const float ascender = pango_units_to_double(pango_layout_get_baseline(layout));
        const float topSpace = ascender - capHeight;
        const float bottomSpace = MAX(lineHeight - ascender - (capHeight - xHeight), 0);
        if (res.height > topSpace + bottomSpace) {
            *tight = Rect(estimateSize.x,
                          estimateSize.y + topSpace,
                          res.width,
                          res.height - topSpace - bottomSpace);
        } else {
            *tight = Rect(0, 0, res.width, res.height);
        }
    }
    g_object_unref(layout);

    return res;
}
示例#16
0
文件: execplugin.c 项目: o9000/tint2
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);
}
示例#17
0
文件: x11-ui.c 项目: johanmalm/jgmenu
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);
}
示例#18
0
ttext& ttext::set_maximum_width(int width)
{
	if(width <= 0) {
		width = -1;
	}

	if(width != maximum_width_) {
		assert(context_);
#if 0
		/**
		 * todo Adding 4 extra pixels feels a bit hacky.
		 *
		 * For some reason it's needed since the following scenario fails:
		 * - pango_layout_set_width(value)
		 * - pango_layout_get_pixel_extents() -> max_width_1
		 * - pango_layout_set_width(max_width_1)
		 * - pango_layout_get_pixel_extents() -> max_width_2
		 *
		 * Now it can happen max_width_2 < max_width_1. Adding the 4 seems to
		 * "fix" the problem.
		 */
		pango_layout_set_width(layout_, width == -1
				? -1
				: (width + 4) * PANGO_SCALE);
#endif
		maximum_width_ = width;
		calculation_dirty_ = true;
		surface_dirty_ = true;
	}

	return *this;
}
/* Updates the pango layout width */
static void
update_pango_layout (MateIconTextItem *iti)
{
    MateIconTextItemPrivate *priv;
    PangoRectangle bounds;
    const char *text;

    priv = iti->_priv;

    if (iti->editing) {
        text = gtk_entry_get_text (GTK_ENTRY (priv->entry));
    } else {
        text = iti->text;
    }

    pango_layout_set_wrap (priv->layout, PANGO_WRAP_WORD_CHAR);
    pango_layout_set_text (priv->layout, text, strlen (text));
    pango_layout_set_width (priv->layout, iti->width * PANGO_SCALE);

    /* In PANGO_WRAP_WORD mode, words wider than a line of text make
     * PangoLayout overflow the layout width.  If this happens, switch to
     * character-based wrapping.
     */

    pango_layout_get_pixel_extents (iti->_priv->layout, NULL, &bounds);

    priv->layout_width = bounds.width;
    priv->layout_height = bounds.height;
}
示例#20
0
文件: decorator.c 项目: micove/compiz
/*
 * max_window_name_width
 *
 * Returns: gint
 * Description: Calculate the width of the decoration required to display
 * the window name using pango (with 6px padding)
 * Returns zero if window has no name.
 */
gint
max_window_name_width (WnckWindow *win)
{
    decor_t     *d = g_object_get_data (G_OBJECT (win), "decor");
    const gchar *name;
    gint	w;

    /* Ensure that a layout is created */
    if (!d->layout)
    {
	d->layout = pango_layout_new (d->frame->pango_context);
	if (!d->layout)
	    return 0;

	pango_layout_set_wrap (d->layout, PANGO_WRAP_CHAR);
    }

    /* Return zero if window has no name */
    name = wnck_window_get_name (win);
    if (!name)
	return 0;

    /* Reset the width, set hte text and get the size required */
    pango_layout_set_auto_dir (d->layout, FALSE);
    pango_layout_set_width (d->layout, -1);
    pango_layout_set_text (d->layout, name, strlen (name));
    pango_layout_get_pixel_size (d->layout, &w, NULL);

    if (d->name)
	pango_layout_set_text (d->layout, d->name, strlen (d->name));

    return w + 6;
}
示例#21
0
void Text::SetString(const string& String)
{
    cairo_surface_t* TempSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0);
    cairo_t* LayoutContext = cairo_create(TempSurface);
    cairo_surface_destroy(TempSurface);

    PangoLayout* Layout = pango_cairo_create_layout(LayoutContext);
    pango_layout_set_width(Layout, LayoutWidth * PANGO_SCALE);
    pango_layout_set_wrap(Layout, PANGO_WRAP_WORD_CHAR);
    pango_layout_set_text(Layout, String.c_str(), -1);

    PangoFontDescription* Desc = pango_font_description_from_string("Sans 18");
    pango_font_description_set_absolute_size(Desc, Size * PANGO_SCALE);
    pango_font_description_set_weight(Desc, PANGO_WEIGHT_MEDIUM);
    pango_layout_set_font_description(Layout, Desc);
    pango_font_description_free(Desc);

    pango_layout_get_pixel_size(Layout, &Width, &Height);
    uint8_t* pData = (uint8_t*)calloc(4 * Width * Height, sizeof(uint8_t));
    cairo_surface_t* Surface = cairo_image_surface_create_for_data(pData, CAIRO_FORMAT_ARGB32, Width, Height, 4 * Width);
    cairo_t* RenderContext = cairo_create(Surface);

    cairo_set_source_rgba(RenderContext, Color & 0xFF, (Color >> 8) & 0xFF, (Color >> 16) & 0xFF, Color >> 24);
    pango_cairo_show_layout(RenderContext, Layout);
    Create(pData, GL_RGBA, Width, Height);

    free(pData);
    g_object_unref(Layout);
    cairo_destroy(LayoutContext);
    cairo_destroy(RenderContext);
    cairo_surface_destroy(Surface);
}
示例#22
0
void LeftMargin::setupMargin(GtkTextView *textView)
    {
    if(!mMarginLayout)
        {
        GtkWidget *widget = GTK_WIDGET(textView);

        mMarginLayout = gtk_widget_create_pango_layout(widget, "");
        updateTextInfo(textView);

        pango_layout_set_width(mMarginLayout, mTextWidth);
        pango_layout_set_alignment(mMarginLayout, PANGO_ALIGN_RIGHT);

        GtkStyleContext *widgetStyle = gtk_widget_get_style_context(widget);
        GdkRGBA color;
        gtk_style_context_get_color(widgetStyle, GTK_STATE_FLAG_NORMAL, &color);
        mMarginAttr = pango_attr_foreground_new(convertGdkColorToPango(color.red),
                convertGdkColorToPango(color.green), convertGdkColorToPango(color.blue));
        mMarginAttrList = pango_attr_list_new();

        mMarginAttr->start_index = 0;
        mMarginAttr->end_index = G_MAXUINT;
        pango_attr_list_insert(mMarginAttrList, mMarginAttr);
        pango_layout_set_attributes(mMarginLayout, mMarginAttrList);
        }
    }
示例#23
0
//________________________________________________________
long    GetVisibleStringWidth (_String& s, _HYFont& f)
{
    static PangoLayout* textLayout       = pango_layout_new (screenPContext);
    static PangoFontDescription * fd     = pango_font_description_new ();
    static _HYFont                         stashedFont;

    if (s.sLength) {
        if (stashedFont.size!=f.size || stashedFont.style != f.style || stashedFont.face != f.face) {
            HYFont2PangoFontDesc(f,fd);
            pango_layout_set_width (textLayout,-1);
            pango_layout_set_font_description(textLayout,fd);
            stashedFont = f;
        }
        pango_layout_set_text (textLayout, s.sData,s.sLength);
        //PangoRectangle charPos;
        //pango_layout_index_to_pos (textLayout,s.sLength-1,&charPos);
        //return PANGO_PIXELS(charPos.x+charPos.width);
        PangoRectangle extents,
                       logical_ext;

        pango_layout_get_pixel_extents (textLayout,&extents,&logical_ext);
        return logical_ext.width;
    } else {
        return 0;
    }

}
示例#24
0
struct TEXT_WIDGET_HANDLE text_widget_init ( float x_mm, float y_mm,
					     float width_mm,
					     float height_mm,
					     float dpmm_x,
					     float dpmm_y )
{
  struct TEXT_WIDGET_HANDLE handle;
  handle.d = malloc( sizeof( struct TEXT_WIDGET_PRIVATE ) );
  handle.d->x_mm = x_mm;
  handle.d->y_mm = y_mm;
  handle.d->dpmm_x = dpmm_x;
  handle.d->dpmm_y = dpmm_y;
  handle.d->font_map = pango_ft2_font_map_new();

  // Note: FreeType works in DPI.
  pango_ft2_font_map_set_resolution( (PangoFT2FontMap*)handle.d->font_map,
				     dpmm_x * 25.4, dpmm_y * 25.4 );

  handle.d->context  = pango_font_map_create_context( handle.d->font_map );
  handle.d->layout   = pango_layout_new( handle.d->context );

  // Pango works in Pango Units. Not exactly clear how the resolution of
  // the font and the size of the rendering box fit together.
  int width = pango_units_from_double( dpmm_x * width_mm );
  int height = pango_units_from_double( dpmm_y * height_mm );
  pango_layout_set_width( handle.d->layout, width );
  pango_layout_set_height( handle.d->layout, height );

  handle.d->foreground = vgCreatePaint();
  vgSetParameterfv( handle.d->foreground, VG_PAINT_COLOR, 4, DEFAULT_FOREGROUND );

  return handle;
}
示例#25
0
text_wrapper::text_wrapper(void)
{
    // voids everything
    utf8_text = NULL;
    uni32_text = NULL;
    glyph_text = NULL;
    utf8_length = 0;
    uni32_length = 0;
    glyph_length = 0;
    utf8_codepoint = NULL;
    uni32_codepoint = NULL;
    default_font = NULL;
    bounds = NULL;
    nbBound = maxBound = 0;
    boxes = NULL;
    nbBox = maxBox = 0;
    paras = NULL;
    nbPara = maxPara = 0;
    kern_x = kern_y = NULL;
    last_addition = -1;
    // inits the pangolayout with default params
    font_factory *font_src = font_factory::Default();
    pLayout = pango_layout_new(font_src->fontContext);
    pango_layout_set_single_paragraph_mode(pLayout, true);
    pango_layout_set_width(pLayout, -1);
}
示例#26
0
/**
 * draw the title if asked
 *
 * \param context           the GtkPrintContext
 * \param line_position     the position to insert the title
 * \param page_width        the page width
 *
 * \return the new line_position to continue to fill the page
 * */
static gint print_tree_view_list_draw_title ( GtkPrintContext *context,
                        gint line_position )
{
    if ( title_string && strlen ( title_string ) )
    {
        PangoLayout *layout;
        devel_debug_int (line_position);

        cairo_move_to ( cr, 0, line_position );

        /* create the new layout */
        layout = gtk_print_context_create_pango_layout ( context );

        pango_layout_set_text ( layout, title_string, -1 );
        pango_layout_set_font_description ( layout, gsb_data_print_config_get_font_title () );
        pango_layout_set_width ( layout, page_width * PANGO_SCALE );
        pango_layout_set_alignment ( layout, PANGO_ALIGN_CENTER );
        pango_layout_set_ellipsize ( layout, PANGO_ELLIPSIZE_END );
        pango_cairo_show_layout ( cr, layout );
        g_object_unref ( layout );

        /* add title line and blank line */
        line_position = line_position + size_title;
    }

    return line_position;
}
示例#27
0
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);
}
示例#28
0
文件: draw.c 项目: wm4/dunst
static void
set_text(DC *dc, const char *text, int force_width, int breaklines) {
    if (force_width != -1)
        force_width *= PANGO_SCALE;
    pango_layout_set_width(dc->plo, force_width);
    pango_layout_set_ellipsize(dc->plo, breaklines ? PANGO_ELLIPSIZE_NONE : PANGO_ELLIPSIZE_END);
    pango_layout_set_text(dc->plo, text, strlen(text));
}
示例#29
0
void
draw_get_text_extents (drawctx_t *ctx, const char *text, int len, int *w, int *h) {
    draw_init_font (ctx, 0, 0);
    pango_layout_set_width (ctx->pangolayout, -1);
    pango_layout_set_alignment (ctx->pangolayout, PANGO_ALIGN_LEFT);
    pango_layout_set_text (ctx->pangolayout, text, len);
    draw_get_layout_extents (ctx, w, h);
}
static PangoLayout *
create_layout (cairo_t *cr)
{
  PangoLayout *layout = pango_cairo_create_layout (cr);
  pango_layout_set_text (layout, text, -1);
  pango_layout_set_width (layout, WIDTH * PANGO_SCALE);
  return layout;
}