Пример #1
0
        internal void WriteGlyphList(Dictionary <ushort, CacheBmp> glyphs)
        {
            _writer.Write((ushort)ObjectKind.GlyphList);
            //total number
            int totalNum = glyphs.Count;

#if DEBUG
            if (totalNum >= ushort.MaxValue)
            {
                throw new NotSupportedException();
            }
#endif

            _writer.Write((ushort)totalNum);
            //
            foreach (CacheBmp g in glyphs.Values)
            {
                //1. code point
                _writer.Write((ushort)g.imgIndex);
                //2. area, left,top,width,height
                _writer.Write((ushort)g.area.Left);
                _writer.Write((ushort)g.area.Top);
                _writer.Write((ushort)g.area.Width);
                _writer.Write((ushort)g.area.Height);


                //3. texture offset
                AtlasItemImage img = g.img;
                _writer.Write((short)img.TextureOffsetX); //short
                _writer.Write((short)img.TextureOffsetY); //short
            }
        }
Пример #2
0
        /// <summary>
        /// add or replace
        /// </summary>
        /// <param name="imgIndex"></param>
        /// <param name="img"></param>
        public void AddAtlasItemImage(ushort imgIndex, AtlasItemImage img)
        {
            var cache = new CacheBmp();

            cache.imgIndex   = imgIndex;
            cache.img        = img;
            _items[imgIndex] = cache;
        }
Пример #3
0
 public MySimpleGLBitmapAtlasManager(TextureKind textureKind)
     : base(textureKind)
 {
     SetLoadNewBmpDel(atlas =>
     {
         //create new one
         AtlasItemImage totalGlyphImg = atlas.TotalImg;
         //load to glbmp
         GLBitmap found   = new GLBitmap(totalGlyphImg.Bitmap, false);
         found.IsYFlipped = false;
         return(found);
     });
 }
Пример #4
0
        /// <summary>
        /// get from cache or create a new one
        /// </summary>
        /// <param name="reqFont"></param>
        /// <returns></returns>
        public SimpleBitmaptAtlas GetBitmapAtlas(string atlasName, out B outputBitmap)
        {
#if DEBUG
            _dbugStopWatch.Reset();
            _dbugStopWatch.Start();
#endif


            if (!_createdAtlases.TryGetValue(atlasName, out SimpleBitmaptAtlas foundAtlas))
            {
                //check from pre-built cache (if availiable)
                string fontTextureInfoFile    = atlasName + ".info";
                string fontTextureImgFilename = atlasName + ".png";
                //check if the file exist

                if (StorageService.Provider.DataExists(fontTextureInfoFile) &&
                    StorageService.Provider.DataExists(fontTextureImgFilename))
                {
                    SimpleBitmapAtlasBuilder atlasBuilder = new SimpleBitmapAtlasBuilder();
                    using (System.IO.Stream dataStream = StorageService.Provider.ReadDataStream(fontTextureInfoFile))
                        using (System.IO.Stream fontImgStream = StorageService.Provider.ReadDataStream(fontTextureImgFilename))
                        {
                            try
                            {
                                foundAtlas = atlasBuilder.LoadAtlasInfo(dataStream);
                                PixelFarm.CpuBlit.MemBitmap memBmp = PixelFarm.CpuBlit.MemBitmap.LoadBitmap(fontImgStream);
                                AtlasItemImage atlasImg            = new AtlasItemImage(memBmp.Width, memBmp.Height); //TODO: review new .ctor
                                atlasImg.SetBitmap(memBmp, false);
                                foundAtlas.TotalImg = atlasImg;
                                _createdAtlases.Add(atlasName, foundAtlas);
                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }
                        }
                }
            }

            outputBitmap = _loadAtlases.GetOrCreateNewOne(foundAtlas);
            return(foundAtlas);
        }