コード例 #1
0
        public SimpleFontAtlas LoadFontInfo(System.IO.Stream dataStream)
        {
            FontAtlasFile atlasFile = new FontAtlasFile();

            //read font atlas from stream data
            atlasFile.Read(dataStream);
            return(atlasFile.Result);
        }
コード例 #2
0
        public SimpleFontAtlas LoadFontInfo(string filename)
        {
            FontAtlasFile atlasFile = new FontAtlasFile();

            using (System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Open))
            {
                //read font atlas from stream data
                return(LoadFontInfo(fs));
            }
        }
コード例 #3
0
ファイル: FormMsdfTest2.cs プロジェクト: zwcloud/Typography
        private void button1_Click_1(object sender, EventArgs e)
        {
            PixelFarm.CpuBlit.MemBitmapExtensions.DefaultMemBitmapIO = new PixelFarm.Drawing.WinGdi.GdiBitmapIO();


            var storageProvider = new LocalFileStorageProvider("", true);

            PixelFarm.Platforms.StorageService.RegisterProvider(storageProvider);


            var bmpFontMx = new BitmapFontManager <MemBitmap>(
                _textServices,
                atlas =>
            {
                GlyphImage totalGlyphImg = atlas.TotalGlyph;
                return(MemBitmap.CreateFromCopy(totalGlyphImg.Width, totalGlyphImg.Height, totalGlyphImg.GetImageBuffer()));
            }
                );

            string multiSizeFontAtlasFilename = "tahoma_set1.multisize_fontAtlas";
            string totalImgAtlasFilename      = "tahoma_set1.multisize_fontAtlas.png";
            //in this version, mutlsize font texture must use the same typeface
            {
                MultiSizeFontAtlasBuilder multiSizeFontAtlasBuilder = new MultiSizeFontAtlasBuilder();
                {
                    bmpFontMx.TextureKindForNewFont = PixelFarm.Drawing.BitmapAtlas.TextureKind.StencilLcdEffect;
                    AddExistingOrCreateNewSimpleFontAtlas(multiSizeFontAtlasBuilder, new RequestFont("tahoma", 10), bmpFontMx);
                    AddExistingOrCreateNewSimpleFontAtlas(multiSizeFontAtlasBuilder, new RequestFont("tahoma", 11), bmpFontMx);
                    AddExistingOrCreateNewSimpleFontAtlas(multiSizeFontAtlasBuilder, new RequestFont("tahoma", 12), bmpFontMx);
                    AddExistingOrCreateNewSimpleFontAtlas(multiSizeFontAtlasBuilder, new RequestFont("tahoma", 13), bmpFontMx);
                    AddExistingOrCreateNewSimpleFontAtlas(multiSizeFontAtlasBuilder, new RequestFont("tahoma", 14), bmpFontMx);

                    bmpFontMx.TextureKindForNewFont = PixelFarm.Drawing.BitmapAtlas.TextureKind.Msdf;
                    AddExistingOrCreateNewSimpleFontAtlas(multiSizeFontAtlasBuilder, new RequestFont("tahoma", 24), bmpFontMx);
                }

                //-------
                multiSizeFontAtlasBuilder.BuildMultiFontSize(multiSizeFontAtlasFilename, totalImgAtlasFilename);
            }
            {
                //test load the font altas back
                FontAtlasFile atlasFile = new FontAtlasFile();
                using (FileStream fs = new FileStream(multiSizeFontAtlasFilename, FileMode.Open))
                {
                    atlasFile.Read(fs);
                }
            }
        }
コード例 #4
0
        public void LoadFontAtlas(string fontTextureInfoFile, string atlasImgFilename)
        {
            //TODO: extension method
            if (PixelFarm.Platforms.StorageService.Provider.DataExists(fontTextureInfoFile) &&
                PixelFarm.Platforms.StorageService.Provider.DataExists(atlasImgFilename))
            {
                using (System.IO.Stream fontTextureInfoStream = PixelFarm.Platforms.StorageService.Provider.ReadDataStream(fontTextureInfoFile))
                    using (System.IO.Stream fontTextureImgStream = PixelFarm.Platforms.StorageService.Provider.ReadDataStream(fontTextureInfoFile))
                    {
                        try
                        {
                            FontAtlasFile fontAtlas = new FontAtlasFile();
                            fontAtlas.Read(fontTextureInfoStream);
                            SimpleFontAtlas[] resultAtlases = fontAtlas.ResultSimpleFontAtlasList.ToArray();
                            _myGLBitmapFontMx.AddSimpleFontAtlas(resultAtlases, fontTextureImgStream);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
            }


            //if (System.IO.File.Exists(fontTextureInfoFile))
            //{
            //    using (System.IO.Stream dataStream = new System.IO.FileStream(fontTextureInfoFile, System.IO.FileMode.Open))
            //    {
            //        try
            //        {
            //            FontAtlasFile fontAtlas = new FontAtlasFile();
            //            fontAtlas.Read(dataStream);
            //            SimpleFontAtlas[] resultAtlases = fontAtlas.ResultSimpleFontAtlasList.ToArray();
            //            _myGLBitmapFontMx.AddSimpleFontAtlas(resultAtlases, atlasImgFilename);
            //        }
            //        catch (Exception ex)
            //        {
            //            throw ex;
            //        }
            //    }
            //}
            //else
            //{

            //}
        }
コード例 #5
0
        public void SaveFontInfo(System.IO.Stream outputStream)
        {
            if (_latestGenGlyphImage == null)
            {
                BuildSingleImage();
            }

            FontAtlasFile fontAtlasFile = new FontAtlasFile();

            fontAtlasFile.StartWrite(outputStream);
            fontAtlasFile.WriteOverviewFontInfo(FontFilename, FontSizeInPoints);

            fontAtlasFile.WriteTotalImageInfo(
                (ushort)_latestGenGlyphImage.Width,
                (ushort)_latestGenGlyphImage.Height, 4,
                this.TextureKind);
            //
            //
            fontAtlasFile.WriteGlyphList(_glyphs);
            fontAtlasFile.EndWrite();
        }