RE: Metapost - text alignment
- From: "Young, Robert" <Robert Young dsto defence gov au>
- To: "discussions about usage and development of dia" <dia-list gnome org>
- Subject: RE: Metapost - text alignment
- Date: Wed, 24 Jan 2007 16:28:32 +1030
It would be an excellent idea to implement draw_text_line.
You should then be able to drop draw_text entirely and have
draw_string call draw_text_line like in diagdkrenderer.
OK, I've taken more of a look. From my reading of DiaRenderer.c,
draw_text calls draw_text_line for each line. This is where the
metapost output becomes a problem - if I am rendering $A_{BC}$ in
metapost, centre aligned, then draw_text subtracts half the length
(text_line_get_alignment_adjustment) and tells
render_metapost.c (via
either draw_text_line or draw_string) that it's left aligned at the
aligned_pos - then metapost renders the text in the wrong position
because the length correction was not really correct.
Am I reading the code correctly? Should I implement draw_text in
render_metapost.c so that I get to control the text
positioning in the
metapost output? I'm in the "let the export renderer control
the text
positioning" camp, if that makes more sense? I note that svg export
also effectively removes the alignment on export.
Unless DIA goes so far as to have some tight integration with
a TeX renderer, it will never be able to properly calculate
the size of $A_{BC}$, which makes proper centering impossible.
MetaPost has two commands for positioning text.
label.xxx or draw
The label command will do the left right positioning
correctly, but it is based on the bounding box, not the
baseline, so it will not get the vertical positioning correct.
The draw command is based on the left hand end of the baseline.
Vertical positioning will be correct, but unless you can
calculate text width, you won't get horizontal positioning right.
I am of the opinion that draw is the better way to go. Most
text will not have special characters or formulas, so I think
it is most important to get the common case right (rather than
none of them). If a user is using lots of special LaTeX
formatting, then manually adjusting the horizontal positioning
isn't that big of a deal.
Rob,
I see your point, especially about the vertical positioning.
However, I'd suggest that at a minimum you would want to know where the
Metapost output will align to in the horizontal dimension?
For $A_{BC}$, if you wanted it to be aligned to the centre of a box, or
a line on a diagram, you want to know how MetaPost will position it.
My experience of Metapost is short. All the diagrams I have done in
Dia->Metapost have had text which is labeling lines, boxes, etc, and it
seemed to work OK in 0.94 and 0.95-1 (ignoring all the font scaling
problems). I could anchor the text, and know that it would then all
appear around the anchor, or to the left or right, depending on how the
alignment was set.
My thoughts for implementation were to obtain the bounding box from Dia
and then pass this to the Metapost label command. My reading of the code
is that for each string the bounding box is available, as are the size
of the ascent and descent. My understanding was that dia used the
baseline to position the text, and so obtaining the descent for each
string would allow me to calculate where to put the bounding box for
MetaPost. This would make the vertical positioning correct for standard
text.
I've read back throught mail list archive, and read your bug report on
the subject. I will test with a UML class diagram.
Thanks,
Rob.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]