gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz test/gzz/vob/textvob.test gzz/util/Scalable...


From: Asko Soukka
Subject: [Gzz-commits] gzz test/gzz/vob/textvob.test gzz/util/Scalable...
Date: Thu, 21 Nov 2002 15:54:02 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Asko Soukka <address@hidden>    02/11/21 15:54:02

Modified files:
        test/gzz/vob   : textvob.test 
        gzz/util       : ScalableFont.java 

Log message:
        Test for scaling font by height.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/test/gzz/vob/textvob.test.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/util/ScalableFont.java.diff?tr1=1.4&tr2=1.5&r1=text&r2=text

Patches:
Index: gzz/gzz/util/ScalableFont.java
diff -u gzz/gzz/util/ScalableFont.java:1.4 gzz/gzz/util/ScalableFont.java:1.5
--- gzz/gzz/util/ScalableFont.java:1.4  Thu Nov 21 14:48:31 2002
+++ gzz/gzz/util/ScalableFont.java      Thu Nov 21 15:54:02 2002
@@ -33,7 +33,7 @@
  */
 
 public final class ScalableFont {
-    public static final String rcsid = "$Id: ScalableFont.java,v 1.4 
2002/11/21 19:48:31 humppake Exp $";
+    public static final String rcsid = "$Id: ScalableFont.java,v 1.5 
2002/11/21 20:54:02 humppake Exp $";
     public static boolean dbg=false;
     private static final void p(String s) { if(dbg) System.out.println(s); }
 
@@ -154,12 +154,22 @@
     public float getScale(float height) {
        float start = 1f;
        while (getFontMetrics(start).getHeight() < height) start += 1f;
-       if ((int)getFontMetrics(start-1f).getHeight() == (int)height) return 
start-1f;
-       else if ((int)getFontMetrics(start).getHeight() == (int)height) return 
start;
+       if (dbg) p("Intended height: " + height);
+       if (dbg) p("Seeking area from " + (start-1f) + " (height: " +
+                  getFontMetrics(start-1f).getHeight() + ") to " + start + " 
(height: " +
+                  getFontMetrics(start).getHeight() + ")");
+
+       if ((int)getFontMetrics(start-1f).getHeight() == (int)height) {
+           if (dbg) p("Best: " + (start-1f) + " (height: " +
+                  getFontMetrics(start-1f).getHeight() + ")");
+           return start-1f;
+       } else if ((int)getFontMetrics(start).getHeight() == (int)height) {
+           if (dbg) p("Best: " + (start) + " (height: " +
+                  getFontMetrics(start).getHeight() + ")");
+           return start;
+       }
 
        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() + ")");
        return seekBestScale(start-1f, start, 0, height);
        
        /*
@@ -184,18 +194,23 @@
      * @param height the intended height of drawn text
      */
     private float seekBestScale(float start, float end, float best, float 
height) {
-       if (getFontMetrics(start).getHeight() > height) return 1; // for 
failsafety
+       if (getFontMetrics(start).getHeight() > height) return 1; // for 
fail-safety
        if (dbg) p("Start: " + start + " End: " + end + " Best: " + best + " 
Height: " + height);
 
-       float current = getFontMetrics(start + (end-start)/2).getHeight();
-       if ((int)current == (int)getFontMetrics(best).getHeight()
-           || (int)current == (int)height) {
-           if (dbg) p("Best: " + best + " (height: " + current + ")");
+       float current = start + (end-start)/2;
+       float current_height = getFontMetrics(current).getHeight();
+       float best_height = getFontMetrics(best).getHeight();
+
+       if ((int)current_height == (int)height && (int)current_height != 
(int)best_height) {
+           if (dbg) p("Best: " + current_height + " (height: " + 
current_height + ")");
+           return current;
+       } else if ((int)current_height == (int)best_height) {
+           if (dbg) p("Best: " + best_height + " (height: " + best_height + 
")");
            return best;
-       } else best = start + (end-start)/2;
+       } else best = current;
 
-       if (current > height) return seekBestScale(start, start + 
(end-start)/2, best, height);
-       else return seekBestScale(start + (end-start)/2, end, best, height);
+       if (current_height > height) return seekBestScale(start, current, best, 
height);
+       else return seekBestScale(current, end, best, height);
     }
 }
 
Index: gzz/test/gzz/vob/textvob.test
diff -u gzz/test/gzz/vob/textvob.test:1.11 gzz/test/gzz/vob/textvob.test:1.12
--- gzz/test/gzz/vob/textvob.test:1.11  Thu Nov 21 14:48:31 2002
+++ gzz/test/gzz/vob/textvob.test       Thu Nov 21 15:54:02 2002
@@ -24,6 +24,14 @@
     failUnlessApprox(20, sty2.getWidth("xx", 1), 50)
     failUnlessApprox(4, sty3.getWidth("xx", 1), 10)
 
+def testStyleScaling():
+    """Tests scaling by height.
+    """
+    for height in range (0, 100):
+       scale = sty1.getScaleByHeight(height)
+       failUnlessApprox(1, sty1.getHeight(scale), height, "height")
+       failUnlessApprox(1, sty1.getAscent(scale) + sty1.getDescent(scale), 
height, "ascender + descender")
+       
 def testSize():
     """Test, for various box sizes, that text consisting of 
     lower-case letter x is on the baseline or slightly above.
@@ -38,7 +46,8 @@
     """Tests that TextVob is drawn with the width and height
     that it claims with getWidth() and getHeight().
     """
-    for text_scale in range(1, 4):
+    for scale in range(3, 10):
+       text_scale = float(scale / 3.0)
        vs = getvs()
        size = vs.getSize()
        vs.map.put(gzz.vob.vobs.SolidBgVob(Color.red))
@@ -66,15 +75,15 @@
        checkNotAvgColor(100, 100+text_height-1, text_width, text_depth+1, 
(255, 0, 0), delta=1)
 
        """The top side."""
-       checkAvgColor(100, 100-10, text_width, 10, (255, 0, 0), delta=20)
+       checkAvgColor(100, 100-19, text_width, 10, (255, 0, 0), delta=1)
 
        """The left side."""
-       checkAvgColor(100-10, 100, 10, text_height+text_depth, (255, 0, 0), 
delta=20)
+       checkAvgColor(100-19, 100, 10, text_height+text_depth, (255, 0, 0), 
delta=1)
 
        """The right side."""
-       checkAvgColor(100+text_width+1, 100, 10, text_height+text_depth, (255, 
0, 0), delta=20)
+       checkAvgColor(100+text_width+10, 100, 10, text_height+text_depth, (255, 
0, 0), delta=1)
 
        """The bottom side."""
-       checkAvgColor(100, 100+text_height+text_depth+1, text_width, 10, (255, 
0, 0), delta=20)
+       checkAvgColor(100, 100+text_height+text_depth+10, text_width, 10, (255, 
0, 0), delta=1)
 
 # : vim: set syntax=python :




reply via email to

[Prev in Thread] Current Thread [Next in Thread]