> Question from me as X11 user:
> A problem that at least looks similar occur with the X11 glyph
> substitution patches from Ian (end of lines truncated):
> <
http://www.fltk.org/str.php?L1903>
> But in this case the whole bounding box is too small if multiple fonts
> are used.
Hi Michael,
Well, that's an interesting question; as I understand it, the problems are exhibiting similar "features", but the underlying causes are somewhat different, but perhaps related.
I'll try to describe what I *think* the problems are; others can then add corrections...
OSX:
In the OSX case the text editor truncates the string when it is rendered, but the unittest bounding box looks correct (indeed probably *is* correct.)
This happens because fltk computes the text editor clip region by summing the individual glyph widths, but this summation is wrong in this case because fltk does not account for the variant selector, and so computes the "default" width for the varied glyph, rather than the actual width of the glyph as it is rendered.
The unittest bounding box is computed by measuring the "inked" region of the whole string, as that string is created by the OSX font system, and this *does* account for the variant glyph selector substitution etc., since OSX font system supports the variant selector.
So we see the string clipped in the text editor, but the unittest renders the correct bounding boxes.
We could potentially move to drop the "per glyph width summation" for text rendering in fltk, and always use the sizes of whole strings, as reported by the OSX font system, but that might be quite a big change internally, and may well be slower (or, it might be faster on modern font systems? I do not have any metrics for this...)
X11:
The X11 case Michael refers to, using my hack X11/XFT glyph substitution scheme, shows a *similar* fault, but that affects both the text editor and the unittest.
To try and explain why...
What my hack is doing is trying to substitute any glyphs that are missing from fltk's current font, by looking for the missing glyph in a (user specified) set of alternate fonts. (To use it, the user selects the fltk current font in the usual way, but also loads a set of optional fallback fonts to search for missing glyphs.)
In practice, this works fairly well; most strings are rendered in the current font, but any individual words in the string that that have problem glyphs, are rendered in whichever of the "fallback" fonts contains the majority (ideally all) of the problem glyphs.
But the hack is incomplete - the glyph substitution I describe happens "correctly" when the string is rendered, but with the present hack, the computation of widths (either on a per-glyph basis as done by the text editor, or on a per-string basis as done by the unittest) are always done using just the fltk current font (as the stock fltk font engine does.)
This happens simply because (so far) I have never made the necessary changes to use the hack substitution model in all cases, but only in the actual rendering pass. As a result the string *as rendered* tends to be a different size from the string *as measured*, if any glyphs need to be substituted (but are mostly fine if no glyphs are substituted, or at least no worse than stock fltk!)
Again, reworking fltk to always try and measure what would actually be rendered is likely to be (at least a part of) the solution. But how we get there might be somewhat different on the two platforms.
And I have no thoughts on what the WinXX port will do... I suspect it will behave like OSX, if it even honours the variant glyph selector substitution at all... Hmm, OK, looks like this Win7 box does not even honour the variant selector and I just get a nasty replacement glyph...
> @Ian:
> In September you have written that you know a way how to fix this.
> Would the fix in your mind also catch this issue or would variation
> selectors be a problem in general on X11 too?
The specific issue with my X11 hack, as noted above, is that the code currently measures "the wrong string"; the "fix" for my hack, that I alluded to back in September, was to always pass strings through my substitution process, both when rendering and measuring them (though this might often entail effectively running substitution on each string twice in some cases.) Note that Oksid's old Xlib substitution scheme did basically that, though in a way that is awkward for me to use with my XFT hack...
I have not done this because it will surely have a performance impact, will involve refactoring a fair bit of code, and I just never got around to it.
Also, I do wonder if the more invasive "fix" of reworking fltk to drop the per-glyph width summation and just measuring the whole (substituted) string might actually end up being faster in the future, as we need to render more complex texts...
As regards variant glyph selector substitution, I am not sure to what extent X11/XFT really understands that, or if we need to do something in fltk to make it work.
I suspect it does not really work at all at present (as you report below...)
>
> I ask because currently (in the unpatched X11 code) the variation
> selector is handled wrong - not detected at all and print as a separate
> replacement character - this looks ugly:
> <
http://micha.freeshell.org/tmp/2015-07-
> 06_flnews_variation_selector.png>
> If you think that this will never work as intended on X11 (even with a
> future version of your glyph substitution patch), I would try to create
> a patch that detect and skip the variation selectors completetly (do
> nothing, print nothing) for X11.
I suspect that in the short term we should probably patch the stock fltk to elide the variation selectors from any string we process.
I think this is more or less what Manolo is proposing as the workaround for OSX anyway?
Longer term it would be nice to do something cleverer. I do nto really know what though. It may be that switching to measuring (and rendering) "whole strings" rather than "per glyph", may prove to be the better option, but that may be a big change in the way fltk handles text rendering in general.
Or I could be talking rubbish again...
--
Ian
Selex ES Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************