示例#1
0
        private static Bitmap ToImage(sNFTR font, Color[] palette, int charWidth, int charHeight,
                                      int numRows, int numColumns, int zoom)
        {
            int numChars = font.plgc.tiles.Length;
            int width    = numColumns * charWidth + BORDER_WIDTH;
            int height   = numRows * charHeight + BORDER_WIDTH;

            Bitmap   image   = new Bitmap(width, height);
            Graphics graphic = Graphics.FromImage(image);

            // Draw chars
            for (int i = 0; i < numRows; i++)
            {
                for (int j = 0; j < numColumns; j++)
                {
                    int index = i * numColumns + j;
                    if (index >= numChars)
                    {
                        break;
                    }

                    int x = j * charWidth + BORDER_WIDTH;
                    int y = i * charHeight + BORDER_WIDTH;

                    int align = BORDER_WIDTH - (BORDER_WIDTH / 2);
                    graphic.DrawRectangle(BORDER, x - align, y - align, charWidth, charHeight);
                    graphic.DrawImage(Get_Char(font, index, palette, zoom), x, y);
                }
            }

            graphic.Dispose();
            graphic = null;
            return(image);
        }
示例#2
0
        public CharControl(String lang,
            int charCode, sNFTR.HDWC.Info tileInfo, Byte[] tiles, int depth, int width, int height, int rotateMode,
            Color[] palette)
        {
            InitializeComponent();
            ReadLanguage(lang);

            this.charCode = charCode;
            this.tileInfo = tileInfo;
            this.tiles = tiles;
            this.depth = depth;
            this.width = width;
            this.height = height;
            this.rotateMode = rotateMode;
            this.palette = palette;

            txtCharCode.Text = String.Format("0x{0:X}", charCode);
            numericStart.Value = tileInfo.pixel_start;
            numericLength.Value = tileInfo.pixel_length;
            numericWidth.Value = tileInfo.pixel_width;

            Draw_Char();

            picPaletteColour.BackColor = palette[0];
            trackPalette.Maximum = Convert.ToByte(new String('1', depth), 2);
            trackPalette.Value = trackPalette.Maximum;
            picPaletteColour.BackColor = palette[trackPalette.Value];
        }
示例#3
0
        public static Bitmap Get_Chars(sNFTR font, int maxWidth, Color[] palette, int zoom = 1)
        {
            int numChars = font.plgc.tiles.Length;

            // Get the image size
            int charWidth  = font.plgc.tile_width * zoom + BORDER_WIDTH;
            int charHeight = font.plgc.tile_height * zoom + BORDER_WIDTH;

            int numColumns = maxWidth / (charWidth + BORDER_WIDTH);
            int numRows    = (int)Math.Ceiling((double)numChars / numColumns);

            return(ToImage(font, palette, charWidth, charHeight, numRows, numColumns, zoom));
        }
示例#4
0
        public static Bitmap ToImage(sNFTR font, Color[] palette)
        {
            int numChars = font.plgc.tiles.Length;

            // Get the image size
            int numColumns = (numChars < CHARS_PER_LINE) ? numChars : CHARS_PER_LINE;
            int numRows    = (int)Math.Ceiling((double)numChars / numColumns);

            int charWidth  = font.plgc.tile_width + BORDER_WIDTH;
            int charHeight = font.plgc.tile_height + BORDER_WIDTH;

            return(ToImage(font, palette, charWidth, charHeight, numRows, numColumns, 1));
        }
示例#5
0
        public static void ExportFullInfo(string fileOut, sNFTR font)
        {
            string encName = null;

            switch (font.fnif.encoding)
            {
            case 0: encName = "utf-8"; break;

            case 1: encName = "utf-16"; break;

            case 2: encName = "shift_jis"; break;

            case 3: encName = Encoding.GetEncoding(1252).EncodingName; break;
            }

            XDocument doc = new XDocument();

            doc.Declaration = new XDeclaration("1.0", encName, "yes");
            XElement root = new XElement("NFTR");

            // Export general info
            // FNIF data
            XElement xmlFnif = new XElement("FNIF");

            xmlFnif.Add(new XElement("Unknown1", font.fnif.unknown1));
            xmlFnif.Add(new XElement("Height", font.fnif.height));
            xmlFnif.Add(new XElement("NullCharIndex", font.fnif.nullCharIndex));
            xmlFnif.Add(new XElement("Unknown2", font.fnif.unknown4));
            xmlFnif.Add(new XElement("Width", font.fnif.width));
            xmlFnif.Add(new XElement("WidthBis", font.fnif.width_bis));
            xmlFnif.Add(new XElement("Encoding", encName));
            if (font.fnif.block_size == 0x20)
            {
                xmlFnif.Add(new XElement("GlyphHeight", font.fnif.height_font));
                xmlFnif.Add(new XElement("GlyphWidth", font.fnif.widht_font));
                xmlFnif.Add(new XElement("BearingY", font.fnif.bearing_y));
                xmlFnif.Add(new XElement("BearingX", font.fnif.bearing_x));
            }
            root.Add(xmlFnif);

            doc.Add(root);
            doc.Save(fileOut);
            root = null;
            doc  = null;
        }
示例#6
0
        public FontControl(IPluginHost pluginHost, sNFTR font)
        {
            InitializeComponent();

            this.pluginHost = pluginHost;
            this.font = font;
            ReadLanguage();
            this.palette = NFTR.CalculatePalette(font.plgc.depth, inversePalette);

            for (int i = 0; i < font.plgc.tiles.Length; i++)
                comboChar.Items.Add("Char " + i.ToString());

            picFont.Image = NFTR.Get_Chars(font, MAX_WIDTH, palette, ZOOM);

            Fill_CharTile();

            comboChar.SelectedIndex = 0;
            comboEncoding.SelectedIndex = font.fnif.encoding;
        }
示例#7
0
        public FontControl(IPluginHost pluginHost, sNFTR font)
        {
            InitializeComponent();

            this.pluginHost = pluginHost;
            this.font       = font;
            ReadLanguage();
            this.palette = NFTR.CalculatePalette(font.plgc.depth, inversePalette);
            for (int i = 0; i < font.plgc.tiles.Length; i++)
            {
                comboChar.Items.Add("Char " + i.ToString());
            }

            picFont.Image = NFTR.Get_Chars(font, MAX_WIDTH, palette, ZOOM);

            Fill_CharTile();

            comboChar.SelectedIndex     = 0;
            comboEncoding.SelectedIndex = font.fnif.encoding;
        }
