Exemple #1
0
G_MODULE_EXPORT void
action_font_activate_cb(GtkWidget *widget, EDITOR *e)
{
	GtkWidget *dialog;
	gchar *selected_text = NULL;
	gchar *size = NULL;
#ifdef HAVE_GTK_32
	dialog = gtk_font_chooser_dialog_new("Select font", NULL);
	gtk_font_chooser_set_font((GtkFontChooser *)dialog,
#else
	dialog = gtk_font_selection_dialog_new("Select font");
	gtk_font_selection_dialog_set_font_name((GtkFontSelectionDialog *)
						dialog,
#endif
				  "Droid Sans 14");

	if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
#ifdef HAVE_GTK_32
		const gchar *fontname = gtk_font_chooser_get_font((GtkFontChooser *)dialog);
#else
		const gchar *fontname = gtk_font_selection_dialog_get_font_name((GtkFontSelectionDialog *)dialog);
#endif
		GString *name = g_string_new(fontname);
		size = get_font_size_from_name(name);
		g_string_free(name, TRUE);

		selected_text = editor_get_selected_text(e);
#ifdef HAVE_GTK_32
		PangoFontDescription *font_description =
			gtk_font_chooser_get_font_desc((GtkFontChooser *)
						       dialog);
		fontname = pango_font_description_get_family(font_description);
#else
		PangoFontDescription *font_description =
			pango_font_description_from_string(fontname);
		fontname = pango_font_description_get_family(font_description);
#endif

		gchar *script = g_strdup_printf("<SPAN STYLE=\"font-family:%s;font-size:%spx;\">%s</SPAN>",
						fontname, size, selected_text);

		editor_insert_html(script, e);
		g_free(script);
	}
	if (size)
		g_free(size);
	if (selected_text)
		g_free(selected_text);
	gtk_widget_destroy(dialog);
}
Exemple #2
0
static void
webkit_pref_callback_font_family (GSettings  *settings,
                                  const char *key,
                                  gpointer    data)
{
  char *webkit_pref = data;
  char *value = NULL;

  char *schema = NULL;
  g_object_get (settings, "schema-id", &schema, NULL);

  /* If we are changing a GNOME font value and we are not using GNOME fonts in
   * Epiphany, return. */
  if (g_strcmp0 (schema, EPHY_PREFS_WEB_SCHEMA) != 0 &&
      g_settings_get_boolean (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_USE_GNOME_FONTS) != TRUE) {
    g_free (schema);
    return;
  }
  g_free (schema);

  value = g_settings_get_string (settings, key);

  if (value) {
    PangoFontDescription *desc;
    const char *family = NULL;

    desc = pango_font_description_from_string (value);
    family = pango_font_description_get_family (desc);
    g_object_set (webkit_settings, webkit_pref, family, NULL);
    pango_font_description_free (desc);
  }

  g_free (value);
}
void RenderThemeGtk::systemFont(CSSValueID, FontDescription& fontDescription) const
{
    GtkSettings* settings = gtk_settings_get_default();
    if (!settings)
        return;

    // This will be a font selection string like "Sans 10" so we cannot use it as the family name.
    GUniqueOutPtr<gchar> fontName;
    g_object_get(settings, "gtk-font-name", &fontName.outPtr(), NULL);

    PangoFontDescription* pangoDescription = pango_font_description_from_string(fontName.get());
    if (!pangoDescription)
        return;

    fontDescription.setOneFamily(pango_font_description_get_family(pangoDescription));

    int size = pango_font_description_get_size(pangoDescription) / PANGO_SCALE;
    // If the size of the font is in points, we need to convert it to pixels.
    if (!pango_font_description_get_size_is_absolute(pangoDescription))
        size = size * (getScreenDPI() / 72.0);

    fontDescription.setSpecifiedSize(size);
    fontDescription.setIsAbsoluteSize(true);
    fontDescription.setGenericFamily(FontDescription::NoFamily);
    fontDescription.setWeight(FontWeightNormal);
    fontDescription.setItalic(false);
    pango_font_description_free(pangoDescription);
}
Exemple #4
0
static gboolean
util_split_font_string(const gchar *font_name, gchar **name, gint *size)
{
	PangoFontDescription *desc;
	PangoFontMask         mask;
	gboolean              retval = FALSE;

	if (font_name == NULL) {
		return FALSE;
	}

	mask = (PangoFontMask) (PANGO_FONT_MASK_FAMILY | PANGO_FONT_MASK_SIZE);

	desc = pango_font_description_from_string(font_name);
	if (!desc) {
		return FALSE;
	}

	if ((pango_font_description_get_set_fields(desc) & mask) == mask) {
		*size = PANGO_PIXELS(pango_font_description_get_size (desc));
		*name = g_strdup(pango_font_description_get_family (desc));
		retval = TRUE;
	}

	pango_font_description_free(desc);

	return retval;
}
Exemple #5
0
GtkWidget *
make_families_menu ()
{
  GtkWidget *combo;
  int n_families;
  PangoFontFamily **families;
  GList *family_list = NULL;
  int i;
  
  pango_context_list_families (context, &families, &n_families);
  qsort (families, n_families, sizeof(char *), cmp_families);

  for (i=0; i<n_families; i++)
    family_list = g_list_prepend (family_list, pango_font_family_get_name (families[i]));

  family_list = g_list_reverse (family_list);
  
  combo = gtk_combo_new ();
  gtk_combo_set_popdown_strings (GTK_COMBO (combo), family_list);
  gtk_combo_set_value_in_list (GTK_COMBO (combo), TRUE, FALSE);
  gtk_editable_set_editable (GTK_EDITABLE (GTK_COMBO (combo)->entry), FALSE);

  gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (combo)->entry), pango_font_description_get_family(font_description));

  gtk_signal_connect (GTK_OBJECT (GTK_COMBO (combo)->entry), "changed",
		      GTK_SIGNAL_FUNC (set_family), NULL);
  
  g_list_free (family_list);

  return combo;
}
void
gkbd_indicator_config_get_font_for_widget (GkbdIndicatorConfig *
					   ind_config, GtkWidget * widget,
					   gchar ** font_family,
					   int *font_size)
{
	GtkStyleContext *context;
	const PangoFontDescription *fd = NULL;

	g_return_if_fail (GTK_IS_WIDGET (widget));

	if (ind_config->font_family != NULL &&
	    ind_config->font_family[0] != '\0') {
		if (font_family)
			*font_family = g_strdup (ind_config->font_family);
		if (font_size)
			*font_size = ind_config->font_size;

		return;
	}

	context = gtk_widget_get_style_context (widget);
	fd = gtk_style_context_get_font (context, GTK_STATE_FLAG_NORMAL);

	if (font_family)
		*font_family =
		    g_strdup (pango_font_description_get_family (fd));
	if (font_size)
		*font_size =
		    pango_font_description_get_size (fd) / PANGO_SCALE;
}
JNIEXPORT jstring JNICALL
Java_org_gnome_pango_PangoFontDescription_pango_1font_1description_1get_1family
(
	JNIEnv* env,
	jclass cls,
	jlong _self
)
{
	const char* result;
	jstring _result;
	PangoFontDescription* self;

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

	// call function
	result = pango_font_description_get_family(self);

	// cleanup parameter self

	// translate return value to JNI type
	_result = (jstring) bindings_java_newString(env, result);

	// and finally
	return _result;
}
bool GtkToolkitUiSettings::GetDefaultFont(FontDetails& font)
{
	gchararray font_face = 0;
	g_object_get(m_settings, "gtk-font-name", &font_face, NULL);
	PangoFontDescription* font_desc = pango_font_description_from_string(font_face);
	g_free(font_face);
	if (!font_desc)
		return false; 

	const char* family = pango_font_description_get_family(font_desc);

	if (family)
	{
		if (strcmp(family, "Sans") == 0)
			font.type = SANSSERIF;
		else if (strcmp(family, "Serif") == 0)
			font.type = SERIF;
		else if (strcmp(family, "Monospace") == 0)
			font.type = MONOSPACE;

		font.family = strdup(family);
	}
	font.weight = pango_font_description_get_weight(font_desc) / 100;
	font.italic = pango_font_description_get_style(font_desc) == PANGO_STYLE_ITALIC;
	font.smallcaps = pango_font_description_get_variant(font_desc) == PANGO_VARIANT_SMALL_CAPS;
	
	double size = pango_font_description_get_size(font_desc) / PANGO_SCALE;
	font.size = size;

	pango_font_description_free(font_desc);

	return true;
}
bool PangoFontInfo::ParseFontDescription(const PangoFontDescription *desc) {
  Clear();
  const char* family = pango_font_description_get_family(desc);
  if (!family) {
    char* desc_str = pango_font_description_to_string(desc);
    tprintf("WARNING: Could not parse family name from description: '%s'\n",
            desc_str);
    g_free(desc_str);
    return false;
  }
  family_name_ = string(family);
  desc_ = pango_font_description_copy(desc);
  is_monospace_ = IsMonospaceFontFamily(family);

  // Set font size in points
  font_size_ = pango_font_description_get_size(desc);
  if (!pango_font_description_get_size_is_absolute(desc)) {
    font_size_ /= PANGO_SCALE;
  }

  PangoStyle style = pango_font_description_get_style(desc);
  is_italic_ = (PANGO_STYLE_ITALIC == style ||
                PANGO_STYLE_OBLIQUE == style);
  is_smallcaps_ = (pango_font_description_get_variant(desc)
                   == PANGO_VARIANT_SMALL_CAPS);

  is_bold_ = (pango_font_description_get_weight(desc) >= PANGO_WEIGHT_BOLD);
  // We dont have a way to detect whether a font is of type Fraktur. The fonts
  // we currently use all have "Fraktur" in their family name, so we do a
  // fragile but functional check for that here.
  is_fraktur_ = (strcasestr(family, "Fraktur") != NULL);
  return true;
}
Exemple #10
0
static bool
pango_load (Lisp_Font *f)
{
    PangoLanguage *language;
    PangoFontDescription *fontdesc;
    PangoFont *font;
    PangoFontMetrics *metrics;

    if (pango_context)
    {
	language = pango_context_get_language (pango_context);
    }
    else
    {
	char *langname, *p;

#ifdef HAVE_PANGO_XFT
	pango_context = pango_xft_get_context (dpy, screen_num);
#endif

	langname = g_strdup (setlocale (LC_CTYPE, NULL));
	p = strchr (langname, '.');
	if (p)
	    *p = 0;
	p = strchr (langname, '@');
	if (p)
	    *p = 0;
	language = pango_language_from_string (langname);
	pango_context_set_language (pango_context, language);
	g_free (langname);
    }

    fontdesc = pango_font_description_from_string (rep_STR (f->name));

    if (!pango_font_description_get_family (fontdesc))
	pango_font_description_set_family (fontdesc, "Sans");
    if (pango_font_description_get_size (fontdesc) <= 0)
	pango_font_description_set_size (fontdesc, 12 * PANGO_SCALE);

    pango_context_set_font_description (pango_context, fontdesc);
    font = pango_context_load_font (pango_context, fontdesc);

    if (!font) {
        pango_font_description_free(fontdesc);
	return FALSE;
    }

    metrics = pango_font_get_metrics (font, language);

    f->ascent = metrics->ascent / PANGO_SCALE;
    f->descent = metrics->descent / PANGO_SCALE;

    pango_font_metrics_unref (metrics);

    f->font = fontdesc; /* We save the font description, not the font itself!
                        That's because it seems we can't recover it perfectly
                        later, and the layout routines want a description */

    return TRUE;
}
	static void
	update_font_family_combo (MucharmapMiniFontSelection *fontsel)
	{
	  GtkTreeModel *model = GTK_TREE_MODEL (fontsel->family_store);
	  GtkTreeIter iter;
	  const char *font_family;
	  gboolean found = FALSE;

	  font_family = pango_font_description_get_family (fontsel->font_desc);
	  if (!font_family || !font_family[0]) {
		gtk_combo_box_set_active (GTK_COMBO_BOX (fontsel->family), -1);
		return;
	  }

	  if (!gtk_tree_model_get_iter_first (model, &iter))
		return;

	  do {
		char *family;

		gtk_tree_model_get (model, &iter, COL_FAMILIY, &family, -1);
		found = family && strcmp (family, font_family) == 0;
		g_free (family);
	  } while (!found && gtk_tree_model_iter_next (model, &iter));

	  if (found) {
		gtk_combo_box_set_active_iter (GTK_COMBO_BOX (fontsel->family), &iter);
	  } else {
		gtk_combo_box_set_active (GTK_COMBO_BOX (fontsel->family), -1);
	  }
	}
Exemple #12
0
static gchar*
get_default_font (GtkWidget *widget)
{
  PangoFontDescription *font_desc = widget->style->font_desc;
  return g_strdup_printf ("%s %d",
                          pango_font_description_get_family (font_desc),
                          pango_font_description_get_size (font_desc) / PANGO_SCALE);
}
Exemple #13
0
static GtkCssValue *
gtk_css_value_initial_compute (GtkCssValue             *value,
                               guint                    property_id,
                               GtkStyleProviderPrivate *provider,
                               GtkCssStyle             *style,
                               GtkCssStyle             *parent_style)
{
  GtkSettings *settings;

  switch (property_id)
    {
    case GTK_CSS_PROPERTY_DPI:
      settings = _gtk_style_provider_private_get_settings (provider);
      if (settings)
        {
          GdkScreen *screen = _gtk_settings_get_screen (settings);
          double resolution = gdk_screen_get_resolution (screen);

          if (resolution > 0.0)
            return _gtk_css_number_value_new (resolution, GTK_CSS_NUMBER);
        }
      break;

    case GTK_CSS_PROPERTY_FONT_FAMILY:
      settings = _gtk_style_provider_private_get_settings (provider);
      if (settings)
        {
          PangoFontDescription *description;
          char *font_name;
          GtkCssValue *value;

          g_object_get (settings, "gtk-font-name", &font_name, NULL);
          description = pango_font_description_from_string (font_name);
          g_free (font_name);
          if (description == NULL)
            break;

          if (pango_font_description_get_set_fields (description) & PANGO_FONT_MASK_FAMILY)
            {
              value = _gtk_css_array_value_new (_gtk_css_string_value_new (pango_font_description_get_family (description)));
              pango_font_description_free (description);
              return value;
            }
 
          pango_font_description_free (description);
        }
      break;

    default:
      break;
    }

  return _gtk_css_value_compute (_gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (property_id)),
                                 property_id,
                                 provider,
                                 style,
                                 parent_style);
}
	void
	mucharmap_mini_font_selection_set_font_desc (MucharmapMiniFontSelection *fontsel,
		                                         PangoFontDescription *font_desc)
	{
	  GObject *object = G_OBJECT (fontsel);
	  PangoFontDescription *new_font_desc;
	  const char *new_font_family;

	  g_return_if_fail (MUCHARMAP_IS_MINI_FONT_SELECTION (fontsel));
	  g_return_if_fail (font_desc != NULL);

	  g_object_freeze_notify (object);

	  new_font_desc = pango_font_description_copy (font_desc);
	  new_font_family = pango_font_description_get_family (new_font_desc);
	  if (!new_font_family) {
		pango_font_description_set_family (new_font_desc, "Sans");
		new_font_family = pango_font_description_get_family (new_font_desc);
	  }

	  if ((!fontsel->font_desc ||
		   strcmp (pango_font_description_get_family (fontsel->font_desc), new_font_family) != 0) &&
		  pango_font_description_get_size (new_font_desc) > 0)
		fontsel->default_size = pango_font_description_get_size (new_font_desc) / PANGO_SCALE;

	  if (fontsel->font_desc)
		pango_font_description_free (fontsel->font_desc);
	  
	  fontsel->font_desc = new_font_desc;
	  
	  update_font_family_combo (fontsel);
		
	  /* treat oblique and italic both as italic */
	  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fontsel->italic), pango_font_description_get_style (fontsel->font_desc) == PANGO_STYLE_ITALIC || pango_font_description_get_style (fontsel->font_desc) == PANGO_STYLE_OBLIQUE);

	  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fontsel->bold), pango_font_description_get_weight (fontsel->font_desc) > PANGO_WEIGHT_NORMAL);

	  gtk_adjustment_set_value (
		      GTK_ADJUSTMENT (fontsel->size_adj), 
		      pango_font_description_get_size (fontsel->font_desc) / PANGO_SCALE);

	  g_object_notify (G_OBJECT (fontsel), "font-desc");

	  g_object_thaw_notify (object);
	}
