43 |
private static void p(String s) { if(dbg) pa(s); } |
private static void p(String s) { if(dbg) pa(s); } |
44 |
private static void pa(String s) { System.err.println(s); } |
private static void pa(String s) { System.err.println(s); } |
45 |
|
|
|
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; |
|
|
} |
|
|
} |
|
|
|
|
46 |
TextStyle style; |
TextStyle style; |
47 |
|
SimpleLinebreaker breaker = new SimpleLinebreaker(); |
48 |
|
|
49 |
public LinebrokenCellContentView(TextStyle style) { |
public LinebrokenCellContentView(TextStyle style) { |
50 |
this.style = style; |
this.style = style; |
54 |
* at a given width and scale. |
* at a given width and scale. |
55 |
*/ |
*/ |
56 |
public float getHeight(Cell c, float forWidth, float scale) { |
public float getHeight(Cell c, float forWidth, float scale) { |
57 |
Chain ch = getChain(c, scale); |
HChain ch = getChain(c, scale); |
58 |
ch.breakLines(forWidth); |
HBroken br = breaker.breakLines(ch, forWidth, scale); |
59 |
int n = ch.getLineCount(); |
return br.getHeight(); |
|
return n * style.getHeight(scale); |
|
60 |
} |
} |
61 |
|
|
62 |
static Rectangle box = new Rectangle(); |
static Rectangle box = new Rectangle(); |
63 |
public void place(Cell c, VobScene v, int into, ViewContext context, float scale) { |
public void place(Cell c, VobScene vs, int cs, ViewContext context, float scale) { |
64 |
Chain ch = getChain(c, scale); |
HChain ch = getChain(c, scale); |
65 |
v.coords.getRenderInfo(into).getExtRect(box); |
vs.coords.getRenderInfo(cs).getExtRect(box); |
66 |
if(dbg) pa(""+box); |
if(dbg) pa(""+box); |
67 |
ch.breakLines(box.width); |
HBroken br = breaker.breakLines(ch, box.width, scale); |
68 |
|
br.put(vs, cs); |
|
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; |
|
|
} |
|
|
} |
|
69 |
} |
} |
70 |
|
|
71 |
protected Chain getChain(Cell c, float scale) { |
protected HChain getChain(Cell c, float scale) { |
72 |
/*Enfilade1D enf = |
/*Enfilade1D enf = |
73 |
((VStreamCellTexter)c.space.getCellTexter()).getEnfilade(c); |
((VStreamCellTexter)c.space.getCellTexter()).getEnfilade(c); |
74 |
String s = enf.makeString();*/ |
String s = enf.makeString();*/ |
75 |
String s = c.t(); |
String s = c.t(); |
76 |
if (s == null) s = ""; |
if (s == null) s = ""; |
77 |
|
|
78 |
Chain ch = new Chain(); |
HChain ch = new LinebreakableChain(); |
79 |
|
|
80 |
int pos = 0; |
int pos = 0; |
81 |
int last; |
int last; |
101 |
return ch; |
return ch; |
102 |
} |
} |
103 |
|
|
104 |
protected void addVobs(String s, Chain ch, int start, int end, |
protected void addVobs(String s, HChain ch, int start, int end, |
105 |
float scale) { |
float scale) { |
106 |
Object key = new Integer(start+1472); |
Object key = new Integer(start+1472); |
107 |
s = s.substring(start, end); |
s = s.substring(start, end); |
108 |
if(dbg) pa("addVobs: "+start+" "+end+" '"+s+"'"); |
if(dbg) pa("addVobs: "+start+" "+end+" '"+s+"'"); |
109 |
TextVob vob = new TextVob(style, scale, s); |
TextVob vob = new TextVob(style, scale, s, key); |
110 |
ch.add(vob, key, style.getWidth(s, scale)); |
ch.addBox(vob); |
111 |
} |
} |
112 |
} |
} |