//calp: printable calendar generator #include #include #include #include #include "draw.h" #include "date.h" #include "color.h" // Metric #define A4_WIDTH 210 #define A4_HEIGHT 297 #define US_LETTER_WIDTH 216 #define US_LETTER_HEIGHT 279 // Font Settings #define FONT_FAMILY "Sans" #define FONT_SIZE_NORMAL 10 #define FONT_SIZE_LARGE 40 int main (void) { // Definitions // ----------- double width = A4_WIDTH; double height = A4_HEIGHT; // Convert to inches, then 1 unit = 1/72th inch width = (width / 25.4) * 72.0; height = (height / 25.4) * 72.0; extern char *months[]; int num_of_months = 12; extern int days_in_month[12]; // TBD: Add ability to choose filename char *filename; filename = "output.pdf"; // Create dimensions struct to hold measurements struct dimensions dim; // Create dimensions struct to hold information about a // month struct month_info month; // Leap year adjustment: increment February day count by one if // it is a leap year. int year = 2026; if (isleap(year)) { days_in_month[1]++; } // Initialization // -------------- // Calculates measurements, stores them in dimensions struct. See "draw.h" calculate_dimensions(width, height, &dim); 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); 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); fill_bg(paper); // Construction // ------------ // Print dimensions, for debugging //print_dimensions(&dim); // Draw all months //struct RGB color; //color = hex_to_rgb("81bbd3"); //printf("red: %f\n", color.r); //printf("green: %f\n", color.g); //printf("blue: %f\n", color.b); // Range of months to be rendered (Default: Full calendar year, 12 months) int first_month = 0; int end_month = num_of_months; // Month generation loop for (int i = first_month; i < end_month; i++) { // Initialize month struct month.first_day = day_of_week(1, i + 1, year); month.num_of_days = days_in_month[i]; //draw_image(paper, "assets/weather.png", 0, 0); set_color(paper, BLACK); draw_month_title(paper, &dim, months[i]); draw_month(paper, cd, day, &month, &dim); draw_month_grid(paper, &month, &dim); // Go to the next page in pdf cairo_show_page(paper); } // Clean up // -------- cairo_destroy(paper); cairo_surface_destroy(surface); return 0; }