aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfoswret <foswret@posteo.com>2025-11-25 22:54:17 -0600
committerfoswret <foswret@posteo.com>2025-11-25 22:54:17 -0600
commitc9493aae669fada3659547b2ce02ee292eb58ba5 (patch)
tree9a870377596a5eb82c718aaa33d56f10e77e16ae
parent36d72aed1800f3e2c514bf264164a6f2a6ba5f5e (diff)
cleaned up Makefile
-rw-r--r--.gitignore2
-rw-r--r--0.pdfbin7286 -> 5492 bytes
-rw-r--r--Makefile15
-rw-r--r--draw.c96
-rw-r--r--draw.h76
5 files changed, 114 insertions, 75 deletions
diff --git a/.gitignore b/.gitignore
index 4c46819..66e5391 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
output
0.pdf
+main.o
+draw.o
diff --git a/0.pdf b/0.pdf
index b26764b..ac92d4d 100644
--- a/0.pdf
+++ b/0.pdf
Binary files differ
diff --git a/Makefile b/Makefile
index 4383372..8c6785c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,2 +1,13 @@
-main: main.c
- clang main.c `pkg-config --cflags -libs cairo cairo-pdf` -o output
+CC = cc
+OBJS = draw.o main.o
+CAIROI = `pkg-config --cflags -libs cairo cairo-pdf`
+.PHONY: clean all
+
+#CFLAGS = -O2 -g -Wall -Werror -Wextra -Winit-self -Wuninitialized -pedantic
+
+all: output
+
+output: $(OBJS)
+ $(CC) $(CAIROI) -o output $(OBJS)
+clean:
+ -rm -f $(OBJS) output
diff --git a/draw.c b/draw.c
new file mode 100644
index 0000000..dc84bfe
--- /dev/null
+++ b/draw.c
@@ -0,0 +1,96 @@
+#include <stdio.h>
+#include <cairo/cairo.h>
+
+struct dimensions {
+ double pw; /* paper width */
+ double ph; /* paper height */
+ double mw; /* month width */
+ double mh; /* month height */
+ double bw; /* day box width */
+ double bh; /* day box height */
+ double r; /* rows */
+ double c; /* columns */
+ double m; /* margin */
+};
+
+
+int draw_calendar(cairo_t *c, double x, double y, struct dimensions d) {
+ double x1, y1, x2, y2;
+ x1 = x;
+ y1 = y;
+ x2 = d.pw - x1; /* Set the line endpoint to right side of the page */
+
+ for (int i = 0; i < d.r + 1; i++) { /* Draw Horizontal Lines */
+ cairo_move_to (c, x, y);
+ cairo_line_to (c, x2, y);
+ y = y + d.bh;
+ }
+
+ x = x1;
+ y = y1;
+ y2 = y1 + d.mh; /* Set the line endpoint as the bottom of the month */
+ for (int i = 0; i < d.c + 1; i++) { /* Draw Vertical Lines */
+ cairo_move_to (c, x, y);
+ cairo_line_to (c, x, y2);
+ x = x + d.bw;
+ }
+ cairo_stroke(c);
+ return(0);
+}
+
+
+
+int draw_numbers(cairo_t *c, double x, double y, struct dimensions d, int wd, int nd) {
+ char str[3];
+ cairo_text_extents_t te;
+ cairo_font_extents_t fe;
+
+ cairo_select_font_face (c, "sans-serif",
+ CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
+ cairo_set_font_size (c, d.bw / 2);
+
+ int iterative = 0;
+ cairo_font_extents (c, &fe);
+ double yi = y;
+ double xi = x;
+ int current_weekday = wd;
+ x = d.m + (wd * d.bw);
+ for (int j = 0; j < d.r; j++) {
+ y = y + d.bh - ((d.bh - fe.ascent) / 2);
+ for (int k = current_weekday; k < d.c; k++) {
+ if (iterative < nd) {
+ sprintf(str, "%d", iterative + 1);
+ cairo_text_extents (c, str, &te);
+ double box_margins = (d.bw - te.width) / 2;
+
+ cairo_move_to(c, x + box_margins - te.x_bearing, y); /* center the number within the box */
+ cairo_show_text(c, str);
+ cairo_move_to(c, x, y); /* Sort of backtrack to realign with the spacing of the boxes */
+ x = x + d.bw;
+ iterative++;
+ current_weekday++;
+ }
+ }
+ current_weekday = 0;
+ y = y - (d.bh - ((d.bh - fe.ascent) / 2));
+ y = y + d.bh;
+ x = xi;
+ }
+ return(0);
+}
+
+
+
+int draw_month_name(cairo_t *c, char *name, struct dimensions d) {
+ double x, y = d.m;
+ cairo_set_font_size(c, 1.0);
+ cairo_text_extents_t te;
+ cairo_font_extents_t fe;
+ cairo_text_extents(c, name, &te);
+ x = (d.pw / 2) - (te.width / 2);
+ y = 1.5;
+ cairo_move_to(c, x, y);
+ cairo_show_text(c, &name[0]);
+ return(0);
+}
+
diff --git a/draw.h b/draw.h
index 503b9c5..7c473a7 100644
--- a/draw.h
+++ b/draw.h
@@ -12,83 +12,13 @@ struct dimensions {
-int draw_calendar(cairo_t *c, double x, double y, struct dimensions d) {
- double x1, y1, x2, y2;
- x1 = x;
- y1 = y;
- x2 = d.pw - x1; /* Set the line endpoint to right side of the page */
+int draw_calendar(cairo_t *c, double x, double y, struct dimensions d);
- for (int i = 0; i < d.r + 1; i++) { /* Draw Horizontal Lines */
- cairo_move_to (c, x, y);
- cairo_line_to (c, x2, y);
- y = y + d.bh;
- }
- x = x1;
- y = y1;
- y2 = y1 + d.mh; /* Set the line endpoint as the bottom of the month */
- for (int i = 0; i < d.c + 1; i++) { /* Draw Vertical Lines */
- cairo_move_to (c, x, y);
- cairo_line_to (c, x, y2);
- x = x + d.bw;
- }
- cairo_stroke(c);
- return(0);
-}
+int draw_numbers(cairo_t *c, double x, double y, struct dimensions d, int wd, int nd);
-int draw_numbers(cairo_t *c, double x, double y, struct dimensions d, int wd, int nd) {
- char str[3];
- cairo_text_extents_t te;
- cairo_font_extents_t fe;
- cairo_select_font_face (c, "sans-serif",
- CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
- cairo_set_font_size (c, d.bw / 2);
-
- int iterative = 0;
- cairo_font_extents (c, &fe);
- double yi = y;
- double xi = x;
- int current_weekday = wd;
- x = d.m + (wd * d.bw);
- for (int j = 0; j < d.r; j++) {
- y = y + d.bh - ((d.bh - fe.ascent) / 2);
- for (int k = current_weekday; k < d.c; k++) {
- if (iterative < nd) {
- sprintf(str, "%d", iterative + 1);
- cairo_text_extents (c, str, &te);
- double box_margins = (d.bw - te.width) / 2;
-
- cairo_move_to(c, x + box_margins - te.x_bearing, y); /* center the number within the box */
- cairo_show_text(c, str);
- cairo_move_to(c, x, y); /* Sort of backtrack to realign with the spacing of the boxes */
- x = x + d.bw;
- iterative++;
- current_weekday++;
- }
- }
- current_weekday = 0;
- y = y - (d.bh - ((d.bh - fe.ascent) / 2));
- y = y + d.bh;
- x = xi;
- }
- return(0);
-}
-
-
-
-int draw_month_name(cairo_t *c, char *name, struct dimensions d) {
- double x, y = d.m;
- cairo_set_font_size(c, 1.0);
- cairo_text_extents_t te;
- cairo_font_extents_t fe;
- cairo_text_extents(c, name, &te);
- x = (d.pw / 2) - (te.width / 2);
- y = 1.5;
- cairo_move_to(c, x, y);
- cairo_show_text(c, &name[0]);
- return(0);
-}
+int draw_month_name(cairo_t *c, char *name, struct dimensions d);