From de77826633fc128b915e999a9adf10f088b4d3f3 Mon Sep 17 00:00:00 2001 From: foswret Date: Thu, 11 Dec 2025 20:22:55 -0600 Subject: added src/, updated README.md --- .gitignore | 1 + 0.pdf | Bin 5500 -> 5505 bytes Makefile | 4 ++- README | 11 ------- README.md | 16 ++++++++++ color.h | 18 ----------- date.h | 1 - draw.c | 94 --------------------------------------------------------- draw.h | 24 --------------- main.c | 99 ------------------------------------------------------------ src/color.h | 18 +++++++++++ src/date.h | 1 + src/draw.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/draw.h | 24 +++++++++++++++ src/main.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 15 files changed, 254 insertions(+), 248 deletions(-) delete mode 100644 README create mode 100644 README.md delete mode 100644 color.h delete mode 100644 date.h delete mode 100644 draw.c delete mode 100644 draw.h delete mode 100644 main.c create mode 100644 src/color.h create mode 100644 src/date.h create mode 100644 src/draw.c create mode 100644 src/draw.h create mode 100644 src/main.c diff --git a/.gitignore b/.gitignore index 66e5391..73283e0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ output 0.pdf main.o draw.o +TODO diff --git a/0.pdf b/0.pdf index a4a8dcc..0157847 100644 Binary files a/0.pdf and b/0.pdf differ diff --git a/Makefile b/Makefile index a53e318..67861a0 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ CC = cc -OBJS = draw.o main.o +DIR = src +OBJS = $(DIR)/draw.o $(DIR)/main.o CAIROI = `pkg-config --cflags -libs cairo cairo-pdf` .PHONY: clean all @@ -9,5 +10,6 @@ all: output output: $(OBJS) $(CC) $(CAIROI) -o output $(OBJS) + clean: -rm -f $(OBJS) output diff --git a/README b/README deleted file mode 100644 index 069f555..0000000 --- a/README +++ /dev/null @@ -1,11 +0,0 @@ -calp: Generate elegant, printable calendars -=========================================== - -calp (CALendar-Print) is a command line tool that allows for the creation of calendars that can be printed. It aims to be highly customizable, with support for holidays, alternative color formatting, alternative calendar systems, month-specific images, various paper formats, and more. - -calp is written in C and utilizes the cairo library. All calculations relating to weekdays and holiday dates are done internally, meaning no programs like cal are used as a dependency. As such, if you find a bug, please create an issue on GitHub. - -Install -======= - - diff --git a/README.md b/README.md new file mode 100644 index 0000000..8e6b231 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Calp +`calp` attempts to generate clear and attractive calendars that can be printed. + +# Dependencies +- `cairo` +- `pkg-config` + +# Build +- `make` + +# Planned Features +- Arguments (`getopts`) +- Holidays +- Moon Phases +- Month Art +- Custom layout file parsing (config files) diff --git a/color.h b/color.h deleted file mode 100644 index e2b4cc0..0000000 --- a/color.h +++ /dev/null @@ -1,18 +0,0 @@ - int set_color(cairo_t *c, char *str) { - if (strcmp("BLACK", str) == 0) { - cairo_set_source_rgb (c, 0.0, 0.0, 0.0); - } - if (strcmp("RED", str) == 0) { - cairo_set_source_rgb (c, 255.0, 0.0, 0.0); - } - if (strcmp("GREEN", str) == 0) { - cairo_set_source_rgb (c, 0.0, 255.0, 0.0); - } - if (strcmp("BLUE", str) == 0) { - cairo_set_source_rgb (c, 0.0, 0.0, 255.0); - } - if (strcmp("GREY", str) == 0) { - cairo_set_source_rgb (c, 128.0, 128.0, 128.0); - } - return(0); - } diff --git a/date.h b/date.h deleted file mode 100644 index 4ff3d32..0000000 --- a/date.h +++ /dev/null @@ -1 +0,0 @@ -/* date.h: Includes all the functions relating to calculating months, days, etc. */ diff --git a/draw.c b/draw.c deleted file mode 100644 index 51f9367..0000000 --- a/draw.c +++ /dev/null @@ -1,94 +0,0 @@ -#include -#include - -struct dimensions { - double pw; /* paper width */ - double ph; /* paper height */ - double mw; /* month width */ - double mh; /* month height */ - double bw; /* day box width */ - double bh; /* day box height */ - double r; /* rows */ - double c; /* columns */ - double m; /* margin */ -}; - - -int draw_calendar(cairo_t *c, double x, double y, struct dimensions d) { - double x1, y1, x2, y2; - x1 = x; - y1 = y; - x2 = d.pw - x1; /* Set the line endpoint to right side of the page */ - - for (int i = 0; i < d.r + 1; i++) { /* Draw Horizontal Lines */ - cairo_move_to (c, x, y); - cairo_line_to (c, x2, y); - y = y + d.bh; - } - - x = x1; - y = y1; - y2 = y1 + d.mh; /* Set the line endpoint as the bottom of the month */ - for (int i = 0; i < d.c + 1; i++) { /* Draw Vertical Lines */ - cairo_move_to (c, x, y); - cairo_line_to (c, x, y2); - x = x + d.bw; - } - cairo_stroke(c); - return(0); -} - - - -int draw_numbers(cairo_t *c, double x, double y, struct dimensions d, int wd, int nd) { - char str[20]; - cairo_text_extents_t te; - cairo_font_extents_t fe; - - cairo_select_font_face (c, "sans-serif", - CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); - cairo_set_font_size (c, d.bw / 2); - - int iterative = 0; - cairo_font_extents (c, &fe); - double xi = x; - int current_weekday = wd; - x = d.m + (wd * d.bw); - for (int j = 0; j < d.r; j++) { - y = y + d.bh - ((d.bh - fe.ascent) / 2); - for (int k = current_weekday; k < d.c; k++) { - if (iterative < nd) { - snprintf(str, sizeof(str), "%d", iterative + 1); - cairo_text_extents (c, str, &te); - double box_margins = (d.bw - te.width) / 2; - - cairo_move_to(c, x + box_margins - te.x_bearing, y); /* center the number within the box */ - cairo_show_text(c, str); - cairo_move_to(c, x, y); /* Sort of backtrack to realign with the spacing of the boxes */ - x = x + d.bw; - iterative++; - current_weekday++; - } - } - current_weekday = 0; - y = y - (d.bh - ((d.bh - fe.ascent) / 2)); - y = y + d.bh; - x = xi; - } - return(0); -} - - - -int draw_month_name(cairo_t *c, char *name, struct dimensions d) { - double x, y = d.m; - cairo_set_font_size(c, 1.0); - cairo_text_extents_t te; - cairo_text_extents(c, name, &te); - x = (d.pw / 2) - (te.width / 2); - y = 1.5; - cairo_move_to(c, x, y); - cairo_show_text(c, &name[0]); - return(0); -} - diff --git a/draw.h b/draw.h deleted file mode 100644 index 7c473a7..0000000 --- a/draw.h +++ /dev/null @@ -1,24 +0,0 @@ -struct dimensions { - double pw; /* paper width */ - double ph; /* paper height */ - double mw; /* month width */ - double mh; /* month height */ - double bw; /* day box width */ - double bh; /* day box height */ - double r; /* rows */ - double c; /* columns */ - double m; /* margin */ -}; - - - -int draw_calendar(cairo_t *c, double x, double y, struct dimensions d); - - - - -int draw_numbers(cairo_t *c, double x, double y, struct dimensions d, int wd, int nd); - - - -int draw_month_name(cairo_t *c, char *name, struct dimensions d); diff --git a/main.c b/main.c deleted file mode 100644 index 51fb86d..0000000 --- a/main.c +++ /dev/null @@ -1,99 +0,0 @@ -/* Standard Libraries */ -#include -#include -#include -#include -#include -#include -#include - -/* Cairo Libraries */ -#include -#include - -/* calp Libraries */ -#include "color.h" -#include "date.h" -#include "draw.h" - - -// int main (int argc, char *argv[]) { -int main (void) { - /* Dimension initialization */ - int rows = 5; /* Number of weeks in a month */ - int columns = 7; /* Number of days in a week */ - double margin = 0.5; /* 0.5" */ - int number_of_days = 28; - - double month_origin_x = margin; - double month_origin_y = 3.0; - double paper_width = 8.5; - double paper_height = 11; - double month_width = paper_width - (month_origin_x * 2); - double month_height = paper_height - month_origin_y - margin; - double day_box_width = month_width / columns; - double day_box_height = month_height / rows; - - struct dimensions dim = { - paper_width, /* pw */ - paper_height, /* ph */ - month_width, /* mw */ - month_height, /* mh */ - day_box_width, /* bw */ - day_box_height, /* bh */ - rows, /* r */ - columns, /* c */ - margin, /* m */ - }; - - /* Date Setup */ - char *months[] = { - "January", "February", "March", "April", "May", - "June", "July", "August", "September", "October", - "November", "December" - }; - - //int days_in_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - - // const char *weekday_names[] = { - // "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" - // }; - - // const char *weekdays_abbr[] = { - // "Su", "Mo", "Tue", "Wed", "Thurs", "Fri", "Sat" - // }; - - int year = 2025; - int month = 2; - - struct tm day; - day.tm_mon = month - 1; - day.tm_mday = 1; - day.tm_year = year - 1900; - - /* tm.hour, tm_min, & tm_sec are not used, but need to be zeroed. */ - day.tm_hour = 0; - day.tm_min = 0; - day.tm_sec = 0; - - mktime(&day); - - cairo_surface_t * surface = cairo_pdf_surface_create("0.pdf", dim.pw * 72, dim.ph * 72); - cairo_t *cr = cairo_create(surface); - - - cairo_scale(cr, 72, 72); - set_color(cr, "BLACK"); - cairo_set_line_width (cr, 0.03); - - - draw_calendar(cr, month_origin_x, month_origin_y, dim); - set_color(cr, "GRAY"); - draw_numbers(cr, month_origin_x, month_origin_y, dim, day.tm_wday, number_of_days); - draw_month_name(cr, months[1], dim); - - /* Clean Up */ - cairo_destroy(cr); - cairo_surface_destroy(surface); - return(0); -} diff --git a/src/color.h b/src/color.h new file mode 100644 index 0000000..e2b4cc0 --- /dev/null +++ b/src/color.h @@ -0,0 +1,18 @@ + int set_color(cairo_t *c, char *str) { + if (strcmp("BLACK", str) == 0) { + cairo_set_source_rgb (c, 0.0, 0.0, 0.0); + } + if (strcmp("RED", str) == 0) { + cairo_set_source_rgb (c, 255.0, 0.0, 0.0); + } + if (strcmp("GREEN", str) == 0) { + cairo_set_source_rgb (c, 0.0, 255.0, 0.0); + } + if (strcmp("BLUE", str) == 0) { + cairo_set_source_rgb (c, 0.0, 0.0, 255.0); + } + if (strcmp("GREY", str) == 0) { + cairo_set_source_rgb (c, 128.0, 128.0, 128.0); + } + return(0); + } diff --git a/src/date.h b/src/date.h new file mode 100644 index 0000000..4ff3d32 --- /dev/null +++ b/src/date.h @@ -0,0 +1 @@ +/* date.h: Includes all the functions relating to calculating months, days, etc. */ diff --git a/src/draw.c b/src/draw.c new file mode 100644 index 0000000..51f9367 --- /dev/null +++ b/src/draw.c @@ -0,0 +1,94 @@ +#include +#include + +struct dimensions { + double pw; /* paper width */ + double ph; /* paper height */ + double mw; /* month width */ + double mh; /* month height */ + double bw; /* day box width */ + double bh; /* day box height */ + double r; /* rows */ + double c; /* columns */ + double m; /* margin */ +}; + + +int draw_calendar(cairo_t *c, double x, double y, struct dimensions d) { + double x1, y1, x2, y2; + x1 = x; + y1 = y; + x2 = d.pw - x1; /* Set the line endpoint to right side of the page */ + + for (int i = 0; i < d.r + 1; i++) { /* Draw Horizontal Lines */ + cairo_move_to (c, x, y); + cairo_line_to (c, x2, y); + y = y + d.bh; + } + + x = x1; + y = y1; + y2 = y1 + d.mh; /* Set the line endpoint as the bottom of the month */ + for (int i = 0; i < d.c + 1; i++) { /* Draw Vertical Lines */ + cairo_move_to (c, x, y); + cairo_line_to (c, x, y2); + x = x + d.bw; + } + cairo_stroke(c); + return(0); +} + + + +int draw_numbers(cairo_t *c, double x, double y, struct dimensions d, int wd, int nd) { + char str[20]; + cairo_text_extents_t te; + cairo_font_extents_t fe; + + cairo_select_font_face (c, "sans-serif", + CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); + cairo_set_font_size (c, d.bw / 2); + + int iterative = 0; + cairo_font_extents (c, &fe); + double xi = x; + int current_weekday = wd; + x = d.m + (wd * d.bw); + for (int j = 0; j < d.r; j++) { + y = y + d.bh - ((d.bh - fe.ascent) / 2); + for (int k = current_weekday; k < d.c; k++) { + if (iterative < nd) { + snprintf(str, sizeof(str), "%d", iterative + 1); + cairo_text_extents (c, str, &te); + double box_margins = (d.bw - te.width) / 2; + + cairo_move_to(c, x + box_margins - te.x_bearing, y); /* center the number within the box */ + cairo_show_text(c, str); + cairo_move_to(c, x, y); /* Sort of backtrack to realign with the spacing of the boxes */ + x = x + d.bw; + iterative++; + current_weekday++; + } + } + current_weekday = 0; + y = y - (d.bh - ((d.bh - fe.ascent) / 2)); + y = y + d.bh; + x = xi; + } + return(0); +} + + + +int draw_month_name(cairo_t *c, char *name, struct dimensions d) { + double x, y = d.m; + cairo_set_font_size(c, 1.0); + cairo_text_extents_t te; + cairo_text_extents(c, name, &te); + x = (d.pw / 2) - (te.width / 2); + y = 1.5; + cairo_move_to(c, x, y); + cairo_show_text(c, &name[0]); + return(0); +} + diff --git a/src/draw.h b/src/draw.h new file mode 100644 index 0000000..7c473a7 --- /dev/null +++ b/src/draw.h @@ -0,0 +1,24 @@ +struct dimensions { + double pw; /* paper width */ + double ph; /* paper height */ + double mw; /* month width */ + double mh; /* month height */ + double bw; /* day box width */ + double bh; /* day box height */ + double r; /* rows */ + double c; /* columns */ + double m; /* margin */ +}; + + + +int draw_calendar(cairo_t *c, double x, double y, struct dimensions d); + + + + +int draw_numbers(cairo_t *c, double x, double y, struct dimensions d, int wd, int nd); + + + +int draw_month_name(cairo_t *c, char *name, struct dimensions d); diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..6d76a6d --- /dev/null +++ b/src/main.c @@ -0,0 +1,97 @@ +/* Standard Libraries */ +#include +#include +#include +#include +#include +#include +#include + +/* Cairo Libraries */ +#include +#include + +/* calp Libraries */ +#include "color.h" +#include "date.h" +#include "draw.h" + +// int main (int argc, char *argv[]) { +int main (void) { + /* Dimension initialization */ + int rows = 6; /* Number of weeks in a month */ + int columns = 7; /* Number of days in a week */ + double margin = 0.5; /* 0.5" */ + int number_of_days = 28; + + double month_origin_x = margin; + double month_origin_y = 3.0; + double paper_width = 8.5; + double paper_height = 11; + double month_width = paper_width - (month_origin_x * 2); + double month_height = paper_height - month_origin_y - margin; + double day_box_width = month_width / columns; + double day_box_height = month_height / rows; + + struct dimensions dim = { + paper_width, /* pw */ + paper_height, /* ph */ + month_width, /* mw */ + month_height, /* mh */ + day_box_width, /* bw */ + day_box_height, /* bh */ + rows, /* r */ + columns, /* c */ + margin, /* m */ + }; + + /* Date Setup */ + char *months[] = { + "January", "February", "March", "April", "May", + "June", "July", "August", "September", "October", + "November", "December" + }; + + //int days_in_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + + // const char *weekday_names[] = { + // "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" + // }; + + // const char *weekdays_abbr[] = { + // "Su", "Mo", "Tue", "Wed", "Thurs", "Fri", "Sat" + // }; + + int year = 2025; + int month = 2; + + struct tm day; + day.tm_mon = month - 1; + day.tm_mday = 1; + day.tm_year = year - 1900; + + /* tm.hour, tm_min, & tm_sec are not used, but need to be zeroed. */ + day.tm_hour = 0; + day.tm_min = 0; + day.tm_sec = 0; + + mktime(&day); + + cairo_surface_t * surface = cairo_pdf_surface_create("0.pdf", dim.pw * 72, dim.ph * 72); + cairo_t *cr = cairo_create(surface); + + + cairo_scale(cr, 72, 72); + set_color(cr, "GRAY"); + cairo_set_line_width (cr, 0.03); + + + draw_calendar(cr, month_origin_x, month_origin_y, dim); + draw_numbers(cr, month_origin_x, month_origin_y, dim, day.tm_wday, number_of_days); + draw_month_name(cr, months[1], dim); + + /* Clean Up */ + cairo_destroy(cr); + cairo_surface_destroy(surface); + return(0); +} -- cgit v1.2.3