NAME
Data::Kanji::KanjiVG - parse KanjiVG kanji data.
SYNOPSIS
parse (xml => $xml, callback => \& callback);
Parse a piece of kanjivg data and call callback
as each piece is parsed.
parse (
file_name => $kanjivg_file,
callback => \& callback,
flatten => 1,
);
Parse the file of kanji vg data, and as each complete <kanji> element is parsed, flatten it out into an array reference, then call back the function "callback" as each piece of data is parsed,
parse (
xml => $xml,
callback => \& callback,
parse_svg => 1,
);
Parse $xml
, and as each complete <kanji> element is parsed, flatten it out, parse the SVG paths, converting all paths to absolute form without shortcuts, then send an array reference of the parsed SVG to callback
(please refer to the test file since this is not completely documented).
DESCRIPTION
This Perl library is for handling the data files generated by the "KanjiVG project". The KanjiVG project is a project to create vector graphic descriptions of Kanji (Japanese versions of Chinese characters). This Perl library is intended to parse the output XML files of the KanjiVG project.
FUNCTIONS
parse
parse (
file_name => $file_name,
callback => $callback,
callback_data => $callback_data,
);
parse (
xml => $xml_text,
callback => $callback,
callback_data => $callback_data,
);
Parse the file specified by file_name
or xml
. As a complete piece of kanji data is achieved, call $callback
in the following form:
&{$callback} ($callback_data, $kanji);
Possible arguments are
- file_name
-
Give the name of the file to parse.
- callback
-
Give a function to call back each time a complete piece of kanji information is parsed.
- callback_data
-
An optional piece of data to pass to the callback function.
- flatten
-
A boolean. If it is false (or if it is omitted), the kanji information is sent as a complete hash reference. If it is true, the kanji information is sent as an array reference containing the paths.
If the data is not flattened using flatten
, $kanji
is a hash reference containing the following fields:
- id
-
The identification number of the kanji.
- g
-
A group of strokes of the kanji. This contains the following sub-fields:
- paths
-
An array reference to strokes or groups of strokes. Each element contains its type and attributes.
Each path is a single stroke of the kanji. This hash reference contains the following sub-fields:
- id
-
The stroke's identification number.
- type
-
The type of the stroke, a field describing the general shape of the stroke.
- d
-
The SVG path information. This information is a string. To parse it, the module Image::SVG::Path may be useful.
SEE ALSO
The KanjiVG project's home page at http://kanjivg.tagaini.net/.
BUGS
The data supplied by the KanjiVG project is subject to drastic and random fluctuations in format, depending on the maintainer's whims, so this module may abruptly cease to function with the latest data due to no fault of the module author's.
AUTHOR
Ben Bullock, <bkb@cpan.org>
COPYRIGHT & LICENCE
This package and associated files are copyright (C) 2012 Ben Bullock.
You can use, copy, modify and redistribute this package and associated files under the Perl Artistic Licence or the GNU General Public Licence.