From 47e262f74105809659372b02b0ba7fdc0d508778 Mon Sep 17 00:00:00 2001 From: Ben Bullock Date: Wed, 13 Jul 2011 15:11:41 +0900 Subject: [PATCH] Fixed reversed 0x7886 kanji --- SVG/7886.svg | 10 +++---- find-radical.pl | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 5 deletions(-) create mode 100755 find-radical.pl diff --git a/SVG/7886.svg b/SVG/7886.svg index a6266ee8d..90a86b72f 100644 --- a/SVG/7886.svg +++ b/SVG/7886.svg @@ -42,11 +42,6 @@ See http://creativecommons.org/licenses/by-sa/3.0/ for more details. --> 13 - - - - - @@ -55,5 +50,10 @@ See http://creativecommons.org/licenses/by-sa/3.0/ for more details. --> + + + + + diff --git a/find-radical.pl b/find-radical.pl new file mode 100755 index 000000000..734208252 --- /dev/null +++ b/find-radical.pl @@ -0,0 +1,76 @@ +#!/home/ben/software/install/bin/perl +use warnings; +use strict; +use FindBin; +use XML::Parser; +use Image::SVG::Path 'extract_path_info'; +use utf8; +my $string = qr/kanjivg:element="氵"/; +my @files = <$FindBin::Bin/kanjivg/*.svg>; +my @matches; +for my $file (@files) { + open my $in, "<:encoding(utf8)", $file + or die $!; + while (<$in>) { + if (/$string/) { + push @matches, $file; +# print "$file matches.\n"; + } + } + close $in or die $!; +} + +my $start; +my $count; + +my %global; + +my $parser = XML::Parser->new ( + Handlers => { + Start => \& handle_start + }, +); + +binmode STDOUT, "utf8"; + +for my $file (@matches) { +# print "Parsing '$file'.\n"; + $global{file} = $file; + $parser->parsefile ($file); +} + +sub handle_start +{ + my ($parser, $element, %attr) = @_; + if ($element eq 'g') { + my $kvg = $attr{'kanjivg:element'}; + if ($kvg) { + if ($kvg eq '氵') { + #print "Found '$kvg' in '$global{file}'\n"; + $start = 1; + $count = 0; + } + } + else { + $start = undef; + $count = 0; + } + } + if ($start && $element eq 'path') { + $count++; + if ($count == 3) { + my $d = $attr{d}; + my @values = extract_path_info ($d, { + no_shortcuts => 1, + absolute => 1, + }); + my @start = @{$values[0]->{point}}; + my @end = @{$values[-1]->{end}}; + my $x_diff = $end[0] - $start[0]; + my $y_diff = $end[1] - $start[1]; + if ($x_diff < 0 || $y_diff > 0) { + printf ("file $global{file}: %d %d\n", $x_diff, $y_diff); + } + } + } +}