sp-pattern.cpp revision d9fcfa259fd382bfb18179ed0dfc9bc4efb70cbb
/*
* SVG <pattern> implementation
*
* Author:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
*
* 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 <glibmm.h>
#include "display/cairo-utils.h"
#include "display/drawing-context.h"
#include "display/drawing-surface.h"
#include "display/drawing-group.h"
#include "attributes.h"
#include "document-private.h"
#include "uri.h"
#include "style.h"
#include "sp-pattern.h"
#include "sp-factory.h"
: SPPaintServer()
, SPViewBox()
{
this->ref = new SPPatternReference(this);
this->patternUnits = UNITS_OBJECTBOUNDINGBOX;
this->patternUnits_set = false;
this->patternContentUnits = UNITS_USERSPACEONUSE;
this->patternContentUnits_set = false;
this->patternTransform_set = false;
this->x.unset();
this->y.unset();
}
{
this->readAttr("patternUnits");
this->readAttr("patternContentUnits");
this->readAttr("patternTransform");
this->readAttr("x");
this->readAttr("y");
this->readAttr("width");
this->readAttr("height");
this->readAttr("viewBox");
this->readAttr("preserveAspectRatio");
this->readAttr("xlink:href");
/* Register ourselves */
}
{
if (this->document) {
// Unregister ourselves
}
if (this->ref) {
this->modified_connection.disconnect();
delete this->ref;
}
SPPaintServer::release();
}
{
switch (key) {
case SP_ATTR_PATTERNUNITS:
if (value) {
this->patternUnits = UNITS_USERSPACEONUSE;
}
else {
this->patternUnits = UNITS_OBJECTBOUNDINGBOX;
}
this->patternUnits_set = true;
}
else {
this->patternUnits_set = false;
}
break;
if (value) {
this->patternContentUnits = UNITS_USERSPACEONUSE;
}
else {
}
this->patternContentUnits_set = true;
}
else {
this->patternContentUnits_set = false;
}
break;
case SP_ATTR_PATTERNTRANSFORM: {
this->patternTransform = t;
this->patternTransform_set = true;
}
else {
this->patternTransform_set = false;
}
break;
}
case SP_ATTR_X:
this->x.readOrUnset(value);
break;
case SP_ATTR_Y:
this->y.readOrUnset(value);
break;
case SP_ATTR_WIDTH:
break;
case SP_ATTR_HEIGHT:
break;
case SP_ATTR_VIEWBOX:
break;
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) */
{
}
break; // do not go further up the chain if children are found
}
}
}
{
if (flags & SP_OBJECT_MODIFIED_FLAG) {
}
_get_children(l);
}
}
}
{
if (flags & SP_OBJECT_MODIFIED_FLAG) {
}
_get_children(l);
}
}
}
{
if (old_ref) {
}
if (SP_IS_PATTERN(ref)) {
}
_on_ref_modified(ref, 0);
}
{
// Conditional to avoid causing infinite loop if there's a cycle in the href chain.
}
{
if (!o)
return 1;
guint i = 0;
i++;
}
i++;
}
i += _count_hrefs(child);
}
return i;
}
{
return SP_PATTERN(child);
}
{
}
return pattern;
}
{
// 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( item, "transform");
// pattern->patternTransform = premul * item->transform * pattern->patternTransform * item->transform.inverse() *
// postmul;
// otherwise the formula is much simpler
if (set) {
}
else {
}
patternTransform_set = true;
}
{
dup_transform *= move;
}
return pat_id;
}
{
return pat_i;
}
}
return this; // 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
{
for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
if (pat_i->patternUnits_set)
return pat_i->patternUnits;
}
return patternUnits;
}
{
for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
if (pat_i->patternContentUnits_set)
return pat_i->patternContentUnits;
}
return patternContentUnits;
}
{
for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
if (pat_i->patternTransform_set)
return pat_i->patternTransform;
}
return patternTransform;
}
{
for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
}
return 0;
}
{
for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
}
return 0;
}
{
for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
}
return 0;
}
{
for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
}
return 0;
}
{
for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
if (pat_i->viewBox_set) {
break;
}
}
return viewbox;
}
bool SPPattern::_has_item_children() const
{
bool hasChildren = false;
if (SP_IS_ITEM(child)) {
hasChildren = true;
}
}
return hasChildren;
}
{
double tile_width = get_width();
double tile_height = get_height();
if (tile_width <= 0 || tile_height <= 0)
return false;
return true;
}
cairo_pattern_t *SPPattern::pattern_new(cairo_t *base_ct, Geom::OptRect const &bbox, 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 drawing for rendering */
if (SP_IS_ITEM(child)) {
// for each item in pattern, show it on our drawing, add to the group,
// and connect to the release signal in case the item gets deleted
}
}
// ****** Geometry ******
//
// * "width" and "height" determine tile size.
// * "viewBox" (if defined) or "patternContentUnits" determines placement of content inside
// tile.
// * "x", "y", and "patternTransform" transform tile to user space after tile is generated.
// These functions recursively search up the tree to find the values.
double tile_width = get_width();
double tile_height = get_height();
}
// Pattern size in pattern space
// Content to tile (pattern space)
if (effective_view_box) {
// viewBox to pattern server (using SPViewBox)
c2p.setIdentity();
content2ps = c2p;
}
else {
// Content to bbox
}
}
// Tile (pattern space) to user.
// Transform of object with pattern (includes screen scaling)
// The DrawingSurface class handles the mapping from "logical space"
// (coordinates in the rendering) to "physical space" (surface pixels).
// An oversampling is done as the pattern may not pixel align with the final surface.
// The cairo surface is created when the DrawingContext is declared.
// Oversample the pattern
// TODO: find optimum value
// TODO: this is lame. instead of using descrim(), we should extract
// the scaling component from the complete matrix and use it
// to find the optimum tile size for rendering
// c is number of pixels in buffer x and y.
// Scale factor of 1.1 is too small... see bug #1251039
// Create drawing surface with size of pattern tile (in pattern space) but with number of pixels
// based on required resolution (c).
// Render pattern.
if (needs_opacity) {
}
// TODO: make sure there are no leaks.
// Render drawing to pattern_surface via drawing context, this calls root->render
// which is really DrawingItem->render().
if (SP_IS_ITEM(child)) {
}
}
// Uncomment to debug
// cairo_surface_t* raw = pattern_surface.raw();
// std::cout << " cairo_surface (sp-pattern): "
// << " width: " << cairo_image_surface_get_width( raw )
// << " height: " << cairo_image_surface_get_height( raw )
// << std::endl;
// std::string filename = "sp-pattern-" + (std::string)getId() + ".png";
// cairo_surface_write_to_png( pattern_surface.raw(), filename.c_str() );
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:fileencoding=utf-8:textwidth=99 :