Skip to content

Non-Latin text renders as tofu #232

Description

@namejiahui

Summary

I noticed that some characters, such as Chinese characters, are rendered as tofu blocks. I believe this issue is probably not limited to Chinese characters.

Example

package main

import (
	"fmt"

	"github.com/gogpu/gogpu"
	"github.com/gogpu/ui/app"
	"github.com/gogpu/ui/core/button"
	"github.com/gogpu/ui/desktop"
	"github.com/gogpu/ui/primitives"
	"github.com/gogpu/ui/widget"
)

func main() {

	gogpuApp := gogpu.NewApp(gogpu.DefaultConfig().
		WithTitle("Font Demo").
		WithSize(600, 300))

	uiApp := app.New(
		app.WithWindowProvider(gogpuApp),
		app.WithPlatformProvider(gogpuApp),
		app.WithEventSource(gogpuApp.EventSource()),
	)

	uiApp.SetRoot(
		primitives.Box(
			primitives.Text("test: 测试").FontSize(20),
			button.New(button.Text("test2: 测试2"), button.OnClick(func() {
				fmt.Println("Button clicked!")
			})),
			primitives.Text("English text (both work)").FontSize(16).Color(widget.RGBA8(100, 100, 100, 255)),
		).Padding(24).Gap(16).Background(widget.RGBA8(255, 255, 255, 255)),
	)

	if err := desktop.Run(gogpuApp, uiApp); err != nil {
		panic(err)
	}
}
Image

Possible root cause

Using button as an example, it uses DefaultPainter, which internally calls canvas.DrawText.

However, canvas (in internal/render/canvas.go) appears to use Inter as its default font. I believe this is likely the reason why characters that are not supported by Inter cannot be rendered correctly.

To be honest, I haven't found a solution that I'm fully satisfied with for rendering characters that are not covered by Inter, so I decided to open this issue.

Environment

  • gogpu/ui v0.1.51
  • gogpu v0.50.2
  • Go 1.26.5, Linux (Wayland)

Finally, thank you for this project. I really like the ambition behind it

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions