#!/usr/bin/env ruby # coding: utf-8 #--------------------------------------------------------------- # # p3cal: png/pdf/ps calendar renderer # #--------------------------------------------------------------- if(ARGV.size == 0) abort(< 'cal', :type => 'pdf' }) # png/pdf/ps win.clear; win.box('|', '-') # cls ((target_month || 1)..(target_month || 12)).each {|month| # 曜日描画 wcols = [ 2, 0, 0, 0, 0, 0, 1, 2] #wdays = %w! Sun Mon Tue Wed Thu Fri Sat Hol! wdays = %w! 日 月 火 水 木 金 土 祝! row = 64; rstep = 80; 7.times {|wday| ps = { :font_family => 'Osaka', :font_weight => 400, :font_size => 20, :layout_width => 128, :layout_alignment => 'center', :get_size => true } win.text(wday * 128 + 64, row, wdays[wday], wcols[wday], ps); ps.delete(:get_size) win.text(wday * 128 + 64, row, wdays[wday], wcols[wday], ps) } # 日付描画 start = Time.local(target_year, month); count = start.dup row += rstep; while(start.month == count.month) holyday = holydays[count.strftime('%Y%m%d')] ps = { :font_family => 'Osaka', :font_weight => 400, :font_size => 36, :layout_width => 128, :layout_alignment => 'left', :get_size => true } win.text(count.wday * 128 + 64, row, count.day.to_s, wcols[holyday ? 7 : count.wday], ps); ps.delete(:get_size) win.text(count.wday * 128 + 64, row, count.day.to_s, wcols[holyday ? 7 : count.wday], ps) win.line(count.wday * 128 + 60, row, count.wday * 128 + 180, row - 4, 0) win.line(count.wday * 128 + 60, row, count.wday * 128 + 64, row + rstep - 4, 0) count.wday == 6 and row += rstep count += 24 * 60 * 60 end # ページ生成(pdf/ps) win.refresh } win.getch win.close __END__