core icon indicating copy to clipboard operation
core copied to clipboard

Setting custom font for web not working

Open 0pcom opened this issue 5 months ago • 0 comments

Describe the bug

Perhaps I'm missing something when following the updated font documentation?

I have a core application where I've embedded a font, for desktop. I want to have the same font on web.

How to reproduce

  • using cogentcore.org/core v0.3.13-0.20250724000930-74c72927e235 in go.mod (latest commit as of the time this was written)

  • I've created a core.toml file with the following contents:

[Web]
  Styles = ["https://fontlibrary.org/en/face/mononoki"]
  • I've included that next to the .go file which defines the main package
  • I do go run cogentcore.org/core@main run web -vv -port 8576
  • The web version does not display in the desired font:
Image

The embedded font displays as desired on desktop:

Image
  • The font does not display on web even when I reference the font name / set the custom font as: s.Font.CustomFont = "mononokiregular" and use the existing style.css of my website
Image

OR

s.Font.CustomFont = "mononokiRegular" as it is defined at the link included in core.toml

Image

Example code

package main

import(
	"embed"
	"cogentcore.org/core/core"
	 "cogentcore.org/core/styles"
	 "cogentcore.org/core/text/fonts"
	 "cogentcore.org/core/text/rich"
	)

	//go:embed mononoki/*.ttf
	var mononoki embed.FS


