Subject: | PATCH - Add centering support for p and h# tags |
Hi Sean,
I've attached a patch against v2.04 of FormatRTF.pm which adds support
for centering to header and paragraph tags. Thanks for creating an
excellent tool for doing HTML-RTF conversion.
William
Subject: | FormatRTF.pm.diff |
--- HTML-Format-2.04/lib/HTML/FormatRTF.pm 2004-06-02 03:47:44.000000000 -0400
+++ HTML/FormatRTF.pm 2006-03-11 13:24:34.000000000 -0500
@@ -304,14 +304,23 @@
# This really should have been called heading_start, but it's too late
# to change now.
- my($self, $level) = @_;
+ my($self, $level, $node) = @_;
DEBUG > 1 and print " Heading of level $level\n";
#$self->adjust_lm(0); # assert new paragraph
$self->vspace(1.5);
- $self->out( \( sprintf '\s3%s\ql\keepn\f2\fs%s\ul'."\n",
+ my $align = $node->attr('align');
+ if (defined($align) && lc($align) eq 'center') {
+ $align = 'qc';
+ }
+ else {
+ $align = 'ql';
+ }
+
+ $self->out( \( sprintf '\s3%s\%s\keepn\f2\fs%s\ul'."\n",
$level,
+ $align,
$self->{'head' . $level .'_halfpoint_size'},
$level,
));
@@ -378,6 +387,32 @@
sub strike_start { shift->out( \'{\strike ') }
sub strike_end { shift->out( \'}' ) }
+sub p_start
+{
+ my ($self, $node) = @_;
+
+ my $align = $node->attr('align');
+ if (defined($align) && lc($align) eq 'center') {
+ $self->{center}++;
+ }
+ #$self->adjust_lm(0); # assert new paragraph
+ $self->vspace(1);
+ # assert one line's worth of vertical space at para-start
+ $self->out('');
+ 1;
+}
+
+sub p_end
+{
+ my ($self, $node) = @_;
+ $self->vspace(1);
+ # assert one line's worth of vertical space at para-end
+ my $align = $node->attr('align');
+ if (defined($align) && lc($align) eq 'center') {
+ $self->{center}--;
+ }
+}
+
sub q_start {
my $self = $_[0];
$self->out(