예제 #1
0
파일: gtkcssimageurl.c 프로젝트: GNOME/gtk
static gboolean
gtk_css_image_url_equal (GtkCssImage *image1,
                         GtkCssImage *image2)
{
  GtkCssImageUrl *url1 = GTK_CSS_IMAGE_URL (image1);
  GtkCssImageUrl *url2 = GTK_CSS_IMAGE_URL (image2);

  return g_file_equal (url1->file, url2->file);
}
예제 #2
0
static int
gtk_css_image_url_get_height (GtkCssImage *image)
{
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);

  return cairo_image_surface_get_height (url->surface);
}
예제 #3
0
파일: gtkcssimageurl.c 프로젝트: GNOME/gtk
static double
gtk_css_image_url_get_aspect_ratio (GtkCssImage *image)
{
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);

  return _gtk_css_image_get_aspect_ratio (gtk_css_image_url_load_image (url, NULL));
}
예제 #4
0
파일: gtkcssimageurl.c 프로젝트: GNOME/gtk
static int
gtk_css_image_url_get_height (GtkCssImage *image)
{
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);

  return _gtk_css_image_get_height (gtk_css_image_url_load_image (url, NULL));
}
예제 #5
0
파일: gtkcssimageurl.c 프로젝트: GNOME/gtk
static gboolean
gtk_css_image_url_is_invalid (GtkCssImage *image)
{
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);

  return gtk_css_image_is_invalid (gtk_css_image_url_load_image (url, NULL));
}
예제 #6
0
static int
gtk_css_image_url_get_width (GtkCssImage *image)
{
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);

  return _gtk_css_image_get_width (gtk_css_image_url_load_image (url));
}
예제 #7
0
파일: gtkcssimageurl.c 프로젝트: GNOME/gtk
static void
gtk_css_image_url_print (GtkCssImage *image,
                         GString     *string)
{
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);

  _gtk_css_image_print (gtk_css_image_url_load_image (url, NULL), string);
}
예제 #8
0
static gboolean
gtk_css_image_url_parse (GtkCssImage  *image,
                         GtkCssParser *parser)
{
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);
  GdkPixbuf *pixbuf;
  GFile *file;
  cairo_t *cr;
  GError *error = NULL;
  GFileInputStream *input;

  file = _gtk_css_parser_read_url (parser);
  if (file == NULL)
    return FALSE;

  /* We special case resources here so we can use
     gdk_pixbuf_new_from_resource, which in turn has some special casing
     for GdkPixdata files to avoid duplicating the memory for the pixbufs */
  if (g_file_has_uri_scheme (file, "resource"))
    {
      char *uri = g_file_get_uri (file);
      char *resource_path = g_uri_unescape_string (uri + strlen ("resource://"), NULL);

      pixbuf = gdk_pixbuf_new_from_resource (resource_path, &error);
      g_free (resource_path);
      g_free (uri);
    }
  else
    {
      input = g_file_read (file, NULL, &error);
      if (input == NULL)
	{
	  _gtk_css_parser_take_error (parser, error);
	  return FALSE;
	}

      pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (input), NULL, &error);
      g_object_unref (input);
    }
  g_object_unref (file);

  if (pixbuf == NULL)
    {
      _gtk_css_parser_take_error (parser, error);
      return FALSE;
    }

  url->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                             gdk_pixbuf_get_width (pixbuf),
                                             gdk_pixbuf_get_height (pixbuf));
  cr = cairo_create (url->surface);
  gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
  cairo_paint (cr);
  cairo_destroy (cr);
  g_object_unref (pixbuf);

  return TRUE;
}
예제 #9
0
파일: gtkcssimageurl.c 프로젝트: GNOME/gtk
static void
gtk_css_image_url_dispose (GObject *object)
{
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (object);

  g_clear_object (&url->file);
  g_clear_object (&url->loaded_image);

  G_OBJECT_CLASS (_gtk_css_image_url_parent_class)->dispose (object);
}
예제 #10
0
파일: gtkcssimageurl.c 프로젝트: GNOME/gtk
static void
gtk_css_image_url_snapshot (GtkCssImage *image,
                            GtkSnapshot *snapshot,
                            double       width,
                            double       height)
{
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);

  gtk_css_image_snapshot (gtk_css_image_url_load_image (url, NULL), snapshot, width, height);
}
예제 #11
0
static void
gtk_css_image_url_draw (GtkCssImage        *image,
                        cairo_t            *cr,
                        double              width,
                        double              height)
{
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);

  _gtk_css_image_draw (gtk_css_image_url_load_image (url), cr, width, height);
}
예제 #12
0
static gboolean
gtk_css_image_url_parse (GtkCssImage  *image,
                         GtkCssParser *parser)
{
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);

  url->file = _gtk_css_parser_read_url (parser);
  if (url->file == NULL)
    return FALSE;

  return TRUE;
}
예제 #13
0
static GtkCssImage *
gtk_css_image_url_compute (GtkCssImage             *image,
                           guint                    property_id,
                           GtkStyleProviderPrivate *provider,
                           GtkCssComputedValues    *values,
                           GtkCssComputedValues    *parent_values,
                           GtkCssDependencies      *dependencies)
{
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);

  return g_object_ref (gtk_css_image_url_load_image (url));
}
예제 #14
0
파일: gtkcssimageurl.c 프로젝트: GNOME/gtk
static gboolean
gtk_css_image_url_parse (GtkCssImage  *image,
                         GtkCssParser *parser)
{
  GtkCssImageUrl *self = GTK_CSS_IMAGE_URL (image);
  char *url, *scheme;

  url = gtk_css_parser_consume_url (parser);
  if (url == NULL)
    return FALSE;

  scheme = g_uri_parse_scheme (url);
  if (scheme && g_ascii_strcasecmp (scheme, "data") == 0)
    {
      GInputStream *stream;
      GdkPixbuf *pixbuf;
      GBytes *bytes;
      GError *error = NULL;

      bytes = gtk_css_data_url_parse (url, NULL, &error);
      if (bytes)
        {
          stream = g_memory_input_stream_new_from_bytes (bytes);
          pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, &error);
          g_object_unref (stream);
          if (pixbuf == NULL)
            {
              gtk_css_parser_emit_error (parser,
                                         gtk_css_parser_get_start_location (parser),
                                         gtk_css_parser_get_end_location (parser),
                                         error);
              g_clear_error (&error);
            }
          else
            {
              GdkTexture *texture = gdk_texture_new_for_pixbuf (pixbuf);
              self->loaded_image = gtk_css_image_paintable_new (GDK_PAINTABLE (texture), GDK_PAINTABLE (texture));
              g_object_unref (texture);
              g_object_unref (pixbuf);
            }
        }
    }
  else
    {
      self->file = gtk_css_parser_resolve_url (parser, url);
    }

  g_free (url);
  g_free (scheme);

  return TRUE;
}
예제 #15
0
static void
gtk_css_image_url_dispose (GObject *object)
{
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (object);

  if (url->surface)
    {
      cairo_surface_destroy (url->surface);
      url->surface = NULL;
    }

  G_OBJECT_CLASS (_gtk_css_image_url_parent_class)->dispose (object);
}
예제 #16
0
static void
gtk_css_image_url_draw (GtkCssImage        *image,
                        cairo_t            *cr,
                        double              width,
                        double              height)
{
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);

  cairo_rectangle (cr, 0, 0, width, height);
  cairo_scale (cr,
               width / cairo_image_surface_get_width (url->surface),
               height / cairo_image_surface_get_height (url->surface));
  cairo_set_source_surface (cr, url->surface, 0, 0);
  cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_PAD);
  cairo_fill (cr);
}
예제 #17
0
파일: gtkcssimageurl.c 프로젝트: GNOME/gtk
static GtkCssImage *
gtk_css_image_url_compute (GtkCssImage      *image,
                           guint             property_id,
                           GtkStyleProvider *provider,
                           GtkCssStyle      *style,
                           GtkCssStyle      *parent_style)
{
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);
  GtkCssImage *copy;
  GError *error = NULL;

  copy = gtk_css_image_url_load_image (url, &error);
  if (error)
    {
      GtkCssSection *section = gtk_css_style_get_section (style, property_id);
      gtk_style_provider_emit_error (provider, section, error);
      g_error_free (error);
    }

  return g_object_ref (copy);
}
예제 #18
0
static void
gtk_css_image_url_print (GtkCssImage *image,
                         GString     *string)
{
#if CAIRO_HAS_PNG_FUNCTIONS
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);
  GByteArray *array;
  char *base64;
  
  array = g_byte_array_new ();
  cairo_surface_write_to_png_stream (url->surface, surface_write, array);
  base64 = g_base64_encode (array->data, array->len);
  g_byte_array_free (array, TRUE);

  g_string_append (string, "url(\"data:image/png;base64,");
  g_string_append (string, base64);
  g_string_append (string, "\")");

  g_free (base64);
#else
  g_string_append (string, "none /* you need cairo png functions enabled to make this work */");
#endif
}