+ private static float[] coeff = null;
+ private static LinearProgramming.Simplex lp_h = new LinearProgramming.Simplex(100, 100, 300);
+ private static LinearProgramming.Simplex lp = new LinearProgramming.Simplex(100, 100, 300);
+ int[] regions = new int[65535];
+ int[] regions_v = new int[65535];
+
+ void place_children() {
+ int numkids = 0; for(Box c = firstPackedChild(); c != null; c = c.nextPackedSibling()) numkids++;
+ int numregions = 0, 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
+ if (cols > 1) do {
+ /* boolean easy_width = contentwidth >= width; */
+
+ // FIXME: numboxes^2, and damn ugly to boot
+ 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;
+
+ /*
+ for(Box c = firstPackedChild(); easy_width && c != null; c = c.nextPackedSibling()) {
+ if (c.contentwidth == c.maxwidth) continue;
+ if (c.maxwidth == Integer.MAX_VALUE) continue;
+ easy_width = false;
+ }
+ if (easy_width) for(int i=0; i<cols; i++) {
+ easy_width = false;
+ boolean good = true;
+ for(Box c = firstPackedChild(); good && c != null; c = c.nextPackedSibling())
+ if (c.col <= i && c.col + c.colspan > i && c.maxwidth < Integer.MAX_VALUE)
+ good = false;
+ if (good) { easy_width = true; break; }
+ }
+ if (easy_width) break;
+ */
+ int nc = numregions * 2 + numkids + 1;
+ 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;
+ 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
+ lp_h.setObjective(coeff, false);
+
+ for(int i=0; i<numregions; i++) lp_h.set_lowbo(i+1, (float)0.0); // invariant: columns cannot have negative size
+
+ // invariant: columns must be at least as large as parent
+ for(int i=0; i<coeff.length; i++) coeff[i] = (i<numregions) ? (float)(regions[i+1] - regions[i]) : (float)0.0;
+ lp_h.add_constraint(coeff, LinearProgramming.GE, (float)width);
+
+ // 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;
+ lp_h.add_constraint(coeff, LinearProgramming.EQ, (float)width);
+
+ 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, LinearProgramming.GE, (float)child.contentwidth);
+
+ // 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, LinearProgramming.LE, (float)child_maxwidth);
+ }