/*
* feImage filter primitive renderer
*
* Authors:
* Felipe CorrĂȘa da Silva Sanches <juca@members.fsf.org>
* Tavmjong Bah <tavmjong@free.fr>
* Abhishek Sharma
*
* Copyright (C) 2007-2011 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "display/nr-filter-image.h"
#include "document.h"
#include "sp-item.h"
#include "display/cairo-utils.h"
#include "display/drawing-context.h"
#include "display/drawing-item.h"
#include "display/nr-filter.h"
#include "display/nr-filter-slot.h"
#include "display/nr-filter-units.h"
#include "enums.h"
#include <glibmm/fileutils.h>
namespace Inkscape {
namespace Filters {
: SVGElem(0)
, document(0)
, feImageHref(0)
, image(0)
, broken_ref(false)
{ }
return new FilterImage();
}
{
if (feImageHref)
delete image;
}
{
if (!feImageHref)
return;
//cairo_surface_t *input = slot.getcairo(_input);
// Viewport is filter primitive area (in user coordinates).
// Note: viewport calculation in non-trivial. Do not rely
// on get_matrix_primitiveunits2pb().
// feImage is suppose to use the same parameters as a normal SVG image.
// If a width or height is set to zero, the image is not suppose to be displayed.
// This does not seem to be what Firefox or Opera does, nor does the W3C displacement
// the width and height of the object bounding box.
// Internal image, like <use>
if (from_element) {
if (!SVGElem) return;
// TODO: do not recreate the rendering tree every time
// TODO: the entire thing is a hack, we should give filter primitives an "update" method
// like the one for DrawingItems
if (!optarea) return;
if (!ai) {
g_warning("feImage renderer: error creating DrawingItem for SVG Element");
return;
}
/* FIXME: These variables are currently unused. Why were they calculated?
double scaleX = feImageWidth / area.width();
double scaleY = feImageHeight / area.height();
*/
// dc.scale(scaleX, scaleY); No scaling should be done
// dc.translate(render_rect.min()); This seems incorrect
// Update to renderable state
// For the moment, we'll assume that any image is in sRGB color space
return;
}
// External image, like <image>
if (!image && !broken_ref) {
broken_ref = true;
/* TODO: If feImageHref is absolute, then use that (preferably handling the
* case that it's not a file URI). Otherwise, go up the tree looking
* for an xml:base attribute, and use that as the base URI for resolving
* the relative feImageHref URI. Otherwise, if document->base is valid,
* then use that as the base URI. Otherwise, use feImageHref directly
* (i.e. interpreting it as relative to our current working directory).
* (See http://www.w3.org/TR/xmlbase/#resolution .) */
// Try to load from relative postion combined with document base
if( document ) {
}
}
// Should display Broken Image png.
return;
}
if ( !image ) {
return;
}
broken_ref = false;
}
if (broken_ref) {
return;
}
// For the moment, we'll assume that any image is in sRGB color space
// set_cairo_surface_ci(out, SP_CSS_COLOR_INTERPOLATION_SRGB);
// This seemed like a sensible thing to do but it breaks filters-displace-01-f.svg
// now ct is in pb coordinates, note the feWidth etc. are in user units
// now ct is in the coordinates of feImageX etc.
// Now that we have the viewport, we must map image inside.
// Partially copied from sp-image.cpp.
// Do nothing if preserveAspectRatio is "none".
if( aspect_align != SP_ASPECT_NONE ) {
// Check aspect ratio of image vs. viewport
switch( aspect_align ) {
case SP_ASPECT_XMIN_YMIN:
ax = 0.0;
ay = 0.0;
break;
case SP_ASPECT_XMID_YMIN:
ax = 0.5;
ay = 0.0;
break;
case SP_ASPECT_XMAX_YMIN:
ax = 1.0;
ay = 0.0;
break;
case SP_ASPECT_XMIN_YMID:
ax = 0.0;
ay = 0.5;
break;
case SP_ASPECT_XMID_YMID:
ax = 0.5;
ay = 0.5;
break;
case SP_ASPECT_XMAX_YMID:
ax = 1.0;
ay = 0.5;
break;
case SP_ASPECT_XMIN_YMAX:
ax = 0.0;
ay = 1.0;
break;
case SP_ASPECT_XMID_YMAX:
ax = 0.5;
ay = 1.0;
break;
case SP_ASPECT_XMAX_YMAX:
ax = 1.0;
ay = 1.0;
break;
default:
ax = 0.0;
ay = 0.0;
break;
}
if( aspect_clip == SP_ASPECT_SLICE ) {
// image clipped by viewbox
if( ratio ) {
} else {
// clip sides
}
} else {
// image fits into viewbox
if( ratio ) {
// fit to height
} else {
// fit to width
}
}
}
}
{
return true;
}
{
// TODO: right now we cannot actually measure this in any meaningful way.
return 1.1;
}
delete image;
broken_ref = false;
}
}
}
aspect_clip = clip;
}
} /* namespace Filters */
} /* namespace Inkscape */
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :