Exemplo n.º 1
0
        public static string GetChar(this IList <FnMpData> FontMap, int index)
        {
            string returned = "";

            FnMpData fnmp = FontMap.FirstOrDefault(x => x.Index == index);

            if (fnmp == null)
            {
                returned += "<NCHAR>";
            }
            else
            {
                if (fnmp.Char.Length == 0)
                {
                    returned += "<CHAR>";
                }
                else if (fnmp.Char.Length == 1)
                {
                    returned += fnmp.Char;
                }
                else
                {
                    returned += "<" + fnmp.Char + ">";
                }
            }

            return(returned);
        }
Exemplo n.º 2
0
        private void save()
        {
            foreach (var CL in CharList)
            {
                FnMpData CL2 = chlt.List.FirstOrDefault(x => x.Index == CL.Index);
                CL2.Char = CL.Char;
            }

            this.DialogResult = true;
        }
Exemplo n.º 3
0
        public static void GetIndex(this List <byte> ByteList, string Char)
        {
            if (Char != "")
            {
                FnMpData fnmp = Static.FontMap.new_char.List.FirstOrDefault(x => x.Char == Char);;
                if (fnmp != null)
                {
                    if (fnmp.Index < 0x80)
                    {
                        ByteList.Add((byte)fnmp.Index);
                    }
                    else
                    {
                        byte byte2 = Convert.ToByte((fnmp.Index - 0x20) % 0x80);
                        byte byte1 = Convert.ToByte(((fnmp.Index - 0x20 - byte2) / 0x80) + 0x81);

                        ByteList.Add(byte1);
                        ByteList.Add(byte2);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static void ReadFNMP(this CharList list, string filename)
        {
            try
            {
                StreamReader sr = new StreamReader(new FileStream(filename, FileMode.Open));

                while (sr.EndOfStream == false)
                {
                    string str = sr.ReadLine();

                    int    Index = Convert.ToInt32(str.Substring(0, str.IndexOf('=')));
                    string Char  = str.Substring(str.IndexOf('=') + 1);
                    if (Char.Length > 3)
                    {
                        Char = Char.Substring(0, 3);
                    }

                    FnMpData fnmp = list.List.FirstOrDefault(x => x.Index == Index);
                    if (fnmp == null)
                    {
                        list.List.Add(new PersonaText.FnMpData {
                            Index = Index, Char = Char
                        });
                    }
                    else
                    {
                        fnmp.Char = Char;
                    }
                }

                sr.Dispose();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Exemplo n.º 5
0
        public static void ReadFONT(this CharList list, string filename)
        {
            try
            {
                FileStream   FONT    = new FileStream(filename, FileMode.Open, FileAccess.Read);
                MemoryStream FontDec = new MemoryStream();

                int MainHeaderSize = FONT.ReadInt();
                FONT.Position = 0xE;
                int    TotalNumberOfGlyphs = FONT.ReadUshort();
                ushort GlyphSize_1         = FONT.ReadUshort();
                list.Width = GlyphSize_1;
                ushort GlyphSize_2 = FONT.ReadUshort();
                list.Height = GlyphSize_2;
                ushort GlyphSizeInByte = FONT.ReadUshort();
                byte   BitPerPixel     = Convert.ToByte((double)(GlyphSizeInByte * 8) / (GlyphSize_1 * GlyphSize_2));
                int    NumberOfColor   = Convert.ToInt32(Math.Pow(2, BitPerPixel));

                if (BitPerPixel == 4)
                {
                    list.PixelFormat = PixelFormats.Indexed4;
                }
                else if (BitPerPixel == 8)
                {
                    list.PixelFormat = PixelFormats.Indexed8;
                }
                else
                {
                    MessageBox.Show("ReadFONT: Unknown PixelFormat");
                }

                int GlyphCutTable_Pos = MainHeaderSize + NumberOfColor * 4 + 4;
                FONT.Position = GlyphCutTable_Pos - 4;
                int GlyphCutTable_Size = FONT.ReadInt();

                int UnknownPos = GlyphCutTable_Pos + GlyphCutTable_Size + 4;
                FONT.Position = UnknownPos - 4;
                int UnknownSize = FONT.ReadInt();

                int ReservedPos  = UnknownPos + UnknownSize;
                int ReservedSize = TotalNumberOfGlyphs * 4;

                int DictionaryHeader_Pos = ReservedPos + ReservedSize;

                FONT.Position = DictionaryHeader_Pos;
                int DictionaryHeader_Size    = FONT.ReadInt();
                int Dictionary_Size          = FONT.ReadInt();
                int CompressedFontBlock_Size = FONT.ReadInt();
                int Dictionary_Pos           = DictionaryHeader_Pos + DictionaryHeader_Size;

                FONT.Position = DictionaryHeader_Pos + 24;
                int GlyphPositionTable_Size = FONT.ReadInt();

                FONT.Position = Dictionary_Pos;

                int[,] Dictionary = new int[Dictionary_Size / 6, 2];
                for (int i = 0; i < Dictionary_Size / 6; i++)
                {
                    FONT.Position    = FONT.Position + 2;
                    Dictionary[i, 0] = FONT.ReadUshort();
                    Dictionary[i, 1] = FONT.ReadUshort();
                }

                int CompressedFontBlock_Pos = Dictionary_Pos + Dictionary_Size + GlyphPositionTable_Size;

                FONT.Position = CompressedFontBlock_Pos;

                int temp = 0;
                for (int m = 0; m < CompressedFontBlock_Size; m += 2)
                {
                    int s4 = FONT.ReadUshort();
                    for (int i = 0; i < 16; i++)
                    {
                        temp = Dictionary[temp, s4 % 2];
                        s4   = s4 >> 1;

                        if (Dictionary[temp, 0] == 0)
                        {
                            int a = Dictionary[temp, 1];

                            if (BitPerPixel == 4)
                            {
                                a = (a >> 4) + (a - (a >> 4 << 4) << 4);
                            }

                            FontDec.WriteByte((byte)a);
                            temp = 0;
                        }
                    }
                }


                FONT.Position = MainHeaderSize;

                List <Color> ColorBMP = new List <Color>();
                for (int i = 0; i < NumberOfColor; i++)
                {
                    byte r = (byte)FONT.ReadByte();
                    byte g = (byte)FONT.ReadByte();
                    byte b = (byte)FONT.ReadByte();
                    byte a = (byte)FONT.ReadByte();
                    ColorBMP.Add(Color.FromArgb(a, r, g, b));
                }
                list.Palette = new BitmapPalette(ColorBMP);

                FontDec.Position = 0;

                FONT.Position    = GlyphCutTable_Pos;
                byte[,] GlyphCut = new byte[TotalNumberOfGlyphs, 2];
                for (int i = 0; i < TotalNumberOfGlyphs; i++)
                {
                    GlyphCut[i, 0] = (byte)FONT.ReadByte();
                    GlyphCut[i, 1] = (byte)FONT.ReadByte();
                }

                int k = 32;

                double ko   = (double)BitPerPixel / 8;
                int    size = Convert.ToInt32(GlyphSize_1 * GlyphSize_1 * ko);

                try
                {
                    byte[] data = new byte[size];
                    FontDec.Read(data, 0, size);

                    FnMpData fnmp = list.List.FirstOrDefault(x => x.Index == k);
                    if (fnmp == null)
                    {
                        list.List.Add(new FnMpData {
                            Index = k, Char = "", Cut = new MyByte {
                                Left = Convert.ToByte(GlyphCut[0, 0] + 5), Right = Convert.ToByte(GlyphCut[0, 1] - 5)
                            }, Image_data = data
                        });
                    }
                    else
                    {
                        fnmp.Cut = new MyByte {
                            Left = 9, Right = 18
                        };
                        fnmp.Image_data = data;
                    }

                    k++;
                }
                catch
                {
                }

                for (int i = 1; i < TotalNumberOfGlyphs; i++)
                {
                    byte[] data = new byte[size];
                    FontDec.Read(data, 0, size);

                    FnMpData fnmp = list.List.FirstOrDefault(x => x.Index == k);
                    if (fnmp == null)
                    {
                        list.List.Add(new FnMpData {
                            Index = k, Char = "", Cut = new MyByte {
                                Left = GlyphCut[i, 0], Right = GlyphCut[i, 1]
                            }, Image_data = data
                        });
                    }
                    else
                    {
                        fnmp.Cut = new MyByte {
                            Left = GlyphCut[i, 0], Right = GlyphCut[i, 1]
                        };
                        fnmp.Image_data = data;
                    }

                    k++;
                }

                FontDec.Close();
                FONT.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }