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); }
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); }