sp-pattern.cpp revision 17baccec87baff66c31ac83abc6fab0d5b7488a7
#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
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <cstring>
#include <string>
#include "macros.h"
#include "display/cairo-utils.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
*/
static cairo_pattern_t *sp_pattern_create_pattern(SPPaintServer *ps, cairo_t *ct, NRRect const *bbox, double opacity);
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;
}
}
/* 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))
/* Conditional to avoid causing infinite loop if there's a cycle in the href chain. */
}
{
}
{
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 {
}
g_free(c);
}
const gchar *
pattern_tile (GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::Matrix transform, Geom::Matrix move)
{
g_free(t);
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
// FIXME: all of them must use chase_hrefs the same as in SPGradient, to avoid lockup on circular refs
{
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;
}
static cairo_pattern_t *
double opacity)
{
if (!visible)
return NULL;
/* Show items */
// find the first one with item children
break; // do not go further up the chain if children are found
}
}
if (!shown) {
return cairo_pattern_create_rgba(0,0,0,0);
}
/* Create arena */
for (SPObject *child = sp_object_first_child(SP_OBJECT(shown)) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
if (SP_IS_ITEM (child)) {
// for each item in pattern, show it on our arena, add to the group,
// and connect to the release signal in case the item gets deleted
}
}
if (pat->viewBox_set) {
// FIXME: preserveAspectRatio must be taken into account here too!
vb2ps = Geom::Matrix(tmp_x, 0.0, 0.0, tmp_y, pattern_x(pat) - pattern_viewBox(pat)->x0 * tmp_x, pattern_y(pat) - pattern_viewBox(pat)->y0 * tmp_y);
}
/* BBox to user coordinate system */
}
double w = pattern_width(pat);
double h = pattern_height(pat);
// oversample the pattern slightly
// TODO: find optimum value. Maybe sqrt(2)?
ink_cairo_transform(ct, t);
// render pattern.
if (needs_opacity) {
}
// TODO: make sure there are no leaks.
for (SPObject *child = sp_object_first_child(SP_OBJECT(shown)) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
if (SP_IS_ITEM (child)) {
}
}
if (needs_opacity) {
}
// Apply transformation to user space. Also compensate for oversampling.
return cp;
}
/*
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:encoding=utf-8:textwidth=99 :