Revision: 3348
http://vexi.svn.sourceforge.net/vexi/?rev=3348&view=rev
Author: clrg
Date: 2009-01-12 16:45:20 +0000 (Mon, 12 Jan 2009)
Log Message:
-----------
Fix several text handling bugs
Modified Paths:
--------------
trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp
trunk/core/org.vexi.core/src/org/vexi/core/Text.java
Modified: trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp 2009-01-09 06:02:01 UTC
(rev 3347)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp 2009-01-12 16:45:20 UTC
(rev 3348)
@@ -117,7 +117,7 @@
static final boolean testDisplay(Box b) { return b.test(DISPLAY); }
/** for Surface to find out if root box is resizable */
- static final boolean testShrink(Box b) { return b.test(SHRINK); }
+ static final boolean testShrink(Box b) { return b.test(SHRINK); }
// Flags
//////////////////////////////////////////////////////////////////////
@@ -165,6 +165,10 @@
private static final int SHRINK_TRAP = 0x04000000;
private static final int HSHRINK_TRAP = 0x10000000;
private static final int VSHRINK_TRAP = 0x20000000;
+
+ // TODO: use these to re-put "colorname"->"#rrggbb"
+ //private static final int FILL_WRITE_TRAP = 0x40000000;
+ //private static final int TEXTCOLOR_WRITE_TRAP = 0x80000000;
private static final short MINWIDTH_TRAP = 0x0001;
private static final short MINHEIGHT_TRAP = 0x0002;
@@ -349,7 +353,7 @@
box.set(PLACE);
}
if (box.text.fontsize_trap)
- box.justTriggerTraps(SC_fontsize, box.text.sizeToJS());
+ box.justTriggerTraps(SC_fontsize,
Text.sizeToJS(box.text.pointsize));
}
int i=0;
//boolean lock = !box.test(LOCK_CHILDREN);
@@ -1205,7 +1209,7 @@
case "tile": return JSU.B(test(TILE_IMAGE));
case "textcolor": return JSU.S(Color.colorToString(text.color));
case "font": return text.font.stream;
- case "fontsize": return text.sizeToJS();
+ case "fontsize": return Text.sizeToJS(text.pointsize);
case "align": return alignToJS();
case "thisbox": return this;
case "shrink": return JSU.B(test(HSHRINK) || test(VSHRINK));
@@ -1274,27 +1278,44 @@
// the moment we handle Blessings separately for this reason.
if (value!=null && JSU.getFountain(value)==null && !(value
instanceof Blessing))
throw new JSExn("Attempt to put a non-stream to the 'font'
property of a box");
- Fountain fontstream = value==null ? null :
(Fountain)value.unclone();
- if ((value==null && !text.streamset) || text.font.stream ==
fontstream) return;
+ if (value == null) {
+ if (text.isDefaultStream()) return;
+ text.setStream();
+ } else {
+ Fountain fontstream = (Fountain)value.unclone();
+ if (text.font.stream == fontstream) return;
+ text = text.setStream(fontstream);
+ }
if (!text.isEmpty()) { setConstrain(); dirty(); }
- text = text.setStream(fontstream);
case "fontsize":
- int ps = Text.jsToSize(value);
- if (ps == text.pointsize) return;
+ if (value==null) {
+ if (text.isDefaultSize()) return;
+ text.setSize();
+ } else {
+ int ps = Text.jsToSize(value);
+ if (ps == text.pointsize) return;
+ text = text.setSize(ps);
+ }
if (!text.isEmpty()) { setConstrain(); dirty(); }
- text = text.setSize(ps);
case "text":
- String s = value == null ? Text.EMPTY_STRING : JSU.toString(value);
+ String s = value==null ? Text.EMPTY_STRING : JSU.toString(value);
+ // is this necessary? - strings are immutable so
""==Text.EMPTY_STRING
+ //if (s.equals("")) s = Text.EMPTY_STRING;
if (s == text.str) return;
text = text.setString(s);
setConstrain();
dirty();
case "textcolor":
try {
- int c = value==null ? -1 :
Color.stringToColor(JSU.toString(value));
- if (c == text.color) return;
+ if (value==null) {
+ if (text.isDefaultColor()) return;
+ text = text.setColor();
+ } else {
+ int c = Color.stringToColor(JSU.toString(value));
+ if (!text.isDefaultColor() && c==text.color) return;
+ text = text.setColor(c);
+ }
if (!text.isEmpty()) dirty();
- text = text.setColor(c);
} catch (ClassCastException cce) { throw new JSExn("Attempt to put
a non-string value to the textcolor property"); }
case "shrink":
boolean shr = JSU.toBoolean(value);
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-09
06:02:01 UTC (rev 3347)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Text.java 2009-01-12
16:45:20 UTC (rev 3348)
@@ -52,7 +52,7 @@
}
/** return appropriate JS constant for size */
- JS sizeToJS() {
+ static JS sizeToJS(int pointsize) {
switch (pointsize) {
case -3: return SC_xxsmall;
case -2: return SC_xsmall;
@@ -105,7 +105,9 @@
//////// INSTANCE PROPERTIES /////////////////////////////////////
- boolean streamset = false;
+ private boolean sizeset = false;
+ private boolean colorset = false;
+ private boolean streamset = false;
public int pointsize = 0;
int color = DEFAULT_COLOR;
int width = 0;
@@ -153,40 +155,67 @@
//////// INSTANCE FUNCTIONS ///////////////////////////////////////
boolean isEmpty() { return str == EMPTY_STRING; }
+ boolean isDefaultSize() { return !sizeset; }
+ boolean isDefaultColor() { return !colorset; }
+ boolean isDefaultStream() { return !streamset; }
- Text setColor() { return setColor(DEFAULT_COLOR); }
+ /** set color to default color */
+ Text setColor() {
+ if (this != DEFAULT_TEXT && colorset) {
+ color = DEFAULT_COLOR;
+ colorset = false;
+ }
+ return this;
+ }
+
+ /** set color to arbitary value */
Text setColor(int color) {
- if (color == this.color) return this;
+ if (colorset && color == this.color) return this;
Text t = (this == DEFAULT_TEXT) ? new Text() : this;
t.color = color;
+ colorset = true;
return t;
}
/** set pointsize of this text object */
- Text setSize() { return setSize(pointsize); }
+ Text setSize() {
+ if (this != DEFAULT_TEXT && sizeset) {
+ pointsize = MEDIUM_SIZE;
+ sizeset = false;
+ }
+ return this;
+ }
+
+ /** set pointsize to arbitary value */
Text setSize(int pointsize) {
- if (this == DEFAULT_TEXT) {
- if (pointsize == 0) return this;
- return new Text(null, pointsize);
- }
+ if (this == DEFAULT_TEXT) return new Text(null, pointsize);
+ if (sizeset && pointsize == this.pointsize) return this;
if (pointsize<6 || pointsize != this.pointsize) {
this.pointsize = pointsize;
setFont(font.stream);
calculateDimensions();
+ sizeset = true;
}
return this;
}
/** set font stream of this text object */
- Text setStream() { return setStream(DEFAULT_STREAM); }
+ Text setStream() {
+ if (this != DEFAULT_TEXT && streamset) {
+ setFont(DEFAULT_STREAM);
+ 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);
}
- // null means use the default
- streamset = stream!=null;
setFont(stream);
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