Skip to content

Commit 08c4d81

Browse files
committed
remove bmpfont debug saving
1 parent 60c5b87 commit 08c4d81

File tree

2 files changed

+82
-82
lines changed

2 files changed

+82
-82
lines changed

Release/V0.01/GrblCNC.exe

0 Bytes
Binary file not shown.

Software/GrblCNC/FontManager.cs

Lines changed: 82 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,82 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using System.Drawing;
7-
using System.Drawing.Text;
8-
using GrblCNC.Properties;
9-
10-
namespace GrblCNC
11-
{
12-
class FontManager
13-
{
14-
static PrivateFontCollection pfc = new PrivateFontCollection();
15-
static FontFamily familyFixed = null;
16-
static Font gcodeFont = null;
17-
static Bitmap bitmapFont;
18-
19-
public static FontFamily GetResourcefont(byte[] fontfile)
20-
{
21-
int len = pfc.Families.Length;
22-
unsafe
23-
{
24-
fixed (byte* pFontData = fontfile)
25-
{
26-
pfc.AddMemoryFont((System.IntPtr)pFontData, fontfile.Length);
27-
}
28-
}
29-
return pfc.Families[len];
30-
}
31-
32-
public static FontFamily FamilyFixed
33-
{
34-
get
35-
{
36-
if (familyFixed == null)
37-
familyFixed = GetResourcefont(Resources.JetBrainsMono_Medium);
38-
return familyFixed;
39-
}
40-
}
41-
42-
public static Font GcodeFont
43-
{
44-
get
45-
{
46-
if (gcodeFont == null)
47-
gcodeFont = new Font(FamilyFixed, 10);
48-
return gcodeFont;
49-
}
50-
}
51-
52-
public static Bitmap BitmapFont
53-
{
54-
get
55-
{
56-
if (bitmapFont != null)
57-
return bitmapFont;
58-
bitmapFont = new Bitmap(512, 512, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
59-
int fontSize = 40;
60-
int sx = BitmapFont.Width / 16;
61-
int sy = sx * 2;
62-
using (Graphics g = Graphics.FromImage(bitmapFont))
63-
{
64-
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
65-
g.Clear(Color.Transparent);
66-
Font fnt = new Font(FamilyFixed, fontSize);
67-
SizeF charSize = g.MeasureString("W", fnt);
68-
int offs = (sx - (int)charSize.Width) / 2;
69-
for (int i = 0; i < 96; i++)
70-
{
71-
string stchar = ((char)(i + 32)).ToString();
72-
int x = (i % 16) * sx + offs;
73-
int y = (i / 16) * sy;
74-
g.DrawString(stchar, fnt, Brushes.White, x, y);
75-
}
76-
}
77-
bitmapFont.Save("bmpFont.png", System.Drawing.Imaging.ImageFormat.Png);
78-
return bitmapFont;
79-
}
80-
}
81-
}
82-
}
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Drawing;
7+
using System.Drawing.Text;
8+
using GrblCNC.Properties;
9+
10+
namespace GrblCNC
11+
{
12+
class FontManager
13+
{
14+
static PrivateFontCollection pfc = new PrivateFontCollection();
15+
static FontFamily familyFixed = null;
16+
static Font gcodeFont = null;
17+
static Bitmap bitmapFont;
18+
19+
public static FontFamily GetResourcefont(byte[] fontfile)
20+
{
21+
int len = pfc.Families.Length;
22+
unsafe
23+
{
24+
fixed (byte* pFontData = fontfile)
25+
{
26+
pfc.AddMemoryFont((System.IntPtr)pFontData, fontfile.Length);
27+
}
28+
}
29+
return pfc.Families[len];
30+
}
31+
32+
public static FontFamily FamilyFixed
33+
{
34+
get
35+
{
36+
if (familyFixed == null)
37+
familyFixed = GetResourcefont(Resources.JetBrainsMono_Medium);
38+
return familyFixed;
39+
}
40+
}
41+
42+
public static Font GcodeFont
43+
{
44+
get
45+
{
46+
if (gcodeFont == null)
47+
gcodeFont = new Font(FamilyFixed, 10);
48+
return gcodeFont;
49+
}
50+
}
51+
52+
public static Bitmap BitmapFont
53+
{
54+
get
55+
{
56+
if (bitmapFont != null)
57+
return bitmapFont;
58+
bitmapFont = new Bitmap(512, 512, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
59+
int fontSize = 40;
60+
int sx = BitmapFont.Width / 16;
61+
int sy = sx * 2;
62+
using (Graphics g = Graphics.FromImage(bitmapFont))
63+
{
64+
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
65+
g.Clear(Color.Transparent);
66+
Font fnt = new Font(FamilyFixed, fontSize);
67+
SizeF charSize = g.MeasureString("W", fnt);
68+
int offs = (sx - (int)charSize.Width) / 2;
69+
for (int i = 0; i < 96; i++)
70+
{
71+
string stchar = ((char)(i + 32)).ToString();
72+
int x = (i % 16) * sx + offs;
73+
int y = (i / 16) * sy;
74+
g.DrawString(stchar, fnt, Brushes.White, x, y);
75+
}
76+
}
77+
//bitmapFont.Save("bmpFont.png", System.Drawing.Imaging.ImageFormat.Png);
78+
return bitmapFont;
79+
}
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)