nsresult
nsSystemFontsGTK2::GetSystemFontInfo(GtkWidget *aWidget, nsString *aFontName,
                                     gfxFontStyle *aFontStyle) const
{
#ifdef MOZ_PANGO
    GtkSettings *settings = gtk_widget_get_settings(aWidget);

    aFontStyle->style       = FONT_STYLE_NORMAL;

    gchar *fontname;
    g_object_get(settings, "gtk-font-name", &fontname, NULL);

    PangoFontDescription *desc;
    desc = pango_font_description_from_string(fontname);

    aFontStyle->systemFont = PR_TRUE;

    g_free(fontname);

    NS_NAMED_LITERAL_STRING(quote, "\"");
    NS_ConvertUTF8toUTF16 family(pango_font_description_get_family(desc));
    *aFontName = quote + family + quote;

    aFontStyle->weight = pango_font_description_get_weight(desc);

    // FIXME: Set aFontStyle->stretch correctly!
    aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;

    float size = float(pango_font_description_get_size(desc)) / PANGO_SCALE;

    // |size| is now either pixels or pango-points (not Mozilla-points!)

    if (!MOZ_pango_font_description_get_size_is_absolute(desc)) {
        // |size| is in pango-points, so convert to pixels.
        size *= float(gfxPlatformGtk::GetDPI()) / POINTS_PER_INCH_FLOAT;
    }

    // |size| is now pixels

    aFontStyle->size = size;
  
    pango_font_description_free(desc);

#else
    /* FIXME: DFB FT2 Hardcoding the system font info for now.. */
    aFontStyle->style       = FONT_STYLE_NORMAL;
    aFontStyle->systemFont = PR_TRUE;

    NS_NAMED_LITERAL_STRING(fontname, "\"Sans\"");
    *aFontName = fontname;
    aFontStyle->weight = 400;
    aFontStyle->size = 40/3;

#endif

    return NS_OK;
}
GR_Font * GR_UnixCairoGraphics::getGUIFont(void)
{
	if (!m_pPFontGUI)
	{
		// get the font resource
#if GTK_CHECK_VERSION(3,0,0)
		GtkStyleContext *tempCtxt = gtk_style_context_new();
		GtkWidgetPath *path = gtk_widget_path_new();
		gtk_widget_path_append_type (path, GTK_TYPE_WINDOW);
		gtk_style_context_set_path(tempCtxt, path);
		gtk_widget_path_free(path);
		const char *guiFontName = pango_font_description_get_family(gtk_style_context_get_font(tempCtxt, GTK_STATE_FLAG_NORMAL));
#else
		GtkStyle *tempStyle = gtk_style_new();
		const char *guiFontName = pango_font_description_get_family(tempStyle->font_desc);
#endif
		if (!guiFontName)
			guiFontName = "'Times New Roman'";

		UT_UTF8String s = XAP_EncodingManager::get_instance()->getLanguageISOName();

		const char * pCountry
			= XAP_EncodingManager::get_instance()->getLanguageISOTerritory();
		
		if(pCountry)
		{
			s += "-";
			s += pCountry;
		}
		
		m_pPFontGUI = new GR_PangoFont(guiFontName, 11.0, this, s.utf8_str(), true);

#if GTK_CHECK_VERSION(3,0,0)
		g_object_unref(G_OBJECT(tempCtxt));
#else
		g_object_unref(G_OBJECT(tempStyle));
#endif
		
		UT_ASSERT(m_pPFontGUI);
	}

	return m_pPFontGUI;
}
Exemple #17
0
static void
gnm_font_button_update_font_data (GnmFontButton *font_button)
{
  GnmFontButtonPrivate *priv = font_button->priv;
  PangoFontFamily **families;
  PangoFontFace **faces;
  gint n_families, n_faces, i;
  const gchar *family;

  g_assert (priv->font_desc != NULL);

  priv->fontname = pango_font_description_to_string (priv->font_desc);

  family = pango_font_description_get_family (priv->font_desc);
  if (family == NULL)
    return;

  n_families = 0;
  families = NULL;
  pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (font_button)),
                               &families, &n_families);
  n_faces = 0;
  faces = NULL;
  for (i = 0; i < n_families; i++)
    {
      const gchar *name = pango_font_family_get_name (families[i]);

      if (!g_ascii_strcasecmp (name, family))
        {
          priv->font_family = g_object_ref (families[i]);

          pango_font_family_list_faces (families[i], &faces, &n_faces);
          break;
        }
    }
  g_free (families);

  for (i = 0; i < n_faces; i++)
    {
      PangoFontDescription *tmp_desc = pango_font_face_describe (faces[i]);

      if (font_description_style_equal (tmp_desc, priv->font_desc))
        {
          priv->font_face = g_object_ref (faces[i]);

          pango_font_description_free (tmp_desc);
          break;
        }
      else
        pango_font_description_free (tmp_desc);
    }

  g_free (faces);
}
void WindowCheckKeyterms::set_fonts()
{
  extern Settings *settings;
  if (!settings->genconfig.text_editor_font_default_get()) {
    PangoFontDescription *desired_font_description = pango_font_description_from_string(settings->genconfig.text_editor_font_name_get().c_str());
    const char * desired_font_family = pango_font_description_get_family (desired_font_description);
    WebKitWebSettings * webkit_settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (webview_terms));
    g_object_set (G_OBJECT (webkit_settings), "default-font-family", desired_font_family, NULL);
    pango_font_description_free (desired_font_description);
  }
}
Exemple #19
0
static int
compare_font_descriptions (const PangoFontDescription *a, const PangoFontDescription *b)
{
  int val = strcmp (pango_font_description_get_family(a), pango_font_description_get_family(b));
  if (val != 0)
    return val;

  if (pango_font_description_get_weight(a) != pango_font_description_get_weight(b))
    return pango_font_description_get_weight(a) - pango_font_description_get_weight(b);

  if (pango_font_description_get_style(a) != pango_font_description_get_style(b))
    return pango_font_description_get_style(a) - pango_font_description_get_style(b);
  
  if (pango_font_description_get_stretch(a) != pango_font_description_get_stretch(b))
    return pango_font_description_get_stretch(a) - pango_font_description_get_stretch(b);

  if (pango_font_description_get_stretch(a) != pango_font_description_get_stretch(b))
    return pango_font_description_get_stretch(a) - pango_font_description_get_stretch(b);

  return 0;
}
static void
matekbd_indicator_config_load_font (MatekbdIndicatorConfig * ind_config)
{
	GError *gerror = NULL;

	ind_config->font_family =
	    mateconf_client_get_string (ind_config->conf_client,
				     MATEKBD_INDICATOR_CONFIG_KEY_FONT_FAMILY,
				     &gerror);
	if (gerror != NULL) {
		g_warning ("Error reading configuration:%s\n",
			   gerror->message);
		ind_config->font_family = g_strdup ("Helvetica");
		g_error_free (gerror);
		gerror = NULL;
	}

	ind_config->font_size =
	    mateconf_client_get_int (ind_config->conf_client,
				  MATEKBD_INDICATOR_CONFIG_KEY_FONT_SIZE,
				  &gerror);
	if (gerror != NULL) {
		g_warning ("Error reading configuration:%s\n",
			   gerror->message);
		ind_config->font_size = 10;
		g_error_free (gerror);
		gerror = NULL;
	}

	if (ind_config->font_family == NULL ||
	    ind_config->font_family[0] == '\0') {
		PangoFontDescription *fd = NULL;
		GtkStyle *style =
		    gtk_rc_get_style_by_paths (gtk_settings_get_default (),
					       GTK_STYLE_PATH,
					       GTK_STYLE_PATH,
					       GTK_TYPE_LABEL);
		if (style != NULL)
			fd = style->font_desc;
		if (fd != NULL) {
			ind_config->font_family =
			    g_strdup (pango_font_description_get_family
				      (fd));
			ind_config->font_size =
			    pango_font_description_get_size (fd) /
			    PANGO_SCALE;
		}
	}
	xkl_debug (150, "font: [%s], size %d\n", ind_config->font_family,
		   ind_config->font_size);

}
Exemple #21
0
DiaFont*
dia_font_new(const char *family, DiaFontStyle style, real height)
{
  DiaFont* font = dia_font_new_from_style(style, height);
  gboolean changed;

  changed = family != NULL && strcmp (pango_font_description_get_family(font->pfd), family) != 0;
  pango_font_description_set_family(font->pfd, family);

  if (changed)
    _dia_font_adjust_size (font, font->height, TRUE);

  return font;
}
const std::string ZLGtkPaintContext::realFontFamilyName(std::string &fontFamily) const {
	if (myContext == 0) {
		return fontFamily;
	}
	PangoFontDescription *description = pango_font_description_new();
	pango_font_description_set_family(description, fontFamily.c_str());
	pango_font_description_set_size(description, 12);
	PangoFont *font = pango_context_load_font(myContext, description);
	pango_font_description_free(description);
	description = pango_font_describe(font);
	std::string realFamily = pango_font_description_get_family(description);
	pango_font_description_free(description);
	return realFamily;
}
Exemple #23
0
gchar *
tbo_tool_text_get_font_name (TboToolText *self)
{
    PangoFontDescription *pango_font = NULL;

    if (self->font)
    {
        pango_font = pango_font_description_from_string (
                         gtk_font_button_get_font_name (GTK_FONT_BUTTON (self->font)));
        return (gchar *)pango_font_description_get_family (pango_font);
    }

    return NULL;
}
Exemple #24
0
void
dia_font_set_any_family(DiaFont* font, const char* family)
{
  gboolean changed;

  g_return_if_fail(font != NULL);

  changed = strcmp (pango_font_description_get_family(font->pfd), family) != 0;
  pango_font_description_set_family(font->pfd, family);
  if (changed) /* force recalculation on name change */
    _dia_font_adjust_size (font, font->height, TRUE);
  if (font->legacy_name) {
    g_free(font->legacy_name);
    font->legacy_name = NULL;
  }
}
static gboolean
webkit_get_font_family (GValue *value,
    GVariant *variant,
    gpointer user_data)
{
  PangoFontDescription *font = pango_font_description_from_string (
      g_variant_get_string (variant, NULL));

  if (font == NULL)
    return FALSE;

  g_value_set_string (value, pango_font_description_get_family (font));
  pango_font_description_free (font);

  return TRUE;
}
Exemple #26
0
/**
 * rpt_common_rptfont_from_pango_description:
 * @description: a #PangoFontDescription.
 *
 * Returns: a new allocated #RptFont from a #PangoFontDescription.
 */