示例#8
0
        public static void FromImage(Bitmap image, sNFTR font, Color[] palette)
        {
            int numChars = font.plgc.tiles.Length;

            // Get the image size
            int numColumns = (numChars < CHARS_PER_LINE) ? numChars : CHARS_PER_LINE;
            int numRows    = (int)Math.Ceiling((double)numChars / numColumns);

            int charWidth  = font.plgc.tile_width + BORDER_WIDTH;
            int charHeight = font.plgc.tile_height + BORDER_WIDTH;

            int width  = numColumns * charWidth + BORDER_WIDTH;
            int height = numRows * charHeight + BORDER_WIDTH;

            if (width != image.Width || height != image.Height)
            {
                System.Windows.Forms.MessageBox.Show("Incorrect size.");
                return;
            }

            // Draw chars
            for (int i = 0; i < numRows; i++)
            {
                for (int j = 0; j < numColumns; j++)
                {
                    int index = i * numColumns + j;
                    if (index >= numChars)
                    {
                        break;
                    }

                    int x = j * charWidth + BORDER_WIDTH;
                    int y = i * charHeight + BORDER_WIDTH;

                    Bitmap charImg = image.Clone(new Rectangle(x, y, charWidth - BORDER_WIDTH, charHeight - BORDER_WIDTH),
                                                 System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                    font.plgc.tiles[index] = SetChar(charImg, font.plgc.depth, palette);
                }
            }
        }
示例#9
0
        public static void ExportInfo(string fileOut, Dictionary <int, int> charTable, sNFTR font)
        {
            string enc_name = "utf-8";

            if (font.fnif.encoding == 2)
            {
                enc_name = "shift_jis";
            }
            else if (font.fnif.encoding == 1)
            {
                enc_name = "utf-16";
            }
            else if (font.fnif.encoding == 0)
            {
                enc_name = "utf-8";
            }
            else if (font.fnif.encoding == 3)
            {
                enc_name = Encoding.GetEncoding(1252).EncodingName;
            }

            XDocument doc = new XDocument();

            doc.Declaration = new XDeclaration("1.0", enc_name, null);

            XElement root = new XElement("CharMap");

            foreach (int c in charTable.Keys)
            {
                string ch    = "";
                byte[] codes = BitConverter.GetBytes(c).Reverse().ToArray();
                ch = new String(Encoding.GetEncoding(enc_name).GetChars(codes)).Replace("\0", "");

                int tileCode = charTable[c];
                if (tileCode >= font.hdwc.info.Count)
                {
                    continue;
                }
                sNFTR.HDWC.Info info = font.hdwc.info[tileCode];

                XElement chx = new XElement("CharInfo");
                chx.SetAttributeValue("Char", ch);
                chx.SetAttributeValue("Code", c.ToString("x"));
                chx.SetAttributeValue("Index", tileCode.ToString());
                chx.SetAttributeValue("Width", info.pixel_length.ToString());
                root.Add(chx);
            }

            doc.Add(root);
            doc.Save(fileOut);
        }
示例#10
0
文件: NFTR.cs 项目: MetLob/tinke
        public static void ExportFullInfo(string fileOut, sNFTR font)
        {
            string encName = null;
            switch (font.fnif.encoding)
            {
                case 0: encName = "utf-8"; break;
                case 1: encName = "utf-16"; break;
                case 2: encName = "shift_jis"; break;
                case 3: encName = Encoding.GetEncoding(1252).EncodingName; break;
            }

            XDocument doc = new XDocument();
            doc.Declaration = new XDeclaration("1.0", encName, "yes");
            XElement root = new XElement("NFTR");

            // Export general info
            // FNIF data
            XElement xmlFnif = new XElement("FNIF");
            xmlFnif.Add(new XElement("Unknown1", font.fnif.unknown1));
            xmlFnif.Add(new XElement("Height", font.fnif.height));
            xmlFnif.Add(new XElement("NullCharIndex", font.fnif.nullCharIndex));
            xmlFnif.Add(new XElement("Unknown2", font.fnif.unknown4));
            xmlFnif.Add(new XElement("Width", font.fnif.width));
            xmlFnif.Add(new XElement("WidthBis", font.fnif.width_bis));
            xmlFnif.Add(new XElement("Encoding", encName));
            if (font.fnif.block_size == 0x20)
            {
                xmlFnif.Add(new XElement("GlyphHeight", font.fnif.height_font));
                xmlFnif.Add(new XElement("GlyphWidth", font.fnif.widht_font));
                xmlFnif.Add(new XElement("BearingY", font.fnif.bearing_y));
                xmlFnif.Add(new XElement("BearingX", font.fnif.bearing_x));
            }
            root.Add(xmlFnif);

            doc.Add(root);
            doc.Save(fileOut);
            root = null;
            doc = null;
        }
示例#11
0
 public static Bitmap Get_Char(sNFTR font, int id, Color[] palette, int zoom = 1)
 {
     return(Get_Char(font.plgc.tiles[id], font.plgc.depth, font.plgc.tile_width, font.plgc.tile_height, font.plgc.rotateMode, palette, zoom));
 }
示例#12
0
文件: NFTR.cs 项目: MetLob/tinke
        public static void ExportInfo(string fileOut, Dictionary<int, int> charTable, sNFTR font)
        {
            string enc_name = "utf-8";
            if (font.fnif.encoding == 2)
                enc_name = "shift_jis";
            else if (font.fnif.encoding == 1)
                enc_name = "utf-16";
            else if (font.fnif.encoding == 0)
                enc_name = "utf-8";
            else if (font.fnif.encoding == 3)
                enc_name = Encoding.GetEncoding(1252).EncodingName;

            XDocument doc = new XDocument();
            doc.Declaration = new XDeclaration("1.0", enc_name, null);

            XElement root = new XElement("CharMap");

            foreach (int c in charTable.Keys)
            {
                string ch = "";
                byte[] codes = BitConverter.GetBytes(c).Reverse().ToArray();
                ch = new String(Encoding.GetEncoding(enc_name).GetChars(codes)).Replace("\0", "");

                int tileCode = charTable[c];
                if (tileCode >= font.hdwc.info.Count)
                    continue;
                sNFTR.HDWC.Info info = font.hdwc.info[tileCode];

                XElement chx = new XElement("CharInfo");
                chx.SetAttributeValue("Char", ch);
                chx.SetAttributeValue("Code", c.ToString("x"));
                chx.SetAttributeValue("Index", tileCode.ToString());
                chx.SetAttributeValue("Width", info.pixel_length.ToString());
                root.Add(chx);
            }

            doc.Add(root);
            doc.Save(fileOut);
        }
示例#13
0
文件: NFTR.cs 项目: MetLob/tinke
 public static Bitmap Get_Char(sNFTR font, int id, Color[] palette, int zoom = 1)
 {
     return Get_Char(font.plgc.tiles[id], font.plgc.depth, font.plgc.tile_width, font.plgc.tile_height, font.plgc.rotateMode, palette, zoom);
 }
示例#14
0
        public static sNFTR Read(sFile cfile, string lang)
        {
            sNFTR font = new sNFTR();

            font.id   = cfile.id;
            font.name = cfile.name;
            BinaryReader br = new BinaryReader(File.OpenRead(cfile.path));

            // Read the standard header
            font.header.type       = br.ReadChars(4);
            font.header.endianess  = br.ReadUInt16();
            font.header.unknown    = br.ReadUInt16();
            font.header.file_size  = br.ReadUInt32();
            font.header.block_size = br.ReadUInt16();
            font.header.num_blocks = br.ReadUInt16();

            // Font INFo section
            font.fnif.type       = br.ReadChars(4);
            font.fnif.block_size = br.ReadUInt32();

            font.fnif.unknown1      = br.ReadByte();
            font.fnif.height        = br.ReadByte();
            font.fnif.nullCharIndex = br.ReadUInt16();
            font.fnif.unknown4      = br.ReadByte();
            font.fnif.width         = br.ReadByte();
            font.fnif.width_bis     = br.ReadByte();
            font.fnif.encoding      = br.ReadByte();

            font.fnif.offset_plgc = br.ReadUInt32();
            font.fnif.offset_hdwc = br.ReadUInt32();
            font.fnif.offset_pamc = br.ReadUInt32();

            if (font.fnif.block_size == 0x20)
            {
                font.fnif.height_font = br.ReadByte();
                font.fnif.widht_font  = br.ReadByte();
                font.fnif.bearing_y   = br.ReadByte();
                font.fnif.bearing_x   = br.ReadByte();
            }

            // Character Graphics LP
            br.BaseStream.Position = font.fnif.offset_plgc - 0x08;
            font.plgc.type         = br.ReadChars(4);
            font.plgc.block_size   = br.ReadUInt32();
            font.plgc.tile_width   = br.ReadByte();
            font.plgc.tile_height  = br.ReadByte();
            font.plgc.tile_length  = br.ReadUInt16();
            font.plgc.unknown      = br.ReadUInt16();
            font.plgc.depth        = br.ReadByte();
            font.plgc.rotateMode   = br.ReadByte();

            font.plgc.tiles = new Byte[(font.plgc.block_size - 0x10) / font.plgc.tile_length][];
            for (int i = 0; i < font.plgc.tiles.Length; i++)
            {
                font.plgc.tiles[i] = BytesToBits(br.ReadBytes(font.plgc.tile_length));
                if (font.plgc.rotateMode >> 1 == 3)
                {
                    font.plgc.tiles[i] = Rotate270(font.plgc.tiles[i], font.plgc.tile_width, font.plgc.tile_height, font.plgc.depth);
                }
                else if (font.plgc.rotateMode >> 1 == 1)
                {
                    font.plgc.tiles[i] = Rotate90(font.plgc.tiles[i], font.plgc.tile_width, font.plgc.tile_height, font.plgc.depth);
                }
                else if (font.plgc.rotateMode >> 1 == 2)
                {
                    font.plgc.tiles[i] = Rotate180(font.plgc.tiles[i], font.plgc.tile_width, font.plgc.tile_height, font.plgc.depth);
                }
            }

            if (font.plgc.rotateMode >> 1 % 2 != 0)
            {
                byte w = font.plgc.tile_width;
                font.plgc.tile_width  = font.plgc.tile_height;
                font.plgc.tile_height = w;
            }

            // Character Width DH
            br.BaseStream.Position = font.fnif.offset_hdwc - 0x08;
            font.hdwc.type         = br.ReadChars(4);
            font.hdwc.block_size   = br.ReadUInt32();
            font.hdwc.fist_code    = br.ReadUInt16();
            font.hdwc.last_code    = br.ReadUInt16();
            font.hdwc.unknown1     = br.ReadUInt32();

            font.hdwc.info = new List <sNFTR.HDWC.Info>();
            for (int i = 0; i < font.plgc.tiles.Length; i++)
            {
                sNFTR.HDWC.Info info = new sNFTR.HDWC.Info();
                info.pixel_start  = br.ReadSByte();
                info.pixel_width  = br.ReadByte();
                info.pixel_length = br.ReadByte();
                font.hdwc.info.Add(info);
            }

            // Character MAP
            br.BaseStream.Position = font.fnif.offset_pamc - 0x08;
            font.pamc = new List <sNFTR.PAMC>();
            uint nextOffset = 0x00;

            do
            {
                sNFTR.PAMC pamc = new sNFTR.PAMC();
                pamc.type         = br.ReadChars(4);
                pamc.block_size   = br.ReadUInt32();
                pamc.first_char   = br.ReadUInt16();
                pamc.last_char    = br.ReadUInt16();
                pamc.type_section = br.ReadUInt32();
                nextOffset        = br.ReadUInt32();
                pamc.next_section = nextOffset;

                switch (pamc.type_section)
                {
                case 0:
                    sNFTR.PAMC.Type0 type0 = new sNFTR.PAMC.Type0();
                    type0.fist_char_code = br.ReadUInt16();
                    pamc.info            = type0;
                    break;

                case 1:
                    sNFTR.PAMC.Type1 type1 = new sNFTR.PAMC.Type1();
                    type1.char_code = new ushort[pamc.last_char - pamc.first_char + 1];
                    for (int i = 0; i < type1.char_code.Length; i++)
                    {
                        type1.char_code[i] = br.ReadUInt16();
                    }

                    pamc.info = type1;
                    break;

                case 2:
                    sNFTR.PAMC.Type2 type2 = new sNFTR.PAMC.Type2();
                    type2.num_chars = br.ReadUInt16();
                    type2.charInfo  = new sNFTR.PAMC.Type2.CharInfo[type2.num_chars];

                    for (int i = 0; i < type2.num_chars; i++)
                    {
                        type2.charInfo[i].chars_code = br.ReadUInt16();
                        type2.charInfo[i].chars      = br.ReadUInt16();
                    }
                    pamc.info = type2;
                    break;
                }

                font.pamc.Add(pamc);
                br.BaseStream.Position = nextOffset - 0x08;
            } while (nextOffset != 0x00 && (nextOffset - 0x08) < br.BaseStream.Length);

            //WriteInfo(font, lang);
            font.plgc.rotateMode &= 1;

            br.Close();
            return(font);
        }
示例#15
0
文件: NFTR.cs 项目: MetLob/tinke
        private static Bitmap ToImage(sNFTR font, Color[] palette, int charWidth, int charHeight,
                                      int numRows, int numColumns, int zoom)
        {
            int numChars = font.plgc.tiles.Length;
            int width = numColumns * charWidth + BORDER_WIDTH;
            int height = numRows * charHeight + BORDER_WIDTH;

            Bitmap image = new Bitmap(width, height);
            Graphics graphic = Graphics.FromImage(image);

            // Draw chars
            for (int i = 0; i < numRows; i++)
            {
                for (int j = 0; j < numColumns; j++)
                {
                    int index = i * numColumns + j;
                    if (index >= numChars)
                        break;

                    int x = j * charWidth + BORDER_WIDTH;
                    int y = i * charHeight + BORDER_WIDTH;

                    int align = BORDER_WIDTH - (BORDER_WIDTH / 2);
                    graphic.DrawRectangle(BORDER, x - align, y - align, charWidth, charHeight);
                    graphic.DrawImage(Get_Char(font, index, palette, zoom), x, y);
                }
            }

            graphic.Dispose();
            graphic = null;
            return image;
        }
示例#16
0
        public static void Write(sNFTR font, string fileout)
        {
            // Calculate de size of each block
            font.plgc.block_size = (uint)(0x10 + font.plgc.tiles.Length * font.plgc.tile_length);
            if (font.plgc.block_size % 4 != 0)  // Padding
            {
                font.plgc.block_size += (4 - (font.plgc.block_size % 4));
            }

            font.hdwc.block_size = (uint)(0x10 + font.hdwc.info.Count * 3);
            if (font.hdwc.block_size % 4 != 0)  // Padding
            {
                font.hdwc.block_size += (4 - (font.hdwc.block_size % 4));
            }

            uint pacm_totalSize = 0x00;

            for (int i = 0; i < font.pamc.Count; i++)
            {
                pacm_totalSize += font.pamc[i].block_size;
            }
            font.header.file_size = font.header.block_size + font.fnif.block_size + font.plgc.block_size +
                                    font.hdwc.block_size + pacm_totalSize;

            // Calculate the new offset
            font.fnif.offset_plgc = font.header.block_size + font.fnif.block_size + 0x08;
            font.fnif.offset_hdwc = (font.fnif.offset_plgc - 0x08) + font.plgc.block_size + 0x08;
            font.fnif.offset_pamc = (font.fnif.offset_hdwc - 0x08) + font.hdwc.block_size + 0x08;

            BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileout));

            // Write the generic header
            bw.Write(font.header.type);
            bw.Write(font.header.endianess);
            bw.Write(font.header.unknown);
            bw.Write(font.header.file_size);
            bw.Write(font.header.block_size);
            bw.Write(font.header.num_blocks);

            // Write the FINF section
            bw.Write(font.fnif.type);
            bw.Write(font.fnif.block_size);
            bw.Write(font.fnif.unknown1);
            bw.Write(font.fnif.height);
            bw.Write(font.fnif.nullCharIndex);
            bw.Write(font.fnif.unknown4);
            bw.Write(font.fnif.width);
            bw.Write(font.fnif.width_bis);
            bw.Write(font.fnif.encoding);
            bw.Write(font.fnif.offset_plgc);
            bw.Write(font.fnif.offset_hdwc);
            bw.Write(font.fnif.offset_pamc);
            if (font.fnif.block_size == 0x20)
            {
                bw.Write(font.fnif.height_font);
                bw.Write(font.fnif.widht_font);
                bw.Write(font.fnif.bearing_y);
                bw.Write(font.fnif.bearing_x);
            }

            // Padding
            int rem = (int)bw.BaseStream.Position % 4;

            if (rem != 0)
            {
                for (; rem < 4; rem++)
                {
                    bw.Write((byte)0x00);
                }
            }

            // Write the PLGC section
            bw.Write(font.plgc.type);
            bw.Write(font.plgc.block_size);
            bw.Write(font.plgc.tile_width);
            bw.Write(font.plgc.tile_height);
            bw.Write(font.plgc.tile_length);
            bw.Write(font.plgc.unknown);
            bw.Write(font.plgc.depth);
            bw.Write(font.plgc.rotateMode);
            for (int i = 0; i < font.plgc.tiles.Length; i++)
            {
                bw.Write(BitsToBytes(font.plgc.tiles[i]));
            }

            // Padding
            rem = (int)bw.BaseStream.Position % 4;
            if (rem != 0)
            {
                for (; rem < 4; rem++)
                {
                    bw.Write((byte)0x00);
                }
            }

            // Write HDWC section
            bw.Write(font.hdwc.type);
            bw.Write(font.hdwc.block_size);
            bw.Write(font.hdwc.fist_code);
            bw.Write(font.hdwc.last_code);
            bw.Write(font.hdwc.unknown1);
            for (int i = 0; i < font.hdwc.info.Count; i++)
            {
                bw.Write(font.hdwc.info[i].pixel_start);
                bw.Write(font.hdwc.info[i].pixel_width);
                bw.Write(font.hdwc.info[i].pixel_length);
            }

            // Padding
            rem = (int)bw.BaseStream.Position % 4;
            if (rem != 0)
            {
                for (; rem < 4; rem++)
                {
                    bw.Write((byte)0x00);
                }
            }

            // Sorts of CMAPs by type
            sNFTR.PAMC[] cmaps = new sNFTR.PAMC[font.pamc.Count];
            uint[]       types = new uint[font.pamc.Count];
            for (int i = 0; i < cmaps.Length; i++)
            {
                cmaps[i] = font.pamc[i];
                types[i] = font.pamc[i].type_section;
            }

            Array.Sort(types, cmaps);
            font.pamc = new List <sNFTR.PAMC>(cmaps);

            // Write the PAMC section
            for (int i = 0; i < font.pamc.Count; i++)
            {
                long currPos      = bw.BaseStream.Position;
                uint next_section = (uint)(currPos + font.pamc[i].block_size) + 0x08;
                if (i + 1 == font.pamc.Count)
                {
                    next_section = 0;
                }
                bw.Write(font.pamc[i].type);
                bw.Write(font.pamc[i].block_size);
                bw.Write(font.pamc[i].first_char);
                bw.Write(font.pamc[i].last_char);
                bw.Write(font.pamc[i].type_section);
                bw.Write(next_section);

                switch (font.pamc[i].type_section)
                {
                case 0:
                    sNFTR.PAMC.Type0 type0 = (sNFTR.PAMC.Type0)font.pamc[i].info;
                    bw.Write(type0.fist_char_code);
                    bw.Write((ushort)0x00);
                    break;

                case 1:
                    sNFTR.PAMC.Type1 type1 = (sNFTR.PAMC.Type1)font.pamc[i].info;
                    for (int j = 0; j < type1.char_code.Length; j++)
                    {
                        bw.Write(type1.char_code[j]);
                    }
                    if (type1.char_code.Length % 2 > 0)
                    {
                        bw.Write((ushort)0x00);
                    }
                    break;

                case 2:
                    sNFTR.PAMC.Type2 type2 = (sNFTR.PAMC.Type2)font.pamc[i].info;
                    bw.Write(type2.num_chars);
                    for (int j = 0; j < type2.num_chars; j++)
                    {
                        bw.Write(type2.charInfo[j].chars_code);
                        bw.Write(type2.charInfo[j].chars);
                    }
                    bw.Write((ushort)0x00);
                    break;
                }
            }

            bw.Flush();
            bw.Close();
        }
