示例#1
0
        public void Load(BMFont font, bool hackForBFG, float hackScaleForBFG = 1.0f)
        {
            Debug.Assert(font.pages.Count == 1);
            BMPage page     = font.pages[0];
            var    bmglyphs = from g in font.glyphs
                              where g.page == 0
                              select g;

            var dict = bmglyphs.ToDictionary(g => g.id, g => g);

            maxHeight = 0;
            maxWidth  = 0;
            maxTop    = 0;
            maxBottom = 0;
            for (int i = 0; i < GLYPHS_PER_FONT; ++i)
            {
                BMGlyph bmglyph = dict.ContainsKey(i) ? dict[i] : bmglyphs.First();

                D3Glyph glyph = new D3Glyph();
                glyph.Load(font, bmglyph, hackForBFG, hackScaleForBFG);
                name = font.faceName;

                if (maxHeight < glyph.height)
                {
                    maxHeight = glyph.height;
                }
                if (maxWidth < glyph.xSkip)
                {
                    maxWidth = glyph.xSkip;
                }
                if (maxTop < glyph.top)
                {
                    maxTop = glyph.top;
                }
                if (maxBottom < glyph.bottom)
                {
                    maxBottom = glyph.bottom;
                }

                glyphs[i] = glyph;
            }

            this.glyphScale = hackScaleForBFG;
        }
示例#2
0
        public void Load(string fileName)
        {
            FileStream   fs = File.OpenRead(fileName);
            BinaryReader br = new BinaryReader(fs);

            name = FriendlyFontFace(fileName);

            maxHeight = 0;
            maxWidth  = 0;
            maxTop    = 0;
            maxBottom = 0;
            for (int i = 0; i < GLYPHS_PER_FONT; i++)
            {
                D3Glyph glyph = new D3Glyph();
                glyph.Load(br);
                glyphs[i] = glyph;

                if (maxHeight < glyph.height)
                {
                    maxHeight = glyph.height;
                }
                if (maxWidth < glyph.xSkip)
                {
                    maxWidth = glyph.xSkip;
                }
                if (maxTop < glyph.top)
                {
                    maxTop = glyph.top;
                }
                if (maxBottom < glyph.bottom)
                {
                    maxBottom = glyph.bottom;
                }
            }

            glyphScale = br.ReadSingle();

            br.Close();
            fs.Close();
        }
示例#3
0
        private IList <string> Decompose()
        {
            var infosDict = new Dictionary <int, IList <string> >();

            for (int i = 0; i < D3Font.GLYPHS_PER_FONT; i++)
            {
                IList <string> infos;
                int            utf32Char = Remap((byte)i, out infos);
                if (iconInfos.ContainsKey(utf32Char))
                {
                    textOut.WriteLine("WARNING: The glyph 0x{0:X2} maps to previously outputted char '{1}' - IGNORING", i, char.ConvertFromUtf32(utf32Char));
                    textOut.WriteLine("    Current output:");
                    foreach (var info in infos)
                    {
                        textOut.WriteLine("        {0}", info);
                    }
                    textOut.WriteLine("    First output:");
                    foreach (var info in infosDict[utf32Char])
                    {
                        textOut.WriteLine("        {0}", info);
                    }
                    continue;
                }
                infosDict[utf32Char] = infos;
                D3Glyph glyph = font.glyphs[i];
                Decompose(glyph, utf32Char);
            }

            IList <string> bmConfig = new List <string>();

            foreach (var kv in iconInfos)
            {
                bmConfig.Add(kv.Value.ToString());
            }
            return(bmConfig);
        }