RptFont
*rpt_common_rptfont_from_pango_description (const PangoFontDescription *description)
{
	RptFont *font;

	font = rpt_common_rptfont_new ();

	font->name = (gchar *)pango_font_description_get_family (description);
	font->size = pango_font_description_get_size (description) / PANGO_SCALE;
	font->bold = (pango_font_description_get_weight (description) == PANGO_WEIGHT_BOLD);
	font->italic = (pango_font_description_get_style (description) == PANGO_STYLE_ITALIC);
	font->underline = PANGO_UNDERLINE_NONE;
	font->strike = FALSE;

	font->color = rpt_common_rptcolor_new ();
	font->color->a = 1.0;

	return font;
}
void ZLGtkPaintContext::setFont(const std::string &family, int size, bool bold, bool italic) {
	bool fontChanged = false;

	if (myFontDescription == 0) {
		myFontDescription = pango_font_description_new();
		fontChanged = true;
	}

	const char *oldFamily = pango_font_description_get_family(myFontDescription);
	if ((oldFamily == 0) || (family != oldFamily)) {
		pango_font_description_set_family(myFontDescription, family.c_str());
		fontChanged = true;
	}

	int newSize = size * PANGO_SCALE;
	if (pango_font_description_get_size(myFontDescription) != newSize) {
		pango_font_description_set_size(myFontDescription, newSize);
		fontChanged = true;
	}

	PangoWeight newWeight = bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL;
	if (pango_font_description_get_weight(myFontDescription) != newWeight) {
		pango_font_description_set_weight(myFontDescription, newWeight);
		fontChanged = true;
	}

	PangoStyle newStyle = italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL;
	if (pango_font_description_get_style(myFontDescription) != newStyle) {
		pango_font_description_set_style(myFontDescription, newStyle);
		fontChanged = true;
	}

	if (fontChanged) {
		if (myContext != 0) {
			myAnalysis.font = pango_context_load_font(myContext, myFontDescription);
			myAnalysis.shape_engine = pango_font_find_shaper(myAnalysis.font, 0, 0);
			PangoFontMetrics *metrics = pango_font_get_metrics(myAnalysis.font, myAnalysis.language);
			myDescent = pango_font_metrics_get_descent(metrics) / PANGO_SCALE;
		}
		myStringHeight = -1;
		mySpaceWidth = -1;
	}
}
/*
 * Wrap calls to pango_font_description_get_family
 * and replace some of the pango font names with generic css names
 * http://www.w3.org/TR/2008/REC-CSS2-20080411/fonts.html#generic-font-families
 *
 * This function should be called in place of pango_font_description_get_family()
 */
const char *sp_font_description_get_family(PangoFontDescription const *fontDescr) {

    static std::map<Glib::ustring, Glib::ustring> fontNameMap;
    std::map<Glib::ustring, Glib::ustring>::iterator it;

    if (fontNameMap.empty()) {
        fontNameMap.insert(std::make_pair("Sans", "sans-serif"));
        fontNameMap.insert(std::make_pair("Serif", "serif"));
        fontNameMap.insert(std::make_pair("Monospace", "monospace"));
    }

    const char *pangoFamily = pango_font_description_get_family(fontDescr);

    if (pangoFamily && ((it = fontNameMap.find(pangoFamily)) != fontNameMap.end())) {
        return ((Glib::ustring)it->second).c_str();
    }

    return pangoFamily;
}
Exemple #29
0
static void
contact_begin_print (GtkPrintOperation *operation,
                     GtkPrintContext *context,
                     EContactPrintContext *ctxt)
{
	GtkPageSetup *setup;
	gdouble page_width;

	e_contact_build_style (ctxt->style);

	setup = gtk_print_context_get_page_setup (context);
	page_width = gtk_page_setup_get_page_width (setup, GTK_UNIT_POINTS);

	ctxt->context = context;
	ctxt->x = ctxt->y = .0;
	ctxt->column = 0;
	ctxt->first_contact = TRUE;
	ctxt->first_section = TRUE;
	ctxt->section = NULL;

	ctxt->column_spacing = gtk_print_context_get_dpi_x (context) / 4;
	ctxt->column_width = (page_width + ctxt->column_spacing) /
		ctxt->style->num_columns - ctxt->column_spacing;

	ctxt->letter_heading_font = pango_font_description_new ();
	pango_font_description_set_family (
		ctxt->letter_heading_font,
		pango_font_description_get_family (
			ctxt->style->headings_font));
	pango_font_description_set_size (
		ctxt->letter_heading_font,
		pango_font_description_get_size (
			ctxt->style->headings_font) * 1.5);

	if (ctxt->contact_list != NULL) {
		ctxt->page_nr = -1;
		ctxt->pages = 1;
		g_slist_foreach (ctxt->contact_list, (GFunc) contact_draw, ctxt);
		gtk_print_operation_set_n_pages (operation, ctxt->pages);
	}
}
Exemple #30
0
static gboolean utils_font_desc_check_monospace(PangoContext *pc, PangoFontDescription *desc)
{
	PangoFontFamily **families;
	gint n_families, i;
	const gchar *font;
	gboolean ret = TRUE;

	font = pango_font_description_get_family(desc);
	pango_context_list_families(pc, &families, &n_families);
	for (i = 0; i < n_families; i++)
	{
		if (utils_str_equal(font, pango_font_family_get_name(families[i])))
		{
			if (!pango_font_family_is_monospace(families[i]))
			{
				ret = FALSE;
			}
		}
	}
	g_free(families);
	return ret;
}