/[gzz]/gzz/gzz/util/ScalableFont.java
ViewVC logotype

Diff of /gzz/gzz/util/ScalableFont.java

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

revision 1.4 by humppake, Thu Nov 21 19:48:31 2002 UTC revision 1.5 by humppake, Thu Nov 21 20:54:02 2002 UTC
# Line 154  public final class ScalableFont { Line 154  public final class ScalableFont {
154      public float getScale(float height) {      public float getScale(float height) {
155          float start = 1f;          float start = 1f;
156          while (getFontMetrics(start).getHeight() < height) start += 1f;          while (getFontMetrics(start).getHeight() < height) start += 1f;
157          if ((int)getFontMetrics(start-1f).getHeight() == (int)height) return start-1f;          if (dbg) p("Intended height: " + height);
158          else if ((int)getFontMetrics(start).getHeight() == (int)height) return start;          if (dbg) p("Seeking area from " + (start-1f) + " (height: " +
159                       getFontMetrics(start-1f).getHeight() + ") to " + start + " (height: " +
160                       getFontMetrics(start).getHeight() + ")");
161    
162            if ((int)getFontMetrics(start-1f).getHeight() == (int)height) {
163                if (dbg) p("Best: " + (start-1f) + " (height: " +
164                       getFontMetrics(start-1f).getHeight() + ")");
165                return start-1f;
166            } else if ((int)getFontMetrics(start).getHeight() == (int)height) {
167                if (dbg) p("Best: " + (start) + " (height: " +
168                       getFontMetrics(start).getHeight() + ")");
169                return start;
170            }
171    
172          if (dbg) p("Enters a recursive search for the best font scale for given height.");          if (dbg) p("Enters a recursive search for the best font scale for given height.");
         if (dbg) p("Intended height: " + height + " Start scale: " + start +  
                    " (height: " + getFontMetrics(start).getHeight() + ")");  
173          return seekBestScale(start-1f, start, 0, height);          return seekBestScale(start-1f, start, 0, height);
174                    
175          /*          /*
# Line 184  public final class ScalableFont { Line 194  public final class ScalableFont {
194       * @param height the intended height of drawn text       * @param height the intended height of drawn text
195       */       */
196      private float seekBestScale(float start, float end, float best, float height) {      private float seekBestScale(float start, float end, float best, float height) {
197          if (getFontMetrics(start).getHeight() > height) return 1; // for failsafety          if (getFontMetrics(start).getHeight() > height) return 1; // for fail-safety
198          if (dbg) p("Start: " + start + " End: " + end + " Best: " + best + " Height: " + height);          if (dbg) p("Start: " + start + " End: " + end + " Best: " + best + " Height: " + height);
199    
200          float current = getFontMetrics(start + (end-start)/2).getHeight();          float current = start + (end-start)/2;
201          if ((int)current == (int)getFontMetrics(best).getHeight()          float current_height = getFontMetrics(current).getHeight();
202              || (int)current == (int)height) {          float best_height = getFontMetrics(best).getHeight();
203              if (dbg) p("Best: " + best + " (height: " + current + ")");  
204            if ((int)current_height == (int)height && (int)current_height != (int)best_height) {
205                if (dbg) p("Best: " + current_height + " (height: " + current_height + ")");
206                return current;
207            } else if ((int)current_height == (int)best_height) {
208                if (dbg) p("Best: " + best_height + " (height: " + best_height + ")");
209              return best;              return best;
210          } else best = start + (end-start)/2;          } else best = current;
211    
212          if (current > height) return seekBestScale(start, start + (end-start)/2, best, height);          if (current_height > height) return seekBestScale(start, current, best, height);
213          else return seekBestScale(start + (end-start)/2, end, best, height);          else return seekBestScale(current, end, best, height);
214      }      }
215  }  }
216    

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

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