func main() {
	fonts.AddEmbedded(mononoki)
	b := core.NewBody()
	tx := core.NewText(b).SetText(title)
	tx.Styler(func(s *styles.Style) {
				s.Font.Family = rich.Custom
				s.Font.CustomFont = "mononoki"
				s.Text.LineHeight = 1
	})
	b.RunMainWindow()
}
const	title = `&nbsp;┌─┐┌─┐┌─┐┌─┐┌┐┌┌┬┐&nbsp;&nbsp;┌─┐┌─┐┬─┐┌─┐&nbsp;&nbsp;┬┌─┐&nbsp;&nbsp;┌─┐┬&nbsp;┬┌─┐┌─┐┌─┐┌┬┐┌─┐<br>
│&nbsp;&nbsp;│&nbsp;││&nbsp;┬├┤&nbsp;│││&nbsp;│&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;│&nbsp;│├┬┘├┤&nbsp;&nbsp;&nbsp;│└─┐&nbsp;&nbsp;├─┤│││├┤&nbsp;└─┐│&nbsp;││││├┤<br>
└─┘└─┘└─┘└─┘┘└┘&nbsp;┴&nbsp;&nbsp;&nbsp;└─┘└─┘┴└─└─┘&nbsp;&nbsp;┴└─┘&nbsp;&nbsp;┴&nbsp;┴└┴┘└─┘└─┘└─┘┴&nbsp;┴└─┘<br>
Hello, world!
A Á Ă Ắ Ặ Ằ Ẳ Ẵ  Ấ Ậ Ầ Ẩ Ẫ Ä Ạ À Ả Ā Ą Å Ã Æ B C Ć Č Ç Ĉ D Ð Ď Đ E É Ě Ê Ế Ệ Ề Ể Ễ Ë Ė Ẹ È Ẻ Ē Ę Ẽ F G Ğ Ĝ H Ĥ I IJ Í Î Ï İ Ị Ì Ỉ Ī Į Ĩ J Ĵ K L Ĺ Ľ Ŀ Ł M N Ń Ň Ñ O Ó Ô Ố Ộ Ồ Ổ Ỗ Ö Ọ Ò Ỏ Ơ Ớ Ợ Ờ Ở Ỡ Ő Ō Ø Õ Œ P Þ Q R Ŕ Ř S Ś Š Ş Ŝ ẞ T Ŧ Ť Ţ U Ú Ŭ Û Ü Ụ Ù Ủ Ư Ứ Ự Ừ Ử Ữ Ű Ū Ų Ů Ũ V W Ẃ Ŵ Ẅ Ẁ X Y Ý Ŷ Ÿ Ỵ Ỳ Ỷ Ỹ Z Ź Ž Ż a á ă ắ ặ ằ ẳ ẵ â ấ ậ ầ ẩ ẫ ä ạ à ả ā ą å ã æ b c ć č ç ĉ d ð ď đ e é ě ê ế ệ ề ể ễ ë ė ẹ è ẻ ē ę ẽ f g ğ ĝ h ĥ i ı í î ï ị ì ỉ ij ī į ĩ j ȷ ĵ k l ĺ ƛ ľ ŀ ł m n ń ň ñ o ó ô ố ộ ồ ổ ỗ ö ọ ò ỏ ơ ớ ợ ờ ở ỡ ő ō ø õ œ p þ q r ŕ ř s ś š ş ŝ ß t ŧ ť ţ u ú ŭ û ü ụ ù ủ ư ứ ự ừ ử ữ ű ū ų ů ũ v w ẃ ŵ ẅ ẁ x y ý ŷ ÿ ỵ ỳ ỷ ỹ z ź ž ż ᵢ ˡ ⁿ ʳ ª º А Б В Г Ѓ Д Е Ё Ж З И Й К Ќ Л М Н О П Р С Т У Ф Х Ч Ц Ш Щ Ь Ы Ъ Ѕ Э І Ї Ј Ю Я Ӏ Ӣ Ӯ а б в г ѓ д е ё ж з и й к ќ л м н о п р с т у ф х ч ц ш щ ь ы ъ ѕ э і ј ю я һ ӣ ӯ Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω Ά Έ Ή Ί Ό Ύ Ώ Ϊ Ϋ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ ς σ τ υ φ χ ψ ω ί ϊ ΐ ύ ϋ ΰ ό ώ ά έ ή ℂ ℍ ℕ ℙ ℚ ℝ ℤ ᵇ ᶜ 0 1 2 3 4 5 6 7 8 9 ⅟ ½ ↉ ⅓ ⅔ ¼ ¾ ⅕ ⅖ ⅗ ⅘ ⅙ ⅚ ⅐ ⅛ ⅜ ⅝ ⅞ ⅑ ⅒ ₀ ₁ ₂ ₃ ₄ ₅ ₆ ₇ ₈ ₉ ⁰ ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹ · ; ⟨ ⟩ . , : ; … ! ¡ ? ¿ · • * ‼ # ․ / \ ‥ - – — _ ₍ ₎ ( ) { } [ ] ⌈ ⌊ ⌉ ⌋ ⁽ ⁾ ‚ „ “ ” ‘ ’ ‛ « » ‹ › " ' ƒ ʹ ͵ ★ @ & ¶ § © ® ™ ° ′ ″ | ¦ ℓ † ‡ ¢ ¤ $ € £ ¥ ≐ ≃ ∙ ∕ ∸ ∈ ∎ ₌ ⁼ ≡ ∃ ≳ ≲ ₋ ⁻ ⊎ ≄ ∌ ∉ ≢ ⊄ ⊅ + − × ÷ = ≠ > < ≥ ≤ ± ≈ ~ ¬ ^ ∅ ∞ ∧ ∨ ∩ ∪ ∫ ∆ ∏ ∑ √ ∂ µ ∥ % ‰ ₊ ⁺ ∷ ≟ ⊢ ∘ ⊔ ⊂ ⊆ ∋ ⊃ ⊇ ⊤ ⊣ ∄ ∴ ⊈ ⊉ ⊊ ⊋ ⊕ ∀ ⊥ ⦂ ⊗ ↑ ↗ → ↘ ↓ ↙ ← ↖ ↔ ↕ ↞ ↠ ⇒ ⇐ ⇔ ▁ ▂ ▃ ▄ ▅ ▆ ▇ █ ▀ ▔ ▏ ▎ ▍ ▌ ▋ ▊ ▉ ▐ ▕ ▖ ▗ ▘ ▙ ▚ ▛ ▜ ▝ ▞ ▟ ░ ▒ ▓ ╦ ╗ ╔ ═ ╩ ╝ ╚ ║ ╬ ╣ ╠ ╥ ╖ ╓ ┰ ┒ ┧ ┎ ┟ ╁ ┯ ┑ ┩ ┍ ┡ ╇ ╤ ╕ ╒ ╍ ╏ ╻ ┳ ┓ ┏ ━ ╸ ╾ ┉ ┋ ╺ ┅ ┇ ╹ ┻ ┛ ╿ ┗ ┃ ╋ ┫ ┣ ╅ ┭ ┵ ┽ ┲ ┺ ╊ ╃ ╮ ╭ ╯ ╰ ╌ ╎ ╳ ╲ ╱ ╷ ┬ ┐ ┌ ╴ ╼ ┈ ┊ ╶ ┄ ┆ ╵ ╽ ┴ ┘ └ │ ┼ ┤ ├ ╆ ┮ ┶ ┾ ┱ ┹ ╉ ╄ ─ ╨ ╜ ╙ ╀ ┸ ┦ ┚ ┞ ┖ ╈ ┷ ┪ ┙ ┢ ┕ ╧ ╛ ╘ ╫ ╢ ╟ ╂ ┨ ┠ ┿ ┥ ┝ ╪ ╡ ╞ ♥ ΄ ΅ ̣ ¨ ˙ ´ ˝ ˆ ˇ ˘ ˚ ˜ ¯ ¸ ˛                    
`

