Re: [ft-devel] How to determine if horizontal hinting is happening?
On Tue, Feb 20, 2018 at 5:10 PM, Behdad Esfahbodwrote: > On Tue, Feb 20, 2018 at 11:04 AM, Alexei Podtelezhnikov > wrote: >> >> >> >> >> > I think Skia does, by default, a 4x1 subpixel grid. >> >> >> >> ... which is almost the same as 3x1, which you would get for free from >> >> LCD rendering with 3 channels shifted by 1/3.. 4x1 is such a minor >> >> gain for a huge cache waste. Just a suggestion. >> > >> > May I ruin your suggestion by suggesting that LCD images are stored four >> > bytes a pixel? ;) >> >> Do you then average the middle bytes for the middle channel, or >> interpolate? >> That is weird, but alright. > > > I have no idea what you're talking about. > > Ignore my 4x1 thing. I said I think that's what Skia does. And I had that in > mind with grayscale, not with subpixel rendering. > > -- > behdad > http://behdad.org/ To try to answer my question from before (please correct my errors!): Any of these conditions result in no horizontal hinting: - FT_LOAD_NO_HINTING is set. - FT_LOAD_TARGET_LIGHT is set. - FT_LOAD_TARGET_NORMAL is set, the autohinter is not used, and interpreter-version == TT_INTERPRETER_VERSION_40, and hinting_engine = FT_HINTING_ADOBE. Otherwise, horizontal hinting may occur. Specifically: - FT_LOAD_TARGET_MONO will hint horizontally. - FT_LOAD_TARGET_LCD will hint horizontally (?) - FT_LOAD_TARGET_V will hint horizontally (?) Does this seem right? Thanks, Adam ___ Freetype-devel mailing list Freetype-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/freetype-devel
Re: [ft-devel] How to determine if horizontal hinting is happening?
On Tue, Feb 20, 2018 at 12:01 PM, Alexei Podtelezhnikovwrote: >> I'm not an expert on how the code works, but my understanding is that >> subpixel positioning is the norm. > > I highly doubt that Chromium implements subpixel positioning. This > isn't the norm. > > - LCD (subpixel) rendering is about utilizing color channels > separately to improve glyph appearance. > - Subpixel position is freedom of placement of outlines relative to > pixel grid *before* rendering, so it is different. > - Kerning is about spacing of letter pairs like "AV". Again I am not > sure your bug is about that. > - Hinting is about improving contrast, relevant mostly to non-LCD rendering > Apologies for the terminology confusion. I was going by the "subpixel positioning" definition here: https://www.freetype.org/freetype2/docs/glyphs/glyphs-5.html : """ Subpixel positioning 1. Convert the character string into a series of glyph indices. 2. Place the pen to the cursor position. This can be a non-integer point. 3. Get or load the glyph image. 4. Translate the glyph by ‘pen_pos - floor(pen_pos)’. 5. Render the glyph to the target device at ‘floor(pen_pos)’. 6. Increment the pen position by the glyph's advance width in fractional pixels. 7. Start over at step 3 for each of the remaining glyphs. 8. When all glyphs are done, set the text cursor to the new pen position. """ My understanding is that Chromium does implement this algorithm. At the top of the page there is a caveat: "This algorithm can be used for hinting modes that don't apply horizontal hinting". Which is what I am trying to figure out :) > You mention all of these in the bug report... This is intractable and > confusing. Can you identify specific problem and file bug report with > FreeType if you think it is our problem? ___ Freetype-devel mailing list Freetype-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/freetype-devel
Re: [ft-devel] How to determine if horizontal hinting is happening?
On Mon, Feb 19, 2018 at 5:06 PM, Alexei Podtelezhnikovwrote: >> Also, I don't think it's necessarily too late to get the information >> after FT_Load_Glyph is called. > > Adam, Ben, > > To be honest, I do not quite follow how Chromium does text rendering. > It was under impression that you guys do font atlasing (aka preloading > of font texture). We just provided presetting of bitmap dimensions to > facilitate that if you wish. This is a sort of GPU caching system. Now > you are asking about subpixel positioning, which is basically > uncacheable because you would have unique bitmap for each subpixel > position. I am totally confused now. Well, you can use LCD rendered > bitmaps as 3 individual bitmaps shifted by 1/3 pixel and have that > granularity but not truly continuous. I just wish I could understand > where Chromium is going in order to help more intelligently. > > Alexei Hi Alexei, Sorry for any confusion. Just to be clear, I'm not on the Chrome graphics team, nor do I speak authoritatively for them. I'm just trying to clean up some of this code in Chrome that I was seeing some issues with. My understanding of the situation is that the non-subpixel case is not the common case, but still important (standard DPI with the horiztonal hinting algorithms). I'm not an expert on how the code works, but my understanding is that subpixel positioning is the norm. I don't know what is cached where, but it looks like it is all within Skia? For reference, this is a pretty good document on some of the issues (though it doesn't really cover caching): https://docs.google.com/document/d/1wpzgGMqXgit6FBVaO76epnnFC_rQPdVKswrDQWyqO1M/edit Thanks, Adam ___ Freetype-devel mailing list Freetype-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/freetype-devel
Re: [ft-devel] How to determine if horizontal hinting is happening?
On Mon, Feb 19, 2018 at 3:05 PM, Werner LEMBERGwrote: > What I need is a reliable mechanism (across Freetype versions and > fonts) to determine if a font has horizontal hinting applied or > not. It looks like it's something Freetype might need to > provide, since the true answer seems to come from the interaction > of flags, fonts, and engines. > > Could this be something that I can read out of FT_FaceRec? No, it can't, since FT_Load_Glyph's load flags determine that, which comes later than the creation of `FT_Face'. >>> >>> Could you get this from comparing linearHoriAdvance with >>> advance.x<<10 ? > > I don't think so. > >> What if we store the resulting load_flags after all massaging inside >> FT_Load_Glyph into the reserved field of FT_GlyphSlot? Would this >> work? Sorry, I do not like adding new function interfaces. > > The very issue is to get information on how FreeType will render a > glyph *before* the actual rendering. This essentially means we have > to call a function *instead* of `FT_Load_Glyph'. > > Abusing `FT_Load_Glyph' for that purpose (for example, by introducing > a new FT_LOAD_GET_RENDERING_INFO flag that do what you suggest) looks > inelegant. Is there a way to use the property mechanism to implement this? I agree adding a new function interface is good to avoid if possible. https://www.freetype.org/freetype2/docs/reference/ft2-properties.html I feel like using properties might be the right way to do it, combined with a new bit of documentation that explains how and what to query. This is a natural extension to the current state of the documentation which incompletely documents the effects certain flags and compilation options have on horizontal hinting. (Example: https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_LOAD_TARGET_XXX). I don't know if this would be possible though, given that it's font-dependent which engine is used, especially if Also, I don't think it's necessarily too late to get the information after FT_Load_Glyph is called. FT_Render_Glyph is already a separate operation, correct? This is a similar operation to the pseudocode at the bottom of https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_Size_Metrics. (The note there is a bit confusing though: "Only the application knows in advance that it is going to use native hinting for TTFs" doesn't seem to make sense in all cases, since Freetype can override this if no FT_LOAD_FORCE_AUTOHINT or FT_LOAD_NO_AUTOHINT are used. This seems like a very similar issue, something that would be nice to be able to query, or have clearly documented.) Thanks, Adam ___ Freetype-devel mailing list Freetype-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/freetype-devel
Re: [ft-devel] How to determine if horizontal hinting is happening?
On Fri, Feb 16, 2018 at 12:39 PM, Adam Goode <ago...@chromium.org> wrote: > On Fri, Feb 16, 2018 at 12:19 PM, Alexei Podtelezhnikov < > apodt...@gmail.com> wrote: > >> >> > (letting me safely do subpixel positioning) >> >> The lsb and rsb delta procedure works with and without hinting. It is the >> only workable procedure with hinting IMO. Why did you choose to stay away >> from it? > > > > I am not sure! I will look into this. (I don't have any familiarity with > this font handling part of the Chromium codebase.) > > > I looked into this. The rendering library is skia, which seems to be doing reasonable things when it comes to Freetype (I see references to delta and rsb/lsb). The issue is that sometimes we want to start text at a non-integer position, but still align each glyph appropriately to allow for hinting to look correct. This means that depending on hinting parameters, we might want to round the final position of each glyph before displaying on screen. If the glyph is horizontally hinted, we do want to round to integer screen positions. But if the glyph is not horizontally hinted, we know that it is better to position the glyph at a subpixel position. Skia already makes some optimizations based on this hinting knowledge. It knows that light hinting does not hint in the horizontal direction and avoids running hinting before computing metrics. But it doesn't know if other engines might not hint horizontally, and has to run the hinter before metric computation. That would be another place to use this information. Thanks, Adam ___ Freetype-devel mailing list Freetype-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/freetype-devel
Re: [ft-devel] How to determine if horizontal hinting is happening?
On Fri, Feb 16, 2018 at 12:19 PM, Alexei Podtelezhnikovwrote: > > > (letting me safely do subpixel positioning) > > The lsb and rsb delta procedure works with and without hinting. It is the > only workable procedure with hinting IMO. Why did you choose to stay away > from it? I am not sure! I will look into this. (I don't have any familiarity with this font handling part of the Chromium codebase.) Thanks, Adam ___ Freetype-devel mailing list Freetype-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/freetype-devel
Re: [ft-devel] How to determine if horizontal hinting is happening?
On Fri, Feb 16, 2018 at 1:31 AM, Werner LEMBERGwrote: > > > > I am working on a Chrome bug (crbug.com/740385) related to subpixel > > positioning and hinting. > > > > There is currently an issue where glyphs do not get positioned > > correctly in all cases, and to solve this problem I need to enable > > subpixel positioning. > > > > This works, except when horizontal hinting is enabled ("full > > hinting" in xft enables this). In this case, letters get smeared > > badly. > > > > https://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html > > suggests that I should do subpixel positioning if I am not hinting > > horizontally, which matches with my understanding. > > > > Therefore, I would like to programatically determine if horizontal > > hinting is happening and base the subpixel positioning decision on > > this information. But I have not been able to figure out how to do > > this. Is there a way that avoids needing to know the internals of > > the engines? > > Well, the decision whether you are using `full hinting' or not is > given by the load flags used in `FT_Load_Glyph'. This is *external* > information given by Chrome itself! FreeType overrides this only for > the very small class of `tricky' fonts which don't display correctly > otherwise; this can be tested with `FT_IS_TRICKY'. > > Am I missing something? > > > Werner Hi Werner, Yes, Chrome itself provides these flags. I'm looking now at https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_LOAD_TARGET_XXX What I think I need is a bit more documentation about these flags, allowing me to reason about which ones will not do horizontal hinting (letting me safely do subpixel positioning) and which ones will do horizontal hinting. Right now, I have to experimentally determine this by changing flags manually and observing what happens. But it looks like I can't quite be sure of this either, because "a font's native hinters may ignore the hinting algorithm you have specified". I don't think I always want to force the autohinter. Really I just want the best hinter to be chosen given the user's preferences and Freetype's internal logic. What I need is a reliable mechanism (across Freetype versions and fonts) to determine if a font has horizontal hinting applied or not. It looks like it's something Freetype might need to provide, since the true answer seems to come from the interaction of flags, fonts, and engines. Could this be something that I can read out of FT_FaceRec ? Or am I overthinking this? Thanks for your help, Adam ___ Freetype-devel mailing list Freetype-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/freetype-devel
[ft-devel] How to determine if horizontal hinting is happening?
Hi, I am working on a Chrome bug (crbug.com/740385) related to subpixel positioning and hinting. There is currently an issue where glyphs do not get positioned correctly in all cases, and to solve this problem I need to enable subpixel positioning. This works, except when horizontal hinting is enabled ("full hinting" in xft enables this). In this case, letters get smeared badly. https://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html suggests that I should do subpixel positioning if I am not hinting horizontally, which matches with my understanding. Therefore, I would like to programatically determine if horizontal hinting is happening and base the subpixel positioning decision on this information. But I have not been able to figure out how to do this. Is there a way that avoids needing to know the internals of the engines? Thanks, Adam ___ Freetype-devel mailing list Freetype-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/freetype-devel