コード例 #1
0
ファイル: BXFNT.cs プロジェクト: skybook888/Switch-Toolbox
 private CharacterWidthEntry GetCharWidthInfoByIndex(FINF fontInfo, UInt16 Index)
 {
     foreach (var v in fontInfo.CharacterWidths)
     {
         if (Index < v.StartIndex || Index > v.EndIndex)
         {
             continue;
         }
         return(v.WidthEntries[Index - v.StartIndex]);
     }
     return(null);
 }
コード例 #2
0
        private static YamlSequenceNode SaveCharacterMaps(FINF fontInfo)
        {
            YamlSequenceNode node = new YamlSequenceNode();

            // node.Style = SharpYaml.YamlStyle.Flow;
            foreach (var character in fontInfo.CodeMapDictionary.Keys)
            {
                YamlMappingNode mapping = new YamlMappingNode();
                mapping.Add($"0x{((ushort)character).ToString("X4")}", character.ToString());
                node.Add(mapping);
            }

            return(node);
        }
コード例 #3
0
        private static YamlSequenceNode SaveCharacterWidths(FINF fontInfo)
        {
            YamlSequenceNode node = new YamlSequenceNode();

            foreach (var character in fontInfo.CodeMapDictionary)
            {
                YamlMappingNode mapping = new YamlMappingNode();
                mapping.Style = SharpYaml.YamlStyle.Flow;
                if (character.Value != -1)
                {
                    var width = fontInfo.GetCharacterWidth(character.Value);
                    mapping.Add($"0x{((ushort)character.Key).ToString("X4")}", SaveCharacterWidth(width));
                }
                node.Add(mapping);
            }
            return(node);
        }
コード例 #4
0
        private static YamlMappingNode SaveFontInfo(FINF fontInfo)
        {
            YamlMappingNode mapping = new YamlMappingNode();

            mapping.Add("Type", fontInfo.Type.ToString());
            mapping.Add("Font_Width", fontInfo.Width.ToString());
            mapping.Add("Font_Height", fontInfo.Height.ToString());
            mapping.Add("Line_Feed", fontInfo.LineFeed.ToString());
            mapping.Add("Ascent", fontInfo.Ascent.ToString());
            mapping.Add("AlterCharIndex", fontInfo.AlterCharIndex.ToString());
            mapping.Add("DefaultCharWidth", fontInfo.DefaultCharWidth.ToString());
            mapping.Add("DefaultGlyphWidth", fontInfo.DefaultGlyphWidth.ToString());
            mapping.Add("DefaultLeftWidth", fontInfo.DefaultLeftWidth.ToString());
            mapping.Add("Texture_Glyph", SaveTextureGlyph(fontInfo.TextureGlyph));
            mapping.Add("Characters", SaveCharacterMaps(fontInfo));
            mapping.Add("Character Widths", SaveCharacterWidths(fontInfo));
            return(mapping);
        }
コード例 #5
0
        public void Read(FileReader reader)
        {
            string Signature = reader.ReadString(4, Encoding.ASCII);

            if (Signature != "FFNT")
            {
                throw new Exception($"Invalid signature {Signature}! Expected FFNT.");
            }

            char[] Magic = reader.ReadChars(4);
            BOM     = reader.ReadUInt16();
            Version = reader.ReadUInt32();
            uint FileSize   = reader.ReadUInt16();
            uint BlockCount = reader.ReadUInt16();
            uint unk        = reader.ReadUInt16();

            finf = new FINF();
            finf.Read(reader);
        }
コード例 #6
0
        public void Read(FileReader reader)
        {
            reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;

            string Signature = reader.ReadString(4, Encoding.ASCII);

            if (Signature != "FFNT")
            {
                throw new Exception($"Invalid signature {Signature}! Expected FFNT.");
            }

            BOM = reader.ReadUInt16();
            reader.CheckByteOrderMark(BOM);
            HeaderSize = reader.ReadUInt16();
            Version    = reader.ReadUInt32();
            uint   FileSize   = reader.ReadUInt16();
            ushort BlockCount = reader.ReadUInt16();
            ushort Padding    = reader.ReadUInt16();

            reader.Seek(HeaderSize, SeekOrigin.Begin);
            string SignatureCheck = CheckSignature(reader);

            switch (SignatureCheck)
            {
            case "FINF":
                FINF finf = new FINF();
                finf.Read(reader);
                Blocks.Add(finf);
                break;

            default:
                throw new NotImplementedException("Unsupported block found! " + SignatureCheck);
            }

            reader.Close();
            reader.Dispose();
        }