Relevant output

$ echo "main.go" | entr -r bash -c 'go run cogentcore.org/core@main run web -port 8576 -vv'
loaded config file:core.toml
go build -o /home/user/go/src/github.com/0pcom/test1/bin/web/app.wasm -ldflags -s -w -X 'cogentcore.org/core/core.AppIcon=<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256" viewBox="0 0 1 1"><path d="M.833.675a.35.35 0 1 1 0-.35" style="stroke:#005bc0;stroke-width:.27;fill:none"/><circle cx=".53" cy=".5" r=".23" style="fill:#fbbd0e;stroke:none"/></svg>' -X cogentcore.org/core/system.CoreVersion=v0.3.13-0.20250724000930-74c72927e235
go run -tags offscreen,generatehtml .
<main id="Cogent Core" style="display:flex;flex-direction:column;flex-grow:1;justify-content:start;align-items:start;gap:0.5em;font-weight:thin;text-align:start"><p id="text-0" style="font-weight:normal;line-height:1;text-align:start">&nbsp;┌─┐┌─┐┌─┐┌─┐┌┐┌┌┬┐&nbsp;&nbsp;┌─┐┌─┐┬─┐┌─┐&nbsp;&nbsp;┬┌─┐&nbsp;&nbsp;┌─┐┬&nbsp;┬┌─┐┌─┐┌─┐┌┬┐┌─┐<br>
│&nbsp;&nbsp;│&nbsp;││&nbsp;┬├┤&nbsp;│││&nbsp;│&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;│&nbsp;│├┬┘├┤&nbsp;&nbsp;&nbsp;│└─┐&nbsp;&nbsp;├─┤│││├┤&nbsp;└─┐│&nbsp;││││├┤<br>
└─┘└─┘└─┘└─┘┘└┘&nbsp;┴&nbsp;&nbsp;&nbsp;└─┘└─┘┴└─└─┘&nbsp;&nbsp;┴└─┘&nbsp;&nbsp;┴&nbsp;┴└┴┘└─┘└─┘└─┘┴&nbsp;┴└─┘<br>
Hello, world!
A Á Ă Ắ Ặ Ằ Ẳ Ẵ  Ấ Ậ Ầ Ẩ Ẫ Ä Ạ À Ả Ā Ą Å Ã Æ B C Ć Č Ç Ĉ D Ð Ď Đ E É Ě Ê Ế Ệ Ề Ể Ễ Ë Ė Ẹ È Ẻ Ē Ę Ẽ F G Ğ Ĝ H Ĥ I IJ Í Î Ï İ Ị Ì Ỉ Ī Į Ĩ J Ĵ K L Ĺ Ľ Ŀ Ł M N Ń Ň Ñ O Ó Ô Ố Ộ Ồ Ổ Ỗ Ö Ọ Ò Ỏ Ơ Ớ Ợ Ờ Ở Ỡ Ő Ō Ø Õ Œ P Þ Q R Ŕ Ř S Ś Š Ş Ŝ ẞ T Ŧ Ť Ţ U Ú Ŭ Û Ü Ụ Ù Ủ Ư Ứ Ự Ừ Ử Ữ Ű Ū Ų Ů Ũ V W Ẃ Ŵ Ẅ Ẁ X Y Ý Ŷ Ÿ Ỵ Ỳ Ỷ Ỹ Z Ź Ž Ż a á ă ắ ặ ằ ẳ ẵ â ấ ậ ầ ẩ ẫ ä ạ à ả ā ą å ã æ b c ć č ç ĉ d ð ď đ e é ě ê ế ệ ề ể ễ ë ė ẹ è ẻ ē ę ẽ f g ğ ĝ h ĥ i ı í î ï ị ì ỉ ij ī į ĩ j ȷ ĵ k l ĺ ƛ ľ ŀ ł m n ń ň ñ o ó ô ố ộ ồ ổ ỗ ö ọ ò ỏ ơ ớ ợ ờ ở ỡ ő ō ø õ œ p þ q r ŕ ř s ś š ş ŝ ß t ŧ ť ţ u ú ŭ û ü ụ ù ủ ư ứ ự ừ ử ữ ű ū ų ů ũ v w ẃ ŵ ẅ ẁ x y ý ŷ ÿ ỵ ỳ ỷ ỹ z ź ž ż ᵢ ˡ ⁿ ʳ ª º А Б В Г Ѓ Д Е Ё Ж З И Й К Ќ Л М Н О П Р С Т У Ф Х Ч Ц Ш Щ Ь Ы Ъ Ѕ Э І Ї Ј Ю Я Ӏ Ӣ Ӯ а б в г ѓ д е ё ж з и й к ќ л м н о п р с т у ф х ч ц ш щ ь ы ъ ѕ э і ј ю я һ ӣ ӯ Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω Ά Έ Ή Ί Ό Ύ Ώ Ϊ Ϋ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ ς σ τ υ φ χ ψ ω ί ϊ ΐ ύ ϋ ΰ ό ώ ά έ ή ℂ ℍ ℕ ℙ ℚ ℝ ℤ ᵇ ᶜ 0 1 2 3 4 5 6 7 8 9 ⅟ ½ ↉ ⅓ ⅔ ¼ ¾ ⅕ ⅖ ⅗ ⅘ ⅙ ⅚ ⅐ ⅛ ⅜ ⅝ ⅞ ⅑ ⅒ ₀ ₁ ₂ ₃ ₄ ₅ ₆ ₇ ₈ ₉ ⁰ ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹ · ; ⟨ ⟩ . , : ; … ! ¡ ? ¿ · • * ‼ # ․ / \ ‥ - – — _ ₍ ₎ ( ) { } [ ] ⌈ ⌊ ⌉ ⌋ ⁽ ⁾ ‚ „ “ ” ‘ ’ ‛ « » ‹ › " ' ƒ ʹ ͵ ★ @ & ¶ § © ® ™ ° ′ ″ | ¦ ℓ † ‡ ¢ ¤ $ € £ ¥ ≐ ≃ ∙ ∕ ∸ ∈ ∎ ₌ ⁼ ≡ ∃ ≳ ≲ ₋ ⁻ ⊎ ≄ ∌ ∉ ≢ ⊄ ⊅ + − × ÷ = ≠ > < ≥ ≤ ± ≈ ~ ¬ ^ ∅ ∞ ∧ ∨ ∩ ∪ ∫ ∆ ∏ ∑ √ ∂ µ ∥ % ‰ ₊ ⁺ ∷ ≟ ⊢ ∘ ⊔ ⊂ ⊆ ∋ ⊃ ⊇ ⊤ ⊣ ∄ ∴ ⊈ ⊉ ⊊ ⊋ ⊕ ∀ ⊥ ⦂ ⊗ ↑ ↗ → ↘ ↓ ↙ ← ↖ ↔ ↕ ↞ ↠ ⇒ ⇐ ⇔ ▁ ▂ ▃ ▄ ▅ ▆ ▇ █ ▀ ▔ ▏ ▎ ▍ ▌ ▋ ▊ ▉ ▐ ▕ ▖ ▗ ▘ ▙ ▚ ▛ ▜ ▝ ▞ ▟ ░ ▒ ▓ ╦ ╗ ╔ ═ ╩ ╝ ╚ ║ ╬ ╣ ╠ ╥ ╖ ╓ ┰ ┒ ┧ ┎ ┟ ╁ ┯ ┑ ┩ ┍ ┡ ╇ ╤ ╕ ╒ ╍ ╏ ╻ ┳ ┓ ┏ ━ ╸ ╾ ┉ ┋ ╺ ┅ ┇ ╹ ┻ ┛ ╿ ┗ ┃ ╋ ┫ ┣ ╅ ┭ ┵ ┽ ┲ ┺ ╊ ╃ ╮ ╭ ╯ ╰ ╌ ╎ ╳ ╲ ╱ ╷ ┬ ┐ ┌ ╴ ╼ ┈ ┊ ╶ ┄ ┆ ╵ ╽ ┴ ┘ └ │ ┼ ┤ ├ ╆ ┮ ┶ ┾ ┱ ┹ ╉ ╄ ─ ╨ ╜ ╙ ╀ ┸ ┦ ┚ ┞ ┖ ╈ ┷ ┪ ┙ ┢ ┕ ╧ ╛ ╘ ╫ ╢ ╟ ╂ ┨ ┠ ┿ ┥ ┝ ╪ ╡ ╞ ♥ ΄ ΅ ̣ ¨ ˙ ´ ˝ ˆ ˇ ˘ ˚ ˜ ¯ ¸ ˛                    
</p></main>
cp icon.svg /home/user/go/src/github.com/0pcom/test1/bin/web/icons/svg.svg
Serving at http://localhost:8576
2025/07/29 11:17:29 INFO http: superfluous response.WriteHeader call from cogentcore.org/core/cmd/web.Serve.func1 (serve.go:34)
2025/07/29 11:23:21 INFO http: superfluous response.WriteHeader call from cogentcore.org/core/cmd/web.Serve.func1 (serve.go:34)

Platform

Web

0pcom avatar Jul 29 '25 16:07 0pcom