aboutsummaryrefslogtreecommitdiff
path: root/src/calp.c
diff options
context:
space:
mode:
authorfoswret2026-05-02 12:22:58 -0500
committerfoswret2026-05-02 12:22:58 -0500
commit7540a10d9a2d377191b64a29e794d4b58f320347 (patch)
tree558b064ff764546cfc0a12da07b4f9ce4d7a80a8 /src/calp.c
parente291d28cdb37534ad5b22c1eff94a9b389edd2ad (diff)
implement correct month rendering, multipage, No start of month offset
Diffstat (limited to 'src/calp.c')
-rw-r--r--src/calp.c69
1 files changed, 51 insertions, 18 deletions
diff --git a/src/calp.c b/src/calp.c
index 6336a40..9360551 100644
--- a/src/calp.c
+++ b/src/calp.c
@@ -1,43 +1,76 @@
#include <stdio.h>
+#include <stdlib.h>
#include <cairo/cairo-pdf.h>
#include <pango/pangocairo.h>
#include "draw.h"
+#include "date.h"
// Metric
-#define US_LETTER_WIDTH 216
-#define US_LETTER_HEIGHT 279
-
#define A4_WIDTH 210
#define A4_HEIGHT 297
-double width = A4_WIDTH;
-double height = A4_HEIGHT;
+int main (void) {
+ // Definitions
+ // -----------
+ // Convert to inches, then 1 unit = 1/72th inch
+ double width = (A4_WIDTH / 25.4) * 72.0;
+ double height = (A4_HEIGHT / 25.4) * 72.0;
+
+ //extern char *months[];
+ int num_of_months = 12;
+ extern int days_in_month[12];
-int main (int argc, char **argv) {
char *filename;
-
- // TBD clean this up
- filename = argv[1];
+ filename = "output.pdf";
+
+ // Create dimensions struct to hold measurements
+ struct dimensions dim;
- if (argc == 1) {
- filename = "output.pdf";
+
+ // Leap year adjustment: increment February day count by one
+ int year = 2026;
+ if (isleap(year)) {
+ days_in_month[1]++;
}
+
+
+
+
// Initialization
- cairo_surface_t *surface = cairo_pdf_surface_create(filename, width, height);
- cairo_t *cr = cairo_create(surface);
+ // --------------
+ // Calculates measurements, stores them in dimensions struct. See "draw.h"
+ calculate_dimensions(width, height, &dim);
- // Draw stuff here
- fill_bg(cr, width, height);
+ cairo_surface_t *surface = cairo_pdf_surface_create(filename, dim.paper_width, dim.paper_height);
+ cairo_t *paper = cairo_create(surface);
- // Draw text in upper left corner
- draw_text(cr, 0.0, 0.0, "1");
+ // Sub-surface for rendering content in day boxes
+ cairo_surface_t *day =
+ cairo_surface_create_similar(surface, CAIRO_CONTENT_COLOR_ALPHA, dim.day_width, dim.day_height);
+ cairo_t *cd = cairo_create(day);
+
+ // Fill background with white color
+ cairo_set_source_rgb (paper, 255.0, 255.0, 255.0);
+ fill_bg(paper);
+ // Print dimensions, for debugging
+ //print_dimensions(&dim);
+
+ // Draw all months
+ for (int i = 0; i < num_of_months; i++) {
+ draw_month(paper, cd, day, &dim, days_in_month[i]);
+ // Goes to next page in pdf
+ cairo_show_page(paper);
+ }
+
+
// Clean up
- cairo_destroy(cr);
+ // --------
+ cairo_destroy(paper);
cairo_surface_destroy(surface);
return 0;
}