static void
update_fonts (UmEditableButton *button)
{
        PangoAttrList *attrs;
        PangoAttribute *attr;
        GtkWidget *label;

        UmEditableButtonPrivate *priv = button->priv;

        attrs = pango_attr_list_new ();
        if (priv->scale_set) {
                attr = pango_attr_scale_new (priv->scale);
                pango_attr_list_insert (attrs, attr);
        }
        if (priv->weight_set) {
                attr = pango_attr_weight_new (priv->weight);
                pango_attr_list_insert (attrs, attr);
        }

        gtk_label_set_attributes (priv->label, attrs);

        label = gtk_bin_get_child (GTK_BIN (priv->button));
        gtk_label_set_attributes (GTK_LABEL (label), attrs);

        pango_attr_list_unref (attrs);
}
Beispiel #2
0
static void
on_regex_error_changed (IdeEditorFrame         *self,
                        GParamSpec             *pspec,
                        GtkSourceSearchContext *search_context)
{
  g_autoptr(GError) error = NULL;
  PangoAttrList *attrs;

  g_assert (IDE_IS_EDITOR_FRAME (self));
  g_assert (GTK_SOURCE_IS_SEARCH_CONTEXT (search_context));

  /*
   * If the regular expression is invalid, add a white squiggly underline;
   * otherwise remove it.
   */
  attrs = pango_attr_list_new ();
  error = gtk_source_search_context_get_regex_error (search_context);

  if (error != NULL)
    {
      pango_attr_list_insert (attrs, pango_attr_underline_new (PANGO_UNDERLINE_ERROR));
      pango_attr_list_insert (attrs, pango_attr_underline_color_new (65535, 65535, 65535));
    }

  gtk_entry_set_attributes (GTK_ENTRY (self->search_entry), attrs);
  pango_attr_list_unref (attrs);

  update_replace_actions_sensitivity (self);
}
Beispiel #3
0
static void
check_replace_text (IdeEditorFrame *self)
{
  GtkSourceSearchContext *search_context;
  GtkSourceSearchSettings *search_settings;
  g_autoptr(GError) error = NULL;
  PangoAttrList *attrs;

  g_assert (IDE_IS_EDITOR_FRAME (self));

  search_context = ide_source_view_get_search_context (self->source_view);
  search_settings = gtk_source_search_context_get_settings (search_context);

  attrs = pango_attr_list_new ();

  /*
   * If the replace expression is invalid, add a white squiggly underline;
   * otherwise remove it.
   */
  if (gtk_source_search_settings_get_regex_enabled (search_settings))
    {
      const gchar *replace_text;

      replace_text = gtk_entry_get_text (GTK_ENTRY (self->replace_entry));

      if (!g_regex_check_replacement (replace_text, NULL, &error))
        {
          pango_attr_list_insert (attrs, pango_attr_underline_new (PANGO_UNDERLINE_ERROR));
          pango_attr_list_insert (attrs, pango_attr_underline_color_new (65535, 65535, 65535));
        }
    }

  gtk_entry_set_attributes (GTK_ENTRY (self->replace_entry), attrs);
  pango_attr_list_unref (attrs);
}
Beispiel #4
0
static GtkWidget *app_window_common(void)
{
	GtkWidget *window;
	PangoAttrList *attr;

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_container_set_border_width(GTK_CONTAINER(window), 10);
	gtk_window_set_title(GTK_WINDOW(window), WINDOW_TITLE);

	g_signal_connect(window, "delete-event", G_CALLBACK(delete_event),
			 NULL);

	tokencode_text = gtk_label_new(NULL);
	attr = pango_attr_list_new();
	pango_attr_list_insert(attr, pango_attr_scale_new(PANGO_SCALE_XX_LARGE));
	pango_attr_list_insert(attr, pango_attr_weight_new(PANGO_WEIGHT_BOLD));
	gtk_label_set_attributes(GTK_LABEL(tokencode_text), attr);
	pango_attr_list_unref(attr);

	/* hack to turn off progress bar animation seen on some themes */
	gtk_rc_parse_string("style \"default\" { engine \"\" { }\n"
		"bg[PRELIGHT] = \"#4b6785\" }\n"
		"widget_class \"*.<GtkProgressBar>\" style \"default\"");

	return window;
}
Beispiel #5
0
static void create_cursor_attr()
{
    if (attr_list)
        pango_attr_list_unref(attr_list);

    GdkColor color_bg, color_fg;
    if (hime_win_color_use)
        gdk_color_parse(tsin_cursor_color, &color_bg);
    else
        gdk_color_parse(TSIN_CURSOR_COLOR_DEFAULT, &color_bg);
    gdk_color_parse("white", &color_fg);

    attr_list = pango_attr_list_new ();
    attr_list_blank = pango_attr_list_new ();

    PangoAttribute *blue_bg = pango_attr_background_new(
                                  color_bg.red, color_bg.green, color_bg.blue);
    blue_bg->start_index = 0;
    blue_bg->end_index = 128;
    pango_attr_list_insert (attr_list, blue_bg);

    PangoAttribute *white_fg = pango_attr_foreground_new(
                                   color_fg.red, color_fg.green, color_fg.blue);
    white_fg->start_index = 0;
    white_fg->end_index = 128;
    pango_attr_list_insert (attr_list, white_fg);
}
Beispiel #6
0
void iupgtkFontUpdatePangoLayout(Ihandle* ih, PangoLayout* layout)
{
  IgtkFont* gtkfont;
  PangoAttrList *attrs;

  if (!layout)
    return;

  gtkfont = gtkFontGet(ih);
  if (!gtkfont)
    return;

  attrs = pango_layout_get_attributes(layout);
  if (!attrs) 
  {
    attrs = pango_attr_list_new();
    pango_attr_list_insert(attrs, pango_attribute_copy(gtkfont->strikethrough));
    pango_attr_list_insert(attrs, pango_attribute_copy(gtkfont->underline));
    pango_layout_set_attributes(layout, attrs);
  }
  else
  {
    pango_attr_list_change(attrs, pango_attribute_copy(gtkfont->strikethrough));
    pango_attr_list_change(attrs, pango_attribute_copy(gtkfont->underline));
  }
}
Beispiel #7
0
static gboolean
cb_unset2 (PangoAttribute *attr, gpointer _data)
{
	struct cb_unset *data = _data;

	/* All inside cleared area.  */
	if (attr->start_index >= data->start_index &&
	    attr->end_index <= data->end_index)
		return FALSE;

	attr = pango_attribute_copy (attr);

	if (attr->end_index > data->start_index && attr->end_index <= data->end_index)
		/* Ends inside cleared area.  */
		attr->end_index = data->start_index;
	else if (attr->start_index >= data->start_index && attr->start_index < data->end_index)
		/* Starts inside cleared area.  */
		attr->start_index = data->end_index;
	else if (attr->start_index < data->start_index && attr->end_index > data->end_index) {
		/* Starts before, ends after.  */
		PangoAttribute *attr2 = pango_attribute_copy (attr);
		attr2->start_index = data->end_index;
		pango_attr_list_insert (data->list, attr2);
		attr->end_index = data->start_index;
	}

	pango_attr_list_insert (data->list, attr);

	return FALSE;
}
Beispiel #8
0
static gboolean
cb_splice (PangoAttribute *attr, gpointer _data)
{
	struct cb_splice *data = _data;

	if (attr->start_index >= data->pos) {
		PangoAttribute *new_attr = pango_attribute_copy (attr);
		new_attr->start_index += data->len;
		new_attr->end_index += data->len;
		pango_attr_list_insert (data->result, new_attr);
	} else if (attr->end_index <= data->pos) {
		PangoAttribute *new_attr = pango_attribute_copy (attr);
		pango_attr_list_insert (data->result, new_attr);
	} else {
		PangoAttribute *new_attr = pango_attribute_copy (attr);
		new_attr->end_index = data->pos;
		pango_attr_list_insert (data->result, new_attr);

		new_attr = pango_attribute_copy (attr);
		new_attr->start_index = data->pos + data->len;
		new_attr->end_index += data->len;
		pango_attr_list_insert (data->result, new_attr);
	}

	return FALSE;
}
Beispiel #9
0
static void
gnm_notebook_button_ensure_layout (GnmNotebookButton *nbb)
{
	const char *text = gtk_label_get_text (GTK_LABEL (nbb));

	if (nbb->layout) {
		if (strcmp (text, pango_layout_get_text (nbb->layout)) == 0)
			return;
		pango_layout_set_text (nbb->layout, text, -1);
		pango_layout_set_text (nbb->layout_active, text, -1);
	} else {
		PangoAttrList *attrs, *attrs_active;
		PangoAttribute *attr;
		PangoFontDescription *desc;
		GtkWidget *widget = GTK_WIDGET (nbb);
		GtkStyleContext *context =
			gtk_widget_get_style_context (widget);

		nbb->layout = gtk_widget_create_pango_layout (widget, text);
		nbb->layout_active = gtk_widget_create_pango_layout (widget, text);

		/* Common */
		attrs = pango_attr_list_new ();
		if (nbb->bg) {
			attr = go_color_to_pango
				(go_color_from_gdk_rgba (nbb->bg, NULL),
				 FALSE);
			attr->start_index = 0;
			attr->end_index = -1;
			pango_attr_list_insert (attrs, attr);
		}
		attrs_active = pango_attr_list_copy (attrs);

		/* Normal */
		gtk_style_context_get (context, GTK_STATE_FLAG_NORMAL,
				       "font", &desc, NULL);
		attr = pango_attr_font_desc_new (desc);
		attr->start_index = 0;
		attr->end_index = -1;
		pango_attr_list_insert (attrs, attr);
		pango_font_description_free (desc);
		pango_layout_set_attributes (nbb->layout, attrs);
		pango_attr_list_unref (attrs);

		/* Active */
		gtk_style_context_get (context, GTK_STATE_FLAG_ACTIVE,
				       "font", &desc, NULL);
		attr = pango_attr_font_desc_new (desc);
		attr->start_index = 0;
		attr->end_index = -1;
		pango_attr_list_insert (attrs_active, attr);
		pango_font_description_free (desc);
		pango_layout_set_attributes (nbb->layout_active, attrs_active);
		pango_attr_list_unref (attrs_active);
	}

	pango_layout_get_extents (nbb->layout, NULL, &nbb->logical);
	pango_layout_get_extents (nbb->layout_active, NULL, &nbb->logical_active);
}
Beispiel #10
0
bool wxStaticText::SetFont( const wxFont &font )
{
    const bool wasUnderlined = GetFont().GetUnderlined();
    const bool wasStrickenThrough = GetFont().GetStrikethrough();

    bool ret = wxControl::SetFont(font);

    const bool isUnderlined = GetFont().GetUnderlined();
    const bool isStrickenThrough = GetFont().GetStrikethrough();

    if ( (isUnderlined != wasUnderlined) ||
            (isStrickenThrough != wasStrickenThrough) )
    {
        // We need to update the Pango attributes used for the text.
        if ( isUnderlined || isStrickenThrough )
        {
            PangoAttrList* const attrs = pango_attr_list_new();
            if ( isUnderlined )
            {
                PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
                a->start_index = 0;
                a->end_index = (guint)-1;
                pango_attr_list_insert(attrs, a);
            }

            if ( isStrickenThrough )
            {
                PangoAttribute *a = pango_attr_strikethrough_new( TRUE );
                a->start_index = 0;
                a->end_index = (guint) -1;
                pango_attr_list_insert(attrs, a);
            }

            gtk_label_set_attributes(GTK_LABEL(m_widget), attrs);
            pango_attr_list_unref(attrs);
        }
        else // No special attributes any more.
        {
            // Just remove any attributes we had set.
            gtk_label_set_attributes(GTK_LABEL(m_widget), NULL);
        }

        // The underlines for mnemonics are incompatible with using attributes
        // so turn them off when setting underlined font.
        gtk_label_set_use_underline(GTK_LABEL(m_widget), !isUnderlined);
    }

    // adjust the label size to the new label unless disabled
    if (!HasFlag(wxST_NO_AUTORESIZE))
    {
        SetSize( GetBestSize() );
    }
    return ret;
}
Beispiel #11
0
/**
 * _st_set_text_from_style:
 * @text: Target #ClutterText
 * @theme_node: Source #StThemeNode
 *
 * Set various GObject properties of the @text object using
 * CSS information from @theme_node.
 */
void
_st_set_text_from_style (ClutterText *text,
                         StThemeNode *theme_node)
{

    ClutterColor color;
    StTextDecoration decoration;
    PangoAttrList *attribs = NULL;
    const PangoFontDescription *font;
    StTextAlign align;

    st_theme_node_get_foreground_color (theme_node, &color);
    clutter_text_set_color (text, &color);

    font = st_theme_node_get_font (theme_node);
    clutter_text_set_font_description (text, (PangoFontDescription *) font);

    decoration = st_theme_node_get_text_decoration (theme_node);
    if (decoration)
    {
        attribs = pango_attr_list_new ();

        if (decoration & ST_TEXT_DECORATION_UNDERLINE)
        {
            PangoAttribute *underline = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
            pango_attr_list_insert (attribs, underline);
        }
        if (decoration & ST_TEXT_DECORATION_LINE_THROUGH)
        {
            PangoAttribute *strikethrough = pango_attr_strikethrough_new (TRUE);
            pango_attr_list_insert (attribs, strikethrough);
        }
        /* Pango doesn't have an equivalent attribute for _OVERLINE, and we deliberately
         * skip BLINK (for now...)
         */
    }

    clutter_text_set_attributes (text, attribs);

    if (attribs)
        pango_attr_list_unref (attribs);

    align = st_theme_node_get_text_align (theme_node);
    if (align == ST_TEXT_ALIGN_JUSTIFY)
    {
        clutter_text_set_justify (text, TRUE);
        clutter_text_set_line_alignment (text, PANGO_ALIGN_LEFT);
    }
    else
    {
        clutter_text_set_justify (text, FALSE);
        clutter_text_set_line_alignment (text, (PangoAlignment) align);
    }
}
Beispiel #12
0
static int cdfont(cdCtxCanvas *ctxcanvas, const char *typeface, int style, int size)
{
  int is_italic = 0, is_bold = 0;   /* default is CD_PLAIN */
  int is_strikeout = 0, is_underline = 0;
  char font[256];
  PangoAttrList *attrs;

  if (cdStrEqualNoCase(typeface, "Courier") || cdStrEqualNoCase(typeface, "Courier New"))
    typeface = "Monospace";
  else if (cdStrEqualNoCase(typeface, "Times") || cdStrEqualNoCase(typeface, "Times New Roman"))
    typeface = "Serif";
  else if (cdStrEqualNoCase(typeface, "Helvetica") || cdStrEqualNoCase(typeface, "Arial"))
    typeface = "Sans";

  if (style & CD_BOLD)
    is_bold = 1;

  if (style & CD_ITALIC)
    is_italic = 1;

  if (style & CD_UNDERLINE)
    is_underline = 1;

  if (style & CD_STRIKEOUT)
    is_strikeout = 1;

  size = cdGetFontSizePoints(ctxcanvas->canvas, size);

  sprintf(font, "%s, %s%s%d", typeface, is_bold?"Bold ":"", is_italic?"Italic ":"", size);

  if (ctxcanvas->fontdesc) 
    pango_font_description_free(ctxcanvas->fontdesc);

  ctxcanvas->fontdesc = pango_font_description_from_string(font);

  if (!ctxcanvas->fontdesc)
    return 0;

  if (ctxcanvas->fontlayout)  
    g_object_unref(ctxcanvas->fontlayout);

  ctxcanvas->fontlayout = pango_layout_new(ctxcanvas->fontcontext);
  pango_layout_set_font_description(ctxcanvas->fontlayout, ctxcanvas->fontdesc);

  attrs = pango_attr_list_new();
  pango_attr_list_insert(attrs, pango_attribute_copy(pango_attr_strikethrough_new(is_strikeout ? TRUE : FALSE)));
  pango_attr_list_insert(attrs, pango_attribute_copy(pango_attr_underline_new(is_underline ? PANGO_UNDERLINE_SINGLE : PANGO_UNDERLINE_NONE)));
  pango_layout_set_attributes(ctxcanvas->fontlayout, attrs);

  pango_attr_list_unref(attrs);

  return 1;
}
Beispiel #13
0
static void
text_input_preedit_styling(void *data,
			   struct wl_text_input *text_input,
			   uint32_t index,
			   uint32_t length,
			   uint32_t style)
{
	struct text_entry *entry = data;
	PangoAttribute *attr1 = NULL;
	PangoAttribute *attr2 = NULL;

	if (!entry->preedit_info.attr_list)
		entry->preedit_info.attr_list = pango_attr_list_new();

	switch (style) {
		case WL_TEXT_INPUT_PREEDIT_STYLE_DEFAULT:
		case WL_TEXT_INPUT_PREEDIT_STYLE_UNDERLINE:
			attr1 = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
			break;
		case WL_TEXT_INPUT_PREEDIT_STYLE_INCORRECT:
			attr1 = pango_attr_underline_new(PANGO_UNDERLINE_ERROR);
			attr2 = pango_attr_underline_color_new(65535, 0, 0);
			break;
		case WL_TEXT_INPUT_PREEDIT_STYLE_SELECTION:
			attr1 = pango_attr_background_new(0.3 * 65535, 0.3 * 65535, 65535);
			attr2 = pango_attr_foreground_new(65535, 65535, 65535);
			break;
		case WL_TEXT_INPUT_PREEDIT_STYLE_HIGHLIGHT:
		case WL_TEXT_INPUT_PREEDIT_STYLE_ACTIVE:
			attr1 = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
			attr2 = pango_attr_weight_new(PANGO_WEIGHT_BOLD);
			break;
		case WL_TEXT_INPUT_PREEDIT_STYLE_INACTIVE:
			attr1 = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
			attr2 = pango_attr_foreground_new(0.3 * 65535, 0.3 * 65535, 0.3 * 65535);
			break;
	}

	if (attr1) {
		attr1->start_index = entry->cursor + index;
		attr1->end_index = entry->cursor + index + length;
		pango_attr_list_insert(entry->preedit_info.attr_list, attr1);
	}

	if (attr2) {
		attr2->start_index = entry->cursor + index;
		attr2->end_index = entry->cursor + index + length;
		pango_attr_list_insert(entry->preedit_info.attr_list, attr2);
	}
}
Beispiel #14
0
static void
coopy_add_attr (PangoAttrList *attrs, PangoAttribute *attr)
{
	attr->start_index = 0;
	attr->end_index = 2;
	pango_attr_list_insert (attrs, attr);
}
Beispiel #15
0
static void
gm_cell_renderer_bitext_update_style (GmCellRendererBitext* renderer,
				      GtkWidget* widget)
{
  GtkStyleContext *style = NULL;
  GtkStateFlags state;
  PangoAttrList *attr_list = NULL;
  PangoAttribute *attr_size = NULL;
  const PangoFontDescription* font = NULL;

  style = gtk_widget_get_style_context (widget);
  state = gtk_widget_get_state_flags (widget);

  attr_list = pango_attr_list_new ();

  /* we want the secondary text smaller */
  gtk_style_context_get (style, state,
			 "font", &font,
			 NULL);
  attr_size = pango_attr_size_new ((int) (pango_font_description_get_size (font) * 0.8));
  attr_size->start_index = strlen (renderer->priv->primary_text) + 1;
  attr_size->end_index = (guint) - 1;
  pango_attr_list_insert (attr_list, attr_size);

  g_object_set (renderer,
		"visible", TRUE,
		"weight", PANGO_WEIGHT_NORMAL,
		"attributes", attr_list,
		NULL);
  pango_attr_list_unref (attr_list);
}
static void
append_item (NemoImagePropertiesPage *page,
	     const char                  *name,
	     const char                  *value)
{
	GtkWidget *name_label;
	GtkWidget *label;
	PangoAttrList *attrs;

	name_label = gtk_label_new (name);
	attrs = pango_attr_list_new ();
	pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
	gtk_label_set_attributes (GTK_LABEL (name_label), attrs);
	pango_attr_list_unref (attrs);
	gtk_misc_set_alignment (GTK_MISC (name_label), 0, 0);
	gtk_container_add (GTK_CONTAINER (page->details->grid), name_label);
	gtk_widget_show (name_label);

	if (value != NULL) {
		label = gtk_label_new (value);
		gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
		gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
		gtk_grid_attach_next_to (GTK_GRID (page->details->grid), label,
					 name_label, GTK_POS_RIGHT,
					 1, 1);
		gtk_widget_show (label);
	}
}
Beispiel #17
0
PangoLayout * VwGraphicsCairo::GetPangoLayoutHelper()
{
	if (m_fontMap == NULL)
		m_fontMap = pango_cairo_font_map_get_default();

	if (m_context == NULL)
	{	m_context = pango_context_new();
		pango_context_set_font_map(m_context, m_fontMap);
	}

	if (m_layout == NULL)
	{
		m_layout = pango_layout_new(m_context);

		PangoAttrList* list = pango_attr_list_new();
		PangoAttribute * fallbackAttrib = pango_attr_fallback_new(true);
		pango_attr_list_insert(list, fallbackAttrib);
		pango_layout_set_attributes(m_layout, list);
		pango_attr_list_unref(list);

		pango_layout_set_single_paragraph_mode(m_layout, true);
	}

	return m_layout;
}
Beispiel #18
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);
        }
    }
