Added minimum width/height for a design. Fixed screwed tiny boxes.

Did not handle zero input.
This commit is contained in:
Thomas Jensen 1999-03-30 13:30:19 +00:00
parent 103bcbffda
commit 504284f942

View File

@ -3,7 +3,7 @@
* Date created: March 18, 1999 (Thursday, 15:09h) * Date created: March 18, 1999 (Thursday, 15:09h)
* Author: Thomas Jensen * Author: Thomas Jensen
* tsjensen@stud.informatik.uni-erlangen.de * tsjensen@stud.informatik.uni-erlangen.de
* Version: $Id: boxes.c,v 1.2 1999/03/19 17:44:47 tsjensen Exp tsjensen $ * Version: $Id: boxes.c,v 1.3 1999/03/30 09:36:23 tsjensen Exp tsjensen $
* Language: ANSI C * Language: ANSI C
* Platforms: sunos5/sparc, for now * Platforms: sunos5/sparc, for now
* World Wide Web: http://home.pages.de/~jensen/boxes/ * World Wide Web: http://home.pages.de/~jensen/boxes/
@ -14,6 +14,10 @@
* Revision History: * Revision History:
* *
* $Log: boxes.c,v $ * $Log: boxes.c,v $
* Revision 1.3 1999/03/30 09:36:23 tsjensen
* ... still programming ...
* (removed setlocale() call and locale.h include)
*
* Revision 1.2 1999/03/19 17:44:47 tsjensen * Revision 1.2 1999/03/19 17:44:47 tsjensen
* ... still programming ... * ... still programming ...
* *
@ -38,7 +42,7 @@ extern char *optarg; /* for getopt() */
extern int optind, opterr, optopt; /* for getopt() */ extern int optind, opterr, optopt; /* for getopt() */
#ident "$Id: boxes.c,v 1.2 1999/03/19 17:44:47 tsjensen Exp tsjensen $" #ident "$Id: boxes.c,v 1.3 1999/03/30 09:36:23 tsjensen Exp tsjensen $"
extern FILE *yyin; /* lex input file */ extern FILE *yyin; /* lex input file */
@ -670,6 +674,13 @@ int read_all_input()
return 1; return 1;
} }
/*
* Exit if there was no input at all
*/
if (input.lines == NULL || input.lines[0].text == NULL) {
return 0;
}
/* /*
* Remove indentation * Remove indentation
*/ */
@ -716,7 +727,7 @@ size_t highest (const sentry_t *sarr, const int n, ...)
int i; int i;
size_t max = 0; /* current maximum height */ size_t max = 0; /* current maximum height */
#if defined(DEBUG) && 1 #if defined(DEBUG) && 0
fprintf (stderr, "highest (%d, ...)\n", n); fprintf (stderr, "highest (%d, ...)\n", n);
#endif #endif
@ -935,10 +946,20 @@ static int vert_precalc (const sentry_t *sarr, const shape_t *seite,
size_t res_hspace = 0; size_t res_hspace = 0;
int i; int i;
size_t j; size_t j;
size_t target_width;
memset (iltf, 0, (SHAPES_PER_SIDE-2) * sizeof(size_t)); memset (iltf, 0, (SHAPES_PER_SIDE-2) * sizeof(size_t));
*hspace = 0; *hspace = 0;
if (input.maxline >= (opt.design->minwidth - sarr[seite[0]].width -
sarr[seite[SHAPES_PER_SIDE-1]].width)) {
target_width = input.maxline;
}
else {
target_width = opt.design->minwidth - sarr[seite[0]].width -
sarr[seite[SHAPES_PER_SIDE-1]].width;
}
for (i=1; i<SHAPES_PER_SIDE-1; ++i) for (i=1; i<SHAPES_PER_SIDE-1; ++i)
if (!isempty(sarr+seite[i])) if (!isempty(sarr+seite[i]))
numshapes++; numshapes++;
@ -952,7 +973,7 @@ static int vert_precalc (const sentry_t *sarr, const shape_t *seite,
for (i=1; i<SHAPES_PER_SIDE-1; ++i) { for (i=1; i<SHAPES_PER_SIDE-1; ++i) {
if (!isempty(&(sarr[seite[i]]))) { if (!isempty(&(sarr[seite[i]]))) {
iltf[i-1] = 0; iltf[i-1] = 0;
for (j=0; !j||res_hspace<input.maxline; ++j) { for (j=0; !j||res_hspace<target_width; ++j) {
iltf[i-1] += sarr[seite[i]].width; iltf[i-1] += sarr[seite[i]].width;
res_hspace += sarr[seite[i]].width; res_hspace += sarr[seite[i]].width;
} }
@ -974,7 +995,7 @@ static int vert_precalc (const sentry_t *sarr, const shape_t *seite,
} }
for (i=1; i<SHAPES_PER_SIDE-1; ++i) { for (i=1; i<SHAPES_PER_SIDE-1; ++i) {
if (!isempty (sarr+seite[i]) && sarr[seite[i]].elastic) { if (!isempty (sarr+seite[i]) && sarr[seite[i]].elastic) {
for (j=0; !j||res_hspace<input.maxline; ++j) { for (j=0; !j||res_hspace<target_width; ++j) {
iltf[i-1] += sarr[seite[i]].width; iltf[i-1] += sarr[seite[i]].width;
res_hspace += sarr[seite[i]].width; res_hspace += sarr[seite[i]].width;
} }
@ -997,10 +1018,10 @@ static int vert_precalc (const sentry_t *sarr, const shape_t *seite,
if (sarr[seite[1]].elastic && sarr[seite[3]].elastic) { if (sarr[seite[1]].elastic && sarr[seite[3]].elastic) {
size_t vtmp; size_t vtmp;
size_t space_to_fill; size_t space_to_fill;
if (res_hspace > input.maxline) if (res_hspace > target_width)
space_to_fill = 0; space_to_fill = 0;
else else
space_to_fill = input.maxline - res_hspace; space_to_fill = target_width - res_hspace;
for (j=0,vtmp=0; !j||vtmp<space_to_fill/2+(space_to_fill%2?1:0); ++j) for (j=0,vtmp=0; !j||vtmp<space_to_fill/2+(space_to_fill%2?1:0); ++j)
vtmp += sarr[seite[3]].width; vtmp += sarr[seite[3]].width;
iltf[2] += vtmp; iltf[2] += vtmp;
@ -1013,7 +1034,7 @@ static int vert_precalc (const sentry_t *sarr, const shape_t *seite,
else { else {
for (i=1; i<SHAPES_PER_SIDE-1; ++i) { for (i=1; i<SHAPES_PER_SIDE-1; ++i) {
if (sarr[seite[i]].elastic) { if (sarr[seite[i]].elastic) {
for (j=0; !j||res_hspace<input.maxline; ++j) { for (j=0; !j||res_hspace<target_width; ++j) {
iltf[i-1] += sarr[seite[i]].width; iltf[i-1] += sarr[seite[i]].width;
res_hspace += sarr[seite[i]].width; res_hspace += sarr[seite[i]].width;
} }
@ -1054,10 +1075,19 @@ static int horiz_precalc (const sentry_t *sarr, const shape_t *seite,
size_t res_vspace = 0; size_t res_vspace = 0;
int i; int i;
size_t j; size_t j;
size_t text_height;
memset (iltf, 0, (SHAPES_PER_SIDE-2) * sizeof(size_t)); memset (iltf, 0, (SHAPES_PER_SIDE-2) * sizeof(size_t));
*vspace = 0; *vspace = 0;
if (input.anz_lines >= (opt.design->minheight - sarr[seite[0]].height -
sarr[seite[SHAPES_PER_SIDE-1]].height))
text_height = input.anz_lines;
else {
text_height = opt.design->minheight - sarr[seite[0]].height -
sarr[seite[SHAPES_PER_SIDE-1]].height;
}
for (i=1; i<SHAPES_PER_SIDE-1; ++i) for (i=1; i<SHAPES_PER_SIDE-1; ++i)
if (!isempty(sarr+seite[i])) if (!isempty(sarr+seite[i]))
numshapes++; numshapes++;
@ -1071,7 +1101,7 @@ static int horiz_precalc (const sentry_t *sarr, const shape_t *seite,
for (i=1; i<SHAPES_PER_SIDE-1; ++i) { for (i=1; i<SHAPES_PER_SIDE-1; ++i) {
if (!isempty(&(sarr[seite[i]]))) { if (!isempty(&(sarr[seite[i]]))) {
iltf[i-1] = 0; iltf[i-1] = 0;
for (j=0; !j||res_vspace<input.anz_lines; ++j) { for (j=0; !j||res_vspace<text_height; ++j) {
iltf[i-1] += sarr[seite[i]].height; iltf[i-1] += sarr[seite[i]].height;
res_vspace += sarr[seite[i]].height; res_vspace += sarr[seite[i]].height;
} }
@ -1095,7 +1125,7 @@ static int horiz_precalc (const sentry_t *sarr, const shape_t *seite,
for (i=1; i<SHAPES_PER_SIDE-1; ++i) { for (i=1; i<SHAPES_PER_SIDE-1; ++i) {
if (!isempty (sarr+seite[i]) if (!isempty (sarr+seite[i])
&& sarr[seite[i]].elastic) { && sarr[seite[i]].elastic) {
for (j=0; !j||res_vspace<input.anz_lines; ++j) { for (j=0; !j||res_vspace<text_height; ++j) {
iltf[i-1] += sarr[seite[i]].height; iltf[i-1] += sarr[seite[i]].height;
res_vspace += sarr[seite[i]].height; res_vspace += sarr[seite[i]].height;
} }
@ -1118,10 +1148,10 @@ static int horiz_precalc (const sentry_t *sarr, const shape_t *seite,
if (sarr[seite[1]].elastic && sarr[seite[3]].elastic) { if (sarr[seite[1]].elastic && sarr[seite[3]].elastic) {
size_t vtmp; size_t vtmp;
size_t space_to_fill; size_t space_to_fill;
if (res_vspace > input.anz_lines) if (res_vspace > text_height)
space_to_fill = 0; space_to_fill = 0;
else else
space_to_fill = input.anz_lines - res_vspace; space_to_fill = text_height - res_vspace;
for (j=0,vtmp=0; !j||vtmp<space_to_fill/2+(space_to_fill%2?1:0); ++j) for (j=0,vtmp=0; !j||vtmp<space_to_fill/2+(space_to_fill%2?1:0); ++j)
vtmp += sarr[seite[3]].height; vtmp += sarr[seite[3]].height;
iltf[2] += vtmp; iltf[2] += vtmp;
@ -1134,7 +1164,7 @@ static int horiz_precalc (const sentry_t *sarr, const shape_t *seite,
else { else {
for (i=1; i<SHAPES_PER_SIDE-1; ++i) { for (i=1; i<SHAPES_PER_SIDE-1; ++i) {
if (sarr[seite[i]].elastic) { if (sarr[seite[i]].elastic) {
for (j=0; !j||res_vspace<input.anz_lines; ++j) { for (j=0; !j||res_vspace<text_height; ++j) {
iltf[i-1] += sarr[seite[i]].height; iltf[i-1] += sarr[seite[i]].height;
res_vspace += sarr[seite[i]].height; res_vspace += sarr[seite[i]].height;
} }
@ -1660,6 +1690,8 @@ int main (int argc, char *argv[])
rc = read_all_input(); rc = read_all_input();
if (rc) exit (EXIT_FAILURE); if (rc) exit (EXIT_FAILURE);
if (input.anz_lines == 0)
exit (EXIT_SUCCESS);
rc = generate_box (thebox); rc = generate_box (thebox);
if (rc) exit (EXIT_FAILURE); if (rc) exit (EXIT_FAILURE);