Revision: 4025
          http://vexi.svn.sourceforge.net/vexi/?rev=4025&view=rev
Author:   clrg
Date:     2011-02-09 01:52:06 +0000 (Wed, 09 Feb 2011)

Log Message:
-----------
Separate textsize and rasterizeGlyphs logic

Modified Paths:
--------------
    trunk/org.vexi-core.main/src/main/java/org/vexi/graphics/Font.java

Modified: trunk/org.vexi-core.main/src/main/java/org/vexi/graphics/Font.java
===================================================================
--- trunk/org.vexi-core.main/src/main/java/org/vexi/graphics/Font.java  
2011-02-09 01:42:36 UTC (rev 4024)
+++ trunk/org.vexi-core.main/src/main/java/org/vexi/graphics/Font.java  
2011-02-09 01:52:06 UTC (rev 4025)
@@ -87,14 +87,10 @@
 
 
     // Methods 
//////////////////////////////////////////////////////////////////////
-
-    /**
-     *  Rasterize the glyphs of <code>text</code>.
-     *  @returns <code>(width&lt;&lt;32)|height</code>
-     */
-    public long rasterizeGlyphs(String text, PixelBuffer pb, int textcolor, 
int x, int y, int cx1, int cy1, int cx2, int cy2) {
-        int width = 0, height = 0;
-        if (!latinCharsPreloaded) {       // preload the Latin-1 charset with 
low priority (we'll probably want it)
+    
+    /** preload the Latin-1 charset with low priority (we'll probably want it) 
*/
+    private void preloadLatinChars() {
+        if (!latinCharsPreloaded) {
             for (int i=48; i<57; i++)  if (glyphs[i]==null) 
glyphsToBeCached.add(glyphs[i]=Platform.createGlyph(this, (char)i));
             for (int i=32; i<47; i++)  if (glyphs[i]==null) 
glyphsToBeCached.add(glyphs[i]=Platform.createGlyph(this, (char)i));
             for (int i=57; i<128; i++) if (glyphs[i]==null) 
glyphsToBeCached.add(glyphs[i]=Platform.createGlyph(this, (char)i));
@@ -104,23 +100,30 @@
             }
             latinCharsPreloaded = true;
         }
+    }
+
+    /**
+     *  Rasterize the glyphs of <code>text</code>.
+     *  @returns <code>(width&lt;&lt;32)|height</code>
+     */
+    public void rasterizeGlyphs(String text, PixelBuffer buf, int textcolor, 
int x, int y, int cx1, int cy1, int cx2, int cy2) {
+        int width = 0;
+        preloadLatinChars();
         for (int i=0; i<text.length(); i++) {
             final char c = text.charAt(i);
             Glyph g = glyphs[c];
             if (g == null) {
                 glyphs[c] = g = Platform.createGlyph(this, c);
-                g.render();
             }
-            else g.render();
-            height = java.lang.Math.max(height, max_ascent + max_descent);
+            g.render();
             // avoid clipping first character
             int ox = x + width;
             if (i!=0 || g.bearingx>0) {
                 ox += g.bearingx;
             }
             // render glyph and move on
-            if (pb != null) {
-                pb.drawGlyph(g, ox, y + g.font.max_ascent - g.baseline, cx1, 
cy1, cx2, cy2, textcolor);
+            if (buf != null) {
+                buf.drawGlyph(g, ox, y + g.font.max_ascent - g.baseline, cx1, 
cy1, cx2, cy2, textcolor);
             }
             width += g.advance;
             // take into account clipping avoidance
@@ -128,13 +131,30 @@
                 width -= g.bearingx;
             }
         }
-        return ((((long)width) << 32) | (height & 0xffffffffL));
     }
 
     // FEATURE do we really need to be caching sizes?
     public int textwidth(String s) { return (int)((textsize(s) >>> 32) & 
0xffffffff); }
     public int textheight(String s) { return (int)(textsize(s) & 0xffffffffL); 
}
-    public long textsize(String s) { return rasterizeGlyphs(s, null, 0, 0, 0, 
0, 0, 0, 0); }
+    public long textsize(String s) {
+        int width = 0, height = 0;
+        preloadLatinChars();
+        for (int i=0; i<s.length(); i++) {
+            final char c = s.charAt(i);
+            Glyph g = glyphs[c];
+            if (g == null) {
+                glyphs[c] = g = Platform.createGlyph(this, c);
+            }
+            g.render();
+            height = java.lang.Math.max(height, max_ascent + max_descent);
+            width += g.advance;
+            // take into account clipping avoidance
+            if (i==0 && g.bearingx<0) {
+                width -= g.bearingx;
+            }
+        }
+        return ((((long)width) << 32) | (height & 0xffffffffL));
+    }
 
     static final Callable glyphRenderingTask = new Callable() { public Object 
run(Object o) {
         // FIXME: this should be a low-priority task


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to