static void
clutter_backend_real_resolution_changed (ClutterBackend *backend)
{
  ClutterBackendPrivate *priv = backend->priv;
  ClutterMainContext *context;
  ClutterSettings *settings;
  gdouble resolution;
  gint dpi;

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

  if (dpi < 0)
    resolution = 96.0;
  else
    resolution = dpi / 1024.0;

  context = _clutter_context_get_default ();
  if (context->font_map != NULL)
    cogl_pango_font_map_set_resolution (context->font_map, resolution);

  priv->units_per_em = get_units_per_em (backend, NULL);
  priv->units_serial += 1;

  CLUTTER_NOTE (BACKEND, "Units per em: %.2f", priv->units_per_em);
}
Esempio n. 2
0
static void
update_fps (ClutterActor *stage,
            GTimer       *timer)
{
  static PangoLayout *layout = NULL;
  static guint counter = 0;
  static CoglColor white;
  gdouble resolution;
  gchar *text;

  if (!layout)
    {
      PangoFontDescription *pango_font_desc;
      CoglPangoFontMap *pango_font_map;
      PangoContext *pango_context;

      cogl_color_set_from_4ub (&white, 0xff, 0xff, 0xff, 0xff);

      pango_font_map = COGL_PANGO_FONT_MAP (cogl_pango_font_map_new());

      resolution = clutter_backend_get_resolution (clutter_get_default_backend ());

      cogl_pango_font_map_set_resolution (pango_font_map, resolution);
      cogl_pango_font_map_set_use_mipmapping (pango_font_map, TRUE);

      pango_context = cogl_pango_font_map_create_context (pango_font_map);

      pango_font_desc = pango_font_description_new ();
      pango_font_description_set_family (pango_font_desc, "Sans");
      pango_font_description_set_size (pango_font_desc, 30 * PANGO_SCALE);

      layout = pango_layout_new (pango_context);
      pango_layout_set_font_description (layout, pango_font_desc);

      pango_font_description_free (pango_font_desc);
      g_object_unref (pango_context);
    }

  if (g_timer_elapsed (timer, NULL) > 0.5)
    {
      text = g_strdup_printf ("%dfps", counter * 2);
      pango_layout_set_text (layout, text, -1);
      g_free (text);
      g_timer_start (timer);
      counter = 0;
    }
  else
    counter++;

  cogl_pango_render_layout (layout, 0, 0, &white, 0);
}
Esempio n. 3
0
/**
 * clutter_backend_set_resolution:
 * @backend: a #ClutterBackend
 * @dpi: the resolution in "dots per inch" (Physical inches aren't
 *   actually involved; the terminology is conventional).
 *
 * Sets the resolution for font handling on the screen. This is a
 * scale factor between points specified in a #PangoFontDescription
 * and cairo units. The default value is 96, meaning that a 10 point
 * font will be 13 units high. (10 * 96. / 72. = 13.3).
 *
 * Applications should never need to call this function.
 *
 * Since: 0.4
 */
void
clutter_backend_set_resolution (ClutterBackend *backend,
                                gdouble         dpi)
{
  ClutterBackendPrivate *priv;

  g_return_if_fail (CLUTTER_IS_BACKEND (backend));

  priv = backend->priv;

  if (dpi < 0)
    dpi = -1.0;

  priv->resolution = dpi;

  if (CLUTTER_CONTEXT ()->font_map)
    cogl_pango_font_map_set_resolution (CLUTTER_CONTEXT ()->font_map, dpi);

  g_signal_emit (backend, backend_signals[RESOLUTION_CHANGED], 0);
}