40 |
|
|
41 |
|
|
42 |
static GL.Font theStaticFont; |
static GL.Font theStaticFont; |
43 |
|
static float[] charWidths = new float[256]; |
44 |
static GLTextStyle[] instances = new GLTextStyle[250]; |
static GLTextStyle[] instances = new GLTextStyle[250]; |
45 |
|
|
46 |
static public GLTextStyle create(String family, int style, int size) { |
static public GLTextStyle create(String family, int style, int size) { |
49 |
if(s == null) { |
if(s == null) { |
50 |
if(theStaticFont == null) |
if(theStaticFont == null) |
51 |
theStaticFont = GL.createFont("gfx/fonts/a010013l.pfb", 64); |
theStaticFont = GL.createFont("gfx/fonts/a010013l.pfb", 64); |
52 |
s = new GLTextStyle(theStaticFont, 1); |
theStaticFont.getWidths(charWidths); |
53 |
|
if(dbg) for(int i=0; i<256; i++) { |
54 |
|
pa("char '"+((char)i)+"': width "+charWidths[i]); |
55 |
|
} |
56 |
|
s = new GLTextStyle(theStaticFont, size); |
57 |
instances[size] = s; |
instances[size] = s; |
58 |
} |
} |
59 |
return s; |
return s; |
62 |
|
|
63 |
float fontScale; |
float fontScale; |
64 |
GL.Font theFont; |
GL.Font theFont; |
|
float[] charWidths = new float[256]; |
|
65 |
|
|
66 |
private GLTextStyle(GL.Font f, float scale) { |
private GLTextStyle(GL.Font f, float scale) { |
67 |
this.theFont = f; |
this.theFont = f; |
68 |
this.fontScale = scale; |
this.fontScale = scale; |
|
f.getWidths(charWidths); |
|
|
if(dbg) for(int i=0; i<256; i++) { |
|
|
pa("char '"+((char)i)+"': width "+charWidths[i]); |
|
|
} |
|
69 |
} |
} |
70 |
|
|
71 |
public float getScaleByHeight(float h) { |
public float getScaleByHeight(float h) { |
73 |
} |
} |
74 |
|
|
75 |
private float getWidth(String s) { |
private float getWidth(String s) { |
76 |
int sum = 0; |
float sum = 0; |
77 |
for(int i=0; i<s.length(); i++) { |
for(int i=0; i<s.length(); i++) { |
78 |
char c = s.charAt(i); |
char c = s.charAt(i); |
79 |
if(c < charWidths.length) |
if(c < charWidths.length) |
82 |
return sum * fontScale; |
return sum * fontScale; |
83 |
} |
} |
84 |
private float getWidth(char[] chars, int offs, int len) { |
private float getWidth(char[] chars, int offs, int len) { |
85 |
int sum = 0; |
float sum = 0; |
86 |
for(int i=offs; i<offs+len; i++) { |
for(int i=offs; i<offs+len; i++) { |
87 |
char c = chars[i]; |
char c = chars[i]; |
88 |
if(c < charWidths.length) |
if(c < charWidths.length) |