giu icon indicating copy to clipboard operation
giu copied to clipboard

[bug] AddFont not working depending on scale factor on windows

Open 0xkalle opened this issue 1 year ago • 10 comments

What happend?

When adding font in different sizes with AddFont to the FontAtlas, it is working fine on 100% Scale. On other Scales it is not working or partly working. e.g. on 125% no custom fonts work while on 150% some work.

Beside the example below I also made as simple as possible example repo: https://github.com/0xkalle/giu-font-test

I also tried to run with master. But it is crashing (even the hello world example crashes)

Code example

main.go
package main

import (
	g "github.com/AllenDang/giu"
)

var (
	datafont_16 *g.FontInfo
	datafont_24 *g.FontInfo
	datafont_32 *g.FontInfo
	datafont_48 *g.FontInfo
	datafont_64 *g.FontInfo
	datafont_72 *g.FontInfo
	datafont_96 *g.FontInfo
)

func loop() {
	g.SingleWindow().Layout(
		g.Label("0verlay Text 96").Font(datafont_96),
		g.Label("0verlay Text 72").Font(datafont_72),
		g.Label("0verlay Text 64").Font(datafont_64),
		g.Label("0verlay Text 48").Font(datafont_48),
		g.Label("0verlay Text 32").Font(datafont_32),
		g.Label("0verlay Text 24").Font(datafont_24),
		g.Label("0verlay Text 16").Font(datafont_16),
	)
}

func main() {
	wnd := g.NewMasterWindow("Font test", 600, 400, 0)
	datafont_16 = g.Context.FontAtlas.AddFont("robotomono-m.ttf", 16)
	datafont_24 = g.Context.FontAtlas.AddFont("robotomono-m.ttf", 24)
	datafont_32 = g.Context.FontAtlas.AddFont("robotomono-m.ttf", 32)
	datafont_48 = g.Context.FontAtlas.AddFont("robotomono-m.ttf", 48)
	datafont_64 = g.Context.FontAtlas.AddFont("robotomono-m.ttf", 64)
	datafont_72 = g.Context.FontAtlas.AddFont("robotomono-m.ttf", 72)
	datafont_96 = g.Context.FontAtlas.AddFont("robotomono-m.ttf", 96)

	wnd.Run(loop)
}

To Reproduce

  1. Set Scale in windows to 100 / 125 / 150 %
  2. Run my demo
  3. see the fonts in window.

Results are: 100% 100

125% 125

150% 150

Version

(latest)

OS

windows 10

0xkalle avatar Feb 09 '24 10:02 0xkalle

Use original key for extraFontMap in FontAtlasProsessor.go

        // Add extra fonts
	for _, fontInfo := range a.extraFonts {
		// Scale font size with DPI scale factor
		key := fontInfo.String()
		if runtime.GOOS == windows {
			fontInfo.size *= Context.GetPlatform().GetContentScale()
		}

		// Store imgui.Font for PushFont
		var f imgui.Font
		if len(fontInfo.fontByte) == 0 {
			f = fonts.AddFontFromFileTTFV(fontInfo.fontPath, fontInfo.size, imgui.DefaultFontConfig, ranges.Data())
		} else {
			f = fonts.AddFontFromMemoryTTFV(fontInfo.fontByte, fontInfo.size, imgui.DefaultFontConfig, ranges.Data())
		}

		a.extraFontMap[key] = &f
	}

wxblue avatar Feb 21 '24 10:02 wxblue

I'll try that later today. Thanks. :)

0xkalle avatar Feb 27 '24 07:02 0xkalle

Works. :) Is it worth it to make a PR for this or should it be fixed in the upcoming c-imgui version if still needed?

0xkalle avatar Feb 27 '24 10:02 0xkalle

idk, could you check if this issue still exists on master?

gucio321 avatar Feb 27 '24 16:02 gucio321

I'll check. Last time I couldn't get it to run with master. I'll try again and report back. :)

0xkalle avatar Feb 27 '24 19:02 0xkalle

Still persists on master as well.

It also leads to this odd window that keeps getting bigger like mentioned in #155 . But I can see the fonts in the beginning and on 125% scaling they are not the fonts they should be and not in the right size.

Here is a screen recording:

https://github.com/AllenDang/giu/assets/31923808/a76bb72c-dddf-4c90-864d-4134d23c2ee3

0xkalle avatar Mar 07 '24 07:03 0xkalle

@0xkalle May I ask you to try again with v0.8.1? The issue from your previous post was fixed in #810

gucio321 avatar Jul 07 '24 21:07 gucio321

@0xkalle May I ask you to try again with v0.8.1? The issue from your previous post was fixed in #810

"Grow to death" is gone. 👍

Font sizes are not working like described in the initial post of the thread https://github.com/AllenDang/giu/issues/759#issue-2126893620

0xkalle avatar Jul 08 '24 06:07 0xkalle