Exemplo n.º 1
0
        static BillboardText3D()
        {
            var assembly = Assembly.GetExecutingAssembly();

            var texDescriptionFilePath = Path.GetTempFileName();
            var texImageFilePath       = Path.GetTempFileName();

            //Read the texture description
            var texDescriptionStream = assembly.GetManifestResourceStream("HelixToolkit.Wpf.SharpDX.Textures.arial.fnt");

            using (var fileStream = File.Create(texDescriptionFilePath))
            {
                texDescriptionStream.CopyTo(fileStream);
            }

            bmpFont = BitmapFontLoader.LoadFontFromFile(texDescriptionFilePath);

            //Read the texture
            var texImageStream = assembly.GetManifestResourceStream("HelixToolkit.Wpf.SharpDX.Textures.arial.png");

            using (var fileStream = File.Create(texImageFilePath))
            {
                texImageStream.CopyTo(fileStream);
            }

            TextureStatic = new BitmapImage(new Uri(texImageFilePath));
            TextureStatic.Freeze();
            //Cleanup the temp files
            if (File.Exists(texDescriptionFilePath))
            {
                File.Delete(texDescriptionFilePath);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads a BitmapFont
        /// </summary>
        public BitmapFont LoadBitmapFont(string name)
        {
            if (LoadedAssets.TryGetValue(name, out var asset))
            {
                if (asset is BitmapFont bmFont)
                {
                    return(bmFont);
                }
            }

            var font = BitmapFontLoader.LoadFontFromFile(name);

            LoadedAssets.Add(name, font);
            DisposableAssets.Add(font);

            return(font);
        }
Exemplo n.º 3
0
        private static void Initialize()
        {
            if (isInitialized)
            {
                return;
            }

            var assembly = Assembly.GetExecutingAssembly();

            var texDescriptionFilePath = Path.GetTempFileName();
            var texImageFilePath       = Path.GetTempFileName();

            //Read the texture description
            var texDescriptionStream = assembly.GetManifestResourceStream("HelixToolkit.Wpf.SharpDX.Textures.arial.fnt");

            using (var fileStream = File.Create(texDescriptionFilePath))
            {
                texDescriptionStream.CopyTo(fileStream);
            }

            bmpFont = BitmapFontLoader.LoadFontFromFile(texDescriptionFilePath);

            //Read the texture
            var texImageStream = assembly.GetManifestResourceStream("HelixToolkit.Wpf.SharpDX.Textures.arial.png");

            using (var fileStream = File.Create(texImageFilePath))
            {
                texImageStream.CopyTo(fileStream);
            }

            Texture = new BitmapImage(new Uri(texImageFilePath));

            //Cleanup the temp files
            if (File.Exists(texDescriptionFilePath))
            {
                File.Delete(texDescriptionFilePath);
            }

            isInitialized = true;
        }
Exemplo n.º 4
0
        public BillboardText3D()
        {
            Positions          = new Vector3Collection();
            Colors             = new Color4Collection();
            TextureCoordinates = new Vector2Collection();

            this.TextInfo = new List <TextInfo>();

            var assembly = Assembly.GetExecutingAssembly();

            var texDescriptionFilePath = Path.GetTempFileName();
            var texImageFilePath       = Path.GetTempFileName();

            //Read the texture description
            var texDescriptionStream = assembly.GetManifestResourceStream("HelixToolkit.Wpf.SharpDX.Textures.arial.fnt");

            using (var fileStream = File.Create(texDescriptionFilePath))
            {
                texDescriptionStream.CopyTo(fileStream);
            }

            bmpFont = BitmapFontLoader.LoadFontFromFile(texDescriptionFilePath);

            //Read the texture
            var texImageStream = assembly.GetManifestResourceStream("HelixToolkit.Wpf.SharpDX.Textures.arial.png");

            using (var fileStream = File.Create(texImageFilePath))
            {
                texImageStream.CopyTo(fileStream);
            }

            Texture = new BitmapImage(new Uri(texImageFilePath));

            //Cleanup the temp files
            if (File.Exists(texDescriptionFilePath))
            {
                File.Delete(texDescriptionFilePath);
            }
        }
Exemplo n.º 5
0
        private void OnExecute()
        {
            if (string.IsNullOrEmpty(Input) || !File.Exists(Input))
            {
                Console.WriteLine($"ERROR: No existe el fichero \"{Input}\"");
                Exit();
            }

            BitmapFont font = null;

            try
            {
                font = BitmapFontLoader.LoadFontFromFile(Input);
            }
            catch (InvalidDataException)
            {
                Console.WriteLine($"ERROR: No se reconoce el formato. Asegurate de que es un fichero de texto o XML creado por BMFont");
                Exit();
            }

            var textures = font.Pages.ToDictionary(page => page.Id, page => Image.FromFile(page.FileName));

            var bitmap = new Bitmap(512, 1024);

            var heightFactor = 1.0f;

            /*foreach (var character in font.Characters)
             * {
             *  if (character.Value.Bounds.Height >= 64)
             *  {
             *      heightFactor = Math.Min(heightFactor, 64f / character.Value.Bounds.Height);
             *  }
             * }*/

            var yOffsetCorrection = 0;

            foreach (var character in font.Characters)
            {
                if (character.Value.Offset.Y + character.Value.Bounds.Height > 64)
                {
                    yOffsetCorrection = Math.Min(yOffsetCorrection, 64 - character.Value.Offset.Y - character.Value.Bounds.Height);
                }
            }

            using (var g = Graphics.FromImage(bitmap))
            {
                var x = 0;
                var y = 0;
                for (var row = 0x2; row < 0x8; row++)
                {
                    x = 0;
                    y = (row - 0x2) * 64;
                    for (var col = 0x0; col < 0x10; col++)
                    {
                        var value = row * 0x10 + col;
                        if (value == 0x5C)
                        {
                            value = 0xA5;
                        }

                        if (value == 0x7F)
                        {
                            value = 0xAE;
                        }

                        var chr = Convert.ToChar(value);
                        if (font.Characters.ContainsKey(chr))
                        {
                            var data = font[chr];
                            DrawCharacter(g, data, textures[data.TexturePage], x, y, heightFactor, yOffsetCorrection);
                        }

                        x += 32;
                    }
                }

                for (var row = 0xA; row < 0x10; row++)
                {
                    x = 0;
                    y = (row - 0x2) * 64;
                    for (var col = 0x0; col < 0x10; col++)
                    {
                        var chr = Convert.ToChar(row * 0x10 + col);
                        if (font.Characters.ContainsKey(chr))
                        {
                            var data = font[chr];
                            DrawCharacter(g, data, textures[data.TexturePage], x, y, heightFactor, yOffsetCorrection);
                        }
                        x += 32;
                    }
                }
            }

            using (var ms = new MemoryStream())
            {
                bitmap.Save(ms, ImageFormat.Png);

                var bytes            = ms.ToArray();
                var unmanagedPointer = Marshal.AllocHGlobal(bytes.Length);
                Marshal.Copy(bytes, 0, unmanagedPointer, bytes.Length);
                var inputDds = TexHelper.Instance.LoadFromWICMemory(unmanagedPointer, bytes.Length, WIC_FLAGS.NONE);
                Marshal.FreeHGlobal(unmanagedPointer);

                var dds = inputDds.Compress(DXGI_FORMAT.BC3_UNORM, TEX_COMPRESS_FLAGS.DEFAULT, 0.5f);

                var outputFile = Path.Combine(Path.GetDirectoryName(Input), "hd2_hankaku.dds");
                dds.SaveToDDSFile(DDS_FLAGS.NONE, outputFile);
            }

            Exit();
        }
Exemplo n.º 6
0
        private void OnExecute()
        {
            foreach (var size in FontSizes)
            {
                var originalChars = ReadGameFont(InputPath, size);
                var newChars      = new Dictionary <int, byte[]>();


                var configFilePath = GenerateConfigFile(ConfigFile, size);
                var fontFilePath   = Path.Combine(OutputPath, "FuenteTrails.fnt");

                GenerateFont(configFilePath, fontFilePath);

                var font     = BitmapFontLoader.LoadFontFromFile(fontFilePath);
                var textures = font.Pages.ToDictionary(page => page.Id, page => Image.FromFile(page.FileName));

                var width = (int)Math.Ceiling(size / 2.0d);

                var charIndexes = new int[256];
                for (var i = 0; i < 255; i++)
                {
                    charIndexes[i] = i;
                }
                charIndexes[0x26] = 0xC9; // É
                charIndexes[0x27] = 0xCD; // Í
                charIndexes[0x3B] = 0xE1; // á
                charIndexes[0x5C] = 0xE9; // é
                charIndexes[0x5E] = 0xED; // í
                charIndexes[0x5F] = 0xF3; // ó
                charIndexes[0x60] = 0xFA; // ú
                charIndexes[0x7B] = 0xFC; // ü
                charIndexes[0x7D] = 0xF1; // ñ
                charIndexes[0x7E] = 0xA1; // ¡
                charIndexes[0x7F] = 0xBF; // ¿


                for (var i = 0x21; i < 0xFF; i++)
                {
                    var chr = Convert.ToChar(charIndexes[i]);
                    if (font.Characters.ContainsKey(chr))
                    {
                        newChars.Add(i, DrawCharacter(font[chr], textures[font[chr].TexturePage], size, width));
                    }
                }

                var fileName = $"FONT{size}";
                var limit    = fileName.Length;
                for (var i = 0; i < 8 - limit; i++)
                {
                    fileName = string.Concat(fileName, " ");
                }
                fileName = string.Concat(fileName, "._DA");
                var file = Path.Combine(OutputPath, fileName);

                using (var bw = new BinaryWriter(new FileStream(file, FileMode.Create)))
                {
                    for (var i = 0x20; i < 0xE0; i++)
                    {
                        bw.Write(newChars.ContainsKey(i) ? newChars[i] : originalChars[i - 0x20]);
                    }

                    for (var i = 0xE0; i < originalChars.Count + 0x20; i++)
                    {
                        bw.Write(originalChars[i - 0x20]);
                    }
                }

                foreach (var texture in textures)
                {
                    texture.Value.Dispose();
                }
                Clean(configFilePath, OutputPath);
            }

            Exit();
        }
Exemplo n.º 7
0
 public BitmapFont LoadAuto()
 {
     return(BitmapFontLoader.LoadFontFromFile(_xmlFileName));
 }
Exemplo n.º 8
0
        private void OnExecute()
        {
            foreach (var size in FontSizes)
            {
                var originalChars = ReadGameFont(InputPath, size);
                var newChars = new List<byte[]>();
                var newChars2 = new List<byte[]>();

                var configFilePath = GenerateConfigFile(ConfigFile, size);
                var fontFilePath = Path.Combine(OutputPath, "FuenteTrails.fnt");

                GenerateFont(configFilePath, fontFilePath);

                var font = BitmapFontLoader.LoadFontFromFile(fontFilePath);
                var textures = font.Pages.ToDictionary(page => page.Id, page => Image.FromFile(page.FileName));

                var width = (int) Math.Ceiling(size / 2.0d);

                for (var i = 0x21; i < 0x7F; i++)
                {
                    var chr = Convert.ToChar(i);
                    if (font.Characters.ContainsKey(chr))
                    {
                        newChars.Add(DrawCharacter(font[chr], textures[font[chr].TexturePage], size, width));
                    }
                }

                for (var i = 0xA1; i < 0x100; i++)
                {
                    var chr = Convert.ToChar(i);
                    if (font.Characters.ContainsKey(chr))
                    {
                        newChars2.Add(DrawCharacter(font[chr], textures[font[chr].TexturePage], size, width));
                    }
                }

                var fileName = $"FONT{size}";
                var limit = fileName.Length;
                for (var i = 0; i < 8 - limit; i++)
                {
                    fileName = string.Concat(fileName, " ");
                }
                fileName = string.Concat(fileName, "._DA");
                var file = Path.Combine(OutputPath, fileName);

                using (var bw = new BinaryWriter(new FileStream(file, FileMode.Create)))
                {
                    bw.Write(originalChars[0]); // El espacio

                    for (var i = 0x21; i < 0x7F; i++)
                    {
                        bw.Write(newChars[i - 0x21]);
                    }

                    for (var i = 0x7F; i < 0xA1; i++)
                    {
                        bw.Write(originalChars[i - 0x20]);
                    }

                    for (var i = 0xA1; i < 0x100; i++)
                    {
                        bw.Write(newChars2[i - 0xA1]);
                    }

                    for (var i = 0x100; i < originalChars.Count + 0x20; i++)
                    {
                        bw.Write(originalChars[i - 0x20]);
                    }
                }

                foreach (var texture in textures)
                {
                    texture.Value.Dispose();
                }
                Clean(configFilePath, OutputPath);
            }

            Exit();
        }