diff options
| author | foswret | 2026-05-22 11:52:34 -0500 |
|---|---|---|
| committer | foswret | 2026-05-22 11:52:34 -0500 |
| commit | 924ca70a4006abbffc8f43f27c4f64c8fc517a08 (patch) | |
| tree | f4926e53b915bdfa9237c7de73d5b59872e48f5e /src/calp.c | |
| parent | 04fc01ab521abf48cede1e64563fd6276e781b24 (diff) | |
draw_month_grid() doesn't use dimension struct anymore. create generate extents structs for month, paper, and day
Diffstat (limited to 'src/calp.c')
| -rw-r--r-- | src/calp.c | 47 |
1 files changed, 35 insertions, 12 deletions
@@ -12,7 +12,6 @@ #include "date.h" #include "color.h" #include "image.h" -#include "ezini.h" // Metric #define A4_WIDTH 210 @@ -32,6 +31,9 @@ int main (void) { double width = A4_WIDTH; double height = A4_HEIGHT; + const int row_count = 6; + const int column_count = 7; + // Convert to inches, then 1 unit = 1/72th inch width = (width / 25.4) * 72.0; height = (height / 25.4) * 72.0; @@ -43,16 +45,15 @@ int main (void) { char *months[num_of_months]; extern int days_in_month[12]; - const nl_item nl_abmons[12] = {ABMON_1, ABMON_2, ABMON_3, ABMON_4, - ABMON_5, ABMON_6, ABMON_7, ABMON_8, - ABMON_9, ABMON_10, ABMON_11, ABMON_12}; + //const nl_item nl_abmons[12] = {ABMON_1, ABMON_2, ABMON_3, ABMON_4, + // ABMON_5, ABMON_6, ABMON_7, ABMON_8, + // ABMON_9, ABMON_10, ABMON_11, ABMON_12}; const nl_item nl_months[12] = {MON_1, MON_2, MON_3, MON_4, MON_5, MON_6, MON_7, MON_8, MON_9, MON_10, MON_11, MON_12}; int i; setlocale(LC_ALL, ""); for (i = 0; i < 12; i++) { - printf("%d\t%s\t%s\n", i+1, nl_langinfo(nl_abmons[i]), nl_langinfo(nl_months[i])); months[i] = nl_langinfo(nl_months[i]); } @@ -68,7 +69,7 @@ int main (void) { // Leap year adjustment: increment February day count by one if // it is a leap year. - int year = 14; + const int year = 2026; if (isleap(year)) { days_in_month[1]++; } @@ -87,17 +88,41 @@ int main (void) { // Calculates measurements, stores them in dimensions struct. See "draw.h" calculate_dimensions(width, height, &dim); + + + struct extents paper_extents = { + .width = width, + .height = height + }; + + const double margin = 0.05 * paper_extents.width; + + struct extents day_extents = { + .width = paper_extents.width / 10.0, + .height = paper_extents.width / 10.0 + }; + + struct extents month_extents = { + .x = (paper_extents.width - (day_extents.width * column_count)) / 2.0, + .y = paper_extents.height - margin - (day_extents.height * row_count), + .width = day_extents.width * column_count, + .height = day_extents.height * row_count, + }; + + printf("%f\n", month_extents.x); + + if (!CAIRO_HAS_PDF_SURFACE) { printf("Error: PDF backend not available.\n"); return 1; } - cairo_surface_t *surface = cairo_pdf_surface_create(filename, dim.paper_width, dim.paper_height); + cairo_surface_t *surface = cairo_pdf_surface_create(filename, paper_extents.width, paper_extents.height); cairo_t *paper = cairo_create(surface); // 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_surface_create_similar(surface, CAIRO_CONTENT_COLOR_ALPHA, day_extents.width, day_extents.height); // cd = context day cairo_t *cd = cairo_create(day); @@ -119,7 +144,7 @@ int main (void) { month.first_day = day_of_week(1, i + 1, year); month.num_of_days = days_in_month[i]; month.month_position = i; - month.minimum_rows = calculate_minimum_rows(&month, &dim); + month.minimum_rows = calculate_minimum_rows(&month); dim.header_width = dim.paper_width - (dim.margin * 2.0); dim.header_height = dim.paper_height - (dim.margin * 3.0) - (month.minimum_rows * dim.day_height); @@ -137,8 +162,6 @@ int main (void) { snprintf(path, 20, "assets/%d.png", i + 1); - prepare_month_art(path, &dim); - if (verbose_output) { printf("Drawing month \'%s\'\n", months[i]); } @@ -149,7 +172,7 @@ int main (void) { cairo_paint(paper); draw_month(paper, cd, day, &month, &dim); - draw_month_grid(paper, &month, &dim); + draw_month_grid(paper, &month, &month_extents, &day_extents); // Go to the next page in pdf cairo_show_page(paper); |
