From: Johan Engelen Date: Sun, 21 Feb 2010 11:39:17 +0000 (+0100) Subject: fix transforms X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ac7640dd5a146c4c3ab473785fe4560c60ae1d3b;p=inkscape.git fix transforms --- diff --git a/src/extension/internal/pdflatex-renderer.cpp b/src/extension/internal/pdflatex-renderer.cpp index 0d2ffcc94..d21457a89 100644 --- a/src/extension/internal/pdflatex-renderer.cpp +++ b/src/extension/internal/pdflatex-renderer.cpp @@ -105,10 +105,11 @@ namespace Internal { PDFLaTeXRenderer::PDFLaTeXRenderer(void) : _stream(NULL), _filename(NULL), - _m(Geom::identity()), _width(0), _height(0) -{} +{ + push_transform(Geom::identity()); +} PDFLaTeXRenderer::~PDFLaTeXRenderer(void) { @@ -334,10 +335,14 @@ PDFLaTeXRenderer::sp_text_render(SPItem *item) { SPText *textobj = SP_TEXT (item); + push_transform(sp_item_i2doc_affine(item)); + gchar *str = sp_te_get_string_multiline(item); - Geom::Point pos = SP_TEXT(item)->attributes.firstXY(); + Geom::Point pos = textobj->attributes.firstXY() * transform(); gchar *alignment = "lb"; + pop_transform(); + // write to LaTeX Inkscape::SVGOStringStream os; @@ -370,10 +375,10 @@ PDFLaTeXRenderer::sp_root_render(SPItem *item) // ctx->pushState(); // setStateForItem(ctx, item); -// Geom::Matrix tempmat (root->c2p); -// ctx->transform(&tempmat); + Geom::Matrix tempmat (root->c2p); + push_transform(tempmat); sp_group_render(item); -// ctx->popState(); + pop_transform(); } void @@ -470,23 +475,22 @@ PDFLaTeXRenderer::setupDocument(SPDocument *doc, bool pageBoundingBox, SPItem *b } // convert from px to pt - d.x0 *= PT_PER_PX; - d.x1 *= PT_PER_PX; - d.y0 *= PT_PER_PX; - d.y1 *= PT_PER_PX; - - _width = d.x1-d.x0; - _height = d.y1-d.y0; + push_transform( Geom::Scale(PT_PER_PX, PT_PER_PX) ); if (!pageBoundingBox) { double high = sp_document_height(doc); - high *= PT_PER_PX; - transform( Geom::Translate( -d.x0 * PX_PER_PT, - (d.y1 - high) * PX_PER_PT ) ); + push_transform( Geom::Translate( -d.x0, + -d.y0 ) ); } + // flip y-axis + push_transform( Geom::Scale(1,-1) * Geom::Translate(0, sp_document_height(doc)) ); + + _width = (d.x1-d.x0) * PT_PER_PX; + _height = (d.y1-d.y0) * PT_PER_PX; + // write the info to LaTeX Inkscape::SVGOStringStream os; @@ -500,12 +504,28 @@ PDFLaTeXRenderer::setupDocument(SPDocument *doc, bool pageBoundingBox, SPItem *b return true; } +Geom::Matrix const & +PDFLaTeXRenderer::transform() +{ + return _transform_stack.top(); +} + void -PDFLaTeXRenderer::transform(Geom::Matrix const &transform) +PDFLaTeXRenderer::push_transform(Geom::Matrix const &tr) { - _m *= transform; + if(_transform_stack.size()){ + Geom::Matrix tr_top = _transform_stack.top(); + _transform_stack.push(tr * tr_top); + } else { + _transform_stack.push(tr); + } } +void +PDFLaTeXRenderer::pop_transform() +{ + _transform_stack.pop(); +} /* #include "macros.h" // SP_PRINT_* diff --git a/src/extension/internal/pdflatex-renderer.h b/src/extension/internal/pdflatex-renderer.h index 856631f95..93c06b114 100644 --- a/src/extension/internal/pdflatex-renderer.h +++ b/src/extension/internal/pdflatex-renderer.h @@ -26,6 +26,7 @@ #include #include <2geom/matrix.h> +#include class SPClipPath; class SPMask; @@ -58,8 +59,10 @@ protected: FILE * _stream; gchar * _filename; - void transform(Geom::Matrix const &transform); - Geom::Matrix _m; // the transform for current item + void push_transform(Geom::Matrix const &transform); + Geom::Matrix const & transform(); + void pop_transform(); + std::stack _transform_stack; double _width; double _height;