示例#17
0
 private int Sort_Font(sNFTR.PAMC.Type2.CharInfo c1, sNFTR.PAMC.Type2.CharInfo c2)
 {
     if (c1.chars_code < c2.chars_code)
         return -1;
     else if (c1.chars_code > c2.chars_code)
         return 1;
     else
         return 0;
 }
示例#18
0
文件: NFTR.cs 项目: MetLob/tinke
        public static void WriteInfo(sNFTR font, string lang)
        {
            try
            {
                XElement xml = XElement.Load(System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar +
                    "Plugins" + Path.DirectorySeparatorChar + "FontLang.xml");
                xml = xml.Element(lang).Element("NFTR");

                Console.WriteLine(xml.Element("S00").Value);
                Console.WriteLine("<pre>");
                Console.WriteLine(xml.Element("S01").Value, font.header.num_blocks.ToString());

                Console.WriteLine("<b>" + xml.Element("S02").Value + "</b>", new String(font.fnif.type));
                Console.WriteLine(xml.Element("S03").Value, font.fnif.block_size.ToString("x"));
                Console.WriteLine(xml.Element("S04").Value, font.fnif.unknown1.ToString("x"));
                Console.WriteLine(xml.Element("S1E").Value, font.fnif.height.ToString("x"));
                Console.WriteLine("Null char index: " + font.fnif.nullCharIndex.ToString());
                Console.WriteLine(xml.Element("S20").Value, font.fnif.unknown4.ToString("x"));
                Console.WriteLine(xml.Element("S21").Value, font.fnif.width.ToString("x"));
                Console.WriteLine(xml.Element("S22").Value, font.fnif.width_bis.ToString("x"));
                Console.WriteLine(xml.Element("S23").Value, font.fnif.encoding.ToString("x"));
                Console.WriteLine(xml.Element("S06").Value, font.fnif.offset_plgc.ToString("x"));
                Console.WriteLine(xml.Element("S07").Value, font.fnif.offset_hdwc.ToString("x"));
                Console.WriteLine(xml.Element("S08").Value, font.fnif.offset_pamc.ToString("x"));
                if (font.fnif.block_size == 0x20)
                {
                    Console.WriteLine(xml.Element("S24").Value, font.fnif.height_font.ToString("x"));
                    Console.WriteLine(xml.Element("S25").Value, font.fnif.widht_font.ToString("x"));
                    Console.WriteLine(xml.Element("S26").Value, font.fnif.bearing_y.ToString("x"));
                    Console.WriteLine(xml.Element("S09").Value, font.fnif.bearing_x.ToString("x"));
                }

                Console.WriteLine("<b>" + xml.Element("S02").Value + "</b>", new String(font.plgc.type));
                Console.WriteLine(xml.Element("S03").Value, font.plgc.block_size.ToString("x"));
                Console.WriteLine(xml.Element("S0A").Value, font.plgc.tile_width.ToString());
                Console.WriteLine(xml.Element("S0B").Value, font.plgc.tile_height.ToString());
                Console.WriteLine(xml.Element("S0C").Value, font.plgc.tile_length.ToString());
                Console.WriteLine(xml.Element("S0D").Value, font.plgc.unknown.ToString("x"));
                Console.WriteLine(xml.Element("S0E").Value, font.plgc.depth.ToString());
                Console.WriteLine(xml.Element("S0F").Value, font.plgc.rotateMode.ToString());
                //Console.WriteLine(xml.Element("S10").Value, font.plgc.unknown2.ToString());

                Console.WriteLine("<b>" + xml.Element("S02").Value + "</b>", new String(font.hdwc.type));
                Console.WriteLine(xml.Element("S03").Value, font.hdwc.block_size.ToString("x"));
                Console.WriteLine(xml.Element("S11").Value, font.hdwc.fist_code.ToString("x"));
                Console.WriteLine(xml.Element("S12").Value, font.hdwc.last_code.ToString("x"));
                Console.WriteLine(xml.Element("S13").Value, font.hdwc.unknown1.ToString("x"));

                Console.WriteLine("<b>" + xml.Element("S02").Value + "</b>", "PAMC");
                for (int i = 0; i < font.pamc.Count; i++)
                {
                    sNFTR.PAMC pamc = font.pamc[i];
                    Console.WriteLine("<u>" + xml.Element("S02").Value + "</u>", i.ToString());
                    Console.WriteLine("  |__" + xml.Element("S03").Value, pamc.block_size.ToString("x"));
                    Console.WriteLine("  |_" + xml.Element("S14").Value, pamc.first_char.ToString("x"));
                    Console.WriteLine("  |_" + xml.Element("S15").Value, pamc.last_char.ToString("x"));
                    Console.WriteLine("  |_" + xml.Element("S16").Value, pamc.type_section.ToString());

                    switch (pamc.type_section)
                    {
                        case 0:
                            sNFTR.PAMC.Type0 type0 = (sNFTR.PAMC.Type0)pamc.info;
                            Console.WriteLine("    \\_" + xml.Element("S17").Value, 0);
                            Console.WriteLine("    \\_" + xml.Element("S18").Value, type0.fist_char_code.ToString("x"));
                            break;

                        case 1:
                            sNFTR.PAMC.Type1 type1 = (sNFTR.PAMC.Type1)pamc.info;
                            Console.WriteLine("    \\_" + xml.Element("S17").Value, 1);
                            Console.WriteLine("    \\_" + xml.Element("S19").Value, type1.char_code.Length.ToString());
                            for (int j = 0; j < type1.char_code.Length; j++)
                                Console.WriteLine("    |_" + xml.Element("S1A").Value, j.ToString(), type1.char_code[j].ToString("x"),
                                        Encoding.GetEncoding("shift-jis").GetChars(
                                        BitConverter.GetBytes(pamc.first_char + j).Reverse().ToArray()).Reverse().ToArray()[0]);
                            break;

                        case 2:
                            sNFTR.PAMC.Type2 type2 = (sNFTR.PAMC.Type2)pamc.info;
                            Console.WriteLine("    \\_" + xml.Element("S17").Value, 2);
                            Console.WriteLine("    \\_" + xml.Element("S1B").Value, type2.num_chars.ToString());
                            for (int j = 0; j < type2.num_chars; j++)
                            {
                                Console.WriteLine("    |_" + xml.Element("S1C").Value, j.ToString(), type2.charInfo[j].chars_code.ToString("x"));
                                Console.WriteLine("    |_" + xml.Element("S1D").Value, j.ToString(), type2.charInfo[j].chars.ToString());
                            }
                            break;
                    }
                }

                Console.WriteLine("EOF</pre>");
            }
            catch { throw new NotSupportedException("There was an error reading the language file"); }
        }
