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

graphviz v12.1.0 breaks theme's custom graphviz ext #383

Closed
2bndy5 opened this issue Aug 29, 2024 · 5 comments · Fixed by #390
Closed

graphviz v12.1.0 breaks theme's custom graphviz ext #383

2bndy5 opened this issue Aug 29, 2024 · 5 comments · Fixed by #390
Labels
bug Something isn't working

Comments

@2bndy5
Copy link
Collaborator

2bndy5 commented Aug 29, 2024

The Ci is failing due to an error that I can reproduce on Windows using graphviz v12.1.0:

Fontconfig error: Cannot load default config file: No such file: (null)

Apparently the graphviz build for windows changed/updated the dependencies. The graphviz_ignore_incorrect_font_metrics flag is no longer relevant with graphviz v12.1.0. Commenting it out in our conf.py file yielded no warning about not finding LibGD support. I was able to confirm this by inspecting

the config file shipped with graphviz v12.1.0
# This file was generated by "dot -c" at time of install.

# You may temporarily disable a plugin by removing or commenting out
# a line in this file, or you can modify its "quality" value to affect
# default plugin selection.

# Manual edits to this file **will be lost** on upgrade.

gvplugin_core.dll core {
	device {
		dot:dot 1
		gv:dot 1
		canon:dot 1
		plain:dot 1
		plain-ext:dot 1
		xdot:xdot 1
		xdot1.2:xdot 1
		xdot1.4:xdot 1
	}
	device {
		fig:fig 1
	}
	device {
		ismap:map 1
		cmap:map 1
		imap:map 1
		cmapx:map 1
		imap_np:map 1
		cmapx_np:map 1
	}
	device {
		ps:ps 1
		ps2:ps 1
		eps:ps 1
	}
	device {
		svg:svg 1
		svgz:svg 1
		svg_inline:svg 1
	}
	device {
		json:json 1
		json0:json 1
		dot_json:json 1
		xdot_json:json 1
	}
	device {
		tk:tk 1
	}
	device {
		pic:pic -1
	}
	device {
		pov:pov 1
	}
	render {
		dot 1
		xdot 1
	}
	render {
		fig 1
	}
	render {
		map 1
	}
	render {
		ps 1
	}
	render {
		svg 1
		svg_inline 1
	}
	render {
		json 1
		json0 1
		dot_json 1
		xdot_json 1
	}
	render {
		tk 1
	}
	render {
		pic -1
	}
	render {
		pov 1
	}
	loadimage {
		png:svg 1
		gif:svg 1
		jpeg:svg 1
		jpe:svg 1
		jpg:svg 1
		png:fig 1
		gif:fig 1
		jpeg:fig 1
		jpe:fig 1
		jpg:fig 1
		png:vrml 1
		gif:vrml 1
		jpeg:vrml 1
		jpe:vrml 1
		jpg:vrml 1
		eps:ps 1
		ps:ps 1
		(lib):ps 1
		png:map 1
		gif:map 1
		jpeg:map 1
		jpe:map 1
		jpg:map 1
		ps:map 1
		eps:map 1
		svg:map 1
		png:dot 1
		gif:dot 1
		jpeg:dot 1
		jpe:dot 1
		jpg:dot 1
		ps:dot 1
		eps:dot 1
		svg:dot 1
		png:xdot 1
		gif:xdot 1
		jpeg:xdot 1
		jpe:xdot 1
		jpg:xdot 1
		ps:xdot 1
		eps:xdot 1
		svg:xdot 1
		svg:svg 1
		gif:tk 1
	}
}
gvplugin_dot_layout.dll dot_layout {
	layout {
		dot 0
	}
}
gvplugin_gd.dll gd {
	render {
		gd 1
	}
	render {
		vrml 1
	}
	textlayout {
		textlayout 2
	}
	loadimage {
		gd:gd 1
		gd2:gd 1
		gif:gd 1
		jpeg:gd 1
		jpe:gd 1
		jpg:gd 1
		png:gd 1
		gd:ps 1
#FAILS		gd:lasi 1
		gd2:ps 1
#FAILS		gd2:lasi 1
		gif:ps 1
#FAILS		gif:lasi 1
		jpeg:ps 1
		jpg:ps 1
		jpe:ps 1
#FAILS		jpeg:lasi 1
#FAILS		jpg:lasi 1
#FAILS		jpe:lasi 1
		png:ps 1
#FAILS		png:lasi 1
		gd:cairo 1
		gd2:cairo 1
		gif:cairo 1
		jpeg:cairo 1
		jpg:cairo 1
		jpe:cairo 1
		png:cairo -1
	}
	device {
		gif:cairo 10
		wbmp:cairo 5
		jpe:cairo 5
		jpeg:cairo 5
		jpg:cairo 5
		png:cairo 5
		gd:cairo 5
		gd2:cairo 5
	}
	device {
		gif:gd 1
		wbmp:gd 1
		jpe:gd 1
		jpeg:gd 1
		jpg:gd 1
		png:gd 1
		gd:gd 1
		gd2:gd 1
	}
	device {
		vrml:vrml 1
	}
}
gvplugin_gdiplus.dll gdiplus {
	render {
		gdiplus 1
	}
	textlayout {
		textlayout 8
	}
	loadimage {
		bmp:gdiplus 8
		gif:gdiplus 8
		jpe:gdiplus 8
		jpeg:gdiplus 8
		jpg:gdiplus 8
		png:gdiplus 8
	}
	device {
		metafile:gdiplus 8
		bmp:gdiplus 8
		emf:gdiplus 8
		emfplus:gdiplus 8
		gif:gdiplus 8
		jpe:gdiplus 8
		jpeg:gdiplus 8
		jpg:gdiplus 8
		png:gdiplus 8
		tif:gdiplus 8
		tiff:gdiplus 8
	}
	device {
		bmp:cairo 8
		gif:cairo 8
		jpe:cairo 8
		jpeg:cairo 8
		jpg:cairo 8
		png:cairo 8
		tif:cairo 8
		tiff:cairo 8
	}
}
gvplugin_kitty.dll kitty {
	device {
		kitty:cairo 0
		kittyz:cairo 1
	}
}
gvplugin_neato_layout.dll neato_layout {
	layout {
		neato 0
		fdp 0
		sfdp 0
		twopi 0
		circo 0
		patchwork 0
		osage 0
		nop 0
		nop1 0
		nop2 0
	}
}
gvplugin_pango.dll cairo {
	render {
		cairo 10
	}
	textlayout {
		textlayout 10
	}
	loadimage {
		png:cairo 1
#FAILS		png:lasi 2
		png:ps 2
	}
	device {
		png:cairo 10
		ps:cairo -10
		eps:cairo -10
		pdf:cairo 10
		svg:cairo -10
	}
}
gvplugin_vt.dll vt {
	device {
		vt:cairo 0
		vt-24bit:cairo 0
		vt-4up:cairo 0
		vt-6up:cairo 0
		vt-8up:cairo 0
	}
}
gvplugin_webp.dll webp {
	device {
		webp:cairo 1
	}
	loadimage {
		webp:cairo 1
	}
}