Beispiel #19
0
/* Set the colour of the "valid from" and "valid until" elements on the
 * Certificate page to red if they are incorrectly in the future or
 * past. */
static void show_date_state(char* label, void* data, int length) {
	gchar* labelname = g_strndup(label, strstr(label, ":") - label);
	GtkLabel* l = GTK_LABEL(gtk_builder_get_object(builder, labelname));
	PangoAttrList *attrs = pango_attr_list_new();
	PangoAttribute *attr;
	gboolean* is_invalid = (gboolean*)data;

	g_free(labelname);
	if(*is_invalid) {
		attr = pango_attr_foreground_new(G_MAXUINT16, 0, 0);
	} else {
#if HAVE_GTK == 3
		GdkRGBA color;
		GtkStyleContext *style = gtk_widget_get_style_context(GTK_WIDGET(l));

		gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
		attr = pango_attr_foreground_new(color.red * G_MAXUINT16, color.green * G_MAXUINT16, color.blue * G_MAXUINT16);
#else
#if HAVE_GTK == 2
		/* In GTK+ 2, there is no GtkStyleContext yet. It
		 * should, in theory, be possible to figure out what the
		 * default foreground color is by using a GTK+
		 * 2-specific API, but that's too much work and GTK+ 2
		 * is a minority now anyway, so... */
		attr = pango_attr_foreground_new(0, 0, 0);
#else
		/* The configure script only allows GTK+2 or GTK+3. */
#error should not happen
#endif
#endif
	}
	pango_attr_list_insert(attrs, attr);
	gtk_label_set_attributes(l, attrs);
}
Beispiel #20
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;
}
Beispiel #21
0
PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
		const char *text, double scale, bool markup) {
	PangoLayout *layout = pango_cairo_create_layout(cairo);
	PangoAttrList *attrs;
	if (markup) {
		char *buf;
		GError *error = NULL;
		if (pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, &error)) {
			pango_layout_set_text(layout, buf, -1);
			free(buf);
		} else {
			sway_log(SWAY_ERROR, "pango_parse_markup '%s' -> error %s", text,
					error->message);
			g_error_free(error);
			markup = false; // fallback to plain text
		}
	}
	if (!markup) {
		attrs = pango_attr_list_new();
		pango_layout_set_text(layout, text, -1);
	}

	pango_attr_list_insert(attrs, pango_attr_scale_new(scale));
	PangoFontDescription *desc = pango_font_description_from_string(font);
	pango_layout_set_font_description(layout, desc);
	pango_layout_set_single_paragraph_mode(layout, 1);
	pango_layout_set_attributes(layout, attrs);
	pango_attr_list_unref(attrs);
	pango_font_description_free(desc);
	return layout;
}
Beispiel #22
0
static void
apply_subtitle_style_to_layout (GtkStyleContext *context,
                                PangoLayout     *layout,
                                GtkStateFlags    flags)
{
  PangoFontDescription *desc;
  PangoAttrList *layout_attr;
  PangoAttribute *attr_alpha;

  gtk_style_context_save (context);
  gtk_style_context_set_state (context, flags);
  gtk_style_context_get (context, gtk_style_context_get_state (context),
                         "font", &desc,
                         NULL);
  gtk_style_context_restore (context);

  /* Set the font size */
  pango_font_description_set_size (desc, pango_font_description_get_size (desc) * SUBTITLE_SIZE_PERCENTAGE);
  pango_layout_set_font_description (layout, desc);
  pango_font_description_free (desc);

  /* Set the font alpha */
  layout_attr = pango_attr_list_new ();
  attr_alpha = pango_attr_foreground_alpha_new (SUBTITLE_DIM_PERCENTAGE * 65535);
  pango_attr_list_insert (layout_attr, attr_alpha);

  pango_layout_set_attributes (layout, layout_attr);
  pango_attr_list_unref (layout_attr);
}
static void
create_layout (GtkSourceGutterRendererText *renderer,
               GtkWidget                   *widget)
{
	PangoLayout *layout;
	PangoAttribute *attr;
	GtkStyleContext *context;
	GdkRGBA color;
	PangoAttrList *attr_list;

	layout = gtk_widget_create_pango_layout (widget, NULL);

	context = gtk_widget_get_style_context (widget);
	gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &color);

	attr = pango_attr_foreground_new (color.red * 65535,
	                                  color.green * 65535,
	                                  color.blue * 65535);

	attr->start_index = 0;
	attr->end_index = G_MAXINT;

	attr_list = pango_attr_list_new ();
	pango_attr_list_insert (attr_list, attr);

	renderer->priv->fg_attr = attr;
	renderer->priv->cached_layout = layout;
	renderer->priv->cached_attr_list = attr_list;
}
Beispiel #24
0
void gnome_main_section_new_with_grid(const gchar *title, GtkWidget **frame, GtkWidget **grid)
{
    PangoAttrList *attrs = pango_attr_list_new();
    PangoAttribute *attr = pango_attr_weight_new(PANGO_WEIGHT_BOLD);
    attr->start_index = 0;
    attr->end_index = -1;
    pango_attr_list_insert(attrs, attr);

    *frame = gtk_frame_new(title);
    gtk_frame_set_shadow_type(GTK_FRAME(*frame), GTK_SHADOW_NONE);
    gtk_container_set_border_width(GTK_CONTAINER(*frame), 2);

    GtkWidget *label = gtk_frame_get_label_widget(GTK_FRAME(*frame));
    gtk_label_set_attributes(GTK_LABEL(label), attrs);
    pango_attr_list_unref(attrs);

    GtkWidget *align = gtk_alignment_new(0.08, 0.2, 0.1, 0.1);
    gtk_container_add(GTK_CONTAINER(*frame), align);

    *grid = gtk_grid_new();
    gtk_grid_set_row_spacing(GTK_GRID(*grid), 2);
    gtk_grid_set_column_spacing(GTK_GRID(*grid), 2);
    gtk_widget_show(*grid);
    gtk_container_add(GTK_CONTAINER(align), *grid);
}
Beispiel #25
0
JNIEXPORT void JNICALL
Java_org_gnome_pango_PangoAttrList_pango_1attr_1list_1insert
(
	JNIEnv* env,
	jclass cls,
	jlong _self,
	jlong _attr
)
{
	PangoAttrList* self;
	PangoAttribute* attr;

	// convert parameter self
	self = (PangoAttrList*) _self;

	// convert parameter attr
	attr = (PangoAttribute*) _attr;

	// call function
	pango_attr_list_insert(self, attr);

	// cleanup parameter self

	// cleanup parameter attr
}
Beispiel #26
0
bool
OxLabel_SetTextColor(OxLabelObject* ox, int iRed, int iGreen, int iBlue)
{
	PangoAttrList* pAL = pango_attr_list_new();
	pango_attr_list_insert(pAL, pango_attr_foreground_new(iRed, iGreen, iBlue));
	gtk_label_set_attributes(GTK_LABEL(ox->pGtk), pAL);
	return TRUE;
}
Beispiel #27
0
void ygtk_steps_append_heading (YGtkSteps *steps, const gchar *heading)
{
	GtkWidget *label = gtk_label_new (heading);
	GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 };
	gtk_widget_override_color (label, GTK_STATE_NORMAL, &black);
	g_object_set_data (G_OBJECT (label), "is-header", GINT_TO_POINTER (1));
	gtk_misc_set_alignment (GTK_MISC (label), 0, 0);

	PangoAttrList *attrbs = pango_attr_list_new();
	pango_attr_list_insert (attrbs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
	pango_attr_list_insert (attrbs, pango_attr_scale_new (PANGO_SCALE_LARGE));
	gtk_label_set_attributes (GTK_LABEL (label), attrbs);
	pango_attr_list_unref (attrbs);

	gtk_widget_show (label);
	gtk_box_pack_start (GTK_BOX (steps), label, FALSE, TRUE, 6);
}
Beispiel #28
0
static void set_background(CustomData *data) {
    PangoAttrList *attrs;

    attrs = pango_attr_list_new();
    pango_attr_list_insert (attrs, pango_attr_background_new (65535, 0, 0));
    gtk_label_set_attributes(GTK_LABEL (data->timelabel), attrs);
    pango_attr_list_unref (attrs);
}
static void
add_attr (PangoAttrList *attr_list,
         PangoAttribute *attr)
{
  attr->start_index = 0;
  attr->end_index = G_MAXINT;
  pango_attr_list_insert (attr_list, attr);
}
Beispiel #30
0
GtkWidget *
gnome_prefs_subsection_new (GtkWidget *window,
			    GtkWidget *container,
			    const gchar *frame_name,       
			    int rows,
			    int cols)      
{
  GnomePrefsWindow *gpw  = NULL;
  
  GtkWidget *hbox = NULL;
  GtkWidget *frame = NULL;
  GtkWidget *table = NULL;
  GtkWidget *label = NULL;
  
  PangoAttrList *attrs = NULL;
  PangoAttribute *attr = NULL;

  if (window)
    gpw = (GnomePrefsWindow *) g_object_get_data (G_OBJECT (window), "gpw");
  
  hbox = gtk_hbox_new (FALSE, 6);

  frame = gtk_frame_new (frame_name);
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
  
  attrs = pango_attr_list_new ();
  attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
  attr->start_index = 0;
  attr->end_index = -1;
  pango_attr_list_insert (attrs, attr);

  label = gtk_frame_get_label_widget (GTK_FRAME (frame));
  gtk_label_set_attributes (GTK_LABEL (label), attrs);
  pango_attr_list_unref (attrs);

  gtk_box_pack_start (GTK_BOX (container), frame,
                      FALSE, FALSE, 0);
  table = gtk_table_new (rows, cols, FALSE);                                   
                                                                              
  gtk_container_add (GTK_CONTAINER (frame), hbox); 

  gtk_container_set_border_width (GTK_CONTAINER (hbox), 3);
  gtk_container_set_border_width (GTK_CONTAINER (frame), 6);

  label = gtk_label_new ("    ");
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
  gtk_box_pack_start (GTK_BOX (hbox), table, FALSE, FALSE, 0);
                                                                               
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);     
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);     

  if (gpw)
    g_object_set_data (G_OBJECT (table), "gpw", gpw);

  gtk_widget_show_all (table);
  
  return table;
}