Re: Proper vertical centering of text

Dr. Olaf Hoffmann wrote:
> a) most viewers seem to have a problem to find a precise boundingBox

Yes. Which is something that would be nice to fix.  Since it causes a lot
of problems.

I think it is unfortunate that SVG2 currently specifically excludes text
from having to return a tight bounding box.  It seems to be just codifying
the behaviour of implementations (?).

I realise that calculating the tight bbox of text is adding complexity, but
can we not add a new "tight" item to SVGBoundingBoxOptions to specify the
behaviour on demand?  In order for this to be useful to non coders, perhaps
there should also be a new attribute for shapes:

bbox-rendering = "[fill] [stroke] [markers] [clipped] [tight]"

The value of which would affect not only my suggestion for an optional
vertical component on text-anchor, but also how objectBoundingBox is
calculated.


> b) one needs to define the center of a general graphical object,

Not in the case of text, as the "centre position" is defined by the <text> x
and y attributes.

I, myself, am not asking for generalised "centre one shape wrt another"
feature.  Text is a common, use case however that should get special
handling.  The fact that you can centre hrisontally reliable, but not
vertically seems to be a large functionality hole.


Unfortunately, alignment-baseline is not a universal solution to this
problem.  Even when it is completely implemented by the renderer, there are
the following issues:

(1) The baseline table is an optional table, so the font you may want to
use doesn't necessarily have it
(2) You have to know which baseline is the appropriate one to use for a
particular glyph.  For example, you need to use a different value for "a"
and "b".

See: http://jsfiddle.net/ap1dvntt/3/

Paul




On 5 March 2015 at 07:07, Dr. Olaf Hoffmann <Dr.O.Hoffmann@gmx.de> wrote:

> Hello,
>
> to generalise this use case, one whats somehow to center
> a text object in relation to another object.
>
> Problems I see:
> a) most viewers seem to have a problem to find a precise boundingBox not
> only
> for text, but in this case it would be essential to get especially the
> vertical dimensions of such a box somehow precisely.
> b) one needs to define the center of a general graphical object, if one
> needs
> to center text to it - how to do this? Again the boundingBox?
> Some viewers have problems as well to get the right boundingBox for
> arbitrary objects or a group of objects.
> c) one needs to refer the object with the center from the text to be
> centered.
> This can be done obviously with some XLink construction, however, how
> do other positioning, alignment, transformation issues for the text
> have influence on this?
>
> Another approach would be to leave the question of the center of
> something to the authors, but to enable them to center the text according
> to a text position, as available now for horizontal centering of the text
> relative to this point due to text-anchor.
> This should be somehow related to the baseline of the text to avoid
> problems with the boundingBox complexity for text objects.
> dominant-baseline and alignment-baseline provide such an access
> approximately with central or middle.
> Why is this not sufficient, is it a general problem or just the usual
> problem with implementation bugs or gaps in some viewers?
> However, just to introduce new features will not help to get current
> implementations to a good state.
> Obviously to get it more precisely done as with a shift of the baseline,
> one needs the boundingBox of the current text, not just the general
> information about the complete font, but obviously this is quite difficult
> for viewers, maybe more in the vertical direction than in horizontal
> direction, at least for latin like text structures.
> My assumption is, that if authors really need perfect control about this,
> they want to have perfect control about the dimension of the text object
> as well, they need to scale it in relation to the object, the text has to
> be
> centered to. Because SVG fonts are not supported in all viewers
> (again the problem with bugs and gaps in viewers), the only
> successfull approach currently is to convert the text into arbitrary path
> data, determine somehow, what the center might be for all objects, that
> need to centered to each other with an algorithms dependent on the
> aesthetic opinions of the specific author, and to position everything
> according to this.
>
> To center something is some kind of a philosophical problem,
> not only a technical question. And not just in CSS fun for authors
> already for many years, in SVG for non trivial objects as well ;o)
>
>
> Olaf
>
>

Received on Thursday, 5 March 2015 04:54:10 UTC