| 1 | |||
| 2 | require 5; | ||
| 3 | use strict; | ||
| 4 | package Tk::Pod::Styles; | ||
| 5 | |||
| 6 | use vars qw($VERSION); | ||
| 7 | $VERSION = '5.06'; | ||
| 8 | |||
| 9 | sub init_styles { | ||
| 10 | my $w = shift; | ||
| 11 | if (!defined $w->{'style'}{'base_font_size'}) { | ||
| 12 | $w->set_base_font_size($w->standard_font_size); | ||
| 13 | } | ||
| 14 | } | ||
| 15 | |||
| 16 | sub standard_font_size { | ||
| 17 | my $w = shift; | ||
| 18 | my $std_font = $w->optionGet('font', 'Font'); | ||
| 19 | my $std_font_size; | ||
| 20 | if (!defined $std_font || $std_font eq '') { | ||
| 21 | my $l = $w->Label; | ||
| 22 | $std_font = $l->cget(-font); | ||
| 23 | $std_font_size = $l->fontActual($std_font, '-size'); | ||
| 24 | $l->destroy; | ||
| 25 | } else { | ||
| 26 | $std_font_size = $w->fontActual($std_font, '-size'); | ||
| 27 | } | ||
| 28 | $std_font_size; | ||
| 29 | } | ||
| 30 | |||
| 31 | sub adjust_font_size { | ||
| 32 | my($w, $new_size) = @_; | ||
| 33 | my $delta = $new_size - $w->base_font_size; | ||
| 34 | $w->set_base_font_size($new_size); | ||
| 35 | |||
| 36 | for my $tag ($w->tagNames) { | ||
| 37 | my $fontsize = $w->{'style_fontsize'}{$tag}; | ||
| 38 | my $f = $w->tagCget($tag, '-font'); | ||
| 39 | if ($f) { | ||
| 40 | my %f = $w->fontActual($f); | ||
| 41 | if (!defined $fontsize) { | ||
| 42 | $fontsize = $f{-size}; | ||
| 43 | } | ||
| 44 | $fontsize += $delta; | ||
| 45 | $w->{'style_fontsize'}{$tag} = $fontsize; | ||
| 46 | $f{-size} = $fontsize; | ||
| 47 | my $new_f = $w->fontCreate(%f); | ||
| 48 | $w->tagConfigure($tag, -font => $new_f); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | sub set_base_font_size { $_[0]{'style'}{'base_font_size'} = $_[1] } | ||
| 54 | |||
| 55 | sub base_font_size { return $_[0]{'style'}{'base_font_size'} ||= 10 } | ||
| 56 | |||
| 57 | sub font_sans_serif { | ||
| 58 | my $w = shift; | ||
| 59 | $w->optionGet("sansSerifFont", "SansSerifFont") || "helvetica"; | ||
| 60 | } | ||
| 61 | |||
| 62 | sub font_serif { | ||
| 63 | my $w = shift; | ||
| 64 | $w->optionGet("serifFont", "SerifFont") || "times"; | ||
| 65 | } | ||
| 66 | |||
| 67 | sub font_monospace { | ||
| 68 | my $w = shift; | ||
| 69 | $w->optionGet("monospaceFont", "MonospaceFont") || "courier"; | ||
| 70 | } | ||
| 71 | |||
| 72 | sub style_over_bullet { | ||
| 73 | $_[0]->{'style'}{'over_bullet'} ||= | ||
| 74 | [ 'indent' => $_[1]->attr('indent') || 4, @{ $_[0]->style_Para } ] | ||
| 75 | } | ||
| 76 | sub style_over_number { | ||
| 77 | $_[0]->{'style'}{'over_number'} ||= | ||
| 78 | [ 'indent' => $_[1]->attr('indent') || 4, @{ $_[0]->style_Para } ] | ||
| 79 | } | ||
| 80 | sub style_over_text { | ||
| 81 | $_[0]->{'style'}{'over_text'} ||= | ||
| 82 | [ 'indent' => $_[1]->attr('indent') || 4, @{ $_[0]->style_Para } ] | ||
| 83 | } | ||
| 84 | |||
| 85 | sub style_item_text { | ||
| 86 | $_[0]->{'style'}{'item_text'} ||= | ||
| 87 | [ 'indent' => -1, @{ $_[0]->style_Para } ] # for back-denting | ||
| 88 | } | ||
| 89 | sub style_item_bullet { | ||
| 90 | $_[0]->{'style'}{'item_bullet'} ||= | ||
| 91 | [ 'indent' => -1, @{ $_[0]->style_Para } ] # for back-denting | ||
| 92 | } | ||
| 93 | sub style_item_number { | ||
| 94 | $_[0]->{'style'}{'item_number'} ||= | ||
| 95 | [ 'indent' => -1, @{ $_[0]->style_Para } ] # for back-denting | ||
| 96 | } | ||
| 97 | |||
| 98 | sub style_Para { | ||
| 99 | $_[0]->{'style'}{'Para'} ||= | ||
| 100 | [ 'family' => $_[0]->font_serif, | ||
| 101 | 'size' => $_[0]->base_font_size, | ||
| 102 | ] | ||
| 103 | } | ||
| 104 | |||
| 105 | sub style_Verbatim { | ||
| 106 | $_[0]->{'style'}{'Verbatim'} ||= | ||
| 107 | [ 'family' => $_[0]->font_monospace, | ||
| 108 | 'size' => $_[0]->base_font_size, | ||
| 109 | 'wrap' => 'none', | ||
| 110 | # background => '#cccccc', | ||
| 111 | # borderwidth => 1, | ||
| 112 | # relief => "solid", | ||
| 113 | # lmargin1 => 10, | ||
| 114 | # rmargin => 10, | ||
| 115 | ] | ||
| 116 | } | ||
| 117 | |||
| 118 | sub style_head1 { | ||
| 119 | $_[0]->{'style'}{'head1'} ||= | ||
| 120 | [ 'family' => $_[0]->font_sans_serif, | ||
| 121 | 'size' => int(1 + 1.75 * $_[0]->base_font_size), | ||
| 122 | 'underline' => 'true', | ||
| 123 | ] | ||
| 124 | } | ||
| 125 | sub style_head2 { | ||
| 126 | $_[0]->{'style'}{'head2'} ||= | ||
| 127 | [ 'family' => $_[0]->font_sans_serif, | ||
| 128 | 'size' => int(1 + 1.50 * $_[0]->base_font_size), | ||
| 129 | 'underline' => 'true', | ||
| 130 | ] | ||
| 131 | } | ||
| 132 | sub style_head3 { | ||
| 133 | $_[0]->{'style'}{'head3'} ||= | ||
| 134 | [ 'family' => $_[0]->font_sans_serif, | ||
| 135 | 'size' => int(1 + 1.25 * $_[0]->base_font_size), | ||
| 136 | 'underline' => 'true', | ||
| 137 | ] | ||
| 138 | } | ||
| 139 | sub style_head4 { | ||
| 140 | $_[0]->{'style'}{'head4'} ||= | ||
| 141 | [ 'family' => $_[0]->font_sans_serif, | ||
| 142 | 'size' => int(1 + 1.10 * $_[0]->base_font_size), | ||
| 143 | 'underline' => 'true', | ||
| 144 | ] | ||
| 145 | } | ||
| 146 | |||
| 147 | # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ | ||
| 148 | |||
| 149 | sub style_C { | ||
| 150 | $_[0]->{'style'}{'C'} ||= [ 'family' => $_[0]->font_monospace, ] } | ||
| 151 | |||
| 152 | sub style_B { | ||
| 153 | $_[0]->{'style'}{'B'} ||= [ 'weight' => 'bold', ] } | ||
| 154 | |||
| 155 | sub style_I { | ||
| 156 | $_[0]->{'style'}{'I'} ||= [ 'slant' => 'italic' , ] } | ||
| 157 | |||
| 158 | sub style_F { | ||
| 159 | $_[0]->{'style'}{'F'} ||= [ 'slant' => 'italic' , ] } | ||
| 160 | |||
| 161 | #sub style_S { | ||
| 162 | # $_[0]->{'style'}{'C'} ||= [ 'wrap' => 'none' ] } | ||
| 163 | |||
| 164 | # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ | ||
| 165 | 1; | ||
| 166 | __END__ |