- void resize_children() {
-
- //#repeat col/row colspan/rowspan contentwidth/contentheight x/y width/height colMaxWidth/rowMaxHeight colWidth/rowHeight \
- // HSHRINK/VSHRINK maxwidth/maxheight cols/rows minwidth/minheight colWidth/rowHeight x_slack/y_slack
- // PHASE 1: compute column min/max sizes
- int x_slack = width;
- for(int i=0; i<cols; i++) x_slack -= colWidth[i];
- for(Box child = firstPackedChild(); child != null; child = child.nextPackedSibling())
- for(int i=child.col; i < child.col + child.colspan; i++) {
- x_slack += colWidth[i];
- colWidth[i] = max(colWidth[i], child.contentwidth / child.colspan);
- x_slack -= colWidth[i];
- colMaxWidth[i] = max(colMaxWidth[i], (child.test(HSHRINK) ? child.contentwidth : child.maxwidth) / child.colspan);
+ private static float[] coeff = null;
+ private static Simplex lp_h = new Simplex(100, 100, 300);
+ private static Simplex lp = new Simplex(100, 100, 300);
+
+ // FIXME: numboxes^2, and damn ugly to boot
+ private static int[] regions = new int[65535];
+ private static int[] regions_v = new int[65535];
+ private static int numregions = 0;
+ private static int numregions_v = 0;
+ //#repeat col/row colspan/rowspan contentwidth/contentheight width/height HSHRINK/VSHRINK numregions/numregions_v \
+ // maxwidth/maxheight cols/rows minwidth/minheight lp_h/lp lp_h/lp easy_width/easy_height regions/regions_v \
+ // computeRegions/computeRegions_v
+ private void computeRegions() {
+ numregions = 0;
+ for(Box c = firstPackedChild(); c != null; c = c.nextPackedSibling()) {
+ int target = c.col;
+ for(boolean stop = false;;) {
+ for(int i=0; i<=numregions; i++) {
+ if (i == numregions) { regions[numregions++] = target; break; }
+ if (target == regions[i]) break;
+ if (target < regions[i]) { int tmp = target; target = regions[i]; regions[i] = tmp; }
+ }
+ if (stop) break;
+ stop = true;
+ target = min(cols, c.col+c.colspan);
+ }
+ }
+ if (regions[numregions-1] == cols) numregions--;
+ else regions[numregions] = cols;
+ }
+ //#end
+
+ void solve(boolean findMinimum) {
+ int numkids = 0; for(Box c = firstPackedChild(); c != null; c = c.nextPackedSibling()) numkids++;
+ //#repeat col/row colspan/rowspan contentwidth/contentheight width/height HSHRINK/VSHRINK numregions/numregions_v \
+ // maxwidth/maxheight cols/rows minwidth/minheight lp_h/lp lp_h/lp easy_width/easy_height regions/regions_v \
+ // computeRegions/computeRegions_v
+ if (numkids > 0 && cols > 1) do {
+ computeRegions();
+ int nc = numregions * 3 + numkids * 2 + 3;
+ if (coeff == null || nc+1>coeff.length) coeff = new float[nc+1];
+ lp_h.init(nc);
+
+ for(int i=0; i<coeff.length; i++) coeff[i] = (float)0.0;
+ if (!findMinimum) {
+ coeff[numregions*2+numkids] = (float)10000.0; // priority 1: sum of columns no greater than parent
+ for(int i=numregions*2; i<numregions*2+numkids; i++) coeff[i] = (float)100.0; // priority 2: honor maxwidths
+ for(int i=numregions; i<numregions*2; i++) coeff[i] = (float)(0.1); // priority 3: equalize columns
+ } else {
+ coeff[numregions*2+numkids] = (float)1.0;
+ }
+ lp_h.setObjective(coeff, false);
+
+ for(int i=0; i<numregions; i++) {
+ for(int j=0; j<coeff.length; j++) coeff[j] = j==i ? (float)1.0 : (float)0.0;
+ lp_h.add_constraint(coeff, Simplex.GE, (float)0.0);