2011-12-19 21:11:20 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2011 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2011-12-19 21:11:20 +00:00
|
|
|
*
|
|
|
|
* Authors: Benjamin Otte <otte@gnome.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkcssimageprivate.h"
|
|
|
|
|
2014-10-22 21:41:50 +00:00
|
|
|
#include "gtkcssstyleprivate.h"
|
2018-03-11 05:29:46 +00:00
|
|
|
#include "gtksnapshot.h"
|
2012-09-28 16:02:46 +00:00
|
|
|
|
2011-12-20 07:00:34 +00:00
|
|
|
/* for the types only */
|
2012-04-02 01:25:30 +00:00
|
|
|
#include "gtk/gtkcssimagecrossfadeprivate.h"
|
2014-05-01 17:50:22 +00:00
|
|
|
#include "gtk/gtkcssimageiconthemeprivate.h"
|
2012-01-16 17:28:58 +00:00
|
|
|
#include "gtk/gtkcssimagelinearprivate.h"
|
2015-12-27 07:03:35 +00:00
|
|
|
#include "gtk/gtkcssimageradialprivate.h"
|
2011-12-20 07:00:34 +00:00
|
|
|
#include "gtk/gtkcssimageurlprivate.h"
|
2013-06-27 16:29:38 +00:00
|
|
|
#include "gtk/gtkcssimagescaledprivate.h"
|
2016-01-14 18:48:43 +00:00
|
|
|
#include "gtk/gtkcssimagerecolorprivate.h"
|
2016-01-30 01:23:27 +00:00
|
|
|
#include "gtk/gtkcssimagefallbackprivate.h"
|
2011-12-20 13:44:53 +00:00
|
|
|
#include "gtk/gtkcssimagewin32private.h"
|
2011-12-20 07:00:34 +00:00
|
|
|
|
2011-12-19 21:11:20 +00:00
|
|
|
G_DEFINE_ABSTRACT_TYPE (GtkCssImage, _gtk_css_image, G_TYPE_OBJECT)
|
|
|
|
|
|
|
|
static int
|
|
|
|
gtk_css_image_real_get_width (GtkCssImage *image)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gtk_css_image_real_get_height (GtkCssImage *image)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static double
|
|
|
|
gtk_css_image_real_get_aspect_ratio (GtkCssImage *image)
|
|
|
|
{
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
width = _gtk_css_image_get_width (image);
|
|
|
|
height = _gtk_css_image_get_height (image);
|
|
|
|
|
|
|
|
if (width && height)
|
|
|
|
return (double) width / height;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkCssImage *
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_css_image_real_compute (GtkCssImage *image,
|
|
|
|
guint property_id,
|
|
|
|
GtkStyleProvider *provider,
|
|
|
|
GtkCssStyle *style,
|
|
|
|
GtkCssStyle *parent_style)
|
2011-12-19 21:11:20 +00:00
|
|
|
{
|
|
|
|
return g_object_ref (image);
|
|
|
|
}
|
|
|
|
|
2012-10-11 10:10:20 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_image_real_equal (GtkCssImage *image1,
|
|
|
|
GtkCssImage *image2)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-10-02 17:23:29 +00:00
|
|
|
static GtkCssImage *
|
2012-10-02 09:31:36 +00:00
|
|
|
gtk_css_image_real_transition (GtkCssImage *start,
|
|
|
|
GtkCssImage *end,
|
|
|
|
guint property_id,
|
|
|
|
double progress)
|
|
|
|
{
|
2012-10-02 09:33:11 +00:00
|
|
|
if (progress <= 0.0)
|
|
|
|
return g_object_ref (start);
|
|
|
|
else if (progress >= 1.0)
|
|
|
|
return end ? g_object_ref (end) : NULL;
|
2015-08-02 19:35:45 +00:00
|
|
|
else if (_gtk_css_image_equal (start, end))
|
|
|
|
return g_object_ref (start);
|
2012-10-02 09:33:11 +00:00
|
|
|
else
|
|
|
|
return _gtk_css_image_cross_fade_new (start, end, progress);
|
2012-10-02 09:31:36 +00:00
|
|
|
}
|
|
|
|
|
2018-02-17 19:31:14 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_image_real_is_invalid (GtkCssImage *image)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-02-13 06:04:21 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_image_real_is_dynamic (GtkCssImage *image)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkCssImage *
|
|
|
|
gtk_css_image_real_get_dynamic_image (GtkCssImage *image,
|
|
|
|
gint64 monotonic_time)
|
|
|
|
{
|
|
|
|
return g_object_ref (image);
|
|
|
|
}
|
|
|
|
|
2011-12-19 21:11:20 +00:00
|
|
|
static void
|
|
|
|
_gtk_css_image_class_init (GtkCssImageClass *klass)
|
|
|
|
{
|
|
|
|
klass->get_width = gtk_css_image_real_get_width;
|
|
|
|
klass->get_height = gtk_css_image_real_get_height;
|
|
|
|
klass->get_aspect_ratio = gtk_css_image_real_get_aspect_ratio;
|
|
|
|
klass->compute = gtk_css_image_real_compute;
|
2012-10-11 10:10:20 +00:00
|
|
|
klass->equal = gtk_css_image_real_equal;
|
2012-10-02 09:31:36 +00:00
|
|
|
klass->transition = gtk_css_image_real_transition;
|
2018-02-17 19:31:14 +00:00
|
|
|
klass->is_invalid = gtk_css_image_real_is_invalid;
|
2018-02-13 06:04:21 +00:00
|
|
|
klass->is_dynamic = gtk_css_image_real_is_dynamic;
|
|
|
|
klass->get_dynamic_image = gtk_css_image_real_get_dynamic_image;
|
2011-12-19 21:11:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_css_image_init (GtkCssImage *image)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_gtk_css_image_get_width (GtkCssImage *image)
|
|
|
|
{
|
|
|
|
GtkCssImageClass *klass;
|
|
|
|
|
|
|
|
klass = GTK_CSS_IMAGE_GET_CLASS (image);
|
|
|
|
|
|
|
|
return klass->get_width (image);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_gtk_css_image_get_height (GtkCssImage *image)
|
|
|
|
{
|
|
|
|
GtkCssImageClass *klass;
|
|
|
|
|
|
|
|
klass = GTK_CSS_IMAGE_GET_CLASS (image);
|
|
|
|
|
|
|
|
return klass->get_height (image);
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
_gtk_css_image_get_aspect_ratio (GtkCssImage *image)
|
|
|
|
{
|
|
|
|
GtkCssImageClass *klass;
|
|
|
|
|
|
|
|
klass = GTK_CSS_IMAGE_GET_CLASS (image);
|
|
|
|
|
|
|
|
return klass->get_aspect_ratio (image);
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkCssImage *
|
2017-10-31 03:31:46 +00:00
|
|
|
_gtk_css_image_compute (GtkCssImage *image,
|
|
|
|
guint property_id,
|
|
|
|
GtkStyleProvider *provider,
|
|
|
|
GtkCssStyle *style,
|
|
|
|
GtkCssStyle *parent_style)
|
2011-12-19 21:11:20 +00:00
|
|
|
{
|
|
|
|
GtkCssImageClass *klass;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), NULL);
|
2015-01-31 10:56:15 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_CSS_STYLE (style), NULL);
|
|
|
|
g_return_val_if_fail (parent_style == NULL || GTK_IS_CSS_STYLE (parent_style), NULL);
|
2011-12-19 21:11:20 +00:00
|
|
|
|
|
|
|
klass = GTK_CSS_IMAGE_GET_CLASS (image);
|
|
|
|
|
2015-02-14 01:27:39 +00:00
|
|
|
return klass->compute (image, property_id, provider, style, parent_style);
|
2011-12-19 21:11:20 +00:00
|
|
|
}
|
|
|
|
|
2012-10-02 09:31:36 +00:00
|
|
|
GtkCssImage *
|
|
|
|
_gtk_css_image_transition (GtkCssImage *start,
|
|
|
|
GtkCssImage *end,
|
|
|
|
guint property_id,
|
|
|
|
double progress)
|
|
|
|
{
|
|
|
|
GtkCssImageClass *klass;
|
|
|
|
|
|
|
|
g_return_val_if_fail (start == NULL || GTK_IS_CSS_IMAGE (start), NULL);
|
|
|
|
g_return_val_if_fail (end == NULL || GTK_IS_CSS_IMAGE (end), NULL);
|
|
|
|
|
|
|
|
progress = CLAMP (progress, 0.0, 1.0);
|
|
|
|
|
|
|
|
if (start == NULL)
|
|
|
|
{
|
|
|
|
if (end == NULL)
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
start = end;
|
|
|
|
end = NULL;
|
|
|
|
progress = 1.0 - progress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
klass = GTK_CSS_IMAGE_GET_CLASS (start);
|
|
|
|
|
|
|
|
return klass->transition (start, end, property_id, progress);
|
|
|
|
}
|
|
|
|
|
2012-10-11 10:10:20 +00:00
|
|
|
gboolean
|
|
|
|
_gtk_css_image_equal (GtkCssImage *image1,
|
|
|
|
GtkCssImage *image2)
|
|
|
|
{
|
|
|
|
GtkCssImageClass *klass;
|
|
|
|
|
|
|
|
g_return_val_if_fail (image1 == NULL || GTK_IS_CSS_IMAGE (image1), FALSE);
|
|
|
|
g_return_val_if_fail (image2 == NULL || GTK_IS_CSS_IMAGE (image2), FALSE);
|
|
|
|
|
|
|
|
if (image1 == image2)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (image1 == NULL || image2 == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (G_OBJECT_TYPE (image1) != G_OBJECT_TYPE (image2))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
klass = GTK_CSS_IMAGE_GET_CLASS (image1);
|
|
|
|
|
|
|
|
return klass->equal (image1, image2);
|
|
|
|
}
|
|
|
|
|
2011-12-19 21:11:20 +00:00
|
|
|
void
|
|
|
|
_gtk_css_image_draw (GtkCssImage *image,
|
|
|
|
cairo_t *cr,
|
|
|
|
double width,
|
|
|
|
double height)
|
|
|
|
{
|
2018-03-11 02:14:09 +00:00
|
|
|
GtkSnapshot *snapshot;
|
2018-02-14 01:30:42 +00:00
|
|
|
GskRenderNode *node;
|
2011-12-19 21:11:20 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CSS_IMAGE (image));
|
|
|
|
g_return_if_fail (cr != NULL);
|
2012-10-26 23:31:59 +00:00
|
|
|
g_return_if_fail (width > 0);
|
|
|
|
g_return_if_fail (height > 0);
|
2011-12-19 21:11:20 +00:00
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
2018-03-30 13:39:25 +00:00
|
|
|
snapshot = gtk_snapshot_new (FALSE, "Fallback<%s>", G_OBJECT_TYPE_NAME (image));
|
2018-03-11 02:14:09 +00:00
|
|
|
gtk_css_image_snapshot (image, snapshot, width, height);
|
|
|
|
node = gtk_snapshot_free_to_node (snapshot);
|
2018-02-14 01:30:42 +00:00
|
|
|
|
|
|
|
if (node != NULL)
|
|
|
|
{
|
|
|
|
gsk_render_node_draw (node, cr);
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
}
|
2011-12-19 21:11:20 +00:00
|
|
|
|
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
|
|
|
|
2016-11-16 19:51:53 +00:00
|
|
|
void
|
|
|
|
gtk_css_image_snapshot (GtkCssImage *image,
|
|
|
|
GtkSnapshot *snapshot,
|
|
|
|
double width,
|
|
|
|
double height)
|
|
|
|
{
|
|
|
|
GtkCssImageClass *klass;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CSS_IMAGE (image));
|
|
|
|
g_return_if_fail (snapshot != NULL);
|
|
|
|
g_return_if_fail (width > 0);
|
|
|
|
g_return_if_fail (height > 0);
|
|
|
|
|
|
|
|
klass = GTK_CSS_IMAGE_GET_CLASS (image);
|
|
|
|
|
|
|
|
klass->snapshot (image, snapshot, width, height);
|
|
|
|
}
|
|
|
|
|
2018-02-17 19:31:14 +00:00
|
|
|
gboolean
|
|
|
|
gtk_css_image_is_invalid (GtkCssImage *image)
|
|
|
|
{
|
|
|
|
GtkCssImageClass *klass;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), FALSE);
|
|
|
|
|
|
|
|
klass = GTK_CSS_IMAGE_GET_CLASS (image);
|
|
|
|
|
|
|
|
return klass->is_invalid (image);
|
|
|
|
}
|
|
|
|
|
2018-02-13 06:04:21 +00:00
|
|
|
gboolean
|
|
|
|
gtk_css_image_is_dynamic (GtkCssImage *image)
|
|
|
|
{
|
|
|
|
GtkCssImageClass *klass;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), FALSE);
|
|
|
|
|
|
|
|
klass = GTK_CSS_IMAGE_GET_CLASS (image);
|
|
|
|
|
|
|
|
return klass->is_dynamic (image);
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkCssImage *
|
|
|
|
gtk_css_image_get_dynamic_image (GtkCssImage *image,
|
|
|
|
gint64 monotonic_time)
|
|
|
|
{
|
|
|
|
GtkCssImageClass *klass;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), NULL);
|
|
|
|
|
|
|
|
klass = GTK_CSS_IMAGE_GET_CLASS (image);
|
|
|
|
|
|
|
|
return klass->get_dynamic_image (image, monotonic_time);
|
|
|
|
}
|
|
|
|
|
2011-12-19 21:11:20 +00:00
|
|
|
void
|
|
|
|
_gtk_css_image_print (GtkCssImage *image,
|
|
|
|
GString *string)
|
|
|
|
{
|
|
|
|
GtkCssImageClass *klass;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CSS_IMAGE (image));
|
|
|
|
g_return_if_fail (string != NULL);
|
|
|
|
|
|
|
|
klass = GTK_CSS_IMAGE_GET_CLASS (image);
|
|
|
|
|
|
|
|
klass->print (image, string);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:40:16 +00:00
|
|
|
/* Applies the algorithm outlined in
|
|
|
|
* http://dev.w3.org/csswg/css3-images/#default-sizing
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
_gtk_css_image_get_concrete_size (GtkCssImage *image,
|
|
|
|
double specified_width,
|
|
|
|
double specified_height,
|
|
|
|
double default_width,
|
|
|
|
double default_height,
|
|
|
|
double *concrete_width,
|
|
|
|
double *concrete_height)
|
|
|
|
{
|
|
|
|
double image_width, image_height, image_aspect;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CSS_IMAGE (image));
|
|
|
|
g_return_if_fail (specified_width >= 0);
|
|
|
|
g_return_if_fail (specified_height >= 0);
|
|
|
|
g_return_if_fail (default_width > 0);
|
|
|
|
g_return_if_fail (default_height > 0);
|
|
|
|
g_return_if_fail (concrete_width != NULL);
|
|
|
|
g_return_if_fail (concrete_height != NULL);
|
|
|
|
|
|
|
|
/* If the specified size is a definite width and height,
|
|
|
|
* the concrete object size is given that width and height.
|
|
|
|
*/
|
|
|
|
if (specified_width && specified_height)
|
|
|
|
{
|
|
|
|
*concrete_width = specified_width;
|
|
|
|
*concrete_height = specified_height;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
image_width = _gtk_css_image_get_width (image);
|
|
|
|
image_height = _gtk_css_image_get_height (image);
|
|
|
|
image_aspect = _gtk_css_image_get_aspect_ratio (image);
|
|
|
|
|
|
|
|
/* If the specified size has neither a definite width nor height,
|
|
|
|
* and has no additional contraints, the dimensions of the concrete
|
|
|
|
* object size are calculated as follows:
|
|
|
|
*/
|
|
|
|
if (specified_width == 0.0 && specified_height == 0.0)
|
|
|
|
{
|
|
|
|
/* If the object has only an intrinsic aspect ratio,
|
|
|
|
* the concrete object size must have that aspect ratio,
|
|
|
|
* and additionally be as large as possible without either
|
|
|
|
* its height or width exceeding the height or width of the
|
|
|
|
* default object size.
|
|
|
|
*/
|
|
|
|
if (image_aspect > 0 && image_width == 0 && image_height == 0)
|
|
|
|
{
|
|
|
|
if (image_aspect * default_height > default_width)
|
|
|
|
{
|
2017-01-13 02:28:34 +00:00
|
|
|
*concrete_width = default_width;
|
|
|
|
*concrete_height = default_width / image_aspect;
|
2011-12-21 16:40:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-13 02:28:34 +00:00
|
|
|
*concrete_width = default_height * image_aspect;
|
|
|
|
*concrete_height = default_height;
|
2011-12-21 16:40:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2014-07-23 16:40:55 +00:00
|
|
|
{
|
|
|
|
/* Otherwise, the width and height of the concrete object
|
|
|
|
* size is the same as the object's intrinsic width and
|
|
|
|
* intrinsic height, if they exist.
|
|
|
|
* If the concrete object size is still missing a width or
|
|
|
|
* height, and the object has an intrinsic aspect ratio,
|
|
|
|
* the missing dimension is calculated from the present
|
|
|
|
* dimension and the intrinsic aspect ratio.
|
|
|
|
* Otherwise, the missing dimension is taken from the default
|
|
|
|
* object size.
|
|
|
|
*/
|
|
|
|
if (image_width)
|
|
|
|
*concrete_width = image_width;
|
|
|
|
else if (image_aspect)
|
|
|
|
*concrete_width = image_height * image_aspect;
|
|
|
|
else
|
|
|
|
*concrete_width = default_width;
|
2011-12-21 16:40:16 +00:00
|
|
|
|
2014-07-23 16:40:55 +00:00
|
|
|
if (image_height)
|
|
|
|
*concrete_height = image_height;
|
|
|
|
else if (image_aspect)
|
|
|
|
*concrete_height = image_width / image_aspect;
|
|
|
|
else
|
|
|
|
*concrete_height = default_height;
|
|
|
|
}
|
2011-12-21 16:40:16 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the specified size has only a width or height, but not both,
|
|
|
|
* then the concrete object size is given that specified width or height.
|
|
|
|
* The other dimension is calculated as follows:
|
|
|
|
* If the object has an intrinsic aspect ratio, the missing dimension of
|
|
|
|
* the concrete object size is calculated using the intrinsic aspect-ratio
|
|
|
|
* and the present dimension.
|
|
|
|
* Otherwise, if the missing dimension is present in the object's intrinsic
|
|
|
|
* dimensions, the missing dimension is taken from the object's intrinsic
|
|
|
|
* dimensions.
|
|
|
|
* Otherwise, the missing dimension of the concrete object size is taken
|
|
|
|
* from the default object size.
|
|
|
|
*/
|
|
|
|
if (specified_width)
|
|
|
|
{
|
|
|
|
*concrete_width = specified_width;
|
|
|
|
if (image_aspect)
|
|
|
|
*concrete_height = specified_width / image_aspect;
|
|
|
|
else if (image_height)
|
|
|
|
*concrete_height = image_height;
|
|
|
|
else
|
|
|
|
*concrete_height = default_height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*concrete_height = specified_height;
|
|
|
|
if (image_aspect)
|
|
|
|
*concrete_width = specified_height * image_aspect;
|
|
|
|
else if (image_width)
|
|
|
|
*concrete_width = image_width;
|
|
|
|
else
|
|
|
|
*concrete_width = default_width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_surface_t *
|
|
|
|
_gtk_css_image_get_surface (GtkCssImage *image,
|
|
|
|
cairo_surface_t *target,
|
|
|
|
int surface_width,
|
|
|
|
int surface_height)
|
|
|
|
{
|
|
|
|
cairo_surface_t *result;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), NULL);
|
|
|
|
g_return_val_if_fail (surface_width > 0, NULL);
|
|
|
|
g_return_val_if_fail (surface_height > 0, NULL);
|
|
|
|
|
|
|
|
if (target)
|
2015-11-21 05:20:48 +00:00
|
|
|
result = cairo_surface_create_similar (target,
|
|
|
|
CAIRO_CONTENT_COLOR_ALPHA,
|
|
|
|
surface_width,
|
|
|
|
surface_height);
|
2011-12-21 16:40:16 +00:00
|
|
|
else
|
|
|
|
result = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
|
|
|
|
surface_width,
|
|
|
|
surface_height);
|
|
|
|
|
|
|
|
cr = cairo_create (result);
|
|
|
|
_gtk_css_image_draw (image, cr, surface_width, surface_height);
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-10-02 17:23:29 +00:00
|
|
|
static GType
|
2012-01-04 17:42:38 +00:00
|
|
|
gtk_css_image_get_parser_type (GtkCssParser *parser)
|
2011-12-19 21:11:20 +00:00
|
|
|
{
|
2011-12-20 07:52:54 +00:00
|
|
|
static const struct {
|
|
|
|
const char *prefix;
|
|
|
|
GType (* type_func) (void);
|
|
|
|
} image_types[] = {
|
2011-12-20 13:46:19 +00:00
|
|
|
{ "url", _gtk_css_image_url_get_type },
|
2014-05-01 17:50:22 +00:00
|
|
|
{ "-gtk-icontheme", _gtk_css_image_icon_theme_get_type },
|
2013-06-27 16:29:38 +00:00
|
|
|
{ "-gtk-scaled", _gtk_css_image_scaled_get_type },
|
2016-01-14 18:48:43 +00:00
|
|
|
{ "-gtk-recolor", _gtk_css_image_recolor_get_type },
|
2012-01-16 17:28:58 +00:00
|
|
|
{ "-gtk-win32-theme-part", _gtk_css_image_win32_get_type },
|
2012-01-17 10:44:07 +00:00
|
|
|
{ "linear-gradient", _gtk_css_image_linear_get_type },
|
2012-04-02 01:25:30 +00:00
|
|
|
{ "repeating-linear-gradient", _gtk_css_image_linear_get_type },
|
2015-12-27 07:03:35 +00:00
|
|
|
{ "radial-gradient", _gtk_css_image_radial_get_type },
|
|
|
|
{ "repeating-radial-gradient", _gtk_css_image_radial_get_type },
|
2016-01-30 01:23:27 +00:00
|
|
|
{ "cross-fade", _gtk_css_image_cross_fade_get_type },
|
|
|
|
{ "image", _gtk_css_image_fallback_get_type }
|
2011-12-20 07:52:54 +00:00
|
|
|
};
|
|
|
|
guint i;
|
2011-12-19 21:11:20 +00:00
|
|
|
|
2011-12-20 07:52:54 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (image_types); i++)
|
2011-12-19 21:11:20 +00:00
|
|
|
{
|
2011-12-20 07:52:54 +00:00
|
|
|
if (_gtk_css_parser_has_prefix (parser, image_types[i].prefix))
|
2012-01-04 17:42:38 +00:00
|
|
|
return image_types[i].type_func ();
|
|
|
|
}
|
2011-12-20 07:52:54 +00:00
|
|
|
|
2012-01-04 17:42:38 +00:00
|
|
|
return G_TYPE_INVALID;
|
|
|
|
}
|
2011-12-20 07:52:54 +00:00
|
|
|
|
2012-01-04 17:42:38 +00:00
|
|
|
/**
|
|
|
|
* _gtk_css_image_can_parse:
|
|
|
|
* @parser: a css parser
|
|
|
|
*
|
|
|
|
* Checks if the parser can potentially parse the given stream as an
|
|
|
|
* image from looking at the first token of @parser. This is useful for
|
|
|
|
* implementing shorthand properties. A successful parse of an image
|
|
|
|
* can not be guaranteed.
|
|
|
|
*
|
|
|
|
* Returns: %TURE if it looks like an image.
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
_gtk_css_image_can_parse (GtkCssParser *parser)
|
|
|
|
{
|
|
|
|
return gtk_css_image_get_parser_type (parser) != G_TYPE_INVALID;
|
|
|
|
}
|
2011-12-20 07:52:54 +00:00
|
|
|
|
2012-01-04 17:42:38 +00:00
|
|
|
GtkCssImage *
|
2012-04-18 19:44:08 +00:00
|
|
|
_gtk_css_image_new_parse (GtkCssParser *parser)
|
2012-01-04 17:42:38 +00:00
|
|
|
{
|
|
|
|
GtkCssImageClass *klass;
|
|
|
|
GtkCssImage *image;
|
|
|
|
GType image_type;
|
|
|
|
|
|
|
|
g_return_val_if_fail (parser != NULL, NULL);
|
|
|
|
|
|
|
|
image_type = gtk_css_image_get_parser_type (parser);
|
|
|
|
if (image_type == G_TYPE_INVALID)
|
|
|
|
{
|
|
|
|
_gtk_css_parser_error (parser, "Not a valid image");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
image = g_object_new (image_type, NULL);
|
|
|
|
|
|
|
|
klass = GTK_CSS_IMAGE_GET_CLASS (image);
|
2012-04-18 19:44:08 +00:00
|
|
|
if (!klass->parse (image, parser))
|
2012-01-04 17:42:38 +00:00
|
|
|
{
|
|
|
|
g_object_unref (image);
|
|
|
|
return NULL;
|
2011-12-19 21:11:20 +00:00
|
|
|
}
|
|
|
|
|
2012-01-04 17:42:38 +00:00
|
|
|
return image;
|
2011-12-19 21:11:20 +00:00
|
|
|
}
|
|
|
|
|