sp-shape.cpp revision 6b15695578f07a3f72c4c9475c1a261a3021472a
#define __SP_SHAPE_C__
/*
* Base class for shapes, including <path> element
*
* Author:
* Lauris Kaplinski <lauris@kaplinski.com>
*
* Copyright (C) 1999-2002 Lauris Kaplinski
* Copyright (C) 2000-2001 Ximian, Inc.
* Copyright (C) 2004 John Cliff
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <libnr/n-art-bpath.h>
#include <libnr/nr-matrix-fns.h>
#include <libnr/nr-matrix-ops.h>
#include <libnr/nr-matrix-translate-ops.h>
#include <libnr/nr-scale-matrix-ops.h>
#include "macros.h"
#include "display/nr-arena-shape.h"
#include "print.h"
#include "document.h"
#include "marker-status.h"
#include "style.h"
#include "sp-marker.h"
#include "sp-path.h"
#include "prefs-utils.h"
#define noSHAPE_VERBOSE
static void sp_shape_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags);
static NRArenaItem *sp_shape_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
static SPItemClass *parent_class;
sp_shape_get_type (void)
{
if (!type) {
sizeof (SPShapeClass),
sizeof (SPShape),
16,
NULL, /* value_table */
};
}
return type;
}
static void
{
}
static void
{
/* Nothing here */
}
static void
{
}
}
static void
{
SPItemView *v;
int i;
for (i=SP_MARKER_LOC_START; i<SP_MARKER_LOC_QTY; i++) {
}
}
}
}
}
}
static void
{
}
/* This stanza checks that an object's marker style agrees with
* the marker objects it has allocated. sp_shape_set_marker ensures
* that the appropriate marker objects are present (or absent) to
* match the style.
*/
/* TODO: It would be nice if this could be done at an earlier level */
for (int i = 0 ; i < SP_MARKER_LOC_QTY ; i++) {
}
}
}
}
/* This is suboptimal, because changing parent style schedules recalculation */
/* But on the other hand - how can we know that parent does not tie style and transform */
if (flags & SP_OBJECT_MODIFIED_FLAG) {
}
s->setPaintBox(paintbox);
}
}
if (sp_shape_has_markers (shape)) {
/* Dimension marker views */
/* Get enough keys for all, start, mid and end marker types,
** and set this view's arenaitem key to the first of these keys.
*/
v->arenaitem,
);
}
for (int i = 0 ; i < SP_MARKER_LOC_QTY ; i++) {
sp_shape_number_of_markers (shape, i));
}
}
}
/* Update marker views */
}
}
}
/**
* Works out whether a marker of a given type is required at a particular
* point on a shape.
*
* \param shape Shape of interest.
* \param m Marker type (e.g. SP_MARKER_LOC_START)
* \param bp Path segment.
* \return 1 if a marker is required here, otherwise 0.
*/
static bool
{
return false;
}
return m == SP_MARKER_LOC_START;
return m == SP_MARKER_LOC_END;
else
return m == SP_MARKER_LOC_MID;
}
static bool
is_moveto(NRPathcode const c)
{
return c == NR_MOVETO || c == NR_MOVETO_OPEN;
}
/** \pre The bpath[] containing bp begins with a moveto. */
static NArtBpath const *
{
--bp;
}
return bp;
}
static NArtBpath const *
{
for(;;) {
++bp;
case NR_MOVETO:
case NR_MOVETO_OPEN:
case NR_END:
--bp;
return bp;
default: continue;
}
}
}
/* A subpath begins with a moveto and ends immediately before the next moveto or NR_END.
* (`moveto' here means either NR_MOVETO or NR_MOVETO_OPEN.) I'm assuming that non-empty
* paths always begin with a moveto.
*
* The control points of the subpath are the control points of the path elements of the subpath.
*
* As usual, the control points of a moveto or NR_LINETO are {c(3)}, and
* the control points of a NR_CURVETO are {c(1), c(2), c(3)}.
* (It follows from the definition that NR_END isn't part of a subpath.)
*
* The initial control point is bpath[bi0].c(3).
*
* Reference: http://www.w3.org/TR/SVG11/painting.html#MarkerElement, the `orient' attribute.
* Reference for behaviour of zero-length segments:
* http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes
*/
static double const no_tangent = 128.0; /* arbitrarily-chosen value outside the range of atan2, i.e. outside of [-pi, pi]. */
/** \pre The bpath[] containing bp0 begins with a moveto. */
static double
{
/* See notes in comment block above. */
++bp;
case NR_LINETO:
goto found;
}
break;
case NR_CURVETO:
goto found;
}
}
break;
case NR_MOVETO_OPEN:
case NR_END:
case NR_MOVETO:
/* Gone right around the subpath without finding any different point since the
* initial moveto. */
return no_tangent;
}
/* Open subpath. */
return no_tangent;
}
goto found;
}
break;
}
/* Back where we started, so zero-length subpath. */
return no_tangent;
/* Note: this test must come after we've looked at element bp, in case bp0 is a curve:
* we must look at c(1) and c(2). (E.g. single-curve subpath.)
*/
}
}
}
/** \pre The bpath[] containing bp0 begins with a moveto. */
static double
{
/* See notes in comment block before outgoing_tangent. */
case NR_LINETO:
goto found;
}
--bp;
break;
case NR_CURVETO:
goto found;
}
}
--bp;
break;
case NR_MOVETO:
case NR_MOVETO_OPEN:
goto found;
}
/* Open subpath. */
return no_tangent;
}
break;
default: /* includes NR_END */
return no_tangent;
}
/* Back where we started from: zero-length subpath. */
return no_tangent;
}
}
}
/**
* Calculate the transform required to get a marker's path object in the
* right place for particular path segment on a shape. You should
* call sp_shape_marker_required first to see if a marker is required
* at this point.
*
* \see sp_shape_marker_required.
*
* \param shape Shape which the marker is for.
* \param m Marker type (e.g. SP_MARKER_LOC_START)
* \param bp Path segment which the arrow is for.
* \return Transform matrix.
*/
{
/* angle1 and angle2 are now each either unset (i.e. still 100 from their initialization) or in
[-pi, pi] from atan2. */
double ret_angle;
if (angle1 == no_tangent) {
/* First vertex of an open subpath. */
? 0.
: angle2 );
} else if (angle2 == no_tangent) {
/* Last vertex of an open subpath. */
} else {
/* ret_angle is in the middle of the larger of the two sectors between angle1 and
* angle2, so flip it by 180degrees to force it to the middle of the smaller sector.
*
* (Imagine a circle with rays drawn at angle1 and angle2 from the centre of the
* circle. Those two rays divide the circle into two sectors.)
*/
}
}
}
/* Marker views have to be scaled already */
static void
{
marker_status("sp_shape_update_marker_view: Updating views of markers");
for (int i = SP_MARKER_LOC_START; i < SP_MARKER_LOC_QTY; i++) {
continue;
}
int n = 0;
NR_ARENA_ITEM_GET_KEY(ai) + i, n, m,
n++;
}
}
}
}
static void
{
}
if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) {
}
}
}
static void sp_shape_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags)
{
}
}
}
// Union with bboxes of the markers, if any
if (sp_shape_has_markers (shape)) {
for (int m = SP_MARKER_LOC_START; m < SP_MARKER_LOC_QTY; m++) {
}
// total marker transform
// get bbox of the marker with that transform
// union it with the shape bbox
}
}
}
}
}
}
}
void
{
gint add_comments = prefs_get_int_attribute_limited ("printing.debug", "add-label-comments", 0, 0, 1);
if (add_comments) {
}
/* fixme: Think (Lauris) */
}
}
for (int m = SP_MARKER_LOC_START; m < SP_MARKER_LOC_QTY; m++) {
}
}
}
}
if (add_comments) {
}
}
static NRArenaItem *
{
s->setPaintBox(paintbox);
if (sp_shape_has_markers (shape)) {
/* Dimension marker views */
}
for (int i = 0; i < SP_MARKER_LOC_QTY; i++) {
sp_shape_number_of_markers (shape, i));
}
}
/* Update marker views */
}
return arenaitem;
}
static void
{
SPItemView *v;
int i;
for (i=0; i<SP_MARKER_LOC_QTY; i++) {
NR_ARENA_ITEM_GET_KEY (v->arenaitem) + i);
}
}
}
}
}
}
/* Marker stuff */
/**
* \param shape Shape.
* \return TRUE if the shape has any markers, or FALSE if not.
*/
static int
{
/* Note, we're ignoring 'marker' settings, which technically should apply for
all three settings. This should be fixed later such that if 'marker' is
specified, then all three should appear. */
return (
);
}
/**
* \param shape Shape.
* \param type Marker type (e.g. SP_MARKER_LOC_START)
* \return Number of markers that the shape has of this type.
*/
static int
{
int n = 0;
n++;
}
}
return n;
}
static void
{
int i;
marker_status("sp_shape_marker_release: Releasing markers");
for (i = SP_MARKER_LOC_START; i < SP_MARKER_LOC_QTY; i++) {
SPItemView *v;
/* Hide marker */
/* fixme: Do we need explicit remove here? (Lauris) */
/* nr_arena_item_set_mask (v->arenaitem, NULL); */
}
/* Detach marker */
}
}
}
static void
{
/* I think mask does update automagically */
/* g_warning ("Item %s mask %s modified", SP_OBJECT_ID (item), SP_OBJECT_ID (mask)); */
}
void
{
return;
}
SPItemView *v;
/* Detach marker */
/* Hide marker */
/* fixme: Do we need explicit remove here? (Lauris) */
/* nr_arena_item_set_mask (v->arenaitem, NULL); */
}
/* Unref marker */
}
if (SP_IS_MARKER (mrk)) {
}
}
}
/* Shape section */
void
{
}
}
void
{
}
if (curve) {
if (owner) {
} else {
}
}
}
/* Return duplicate of curve or NULL */
SPCurve *
{
}
return NULL;
}
/* NOT FOR GENERAL PUBLIC UNTIL SORTED OUT (Lauris) */
void
{
}
if (curve) {
if (owner) {
} else {
}
}
}
{
return;
}
/* Use the end points of each segment of the path */
bp++;
}
}
/*
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 :