コード例 #7
0
ファイル: BXFNT.cs プロジェクト: skybook888/Switch-Toolbox
        public void Read(FileReader reader)
        {
            reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;

            Signature = reader.ReadString(4, Encoding.ASCII);
            if (Signature != "FFNT" && Signature != "CFNT" && Signature != "RFNT")
            {
                throw new Exception($"Invalid signature {Signature}! Expected FFNT or CFNT or RFNT.");
            }

            BOM = reader.ReadUInt16();
            reader.CheckByteOrderMark(BOM);

            //Parse header first and check the version
            //Brfnt uses a slightly different header structure
            if (Signature == "RFNT")
            {
                Version = reader.ReadUInt16();
                uint FileSize = reader.ReadUInt32();
                HeaderSize = reader.ReadUInt16();
                ushort BlockCount = reader.ReadUInt16();
            }
            else
            {
                HeaderSize = reader.ReadUInt16();
                Version    = reader.ReadUInt32();
                uint   FileSize   = reader.ReadUInt16();
                ushort BlockCount = reader.ReadUInt16();
                ushort Padding    = reader.ReadUInt16();
            }

            //Check platform based on version, magic, and endianness
            if (reader.ByteOrder == Syroot.BinaryData.ByteOrder.LittleEndian)
            {
                if (Version >= 0x04010000)
                {
                    Platform = PlatformType.NX;
                }
                else
                {
                    Platform = PlatformType.Ctr;
                }
            }
            else
            {
                Platform = PlatformType.Cafe;
            }

            if (Signature == "CFNT")
            {
                Platform = PlatformType.Ctr;
            }
            if (Signature == "RFNT")
            {
                Platform = PlatformType.Wii;
            }

            Console.WriteLine($"Platform {Platform}");

            reader.Seek(HeaderSize, SeekOrigin.Begin);
            FontSection = new FINF();
            FontSection.Read(reader, this);

            //Check for any unread blocks
            reader.Seek(HeaderSize, SeekOrigin.Begin);
            while (!reader.EndOfStream)
            {
                long BlockStart = reader.Position;

                string BlockSignature = reader.ReadString(4, Encoding.ASCII);
                uint   BlockSize      = reader.ReadUInt32();

                switch (BlockSignature)
                {
                case "FFNT":
                case "FFNA":
                case "FCPX":
                case "CWDH":
                case "CGLP":
                case "CMAP":
                case "TGLP":
                case "FINF":
                    break;

                case "KRNG":
                    KerningTable = new FontKerningTable();
                    KerningTable.Read(reader, this, BlockSize);
                    break;

                case "GLGR":
                case "HTGL":
                    break;

                default:
                    throw new Exception("Unknown block found! " + BlockSignature);
                }

                reader.SeekBegin(BlockStart + BlockSize);
            }
        }
コード例 #8
0
ファイル: BFFNT.cs プロジェクト: LockeExile/Switch-Toolbox
        public void Read(FileReader reader)
        {
            reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;

            string Signature = reader.ReadString(4, Encoding.ASCII);

            if (Signature != "FFNT" && Signature != "CFNT")
            {
                throw new Exception($"Invalid signature {Signature}! Expected FFNT or CFNT.");
            }

            BOM = reader.ReadUInt16();
            reader.CheckByteOrderMark(BOM);
            HeaderSize = reader.ReadUInt16();
            Version    = reader.ReadUInt32();
            uint   FileSize   = reader.ReadUInt16();
            ushort BlockCount = reader.ReadUInt16();
            ushort Padding    = reader.ReadUInt16();

            if (reader.ByteOrder == Syroot.BinaryData.ByteOrder.LittleEndian)
            {
                if (Version > 0x3000000 || Version > 0x00000103)
                {
                    Platform = PlatformType.NX;
                }
                else
                {
                    Platform = PlatformType.Ctr;
                }
            }
            else
            {
                Platform = PlatformType.Cafe;
            }

            if (Signature == "CFNT")
            {
                Platform = PlatformType.Ctr;
            }

            reader.Seek(HeaderSize, SeekOrigin.Begin);
            FontSection = new FINF();
            FontSection.Read(reader, this);
            Blocks.Add(FontSection);

            //Check for any unread blocks
            reader.Seek(HeaderSize, SeekOrigin.Begin);
            while (!reader.EndOfStream)
            {
                long BlockStart = reader.Position;

                string BlockSignature = reader.ReadString(4, Encoding.ASCII);
                uint   BlockSize      = reader.ReadUInt32();

                switch (BlockSignature)
                {
                case "FFNT":
                case "FFNA":
                case "FCPX":
                case "CWDH":
                case "CGLP":
                case "CMAP":
                case "TGLP":
                case "FINF":
                    break;

                case "KRNG":
                    KerningTable = new FontKerningTable();
                    KerningTable.Read(reader, this);
                    break;

                case "GLGR":
                case "HTGL":
                    break;

                default:
                    throw new Exception("Unknown block found! " + BlockSignature);
                }

                reader.SeekBegin(BlockStart + BlockSize);
            }
        }