After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 332554 - More metapost text positioning
More metapost text positioning
Status: RESOLVED FIXED
Product: dia
Classification: Other
Component: exports
0.95
Other All
: Normal normal
: 0.96
Assigned To: Dia maintainers
Dia maintainers
Depends on:
Blocks:
 
 
Reported: 2006-02-25 17:15 UTC by Rob McDonald
Modified: 2008-05-18 14:13 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test cases for MetaPost (23.73 KB, application/x-compressed-tar)
2007-01-30 04:17 UTC, Robert Young
  Details
Patch referenced in comment #2 and #3 (3.34 KB, patch)
2007-01-30 04:27 UTC, Robert Young
none Details | Review
Metapost Test Cases (37.79 KB, application/x-compressed-tar)
2007-01-30 23:32 UTC, Robert Young
  Details
Improved font size matching (4.09 KB, patch)
2007-01-30 23:34 UTC, Robert Young
none Details | Review
Patch with text_line (5.84 KB, patch)
2007-01-31 07:17 UTC, Lars Clausen
committed Details | Review

Description Rob McDonald 2006-02-25 17:15:41 UTC
Please describe the problem:
The metapost command label uses a bouding box as a reference point for 
positioning text.  This makes consistent positioning impossible.

Steps to reproduce:
1. Create a UML class diagram
2. Enter a list of properties, some with tall letters T,h,I, some with normal 
letters e,o,u,w, and some with descending letters p,y,j.  Say This, puny, car, 
with some other words thrown in for good measure.
3. Export MetaPost, compile, and observe the uneven spacing of the words.


Actual results:
The words aren't spaced right.

Expected results:
Have them be spaced right

Does this happen every time?
Yes

Other information:
> It turns out that MetaPost positions text based on the bounding box of
that
> particular text element.  So, the left, right, top, bottom, etc. commands
> are difficult to apply correctly.  I.E. if you position the words: dog cat
> sea This puny.  And you try to align them by their tops, bottoms, or
> middles, you'll get a zigzag of words.  Some poke down, some poke up, some
> do both, and some do neither....

As the label command (and all its variants) are based on positioning text by
the coordinates of its bounding box, it is impossible to get precisely
controlled text layout (using that command) in MetaPost.

Instead, you have to use the (less powerful) draw command...  It is less
powerful because draw won't take care of left, right, center positioning for
you.  You'll have to calculate that yourself...

For an example of a list of attributes in a UML diagram.

So, instead of this:

label.urt(btex {\usefont{OT1}{cmr}{m}{n} dog} etex scaled 1.0,
(0.0x,0.00y));
label.urt(btex {\usefont{OT1}{cmr}{m}{n} cat} etex scaled 1.0,
(0.0x,0.35y));
label.urt(btex {\usefont{OT1}{cmr}{m}{n} sea} etex scaled 1.0,
(0.0x,0.70y));
label.urt(btex {\usefont{OT1}{cmr}{m}{n} This} etex scaled 1.0,
(0.0x,1.05y));
label.urt(btex {\usefont{OT1}{cmr}{m}{n} puny} etex scaled 1.0,
(0.0x,1.40y));

We need to do this...

draw btex {\usefont{OT1}{cmr}{m}{n} dog} etex scaled 1.0 shifted
(5.0x,0.00y);
draw btex {\usefont{OT1}{cmr}{m}{n} cat} etex scaled 1.0 shifted (5.0x,
0.35y);
draw btex {\usefont{OT1}{cmr}{m}{n} sea} etex scaled 1.0 shifted
(5.0x,0.70y);
draw btex {\usefont{OT1}{cmr}{m}{n} This} etex scaled 1.0 shifted
(5.0x,1.05y);
draw btex {\usefont{OT1}{cmr}{m}{n} puny} etex scaled 1.0 shifted
(5.0x,1.40y);

The 'x' coordinate difference is just to separate the two columns of text.
The 'y' values are separated by 0.35cm (the font size).  Using the draw
command with the shifted transformation, you position text by the left end
of the baseline.

Using the label.??? command, you position text such that its bounding box is
positioned ??? relative to the coordinate point.  In this case, label.urt
means the bounding box is up and to the right of the specified coordinates.

While left-right-center will take some special handling (although Dia must
do this someplace already), this should be an answer once and for all...
There were some hackish fixes suggested where you insert an invisible
character that reaches to the top of the tallest and the bottom of the
lowest character.
Comment 1 Hans Breuer 2006-07-15 16:10:54 UTC
pushing bugs forward to a still relevant version, 0.95-pre2 is not
Comment 2 Robert Young 2007-01-30 04:12:12 UTC
I've looked at this, and have written a couple of test files and some code.

I've used the macro suggestions Rob McDonald made on the mailing list:

% Define macro for horizontal centering.
vardef hcentered primary P =
  P shifted -(xpart center P, 0)
enddef;

% Define macro for right justification.
vardef rjust primary P =
  P shifted -(xpart (lrcorner P - llcorner P), 0)
enddef;

and plain draw for left justification.

Comment 3 Robert Young 2007-01-30 04:17:38 UTC
Created attachment 81488 [details]
Test cases for MetaPost

Two test cases:
Diagram1 -> .dia, .mp and .pdf. This is a UML class as per Comment #1. Created using patch and then mptopdf to create pdf.

TextTestCase -> .dia, .mp and .pdf. This has two different text sizes and shows problems with left, centred and right aligned text which are fixed by the patch.
Comment 4 Robert Young 2007-01-30 04:27:16 UTC
Created attachment 81489 [details] [review]
Patch referenced in comment #2 and #3

Note that text scaling has been changed (from 3.0 to 2.05). THis may be the WRONG thing to do, but it made the test cases look pretty similar when comparing the MetaPost and Dia files.
Comment 5 Robert Young 2007-01-30 23:32:48 UTC
Created attachment 81558 [details]
Metapost Test Cases

Added extra test cases - serif, monospace and cmr10.
Comment 6 Robert Young 2007-01-30 23:34:43 UTC
Created attachment 81559 [details] [review]
Improved font size matching

Changed font scaling for each font type (sans, serif, monospace, cmr).
Comment 7 Lars Clausen 2007-01-31 07:17:20 UTC
Created attachment 81569 [details] [review]
Patch with text_line

Experimental patch using text_line, something's wrong with the makebox, though, complains about missing $.
Comment 8 Hans Breuer 2008-05-18 14:13:46 UTC
The 'experimental' patch was applied before dia-0.96 was released, so I think this is obsolete (or broken with 0.96)?

Revision: 3609
Author: lclausen
Date: 17:52:32, Samstag, 3. Februar 2007
Message:
VDX v. 0.9
----
Modified : /trunk/ChangeLog
Modified : /trunk/plug-ins/metapost/render_metapost.c
Modified : /trunk/plug-ins/vdx/vdx-import.c
Modified : /trunk/plug-ins/vdx/vdx-xml.c
Modified : /trunk/plug-ins/vdx/vdx.h
Modified : /trunk/plug-ins/vdx/visio-types.h