示例#4
0
        public void Load(BMFont font, bool hackForBFG, float hackScaleForBFG = 1.0f)
        {
            Debug.Assert(font.pages.Count == 1);
            BMPage page = font.pages[0];
            var bmglyphs = from g in font.glyphs
                         where g.page == 0
                         select g;

            var dict = bmglyphs.ToDictionary(g => g.id, g => g);

            maxHeight = 0;
            maxWidth = 0;
            maxTop = 0;
            maxBottom = 0;
            for (int i = 0; i < GLYPHS_PER_FONT; ++i)
            {
                BMGlyph bmglyph = dict.ContainsKey(i) ? dict[i] : bmglyphs.First();

                D3Glyph glyph = new D3Glyph();
                glyph.Load(font, bmglyph, hackForBFG, hackScaleForBFG);
                name = font.faceName;

                if (maxHeight < glyph.height)
                    maxHeight = glyph.height;
                if (maxWidth < glyph.xSkip)
                    maxWidth = glyph.xSkip;
                if (maxTop < glyph.top)
                    maxTop = glyph.top;
                if (maxBottom < glyph.bottom)
                    maxBottom = glyph.bottom;

                glyphs[i] = glyph;
            }

            this.glyphScale = hackScaleForBFG;
        }
示例#5
0
        private void Decompose(D3Glyph glyph, int utf32Char)
        {
            string textureName = Path.Combine(dirWithFontTextures, Path.GetFileName(glyph.textureName));

            if (!textures.ContainsKey(textureName))
            {
                string realName = textureName;
                if (!File.Exists(realName))
                {
                    realName = Path.ChangeExtension(textureName, "dds");
                }
                MagickImage newImage = new MagickImage(realName);
                textures[textureName] = newImage;
            }

            MagickImage image = textures[textureName].Clone();


            BMIconInfo icon = new BMIconInfo();

            icon.imageFile = Path.Combine(imageOutputDir, string.Format("{0}_char{1}.tga", font.name, utf32Char));
            icon.charId    = utf32Char;

            // baseline position in pixels from top edges of the image
            int baseline = glyph.height - glyph.top; // maybe... maybe it's glyph.imageHeight - glyph.top... and maybe it's something else...

            Debug.Assert(image.Width == 256);
            Debug.Assert(image.Height == 256);
            icon.xoffset = 0;
            //icon.yoffset = font.maxHeight - glyph.top - glyph.bottom; // -baseline;
            icon.yoffset = font.maxTop - glyph.top;
            int xstart      = (int)(glyph.s * image.Width + 0.0f); // +glyph.pitch; // this "+ glyph.pitch" is a guess
            int ystart      = (int)(glyph.t * image.Height + 0.0f);
            int xend        = (int)(glyph.s2 * image.Width - 0.0f);
            int yend        = (int)(glyph.t2 * image.Height - 0.0f);
            int glyphWidth  = xend - xstart;
            int glyphHeight = yend - ystart;

            Debug.Assert(glyph.imageWidth == glyphWidth);
            Debug.Assert(glyph.imageHeight == glyphHeight);
            xstart += glyph.pitch; // this "+ glyph.pitch" is a guess

            // this damn ImageMagick can't create zero size images!
            if (zeroSizeImage == null)
            {
                if (glyphWidth == 0)
                {
                    glyphWidth = 1;
                }
                if (glyphHeight == 0)
                {
                    glyphHeight = 1;
                }
            }

            icon.xadvance = glyph.xSkip - glyphWidth; // maybe add "- glyph.pitch" here?

            iconInfos[icon.charId] = icon;

            MagickGeometry geom = new MagickGeometry(xstart, ystart, glyphWidth, glyphHeight);

            if (glyphWidth == 0 || glyphHeight == 0)
            {
                //Bitmap bmp = new Bitmap(0, 0, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                var newImage = new MagickImage(zeroSizeImage);
                //newImage.ColorType = image.ColorType;
                //newImage.ColorSpace = image.ColorSpace;
                //image.Crop(1, 0);
                //image.Trim();
                image = newImage;
            }
            else
            {
                image.Crop(geom);
            }
            image.Format = MagickFormat.Tga;
            image.Write(icon.imageFile);
        }
