/usr/lib/perl5/Ace/Graphics/GlyphFactory.pm is in libace-perl 1.92-2build3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | package Ace::Graphics::GlyphFactory;
# parameters for creating sequence glyphs of various sorts
# you *do* like glyphs, don't you?
use strict;
use Carp qw(carp croak confess);
use Ace::Graphics::Glyph;
use GD;
sub DESTROY { }
sub new {
my $class = shift;
my $type = shift;
my @options = @_;
# normalize options
my %options;
while (my($key,$value) = splice (@options,0,2)) {
$key =~ s/^-//;
$options{lc $key} = $value;
}
$options{bgcolor} ||= 'white';
$options{fgcolor} ||= 'black';
$options{fillcolor} ||= 'turquoise';
$options{height} ||= 10;
$options{font} ||= gdSmallFont;
$options{fontcolor} ||= 'black';
$type = $options{glyph} if defined $options{glyph};
my $glyphclass = 'Ace::Graphics::Glyph';
$glyphclass .= "\:\:$type" if $type && $type ne 'generic';
confess("the requested glyph class, ``$type'' is not available: $@")
unless (eval "require $glyphclass");
return bless {
glyphclass => $glyphclass,
scale => 1, # 1 pixel per kb
options => \%options,
},$class;
}
sub clone {
my $self = shift;
my %val = %$self;
$val{options} = {%{$self->{options}}};
return bless \%val,ref($self);
}
# set the scale for glyphs we create
sub scale {
my $self = shift;
my $g = $self->{scale};
$self->{scale} = shift if @_;
$g;
}
sub width {
my $self = shift;
my $g = $self->{width};
$self->{width} = shift if @_;
$g;
}
# font to draw with
sub font {
my $self = shift;
$self->option('font',@_);
}
# set the height for glyphs we create
sub height {
my $self = shift;
$self->option('height',@_);
}
sub options {
my $self = shift;
my $g = $self->{options};
$self->{options} = shift if @_;
$g;
}
sub panel {
my $self = shift;
my $g = $self->{panel};
$self->{panel} = shift if @_;
$g;
}
sub option {
my $self = shift;
my $option_name = shift;
my $o = $self->{options} or return;
my $d = $o->{$option_name};
$o->{$option_name} = shift if @_;
$d;
}
# set the foreground and background colors
# expressed as GD color indices
sub _fgcolor {
my $self = shift;
my $c = $self->option('color',@_) || $self->option('fgcolor',@_) || $self->option('outlinecolor',@_);
$self->translate($c);
}
sub fgcolor {
my $self = shift;
my $linewidth = $self->option('linewidth');
return $self->_fgcolor unless defined($linewidth) && $linewidth > 1;
$self->panel->set_pen($linewidth,$self->_fgcolor);
return gdBrushed;
}
sub fontcolor {
my $self = shift;
my $c = $self->option('fontcolor',@_);
$self->translate($c);
# return $self->_fgcolor;
}
sub bgcolor {
my $self = shift;
my $c = $self->option('bgcolor',@_);
$self->translate($c);
}
sub fillcolor {
my $self = shift;
my $c = $self->option('fillcolor',@_) || $self->option('color',@_);
$self->translate($c);
}
sub length { shift->option('length',@_) }
sub offset { shift->option('offset',@_) }
sub translate { my $self = shift; $self->panel->translate(@_) || $self->fgcolor; }
sub rgb { shift->panel->rgb(@_) }
# create a new glyph from configuration
sub glyph {
my $self = shift;
my $feature = shift;
return $self->{glyphclass}->new(-feature => $feature,
-factory => $self);
}
1;
__END__
=head1 NAME
Ace::Graphics::GlyphFactory - Create Ace::Graphics::Glyphs
=head1 SYNOPSIS
use Ace::Graphics::GlyphFactory;
my $factory = Ace::Graphics::GlyphFactory($glyph_name,@options);
=head1 DESCRIPTION
The Ace::Graphics::GlyphFactory class is used internally by
Ace::Graphics::Track and Ace::Graphics::Glyph to hold the options
pertaining to a set of related glyphs and creating them on demand.
This class is not ordinarily useful to the end-developer.
=head1 METHODS
This section describes the class and object methods for
Ace::Graphics::GlyphFactory.
=head2 CONSTRUCTORS
There is only one constructor, the new() method. It is ordinarily
called by Ace::Graphics::Track, in the make_factory() subroutine.
=over 4
=item $factory = Ace::Graphics::GlyphFactory->new($glyph_name,@options)
The new() method creates a new factory object. The object will create
glyphs of type $glyph_name, and using the options specified in
@options. Generic options are described in L<Ace::Graphics::Panel>,
and specific options are described in each of the
Ace::Graphics::Glyph::* manual pages.
=back
=head2 OBJECT METHODS
Once a track is created, the following methods can be invoked:
=over 4
=item $glyph = $factory->glyph($feature)
Given a sequence feature, creates an Ace::Graphics::Glyph object to
display it. The various attributes of the glyph are set from the
options provided at factory creation time.
=item $option = $factory->option($option_name [,$new_option])
Given an option name, returns its value. If a second argument is
provided, sets the option to the new value and returns its previous
one.
=item $index = $factory->fgcolor
Returns the desired foreground color for the glyphs in the form of an
GD::Image color index. This may be the one of the special colors
gdBrushed and gdStyled. This is only useful while the enclosing
Ace::Graphics::Panel object is rendering the object. In other
contexts it returns undef.
=item $scale = $factory->scale([$scale])
Get or set the scale, in pixels/bp, for the glyph. This is
ordinarily set by the Ace::Graphics::Track object just prior to
rendering, and called by each glyphs' map_pt() method when performing
the rendering.
=item $color = $factory->bgcolor([$color])
Get or set the background color for the glyphs.
=item $color = $factory->fillcolor([$color])
Get or set the fill color for the glyphs.
=item $font = $factory->font([$font])
Get or set the font to use for rendering the glyph.
=item $color = $factory->fontcolor
Get the color for the font (to set it, use fgcolor()). This is subtly
different from fgcolor() itself, because it will never return a styled
color, such as gdBrushed.
=item $panel = $factory->panel([$panel])
Get or set the panel that contains the GD::Image object used by this
factory.
=item $index = $factory->translate($color)
=item @rgb = $factory->rgb($index)
These are convenience procedures that are passed through to the
enclosing Panel object and have the same effect as the like-named
methods in that class. See L<Ace::Graphics::Panel>.
=back
=head1 BUGS
Please report them.
=head1 SEE ALSO
L<Ace::Sequence>, L<Ace::Sequence::Feature>, L<Ace::Graphics::Panel>,
L<Ace::Graphics::Track>, L<Ace::Graphics::Glyph>
=head1 AUTHOR
Lincoln Stein <lstein@cshl.org>.
Copyright (c) 2001 Cold Spring Harbor Laboratory
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself. See DISCLAIMER.txt for
disclaimers of warranty.
=cut
|