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;
}
示例#2
0
static gfloat
units_pt_to_pixels (gfloat pt)
{
  ClutterBackend *backend;
  gdouble dpi;

  backend = clutter_get_default_backend ();
  dpi = clutter_backend_get_resolution (backend);
  if (dpi < 0)
    dpi = DPI_FALLBACK;

  return pt * dpi / 72.0;
}
示例#3
0
static gfloat
units_mm_to_pixels (gfloat mm)
{
  ClutterBackend *backend;
  gdouble dpi;

  backend = clutter_get_default_backend ();
  dpi = clutter_backend_get_resolution (backend);
  if (dpi < 0)
    dpi = DPI_FALLBACK;

  return mm * dpi / 25.4;
}
示例#4
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);
}
示例#5
0
static gboolean
clutter_backend_x11_post_parse (ClutterBackend  *backend,
                                GError         **error)
{
  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
  ClutterSettings *settings;
  Atom atoms[N_ATOM_NAMES];
  double dpi;

  if (_foreign_dpy)
    backend_x11->xdpy = _foreign_dpy;

  /* Only open connection if not already set by prior call to
   * clutter_x11_set_display()
   */
  if (backend_x11->xdpy == NULL)
    {
      if (clutter_display_name != NULL &&
          *clutter_display_name != '\0')
	{
	  CLUTTER_NOTE (BACKEND, "XOpenDisplay on '%s'", clutter_display_name);

	  backend_x11->xdpy = XOpenDisplay (clutter_display_name);
          if (backend_x11->xdpy == NULL)
            {
              g_set_error (error, CLUTTER_INIT_ERROR,
                           CLUTTER_INIT_ERROR_BACKEND,
                           "Unable to open display '%s'",
                           clutter_display_name);
              return FALSE;
            }
	}
      else
	{
	  g_set_error_literal (error, CLUTTER_INIT_ERROR,
                               CLUTTER_INIT_ERROR_BACKEND,
                               "Unable to open display. You have to set the "
                               "DISPLAY environment variable, or use the "
                               "--display command line argument");
	  return FALSE;
	}
    }

  g_assert (backend_x11->xdpy != NULL);

  CLUTTER_NOTE (BACKEND, "Getting the X screen");

  settings = clutter_settings_get_default ();

  /* add event filter for Cogl events */
  clutter_x11_add_filter (cogl_xlib_filter, backend);

  if (clutter_screen == -1)
    backend_x11->xscreen = DefaultScreenOfDisplay (backend_x11->xdpy);
  else
    backend_x11->xscreen = ScreenOfDisplay (backend_x11->xdpy,
                                            clutter_screen);

  backend_x11->xscreen_num = XScreenNumberOfScreen (backend_x11->xscreen);
  backend_x11->xscreen_width = WidthOfScreen (backend_x11->xscreen);
  backend_x11->xscreen_height = HeightOfScreen (backend_x11->xscreen);

  backend_x11->xwin_root = RootWindow (backend_x11->xdpy,
                                       backend_x11->xscreen_num);

  backend_x11->display_name = g_strdup (clutter_display_name);

  dpi = (((double) DisplayHeight (backend_x11->xdpy, backend_x11->xscreen_num) * 25.4)
      / (double) DisplayHeightMM (backend_x11->xdpy, backend_x11->xscreen_num));

  g_object_set (settings, "font-dpi", (int) dpi * 1024, NULL);

  /* create XSETTINGS client */
  backend_x11->xsettings =
    _clutter_xsettings_client_new (backend_x11->xdpy,
                                   backend_x11->xscreen_num,
                                   clutter_backend_x11_xsettings_notify,
                                   NULL,
                                   backend_x11);

  /* add event filter for XSETTINGS events */
  clutter_x11_add_filter (xsettings_filter, backend_x11);

  if (clutter_synchronise)
    XSynchronize (backend_x11->xdpy, True);

  XInternAtoms (backend_x11->xdpy,
                (char **) atom_names, N_ATOM_NAMES,
                False, atoms);

  backend_x11->atom_NET_WM_PID = atoms[0];
  backend_x11->atom_NET_WM_PING = atoms[1];
  backend_x11->atom_NET_WM_STATE = atoms[2];
  backend_x11->atom_NET_WM_STATE_FULLSCREEN = atoms[3];
  backend_x11->atom_NET_WM_USER_TIME = atoms[4];
  backend_x11->atom_WM_PROTOCOLS = atoms[5];
  backend_x11->atom_WM_DELETE_WINDOW = atoms[6];
  backend_x11->atom_XEMBED = atoms[7];
  backend_x11->atom_XEMBED_INFO = atoms[8];
  backend_x11->atom_NET_WM_NAME = atoms[9];
  backend_x11->atom_UTF8_STRING = atoms[10];

  g_free (clutter_display_name);

  CLUTTER_NOTE (BACKEND,
                "X Display '%s'[%p] opened (screen:%d, root:%u, dpi:%f)",
                backend_x11->display_name,
                backend_x11->xdpy,
                backend_x11->xscreen_num,
                (unsigned int) backend_x11->xwin_root,
                clutter_backend_get_resolution (backend));

  return TRUE;
}