[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] gzz/gzz view/LinebrokenCellContentView.java vob...
From: |
Benja Fallenstein |
Subject: |
[Gzz-commits] gzz/gzz view/LinebrokenCellContentView.java vob... |
Date: |
Sat, 21 Sep 2002 17:49:05 -0400 |
CVSROOT: /cvsroot/gzz
Module name: gzz
Changes by: Benja Fallenstein <address@hidden> 02/09/21 17:49:04
Modified files:
gzz/view : LinebrokenCellContentView.java
gzz/vob : HChain.java LinebreakableChain.java
TextVob.java
Added files:
gzz/vob : HBroken.java SimpleLinebreaker.java
Log message:
Refactor LinebrokenCellContentView to use LinebreakableChain.
Not right yet, tho, because it doesn't do glue yet...
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/view/LinebrokenCellContentView.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/vob/HBroken.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/vob/SimpleLinebreaker.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/vob/HChain.java.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/vob/LinebreakableChain.java.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/vob/TextVob.java.diff?tr1=1.25&tr2=1.26&r1=text&r2=text
Patches:
Index: gzz/gzz/view/LinebrokenCellContentView.java
diff -c gzz/gzz/view/LinebrokenCellContentView.java:1.3
gzz/gzz/view/LinebrokenCellContentView.java:1.4
*** gzz/gzz/view/LinebrokenCellContentView.java:1.3 Wed Sep 18 08:55:45 2002
--- gzz/gzz/view/LinebrokenCellContentView.java Sat Sep 21 17:49:04 2002
***************
*** 38,109 ****
*/
public class LinebrokenCellContentView implements CellContentView {
! public static final String rcsid = "$Id: LinebrokenCellContentView.java,v 1.3
2002/09/18 12:55:45 benja Exp $";
public static boolean dbg = false;
private static void p(String s) { if(dbg) pa(s); }
private static void pa(String s) { System.err.println(s); }
- class Chain {
- Vob[] vobs = new Vob[20];
- Object[] keys = new Object[20];
- float[] widths = new float[20];
- boolean[] mustBreak = new boolean[20];
- int length = 0;
-
- void add(Vob v, Object key, float width) {
- if(++length > vobs.length) more();
- vobs[length-1] = v;
- keys[length-1] = key;
- widths[length-1] = width;
- }
-
- void addBreak() {
- add(null, null, 0);
- mustBreak[length-1] = true;
- }
-
- void breakBefore(int pos) {
- if(pos == 0) return;
- mustBreak[pos-1] = true;
- }
-
- void more() {
- Vob[] nvobs = new Vob[vobs.length*2];
- Object[] nkeys = new Object[keys.length*2];
- float[] nwidths = new float[widths.length*2];
- boolean[] nmustBreak = new boolean[mustBreak.length*2];
- System.arraycopy(vobs, 0, nvobs, 0, vobs.length);
- System.arraycopy(keys, 0, nkeys, 0, keys.length);
- System.arraycopy(widths, 0, nwidths, 0, widths.length);
- System.arraycopy(mustBreak, 0, nmustBreak, 0, mustBreak.length);
- vobs = nvobs; widths = nwidths;
- keys = nkeys; mustBreak = nmustBreak;
- }
-
- void breakLines(float width) {
- if(length == 0) return;
- if(width <= 0)
- throw new IllegalArgumentException("width == "+width+" <= 0");
-
- float x = 0;
- for(int i=0; i<length; i++) {
- x += widths[i];
- if(x > width) {
- breakBefore(i);
- x = widths[i];
- }
- }
- }
-
- int getLineCount() {
- int lines = 1;
- for(int i=0; i<length; i++)
- if(mustBreak[i]) lines++;
- return lines;
- }
- }
-
TextStyle style;
public LinebrokenCellContentView(TextStyle style) {
this.style = style;
--- 38,50 ----
*/
public class LinebrokenCellContentView implements CellContentView {
! public static final String rcsid = "$Id: LinebrokenCellContentView.java,v 1.4
2002/09/21 21:49:04 benja Exp $";
public static boolean dbg = false;
private static void p(String s) { if(dbg) pa(s); }
private static void pa(String s) { System.err.println(s); }
TextStyle style;
+ SimpleLinebreaker breaker = new SimpleLinebreaker();
public LinebrokenCellContentView(TextStyle style) {
this.style = style;
***************
*** 113,160 ****
* at a given width and scale.
*/
public float getHeight(Cell c, float forWidth, float scale) {
! Chain ch = getChain(c, scale);
! ch.breakLines(forWidth);
! int n = ch.getLineCount();
! return n * style.getHeight(scale);
}
static Rectangle box = new Rectangle();
! public void place(Cell c, VobScene v, int into, ViewContext context,
float scale) {
! Chain ch = getChain(c, scale);
! v.coords.getRenderInfo(into).getExtRect(box);
if(dbg) pa(""+box);
! ch.breakLines(box.width);
!
! float x = 0, y = 0;
! float h = style.getHeight(scale);
! for(int i=0; i<ch.length; i++) {
! float w = ch.widths[i];
! if(ch.vobs[i] != null) {
! if(dbg) {
! pa(i+" "+ch.vobs[i]+" "+ch.widths[i]+" "+ch.mustBreak[i]);
! pa(into+" "+ch.keys[i]+" "+0+" "+x+" "+y+" "+w+" "+h);
! }
! int cs = v.coords.coordsys(into, ch.keys[i], 0, x, y, w, h);
! v.map.put(ch.vobs[i], cs);
! }
!
! if(!ch.mustBreak[i])
! x += w;
! else {
! x = 0; y += h;
! }
! }
}
! protected Chain getChain(Cell c, float scale) {
/*Enfilade1D enf =
((VStreamCellTexter)c.space.getCellTexter()).getEnfilade(c);
String s = enf.makeString();*/
String s = c.t();
if (s == null) s = "";
! Chain ch = new Chain();
int pos = 0;
int last;
--- 54,81 ----
* at a given width and scale.
*/
public float getHeight(Cell c, float forWidth, float scale) {
! HChain ch = getChain(c, scale);
! HBroken br = breaker.breakLines(ch, forWidth, scale);
! return br.getHeight();
}
static Rectangle box = new Rectangle();
! public void place(Cell c, VobScene vs, int cs, ViewContext context, float
scale) {
! HChain ch = getChain(c, scale);
! vs.coords.getRenderInfo(cs).getExtRect(box);
if(dbg) pa(""+box);
! HBroken br = breaker.breakLines(ch, box.width, scale);
! br.put(vs, cs);
}
! protected HChain getChain(Cell c, float scale) {
/*Enfilade1D enf =
((VStreamCellTexter)c.space.getCellTexter()).getEnfilade(c);
String s = enf.makeString();*/
String s = c.t();
if (s == null) s = "";
! HChain ch = new LinebreakableChain();
int pos = 0;
int last;
***************
*** 180,191 ****
return ch;
}
! protected void addVobs(String s, Chain ch, int start, int end,
float scale) {
Object key = new Integer(start+1472);
s = s.substring(start, end);
if(dbg) pa("addVobs: "+start+" "+end+" '"+s+"'");
! TextVob vob = new TextVob(style, scale, s);
! ch.add(vob, key, style.getWidth(s, scale));
}
}
--- 101,112 ----
return ch;
}
! protected void addVobs(String s, HChain ch, int start, int end,
float scale) {
Object key = new Integer(start+1472);
s = s.substring(start, end);
if(dbg) pa("addVobs: "+start+" "+end+" '"+s+"'");
! TextVob vob = new TextVob(style, scale, s, key);
! ch.addBox(vob);
}
}
Index: gzz/gzz/vob/HChain.java
diff -c gzz/gzz/vob/HChain.java:1.2 gzz/gzz/vob/HChain.java:1.3
*** gzz/gzz/vob/HChain.java:1.2 Sat Sep 21 12:47:15 2002
--- gzz/gzz/vob/HChain.java Sat Sep 21 17:49:04 2002
***************
*** 45,53 ****
--- 45,66 ----
* or <code>GLUE_SHRINK</code>.
*/
float getGlue(int n, int property);
+
+ /** Get the number of forced line breaks before the
+ * <code>n</code>th box.
+ */
+ int getBreaks(int n);
void addBox(HBox box);
void addGlue(float length, float stretch, float shrink);
+
+ /** Add a forced line break at the current position.
+ * This is a "logical" line break, i.e. one in the text content,
+ * not one created by the line breaker. Line breakers should use
+ * <code>HBroken</code> to represent linebroken versions of an
+ * <code>HChain</code>.
+ */
+ void addBreak();
/** Get the height of a line given the index of the first and the
* index after the last box in that line. The height of the line is
Index: gzz/gzz/vob/LinebreakableChain.java
diff -c gzz/gzz/vob/LinebreakableChain.java:1.5
gzz/gzz/vob/LinebreakableChain.java:1.6
*** gzz/gzz/vob/LinebreakableChain.java:1.5 Sat Sep 21 12:53:34 2002
--- gzz/gzz/vob/LinebreakableChain.java Sat Sep 21 17:49:04 2002
***************
*** 26,36 ****
/** Default impl of <code>HChain</code>.
*/
public class LinebreakableChain implements HChain {
! String rcsid = "$Id: LinebreakableChain.java,v 1.5 2002/09/21 16:53:34 benja
Exp $";
public static final int GLUE_LENGTH = 0;
public static final int GLUE_STRETCH = 1;
public static final int GLUE_SHRINK = 2;
int nboxes;
protected HBox[] boxes;
--- 26,39 ----
/** Default impl of <code>HChain</code>.
*/
public class LinebreakableChain implements HChain {
! String rcsid = "$Id: LinebreakableChain.java,v 1.6 2002/09/21 21:49:04 benja
Exp $";
public static final int GLUE_LENGTH = 0;
public static final int GLUE_STRETCH = 1;
public static final int GLUE_SHRINK = 2;
+ public static final int BREAKS = 3;
+
+ protected static final int PROPERTIES = 4;
int nboxes;
protected HBox[] boxes;
***************
*** 57,65 ****
}
public void addGlue(float len, float str, float shr) {
! glues[nboxes*3 + GLUE_LENGTH] += len;
! glues[nboxes*3 + GLUE_STRETCH] += str;
! glues[nboxes*3 + GLUE_SHRINK] += shr;
}
public int length() {
--- 60,72 ----
}
public void addGlue(float len, float str, float shr) {
! glues[nboxes*PROPERTIES + GLUE_LENGTH] += len;
! glues[nboxes*PROPERTIES + GLUE_STRETCH] += str;
! glues[nboxes*PROPERTIES + GLUE_SHRINK] += shr;
! }
!
! public void addBreak() {
! glues[nboxes*PROPERTIES + BREAKS]++;
}
public int length() {
***************
*** 73,79 ****
public float getGlue(int n, int property) {
if(property < 0 || property > 2)
throw new IllegalArgumentException("illegal property: "+property);
! return glues[(n * 3) + property];
}
--- 80,90 ----
public float getGlue(int n, int property) {
if(property < 0 || property > 2)
throw new IllegalArgumentException("illegal property: "+property);
! return glues[(n * PROPERTIES) + property];
! }
!
! public int getBreaks(int n) {
! return (int)glues[(n * PROPERTIES) + BREAKS];
}
***************
*** 87,93 ****
*/
void allocCopy(int n) {
HBox[] nboxes = new HBox[n];
! float[] nglues = new float[3*(n+1)];
if(boxes != null) {
System.arraycopy(boxes, 0, nboxes, 0, boxes.length);
System.arraycopy(glues, 0, nglues, 0, glues.length);
--- 98,104 ----
*/
void allocCopy(int n) {
HBox[] nboxes = new HBox[n];
! float[] nglues = new float[PROPERTIES*(n+1)];
if(boxes != null) {
System.arraycopy(boxes, 0, nboxes, 0, boxes.length);
System.arraycopy(glues, 0, nglues, 0, glues.length);
Index: gzz/gzz/vob/TextVob.java
diff -c gzz/gzz/vob/TextVob.java:1.25 gzz/gzz/vob/TextVob.java:1.26
*** gzz/gzz/vob/TextVob.java:1.25 Sat Sep 21 09:04:56 2002
--- gzz/gzz/vob/TextVob.java Sat Sep 21 17:49:04 2002
***************
*** 31,37 ****
* from these and use a LineBreaker.
*/
public class TextVob extends HBox.VobHBox {
! String rcsid = "$Id: TextVob.java,v 1.25 2002/09/21 13:04:56 benja Exp $";
public static boolean dbg = false;
private static void pa(String s) { System.err.println(s); }
--- 31,37 ----
* from these and use a LineBreaker.
*/
public class TextVob extends HBox.VobHBox {
! String rcsid = "$Id: TextVob.java,v 1.26 2002/09/21 21:49:04 benja Exp $";
public static boolean dbg = false;
private static void pa(String s) { System.err.println(s); }
***************
*** 41,46 ****
--- 41,48 ----
* XXX Performance?
*/
protected float scale;
+
+ protected Object key;
public TextVob(TextStyle style, String text) {
super();
***************
*** 54,63 ****
this.scale = scale;
}
public String getText() { return text; }
public Object getKey() {
! throw new UnsupportedOperationException("not implemented");
}
public float getScale() { return scale; }
--- 56,70 ----
this.scale = scale;
}
+ public TextVob(TextStyle style, float scale, String text, Object key) {
+ this(style, scale, text);
+ this.key = key;
+ }
+
public String getText() { return text; }
public Object getKey() {
! return key;
}
public float getScale() { return scale; }
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gzz-commits] gzz/gzz view/LinebrokenCellContentView.java vob...,
Benja Fallenstein <=