@@ -131,6 +131,25 @@ def done(self, dest, kind, title) -> DocumentPage:
131131 links = tuple (self .links ), title = title )
132132
133133
134+ def marked_days (cfg ) -> dict [datetime .date , str ]:
135+ """date → the colour that marks it (§ 7).
136+
137+ A marked day is any entry of `holidays` — a public holiday, a birthday, an
138+ anniversary; the calendar does not care which. Its own `color` wins, else the
139+ definition's `holiday_color`.
140+ """
141+ return {h .date : (h .color or cfg .holiday_color ) for h in cfg .holidays }
142+
143+
144+ def _badge (page : Page , x , top , text , size , color ) -> None :
145+ """A filled patch behind a piece of text — how a marked day shows itself
146+ where there is no cell to fill (§ 7). Drawn before the text, so the text
147+ reads over it; the patch is the glyphs' own width, measured."""
148+ pad = pt (1.5 )
149+ width = page .q .text_width (text , family = "sans" , size = round (size ))
150+ page .box (x - pad , top - pad , width + 2 * pad , size + 2 * pad , 0.0 , color , color )
151+
152+
134153# ------------------------------------------------------------------ nav strip
135154
136155
@@ -291,11 +310,12 @@ def year_overview_page(page: Page, cfg, n: Nav, months, weekdays) -> DocumentPag
291310 gutter = _YEAR_GUTTER
292311 cell_w = mini_month_cell_width (page .W )
293312 cell_h = (page .H - top - pt (2 ) - (rows - 1 ) * gutter ) / rows
313+ marked = marked_days (cfg )
294314 for m in range (12 ):
295315 r , c = divmod (m , cols )
296316 _mini_month (page , cfg , months , weekdays , m + 1 ,
297317 c * (cell_w + gutter ), top + r * (cell_h + gutter ), cell_w , cell_h ,
298- n .has_week )
318+ n .has_week , marked )
299319 return page .done ("year" , "year" , f"{ cfg .year } full year" )
300320
301321
@@ -330,7 +350,7 @@ def mini_month_cell_width(area_width: int) -> float:
330350
331351
332352def _mini_month (page : Page , cfg , months , weekdays , month , x , top , w , h ,
333- has_week : bool = False ) -> None :
353+ has_week : bool = False , marked : dict | None = None ) -> None :
334354 """One mini-month of the full-year overview (§ 7).
335355
336356 Everything hangs off one right edge per column: the weekday letter and every
@@ -406,6 +426,10 @@ def right_edge(column: int) -> float:
406426 # and the tap box follow the glyphs rather than a guessed box.
407427 cx = right_edge (idx % 7 ) - page .q .text_width (label , family = "sans" , size = round (day_size ))
408428 cy = grid_top + (idx // 7 ) * row_h
429+ # No cell boxes here by design (§ 7), so a marked day colours the number.
430+ colour = (marked or {}).get (datetime .date (cfg .year , month , d ))
431+ if colour :
432+ _badge (page , round (cx ), round (cy ), label , day_size , colour )
409433 page .link_text (round (cx ), round (cy ), label ,
410434 f"day-{ cfg .year :04d} -{ month :02d} -{ d :02d} " , day_size )
411435
@@ -434,6 +458,7 @@ def _half_table(page: Page, cfg, months, top, h, *, first_month: int) -> None:
434458 col_w = (page .W - day_col - (day_col if both else 0 )) / 6
435459 row_h = h / 32 # one header row + 31 day rows
436460 shade = cfg .year_view .weekend_shade
461+ marked = marked_days (cfg )
437462 size = pt (6.5 )
438463
439464 def in_row (row : int , text_size : float ) -> int :
@@ -456,8 +481,10 @@ def in_row(row: int, text_size: float) -> int:
456481 for d in range (1 , ndays + 1 ):
457482 rtop = top + row_h * d
458483 date = datetime .date (cfg .year , month , d )
459- if date .weekday () >= 5 and shade :
460- page .box (cx , rtop , col_w , row_h , 0.0 , shade , shade )
484+ # The marked day's own colour first: it is the more particular fact.
485+ fill = marked .get (date ) or (shade if date .weekday () >= 5 else None )
486+ if fill :
487+ page .box (cx , rtop , col_w , row_h , 0.0 , fill , fill )
461488 page .box (cx , rtop , col_w , row_h , 0.2 , GUIDE ) # only existing days get a cell
462489 if cfg .year_view .cell_link == "day" :
463490 page .links .append (
@@ -472,30 +499,38 @@ def month_page(page: Page, cfg, n: Nav, months, weekdays, month, holidays, prev,
472499 top = crumb (page , title = f"{ months [month - 1 ]} { cfg .year } " , prev = prev , nxt = nxt , up = "year" )
473500 avail = page .H - top - pt (2 )
474501 row_h = avail / ndays
502+ marked = marked_days (cfg )
475503 for d in range (1 , ndays + 1 ):
476504 date = datetime .date (cfg .year , month , d )
477505 rtop = top + (d - 1 ) * row_h
478- if date .weekday () >= 5 and cfg .month_view .weekend_shade :
479- page .box (0 , rtop , page .W , row_h , 0.0 ,
480- cfg .month_view .weekend_shade , cfg .month_view .weekend_shade )
506+ fill = marked .get (date ) or (
507+ cfg .month_view .weekend_shade if date .weekday () >= 5 else None
508+ )
509+ if fill :
510+ page .box (0 , rtop , page .W , row_h , 0.0 , fill , fill )
481511 page .hline (0 , page .W , rtop , 0.2 , GUIDE )
482512 page .link_text (pt (1 ), round (rtop + row_h / 2 - pt (5 )),
483513 f"{ weekdays [date .weekday ()]} { d } " , f"day-{ date .isoformat ()} " , pt (10 ))
484- label = holidays .get (date )
485- if label :
486- page .text (mm (22 ), round (rtop + row_h / 2 - pt (4 )), label , pt (8 ), LINK )
514+ holiday = holidays .get (date )
515+ if holiday is not None :
516+ page .text (mm (22 ), round (rtop + row_h / 2 - pt (4 )), holiday . label , pt (8 ), INK )
487517 page .hline (0 , page .W , top + ndays * row_h , 0.2 , GUIDE )
488518 return page .done (f"month-{ month :02d} " , "month" , f"{ months [month - 1 ]} { cfg .year } " )
489519
490520
491- def day_page (page : Page , cfg , n : Nav , months , weekdays , date , blocks , holiday_label , prev , nxt ):
521+ def day_page (page : Page , cfg , n : Nav , months , weekdays , date , blocks , holiday , prev , nxt ):
492522 month = date .month
493523 nav (page , n )
494524 title = f"{ weekdays [date .weekday ()]} { date .day } { months [month - 1 ]} "
495525 top = crumb (page , title = title , prev = prev , nxt = nxt , up = f"month-{ month :02d} " )
496- if holiday_label :
497- page .text (0 , top , holiday_label , pt (9 ), LINK )
498- top += pt (12 )
526+ if holiday is not None :
527+ # The day has no cell to fill, so the label wears the colour itself. It
528+ # starts a little lower than the body would: the patch reaches above the
529+ # cap, and the title above it has descenders.
530+ top += pt (4 )
531+ _badge (page , 0 , top , holiday .label , pt (9 ), holiday .color or cfg .holiday_color )
532+ page .text (0 , top , holiday .label , pt (9 ), INK )
533+ top += pt (16 )
499534 _draw_blocks (page , blocks , top )
500535 return page .done (f"day-{ date .isoformat ()} " , "day" , title )
501536
0 commit comments