* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Benjamin Otte <otte@gnome.org>
*/
#include "config.h"
+#include <string.h>
+
#include "gtkcssimageurlprivate.h"
#include "gtkcssprovider.h"
cairo_fill (cr);
}
-static GFile *
-gtk_css_parse_url (GtkCssParser *parser,
- GFile *base)
-{
- gchar *path;
- GFile *file;
-
- if (_gtk_css_parser_try (parser, "url", FALSE))
- {
- if (!_gtk_css_parser_try (parser, "(", TRUE))
- {
- _gtk_css_parser_skip_whitespace (parser);
- if (_gtk_css_parser_try (parser, "(", TRUE))
- {
- GError *error;
-
- error = g_error_new_literal (GTK_CSS_PROVIDER_ERROR,
- GTK_CSS_PROVIDER_ERROR_DEPRECATED,
- "Whitespace between 'url' and '(' is deprecated");
-
- _gtk_css_parser_take_error (parser, error);
- }
- else
- {
- _gtk_css_parser_error (parser, "Expected '(' after 'url'");
- return NULL;
- }
- }
-
- path = _gtk_css_parser_read_string (parser);
- if (path == NULL)
- return NULL;
-
- if (!_gtk_css_parser_try (parser, ")", TRUE))
- {
- _gtk_css_parser_error (parser, "No closing ')' found for 'url'");
- g_free (path);
- return NULL;
- }
- }
- else
- {
- path = _gtk_css_parser_try_name (parser, TRUE);
- if (path == NULL)
- {
- _gtk_css_parser_error (parser, "Not a valid url");
- return NULL;
- }
- }
-
- file = g_file_resolve_relative_path (base, path);
- g_free (path);
-
- return file;
-}
-
static gboolean
gtk_css_image_url_parse (GtkCssImage *image,
GtkCssParser *parser,
GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);
GdkPixbuf *pixbuf;
GFile *file;
- char *path;
cairo_t *cr;
GError *error = NULL;
+ GFileInputStream *input;
- file = gtk_css_parse_url (parser, base);
+ file = _gtk_css_parser_read_url (parser, base);
if (file == NULL)
return FALSE;
- path = g_file_get_path (file);
+ /* 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);
- pixbuf = gdk_pixbuf_new_from_file (path, &error);
- g_free (path);
if (pixbuf == NULL)
{
_gtk_css_parser_take_error (parser, error);
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;