# script to create an A3 paysage yearly calendar
#
Options {
  PaperSize 3     # A3
  Limits {
    # not Shown
    Landscape
    # Default
  }
  Grid {
    Spacing 1
    Divisions 2
    # Rectangular
    # no AutoAdjust
    # Shown # not Shown
    Lock # no Lock
    # centimetre default
  }
  Zoom {
    Ratio 1 1
    # no Lock
  }
  # toolbox present
  Mode Select
  UndoSize 8192
}

Units $Centimetres

FontTable {
  1 "Homerton.Medium"
}



#======= box for month name or Day letter ===========
# text  %m
define box [ %x0 %y0 %w %h %m ] {
  path {
    FillColour none
    OutlineColour r0g0b0
    Width 0
	Move  %x0 %y0
	Line ( ( %x0        %y0 + %h  ) )
	Line ( ( %x0 + %w   %y0 + %h  ) )
	Line ( ( %x0 + %w   %y0       ) )
	Line ( ( %x0        %y0       ) )
	Close
  }

	Text {
	  CentreAt  ( %x0 + %w / 2 ) ( %y0 + %h / 2 )
	  Size  .7 .7
	  Style 1
	  Text %m
	}
}


#============ week-end box ==============
# dfault
# %w = 2
# %h = 29
Define we_box [ %x0 %y0 ] {
  set %w 2
  set %h 28
  path {
    FillColour r240g240b240
    OutlineColour r0g0b0
    Width 0
   	Move  %x0 %y0
	Line ( ( %x0        %y0 + %h  ) )
	Line ( ( %x0 + %w   %y0 + %h  ) )
	Line ( ( %x0 + %w   %y0       ) )
	Line ( ( %x0        %y0       ) )
	Close
  }
}

#============== month boxes ================
# dfault
# %w = 1
# %h = 2
# %ph public holidays
Define monthboxes [ %x0 %y0 %ph ] {
  set %w 1
  set %h 2
  path {
    IfEqual %ph 0     FillColour transparent
    Else FillColour r250g187b187
    Endif
    OutlineColour r0g0b0
    Width 0
   	Move  %x0 %y0
	Line ( ( %x0        %y0 + %h  ) )
	Line ( ( %x0 + %w   %y0 + %h  ) )
	Line ( ( %x0 + %w   %y0       ) )
	Line ( ( %x0        %y0       ) )
	Close
  }
}

#================  month line ==================
Define month_line [ %nb_days  %pos_x  %pos_y %phd ] {
  set %pos_x ( %pos_x +  2 )
  for %d  from 1 to %nb_days Step 1 {
     monthboxes [ ( %pos_x + %d )  ( %pos_y )  0 ]
   }
  for $phd in %phd  do {
     monthboxes [ ( %pos_x + $phd )  ( %pos_y )  1 ]
  }
  for %d  from 1 to %nb_days Step 1 {
    Text {
   	 Colour r0g0b0
    	 Background transparent
    	  CentreAt ( %pos_x + 0.5 + %d ) ( %pos_y  + 1.75 )
    	  Size  .5 .5
    	  Style 1
    	  Text Num2Str %d
    }
  }

}

#=========== year Box ========
# Box with rounded corners.
# on construit en tournant dans le sens trigo
# %x0,%y0 is bottom left corner point
# %w,%h are width and height
# %rx, %ry  are corner radius x, y
define rect_rounded [ %x0 %y0 %w %h %rx %ry ] {
  path {
    FillColour none
    OutlineColour r120g120b120
    Width 0.1
	move ( ( %x0             %y0 + %ry               ) )
	arc  ( ( %x0 + %rx       %y0 + %ry        $pi/2 ) )
	line ( ( %x0 + %w - %rx  %y0                    ) )
	arc  ( ( %x0 + %w - %rx  %y0 + %ry        $pi/2 ) )
	line ( ( %x0 + %w        %y0 + %h - %ry         ) )
	arc  ( ( %x0 + %w - %rx  %y0 + %h - %ry    $pi/2 ) )
	line ( ( %x0 + %rx       %y0 + %h                ) )
	arc  ( ( %x0 + %rx       %y0 + %h - %ry    $pi/2 ) )
	line ( ( %x0             %y0 + %ry               ) )
	close
    }
}

# start drawing

#========== background group =========

