diff --git a/doc/smrender.html b/doc/smrender.html
index c2dcb5d..030c6a2 100644
--- a/doc/smrender.html
+++ b/doc/smrender.html
@@ -380,18 +380,23 @@
Contents
american
-P fmt geom[:angle]
- Select the page format of the output image. The format can be set either named format fmt which
- has a specific dimension or as geometry geom which contains the width and height of the page
- in millimeters in the format widthxheight.
- Fmt currently supports the values A4 up to A0.
- If this option is omitted, A3 format is selected by default.
+ Select the page format of the output image. The format can be set to either
+ a named format fmt which has a predefined dimension or as a geometry
+ geom which contains the width and height of the page in millimeters
+ in the format widthxheight.
+
+
+ Fmt
currently supports the ISO formats A4 up to A0,
+ and the ANSI formats A to E, letter,
+ legal, and ledger. If this option is omitted the format
+ A3 is selected by default.
If the area to be rendered is specified as bounding box (see Section
4.1) this will most probably colide with the dimension of the
page because of the requirements of the projection in which case Smrender
will resize the bounding box appropriately. If either the width or
- the height (but never both) is set to zero then Smrender will
+ the height (but never both) is set to zero, Smrender will
calculate the missing dimension according to the bounding box and the
projection.
diff --git a/doc/smrender.pdf b/doc/smrender.pdf
index 2bbed9f..47c061c 100644
Binary files a/doc/smrender.pdf and b/doc/smrender.pdf differ
diff --git a/doc/smrender.tex b/doc/smrender.tex
index 2007dbc..5a78ada 100644
--- a/doc/smrender.tex
+++ b/doc/smrender.tex
@@ -337,17 +337,21 @@ \subsection{Options} \label{sec:options}
\item[\optk{P}] \optv{fmt\textbar geom}[:\optv{angle}{]}
- Select the page format of the output image. The format can be set either named format \optv{fmt} which
- has a specific dimension or as geometry \optv{geom} which contains the width and height of the page
- in millimeters in the format \optv{width}\textsf{x}\optv{height}.
- \optv{Fmt} currently supports the values \textsf{A4} up to \textsf{A0}.
- If this option is omitted, \textsf{A3} format is selected by default.
+ Select the page format of the output image. The format can be set to either
+ a named format \optv{fmt} which has a predefined dimension or as a geometry
+ \optv{geom} which contains the width and height of the page in millimeters
+ in the format \optv{width}\textsf{x}\optv{height}.
+
+ \optv{Fmt} currently supports the ISO formats \textsf{A4} up to \textsf{A0},
+ and the ANSI formats \textsf{A} to \textsf{E}, \textsf{letter},
+ \textsf{legal}, and \textsf{ledger}. If this option is omitted the format
+ \textsf{A3} is selected by default.
If the area to be rendered is specified as bounding box (see Section
\ref{sec:window}) this will most probably colide with the dimension of the
page because of the requirements of the projection in which case \smrender{}
will resize the bounding box appropriately. If either the \optv{width} or
- the \optv{height} (but never both) is set to zero then \smrender{} will
+ the \optv{height} (but never both) is set to zero, \smrender{} will
calculate the missing dimension according to the bounding box and the
projection.
diff --git a/src/smrender.c b/src/smrender.c
index 65b2f3e..72e84d1 100644
--- a/src/smrender.c
+++ b/src/smrender.c
@@ -19,7 +19,7 @@
* This file contains the main() function and main initialization functions.
*
* \author Bernhard R. Fischer,
- * \date 2022/03/08
+ * \date 2022/03/24
*/
#ifdef HAVE_CONFIG_H
@@ -391,72 +391,91 @@ static void page_rotate(struct rdata *rd, const char *angle)
char *init_rd_paper(struct rdata *rd, const char *paper)
{
char buf[strlen(paper) + 1], *s, *angle;
- double a4_w, a4_h;
-
- a4_w = MM2PX(210);
- a4_h = MM2PX(297);
+ double width = 0.;
+ double height = 0.; // in mm
+
+ struct PAPERSIZE {
+ const char * const name;
+ const double w;
+ const double h;
+ };
+ // all in mm
+ const float A4_W = 210;
+ const float A4_H = 297;
+ const float A_W = 8.5 * 25.4; // ANSI A
+ const float A_H = 11. * 25.4;
+ const float L_H = 14. * 25.4; // legal
+
+ const struct PAPERSIZE papersize[] = {
+ { "A4", A4_W, A4_H },
+ { "A3", A4_H, A4_W * 2. },
+ { "A2", A4_W * 2., A4_H * 2. },
+ { "A1", A4_H * 2., A4_W * 4. },
+ { "A0", A4_W * 4., A4_H * 4. },
+ { "A", A_W, A_H },
+ { "B", A_H, A_W * 2. },
+ { "C", A_W * 2., A_H * 2. },
+ { "D", A_H * 2., A_W * 4. },
+ { "E", A_W * 4., A_H * 4. },
+ { "letter", A_W, A_H },
+ { "legal", A_W, L_H },
+ { "ledger", A_H, A_W * 2. },
+ { NULL, 0., 0. }
+ };
strcpy(buf, paper);
strtok(buf, ":");
angle = strtok(NULL, ":");
+ // check if format is given as WxH
if (strchr(buf, 'x'))
{
if ((s = strtok(buf, "x")) == NULL)
log_msg(LOG_ERR, "strtok returned NULL"),
exit(EXIT_FAILURE);
- rd->w = MM2PX(atof(s));
+ width = atof(s);
if ((s = strtok(NULL, "x")) == NULL)
log_msg(LOG_ERR, "format error in page size: '%s'", buf),
exit(EXIT_FAILURE);
- rd->h = MM2PX(atof(s));
-
- if ((rd->w < 0) || (rd->h < 0))
- log_msg(LOG_ERR, "page width and height must be a decimal value greater than 0"),
- exit(EXIT_FAILURE);
-
- if (!rd->w && !rd->h)
- log_msg(LOG_ERR, "width and height cannot both be 0"),
- exit(EXIT_FAILURE);
- }
- else if (!strcasecmp(buf, "A4"))
- {
- rd->w = a4_w;
- rd->h = a4_h;
- }
- else if (!strcasecmp(buf, "A3"))
- {
- rd->w = a4_h;
- rd->h = a4_w * 2;
- }
- else if (!strcasecmp(buf, "A2"))
- {
- rd->w = a4_w * 2;
- rd->h = a4_h * 2;
- }
- else if (!strcasecmp(buf, "A1"))
- {
- rd->w = a4_h * 2;
- rd->h = a4_w * 4;
- }
- else if (!strcasecmp(buf, "A0"))
- {
- rd->w = a4_w * 4;
- rd->h = a4_h * 4;
+ height = atof(s);
}
+ // test if format is one of the preset formats
else
{
- log_msg(LOG_WARN, "unknown page size %s, defaulting to A4", buf);
- rd->w = a4_w;
- rd->h = a4_h;
- }
+ struct PAPERSIZE const * sizeptr = papersize + 0;
+ while ( sizeptr->name != NULL )
+ {
+ if ( !strcasecmp(buf, sizeptr->name))
+ {
+ width = sizeptr->w;
+ height = sizeptr->h;
+ break;
+ } // end if
+ ++sizeptr;
+ } //end while
+
+ // set default size if specified format is unknown
+ if ( sizeptr->name == NULL ) {
+ log_msg(LOG_WARN, "unknown page size %s, defaulting to A3", buf);
+ width = A4_H;
+ height = A4_W * 2.;
+ } // end if
+ } // end else
+
+ if ( (width <= 0.) || (height <= 0.) ) {
+ log_msg(LOG_ERR, "page width and height must be a decimal value greater than 0"),
+ exit(EXIT_FAILURE);
+ } // end if
+ // set final width and height to config structure of renderer
if (rd->flags & RD_LANDSCAPE)
{
- a4_w = rd->w;
- rd->w = rd->h;
- rd->h = a4_w;
- }
+ rd->w = MM2PX(height);
+ rd->h = MM2PX(width);
+ } else {
+ rd->w = MM2PX(width );
+ rd->h = MM2PX(height);
+ } // end else
return angle;
}