public static Bitmap ArrangeGlyphsFast(Glyph[] sourceGlyphs) { // Build up a list of all the glyphs needing to be arranged. List <ArrangedGlyph> glyphs = new List <ArrangedGlyph>(); int largestWidth = 1; int largestHeight = 1; for (int i = 0; i < sourceGlyphs.Length; i++) { ArrangedGlyph glyph = new ArrangedGlyph(); glyph.Source = sourceGlyphs[i]; // Leave a one pixel border around every glyph in the output bitmap. glyph.Width = sourceGlyphs[i].Subrect.Width + 2; glyph.Height = sourceGlyphs[i].Subrect.Height + 2; if (glyph.Width > largestWidth) { largestWidth = glyph.Width; } if (glyph.Height > largestHeight) { largestHeight = glyph.Height; } glyphs.Add(glyph); } // Work out how big the output bitmap should be. int outputWidth = GuessOutputWidth(sourceGlyphs); // Place each glyph in a grid based on the largest glyph size int curx = 0; int cury = 0; for (int i = 0; i < glyphs.Count; i++) { glyphs[i].X = curx; glyphs[i].Y = cury; curx += largestWidth; if (curx + largestWidth > outputWidth) { curx = 0; cury += largestHeight; } } // Create the merged output bitmap. int outputHeight = MakeValidTextureSize(cury + largestHeight, false); return(CopyGlyphsToOutput(glyphs, outputWidth, outputHeight)); }
public static Bitmap ArrangeGlyphsFast(Glyph[] sourceGlyphs) { // Build up a list of all the glyphs needing to be arranged. List<ArrangedGlyph> glyphs = new List<ArrangedGlyph>(); int largestWidth = 1; int largestHeight = 1; for (int i = 0; i < sourceGlyphs.Length; i++) { ArrangedGlyph glyph = new ArrangedGlyph(); glyph.Source = sourceGlyphs[i]; // Leave a one pixel border around every glyph in the output bitmap. glyph.Width = sourceGlyphs[i].Subrect.Width + 2; glyph.Height = sourceGlyphs[i].Subrect.Height + 2; if (glyph.Width > largestWidth) largestWidth = glyph.Width; if (glyph.Height > largestHeight) largestHeight = glyph.Height; glyphs.Add(glyph); } // Work out how big the output bitmap should be. int outputWidth = GuessOutputWidth(sourceGlyphs); // Place each glyph in a grid based on the largest glyph size int curx = 0; int cury = 0; for (int i = 0; i < glyphs.Count; i++) { glyphs[i].X = curx; glyphs[i].Y = cury; curx += largestWidth; if (curx + largestWidth > outputWidth) { curx = 0; cury += largestHeight; } } // Create the merged output bitmap. int outputHeight = MakeValidTextureSize(cury + largestHeight, false); return CopyGlyphsToOutput(glyphs, outputWidth, outputHeight); }
// Comparison function for sorting glyphs by size. static int CompareGlyphSizes(ArrangedGlyph a, ArrangedGlyph b) { const int heightWeight = 1024; int aSize = a.Height * heightWeight + a.Width; int bSize = b.Height * heightWeight + b.Width; if (aSize != bSize) return bSize.CompareTo(aSize); else return a.Source.Character.CompareTo(b.Source.Character); }
public static Bitmap ArrangeGlyphs(Glyph[] sourceGlyphs) { // Build up a list of all the glyphs needing to be arranged. List<ArrangedGlyph> glyphs = new List<ArrangedGlyph>(); for (int i = 0; i < sourceGlyphs.Length; i++) { ArrangedGlyph glyph = new ArrangedGlyph(); glyph.Source = sourceGlyphs[i]; // Leave a one pixel border around every glyph in the output bitmap. glyph.Width = sourceGlyphs[i].Subrect.Width + 2; glyph.Height = sourceGlyphs[i].Subrect.Height + 2; glyphs.Add(glyph); } // Sort so the largest glyphs get arranged first. glyphs.Sort(CompareGlyphSizes); // Work out how big the output bitmap should be. int outputWidth = GuessOutputWidth(sourceGlyphs); int outputHeight = 0; // Choose positions for each glyph, one at a time. for (int i = 0; i < glyphs.Count; i++) { if (i > 0 && (i % 500) == 0) { Console.Write("."); } PositionGlyph(glyphs, i, outputWidth); outputHeight = Math.Max(outputHeight, glyphs[i].Y + glyphs[i].Height); } if (glyphs.Count >= 500) { Console.WriteLine(); } // Create the merged output bitmap. outputHeight = MakeValidTextureSize(outputHeight, false); return CopyGlyphsToOutput(glyphs, outputWidth, outputHeight); }
public static Bitmap ArrangeGlyphs(Glyph[] sourceGlyphs) { // Build up a list of all the glyphs needing to be arranged. List <ArrangedGlyph> glyphs = new List <ArrangedGlyph>(); for (int i = 0; i < sourceGlyphs.Length; i++) { ArrangedGlyph glyph = new ArrangedGlyph(); glyph.Source = sourceGlyphs[i]; // Leave a one pixel border around every glyph in the output bitmap. glyph.Width = sourceGlyphs[i].Subrect.Width + 2; glyph.Height = sourceGlyphs[i].Subrect.Height + 2; glyphs.Add(glyph); } // Sort so the largest glyphs get arranged first. glyphs.Sort(CompareGlyphSizes); // Work out how big the output bitmap should be. int outputWidth = GuessOutputWidth(sourceGlyphs); int outputHeight = 0; // Choose positions for each glyph, one at a time. for (int i = 0; i < glyphs.Count; i++) { if (i > 0 && (i % 500) == 0) { Console.Write("."); } PositionGlyph(glyphs, i, outputWidth); outputHeight = Math.Max(outputHeight, glyphs[i].Y + glyphs[i].Height); } if (glyphs.Count >= 500) { Console.WriteLine(); } // Create the merged output bitmap. outputHeight = MakeValidTextureSize(outputHeight, false); return(CopyGlyphsToOutput(glyphs, outputWidth, outputHeight)); }
// Comparison function for sorting glyphs by size. static int CompareGlyphSizes(ArrangedGlyph a, ArrangedGlyph b) { const int heightWeight = 1024; int aSize = a.Height * heightWeight + a.Width; int bSize = b.Height * heightWeight + b.Width; if (aSize != bSize) { return(bSize.CompareTo(aSize)); } else { return(a.Source.Character.CompareTo(b.Source.Character)); } }
//public static Bitmap ArrangeGlyphs(Glyph[] sourceGlyphs) //{ // // Build up a list of all the glyphs needing to be arranged. // List<ArrangedGlyph> glyphs = new List<ArrangedGlyph>(); // for (int i = 0; i < sourceGlyphs.Length; i++) // { // ArrangedGlyph glyph = new ArrangedGlyph(); // glyph.Source = sourceGlyphs[i]; // // Leave a one pixel border around every glyph in the output bitmap. // glyph.Width = sourceGlyphs[i].Subrect.Width + 2; // glyph.Height = sourceGlyphs[i].Subrect.Height + 2; // glyphs.Add(glyph); // } // // Sort so the largest glyphs get arranged first. // glyphs.Sort(CompareGlyphSizes); // // Work out how big the output bitmap should be. // int outputWidth = GuessOutputWidth(sourceGlyphs); // int outputHeight = 0; // // Choose positions for each glyph, one at a time. // for (int i = 0; i < glyphs.Count; i++) // { // if (i > 0 && (i % 500) == 0) // { // Console.Write("."); // } // PositionGlyph(glyphs, i, outputWidth); // outputHeight = Math.Max(outputHeight, glyphs[i].Y + glyphs[i].Height); // } // if (glyphs.Count >= 500) // { // Console.WriteLine(); // } // // Create the merged output bitmap. // outputHeight = MakeValidTextureSize(outputHeight, false); // return CopyGlyphsToOutput(glyphs, outputWidth, outputHeight); //} public static Bitmap ArrangeGlyphs(Glyph[] sourceGlyphs) { // Build up a list of all the glyphs needing to be arranged. List <ArrangedGlyph> glyphs = new List <ArrangedGlyph>(); int font_h = 0; for (int i = 0; i < sourceGlyphs.Length; i++) { ArrangedGlyph glyph = new ArrangedGlyph(); glyph.Source = sourceGlyphs[i]; // Leave a one pixel border around every glyph in the output bitmap. glyph.Width = sourceGlyphs[i].Subrect.Width + 2; glyph.Height = sourceGlyphs[i].Subrect.Height + 2; font_h = Math.Max(font_h, glyph.Height); glyphs.Add(glyph); } // Sort so the largest glyphs get arranged first. glyphs.Sort(CompareGlyphSizes); // Work out how big the output bitmap should be. int outputWidth = GuessOutputWidth(sourceGlyphs); int outputHeight = 0; // Choose positions for each glyph, one at a time. int last_x = 0, last_y = 0; for (int i = 0; i < glyphs.Count; i++) { //毎回左上から隙間を1ドット単位で検索 遅すぎる!! PositionGlyph(glyphs, i, outputWidth, font_h, ref last_x, ref last_y); // 漢字は矩形内に収まるので順番に詰めていく 詰めた場所をlast_xyで保存しておく outputHeight = Math.Max(outputHeight, glyphs[i].Y + glyphs[i].Height); } // Create the merged output bitmap. outputHeight = MakeValidTextureSize(outputHeight, false); return(CopyGlyphsToOutput(glyphs, outputWidth, outputHeight)); }
public static BitmapContent ArrangeGlyphs(Glyph[] sourceGlyphs, bool requirePOT, bool requireSquare) { // Build up a list of all the glyphs needing to be arranged. var glyphs = new List <ArrangedGlyph>(); for (int i = 0; i < sourceGlyphs.Length; i++) { var glyph = new ArrangedGlyph(); glyph.Source = sourceGlyphs[i]; // Leave a one pixel border around every glyph in the output bitmap. glyph.Width = sourceGlyphs[i].Subrect.Width + 2; glyph.Height = sourceGlyphs[i].Subrect.Height + 2; glyphs.Add(glyph); } // Sort so the largest glyphs get arranged first. glyphs.Sort(CompareGlyphSizes); // Work out how big the output bitmap should be. int outputWidth = GuessOutputWidth(sourceGlyphs); int outputHeight = 0; // Choose positions for each glyph, one at a time. for (int i = 0; i < glyphs.Count; i++) { PositionGlyph(glyphs, i, outputWidth); outputHeight = Math.Max(outputHeight, glyphs[i].Y + glyphs[i].Height); } // Create the merged output bitmap. outputHeight = MakeValidTextureSize(outputHeight, requirePOT); if (requireSquare) { outputHeight = Math.Max(outputWidth, outputHeight); outputWidth = outputHeight; } return(CopyGlyphsToOutput(glyphs, outputWidth, outputHeight)); }
public static BitmapContent ArrangeGlyphs(Glyph[] sourceGlyphs, bool requirePOT, bool requireSquare) { // Build up a list of all the glyphs needing to be arranged. var glyphs = new List<ArrangedGlyph>(); for (int i = 0; i < sourceGlyphs.Length; i++) { var glyph = new ArrangedGlyph(); glyph.Source = sourceGlyphs[i]; // Leave a one pixel border around every glyph in the output bitmap. glyph.Width = sourceGlyphs[i].Subrect.Width + 2; glyph.Height = sourceGlyphs[i].Subrect.Height + 2; glyphs.Add(glyph); } // Sort so the largest glyphs get arranged first. glyphs.Sort(CompareGlyphSizes); // Work out how big the output bitmap should be. int outputWidth = GuessOutputWidth(sourceGlyphs); int outputHeight = 0; // Choose positions for each glyph, one at a time. for (int i = 0; i < glyphs.Count; i++) { PositionGlyph(glyphs, i, outputWidth); outputHeight = Math.Max(outputHeight, glyphs[i].Y + glyphs[i].Height); } // Create the merged output bitmap. outputHeight = MakeValidTextureSize(outputHeight, requirePOT); if (requireSquare) { outputHeight = Math.Max (outputWidth, outputHeight); outputWidth = outputHeight; } return CopyGlyphsToOutput(glyphs, outputWidth, outputHeight); }