Group {
   Name "background"

   #months column
    set $month_x 1
    set $month_y 25
   for $Month in { "Jan" "Feb" "Mar" "Apr" "May" "June" "July" "Aug" "Sept" "Oct" "Nov" "Dec" } do {
     box [ $month_x $month_y 2 2 $Month ]
     set $month_y  ( $month_y - 2  )
   }

   # grey week-end
   # $y = 1
   for $x from 5 to 33  step 7 {
      we_box [ $x  1 ]
   }


   #days raw 1
    set $day_x 4
    set $day_y 28
   for $Day in { "F" "S" "S" "M" "T" "W" "T" "F" "S" "S" "M" "T" "W" "T" "F" "S" "S" "M" "T" "W" "T" "F" "S" "S" "M" "T" "W" "T" "F" "S" "S" "M" "T" "W" "T" "F" "S"} do {
     box [ $day_x $day_y 1 1 $Day ]
     set $day_x  ( $day_x + 1 )
   }

   #days raw 2
    set $day_x 4
    set $day_y 1
   for $Day in { "F" "S" "S" "M" "T" "W" "T" "F" "S" "S" "M" "T" "W" "T" "F" "S" "S" "M" "T" "W" "T" "F" "S" "S" "M" "T" "W" "T" "F" "S" "S" "M" "T" "W" "T" "F" "S"} do {
     box [ $day_x $day_y 1 1 $Day ]
     set $day_x  ( $day_x + 1 )
   }
   # year
   rect_rounded [ 1 27.5  2 1.5  .2 .2 ]
    Text {
   	 Colour r0g0b0
    	 Background transparent
    	  CentreAt ( 2  ) ( 27.5  + 1.6 / 2 )
    	  Size  .7 .8
    	  Style 1
    	  Text "2026"
    }
}

#start day of week: sdow

  set $Fr 1
  set $Sa 2
  set $Su 3
  set $Mo 4
  set $Tu 5
  set $We 6
  set $Th 7


# public holidays
# $phd days list
# 1 Jan Sunday pos_x : 5+1
# month pos_y : 25
# days_number : 31
Group {
  Name "Jan"
  set $phd { 1 }
  month_line [ 31 $Th 25 $phd  ] 
}

# 1 Feb wednesday pos_x 8+1
# month pos_y : 23
# $leap_year : 28 days (or 29)
Group {
  Name "Feb"
  set $phd { }
  set $leap_year 28
  month_line [ $leap_year $Su 23 $phd  ]
}

# 1 Mars wednesday pos_x 8+1
# month pos_y : 23
Group {
  Name "Mar"
  set $phd { }
  month_line [ 31 $Su 21 $phd  ]
}

# 1 Apr saturday pos_x 4+1
# month pos_y : 19
Group {
  Name "Apr"
  set $phd { 6 }
  month_line [ 30 $We 19 $phd  ]
}

# 1 May Monday pos_x 6+1
# month pos_y : 17
Group {
  Name "May"
  set $phd { 1 8 25 }
  month_line [ 31 $Fr 17 $phd  ]
}

# 1 June Tuesday pos_x 9+1
# month pos_y : 15
Group {
  Name "June"
  set $phd {  }
  month_line [ 30 $Mo 15 $phd  ]
}

# 1 July Saturday pos_x 4+1
# month pos_y : 13
Group {
  Name "Jul"
  set $phd { 14 }
  month_line [ 31 $We 13 $phd  ]
}

# 1 August Thursday pos_x 7+1
# month pos_y : 11
Group {
  Name "Aug"
  set $phd { 15 }
  month_line [ 31 $Sa 11 $phd  ]
}

# 1 September Firsday pos_x 3+1
# month pos_y : 9
Group {
  Name "Sept"
  set $phd {  }
  month_line [ 30 $Tu 9 $phd  ]
}

# 1 October Sunday pos_x 5+1
# month pos_y : 7
Group {
  Name "Oct"
  set $phd { 2 }
  month_line [ 31 $Th 7 $phd  ]
}

# 1 November Wednesday pos_x 7+1
# month pos_y : 5
Group {
  Name "Nov"
  set $phd { 11 }
  month_line [ 30 $Su 5 $phd  ]
}

# 1 December Thursday pos_x 3+1
# month pos_y : 3
Group {
  Name "Dec"
  set $phd { 25 }
  month_line [ 31 $Tu 3 $phd  ]
}




