sp-pattern.cpp revision 5e6d8ac87c28d9a01a75e95efa8752e0c20d8deb
#define __SP_PATTERN_C__
/*
* SVG <pattern> implementation
*
* Author:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
*
* Copyright (C) 2002 Lauris Kaplinski
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "config.h"
#include <libnr/nr-matrix-ops.h>
#include "libnr/nr-matrix-fns.h"
#include <libnr/nr-translate-matrix-ops.h>
#include "macros.h"
#include "display/nr-arena.h"
#include "display/nr-arena-group.h"
#include "attributes.h"
#include "document-private.h"
#include "uri.h"
#include "sp-pattern.h"
/*
* Pattern
*/
class SPPatPainter;
struct SPPatPainter {
unsigned int dkey;
bool use_cached_tile;
};
static void sp_pattern_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
static SPPainter *sp_pattern_painter_new (SPPaintServer *ps, NR::Matrix const &full_transform, NR::Matrix const &parent_transform, const NRRect *bbox);
static SPPaintServerClass * pattern_parent_class;
sp_pattern_get_type (void)
{
static GType pattern_type = 0;
if (!pattern_type) {
sizeof (SPPatternClass),
NULL, /* base_init */
NULL, /* base_finalize */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (SPPattern),
16, /* n_preallocs */
NULL, /* value_table */
};
pattern_type = g_type_register_static (SP_TYPE_PAINT_SERVER, "SPPattern", &pattern_info, (GTypeFlags)0);
}
return pattern_type;
}
static void
{
// do we need _write? seems to work without it
}
static void
{
}
static void
{
/* Register ourselves */
}
static void
{
if (SP_OBJECT_DOCUMENT (object)) {
/* Unregister ourselves */
}
}
}
static void
{
switch (key) {
case SP_ATTR_PATTERNUNITS:
if (value) {
} else {
}
} else {
}
break;
if (value) {
} else {
}
} else {
}
break;
case SP_ATTR_PATTERNTRANSFORM: {
pat->patternTransform = t;
} else {
}
break;
}
case SP_ATTR_X:
break;
case SP_ATTR_Y:
break;
case SP_ATTR_WIDTH:
break;
case SP_ATTR_HEIGHT:
break;
case SP_ATTR_VIEWBOX: {
/* fixme: Think (Lauris) */
char *eptr;
if (value) {
} else {
}
} else {
}
break;
}
case SP_ATTR_XLINK_HREF:
/* Href unchanged, do nothing. */
} else {
if (value) {
// First, set the href field; it's only used in the "unchanged" check above.
// Now do the attaching, which emits the changed signal.
if (value) {
try {
} catch (Inkscape::BadURIException &e) {
}
} else {
}
}
}
break;
default:
break;
}
}
static void
{
if (SP_IS_ITEM (ochild)) {
NRArenaItem *ai = sp_item_invoke_show (SP_ITEM (ochild), pp->arena, pp->dkey, SP_ITEM_REFERENCE_FLAGS);
if (ai) {
}
}
}
}
/* TODO: do we need a ::remove_child handler? */
/* fixme: We need ::order_changed handler too (Lauris) */
GSList *
{
for (SPObject *child = sp_object_first_child(SP_OBJECT (pat)) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
l = g_slist_prepend (l, child);
}
break; // do not go further up the chain if children are found
}
}
return l;
}
static void
{
l = g_slist_reverse (l);
while (l) {
l = g_slist_remove (l, child);
}
}
}
static void
{
l = g_slist_reverse (l);
while (l) {
l = g_slist_remove (l, child);
}
}
}
/**
Gets called when the pattern is reattached to another <pattern>
*/
static void
{
if (old_ref) {
}
if (SP_IS_PATTERN (ref)) {
pat->modified_connection = ref->connectModified(sigc::bind<2>(sigc::ptr_fun(&pattern_ref_modified), pat));
}
}
/**
Gets called when the referenced <pattern> is changed
*/
static void
{
if (SP_IS_OBJECT (pattern))
}
{
}
{
g_free (parent_ref);
return SP_PATTERN (child);
}
{
}
return pattern;
}
void
{
// this formula is for a different interpretation of pattern transforms as described in (*) in sp-pattern.cpp
// for it to work, we also need sp_object_read_attr (SP_OBJECT (item), "transform");
//pattern->patternTransform = premul * item->transform * pattern->patternTransform * item->transform.inverse() * postmul;
// otherwise the formula is much simpler
if (set) {
} else {
}
gchar c[256];
} else {
}
}
const gchar *
pattern_tile (GSList *reprs, NR::Rect bounds, SPDocument *document, NR::Matrix transform, NR::Matrix move)
{
gchar t[256];
} else {
}
dup_transform *= move;
}
return pat_id;
}
{
return pat_i;
}
}
return pat; // document is broken, we can't get to root; but at least we can return pat which is supposedly a valid pattern
}
// Access functions that look up fields up the chain of referenced patterns and return the first one which is set
{
if (pat_i->patternUnits_set)
return pat_i->patternUnits;
}
return pat->patternUnits;
}
{
if (pat_i->patternContentUnits_set)
return pat_i->patternContentUnits;
}
return pat->patternContentUnits;
}
{
for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
if (pat_i->patternTransform_set)
return pat_i->patternTransform;
}
return pat->patternTransform;
}
{
}
return 0;
}
{
}
return 0;
}
{
}
return 0;
}
{
}
return 0;
}
{
if (pat_i->viewBox_set)
}
}
{
for (SPObject *child = sp_object_first_child(SP_OBJECT(pat)) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
if (SP_IS_ITEM (child)) {
return true;
}
}
return false;
}
/* Painter */
/**
Creates a painter (i.e. the thing that does actual filling at the given zoom).
See (*) below for why the parent_transform may be necessary.
*/
static SPPainter *
sp_pattern_painter_new (SPPaintServer *ps, NR::Matrix const &full_transform, NR::Matrix const &parent_transform, const NRRect *bbox)
{
/* BBox to user coordinate system */
// the final patternTransform, taking into account bbox
// see (*) comment below
} else {
/* Problem: What to do, if we have mixed lengths and percentages? */
/* Currently we do ignore percentages at all, but that is not good (lauris) */
/* fixme: We may try to normalize here too, look at linearGradient (Lauris) */
// (*) The spec says, "This additional transformation matrix [patternTransform] is
// post-multiplied to (i.e., inserted to the right of) any previously defined
// transformations, including the implicit transformation necessary to convert from
// object bounding box units to user space." To me, this means that the order should be:
// item_transform * patternTransform * parent_transform
// However both Batik and Adobe plugin use:
// patternTransform * item_transform * parent_transform
// So here I comply with the majority opinion, but leave my interpretation commented out below.
// (To get item_transform, I subtract parent from full.)
//NR::Matrix ps2px = (full_transform / parent_transform) * pattern_patternTransform(pat) * parent_transform;
}
if (pat->viewBox_set) {
// FIXME: preserveAspectRatio must be taken into account here too!
NR::Matrix vb2ps (tmp_x, 0.0, 0.0, tmp_y, pattern_x(pat) - pattern_viewBox(pat)->x0, pattern_y(pat) - pattern_viewBox(pat)->y0);
// see (*)
} else {
/* No viewbox, have to parse units */
/* BBox to user coordinate system */
// see (*)
} else {
// see (*)
//pcs2px = (full_transform / parent_transform) * pattern_patternTransform(pat) * parent_transform;
}
}
/* Create arena */
/* Create group */
/* Show items */
if (pat_i && SP_IS_OBJECT (pat_i) && pattern_hasItemChildren(pat_i)) { // find the first one with item children
for (SPObject *child = sp_object_first_child(SP_OBJECT(pat_i)) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
if (SP_IS_ITEM (child)) {
}
}
break; // do not go further up the chain if children are found
}
}
{
// if ( tr_width < 10000 && tr_height < 10000 && tr_width*tr_height < 1000000 ) {
if (pp->use_cached_tile) {
nr_pixblock_setup (&pp->cached_tile,NR_PIXBLOCK_MODE_R8G8B8A8N, pp->cached_bbox.x0, pp->cached_bbox.y0, pp->cached_bbox.x1, pp->cached_bbox.y1,TRUE);
}
// } else {
// pp->use_cached_tile=false;
// }
}
if ( pp->use_cached_tile ) {
} else {
}
nr_arena_item_invoke_update (pp->root, NULL, &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_ALL);
if ( pp->use_cached_tile ) {
} else {
// nothing to do now
}
}
static void
{
if (pat_i && SP_IS_OBJECT (pat_i) && pattern_hasItemChildren(pat_i)) { // find the first one with item children
for (SPObject *child = sp_object_first_child(SP_OBJECT(pat_i)) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
if (SP_IS_ITEM (child)) {
}
}
break; // do not go further up the chain if children are found
}
}
}
void
get_cached_tile_pixel(SPPatPainter* pp,double x,double y,unsigned char &r,unsigned char &g,unsigned char &b,unsigned char &a)
{
r=f_c;
g=f_c;
b=f_c;
a=f_c;
}
static void
{
double x, y;
/* Find buffer area in gradient space */
/* fixme: This is suboptimal (Lauris) */
if ( pp->use_cached_tile ) {
if ( pb->mode == NR_PIXBLOCK_MODE_R8G8B8A8N || pb->mode == NR_PIXBLOCK_MODE_R8G8B8A8P ) { // same thing because it's filling an empty pixblock
px_x+=1.0;
cpx+=4;
}
px_y+=1.0;
}
px_x+=1.0;
cpx+=4;
}
px_y+=1.0;
}
}
} else {
// We do not update here anymore
// Set up buffer
// fixme: (Lauris)
nr_pixblock_setup_extern (&ppb, pb->mode, area.x0, area.y0, area.x1, area.y1, NR_PIXBLOCK_PX (pb), pb->rs, FALSE, FALSE);
}
}
}
}