Exemplo n.º 1
0
        internal override CCFontAtlas CreateFontAtlas()
        {
            var atlas = new CCFontAtlas(this);

            // Try to load the texture
            CCTexture2D atlasTexture = null;

            float loadedSize = fontSize;

            SpriteFont font = CCSpriteFontCache.SharedInstance.TryLoadFont(fontName, fontSize, out loadedSize);

            if (font == null)
            {
                atlasTexture = new CCTexture2D();
            }
            else
            {
                atlasTexture = new CCTexture2D(font.Texture);
            }

            // add the texture (only one for now)
            atlas.AddTexture(atlasTexture, 0);

            // Set the atlas's common height
            atlas.CommonHeight = font.LineSpacing;
            // Set the default character to us if a character does not exist in the font
            atlas.DefaultCharacter = font.DefaultCharacter;

            var glyphs     = font.GetGlyphs();
            var reusedRect = Rectangle.Empty;

            foreach (var character in font.Characters)
            {
                var glyphDefintion = new CCFontLetterDefinition();

                glyphDefintion.LetterChar = character;

                var glyphDef = glyphs[character];

                glyphDefintion.XOffset = glyphDef.LeftSideBearing + glyphDef.Cropping.X;

                glyphDefintion.YOffset = glyphDef.Cropping.Y;

                reusedRect             = glyphDef.BoundsInTexture;
                glyphDefintion.Subrect = new CCRect(reusedRect.X, reusedRect.Y, reusedRect.Width, reusedRect.Height);

                reusedRect = glyphDef.Cropping;
                glyphDefintion.Cropping = new CCRect(reusedRect.X, reusedRect.Y, reusedRect.Width, reusedRect.Height);

                glyphDefintion.TextureID = 0;

                glyphDefintion.IsValidDefinition = true;
                glyphDefintion.XAdvance          = (int)(font.Spacing + glyphDef.Width + glyphDef.RightSideBearing);//(int)glyphDef.WidthIncludingBearings;

                atlas.AddLetterDefinition(glyphDefintion);
            }

            return(atlas);
        }
Exemplo n.º 2
0
        internal override CCFontAtlas CreateFontAtlas()
        {
            var atlas = new CCFontAtlas(this);

            // Check if any Bitmap Font configurations are loaded at all.
            if (Configuration.Glyphs.Count == 0)
            {
                return(null);
            }

            if (Configuration.CommonHeight == 0)
            {
                return(null);
            }


            // Set the atlas's common height
            atlas.CommonHeight = Configuration.CommonHeight;

            foreach (var glyph in Configuration.Glyphs)
            {
                var glyphDefintion = new CCFontLetterDefinition();

                glyphDefintion.LetterChar = (char)glyph.Key;

                var glyphDef = glyph.Value;

                glyphDefintion.XOffset = glyphDef.XOffset;
                glyphDefintion.YOffset = glyphDef.YOffset;

                glyphDefintion.Subrect = glyphDef.Subrect;

                glyphDefintion.TextureID = 0;

                glyphDefintion.IsValidDefinition = true;
                glyphDefintion.XAdvance          = glyphDef.XAdvance;

                atlas.AddLetterDefinition(glyphDefintion);
            }

            // Try to load the texture
            CCTexture2D atlasTexture = null;

            try
            {
                atlasTexture = CCTextureCache.SharedTextureCache.AddImage(Configuration.AtlasName);
            }
            catch (Exception)
            {
                // Try the 'images' ref location just in case.
                try
                {
                    atlasTexture =
                        CCTextureCache.SharedTextureCache.AddImage(System.IO.Path.Combine("images",
                                                                                          Configuration.AtlasName));
                }
                catch (Exception)
                {
                    // Lastly, try <font_path>/images/<font_name>
                    string dir     = System.IO.Path.GetDirectoryName(Configuration.AtlasName);
                    string fname   = System.IO.Path.GetFileName(Configuration.AtlasName);
                    string newName = System.IO.Path.Combine(System.IO.Path.Combine(dir, "images"), fname);
                    atlasTexture = CCTextureCache.SharedTextureCache.AddImage(newName);
                }
            }

            if (atlasTexture == null)
            {
                atlasTexture = new CCTexture2D();
            }

            // add the texture (only one for now)
            atlas.AddTexture(atlasTexture, 0);

            return(atlas);
        }