示例#19
0
文件: NFTR.cs 项目: MetLob/tinke
        public static Bitmap ToImage(sNFTR font, Color[] palette)
        {
            int numChars = font.plgc.tiles.Length;

            // Get the image size
            int numColumns = (numChars < CHARS_PER_LINE) ? numChars : CHARS_PER_LINE;
            int numRows = (int)Math.Ceiling((double)numChars / numColumns);

            int charWidth = font.plgc.tile_width + BORDER_WIDTH;
            int charHeight = font.plgc.tile_height + BORDER_WIDTH;

            return ToImage(font, palette, charWidth, charHeight, numRows, numColumns, 1);
        }
示例#20
0
文件: NFTR.cs 项目: MetLob/tinke
        public static sNFTR Read(sFile cfile, string lang)
        {
            sNFTR font = new sNFTR();
            font.id = cfile.id;
            font.name = cfile.name;
            BinaryReader br = new BinaryReader(File.OpenRead(cfile.path));

            // Read the standard header
            font.header.type = br.ReadChars(4);
            font.header.endianess = br.ReadUInt16();
            font.header.unknown = br.ReadUInt16();
            font.header.file_size = br.ReadUInt32();
            font.header.block_size = br.ReadUInt16();
            font.header.num_blocks = br.ReadUInt16();

            // Font INFo section
            font.fnif.type = br.ReadChars(4);
            font.fnif.block_size = br.ReadUInt32();

            font.fnif.unknown1 = br.ReadByte();
            font.fnif.height = br.ReadByte();
            font.fnif.nullCharIndex = br.ReadUInt16();
            font.fnif.unknown4 = br.ReadByte();
            font.fnif.width = br.ReadByte();
            font.fnif.width_bis = br.ReadByte();
            font.fnif.encoding = br.ReadByte();

            font.fnif.offset_plgc = br.ReadUInt32();
            font.fnif.offset_hdwc = br.ReadUInt32();
            font.fnif.offset_pamc = br.ReadUInt32();

            if (font.fnif.block_size == 0x20)
            {
                font.fnif.height_font = br.ReadByte();
                font.fnif.widht_font = br.ReadByte();
                font.fnif.bearing_y = br.ReadByte();
                font.fnif.bearing_x = br.ReadByte();
            }

            // Character Graphics LP
            br.BaseStream.Position = font.fnif.offset_plgc - 0x08;
            font.plgc.type = br.ReadChars(4);
            font.plgc.block_size = br.ReadUInt32();
            font.plgc.tile_width = br.ReadByte();
            font.plgc.tile_height = br.ReadByte();
            font.plgc.tile_length = br.ReadUInt16();
            font.plgc.unknown = br.ReadUInt16();
            font.plgc.depth = br.ReadByte();
            font.plgc.rotateMode = br.ReadByte();

            font.plgc.tiles = new Byte[(font.plgc.block_size - 0x10) / font.plgc.tile_length][];
            for (int i = 0; i < font.plgc.tiles.Length; i++)
            {
                font.plgc.tiles[i] = BytesToBits(br.ReadBytes(font.plgc.tile_length));
                if (font.plgc.rotateMode == 2)
                    font.plgc.tiles[i] = Rotate270(font.plgc.tiles[i], font.plgc.tile_width, font.plgc.tile_height, font.plgc.depth);
                else if (font.plgc.rotateMode == 1)
                    font.plgc.tiles[i] = Rotate90(font.plgc.tiles[i], font.plgc.tile_width, font.plgc.tile_height, font.plgc.depth);
                else if (font.plgc.rotateMode == 3)
                    font.plgc.tiles[i] = Rotate180(font.plgc.tiles[i], font.plgc.tile_width, font.plgc.tile_height, font.plgc.depth);

            }

            // Character Width DH
            br.BaseStream.Position = font.fnif.offset_hdwc - 0x08;
            font.hdwc.type = br.ReadChars(4);
            font.hdwc.block_size = br.ReadUInt32();
            font.hdwc.fist_code = br.ReadUInt16();
            font.hdwc.last_code = br.ReadUInt16();
            font.hdwc.unknown1 = br.ReadUInt32();

            font.hdwc.info = new List<sNFTR.HDWC.Info>();
            for (int i = 0; i < font.plgc.tiles.Length; i++)
            {
                sNFTR.HDWC.Info info = new sNFTR.HDWC.Info();
                info.pixel_start = br.ReadByte();
                info.pixel_width = br.ReadByte();
                info.pixel_length = br.ReadByte();
                font.hdwc.info.Add(info);
            }

            // Character MAP
            br.BaseStream.Position = font.fnif.offset_pamc - 0x08;
            font.pamc = new List<sNFTR.PAMC>();
            uint nextOffset = 0x00;
            do
            {
                sNFTR.PAMC pamc = new sNFTR.PAMC();
                pamc.type = br.ReadChars(4);
                pamc.block_size = br.ReadUInt32();
                pamc.first_char = br.ReadUInt16();
                pamc.last_char = br.ReadUInt16();
                pamc.type_section = br.ReadUInt32();
                nextOffset = br.ReadUInt32();
                pamc.next_section = nextOffset;

                switch (pamc.type_section)
                {
                    case 0:
                        sNFTR.PAMC.Type0 type0 = new sNFTR.PAMC.Type0();
                        type0.fist_char_code = br.ReadUInt16();
                        pamc.info = type0;
                        break;
                    case 1:
                        sNFTR.PAMC.Type1 type1 = new sNFTR.PAMC.Type1();
                        type1.char_code = new ushort[(pamc.block_size - 0x14 - 0x02) / 2];
                        for (int i = 0; i < type1.char_code.Length; i++)
                            type1.char_code[i] = br.ReadUInt16();

                        pamc.info = type1;
                        break;
                    case 2:
                        sNFTR.PAMC.Type2 type2 = new sNFTR.PAMC.Type2();
                        type2.num_chars = br.ReadUInt16();
                        type2.charInfo = new sNFTR.PAMC.Type2.CharInfo[type2.num_chars];

                        for (int i = 0; i < type2.num_chars; i++)
                        {
                            type2.charInfo[i].chars_code = br.ReadUInt16();
                            type2.charInfo[i].chars = br.ReadUInt16();
                        }
                        pamc.info = type2;
                        break;
                }

                font.pamc.Add(pamc);
                br.BaseStream.Position = nextOffset - 0x08;
            } while (nextOffset != 0x00 && (nextOffset - 0x08) < br.BaseStream.Length);

            //WriteInfo(font, lang);
            font.plgc.rotateMode = 0;

            br.Close();
            return font;
        }
