public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            IList <TextBaseElement> array = values[0] as IList <TextBaseElement>;
            CharList charlist             = (CharList)values[1];

            return(array.GetString(charlist, true));
        }
        private void OpenFont_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog OFD = new OpenFileDialog
            {
                Filter      = "Persona Font (*.FNT) | *.FNT",
                Multiselect = false
            };

            if (OFD.ShowDialog() == true)
            {
                CharList current = (sender as MenuItem).DataContext as CharList;

                string Font = OFD.FileName;

                if (MessageBox.Show("Replace current " + current.Tag + " font?", "Raplace font?", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.Yes)
                {
                    File.Copy(Font, Path.Combine(Static.Paths.CurrentFolderEXE, "FONT_" + current.Tag.ToUpper() + ".FNT"), true);
                    string FontMap = Path.Combine(Path.GetDirectoryName(Font), Path.GetFileNameWithoutExtension(Font) + ".TXT");
                    if (File.Exists(FontMap))
                    {
                        if (MessageBox.Show("Detected font's map: " + Path.GetFileName(FontMap) + "\nReplace current " + current.Tag + " font's map?", "Replace font's map?", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.Yes)
                        {
                            File.Copy(FontMap, Path.Combine(Static.Paths.CurrentFolderEXE, "FONT_" + current.Tag.ToUpper() + ".TXT"), true);
                        }
                    }
                    Font    = Path.Combine(Static.Paths.CurrentFolderEXE, "FONT_" + current.Tag.ToUpper() + ".FNT");
                    FontMap = Path.Combine(Static.Paths.CurrentFolderEXE, "FONT_" + current.Tag.ToUpper() + ".TXT");
                    current.OpenFont(Font);
                    current.OpenFontMap(FontMap);
                }
            }
        }
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            byte[]   array    = (byte[])values[0];
            CharList charlist = (CharList)values[1];

            return(array.GetTextBaseList().GetString(charlist, true));
        }
Exemplo n.º 4
0
        public Visual(CharList CharLST, BackgroundImage background)
        {
            this.CharLST = CharLST;

            TextColor   = background.ColorText;
            TextStart   = background.TextStart;
            NameColor   = background.ColorName;
            NameStart   = background.NameStart;
            GlyphScale  = background.GlyphScale;
            LineSpacing = background.LineSpacing;
        }
Exemplo n.º 5
0
 public CharSet(object cl)
 {
     chlt = cl as CharList;
     InitializeComponent();
     DataContext = CharList;
     foreach (var C in chlt.List)
     {
         CharList.Add(new FnMpImg
         {
             Index = C.Index,
             Image = BitmapSource.Create(chlt.Width, chlt.Height, 96, 96, PixelFormats.Indexed4, chlt.Palette, C.Image_data, 16),
             Char  = C.Char
         });
     }
 }
Exemplo n.º 6
0
        private void ComboBox_Font_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBoxList CBL = (ComboBoxList)e.AddedItems[0];

            if (CBL.Name == "OldFont")
            {
                CharList = Static.FontMap.old_char;
            }
            else if (CBL.Name == "NewFont")
            {
                CharList = Static.FontMap.new_char;
            }

            TextBox_TextChanged(TextBoxText, null);
            TextBox_NameChanged(TextBoxName, null);
        }
Exemplo n.º 7
0
        public void Open(CharList CharList)
        {
            CL = CharList;

            foreach (var a in CharList.List)
            {
                CurrentCL.Add(new CharList.FnMpImg()
                {
                    Index = a.Index,
                    Char  = a.Char,
                    Image = BitmapSource.Create(CharList.Width, CharList.Height, 96, 96, CharList.PixelFormat, CharList.Palette,
                                                a.Image_data, (CharList.PixelFormat.BitsPerPixel * CharList.Width + 7) / 8)
                });
            }

            CurrentCL.ListChanged += CurrentCL_ListChanged;
        }
Exemplo n.º 8
0
 private void Window_Closing(object sender, EventArgs e)
 {
     if (ListChanged)
     {
         if (MessageBox.Show("Font's map will be changed.\nSave?", "Font's map changed", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.Yes)
         {
             foreach (var a in CurrentCL)
             {
                 var elem = CL.List.Find(x => x.Index == a.Index);
                 if (elem != null)
                 {
                     elem.Char = a.Char;
                 }
             }
             CL.SaveFontMap(Path.Combine(Static.Paths.CurrentFolderEXE, "FONT_" + CL.Tag.ToUpper() + ".TXT"));
         }
     }
     CL = null;
     CurrentCL.Clear();
 }
Exemplo n.º 9
0
        public static void WriteFNMP(this CharList list, string filename)
        {
            try
            {
                StreamWriter sw = new StreamWriter(new FileStream(filename, FileMode.Create));

                foreach (var CL in list.List)
                {
                    if (CL.Char != "")
                    {
                        string str = Convert.ToString(CL.Index) + "=" + Convert.ToString(CL.Char);
                        sw.WriteLine(str);
                        sw.Flush();
                    }
                }

                sw.Dispose();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Exemplo n.º 10
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.º 11
0
        public static BitmapSource DrawText(this IList <MyByteArray> text, CharList CharList, Color Color)
        {
            BitmapPalette ColorPaletteBMP = Util.CreatePallete(Color);
            ImageData     returned        = null;
            ImageData     line            = null;

            foreach (var a in text)
            {
                if (a.Type == arrayType.System)
                {
                    if (Util.ByteArrayCompareWithSimplest(a.Bytes, new byte[] { 0x0A }))
                    {
                        if (returned == null)
                        {
                            if (line == null)
                            {
                                returned = new ImageData(PixelFormats.Indexed4, 32);
                            }
                            else
                            {
                                returned = line;
                                line     = null;
                            }
                        }
                        else
                        {
                            if (line == null)
                            {
                                returned = ImageData.MergeUpDown(returned, new ImageData(PixelFormats.Indexed4, 32));
                            }
                            else
                            {
                                returned = ImageData.MergeUpDown(returned, line);
                                line     = null;
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < a.Bytes.Length; i++)
                    {
                        FnMpData fnmp;
                        if (0x20 <= a.Bytes[i] & a.Bytes[i] < 0x80)
                        {
                            fnmp = CharList.List.FirstOrDefault(x => x.Index == a.Bytes[i]);
                        }
                        else if (0x80 <= a.Bytes[i] & a.Bytes[i] < 0xF0)
                        {
                            int newindex = (a.Bytes[i] - 0x81) * 0x80 + a.Bytes[i + 1] + 0x20;

                            i++;
                            fnmp = CharList.List.FirstOrDefault(x => x.Index == newindex);
                        }
                        else
                        {
                            Console.WriteLine("ASD");
                            fnmp = null;
                        }

                        if (fnmp != null)
                        {
                            glyphYshift temp  = Static.FontMap.char_shift.Find(x => x.Index == fnmp.Index);
                            ImageData   glyph = new ImageData(fnmp.Image_data, PixelFormats.Indexed4, 32, 32);
                            glyph = temp == null?ImageData.Crop(glyph, fnmp.Cut.Left, fnmp.Cut.Right - 1) : ImageData.Shift(ImageData.Crop(glyph, fnmp.Cut.Left, fnmp.Cut.Right - 1), temp.Shift);

                            line = ImageData.MergeLeftRight(line, glyph);
                        }
                    }
                }
            }
            returned = ImageData.MergeUpDown(returned, line);
            return(returned == null ? null : BitmapSource.Create(returned.PixelWidth, returned.PixelHeight, 96, 96, returned.PixelFormat, ColorPaletteBMP, returned.Data, returned.Stride));
        }
Exemplo n.º 12
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());
            }
        }