aboutsummaryrefslogtreecommitdiff
path: root/src/calp.c
blob: 936055193d3247d91477b98229f0ca52b9ba14cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include <stdlib.h>
#include <cairo/cairo-pdf.h>
#include <pango/pangocairo.h>

#include "draw.h"
#include "date.h"

// Metric
#define A4_WIDTH 210
#define A4_HEIGHT 297

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];

   char *filename;
   filename = "output.pdf";

   // Create dimensions struct to hold measurements
   struct dimensions dim;


   // Leap year adjustment: increment February day count by one
   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);

   // 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(paper);
   cairo_surface_destroy(surface);
   return 0;
}