[sword-svn] r121 - trunk/app/src/org/crosswire/flashcards

Apache apache at www.crosswire.org
Tue May 8 20:11:53 MST 2007


Author: 
Date: 2007-05-08 20:11:52 -0700 (Tue, 08 May 2007)
New Revision: 121

Modified:
   trunk/app/src/org/crosswire/flashcards/ComplexLesson.java
Log:
Fixed rendering of images to bound the actual text better


Modified: trunk/app/src/org/crosswire/flashcards/ComplexLesson.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/ComplexLesson.java	2007-05-01 10:29:03 UTC (rev 120)
+++ trunk/app/src/org/crosswire/flashcards/ComplexLesson.java	2007-05-09 03:11:52 UTC (rev 121)
@@ -35,6 +35,7 @@
 import java.util.Properties;
 
 import javax.imageio.ImageIO;
+import java.awt.geom.Rectangle2D;
 
 
 /**
@@ -180,7 +181,7 @@
                          dir.mkdirs();
                     }
                     outStream = new FileOutputStream(file);
-                    final int width = 140;
+                    final int width = 800;
                     final int height = 40;
 
                     // Create a buffered image in which to draw
@@ -193,8 +194,11 @@
                     g2d.setColor(Color.white);
                     g2d.fillRect(0, 0, width, height);
                     g2d.setColor(Color.black);
-                    g2d.setFont(new Font(g2d.getFont().getName(), Font.BOLD, (int)(height*.75)));
-                    g2d.drawString(f.getFront(), 4, (int)(height*.67));
+                    Font font = new Font(g2d.getFont().getName(), Font.BOLD, (int)(height*.75));
+                    g2d.setFont(font);
+                    Rectangle2D rect = font.getStringBounds(f.getFront(), g2d.getFontRenderContext());
+                    g2d.drawString(f.getFront(), 4, (int)(height*.70));
+                    bufferedImage = bufferedImage.getSubimage(0, 0, (int)(rect.getWidth()+8), 40);
 
                     // Graphics context no longer needed so dispose it
                     g2d.dispose();




More information about the sword-cvs mailing list