- lp_h.setObjective(coeff, false);
-
- // priority 1: sum of columns as close to parent's width as possible
- for(int i=0; i<coeff.length; i++) coeff[i] = (i<numregions) ? (float)(regions[i+1] - regions[i]) : (float)0.0;
- coeff[numregions*2+numkids] = (float)-1.0;
- if (!findMinimum) lp_h.add_constraint(coeff, Simplex.EQ, (float)width);
- else lp_h.add_constraint(coeff, Simplex.LE, (float)0);
-
- int childnum = 0;
- for(Box child = firstPackedChild(); child != null; child = child.nextPackedSibling()) {
-
- // invariant: honor minwidths
- for(int i=0; i<coeff.length; i++) coeff[i] = (float)0.0;
- for(int r=0; r<numregions; r++)
- if (regions[r] >= child.col && regions[r+1] <= min(child.col+child.colspan,cols))
- coeff[r] = (float)(regions[r+1] - regions[r]);
- lp_h.add_constraint(coeff, Simplex.GE, (float)child.contentwidth);
- if (!findMinimum) {
- // priority 2: honor maxwidths
- 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] = (float)0.0;
- for(int r=0; r<numregions; r++)
- if (regions[r] >= child.col && regions[r+1] <= min(child.col+child.colspan,cols))
- coeff[r] = (float)(regions[r+1] - regions[r]);
- coeff[numregions*2+childnum] = (float)-1.0;
- lp_h.add_constraint(coeff, Simplex.LE, (float)child_maxwidth);
+ } else if (cols > 1) do {
+ computeRegions();
+ int target = findMinimum ? 0 : Math.max(width, contentwidth);
+ // priority 0: (inviolable) honor minwidths
+ // priority 1: sum of columns no greater than parent
+ // priority 2: honor maxwidths
+ // priority 3: equalize columns
+ float targetColumnSize = target == 0 ? 0 : this.targetColumnSize;
+ float last_columnsize = 0;
+ float last_total = 0;
+ float total;
+ boolean first = true;
+ while(true) {
+ total = (float)0.0;
+ for(int r=0; r<numregions; r++) total += (sizes[r] = (float)(targetColumnSize * (regions[r+1]-regions[r])));
+ int minregion = 0;
+ for(Box child = firstPackedChild(); child != null; child = child.nextPackedSibling())
+ for(int r=(child.col==0?0:minregion); r<numregions; r++) {
+ if (regions[r+1] < child.col) continue;
+ if (regions[r] >= min(child.col+child.colspan,cols)) { minregion = r; break; }
+ total -= sizes[r];
+ if (sizes[r] <= (float)(targetColumnSize*(regions[r+1]-regions[r])))
+ if ((child.colspan * targetColumnSize) > (child.maxwidth + (float)0.5))
+ sizes[r] = (float)Math.min(sizes[r], (regions[r+1]-regions[r])*(child.maxwidth/child.colspan));
+ if ((child.colspan * targetColumnSize) < (child.contentwidth - (float)0.5))
+ sizes[r] = (float)Math.max(sizes[r], (regions[r+1]-regions[r])*(child.contentwidth/child.colspan));
+ total += sizes[r];