40 |
public final class ScalableFont { |
public final class ScalableFont { |
41 |
public static final String rcsid = "$Id$"; |
public static final String rcsid = "$Id$"; |
42 |
public static boolean dbg=false; |
public static boolean dbg=false; |
43 |
private static final void p(String s) { if(dbg) System.out.println(s); } |
private static final void p(String s) { System.out.println(s); } |
44 |
|
|
45 |
/** If set, font metrics will not be cached. |
/** If set, font metrics will not be cached. |
46 |
*/ |
*/ |
84 |
} |
} |
85 |
|
|
86 |
FontMetrics getFontMetrics(int pt) { |
FontMetrics getFontMetrics(int pt) { |
87 |
|
if(pt < 0) |
88 |
|
throw new IllegalArgumentException("Negative point size: "+pt); |
89 |
|
|
90 |
if(dontCache) return fmComp.getFontMetrics(getFont(pt)); |
if(dontCache) return fmComp.getFontMetrics(getFont(pt)); |
91 |
|
|
92 |
if(metrics.length <= pt) { |
if(metrics.length <= pt) { |
146 |
* @return May not return null. |
* @return May not return null. |
147 |
*/ |
*/ |
148 |
public FontMetrics getFontMetrics(float scale) { |
public FontMetrics getFontMetrics(float scale) { |
149 |
|
if(scale < 0) |
150 |
|
throw new IllegalArgumentException("Negative scale: "+scale); |
151 |
|
|
152 |
if(scale == lastFMScale) return lastFM; |
if(scale == lastFMScale) return lastFM; |
153 |
int pt=scale2pt(scale); |
int pt=scale2pt(scale); |
154 |
FontMetrics fm = myCache.getFontMetrics(pt); |
FontMetrics fm = myCache.getFontMetrics(pt); |
164 |
*/ |
*/ |
165 |
public float getScale(float height) { |
public float getScale(float height) { |
166 |
float start = 1f; |
float start = 1f; |
167 |
while (getFontMetrics(start).getHeight() < height) start += 1f; |
if (dbg) p("Start with start: "+start+" height: "+getFontMetrics(start).getHeight()); |
168 |
|
while (getFontMetrics(start).getHeight() < height) { |
169 |
|
if (dbg) p("Increment start, was: "+start); |
170 |
|
start += 1f; |
171 |
|
} |
172 |
if (dbg) p("Intended height: " + height); |
if (dbg) p("Intended height: " + height); |
173 |
|
if (dbg) p("Start: "+start); |
174 |
if (dbg) p("Seeking area from " + (start-1f) + " (height: " + |
if (dbg) p("Seeking area from " + (start-1f) + " (height: " + |
175 |
getFontMetrics(start-1f).getHeight() + ") to " + start + " (height: " + |
getFontMetrics(start-1f).getHeight() + ") to " + start + " (height: " + |
176 |
getFontMetrics(start).getHeight() + ")"); |
getFontMetrics(start).getHeight() + ")"); |