RTF-HTMLConverter
view release on metacpan or search on metacpan
HTMLConverter.pm view on Meta::CPAN
return $buf;
}
sub get_parsed_group_text {
my $self = shift;
my $buf = $self->set_new_group_buffer();
$self->parse();
return $buf->get_text();
}
sub get_parsed_group_pcdata { $_[0]->set_pcdata_mode(); $_[0]->get_parsed_group_text() }
sub set_group_cwhandler {
my ($self, $prefix) = @_;
my @oldvalues;
$oldvalues[0] = $self->set_token_handler(CWORD, 'pth_cword');
$oldvalues[1] = $self->{cword_prefix};
$self->{cword_prefix} = $prefix;
$self->add_on_leave_handler('_restore_cwhandler', \@oldvalues);
}
HTMLConverter.pm view on Meta::CPAN
my $old = $self->notes($key => $value);
$self->_add_on_leave('on_leave2', sub { $_[0]->notes($_[1], $_[2]) }, [$key, $old]);
return $old;
}
sub store_notes {
my ($self, $arr) = splice(@_, 0, 2);
$self->add_on_leave_handler(sub { push @{$_[1]}, map { $_[0]->notes($_) } @{$_[2]} }, [$arr, [@_]]);
}
sub set_pcdata_mode { $_[0]->group_notes(pcdata => 1) }
sub _add_on_leave { unshift @{$_[0]->{$_[1]}[0]}, [$_[2], $_[3] || []] }
sub add_on_leave_handler { shift()->_add_on_leave('on_leave1', @_) }
sub add_sect_on_leave_handler {
my ($self, $sub, $args) = @_;
unshift @{$self->{sect_on_leave}}, [$sub, $args || []];
}
HTMLConverter.pm view on Meta::CPAN
substr($string, 0, $uc) = '';
$self->out($string) if length $string;
}
sub cw_uc { $_[0]->group_notes(uc => $_[1]) }
###### Font Table
sub cw_fonttbl {
my $self = shift;
$self->set_pcdata_mode();
$self->set_new_group_buffer();
$self->set_group_cwhandler('fcw_');
$self->parse();
my $deff = $self->notes('deff');
if(length $deff){
my $font = $self->notes('f'.$deff);
return unless $font;
$self->notes(f => $font);
my $ff = $self->_get_font_family($font);
return unless $ff;
my $style = $self->get_style_element();
$self->append_text_node($style, " BODY { font-family: $ff; font-size: 10pt }\n", 1) if $style;
}
}
sub fcw_f {
my ($self, $num) = @_;
my $font = {};
$self->notes(f => $font);
$self->notes('f'.$num => $font);
my $txt = $self->get_parsed_group_pcdata();
$txt =~ s/;$//;
$font->{face} = $txt;
}
sub fcw_fnil { delete (($_[0]->notes('f') || {})->{family}) }
sub fcw_froman { ($_[0]->notes('f') || {})->{family} = 'serif' }
sub fcw_fswiss { ($_[0]->notes('f') || {})->{family} = 'sans-serif' }
sub fcw_fmodern { ($_[0]->notes('f') || {})->{family} = 'monospace' }
sub fcw_fscript { ($_[0]->notes('f') || {})->{family} = 'cursive' }
sub fcw_fdecor { ($_[0]->notes('f') || {})->{family} = 'fantasy' }
HTMLConverter.pm view on Meta::CPAN
my ($self, $num) = @_;
my $font = $self->notes('f');
return unless $font;
$font->{codepage} = $charsets{$num};
}
}
sub fcw_falt {
my $self = shift;
my $font = $self->notes('f');
my $txt = $self->get_parsed_group_pcdata();
($font || {})->{falt} = $txt;
}
sub _get_text_encoding {
($_[0]->notes('pcdata') ? {} : $_[0]->notes('f') || {})->{codepage}
|| $_[0]->notes('ansicpg') || $_[0]->{doc_codepage}
}
sub _get_font_family { $_[1]->{family} }
###### Color Table
sub cw_colortbl {
my $self = shift;
$self->set_pcdata_mode();
$self->notes(colortbl => []);
$self->group_notes(colortbl_current => [(undef)x3]);
$self->set_group_token_handler(PTEXT, 'th_ptext_colortbl');
}
sub cw_red { ($_[0]->notes('colortbl_current') || [])->[0] = sprintf("%02x", $_[1]) }
sub cw_green { ($_[0]->notes('colortbl_current') || [])->[1] = sprintf("%02x", $_[1]) }
sub cw_blue { ($_[0]->notes('colortbl_current') || [])->[2] = sprintf("%02x", $_[1]) }
sub th_ptext_colortbl {
HTMLConverter.pm view on Meta::CPAN
my $text = $token->text();
return unless $text =~ /;/;
push @{$self->notes('colortbl')}, $self->notes('colortbl_current');
$self->notes(colortbl_current => [(undef)x3]);
}
###### Style Sheet
sub cw_stylesheet {
my $self = shift;
$self->set_pcdata_mode();
$self->set_new_group_buffer();
$self->set_group_cwhandler('scw_');
my $oldh = $self->set_group_token_handler(ENTER, 'th_enter_style');
$self->group_notes(stylesheet_enter => $oldh);
}
sub th_enter_style {
my $self = shift;
my $oldh = $self->notes('stylesheet_enter');
$self->$oldh();
HTMLConverter.pm view on Meta::CPAN
$self->notes('list'.($num || 0) => $list);
}
sub ltcw_listtemplateid { ($_[0]->notes('list') || {})->{templateid} = $_[1] }
sub ltcw_listsimple { ($_[0]->notes('list') || {})->{simple} = $_[1] }
sub ltcw_listhybrid { ($_[0]->notes('list') || {})->{hybrid} = 1 }
sub ltcw_listname {
my $self = shift;
my $txt = $self->get_parsed_group_pcdata();
$txt =~ s/;$//;
($self->notes('list') || {})->{name} = $txt;
}
######## List Levels
sub ltcw_listlevel {
my $self = shift;
my $list = $self->_get_current_list();
unless($list){
HTMLConverter.pm view on Meta::CPAN
#### Document Area
###### Information Group
sub cw_info { }
sub cw_title {
my $self = shift;
my $text = $self->get_parsed_group_pcdata();
my $head = $self->get_head_element();
return unless $head;
my $title = $self->create_element('title', $head);
$self->append_text_node($title, $text);
}
###### Document Formatting Properties
sub cw_private { $_[0]->set_destination() if $_[1] == 1 }
HTMLConverter.pm view on Meta::CPAN
my ($self, $txt) = @_;
$self->{ancor_count} = 0 unless defined $self->{ancor_count};
$self->{ancors} ||= {};
my $name = $self->{ancors}{$txt};
return $name if defined $name;
return $self->{ancors}{$txt} = 'a'.$self->{ancor_count}++;
}
sub cw_bkmkstart {
my $self = shift;
$self->set_pcdata_mode();
my $txt = $self->get_parsed_group_text();
my $name = $self->_get_ancor_name($txt);
my $el= $self->create_element('a');
$el->setAttribute(name => $name);
$self->append_text_node($el, ' ');
$self->append_element($el);
}
###### Pictures
( run in 0.706 second using v1.01-cache-2.11-cpan-454fe037f31 )