示例#21
0
文件: NFTR.cs 项目: MetLob/tinke
        public static Bitmap Get_Chars(sNFTR font, int maxWidth, Color[] palette, int zoom = 1)
        {
            int numChars = font.plgc.tiles.Length;

            // Get the image size
            int charWidth = font.plgc.tile_width * zoom + BORDER_WIDTH;
            int charHeight = font.plgc.tile_height * zoom + BORDER_WIDTH;

            int numColumns = maxWidth / (charWidth + BORDER_WIDTH);
            int numRows = (int)Math.Ceiling((double)numChars / numColumns);

            return ToImage(font, palette, charWidth, charHeight, numRows, numColumns, zoom);
        }
示例#22
0
文件: NFTR.cs 项目: chyyran/tinke
        public static void ExportInfo(string fileOut, Dictionary <int, int> charTable, sNFTR font)
        {
            var encoding = Encoding.UTF8;

            switch (font.fnif.encoding)
            {
            case 2:
                encoding = Encoding.GetEncoding(932);     //Shift-JIS
                break;

            case 0:
                encoding = Encoding.UTF8;
                break;

            case 3:
                encoding = Encoding.GetEncoding(1252);
                break;

            case 1:
                encoding = Encoding.Unicode;
                break;
            }

            XDocument doc = new XDocument();

            doc.Declaration = new XDeclaration("1.0", encoding.BodyName, null);

            XElement root = new XElement("CharMap");

            var charCodeTuples = charTable.OrderBy(kvp => kvp.Value).ToList();

            foreach (var kvp in charCodeTuples)
            {
                var c = kvp.Key;

                string ch = "";

                byte[] codes = BitConverter.GetBytes(c).ToArray();
                ch = new String(Encoding.Unicode.GetChars(codes)).Replace("\0", "");

                int tileCode = kvp.Value;
                if (tileCode >= font.hdwc.info.Count)
                {
                    continue;
                }
                sNFTR.HDWC.Info info = font.hdwc.info[tileCode];

                XElement chx = new XElement("CharInfo");
                chx.SetAttributeValue("Char", ch);
                chx.SetAttributeValue("Code", c);
                chx.SetAttributeValue("Index", tileCode.ToString());
                chx.SetAttributeValue("Width", info.pixel_length.ToString());
                root.Add(chx);
            }

            doc.Add(root);
            doc.Save(fileOut);
        }