Although, I think the default fonts.conf file that it is looking for is intentionally excluded from the release assets.

I don't have a proposal yet, but I'm opening this to track it. I think we can generate a conf file for the theme's font being used, but that doesn't compensate for when a system font is used instead of a google font.

@2bndy5 2bndy5 added the bug Something isn't working label Aug 29, 2024
@2bndy5
Copy link
Collaborator Author

2bndy5 commented Oct 3, 2024

@jbms Was this helpful? Can I provide more details about something (env or FS)?

@jbms
Copy link
Owner

jbms commented Oct 3, 2024

I think the issue may be that the newer graphviz Windows build compiles in support for LibGD (which is good) and Fontconfig for LibGD, but then no default configuration file for fontconfig can be found which makes it fail. I think fontconfig is not actually used by LibGD when we specify a path to a TTF file but graphviz still attempts to initialize it which fails. I am trying to see if specifying a minimal fontconfig config fixes the problem.

@jbms
Copy link
Owner

jbms commented Oct 3, 2024

Actually I think the issue is that graphviz checks if the font path contains a forward slash to determine if it is a path to a font file. On Windows that fails because the paths we supply use backslashes.

I haven't checked yet but normalizing to forward slashes in the font path may fix it and a fontconfig config may not even be required.

@2bndy5
Copy link
Collaborator Author

2bndy5 commented Oct 3, 2024

yep. posix path seperators fixed it:

diff --git a/sphinx_immaterial/graphviz.py b/sphinx_immaterial/graphviz.py
index 895a0f9c..0d7d96b6 100644
--- a/sphinx_immaterial/graphviz.py
+++ b/sphinx_immaterial/graphviz.py
@@ -244,7 +244,7 @@ def render_dot_html(
     if ttf_font_paths and font is not None:
         try:
             # can only support the chosen font if cache exists and a Google font is used
-            ttf_font = ttf_font_paths[(font, "400")]
+            ttf_font = ttf_font_paths[(font, "400")].replace("\\", "/")
         except KeyError as exc:
             # weight `400` might not exist for the specified font
             all_font_keys = [i for i in ttf_font_paths.keys() if i[0] == font]
@@ -253,7 +253,7 @@ def render_dot_html(
                     f"Font file for {font} could not be found in cache"
                 ) from exc
             # just use first weight for the specified font
-            ttf_font = ttf_font_paths[all_font_keys[0]]
+            ttf_font = ttf_font_paths[all_font_keys[0]].replace("\\", "/")

     code = _replace_resolved_xrefs(node, code)

and additionally using the patch in #390.

@2bndy5
Copy link
Collaborator Author

2bndy5 commented Oct 3, 2024

Bonus 🎉

The font metrics seem correct on Windows now:
image

@2bndy5 2bndy5 linked a pull request Oct 3, 2024 that will close this issue
@jbms jbms closed this as completed in #390 Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants