void writeFonts(string datadir)
        {
            FileStream fs = new FileStream(datadir+"fonts.dat", FileMode.Create);
            ZipOutputStream masterz = new ZipOutputStream(fs);
            masterz.UseZip64 = UseZip64.Off;
            for (int font = 1; font <= mData.Settings.Fonts.Count; ++font){
                Fonts fnts = new Fonts(mData);
                Bitmap[] images;
                Bitmap[] alphaimages;
                Vec2i dims;
                Vec2i numchars;
                int[] widths = fnts.createBitmapFont(font, out images, out alphaimages, out dims, out numchars);

                string fontname = String.Format("font.00{0}", font);
                ZipEntry mze = new ZipEntry(fontname);
                masterz.PutNextEntry(mze);
                ZipOutputStream zos = new ZipOutputStream(masterz);
                zos.UseZip64 = UseZip64.Off;
                for (int i = 0; i < images.Length; ++i)
                {
                    string imagename = String.Format("font{0}.bm{1}", font, i+1);
                    ZipEntry ze = new ZipEntry(imagename);
                    zos.PutNextEntry(ze);
                    MemoryStream ms = new MemoryStream();
                    images[i].Save(ms, ImageFormat.Bmp);
                    zos.Write(ms.GetBuffer(), 0, (int)ms.Length);
                    imagename = String.Format("font{0}.al{1}", font, i + 1);
                    zos.CloseEntry();
                    ze = new ZipEntry(imagename);
                    zos.PutNextEntry(ze);
                    ms = new MemoryStream();
                    alphaimages[i].Save(ms, ImageFormat.Bmp);
                    zos.Write(ms.GetBuffer(), 0, (int)ms.Length);
                    zos.CloseEntry();
                }
                string dataname = String.Format("fontdata.{0:D3}", font);
                ZipEntry zippe = new ZipEntry(dataname);
                zos.PutNextEntry(zippe);

                StreamWriter swr = new StreamWriter(zos, Encoding.GetEncoding(1252));
                swr.WriteLine(images.Length);
                swr.WriteLine(dims.x);
                swr.WriteLine(dims.y);
                swr.WriteLine(numchars.x);
                swr.WriteLine(numchars.y);
                foreach (int width in widths)
                {
                    swr.WriteLine(width);
                }
                swr.Flush();
                zos.CloseEntry();
                zos.Finish();

                masterz.CloseEntry();
            }
            masterz.Finish();
            fs.Close();
            //write system font
            System.Reflection.Assembly assy = System.Reflection.Assembly.GetExecutingAssembly();
            Stream fontstr = assy.GetManifestResourceStream("StoryDesigner.Resources.font.dat");
            int length = (int)fontstr.Length;
            byte[] fontdat = new byte[length];
            fontstr.Read(fontdat, 0, length);
            fontstr.Close();
            FileStream fontout = new FileStream(datadir + "font.dat", FileMode.Create);
            fontout.Write(fontdat, 0, length);
            fontout.Close();
        }
예제 #2
0
        void writeFonts(string datadir)
        {
            FileStream      fs      = new FileStream(datadir + "fonts.dat", FileMode.Create);
            ZipOutputStream masterz = new ZipOutputStream(fs);

            masterz.UseZip64 = UseZip64.Off;
            for (int font = 1; font <= mData.Settings.Fonts.Count; ++font)
            {
                Fonts    fnts = new Fonts(mData);
                Bitmap[] images;
                Bitmap[] alphaimages;
                Vec2i    dims;
                Vec2i    numchars;
                int[]    widths = fnts.createBitmapFont(font, out images, out alphaimages, out dims, out numchars);

                string   fontname = String.Format("font.00{0}", font);
                ZipEntry mze      = new ZipEntry(fontname);
                masterz.PutNextEntry(mze);
                ZipOutputStream zos = new ZipOutputStream(masterz);
                zos.UseZip64 = UseZip64.Off;
                for (int i = 0; i < images.Length; ++i)
                {
                    string   imagename = String.Format("font{0}.bm{1}", font, i + 1);
                    ZipEntry ze        = new ZipEntry(imagename);
                    zos.PutNextEntry(ze);
                    MemoryStream ms = new MemoryStream();
                    images[i].Save(ms, ImageFormat.Bmp);
                    zos.Write(ms.GetBuffer(), 0, (int)ms.Length);
                    imagename = String.Format("font{0}.al{1}", font, i + 1);
                    zos.CloseEntry();
                    ze = new ZipEntry(imagename);
                    zos.PutNextEntry(ze);
                    ms = new MemoryStream();
                    alphaimages[i].Save(ms, ImageFormat.Bmp);
                    zos.Write(ms.GetBuffer(), 0, (int)ms.Length);
                    zos.CloseEntry();
                }
                string   dataname = String.Format("fontdata.{0:D3}", font);
                ZipEntry zippe    = new ZipEntry(dataname);
                zos.PutNextEntry(zippe);

                StreamWriter swr = new StreamWriter(zos, Encoding.GetEncoding(1252));
                swr.WriteLine(images.Length);
                swr.WriteLine(dims.x);
                swr.WriteLine(dims.y);
                swr.WriteLine(numchars.x);
                swr.WriteLine(numchars.y);
                foreach (int width in widths)
                {
                    swr.WriteLine(width);
                }
                swr.Flush();
                zos.CloseEntry();
                zos.Finish();

                masterz.CloseEntry();
            }
            masterz.Finish();
            fs.Close();
            //write system font
            System.Reflection.Assembly assy = System.Reflection.Assembly.GetExecutingAssembly();
            Stream fontstr = assy.GetManifestResourceStream("StoryDesigner.Resources.font.dat");
            int    length  = (int)fontstr.Length;

            byte[] fontdat = new byte[length];
            fontstr.Read(fontdat, 0, length);
            fontstr.Close();
            FileStream fontout = new FileStream(datadir + "font.dat", FileMode.Create);

            fontout.Write(fontdat, 0, length);
            fontout.Close();
        }