|
From: <sh...@us...> - 2007-09-04 12:11:10
|
Revision: 51
http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=51&view=rev
Author: shaplov
Date: 2007-09-04 05:11:02 -0700 (Tue, 04 Sep 2007)
Log Message:
-----------
Now remove communiware dependences...
Modified Paths:
--------------
trunk/fb2-perl-tools/RTF/Control.pm
trunk/fb2-perl-tools/RTF/HTML/ansi
trunk/fb2-perl-tools/rtf2html
Modified: trunk/fb2-perl-tools/RTF/Control.pm
===================================================================
--- trunk/fb2-perl-tools/RTF/Control.pm 2007-09-04 12:09:14 UTC (rev 50)
+++ trunk/fb2-perl-tools/RTF/Control.pm 2007-09-04 12:11:02 UTC (rev 51)
@@ -56,12 +56,10 @@
process_char_props
reset_char_props
- set_input_charset
- set_output_charset
- $InMapper
- $OutMapper
from_unicode
- );
+ );
+
+
###########################################################################
%do_on_event = (); # output routines
@@ -107,14 +105,14 @@
die "Bad params for accept options" unless ref($optdef) eq 'HASH';
my %opts = %$optdef;
- # \xF0\xD2\xCF\xD7\xC5\xD2\xD1\xC5\xCD \xD7\xD3\xC5 \xD0\xC5\xD2\xC5\xC4\xC1\xCE\xCE\xD9\xC5 \xCF\xD0\xC3\xC9\xC9
+ # Проверяем все переданные опции
while (my ($key, $value) = each %arg) {
next unless exists $opts{$key};
$self->{$key} = $value;
delete $opts{$key};
}
- # \xE9 \xCF\xD0\xD2\xC5\xC4\xC5\xCC\xC9\xCD \xD5\xCD\xCF\xCC\xDE\xC1\xCE\xC9\xD1
+ # И определим умолчания
while (my ($key, $value) = each %opts) {
next unless defined $value;
$self->{$key} = $value unless exists $self->{$key};
@@ -129,18 +127,16 @@
(
{
Output => \*STDOUT,
- InputCharset => 'cp1251', # \xEB\xC1\xCB\xCF\xCA \xD0\xD2\xC9\xCE\xD1\xD4\xD8 \xD7\xC8\xCF\xC4\xCE\xD9\xCD \xC5\xD3\xCC\xC9 \xCE\xC5\xD4 ansicpg
- StrictInputCharset => '', # \xE5\xD3\xCC\xC9 \xDA\xC1\xC4\xC1\xCE - \xD4\xCF \xD0\xCC\xC5\xD7\xC1\xD4\xD8 \xCE\xC1 InCharset
- OutputCharset => 'koi8-r', # \xF7 \xCB\xC1\xCB\xCF\xCD charset-\xC5 \xD7\xD9\xD7\xCF\xC4\xC9\xD4\xD8
+ InputCharset => 'cp1251', # Какой принять входным если нет ansicpg
+ StrictInputCharset => '', # Если задан - то плевать на InCharset
+ OutputCharset => 'utf-8', # В каком charset-е выводить
CatdocCharsets => '/usr/local/lib/catdoc',
},
@_
);
set_top_output_to($self->{Output});
set_catdoc_libs($self->{CatdocCharsets});
- require Communiware::Charset;
- Communiware::Charset::init_charset($self->{OutputCharset})
- unless ($Communiware::Charset::replace_string);
+
$self;
}
@@ -163,83 +159,37 @@
###########################################################################
-# \xF0\xCF\xC4\xC4\xC5\xD2\xD6\xCB\xC1 \xD0\xC5\xD2\xC5\xCB\xCF\xC4\xC9\xD2\xCF\xD7\xCF\xCB
+# Поддержка перекодировок
+use Encode;
use vars qw/
- $InMapper
$InCharset
- $OutMapper
$OutCharset
- @directMapper
$CatdocCharsets
/;
-# \xE7\xC4\xC5 \xCC\xC5\xD6\xC1\xD4 \xC6\xC1\xCA\xCC\xD9 \xDE\xC1\xD2\xD3\xC5\xD4\xCF\xD7
-($InMapper, $OutMapper, $InCharset, $OutCharset, $CatdocCharsets) =
- (undef, undef, '', '', '');
+# Где лежат файлы чарсетов
+($InCharset, $OutCharset, $CatdocCharsets) =
+ ('', '', '');
sub set_catdoc_libs {$CatdocCharsets = $_[0]}
-sub set_input_charset {
- my $charset= shift;
- return if ($InCharset eq $charset);
- my ($code,$unicode);
- my $chrsname = "$CatdocCharsets/$charset.txt";
- die "Cannot set input charset to $charset, no $chrsname" unless -f $chrsname;
- open CHARSET, $chrsname;
- $InMapper = {};
- while (<CHARSET>) {
- next unless /^\s*(0x[0-9A-Fa-f]{2})\s+((0x)?[0-9A-Fa-f]{4})/;
- $code = hex($1); $unicode = hex($2);
- $InMapper->{$unicode}=chr($code);
- $directMapper[$code] = $unicode;
- }
- close CHARSET;
- $InCharset = $charset;
-}
+sub from_unicode {
+ return $_[0];
+# Этого момента я не понял... Что бы мы не возвращали, все равно все работает правильно :-/
+# Разбираться пока леть... Работает же ;-)
+# Шаплов.
-sub set_output_charset {
- my $charset= shift;
- return if ($OutCharset eq $charset);
- my ($code,$unicode);
- my $chrsname = "$CatdocCharsets/$charset.txt";
- die "Cannot set output charset to $charset, no $chrsname" unless -f $chrsname;
- open CHARSET, $chrsname;
- $OutMapper = {};
- while (<CHARSET>) {
- next unless /^\s*(0x[0-9A-Fa-f]{2})\s+((0x)?[0-9A-Fa-f]{4})/;
- $code = chr(hex($1)); $unicode = hex($2);
- $OutMapper->{$unicode} =$code;
- }
- close CHARSET;
- $OutCharset = $charset;
+# return "b";
+# return ($InMapper->{$_[0]} || '"');
}
-sub make_direct_map {
- my $i;
- foreach $i (grep {defined} @directMapper) {
-
- $i = $OutMapper->{$i} || '"';
- }
-}
-sub from_unicode {
- return ($InMapper->{$_[0]} || '"');
-}
-
-sub recode_char {
- my $char= $directMapper[ord($_[0])];
- $char = $Communiware::Charset::escaping{$char}
- if exists $Communiware::Charset::escaping{$char};
- return $char;
-}
-
sub recode_string {
- local $_ = shift;
- s/([\200-\377])/$directMapper[ord($1)]/eg;
- s/([$Communiware::Charset::replace_string])/$Communiware::Charset::escaping{$1}/eg;
-
- return $_;
+ my $in_str = shift;
+ my $utf8_str = Encode::decode($InCharset,$in_str);
+ my $out_str = Encode::encode($OutCharset,$utf8_str,Encode::FB_XMLCREF);
+ return $out_str;
}
###########################################################################
# Utils
@@ -317,7 +267,7 @@
# the default prints on the selected output filehandle
sub flush_top_output {
- # \xF0\xC5\xDE\xC1\xD4\xC1\xD4\xD8 \xC9\xCC\xC9 \xCB\xC1\xCB \xC5\xD3\xD4\xD8, \xC9\xCC\xC9 \xD3 \xD0\xC5\xD2\xC5\xCB\xCF\xC4\xC9\xD2\xCF\xD7\xCB\xCF\xCA
+ # Печатать или как есть, или с перекодировкой
my $o = ($InCharset eq $OutCharset) ?
$output_stack[TOP] : recode_string( $output_stack[TOP]);
print $o;
@@ -1252,7 +1202,6 @@
}
use constant PARSE_START_END => 0;
-
sub parse_start {
my $self = shift;
@@ -1261,10 +1210,12 @@
%fonttbl = ();
%colortbl = ();
%stylesheet = ();
-
- set_input_charset($self->{StrictInputCharset} || $self->{InputCharset});
- set_output_charset($self->{OutputCharset});
- make_direct_map();
+ $InCharset = $self->{StrictInputCharset} || $self->{InputCharset};
+ $OutCharset = $self->{OutputCharset};
+
+# set_input_charset($self->{StrictInputCharset} || $self->{InputCharset});
+# set_output_charset($self->{OutputCharset});
+# make_direct_map();
push_output();
if (defined (my $action = $do_on_event{'document'})) {
$event = 'start';
@@ -1273,7 +1224,6 @@
flush_top_output();
push_output();
}
-
sub parse_end {
my $self = shift;
my $action = '';
Modified: trunk/fb2-perl-tools/RTF/HTML/ansi
===================================================================
--- trunk/fb2-perl-tools/RTF/HTML/ansi 2007-09-04 12:09:14 UTC (rev 50)
+++ trunk/fb2-perl-tools/RTF/HTML/ansi 2007-09-04 12:11:02 UTC (rev 51)
@@ -25,8 +25,8 @@
93 ``
94 ''
95 ·
-96 -
-97 --
+96 –
+97 —
98 ~
99 [tm]
9a s
Modified: trunk/fb2-perl-tools/rtf2html
===================================================================
--- trunk/fb2-perl-tools/rtf2html 2007-09-04 12:09:14 UTC (rev 50)
+++ trunk/fb2-perl-tools/rtf2html 2007-09-04 12:11:02 UTC (rev 51)
@@ -74,13 +74,8 @@
=cut
require 5.004;
-use lib qw(/cmw/perllib /cmw/perllib/i386-linux-thread-multi);
use strict;
-BEGIN {
- delete $ENV{MOD_PERL};
-};
-
use File::Basename;
use Getopt::Long;
@@ -134,16 +129,17 @@
$opt{tables} and $par{CatdocCharsets} = $opt{tables};
-if (defined $par{OutputCharset} && !-f "$par{CatdocCharsets}/$par{OutputCharset}.txt") {
- open F, "$par{CatdocCharsets}/charset.map" or die "$par{CatdocCharsets}/charset.map:$!";
- while (<F>) {
- next if /^\s*#/ || /^\s*$/;
- my ($mime_name,$table_name) = split;
- $par{OutputCharset}=$table_name if $mime_name eq $par{OutputCharset};
- }
-}
+#if (defined $par{OutputCharset} && !-f "$par{CatdocCharsets}/$par{OutputCharset}.txt") {
+# open F, "$par{CatdocCharsets}/charset.map" or die "$par{CatdocCharsets}/charset.map:$!";
+# while (<F>) {
+# next if /^\s*#/ || /^\s*$/;
+# my ($mime_name,$table_name) = split;
+# $par{OutputCharset}=$table_name if $mime_name eq $par{OutputCharset};
+# }
+# }
-die "Unknown output charset $par{OutputCharset}" if $par{OutputCharset} && ! -f "$par{CatdocCharsets}/$par{OutputCharset}.txt";
+# die "Unknown output charset $par{OutputCharset}" if $par{OutputCharset} && ! -f "$par{CatdocCharsets}/$par{OutputCharset}.txt";
+
unless (defined $ARGV[0]) {
# stdin -> stdout
$cnv = new RTF::HTML::Converter(%par);
@@ -163,8 +159,8 @@
}
-# \xF0\xD2\xC5\xCF\xC2\xD2\xC1\xDA\xCF\xD7\xC1\xCE\xC9\xC5 \xCB\xC1\xD2\xD4\xC9\xCE\xCF\xCB - \xD4\xCF\xCC\xD8\xCB\xCF \xC5\xD3\xCC\xC9 \xC9\xC8 \xCB\xCF\xCE\xD7\xC5\xD2\xD4\xC1\xC3\xC9\xD1 \xD0\xCF\xC4\xC4\xC5\xD2\xD6\xC9\xD7\xC1\xC5\xD4\xD3\xD1 \xD7 \xD4\xC5\xCB\xD5\xDD\xC5\xCA
-# \xCB\xCF\xCE\xC6\xC9\xC7\xD5\xD2\xC1\xC3\xC9\xC9
+# Преобразование картинок - только если их конвертация поддерживается в текущей
+# конфигурации
if ($par{ImageDir} ne 'NONE') {
my %job = $cnv->files2convert();
@@ -173,7 +169,7 @@
next unless $to =~ /\.png$/;
die "No source file $from" unless -f $from;
- # \xF5\xC4\xC1\xCC\xD1\xC5\xCD dst
+ # Удаляем dst
unlink $to;
die "Dst file $to cannot be deleted before converting" if -f $to;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|