diff options
| author | Krzysztof Kosi??ski <tweenk.pl@gmail.com> | 2011-08-27 14:58:22 +0000 |
|---|---|---|
| committer | Krzysztof Kosinski <tweenk.pl@gmail.com> | 2011-08-27 14:58:22 +0000 |
| commit | 24526cceccb4ed103a6324756476c64efb3fb5dd (patch) | |
| tree | 24abb1d2b1bdb6156a83f2d393cbdc4747fda4ac /src | |
| parent | Remove NRRect from paint servers and temporary calculations (diff) | |
| download | inkscape-24526cceccb4ed103a6324756476c64efb3fb5dd.tar.gz inkscape-24526cceccb4ed103a6324756476c64efb3fb5dd.zip | |
Remove all NRRect use.
(bzr r10582.1.5)
Diffstat (limited to 'src')
| -rw-r--r-- | src/desktop.cpp | 57 | ||||
| -rw-r--r-- | src/desktop.h | 7 | ||||
| -rw-r--r-- | src/document.cpp | 44 | ||||
| -rw-r--r-- | src/document.h | 1 | ||||
| -rw-r--r-- | src/extension/internal/cairo-render-context.cpp | 23 | ||||
| -rw-r--r-- | src/extension/internal/cairo-renderer.cpp | 36 | ||||
| -rw-r--r-- | src/marker.cpp | 44 | ||||
| -rw-r--r-- | src/print.h | 1 | ||||
| -rw-r--r-- | src/sp-ellipse.cpp | 25 | ||||
| -rw-r--r-- | src/sp-item.h | 2 | ||||
| -rw-r--r-- | src/sp-line.cpp | 4 | ||||
| -rw-r--r-- | src/sp-namedview.cpp | 5 | ||||
| -rw-r--r-- | src/sp-paint-server.cpp | 3 | ||||
| -rw-r--r-- | src/sp-paint-server.h | 2 | ||||
| -rw-r--r-- | src/sp-pattern.cpp | 29 | ||||
| -rw-r--r-- | src/sp-pattern.h | 4 | ||||
| -rw-r--r-- | src/sp-rect.cpp | 4 | ||||
| -rw-r--r-- | src/sp-root.cpp | 48 | ||||
| -rw-r--r-- | src/sp-root.h | 18 | ||||
| -rw-r--r-- | src/sp-symbol.cpp | 56 | ||||
| -rw-r--r-- | src/sp-symbol.h | 2 | ||||
| -rw-r--r-- | src/sp-use.cpp | 13 |
22 files changed, 178 insertions, 250 deletions
diff --git a/src/desktop.cpp b/src/desktop.cpp index f1a63d22c..dc06f773e 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -144,8 +144,6 @@ SPDesktop::SPDesktop() : page_border( 0 ), current( 0 ), _focusMode(false), - zooms_past( 0 ), - zooms_future( 0 ), dkey( 0 ), number( 0 ), window_state(0), @@ -410,9 +408,6 @@ void SPDesktop::destroy() delete _guides_message_context; _guides_message_context = NULL; - - g_list_free (zooms_past); - g_list_free (zooms_future); } SPDesktop::~SPDesktop() {} @@ -771,25 +766,12 @@ SPDesktop::point() const * Put current zoom data in history list. */ void -SPDesktop::push_current_zoom (GList **history) +SPDesktop::push_current_zoom (std::list<Geom::Rect> &history) { - Geom::Rect const area = get_display_area(); + Geom::Rect area = get_display_area(); - NRRect *old_zoom = g_new(NRRect, 1); - old_zoom->x0 = area.min()[Geom::X]; - old_zoom->x1 = area.max()[Geom::X]; - old_zoom->y0 = area.min()[Geom::Y]; - old_zoom->y1 = area.max()[Geom::Y]; - if ( *history == NULL - || !( ( ((NRRect *) ((*history)->data))->x0 == old_zoom->x0 ) && - ( ((NRRect *) ((*history)->data))->x1 == old_zoom->x1 ) && - ( ((NRRect *) ((*history)->data))->y0 == old_zoom->y0 ) && - ( ((NRRect *) ((*history)->data))->y1 == old_zoom->y1 ) ) ) - { - *history = g_list_prepend (*history, old_zoom); - } else { - g_free(old_zoom); - old_zoom = 0; + if (history.empty() || history.front() == area) { + history.push_front(area); } } @@ -804,10 +786,9 @@ SPDesktop::set_display_area (double x0, double y0, double x1, double y1, double // save the zoom if (log) { - push_current_zoom(&zooms_past); + push_current_zoom(zooms_past); // if we do a logged zoom, our zoom-forward list is invalidated, so delete it - g_list_free (zooms_future); - zooms_future = NULL; + zooms_future.clear(); } double const cx = 0.5 * (x0 + x1); @@ -882,23 +863,20 @@ Geom::Rect SPDesktop::get_display_area() const void SPDesktop::prev_zoom() { - if (zooms_past == NULL) { + if (zooms_past.empty()) { messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No previous zoom.")); return; } // push current zoom into forward zooms list - push_current_zoom (&zooms_future); + push_current_zoom (zooms_future); // restore previous zoom - set_display_area (((NRRect *) zooms_past->data)->x0, - ((NRRect *) zooms_past->data)->y0, - ((NRRect *) zooms_past->data)->x1, - ((NRRect *) zooms_past->data)->y1, - 0, false); + Geom::Rect past = zooms_past.front(); + set_display_area (past.left(), past.top(), past.right(), past.bottom(), 0, false); // remove the just-added zoom from the past zooms list - zooms_past = g_list_remove (zooms_past, ((NRRect *) zooms_past->data)); + zooms_past.pop_front(); } /** @@ -907,23 +885,20 @@ SPDesktop::prev_zoom() void SPDesktop::next_zoom() { - if (zooms_future == NULL) { + if (zooms_future.empty()) { this->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No next zoom.")); return; } // push current zoom into past zooms list - push_current_zoom (&zooms_past); + push_current_zoom (zooms_past); // restore next zoom - set_display_area (((NRRect *) zooms_future->data)->x0, - ((NRRect *) zooms_future->data)->y0, - ((NRRect *) zooms_future->data)->x1, - ((NRRect *) zooms_future->data)->y1, - 0, false); + Geom::Rect future = zooms_future.front(); + set_display_area (future.left(), future.top(), future.right(), future.bottom(), 0, false); // remove the just-used zoom from the zooms_future list - zooms_future = g_list_remove (zooms_future, ((NRRect *) zooms_future->data)); + zooms_future.pop_front(); } /** \brief Performs a quick zoom into what the user is working on diff --git a/src/desktop.h b/src/desktop.h index 5dcd014ca..d15fb7d69 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -117,8 +117,9 @@ public: SPCSSAttr *current; ///< current style bool _focusMode; ///< Whether we're focused working or general working - GList *zooms_past; - GList *zooms_future; + std::list<Geom::Rect> zooms_past; + std::list<Geom::Rect> zooms_future; + bool _quick_zoom_enabled; ///< Signifies that currently we're in quick zoom mode Geom::Rect _quick_zoom_stored_area; ///< The area of the screen before quick zoom unsigned int dkey; @@ -359,7 +360,7 @@ private: bool grids_visible; /* don't set this variable directly, use the method below */ void set_grids_visible(bool visible); - void push_current_zoom (GList**); + void push_current_zoom(std::list<Geom::Rect> &); sigc::signal<void,SPDesktop*,SPDocument*> _document_replaced_signal; sigc::signal<void> _activate_signal; diff --git a/src/document.cpp b/src/document.cpp index cf2474fe5..d45041296 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -534,7 +534,7 @@ gdouble SPDocument::getWidth() const gdouble result = root->width.computed; if (root->width.unit == SVGLength::PERCENT && root->viewBox_set) { - result = root->viewBox.x1 - root->viewBox.x0; + result = root->viewBox.width(); } return result; } @@ -542,7 +542,7 @@ gdouble SPDocument::getWidth() const void SPDocument::setWidth(gdouble width, const SPUnit *unit) { if (root->width.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox= - root->viewBox.x1 = root->viewBox.x0 + sp_units_get_pixels (width, *unit); + root->viewBox.setMax(Geom::Point(root->viewBox.left() + sp_units_get_pixels (width, *unit), root->viewBox.bottom())); } else { // set to width= gdouble old_computed = root->width.computed; root->width.computed = sp_units_get_pixels (width, *unit); @@ -557,16 +557,28 @@ void SPDocument::setWidth(gdouble width, const SPUnit *unit) } if (root->viewBox_set) - root->viewBox.x1 = root->viewBox.x0 + (root->width.computed / old_computed) * (root->viewBox.x1 - root->viewBox.x0); + root->viewBox.setMax(Geom::Point(root->viewBox.left() + (root->width.computed / old_computed) * root->viewBox.width(), root->viewBox.bottom())); } root->updateRepr(); } +gdouble SPDocument::getHeight() const +{ + g_return_val_if_fail(this->priv != NULL, 0.0); + g_return_val_if_fail(this->root != NULL, 0.0); + + gdouble result = root->height.computed; + if (root->height.unit == SVGLength::PERCENT && root->viewBox_set) { + result = root->viewBox.height(); + } + return result; +} + void SPDocument::setHeight(gdouble height, const SPUnit *unit) { if (root->height.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox= - root->viewBox.y1 = root->viewBox.y0 + sp_units_get_pixels (height, *unit); + root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + sp_units_get_pixels (height, *unit))); } else { // set to height= gdouble old_computed = root->height.computed; root->height.computed = sp_units_get_pixels (height, *unit); @@ -581,24 +593,12 @@ void SPDocument::setHeight(gdouble height, const SPUnit *unit) } if (root->viewBox_set) - root->viewBox.y1 = root->viewBox.y0 + (root->height.computed / old_computed) * (root->viewBox.y1 - root->viewBox.y0); + root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + (root->height.computed / old_computed) * root->viewBox.height())); } root->updateRepr(); } -gdouble SPDocument::getHeight() const -{ - g_return_val_if_fail(this->priv != NULL, 0.0); - g_return_val_if_fail(this->root != NULL, 0.0); - - gdouble result = root->height.computed; - if (root->height.unit == SVGLength::PERCENT && root->viewBox_set) { - result = root->viewBox.y1 - root->viewBox.y0; - } - return result; -} - Geom::Point SPDocument::getDimensions() const { return Geom::Point(getWidth(), getHeight()); @@ -941,15 +941,9 @@ void SPDocument::setupViewport(SPItemCtx *ctx) ctx->i2doc = Geom::identity(); // Set up viewport in case svg has it defined as percentages if (root->viewBox_set) { // if set, take from viewBox - ctx->vp.x0 = root->viewBox.x0; - ctx->vp.y0 = root->viewBox.y0; - ctx->vp.x1 = root->viewBox.x1; - ctx->vp.y1 = root->viewBox.y1; + ctx->viewport = root->viewBox; } else { // as a last resort, set size to A4 - ctx->vp.x0 = 0.0; - ctx->vp.y0 = 0.0; - ctx->vp.x1 = 210 * PX_PER_MM; - ctx->vp.y1 = 297 * PX_PER_MM; + ctx->viewport = Geom::Rect::from_xywh(0, 0, 210 * PX_PER_MM, 297 * PX_PER_MM); } ctx->i2vp = Geom::identity(); } diff --git a/src/document.h b/src/document.h index c94b66c4d..83cb57eea 100644 --- a/src/document.h +++ b/src/document.h @@ -38,7 +38,6 @@ namespace Avoid { class Router; } -struct NRRect; struct SPDesktop; struct SPItem; struct SPObject; diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp index a0573d9ff..9bafa9432 100644 --- a/src/extension/internal/cairo-render-context.cpp +++ b/src/extension/internal/cairo-render-context.cpp @@ -87,19 +87,19 @@ #define TEST(_args) // FIXME: expose these from sp-clippath/mask.cpp -struct SPClipPathView { +/*struct SPClipPathView { SPClipPathView *next; unsigned int key; Inkscape::DrawingItem *arenaitem; - NRRect bbox; + Geom::OptRect bbox; }; struct SPMaskView { SPMaskView *next; unsigned int key; Inkscape::DrawingItem *arenaitem; - NRRect bbox; -}; + Geom::OptRect bbox; +};*/ namespace Inkscape { namespace Extension { @@ -1043,27 +1043,22 @@ CairoRenderContext::_createPatternPainter(SPPaintServer const *const paintserver // create pattern contents coordinate system if (pat->viewBox_set) { - NRRect *view_box = pattern_viewBox(pat); + Geom::Rect view_box = *pattern_viewBox(pat); double x, y, w, h; - double view_width, view_height; x = 0; y = 0; w = width * bbox_width_scaler; h = height * bbox_height_scaler; - view_width = view_box->x1 - view_box->x0; - view_height = view_box->y1 - view_box->y0; - //calculatePreserveAspectRatio(pat->aspect_align, pat->aspect_clip, view_width, view_height, &x, &y, &w, &h); - pcs2dev[0] = w / view_width; - pcs2dev[3] = h / view_height; - pcs2dev[4] = x - view_box->x0 * pcs2dev[0]; - pcs2dev[5] = y - view_box->y0 * pcs2dev[3]; + pcs2dev[0] = w / view_box.width(); + pcs2dev[3] = h / view_box.height(); + pcs2dev[4] = x - view_box.left() * pcs2dev[0]; + pcs2dev[5] = y - view_box.top() * pcs2dev[3]; } else if (pbox && pattern_patternContentUnits(pat) == SP_PATTERN_UNITS_OBJECTBOUNDINGBOX) { pcs2dev[0] = pbox->width(); pcs2dev[3] = pbox->height(); - } // Calculate the size of the surface which has to be created diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index adfa0421d..3a2cea3c1 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -87,14 +87,14 @@ struct SPClipPathView { SPClipPathView *next; unsigned int key; Inkscape::DrawingItem *arenaitem; - NRRect bbox; + Geom::OptRect bbox; }; struct SPMaskView { SPMaskView *next; unsigned int key; Inkscape::DrawingItem *arenaitem; - NRRect bbox; + Geom::OptRect bbox; }; namespace Inkscape { @@ -394,8 +394,8 @@ static void sp_symbol_render(SPItem *item, CairoRenderContext *ctx) width = 1.0; height = 1.0; - view_width = symbol->viewBox.x1 - symbol->viewBox.x0; - view_height = symbol->viewBox.y1 - symbol->viewBox.y0; + view_width = symbol->viewBox.width(); + view_height = symbol->viewBox.height(); calculatePreserveAspectRatio(symbol->aspect_align, symbol->aspect_clip, view_width, view_height, &x, &y,&width, &height); @@ -404,8 +404,8 @@ static void sp_symbol_render(SPItem *item, CairoRenderContext *ctx) vb2user = Geom::identity(); vb2user[0] = width / view_width; vb2user[3] = height / view_height; - vb2user[4] = x - symbol->viewBox.x0 * vb2user[0]; - vb2user[5] = y - symbol->viewBox.y0 * vb2user[3]; + vb2user[4] = x - symbol->viewBox.left() * vb2user[0]; + vb2user[5] = y - symbol->viewBox.top() * vb2user[3]; ctx->transform(vb2user); } @@ -668,13 +668,14 @@ CairoRenderer::applyClipPath(CairoRenderContext *ctx, SPClipPath const *cp) CairoRenderContext::CairoRenderMode saved_mode = ctx->getRenderMode(); ctx->setRenderMode(CairoRenderContext::RENDER_MODE_CLIP); + // FIXME: the access to the first clippath view to obtain the bbox is completely bogus Geom::Affine saved_ctm; - if (cp->clipPathUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX) { + if (cp->clipPathUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX && cp->display->bbox) { //SP_PRINT_DRECT("clipd", cp->display->bbox); - NRRect clip_bbox(cp->display->bbox); - Geom::Affine t(Geom::Scale(clip_bbox.x1 - clip_bbox.x0, clip_bbox.y1 - clip_bbox.y0)); - t[4] = clip_bbox.x0; - t[5] = clip_bbox.y0; + Geom::Rect clip_bbox = *cp->display->bbox; + Geom::Affine t(Geom::Scale(clip_bbox.dimensions())); + t[4] = clip_bbox.left(); + t[5] = clip_bbox.top(); t *= ctx->getCurrentState()->transform; saved_ctm = ctx->getTransform(); ctx->setTransform(t); @@ -720,13 +721,14 @@ CairoRenderer::applyMask(CairoRenderContext *ctx, SPMask const *mask) if (mask == NULL) return; - //SP_PRINT_DRECT("maskd", &mask->display->bbox); - NRRect mask_bbox(mask->display->bbox); + // FIXME: the access to the first mask view to obtain the bbox is completely bogus // TODO: should the bbox be transformed if maskUnits != userSpaceOnUse ? - if (mask->maskContentUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX) { - Geom::Affine t(Geom::Scale(mask_bbox.x1 - mask_bbox.x0, mask_bbox.y1 - mask_bbox.y0)); - t[4] = mask_bbox.x0; - t[5] = mask_bbox.y0; + if (mask->maskContentUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX && mask->display->bbox) { + //SP_PRINT_DRECT("maskd", &mask->display->bbox); + Geom::Rect mask_bbox = *mask->display->bbox; + Geom::Affine t(Geom::Scale(mask_bbox.dimensions())); + t[4] = mask_bbox.left(); + t[5] = mask_bbox.top(); t *= ctx->getCurrentState()->transform; ctx->setTransform(t); } diff --git a/src/marker.cpp b/src/marker.cpp index 9db5cfdc1..db9779460 100644 --- a/src/marker.cpp +++ b/src/marker.cpp @@ -349,10 +349,7 @@ static void sp_marker_update(SPObject *object, SPCtx *ctx, guint flags) rctx.i2doc = Geom::identity(); rctx.i2vp = Geom::identity(); /* Set up viewport */ - rctx.vp.x0 = 0.0; - rctx.vp.y0 = 0.0; - rctx.vp.x1 = marker->markerWidth.computed; - rctx.vp.y1 = marker->markerHeight.computed; + rctx.viewport = Geom::Rect::from_xywh(0, 0, marker->markerWidth.computed, marker->markerHeight.computed); /* Start with identity transform */ marker->c2p.setIdentity(); @@ -361,20 +358,20 @@ static void sp_marker_update(SPObject *object, SPCtx *ctx, guint flags) if (marker->viewBox) { vb = *marker->viewBox; } else { - vb = *(rctx.vp.upgrade_2geom()); + vb = rctx.viewport; } /* Now set up viewbox transformation */ /* Determine actual viewbox in viewport coordinates */ if (marker->aspect_align == SP_ASPECT_NONE) { x = 0.0; y = 0.0; - width = rctx.vp.x1 - rctx.vp.x0; - height = rctx.vp.y1 - rctx.vp.y0; + width = rctx.viewport.width(); + height = rctx.viewport.height(); } else { double scalex, scaley, scale; /* Things are getting interesting */ - scalex = (rctx.vp.x1 - rctx.vp.x0) / (vb.width()); - scaley = (rctx.vp.y1 - rctx.vp.y0) / (vb.height()); + scalex = rctx.viewport.width() / (vb.width()); + scaley = rctx.viewport.height() / (vb.height()); scale = (marker->aspect_clip == SP_ASPECT_MEET) ? MIN (scalex, scaley) : MAX (scalex, scaley); width = (vb.width()) * scale; height = (vb.height()) * scale; @@ -385,36 +382,36 @@ static void sp_marker_update(SPObject *object, SPCtx *ctx, guint flags) y = 0.0; break; case SP_ASPECT_XMID_YMIN: - x = 0.5 * ((rctx.vp.x1 - rctx.vp.x0) - width); + x = 0.5 * (rctx.viewport.width() - width); y = 0.0; break; case SP_ASPECT_XMAX_YMIN: - x = 1.0 * ((rctx.vp.x1 - rctx.vp.x0) - width); + x = 1.0 * (rctx.viewport.width() - width); y = 0.0; break; case SP_ASPECT_XMIN_YMID: x = 0.0; - y = 0.5 * ((rctx.vp.y1 - rctx.vp.y0) - height); + y = 0.5 * (rctx.viewport.height() - height); break; case SP_ASPECT_XMID_YMID: - x = 0.5 * ((rctx.vp.x1 - rctx.vp.x0) - width); - y = 0.5 * ((rctx.vp.y1 - rctx.vp.y0) - height); + x = 0.5 * (rctx.viewport.width() - width); + y = 0.5 * (rctx.viewport.height() - height); break; case SP_ASPECT_XMAX_YMID: - x = 1.0 * ((rctx.vp.x1 - rctx.vp.x0) - width); - y = 0.5 * ((rctx.vp.y1 - rctx.vp.y0) - height); + x = 1.0 * (rctx.viewport.width() - width); + y = 0.5 * (rctx.viewport.height() - height); break; case SP_ASPECT_XMIN_YMAX: x = 0.0; - y = 1.0 * ((rctx.vp.y1 - rctx.vp.y0) - height); + y = 1.0 * (rctx.viewport.height() - height); break; case SP_ASPECT_XMID_YMAX: - x = 0.5 * ((rctx.vp.x1 - rctx.vp.x0) - width); - y = 1.0 * ((rctx.vp.y1 - rctx.vp.y0) - height); + x = 0.5 * (rctx.viewport.width() - width); + y = 1.0 * (rctx.viewport.height() - height); break; case SP_ASPECT_XMAX_YMAX: - x = 1.0 * ((rctx.vp.x1 - rctx.vp.x0) - width); - y = 1.0 * ((rctx.vp.y1 - rctx.vp.y0) - height); + x = 1.0 * (rctx.viewport.width() - width); + y = 1.0 * (rctx.viewport.height() - height); break; default: x = 0.0; @@ -432,10 +429,7 @@ static void sp_marker_update(SPObject *object, SPCtx *ctx, guint flags) /* If viewBox is set reinitialize child viewport */ /* Otherwise it already correct */ if (marker->viewBox) { - rctx.vp.x0 = marker->viewBox->min()[Geom::X]; - rctx.vp.y0 = marker->viewBox->min()[Geom::Y]; - rctx.vp.x1 = marker->viewBox->max()[Geom::X]; - rctx.vp.y1 = marker->viewBox->max()[Geom::Y]; + rctx.viewport = *marker->viewBox; rctx.i2vp = Geom::identity(); } diff --git a/src/print.h b/src/print.h index d584245e5..422f18669 100644 --- a/src/print.h +++ b/src/print.h @@ -17,7 +17,6 @@ #include "forward.h" #include "extension/extension-forward.h" -struct NRRect; struct SPPrintContext { Inkscape::Extension::Print *module; }; diff --git a/src/sp-ellipse.cpp b/src/sp-ellipse.cpp index 99189da45..ba100a1d7 100644 --- a/src/sp-ellipse.cpp +++ b/src/sp-ellipse.cpp @@ -140,19 +140,18 @@ sp_genericellipse_update(SPObject *object, SPCtx *ctx, guint flags) if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { SPGenericEllipse *ellipse = (SPGenericEllipse *) object; SPStyle const *style = object->style; - Geom::OptRect viewbox = ((SPItemCtx const *) ctx)->vp; - if (viewbox) { - double const dx = viewbox->width(); - double const dy = viewbox->height(); - double const dr = sqrt(dx*dx + dy*dy)/sqrt(2); - double const em = style->font_size.computed; - double const ex = em * 0.5; // fixme: get from pango or libnrtype - ellipse->cx.update(em, ex, dx); - ellipse->cy.update(em, ex, dy); - ellipse->rx.update(em, ex, dr); - ellipse->ry.update(em, ex, dr); - static_cast<SPShape *>(object)->setShape(); - } + Geom::Rect const &viewbox = ((SPItemCtx const *) ctx)->viewport; + + double const dx = viewbox.width(); + double const dy = viewbox.height(); + double const dr = sqrt(dx*dx + dy*dy)/sqrt(2); + double const em = style->font_size.computed; + double const ex = em * 0.5; // fixme: get from pango or libnrtype + ellipse->cx.update(em, ex, dx); + ellipse->cy.update(em, ex, dy); + ellipse->rx.update(em, ex, dr); + ellipse->ry.update(em, ex, dr); + static_cast<SPShape *>(object)->setShape(); } if (((SPObjectClass *) ge_parent_class)->update) diff --git a/src/sp-item.h b/src/sp-item.h index 62336e3c8..21b3d9006 100644 --- a/src/sp-item.h +++ b/src/sp-item.h @@ -88,7 +88,7 @@ public: /** Item to document transformation */ Geom::Affine i2doc; /** Viewport size */ - NRRect vp; + Geom::Rect viewport; /** Item to viewport transformation */ Geom::Affine i2vp; }; diff --git a/src/sp-line.cpp b/src/sp-line.cpp index d3faf2299..06604a1d6 100644 --- a/src/sp-line.cpp +++ b/src/sp-line.cpp @@ -127,8 +127,8 @@ void SPLine::update(SPObject *object, SPCtx *ctx, guint flags) SPStyle const *style = object->style; SPItemCtx const *ictx = (SPItemCtx const *) ctx; - double const w = (ictx->vp.x1 - ictx->vp.x0); - double const h = (ictx->vp.y1 - ictx->vp.y0); + double const w = ictx->viewport.width(); + double const h = ictx->viewport.height(); double const em = style->font_size.computed; double const ex = em * 0.5; // fixme: get from pango or libnrtype. line->x1.update(em, ex, w); diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 71ee8298b..e94a02265 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -807,10 +807,7 @@ void sp_namedview_window_from_document(SPDesktop *desktop) } // cancel any history of zooms up to this point - if (desktop->zooms_past) { - g_list_free(desktop->zooms_past); - desktop->zooms_past = NULL; - } + desktop->zooms_past.clear(); } bool SPNamedView::getSnapGlobal() const diff --git a/src/sp-paint-server.cpp b/src/sp-paint-server.cpp index be7494908..ceb36740f 100644 --- a/src/sp-paint-server.cpp +++ b/src/sp-paint-server.cpp @@ -73,11 +73,8 @@ cairo_pattern_t *sp_paint_server_create_pattern(SPPaintServer *ps, Geom::OptRect const &bbox, double opacity) { - // NOTE: the ct argument is used for when rendering patterns - // to create a group, instead of explicitly creating a temporary surface g_return_val_if_fail(ps != NULL, NULL); g_return_val_if_fail(SP_IS_PAINT_SERVER(ps), NULL); - g_return_val_if_fail(bbox != NULL, NULL); cairo_pattern_t *cp = NULL; SPPaintServerClass *psc = (SPPaintServerClass *) G_OBJECT_GET_CLASS(ps); diff --git a/src/sp-paint-server.h b/src/sp-paint-server.h index 7d6f7a5ef..a266ee5a5 100644 --- a/src/sp-paint-server.h +++ b/src/sp-paint-server.h @@ -20,8 +20,6 @@ #include "sp-object.h" #include "uri-references.h" -struct NRRect; - #define SP_TYPE_PAINT_SERVER (SPPaintServer::get_type()) #define SP_PAINT_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_PAINT_SERVER, SPPaintServer)) #define SP_PAINT_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SP_TYPE_PAINT_SERVER, SPPaintServerClass)) diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp index b8ccf5648..03afc1bf3 100644 --- a/src/sp-pattern.cpp +++ b/src/sp-pattern.cpp @@ -245,11 +245,8 @@ sp_pattern_set (SPObject *object, unsigned int key, const gchar *value) height = g_ascii_strtod (eptr, &eptr); while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++; if ((width > 0) && (height > 0)) { - pat->viewBox.x0 = x; - pat->viewBox.y0 = y; - pat->viewBox.x1 = x + width; - pat->viewBox.y1 = y + height; - pat->viewBox_set = TRUE; + pat->viewBox = Geom::Rect::from_xywh(x, y, width, height); + pat->viewBox_set = TRUE; } else { pat->viewBox_set = FALSE; } @@ -581,13 +578,16 @@ gdouble pattern_height (SPPattern *pat) return 0; } -NRRect *pattern_viewBox (SPPattern *pat) +Geom::OptRect pattern_viewBox (SPPattern *pat) { - for (SPPattern *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { - if (pat_i->viewBox_set) - return &(pat_i->viewBox); - } - return &(pat->viewBox); + Geom::OptRect viewbox; + for (SPPattern *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { + if (pat_i->viewBox_set) { + viewbox = pat_i->viewBox; + break; + } + } + return viewbox; } bool pattern_hasItemChildren (SPPattern *pat) @@ -647,11 +647,12 @@ sp_pattern_create_pattern(SPPaintServer *ps, } if (pat->viewBox_set) { - gdouble tmp_x = pattern_width (pat) / (pattern_viewBox(pat)->x1 - pattern_viewBox(pat)->x0); - gdouble tmp_y = pattern_height (pat) / (pattern_viewBox(pat)->y1 - pattern_viewBox(pat)->y0); + Geom::Rect vb = *pattern_viewBox(pat); + gdouble tmp_x = pattern_width (pat) / vb.width(); + gdouble tmp_y = pattern_height (pat) / vb.height(); // FIXME: preserveAspectRatio must be taken into account here too! - vb2ps = Geom::Affine(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); + vb2ps = Geom::Affine(tmp_x, 0.0, 0.0, tmp_y, pattern_x(pat) - vb.left() * tmp_x, pattern_y(pat) - vb.top() * tmp_y); } ps2user = pattern_patternTransform(pat); diff --git a/src/sp-pattern.h b/src/sp-pattern.h index 1f545bfc4..ee7ffd477 100644 --- a/src/sp-pattern.h +++ b/src/sp-pattern.h @@ -72,7 +72,7 @@ struct SPPattern : public SPPaintServer { SVGLength width; SVGLength height; /* VieBox */ - NRRect viewBox; + Geom::Rect viewBox; guint viewBox_set : 1; sigc::connection modified_connection; @@ -98,7 +98,7 @@ gdouble pattern_x (SPPattern *pat); gdouble pattern_y (SPPattern *pat); gdouble pattern_width (SPPattern *pat); gdouble pattern_height (SPPattern *pat); -NRRect *pattern_viewBox (SPPattern *pat); +Geom::OptRect pattern_viewBox (SPPattern *pat); #endif // SEEN_SP_PATTERN_H diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index 729e2a34c..22a403345 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -173,8 +173,8 @@ sp_rect_update(SPObject *object, SPCtx *ctx, guint flags) SPRect *rect = (SPRect *) object; SPStyle *style = object->style; SPItemCtx const *ictx = (SPItemCtx const *) ctx; - double const w = (ictx->vp.x1 - ictx->vp.x0); - double const h = (ictx->vp.y1 - ictx->vp.y0); + double const w = ictx->viewport.width(); + double const h = ictx->viewport.height(); double const em = style->font_size.computed; double const ex = 0.5 * em; // fixme: get x height from pango or libnrtype. rect->x.update(em, ex, w); diff --git a/src/sp-root.cpp b/src/sp-root.cpp index a6df580d3..788d1958a 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -123,7 +123,6 @@ sp_root_init(SPRoot *root) root->width.unset(SVGLength::PERCENT, 1.0, 1.0); root->height.unset(SVGLength::PERCENT, 1.0, 1.0); - /* root->viewbox.set_identity(); */ root->viewBox_set = FALSE; root->c2p.setIdentity(); @@ -253,10 +252,7 @@ sp_root_set(SPObject *object, unsigned int key, gchar const *value) while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++; if ((width > 0) && (height > 0)) { /* Set viewbox */ - root->viewBox.x0 = x; - root->viewBox.y0 = y; - root->viewBox.x1 = x + width; - root->viewBox.y1 = y + height; + root->viewBox = Geom::Rect::from_xywh(x, y, width, height); root->viewBox_set = TRUE; } else { root->viewBox_set = FALSE; @@ -404,16 +400,16 @@ static void sp_root_update(SPObject *object, SPCtx *ctx, guint flags) /* fixme: We should calculate only if parent viewport has changed (Lauris) */ /* If position is specified as percentage, calculate actual values */ if (root->x.unit == SVGLength::PERCENT) { - root->x.computed = root->x.value * (ictx->vp.x1 - ictx->vp.x0); + root->x.computed = root->x.value * ictx->viewport.width(); } if (root->y.unit == SVGLength::PERCENT) { - root->y.computed = root->y.value * (ictx->vp.y1 - ictx->vp.y0); + root->y.computed = root->y.value * ictx->viewport.height(); } if (root->width.unit == SVGLength::PERCENT) { - root->width.computed = root->width.value * (ictx->vp.x1 - ictx->vp.x0); + root->width.computed = root->width.value * ictx->viewport.width(); } if (root->height.unit == SVGLength::PERCENT) { - root->height.computed = root->height.value * (ictx->vp.y1 - ictx->vp.y0); + root->height.computed = root->height.value * ictx->viewport.height(); } /* Create copy of item context */ @@ -445,11 +441,11 @@ static void sp_root_update(SPObject *object, SPCtx *ctx, guint flags) } else { double scalex, scaley, scale; /* Things are getting interesting */ - scalex = root->width.computed / (root->viewBox.x1 - root->viewBox.x0); - scaley = root->height.computed / (root->viewBox.y1 - root->viewBox.y0); + scalex = root->width.computed / root->viewBox.width(); + scaley = root->height.computed / root->viewBox.height(); scale = (root->aspect_clip == SP_ASPECT_MEET) ? MIN(scalex, scaley) : MAX(scalex, scaley); - width = (root->viewBox.x1 - root->viewBox.x0) * scale; - height = (root->viewBox.y1 - root->viewBox.y0) * scale; + width = root->viewBox.width() * scale; + height = root->viewBox.height() * scale; /* Now place viewbox to requested position */ /* todo: Use an array lookup to find the 0.0/0.5/1.0 coefficients, as is done for dialogs/align.cpp. */ @@ -498,38 +494,27 @@ static void sp_root_update(SPObject *object, SPCtx *ctx, guint flags) } /* Compose additional transformation from scale and position */ - Geom::Point const viewBox_min(root->viewBox.x0, - root->viewBox.y0); - Geom::Point const viewBox_max(root->viewBox.x1, - root->viewBox.y1); - Geom::Scale const viewBox_length( viewBox_max - viewBox_min ); + Geom::Scale const viewBox_length( root->viewBox.dimensions() ); Geom::Scale const new_length(width, height); /* Append viewbox transformation */ /* TODO: The below looks suspicious to me (pjrm): I wonder whether the RHS expression should have c2p at the beginning rather than at the end. Test it. */ - root->c2p = Geom::Translate(-viewBox_min) * ( new_length * viewBox_length.inverse() ) * Geom::Translate(x, y) * root->c2p; + root->c2p = Geom::Translate(-root->viewBox.min()) * ( new_length * viewBox_length.inverse() ) * Geom::Translate(x, y) * root->c2p; } rctx.i2doc = root->c2p * rctx.i2doc; /* Initialize child viewport */ if (root->viewBox_set) { - rctx.vp.x0 = root->viewBox.x0; - rctx.vp.y0 = root->viewBox.y0; - rctx.vp.x1 = root->viewBox.x1; - rctx.vp.y1 = root->viewBox.y1; + rctx.viewport = root->viewBox; } else { /* fixme: I wonder whether this logic is correct (Lauris) */ + Geom::Point minp(0,0); if (object->parent) { - rctx.vp.x0 = root->x.computed; - rctx.vp.y0 = root->y.computed; - } else { - rctx.vp.x0 = 0.0; - rctx.vp.y0 = 0.0; + minp = Geom::Point(root->x.computed, root->y.computed); } - rctx.vp.x1 = root->width.computed; - rctx.vp.y1 = root->height.computed; + rctx.viewport = Geom::Rect::from_xywh(minp[Geom::X], minp[Geom::Y], root->width.computed, root->height.computed); } rctx.i2vp = Geom::identity(); @@ -597,7 +582,8 @@ sp_root_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML: if (root->viewBox_set) { Inkscape::SVGOStringStream os; - os << root->viewBox.x0 << " " << root->viewBox.y0 << " " << root->viewBox.x1 - root->viewBox.x0 << " " << root->viewBox.y1 - root->viewBox.y0; + os << root->viewBox.left() << " " << root->viewBox.top() << " " + << root->viewBox.width() << " " << root->viewBox.height(); repr->setAttribute("viewBox", os.str().c_str()); } diff --git a/src/sp-root.h b/src/sp-root.h index 86b92b2b3..e2bad917b 100644 --- a/src/sp-root.h +++ b/src/sp-root.h @@ -1,6 +1,3 @@ -#ifndef SP_ROOT_H_SEEN -#define SP_ROOT_H_SEEN - /** \file * SPRoot: SVG \<svg\> implementation. */ @@ -14,17 +11,20 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#define SP_TYPE_ROOT (sp_root_get_type()) -#define SP_ROOT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_ROOT, SPRoot)) -#define SP_ROOT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), SP_TYPE_ROOT, SPRootClass)) -#define SP_IS_ROOT(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), SP_TYPE_ROOT)) -#define SP_IS_ROOT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), SP_TYPE_ROOT)) +#ifndef SP_ROOT_H_SEEN +#define SP_ROOT_H_SEEN #include "version.h" #include "svg/svg-length.h" #include "enums.h" #include "sp-item-group.h" +#define SP_TYPE_ROOT (sp_root_get_type()) +#define SP_ROOT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_ROOT, SPRoot)) +#define SP_ROOT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), SP_TYPE_ROOT, SPRootClass)) +#define SP_IS_ROOT(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), SP_TYPE_ROOT)) +#define SP_IS_ROOT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), SP_TYPE_ROOT)) + class SPDefs; /** \<svg\> element */ @@ -41,7 +41,7 @@ struct SPRoot : public SPGroup { /* viewBox; */ unsigned int viewBox_set : 1; - NRRect viewBox; + Geom::Rect viewBox; /* preserveAspectRatio */ unsigned int aspect_set : 1; diff --git a/src/sp-symbol.cpp b/src/sp-symbol.cpp index 0a1ebdb06..87cd210e4 100644 --- a/src/sp-symbol.cpp +++ b/src/sp-symbol.cpp @@ -131,10 +131,7 @@ static void sp_symbol_set(SPObject *object, unsigned int key, const gchar *value while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++; if ((width > 0) && (height > 0)) { /* Set viewbox */ - symbol->viewBox.x0 = x; - symbol->viewBox.y0 = y; - symbol->viewBox.x1 = x + width; - symbol->viewBox.y1 = y + height; + symbol->viewBox = Geom::Rect::from_xywh(x, y, width, height); symbol->viewBox_set = TRUE; } else { symbol->viewBox_set = FALSE; @@ -234,7 +231,7 @@ static void sp_symbol_update(SPObject *object, SPCtx *ctx, guint flags) /* Calculate child to parent transformation */ /* Apply parent <use> translation (set up as vewport) */ - symbol->c2p = Geom::Affine(Geom::Translate(rctx.vp.x0, rctx.vp.y0)); + symbol->c2p = Geom::Translate(rctx.viewport.min()); if (symbol->viewBox_set) { double x, y, width, height; @@ -242,16 +239,16 @@ static void sp_symbol_update(SPObject *object, SPCtx *ctx, guint flags) if (symbol->aspect_align == SP_ASPECT_NONE) { x = 0.0; y = 0.0; - width = rctx.vp.x1 - rctx.vp.x0; - height = rctx.vp.y1 - rctx.vp.y0; + width = rctx.viewport.width(); + height = rctx.viewport.height(); } else { double scalex, scaley, scale; /* Things are getting interesting */ - scalex = (rctx.vp.x1 - rctx.vp.x0) / (symbol->viewBox.x1 - symbol->viewBox.x0); - scaley = (rctx.vp.y1 - rctx.vp.y0) / (symbol->viewBox.y1 - symbol->viewBox.y0); + scalex = rctx.viewport.width() / symbol->viewBox.width(); + scaley = rctx.viewport.height() / symbol->viewBox.height(); scale = (symbol->aspect_clip == SP_ASPECT_MEET) ? MIN (scalex, scaley) : MAX (scalex, scaley); - width = (symbol->viewBox.x1 - symbol->viewBox.x0) * scale; - height = (symbol->viewBox.y1 - symbol->viewBox.y0) * scale; + width = symbol->viewBox.width() * scale; + height = symbol->viewBox.height() * scale; /* Now place viewbox to requested position */ switch (symbol->aspect_align) { case SP_ASPECT_XMIN_YMIN: @@ -259,36 +256,36 @@ static void sp_symbol_update(SPObject *object, SPCtx *ctx, guint flags) y = 0.0; break; case SP_ASPECT_XMID_YMIN: - x = 0.5 * ((rctx.vp.x1 - rctx.vp.x0) - width); + x = 0.5 * (rctx.viewport.width() - width); y = 0.0; break; case SP_ASPECT_XMAX_YMIN: - x = 1.0 * ((rctx.vp.x1 - rctx.vp.x0) - width); + x = 1.0 * (rctx.viewport.width() - width); y = 0.0; break; case SP_ASPECT_XMIN_YMID: x = 0.0; - y = 0.5 * ((rctx.vp.y1 - rctx.vp.y0) - height); + y = 0.5 * (rctx.viewport.height() - height); break; case SP_ASPECT_XMID_YMID: - x = 0.5 * ((rctx.vp.x1 - rctx.vp.x0) - width); - y = 0.5 * ((rctx.vp.y1 - rctx.vp.y0) - height); + x = 0.5 * (rctx.viewport.width() - width); + y = 0.5 * (rctx.viewport.height() - height); break; case SP_ASPECT_XMAX_YMID: - x = 1.0 * ((rctx.vp.x1 - rctx.vp.x0) - width); - y = 0.5 * ((rctx.vp.y1 - rctx.vp.y0) - height); + x = 1.0 * (rctx.viewport.width() - width); + y = 0.5 * (rctx.viewport.height() - height); break; case SP_ASPECT_XMIN_YMAX: x = 0.0; - y = 1.0 * ((rctx.vp.y1 - rctx.vp.y0) - height); + y = 1.0 * (rctx.viewport.height() - height); break; case SP_ASPECT_XMID_YMAX: - x = 0.5 * ((rctx.vp.x1 - rctx.vp.x0) - width); - y = 1.0 * ((rctx.vp.y1 - rctx.vp.y0) - height); + x = 0.5 * (rctx.viewport.width() - width); + y = 1.0 * (rctx.viewport.height() - height); break; case SP_ASPECT_XMAX_YMAX: - x = 1.0 * ((rctx.vp.x1 - rctx.vp.x0) - width); - y = 1.0 * ((rctx.vp.y1 - rctx.vp.y0) - height); + x = 1.0 * (rctx.viewport.width() - width); + y = 1.0 * (rctx.viewport.height() - height); break; default: x = 0.0; @@ -298,12 +295,12 @@ static void sp_symbol_update(SPObject *object, SPCtx *ctx, guint flags) } /* Compose additional transformation from scale and position */ Geom::Affine q; - q[0] = width / (symbol->viewBox.x1 - symbol->viewBox.x0); + q[0] = width / symbol->viewBox.width(); q[1] = 0.0; q[2] = 0.0; - q[3] = height / (symbol->viewBox.y1 - symbol->viewBox.y0); - q[4] = -symbol->viewBox.x0 * q[0] + x; - q[5] = -symbol->viewBox.y0 * q[3] + y; + q[3] = height / symbol->viewBox.height(); + q[4] = -symbol->viewBox.left() * q[0] + x; + q[5] = -symbol->viewBox.top() * q[3] + y; /* Append viewbox transformation */ symbol->c2p = q * symbol->c2p; } @@ -313,10 +310,7 @@ static void sp_symbol_update(SPObject *object, SPCtx *ctx, guint flags) /* If viewBox is set initialize child viewport */ /* Otherwise <use> has set it up already */ if (symbol->viewBox_set) { - rctx.vp.x0 = symbol->viewBox.x0; - rctx.vp.y0 = symbol->viewBox.y0; - rctx.vp.x1 = symbol->viewBox.x1; - rctx.vp.y1 = symbol->viewBox.y1; + rctx.viewport = symbol->viewBox; rctx.i2vp = Geom::identity(); } diff --git a/src/sp-symbol.h b/src/sp-symbol.h index 120591459..536486bc3 100644 --- a/src/sp-symbol.h +++ b/src/sp-symbol.h @@ -33,7 +33,7 @@ class SPSymbolClass; struct SPSymbol : public SPGroup { /* viewBox; */ unsigned int viewBox_set : 1; - NRRect viewBox; + Geom::Rect viewBox; /* preserveAspectRatio */ unsigned int aspect_set : 1; diff --git a/src/sp-use.cpp b/src/sp-use.cpp index 057c01ef1..04cf1eb2c 100644 --- a/src/sp-use.cpp +++ b/src/sp-use.cpp @@ -594,21 +594,18 @@ sp_use_update(SPObject *object, SPCtx *ctx, unsigned flags) /* Set up child viewport */ if (use->x.unit == SVGLength::PERCENT) { - use->x.computed = use->x.value * (ictx->vp.x1 - ictx->vp.x0); + use->x.computed = use->x.value * ictx->viewport.width(); } if (use->y.unit == SVGLength::PERCENT) { - use->y.computed = use->y.value * (ictx->vp.y1 - ictx->vp.y0); + use->y.computed = use->y.value * ictx->viewport.height(); } if (use->width.unit == SVGLength::PERCENT) { - use->width.computed = use->width.value * (ictx->vp.x1 - ictx->vp.x0); + use->width.computed = use->width.value * ictx->viewport.width(); } if (use->height.unit == SVGLength::PERCENT) { - use->height.computed = use->height.value * (ictx->vp.y1 - ictx->vp.y0); + use->height.computed = use->height.value * ictx->viewport.height(); } - cctx.vp.x0 = 0.0; - cctx.vp.y0 = 0.0; - cctx.vp.x1 = use->width.computed; - cctx.vp.y1 = use->height.computed; + cctx.viewport = Geom::Rect::from_xywh(0, 0, use->width.computed, use->height.computed); cctx.i2vp = Geom::identity(); flags&=~SP_OBJECT_USER_MODIFIED_FLAG_B; |
