Skip to content

Commit

Permalink
New drawing: A6 postcard labels. Draw a sheet of postcards, ISO A6 si…
Browse files Browse the repository at this point in the history
…ze, just the rear with space for message, address and stamp.
  • Loading branch information
anachrocomputer committed Aug 23, 2020
1 parent 2731c3f commit c6ddf45
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ private
*.nc
*.png
*.svg
a6cardlabels
allover12
allover13
arches
Expand Down
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ HPGL=flake.hpgl op.hpgl dala1.hpgl hconic2.hpgl tree.hpgl dome.hpgl \
qrplot.hpgl lotus.hpgl celticstep.hpgl op_moire.hpgl sutpent.hpgl \
morphpoly.hpgl pin_circle.hpgl isogrid.hpgl circle_lines.hpgl \
star_grid.hpgl ternary_arcs.hpgl hexspiral.hpgl poly_oval.hpgl \
libtest.hpgl linetiles.hpgl
libtest.hpgl linetiles.hpgl a6cardlabels.hpgl

SVG=$(HPGL:.hpgl=.svg)

Expand Down Expand Up @@ -57,6 +57,15 @@ op.o: op.c

# HPGL library programs

a6cardlabels.hpgl: a6cardlabels Makefile
./a6cardlabels $(TITLE) $(BOLDPEN) -o $@

a6cardlabels: a6cardlabels.o hpgllib.o
$(LD) -o $@ a6cardlabels.o hpgllib.o -lm

a6cardlabels.o: a6cardlabels.c hpgllib.h
$(CC) $(CFLAGS) -o $@ a6cardlabels.c

piscis.hpgl: piscis Makefile
./piscis $(TITLE) $(BOLDPEN) -o $@

Expand Down
132 changes: 132 additions & 0 deletions a6cardlabels.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/* a6cardlabels --- plot labelling for A6 postcards 2020-08-23 */
/* Copyright (c) 2020 John Honniball, Froods Software Development */

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
#include "hpgllib.h"

void postcard_port(const double x, const double y, const double wd, const double ht);
void postcard_land(const double x, const double y, const double wd, const double ht);

int main(int argc, char * const argv[])
{
int opt;
int i, j;
bool portrait;
double x, y;
double dx, dy;
int nx, ny;
double maxx, maxy;
PlotInfo_t info;

while ((opt = getopt(argc, argv, "no:p:q:s:t:v:")) != -1) {
switch (opt) {
case 's':
case 'n':
case 'o':
case 'p':
case 'q':
case 'v':
plotopt(opt, optarg);
break;
case 't': // Suppress title, which would spoil the lower-left postcard
break;
default: /* '?' */
fprintf(stderr, "Usage: %s [-p pen] [-q plotter] [-s <size>] [-t title]\n", argv[0]);
fprintf(stderr, " <size> ::= A1 | A2 | A3 | A4 | A5 | A6\n");
exit(EXIT_FAILURE);
}
}

if (plotbegin(1) < 0) {
fputs("Failed to initialise HPGL library\n", stderr);
exit(EXIT_FAILURE);
}

if (getplotinfo(&info, sizeof (info)) < 0) {
fputs("Failed to get plot information\n", stderr);
exit(EXIT_FAILURE);
}

getplotsize(&maxx, &maxy);

switch (info.paperSize) {
case ISO_A3:
nx = 4;
ny = 2;
portrait = true;
break;
case ISO_A4:
nx = 2;
ny = 2;
portrait = false;
break;
case ISO_A5:
nx = 2;
ny = 1;
portrait = true;
break;
case ISO_A6:
nx = 1;
ny = 1;
portrait = false;
break;
}

dx = maxx / (double)nx;
dy = maxy / (double)ny;

for (i = 1; i < nx; i++) {
x = dx * (double)i;
moveto(x, 0);
lineto(x, maxy);
}

for (i = 1; i < ny; i++) {
y = dy * (double)i;
moveto(0, y);
lineto(maxx, y);
}

for (i = 0; i < nx; i++)
for (j = 0; j < ny; j++) {
x = dx * (double)i;
y = dy * (double)j;

if (portrait)
postcard_port(x, y, dx, dy);
else
postcard_land(x, y, dx, dy);
}

plotend();

return (0);
}


void postcard_port(const double x, const double y, const double wd, const double ht)
{
double yc = y + (ht / 2.0);
double x1 = x + (wd / 16.0);
double x2 = x + wd - (wd / 16.0);
double sx2 = x + wd - (5.0 * 40.0);
double sy2 = y + (5.0 * 40.0);
double sx1 = sx2 - (22.0 * 40.0);
double sy1 = sy2 + (19.0 * 40.0);

moveto(x1, yc);
lineto(x2, yc);

rectangle(sx1, sy1, sx2, sy2);
}


void postcard_land(const double x, const double y, const double wd, const double ht)
{
}

0 comments on commit c6ddf45

Please sign in to comment.