Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GDI Font Matching Fallback #502

Closed
wants to merge 1 commit into from
Closed

Conversation

Ristellise
Copy link

@Ristellise Ristellise commented May 3, 2021

This PR attempts to solve Font Manager related issues by introducing a font matching fallback through CreateFontIndirect.
Note that this is a draft PR for the following reasons:

  • Figure out why does CreateFontFaceFromHdc throws an Access Violation even though SelectObject appears to be valid.
  • Remove all the ass_msg debug logging.
  • Check if it really fixes font manager issues.

Currently font managers such as fontbase write directly their values to registry in a way which directwrite is not able to find through their own methods, so when any user tries to load a font throught fontbase for example, the font appears
To bypass the issue, Aegisub has a GDI font selection patch that overrides libass directwrite font selection behavior.--

This PR's inspiration came mainly from this Chromium patch.

@astiob
Copy link
Member

astiob commented May 3, 2021

Quick question: do you know if there’s a way to reimplement get_fallback in GDI? If so, we could replace the entire DirectWrite provider with GDI and gain a native provider for Windows XP for any poor (or proud) souls who might still be using it.

@Ristellise
Copy link
Author

Ristellise commented May 3, 2021

Quick question: do you know if there’s a way to reimplement get_fallback in GDI? If so, we could replace the entire DirectWrite provider with GDI and gain a native provider for Windows XP for any poor (or proud) souls who might still be using it.

Should be possible, the overall process that Aegisub uses a EnumFontFamiliesEx to enumerate through all the font families (with a filter provided with a LOGFONT as filter input) and then adding it manually.
This method takes a different approach by calling CreateFontIndirectW directing without enumerating.
I'm unsure if EnumFontFamiliesEx is needed but I think it is.

@astiob
Copy link
Member

astiob commented May 3, 2021

Uhh, that sounds like preloading the whole font list?

I see Aegisub use EnumFontFamiliesEx to find fonts by name, but I don’t see how it helps with finding another font when the main font lacks a character (which is what get_fallback does), which I believe Aegisub doesn’t do.

Actually, didn’t we break the DirectWrite provider with the recent changes for fonts of multiple styles? Now match_fonts finds only a single font for each name, instead of the whole family. Presumably EnumFontFamiliesEx is needed to fix that.

@realfinder
Copy link

so this will make libass work in different way (better or more close to vsfilter) in windows?

@Ristellise
Copy link
Author

so this will make libass work in different way (better or more close to vsfilter) in windows?

In theory it should. I probably need to rethink this when I have the time for it.

@astiob
Copy link
Member

astiob commented May 24, 2021

@Ristellise What’s the current state of this PR? The code seems benign (and has been independently recreated [?] in #503 (comment)), but you said there was an Access Violation error somewhere. Can we help debug that? Is there a particular way to reproduce it?

Also, are you saying these fonts do actually work in Aegisub’s libass? That is, is it safe to assume they work with EnumFontFamiliesEx?

@Ristellise
Copy link
Author

Ristellise commented May 24, 2021

@Ristellise What’s the current state of this PR? The code seems benign (and has been independently recreated [?] in #503 (comment)), but you said there was an Access Violation error somewhere. Can we help debug that? Is there a particular way to reproduce it?

Also, are you saying these fonts do actually work in Aegisub’s libass? That is, is it safe to assume they work with EnumFontFamiliesEx?

What’s the current state of this PR?

Feel free to fork. Currently I'm trying to finish up my fansubbing stuff (Its taking a while), so I dont have motivation to work on it.
Feel free to close and move it to #503 (comment)) if necessary.

but you said there was an Access Violation error somewhere...

Specifically the line which CreateFontFaceFromHdc is called, throws an Access Violation.

Is there a particular way to reproduce it?

Currently building my own libass over at AegisubDC, It might be a bit annoying to setup as it uses Visual Studio to build the entire project.

Another way to reproduce it is to try to load it through a font manager like fontbase and check it out from there, though this method seems a bit unreliable as it sometimes works while sometimes is doesnt. It's really dependent if the user experiences it or not.

Also, are you saying these fonts do actually work in Aegisub’s libass?

According to reports I'm getting, yes.

EDIT: I'm personally not comfortable pushing such a change to a library such as libass as I know I'll break something. So if anyone wants to fork from my work, please feel free to do so. As long as I get appropriate credit, its good enough for me :)

@Apache553
Copy link
Contributor

Specifically the line which CreateFontFaceFromHdc is called, throws an Access Violation.

You can refer to this, in the dwrite_c.h. You lack some dummy vtable entries.

@astiob
Copy link
Member

astiob commented May 24, 2021

Ah, nice, thanks! That would explain it.

@Ristellise
Copy link
Author

Closing in favor of #503 with a more reasonable approach, refer to latest comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants