3
3
import argparse
4
4
import sys
5
5
import os
6
+ import math
6
7
7
8
import cairo
8
9
@@ -214,8 +215,10 @@ def draw_grid(ctx, date, birthdate, age, darken_until_date):
214
215
pos_y += box_size + BOX_MARGIN
215
216
date += datetime .timedelta (weeks = 52 )
216
217
218
+ return x_margin
217
219
218
- def gen_calendar (birthdate , title , age , filename , darken_until_date ):
220
+ def gen_calendar (birthdate , title , age , filename , darken_until_date , sidebar_text = None ,
221
+ subtitle_text = None ):
219
222
if len (title ) > MAX_TITLE_SIZE :
220
223
raise ValueError ("Title can't be longer than %d characters"
221
224
% MAX_TITLE_SIZE )
@@ -240,10 +243,27 @@ def gen_calendar(birthdate, title, age, filename, darken_until_date):
240
243
ctx .move_to ((DOC_WIDTH / 2 ) - (w / 2 ), (Y_MARGIN / 2 ) - (h / 2 ))
241
244
ctx .show_text (title )
242
245
246
+ if subtitle_text is not None :
247
+ ctx .set_source_rgb (0.7 , 0.7 , 0.7 )
248
+ ctx .set_font_size (SMALLFONT_SIZE )
249
+ w , h = text_size (ctx , subtitle_text )
250
+ ctx .move_to ((DOC_WIDTH / 2 ) - (w / 2 ), (Y_MARGIN / 2 ) - (h / 2 ) + 15 )
251
+ ctx .show_text (subtitle_text )
252
+
243
253
date = back_up_to_monday (birthdate )
244
254
245
255
# Draw 52x90 grid of squares
246
- draw_grid (ctx , date , birthdate , age , darken_until_date )
256
+ x_margin = draw_grid (ctx , date , birthdate , age , darken_until_date )
257
+
258
+ if sidebar_text is not None :
259
+ # Draw text on sidebar
260
+ w , h = text_size (ctx , sidebar_text )
261
+ ctx .move_to ((DOC_WIDTH - x_margin ) + 20 , Y_MARGIN + w + 100 )
262
+ ctx .set_font_size (SMALLFONT_SIZE )
263
+ ctx .set_source_rgb (0.7 , 0.7 , 0.7 )
264
+ ctx .rotate (- 90 * math .pi / 180 )
265
+ ctx .show_text (sidebar_text )
266
+
247
267
ctx .show_page ()
248
268
249
269
@@ -263,6 +283,14 @@ def main():
263
283
help = 'Calendar title text (default is "%s")' % DEFAULT_TITLE ,
264
284
default = DEFAULT_TITLE )
265
285
286
+ parser .add_argument ('-s' , '--sidebar-text' , type = str , dest = 'sidebar_text' ,
287
+ help = 'Text to show along the right side of grid (default is no sidebar text)' ,
288
+ default = None )
289
+
290
+ parser .add_argument ('-b' , '--subtitle-text' , type = str , dest = 'subtitle_text' ,
291
+ help = 'Text to show under the calendar title (default is no subtitle text)' ,
292
+ default = None )
293
+
266
294
parser .add_argument ('-a' , '--age' , type = int , dest = 'age' , choices = range (MIN_AGE , MAX_AGE + 1 ),
267
295
metavar = '[%s-%s]' % (MIN_AGE , MAX_AGE ),
268
296
help = ('Number of rows to generate, representing years of life' ),
@@ -276,7 +304,8 @@ def main():
276
304
doc_name = '%s.pdf' % (os .path .splitext (args .filename )[0 ])
277
305
278
306
try :
279
- gen_calendar (args .date , args .title , args .age , doc_name , args .darken_until_date )
307
+ gen_calendar (args .date , args .title , args .age , doc_name , args .darken_until_date ,
308
+ sidebar_text = args .sidebar_text , subtitle_text = args .subtitle_text )
280
309
except Exception as e :
281
310
print ("Error: %s" % e )
282
311
return
0 commit comments