Пример #1
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);
}
Пример #2
0
void
rsvg_text_render_text (RsvgDrawingCtx * ctx, const char *text, gdouble * x, gdouble * y)
{
    PangoContext *context;
    PangoLayout *layout;
    PangoLayoutIter *iter;
    RsvgState *state;
    gint w, h, baseline;

    state = rsvg_current_state (ctx);

    /* Do not render the text if the font size is zero. See bug #581491. */
    if (state->font_size.length == 0)
        return;

    context = ctx->render->create_pango_context (ctx);
    layout = rsvg_text_create_layout (ctx, state, text, context);
    pango_layout_get_size (layout, &w, &h);
    iter = pango_layout_get_iter (layout);
    baseline = pango_layout_iter_get_baseline (iter) / (double)PANGO_SCALE;
    pango_layout_iter_free (iter);
    ctx->render->render_pango_layout (ctx, layout, *x, *y - baseline);
    *x += w / (double)PANGO_SCALE;
    g_object_unref (layout);
    g_object_unref (context);
}
Пример #3
0
static void get_text_dimensions(PangoLayout *layout, const gchar *text, gdouble *width, gdouble *height)
{
	gint layout_w, layout_h;

	pango_layout_set_text(layout, text, -1);
	pango_layout_get_size(layout, &layout_w, &layout_h);
	if (layout_w <= 0)
	{
		gint default_w = 50 * strlen(text) * PANGO_SCALE;

		geany_debug("Invalid layout_w (%d). Falling back to default width (%d)",
			layout_w, default_w);
		layout_w = default_w;
	}
	if (layout_h <= 0)
	{
		gint default_h = 100 * PANGO_SCALE;

		geany_debug("Invalid layout_h (%d). Falling back to default height (%d)",
			layout_h, default_h);
		layout_h = default_h;
	}

	if (width)
		*width = (gdouble)layout_w / PANGO_SCALE;
	if (height)
		*height = (gdouble)layout_h / PANGO_SCALE;
}
Пример #4
0
static void
draw_text (RsvgDrawingCtx * ctx, cairo_t *cr, double *x, double *y,
           const char *text)
{
    PangoContext *context;
    PangoLayout *layout;
    RsvgState *state;
    PangoLayoutLine *line;
    int w, h;

    state = rsvg_current_state (ctx);
    if (state->font_size.length == 0)
        return;

    context = ctx->render->create_pango_context (ctx);
    layout = rsvg_text_create_layout (ctx, state, text, context);
    pango_layout_get_size(layout, &w, &h);

    // From pango example
    // http://git.gnome.org/browse/pango/tree/examples/cairotwisted.c
    line = pango_layout_get_line_readonly (layout, 0);

    cairo_move_to (cr, *x, *y);
    pango_cairo_layout_line_path (cr, line);

    // Update x, y based on dimensions of text drawn
    if (PANGO_GRAVITY_IS_VERTICAL (state->text_gravity))
        *y += w / (double)PANGO_SCALE;
    else
        *x += w / (double)PANGO_SCALE;

    g_object_unref (layout);
    g_object_unref (context);
}
Пример #5
0
static void _draw_page_number (GtkPrintContext *context, gint page_nr, GwPageInfo *page, GwPrintData *data)
{
    //Declarations
    PangoLayout *layout;
    char *text;
    PangoFontDescription *desc;
    int width;
    int height;
    cairo_t *cr;
    gdouble drawable_width;

    //Initializations
    text = g_strdup_printf (gettext("Page %d/%d"), page_nr + 1, g_list_length (data->pages));
    layout = gtk_print_context_create_pango_layout (context);
    desc = pango_font_description_from_string ("sans 8");
    cr = gtk_print_context_get_cairo_context (context);
    drawable_width = gtk_print_context_get_width (context);

    //Draw
    if (text != NULL && layout != NULL && desc != NULL)
    {
      pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD);
      pango_layout_set_alignment (layout, PANGO_ALIGN_RIGHT);
      pango_layout_set_font_description (layout, desc);
      pango_layout_set_markup (layout, text, -1);
      pango_layout_get_size (layout, &width, &height);
      cairo_move_to (cr, (int) drawable_width - PANGO_PIXELS (width), 0);
      pango_cairo_show_layout (cr, layout);
    }

    //Cleanup
    if (text != NULL) g_free (text);
    if (layout != NULL) g_object_unref (layout);
    if (desc != NULL) pango_font_description_free (desc);
}
Пример #6
0
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);
}
Пример #7
0
static AboutRenderer *
make_text_item (AboutState *state, const char *text, int duration)
{
	AboutRenderer *r = g_new0 (AboutRenderer, 1);
	PangoAttrList *attrlist;
	PangoAttribute *attr;

	duration = (int)(duration / SPEED_FACTOR);

	r->start_time = state->now;
	r->duration = duration;
	r->layout = gtk_widget_create_pango_layout (state->anim_area, NULL);
	r->renderer = text_item_renderer;
	r->fade_in = r->fade_out = TRUE;
	set_text_motion (r, 0.5, 0.5, 0.5, 0.5);

	pango_layout_set_text (r->layout, text, -1);
	pango_layout_get_size (r->layout, &r->natural_width, NULL);

	attrlist = pango_attr_list_new ();
	attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
	pango_attr_list_change (attrlist, attr);
	pango_layout_set_attributes (r->layout, attrlist);
	pango_attr_list_unref (attrlist);

	state->now += duration;

	return r;
}
Пример #8
0
static void
hippo_canvas_text_get_content_height_request(HippoCanvasBox  *box,
                                             int              for_width,
                                             int             *min_height_p,
                                             int             *natural_height_p)
{
    HippoCanvasText *text = HIPPO_CANVAS_TEXT(box);
    int children_min_height, children_natural_height;
    PangoLayout *layout;
    int layout_height;

    HIPPO_CANVAS_BOX_CLASS(hippo_canvas_text_parent_class)->get_content_height_request(box,
                                                                                       for_width,
                                                                                       &children_min_height,
                                                                                       &children_natural_height);

    if (for_width > 0) {
        if (box->context != NULL) {
            layout = create_layout(text, for_width);
            pango_layout_get_size(layout, NULL, &layout_height);
            
            layout_height /= PANGO_SCALE;
            g_object_unref(layout);
        } else {
            layout_height = 0;
        }
    } else {
        layout_height = 0;
    }
    
    if (min_height_p)
        *min_height_p = MAX(layout_height, children_min_height);
    if (natural_height_p)
        *natural_height_p = MAX(layout_height, children_natural_height);
}
Пример #9
0
static VALUE
rg_size(VALUE self)
{
    int width, height;
    pango_layout_get_size(_SELF(self), &width, &height);
    return rb_ary_new3(2, INT2NUM(width), INT2NUM(height));
}
Пример #10
0
static void _draw_page_title (GtkPrintContext *context, GwPageInfo *page, GwPrintData *data) {
    //Declarations
    PangoLayout *layout;
    char *text;
    PangoFontDescription *desc;
    int width;
    int height;
    gint index;
    cairo_t *cr;
    LwSearch *search;

    //Initializations
    index = gw_searchwindow_get_current_tab_index (data->window);
    search = gw_searchwindow_get_searchitem_by_index (data->window, index);
    text = gw_searchwindow_get_title_by_searchitem (data->window, search);
    layout = gtk_print_context_create_pango_layout (context);
    desc = pango_font_description_from_string ("sans 8");
    cr = gtk_print_context_get_cairo_context (context);

    //Draw
    if (text != NULL && layout != NULL && desc != NULL)
    {
      cairo_move_to (cr, 0, 0);
      pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD);
      pango_layout_set_font_description (layout, desc);
      pango_layout_set_markup (layout, text, -1);
      pango_layout_get_size (layout, &width, &height);
      pango_cairo_show_layout (cr, layout);
    }

    //Cleanup
    if (text != NULL) g_free (text);
    if (layout != NULL) g_object_unref (layout);
    if (desc != NULL) pango_font_description_free (desc);
}
Пример #11
0
static void
hippo_canvas_text_get_content_width_request(HippoCanvasBox *box,
                                            int            *min_width_p,
                                            int            *natural_width_p)
{
    HippoCanvasText *text = HIPPO_CANVAS_TEXT(box);
    int children_min_width, children_natural_width;
    int layout_width;
    
    HIPPO_CANVAS_BOX_CLASS(hippo_canvas_text_parent_class)->get_content_width_request(box,
                                                                                      &children_min_width,
                                                                                      &children_natural_width);
    if (box->context != NULL) {
        PangoLayout *layout = create_layout(text, -1);
        pango_layout_get_size(layout, &layout_width, NULL);
        layout_width /= PANGO_SCALE;
        g_object_unref(layout);
    } else {
        layout_width = 0;
    }

    if (min_width_p) {
        if (text->size_mode == HIPPO_CANVAS_SIZE_FULL_WIDTH)
            *min_width_p = MAX(children_min_width, layout_width);
        else
            *min_width_p = children_min_width;
    }

    if (natural_width_p) {
        *natural_width_p = MAX(children_natural_width, layout_width);
    }
}
Пример #12
0
double pangox_layout_get_string_width(PangoLayout *layout, char *text)
{
    int w, h;

    pango_layout_set_text(layout, text, strlen(text));
    pango_layout_get_size(layout, &w, &h);
    return(w / (double) PANGO_SCALE);
}
Пример #13
0
/* return the height of the passed string in Pango units */
gint
p_string_height_from_layout(PangoLayout * layout, const gchar * text)
{
    gint height;

    pango_layout_set_text(layout, text, -1);
    pango_layout_get_size(layout, NULL, &height);
    return height;
}
Пример #14
0
/* return the width of the passed string in Pango units */
gint
p_string_width_from_layout(PangoLayout * layout, const gchar * text)
{
    gint width;

    pango_layout_set_text(layout, text, -1);
    pango_layout_get_size(layout, &width, NULL);
    return width;
}
Пример #15
0
static void getlsize(PangoLayout *layout, double *pw, double *ph) {
  // calculate width and height of layout
  int w_, h_;
  pango_layout_get_size(layout, &w_, &h_);
  if (pw)
    *pw = ((double)w_)/PANGO_SCALE;
  if (ph)
    *ph = ((double)h_)/PANGO_SCALE;
}
Пример #16
0
static gdouble
rsvg_text_layout_width (RsvgTextLayout * layout)
{
    gint width;

    pango_layout_get_size (layout->layout, &width, NULL);

    return width / (double)PANGO_SCALE;
}
Пример #17
0
static void
e_contact_print_letter_heading (EContactPrintContext *ctxt,
                                gchar *letter)
{
	PangoLayout *layout;
	PangoFontDescription *desc;
	PangoFontMetrics *metrics;
	gint width, height;
	cairo_t *cr;

	desc = ctxt->letter_heading_font;

	layout = gtk_print_context_create_pango_layout (ctxt->context);

	/* Make the rectangle thrice the average character width.
	 * XXX Works well for English, what about other locales? */
	metrics = pango_context_get_metrics (
		pango_layout_get_context (layout),
		desc, pango_language_get_default ());
	width = pango_font_metrics_get_approximate_char_width (metrics) * 3;
	pango_font_metrics_unref (metrics);

	pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
	pango_layout_set_font_description (layout, desc);
	pango_layout_set_text (layout, letter, -1);
	pango_layout_set_width (layout, width);
	pango_layout_get_size (layout, NULL, &height);

	if (ctxt->page_nr == -1 || ctxt->pages != ctxt->page_nr) {
		/* only calculating number of pages
		 * or on page we do not want to print */
		ctxt->y += pango_units_to_double (height);

		return;
	}

	/* Draw white text centered in a black rectangle. */
	cr = gtk_print_context_get_cairo_context (ctxt->context);

	cairo_save (cr);
	cairo_set_source_rgb (cr, .0, .0, .0);
	cairo_rectangle (
		cr, ctxt->x, ctxt->y,
		pango_units_to_double (width),
		pango_units_to_double (height));
	cairo_fill (cr);
	cairo_restore (cr);

	cairo_save (cr);
	cairo_move_to (cr, ctxt->x, ctxt->y);
	cairo_set_source_rgb (cr, 1., 1., 1.);
	pango_cairo_show_layout (cr, layout);
	cairo_restore (cr);

	ctxt->y += pango_units_to_double (height);
}
Пример #18
0
void
setup_text (struct font *font, char *str, double *dxp, double *dyp)
{
	int pango_width, pango_height;
	set_font (font);
	pango_layout_set_markup (layout, str, strlen (str));
	pango_layout_get_size (layout, &pango_width, &pango_height);
	*dxp = (double)pango_width / PANGO_SCALE;
	*dyp = (double)pango_height / PANGO_SCALE;
}
Пример #19
0
gboolean mw_tooltip_timeout(GtkWidget *tv)
{
	GtkAllocation allocation;
	int scr_w,scr_h, w, h, x, y;
	char *tooltiptext = NULL;

	tooltiptext = get_tooltip_text();

	tipwindow = gtk_window_new(GTK_WINDOW_POPUP);
	gtk_widget_set_parent(tipwindow, tv);
	gtk_widget_set_app_paintable(tipwindow, TRUE);
	gtk_window_set_resizable(GTK_WINDOW(tipwindow), FALSE);
	gtk_widget_set_name(tipwindow, "gtk-tooltips");
	g_signal_connect(G_OBJECT(tipwindow), "expose_event",
			G_CALLBACK(mw_paint_tip), NULL);
	gtk_widget_ensure_style (tipwindow);

	layout = gtk_widget_create_pango_layout (tipwindow, NULL);
	pango_layout_set_wrap(layout, PANGO_WRAP_WORD);
	pango_layout_set_width(layout, 300000);
	pango_layout_set_markup(layout, tooltiptext, strlen(tooltiptext));
	scr_w = gdk_screen_width();
	scr_h = gdk_screen_height();
	pango_layout_get_size (layout, &w, &h);
	w = PANGO_PIXELS(w) + 8;
	h = PANGO_PIXELS(h) + 8;

	gdk_window_get_pointer(NULL, &x, &y, NULL);
	if (!gtk_widget_get_has_window (mw.vbox))
	{
		gtk_widget_get_allocation (mw.vbox, &allocation);
		y += allocation.y;
	}

	x -= ((w >> 1) + 4);

	if ((x + w) > scr_w)
		x -= (x + w) - scr_w;
	else if (x < 0)
		x = 0;

	if ((y + h + 4) > scr_h)
		y = y - h;
	else
		y = y + 6;
	/*
	   g_object_unref(layout);
	   */
	g_free(tooltiptext);
	gtk_widget_set_size_request(tipwindow, w, h);
	gtk_window_move(GTK_WINDOW(tipwindow), x, y);
	gtk_widget_show(tipwindow);

	return FALSE;
}
Пример #20
0
Файл: te.c Проект: ITikhonov/tem
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;
}
Пример #21
0
static float getWidth(PangoLayout *layout, const TextRun& run, int from, int to)
{
    int layoutWidth;

    gchar* utf8 = convertUniCharToUTF8(run.characters(), run.length(), from, to);
    pango_layout_set_text(layout, utf8, -1);
    g_free(utf8);
    pango_layout_get_size(layout, &layoutWidth, 0);
    float width = (float)layoutWidth / (double)PANGO_SCALE;

    return width;
}
Пример #22
0
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);
}
Пример #23
0
static void _draw_page_results (GtkPrintContext *context, GwPageInfo *page, GwPrintData *data)
{
    //Declarations
    GtkTextView *view;
    GtkTextBuffer *buffer;
    PangoLayout *layout;
    char *text;
    PangoFontDescription *desc;
    int width;
    int height;
    gdouble drawable_width, drawable_height;
    cairo_t *cr;
    gint line_start;
    gint line_end;

    //Initializations
    view = gw_searchwindow_get_current_textview (data->window);
    buffer = gtk_text_view_get_buffer (view);
    text = gtk_text_buffer_get_text (buffer, &(page->start), &(page->end), FALSE);
    layout = gtk_print_context_create_pango_layout (context);
    desc = pango_font_description_from_string ("sans 10");
    drawable_width = gtk_print_context_get_width (context);
    drawable_height = gtk_print_context_get_height (context);
    cr = gtk_print_context_get_cairo_context (context);
    line_start = 0;
    line_end = 0;

    //Draw
    if (text != NULL)
    {
      cairo_move_to (cr, 5, 10);
      pango_layout_set_font_description (layout, desc);
      pango_layout_set_markup (layout, text, -1);
      pango_layout_set_width (layout, drawable_width * PANGO_SCALE);
      pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
      pango_layout_set_height (layout, drawable_height * PANGO_SCALE);
      pango_layout_get_size (layout, &width, &height);
      pango_cairo_show_layout (cr, layout);
      
      //Adjust the end GtkTextIter to the cutoff in the visible cairo context
      line_start = gtk_text_iter_get_line (&page->start);
      line_end = line_start + pango_layout_get_line_count (layout) - 1;
      gtk_text_buffer_get_iter_at_line (buffer, &(page->end), line_end);
    }

    //Cleanup
    if (text != NULL) g_free (text);
    if (layout != NULL) g_object_unref (layout);
    if (desc != NULL) pango_font_description_free (desc);
}
Пример #24
0
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);
}
Пример #25
0
void TextView::calcSize(Text* t, double& width, double& height)
{
	cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1);
	cairo_t* cr = cairo_create(surface);

	PangoLayout* layout = initPango(cr, t);
	string str = t->getText();
	pango_layout_set_text(layout, str.c_str(), str.length());
	int w = 0;
	int h = 0;
	pango_layout_get_size(layout, &w, &h);
	width = ((double) w) / PANGO_SCALE;
	height = ((double) h) / PANGO_SCALE;
	g_object_unref(layout);

	cairo_surface_destroy(surface);
	cairo_destroy(cr);
}
Пример #26
0
 static int doPrint(GtkPrintOperation *prt, GtkPrintContext *context,cairo_t *cr,gint page)
 {
	gdouble					maxHeight	= gtk_print_context_get_height(context);
	PangoFontDescription	*desc;
	gint					pg			= 0;
	gdouble					row			= 0;

	gchar					**text;
	gdouble					text_height;


	desc = pango_font_description_from_string(g_object_get_data(G_OBJECT(prt),"3270FontName"));

	for(text = g_object_get_data(G_OBJECT(prt),"3270Text");*text;text++)
	{
		gint		layout_height;
		PangoLayout	*layout			= gtk_print_context_create_pango_layout(context);

		pango_layout_set_font_description(layout, desc);
		pango_layout_set_text(layout, *text, -1);
		pango_layout_get_size(layout, NULL, &layout_height);
		text_height = ((gdouble)layout_height) / PANGO_SCALE;

		if((row+text_height) >= maxHeight)
		{
			row = 0;
			pg++;
		}

		row += text_height;

		if(cr && page == pg)
		{
			cairo_move_to(cr,0,row);
			pango_cairo_show_layout(cr, layout);
		}

		g_object_unref(layout);
	}

	pango_font_description_free(desc);

	return pg+1;
 }
Пример #27
0
float Font::floatWidthForComplexText(const TextRun& run, const TextStyle& style) const
{
    if (run.length() == 0)
        return 0.0f;

    PangoLayout* layout = getDefaultPangoLayout(run);
    setPangoAttributes(this, run, layout, style.rtl());

    gchar* utf8 = convertUniCharToUTF8(run.characters(), run.length(), 0, run.length());
    pango_layout_set_text(layout, utf8, -1);
    g_free(utf8);

    int layoutWidth;
    pango_layout_get_size(layout, &layoutWidth, 0);
    float width = (float)layoutWidth / (double)PANGO_SCALE;
    g_object_unref(layout);

    return width;
}
Пример #28
0
static gdouble
e_contact_text_height (GtkPrintContext *context,
                       PangoFontDescription *desc,
                       const gchar *text)
{
	PangoLayout *layout;
	gint width, height;

	layout = gtk_print_context_create_pango_layout (context);

	pango_layout_set_font_description (layout, desc);
	pango_layout_set_text (layout, text, -1);

	pango_layout_get_size (layout, &width, &height);

	g_object_unref (layout);

	return pango_units_to_double (height);
}
Пример #29
0
static void cb_draw_page(GtkPrintOperation *op,
		GtkPrintContext *ctx, gint page_nr, gpointer data)
{
	cairo_t *cr;
	PangoLayoutLine *line;
	gint n_line, i, j = 0;
	
	PangoLayout *layout_lh, *layout_rh;
	gchar *page_text;
	gint layout_width;
	
	cr = gtk_print_context_get_cairo_context(ctx);
	
	layout_lh = gtk_print_context_create_pango_layout(ctx);
	pango_layout_set_font_description(layout_lh, font_desc);
	pango_layout_set_text(layout_lh, page_title, -1);
	cairo_move_to(cr, 0, - 72 / 25.4 * 10);
	pango_cairo_show_layout(cr, layout_lh);
	
	page_text = g_strdup_printf("%d / %d", page_nr + 1, n_pages);
	layout_rh = gtk_print_context_create_pango_layout(ctx);
	pango_layout_set_font_description(layout_rh, font_desc);
	pango_layout_set_text(layout_rh, page_text, -1);
//	pango_layout_set_alignment(layout_rh, PANGO_ALIGN_RIGHT);
	pango_layout_get_size(layout_rh, &layout_width, NULL);
	cairo_move_to(cr,
		page_width - layout_width / PANGO_SCALE, - 72 / 25.4 * 10);
	pango_cairo_show_layout(cr, layout_rh);
	g_free(page_text);
	
	if (line_count > lines_per_page * (page_nr + 1))
		n_line = lines_per_page * (page_nr + 1);
	else
		n_line = line_count;
	
	for (i = lines_per_page * page_nr; i < n_line; i++) {
		line = pango_layout_get_line(layout, i);
		cairo_move_to(cr, 0, text_height * (j + 1));
		pango_cairo_show_layout_line(cr, line);
		j++;
	}	
}
Пример #30
0
GdkPixbuf *text_to_gtk_pixbuf (gchar *text) 
{	
	GtkWidget *scratch = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_widget_realize (scratch); 
	//GtkStyle *style = gtk_widget_get_style(scratch);
	//gchar *bgcolor = gdk_color_to_string(&style->bg[GTK_STATE_NORMAL]);
	//gchar *textcolor = gdk_color_to_string(&style->text[GTK_STATE_NORMAL]);
	PangoLayout *layout = gtk_widget_create_pango_layout (scratch, NULL); 
	//g_object_unref(style);
	gtk_widget_destroy (scratch);

	//gchar *markup = g_strdup_printf ("<span bgcolor='%s' color='%s'>%s</span>", bgcolor, textcolor, text); 
	//gchar *markup = g_strdup_printf ("<span color='%s'>%s</span>", textcolor, text); 
	gchar *markup = g_strdup_printf ("%s", text);
	pango_layout_set_markup (layout, markup, -1); 
	g_free (markup);
	//g_free (bgcolor);
	//g_free (textcolor);

	int width = 0;
	int heigth = 0;
	pango_layout_get_size (layout, &width, &heigth);
	width = width/PANGO_SCALE;
	heigth = heigth/PANGO_SCALE;

	GdkPixbuf *pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, width, heigth);
	gdk_pixbuf_fill(pb, 0xffffffff);
	
	GdkPixmap *pm = gdk_pixmap_new (NULL, width, heigth, 24);
	GdkGC *gc = gdk_gc_new (pm); 
	gdk_draw_pixbuf (pm, gc, pb, 0, 0, 0, 0, width, heigth, GDK_RGB_DITHER_NONE, 0, 0);
	
	gdk_draw_layout (pm, gc, 0, 0, layout);


	g_object_unref(layout);
	g_object_unref(gc);

	GdkPixbuf *ret = gdk_pixbuf_get_from_drawable (NULL, pm, NULL, 0, 0, 0, 0, width, heigth);
	g_object_unref(pb);
	return ret;
}