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

[FEATURE] Provide Function to Install CMU Fonts on a User's Machine #45

Closed
TheCedarPrince opened this issue Dec 28, 2021 · 7 comments
Closed

Comments

@TheCedarPrince
Copy link

TheCedarPrince commented Dec 28, 2021

Hey @Kolaru ,

This is an amazing package!
Thanks to @davibarreira, we have it working with enabling LaTeX to work within Luxor.jl to make really professional looking diagrams:

image

Would it be possible to create a function that allows one to install the CMU fonts onto a user's machine?
I see you distribute the package with the fonts already and it would be nice if this package installed the fonts for you as well.

Thanks!

~ tcp

@Kolaru
Copy link
Owner

Kolaru commented Dec 31, 2021

Wow, that looks absolutely amazing!

Installing the font seems to be easy for linux, but some kind of black magic for windows. So it will require further investigation.

What is your use case for this? In MathTeXEngine I currently only include the subset of the CM family we are using.

@TheCedarPrince
Copy link
Author

Hey @Kolaru !

Yea, with Linux, using a tool like fontconfig would probably work well.
With Windows, not too sure.

In my case, I have two main use cases currently:

  1. Right now we want to merge this as potentially an optional dependency to Luxor.jl. By merging, we were hoping to have this functionality to make it easier for Luxor users to use MathTeXEngine.
  2. I am the co-creator of Javis.jl in the JuliaAnimators organization and would love to have this function for our users in the ecosystem to simply/easily install the tools to utilize MathTeXEngine with Javis.

As Javis is built on top of Luxor, solving the first use case would help solve the second.

Totally understand if you don't want to work on this but figured I would ask to see if it was possible.
Thanks @Kolaru !

@TheCedarPrince
Copy link
Author

P.S. An additional use case that I forgot about was the fact that the above image was created for use within the AlgebraicJulia ecosystem.
I had some tremendous issues at first as I didn't know the fonts were required and kept getting outputs like this:

image

Having a function or alert that could assist a user in installing these fonts would be great as I spent a couple hours tracking down this strange issue.

@Kolaru
Copy link
Owner

Kolaru commented Jan 3, 2022

I see. I build the package on the assumption that any dependency would load the fonts from the files included in the package using for example FreeTypeAbstraction.jl (it is what Makie.jl and MathTeXEngine.jl itself are doing). This way there is no need to rely on the font being installed. I guess that this difference in design is the source of your problems there.

Would it be feasible for Luxor to load the font directly without needing a system installation?

@TheCedarPrince
Copy link
Author

@Kolaru - unfortunately, I do not know.
In my experiments with my Linux machine, I was unable to get Luxor to automatically recognize a loaded font via FreeTypeAbstraction.jl.
I am unsure as to why it did not work and still unsure how Makie.jl does this for rendering.

The best person who would probably know is @cormullion .
I know we were chatting about the evils of font installations earlier but do you think there is anything that can be done Luxor side to better compatibility with MathTeXEngine?
Or not possible @cormullion?
Based on what I was reading is that Cairo uses its own quirky version of fontconfig to find system fonts, and I did not see an easy way to interface with these fonts through Cairo.
But you'd know better than I would here so I defer to you - thanks!

@cormullion
Copy link

TL;DR: Cairo.jl does all the font-finding and font-rendering work for Luxor.jl, and I don't know enough about how it works or whether adding new features would be possible. I wish I could be more helpful. :(

I think there are two tasks here: finding the desired font files on disk, and extracting the glyph outlines to draw the glyphs on some surface. I suspect Cairo.jl and Makie.jl use different code paths for both tasks.

I don't know what Makie.jl does. ¯\_(ツ)_/¯

Finding fonts

I think Cairo.jl uses fontconfig to load a list of active fonts from the operating system. For example, to render LaTeX text correctly, I first copied the fonts from MathTeXEngine/assets/fonts directory to my font manager's folder and activated them. Each platform uses different ways of installing and activating fonts. Last year we investigated some Julia-based ways of installing the JuliaMono fonts but made no progress.

Drawing glyphs

Presumably Cairo is using FreeType on Linux, Quartz on MacOS, and Win-something on Windows? (See https://cairographics.org/manual/cairo-fonts.html)

When drawing text to PNGs and GIFs, I think Cairo.jl passes the job of actually rasterizing the glyph outlines to the operating system's text rendering routines. This might explain why you get different output on different platforms see this section.

When drawing text to SVGs, Cairo.jl extracts the outlines and converts them to Bezier-based paths; this is also how you can draw text outlines in Luxor.

When drawing text to EPS and PDF, Cairo.jl just makes a copy of a subset of the original font data and embeds it in the file.

That's about all I know... :)

@Kolaru
Copy link
Owner

Kolaru commented Oct 15, 2022

This will be fixed on the Cairo side, all font information is included by MathTeXEngine through FreeTypeAbstraction.

@Kolaru Kolaru closed this as completed Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants