
* scribo/convert/from_base64.hh: Remove guards HAVE_QT. * scribo/core/document.hh: Initialize ImageMagick. * scribo/io/xml/internal/html_markups_replace.hh: Remove. Move code... * scribo/core/line_info.hh: ... here. * scribo/core/line_links.hh: Make use of is_textline method. * scribo/core/paragraph_info.hh: Add nlines method. * scribo/core/paragraph_set.hh: Add a construction routine using a line_set. * scribo/io/xml/internal/extended_page_xml_visitor.hh, * scribo/io/xml/internal/print_box_coords.hh, * scribo/io/xml/internal/print_page_preambule.hh, * src/primitive/extract/separators_nonvisible.cc: Fix includes. * scribo/io/xml/save.hh: Add a precondition. * scribo/text/extract_lines.hh, * src/debug/show_info_median_inter_characters.cc, * src/debug/show_info_x_height.cc, * src/debug/show_text_lines.cc: Fix label type. --- scribo/ChangeLog | 30 ++++++ scribo/scribo/convert/from_base64.hh | 8 -- scribo/scribo/core/document.hh | 1 + scribo/scribo/core/line_info.hh | 45 ++++++++- scribo/scribo/core/line_links.hh | 5 +- scribo/scribo/core/paragraph_info.hh | 9 ++ scribo/scribo/core/paragraph_set.hh | 28 ++++++ .../io/xml/internal/extended_page_xml_visitor.hh | 2 - .../scribo/io/xml/internal/html_markups_replace.hh | 97 -------------------- scribo/scribo/io/xml/internal/print_box_coords.hh | 3 + .../scribo/io/xml/internal/print_page_preambule.hh | 5 + scribo/scribo/io/xml/save.hh | 2 + scribo/scribo/text/extract_lines.hh | 16 ++-- .../src/debug/show_info_median_inter_characters.cc | 12 +- scribo/src/debug/show_info_x_height.cc | 12 +- scribo/src/debug/show_text_lines.cc | 2 +- .../src/primitive/extract/separators_nonvisible.cc | 2 +- 17 files changed, 143 insertions(+), 136 deletions(-) delete mode 100644 scribo/scribo/io/xml/internal/html_markups_replace.hh diff --git a/scribo/ChangeLog b/scribo/ChangeLog index 4eae5f8..7c29163 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,3 +1,33 @@ +2011-03-03 Guillaume Lazzara <z@lrde.epita.fr> + + Small fixes in Scribo. + + * scribo/convert/from_base64.hh: Remove guards HAVE_QT. + + * scribo/core/document.hh: Initialize ImageMagick. + + * scribo/io/xml/internal/html_markups_replace.hh: Remove. Move code... + * scribo/core/line_info.hh: ... here. + + * scribo/core/line_links.hh: Make use of is_textline method. + + * scribo/core/paragraph_info.hh: Add nlines method. + + * scribo/core/paragraph_set.hh: Add a construction routine using a + line_set. + + * scribo/io/xml/internal/extended_page_xml_visitor.hh, + * scribo/io/xml/internal/print_box_coords.hh, + * scribo/io/xml/internal/print_page_preambule.hh, + * src/primitive/extract/separators_nonvisible.cc: Fix includes. + + * scribo/io/xml/save.hh: Add a precondition. + + * scribo/text/extract_lines.hh, + * src/debug/show_info_median_inter_characters.cc, + * src/debug/show_info_x_height.cc, + * src/debug/show_text_lines.cc: Fix label type. + 2011-03-02 Guillaume Lazzara <z@lrde.epita.fr> Regen mk files. diff --git a/scribo/scribo/convert/from_base64.hh b/scribo/scribo/convert/from_base64.hh index 8c14a0f..5eeeb53 100644 --- a/scribo/scribo/convert/from_base64.hh +++ b/scribo/scribo/convert/from_base64.hh @@ -82,13 +82,9 @@ namespace scribo Image<I>& output); -# if defined HAVE_QT - template <typename I> void from_base64(const QString& data64, Image<I>& output_); -# endif // ! HAVE_QT - # ifndef MLN_INCLUDE_ONLY @@ -191,8 +187,6 @@ namespace scribo } -# if defined HAVE_QT - template <typename I> void from_base64(const QString& data64, Image<I>& output_) @@ -205,8 +199,6 @@ namespace scribo trace::exiting("scribo::convert::to_base64"); } -# endif // ! HAVE_QT - # endif // ! MLN_INCLUDE_ONLY diff --git a/scribo/scribo/core/document.hh b/scribo/scribo/core/document.hh index 372f0a4..689d0e3 100644 --- a/scribo/scribo/core/document.hh +++ b/scribo/scribo/core/document.hh @@ -160,6 +160,7 @@ namespace scribo void document<L>::open() { + Magick::InitializeMagick(0); mln::io::magick::load(image_, filename_); } diff --git a/scribo/scribo/core/line_info.hh b/scribo/scribo/core/line_info.hh index 33a1529..46ba720 100644 --- a/scribo/scribo/core/line_info.hh +++ b/scribo/scribo/core/line_info.hh @@ -35,9 +35,10 @@ /// from the x_height and the baseline. /// /// \fixme The way the meanline and the baseline are computed is not -/// optimal and does not work is the components are too high (because +/// optimal and does not work if the components are too high (because /// of the median accumulator and int_u12 overflows). +# include <map> # include <mln/core/alias/box2d.hh> # include <mln/core/alias/point2d.hh> @@ -53,8 +54,6 @@ # include <scribo/core/line_set.hh> # include <scribo/core/component_set.hh> -# include <scribo/io/xml/internal/html_markups_replace.hh> - # include <scribo/core/concept/serializable.hh> @@ -287,6 +286,42 @@ namespace scribo namespace internal { + // INTERNAL TOOLS + + static inline std::map<char, std::string> init_map() + { + std::map<char, std::string> html_map; + html_map['\"'] = """; + html_map['<'] = "<"; + html_map['>'] = ">"; + html_map['&'] = "&"; + return html_map; + } + + + inline + std::string + html_markups_replace(const std::string& input) + { + static std::map<char, std::string> map = init_map(); + + std::string output = input; + for (unsigned i = 0; i < input.size(); ++i) + { + std::map<char, std::string>::iterator it = map.find(output.at(i)); + if (it != map.end()) + { + output.replace(i, 1, it->second); + i += it->second.size() - 1; + } + } + return output; + } + + + + // LINE INFO DATA + template <typename L> line_info_data<L>::line_info_data() { @@ -641,7 +676,7 @@ namespace scribo line_info<L>::update_text(const std::string& str) { data_->text_ = str; - data_->html_text_ = scribo::io::xml::internal::html_markups_replace(str); + data_->html_text_ = scribo::internal::html_markups_replace(str); } @@ -869,6 +904,8 @@ namespace scribo ref_line = mln::math::min(comp_set(c).bbox().pmin().row(), ref_line); } + // FIXME: compute font color! + for_all_elements(i, data_->components_) { unsigned c = data_->components_(i); diff --git a/scribo/scribo/core/line_links.hh b/scribo/scribo/core/line_links.hh index fdd09a5..ab36a73 100644 --- a/scribo/scribo/core/line_links.hh +++ b/scribo/scribo/core/line_links.hh @@ -215,9 +215,8 @@ namespace scribo line_links<L>::init() { for (unsigned i = 0; i < nelements(); ++i) - if (! data_->lines_(i).is_valid() - || data_->lines_(i).is_hidden() - || data_->lines_(i).type() != line::Text) + if (!data_->lines_(i).is_valid() + || !data_->lines_(i).is_textline()) { data_->line_to_link_(i) = 0; } diff --git a/scribo/scribo/core/paragraph_info.hh b/scribo/scribo/core/paragraph_info.hh index 17f847f..f4b1309 100644 --- a/scribo/scribo/core/paragraph_info.hh +++ b/scribo/scribo/core/paragraph_info.hh @@ -52,6 +52,8 @@ namespace scribo const mln::util::array<line_id_t>& line_ids() const; + unsigned nlines() const; + bool is_valid() const; private: @@ -106,6 +108,13 @@ namespace scribo } template <typename L> + unsigned + paragraph_info<L>::nlines() const + { + return line_ids_.nelements(); + } + + template <typename L> bool paragraph_info<L>::is_valid() const { diff --git a/scribo/scribo/core/paragraph_set.hh b/scribo/scribo/core/paragraph_set.hh index 5451069..f081472 100644 --- a/scribo/scribo/core/paragraph_set.hh +++ b/scribo/scribo/core/paragraph_set.hh @@ -215,6 +215,7 @@ namespace scribo } // end of namespace scribo::make::internal + // FIXME: move that code into paragraph_set constructor? template <typename L> scribo::paragraph_set<L> paragraph(const line_links<L>& llinks) @@ -241,6 +242,33 @@ namespace scribo return parset; } + + // FIXME: move that code into paragraph_set constructor? + template <typename L> + scribo::paragraph_set<L> + paragraph(const scribo::line_set<L>& lines) + { + line_links<L> links(lines); + links.init(); + + unsigned npars; + mln::fun::i2v::array<unsigned> + par_ids = mln::make::relabelfun(links.line_to_link(), + links.nelements() - 1, npars); + paragraph_set<L> parset(links, npars); + + for_all_links(l, links) + if (links(l)) + { + value::int_u16 par_id = par_ids(l); + parset(par_id).add_line(lines(l)); + } + + return parset; + } + + + } // end of namespace scribo::make diff --git a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh index 5d8a672..4da0755 100644 --- a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh +++ b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh @@ -40,8 +40,6 @@ # include <scribo/core/line_links.hh> # include <scribo/core/line_info.hh> -# include <scribo/convert/to_base64.hh> - # include <scribo/io/xml/internal/print_box_coords.hh> # include <scribo/io/xml/internal/print_page_preambule.hh> diff --git a/scribo/scribo/io/xml/internal/html_markups_replace.hh b/scribo/scribo/io/xml/internal/html_markups_replace.hh deleted file mode 100644 index 76f8107..0000000 --- a/scribo/scribo/io/xml/internal/html_markups_replace.hh +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see <http://www.gnu.org/licenses/>. -// -// As a special exception, you may use this file as part of a free -// software project without restriction. Specifically, if other files -// instantiate templates or use macros or inline functions from this -// file, or you compile this file and link it with other files to produce -// an executable, this file does not by itself cause the resulting -// executable to be covered by the GNU General Public License. This -// exception does not however invalidate any other reasons why the -// executable file might be covered by the GNU General Public License. - -#ifndef SCRIBO_IO_XML_INTERNAL_HTML_MARKUPS_REPLACE_HH -# define SCRIBO_IO_XML_INTERNAL_HTML_MARKUPS_REPLACE_HH - -/// \file -/// -/// \brief Replace HTML markups characters by their corresponding -/// markups. - - -namespace scribo -{ - - namespace io - { - - namespace xml - { - - namespace internal - { - - /*! \brief Replace HTML markups characters by their corresponding - markups. - */ - inline - std::string - html_markups_replace(std::string& input); - - -# ifndef MLN_INCLUDE_ONLY - - static inline std::map<char, std::string> init_map() - { - std::map<char, std::string> html_map; - html_map['\"'] = """; - html_map['<'] = "<"; - html_map['>'] = ">"; - html_map['&'] = "&"; - return html_map; - } - - - inline - std::string - html_markups_replace(const std::string& input) - { - static std::map<char, std::string> map = init_map(); - - std::string output = input; - for (unsigned i = 0; i < input.size(); ++i) - { - std::map<char, std::string>::iterator it = map.find(output.at(i)); - if (it != map.end()) - { - output.replace(i, 1, it->second); - i += it->second.size() - 1; - } - } - return output; - } - -# endif // ! MLN_INCLUDE_ONLY - - } // end of namespace scribo::io::xml::internal - - } // end of namespace scribo::io::xml - - } // end of namespace scribo::io - -} // end of namespace scribo - -#endif // ! SCRIBO_IO_XML_INTERNAL_HTML_MARKUPS_REPLACE_HH diff --git a/scribo/scribo/io/xml/internal/print_box_coords.hh b/scribo/scribo/io/xml/internal/print_box_coords.hh index d3aeedf..ad84709 100644 --- a/scribo/scribo/io/xml/internal/print_box_coords.hh +++ b/scribo/scribo/io/xml/internal/print_box_coords.hh @@ -30,6 +30,7 @@ /// /// \brief Prints box2d coordinates to XML data. +# include <fstream> # include <mln/core/alias/box2d.hh> namespace scribo @@ -44,6 +45,8 @@ namespace scribo namespace internal { + using namespace mln; + /*! \brief Prints box2d coordinates to XML data. */ void diff --git a/scribo/scribo/io/xml/internal/print_page_preambule.hh b/scribo/scribo/io/xml/internal/print_page_preambule.hh index b5ae891..3ee29be 100644 --- a/scribo/scribo/io/xml/internal/print_page_preambule.hh +++ b/scribo/scribo/io/xml/internal/print_page_preambule.hh @@ -30,7 +30,9 @@ /// /// \brief Print PAGE XML format preambule. +# include <fstream> # include <mln/core/alias/box2d.hh> +# include <scribo/core/document.hh> namespace scribo { @@ -44,6 +46,9 @@ namespace scribo namespace internal { + using namespace mln; + + /// \brief Print PAGE XML format preambule. template <typename L> void print_PAGE_preambule(std::ofstream& output, diff --git a/scribo/scribo/io/xml/save.hh b/scribo/scribo/io/xml/save.hh index 30579d0..7428e5d 100644 --- a/scribo/scribo/io/xml/save.hh +++ b/scribo/scribo/io/xml/save.hh @@ -121,6 +121,8 @@ namespace scribo { trace::entering("scribo::io::xml::save"); + mln_precondition(doc.is_open()); + // Open file std::ofstream output(output_name.c_str()); if (! output) diff --git a/scribo/scribo/text/extract_lines.hh b/scribo/scribo/text/extract_lines.hh index b81cb79..9949d09 100644 --- a/scribo/scribo/text/extract_lines.hh +++ b/scribo/scribo/text/extract_lines.hh @@ -33,8 +33,8 @@ # include <mln/core/concept/image.hh> -# include <mln/value/int_u16.hh> +# include <scribo/core/def/lbl_type.hh> # include <scribo/core/line_set.hh> # include <scribo/primitive/extract/components.hh> @@ -71,13 +71,13 @@ namespace scribo ** \return A set of lines. */ template <typename I, typename N> - line_set<mln_ch_value(I,value::int_u16)> + line_set<mln_ch_value(I,scribo::def::lbl_type)> extract_lines(const Image<I>& input_, const Neighborhood<N>& nbh_, const mln_ch_value(I,bool)& separators); /// \overload template <typename I, typename N> - line_set<mln_ch_value(I,value::int_u16)> + line_set<mln_ch_value(I,scribo::def::lbl_type)> extract_lines(const Image<I>& input, const Neighborhood<N>& nbh); @@ -85,7 +85,7 @@ namespace scribo template <typename I, typename N> - line_set<mln_ch_value(I,value::int_u16)> + line_set<mln_ch_value(I,scribo::def::lbl_type)> extract_lines(const Image<I>& input, const Neighborhood<N>& nbh) { mln_ch_value(I,bool) seps; @@ -94,7 +94,7 @@ namespace scribo template <typename I, typename N> - line_set<mln_ch_value(I,value::int_u16)> + line_set<mln_ch_value(I,scribo::def::lbl_type)> extract_lines(const Image<I>& input_, const Neighborhood<N>& nbh_, const mln_ch_value(I,bool)& separators) { @@ -107,10 +107,10 @@ namespace scribo mln_precondition(nbh.is_valid()); /// Finding comps. - typedef mln_ch_value(I,value::int_u16) L; - value::int_u16 ncomps; + typedef mln_ch_value(I,scribo::def::lbl_type) L; + scribo::def::lbl_type ncomps; component_set<L> - comps = scribo::primitive::extract::components(input, c8(), ncomps); + comps = scribo::primitive::extract::components(input, nbh, ncomps); /// First filtering. comps = scribo::filter::components_small(comps, 3); diff --git a/scribo/src/debug/show_info_median_inter_characters.cc b/scribo/src/debug/show_info_median_inter_characters.cc index b55079d..2ba240e 100644 --- a/scribo/src/debug/show_info_median_inter_characters.cc +++ b/scribo/src/debug/show_info_median_inter_characters.cc @@ -1,5 +1,5 @@ -// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory -// (LRDE) +// Copyright (C) 2009, 2010, 2011 EPITA Research and Development +// Laboratory (LRDE) // // This file is part of Olena. // @@ -35,7 +35,7 @@ #include <mln/io/ppm/save.hh> #include <mln/value/rgb8.hh> -#include <mln/value/label_16.hh> +#include <mln/value/int_u16.hh> #include <mln/draw/box.hh> #include <mln/draw/line.hh> @@ -71,14 +71,14 @@ int main(int argc, char* argv[]) image2d<bool> input; - io::pbm::load(input, argv[1]); + mln::io::pbm::load(input, argv[1]); - typedef image2d<value::label_16> L; + typedef image2d<scribo::def::lbl_type> L; line_set<L> line = scribo::text::extract_lines(input, c8()); image2d<value::rgb8> output = scribo::debug::char_space_image(input, line); - io::ppm::save(output, argv[2]); + mln::io::ppm::save(output, argv[2]); trace::exiting("main"); } diff --git a/scribo/src/debug/show_info_x_height.cc b/scribo/src/debug/show_info_x_height.cc index e5ff8d2..2997230 100644 --- a/scribo/src/debug/show_info_x_height.cc +++ b/scribo/src/debug/show_info_x_height.cc @@ -1,5 +1,5 @@ -// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory -// (LRDE) +// Copyright (C) 2009, 2010, 2011 EPITA Research and Development +// Laboratory (LRDE) // // This file is part of Olena. // @@ -35,8 +35,8 @@ #include <mln/io/ppm/save.hh> #include <mln/value/rgb8.hh> -#include <mln/value/label_16.hh> +#include <scribo/core/def/lbl_type.hh> #include <scribo/text/extract_lines.hh> #include <scribo/debug/line_info_image.hh> #include <scribo/debug/usage.hh> @@ -66,14 +66,14 @@ int main(int argc, char* argv[]) image2d<bool> input; - io::pbm::load(input, argv[1]); + mln::io::pbm::load(input, argv[1]); - typedef image2d<value::label_16> L; + typedef image2d<scribo::def::lbl_type> L; line_set<L> line = scribo::text::extract_lines(input, c8()); image2d<value::rgb8> output = scribo::debug::line_info_image(input, line); - io::ppm::save(output, argv[2]); + mln::io::ppm::save(output, argv[2]); trace::exiting("main"); } diff --git a/scribo/src/debug/show_text_lines.cc b/scribo/src/debug/show_text_lines.cc index a031072..368f375 100644 --- a/scribo/src/debug/show_text_lines.cc +++ b/scribo/src/debug/show_text_lines.cc @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) util::timer t; t.start(); - typedef image2d<value::int_u16> L; + typedef image2d<scribo::def::lbl_type> L; line_set<L> lines = text::extract_lines(input, c8(), input_seps); t.stop(); diff --git a/scribo/src/primitive/extract/separators_nonvisible.cc b/scribo/src/primitive/extract/separators_nonvisible.cc index 82d4787..d50cc73 100644 --- a/scribo/src/primitive/extract/separators_nonvisible.cc +++ b/scribo/src/primitive/extract/separators_nonvisible.cc @@ -27,7 +27,7 @@ #include <mln/io/pbm/all.hh> #include <mln/data/convert.hh> -#include <scribo/primitive/extract/separators_nonvisible2.hh> +#include <scribo/primitive/extract/separators_nonvisible.hh> #include <scribo/debug/usage.hh> const char *args_desc[][2] = -- 1.5.6.5