GNOME Bugzilla – Bug 482173
Exports tries to be too smart when placing texts
Last modified: 2009-11-02 19:50:33 UTC
Please describe the problem: When exporting to PSTricks or PGF for LaTeX, Dia computes the position of the left side of text strings, and places them there with left alignement. This is kind of stupid, because the point of LaTeX export is to let LaTeX render the text, and the position of the left point computed by Dia will be incorrect. Steps to reproduce: 1. Draw a box and put some text inside, centered in the middle of the box 2. Export to PGF 3. Compile in a LaTeX document Actual results: The text is not centered correctly. Expected results: Does this happen every time? Other information: I attach a patch to fix the PGF export. draw_string allready handles alignement correctly, we only need to override the stupid calculation in draw_text. A similar fix should be applied to the PStricks export. Additionnally, this patch modifies a little bit the preamble: I puts the actual value of \du inside the conditional, so that youy just have to define \du once in your LaTeX document to scale every Dia picture. I also define a conditional to easily disable TeX escaping (defaults to no escaping, wich could make some people angry but is really what I need...): I guess this shoult be dealt with a ./configure option, but I am not familiar with autoconf...
Created attachment 96462 [details] [review] Patch to fix PGF export Note: multiline texts could be put in a parbox instead of letting Dia compute the height of a line...
You patch is mostly reverting something which apparently never hit SVN - at least I'm not able to find any traces of it, neither on the o.96 branch nor on trunk. Lars: maybe you forgot to commit before doing the release?
Forget about the comment: the patch is inverted. It marks with '-' what needs to be added.
Thanks for the report and patch. I've chosen to have a sensible default behavior everywhere, not only with pgf export ;) 2007-10-13 Hans Breuer <hans@breuer.org> * lib/diarenderer.[ch] lib/textline.[ch] lib/libdia.def : instead of throwing away the alignment information in DiaRenderer::draw_text pass it through DiaRenderer::draw_text_line so it is still available for renderers just implementing DiaRenderer::draw_string * app/diapsft2renderer.c app/diapsrenderer.c lib/diagdkrenderer.c lib/dialibartrenderer.c plug-ins/metapost/render_metapost.c : adapted accordingly, should give same results as before * lib/diasvgrenderer.c : adapted and write text-anchor again * plug-ins/cairo/diacairo.c : make DiaCairoRenderer::draw_string work for alignment CENTER and RIGHT as well * plug-ins/pgf/render_pgf.c : put \\setlength{\\du}{15\\unitlength}\n into the if branch (Gaëtan Leurent, bug #482173)
Well, actually, I noticed that there is a problem with putting the \\setlength{\\du}{15\\unitlength} inside the if branch... If \du is not defined before \input-ing the first dia picture, it is defined by the picture, and set to the value of 15\unitlength, which is fine for this picture, but unfortunatly, \setlength only has a local effect... In the next dia picture, \du is already defined (\newlength has a global effect) so we don't enter the if branch, and with this patch we don't set \du to a usefull value, and we get a messed-up picture because \du is set to zero. Sorry about that, I didn't know about this locality problem in LaTeX... To make it clear, the old code does \ifx\du\undefined \newlength{\du} \fi \setlength{\du}{15\unitlength} which is fine but gives no easy way to scale the picture, while the new one does \ifx\du\undefined \newlength{\du} \setlength{\du}{15\unitlength} \fi which is good if you define \du outside the pictures to scale them or if you only use one dia picture in your document... but fails when you have two pictures and you don't try to scale them. I'm not a LaTeX export expert, so I'm not really sure what the best solution is, but a possible workaroud seems to be \global\du=15\unitlength instead of \setlength{\du}{15\unitlength} inside the if branch (it will set the value of \du globally) Or you could just revert this part of the patch, but I feel it would be a nice feature to be able to scale the dia pictures easily...
2007-10-14 Hans Breuer <hans@breuer.org> * plug-ins/pgf/render_pgf.c : *reverted* put \\setlength{\\du}{15\\unitlength}\n into the if branch (again Gaëtan Leurent, bug #482173)
*** Bug 600418 has been marked as a duplicate of this bug. ***