Ejemplo n.º 1
0
        void AddExistingOrCreateNewSimpleFontAtlas(
            MultiSizeFontAtlasBuilder multisizeFontAtlasBuilder,
            RequestFont reqFont,
            BitmapFontManager <MemBitmap> bmpFontMx)
        {
            int fontKey = reqFont.FontKey;

            string fontTextureFile        = reqFont.Name + "_" + fontKey;
            string resolveFontTextureFile = fontTextureFile + ".info";
            string fontTextureInfoFile    = resolveFontTextureFile;
            string fontTextureImgFilename = fontTextureInfoFile + ".png";

            _textServices.ResolveTypeface(reqFont); //resolve for 'actual' font
            if (PixelFarm.Platforms.StorageService.Provider.DataExists(resolveFontTextureFile) &&
                File.Exists(fontTextureImgFilename))
            {
                multisizeFontAtlasBuilder.AddSimpleFontAtlasFile(reqFont,
                                                                 resolveFontTextureFile,
                                                                 fontTextureImgFilename,
                                                                 bmpFontMx.TextureKindForNewFont
                                                                 );
            }
            else
            {
                //create a new one
                PixelFarm.Drawing.Fonts.SimpleFontAtlas fontAtlas = bmpFontMx.GetFontAtlas(reqFont, out MemBitmap fontBmp);
                bmpFontMx.GetFontAtlas(reqFont, out fontBmp);
                multisizeFontAtlasBuilder.AddSimpleFontAtlasFile(reqFont,
                                                                 resolveFontTextureFile,
                                                                 fontTextureImgFilename,
                                                                 bmpFontMx.TextureKindForNewFont);
            }
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }