Exemplo n.º 1
0
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);
}
Exemplo n.º 2
0
real
dia_font_get_size(const DiaFont* font)
{
  if (!pango_font_description_get_size_is_absolute (font->pfd))
    g_warning ("dia_font_get_size() : no absolute size");
  return pdu_to_dcm(pango_font_description_get_size(font->pfd));
}
Exemplo n.º 3
0
/* Return the font size in Pango units for the font size setting */
gint
get_font_size(PangoFontDescription *font)
{
	I7App *theapp = i7_app_get();
	double size = pango_font_description_get_size(font);

	if(pango_font_description_get_size_is_absolute(font))
		size *= 96.0 / 72.0; /* a guess; not likely to be absolute anyway */
	if(size == 0.0)
		size = DEFAULT_SIZE_STANDARD * PANGO_SCALE;

	switch(g_settings_get_enum(i7_app_get_prefs(theapp), PREFS_FONT_SIZE)) {
		case FONT_SIZE_MEDIUM:
			size *= RELATIVE_SIZE_MEDIUM;
			break;
		case FONT_SIZE_LARGE:
			size *= RELATIVE_SIZE_LARGE;
			break;
		case FONT_SIZE_HUGE:
			size *= RELATIVE_SIZE_HUGE;
			break;
		default:
			size *= RELATIVE_SIZE_STANDARD;
	}
	return size;
}
Exemplo n.º 4
0
JNIEXPORT jboolean JNICALL
Java_org_gnome_pango_PangoFontDescription_pango_1font_1description_1get_1size_1is_1absolute
(
	JNIEnv* env,
	jclass cls,
	jlong _self
)
{
	gboolean result;
	jboolean _result;
	PangoFontDescription* self;

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

	// call function
	result = pango_font_description_get_size_is_absolute(self);

	// cleanup parameter self

	// translate return value to JNI type
	_result = (jboolean) result;

	// and finally
	return _result;
}
Exemplo n.º 5
0
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;
}
static gboolean
webkit_get_font_size (GValue *value,
    GVariant *variant,
    gpointer user_data)
{
  PangoFontDescription *font = pango_font_description_from_string (
      g_variant_get_string (variant, NULL));
  int size;

  if (font == NULL)
    return FALSE;

  size = pango_font_description_get_size (font) / PANGO_SCALE;

  if (pango_font_description_get_size_is_absolute (font))
    {
      GdkScreen *screen = gdk_screen_get_default ();
      double dpi;

      if (screen != NULL)
        dpi = gdk_screen_get_resolution (screen);
      else
        dpi = BORING_DPI_DEFAULT;

      size = (gint) (size / (dpi / 72));
    }

  g_value_set_int (value, size);
  pango_font_description_free (font);

  return TRUE;
}
Exemplo n.º 7
0
static gfloat
get_units_per_em (ClutterBackend       *backend,
                  PangoFontDescription *font_desc)
{
  gfloat units_per_em = -1.0;
  gboolean free_font_desc = FALSE;
  gdouble dpi;

  dpi = clutter_backend_get_resolution (backend);

  if (font_desc == NULL)
    {
      ClutterSettings *settings;
      gchar *font_name = NULL;

      settings = clutter_settings_get_default ();
      g_object_get (settings, "font-name", &font_name, NULL);

      if (G_LIKELY (font_name != NULL && *font_name != '\0'))
        {
          font_desc = pango_font_description_from_string (font_name);
          free_font_desc = TRUE;

          g_free (font_name);
        }
    }

  if (font_desc != NULL)
    {
      gdouble font_size = 0;
      gint pango_size;
      gboolean is_absolute;

      pango_size = pango_font_description_get_size (font_desc);
      is_absolute = pango_font_description_get_size_is_absolute (font_desc);

      /* "absolute" means "device units" (usually, pixels); otherwise,
       * it means logical units (points)
       */
      if (is_absolute)
        font_size = (gdouble) pango_size / PANGO_SCALE;
      else
        font_size = dpi * ((gdouble) pango_size / PANGO_SCALE) / 72.0f;

      /* 10 points at 96 DPI is 13.3 pixels */
      units_per_em = (1.2f * font_size) * dpi / 96.0f;
    }
  else
    units_per_em = -1.0f;

  if (free_font_desc)
    pango_font_description_free (font_desc);

  return units_per_em;
}
Exemplo n.º 8
0
int ZLGtkPaintContext::stringHeight() const {
	if (myFontDescription == 0) {
		return 0;
	}
	if (myStringHeight == -1) {
#if GTK_CHECK_VERSION(2,10,0)
		if (pango_font_description_get_size_is_absolute(myFontDescription)) {
			myStringHeight = pango_font_description_get_size(myFontDescription) / PANGO_SCALE + 2;
		} else {
			static const int resolution = gdk_screen_get_resolution(gdk_screen_get_default());
			myStringHeight = pango_font_description_get_size(myFontDescription) * resolution / 72 / PANGO_SCALE + 2;
		}
#else // GTK_CHECK_VERSION(2,10,0)
		myStringHeight = pango_font_description_get_size(myFontDescription) / PANGO_SCALE + 2;
#endif // GTK_CHECK_VERSION(2,10,0)
	}
	return myStringHeight;
}
Exemplo n.º 9
0
static void
gnm_font_button_take_font_desc (GnmFontButton        *font_button,
                                PangoFontDescription *font_desc)
{
  GnmFontButtonPrivate *priv = font_button->priv;
  GObject *object = G_OBJECT (font_button);

  if (priv->font_desc && font_desc &&
      pango_font_description_equal (priv->font_desc, font_desc))
    {
      pango_font_description_free (font_desc);
      return;
    }

  g_object_freeze_notify (object);

  clear_font_data (font_button);

  if (font_desc)
    priv->font_desc = font_desc; /* adopted */
  else
    priv->font_desc = pango_font_description_from_string (_("Sans 12"));

  if (pango_font_description_get_size_is_absolute (priv->font_desc))
    priv->font_size = pango_font_description_get_size (priv->font_desc);
  else
    priv->font_size = pango_font_description_get_size (priv->font_desc) / PANGO_SCALE;

  gnm_font_button_update_font_data (font_button);
  gnm_font_button_update_font_info (font_button);

  if (priv->font_dialog)
    gtk_font_chooser_set_font_desc (GTK_FONT_CHOOSER (priv->font_dialog),
                                    priv->font_desc);

  g_object_notify (G_OBJECT (font_button), "font");
  g_object_notify (G_OBJECT (font_button), "font-desc");
  g_object_notify (G_OBJECT (font_button), "font-name");

  g_object_thaw_notify (object);
}
Exemplo n.º 10
0
static void
gtk_font_button_update_font_info (GtkFontButton *font_button)
{
  GtkFontButtonPrivate *priv = font_button->priv;
  const gchar *fam_name;
  const gchar *face_name;
  gchar *family_style;

  if (priv->font_family)
    fam_name = pango_font_family_get_name (priv->font_family);
  else
    fam_name = C_("font", "None");
  if (priv->font_face)
    face_name = pango_font_face_get_face_name (priv->font_face);
  else
    face_name = "";

  if (priv->show_style)
    family_style = g_strconcat (fam_name, " ", face_name, NULL);
  else
    family_style = g_strdup (fam_name);

  gtk_label_set_text (GTK_LABEL (font_button->priv->font_label), family_style);
  g_free (family_style);

  if (font_button->priv->show_size) 
    {
      /* mirror Pango, which doesn't translate this either */
      gchar *size = g_strdup_printf ("%2.4g%s",
                                     pango_font_description_get_size (priv->font_desc) / (double)PANGO_SCALE,
                                     pango_font_description_get_size_is_absolute (priv->font_desc) ? "px" : "");
      
      gtk_label_set_text (GTK_LABEL (font_button->priv->size_label), size);
      
      g_free (size);
    }

  gtk_font_button_label_use_font (font_button);
} 
Exemplo n.º 11
0
static void
gnm_font_button_update_font_info (GnmFontButton *font_button)
{
  GnmFontButtonPrivate *priv = font_button->priv;
  gchar *family_style;

  g_assert (priv->font_desc != NULL);

  if (priv->show_style)
    {
      PangoFontDescription *desc = pango_font_description_copy_static (priv->font_desc);

      pango_font_description_unset_fields (desc, PANGO_FONT_MASK_SIZE);
      family_style = pango_font_description_to_string (desc);
      pango_font_description_free (desc);
    }
  else
    family_style = g_strdup (pango_font_description_get_family (priv->font_desc));

  gtk_label_set_text (GTK_LABEL (font_button->priv->font_label), family_style);
  g_free (family_style);

  if (font_button->priv->show_size)
    {
      /* mirror Pango, which doesn't translate this either */
      gchar *size = g_strdup_printf ("%g%s",
                                     pango_font_description_get_size (priv->font_desc) / (double)PANGO_SCALE,
                                     pango_font_description_get_size_is_absolute (priv->font_desc) ? "px" : "");

      gtk_label_set_text (GTK_LABEL (font_button->priv->size_label), size);

      g_free (size);
    }

  gnm_font_button_label_use_font (font_button);
}
Exemplo n.º 12
0
static void
webkit_pref_callback_font_size (GSettings  *settings,
                                const char *key,
                                gpointer    data)
{
  char *webkit_pref = data;
  char *value = NULL;
  int size = 9; /* FIXME: What to use here? */

  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;

    desc = pango_font_description_from_string (value);
    size = pango_font_description_get_size (desc);
    if (pango_font_description_get_size_is_absolute (desc) == FALSE)
      size /= PANGO_SCALE;
    pango_font_description_free (desc);
  }

  g_object_set (webkit_settings, webkit_pref, webkit_settings_font_size_to_pixels (size), NULL);
  g_free (value);
}
static void
mx_label_font_description_cb (ClutterText *text,
                              GParamSpec  *pspec,
                              MxLabel     *self)
{
  PangoFontDescription *font;

  MxLabelPrivate *priv = self->priv;

  /* Find out the em-width - code pretty much copied from Clutter,
   * clutter-backend.c, get_units_per_em ()
   */
  font = clutter_text_get_font_description (text);
  if (font)
    {
      gint i_dpi;
      gdouble dpi;

      gdouble font_size = 0;
      gint pango_size = pango_font_description_get_size (font);
      ClutterSettings *settings = clutter_settings_get_default ();

      g_object_get (G_OBJECT (settings), "font-dpi", &i_dpi, NULL);
      dpi = i_dpi / 1024.0;

      if (pango_font_description_get_size_is_absolute (font))
        font_size = pango_size / PANGO_SCALE;
      else
        font_size = pango_size / PANGO_SCALE * dpi / 96.f;

      priv->em_width = (1.2f * font_size) * dpi / 96.f;

      mx_fade_effect_set_border (MX_FADE_EFFECT (priv->fade_effect),
                                 0, priv->em_width * 5, 0, 0);
    }
}
Exemplo n.º 14
0
static inline gboolean
MOZ_pango_font_description_get_size_is_absolute(PangoFontDescription *desc)
{
    pango_font_description_get_size_is_absolute(desc);
}