nr-arena-shape.cpp revision 77eda576f455eeb23c7b92510f38bc60738473ab
#define __NR_ARENA_SHAPE_C__
/*
* RGBA display list system for inkscape
*
* Author:
* Lauris Kaplinski <lauris@kaplinski.com>
*
* Copyright (C) 2001-2002 Lauris Kaplinski
* Copyright (C) 2001 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <display/canvas-arena.h>
#include <display/nr-arena.h>
#include <display/nr-arena-shape.h>
#include <libnr/nr-pixops.h>
#include <libnr/nr-matrix-ops.h>
#include <libnr/nr-matrix-fns.h>
#include <libnr/nr-convert2geom.h>
#include <livarot/float-line.h>
#include <livarot/int-line.h>
#include <style.h>
#include "prefs-utils.h"
#include "inkscape-cairo.h"
#include "helper/geom-curves.h"
#include "sp-filter.h"
#include "sp-filter-reference.h"
#include "display/nr-filter.h"
#include <typeinfo>
#include <cairo.h>
#include <glib.h>
#include <fenv.h>
//int showRuns=0;
static void nr_arena_shape_set_child_position(NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref);
static guint nr_arena_shape_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, guint reset);
static unsigned int nr_arena_shape_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags);
static NRArenaItem *nr_arena_shape_pick(NRArenaItem *item, NR::Point p, double delta, unsigned int sticky);
static NRArenaItemClass *shape_parent_class;
nr_arena_shape_get_type(void)
{
if (!type) {
"NRArenaShape",
sizeof(NRArenaShapeClass),
sizeof(NRArenaShape),
(void (*)(NRObjectClass *)) nr_arena_shape_class_init,
(void (*)(NRObject *)) nr_arena_shape_init);
}
return type;
}
static void
{
}
/**
* Initializes the arena shape, setting all parameters to null, 0, false,
* or other defaults
*/
static void
{
shape->cached_fpartialy = false;
shape->cached_spartialy = false;
shape->delayed_shp = false;
shape->repick_after = 0;
}
static void
{
}
/**
* Retrieves the markers from the item
*/
static NRArenaItem *
{
}
/**
* Attaches child to item, and if ref is not NULL, sets it and ref->next as
* the prev and next items. If ref is NULL, then it sets the item's markers
* as the next items.
*/
static void
{
if (!ref) {
} else {
}
}
/**
* Removes child from the shape. If there are no prev items in
* the child, it sets items' markers to the next item in the child.
*/
static void
{
} else {
}
}
/**
* Detaches child from item, and if there are no previous items in child, it
* sets item's markers to the child. It then attaches the child back onto the item.
* If ref is null, it sets the markers to be the next item, otherwise it uses
*/
static void
{
} else {
}
if (!ref) {
} else {
}
}
void nr_arena_shape_update_fill(NRArenaShape *shape, NRGC *gc, NRRectL *area, bool force_shape = false);
/**
* Updates the arena shape 'item' and all of its children, including the markers.
*/
static guint
{
unsigned int beststate = NR_ARENA_ITEM_STATE_ALL;
unsigned int newstate;
}
if (!(state & NR_ARENA_ITEM_STATE_RENDER)) {
/* We do not have to create rendering structures */
if (state & NR_ARENA_ITEM_STATE_BBOX) {
}
if (beststate & NR_ARENA_ITEM_STATE_BBOX) {
}
}
}
}
shape->delayed_shp=true;
}
// those pesky miters, now
if ( miterMax > 0.01 ) {
// grunt mode. we should compute the various miters instead (one for each point on the curve)
}
}
} else {
}
/* Release state data */
/* Concept test */
}
}
if (shape->stroke_shp) {
delete shape->stroke_shp;
}
if (shape->fill_painter) {
}
if (shape->stroke_painter) {
}
{
return NR_ARENA_ITEM_STATE_ALL;
}
/* Build state data */
if ( shape->delayed_shp ) {
} else {
}
if (boundingbox.isEmpty())
return NR_ARENA_ITEM_STATE_ALL;
}
}
}
}
)
{
// don't merge item opacity with paint opacity if there is a stroke on the fill, or markers on stroke
}
if (beststate & NR_ARENA_ITEM_STATE_BBOX) {
}
}
return NR_ARENA_ITEM_STATE_ALL;
}
// transposition
tp[0]=p[0];
for (int i = 4; i < 6; i++) // shut valgrind up :)
tp[i] = p[i] = 0;
// Is the adjunct nearly an identity function?
// the transformation is an isometry -> no need to recompute
// the uncrossed polygon
if ( p.det() < 0 )
return -1;
else
return 1;
}
return 0;
}
return (outer.x0 <= inner.x0 && outer.y0 <= inner.y0 && outer.x1 >= inner.x1 && outer.y1 >= inner.y1);
}
/* returns true if the pathvector has a region that needs fill.
* is for optimizing purposes, so should be fast and can falsely return true.
* CANNOT falsely return false. */
// return false for the cases where there is surely no region to be filled
return false;
// vector has only one path with only one segment, see if that's a non-curve segment: that would mean no internal region
{
return false;
}
}
return true; //too costly to see if it has region to be filled, so return true.
}
/** force_shape is used for clipping paths, when we need the shape for clipping even if it's not filled */
void
{
// ((shape->curve->get_length() > 2) || (SP_CURVE_BPATH(shape->curve)[1].code == NR_CURVETO)) ) { // <-- this used to be the old code, i think it has to determine that the path has a sort of 'internal region' where fill would occur
int isometry = 0;
if ( shape->cached_fill ) {
} else {
}
isometry = 0;
}
if ( isometry == 0 ) {
{
}
shape->cached_fpartialy = false;
} else {
shape->cached_fpartialy = true;
}
// alternatively, this speeds up rendering of oddeven shapes but disables AA :(
//shape->cached_fill->Copy(theShape);
} else {
}
delete theShape;
delete thePath;
} else if ( 2 == isometry ) {
}
} else {
if ( isometry == 1 ) {
}
}
}
}
}
void
{
if (outline) {
// cairo does not need the livarot path for rendering
return;
}
// after switching normal stroke rendering to cairo too, optimize this: lower tolerance, disregard dashes
// (since it will only be used for picking, not for rendering)
if (outline ||
float width;
if (outline) {
} else {
width = style_width;
}
int isometry = 0;
if ( shape->cached_stroke ) {
} else {
}
isometry = 0;
// if this happens without setting style, we have just switched to outline or back
isometry = 0;
}
}
if ( isometry == 0 ) {
{
}
// add some padding to the rendering area, so clipped path does not go into a render area
if ((style->stroke_dash.n_dash && !outline) || is_inner_area(padded_area, NR_ARENA_ITEM(shape)->bbox)) {
shape->cached_spartialy = false;
}
else {
shape->cached_spartialy = true;
}
}
case NRArenaShape::BUTT_CAP:
break;
case NRArenaShape::ROUND_CAP:
butt = butt_round;
break;
case NRArenaShape::SQUARE_CAP:
butt = butt_square;
break;
}
case NRArenaShape::MITRE_JOIN:
join = join_pointy;
break;
case NRArenaShape::ROUND_JOIN:
join = join_round;
break;
case NRArenaShape::BEVEL_JOIN:
break;
}
if (outline) {
}
if (outline) {
// speeds it up, but uses evenodd for the stroke shape (which does not matter for 1-pixel wide outline)
} else {
}
delete thePath;
delete theShape;
} else if ( 2 == isometry ) {
}
} else {
shape->stroke_shp->Reset(shape->cached_stroke->numberOfPoints(), shape->cached_stroke->numberOfEdges());
if ( isometry == 1 ) {
} else if ( isometry == -1 ) {
}
}
}
}
void
{
/* TODO: are these two if's mutually exclusive? ( i.e. "shape->stroke_shp <=> !shape->fill_shp" )
* if so, then this can be written much more compact ! */
if ( shape->stroke_shp ) {
}
}
}
// cairo outline rendering:
static unsigned int
{
if (!ct)
// FIXME: we use RGBA buffers but cairo writes BGRA (on i386), so we must cheat
// by setting color channels in the "wrong" order
cairo_set_source_rgba(ct, SP_RGBA32_B_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_R_F(rgba), SP_RGBA32_A_F(rgba));
}
// cairo stroke rendering (flat color only so far!):
// works on canvas, but wrongs the colors in nonpremul buffers: icons and png export
// (need to switch them to premul before this can be enabled)
void
{
return;
if (!ct)
return;
if ( item->render_opacity ) {
} else {
}
// FIXME: we use RGBA buffers but cairo writes BGRA (on i386), so we must cheat
// by setting color channels in the "wrong" order
cairo_set_source_rgba(ct, SP_RGBA32_B_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_R_F(rgba), SP_RGBA32_A_F(rgba));
case NRArenaShape::BUTT_CAP:
break;
case NRArenaShape::ROUND_CAP:
break;
case NRArenaShape::SQUARE_CAP:
break;
}
case NRArenaShape::MITRE_JOIN:
break;
case NRArenaShape::ROUND_JOIN:
break;
case NRArenaShape::BEVEL_JOIN:
break;
}
}
}
feed_pathvector_to_cairo (ct, shape->curve->get_pathvector(), to_2geom(shape->ctm), area->upgrade(), true, style_width);
cairo_destroy (ct);
}
/**
* Renders the item. Markers are just composed into the parent buffer.
*/
static unsigned int
nr_arena_shape_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags)
{
if (outline) { // cairo outline rendering
} else {
if ( shape->delayed_shp ) {
shape->delayed_shp = false;
/* NRRect bbox;
bbox.x0 = bbox.y0 = bbox.x1 = bbox.y1 = 0.0;
nr_arena_shape_add_bboxes(shape,bbox);
item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
item->bbox.x1 = (gint32)(bbox.x1 + 1.0F);
item->bbox.y1 = (gint32)(bbox.y1 + 1.0F);
shape->approx_bbox=item->bbox;*/
} else {
}
}
NRPixBlock m;
// if memory allocation failed, abort render
nr_pixblock_release (&m);
}
// do not render fill in any way
if ( item->render_opacity ) {
} else {
}
if (shape->fill_painter) {
}
}
nr_pixblock_release(&m);
}
// cairo_arena_shape_render_stroke(item, area, pb);
NRPixBlock m;
// if memory allocation failed, abort render
nr_pixblock_release (&m);
}
if ( item->render_opacity ) {
} else {
}
nr_pixblock_release(&m);
NRPixBlock m;
// if memory allocation failed, abort render
nr_pixblock_release (&m);
}
if (shape->stroke_painter) {
}
nr_pixblock_release(&m);
}
} // non-cairo non-outline branch
/* Render markers into parent buffer */
}
}
// cairo clipping: this basically works except for the stride-must-be-divisible-by-4 cairo bug;
// reenable this when the bug is fixed and remove the rest of this function
// TODO
static guint
{
if (!ct)
feed_pathvector_to_cairo (ct, shape->curve->get_pathvector(), to_2geom(shape->ctm), (area)->upgrade(), false, 0);
cairo_fill(ct);
cairo_destroy (ct);
}
#endif //defined(DEADCODE) && !defined(DEADCODE)
static guint
{
//return cairo_arena_shape_clip(item, area, pb);
shape->delayed_shp = false;
} else {
}
}
NRPixBlock m;
/* fixme: We can OR in one step (Lauris) */
// if memory allocation failed, abort
nr_pixblock_release (&m);
}
unsigned char *s, *d;
*d = NR_COMPOSEA_111(*s, *d);
d ++;
s ++;
}
}
nr_pixblock_release(&m);
}
}
static NRArenaItem *
{
if (shape->repick_after > 0)
shape->repick_after--;
if (shape->repick_after > 0) // we are a slow, huge path. skip this pick, returning what was returned last time
// fully transparent, no pick unless outline mode
return NULL;
double width;
if (outline) {
width = 0.5;
} else if (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE && shape->_stroke.opacity > 1e-3) {
} else {
width = 0;
}
int wind = 0;
pathv_matrix_point_bbox_wind_distance(shape->curve->get_pathvector(), to_2geom(shape->ctm), to_2geom(p), NULL, needfill? &wind : NULL, &dist, 0.5, &viewbox);
} else {
pathv_matrix_point_bbox_wind_distance(shape->curve->get_pathvector(), to_2geom(shape->ctm), to_2geom(p), NULL, needfill? &wind : NULL, &dist, 0.5, NULL);
}
//g_print ("pick time %lu\n", this_pick);
}
// covered by fill?
if (needfill) {
if (wind != 0) {
return item;
}
} else {
if (wind & 0x1) {
return item;
}
}
}
// close to the edge, as defined by strokewidth and delta?
// this ignores dashing (as if the stroke is solid) and always works as if caps are round
return item;
}
}
// if not picked on the shape itself, try its markers
if (ret) {
return item;
}
}
return NULL;
}
/**
*
* Requests a render of the shape, then if the shape is already a curve it
* unrefs the old curve; if the new curve is valid it creates a copy of the
* curve and adds it to the shape. Finally, it requests an update of the
* arena for the shape.
*/
{
if ( justTrans == false ) {
// dirty cached versions
if ( shape->cached_fill ) {
delete shape->cached_fill;
}
if ( shape->cached_stroke ) {
delete shape->cached_stroke;
}
}
}
if (curve) {
}
}
}
}
}
}
}
}
}
}
}
}
}
/** nr_arena_shape_set_style
*
* Unrefs any existing style and ref's to the given one, then requests an update of the arena
*/
void
{
} else {
}
case SP_WIND_RULE_EVENODD: {
break;
}
case SP_WIND_RULE_NONZERO: {
break;
}
default: {
}
}
} else {
}
case SP_STROKE_LINECAP_ROUND: {
break;
}
case SP_STROKE_LINECAP_SQUARE: {
break;
}
case SP_STROKE_LINECAP_BUTT: {
break;
}
default: {
}
}
case SP_STROKE_LINEJOIN_ROUND: {
break;
}
case SP_STROKE_LINEJOIN_BEVEL: {
break;
}
case SP_STROKE_LINEJOIN_MITER: {
break;
}
default: {
}
}
//if shape has a filter
}
} else {
//no filter set for this shape
}
}
void
{
} else {
/* fixme: We kill warning, although not sure what to do here (Lauris) */
}
}
{
}
static void
{
if ( vst > 0.999 ) {
/* Simple copy */
while (len > 0) {
d[0] = 255;
d += 1;
len -= 1;
}
} else {
sv*=256;
c0_24&=0xFF;
while (len > 0) {
/* Draw */
d[0] = NR_COMPOSEA_111(c0_24,d[0]);
d += 1;
len -= 1;
}
}
} else {
sv*=256;
c0_24&=0xFF;
/* Draw */
d[0] = NR_COMPOSEA_111(c0_24,d[0]);
} else {
sv*=16777216;
dv*=16777216;
while (len > 0) {
unsigned int ca;
/* Draw */
d[0] = NR_COMPOSEA_111(ca,d[0]);
d += 1;
len -= 1;
}
}
}
}
{
/* This is the FloatLigne version. See svn (prior to Apr 2006) for versions using BitLigne or direct BitLigne. */
int curPt;
float curY;
}
theS->EndQuickRaster();
delete theI;
delete theIL;
}
/*
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 :