# # Copyright (c) 2003, Asko Soukka # # This file is part of Gzz. # # Gzz is free software; you can redistribute it and/or modify it under # the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # Gzz is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General # Public License for more details. # # You should have received a copy of the GNU Lesser General # Public License along with Gzz; if not, write to the Free # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, # MA 02111-1307 USA # # """Test text sizes, rendering etc. """ from test.tools.gfx import * from java.awt import Color sty1 = win.getGraphicsAPI().getTextStyle("SansSerif", 0, 20) sty2 = win.getGraphicsAPI().getTextStyle("SansSerif", 0, 50) sty3 = win.getGraphicsAPI().getTextStyle("SansSerif", 0, 10) def testStyleSize(): """Test that the different styles give out suitable heights. """ failUnlessApprox(4, sty1.getHeight(1), 20) failUnlessApprox(15, sty2.getHeight(1), 50) failUnlessApprox(4, sty3.getHeight(1), 10) failUnlessApprox(10, sty1.getHeight(2), 40) failUnlessApprox(25, sty2.getHeight(2), 100) failUnlessApprox(8, sty3.getHeight(2), 20) 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. """ def testScale(): """Test that hierarchical coordinate systems affect the scaling in the same way. """ def testWH(): """Tests that TextVob is drawn with the width and height that it claims with getWidth() and getHeight(). """ text_scale = 0 for scale in range(1, 3): text_scale += scale vs = getvs() size = vs.getSize() vs.map.put(vob.vobs.SolidBgVob(Color.red)) textvob = vob.vobs.TextVob(sty1, "Xj"+chr(196)+"j"+chr(197)+"j"+chr(214)+"jX") text_width = int(textvob.getWidth(text_scale)) text_height = int(textvob.getHeight(text_scale)) text_depth = int(textvob.getDepth(text_scale)) cs = vs.orthoBoxCS(0, "window", 0, 100, 100, 1, 1, size.width, size.height) cs_text = vs.orthoCS(cs, "text", 0, 0, 0, text_height + text_depth, text_height + text_depth) vs.map.put(textvob, cs_text) render(vs) """The top edge.""" checkNotAvgColor(100, 100, text_width, 10, (255, 0, 0), delta=1) """The left edge.""" checkNotAvgColor(100, 100, 10, text_height+text_depth, (255, 0, 0), delta=1) """The right edge.""" checkNotAvgColor(100+text_width-10, 100, 10, text_height+text_depth, (255, 0, 0), delta=1) """The bottom edge.""" checkNotAvgColor(100, 100+text_height-1, text_width, text_depth+1, (255, 0, 0), delta=1) """The top side.""" checkAvgColor(100, 100-19, text_width, 10, (255, 0, 0), delta=1) """The left side.""" checkAvgColor(100-19, 100, 10, text_height+text_depth, (255, 0, 0), delta=1) """The right side.""" 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+10, text_width, 10, (255, 0, 0), delta=1) # : vim: set syntax=python :