/[libvob]/libvob/org/nongnu/libvob/util/ScalableFont.java
ViewVC logotype

Diff of /libvob/org/nongnu/libvob/util/ScalableFont.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by tjl, Sun Mar 9 13:13:14 2003 UTC revision 1.2 by benja, Sun Mar 30 19:55:21 2003 UTC
# Line 40  import java.util.*; Line 40  import java.util.*;
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       */       */
# Line 84  public final class ScalableFont { Line 84  public final class ScalableFont {
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) {
# Line 143  public final class ScalableFont { Line 146  public final class ScalableFont {
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);
# Line 158  public final class ScalableFont { Line 164  public final class ScalableFont {
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() + ")");

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26