Skip to content

Commit

Permalink
ANSI page formats added (thanks go to Jim Ham\!)
Browse files Browse the repository at this point in the history
  • Loading branch information
rahra committed Mar 24, 2022
1 parent ab06d84 commit 9559551
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 60 deletions.
17 changes: 11 additions & 6 deletions doc/smrender.html
Original file line number Diff line number Diff line change
Expand Up @@ -380,18 +380,23 @@ <h1>Contents </h1> american
<br /><span style="font-family:helvetica"><span class="small"><b>-P</b></span></span> <span style="font-family:helvetica"><span class="small"><u>fmt geom</u></span></span>[:<span style="font-family:helvetica"><span class="small"><u>angle</u></span></span>]

<div class="p"><!----></div>
Select the page format of the output image. The format can be set either named format <span style="font-family:helvetica"><span class="small"><u>fmt</u></span></span> which
has a specific dimension or as geometry <span style="font-family:helvetica"><span class="small"><u>geom</u></span></span> which contains the width and height of the page
in millimeters in the format <span style="font-family:helvetica"><span class="small"><u>width</u></span></span><span style="font-family:helvetica">x</span><span style="font-family:helvetica"><span class="small"><u>height</u></span></span>.
<span style="font-family:helvetica"><span class="small"><u>Fmt</u></span></span> currently supports the values <span style="font-family:helvetica">A4</span> up to <span style="font-family:helvetica">A0</span>.
If this option is omitted, <span style="font-family:helvetica">A3</span> format is selected by default.
Select the page format of the output image. The format can be set to either
a named format <span style="font-family:helvetica"><span class="small"><u>fmt</u></span></span> which has a predefined dimension or as a geometry
<span style="font-family:helvetica"><span class="small"><u>geom</u></span></span> which contains the width and height of the page in millimeters
in the format <span style="font-family:helvetica"><span class="small"><u>width</u></span></span><span style="font-family:helvetica">x</span><span style="font-family:helvetica"><span class="small"><u>height</u></span></span>.

<div class="p"><!----></div>
<span style="font-family:helvetica"><div class="small"><u>Fmt</u></div></span> currently supports the ISO formats <span style="font-family:helvetica">A4</span> up to <span style="font-family:helvetica">A0</span>,
and the ANSI formats <span style="font-family:helvetica">A</span> to <span style="font-family:helvetica">E</span>, <span style="font-family:helvetica">letter</span>,
<span style="font-family:helvetica">legal</span>, and <span style="font-family:helvetica">ledger</span>. If this option is omitted the format
<span style="font-family:helvetica">A3</span> is selected by default.

<div class="p"><!----></div>
If the area to be rendered is specified as bounding box (see Section
<a href="#sec:window">4.1</a>) this will most probably colide with the dimension of the
page because of the requirements of the projection in which case <span style="font-family:helvetica"><i><span class="small">Smrender</span></i></span>
will resize the bounding box appropriately. If either the <span style="font-family:helvetica"><span class="small"><u>width</u></span></span> or
the <span style="font-family:helvetica"><span class="small"><u>height</u></span></span> (but never both) is set to zero then <span style="font-family:helvetica"><i><span class="small">Smrender</span></i></span> will
the <span style="font-family:helvetica"><span class="small"><u>height</u></span></span> (but never both) is set to zero, <span style="font-family:helvetica"><i><span class="small">Smrender</span></i></span> will
calculate the missing dimension according to the bounding box and the
projection.

Expand Down
Binary file modified doc/smrender.pdf
Binary file not shown.
16 changes: 10 additions & 6 deletions doc/smrender.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
115 changes: 67 additions & 48 deletions src/smrender.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* This file contains the main() function and main initialization functions.
*
* \author Bernhard R. Fischer, <[email protected]>
* \date 2022/03/08
* \date 2022/03/24
*/

#ifdef HAVE_CONFIG_H
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 9559551

Please sign in to comment.