28 |
return new Layout(enf); |
return new Layout(enf); |
29 |
} |
} |
30 |
|
|
31 |
|
public Layout getLayout(ScrollBlock sb) { |
32 |
|
return new Layout((PageSpan)sb.getCurrent()); // XXX Cache |
33 |
|
} |
34 |
|
|
35 |
public void getSize(Enfilade1D enf, float[] out) { |
public void getSize(Enfilade1D enf, float[] out) { |
36 |
Layout l = getLayout(enf); |
Layout l = getLayout(enf); |
37 |
out[0] = l.w; |
out[0] = l.w; |
49 |
float w; |
float w; |
50 |
float h; |
float h; |
51 |
|
|
52 |
|
/** Allocate the structure to hold a given number of pages. |
53 |
public Layout(Enfilade1D enf) { |
*/ |
54 |
npages = enf.length(); |
private void alloc(int size) { |
55 |
|
npages = size; |
56 |
pages = new PageSpan[npages]; |
pages = new PageSpan[npages]; |
57 |
psps = new PageSpanPaper[npages]; |
psps = new PageSpanPaper[npages]; |
58 |
xywh = new float[npages * 4]; // x, y, w, h in PAPER coordinates |
xywh = new float[npages * 4]; // x, y, w, h in PAPER coordinates |
59 |
w = 0; |
w = 0; |
60 |
h = 0; |
h = 0; |
61 |
|
} |
62 |
|
|
63 |
|
/** (To be called with increasing p): add a page. |
64 |
|
*/ |
65 |
|
private void page(int p, PageSpan sp) { |
66 |
|
pages[p] = sp; |
67 |
|
GLSpanner.SpanRect rect = GLSpanner.getSpanRect(pages[p]); |
68 |
|
psps[p] = new PageSpanPaper(null, rect.page); |
69 |
|
|
70 |
|
Point l_p = pages[p].getLocation(); |
71 |
|
Dimension d_p = pages[p].getSize(); |
72 |
|
|
73 |
|
xywh[4*p + 0] = psps[p].getX(l_p.x); |
74 |
|
xywh[4*p + 1] = psps[p].getY(l_p.y); |
75 |
|
xywh[4*p + 2] = psps[p].getX(d_p.width); |
76 |
|
xywh[4*p + 3] = psps[p].getY(d_p.height); |
77 |
|
|
78 |
|
if(dbg) pa("Page "+p+" "+ |
79 |
|
xywh[4*p+0]+" "+ |
80 |
|
xywh[4*p+1]+" "+ |
81 |
|
xywh[4*p+2]+" "+ |
82 |
|
xywh[4*p+3]+" "+ |
83 |
|
pages[p]); |
84 |
|
|
85 |
|
w += scale * xywh[4*p + 2]; |
86 |
|
if(h < scale * xywh[4*p + 3]) |
87 |
|
h = scale * xywh[4*p + 3]; |
88 |
|
} |
89 |
|
|
90 |
boolean foundCenter = false; |
public Layout(Enfilade1D enf) { |
91 |
|
alloc(enf.length()); |
92 |
|
|
93 |
for(int p = 0; p < npages; p++) { |
for(int p = 0; p < npages; p++) { |
94 |
pages[p] = (PageSpan)enf.sub(p, p+1).getList().get(0); // XXX INEFFICIENT! |
// XXX INEFFICIENT! |
95 |
GLSpanner.SpanRect rect = GLSpanner.getSpanRect(pages[p]); |
page(p, (PageSpan)enf.sub(p, p+1).getList().get(0)); |
|
psps[p] = new PageSpanPaper(null, rect.page); |
|
|
|
|
|
Point l_p = pages[p].getLocation(); |
|
|
Dimension d_p = pages[p].getSize(); |
|
|
|
|
|
xywh[4*p + 0] = psps[p].getX(l_p.x); |
|
|
xywh[4*p + 1] = psps[p].getY(l_p.y); |
|
|
xywh[4*p + 2] = psps[p].getX(d_p.width); |
|
|
xywh[4*p + 3] = psps[p].getY(d_p.height); |
|
|
|
|
|
if(dbg) pa("Page "+p+" "+ |
|
|
xywh[4*p+0]+" "+ |
|
|
xywh[4*p+1]+" "+ |
|
|
xywh[4*p+2]+" "+ |
|
|
xywh[4*p+3]+" "+ |
|
|
pages[p]); |
|
|
|
|
|
w += scale * xywh[4*p + 2]; |
|
|
if(h < scale * xywh[4*p + 3]) |
|
|
h = scale * xywh[4*p + 3]; |
|
96 |
} |
} |
97 |
|
|
98 |
|
} |
99 |
|
|
100 |
|
public Layout(PageSpan sp) { |
101 |
|
alloc(sp.length()); |
102 |
|
|
103 |
|
for(int p = 0; p < npages; p++) { |
104 |
|
page(p, (PageSpan)sp.subSpan(p, p+1)); |
105 |
|
} |
106 |
|
|
107 |
} |
} |
108 |
|
|
109 |
|
|
110 |
/** Get the extents (in the output coordinates) |
/** Get the extents (in the output coordinates) |
111 |
* of a given page span. |
* of a given page span. |
112 |
* Currently, only the first intersecting page |
* Currently, only the first intersecting page |