示例#6
0
        public void Load(string fileName)
        {
            FileStream fs = File.OpenRead(fileName);
            BinaryReader br = new BinaryReader(fs);

            name = FriendlyFontFace(fileName);

            maxHeight = 0;
            maxWidth = 0;
            maxTop = 0;
            maxBottom = 0;
            for (int i = 0; i < GLYPHS_PER_FONT; i++)
            {
                D3Glyph glyph = new D3Glyph();
                glyph.Load(br);
                glyphs[i] = glyph;

                if (maxHeight < glyph.height)
                    maxHeight = glyph.height;
                if (maxWidth < glyph.xSkip)
                    maxWidth = glyph.xSkip;
                if (maxTop < glyph.top)
                    maxTop = glyph.top;
                if (maxBottom < glyph.bottom)
                    maxBottom = glyph.bottom;
            }

            glyphScale = br.ReadSingle();

            br.Close();
            fs.Close();
        }
示例#7
0
        private void Decompose(D3Glyph glyph, int utf32Char)
        {
            string textureName = Path.Combine(dirWithFontTextures, Path.GetFileName(glyph.textureName));
            if (!textures.ContainsKey(textureName))
            {
                string realName = textureName;
                if (!File.Exists(realName))
                {
                    realName = Path.ChangeExtension(textureName, "dds");
                }
                MagickImage newImage = new MagickImage(realName);
                textures[textureName] = newImage;
            }

            MagickImage image = textures[textureName].Clone();

            BMIconInfo icon = new BMIconInfo();
            icon.imageFile = Path.Combine(imageOutputDir, string.Format("{0}_char{1}.tga", font.name, utf32Char));
            icon.charId = utf32Char;

            // baseline position in pixels from top edges of the image
            int baseline = glyph.height - glyph.top; // maybe... maybe it's glyph.imageHeight - glyph.top... and maybe it's something else...

            Debug.Assert(image.Width == 256);
            Debug.Assert(image.Height == 256);
            icon.xoffset = 0;
            //icon.yoffset = font.maxHeight - glyph.top - glyph.bottom; // -baseline;
            icon.yoffset = font.maxTop - glyph.top;
            int xstart = (int)(glyph.s * image.Width + 0.0f); // +glyph.pitch; // this "+ glyph.pitch" is a guess
            int ystart = (int)(glyph.t * image.Height + 0.0f);
            int xend = (int)(glyph.s2 * image.Width - 0.0f);
            int yend = (int)(glyph.t2 * image.Height - 0.0f);
            int glyphWidth = xend - xstart;
            int glyphHeight = yend - ystart;
            Debug.Assert(glyph.imageWidth == glyphWidth);
            Debug.Assert(glyph.imageHeight == glyphHeight);
            xstart += glyph.pitch; // this "+ glyph.pitch" is a guess

            // this damn ImageMagick can't create zero size images!
            if (zeroSizeImage == null)
            {
                if (glyphWidth == 0)
                {
                    glyphWidth = 1;
                }
                if (glyphHeight == 0)
                {
                    glyphHeight = 1;
                }
            }

            icon.xadvance = glyph.xSkip - glyphWidth; // maybe add "- glyph.pitch" here?

            iconInfos[icon.charId] = icon;

            MagickGeometry geom = new MagickGeometry(xstart, ystart, glyphWidth, glyphHeight);
            if (glyphWidth == 0 || glyphHeight == 0)
            {
                //Bitmap bmp = new Bitmap(0, 0, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                var newImage = new MagickImage(zeroSizeImage);
                //newImage.ColorType = image.ColorType;
                //newImage.ColorSpace = image.ColorSpace;
                //image.Crop(1, 0);
                //image.Trim();
                image = newImage;
            }
            else
            {
                image.Crop(geom);
            }
            image.Format = MagickFormat.Tga;
            image.Write(icon.imageFile);
        }