aboutsummaryrefslogtreecommitdiff
path: root/src/calp.c
diff options
context:
space:
mode:
authorfoswret2026-05-08 22:20:02 -0500
committerfoswret2026-05-08 22:20:02 -0500
commit820a647eb2ad5e1b424acd72a4cf7362cfda2e8a (patch)
tree76189a8b9e8bd64f2c439bb02305b7725db0bb97 /src/calp.c
parentf0c9538a77c942ac96aebe52319f3e127be230ee (diff)
Shrink default month-grid size, render month art comfortably
Diffstat (limited to 'src/calp.c')
-rw-r--r--src/calp.c57
1 files changed, 48 insertions, 9 deletions
diff --git a/src/calp.c b/src/calp.c
index 893b5f4..2d155cc 100644
--- a/src/calp.c
+++ b/src/calp.c
@@ -46,33 +46,40 @@ int main (void) {
// Leap year adjustment: increment February day count by one if
// it is a leap year.
- int year = 2026;
+ int year = 3043;
if (isleap(year)) {
days_in_month[1]++;
}
+ int verbose_output = 1;
+
// TBD: Add ability to choose filename
+ // Defaults to the year being generated
char filename[20];
snprintf(filename, sizeof(filename), "%d.pdf", year);
- //filename = "output.pdf";
+
// Initialization
// --------------
// Calculates measurements, stores them in dimensions struct. See "draw.h"
calculate_dimensions(width, height, &dim);
+ 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_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);
+ // cd = context day
cairo_t *cd = cairo_create(day);
- // General rectangle struct for positioning. Used whenever dimensions need
- // to be passed to another function
- // PangoRectangle logical_extents;
+
// Fill background with white color
set_color(paper, WHITE);
@@ -84,7 +91,10 @@ int main (void) {
// Construction
// ------------
// Print dimensions, for debugging
- print_dimensions(&dim);
+
+ if (verbose_output) {
+ print_dimensions(&dim);
+ }
// Range of months to be rendered (Default: Full calendar year, 12 months)
@@ -97,32 +107,61 @@ int main (void) {
// Initialize month struct
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);
+ printf("month.minimum_rows: %d\n", month.minimum_rows);
- //draw_image(paper, "assets/weather.png", 0, 0);
+ 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);
+ cairo_surface_t *header = cairo_surface_create_similar(surface, CAIRO_CONTENT_COLOR_ALPHA, dim.header_width, dim.header_height);
+ cairo_t *ch = cairo_create(header);
- set_color(paper, BLACK);
- draw_month_title(paper, &dim, months[i]);
+ //set_color(ch, BLUE);
+ //fill_bg(ch);
+
+ set_color(ch, BLACK);
+ draw_month_title(ch, &dim, "Sans", 40, months[i]);
+
+ printf("header width: %f\n", dim.header_width);
+ printf("header height: %f\n", dim.header_height);
char path[20];
snprintf(path, 20, "assets/%d.png", i + 1);
+ if (verbose_output) {
+ printf("Drawing month \'%s\'\n", months[i]);
+ }
draw_month_art(paper, &dim, path);
+
+
+ cairo_set_source_surface(paper, header, dim.margin, dim.margin);
+ cairo_paint(paper);
draw_month(paper, cd, day, &month, &dim);
draw_month_grid(paper, &month, &dim);
// Go to the next page in pdf
cairo_show_page(paper);
+
+ cairo_destroy(ch);
+ cairo_surface_destroy(header);
}
+ if (verbose_output) {
+ printf("Finished generating \'%s\'.\n", filename);
+ }
// Clean up
// --------
cairo_destroy(paper);
cairo_surface_destroy(surface);
+
+ cairo_destroy(cd);
+ cairo_surface_destroy(day);
+
return 0;
}