Skip to content

Align text using advance width, not glyph width #253

Closed
@ddale

Description

@ddale

Original report at SourceForge, opened Thu May 29 15:12:49 2008

As far as I can tell, the alignment of text strings is based on the bounding box of the composite glyphs--the painted region. In certain cases, this behavior is producing results that I think are undesirable. The attached script illustrates some examples.

In the Y axis labels, the digit one has a narrower glyph and larger right-side bearing than the other digits, so the labels "0.1" and "-0.1" are shifted such that the leading zero and decimal point don't align with the other labels. Because these are tabular rather than proportional figures (numerals), the numerals' advance widths are equal; if the alignment were based on the total advance width of the label, the decimal points and places would align, although there would be more space between the digit one glyph and the axis.

The text objects show a similar vertical misalignment with multi-line strings.

The X axis labels are set with old-style, lowercase, or non-lining figures. The varying extent of the numerals above and below the baseline isn't accounted for by the glyph-based alignment, so the baselines don't line up. Granted, I rarely see old-style figures used in graphs, but they illustrate the behavior well.

I've observed this behavior on 0.91.2 using the WXAgg backend and with PNG, SVG, EPS, and PDF files. It seems to come through the font.get_width_height and font.get_descent calls within RendererAgg.get_text_width_height_descent and, more deeply, from the routines in FT2Font. I haven't gotten the SVN maintenance branch or the trunk running on my machine, so I'm unsure whether the behavior appears with the newer code.

What would be required to align text horizontally using advance widths and vertically using font-wide metrics for ascent, descent, and so on? Thanks.

SourceForge Comments

On Tue Jun 3 17:18:19 2008, jdh2358 wrote:

Logged In: YES
user_id=395152
Originator: NO

Hi Stan -- this is indeed an important feature request, and the trunk is the same as the branch in this regard. I'm not sure what the timeline is to get it done, but it's something I've wanted to add for a while. If you want to take a crack at it.... :-)

JDH

On Thu May 29 15:15:34 2008, stanwest wrote:

Logged In: YES
user_id=2093133
Originator: YES

File Added: textaligntest.png

SourceForge History

  • On Tue Jun 3 17:18:19 2008, by jdh2358: priority: 5
  • On Thu May 29 15:15:34 2008, by stanwest: File Added: 279501: textaligntest.png
  • On Thu May 29 15:12:50 2008, by stanwest: File Added: 279500: textaligntest.py

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions