34 |
import org.nongnu.libvob.*; |
import org.nongnu.libvob.*; |
35 |
import org.nongnu.libvob.gl.*; |
import org.nongnu.libvob.gl.*; |
36 |
import org.nongnu.alph.*; |
import org.nongnu.alph.*; |
37 |
|
import org.fenfire.spanimages.*; |
38 |
|
|
39 |
/** A single pagespan enfilade laid out on the plane. |
/** A single pagespan enfilade laid out on the plane. |
40 |
*/ |
*/ |
44 |
public static boolean dbg = false; |
public static boolean dbg = false; |
45 |
private void p(String s) { System.out.println("PageSpanLayout:: "+s); } |
private void p(String s) { System.out.println("PageSpanLayout:: "+s); } |
46 |
|
|
47 |
public static final float scale = 72 * 6; |
public static SpanImageFactory spanImageFactory = |
48 |
|
SpanImageFactory.getDefaultInstance(); |
|
public static float diceLength = 2f; |
|
|
public static float diceLength2 = 16f; |
|
|
public static int diceDepth = 20; |
|
|
public static int flags = 2; |
|
|
|
|
|
public interface PageSpanPaperMaker { |
|
|
PageSpanPaper getPaper(GLSpanner.SpanPage p, PageImageSpan sp); |
|
|
} |
|
|
public static class DefaultPageSpanPaperMaker implements PageSpanPaperMaker { |
|
|
public PageSpanPaper getPaper(GLSpanner.SpanPage p, PageImageSpan sp) { |
|
|
return new PageSpanPaper(p, sp.getScrollBlock().hashCode()); |
|
|
} |
|
|
} |
|
|
static public final DefaultPageSpanPaperMaker defaultPageSpanPaperMaker = new DefaultPageSpanPaperMaker(); |
|
|
|
|
|
public boolean useBg = true; |
|
|
public boolean useText = true; |
|
49 |
|
|
50 |
private int npages; |
private int npages; |
51 |
private PageImageSpan[] pages; |
private PageImageSpan[] pages; |
52 |
private PageSpanPaper[] psps; |
private SpanImageVob[] spivs; |
53 |
private float[] xywh; |
private float[] xywh; |
54 |
|
|
55 |
private float w; |
private float w; |
63 |
private void alloc(int size) { |
private void alloc(int size) { |
64 |
npages = size; |
npages = size; |
65 |
pages = new PageImageSpan[npages]; |
pages = new PageImageSpan[npages]; |
66 |
psps = new PageSpanPaper[npages]; |
spivs = new SpanImageVob[npages]; |
67 |
xywh = new float[npages * 4]; // x, y, w, h in PAPER coordinates |
xywh = new float[npages * 4]; // x, y, w, h in PAPER coordinates |
68 |
w = 0; |
w = 0; |
69 |
h = 0; |
h = 0; |
71 |
|
|
72 |
/** (To be called with increasing p): add a page. |
/** (To be called with increasing p): add a page. |
73 |
*/ |
*/ |
74 |
private void page(int p, PageImageSpan sp, PageSpanPaperMaker pageSpanPaperMaker) { |
private void page(int p, PageImageSpan sp, |
75 |
|
SpanImageFactory spanImageFactory) { |
76 |
pages[p] = sp; |
pages[p] = sp; |
|
GLSpanner.SpanRect rect = GLSpanner.getSpanRect(pages[p]); |
|
|
psps[p] = pageSpanPaperMaker.getPaper(rect.page, sp); |
|
77 |
|
|
78 |
Point l_p = pages[p].getLocation(); |
spivs[p] = spanImageFactory.getSpanImageVob(sp); |
|
Dimension d_p = pages[p].getSize(); |
|
79 |
|
|
80 |
xywh[4*p + 0] = psps[p].getX(l_p.x); |
xywh[4*p + 0] = 0; |
81 |
xywh[4*p + 1] = psps[p].getY(l_p.y); |
xywh[4*p + 1] = 0; |
82 |
xywh[4*p + 2] = psps[p].getX(d_p.width); |
xywh[4*p + 2] = spivs[p].getWidth(); |
83 |
xywh[4*p + 3] = psps[p].getY(d_p.height); |
xywh[4*p + 3] = spivs[p].getHeight(); |
84 |
|
|
85 |
if(dbg) p("Page "+p+" "+ |
if(dbg) p("Page "+p+" "+ |
86 |
xywh[4*p+0]+" "+ |
xywh[4*p+0]+" "+ |
89 |
xywh[4*p+3]+" "+ |
xywh[4*p+3]+" "+ |
90 |
pages[p]); |
pages[p]); |
91 |
|
|
92 |
w += scale * xywh[4*p + 2]; |
w += xywh[4*p + 2]; |
93 |
if(h < scale * xywh[4*p + 3]) |
if(h < xywh[4*p + 3]) |
94 |
h = scale * xywh[4*p + 3]; |
h = xywh[4*p + 3]; |
95 |
} |
} |
96 |
|
|
97 |
public PageSpanLayout(Enfilade1D enf) { |
public PageSpanLayout(Enfilade1D enf) { |
98 |
this(enf, defaultPageSpanPaperMaker); |
this(enf, spanImageFactory); |
99 |
} |
} |
100 |
public PageSpanLayout(Enfilade1D enf, PageSpanPaperMaker maker) { |
public PageSpanLayout(Enfilade1D enf, |
101 |
|
SpanImageFactory spanImageFactory) { |
102 |
alloc(enf.length()); |
alloc(enf.length()); |
103 |
|
|
104 |
for(int p = 0; p < npages; p++) { |
for(int p = 0; p < npages; p++) { |
106 |
Object span = enf.sub(p, p+1).getList().get(0); |
Object span = enf.sub(p, p+1).getList().get(0); |
107 |
if(span instanceof PageSpan) |
if(span instanceof PageSpan) |
108 |
span = ((PageSpan)span).getPage(0); |
span = ((PageSpan)span).getPage(0); |
109 |
page(p, (PageImageSpan)span, maker); |
page(p, (PageImageSpan)span, spanImageFactory); |
110 |
} |
} |
111 |
|
|
112 |
} |
} |
113 |
|
|
114 |
public PageSpanLayout(PageSpan sp) { |
public PageSpanLayout(PageSpan sp) { |
115 |
this(sp, defaultPageSpanPaperMaker); |
this(sp, spanImageFactory); |
116 |
} |
} |
117 |
|
|
118 |
public PageSpanLayout(PageSpan sp, PageSpanPaperMaker maker) { |
public PageSpanLayout(PageSpan sp, |
119 |
|
SpanImageFactory spanImageFactory) { |
120 |
alloc(sp.length()); |
alloc(sp.length()); |
121 |
|
|
122 |
for(int p = 0; p < npages; p++) { |
for(int p = 0; p < npages; p++) { |
123 |
page(p, sp.getPage(p), maker); |
page(p, sp.getPage(p), spanImageFactory); |
124 |
} |
} |
125 |
} |
} |
126 |
|
|
127 |
public PageSpanLayout(PageImageSpan sp) { |
public PageSpanLayout(PageImageSpan sp) { |
128 |
this(sp, defaultPageSpanPaperMaker); |
this(sp, spanImageFactory); |
129 |
} |
} |
130 |
|
|
131 |
public PageSpanLayout(PageImageSpan sp, PageSpanPaperMaker maker) { |
public PageSpanLayout(PageImageSpan sp, |
132 |
page(0, sp, maker); |
SpanImageFactory spanImageFactory) { |
133 |
|
page(0, sp, spanImageFactory); |
134 |
} |
} |
135 |
|
|
136 |
|
|
149 |
Point l_c = s.getLocation(); |
Point l_c = s.getLocation(); |
150 |
Dimension d_c = s.getSize(); |
Dimension d_c = s.getSize(); |
151 |
|
|
152 |
xywh_out[0] = curw + scale * psps[p].getX(l_c.x); |
float x0 = spivs[p].getRealX(l_c.x); |
153 |
xywh_out[2] = scale * psps[p].getX(d_c.width); |
float x1 = spivs[p].getRealX(l_c.x+d_c.width); |
154 |
|
float y0 = spivs[p].getRealY(l_c.y); |
155 |
|
float y1 = spivs[p].getRealY(l_c.y+d_c.height); |
156 |
|
|
157 |
xywh_out[1] = scale * ( |
xywh_out[0] = curw + x0; |
158 |
psps[p].getY(l_c.y) - xywh[4*p + 1]); |
xywh_out[2] = x1-x0; |
159 |
xywh_out[3] = scale * psps[p].getY(d_c.height); |
|
160 |
|
xywh_out[1] = y0; |
161 |
|
xywh_out[3] = y1-y0; |
162 |
|
|
163 |
if(dbg) p("Center found: "+p+" "+pages[p]+" "+ |
if(dbg) p("Center found: "+p+" "+pages[p]+" "+ |
164 |
xywh_out[0] + " " + xywh_out[1] + " " + |
xywh_out[0] + " " + xywh_out[1] + " " + |
166 |
|
|
167 |
return xywh_out; |
return xywh_out; |
168 |
} |
} |
169 |
curw += scale * xywh[4*p + 2]; |
curw += xywh[4*p + 2]; |
170 |
} |
} |
171 |
return null; |
return null; |
172 |
} |
} |
173 |
|
|
174 |
public void place(VobScene vs, int into) { |
public void place(VobScene vs, int into) { |
175 |
place(vs, into, .0001f, 1f, -1); |
place(vs, into, -1, -1); |
176 |
} |
} |
177 |
|
|
|
public void place(VobScene vs, int into, float importance, float pixelscale) { |
|
|
|
|
|
place(vs, into, importance, pixelscale, -1); |
|
|
} |
|
178 |
/** Place this layout into the given coordinate system. |
/** Place this layout into the given coordinate system. |
179 |
* Note that the layout is not affected by the |
* Note that the layout is not affected by the |
180 |
* box size of the coordinate system. |
* box size of the coordinate system. |
181 |
* @param cullCS The coordinate system against which |
* @param cullCS The coordinate system against which |
182 |
* all objects should be culled. |
* all objects should be culled. |
183 |
|
* @param matchCS the matching parent for the spans as keys of |
184 |
|
* coordinate systems |
185 |
*/ |
*/ |
186 |
public void place(VobScene vs, int into, float importance, float pixelscale, int cullCS) { |
public void place(VobScene vs, int into, int cullCS, int matchCs) { |
|
this.place(vs, into, importance, pixelscale, cullCS, into); |
|
|
} |
|
|
public void place(VobScene vs, int into, float importance, float pixelscale, int cullCS, |
|
|
int matchCs) { |
|
187 |
float curx = 0; |
float curx = 0; |
188 |
// Now we can draw the pages. |
// Now we can draw the pages. |
189 |
|
if(matchCs < 0) matchCs = into; |
190 |
for(int p = 0; p < npages; p++) { |
for(int p = 0; p < npages; p++) { |
191 |
|
if(dbg) p("Place page: "+p+" "+spivs[p]+" "+curx+" "+ |
192 |
|
+ xywh[4*p+2]+" "+ |
193 |
|
+ xywh[4*p+3]+" "); |
194 |
// We want a coordinate system |
// We want a coordinate system |
195 |
// whose box is exactly the span |
// whose box is exactly the span |
196 |
int around = vs.coords.orthoBox(into, 0, |
int around = vs.coords.orthoBox(into, 0, |
197 |
curx, 0, scale, scale, |
curx, 0, 1, 1, |
198 |
xywh[4*p+2], xywh[4*p+3]); |
xywh[4*p+2], xywh[4*p+3]); |
199 |
vs.matcher.add(matchCs, around, pages[p]); |
vs.matcher.add(matchCs, around, pages[p]); |
200 |
if(cullCS >= 0) |
if(cullCS >= 0) |
201 |
around = vs.cullCS(around, "CULL", cullCS); |
around = vs.cullCS(around, "CULL", cullCS); |
202 |
// and then translate to the whole page. |
|
203 |
int tr = vs.translateCS(around, "T", -xywh[4*p+0], -xywh[4*p+1]); |
curx += xywh[4*p + 2]; |
204 |
curx += scale * xywh[4*p + 2]; |
|
205 |
|
vs.map.put(spivs[p], around); |
|
psps[p].request(importance, scale * pixelscale); |
|
|
|
|
|
vs.map.put(GLRen.createFixedPaperQuad(psps[p].getPaper(useBg, useText), |
|
|
xywh[4*p + 0], |
|
|
xywh[4*p + 1], |
|
|
xywh[4*p + 0]+xywh[4*p + 2], |
|
|
xywh[4*p + 1]+xywh[4*p + 3], flags, |
|
|
diceLength, |
|
|
diceLength2, |
|
|
diceDepth |
|
|
), tr); |
|
206 |
} |
} |
207 |
} |
} |
208 |
|
|
211 |
* Note that this won't interpolate nicely to |
* Note that this won't interpolate nicely to |
212 |
* "place". |
* "place". |
213 |
*/ |
*/ |
214 |
public void placeBoxed(VobScene vs, int into, float importance, float pixelscale) { |
public void placeBoxed(VobScene vs, int into) { |
215 |
int unit = vs.unitSqCS(into, "PSPCV.UNIT"); |
int unit = vs.unitSqCS(into, "PSPCV.UNIT"); |
216 |
int scaled = vs.scaleCS(unit, "PSPCV.SCALED", |
int scaled = vs.scaleCS(unit, "PSPCV.SCALED", |
217 |
1.0f / w, 1.0f / h); |
1.0f / w, 1.0f / h); |
218 |
place(vs, scaled, importance, pixelscale); |
place(vs, scaled); |
219 |
} |
} |
220 |
|
|
|
/** Make a request for loading the textures into memory. |
|
|
*/ |
|
|
public void request(float x, float y, float radius, |
|
|
float importanceAt, |
|
|
float importanceOutside, |
|
|
float pixelscale) { |
|
|
if(dbg) p("Request: "+x+" "+y+" "+radius); |
|
|
float curx = 0; |
|
|
for(int p = 0; p < npages; p++) { |
|
|
float dx = Math.abs((curx + .5f * scale * xywh[4*p+2]) - x) - .5f*scale * xywh[4*p+2]; |
|
|
float dy = Math.abs((.5f * scale * xywh[4*p+3]) - y) - .5f*scale * xywh[4*p+3]; |
|
|
if(dbg) p("RequestCoords: "+xywh[4*p+0]+" "+xywh[4*p+1]+" "+ |
|
|
xywh[4*p+2]+" "+xywh[4*p+3]); |
|
|
float dist = Math.max(dx, dy); |
|
|
if(dist < 0) { |
|
|
psps[p].request(importanceAt, pixelscale); |
|
|
} else if(dist < radius) { |
|
|
if(dbg) p("Request DO: "+dx+" "+dy); |
|
|
psps[p].request(importanceOutside * (1-dist/radius), |
|
|
pixelscale); |
|
|
} |
|
|
curx += scale * xywh[4*p + 2]; |
|
|
} |
|
|
} |
|
221 |
|
|
222 |
} |
} |
223 |
|
|