45 |
private static void p(String s) { if(dbg) pa(s); } |
private static void p(String s) { if(dbg) pa(s); } |
46 |
private static void pa(String s) { System.err.println(s); } |
private static void pa(String s) { System.err.println(s); } |
47 |
|
|
48 |
static Object ARGH_KEY = new Object(); |
static Object CONTENT_KEY = new Object(); |
49 |
|
static Object CURSOR_KEY = new Object(); |
50 |
|
LineVob cursorVob = new LineVob(0, 0, 0, 1, Color.black); |
51 |
|
|
52 |
TextStyle style; |
TextStyle style; |
53 |
SimpleLinebreaker breaker = new SimpleLinebreaker(); |
SimpleLinebreaker breaker = new SimpleLinebreaker(); |
64 |
this.widthString = widthString; |
this.widthString = widthString; |
65 |
} |
} |
66 |
|
|
67 |
/** Get the height necessary to layout *all* text in a cell, |
/** Get the height necessary to layout a range of text in a cell, |
68 |
* at a given width and scale. |
* at a given width and scale. |
69 |
*/ |
*/ |
70 |
public float getHeight(Cell c, float forWidth, float scale) { |
public float getHeight(Cell c, float forWidth, float scale) { |
93 |
} |
} |
94 |
|
|
95 |
static Rectangle box = new Rectangle(); |
static Rectangle box = new Rectangle(); |
96 |
float[] boxwh = new float[2]; |
float[] boxwh = new float[2], xoffsarr = new float[1]; |
97 |
public void place(Cell c, VobScene vs, int box, |
public void place(Cell c, VobScene vs, int box, |
98 |
ViewContext context) { |
ViewContext context) { |
99 |
float scale = 1; // XXX getFontScale (see PEG vobcoorder_fontscale--tjl) |
float scale = 1; // XXX getFontScale (see PEG vobcoorder_fontscale--tjl) |
|
HChain ch = getChain(c, scale); |
|
100 |
vs.coords.getSqSize(box, boxwh); |
vs.coords.getSqSize(box, boxwh); |
101 |
if(dbg) pa(""+boxwh[0]); |
if(dbg) pa(""+boxwh[0]); |
102 |
|
|
103 |
|
int pos = context.getCursorOffset(c); |
104 |
|
float line_height = style.getHeight(scale); |
105 |
|
float xoffs = 0, yoffs0 = 0, yoffs1 = 0; |
106 |
|
|
107 |
|
HChain ch = getChain(c, scale); |
108 |
HBroken br = breaker.breakLines(ch, boxwh[0], scale); |
HBroken br = breaker.breakLines(ch, boxwh[0], scale); |
109 |
br.put(vs, box); |
|
110 |
|
if(pos >= 0) { |
111 |
|
int line = br.getLine(pos, xoffsarr); |
112 |
|
xoffs = xoffsarr[0]; |
113 |
|
yoffs0 = br.getLineOffset(line-1); |
114 |
|
yoffs1 = br.getLineOffset(line); |
115 |
|
} |
116 |
|
|
117 |
|
float h = br.getHeight(); |
118 |
|
float middle = boxwh[1]/2; |
119 |
|
float yoffs = (yoffs0 + yoffs1) / 2; |
120 |
|
|
121 |
|
int content; |
122 |
|
if(h < boxwh[1] || yoffs < middle) |
123 |
|
content = vs.translateCS(box, CONTENT_KEY, 0, 0); |
124 |
|
else if(yoffs > h-middle) |
125 |
|
content = vs.translateCS(box, CONTENT_KEY, 0, -h + boxwh[1]); |
126 |
|
else |
127 |
|
content = vs.translateCS(box, CONTENT_KEY, 0, -yoffs + middle); |
128 |
|
|
129 |
|
br.put(vs, content); |
130 |
|
|
131 |
|
if(pos >= 0) { |
132 |
|
int cursor = vs.orthoCS(content, CURSOR_KEY, -1, |
133 |
|
xoffs, yoffs0, |
134 |
|
1, line_height); |
135 |
|
vs.map.put(cursorVob, cursor); |
136 |
|
} |
137 |
} |
} |
138 |
|
|
139 |
protected HChain getChain(Cell c, float scale) { |
protected HChain getChain(Cell c, float scale) { |
140 |
String s = Containment.getContainedText(c); |
String s = Containment.getContainedText(c); |
141 |
|
return getChain(s, scale); |
142 |
|
} |
143 |
|
|
144 |
|
protected HChain getChain(String s, float scale) { |
145 |
if (s == null) s = ""; |
if (s == null) s = ""; |
146 |
|
|
147 |
HChain ch = new LinebreakableChain(); |
HChain ch = new LinebreakableChain(); |
162 |
|
|
163 |
addVobs(s, ch, last, pos, scale); |
addVobs(s, ch, last, pos, scale); |
164 |
if(pos == br) { |
if(pos == br) { |
165 |
|
ch.addBox(new HBox.Null(1)); |
166 |
ch.addBreak(); |
ch.addBreak(); |
167 |
pos++; |
pos++; |
168 |
} |
} |