/* Copyright (C) 2001-2005 Peter Selinger. This file is part of psdim. It is free software and it is covered by the GNU general public license. See the file COPYING for details. */ /* $Id: format.c,v 1.3 2005/03/31 03:20:13 selinger Exp $ */ #include #include "main.h" #include "format.h" #define min(a,b) (ab ? a : b) #define INFTY 10000 int format(info_t info, int n, bbox_t *bboxes) { int xmin[info.cols], xmax[info.cols], dxmax[info.cols]; int ymin[info.rows], ymax[info.rows], dymax[info.rows]; int xmint, xmaxt, dxmaxt, dxmaxt2, dxmaxs, dxmaxs2; int ymint, ymaxt, dymaxt, dymaxt2, dymaxs, dymaxs2; double xoff[info.cols+1], yoff[info.rows+1]; int totalw, totalh; transform_t tr[n]; bbox_t *b; int i,j,k; double w, h; /* effective width, height */ double sf1, sf2, sf; /* scaling factor */ double padx, pady; int origin; /* page on upper left corner */ int incx, incy; /* page increment x and y direction */ /* figure out page numbering */ if (info.columnmode) { incx = info.righttoleft ? -info.rows : info.rows; incy = info.bottomtotop ? -1 : 1; origin = info.rows*(info.righttoleft ? info.cols : 1) -(info.bottomtotop ? 1 : info.rows); } else { incx = info.righttoleft ? -1 : 1; incy = info.bottomtotop ? -info.cols : info.cols; origin = info.cols*(info.bottomtotop ? info.rows : 1) -(info.righttoleft ? 1 : info.cols); } /* first calculate aggregate widths and heights of rows and columns, according to various alignment policies */ for (i=0; iy0); ymax[i] = max(ymax[i], b->y1); dymax[i] = max(dymax[i], b->y1 - b->y0); xmin[j] = min(xmin[j], b->x0); xmax[j] = max(xmax[j], b->x1); dxmax[j] = max(dxmax[j], b->x1 - b->x0); #ifdef DEBUG fprintf(stderr, "### bbox(%d,%d): x0=%d x1=%d y0=%d y1=%d dx=%d dy=%d\n", i, j, b->x0, b->x1, b->y0, b->y1, b->x1-b->x0, b->y1-b->y0); #endif } } ymint = xmint = INFTY; ymaxt = xmaxt = 0; dymaxt = dxmaxt = -1; dymaxt2 = dxmaxt2 = -1; dymaxs = dxmaxs = 0; dymaxs2 = dxmaxs2 = 0; for (i=0; ix0; x1 = b->x1; break; } switch(info.vpolicy) { case 0: default: y0 = ymint; y1 = ymaxt; break; case 1: case 3: y0 = ymax[i]; y1 = ymin[i]; break; case 2: case 4: y0 = b->y0; y1 = b->y1; break; } x = (xoff[j]+xoff[j+1]-info.hsep-padx)/2-sf*(x0+x1)/2; y = (yoff[i]+yoff[i+1]+info.vsep+pady)/2-sf*(y0+y1)/2; switch(info.land) { case 0: default: tr[k].rot = ""; tr[k].sf = sf; tr[k].dx = x/72; tr[k].dy = y/72; break; case 1: tr[k].rot = "L"; tr[k].sf = sf; tr[k].dx = (-y+info.w)/72; tr[k].dy = x/72; break; case 2: tr[k].rot = "U"; tr[k].sf = sf; tr[k].dx = (-x+info.w)/72; tr[k].dy = (-y+info.h)/72; break; case 3: tr[k].rot = "R"; tr[k].sf = sf; tr[k].dx = y/72; tr[k].dy = (-x+info.h)/72; break; } } } /* output the results in order */ printf("%d:", n); for (k=0; k