- //#repeat col/row colspan/rowspan contentwidth/contentheight width/height HSHRINK/VSHRINK \
- // maxwidth/maxheight cols/rows minwidth/minheight lp_h/lp_v lp_h/lp_v
- do {
- int nc = numkids * 2 + cols * 3 + 1 + 2;
- if (coeff == null || nc+1>coeff.length) coeff = new float[nc+1];
- lp_h.init(nc);
-
- // objective function
- for(int i=0; i<coeff.length; i++) coeff[i] = (float)0.0;
- coeff[cols*2+numkids] = (float)10000.0; // priority 1: sum of columns equals parent
- for(int i=cols*2; i<cols*2+numkids; i++) coeff[i] = (float)100.0; // priority 2: honor maxwidths
- for(int i=cols; i<cols*2; i++) coeff[i] = (float)(1.0); // priority 3: equalize columns
- lp_h.setObjective(coeff, false);
-
- // priority 1: sum of columns at least as big as parent
- for(int i=0; i<coeff.length; i++) coeff[i] = (i<cols) ? (float)1.0 : (float)0.0;
- lp_h.add_constraint(coeff, LinearProgramming.GE, (float)width);
- for(int i=0; i<coeff.length; i++) coeff[i] = (i<cols) ? (float)1.0 : (float)0.0;
- coeff[cols*2+numkids] = (float)1.0;
- lp_h.add_constraint(coeff, LinearProgramming.EQ, (float)width);
-
- // priority 2: honor maxwidths
- int childnum = 0;
- for(Box child = firstPackedChild(); child != null; child = child.nextPackedSibling()) {
- for(int i=0; i<coeff.length; i++)
- coeff[i] = (i>=child.col && i<min(child.colspan+child.col, cols)) ? (float)1.0 : (float)0.0;
- lp_h.add_constraint(coeff, LinearProgramming.GE, (float)child.contentwidth);
- int child_maxwidth = child.test(HSHRINK) ? min(child.maxwidth, child.contentwidth) : child.maxwidth;
- if (child_maxwidth < Integer.MAX_VALUE) {
- for(int i=0; i<coeff.length; i++)
- coeff[i] = (i>=child.col && i<min(child.colspan+child.col, cols)) ? (float)1.0 : (float)0.0;
- coeff[cols*2+childnum] = (float)-1.0;
- lp_h.add_constraint(coeff, LinearProgramming.EQ, (float)child_maxwidth);
- }
- for(int j=0; j<coeff.length; j++) coeff[j] = (float)0.0;
- childnum++;
+ //#repeat col/row colspan/rowspan contentwidth/contentheight width/height HSHRINK/VSHRINK numregions/numregions_v \
+ // maxwidth/maxheight cols/rows minwidth/minheight regions/regions_v targetColumnSize/targetRowSize sizes/sizes_v \
+ // HSHRINK/VSHRINK
+ if (numkids == 0) {
+ if (findMinimum) contentwidth = 0;
+ else targetColumnSize = 0;
+ } else if (cols == 1) {
+ if (findMinimum) {
+ contentwidth = 0;
+ for(Box c = firstPackedChild(); c != null; c = c.nextPackedSibling())
+ contentwidth = max(contentwidth, c.contentwidth);
+ } else {
+ targetColumnSize = width;
+ }
+ } else if (cols > 1) do {
+
+ // FIXME: cache these?
+ // compute regions
+ numregions = 0;
+ for(Box c = firstPackedChild(); c != null; c = c.nextPackedSibling()) {
+ regions[numregions++] = c.col;
+ regions[numregions++] = min(cols, c.col+c.colspan);