Пример #1
0
        private unsafe void SetFonts()
        {
            var folder = "fonts";
            var files  = Directory.GetFiles(folder);

            if (!(Directory.Exists(folder) && files.Length > 0))
            {
                return;
            }

            var fontsForLoad = new List <(string, int)>();

            if (files.Contains($"{folder}\\config.ini"))
            {
                var lines = File.ReadAllLines($"{folder}\\config.ini");

                foreach (var line in lines)
                {
                    var split = line.Split(':');
                    fontsForLoad.Add(($"{folder}\\{split[0]}.ttf", int.Parse(split[1])));
                }
            }

            var          sm   = new ImFontAtlas();
            ImFontAtlas *some = &sm;

            var imFontAtlasGetGlyphRangesCyrillic = ImGuiNative.ImFontAtlas_GetGlyphRangesCyrillic(some);

            fonts["Default:13"] = new FontContainer(ImGuiNative.ImFontAtlas_AddFontDefault(some, null),
                                                    "Default", 13);

            foreach (var tuple in fontsForLoad)
            {
                var bytes = Encoding.UTF8.GetBytes(tuple.Item1);

                fixed(byte *f = &bytes[0])
                {
                    fonts[$"{tuple.Item1.Replace(".ttf", "").Replace("fonts\\", "")}:{tuple.Item2}"] =
                        new FontContainer(
                            ImGuiNative.ImFontAtlas_AddFontFromFileTTF(some, f, tuple.Item2, null,
                                                                       imFontAtlasGetGlyphRangesCyrillic), tuple.Item1, tuple.Item2);
                }
            }

            Settings.Font.Values = new List <string>(fonts.Keys);
        }
Пример #2
0
        public Font AddDefaultFont()
        {
            NativeFont *nativeFontPtr = ImGuiNative.ImFontAtlas_AddFontDefault(_atlasPtr);

            return(new Font(nativeFontPtr));
        }