New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION] Achieve same text rendering like Chrome #1253
Comments
SkiaSharp also supports using HarfBuzz to properly shape the text. The current version uses DirectWrite on Windows, as far as I know, Chrome uses Freetype. Some shared code might help to investigate this further. |
It might also be that Chrome is making use of some of the text hinting and subpixel things... |
Let's compare SkiaSharp v2 with current Chrome. That should yield similar results. |
You can check out the preview bits in the preview feed: https://aka.ms/skiasharp-eap/index.json I am busy sorting out the branches and getting CI to a more official preview place. But that is a fairly recent build already. |
I prepared a small example: After I opened this issue yesterday I found that SubpixelText already made quite a difference on some texts. But with the given example I can still see a significant difference.
No problem, such a feed works out fine for me in this case 馃槈 |
What happens if you clear the canvas with a non transparent color and enable LcdRenderText on the paint? This should enable ClearType. |
I digged now very deep into Skia and Chromium and finally managed to setup the rendering correctly using SkiaSharp 2. I compiled Chromium on my machine and extended Skia with additional logs that tell me what's happening insight. It seems that the default SkiaSharp.HarfBuzz logic does not shape and align the glyphs like Chrome. When I had a look at the I updated my gist with the variant I adopted from the Chromium source and achieved exactly the same glyph positions for my test: As a next step I will try using the EAP in my Library to really see if really all text renderings are now done correctly. There is still a slight difference on the grayscale of the glyphs where I'm not sure where it comes from. I was wondering if there is an estimated release date for SkiaSharp 2 already? Achieving the correct rendering heavily relies on SkiaSharp 2 uses the >=m80 branch of Skia. They reworked the text rendering and API somewhere between m73 and m75. |
@Danielku15 are things working better for you now? It sort of looks like this set of properties does the main work? using var skFont = new SKFont
{
Edging = SKFontEdging.Antialias,
Subpixel = true,
Hinting = SKFontHinting.Normal,
Typeface = typeface,
Size = size
}; With the color difference, are they actually using black or an off-black/dark grey? |
I haven't checked since a while the new NuGet packages. I just saw that 2.80.2 is now officially available since a while. I will try to check again my tests soon to check the differences again in detail. I hope I can have an early look this weekend. |
Thanks for the feedback. Can we close this? |
Not really, my question is still open and unanswered: how can I get the exact same output like Chrome using SkiaSharp. While I was able to figure out the text shapingg part on my own, the aspect of colors/opacity is still unclear. |
Using HarfBuzz is the correct way. Chrome is using a text shaping engine to do what you did. And the colors, are you sure they are not drawing the text with an opacity? Or maybe layers with some sort of blending? |
The moment ClearType comes into play you will not get the same results. Are you running this on Windows or on Linux, OSX as well? Are you using a Canvas to draw the text? |
@mattleibow https://github.com/google/skia/blob/52a4379f03f7cd4e1c67eb69a756abc5838a658f/src/ports/SkTypeface_win_dw.cpp#L395 is this enabled for the Windows builds? |
I am not 100% sure by code. But the fact that some pixels manage to reach the 100% opacity indicates that they are drawing it just normally and the rest happens during drawing.
For now I am testing only on Windows 10. For the analysis I also ensure not to compare images generated across different systems.
I am still using the same code snippets like before: |
@Gillibald I'll create a PR with that so we can test, but I did a search in the entire chromium source and that is the only reference to that define. I am going to ask on skia-discuss to try and understand it a bit better: https://groups.google.com/g/skia-discuss/c/gRU6aa0xhvU |
With the latest SkiaSharp I was able to get a rendering that close, that my visual tests succeed. From my perspective we can close this issue. Just some additional bits for you:
Quite a nightmare that they have so many hacks to align the text 馃槰 Makes it hard to get a consistent rendering using Skia directly. Some reference links on the last point: Now I only single failing test left is some edgy rendering of quadratic curves on small scales. But I guess this is another special Chrome thing I will have to find out. The numbers passed into the HTML5 rendering context are the same as I pass into Skia. I might open a different issue for that one if I find something significant in SkiaSharp 馃槈 |
To sum it up Chrome isn't using the font author's default scaling and instead just uses a different scaling which results in a slightly different rendering. |
@Gillibald To be precise: SkiaSharp uses I plan to open a PR with an extension to allow configuring this scale factor and also fixing missing handling of the text alignment. (I want to get rid of this custom code on my side 馃榿 ) |
The question might sound stupid at the beginning but please give it a chance 馃槈 It might not be dedicated 100% to this library but I'm giving it a shot to maybe catch an expert.
I am maintaining a library available in JavaScript and in .net which is rendering music notation to a canvas. For this library I created a visual regression test suite based on images rendered in Chrome. On my .net version I use SkiaSharp and my tests fail with slight differences on the text rendering.
As Chrome is using Skia underneath and I'm testing on the same machine/platform I guess it should be possible to achieve the same render output. Here an example test that fails:
The difference is subtle for humans but significant on technical comparison. On the first example you can see it very good on the character t of "Standard" how the character alignment is different. Also the whole anti aliasing is slightly different heavily on the second example.
Are there some special settings on the font rendering and anti aliasing that chrome uses? Do they use a different text shaper than SkiaSharp? Skia mentions that the text layouting is done by another library and Chrome is using HarfBuzz. For text hinting I guess GDI is used.
I am wondering if SkiaSharp is using the same settings as Chrome for compiling Skia native. Are there settings to control the text rendering allowing me to achieve the same output in SkiaSharp as in Chrome?
The text was updated successfully, but these errors were encountered: