예제 #1
0
void pangox_layout_set_font_face(PangoLayout *layout, OutputFontFace face)
{
    if (layout != NULL) {
        const PangoFontDescription *old_font;
        PangoFontDescription *new_font;

        if ((old_font = pango_layout_get_font_description(layout)) == NULL) {
            PangoContext *context = pango_layout_get_context(layout);
            new_font = pango_font_description_copy(pango_context_get_font_description(context));
        }
        else {
            new_font = pango_font_description_copy(old_font);
        }
        switch (face) {
            case PS_FONT_SANS: {
                pango_font_description_set_family(new_font, "Sans");
                break;
            }
            case PS_FONT_SERIF: {
                pango_font_description_set_family(new_font, "Serif");
                break;
            }
            default: {
                pango_font_description_set_family(new_font, "Fixed");
                break;
            }
	}
        pango_layout_set_font_description(layout, new_font);
        pango_font_description_free(new_font);
    }
}
예제 #2
0
static int
ol_scroll_window_get_font_height (OlScrollWindow *scroll)
{
  ol_assert_ret (OL_IS_SCROLL_WINDOW (scroll), 0);
  OlScrollWindowPrivate *priv = OL_SCROLL_WINDOW_GET_PRIVATE (scroll);
  
  PangoContext *pango_context = gdk_pango_context_get ();
  PangoLayout *pango_layout = pango_layout_new (pango_context);
  PangoFontDescription *font_desc = pango_font_description_from_string (priv->font_name);
  pango_layout_set_font_description (pango_layout, font_desc);

  PangoFontMetrics *metrics = pango_context_get_metrics (pango_context,
                                                         pango_layout_get_font_description (pango_layout), /* font desc */
                                                         NULL); /* languague */
  int height = 0;
  int ascent, descent;
  ascent = pango_font_metrics_get_ascent (metrics);
  descent = pango_font_metrics_get_descent (metrics);
  pango_font_metrics_unref (metrics);
    
  height += PANGO_PIXELS (ascent + descent);
  pango_font_description_free (font_desc);
  g_object_unref (pango_layout);
  g_object_unref (pango_context);
  return height;
}
예제 #3
0
파일: gdkdrawing.c 프로젝트: bro1/deadbeef
int
draw_get_listview_rowheight (drawctx_t *ctx) {
    PangoFontDescription *font_desc = pango_font_description_copy (pango_layout_get_font_description (ctx->pangolayout));
    PangoFontMetrics *metrics = pango_context_get_metrics (ctx->pangoctx,
            font_desc,
            pango_context_get_language (ctx->pangoctx));
    int row_height = (pango_font_metrics_get_ascent (metrics) +
            pango_font_metrics_get_descent (metrics));
    pango_font_metrics_unref (metrics);
    pango_font_description_free (font_desc);
    return PANGO_PIXELS(row_height)+6;
}
예제 #4
0
파일: gdkdrawing.c 프로젝트: bro1/deadbeef
void
draw_init_font_style (drawctx_t *ctx, int bold, int italic, int type) {
    PangoFontDescription *desc_default = ctx->font_style->font_desc;
    if (desc_default != NULL) {
        pango_layout_set_font_description (ctx->pangolayout, desc_default);
    }
    PangoFontDescription *desc = pango_font_description_copy (pango_layout_get_font_description (ctx->pangolayout));
    if (bold) {
        pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD);
    }
    if (italic) {
        pango_font_description_set_style (desc, PANGO_STYLE_ITALIC);
    }
    pango_layout_set_font_description (ctx->pangolayout, desc);
    pango_font_description_free (desc);
}
예제 #5
0
static PangoAttrList *
create_shape_attr_list_for_layout (PangoLayout   *layout,
                                   IconShapeData *data)
{
        PangoAttrList *attrs;
        PangoFontMetrics *metrics;
        gint ascent, descent;
        PangoRectangle ink_rect, logical_rect;
        const gchar *p;
        const gchar *text;
        gint placeholder_len;

        /* Get font metrics and prepare fancy shape size */
        metrics = pango_context_get_metrics (pango_layout_get_context (layout),
                                             pango_layout_get_font_description (layout),
                                             NULL);
        ascent = pango_font_metrics_get_ascent (metrics);
        descent = pango_font_metrics_get_descent (metrics);
        pango_font_metrics_unref (metrics);

        logical_rect.x = 0;
        logical_rect.y = - ascent;
        logical_rect.width = ascent + descent;
        logical_rect.height = ascent + descent;

        ink_rect = logical_rect;

        attrs = pango_attr_list_new ();
        text = pango_layout_get_text (layout);
        placeholder_len = strlen (data->placeholder_str);
        for (p = text; (p = strstr (p, data->placeholder_str)); p += placeholder_len) {
                PangoAttribute *attr;

                attr = pango_attr_shape_new_with_data (&ink_rect,
                                                       &logical_rect,
                                                       GUINT_TO_POINTER (g_utf8_get_char (p)),
                                                       NULL, NULL);

                attr->start_index = p - text;
                attr->end_index = attr->start_index + placeholder_len;

                pango_attr_list_insert (attrs, attr);
        }

        return attrs;
}
예제 #6
0
static void
ol_osd_render_update_font_height (OlOsdRenderContext *context)
{
  PangoFontMetrics *metrics = pango_context_get_metrics (context->pango_context,
                                                         pango_layout_get_font_description (context->pango_layout), /* font desc */
                                                         NULL); /* languague */
  if (metrics == NULL)
  {
    ol_errorf ("Cannot get font metrics\n");
  }
  context->font_height = 0;
  int ascent, descent;
  ascent = pango_font_metrics_get_ascent (metrics);
  descent = pango_font_metrics_get_descent (metrics);
  pango_font_metrics_unref (metrics);
  context->font_height += PANGO_PIXELS (ascent + descent);
}
예제 #7
0
void pangox_layout_set_font_style(PangoLayout *layout, PangoStyle style)
{
    if (layout != NULL) {
        const PangoFontDescription *old_font;
        PangoFontDescription *new_font;

        if ((old_font = pango_layout_get_font_description(layout)) == NULL) {
            PangoContext *context = pango_layout_get_context(layout);
            new_font = pango_font_description_copy(pango_context_get_font_description(context));
        }
        else {
            new_font = pango_font_description_copy(old_font);
        }
        pango_font_description_set_style(new_font, style);
        pango_layout_set_font_description(layout, new_font);
        pango_font_description_free(new_font);
    }
}
예제 #8
0
void pangox_layout_set_font_size(PangoLayout *layout, int size)
{
    if (layout != NULL) {
        const PangoFontDescription *old_font;
        PangoFontDescription *new_font;

        if ((old_font = pango_layout_get_font_description(layout)) == NULL) {
            PangoContext *context = pango_layout_get_context(layout);
            new_font = pango_font_description_copy(pango_context_get_font_description(context));
        }
        else {
            new_font = pango_font_description_copy(old_font);
        }
        pango_font_description_set_size(new_font, size * PANGO_SCALE * 0.71);
        pango_layout_set_font_description(layout, new_font);
        pango_font_description_free(new_font);
    }
}
예제 #9
0
PangoAttrList *
create_fancy_attr_list_for_layout (PangoLayout *layout)
{
  PangoAttrList *attrs;
  PangoFontMetrics *metrics;
  int ascent;
  PangoRectangle ink_rect, logical_rect;
  const char *p;

  /* Get font metrics and prepare fancy shape size */
  metrics = pango_context_get_metrics (pango_layout_get_context (layout),
                                       pango_layout_get_font_description (layout),
                                       NULL);
  ascent = pango_font_metrics_get_ascent (metrics);
  logical_rect.x = 0;
  logical_rect.width = ascent;
  logical_rect.y = -ascent;
  logical_rect.height = ascent;
  ink_rect = logical_rect;
  pango_font_metrics_unref (metrics);

  /* Set fancy shape attributes for all hearts */
  attrs = pango_attr_list_new ();
  for (p = text; (p = strstr (p, HEART)); p += strlen (HEART))
    {
      PangoAttribute *attr;

      attr = pango_attr_shape_new_with_data (&ink_rect,
                                             &logical_rect,
                                             GUINT_TO_POINTER (g_utf8_get_char (p)),
                                             NULL, NULL);

      attr->start_index = p - text;
      attr->end_index = attr->start_index + strlen (HEART);

      pango_attr_list_insert (attrs, attr);
    }

  return attrs;
}
static int
get_pango_vertical_offset (PangoLayout *layout)
{
	const PangoFontDescription *desc;
	PangoContext               *context;
	PangoLanguage              *language;
	PangoFontMetrics           *metrics;
	int                         baseline;
	int                         strikethrough;
	int                         thickness;

	context = pango_layout_get_context (layout);
	language = pango_language_get_default ();
	desc = pango_layout_get_font_description (layout);
	metrics = pango_context_get_metrics (context, desc, language);

	baseline = pango_layout_get_baseline (layout);
	strikethrough =  pango_font_metrics_get_strikethrough_position (metrics);
	thickness =  pango_font_metrics_get_underline_thickness (metrics);

	return PANGO_PIXELS (baseline - strikethrough - thickness / 2);
}
예제 #11
0
static void rc_ui_scrollable_label_get_preferred_height(GtkWidget *widget,
        gint *min_height, gint *nat_height)
{
    RCUiScrollableLabelPrivate *priv;
    PangoFontMetrics *metrics;
    PangoContext *context;
    gint ascent, descent;
    gint height;
    if(widget==NULL) return;
    priv = RC_UI_SCROLLABLE_LABEL(widget)->priv;
    if(priv==NULL) return;
    context = pango_layout_get_context(priv->layout);
    if(context==NULL) return;
    metrics = pango_context_get_metrics(context,
                                        pango_layout_get_font_description(priv->layout), NULL);
    ascent = pango_font_metrics_get_ascent(metrics);
    descent = pango_font_metrics_get_descent(metrics);
    pango_font_metrics_unref(metrics);
    height = PANGO_PIXELS(ascent + descent);
    *min_height = height;
    *nat_height = height;
}
예제 #12
0
static VALUE
rg_font_description(VALUE self)
{
    const PangoFontDescription* desc = pango_layout_get_font_description(_SELF(self));
    return BOXED2RVAL((gpointer)desc, PANGO_TYPE_FONT_DESCRIPTION);
}
예제 #13
0
static void
marlin_text_renderer_set_widget (MarlinTextRenderer *text_renderer,
                                 GtkWidget          *widget)
{
    PangoFontMetrics *metrics;
    PangoContext *context;
    gint focus_padding;
    gint focus_line_width;
    const PangoFontDescription *font_desc;

    if (G_LIKELY (widget == text_renderer->widget))
        return;

    /* disconnect from the previously set widget */
    if (G_UNLIKELY (text_renderer->widget != NULL))
    {
        g_signal_handlers_disconnect_by_func (G_OBJECT (text_renderer->widget), marlin_text_renderer_invalidate, text_renderer);
        g_object_unref (G_OBJECT (text_renderer->layout));
        g_object_unref (G_OBJECT (text_renderer->widget));
    }

    /* activate the new widget */
    text_renderer->widget = widget;

    /* connect to the new widget */
    if (G_LIKELY (widget != NULL))
    {
        /* take a reference on the widget */
        g_object_ref (G_OBJECT (widget));

        /* we need to recalculate the metrics when a new style (and thereby a new font) is set */
        g_signal_connect_swapped (G_OBJECT (text_renderer->widget), "destroy", G_CALLBACK (marlin_text_renderer_invalidate), text_renderer);
        g_signal_connect_swapped (G_OBJECT (text_renderer->widget), "style-set", G_CALLBACK (marlin_text_renderer_invalidate), text_renderer);

        /* allocate a new pango layout for this widget */
        context = gtk_widget_get_pango_context (widget);
        text_renderer->layout = pango_layout_new (context);

        /* disable automatic text direction, but use the direction specified by Gtk+ */
        pango_layout_set_auto_dir (text_renderer->layout, FALSE);

        /* we don't want to interpret line separators in file names */
        pango_layout_set_single_paragraph_mode (text_renderer->layout, TRUE);

        font_desc = pango_layout_get_font_description (text_renderer->layout);

        /* calculate the average character dimensions */
        metrics = pango_context_get_metrics (context, font_desc, pango_context_get_language (context));

        text_renderer->char_width = PANGO_PIXELS (pango_font_metrics_get_approximate_char_width (metrics));
        text_renderer->char_height = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) + pango_font_metrics_get_descent (metrics));
        pango_font_metrics_unref (metrics);

        /* tell the cell renderer about the fixed height if we're not wrapping text */
        if (G_LIKELY (text_renderer->wrap_width < 0))
            gtk_cell_renderer_set_fixed_size (GTK_CELL_RENDERER (text_renderer), -1, text_renderer->char_height);

        /* determine the focus-padding and focus-line-width style properties from the widget */
        gtk_widget_style_get (widget, "focus-padding", &focus_padding, "focus-line-width", &focus_line_width, NULL);
        text_renderer->focus_width = focus_padding + focus_line_width;
    }
    else
    {
        text_renderer->layout = NULL;
        text_renderer->char_width = 0;
        text_renderer->char_height = 0;
    }
}
예제 #14
0
static VALUE
rg_font_description(VALUE self)
{
    const PangoFontDescription* desc = pango_layout_get_font_description(_SELF(self));
    return PANGOFONTDESCRIPTION2RVAL((gpointer)desc);
}
예제 #15
0
파일: tray.c 프로젝트: b4283/hime
gboolean create_tray(gpointer data)
{
  if (da)
    return FALSE;

  destroy_other_tray();

  egg_tray_icon = egg_tray_icon_new ("hime");

  if (!egg_tray_icon)
    return FALSE;

  GtkWidget *event_box = gtk_event_box_new ();
// Do not use this, otherwise tray menu fails
//  gtk_event_box_set_visible_window (event_box, FALSE);
  gtk_container_add (GTK_CONTAINER (egg_tray_icon), event_box);
#if GTK_CHECK_VERSION(2,12,0)
  gtk_widget_set_tooltip_text (event_box, _("左:中英切換 中:小鍵盤 右:選項"));
#else
  GtkTooltips *tips = gtk_tooltips_new ();
  gtk_tooltips_set_tip (GTK_TOOLTIPS (tips), event_box, _("左:中英切換 中:小鍵盤 右:選項"), NULL);
#endif

  g_signal_connect (G_OBJECT (event_box), "button-press-event",
                    G_CALLBACK (tray_button_press_event_cb), NULL);

  GError *err = NULL;
  if (pixbuf)
    g_object_unref(pixbuf);

  char icon_fname[128];
  get_icon_path(HIME_TRAY_PNG, icon_fname);
  pixbuf = gdk_pixbuf_new_from_file(icon_fname, &err);
  int pwidth = gdk_pixbuf_get_width (pixbuf);
  int pheight = gdk_pixbuf_get_height (pixbuf);

  da =  gtk_drawing_area_new();
  g_signal_connect (G_OBJECT (event_box), "destroy",
                    G_CALLBACK (gtk_widget_destroyed), &da);
#if !GTK_CHECK_VERSION(2,91,0)
  g_signal_connect(G_OBJECT(da), "expose-event", G_CALLBACK(cb_expose), NULL);
#else
  g_signal_connect(G_OBJECT(da), "draw", G_CALLBACK(cb_expose), NULL);
#endif

  gtk_container_add (GTK_CONTAINER (event_box), da);
  gtk_widget_set_size_request(GTK_WIDGET(egg_tray_icon), pwidth, pheight);

  gtk_widget_show_all (GTK_WIDGET (egg_tray_icon));
  tray_da_win = gtk_widget_get_window(da);
  // tray window is not ready ??
  if (!tray_da_win || !GTK_WIDGET_DRAWABLE(da)) {
    gtk_widget_destroy(GTK_WIDGET(egg_tray_icon));
    da = NULL;
    return FALSE;
  }

  PangoContext *context=gtk_widget_get_pango_context(da);
  PangoFontDescription* desc=pango_context_get_font_description(context);

//  dbg("zz %s %d\n",  pango_font_description_to_string(desc), PANGO_SCALE);

  pango = gtk_widget_create_pango_layout(da, NULL);
  pango_layout_set_font_description(pango, desc);
#if 1
  // strange bug, why do we need this ?
  desc = (PangoFontDescription *)pango_layout_get_font_description(pango);
#endif
  pango_font_description_set_size(desc, 9 * PANGO_SCALE);

#if 0
  dbg("aa %s\n",  pango_font_description_to_string(desc));
  dbg("context %x %x\n", pango_layout_get_context(pango), context);
  dbg("font %x %x\n",pango_layout_get_font_description(pango), desc);
#endif
#if !GTK_CHECK_VERSION(2,90,6)
  gc = gdk_gc_new (tray_da_win);
#endif
  return FALSE;
}