/[gzz]/gzz/gzz/vob/GLTextStyle.java
ViewVC logotype

Diff of /gzz/gzz/vob/GLTextStyle.java

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

revision 1.14 by tjl, Mon Oct 7 17:47:55 2002 UTC revision 1.15 by tjl, Sat Oct 19 14:29:13 2002 UTC
# Line 40  public static final String rcsid = "$Id$ Line 40  public static final String rcsid = "$Id$
40    
41    
42      static GL.Font theStaticFont;      static GL.Font theStaticFont;
43        static float[] charWidths = new float[256];
44      static GLTextStyle[] instances = new GLTextStyle[250];      static GLTextStyle[] instances = new GLTextStyle[250];
45    
46      static public GLTextStyle create(String family, int style, int size) {      static public GLTextStyle create(String family, int style, int size) {
# Line 48  public static final String rcsid = "$Id$ Line 49  public static final String rcsid = "$Id$
49          if(s == null) {          if(s == null) {
50              if(theStaticFont == null)              if(theStaticFont == null)
51                  theStaticFont = GL.createFont("gfx/fonts/a010013l.pfb", 64);                  theStaticFont = GL.createFont("gfx/fonts/a010013l.pfb", 64);
52              s = new GLTextStyle(theStaticFont, 1);              theStaticFont.getWidths(charWidths);
53                if(dbg) for(int i=0; i<256; i++) {
54                    pa("char '"+((char)i)+"': width "+charWidths[i]);
55                }
56                s = new GLTextStyle(theStaticFont, size);
57              instances[size] = s;              instances[size] = s;
58          }          }
59          return s;          return s;
# Line 57  public static final String rcsid = "$Id$ Line 62  public static final String rcsid = "$Id$
62    
63      float fontScale;      float fontScale;
64      GL.Font theFont;      GL.Font theFont;
     float[] charWidths = new float[256];  
65    
66      private GLTextStyle(GL.Font f, float scale) {      private GLTextStyle(GL.Font f, float scale) {
67          this.theFont = f;          this.theFont = f;
68          this.fontScale = scale;          this.fontScale = scale;
         f.getWidths(charWidths);  
         if(dbg) for(int i=0; i<256; i++) {  
             pa("char '"+((char)i)+"': width "+charWidths[i]);  
         }  
69      }      }
70    
71      public float getScaleByHeight(float h) {      public float getScaleByHeight(float h) {
# Line 73  public static final String rcsid = "$Id$ Line 73  public static final String rcsid = "$Id$
73      }      }
74    
75      private float getWidth(String s) {      private float getWidth(String s) {
76          int sum = 0;          float sum = 0;
77          for(int i=0; i<s.length(); i++) {          for(int i=0; i<s.length(); i++) {
78              char c = s.charAt(i);              char c = s.charAt(i);
79              if(c < charWidths.length)              if(c < charWidths.length)
# Line 82  public static final String rcsid = "$Id$ Line 82  public static final String rcsid = "$Id$
82          return sum * fontScale;          return sum * fontScale;
83      }      }
84      private float getWidth(char[] chars, int offs, int len) {      private float getWidth(char[] chars, int offs, int len) {
85          int sum = 0;          float sum = 0;
86          for(int i=offs; i<offs+len; i++) {          for(int i=offs; i<offs+len; i++) {
87              char c = chars[i];              char c = chars[i];
88              if(c < charWidths.length)              if(c < charWidths.length)

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

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