示例#23
0
        public static void WriteInfo(sNFTR font, string lang)
        {
            try
            {
                XElement xml = XElement.Load(System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar +
                                             "Plugins" + Path.DirectorySeparatorChar + "FontLang.xml");
                xml = xml.Element(lang).Element("NFTR");

                Console.WriteLine(xml.Element("S00").Value);
                Console.WriteLine("<pre>");
                Console.WriteLine(xml.Element("S01").Value, font.header.num_blocks.ToString());


                Console.WriteLine("<b>" + xml.Element("S02").Value + "</b>", new String(font.fnif.type));
                Console.WriteLine(xml.Element("S03").Value, font.fnif.block_size.ToString("x"));
                Console.WriteLine(xml.Element("S04").Value, font.fnif.unknown1.ToString("x"));
                Console.WriteLine(xml.Element("S1E").Value, font.fnif.height.ToString("x"));
                Console.WriteLine("Null char index: " + font.fnif.nullCharIndex.ToString());
                Console.WriteLine(xml.Element("S20").Value, font.fnif.unknown4.ToString("x"));
                Console.WriteLine(xml.Element("S21").Value, font.fnif.width.ToString("x"));
                Console.WriteLine(xml.Element("S22").Value, font.fnif.width_bis.ToString("x"));
                Console.WriteLine(xml.Element("S23").Value, font.fnif.encoding.ToString("x"));
                Console.WriteLine(xml.Element("S06").Value, font.fnif.offset_plgc.ToString("x"));
                Console.WriteLine(xml.Element("S07").Value, font.fnif.offset_hdwc.ToString("x"));
                Console.WriteLine(xml.Element("S08").Value, font.fnif.offset_pamc.ToString("x"));
                if (font.fnif.block_size == 0x20)
                {
                    Console.WriteLine(xml.Element("S24").Value, font.fnif.height_font.ToString("x"));
                    Console.WriteLine(xml.Element("S25").Value, font.fnif.widht_font.ToString("x"));
                    Console.WriteLine(xml.Element("S26").Value, font.fnif.bearing_y.ToString("x"));
                    Console.WriteLine(xml.Element("S09").Value, font.fnif.bearing_x.ToString("x"));
                }


                Console.WriteLine("<b>" + xml.Element("S02").Value + "</b>", new String(font.plgc.type));
                Console.WriteLine(xml.Element("S03").Value, font.plgc.block_size.ToString("x"));
                Console.WriteLine(xml.Element("S0A").Value, font.plgc.tile_width.ToString());
                Console.WriteLine(xml.Element("S0B").Value, font.plgc.tile_height.ToString());
                Console.WriteLine(xml.Element("S0C").Value, font.plgc.tile_length.ToString());
                Console.WriteLine(xml.Element("S0D").Value, font.plgc.unknown.ToString("x"));
                Console.WriteLine(xml.Element("S0E").Value, font.plgc.depth.ToString());
                Console.WriteLine(xml.Element("S0F").Value, font.plgc.rotateMode.ToString());
                //Console.WriteLine(xml.Element("S10").Value, font.plgc.unknown2.ToString());

                Console.WriteLine("<b>" + xml.Element("S02").Value + "</b>", new String(font.hdwc.type));
                Console.WriteLine(xml.Element("S03").Value, font.hdwc.block_size.ToString("x"));
                Console.WriteLine(xml.Element("S11").Value, font.hdwc.fist_code.ToString("x"));
                Console.WriteLine(xml.Element("S12").Value, font.hdwc.last_code.ToString("x"));
                Console.WriteLine(xml.Element("S13").Value, font.hdwc.unknown1.ToString("x"));

                Console.WriteLine("<b>" + xml.Element("S02").Value + "</b>", "PAMC");
                for (int i = 0; i < font.pamc.Count; i++)
                {
                    sNFTR.PAMC pamc = font.pamc[i];
                    Console.WriteLine("<u>" + xml.Element("S02").Value + "</u>", i.ToString());
                    Console.WriteLine("  |__" + xml.Element("S03").Value, pamc.block_size.ToString("x"));
                    Console.WriteLine("  |_" + xml.Element("S14").Value, pamc.first_char.ToString("x"));
                    Console.WriteLine("  |_" + xml.Element("S15").Value, pamc.last_char.ToString("x"));
                    Console.WriteLine("  |_" + xml.Element("S16").Value, pamc.type_section.ToString());

                    switch (pamc.type_section)
                    {
                    case 0:
                        sNFTR.PAMC.Type0 type0 = (sNFTR.PAMC.Type0)pamc.info;
                        Console.WriteLine("    \\_" + xml.Element("S17").Value, 0);
                        Console.WriteLine("    \\_" + xml.Element("S18").Value, type0.fist_char_code.ToString("x"));
                        break;

                    case 1:
                        sNFTR.PAMC.Type1 type1 = (sNFTR.PAMC.Type1)pamc.info;
                        Console.WriteLine("    \\_" + xml.Element("S17").Value, 1);
                        Console.WriteLine("    \\_" + xml.Element("S19").Value, type1.char_code.Length.ToString());
                        for (int j = 0; j < type1.char_code.Length; j++)
                        {
                            Console.WriteLine("    |_" + xml.Element("S1A").Value, j.ToString(), type1.char_code[j].ToString("x"),
                                              Encoding.GetEncoding("shift-jis").GetChars(
                                                  BitConverter.GetBytes(pamc.first_char + j).Reverse().ToArray()).Reverse().ToArray()[0]);
                        }
                        break;

                    case 2:
                        sNFTR.PAMC.Type2 type2 = (sNFTR.PAMC.Type2)pamc.info;
                        Console.WriteLine("    \\_" + xml.Element("S17").Value, 2);
                        Console.WriteLine("    \\_" + xml.Element("S1B").Value, type2.num_chars.ToString());
                        for (int j = 0; j < type2.num_chars; j++)
                        {
                            Console.WriteLine("    |_" + xml.Element("S1C").Value, j.ToString(), type2.charInfo[j].chars_code.ToString("x"));
                            Console.WriteLine("    |_" + xml.Element("S1D").Value, j.ToString(), type2.charInfo[j].chars.ToString());
                        }
                        break;
                    }
                }

                Console.WriteLine("EOF</pre>");
            }
            catch { throw new NotSupportedException("There was an error reading the language file"); }
        }
示例#24
0
文件: NFTR.cs 项目: MetLob/tinke
        public static void Write(sNFTR font, string fileout)
        {
            // Calculate de size of each block
            font.plgc.block_size = (uint)(0x10 + font.plgc.tiles.Length * font.plgc.tile_length);
            if (font.plgc.block_size % 4 != 0)  // Padding
                font.plgc.block_size += (4 - (font.plgc.block_size % 4));

            font.hdwc.block_size = (uint)(0x10 + font.hdwc.info.Count * 3);
            if (font.hdwc.block_size % 4 != 0)  // Padding
                font.hdwc.block_size += (4 - (font.hdwc.block_size % 4));

            uint pacm_totalSize = 0x00;
            for (int i = 0; i < font.pamc.Count; i++)
                pacm_totalSize += font.pamc[i].block_size;
            font.header.file_size = font.header.block_size + font.fnif.block_size + font.plgc.block_size +
                font.hdwc.block_size + pacm_totalSize;

            // Calculate the new offset
            font.fnif.offset_plgc = font.header.block_size + font.fnif.block_size + 0x08;
            font.fnif.offset_hdwc = (font.fnif.offset_plgc - 0x08) + font.plgc.block_size + 0x08;
            font.fnif.offset_pamc = (font.fnif.offset_hdwc - 0x08) + font.hdwc.block_size + 0x08;

            BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileout));

            // Write the generic header
            bw.Write(font.header.type);
            bw.Write(font.header.endianess);
            bw.Write(font.header.unknown);
            bw.Write(font.header.file_size);
            bw.Write(font.header.block_size);
            bw.Write(font.header.num_blocks);

            // Write the FINF section
            bw.Write(font.fnif.type);
            bw.Write(font.fnif.block_size);
            bw.Write(font.fnif.unknown1);
            bw.Write(font.fnif.height);
            bw.Write(font.fnif.nullCharIndex);
            bw.Write(font.fnif.unknown4);
            bw.Write(font.fnif.width);
            bw.Write(font.fnif.width_bis);
            bw.Write(font.fnif.encoding);
            bw.Write(font.fnif.offset_plgc);
            bw.Write(font.fnif.offset_hdwc);
            bw.Write(font.fnif.offset_pamc);
            if (font.fnif.block_size == 0x20)
            {
                bw.Write(font.fnif.height_font);
                bw.Write(font.fnif.widht_font);
                bw.Write(font.fnif.bearing_y);
                bw.Write(font.fnif.bearing_x);
            }

            // Padding
            int rem = (int)bw.BaseStream.Position % 4;
            if (rem != 0)
                for (; rem < 4; rem++)
                    bw.Write((byte)0x00);

            // Write the PLGC section
            bw.Write(font.plgc.type);
            bw.Write(font.plgc.block_size);
            bw.Write(font.plgc.tile_width);
            bw.Write(font.plgc.tile_height);
            bw.Write(font.plgc.tile_length);
            bw.Write(font.plgc.unknown);
            bw.Write(font.plgc.depth);
            bw.Write(font.plgc.rotateMode);
            for (int i = 0; i < font.plgc.tiles.Length; i++)
                bw.Write(BitsToBytes(font.plgc.tiles[i]));

            // Padding
            rem = (int)bw.BaseStream.Position % 4;
            if (rem != 0)
                for (; rem < 4; rem++)
                    bw.Write((byte)0x00);

            // Write HDWC section
            bw.Write(font.hdwc.type);
            bw.Write(font.hdwc.block_size);
            bw.Write(font.hdwc.fist_code);
            bw.Write(font.hdwc.last_code);
            bw.Write(font.hdwc.unknown1);
            for (int i = 0; i < font.hdwc.info.Count; i++)
            {
                bw.Write(font.hdwc.info[i].pixel_start);
                bw.Write(font.hdwc.info[i].pixel_width);
                bw.Write(font.hdwc.info[i].pixel_length);
            }

            // Padding
            rem = (int)bw.BaseStream.Position % 4;
            if (rem != 0)
                for (; rem < 4; rem++)
                    bw.Write((byte)0x00);

            // Write the PAMC section
            for (int i = 0; i < font.pamc.Count; i++)
            {
                long currPos = bw.BaseStream.Position;
                uint next_section = (uint)(currPos + font.pamc[i].block_size) + 0x08;
                if (i + 1 == font.pamc.Count)
                    next_section = 0;
                bw.Write(font.pamc[i].type);
                bw.Write(font.pamc[i].block_size);
                bw.Write(font.pamc[i].first_char);
                bw.Write(font.pamc[i].last_char);
                bw.Write(font.pamc[i].type_section);
                bw.Write(next_section);

                switch (font.pamc[i].type_section)
                {
                    case 0:
                        sNFTR.PAMC.Type0 type0 = (sNFTR.PAMC.Type0)font.pamc[i].info;
                        bw.Write(type0.fist_char_code);
                        break;
                    case 1:
                        sNFTR.PAMC.Type1 type1 = (sNFTR.PAMC.Type1)font.pamc[i].info;
                        for (int j = 0; j < type1.char_code.Length; j++)
                            bw.Write(type1.char_code[j]);
                        break;
                    case 2:
                        sNFTR.PAMC.Type2 type2 = (sNFTR.PAMC.Type2)font.pamc[i].info;
                        bw.Write(type2.num_chars);
                        for (int j = 0; j < type2.num_chars; j++)
                        {
                            bw.Write(type2.charInfo[j].chars_code);
                            bw.Write(type2.charInfo[j].chars);
                        }
                        break;
                }
                bw.Write((ushort)0x00);
            }

            bw.Flush();
            bw.Close();
        }
示例#25
0
文件: NFTR.cs 项目: MetLob/tinke
        public static void FromImage(Bitmap image, sNFTR font, Color[] palette)
        {
            int numChars = font.plgc.tiles.Length;

            // Get the image size
            int numColumns = (numChars < CHARS_PER_LINE) ? numChars : CHARS_PER_LINE;
            int numRows = (int)Math.Ceiling((double)numChars / numColumns);

            int charWidth = font.plgc.tile_width + BORDER_WIDTH;
            int charHeight = font.plgc.tile_height + BORDER_WIDTH;

            int width = numColumns * charWidth + BORDER_WIDTH;
            int height = numRows * charHeight + BORDER_WIDTH;

            if (width != image.Width || height != image.Height)
            {
                System.Windows.Forms.MessageBox.Show("Incorrect size.");
                return;
            }

            // Draw chars
            for (int i = 0; i < numRows; i++)
            {
                for (int j = 0; j < numColumns; j++)
                {
                    int index = i * numColumns + j;
                    if (index >= numChars)
                        break;

                    int x = j * charWidth + BORDER_WIDTH;
                    int y = i * charHeight + BORDER_WIDTH;

                    Bitmap charImg = image.Clone(new Rectangle(x, y, charWidth - BORDER_WIDTH, charHeight - BORDER_WIDTH),
                        System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                    font.plgc.tiles[index] = SetChar(charImg, font.plgc.depth, palette);
                }
            }
        }