Exemplo n.º 3
0
        internal override CCFontAtlas CreateFontAtlas()
        {
            var atlas = new CCFontAtlas(this);

            // Check if any Bitmap Font configurations are loaded at all.
            if (Configuration.Glyphs.Count == 0)
                return null;

            if (Configuration.CommonHeight == 0)
                return null;


            // Set the atlas's common height
            atlas.CommonHeight = Configuration.CommonHeight;

            foreach (var glyph in Configuration.Glyphs)
            {
                var glyphDefintion = new CCFontLetterDefinition();

                glyphDefintion.LetterChar = (char)glyph.Key;

                var glyphDef = glyph.Value;

                glyphDefintion.XOffset = glyphDef.XOffset;
                glyphDefintion.YOffset = glyphDef.YOffset;

                glyphDefintion.Subrect = glyphDef.Subrect;

                glyphDefintion.TextureID = 0;

                glyphDefintion.IsValidDefinition = true;
                glyphDefintion.XAdvance = glyphDef.XAdvance;

                atlas.AddLetterDefinition(glyphDefintion);
            }

            // Try to load the texture
            CCTexture2D atlasTexture = null;

            try
            {
                atlasTexture = CCTextureCache.SharedTextureCache.AddImage(Configuration.AtlasName);
            }
            catch (Exception)
            {
                // Try the 'images' ref location just in case.
                try
                {
                    atlasTexture =
                        CCTextureCache.SharedTextureCache.AddImage(System.IO.Path.Combine("images",
                            Configuration.AtlasName));
                }
                catch (Exception)
                {
                    // Lastly, try <font_path>/images/<font_name>
                    string dir = System.IO.Path.GetDirectoryName(Configuration.AtlasName);
                    string fname = System.IO.Path.GetFileName(Configuration.AtlasName);
                    string newName = System.IO.Path.Combine(System.IO.Path.Combine(dir, "images"), fname);
                    atlasTexture = CCTextureCache.SharedTextureCache.AddImage(newName);
                }
            }

            if (atlasTexture == null)
                atlasTexture = new CCTexture2D();

            // add the texture (only one for now)
            atlas.AddTexture(atlasTexture, 0);

            return atlas;
        }
Exemplo n.º 4
0
        internal override CCFontAtlas CreateFontAtlas()
        {
            float loadedSize = fontSize;
            SpriteFont font = CCSpriteFontCache.SharedInstance.TryLoadFont(fontName, fontSize, out loadedSize);
            if (font == null)
            {
                return null;
            }
#if XNA
            CCTexture2D atlasTexture = new CCTexture2D();
#else
            CCTexture2D atlasTexture = new CCTexture2D(font.Texture);
#endif

            if (loadedSize != 0)
            {
                fontScale = fontSize / loadedSize * CCSpriteFontCache.FontScale;
            }

            var atlas = new CCFontAtlas(this);
            // add the texture (only one for now)
            atlas.AddTexture(atlasTexture, 0);

            // Set the atlas's common height
            atlas.CommonHeight = font.LineSpacing;
            // Set the default character to us if a character does not exist in the font
            atlas.DefaultCharacter = font.DefaultCharacter;

#if !XNA
            
            var glyphs = font.GetGlyphs();
            var reusedRect = Rectangle.Empty;

            foreach ( var character in font.Characters)
            {
                var glyphDefintion = new CCFontLetterDefinition();

                glyphDefintion.LetterChar = character;

                var glyphDef = glyphs[character];

                glyphDefintion.XOffset = glyphDef.LeftSideBearing + glyphDef.Cropping.X;

                glyphDefintion.YOffset = glyphDef.Cropping.Y;

                reusedRect = glyphDef.BoundsInTexture;
                glyphDefintion.Subrect = new CCRect(reusedRect.X, reusedRect.Y, reusedRect.Width, reusedRect.Height);

                reusedRect = glyphDef.Cropping;
                glyphDefintion.Cropping = new CCRect(reusedRect.X, reusedRect.Y, reusedRect.Width, reusedRect.Height);

                glyphDefintion.TextureID = 0;

                glyphDefintion.IsValidDefinition = true;
                //glyphDefintion.XAdvance = (int)(font.Spacing + glyphDef.Width + glyphDef.RightSideBearing);
                glyphDefintion.XAdvance = (int)glyphDef.WidthIncludingBearings;

                atlas.AddLetterDefinition(glyphDefintion);

            }
#endif
            return atlas;
        }