Revision: 3350
          http://vexi.svn.sourceforge.net/vexi/?rev=3350&view=rev
Author:   clrg
Date:     2009-01-12 17:41:05 +0000 (Mon, 12 Jan 2009)

Log Message:
-----------
Fix several text handling bugs

Modified Paths:
--------------
    trunk/core/org.vexi.core/src/org/vexi/core/Text.java

Modified: trunk/core/org.vexi.core/src/org/vexi/core/Text.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Text.java        2009-01-12 
17:02:24 UTC (rev 3349)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Text.java        2009-01-12 
17:41:05 UTC (rev 3350)
@@ -126,11 +126,16 @@
     Text() { }
 
     /** construct new text object based on font from 'stream' of size 
'pointsize' */
-    Text(JS stream, int pointsize) {
-        this.streamset = stream!=null;
-        this.pointsize = pointsize;
-        setFont(stream);
+    Text(JS stream) {
+        this.streamset = true;
+        setFont(stream, MEDIUM_SIZE);
     }
+
+    /** construct new text object based on font from 'stream' of size 
'pointsize' */
+    Text(int pointsize) {
+        this.sizeset = true;
+        setFont(DEFAULT_STREAM, pointsize);
+    }
     
     static final int normalizeSize(int pointsize) {
         if (pointsize>5) return pointsize;
@@ -147,8 +152,11 @@
         return ps>5 ? ps : 6;
     }
     
-    private final void setFont(JS stream) {
-        font = Font.getFont(stream == null ? DEFAULT_STREAM : stream, 
normalizeSize(pointsize));
+    private final void setFont(JS stream, int pointsize) {
+        if (stream == font.stream && pointsize == this.pointsize) return;
+        font = Font.getFont(stream, normalizeSize(pointsize));
+        this.pointsize = pointsize;
+        calculateDimensions();
     }
 
 
@@ -170,17 +178,19 @@
     
     /** set color to arbitary value */
     Text setColor(int color) {
-        if (colorset && color == this.color) return this;
+        if (colorset && color == this.color)
+            return this;
+        colorset = true;
         Text t = (this == DEFAULT_TEXT) ? new Text() : this;
         t.color = color;
-        colorset = true;
         return t;
     }
 
     /** set pointsize of this text object */
     Text setSize() {
         if (this != DEFAULT_TEXT && sizeset) {
-            pointsize = MEDIUM_SIZE;
+            if (pointsize != MEDIUM_SIZE)
+                setFont(font.stream, MEDIUM_SIZE);
             sizeset = false;
         }
         return this;
@@ -188,13 +198,14 @@
     
     /** set pointsize to arbitary value */
     Text setSize(int pointsize) {
-        if (this == DEFAULT_TEXT) return new Text(null, pointsize);
-        if (sizeset && pointsize == this.pointsize) return this;
+        if (sizeset && pointsize == this.pointsize)
+            return this;
+        if (this == DEFAULT_TEXT)
+            return new Text(pointsize);
+        sizeset = true;
         if (pointsize<6 || pointsize != this.pointsize) {
             this.pointsize = pointsize;
-            setFont(font.stream);
-            calculateDimensions();
-            sizeset = true;
+            setFont(font.stream, pointsize);
         }
         return this;
     }
@@ -202,21 +213,21 @@
     /** set font stream of this text object */
     Text setStream() {
         if (this != DEFAULT_TEXT && streamset) {
-            setFont(DEFAULT_STREAM);
+            if (font.stream != DEFAULT_STREAM)
+                setFont(DEFAULT_STREAM, pointsize);
             streamset = false;
-            calculateDimensions();
         }
         return this;
     }
     
     /** set stream to arbitrary font stream */
     Text setStream(JS stream) {
-        if (stream == font.stream) return this;
-        if (this == DEFAULT_TEXT) {
-            if (stream == null) return this;
-            return new Text(stream, 0);
-        }
-        setFont(stream);
+        if (streamset && stream == font.stream)
+            return this;
+        if (this == DEFAULT_TEXT)
+            return new Text(stream);
+        streamset = true;
+        setFont(stream, pointsize);
         calculateDimensions();
         return this;
     }


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

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to