diff options
| author | foswret | 2026-05-02 12:22:58 -0500 |
|---|---|---|
| committer | foswret | 2026-05-02 12:22:58 -0500 |
| commit | 7540a10d9a2d377191b64a29e794d4b58f320347 (patch) | |
| tree | 558b064ff764546cfc0a12da07b4f9ce4d7a80a8 /src/calp.c | |
| parent | e291d28cdb37534ad5b22c1eff94a9b389edd2ad (diff) | |
implement correct month rendering, multipage, No start of month offset
Diffstat (limited to 'src/calp.c')
| -rw-r--r-- | src/calp.c | 69 |
1 files changed, 51 insertions, 18 deletions
@@ -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; } |
