Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
16 Nov '10
---
scribo/scribo/toolchain/text_in_picture.hh | 523 ++++++++++++++++++++++++++++
1 files changed, 523 insertions(+), 0 deletions(-)
create mode 100644 scribo/scribo/toolchain/text_in_picture.hh
diff --git a/scribo/scribo/toolchain/text_in_picture.hh b/scribo/scribo/toolchain/text_in_picture.hh
new file mode 100644
index 0000000..7d83577
--- /dev/null
+++ b/scribo/scribo/toolchain/text_in_picture.hh
@@ -0,0 +1,523 @@
+// Copyright (C) 2009, 2010 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_TOOLCHAIN_TEXT_IN_PICTURE_HH
+# define SCRIBO_TOOLCHAIN_TEXT_IN_PICTURE_HH
+
+
+/// \file
+///
+/// Localize text in a picture.
+
+
+
+
+#include <src/afp/components.hh>
+#include <src/afp/link.hh>
+#include <src/afp/regroup.hh>
+
+
+# include <mln/util/timer.hh>
+
+
+namespace scribo
+{
+
+ namespace toolchain
+ {
+
+ using namespace mln;
+
+
+ template <typename I>
+ component_set<mln_ch_value(I, value::label_16)>
+ text_in_picture(const Image<I>& input_rgb_orig,
+ bool bg_removal, bool multi_scale_bin,
+ bool negate = false,
+ unsigned max_dim_size = 0, unsigned lambda = 0,
+ const char *debug_outdir = 0);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+ template <typename I>
+ unsigned get_factor(const I& ima, unsigned max_dim_size)
+ {
+ unsigned
+ nrows = ima.nrows(),
+ ncols = ima.ncols(),
+ max_dim = std::max(nrows, ncols),
+ factor = max_dim / max_dim_size;
+
+ return factor ? factor : 1;
+ }
+
+
+ struct config
+ {
+ config()
+ {
+ max_dim_size = 1024;
+
+ sauvola_s = 2u; // 3?
+ sauvola_min_w = 51u;
+
+ // Group Filtering
+ bbox_h_ratio = 1.60f;
+ bbox_overlap = 0.80f;
+ small_groups = 3;
+ v_thickness = 8;
+ regroup_dmax = 30;
+ group_min_holes = 3;
+ }
+
+ // Image resizing factor
+ unsigned max_dim_size;
+
+ // Sauvola ms
+ unsigned sauvola_s;
+ unsigned sauvola_min_w;
+
+ // Group Filtering
+ float bbox_h_ratio;
+ float bbox_overlap;
+ unsigned small_groups;
+ unsigned v_thickness;
+ unsigned regroup_dmax;
+ unsigned group_min_holes;
+ };
+
+
+ } // end of namespace scribo::toolchain::internal
+
+
+ template <typename I>
+ component_set<mln_ch_value(I, value::label_16)>
+ text_in_picture(const Image<I>& input_rgb_orig_,
+ bool bg_removal, bool multi_scale_bin, bool negate = false,
+ unsigned max_dim_size = 0, unsigned lambda = 0,
+ const char *debug_outdir = 0)
+ {
+ trace::entering("scribo::toolchain::text_in_picture");
+
+ const I& input_rgb_orig = exact(input_rgb_orig_);
+ mln_precondition(input.is_valid());
+
+ using namespace scribo;
+ using namespace scribo::primitive;
+ using namespace mln;
+
+
+ // Global config variable.
+ internal::config conf;
+
+
+ bool debug = false;
+ if (debug_outdir)
+ {
+ scribo::make::internal::debug_filename_prefix = debug_outdir;
+ debug = true;
+ }
+
+ if (max_dim_size != 0)
+ conf.max_dim_size = max_dim_size;
+
+ unsigned factor = internal::get_factor(input_rgb_orig, conf.max_dim_size);
+
+ std::cout << "Reduction Factor : " << factor << std::endl;
+
+ std::cout << "Original domain: " << input_rgb_orig.domain() << std::endl;
+
+ mln_concrete(I)
+ input_rgb = mln::subsampling::antialiased(input_rgb_orig, factor);
+
+ std::cout << "Resized domain: " << input_rgb.domain() << std::endl;
+
+ if (lambda == 0)
+ lambda = 1.2 * (input_rgb.nrows() + input_rgb.ncols());
+
+ std::cout << "Using lambda = " << lambda << std::endl;
+
+ mln_ch_value(I,value::int_u8) intensity_ima;
+ mln::util::timer timer_, global_t_;
+ float t_;
+
+ global_t_.start();
+
+ if (bg_removal)
+ {
+ // Extract foreground
+ timer_.start();
+ std::cout << "** Using split_bg_fg" << std::endl;
+ mln_ch_value(I,value::rgb8)
+ fg = preprocessing::split_bg_fg(input_rgb, lambda, 32).second();
+ intensity_ima = data::transform(fg, mln::fun::v2v::rgb_to_int_u<8>());
+ t_ = timer_;
+ std::cout << "Foreground extracted. " << t_ << std::endl;
+
+ if (debug)
+ {
+ io::ppm::save(fg, scribo::make::debug_filename("foreground.ppm"));
+ }
+ }
+ else
+ {
+ timer_.start();
+ std::cout << "** Using data::transform(intensity)" << std::endl;
+ intensity_ima = data::transform(input_rgb,
+ mln::fun::v2v::rgb_to_int_u<8>());
+ t_ = timer_;
+ std::cout << "Intensity image " << t_ << std::endl;
+ }
+
+
+ // Binarize foreground to use it in the processing chain.
+ timer_.restart();
+ mln_ch_value(I,bool) input;
+ unsigned w = std::min(intensity_ima.nrows() / 3, intensity_ima.ncols() / 3);
+ if (! w % 2)
+ ++w;
+ w = std::min(w, conf.sauvola_min_w);
+ if (multi_scale_bin)
+ {
+ std::cout << "** Using sauvola_ms with w_1 = " << w << std::endl;
+ input = scribo::binarization::sauvola_ms(intensity_ima, w, conf.sauvola_s);
+ }
+ else
+ {
+ std::cout << "** Using sauvola with w_1 = " << w << std::endl;
+ input = scribo::binarization::sauvola(intensity_ima, w);
+ }
+
+ if (debug)
+ {
+ io::pbm::save(input,
+ scribo::make::debug_filename("binarization.pbm"));
+ }
+
+
+ // Yeah, looks strange, but we need to negate by default to
+ // process dark objects on light background.
+ if (!negate)
+ logical::not_inplace(input);
+
+ t_ = timer_;
+ std::cout << "Foreground binarized. " << t_ << std::endl;
+
+
+
+ typedef mln_ch_value(I,value::label_16) L;
+
+ /// Finding components.
+ timer_.restart();
+
+ typedef component_set<L> Obj;
+ Obj filtered_components;
+
+ {
+ mln::util::array<std::pair<box2d, std::pair<point2d, unsigned> > > attribs;
+
+ value::label_16 ncomponents;
+ L components = extract_components(input, ncomponents, attribs);
+
+ filtered_components = Obj(components, ncomponents, attribs);
+ }
+
+ t_ = timer_;
+ std::cout << "Object extracted " << t_ << " - " << filtered_components.nelements() << " components" << std::endl;
+
+// if (debug)
+// io::pgm::save(data::stretch(value::int_u8(), filtered_components), "ref_components.pgm");
+
+
+ /// linking potential components
+ timer_.restart();
+ mln::util::couple<object_links<L>, object_links<L> >
+ links = link::left_right(filtered_components);
+
+ object_links<L>& left_link = links.first();
+ object_links<L>& right_link = links.second();
+
+// object_links<L> left_link
+// = primitive::link::with_single_left_link(filtered_components, 30);
+// t_ = timer_;
+// std::cout << "Left Link done " << t_ << std::endl;
+
+// timer_.restart();
+// object_links<L> right_link
+// = primitive::link::with_single_right_link(filtered_components, 30);
+ t_ = timer_;
+ std::cout << "Link done " << t_ << std::endl;
+
+
+
+#ifndef NOUT
+ if (debug)
+ {
+ std::cerr << "BEFORE - ncomponents = " << filtered_components.nelements() << std::endl;
+ scribo::debug::save_linked_bboxes_image(input,
+ left_link, right_link,
+ literal::red, literal::cyan,
+ literal::yellow,
+ literal::green,
+ anchor::MassCenter,
+ scribo::make::debug_filename("links.ppm"));
+ }
+#endif
+
+
+
+ // Validating left and right links.
+ timer_.restart();
+ object_links<L>
+ merged_links = link::merge_double_link(left_link, right_link);
+ t_ = timer_;
+ std::cout << "Right/Left Validation. " << t_ << std::endl;
+
+
+ // Remove links if bboxes have too different sizes.
+ timer_.restart();
+ object_links<L>
+ hratio_filtered_links = filter::object_links_bbox_h_ratio(merged_links,
+ conf.bbox_h_ratio);
+
+
+
+
+#ifndef NOUT
+ if (debug)
+ {
+ mln_ch_value(I,value::rgb8)
+ hratio_decision_image = scribo::debug::decision_image(input,
+ merged_links,
+ hratio_filtered_links,
+ anchor::MassCenter);
+ io::ppm::save(hratio_decision_image,
+ scribo::make::debug_filename("hratio_links_decision_image.ppm"));
+ }
+#endif
+
+
+
+
+ //Remove links if bboxes overlap too much.
+ object_links<L> overlap_filtered_links
+ = filter::object_links_bbox_overlap(hratio_filtered_links,
+ conf.bbox_overlap);
+
+
+
+
+#ifndef NOUT
+ if (debug)
+ {
+ mln_ch_value(I,value::rgb8) overlap_decision_image
+ = scribo::debug::decision_image(input,
+ hratio_filtered_links,
+ overlap_filtered_links,
+ anchor::MassCenter);
+ io::ppm::save(overlap_decision_image,
+ scribo::make::debug_filename("overlap_links_decision_image.ppm"));
+ }
+#endif
+
+
+ t_ = timer_;
+ std::cout << "Components links filtered. " << t_ << std::endl;
+
+ timer_.restart();
+ object_groups<L>
+ groups = group::from_single_link(overlap_filtered_links);
+
+
+
+// Apply grouping in a temporary image (for debug purpose).
+#ifndef NOUT
+ component_set<L>
+ raw_group_image = group::apply(groups);
+#endif // !NOUT
+
+ t_ = timer_;
+ std::cout << "Components grouped. " << t_ << std::endl;
+
+#ifndef NOUT
+
+ if (debug)
+ {
+ mln_ch_value(I,value::rgb8)
+ decision_image = data::convert(value::rgb8(), input);
+
+ scribo::draw::bounding_boxes(decision_image,
+ filtered_components, literal::green);
+ scribo::draw::bounding_boxes(decision_image,
+ raw_group_image, literal::blue);
+
+ io::ppm::save(decision_image,
+ scribo::make::debug_filename("group_and_object_image.ppm"));
+
+ decision_image = data::convert(value::rgb8(), input);
+ scribo::draw::bounding_boxes(decision_image,
+ raw_group_image, literal::blue);
+ io::ppm::save(decision_image,
+ scribo::make::debug_filename("group_image.ppm"));
+ }
+#endif // !NOUT
+
+
+ std::cout << "Filtering groups..." << std::endl;
+
+ mln::util::timer g_timer;
+
+ timer_.restart();
+ // Remove components part of groups with strictly less than 3 components.
+
+ g_timer.start();
+ object_groups<L> filtered_small_groups;
+ std::cout << "** Using group too small" << std::endl;
+ filtered_small_groups = filter::object_groups_small(groups,
+ conf.small_groups);
+ t_ = g_timer;
+ std::cout << "Small groups removed " << t_ << std::endl;
+
+
+
+ component_set<L> debug_image;
+ mln_ch_value(I,value::rgb8) decision_image;
+ if (debug)
+ {
+ decision_image = data::convert(value::rgb8(), input);
+
+ scribo::draw::groups_bboxes(decision_image, groups, literal::red);
+ scribo::draw::groups_bboxes(decision_image, filtered_small_groups,
+ literal::green);
+
+
+ io::ppm::save(decision_image,
+ scribo::make::debug_filename("small_groups_filter.ppm"));
+ }
+
+
+
+ // Remove components part of groups having a mean thickness lower than 8.
+ g_timer.restart();
+ object_groups<L> filtered_thin_groups;
+ std::cout << "** Using group too thin" << std::endl;
+ filtered_thin_groups
+ = filter::object_groups_v_thickness(filtered_small_groups,
+ conf.v_thickness);
+ t_ = g_timer;
+ std::cout << "Groups too thin " << t_ << std::endl;
+
+
+ if (debug)
+ {
+ decision_image = data::convert(value::rgb8(), input);
+
+ scribo::draw::groups_bboxes(decision_image, filtered_small_groups,
+ literal::red);
+ scribo::draw::groups_bboxes(decision_image, filtered_thin_groups,
+ literal::green);
+
+ io::ppm::save(decision_image,
+ scribo::make::debug_filename("thin_groups_filter.ppm"));
+ }
+
+
+
+ /// Apply grouping in the object image.
+ g_timer.restart();
+
+
+ filtered_thin_groups = regroup::from_single_left_link(filtered_thin_groups,
+ conf.regroup_dmax);
+
+
+ t_ = g_timer;
+ std::cout << "Link and group again " << t_ << std::endl;
+
+ timer_.stop();
+
+ timer_.resume();
+
+ g_timer.restart();
+
+
+ /// Filter grouped objects not having enough background components.
+ std::cout << "** Using objects_with_two_holes" << std::endl;
+
+ groups = scribo::filter::object_groups_with_holes(filtered_thin_groups,
+ conf.group_min_holes);
+
+ t_ = g_timer;
+ std::cout << "Objects_with_holes " << t_ << std::endl;
+
+ t_ = timer_;
+ std::cout << "Objects groups filtered. " << t_ << std::endl;
+
+
+ t_ = global_t_;
+ std::cout << "*** Result computed " << t_ << std::endl;
+
+ if (debug)
+ {
+ decision_image = data::convert(value::rgb8(), input);
+
+ scribo::draw::groups_bboxes(decision_image, filtered_thin_groups,
+ literal::red);
+ scribo::draw::groups_bboxes(decision_image, groups, literal::green);
+
+ io::ppm::save(decision_image, scribo::make::debug_filename("group_with_holes_filter.ppm"));
+ }
+
+
+ timer_.restart();
+ std::cout << "Saving result..." << std::endl;
+
+ component_set<L> comps = primitive::group::apply(groups);
+
+ t_ = timer_;
+ std::cout << "Output saved " << t_ << std::endl;
+
+ std::cout << "# objects = " << comps.nelements() << std::endl;
+
+ trace::exiting("scribo::toolchain::text_in_picture");
+ return comps;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ } // end of namespace scribo::toolchain
+
+} // end of namespace scribo
+
+
+#endif // SCRIBO_TOOLCHAIN_TEXT_IN_PICTURE_HH
+
--
1.5.6.5
1
0
16 Nov '10
---
scribo/scribo/primitive/merge/components.hh | 121 +++++++++++++++++++++++++++
1 files changed, 121 insertions(+), 0 deletions(-)
create mode 100644 scribo/scribo/primitive/merge/components.hh
diff --git a/scribo/scribo/primitive/merge/components.hh b/scribo/scribo/primitive/merge/components.hh
new file mode 100644
index 0000000..7570d2e
--- /dev/null
+++ b/scribo/scribo/primitive/merge/components.hh
@@ -0,0 +1,121 @@
+// Copyright (C) 2010 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.
+
+/// \file
+///
+///
+
+#ifndef SCRIBO_PRIMITIVE_MERGE_COMPONENTS_HH
+# define SCRIBO_PRIMITIVE_MERGE_COMPONENTS_HH
+
+# include <mln/core/image/vmorph/fun_image.hh>
+
+
+namespace scribo
+{
+
+ namespace primitive
+ {
+
+ namespace merge
+ {
+
+ using namespace mln;
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+ template <typename V>
+ struct rebase_label : mln::Function_v2v<rebase_label<V> >
+ {
+ typedef V result;
+
+ rebase_label()
+ : base_label_(0)
+ {}
+
+ rebase_label(const V& base_label)
+ : base_label_(base_label)
+ {}
+
+ V operator()(const V& v) const
+ {
+ if (v)
+ return unsigned(base_label_) + unsigned(v);
+ return literal::zero;
+ }
+
+
+ V base_label_;
+ };
+
+
+ } // end of namespace scribo::primitive::merge
+
+
+ template <typename L>
+ component_set<L>
+ components(const component_set<L>& lhs, const component_set<L>& rhs)
+ {
+ trace::entering("scribo::primitive::merge::components");
+
+ const L& lhs_lbl = lhs.labeled_image();
+ const L& rhs_lbl = rhs.labeled_image();
+
+ typedef mln_value(L) V;
+
+
+ V nlabels = unsigned(lhs.nelements()) + unsigned(rhs.nelements());
+
+ // Merge labeled images.
+ //
+ // Rebase labeling in the second image, according to the
+ // number of labels in the first one.
+ //
+ L lbl_merge = duplicate(lhs_lbl);
+
+ internal::rebase_label<V> f(lhs.nelements());
+ fun_image<internal::rebase_label<V>, L> fima(f, rhs_lbl);
+ data::fill((lbl_merge | (pw::value(lbl_merge) == pw::cst(0))).rw(), fima);
+
+ component_set<L> output(lbl_merge, nlabels);
+
+ trace::exiting("scribo::primitive::merge::components");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::primitive::merge
+
+ } // end of namespace scribo::primitive
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_PRIMITIVE_MERGE_COMPONENTS_HH
--
1.5.6.5
1
0
16 Nov '10
---
scribo/src/Makefile.am | 10 ++
scribo/src/text_in_picture_neg.cc | 195 +++++++++++++++++++++++++++++++++++++
2 files changed, 205 insertions(+), 0 deletions(-)
create mode 100644 scribo/src/text_in_picture_neg.cc
diff --git a/scribo/src/Makefile.am b/scribo/src/Makefile.am
index cd7618c..9efa0da 100644
--- a/scribo/src/Makefile.am
+++ b/scribo/src/Makefile.am
@@ -70,6 +70,16 @@ if HAVE_MAGICKXX
-lpthread \
$(MAGICKXX_LDFLAGS)
+
+ utilexec_PROGRAMS += text_in_picture_neg
+ text_in_picture_neg_SOURCES = text_in_picture_neg.cc
+ text_in_picture_neg_CPPFLAGS = $(AM_CPPFLAGS) \
+ $(MAGICKXX_CPPFLAGS)
+ text_in_picture_neg_LDFLAGS = $(AM_LDFLAGS) \
+ -lpthread \
+ $(MAGICKXX_LDFLAGS)
+
+
if HAVE_TESSERACT
utilexec_PROGRAMS += text_recognition_in_picture
diff --git a/scribo/src/text_in_picture_neg.cc b/scribo/src/text_in_picture_neg.cc
new file mode 100644
index 0000000..e3078c6
--- /dev/null
+++ b/scribo/src/text_in_picture_neg.cc
@@ -0,0 +1,195 @@
+// Copyright (C) 2010 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.
+
+#include <libgen.h>
+#include <iostream>
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/imorph/tr_image.hh>
+#include <mln/core/alias/neighb2d.hh>
+
+#include <mln/labeling/colorize.hh>
+
+#include <mln/data/stretch.hh>
+
+#include <mln/io/pbm/all.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/io/magick/all.hh>
+
+#include <mln/math/min.hh>
+
+#include <mln/logical/not.hh>
+
+#include <mln/literal/colors.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/value/label_16.hh>
+
+#include <mln/fun/v2v/rgb_to_int_u.hh>
+
+#include <mln/data/wrap.hh>
+
+#include <mln/draw/box.hh>
+
+#include <mln/geom/translate.hh>
+
+#include <mln/subsampling/antialiased.hh>
+
+#include <scribo/draw/bounding_boxes.hh>
+#include <scribo/draw/groups_bboxes.hh>
+
+#include <scribo/binarization/sauvola_ms.hh>
+#include <scribo/binarization/sauvola.hh>
+
+#include <scribo/primitive/extract/components.hh>
+
+#include <scribo/primitive/link/merge_double_link.hh>
+#include <scribo/primitive/link/with_single_left_link.hh>
+#include <scribo/primitive/link/with_single_right_link.hh>
+
+#include <scribo/primitive/group/apply.hh>
+#include <scribo/primitive/group/from_double_link.hh>
+#include <scribo/primitive/group/from_single_link.hh>
+
+#include <scribo/primitive/regroup/from_single_left_link.hh>
+// #include <scribo/primitive/regroup/from_single_left_link_wrt_h_ratio.hh>
+
+#include <scribo/filter/object_groups_with_holes.hh>
+
+#include <scribo/filter/object_links_bbox_h_ratio.hh>
+#include <scribo/filter/object_links_bbox_overlap.hh>
+
+#include <scribo/filter/common/objects_photo.hh>
+
+#include <scribo/filter/object_groups_small.hh>
+#include <scribo/filter/object_groups_v_thickness.hh>
+
+#include <scribo/debug/highlight_text_area.hh>
+#include <scribo/debug/text_areas_image.hh>
+
+#include <scribo/debug/decision_image.hh>
+#include <scribo/debug/save_bboxes_image.hh>
+#include <scribo/debug/save_linked_bboxes_image.hh>
+
+#include <scribo/debug/usage.hh>
+
+#include <scribo/preprocessing/split_bg_fg.hh>
+
+#include <scribo/make/debug_filename.hh>
+
+#include <scribo/toolchain/text_in_picture.hh>
+
+#include <scribo/primitive/merge/components.hh>
+
+#include <mln/util/timer.hh>
+#include <mln/core/var.hh>
+
+const char *args_desc[][2] =
+{
+ { "input.*", "A color image." },
+ { "ouput.ppm", "A color image where the text is highlighted." },
+ { "debug_output_dir", "Directory were debug images will be saved" },
+ { "lambda", "Lambda value used for foreground extraction" },
+ {0, 0}
+};
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace scribo;
+ using namespace scribo::primitive;
+ using namespace mln;
+
+ if (argc < 3 || argc > 8)
+ return scribo::debug::usage(argv,
+ "Find text in a photo.\n\n"
+ "Common usage: ./text_in_photo_fast input.*"
+ " output.ppm 1 1",
+ "input.ppm output.ppm <bg/fg enabled>"
+ " <sauvola_ms enabled> "
+ "[debug_output_dir] [max_dim_size] [lambda]",
+ args_desc);
+
+ char *out_base_dir = 0;
+ if (argc > 5)
+ out_base_dir = argv[5];
+
+ trace::entering("main");
+
+ image2d<value::rgb8> input_rgb;
+ io::magick::load(input_rgb, argv[1]);
+
+ unsigned max_dim_size = 0;
+ if (argc >= 7)
+ max_dim_size = atoi(argv[6]);
+
+
+ unsigned lambda = 0;
+ if (argc == 8)
+ lambda = atoi(argv[7]);
+
+ bool bg_removal = false;
+ if (argc > 3 && atoi(argv[3]) != 0)
+ bg_removal = true;
+
+ bool multi_scale_bin = false;
+ if (argc > 4 && atoi(argv[4]) != 0)
+ multi_scale_bin = true;
+
+
+ typedef image2d<value::label_16> L;
+ component_set<L>
+ comps = toolchain::text_in_picture(input_rgb, bg_removal, multi_scale_bin,
+ false,
+ max_dim_size, lambda, out_base_dir);
+
+
+ typedef image2d<value::label_16> L;
+ component_set<L>
+ comps_neg = toolchain::text_in_picture(input_rgb, bg_removal, multi_scale_bin,
+ true,
+ max_dim_size, lambda, out_base_dir);
+
+
+ component_set<L> merged_comps = primitive::merge::components(comps, comps_neg);
+
+
+
+ io::ppm::save(mln::labeling::colorize(value::rgb8(),
+ merged_comps.labeled_image(),
+ merged_comps.nelements()),
+ argv[2]);
+
+ if (out_base_dir)
+ {
+ io::ppm::save(scribo::debug::highlight_text_area(input_rgb, merged_comps),
+ std::string(out_base_dir) + "_input_with_bboxes.ppm");
+ io::ppm::save(scribo::debug::text_areas_image(input_rgb, merged_comps),
+ std::string(out_base_dir) + "_out_text.ppm");
+ }
+
+ std::cout << "# objects = " << merged_comps.nelements() << std::endl;
+
+}
--
1.5.6.5
1
0
last-svn-commit-578-g6f0918c Add missing const references to function arguments.
by Guillaume Lazzara 16 Nov '10
by Guillaume Lazzara 16 Nov '10
16 Nov '10
* arthur/xml_transform/common.cc,
* arthur/xml_transform/common.hh,
* arthur/xml_transform/image_crop.cc,
* arthur/xml_transform/image_crop.hh,
* arthur/xml_transform/loader.cc,
* arthur/xml_transform/loader.hh,
* arthur/xml_transform/main.cc,
* arthur/xml_transform/xml_transform.cc,
* arthur/xml_transform/xml_transform.hh: Here.
---
scribo/sandbox/ChangeLog | 14 +++++++++++
scribo/sandbox/arthur/xml_transform/common.cc | 4 +-
scribo/sandbox/arthur/xml_transform/common.hh | 4 +-
scribo/sandbox/arthur/xml_transform/image_crop.cc | 25 ++++++++++++--------
scribo/sandbox/arthur/xml_transform/image_crop.hh | 10 ++++----
scribo/sandbox/arthur/xml_transform/loader.cc | 12 ++++----
scribo/sandbox/arthur/xml_transform/loader.hh | 23 +++++++++--------
scribo/sandbox/arthur/xml_transform/main.cc | 6 ++++-
.../sandbox/arthur/xml_transform/xml_transform.cc | 2 +-
.../sandbox/arthur/xml_transform/xml_transform.hh | 3 +-
10 files changed, 64 insertions(+), 39 deletions(-)
diff --git a/scribo/sandbox/ChangeLog b/scribo/sandbox/ChangeLog
index 052bd6d..485cc02 100644
--- a/scribo/sandbox/ChangeLog
+++ b/scribo/sandbox/ChangeLog
@@ -1,3 +1,17 @@
+2010-09-02 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Add missing const references to function arguments.
+
+ * arthur/xml_transform/common.cc,
+ * arthur/xml_transform/common.hh,
+ * arthur/xml_transform/image_crop.cc,
+ * arthur/xml_transform/image_crop.hh,
+ * arthur/xml_transform/loader.cc,
+ * arthur/xml_transform/loader.hh,
+ * arthur/xml_transform/main.cc,
+ * arthur/xml_transform/xml_transform.cc,
+ * arthur/xml_transform/xml_transform.hh: Here.
+
2010-08-06 Arthur Crepin-Leblond <crepin(a)lrde.epita.fr>
Open Document bug warning.
diff --git a/scribo/sandbox/arthur/xml_transform/common.cc b/scribo/sandbox/arthur/xml_transform/common.cc
index 05117b2..d1f3a6c 100644
--- a/scribo/sandbox/arthur/xml_transform/common.cc
+++ b/scribo/sandbox/arthur/xml_transform/common.cc
@@ -1,13 +1,13 @@
# include "common.hh"
-QString Common::get_file_name(QString image)
+QString Common::get_file_name(const QString& image)
{
QString tmp = image.mid(image.lastIndexOf("/") + 1);
tmp.chop(tmp.size() - tmp.lastIndexOf("."));
return tmp;
}
-QString Common::get_file_ext(QString image)
+QString Common::get_file_ext(const QString& image)
{
return image.right(image.size() - image.lastIndexOf("."));
}
diff --git a/scribo/sandbox/arthur/xml_transform/common.hh b/scribo/sandbox/arthur/xml_transform/common.hh
index f72218f..21b984a 100644
--- a/scribo/sandbox/arthur/xml_transform/common.hh
+++ b/scribo/sandbox/arthur/xml_transform/common.hh
@@ -9,8 +9,8 @@ class Common : public QObject
public:
Common() {}
~Common() {}
- static QString get_file_name(QString image);
- static QString get_file_ext(QString image);
+ static QString get_file_name(const QString& image);
+ static QString get_file_ext(const QString& image);
};
#endif // ! COMMON_HH
diff --git a/scribo/sandbox/arthur/xml_transform/image_crop.cc b/scribo/sandbox/arthur/xml_transform/image_crop.cc
index ffe2b44..f691b57 100644
--- a/scribo/sandbox/arthur/xml_transform/image_crop.cc
+++ b/scribo/sandbox/arthur/xml_transform/image_crop.cc
@@ -36,10 +36,11 @@
#include <mln/io/magick/save.hh>
#include <mln/io/ppm/all.hh>
-ImageCrop::ImageCrop(QString xml, QString img, QString output) :
- xml_(xml),
- image_(img),
- output_dir_(output)
+ImageCrop::ImageCrop(const QString& xml, const QString& img,
+ const QString& output)
+ : xml_(xml),
+ image_(img),
+ output_dir_(output)
{
}
@@ -47,8 +48,9 @@ ImageCrop::~ImageCrop()
{
}
-/* Save PPM image to PNG format in output_dir/img. */
-void ImageCrop::save_image(QString file)
+
+/* Save image to PNG format in output_dir/img. */
+void ImageCrop::save_image(const QString& out)
{
using namespace mln;
@@ -82,8 +84,10 @@ QString ImageCrop::img_to_base64()
return file_content.toBase64();
}
-/* Decode the base 64 string str and save into output_dir_/img/img_name. */
-bool ImageCrop::img_from_base64(QString str, QString img_name, QString mime)
+
+/* Decode the base 64 string str and save into
+ * output_dir_/img/img_name. */
+bool ImageCrop::img_from_base64(const QString& str, const QString& img)
{
QByteArray ba;
@@ -94,7 +98,8 @@ bool ImageCrop::img_from_base64(QString str, QString img_name, QString mime)
return ima.save(output_dir_ + "img/" + img_name + "." + mime);
}
-/* Read all regions of the XML file and save all base 64 data into output_dir/img */
+/* Read all regions of the XML file and save all base 64 data into
+ * output_dir/img */
void ImageCrop::from_base64()
{
QFile f_in(xml_);
@@ -134,7 +139,7 @@ void ImageCrop::from_base64()
/* Tranfsorm the input XML file associated with images into a single
XML output containing datas if images in base 64. */
-void ImageCrop::to_base64(QString out_file, bool no_crop)
+void ImageCrop::to_base64(const QString& out_file, bool no_crop)
{
QFile file(xml_);
file.open(QIODevice::ReadOnly);
diff --git a/scribo/sandbox/arthur/xml_transform/image_crop.hh b/scribo/sandbox/arthur/xml_transform/image_crop.hh
index 9b034cc..1644373 100644
--- a/scribo/sandbox/arthur/xml_transform/image_crop.hh
+++ b/scribo/sandbox/arthur/xml_transform/image_crop.hh
@@ -36,15 +36,15 @@ class ImageCrop : public QObject
Q_OBJECT
public:
- ImageCrop(QString xml, QString img, QString output);
+ ImageCrop(const QString&, const QString&, const QString&);
~ImageCrop();
- void save_image(QString file = QString::Null());
- bool crop_regions();
+ void save_image(const QString&);
+ bool crop_regions(bool temp = false);
QString img_to_base64();
- bool img_from_base64(QString str, QString img_name, QString mime);
- void to_base64(QString out_file, bool no_crop);
+ bool img_from_base64(const QString&, const QString&);
+ void to_base64(const QString&, bool);
void from_base64();
diff --git a/scribo/sandbox/arthur/xml_transform/loader.cc b/scribo/sandbox/arthur/xml_transform/loader.cc
index d4778a9..f9316f2 100644
--- a/scribo/sandbox/arthur/xml_transform/loader.cc
+++ b/scribo/sandbox/arthur/xml_transform/loader.cc
@@ -33,7 +33,7 @@ Loader::~Loader()
{
}
-QDomDocument* Loader::xml_to_dom(QString xml_file)
+QDomDocument* Loader::xml_to_dom(const QString& xml_file)
{
QFile file(xml_file);
@@ -68,7 +68,7 @@ bool Loader::set_output(QString& output)
}
-void Loader::add_html_templates(bool base64, QString output)
+void Loader::add_html_templates(bool base64, const QString& output)
{
QFile gen("templates/html/html_generator.sh");
gen.copy(output + "html_generator.sh");
@@ -88,7 +88,7 @@ void Loader::add_html_templates(bool base64, QString output)
}
}
-void Loader::add_pdf_templates(bool crop, bool base64, QString output)
+void Loader::add_pdf_templates(bool crop, bool base64, const QString& output)
{
if (base64)
{
@@ -126,7 +126,7 @@ void Loader::add_pdf_templates(bool crop, bool base64, QString output)
}
}
-void Loader::add_svg_templates(QString output)
+void Loader::add_svg_templates(const QString& output)
{
QFile regions("templates/pdf/regions_svg.xsl");
regions.copy(output + "regions.xsl");
@@ -141,7 +141,7 @@ void Loader::add_svg_templates(QString output)
xsl.copy(output + "main.xsl");
}
-void Loader::add_open_templates(QString output)
+void Loader::add_open_templates(const QString& output)
{
QFile css("templates/opendoc/css.css");
css.copy(output + "css.css");
@@ -153,7 +153,7 @@ void Loader::add_open_templates(QString output)
xsl.copy(output + "xsl.xsl");
}
-bool Loader::xml_output(QString xml_file, bool html, QString output)
+bool Loader::xml_output(const QString& xml_file, bool html, const QString& output)
{
QFile file(xml_file);
diff --git a/scribo/sandbox/arthur/xml_transform/loader.hh b/scribo/sandbox/arthur/xml_transform/loader.hh
index a5c3637..a66af2d 100644
--- a/scribo/sandbox/arthur/xml_transform/loader.hh
+++ b/scribo/sandbox/arthur/xml_transform/loader.hh
@@ -23,11 +23,11 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef LOADER_HH
-# define LOADER_HH
+#ifndef LOADER_HH
+# define LOADER_HH
# include <QtCore>
-#include <QDomDocument>
+# include <QDomDocument>
class Loader : public QObject
{
@@ -37,14 +37,15 @@ class Loader : public QObject
Loader();
~Loader();
- // void merge(QString in, QString other, QString output = "output.xml");
- bool xml_output(QString xml_file, bool html, QString output);
- QDomDocument* xml_to_dom(QString xml_file);
+ // void merge(const QString& in, const QString& other, const
+ // QString& output = "output.xml");
+ bool xml_output(const QString& xml_file, bool html, const QString& output);
+ QDomDocument* xml_to_dom(const QString& xml_file);
bool set_output(QString& output);
- void add_pdf_templates(bool crop, bool base64, QString output);
- void add_svg_templates(QString output);
- void add_open_templates(QString output);
- void add_html_templates(bool base64, QString output);
+ void add_pdf_templates(bool crop, bool base64, const QString& output);
+ void add_svg_templates(const QString& output);
+ void add_open_templates(const QString& output);
+ void add_html_templates(bool base64, const QString& output);
};
-#endif /* !LOADER_HH */
+#endif /* !LOADER_HH */
diff --git a/scribo/sandbox/arthur/xml_transform/main.cc b/scribo/sandbox/arthur/xml_transform/main.cc
index 8489376..2280b7d 100644
--- a/scribo/sandbox/arthur/xml_transform/main.cc
+++ b/scribo/sandbox/arthur/xml_transform/main.cc
@@ -1,9 +1,13 @@
#include <iostream>
-#include <QDomDocument>
+#include <string>
+#include <string>
+#include <cstdlib>
+#include <Magick++.h>
#include "xml_transform.hh"
int main(int argc, char **argv)
{
+ Magick::InitializeMagick(argv[0]);
std::string man;
man = "xml_transform\n"
diff --git a/scribo/sandbox/arthur/xml_transform/xml_transform.cc b/scribo/sandbox/arthur/xml_transform/xml_transform.cc
index 90af5a5..7149bdf 100644
--- a/scribo/sandbox/arthur/xml_transform/xml_transform.cc
+++ b/scribo/sandbox/arthur/xml_transform/xml_transform.cc
@@ -29,7 +29,7 @@
# include "common.hh"
# include <iostream>
-XmlTransform::XmlTransform(QString xml_file, QString image_file, QString output, QString file) :
+XmlTransform::XmlTransform(const QString& xml_file, const QString& image_file, const QString& output, const QString& file) :
xml_file_(xml_file),
image_(image_file),
loader_(new Loader()),
diff --git a/scribo/sandbox/arthur/xml_transform/xml_transform.hh b/scribo/sandbox/arthur/xml_transform/xml_transform.hh
index ad83fd5..c5dfc49 100644
--- a/scribo/sandbox/arthur/xml_transform/xml_transform.hh
+++ b/scribo/sandbox/arthur/xml_transform/xml_transform.hh
@@ -37,7 +37,8 @@ class XmlTransform : public QObject
Q_OBJECT
public:
- XmlTransform(QString xml_file, QString image_file, QString output, QString file = QString::Null());
+ XmlTransform(const QString& xml_file, const QString& image_file,
+ const QString& output, const QString& file = QString::Null());
~XmlTransform();
void createHTML(bool base64);
--
1.5.6.5
1
0
last-svn-commit-579-g398af6c arthur/xml_transform/xml_transform.pro: Define NDEBUG at compile time.
by Guillaume Lazzara 16 Nov '10
by Guillaume Lazzara 16 Nov '10
16 Nov '10
---
scribo/sandbox/ChangeLog | 5 +++++
.../sandbox/arthur/xml_transform/xml_transform.pro | 1 +
2 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/scribo/sandbox/ChangeLog b/scribo/sandbox/ChangeLog
index 485cc02..67e3479 100644
--- a/scribo/sandbox/ChangeLog
+++ b/scribo/sandbox/ChangeLog
@@ -1,5 +1,10 @@
2010-09-02 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * arthur/xml_transform/xml_transform.pro: Define NDEBUG at compile
+ time.
+
+2010-09-02 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add missing const references to function arguments.
* arthur/xml_transform/common.cc,
diff --git a/scribo/sandbox/arthur/xml_transform/xml_transform.pro b/scribo/sandbox/arthur/xml_transform/xml_transform.pro
index c038cf6..a15f31f 100644
--- a/scribo/sandbox/arthur/xml_transform/xml_transform.pro
+++ b/scribo/sandbox/arthur/xml_transform/xml_transform.pro
@@ -7,6 +7,7 @@ TARGET =
DEPENDPATH += .
INCLUDEPATH += .
QMAKE_CXXFLAGS += -I/amd/beyrouth/home/lrde/stage/crepin/git/olena/milena -I/amd/beyrouth/home/lrde/stage/crepin/git/olena/
+DEFINES += NDEBUG
QT += xml
LIBS += `Magick++-config --libs`
--
1.5.6.5
1
0
* sandbox/arthur/xml_to_html/xml_to_html.hh,
* sandbox/arthur/xml_to_html/xml_to_html.cc,
* sandbox/arthur/xml_to_html/xml_to_html.pro: Remove.
* sandbox/arthur/xml_to_html/README,
* sandbox/arthur/xml_to_html/main.cc,
* sandbox/arthur/xml_to_html/domitem.cc,
* sandbox/arthur/xml_to_html/domitem.hh,
* sandbox/arthur/xml_to_html/dommodel.cc,
* sandbox/arthur/xml_to_html/dommodel.hh: Move to...
* sandbox/arthur/xml_transform/README,
* sandbox/arthur/xml_transform/main.cc,
* sandbox/arthur/xml_transform/domitem.cc,
* sandbox/arthur/xml_transform/domitem.hh,
* sandbox/arthur/xml_transform/dommodel.cc,
* sandbox/arthur/xml_transform/dommodel.hh: ...this.
* sandbox/arthur/xml_to_html/patterns/css.css,
* sandbox/arthur/xml_to_html/patterns/xsl.xsl: Move to...
* sandbox/arthur/xml_transform/templates/html/css.css,
* sandbox/arthur/xml_transform/templates/html/xsl.xsl: ...this.
* sandbox/arthur/xml_transform/image_crop.cc,
* sandbox/arthur/xml_transform/loader.cc: New.
* sandbox/arthur/xml_transform/templates/html/html_generator.sh,
* sandbox/arthur/xml_transform/templates/pdf/line.xsl,
* sandbox/arthur/xml_transform/templates/pdf/main.xsl,
* sandbox/arthur/xml_transform/templates/pdf/main_crop.xsl,
* sandbox/arthur/xml_transform/templates/pdf/pdf_generator.sh,
* sandbox/arthur/xml_transform/templates/pdf/regions.xsl,
* sandbox/arthur/xml_transform/xml_transform.pro: New.
---
scribo/ChangeLog | 39 +++
scribo/sandbox/arthur/xml_to_html/README | 25 --
scribo/sandbox/arthur/xml_to_html/main.cc | 58 ----
scribo/sandbox/arthur/xml_to_html/patterns/css.css | 28 --
scribo/sandbox/arthur/xml_to_html/patterns/xsl.xsl | 229 ---------------
scribo/sandbox/arthur/xml_to_html/xml_to_html.cc | 292 --------------------
scribo/sandbox/arthur/xml_to_html/xml_to_html.hh | 49 ----
scribo/sandbox/arthur/xml_to_html/xml_to_html.pro | 16 -
scribo/sandbox/arthur/xml_transform/README | 19 ++
.../{xml_to_html => xml_transform}/domitem.cc | 0
.../{xml_to_html => xml_transform}/domitem.hh | 0
.../{xml_to_html => xml_transform}/dommodel.cc | 0
.../{xml_to_html => xml_transform}/dommodel.hh | 0
scribo/sandbox/arthur/xml_transform/image_crop.cc | 184 ++++++++++++
scribo/sandbox/arthur/xml_transform/image_crop.hh | 46 +++
scribo/sandbox/arthur/xml_transform/loader.cc | 162 +++++++++++
scribo/sandbox/arthur/xml_transform/loader.hh | 49 ++++
scribo/sandbox/arthur/xml_transform/main.cc | 30 ++
.../arthur/xml_transform/templates/html/css.css | 31 ++
.../xml_transform/templates/html/html_generator.sh | 3 +
.../arthur/xml_transform/templates/html/xsl.xsl | 224 +++++++++++++++
.../arthur/xml_transform/templates/pdf/line.xsl | 129 +++++++++
.../arthur/xml_transform/templates/pdf/main.xsl | 62 ++++
.../xml_transform/templates/pdf/main_crop.xsl | 42 +++
.../xml_transform/templates/pdf/pdf_generator.sh | 3 +
.../arthur/xml_transform/templates/pdf/regions.xsl | 59 ++++
.../sandbox/arthur/xml_transform/xml_transform.cc | 93 +++++++
.../sandbox/arthur/xml_transform/xml_transform.hh | 48 ++++
.../sandbox/arthur/xml_transform/xml_transform.pro | 20 ++
29 files changed, 1243 insertions(+), 697 deletions(-)
delete mode 100644 scribo/sandbox/arthur/xml_to_html/README
delete mode 100644 scribo/sandbox/arthur/xml_to_html/main.cc
delete mode 100644 scribo/sandbox/arthur/xml_to_html/patterns/css.css
delete mode 100644 scribo/sandbox/arthur/xml_to_html/patterns/xsl.xsl
delete mode 100644 scribo/sandbox/arthur/xml_to_html/xml_to_html.cc
delete mode 100644 scribo/sandbox/arthur/xml_to_html/xml_to_html.hh
delete mode 100644 scribo/sandbox/arthur/xml_to_html/xml_to_html.pro
create mode 100644 scribo/sandbox/arthur/xml_transform/README
rename scribo/sandbox/arthur/{xml_to_html => xml_transform}/domitem.cc (100%)
rename scribo/sandbox/arthur/{xml_to_html => xml_transform}/domitem.hh (100%)
rename scribo/sandbox/arthur/{xml_to_html => xml_transform}/dommodel.cc (100%)
rename scribo/sandbox/arthur/{xml_to_html => xml_transform}/dommodel.hh (100%)
create mode 100644 scribo/sandbox/arthur/xml_transform/image_crop.cc
create mode 100644 scribo/sandbox/arthur/xml_transform/image_crop.hh
create mode 100644 scribo/sandbox/arthur/xml_transform/loader.cc
create mode 100644 scribo/sandbox/arthur/xml_transform/loader.hh
create mode 100644 scribo/sandbox/arthur/xml_transform/main.cc
create mode 100644 scribo/sandbox/arthur/xml_transform/templates/html/css.css
create mode 100644 scribo/sandbox/arthur/xml_transform/templates/html/html_generator.sh
create mode 100644 scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
create mode 100644 scribo/sandbox/arthur/xml_transform/templates/pdf/line.xsl
create mode 100644 scribo/sandbox/arthur/xml_transform/templates/pdf/main.xsl
create mode 100644 scribo/sandbox/arthur/xml_transform/templates/pdf/main_crop.xsl
create mode 100644 scribo/sandbox/arthur/xml_transform/templates/pdf/pdf_generator.sh
create mode 100644 scribo/sandbox/arthur/xml_transform/templates/pdf/regions.xsl
create mode 100644 scribo/sandbox/arthur/xml_transform/xml_transform.cc
create mode 100644 scribo/sandbox/arthur/xml_transform/xml_transform.hh
create mode 100644 scribo/sandbox/arthur/xml_transform/xml_transform.pro
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index d7be39d..e58af8d 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,42 @@
+2010-07-08 Arthur Crepin-Leblond <crepin(a)ptaouchnok.lrde.epita.fr>
+
+ XML transform program.
+
+ * sandbox/arthur/xml_to_html/xml_to_html.hh,
+ * sandbox/arthur/xml_to_html/xml_to_html.cc,
+ * sandbox/arthur/xml_to_html/xml_to_html.pro: Remove.
+
+ * sandbox/arthur/xml_to_html/README,
+ * sandbox/arthur/xml_to_html/main.cc,
+ * sandbox/arthur/xml_to_html/domitem.cc,
+ * sandbox/arthur/xml_to_html/domitem.hh,
+ * sandbox/arthur/xml_to_html/dommodel.cc,
+ * sandbox/arthur/xml_to_html/dommodel.hh: Move to...
+
+ * sandbox/arthur/xml_transform/README,
+ * sandbox/arthur/xml_transform/main.cc,
+ * sandbox/arthur/xml_transform/domitem.cc,
+ * sandbox/arthur/xml_transform/domitem.hh,
+ * sandbox/arthur/xml_transform/dommodel.cc,
+ * sandbox/arthur/xml_transform/dommodel.hh: ...this.
+
+ * sandbox/arthur/xml_to_html/patterns/css.css,
+ * sandbox/arthur/xml_to_html/patterns/xsl.xsl: Move to...
+
+ * sandbox/arthur/xml_transform/templates/html/css.css,
+ * sandbox/arthur/xml_transform/templates/html/xsl.xsl: ...this.
+
+ * sandbox/arthur/xml_transform/image_crop.cc,
+ * sandbox/arthur/xml_transform/loader.cc: New.
+
+ * sandbox/arthur/xml_transform/templates/html/html_generator.sh,
+ * sandbox/arthur/xml_transform/templates/pdf/line.xsl,
+ * sandbox/arthur/xml_transform/templates/pdf/main.xsl,
+ * sandbox/arthur/xml_transform/templates/pdf/main_crop.xsl,
+ * sandbox/arthur/xml_transform/templates/pdf/pdf_generator.sh,
+ * sandbox/arthur/xml_transform/templates/pdf/regions.xsl,
+ * sandbox/arthur/xml_transform/xml_transform.pro: New.
+
2010-06-30 Arthur Crepin-Leblond <crepin(a)stockholm.lrde.epita.fr>
Extended XML mode support.
diff --git a/scribo/sandbox/arthur/xml_to_html/README b/scribo/sandbox/arthur/xml_to_html/README
deleted file mode 100644
index f16f472..0000000
--- a/scribo/sandbox/arthur/xml_to_html/README
+++ /dev/null
@@ -1,25 +0,0 @@
-xml_to_html
-
-Produce HTML view from ICDAR (or LRDE extended) XML.
-
-*Compilation:
-
- Just change the paths to olena and milena in xml_to_html.pro
-
-*Usage:
-
- -m, --merge: Merge an XML with an other XML
- args: <xml_file_1> <xml_file_2> [xml_output]
-
-Useful to merge LRDE XML extended mode files with ICDAR XML files to combine both images and recognized text.
-
-
- -c, --create-html: Crop images (if exist) from the ppm file using the XML file and produce an html output.
- args: <xml_file> [ppm_file] [output dir]
-
-If no PPM file is given, the program will only produce an HTML output without images.
-If a PPM file is given, the program will crop image_region, separator_region, graphic_regions, chart_region and table_region to output_dir/img/id.png
-
-*Result:
-
-To view the result run your internet browser on output_dir/output.xml (Does not work with Chrome on local, use a LAMPP server to fix this ;-) ).
\ No newline at end of file
diff --git a/scribo/sandbox/arthur/xml_to_html/main.cc b/scribo/sandbox/arthur/xml_to_html/main.cc
deleted file mode 100644
index 9ec705a..0000000
--- a/scribo/sandbox/arthur/xml_to_html/main.cc
+++ /dev/null
@@ -1,58 +0,0 @@
-#include <iostream>
-#include "xml_to_html.hh"
-
-int main(int argc, char **argv)
-{
-
- std::string man;
- man = "xml_to_html: ...usage\n -m, --merge: Merge an XML with an other XML\n \targs: <xml_file_1> <xml_file_2> [xml_output]\n\n -c, --create-html: Crop images (if exist) from the ppm file using the XML file and produce an html output.\n \targs: <xml_file> [ppm_file] [output dir]\n";
-
- if (argc > 2)
- {
- new QApplication::QApplication(argc, argv, false);
- ImageCrop crop;
-
- std::string merge = "--merge";
- std::string m = "-m";
- std::string scrop = "--create-html";
- std::string c = "-c";
-
- if (argc == 3 && (scrop.compare(argv[1]) == 0 || c.compare(argv[1]) == 0))
- {
- bool b = false;
- b = crop.load_xml(argv[2], QString::Null());
-
- if (b)
- crop.find_image_regions();
- }
- else if (argc > 3)
- {
- if (merge.compare(argv[1]) == 0 || m.compare(argv[1]) == 0)
- {
- if (argc > 4)
- crop.merge(argv[2], argv[3], argv[4]);
- else
- crop.merge(argv[2], argv[3]);
- }
- else if (scrop.compare(argv[1]) == 0 || c.compare(argv[1]) == 0)
- {
- bool b = false;
- if (argc > 4)
- b = crop.load_xml(argv[2], argv[3], argv[4]);
- else
- b = crop.load_xml(argv[2], argv[3]);
-
- if (b)
- crop.find_image_regions();
- }
- else
- std::cout << man;
- }
- else
- std::cout << man;
- }
- else
- std::cout << man;
-
- return 0;
-}
diff --git a/scribo/sandbox/arthur/xml_to_html/patterns/css.css b/scribo/sandbox/arthur/xml_to_html/patterns/css.css
deleted file mode 100644
index 7171754..0000000
--- a/scribo/sandbox/arthur/xml_to_html/patterns/css.css
+++ /dev/null
@@ -1,28 +0,0 @@
-.line
-{
- position:absolute;
- background-color:white;
- z-index:7;
- display:inline;
- white-space:pre;
- letter-spacing:-2px;
- padding:0px;
- margin:0px;
- filter:alpha(opacity=100);
- font-family:"Times New Roman", Times, serif;
-}
-.para
-{
- position:absolute;
- z-index:6;
-}
-.region
-{
- position:absolute;
- z-index:5;
-}
-.image
-{
- position:absolute;
- border:0;
-}
\ No newline at end of file
diff --git a/scribo/sandbox/arthur/xml_to_html/patterns/xsl.xsl b/scribo/sandbox/arthur/xml_to_html/patterns/xsl.xsl
deleted file mode 100644
index aa5a078..0000000
--- a/scribo/sandbox/arthur/xml_to_html/patterns/xsl.xsl
+++ /dev/null
@@ -1,229 +0,0 @@
-<?xml version="1.0"?>
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-
- <xsl:template match="/"> <!-- "/" means the whole document (root) -->
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <title>Fooooooo !</title>
- <link rel="stylesheet" type="text/css" href="css.css" />
- </head>
- <body>
-
- <div class="image" style="top:0px;left:0px;">
- <img src="../../ppm/mp00076.png" />
- </div>
-
- <!-- BEGIN IMAGE REGION -->
- <xsl:for-each select="pcGts/page/graphic_region|
- pcGts/page/image_region|
- pcGts/page/chart_region|
- pcGts/page/table_region|
- pcGts/page/separator_region|
- pcGts/page/text_region|
- pcGts/page/text_region/paragraph|
- pcGts/page/text_region/paragraph/line">
-
- <!-- y1 -->
- <xsl:variable name="y1">
- <xsl:for-each select="coords/point">
- <xsl:sort select="@y" order="ascending" data-type="number"/>
- <xsl:if test="position() = 1">
- <xsl:value-of select="@y" />
- </xsl:if>
- </xsl:for-each>
- </xsl:variable>
-
- <!-- x2 -->
- <xsl:variable name="x2">
- <xsl:for-each select="coords/point">
- <xsl:sort select="@x" order="descending" data-type="number"/>
- <xsl:if test="position() = 1">
- <xsl:value-of select="@x" />
- </xsl:if>
- </xsl:for-each>
- </xsl:variable>
-
- <!-- y2 -->
- <xsl:variable name="y2">
- <xsl:for-each select="coords/point">
- <xsl:sort select="@y" order="descending" data-type="number"/>
- <xsl:if test="position() = 1">
- <xsl:value-of select="@y" />
- </xsl:if>
- </xsl:for-each>
- </xsl:variable>
-
- <!-- x1 -->
- <xsl:variable name="x1">
- <xsl:for-each select="coords/point">
- <xsl:sort select="@x" order="ascending" data-type="number"/>
- <xsl:if test="position() = 1">
- <xsl:value-of select="@x" />
- </xsl:if>
- </xsl:for-each>
- </xsl:variable>
-
- <!-- TEXT LINE-->
- <xsl:if test="name() = 'line'">
-
- <xsl:variable name="x_height">
- <xsl:value-of select="../../@x_height" />
- </xsl:variable>
-
- <xsl:variable name="a_height">
- <xsl:value-of select="../../@a_height" />
- </xsl:variable>
-
- <xsl:variable name="colour">
- <xsl:choose>
- <xsl:when test="../../@txt_colour != ''">
- <xsl:value-of select="../../@txt_colour" />
- </xsl:when>
- <xsl:otherwise>
- Black
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
- <xsl:variable name="d_height_tmp">
- <xsl:value-of select="../../@d_height" />
- </xsl:variable>
-
- <xsl:variable name="d_height">
- <xsl:choose>
- <xsl:when test="$d_height_tmp < 0">
- <xsl:value-of select="-$d_height_tmp" />
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$d_height_tmp" />
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
- <xsl:variable name="a">
- <xsl:choose>
- <xsl:when test="($a_height - $x_height) < $d_height">
- <xsl:value-of select="$x_height + $d_height" />
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$a_height" />
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
- <xsl:variable name="d">
- <xsl:choose>
- <xsl:when test="($a_height - $x_height) > $d_height">
- <xsl:value-of select="-($a_height - $x_height)" />
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$d_height" />
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
- <xsl:variable name="d_f">
- <xsl:choose>
- <xsl:when test="$d < 0">
- <xsl:value-of select="-$d" />
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$d" />
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
- <div class="line" onmouseover="this.style.opacity=0.2;this.filters.alpha.opacity=20"
- onmouseout="this.style.opacity=1;this.filters.alpha.opacity=100">
- <xsl:attribute name="style">
- opacity:1;
- height:auto;
- font-size:<xsl:value-of select="$a+$d_f" />px;
- width:<xsl:value-of select="$x2 - $x1" />px;
- left:<xsl:value-of select="$x1 " />px;
- top:<xsl:value-of select="$y1 " />px;
- color:<xsl:value-of select="$colour" />;
- </xsl:attribute>
- <xsl:value-of select="@text"/>
- </div>
- </xsl:if>
- <!-- ENF OF TEXT LINE -->
-
- <!-- TEXT REGION -->
- <xsl:if test="name() = 'text_region'">
- <div class="region">
- <xsl:attribute name="style">
- height:<xsl:value-of select="$y2 - $y1" />px;
- width:<xsl:value-of select="$x2 - $x1" />px;
- left:<xsl:value-of select="$x1" />px;
- top:<xsl:value-of select="$y1" />px;
- </xsl:attribute>
- </div>
- </xsl:if>
- <!-- ENF OF TEXT REGION -->
-
- <!-- PARAGRAPH -->
- <xsl:if test="name() = 'paragraph'">
- <div class="para">
- <xsl:attribute name="style">
- height:<xsl:value-of select="$y2 - $y1" />px;
- width:<xsl:value-of select="$x2 - $x1" />px;
- left:<xsl:value-of select="$x1" />px;
- top:<xsl:value-of select="$y1" />px;
- </xsl:attribute>
- </div>
- </xsl:if>
- <!-- ENF OF PARAGRAPH -->
-
- <!-- NON-TEXT REGIONS -->
- <xsl:if test="name() = 'image_region' or name() = 'separator_region' or name() = 'graphic_region' or name() = 'chart_region' or name() = 'table_region'">
-
- <!-- id -->
- <xsl:variable name="id">
- <xsl:value-of select="@id" />
- </xsl:variable>
-
- <!-- depth -->
- <xsl:variable name="depth">
- <xsl:choose>
- <xsl:when test="name() = 'separator_region'">
- 1
- </xsl:when>
- <xsl:otherwise>
- 4
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
- <div class="image">
- <xsl:attribute name="style">
- top:<xsl:value-of select="$y1" />px;
- left:<xsl:value-of select="$x1" />px;
- width:<xsl:value-of select="$x2 - $x1"/>px;
- height:<xsl:value-of select="$y2 - $y1"/>px;
- z-index:<xsl:value-of select="$depth"/>;
- </xsl:attribute>
- <img>
- <xsl:attribute name="alt">
- <xsl:value-of select="name()" />
- </xsl:attribute>
- <xsl:attribute name="width">
- <xsl:value-of select="$x2 - $x1" />
- </xsl:attribute>
- <xsl:attribute name="height">
- <xsl:value-of select="$y2 - $y1" />
- </xsl:attribute>
- <xsl:attribute name="src">
- img/<xsl:value-of select="$id"/>.png</xsl:attribute>
- </img>
- </div>
-
- </xsl:if>
- <!-- END NON-TEXT REGIONS -->
- </xsl:for-each>
- </body>
- </html>
- </xsl:template>
-
-</xsl:stylesheet>
diff --git a/scribo/sandbox/arthur/xml_to_html/xml_to_html.cc b/scribo/sandbox/arthur/xml_to_html/xml_to_html.cc
deleted file mode 100644
index 8267466..0000000
--- a/scribo/sandbox/arthur/xml_to_html/xml_to_html.cc
+++ /dev/null
@@ -1,292 +0,0 @@
-// Copyright (C) 2010 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.
-
-# include "xml_to_html.hh"
-# include "dommodel.hh"
-# include <limits.h>
-
-#include <scribo/preprocessing/crop.hh>
-#include <mln/value/rgb8.hh>
-#include <mln/core/alias/box2d.hh>
-#include <mln/core/image/image2d.hh>
-#include <mln/io/magick/save.hh>
-#include <mln/io/ppm/all.hh>
-
-ImageCrop::ImageCrop():
- regions_(false)
-{
-}
-
-ImageCrop::~ImageCrop()
-{
-}
-
-void ImageCrop::merge(QString in, QString other, QString output)
-{
- if (in.endsWith(".xml") && other.endsWith(".xml") && output.endsWith(".xml"))
- {
- QFile f_in(in);
- QFile f_other(other);
- QFile f_output(output);
-
- qDebug() << "Merging to " << output << "...";
-
- f_in.open(QIODevice::ReadOnly);
- f_other.open(QIODevice::ReadOnly);
- f_output.open(QIODevice::ReadWrite);
-
- QTextStream stream_in(&f_in);
- QTextStream stream_other(&f_other);
- QTextStream output_stream(&f_output);
-
- QString line = stream_in.readLine();
- output_stream << line;
- line = stream_in.readLine();
-
- while (!line.contains("</page>"))
- {
- output_stream << "\n" << line;
- line = stream_in.readLine();
- }
-
- line = stream_other.readLine();
-
- while (!line.contains("<page"))
- line = stream_other.readLine();
-
- line = stream_other.readLine();
-
- while (!line.contains("</pcGts>"))
- {
- output_stream << "\n" << line;
- line = stream_other.readLine();
- }
-
- output_stream << "\n" << line;
-
- f_in.close();
- f_other.close();
- f_output.close();
- }
- else
- std::cout << "merge : error, only xml files are needed." << std::endl;
-}
-
-bool ImageCrop::load_xml(QString xml_file, QString image_file, QString path)
-{
- if (xml_file.endsWith(".xml") && (image_file.endsWith(".ppm") || image_file == QString::Null()) )
- {
- image_file_ = image_file;
- regions_ = (image_file != QString::Null());
-
- path_ = path;
- if (!path_.endsWith("/"))
- path_.append("/");
-
- QDir dir(path_);
-
- if (!dir.mkpath("img"))
- {
- path_ = "output/";
- dir.mkpath(path_);
- dir.setPath(path_);
- dir.mkpath("img");
- }
-
- if (QFile::exists(xml_file))
- {
- QFile file(xml_file);
- QFile output(path_ + "output.xml");
- QFile xsl("patterns/xsl.xsl");
- QFile css("patterns/css.css");
- xsl.copy(path_ + "xsl.xsl");
- css.copy(path_ + "css.css");
-
- if (QFile::exists(path_ + "output.xml"))
- output.remove();
-
- output.open(QIODevice::ReadWrite);
- file.open(QIODevice::ReadOnly);
-
- QTextStream stream_in(&file);
- QTextStream stream_out(&output);
- stream_in.setCodec("UTF-8");
- stream_out.setCodec("UTF-8");
-
- QString line = stream_in.readLine();
- stream_out << line;
- stream_out << "\n<?xml-stylesheet type=\"text/xsl\" href=\"xsl.xsl\" ?>";
-
- // /!\ attributes of ICDAR PcGts removed.
- line = stream_in.readLine();
- stream_out << "\n<pcGts>";
-
- line = stream_in.readLine();
-
- while (!line.contains("</pcGts>"))
- {
- stream_out << "\n" << line;
- line = stream_in.readLine();
- }
-
- stream_out << "\n" << line;
-
- output.close();
- file.close();
-
- qDebug() << "Output saved to " + path_;
-
- if (file.open(QIODevice::ReadOnly))
- {
- QDomDocument document;
- if (document.setContent(&file))
- {
- layout_ = new DomModel(document, this);
- }
- else
- qDebug() << "Error while loading the XML file, please choose another.";
-
- file.close();
- }
- }
- return true;
- }
- else
- {
- std::cout << "Wrong files format !" << std::endl;
- return false;
- }
-}
-
-void ImageCrop::find_image_regions()
-{
- if (layout_ && regions_)
- {
- QModelIndex pgGts = layout_->index(1, 0);
- QModelIndex page = layout_->index(1, 0, pgGts);
- QModelIndex region;
- QModelIndex attributes;
- QModelIndex coords;
- QModelIndex point;
- bool regions_found = false;
- for (int i = 0; true; ++i)
- {
- region = layout_->index(i, 0, page);
- attributes = layout_->index(i, 1, page);
- QString name = layout_->data(region, Qt::DisplayRole).toString();
- coords = layout_->index(0, 0, region);
-
- bool is_image_region = name == QString("image_region")
- || name == QString("graphic_region")
- || name == QString("separator_region")
- || name == QString("chart_region")
- || name == QString("table_region") ;
-
- if (!region.isValid() || !coords.isValid())
- break;
-
- if (is_image_region)
- {
-
- regions_found = true;
- QMap<QString, QVariant> data =
- layout_->data(attributes, Qt::UserRole).toMap();
-
- QString id;
- QMap<QString, QVariant>::iterator it = data.find("id");
-
- if (it == data.end() || it.key() != "id")
- qDebug() << "No image region.";
-
- while (it != data.end() && it.key() == "id")
- {
- qDebug() << name;
- id = it.value().toString();
- qDebug() << it.key() + " = " + it.value().toString();
- ++it;
- }
-
- int x_max = 0;
- int y_max = 0;
- int x_min = INT_MAX;
- int y_min = INT_MAX;
-
- // QVector<QMap<QString, QVariant> > vect;
- for (int j = 0; true; ++j)
- {
- // Navigate to the coordinate list
- point = layout_->index(j, 1, coords);
- if (!point.isValid())
- break;
-
- QMap<QString, QVariant> data =
- layout_->data(point, Qt::UserRole).toMap();
- int x = data["x"].toInt();
- int y = data["y"].toInt();
-
- // vect << data;
-
- if (x < x_min)
- x_min = x;
- if (x > x_max)
- x_max = x;
-
- if (y < y_min)
- y_min = y;
- if (y > y_max)
- y_max = y;
-
- }
-
- using namespace mln;
-
- box2d box = make::box2d(y_min, x_min, y_max, x_max);
-
- image2d<value::rgb8> ima;
- io::ppm::load(ima, image_file_.toStdString());
- ima = scribo::preprocessing::crop(ima, box);
-
- // image2d<bool> mask = make::box2d(y_min, x_min, y_max, x_max);
- // data::fill(mask, true);
-
- /*for (int a = 1; a < vect.size(); ++a)
- {
- int x = vect[a]["x"].toInt();
- int y = vect[a]["y"].toInt();
-
- data::fill((mask | make::box2d(y, x, y, x)).rw(), false);
- }*/
-
-
- // io::pbm::save(mask, "output/img/mask_" + id.toStdString());
- io::magick::save(ima, path_.toStdString() + "img/" + id.toStdString() + ".png");
-
- }
- }
-
- if (!regions_found)
- qDebug() << "No regions found.";
- }
-}
diff --git a/scribo/sandbox/arthur/xml_to_html/xml_to_html.hh b/scribo/sandbox/arthur/xml_to_html/xml_to_html.hh
deleted file mode 100644
index 27a271e..0000000
--- a/scribo/sandbox/arthur/xml_to_html/xml_to_html.hh
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright (C) 2010 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 IMAGE_CROP_HH
-# define IMAGE_CROP_HH
-
-# include <QtGui>
-
-class DomModel;
-
-class ImageCrop : public QObject
-{
- Q_OBJECT
- public:
- ImageCrop();
- ~ImageCrop();
- void merge(QString in, QString other, QString output = "output.xml");
- bool load_xml(QString xml_file, QString image_file = "", QString path = "output");
- void find_image_regions();
- private:
- DomModel* layout_;
- QString image_file_;
- QString path_;
- bool regions_;
-};
-
-#endif /* !IMAGE_CROP_HH */
diff --git a/scribo/sandbox/arthur/xml_to_html/xml_to_html.pro b/scribo/sandbox/arthur/xml_to_html/xml_to_html.pro
deleted file mode 100644
index b43b527..0000000
--- a/scribo/sandbox/arthur/xml_to_html/xml_to_html.pro
+++ /dev/null
@@ -1,16 +0,0 @@
-######################################################################
-# Automatically generated by qmake (2.01a) lun. juil. 5 16:53:31 2010
-######################################################################
-
-TEMPLATE = app
-TARGET =
-DEPENDPATH += .
-INCLUDEPATH += .
-QMAKE_CXXFLAGS += -I/amd/beyrouth/home/lrde/stage/crepin/olena/milena -I/amd/beyrouth/home/lrde/stage/crepin/olena/
-QT += xml
-LIBS += `Magick++-config --libs`
-
-
-# Input
-HEADERS += domitem.hh dommodel.hh xml_to_html.hh
-SOURCES += domitem.cc dommodel.cc main.cc xml_to_html.cc
diff --git a/scribo/sandbox/arthur/xml_transform/README b/scribo/sandbox/arthur/xml_transform/README
new file mode 100644
index 0000000..e0bfbc8
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/README
@@ -0,0 +1,19 @@
+xml_transform <option> <xml_file> <ppm_file> <output_dir>
+
+Transforms an ICDAR XML file to different kind of output.
+
+OPTIONS:
+
+ --html: Produce a HTML output
+
+Once process is finished, open output.xml with your internet browser. If this one supports XSLT, there is no problem to display the result but if it does not support it (like Konqueror or Chrome in local), you should run `sh html_generator.sh` (xsltproc package required) to generate a HTML file readable by all browsers.
+
+ --pdf: Produce a PDF output, regions will be cropped as follows in the XML file.
+ --pdf-no-crop: Produce a PDF output without cropping regions, the entire picture will be displayed.
+
+PDF is not directly created once the process is finished, to produce it, go to the output_dir and run `sh pdf_generator.sh` (fop >= 0.95 required).
+
+
+BUILD:
+
+Chnage the environment variable QMAKE_CXXFLAGS to indicate the correct paths to milena and olena then, just type qmake and make.
\ No newline at end of file
diff --git a/scribo/sandbox/arthur/xml_to_html/domitem.cc b/scribo/sandbox/arthur/xml_transform/domitem.cc
similarity index 100%
rename from scribo/sandbox/arthur/xml_to_html/domitem.cc
rename to scribo/sandbox/arthur/xml_transform/domitem.cc
diff --git a/scribo/sandbox/arthur/xml_to_html/domitem.hh b/scribo/sandbox/arthur/xml_transform/domitem.hh
similarity index 100%
rename from scribo/sandbox/arthur/xml_to_html/domitem.hh
rename to scribo/sandbox/arthur/xml_transform/domitem.hh
diff --git a/scribo/sandbox/arthur/xml_to_html/dommodel.cc b/scribo/sandbox/arthur/xml_transform/dommodel.cc
similarity index 100%
rename from scribo/sandbox/arthur/xml_to_html/dommodel.cc
rename to scribo/sandbox/arthur/xml_transform/dommodel.cc
diff --git a/scribo/sandbox/arthur/xml_to_html/dommodel.hh b/scribo/sandbox/arthur/xml_transform/dommodel.hh
similarity index 100%
rename from scribo/sandbox/arthur/xml_to_html/dommodel.hh
rename to scribo/sandbox/arthur/xml_transform/dommodel.hh
diff --git a/scribo/sandbox/arthur/xml_transform/image_crop.cc b/scribo/sandbox/arthur/xml_transform/image_crop.cc
new file mode 100644
index 0000000..aa17c31
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/image_crop.cc
@@ -0,0 +1,184 @@
+// Copyright (C) 2010 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.
+
+# include "image_crop.hh"
+# include "loader.hh"
+# include "dommodel.hh"
+
+# include <limits.h>
+
+#include <scribo/preprocessing/crop.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/core/alias/box2d.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/io/magick/save.hh>
+#include <mln/io/ppm/all.hh>
+
+ImageCrop::ImageCrop()
+{
+}
+
+ImageCrop::~ImageCrop()
+{
+}
+
+void ImageCrop::save_image(QString image, QString output)
+{
+ using namespace mln;
+
+ image2d<value::rgb8> ima;
+ io::ppm::load(ima, image.toStdString());
+
+ io::magick::save(ima, output.toStdString() + "img/image.png");
+}
+
+void ImageCrop::crop_regions(QString xml_file, QString image_file, QString output)
+{
+ Loader loader;
+
+ QFile f(image_file);
+
+ if (!f.exists())
+ {
+ qDebug() << "Image doesn't exist !";
+ abort();
+ }
+ DomModel* layout = loader.xml_to_dom(xml_file);
+ if (layout)
+ {
+ QModelIndex pcGts = layout->index(1, 0);
+ QModelIndex page = layout->index(1, 0, pcGts);
+ QModelIndex region;
+ QModelIndex attributes;
+ QModelIndex coords;
+ QModelIndex point;
+ bool regions_found = false;
+
+ for (int i = 0; true; ++i)
+ {
+ region = layout->index(i, 0, page);
+ attributes = layout->index(i, 1, page);
+
+ QString name = layout->data(region, Qt::DisplayRole).toString();
+ coords = layout->index(0, 0, region);
+
+ bool is_region =
+ name == QString("image_region")
+ || name == QString("graphic_region")
+ || name == QString("separator_region")
+ || name == QString("chart_region")
+ || name == QString("table_region") ;
+
+ if (!region.isValid() || !coords.isValid())
+ break;
+
+ if (is_region)
+ {
+ regions_found = true;
+ QMap<QString, QVariant> data =
+ layout->data(attributes, Qt::UserRole).toMap();
+
+ QString id;
+ QMap<QString, QVariant>::iterator it = data.find("id");
+
+ if (it == data.end() || it.key() != "id")
+ qDebug() << "WTF_Error : No image region.";
+
+ while (it != data.end() && it.key() == "id")
+ {
+ qDebug() << name;
+ id = it.value().toString();
+ qDebug() << it.key() + " = " + it.value().toString();
+ ++it;
+ }
+
+ int x_max = 0;
+ int y_max = 0;
+ int x_min = INT_MAX;
+ int y_min = INT_MAX;
+
+ // QVector<QMap<QString, QVariant> > vect;
+ for (int j = 0; true; ++j)
+ {
+ // Navigate to the coordinate list
+ point = layout->index(j, 1, coords);
+ if (!point.isValid())
+ break;
+
+ QMap<QString, QVariant> data =
+ layout->data(point, Qt::UserRole).toMap();
+ int x = data["x"].toInt();
+ int y = data["y"].toInt();
+
+ // vect << data;
+
+ if (x < x_min)
+ x_min = x;
+ if (x > x_max)
+ x_max = x;
+
+ if (y < y_min)
+ y_min = y;
+ if (y > y_max)
+ y_max = y;
+
+ }
+
+ using namespace mln;
+
+ box2d box = make::box2d(y_min, x_min, y_max, x_max);
+
+ image2d<value::rgb8> ima;
+ io::ppm::load(ima, image_file.toStdString());
+ ima = scribo::preprocessing::crop(ima, box);
+
+ // image2d<bool> mask = make::box2d(y_min, x_min, y_max, x_max);
+ // data::fill(mask, true);
+
+ /*for (int a = 1; a < vect.size(); ++a)
+ {
+ int x = vect[a]["x"].toInt();
+ int y = vect[a]["y"].toInt();
+
+ data::fill((mask | make::box2d(y, x, y, x)).rw(), false);
+ }*/
+
+ // io::pbm::save(mask, "output/img/mask_" + id.toStdString());
+ io::magick::save(ima, output.toStdString() + "img/" + id.toStdString() + ".png");
+
+ }
+ }
+
+ if (!regions_found)
+ qDebug() << "No regions found.";
+
+ }
+ else
+ {
+ qDebug() << "Error with XML file.";
+ }
+
+
+}
diff --git a/scribo/sandbox/arthur/xml_transform/image_crop.hh b/scribo/sandbox/arthur/xml_transform/image_crop.hh
new file mode 100644
index 0000000..e4b0a38
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/image_crop.hh
@@ -0,0 +1,46 @@
+// Copyright (C) 2010 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 IMAGE_CROP_HH
+# define IMAGE_CROP_HH
+
+# include <QtGui>
+
+class DomModel;
+
+class ImageCrop : public QObject
+{
+ Q_OBJECT
+ public:
+
+ ImageCrop();
+ ~ImageCrop();
+
+ void save_image(QString image, QString output);
+ void crop_regions(QString xml_file, QString image_file, QString output);
+
+};
+
+#endif /* !IMAGE_CROP_HH */
diff --git a/scribo/sandbox/arthur/xml_transform/loader.cc b/scribo/sandbox/arthur/xml_transform/loader.cc
new file mode 100644
index 0000000..5623928
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/loader.cc
@@ -0,0 +1,162 @@
+// Copyright (C) 2010 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.
+
+# include "loader.hh"
+# include "dommodel.hh"
+# include "xml_transform.hh"
+
+Loader::Loader()
+{
+}
+
+Loader::~Loader()
+{
+}
+
+DomModel* Loader::xml_to_dom(QString output)
+{
+ QString file_path = output;
+
+ QFile file(file_path);
+
+ if (file.open(QIODevice::ReadOnly))
+ {
+ QDomDocument document;
+ if (document.setContent(&file))
+ {
+ return new DomModel(document);
+ }
+ }
+
+ return 0;
+}
+
+bool Loader::set_output(QString& output)
+{
+ QDir dir(output);
+
+ if (!output.endsWith("/"))
+ output.append("/");
+
+ if (!dir.exists())
+ {
+ return dir.mkpath(".");
+ }
+ else
+ {
+ QStringList list = dir.entryList(QDir::Writable | QDir::AllDirs);
+ return list.size() != 0;
+ }
+}
+
+
+void Loader::add_html_templates(QString output)
+{
+
+ QFile gen("templates/html/html_generator.sh");
+ gen.copy(output + "html_generator.sh");
+
+ QFile css("templates/html/css.css");
+ css.copy(output + "css.css");
+
+ QFile xsl("templates/html/xsl.xsl");
+ xsl.copy(output + "xsl.xsl");
+
+}
+
+void Loader::add_pdf_templates(bool crop, QString output)
+{
+
+ QFile regions("templates/pdf/regions.xsl");
+ regions.copy(output + "regions.xsl");
+
+ QFile gen("templates/pdf/pdf_generator.sh");
+ gen.copy(output + "pdf_generator.sh");
+
+ QFile line("templates/pdf/line.xsl");
+ line.copy(output + "line.xsl");
+ if (crop)
+ {
+ QFile xsl("templates/pdf/main_crop.xsl");
+ xsl.copy(output + "main.xsl");
+ }
+ else
+ {
+ QFile xsl("templates/pdf/main.xsl");
+ xsl.copy(output + "main.xsl");
+ }
+}
+
+bool Loader::load_xml(QString xml_file, bool html, QString output)
+{
+ QFile file(xml_file);
+
+ if (file.exists())
+ {
+ file.open(QIODevice::ReadOnly);
+ set_output(output);
+
+ QFile out_file(output + "output.xml");
+ out_file.open(QIODevice::ReadWrite);
+
+ QTextStream stream_in(&file);
+ QTextStream stream_out(&out_file);
+
+ QString line = stream_in.readLine();
+
+ while(!line.contains("<?xml"))
+ line = stream_in.readLine();
+
+ stream_out << line;
+
+ if (html)
+ stream_out << "\n<?xml-stylesheet type=\"text/xsl\" href=\"xsl.xsl\" ?>";
+
+ // /!\ attributes of ICDAR PcGts removed.
+ while(!line.contains("<pcGts"))
+ line = stream_in.readLine();
+
+ line = stream_in.readLine();
+ stream_out << "\n<pcGts>";
+
+ while (!line.contains("</pcGts>"))
+ {
+ stream_out << "\n" << line;
+ line = stream_in.readLine();
+ }
+
+ stream_out << "\n" << line;
+
+ file.close();
+ out_file.close();
+
+ return true;
+ }
+ else
+ {
+ qDebug() << xml_file + " doesn't exist";
+ return false;
+ }
+}
diff --git a/scribo/sandbox/arthur/xml_transform/loader.hh b/scribo/sandbox/arthur/xml_transform/loader.hh
new file mode 100644
index 0000000..7d24254
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/loader.hh
@@ -0,0 +1,49 @@
+// Copyright (C) 2010 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 LOADER_HH
+# define LOADER_HH
+
+//# include <QtGui>
+# include "xml_transform.hh"
+
+class DomModel;
+
+class Loader
+{
+ public:
+
+ Loader();
+ ~Loader();
+
+ // void merge(QString in, QString other, QString output = "output.xml");
+ bool load_xml(QString xml_file, bool html, QString output);
+ DomModel* xml_to_dom(QString output);
+ bool set_output(QString& output);
+ void add_pdf_templates(bool crop, QString output);
+ void add_html_templates(QString output);
+};
+
+#endif /* !LOADER_HH */
diff --git a/scribo/sandbox/arthur/xml_transform/main.cc b/scribo/sandbox/arthur/xml_transform/main.cc
new file mode 100644
index 0000000..9e18cff
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/main.cc
@@ -0,0 +1,30 @@
+#include <iostream>
+#include "xml_transform.hh"
+
+int main(int argc, char **argv)
+{
+
+ std::string man = "xml_transform <option> <xml_file> <ppm_file> <output_dir>\nOPTIONS:\n\t--html: Produce a HTML output\n\t--pdf: Produce a PDF output, regions will be croped as follows in the XML file.\n\t--pdf-no-crop: Produce a PDF output without croping regions, the entire picture will be displayed.";
+
+ if (argc > 4)
+ {
+ std::string html = "--html";
+ std::string pdf = "--pdf";
+ std::string pdf_no_crop = "--pdf-no-crop";
+
+ XmlTransform xmlt(argv[4], argv[2]);
+
+ if (html.compare(argv[1]) == 0)
+ xmlt.createHTML(argv[3]);
+ else if (pdf.compare(argv[1]) == 0)
+ xmlt.createPDF(argv[3], true);
+ else if (pdf_no_crop.compare(argv[1]) == 0)
+ xmlt.createPDF(argv[3], false);
+ else
+ std::cout << man << std::endl;
+ }
+ else
+ std::cout << man << std::endl;
+
+ return 0;
+}
diff --git a/scribo/sandbox/arthur/xml_transform/templates/html/css.css b/scribo/sandbox/arthur/xml_transform/templates/html/css.css
new file mode 100644
index 0000000..0443390
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/templates/html/css.css
@@ -0,0 +1,31 @@
+.line
+{
+ position:absolute;
+ background-color:white;
+ z-index:7;
+ display:inline;
+ white-space:pre;
+
+ /* FIXME */
+ letter-spacing:-2px;
+
+ padding:0px;
+ margin:0px;
+ filter:alpha(opacity=100);
+ font-family:"Times New Roman", Times, serif;
+}
+.para
+{
+ position:absolute;
+ z-index:6;
+}
+.region
+{
+ position:absolute;
+ z-index:5;
+}
+.image
+{
+ position:absolute;
+ border:0;
+}
\ No newline at end of file
diff --git a/scribo/sandbox/arthur/xml_transform/templates/html/html_generator.sh b/scribo/sandbox/arthur/xml_transform/templates/html/html_generator.sh
new file mode 100644
index 0000000..bb24305
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/templates/html/html_generator.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+xsltproc xsl.xsl output.xml > output.html
\ No newline at end of file
diff --git a/scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl b/scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
new file mode 100644
index 0000000..3d6a1c5
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
@@ -0,0 +1,224 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+ <xsl:template match="/"> <!-- "/" means the whole document (root) -->
+ <html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <title>SCRIBO</title>
+ <link rel="stylesheet" type="text/css" href="css.css" />
+ </head>
+ <body>
+
+ <xsl:for-each select="pcGts/page/graphic_region|
+ pcGts/page/image_region|
+ pcGts/page/chart_region|
+ pcGts/page/table_region|
+ pcGts/page/separator_region|
+ pcGts/page/text_region|
+ pcGts/page/text_region/paragraph|
+ pcGts/page/text_region/paragraph/line">
+
+ <!-- Regions Coordinates -->
+
+ <!-- y1 -->
+ <xsl:variable name="y1">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@y" order="ascending" data-type="number"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="@y" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+
+ <!-- x2 -->
+ <xsl:variable name="x2">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@x" order="descending" data-type="number"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="@x" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+
+ <!-- y2 -->
+ <xsl:variable name="y2">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@y" order="descending" data-type="number"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="@y" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+
+ <!-- x1 -->
+ <xsl:variable name="x1">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@x" order="ascending" data-type="number"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="@x" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+
+ <!-- END OF Regions Coordinates -->
+
+ <!-- TEXT LINE-->
+ <xsl:if test="name() = 'line'">
+
+ <xsl:variable name="colour">
+ <xsl:choose>
+ <xsl:when test="../../@txt_colour != ''">
+ <xsl:value-of select="../../@txt_colour" />
+ </xsl:when>
+ <xsl:otherwise>
+ Black
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <!-- x_height -->
+ <xsl:variable name="x_height">
+ <xsl:value-of select="../../@x_height" />
+ </xsl:variable>
+
+ <!-- a_height -->
+ <xsl:variable name="a_height">
+ <xsl:value-of select="../../@a_height" />
+ </xsl:variable>
+
+ <!-- ABS(d_height) -->
+ <xsl:variable name="d_height_abs">
+ <xsl:choose>
+ <xsl:when test="../../@d_height < 0">
+ <xsl:value-of select="-../../@d_height" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="../../@d_height" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <!-- a_height computed, i.e>
+ if (A - X < |D|)
+ A = X + |D|
+ -->
+ <xsl:variable name="a">
+ <xsl:choose>
+ <xsl:when test="($a_height - $x_height) < $d_height_abs">
+ <xsl:value-of select="$x_height + $d_height_abs" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$a_height" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <!-- d_height computed, i.e>
+ if (A - A > |D|)
+ |D| = A - X
+ -->
+ <xsl:variable name="d">
+ <xsl:choose>
+ <xsl:when test="($a_height - $x_height) > $d_height_abs">
+ <xsl:value-of select="$a_height - $x_height" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$d_height_abs" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <div class="line" onmouseover="this.style.opacity=0.2;this.filters.alpha.opacity=20"
+ onmouseout="this.style.opacity=1;this.filters.alpha.opacity=100">
+ <xsl:attribute name="style">
+ opacity:1;
+ height:auto;
+ font-size:<xsl:value-of select="$a+$d" />px;
+ width:<xsl:value-of select="$x2 - $x1" />px;
+ left:<xsl:value-of select="$x1 " />px;
+ top:<xsl:value-of select="$y1 " />px;
+ color:<xsl:value-of select="$colour" />;
+ </xsl:attribute>
+ <xsl:value-of select="@text"/>
+ </div>
+ </xsl:if>
+ <!-- ENF OF TEXT LINE -->
+
+ <!-- TEXT REGION -->
+ <xsl:if test="name() = 'text_region'">
+ <div class="region">
+ <xsl:attribute name="style">
+ height:<xsl:value-of select="$y2 - $y1" />px;
+ width:<xsl:value-of select="$x2 - $x1" />px;
+ left:<xsl:value-of select="$x1" />px;
+ top:<xsl:value-of select="$y1" />px;
+ </xsl:attribute>
+ </div>
+ </xsl:if>
+ <!-- ENF OF TEXT REGION -->
+
+ <!-- PARAGRAPH -->
+ <xsl:if test="name() = 'paragraph'">
+ <div class="para">
+ <xsl:attribute name="style">
+ height:<xsl:value-of select="$y2 - $y1" />px;
+ width:<xsl:value-of select="$x2 - $x1" />px;
+ left:<xsl:value-of select="$x1" />px;
+ top:<xsl:value-of select="$y1" />px;
+ </xsl:attribute>
+ </div>
+ </xsl:if>
+ <!-- ENF OF PARAGRAPH -->
+
+ <!-- NON-TEXT REGIONS -->
+ <xsl:if test="name() = 'image_region' or name() = 'separator_region' or name() = 'graphic_region' or name() = 'chart_region' or name() = 'table_region'">
+
+ <!-- id -->
+ <xsl:variable name="id">
+ <xsl:value-of select="@id" />
+ </xsl:variable>
+
+ <!-- depth -->
+ <xsl:variable name="depth">
+ <xsl:choose>
+ <xsl:when test="name() = 'separator_region'">
+ 1
+ </xsl:when>
+ <xsl:otherwise>
+ 4
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <div class="image">
+ <xsl:attribute name="style">
+ top:<xsl:value-of select="$y1" />px;
+ left:<xsl:value-of select="$x1" />px;
+ width:<xsl:value-of select="$x2 - $x1"/>px;
+ height:<xsl:value-of select="$y2 - $y1"/>px;
+ z-index:<xsl:value-of select="$depth"/>;
+ </xsl:attribute>
+ <img>
+ <xsl:attribute name="alt">
+ <xsl:value-of select="name()" />
+ </xsl:attribute>
+ <xsl:attribute name="width">
+ <xsl:value-of select="$x2 - $x1" />
+ </xsl:attribute>
+ <xsl:attribute name="height">
+ <xsl:value-of select="$y2 - $y1" />
+ </xsl:attribute>
+ <xsl:attribute name="src">
+ img/<xsl:value-of select="$id"/>.png</xsl:attribute>
+ </img>
+ </div>
+
+ </xsl:if>
+ <!-- END NON-TEXT REGIONS -->
+ </xsl:for-each>
+ </body>
+ </html>
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git a/scribo/sandbox/arthur/xml_transform/templates/pdf/line.xsl b/scribo/sandbox/arthur/xml_transform/templates/pdf/line.xsl
new file mode 100644
index 0000000..b143502
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/templates/pdf/line.xsl
@@ -0,0 +1,129 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
+
+ <!-- FILE: line.xsl
+ DESCRIPTION: match all pcGts/page/text_region/paragraph/line in order to display the "text" attributes
+ -->
+
+ <xsl:template match="pcGts/page/text_region/paragraph/line">
+
+ <!-- x_height -->
+ <xsl:variable name="x_height">
+ <xsl:value-of select="../../@x_height" />
+ </xsl:variable>
+
+ <!-- a_height -->
+ <xsl:variable name="a_height">
+ <xsl:value-of select="../../@a_height" />
+ </xsl:variable>
+
+
+ <!-- ABS(d_height) -->
+ <xsl:variable name="d_height_abs">
+ <xsl:choose>
+ <xsl:when test="../../@d_height < 0">
+ <xsl:value-of select="-../../@d_height" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="../../@d_height" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <!-- a_height computed, i.e>
+ if (A - X < |D|)
+ A = X + |D|
+ -->
+ <xsl:variable name="a">
+ <xsl:choose>
+ <xsl:when test="($a_height - $x_height) < $d_height_abs">
+ <xsl:value-of select="$x_height + $d_height_abs" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$a_height" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <!-- d_height computed, i.e>
+ if (A - A > |D|)
+ |D| = A - X
+ -->
+ <xsl:variable name="d">
+ <xsl:choose>
+ <xsl:when test="($a_height - $x_height) > $d_height_abs">
+ <xsl:value-of select="$a_height - $x_height" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$d_height_abs" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <!-- Text lines coordinates -->
+ <xsl:variable name="y1">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@y" order="ascending" data-type="number"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="@y" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+
+ <xsl:variable name="x1">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@x" order="ascending" data-type="number"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="@x" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+ <!-- END OF lines coordinates -->
+
+ <!-- WTF !?, Necessary to do a lower-case ! -->
+ <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
+ <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
+
+ <!-- Text Colour -->
+ <xsl:variable name="colour">
+ <xsl:choose>
+ <xsl:when test="../../@txt_colour != ''">
+ <xsl:value-of select="translate(../../@txt_colour, $smallcase, $uppercase)" />
+ </xsl:when>
+ <xsl:otherwise>
+ black
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+
+ <fo:block-container position="absolute">
+
+ <xsl:attribute name="left">
+ <xsl:value-of select="$x1" />px
+ </xsl:attribute>
+ <xsl:attribute name="top">
+ <xsl:value-of select="$y1" />px
+ </xsl:attribute>
+
+ <xsl:attribute name="color">
+ <xsl:value-of select="$colour" />
+ </xsl:attribute>
+
+ <!-- if necessary, put letter-spacing="-Npt" ~ -3 <= N <= -1
+ in fo:block-->
+
+ <fo:block font-family="Times">
+
+ <xsl:attribute name="font-size">
+ <xsl:value-of select="$a + $d" />px
+ </xsl:attribute>
+
+ <xsl:value-of select="@text"/>
+ </fo:block>
+
+ </fo:block-container>
+
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git a/scribo/sandbox/arthur/xml_transform/templates/pdf/main.xsl b/scribo/sandbox/arthur/xml_transform/templates/pdf/main.xsl
new file mode 100644
index 0000000..065831e
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/templates/pdf/main.xsl
@@ -0,0 +1,62 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
+
+ <!-- FILE: main.xsl
+ DESCRIPTION: produce pdf output -->
+
+ <xsl:import href="line.xsl"/>
+
+ <xsl:template match="/">
+ <fo:root>
+
+ <fo:layout-master-set>
+ <fo:simple-page-master master-name="page" margin-left="0cm" margin-right="0cm" margin-bottom="0cm" margin-top="0cm">
+
+ <!-- Output will be sized with image size -->
+ <xsl:attribute name="page-width">
+ <xsl:value-of select="pcGts/page/@image_width" />px
+ </xsl:attribute>
+ <xsl:attribute name="page-height">
+ <xsl:value-of select="pcGts/page/@image_height" />px
+ </xsl:attribute>
+
+ <fo:region-body
+ margin-top="0mm" margin-bottom="0mm"
+ margin-left="0mm" margin-right="0mm"/>
+ <fo:region-after extent="0mm"/>
+
+ </fo:simple-page-master>
+ </fo:layout-master-set>
+
+ <fo:page-sequence master-reference="page">
+
+ <fo:flow flow-name="xsl-region-body">
+
+ <xsl:apply-imports />
+
+ <fo:block-container position="absolute" z-index="-3">
+
+ <xsl:attribute name="left">
+ 0px
+ </xsl:attribute>
+ <xsl:attribute name="top">
+ 0px
+ </xsl:attribute>
+
+ <fo:block>
+ <fo:external-graphic>
+ <xsl:attribute name="src">
+ url('img/image.png')
+ </xsl:attribute>
+ </fo:external-graphic>
+ </fo:block>
+
+ </fo:block-container>
+
+ </fo:flow>
+
+ </fo:page-sequence>
+ </fo:root>
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git a/scribo/sandbox/arthur/xml_transform/templates/pdf/main_crop.xsl b/scribo/sandbox/arthur/xml_transform/templates/pdf/main_crop.xsl
new file mode 100644
index 0000000..0dbb673
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/templates/pdf/main_crop.xsl
@@ -0,0 +1,42 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
+
+ <!-- FILE: main.xsl
+ DESCRIPTION: produce pdf output -->
+
+ <xsl:import href="regions.xsl"/>
+ <xsl:import href="line.xsl"/>
+
+ <xsl:template match="/">
+ <fo:root>
+
+ <fo:layout-master-set>
+ <fo:simple-page-master master-name="page" margin-left="0cm" margin-right="0cm" margin-bottom="0cm" margin-top="0cm">
+
+ <!-- Output will be sized with image size -->
+ <xsl:attribute name="page-width">
+ <xsl:value-of select="pcGts/page/@image_width" />px
+ </xsl:attribute>
+ <xsl:attribute name="page-height">
+ <xsl:value-of select="pcGts/page/@image_height" />px
+ </xsl:attribute>
+
+ <fo:region-body
+ margin-top="0mm" margin-bottom="0mm"
+ margin-left="0mm" margin-right="0mm"/>
+ <fo:region-after extent="0mm"/>
+
+ </fo:simple-page-master>
+ </fo:layout-master-set>
+
+ <fo:page-sequence master-reference="page">
+
+ <fo:flow flow-name="xsl-region-body">
+ <xsl:apply-imports />
+ </fo:flow>
+
+ </fo:page-sequence>
+ </fo:root>
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git a/scribo/sandbox/arthur/xml_transform/templates/pdf/pdf_generator.sh b/scribo/sandbox/arthur/xml_transform/templates/pdf/pdf_generator.sh
new file mode 100644
index 0000000..c6339a5
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/templates/pdf/pdf_generator.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+fop -xsl main.xsl -xml output.xml -pdf output.pdf
\ No newline at end of file
diff --git a/scribo/sandbox/arthur/xml_transform/templates/pdf/regions.xsl b/scribo/sandbox/arthur/xml_transform/templates/pdf/regions.xsl
new file mode 100644
index 0000000..65a8c79
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/templates/pdf/regions.xsl
@@ -0,0 +1,59 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
+
+ <!-- FILE: regions.xsl
+ DESCRIPTION: Match all regions that are not text to display them -->
+
+ <xsl:template match="pcGts/page/image_region|
+ pcGts/page/graphic_region|
+ pcGts/page/chart_region|
+ pcGts/page/table_region|
+ pcGts/page/separator_region">
+
+ <!-- ID of the region, used to display id.png -->
+ <xsl:variable name="id">
+ <xsl:value-of select="@id" />
+ </xsl:variable>
+
+ <!-- Regions coordinates -->
+ <xsl:variable name="y1">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@y" order="ascending" data-type="number"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="@y" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+
+ <xsl:variable name="x1">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@x" order="ascending" data-type="number"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="@x" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+ <!-- END OF regions coordinates -->
+
+ <fo:block-container position="absolute">
+
+ <xsl:attribute name="left">
+ <xsl:value-of select="$x1" />px
+ </xsl:attribute>
+ <xsl:attribute name="top">
+ <xsl:value-of select="$y1" />px
+ </xsl:attribute>
+
+ <fo:block>
+ <fo:external-graphic>
+ <xsl:attribute name="src">
+ url('img/<xsl:value-of select="$id" />.png')
+ </xsl:attribute>
+ </fo:external-graphic>
+ </fo:block>
+
+ </fo:block-container>
+
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git a/scribo/sandbox/arthur/xml_transform/xml_transform.cc b/scribo/sandbox/arthur/xml_transform/xml_transform.cc
new file mode 100644
index 0000000..dd35aff
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/xml_transform.cc
@@ -0,0 +1,93 @@
+// Copyright (C) 2010 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.
+
+# include "image_crop.hh"
+# include "loader.hh"
+# include "xml_transform.hh"
+
+XmlTransform::XmlTransform(QString output, QString xml_file) :
+ output_dir_(output),
+ xml_file_(xml_file)
+{
+ Loader loader;
+ if (!loader.set_output(output_dir_))
+ abort();
+}
+
+XmlTransform::~XmlTransform()
+{
+}
+
+void XmlTransform::createPDF (QString img, bool crop)
+{
+ Loader loader;
+
+ QString output = output_dir_;
+ output.append("img");
+
+ if (loader.set_output(output))
+ {
+ if (loader.load_xml(xml_file_, false, output_dir_))
+ {
+
+ ImageCrop Crop;
+
+ if (crop)
+ Crop.crop_regions(xml_file_, img, output_dir_);
+ else
+ Crop.save_image(img, output_dir_);
+
+ loader.add_pdf_templates(crop, output_dir_);
+ }
+ else
+ abort();
+ }
+ else
+ abort();
+}
+
+void XmlTransform::createHTML(QString img)
+{
+ Loader loader;
+
+ QString output = output_dir_;
+ output.append("img");
+
+ if (loader.set_output(output))
+ {
+ if (loader.load_xml(xml_file_, true, output_dir_))
+ {
+ ImageCrop Crop;
+
+ Crop.crop_regions(xml_file_, img, output_dir_);
+ loader.add_html_templates(output_dir_);
+ }
+ else
+ abort();
+ }
+ else
+ abort();
+}
+
diff --git a/scribo/sandbox/arthur/xml_transform/xml_transform.hh b/scribo/sandbox/arthur/xml_transform/xml_transform.hh
new file mode 100644
index 0000000..808c108
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/xml_transform.hh
@@ -0,0 +1,48 @@
+// Copyright (C) 2010 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 XML_TRANFORM_HH
+# define XML_TRANFORM_HH
+
+# include <QtGui>
+
+class XmlTransform : public QObject
+{
+ Q_OBJECT
+ public:
+
+ XmlTransform(QString output, QString xml_file);
+ ~XmlTransform();
+
+ void createHTML(QString img);
+ void createPDF(QString img, bool crop);
+
+protected:
+ QString output_dir_;
+ QString xml_file_;
+};
+
+#endif // !XML_TRANFORM_HH
+
diff --git a/scribo/sandbox/arthur/xml_transform/xml_transform.pro b/scribo/sandbox/arthur/xml_transform/xml_transform.pro
new file mode 100644
index 0000000..161a7f4
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/xml_transform.pro
@@ -0,0 +1,20 @@
+######################################################################
+# Automatically generated by qmake (2.01a) jeu. juil. 8 16:33:27 2010
+######################################################################
+
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+QMAKE_CXXFLAGS += -I/amd/beyrouth/home/lrde/stage/crepin/git/olena/milena -I/amd/beyrouth/home/lrde/stage/crepin/git/olena/
+QT += xml
+LIBS += `Magick++-config --libs`
+
+# Input
+HEADERS += domitem.hh dommodel.hh image_crop.hh loader.hh xml_transform.hh
+SOURCES += domitem.cc \
+ dommodel.cc \
+ image_crop.cc \
+ loader.cc \
+ main.cc \
+ xml_transform.cc
--
1.5.6.5
1
0
* scribo/sandbox/arthur/xml_transform/xml_transform.cc,
* scribo/sandbox/arthur/xml_transform/xml_transform.hh: Facade.
* scribo/sandbox/arthur/xml_transform/image_crop.cc,
* scribo/sandbox/arthur/xml_transform/image_crop.hh: Image process.
* scribo/sandbox/arthur/xml_transform/loader.cc,
* scribo/sandbox/arthur/xml_transform/loader.hh: XML loader.
* scribo/sandbox/arthur/xml_transform/main.cc
* scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
* scribo/sandbox/arthur/xml_transform/xml_transform.pro
* scribo/sandbox/arthur/xml_transform/README
* scribo/sandbox/arthur/xml_transform/common.cc,
* scribo/sandbox/arthur/xml_transform/common.hh,
* scribo/sandbox/arthur/xml_transform/moc_dommodel.cpp,
* scribo/sandbox/arthur/xml_transform/templates/html/xsl_base64.xsl,
* scribo/sandbox/arthur/xml_transform/templates/pdf/main64.xsl,
* scribo/sandbox/arthur/xml_transform/templates/pdf/regions_base64.xsl: New.
* scribo/sandbox/arthur/xml_transform/domitem.cc,
* scribo/sandbox/arthur/xml_transform/domitem.hh,
* scribo/sandbox/arthur/xml_transform/dommodel.cc,
* scribo/sandbox/arthur/xml_transform/dommodel.hh: Delete.
* scribo/sandbox/arthur/xml_transform/templates/pdf/regions.xsl: Rename as...
* scribo/sandbox/arthur/xml_transform/templates/pdf/regions_png.xsl:...this.
---
scribo/sandbox/ChangeLog | 33 +++
scribo/sandbox/arthur/xml_transform/README | 25 +-
scribo/sandbox/arthur/xml_transform/common.cc | 13 +
scribo/sandbox/arthur/xml_transform/common.hh | 16 +
scribo/sandbox/arthur/xml_transform/domitem.cc | 98 -------
scribo/sandbox/arthur/xml_transform/domitem.hh | 75 -----
scribo/sandbox/arthur/xml_transform/dommodel.cc | 198 -------------
scribo/sandbox/arthur/xml_transform/dommodel.hh | 85 ------
scribo/sandbox/arthur/xml_transform/image_crop.cc | 303 ++++++++++++++------
scribo/sandbox/arthur/xml_transform/image_crop.hh | 19 +-
scribo/sandbox/arthur/xml_transform/loader.cc | 124 +++++----
scribo/sandbox/arthur/xml_transform/loader.hh | 17 +-
scribo/sandbox/arthur/xml_transform/main.cc | 78 +++++-
.../arthur/xml_transform/templates/html/xsl.xsl | 3 +-
.../templates/html/{xsl.xsl => xsl_base64.xsl} | 9 +-
.../templates/pdf/{main.xsl => main64.xsl} | 2 +-
.../pdf/{regions.xsl => regions_base64.xsl} | 6 +-
.../templates/pdf/{regions.xsl => regions_png.xsl} | 0
.../sandbox/arthur/xml_transform/xml_transform.cc | 113 +++++---
.../sandbox/arthur/xml_transform/xml_transform.hh | 20 +-
.../sandbox/arthur/xml_transform/xml_transform.pro | 12 +-
21 files changed, 564 insertions(+), 685 deletions(-)
create mode 100644 scribo/sandbox/arthur/xml_transform/common.cc
create mode 100644 scribo/sandbox/arthur/xml_transform/common.hh
delete mode 100644 scribo/sandbox/arthur/xml_transform/domitem.cc
delete mode 100644 scribo/sandbox/arthur/xml_transform/domitem.hh
delete mode 100644 scribo/sandbox/arthur/xml_transform/dommodel.cc
delete mode 100644 scribo/sandbox/arthur/xml_transform/dommodel.hh
copy scribo/sandbox/arthur/xml_transform/templates/html/{xsl.xsl => xsl_base64.xsl} (97%)
copy scribo/sandbox/arthur/xml_transform/templates/pdf/{main.xsl => main64.xsl} (94%)
copy scribo/sandbox/arthur/xml_transform/templates/pdf/{regions.xsl => regions_base64.xsl} (91%)
rename scribo/sandbox/arthur/xml_transform/templates/pdf/{regions.xsl => regions_png.xsl} (100%)
diff --git a/scribo/sandbox/ChangeLog b/scribo/sandbox/ChangeLog
index d3f537b..0fb733f 100644
--- a/scribo/sandbox/ChangeLog
+++ b/scribo/sandbox/ChangeLog
@@ -1,3 +1,36 @@
+2010-07-15 Arthur Crepin-Leblond <crepin(a)stockholm.lrde.epita.fr>
+
+ XML Tranform.
+
+ * scribo/sandbox/arthur/xml_transform/xml_transform.cc,
+ * scribo/sandbox/arthur/xml_transform/xml_transform.hh: Facade.
+
+ * scribo/sandbox/arthur/xml_transform/image_crop.cc,
+ * scribo/sandbox/arthur/xml_transform/image_crop.hh: Image process.
+
+ * scribo/sandbox/arthur/xml_transform/loader.cc,
+ * scribo/sandbox/arthur/xml_transform/loader.hh: XML loader.
+
+ * scribo/sandbox/arthur/xml_transform/main.cc
+ * scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
+ * scribo/sandbox/arthur/xml_transform/xml_transform.pro
+ * scribo/sandbox/arthur/xml_transform/README
+
+ * scribo/sandbox/arthur/xml_transform/common.cc,
+ * scribo/sandbox/arthur/xml_transform/common.hh,
+ * scribo/sandbox/arthur/xml_transform/templates/html/xsl_base64.xsl,
+ * scribo/sandbox/arthur/xml_transform/templates/pdf/main64.xsl,
+ * scribo/sandbox/arthur/xml_transform/templates/pdf/regions_base64.xsl: New.
+
+ * scribo/sandbox/arthur/xml_transform/domitem.cc,
+ * scribo/sandbox/arthur/xml_transform/domitem.hh,
+ * scribo/sandbox/arthur/xml_transform/dommodel.cc,
+ * scribo/sandbox/arthur/xml_transform/dommodel.hh: Delete.
+
+ * scribo/sandbox/arthur/xml_transform/templates/pdf/regions.xsl: Rename as...
+ * scribo/sandbox/arthur/xml_transform/templates/pdf/regions_png.xsl:...this.
+
+
2010-07-05 Arthur Crepin-Leblond <crepin(a)stockholm.lrde.epita.fr>
ICDAR XML to HTML.
diff --git a/scribo/sandbox/arthur/xml_transform/README b/scribo/sandbox/arthur/xml_transform/README
index e0bfbc8..1f358e3 100644
--- a/scribo/sandbox/arthur/xml_transform/README
+++ b/scribo/sandbox/arthur/xml_transform/README
@@ -1,19 +1,24 @@
-xml_transform <option> <xml_file> <ppm_file> <output_dir>
-
-Transforms an ICDAR XML file to different kind of output.
+xml_transform
OPTIONS:
- --html: Produce a HTML output
-
-Once process is finished, open output.xml with your internet browser. If this one supports XSLT, there is no problem to display the result but if it does not support it (like Konqueror or Chrome in local), you should run `sh html_generator.sh` (xsltproc package required) to generate a HTML file readable by all browsers.
+HTML output:
+ --html <xml> <ppm> <out_dir> : HTML output with non-text regions croped into many png files.
+ --html-base64 <xml> <out_dir> : HTML output from a container XML file.
- --pdf: Produce a PDF output, regions will be cropped as follows in the XML file.
- --pdf-no-crop: Produce a PDF output without cropping regions, the entire picture will be displayed.
+PDF output:
+ --pdf <xml> <ppm> <out_dir> : PDF output with non-text regions croped into many png files.
+ --pdf-no-crop <xml> <ppm> <out_dir>: PDF output with the entire picture displayed over the text.
+ --pdf-base64 <xml> <out_dir> : PDF output from a container XML file.
+ --pdf-base64-no-crop <xml> <ppm> <out_dir> : PDF with the entire picture displayed over the text,
+ the picture is loaded from a container XML file.
-PDF is not directly created once the process is finished, to produce it, go to the output_dir and run `sh pdf_generator.sh` (fop >= 0.95 required).
+Base 64 operations:
+ --to-base64 <xml> <ppm> <out_xml> : Produces a container XML file by converting croped pictures into base 64 format.
+ --to-base64-no-crop <xml> <ppm> <out_xml> : Same as to-base64 but only the picture is converted in base 64.
+ --from-base64 <xml> <out_dir> : Decodes a XML container file to produce original image files.
BUILD:
-Chnage the environment variable QMAKE_CXXFLAGS to indicate the correct paths to milena and olena then, just type qmake and make.
\ No newline at end of file
+Chnage the environment variable QMAKE_CXXFLAGS to indicate the correct paths to milena and olena in the .pro file then, just type qmake and make.
\ No newline at end of file
diff --git a/scribo/sandbox/arthur/xml_transform/common.cc b/scribo/sandbox/arthur/xml_transform/common.cc
new file mode 100644
index 0000000..05117b2
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/common.cc
@@ -0,0 +1,13 @@
+# include "common.hh"
+
+QString Common::get_file_name(QString image)
+{
+ QString tmp = image.mid(image.lastIndexOf("/") + 1);
+ tmp.chop(tmp.size() - tmp.lastIndexOf("."));
+ return tmp;
+}
+
+QString Common::get_file_ext(QString image)
+{
+ return image.right(image.size() - image.lastIndexOf("."));
+}
diff --git a/scribo/sandbox/arthur/xml_transform/common.hh b/scribo/sandbox/arthur/xml_transform/common.hh
new file mode 100644
index 0000000..f72218f
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/common.hh
@@ -0,0 +1,16 @@
+#ifndef COMMON_HH
+# define COMMON_HH
+
+# include <QtGui>
+
+class Common : public QObject
+{
+ Q_OBJECT
+public:
+ Common() {}
+ ~Common() {}
+ static QString get_file_name(QString image);
+ static QString get_file_ext(QString image);
+};
+
+#endif // ! COMMON_HH
diff --git a/scribo/sandbox/arthur/xml_transform/domitem.cc b/scribo/sandbox/arthur/xml_transform/domitem.cc
deleted file mode 100644
index 66e989a..0000000
--- a/scribo/sandbox/arthur/xml_transform/domitem.cc
+++ /dev/null
@@ -1,98 +0,0 @@
-/****************************************************************************
- **
- ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
- ** Contact: Qt Software Information (qt-info(a)nokia.com)
- **
- ** This file is part of the example classes of the Qt Toolkit.
- **
- ** Commercial Usage
- ** Licensees holding valid Qt Commercial licenses may use this file in
- ** accordance with the Qt Commercial License Agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and Nokia.
- **
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License versions 2.0 or 3.0 as published by the Free
- ** Software Foundation and appearing in the file LICENSE.GPL included in
- ** the packaging of this file. Please review the following information
- ** to ensure GNU General Public Licensing requirements will be met:
- ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
- ** http://www.gnu.org/copyleft/gpl.html. In addition, as a special
- ** exception, Nokia gives you certain additional rights. These rights
- ** are described in the Nokia Qt GPL Exception version 1.3, included in
- ** the file GPL_EXCEPTION.txt in this package.
- **
- ** Qt for Windows(R) Licensees
- ** As a special exception, Nokia, as the sole copyright holder for Qt
- ** Designer, grants users of the Qt/Eclipse Integration plug-in the
- ** right for the Qt/Eclipse Integration to link to functionality
- ** provided by Qt Designer and its related libraries.
- **
- ** If you are unsure which license is appropriate for your use, please
- ** contact the sales department at qt-sales(a)nokia.com.
- **
- ****************************************************************************/
-
-//
-// Document layout viewer.
-//
-// Copyright (C) 2009 Florent D'Halluin.
-//
-// This program 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; either version 2
-// of the License, or (at your option) any later version.
-//
-// The complete GNU General Public Licence Notice can be found as the
-// `COPYING' file in the root directory.
-//
-
-#include <QtXml>
-
-#include "domitem.hh"
-
-DomItem::DomItem(QDomNode &node, int row, DomItem *parent)
-{
- domNode = node;
- // Record the item's location within its parent.
- rowNumber = row;
- parentItem = parent;
-}
-
-DomItem::~DomItem()
-{
- QHash<int,DomItem*>::iterator it;
- for (it = childItems.begin(); it != childItems.end(); ++it)
- delete it.value();
-}
-
-QDomNode DomItem::node() const
-{
- return domNode;
-}
-
-DomItem *DomItem::parent()
-{
- return parentItem;
-}
-
-DomItem *DomItem::child(int i)
-{
- if (childItems.contains(i))
- return childItems[i];
-
- if (i >= 0 && i < domNode.childNodes().count()) {
- QDomNode childNode = domNode.childNodes().item(i);
- DomItem *childItem = new DomItem(childNode, i, this);
- childItems[i] = childItem;
- return childItem;
- }
- return 0;
-}
-
-int DomItem::row()
-{
- return rowNumber;
-}
diff --git a/scribo/sandbox/arthur/xml_transform/domitem.hh b/scribo/sandbox/arthur/xml_transform/domitem.hh
deleted file mode 100644
index a5c22cc..0000000
--- a/scribo/sandbox/arthur/xml_transform/domitem.hh
+++ /dev/null
@@ -1,75 +0,0 @@
- /****************************************************************************
- **
- ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
- ** Contact: Qt Software Information (qt-info(a)nokia.com)
- **
- ** This file is part of the example classes of the Qt Toolkit.
- **
- ** Commercial Usage
- ** Licensees holding valid Qt Commercial licenses may use this file in
- ** accordance with the Qt Commercial License Agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and Nokia.
- **
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License versions 2.0 or 3.0 as published by the Free
- ** Software Foundation and appearing in the file LICENSE.GPL included in
- ** the packaging of this file. Please review the following information
- ** to ensure GNU General Public Licensing requirements will be met:
- ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
- ** http://www.gnu.org/copyleft/gpl.html. In addition, as a special
- ** exception, Nokia gives you certain additional rights. These rights
- ** are described in the Nokia Qt GPL Exception version 1.3, included in
- ** the file GPL_EXCEPTION.txt in this package.
- **
- ** Qt for Windows(R) Licensees
- ** As a special exception, Nokia, as the sole copyright holder for Qt
- ** Designer, grants users of the Qt/Eclipse Integration plug-in the
- ** right for the Qt/Eclipse Integration to link to functionality
- ** provided by Qt Designer and its related libraries.
- **
- ** If you are unsure which license is appropriate for your use, please
- ** contact the sales department at qt-sales(a)nokia.com.
- **
- ****************************************************************************/
-
-//
-// Document layout viewer.
-//
-// Copyright (C) 2009 Florent D'Halluin.
-//
-// This program 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; either version 2
-// of the License, or (at your option) any later version.
-//
-// The complete GNU General Public Licence Notice can be found as the
-// `COPYING' file in the root directory.
-//
-
-#ifndef DOMITEM_H
-#define DOMITEM_H
-
-#include <QDomNode>
-#include <QHash>
-
-class DomItem
-{
-public:
- DomItem(QDomNode &node, int row, DomItem *parent = 0);
- ~DomItem();
- DomItem *child(int i);
- DomItem *parent();
- QDomNode node() const;
- int row();
-
-private:
- QDomNode domNode;
- QHash<int,DomItem*> childItems;
- DomItem *parentItem;
- int rowNumber;
-};
-
-#endif
diff --git a/scribo/sandbox/arthur/xml_transform/dommodel.cc b/scribo/sandbox/arthur/xml_transform/dommodel.cc
deleted file mode 100644
index baaf9a7..0000000
--- a/scribo/sandbox/arthur/xml_transform/dommodel.cc
+++ /dev/null
@@ -1,198 +0,0 @@
-/****************************************************************************
- **
- ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
- ** Contact: Qt Software Information (qt-info(a)nokia.com)
- **
- ** This file is part of the example classes of the Qt Toolkit.
- **
- ** Commercial Usage
- ** Licensees holding valid Qt Commercial licenses may use this file in
- ** accordance with the Qt Commercial License Agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and Nokia.
- **
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License versions 2.0 or 3.0 as published by the Free
- ** Software Foundation and appearing in the file LICENSE.GPL included in
- ** the packaging of this file. Please review the following information
- ** to ensure GNU General Public Licensing requirements will be met:
- ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
- ** http://www.gnu.org/copyleft/gpl.html. In addition, as a special
- ** exception, Nokia gives you certain additional rights. These rights
- ** are described in the Nokia Qt GPL Exception version 1.3, included in
- ** the file GPL_EXCEPTION.txt in this package.
- **
- ** Qt for Windows(R) Licensees
- ** As a special exception, Nokia, as the sole copyright holder for Qt
- ** Designer, grants users of the Qt/Eclipse Integration plug-in the
- ** right for the Qt/Eclipse Integration to link to functionality
- ** provided by Qt Designer and its related libraries.
- **
- ** If you are unsure which license is appropriate for your use, please
- ** contact the sales department at qt-sales(a)nokia.com.
- **
- ****************************************************************************/
-
-//
-// Document layout viewer.
-//
-// Copyright (C) 2009 Florent D'Halluin.
-//
-// This program 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; either version 2
-// of the License, or (at your option) any later version.
-//
-// The complete GNU General Public Licence Notice can be found as the
-// `COPYING' file in the root directory.
-//
-
-#include <QtGui>
-#include <QtXml>
-
-#include "domitem.hh"
-#include "dommodel.hh"
-
-DomModel::DomModel(QDomDocument document, QObject *parent)
- : QAbstractItemModel(parent), domDocument(document)
-{
- rootItem = new DomItem(domDocument, 0);
-}
-
-DomModel::~DomModel()
-{
- delete rootItem;
-}
-
-int DomModel::columnCount(const QModelIndex &/*parent*/) const
-{
- return 3;
-}
-
-QVariant DomModel::data(const QModelIndex &index, int role) const
-{
- if (!index.isValid())
- return QVariant();
-
- DomItem *item = static_cast<DomItem*>(index.internalPointer());
- QDomNode node = item->node();
- QDomNamedNodeMap attributeMap = node.attributes();
-
- if (role == Qt::DisplayRole)
- {
- QStringList attributes;
-
- switch (index.column())
- {
- case 0:
- return node.nodeName();
- case 1:
- for (int i = 0; i < attributeMap.count(); ++i)
- {
- QDomNode attribute = attributeMap.item(i);
- attributes << attribute.nodeName() + "=\""
- + attribute.nodeValue() + "\"";
- }
- return attributes.join(" ");
- case 2:
- return node.nodeValue().split("\n").join(" ");
- default:
- return QVariant();
- }
- }
- else if (role == Qt::UserRole)
- {
- QMap<QString, QVariant> attributes;
- switch (index.column())
- {
- case 1:
- for (int i = 0; i < attributeMap.count(); ++i)
- {
- QDomNode attribute = attributeMap.item(i);
- attributes[attribute.nodeName()] = attribute.nodeValue();
- }
- return attributes;
- default:
- return QVariant();
- }
- }
- return QVariant();
-}
-
-Qt::ItemFlags DomModel::flags(const QModelIndex &index) const
-{
- if (!index.isValid())
- return 0;
-
- return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
-}
-
-QVariant DomModel::headerData(int section, Qt::Orientation orientation,
- int role) const
-{
- if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
- switch (section) {
- case 0:
- return tr("Name");
- case 1:
- return tr("Attributes");
- case 2:
- return tr("Value");
- default:
- return QVariant();
- }
- }
-
- return QVariant();
-}
-
-QModelIndex DomModel::index(int row, int column, const QModelIndex &parent)
- const
-{
- if (!hasIndex(row, column, parent))
- return QModelIndex();
-
- DomItem *parentItem;
-
- if (!parent.isValid())
- parentItem = rootItem;
- else
- parentItem = static_cast<DomItem*>(parent.internalPointer());
-
- DomItem *childItem = parentItem->child(row);
- if (childItem)
- return createIndex(row, column, childItem);
- else
- return QModelIndex();
-}
-
-QModelIndex DomModel::parent(const QModelIndex &child) const
-{
- if (!child.isValid())
- return QModelIndex();
-
- DomItem *childItem = static_cast<DomItem*>(child.internalPointer());
- DomItem *parentItem = childItem->parent();
-
- if (!parentItem || parentItem == rootItem)
- return QModelIndex();
-
- return createIndex(parentItem->row(), 0, parentItem);
-}
-
-int DomModel::rowCount(const QModelIndex &parent) const
-{
- if (parent.column() > 0)
- return 0;
-
- DomItem *parentItem;
-
- if (!parent.isValid())
- parentItem = rootItem;
- else
- parentItem = static_cast<DomItem*>(parent.internalPointer());
-
- return parentItem->node().childNodes().count();
-}
diff --git a/scribo/sandbox/arthur/xml_transform/dommodel.hh b/scribo/sandbox/arthur/xml_transform/dommodel.hh
deleted file mode 100644
index 16c5a23..0000000
--- a/scribo/sandbox/arthur/xml_transform/dommodel.hh
+++ /dev/null
@@ -1,85 +0,0 @@
-/****************************************************************************
- **
- ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
- ** Contact: Qt Software Information (qt-info(a)nokia.com)
- **
- ** This file is part of the example classes of the Qt Toolkit.
- **
- ** Commercial Usage
- ** Licensees holding valid Qt Commercial licenses may use this file in
- ** accordance with the Qt Commercial License Agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and Nokia.
- **
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License versions 2.0 or 3.0 as published by the Free
- ** Software Foundation and appearing in the file LICENSE.GPL included in
- ** the packaging of this file. Please review the following information
- ** to ensure GNU General Public Licensing requirements will be met:
- ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
- ** http://www.gnu.org/copyleft/gpl.html. In addition, as a special
- ** exception, Nokia gives you certain additional rights. These rights
- ** are described in the Nokia Qt GPL Exception version 1.3, included in
- ** the file GPL_EXCEPTION.txt in this package.
- **
- ** Qt for Windows(R) Licensees
- ** As a special exception, Nokia, as the sole copyright holder for Qt
- ** Designer, grants users of the Qt/Eclipse Integration plug-in the
- ** right for the Qt/Eclipse Integration to link to functionality
- ** provided by Qt Designer and its related libraries.
- **
- ** If you are unsure which license is appropriate for your use, please
- ** contact the sales department at qt-sales(a)nokia.com.
- **
- ****************************************************************************/
-
-//
-// Document layout viewer.
-//
-// Copyright (C) 2009 Florent D'Halluin.
-//
-// This program 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; either version 2
-// of the License, or (at your option) any later version.
-//
-// The complete GNU General Public Licence Notice can be found as the
-// `COPYING' file in the root directory.
-//
-
-#ifndef DOMMODEL_H
-#define DOMMODEL_H
-
-#include <QAbstractItemModel>
-#include <QDomDocument>
-#include <QModelIndex>
-#include <QVariant>
-
-class DomItem;
-
-class DomModel : public QAbstractItemModel
-{
- Q_OBJECT
-
- public:
- DomModel(QDomDocument document, QObject *parent = 0);
- ~DomModel();
-
- QVariant data(const QModelIndex &index, int role) const;
- Qt::ItemFlags flags(const QModelIndex &index) const;
- QVariant headerData(int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const;
- QModelIndex index(int row, int column,
- const QModelIndex &parent = QModelIndex()) const;
- QModelIndex parent(const QModelIndex &child) const;
- int rowCount(const QModelIndex &parent = QModelIndex()) const;
- int columnCount(const QModelIndex &parent = QModelIndex()) const;
-
-private:
- QDomDocument domDocument;
- DomItem *rootItem;
-};
-
-#endif
diff --git a/scribo/sandbox/arthur/xml_transform/image_crop.cc b/scribo/sandbox/arthur/xml_transform/image_crop.cc
index aa17c31..8aafe45 100644
--- a/scribo/sandbox/arthur/xml_transform/image_crop.cc
+++ b/scribo/sandbox/arthur/xml_transform/image_crop.cc
@@ -25,7 +25,7 @@
# include "image_crop.hh"
# include "loader.hh"
-# include "dommodel.hh"
+# include "common.hh"
# include <limits.h>
@@ -36,7 +36,10 @@
#include <mln/io/magick/save.hh>
#include <mln/io/ppm/all.hh>
-ImageCrop::ImageCrop()
+ImageCrop::ImageCrop(QString xml, QString img, QString output) :
+ xml_(xml),
+ image_(img),
+ output_dir_(output)
{
}
@@ -44,95 +47,242 @@ ImageCrop::~ImageCrop()
{
}
-void ImageCrop::save_image(QString image, QString output)
+/* Save PPM image to PNG format in output_dir/img. */
+void ImageCrop::save_image(QString file)
{
using namespace mln;
image2d<value::rgb8> ima;
- io::ppm::load(ima, image.toStdString());
+ io::ppm::load(ima, image_.toStdString());
- io::magick::save(ima, output.toStdString() + "img/image.png");
+ QString filename;
+ if (file == QString::Null())
+ filename = Common::get_file_name(image_);
+ else
+ filename = file;
+
+ std::cout << "Saving " << image_.toStdString() << " to "
+ << output_dir_.toStdString() << "img/"
+ << filename.toStdString() << ".png"
+ << std::endl;
+
+ io::magick::save(ima, output_dir_.toStdString() + "img/" + filename.toStdString() + ".png");
}
-void ImageCrop::crop_regions(QString xml_file, QString image_file, QString output)
+/* Return the image in base 64. */
+QString ImageCrop::img_to_base64()
{
- Loader loader;
+ QFile f(image_);
+ f.open(QIODevice::ReadOnly);
+
+ QByteArray file_content = f.readAll();
- QFile f(image_file);
+ f.close();
- if (!f.exists())
+ return file_content.toBase64();
+}
+
+/* Decode the base 64 string str and save into output_dir_/img/img_name. */
+bool ImageCrop::img_from_base64(QString str, QString img_name, QString mime)
+{
+ QByteArray ba;
+
+ ba = ba.append(str);
+ QByteArray out_ba = QByteArray::fromBase64(ba);
+ QImage ima = QImage::fromData(out_ba);
+
+ return ima.save(output_dir_ + "img/" + img_name + "." + mime);
+}
+
+/* Read all regions of the XML file and save all base 64 data into output_dir/img */
+void ImageCrop::from_base64()
+{
+ QFile f_in(xml_);
+ f_in.open(QIODevice::ReadOnly);
+
+ QDomDocument doc;
+ doc.setContent(&f_in);
+ f_in.close();
+
+ QDomElement root = doc.documentElement();
+ QDomNode child = root.firstChild();
+
+ while (!child.isNull() && !child.toElement().tagName().contains("page"))
+ child = child.nextSibling();
+
+ child = child.firstChild();
+ while (!child.isNull())
{
- qDebug() << "Image doesn't exist !";
- abort();
+ if (child.toElement().tagName().contains(QRegExp("(image|graphic|chart|separator|table)_region")))
+ {
+ QDomNode node = child.firstChild();
+ QString id = child.toElement().attribute("id", "none");
+
+ while (!node.isNull() && !node.toElement().tagName().contains("container"))
+ node = node.nextSibling();
+
+ if (!node.isNull())
+ {
+ QString data = node.firstChildElement("data").text();
+ QString mime = node.firstChildElement("mime").text();
+ img_from_base64(data, id, mime);
+ }
+ }
+ child = child.nextSibling();
+ }
+}
+
+/* Tranfsorm the input XML file associated with images into a single
+ XML output containing datas if images in base 64. */
+void ImageCrop::to_base64(QString out_file, bool no_crop)
+{
+ QFile file(xml_);
+ file.open(QIODevice::ReadOnly);
+ QTextStream stream(&file);
+
+ QFile file2(out_file);
+ file2.open(QIODevice::ReadWrite);
+ QTextStream stream2(&file2);
+
+ QString line = stream.readLine();
+ stream2 << line;
+ line = stream.readLine();
+
+ // HEAD
+ while (!line.contains("<page"))
+ {
+ stream2 << "\n" << line;
+ line = stream.readLine();
+ }
+
+ if (no_crop)
+ {
+ stream2 << "\n" << line;
+
+ stream2 << "\n" << " <image_region id=\"image\">";
+ stream2 << "\n" << " <container>\n";
+ stream2 << " <mime>png</mime>\n";
+
+ QString file_name = Common::get_file_name(image_);
+ save_image();
+ QFile img(output_dir_ + "img/" + file_name + ".png");
+
+ img.open(QIODevice::ReadOnly);
+ stream2 << " <data>\n";
+
+ QByteArray byte = img.readAll();
+ stream2 << byte.toBase64();
+
+ stream2 << " </data>";
+ stream2 << "\n </container>";
+ stream2 << "\n <coords>\n";
+
+ stream2 << " <point x=\"0\" y=\"0\" />\n";
+ stream2 << " <point x=\"0\" y=\"0\" />";
+
+ stream2 << "\n </coords>";
+ stream2 << "\n" << " </image_region>\n";
+ img.close();
+
+ line = stream.readLine();
+
+ while(!line.contains("</pcGts>"))
+ {
+ stream2 << "\n" << line;
+ line = stream.readLine();
+ }
+
+ stream2 << "\n" << line;
}
- DomModel* layout = loader.xml_to_dom(xml_file);
- if (layout)
+ else
{
- QModelIndex pcGts = layout->index(1, 0);
- QModelIndex page = layout->index(1, 0, pcGts);
- QModelIndex region;
- QModelIndex attributes;
- QModelIndex coords;
- QModelIndex point;
- bool regions_found = false;
-
- for (int i = 0; true; ++i)
+ while(!line.contains("</pcGts>"))
{
- region = layout->index(i, 0, page);
- attributes = layout->index(i, 1, page);
+ stream2 << "\n" << line;
+ if (line.contains(QRegExp("<(image|graphic|chart|separator|table)_region")))
+ {
+ stream2 << "\n" << " <container>\n";
+ stream2 << " <mime>png</mime>\n";
+
+ QDomDocument doc;
+ doc.setContent(line);
+
+ QDomElement root = doc.documentElement();
+ QString id = root.attribute("id", "none");
- QString name = layout->data(region, Qt::DisplayRole).toString();
- coords = layout->index(0, 0, region);
+ QFile img(output_dir_ + "img/" + id + ".png");
- bool is_region =
- name == QString("image_region")
- || name == QString("graphic_region")
- || name == QString("separator_region")
- || name == QString("chart_region")
- || name == QString("table_region") ;
+ img.open(QIODevice::ReadOnly);
+ stream2 << " <data>\n";
- if (!region.isValid() || !coords.isValid())
- break;
+ QByteArray byte = img.readAll();
+ stream2 << byte.toBase64();
+
+ stream2 << " </data>";
+ stream2 << "\n </container>";
+ img.close();
+ }
- if (is_region)
+ line = stream.readLine();
+ }
+
+ stream2 << "\n" << line;
+ }
+
+ file2.close();
+ file.close();
+}
+
+bool ImageCrop::crop_regions()
+{
+ Loader loader;
+ QFile f(xml_);
+ f.open(QIODevice::ReadOnly);
+ QDomDocument doc;
+
+ if (doc.setContent(&f))
+ {
+ bool found_regions = false;
+ f.close();
+
+ QDomElement root = doc.documentElement();
+ QDomNode page = root.firstChild();
+
+ while (!page.isNull() && !page.toElement().tagName().contains("page"))
+ page = page.nextSibling();
+
+ if (page.isNull())
+ return false;
+
+ QDomNode region = page.firstChild();
+
+ while (!region.isNull())
+ {
+ if (region.toElement().tagName().contains(QRegExp("(image|graphic|chart|separator|table)_region")))
{
- regions_found = true;
- QMap<QString, QVariant> data =
- layout->data(attributes, Qt::UserRole).toMap();
+ found_regions = true;
- QString id;
- QMap<QString, QVariant>::iterator it = data.find("id");
+ QDomNode coords = region.firstChild();
+ QString id = region.toElement().attribute("id", "none");
- if (it == data.end() || it.key() != "id")
- qDebug() << "WTF_Error : No image region.";
+ qDebug() << region.toElement().tagName();
- while (it != data.end() && it.key() == "id")
- {
- qDebug() << name;
- id = it.value().toString();
- qDebug() << it.key() + " = " + it.value().toString();
- ++it;
- }
+ while (!coords.isNull() && !coords.toElement().tagName().contains("coords"))
+ coords = coords.nextSibling();
+ if (coords.isNull())
+ break;
+
+ QDomNode point = coords.firstChild();
int x_max = 0;
int y_max = 0;
int x_min = INT_MAX;
int y_min = INT_MAX;
- // QVector<QMap<QString, QVariant> > vect;
- for (int j = 0; true; ++j)
+ while (!point.isNull())
{
- // Navigate to the coordinate list
- point = layout->index(j, 1, coords);
- if (!point.isValid())
- break;
-
- QMap<QString, QVariant> data =
- layout->data(point, Qt::UserRole).toMap();
- int x = data["x"].toInt();
- int y = data["y"].toInt();
-
- // vect << data;
+ int x = point.toElement().attribute("x", "none").toInt();
+ int y = point.toElement().attribute("y", "none").toInt();
if (x < x_min)
x_min = x;
@@ -144,41 +294,26 @@ void ImageCrop::crop_regions(QString xml_file, QString image_file, QString outpu
if (y > y_max)
y_max = y;
+ point = point.nextSibling();
}
using namespace mln;
-
box2d box = make::box2d(y_min, x_min, y_max, x_max);
image2d<value::rgb8> ima;
- io::ppm::load(ima, image_file.toStdString());
+ io::ppm::load(ima, image_.toStdString());
ima = scribo::preprocessing::crop(ima, box);
- // image2d<bool> mask = make::box2d(y_min, x_min, y_max, x_max);
- // data::fill(mask, true);
-
- /*for (int a = 1; a < vect.size(); ++a)
- {
- int x = vect[a]["x"].toInt();
- int y = vect[a]["y"].toInt();
-
- data::fill((mask | make::box2d(y, x, y, x)).rw(), false);
- }*/
-
- // io::pbm::save(mask, "output/img/mask_" + id.toStdString());
- io::magick::save(ima, output.toStdString() + "img/" + id.toStdString() + ".png");
-
+ io::magick::save(ima, output_dir_.toStdString() + "img/" + id.toStdString() + ".png");
}
+ region = region.nextSibling();
}
- if (!regions_found)
- qDebug() << "No regions found.";
-
+ return found_regions;
}
else
{
- qDebug() << "Error with XML file.";
+ f.close();
+ return false;
}
-
-
}
diff --git a/scribo/sandbox/arthur/xml_transform/image_crop.hh b/scribo/sandbox/arthur/xml_transform/image_crop.hh
index e4b0a38..9b034cc 100644
--- a/scribo/sandbox/arthur/xml_transform/image_crop.hh
+++ b/scribo/sandbox/arthur/xml_transform/image_crop.hh
@@ -26,7 +26,8 @@
#ifndef IMAGE_CROP_HH
# define IMAGE_CROP_HH
-# include <QtGui>
+#include <QDomDocument>
+# include <QtCore>
class DomModel;
@@ -35,12 +36,22 @@ class ImageCrop : public QObject
Q_OBJECT
public:
- ImageCrop();
+ ImageCrop(QString xml, QString img, QString output);
~ImageCrop();
- void save_image(QString image, QString output);
- void crop_regions(QString xml_file, QString image_file, QString output);
+ void save_image(QString file = QString::Null());
+ bool crop_regions();
+ QString img_to_base64();
+ bool img_from_base64(QString str, QString img_name, QString mime);
+ void to_base64(QString out_file, bool no_crop);
+
+ void from_base64();
+
+private:
+ QString xml_;
+ QString image_;
+ QString output_dir_;
};
#endif /* !IMAGE_CROP_HH */
diff --git a/scribo/sandbox/arthur/xml_transform/loader.cc b/scribo/sandbox/arthur/xml_transform/loader.cc
index 5623928..2b64337 100644
--- a/scribo/sandbox/arthur/xml_transform/loader.cc
+++ b/scribo/sandbox/arthur/xml_transform/loader.cc
@@ -24,8 +24,6 @@
// executable file might be covered by the GNU General Public License.
# include "loader.hh"
-# include "dommodel.hh"
-# include "xml_transform.hh"
Loader::Loader()
{
@@ -35,21 +33,21 @@ Loader::~Loader()
{
}
-DomModel* Loader::xml_to_dom(QString output)
+QDomDocument* Loader::xml_to_dom(QString xml_file)
{
- QString file_path = output;
-
- QFile file(file_path);
+ QFile file(xml_file);
if (file.open(QIODevice::ReadOnly))
{
- QDomDocument document;
- if (document.setContent(&file))
+ QDomDocument* document = new QDomDocument;
+ if (document->setContent(&file))
{
- return new DomModel(document);
+ file.close();
+ return document;
}
}
+ file.close();
return 0;
}
@@ -61,9 +59,7 @@ bool Loader::set_output(QString& output)
output.append("/");
if (!dir.exists())
- {
- return dir.mkpath(".");
- }
+ return dir.mkpath(".");
else
{
QStringList list = dir.entryList(QDir::Writable | QDir::AllDirs);
@@ -72,25 +68,38 @@ bool Loader::set_output(QString& output)
}
-void Loader::add_html_templates(QString output)
+void Loader::add_html_templates(bool base64, QString output)
{
-
QFile gen("templates/html/html_generator.sh");
gen.copy(output + "html_generator.sh");
QFile css("templates/html/css.css");
css.copy(output + "css.css");
- QFile xsl("templates/html/xsl.xsl");
- xsl.copy(output + "xsl.xsl");
-
+ if (base64)
+ {
+ QFile xsl("templates/html/xsl_base64.xsl");
+ xsl.copy(output + "xsl.xsl");
+ }
+ else
+ {
+ QFile xsl("templates/html/xsl.xsl");
+ xsl.copy(output + "xsl.xsl");
+ }
}
-void Loader::add_pdf_templates(bool crop, QString output)
+void Loader::add_pdf_templates(bool crop, bool base64, QString output)
{
-
- QFile regions("templates/pdf/regions.xsl");
- regions.copy(output + "regions.xsl");
+ if (base64)
+ {
+ QFile regions("templates/pdf/regions_base64.xsl");
+ regions.copy(output + "regions.xsl");
+ }
+ else
+ {
+ QFile regions("templates/pdf/regions_png.xsl");
+ regions.copy(output + "regions.xsl");
+ }
QFile gen("templates/pdf/pdf_generator.sh");
gen.copy(output + "pdf_generator.sh");
@@ -104,59 +113,58 @@ void Loader::add_pdf_templates(bool crop, QString output)
}
else
{
- QFile xsl("templates/pdf/main.xsl");
- xsl.copy(output + "main.xsl");
+ if (base64)
+ {
+ QFile xsl("templates/pdf/main.xsl");
+ xsl.copy(output + "main.xsl");
+ }
+ else
+ {
+ QFile xsl("templates/pdf/main64.xsl");
+ xsl.copy(output + "main.xsl");
+ }
}
}
-bool Loader::load_xml(QString xml_file, bool html, QString output)
+bool Loader::xml_output(QString xml_file, bool html, QString output)
{
QFile file(xml_file);
- if (file.exists())
- {
- file.open(QIODevice::ReadOnly);
- set_output(output);
+ file.open(QIODevice::ReadOnly);
- QFile out_file(output + "output.xml");
- out_file.open(QIODevice::ReadWrite);
+ QFile out_file(output + "output.xml");
+ out_file.open(QIODevice::ReadWrite);
- QTextStream stream_in(&file);
- QTextStream stream_out(&out_file);
+ QTextStream stream_in(&file);
+ QTextStream stream_out(&out_file);
- QString line = stream_in.readLine();
+ QString line = stream_in.readLine();
- while(!line.contains("<?xml"))
- line = stream_in.readLine();
+ while(!line.contains("<?xml"))
+ line = stream_in.readLine();
- stream_out << line;
+ stream_out << line;
- if (html)
- stream_out << "\n<?xml-stylesheet type=\"text/xsl\" href=\"xsl.xsl\" ?>";
+ if (html)
+ stream_out << "\n<?xml-stylesheet type=\"text/xsl\" href=\"xsl.xsl\" ?>";
- // /!\ attributes of ICDAR PcGts removed.
- while(!line.contains("<pcGts"))
- line = stream_in.readLine();
+ // /!\ attributes of ICDAR PcGts removed.
+ while(!line.contains("<pcGts"))
+ line = stream_in.readLine();
- line = stream_in.readLine();
- stream_out << "\n<pcGts>";
-
- while (!line.contains("</pcGts>"))
- {
- stream_out << "\n" << line;
- line = stream_in.readLine();
- }
+ line = stream_in.readLine();
+ stream_out << "\n<pcGts>";
+ while (!line.contains("</pcGts>"))
+ {
stream_out << "\n" << line;
+ line = stream_in.readLine();
+ }
- file.close();
- out_file.close();
+ stream_out << "\n" << line;
- return true;
- }
- else
- {
- qDebug() << xml_file + " doesn't exist";
- return false;
- }
+ file.close();
+ out_file.close();
+
+ return true;
}
diff --git a/scribo/sandbox/arthur/xml_transform/loader.hh b/scribo/sandbox/arthur/xml_transform/loader.hh
index 7d24254..fadceed 100644
--- a/scribo/sandbox/arthur/xml_transform/loader.hh
+++ b/scribo/sandbox/arthur/xml_transform/loader.hh
@@ -26,24 +26,23 @@
#ifndef LOADER_HH
# define LOADER_HH
-//# include <QtGui>
-# include "xml_transform.hh"
+# include <QtCore>
+#include <QDomDocument>
-class DomModel;
-
-class Loader
+class Loader : public QObject
{
+ Q_OBJECT
public:
Loader();
~Loader();
// void merge(QString in, QString other, QString output = "output.xml");
- bool load_xml(QString xml_file, bool html, QString output);
- DomModel* xml_to_dom(QString output);
+ bool xml_output(QString xml_file, bool html, QString output);
+ QDomDocument* xml_to_dom(QString xml_file);
bool set_output(QString& output);
- void add_pdf_templates(bool crop, QString output);
- void add_html_templates(QString output);
+ void add_pdf_templates(bool crop, bool base64, QString output);
+ void add_html_templates(bool base64, QString output);
};
#endif /* !LOADER_HH */
diff --git a/scribo/sandbox/arthur/xml_transform/main.cc b/scribo/sandbox/arthur/xml_transform/main.cc
index 9e18cff..e097430 100644
--- a/scribo/sandbox/arthur/xml_transform/main.cc
+++ b/scribo/sandbox/arthur/xml_transform/main.cc
@@ -1,25 +1,89 @@
#include <iostream>
+#include <QDomDocument>
#include "xml_transform.hh"
int main(int argc, char **argv)
{
- std::string man = "xml_transform <option> <xml_file> <ppm_file> <output_dir>\nOPTIONS:\n\t--html: Produce a HTML output\n\t--pdf: Produce a PDF output, regions will be croped as follows in the XML file.\n\t--pdf-no-crop: Produce a PDF output without croping regions, the entire picture will be displayed.";
+ std::string man;
+ man = "xml_transform\n";
+ man += "OPTIONS:\n\n";
+ man += "HTML output:\n";
+ man += "\t--html <xml> <ppm> <out_dir> : HTML output with non-text regions croped into many png files.\n";
+ man += "\t--html-base64 <xml> <out_dir> : HTML output from a container XML file.\n\n";
+ man += "PDF output:\n";
+ man += "\t--pdf <xml> <ppm> <out_dir> : PDF output with non-text regions croped into many png files.\n";
+ man += "\t--pdf-no-crop <xml> <ppm> <out_dir>: PDF output with the entire picture displayed over the text.\n";
+ man += "\t--pdf-base64 <xml> <out_dir> : PDF output from a container XML file.\n";
+ man += "\t--pdf-base64-no-crop <xml> <ppm> <out_dir> : PDF with the entire picture displayed over the text, the picture is loaded from a container XML file.\n\n";
+ man += "Base 64 operations:\n";
+ man += "\t--to-base64 <xml> <ppm> <out_xml> : Produces a container XML file by converting croped pictures into base 64 format.\n";
+ man += "\t--to-base64-no-crop <xml> <ppm> <out_xml> : Same as to-base64 but only the picture is converted in base 64.\n";
+ man += "\t--from-base64 <xml> <out_dir> : Decodes a XML container file to produce original image files.\n";
if (argc > 4)
{
std::string html = "--html";
std::string pdf = "--pdf";
std::string pdf_no_crop = "--pdf-no-crop";
-
- XmlTransform xmlt(argv[4], argv[2]);
+ std::string to_base64 = "--to-base64";
+ std::string to_base64nocrop = "--to-base64-no-crop";
if (html.compare(argv[1]) == 0)
- xmlt.createHTML(argv[3]);
- else if (pdf.compare(argv[1]) == 0)
- xmlt.createPDF(argv[3], true);
+ {
+ XmlTransform xmlt(argv[2], argv[3], argv[4]);
+ xmlt.createHTML(false);
+ }
+ if (pdf.compare(argv[1]) == 0)
+ {
+ XmlTransform xmlt(argv[2], argv[3], argv[4]);
+ xmlt.createPDF(true, false);
+ }
else if (pdf_no_crop.compare(argv[1]) == 0)
- xmlt.createPDF(argv[3], false);
+ {
+ XmlTransform xmlt(argv[2], argv[3], argv[4]);
+ xmlt.createPDF(false, false);
+ }
+ else if (to_base64.compare(argv[1]) == 0)
+ {
+ XmlTransform xmlt(argv[2], argv[3], QString::Null(), argv[4]);
+ xmlt.toBase64(false);
+ }
+ else if (to_base64nocrop.compare(argv[1]) == 0)
+ {
+ XmlTransform xmlt(argv[2], argv[3], QString::Null(), argv[4]);
+ xmlt.toBase64(true);
+ }
+ else
+ std::cout << man << std::endl;
+ }
+ else if (argc > 3)
+ {
+ std::string pdfbase64 = "--pdf-base64";
+ std::string pdfbase64nocrop = "--pdf-base64-no-crop";
+ std::string htmlbase64 = "--html-base64";
+ std::string from_base64 = "--from-base64";
+
+ if (pdfbase64.compare(argv[1]) == 0)
+ {
+ XmlTransform xmlt(argv[2], QString::Null(), argv[3]);
+ xmlt.createPDF(true, true);
+ }
+ else if (pdfbase64nocrop.compare(argv[1]) == 0)
+ {
+ XmlTransform xmlt(argv[2], QString::Null(), argv[3]);
+ xmlt.createPDF(false, true);
+ }
+ else if (htmlbase64.compare(argv[1]) == 0)
+ {
+ XmlTransform xmlt(argv[2], QString::Null(), argv[3]);
+ xmlt.createHTML(true);
+ }
+ else if (from_base64.compare(argv[1]) == 0)
+ {
+ XmlTransform xmlt(argv[2], QString::Null(), argv[3]);
+ xmlt.fromBase64();
+ }
else
std::cout << man << std::endl;
}
diff --git a/scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl b/scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
index 3d6a1c5..1f29044 100644
--- a/scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
+++ b/scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
@@ -209,8 +209,7 @@
<xsl:attribute name="height">
<xsl:value-of select="$y2 - $y1" />
</xsl:attribute>
- <xsl:attribute name="src">
- img/<xsl:value-of select="$id"/>.png</xsl:attribute>
+ <xsl:attribute name="src">img/<xsl:value-of select="$id"/>.png</xsl:attribute>
</img>
</div>
diff --git a/scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl b/scribo/sandbox/arthur/xml_transform/templates/html/xsl_base64.xsl
similarity index 97%
copy from scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
copy to scribo/sandbox/arthur/xml_transform/templates/html/xsl_base64.xsl
index 3d6a1c5..1c25e42 100644
--- a/scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
+++ b/scribo/sandbox/arthur/xml_transform/templates/html/xsl_base64.xsl
@@ -174,9 +174,9 @@
<!-- NON-TEXT REGIONS -->
<xsl:if test="name() = 'image_region' or name() = 'separator_region' or name() = 'graphic_region' or name() = 'chart_region' or name() = 'table_region'">
- <!-- id -->
- <xsl:variable name="id">
- <xsl:value-of select="@id" />
+ <!-- data -->
+ <xsl:variable name="data">
+ <xsl:value-of select="container/data" />
</xsl:variable>
<!-- depth -->
@@ -210,7 +210,8 @@
<xsl:value-of select="$y2 - $y1" />
</xsl:attribute>
<xsl:attribute name="src">
- img/<xsl:value-of select="$id"/>.png</xsl:attribute>
+ data:image/png;base64,<xsl:value-of select="$data"/>
+ </xsl:attribute>
</img>
</div>
diff --git a/scribo/sandbox/arthur/xml_transform/templates/pdf/main.xsl b/scribo/sandbox/arthur/xml_transform/templates/pdf/main64.xsl
similarity index 94%
copy from scribo/sandbox/arthur/xml_transform/templates/pdf/main.xsl
copy to scribo/sandbox/arthur/xml_transform/templates/pdf/main64.xsl
index 065831e..ecc7443 100644
--- a/scribo/sandbox/arthur/xml_transform/templates/pdf/main.xsl
+++ b/scribo/sandbox/arthur/xml_transform/templates/pdf/main64.xsl
@@ -46,7 +46,7 @@
<fo:block>
<fo:external-graphic>
<xsl:attribute name="src">
- url('img/image.png')
+ data:image/png;base64,<xsl:value-of select="pcGts/page/image_region/container/data" />
</xsl:attribute>
</fo:external-graphic>
</fo:block>
diff --git a/scribo/sandbox/arthur/xml_transform/templates/pdf/regions.xsl b/scribo/sandbox/arthur/xml_transform/templates/pdf/regions_base64.xsl
similarity index 91%
copy from scribo/sandbox/arthur/xml_transform/templates/pdf/regions.xsl
copy to scribo/sandbox/arthur/xml_transform/templates/pdf/regions_base64.xsl
index 65a8c79..add0cba 100644
--- a/scribo/sandbox/arthur/xml_transform/templates/pdf/regions.xsl
+++ b/scribo/sandbox/arthur/xml_transform/templates/pdf/regions_base64.xsl
@@ -11,8 +11,8 @@
pcGts/page/separator_region">
<!-- ID of the region, used to display id.png -->
- <xsl:variable name="id">
- <xsl:value-of select="@id" />
+ <xsl:variable name="data">
+ <xsl:value-of select="container/data" />
</xsl:variable>
<!-- Regions coordinates -->
@@ -47,7 +47,7 @@
<fo:block>
<fo:external-graphic>
<xsl:attribute name="src">
- url('img/<xsl:value-of select="$id" />.png')
+ url('data:image/png;base64,<xsl:value-of select="$data" />')
</xsl:attribute>
</fo:external-graphic>
</fo:block>
diff --git a/scribo/sandbox/arthur/xml_transform/templates/pdf/regions.xsl b/scribo/sandbox/arthur/xml_transform/templates/pdf/regions_png.xsl
similarity index 100%
rename from scribo/sandbox/arthur/xml_transform/templates/pdf/regions.xsl
rename to scribo/sandbox/arthur/xml_transform/templates/pdf/regions_png.xsl
diff --git a/scribo/sandbox/arthur/xml_transform/xml_transform.cc b/scribo/sandbox/arthur/xml_transform/xml_transform.cc
index dd35aff..ebfbed8 100644
--- a/scribo/sandbox/arthur/xml_transform/xml_transform.cc
+++ b/scribo/sandbox/arthur/xml_transform/xml_transform.cc
@@ -23,69 +23,114 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
+# include "xml_transform.hh"
# include "image_crop.hh"
# include "loader.hh"
-# include "xml_transform.hh"
+# include "common.hh"
+# include <iostream>
-XmlTransform::XmlTransform(QString output, QString xml_file) :
- output_dir_(output),
- xml_file_(xml_file)
+XmlTransform::XmlTransform(QString xml_file, QString image_file, QString output, QString file) :
+ xml_file_(xml_file),
+ image_(image_file),
+ loader_(new Loader()),
+ file_(file)
{
- Loader loader;
- if (!loader.set_output(output_dir_))
- abort();
+ QFile fi(image_);
+ QFile fx(xml_file_);
+
+ if (file_ != QString::Null())
+ output_dir_ = "/tmp/xml_transform";
+ else
+ output_dir_ = output;
+
+ if (output_dir_ != QString::Null() && !loader_->set_output(output_dir_))
+ {
+ std::cout << "Cant't create " << output_dir_.toStdString() << "dir! Aborting..." << std::endl;
+ abort();
+ }
+ else if (!fi.exists() && image_ != QString::Null())
+ {
+ std::cout << "Image file does not exist ! Aborting..." << std::endl;
+ abort();
+ }
+ else if (!fx.exists())
+ {
+ std::cout << "XML file does not exist ! Aborting..." << std::endl;
+ abort();
+ }
+
+ crop_ = new ImageCrop(xml_file_, image_, output_dir_);
}
XmlTransform::~XmlTransform()
{
}
-void XmlTransform::createPDF (QString img, bool crop)
+void XmlTransform::fromBase64()
{
- Loader loader;
+ QString output = output_dir_;
+ output.append("img");
+
+ if (loader_->set_output(output))
+ crop_->from_base64();
+ else
+ abort();
+}
+void XmlTransform::toBase64(bool crop)
+{
QString output = output_dir_;
output.append("img");
- if (loader.set_output(output))
+ if (loader_->set_output(output))
{
- if (loader.load_xml(xml_file_, false, output_dir_))
- {
+ if (!crop)
+ crop_->crop_regions();
- ImageCrop Crop;
+ crop_->to_base64(file_, crop);
+ }
+ else
+ abort();
+}
- if (crop)
- Crop.crop_regions(xml_file_, img, output_dir_);
- else
- Crop.save_image(img, output_dir_);
+void XmlTransform::createPDF (bool crop, bool base64)
+{
+ if (loader_->xml_output(xml_file_, false, output_dir_))
+ {
+ if (!base64)
+ {
+ QString output = output_dir_;
+ output.append("img");
- loader.add_pdf_templates(crop, output_dir_);
+ if (loader_->set_output(output))
+ {
+ if (crop)
+ crop_->crop_regions();
+ else
+ crop_->save_image("image");
+ }
}
- else
- abort();
+
+ loader_->add_pdf_templates(crop, base64, output_dir_);
}
else
abort();
}
-void XmlTransform::createHTML(QString img)
+void XmlTransform::createHTML(bool base64)
{
- Loader loader;
-
- QString output = output_dir_;
- output.append("img");
-
- if (loader.set_output(output))
+ if (loader_->xml_output(xml_file_, true, output_dir_))
{
- if (loader.load_xml(xml_file_, true, output_dir_))
+ if (!base64)
{
- ImageCrop Crop;
-
- Crop.crop_regions(xml_file_, img, output_dir_);
- loader.add_html_templates(output_dir_);
+ QString output = output_dir_;
+ output.append("img");
+ if (loader_->set_output(output))
+ crop_->crop_regions();
+ else
+ abort();
}
- else
- abort();
+ loader_->add_html_templates(base64, output_dir_);
}
else
abort();
diff --git a/scribo/sandbox/arthur/xml_transform/xml_transform.hh b/scribo/sandbox/arthur/xml_transform/xml_transform.hh
index 808c108..172bddb 100644
--- a/scribo/sandbox/arthur/xml_transform/xml_transform.hh
+++ b/scribo/sandbox/arthur/xml_transform/xml_transform.hh
@@ -26,22 +26,32 @@
#ifndef XML_TRANFORM_HH
# define XML_TRANFORM_HH
-# include <QtGui>
+# include <QtCore>
+
+
+class Loader;
+class ImageCrop;
class XmlTransform : public QObject
{
Q_OBJECT
public:
- XmlTransform(QString output, QString xml_file);
+ XmlTransform(QString xml_file, QString image_file, QString output, QString file = QString::Null());
~XmlTransform();
- void createHTML(QString img);
- void createPDF(QString img, bool crop);
+ void createHTML(bool base64);
+ void createPDF(bool crop, bool base64);
+ void toBase64(bool crop);
+ void fromBase64();
-protected:
+private:
QString output_dir_;
QString xml_file_;
+ QString image_;
+ Loader* loader_;
+ ImageCrop* crop_;
+ QString file_;
};
#endif // !XML_TRANFORM_HH
diff --git a/scribo/sandbox/arthur/xml_transform/xml_transform.pro b/scribo/sandbox/arthur/xml_transform/xml_transform.pro
index 161a7f4..c038cf6 100644
--- a/scribo/sandbox/arthur/xml_transform/xml_transform.pro
+++ b/scribo/sandbox/arthur/xml_transform/xml_transform.pro
@@ -1,5 +1,5 @@
######################################################################
-# Automatically generated by qmake (2.01a) jeu. juil. 8 16:33:27 2010
+# Automatically generated by qmake (2.01a) jeu. juil. 15 13:47:38 2010
######################################################################
TEMPLATE = app
@@ -10,11 +10,7 @@ QMAKE_CXXFLAGS += -I/amd/beyrouth/home/lrde/stage/crepin/git/olena/milena -I/amd
QT += xml
LIBS += `Magick++-config --libs`
+
# Input
-HEADERS += domitem.hh dommodel.hh image_crop.hh loader.hh xml_transform.hh
-SOURCES += domitem.cc \
- dommodel.cc \
- image_crop.cc \
- loader.cc \
- main.cc \
- xml_transform.cc
+HEADERS += common.hh image_crop.hh loader.hh xml_transform.hh
+SOURCES += common.cc image_crop.cc loader.cc main.cc xml_transform.cc
--
1.5.6.5
1
0
* scribo/ChangeLog: Move 2010-07-08 entry in...
* scribo/sandbox/ChangeLog:...this.
---
scribo/ChangeLog | 44 +++----------------------
scribo/sandbox/ChangeLog | 80 ++++++++++++++++++++++++++++++++++------------
2 files changed, 65 insertions(+), 59 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index e58af8d..fb8a48b 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,41 +1,9 @@
-2010-07-08 Arthur Crepin-Leblond <crepin(a)ptaouchnok.lrde.epita.fr>
-
- XML transform program.
-
- * sandbox/arthur/xml_to_html/xml_to_html.hh,
- * sandbox/arthur/xml_to_html/xml_to_html.cc,
- * sandbox/arthur/xml_to_html/xml_to_html.pro: Remove.
-
- * sandbox/arthur/xml_to_html/README,
- * sandbox/arthur/xml_to_html/main.cc,
- * sandbox/arthur/xml_to_html/domitem.cc,
- * sandbox/arthur/xml_to_html/domitem.hh,
- * sandbox/arthur/xml_to_html/dommodel.cc,
- * sandbox/arthur/xml_to_html/dommodel.hh: Move to...
-
- * sandbox/arthur/xml_transform/README,
- * sandbox/arthur/xml_transform/main.cc,
- * sandbox/arthur/xml_transform/domitem.cc,
- * sandbox/arthur/xml_transform/domitem.hh,
- * sandbox/arthur/xml_transform/dommodel.cc,
- * sandbox/arthur/xml_transform/dommodel.hh: ...this.
-
- * sandbox/arthur/xml_to_html/patterns/css.css,
- * sandbox/arthur/xml_to_html/patterns/xsl.xsl: Move to...
-
- * sandbox/arthur/xml_transform/templates/html/css.css,
- * sandbox/arthur/xml_transform/templates/html/xsl.xsl: ...this.
-
- * sandbox/arthur/xml_transform/image_crop.cc,
- * sandbox/arthur/xml_transform/loader.cc: New.
-
- * sandbox/arthur/xml_transform/templates/html/html_generator.sh,
- * sandbox/arthur/xml_transform/templates/pdf/line.xsl,
- * sandbox/arthur/xml_transform/templates/pdf/main.xsl,
- * sandbox/arthur/xml_transform/templates/pdf/main_crop.xsl,
- * sandbox/arthur/xml_transform/templates/pdf/pdf_generator.sh,
- * sandbox/arthur/xml_transform/templates/pdf/regions.xsl,
- * sandbox/arthur/xml_transform/xml_transform.pro: New.
+2010-07-16 Arthur Crepin-Leblond <crepin(a)ptaouchnok.lrde.epita.fr>
+
+ ChangeLog mistake.
+
+ * scribo/ChangeLog: Move 2010-07-08 entry in...
+ * scribo/sandbox/ChangeLog:...this.
2010-06-30 Arthur Crepin-Leblond <crepin(a)stockholm.lrde.epita.fr>
diff --git a/scribo/sandbox/ChangeLog b/scribo/sandbox/ChangeLog
index 0fb733f..8d7b3e9 100644
--- a/scribo/sandbox/ChangeLog
+++ b/scribo/sandbox/ChangeLog
@@ -2,34 +2,72 @@
XML Tranform.
- * scribo/sandbox/arthur/xml_transform/xml_transform.cc,
- * scribo/sandbox/arthur/xml_transform/xml_transform.hh: Facade.
+ * arthur/xml_transform/xml_transform.cc,
+ * arthur/xml_transform/xml_transform.hh: Facade.
- * scribo/sandbox/arthur/xml_transform/image_crop.cc,
- * scribo/sandbox/arthur/xml_transform/image_crop.hh: Image process.
+ * arthur/xml_transform/image_crop.cc,
+ * arthur/xml_transform/image_crop.hh: Image process.
- * scribo/sandbox/arthur/xml_transform/loader.cc,
- * scribo/sandbox/arthur/xml_transform/loader.hh: XML loader.
+ * arthur/xml_transform/loader.cc,
+ * arthur/xml_transform/loader.hh: XML loader.
- * scribo/sandbox/arthur/xml_transform/main.cc
- * scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
- * scribo/sandbox/arthur/xml_transform/xml_transform.pro
- * scribo/sandbox/arthur/xml_transform/README
+ * arthur/xml_transform/main.cc
+ * arthur/xml_transform/templates/html/xsl.xsl
+ * arthur/xml_transform/xml_transform.pro
+ * arthur/xml_transform/README
- * scribo/sandbox/arthur/xml_transform/common.cc,
- * scribo/sandbox/arthur/xml_transform/common.hh,
- * scribo/sandbox/arthur/xml_transform/templates/html/xsl_base64.xsl,
- * scribo/sandbox/arthur/xml_transform/templates/pdf/main64.xsl,
- * scribo/sandbox/arthur/xml_transform/templates/pdf/regions_base64.xsl: New.
+ * arthur/xml_transform/common.cc,
+ * arthur/xml_transform/common.hh,
+ * arthur/xml_transform/templates/html/xsl_base64.xsl,
+ * arthur/xml_transform/templates/pdf/main64.xsl,
+ * arthur/xml_transform/templates/pdf/regions_base64.xsl: New.
- * scribo/sandbox/arthur/xml_transform/domitem.cc,
- * scribo/sandbox/arthur/xml_transform/domitem.hh,
- * scribo/sandbox/arthur/xml_transform/dommodel.cc,
- * scribo/sandbox/arthur/xml_transform/dommodel.hh: Delete.
+ * arthur/xml_transform/domitem.cc,
+ * arthur/xml_transform/domitem.hh,
+ * arthur/xml_transform/dommodel.cc,
+ * arthur/xml_transform/dommodel.hh: Delete.
- * scribo/sandbox/arthur/xml_transform/templates/pdf/regions.xsl: Rename as...
- * scribo/sandbox/arthur/xml_transform/templates/pdf/regions_png.xsl:...this.
+ * arthur/xml_transform/templates/pdf/regions.xsl: Rename as...
+ * arthur/xml_transform/templates/pdf/regions_png.xsl:...this.
+2010-07-08 Arthur Crepin-Leblond <crepin(a)ptaouchnok.lrde.epita.fr>
+
+ XML transform program.
+
+ * arthur/xml_to_html/xml_to_html.hh,
+ * arthur/xml_to_html/xml_to_html.cc,
+ * arthur/xml_to_html/xml_to_html.pro: Remove.
+
+ * arthur/xml_to_html/README,
+ * arthur/xml_to_html/main.cc,
+ * arthur/xml_to_html/domitem.cc,
+ * arthur/xml_to_html/domitem.hh,
+ * arthur/xml_to_html/dommodel.cc,
+ * arthur/xml_to_html/dommodel.hh: Move to...
+
+ * arthur/xml_transform/README,
+ * arthur/xml_transform/main.cc,
+ * arthur/xml_transform/domitem.cc,
+ * arthur/xml_transform/domitem.hh,
+ * arthur/xml_transform/dommodel.cc,
+ * arthur/xml_transform/dommodel.hh: ...this.
+
+ * arthur/xml_to_html/patterns/css.css,
+ * arthur/xml_to_html/patterns/xsl.xsl: Move to...
+
+ * arthur/xml_transform/templates/html/css.css,
+ * arthur/xml_transform/templates/html/xsl.xsl: ...this.
+
+ * arthur/xml_transform/image_crop.cc,
+ * arthur/xml_transform/loader.cc: New.
+
+ * arthur/xml_transform/templates/html/html_generator.sh,
+ * arthur/xml_transform/templates/pdf/line.xsl,
+ * arthur/xml_transform/templates/pdf/main.xsl,
+ * arthur/xml_transform/templates/pdf/main_crop.xsl,
+ * arthur/xml_transform/templates/pdf/pdf_generator.sh,
+ * arthur/xml_transform/templates/pdf/regions.xsl,
+ * arthur/xml_transform/xml_transform.pro: New.
2010-07-05 Arthur Crepin-Leblond <crepin(a)stockholm.lrde.epita.fr>
--
1.5.6.5
1
0
16 Nov '10
* demo/viewer/browser_widget.cc,
* demo/viewer/browser_widget.hh: Add arrows to change image and keep
XML step.
* demo/viewer/key_widget.cc,
* demo/viewer/key_widget.hh: Change ListWidget to TreeWidget, Items can be
disabled/enabled in groups.
* demo/viewer/step_widget.cc,
* demo/viewer/step_widget.hh: Small changes to keep the step when next/prev.
picture is chosen.
* demo/viewer/viewer.cc,
* demo/viewer/xml_widget.cc: Layout adjustement.
---
scribo/ChangeLog | 20 ++++++
scribo/demo/viewer/browser_widget.cc | 56 +++++++++++++++--
scribo/demo/viewer/browser_widget.hh | 8 ++-
scribo/demo/viewer/key_widget.cc | 113 +++++++++++++++++++++++----------
scribo/demo/viewer/key_widget.hh | 12 +++-
scribo/demo/viewer/step_widget.cc | 38 +++++++++---
scribo/demo/viewer/step_widget.hh | 4 +-
scribo/demo/viewer/viewer.cc | 24 +++++---
scribo/demo/viewer/xml_widget.cc | 3 +-
9 files changed, 213 insertions(+), 65 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index fb8a48b..f2b8e4a 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,25 @@
2010-07-16 Arthur Crepin-Leblond <crepin(a)ptaouchnok.lrde.epita.fr>
+ Two new features in Qt interface.
+
+ * demo/viewer/browser_widget.cc,
+ * demo/viewer/browser_widget.hh: Add arrows to change image and keep
+ XML step.
+
+ * demo/viewer/key_widget.cc,
+ * demo/viewer/key_widget.hh: Change ListWidget to TreeWidget, Items can be
+ disabled/enabled in groups.
+
+ * demo/viewer/step_widget.cc,
+ * demo/viewer/step_widget.hh: Small changes to keep the step when next/prev.
+ picture is chosen.
+
+ * demo/viewer/viewer.cc,
+ * demo/viewer/xml_widget.cc: Layout adjustement.
+
+
+2010-07-16 Arthur Crepin-Leblond <crepin(a)ptaouchnok.lrde.epita.fr>
+
ChangeLog mistake.
* scribo/ChangeLog: Move 2010-07-08 entry in...
diff --git a/scribo/demo/viewer/browser_widget.cc b/scribo/demo/viewer/browser_widget.cc
index d69fea0..bd70648 100644
--- a/scribo/demo/viewer/browser_widget.cc
+++ b/scribo/demo/viewer/browser_widget.cc
@@ -17,16 +17,28 @@
BrowserWidget::BrowserWidget(QDirModel* files, QString dir)
: files_(files),
view_(new QListView()),
- path_(new QLineEdit(""))
+ path_(new QLineEdit("")),
+ first_time_(true)
{
+ QToolButton* next= new QToolButton();
+ QToolButton* prev= new QToolButton();
+ next->setArrowType(Qt::RightArrow);
+ prev->setArrowType(Qt::LeftArrow);
+
QLabel* title = new QLabel(tr("Images"));
title->setAlignment(Qt::AlignHCenter);
QVBoxLayout* layout = new QVBoxLayout;
- layout->addWidget(title);
+ QHBoxLayout *hlayout = new QHBoxLayout;
+
+ hlayout->addWidget(prev);
+ hlayout->addWidget(title);
+ hlayout->addWidget(next);
+ layout->addLayout(hlayout);
layout->addWidget(path_);
layout->addWidget(view_);
+ //setLayout(hlayout);
setLayout(layout);
view_->setModel(files);
@@ -34,19 +46,28 @@ BrowserWidget::BrowserWidget(QDirModel* files, QString dir)
| QDir::Readable | QDir::Drives);
view_->setRootIndex(files->index(QDir::currentPath()));
+
QDir d(dir);
if (d.isReadable())
view_->setRootIndex(files->index(d.absolutePath()));
+
view_->setRowHidden(0, true);
+
path_->setText(files->filePath(view_->rootIndex()));
+
connect(view_, SIGNAL(activated(const QModelIndex&)),
this, SLOT(activate(const QModelIndex&)));
+ connect(next, SIGNAL(released ()),
+ this, SLOT(next()));
+ connect(prev, SIGNAL(released ()),
+ this, SLOT(prev()));
connect(path_, SIGNAL(returnPressed()),
this, SLOT(path_return_pressed()));
QStringList files_filters;
files_filters << "*.png" << "*.jpg"
- << "*.tif" << "*.ppm" << "*.pgm" << "*.pbm";
+ << "*.tif" << "*.ppm" << "*.pgm" << "*.pbm" << "pnm";
+
files->setNameFilters(files_filters);
}
@@ -57,20 +78,43 @@ BrowserWidget::path_return_pressed()
QDir d(path);
if (d.isReadable())
- activate(files_->index(QString(path)));
+ activate(files_->index(QString(path)), false);
}
void
-BrowserWidget::activate(const QModelIndex& index)
+BrowserWidget::activate(const QModelIndex& index, bool b)
{
if (files_->isDir(index))
{
view_->setRootIndex(index);
view_->setRowHidden(0, true);
path_->setText(files_->filePath(view_->rootIndex()));
+ first_time_ = true;
return;
}
- emit activated(files_->filePath(index));
+
+ first_time_ = false;
+
+ emit activated(files_->filePath(index), b);
+}
+
+void
+BrowserWidget::change_pos(bool next)
+{
+ QModelIndex index = view_->currentIndex();
+
+ if(next)
+ index = files_->index(index.row() + 1, index.column(), index.parent());
+ else
+ index = files_->index(index.row() - 1, index.column(), index.parent());
+
+ if (index.isValid())
+ {
+ if (!files_->isDir(index))
+ if (!first_time_)
+ activate(index, true);
+ view_->setCurrentIndex(index);
+ }
}
BrowserWidget::~BrowserWidget()
diff --git a/scribo/demo/viewer/browser_widget.hh b/scribo/demo/viewer/browser_widget.hh
index 23930cd..a0fbe43 100644
--- a/scribo/demo/viewer/browser_widget.hh
+++ b/scribo/demo/viewer/browser_widget.hh
@@ -27,16 +27,20 @@ public:
~BrowserWidget();
public slots:
- void activate(const QModelIndex& index);
+ void activate(const QModelIndex& index, bool b = false);
void path_return_pressed();
+ void next() { change_pos(true); }
+ void prev() { change_pos(false); }
signals:
- void activated(QString filename);
+ void activated(QString filename, bool b);
private:
+ void change_pos(bool next);
QDirModel* files_;
QListView* view_;
QLineEdit* path_;
+ bool first_time_;
};
#endif /* !BROWSER_WIDGET_HH_ */
diff --git a/scribo/demo/viewer/key_widget.cc b/scribo/demo/viewer/key_widget.cc
index 5e371ab..47203c3 100644
--- a/scribo/demo/viewer/key_widget.cc
+++ b/scribo/demo/viewer/key_widget.cc
@@ -16,82 +16,127 @@
#include "common.hh"
KeyWidget::KeyWidget(const region::KeyMap& key_map)
- : items_(new QListWidget())
+ : items_(new QTreeWidget()),
+ text_(new QTreeWidgetItem(QStringList("Text"))),
+ regions_(new QTreeWidgetItem(QStringList("Regions")))
{
QLabel* title = new QLabel(tr("Key"));
title->setAlignment(Qt::AlignHCenter);
+ items_->addTopLevelItem(text_);
+ items_->addTopLevelItem(regions_);
+ items_->setHeaderHidden(true);
+
+ text_->setCheckState(0, Qt::Checked);
+ regions_->setCheckState(0, Qt::Checked);
+ regions_->setExpanded(true);
+ text_->setExpanded(true);
+
+ for (int i = 0; i < 3; ++i)
+ add_item_(key_map.at(i).first, key_map.at(i).second,
+ i == region::Line ||
+ i == region::Paragraph, text_);
+
+ for (int i = 3; i < key_map.size(); ++i)
+ add_item_(key_map.at(i).first, key_map.at(i).second, false, regions_);
+
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(title);
layout->addWidget(items_);
- for (int i = 0; i < key_map.size(); ++i)
- add_item_(key_map[i].first, key_map[i].second,
- (i == region::Paragraph) ||
- (i == region::Line) );
-
setLayout(layout);
- connect(items_, SIGNAL(itemChanged(QListWidgetItem*)),
- this, SLOT(update(QListWidgetItem*)));
+ connect(items_, SIGNAL(itemChanged(QTreeWidgetItem*, int)),
+ this, SLOT(update(QTreeWidgetItem*)));
+}
+
+void KeyWidget::update_all()
+{
+ for (int i = 0; i < text_->childCount(); ++i)
+ update(text_->child(i));
+
+ for (int i = 0; i < regions_->childCount(); ++i)
+ update(regions_->child(i));
}
-void KeyWidget::checkAll()
+void KeyWidget::setAllCheck(QTreeWidgetItem* parent)
{
- for (int i = 0; i < items_->count(); ++i)
+ for (int i = 0; i < parent->childCount(); ++i)
{
- items_->item(i)->setCheckState(Qt::Checked);
- emit updated(i, true);
+ if (parent->checkState(0) == Qt::Checked)
+ parent->child(i)->setCheckState(0, Qt::Checked);
+ else
+ parent->child(i)->setCheckState(0, Qt::Unchecked);
+ update(parent->child(i));
}
}
-void
+void
KeyWidget::change_mode(bool b)
{
int id_region = region::Paragraph;
int id_line = region::Line;
+
if (b)
{
- items_->item(id_region)->setCheckState(Qt::Checked);
- items_->item(id_region)->setHidden(false);
- items_->item(id_line)->setCheckState(Qt::Checked);
- items_->item(id_line)->setHidden(false);
+ text_->child(id_region)->setCheckState(0, Qt::Checked);
+ text_->child(id_region)->setHidden(false);
+ text_->child(id_line)->setCheckState(0, Qt::Checked);
+ text_->child(id_line)->setHidden(false);
}
else
{
- items_->item(id_region)->setCheckState(Qt::Unchecked);
- items_->item(id_region)->setHidden(true);
- items_->item(id_line)->setCheckState(Qt::Unchecked);
- items_->item(id_line)->setHidden(true);
+ text_->child(id_region)->setCheckState(0, Qt::Unchecked);
+ text_->child(id_region)->setHidden(true);
+ text_->child(id_line)->setCheckState(0, Qt::Unchecked);
+ text_->child(id_line)->setHidden(true);
}
}
void
-KeyWidget::add_item_(QString text, QColor color, bool b)
+KeyWidget::add_item_(QString text, QColor color, bool b, QTreeWidgetItem* parent)
{
- QListWidgetItem* item = new QListWidgetItem(text);
+ QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(text));
QPixmap pixmap(10, 6);
+
pixmap.fill(color);
- item->setIcon(QIcon(pixmap));
- item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
- item->setCheckState(Qt::Checked);
- items_->addItem(item);
- int id = items_->row(item);
- items_->item(id)->setHidden(b);
+ item->setIcon(0, QIcon(pixmap));
+ item->setCheckState(0, Qt::Checked);
+ parent->addChild(item);
+ item->setHidden(b);
}
-bool
+ bool
KeyWidget::isChecked(region::RegionId id)
{
- return items_->item(id)->checkState() == Qt::Checked;
+ QTreeWidgetItem* item = text_->child(id);
+ if (item)
+ return item->checkState(0) == Qt::Checked;
+ else
+ {
+ item = regions_->child(id);
+ if(item)
+ return item->checkState(0) == Qt::Checked;
+ else
+ return false;
+ }
}
void
-KeyWidget::update(QListWidgetItem* item)
+KeyWidget::update(QTreeWidgetItem* item)
{
- int id = items_->row(item);
+ int id;
+ id = text_->indexOfChild(item);
+ if (id == -1)
+ id = regions_->indexOfChild(item) + 3;
+
+ emit updated(id, item->checkState(0) == Qt::Checked);
- emit updated(id, item->checkState() == Qt::Checked);
+ if (item == text_ || item == regions_)
+ {
+ setAllCheck(item);
+ return;
+ }
}
KeyWidget::~KeyWidget()
diff --git a/scribo/demo/viewer/key_widget.hh b/scribo/demo/viewer/key_widget.hh
index 71200c8..d7767b0 100644
--- a/scribo/demo/viewer/key_widget.hh
+++ b/scribo/demo/viewer/key_widget.hh
@@ -27,20 +27,24 @@ public:
KeyWidget(const region::KeyMap& key_map);
~KeyWidget();
- void checkAll();
bool isChecked(region::RegionId id);
+ QTreeWidget* items() { return items_; };
+ void update_all();
signals:
void updated(int key, bool checked);
private slots:
- void update(QListWidgetItem* slot);
void change_mode(bool b);
+ void update(QTreeWidgetItem* item);
+ void setAllCheck(QTreeWidgetItem* parent);
private:
- void add_item_(QString text, QColor color, bool b);
+ void add_item_(QString text, QColor color, bool b, QTreeWidgetItem* parent);
- QListWidget* items_;
+ QTreeWidget* items_;
+ QTreeWidgetItem* text_;
+ QTreeWidgetItem* regions_;
};
#endif /* !KEY_WIDGET_HH_ */
diff --git a/scribo/demo/viewer/step_widget.cc b/scribo/demo/viewer/step_widget.cc
index 7d35543..1020c6a 100644
--- a/scribo/demo/viewer/step_widget.cc
+++ b/scribo/demo/viewer/step_widget.cc
@@ -26,7 +26,8 @@
# include "step_widget.hh"
StepWidget::StepWidget()
- : view_(new QListWidget())
+ : view_(new QListWidget()),
+ step_(QString::Null())
{
QLabel* title = new QLabel(tr("Steps"));
title->setAlignment(Qt::AlignHCenter);
@@ -42,6 +43,9 @@ StepWidget::StepWidget()
connect(view_, SIGNAL(itemActivated(QListWidgetItem*)),
this, SLOT(activate(QListWidgetItem*)));
+
+ connect(this, SIGNAL(activated(QListWidgetItem*)),
+ this, SLOT(activate(QListWidgetItem*)));
}
void StepWidget::activate(QListWidgetItem* item)
@@ -49,18 +53,22 @@ void StepWidget::activate(QListWidgetItem* item)
QString key, value;
StepQMap::iterator iter = map_.find(item->text());
-
+
+ view_->setCurrentItem(item);
if (iter != map_.end())
{
+ step_ = item->text();
key = iter.key();
value = iter.value();
+
+ emit load_xml(value);
}
-
- emit load_xml(value);
+ else
+ qDebug() << "Step not found!";
}
-void StepWidget::fill_steps(QString file)
+void StepWidget::fill_steps(QString file, bool step)
{
view_->clear();
map_.clear();
@@ -69,13 +77,14 @@ void StepWidget::fill_steps(QString file)
emit load_image(file);
int cut = file.lastIndexOf(QChar('/'));
- QString path = file.left(cut+1);
+ QString path = file.left(cut+1);
QString filename = file.mid(cut+1);
-
+
cut = filename.lastIndexOf(QChar('.'));
+
QString file_with_no_ext = filename.left(cut);
// view_->addItem(file_with_no_ext);
-
+
QDir dir(path);
if (dir.isReadable())
@@ -84,7 +93,7 @@ void StepWidget::fill_steps(QString file)
filter << "*.xml";
QStringList xml_list = dir.entryList(filter);
for (int i = 0; i < xml_list.size(); ++i)
- {
+ {
if (xml_list.at(i).startsWith(file_with_no_ext))
{
cut = xml_list.at(i).lastIndexOf(QChar('.'));
@@ -99,6 +108,17 @@ void StepWidget::fill_steps(QString file)
}
}
}
+
+
+ if (step && step_ != QString::Null())
+ {
+ QList<QListWidgetItem*> list = view_->findItems(step_, Qt::MatchContains);
+
+ if (!list.isEmpty())
+ emit activated(list.first());
+ }
+ else
+ step_ = QString::Null();
}
void StepWidget::add_element(const QString& element)
diff --git a/scribo/demo/viewer/step_widget.hh b/scribo/demo/viewer/step_widget.hh
index 829f814..928e503 100644
--- a/scribo/demo/viewer/step_widget.hh
+++ b/scribo/demo/viewer/step_widget.hh
@@ -44,14 +44,16 @@ public:
signals:
void load_image(QString);
void load_xml(QString);
+ void activated(QListWidgetItem*);
public slots:
- void fill_steps(QString file);
+ void fill_steps(QString file, bool = false);
void activate(QListWidgetItem* item);
private:
QListWidget* view_;
StepQMap map_;
+ QString step_;
};
#endif /* !STEP_WIDGET_HH_ */
diff --git a/scribo/demo/viewer/viewer.cc b/scribo/demo/viewer/viewer.cc
index 61a57c1..b3fd6f5 100644
--- a/scribo/demo/viewer/viewer.cc
+++ b/scribo/demo/viewer/viewer.cc
@@ -44,6 +44,7 @@ Viewer::Viewer(int &argc, char** argv)
key_map_[region::Text] = qMakePair(tr("Text Region"), QColor(0, 200, 0));
key_map_[region::Paragraph] = qMakePair(tr("Paragraph"), QColor(0, 0, 255));
key_map_[region::Line] = qMakePair(tr("Text line"), QColor(255, 0, 0));
+
key_map_[region::Image] = qMakePair(tr("Image"), QColor(255, 120, 0));
key_map_[region::Noise] = qMakePair(tr("Noise"), QColor(43, 39, 128));
key_map_[region::Separator] = qMakePair(tr("Separator"), QColor(0, 0, 255));
@@ -70,7 +71,7 @@ Viewer::Viewer(int &argc, char** argv)
// Layout
- win_->resize(1024, 768);
+ win_->resize(1152, 864);
win_->statusBar();
QMenu* file_menu = win_->menuBar()->addMenu(tr("File"));
@@ -157,7 +158,7 @@ Viewer::Viewer(int &argc, char** argv)
win_->setCentralWidget(h_splitter);
QList<int> v_sizes;
- v_sizes << 300 << 200 << 200 << 300;
+ v_sizes << 200 << 200 << 300 << 400;
v_splitter->setSizes(v_sizes);
QList<int> v_sizes2;
@@ -168,8 +169,8 @@ Viewer::Viewer(int &argc, char** argv)
h_sizes << 200 << 700;
h_splitter->setSizes(h_sizes);
- connect(browser_wgt, SIGNAL(activated(QString)),
- step_widget, SLOT(fill_steps(QString)));
+ connect(browser_wgt, SIGNAL(activated(QString, bool)),
+ step_widget, SLOT(fill_steps(QString, bool)));
connect(step_widget, SIGNAL(load_image(QString)),
this, SLOT(load(QString)));
@@ -252,6 +253,11 @@ Viewer::load_xml(QString filename)
void
Viewer::xml_to_layout()
{
+
+ /* /!\ XML parsing is VERY UGLY /!\
+ TO DO: use same parsing as xml_transfrom. */
+
+
// Add layout info to the scene.
if (doc_layout_)
{
@@ -284,6 +290,7 @@ Viewer::xml_to_layout()
doc_layout_->data(point, Qt::UserRole).toMap();
int x = data["x"].toInt();
int y = data["y"].toInt();
+
points << QPoint(x, y);
}
@@ -396,8 +403,8 @@ Viewer::xml_to_layout()
attributes_line, points_line,
outline_action_->isChecked(),
fill_action_->isChecked(),
- precise_action_->isChecked(),
- key_wgt_->isChecked(id_line));
+ precise_action_->isChecked(),
+ key_wgt_->isChecked(id_line));
connect(this, SIGNAL(key_updated(int, bool)),
r_line, SLOT(setDrawIfSameId(int, bool)));
@@ -417,6 +424,7 @@ Viewer::xml_to_layout()
}
emit updated(doc_layout_);
+ key_wgt_->update_all();
}
}
@@ -427,7 +435,7 @@ Viewer::load(QString filename)
scene_->clear();
scene_->update();
image_ = 0;
- xml_file_ = "";
+ // xml_file_ = "";
// Load the image in a pixmap that is directly shown on screen.
// This is very slow when used with the normal rendering system.
@@ -482,7 +490,7 @@ Viewer::maybeChangeCacheMode(qreal scale)
void Viewer::useExtended(bool b)
{
extended_mode_ = b;
- key_wgt_->checkAll();
+ key_wgt_->update_all();
if (xml_file_ != QString(""))
load_xml(xml_file_);
diff --git a/scribo/demo/viewer/xml_widget.cc b/scribo/demo/viewer/xml_widget.cc
index fa050ec..36f0406 100644
--- a/scribo/demo/viewer/xml_widget.cc
+++ b/scribo/demo/viewer/xml_widget.cc
@@ -24,6 +24,7 @@ XmlWidget::XmlWidget()
title->setAlignment(Qt::AlignHCenter);
QVBoxLayout* layout = new QVBoxLayout;
+
layout->addWidget(title);
layout->addWidget(view_);
@@ -34,7 +35,7 @@ void
XmlWidget::update(DomModel* model)
{
view_->setModel(model);
- view_->resizeColumnToContents(2);
+ // view_->resizeColumnToContents(2);
}
void
--
1.5.6.5
1
0
last-svn-commit-563-g6d0a92e Base 64 support in Qt interface (xmlc extension)
by Arthur Crepin-Leblond 16 Nov '10
by Arthur Crepin-Leblond 16 Nov '10
16 Nov '10
* scribo/demo/viewer/step_widget.cc
* scribo/demo/viewer/step_widget.hh
* scribo/demo/viewer/browser_widget.cc,
* scribo/demo/viewer/browser_widget.hh: Add .xmlc extension.
* scribo/demo/viewer/image_scene.cc
* scribo/demo/viewer/viewer.cc,
* scribo/demo/viewer/viewer.hh: base 64 loading.
---
scribo/ChangeLog | 38 +++++++++++------
scribo/demo/viewer/browser_widget.cc | 9 +++-
scribo/demo/viewer/browser_widget.hh | 2 +-
scribo/demo/viewer/image_scene.cc | 10 ++--
scribo/demo/viewer/step_widget.cc | 77 ++++++++++++++++++---------------
scribo/demo/viewer/step_widget.hh | 4 +-
scribo/demo/viewer/viewer.cc | 60 +++++++++++++++++++++++---
scribo/demo/viewer/viewer.hh | 3 +-
8 files changed, 137 insertions(+), 66 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index f2b8e4a..1c9bdbd 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,29 +1,41 @@
2010-07-16 Arthur Crepin-Leblond <crepin(a)ptaouchnok.lrde.epita.fr>
+ Base 64 support in Qt interface (xmlc extension)
+
+ * demo/viewer/step_widget.cc
+ * demo/viewer/step_widget.hh
+ * demo/viewer/browser_widget.cc,
+ * demo/viewer/browser_widget.hh: Add .xmlc extension.
+
+ * demo/viewer/image_scene.cc
+ * demo/viewer/viewer.cc,
+ * demo/viewer/viewer.hh: base 64 loading.
+
+2010-07-16 Arthur Crepin-Leblond <crepin(a)ptaouchnok.lrde.epita.fr>
+
Two new features in Qt interface.
* demo/viewer/browser_widget.cc,
- * demo/viewer/browser_widget.hh: Add arrows to change image and keep
- XML step.
+ * demo/viewer/browser_widget.hh: Add arrows to change image and
+ keep XML step.
* demo/viewer/key_widget.cc,
- * demo/viewer/key_widget.hh: Change ListWidget to TreeWidget, Items can be
- disabled/enabled in groups.
+ * demo/viewer/key_widget.hh: Change ListWidget to TreeWidget,
+ Items can be disabled/enabled in groups.
* demo/viewer/step_widget.cc,
- * demo/viewer/step_widget.hh: Small changes to keep the step when next/prev.
- picture is chosen.
+ * demo/viewer/step_widget.hh: Small changes to keep the step when
+ next/prev. picture is chosen.
* demo/viewer/viewer.cc,
* demo/viewer/xml_widget.cc: Layout adjustement.
-
2010-07-16 Arthur Crepin-Leblond <crepin(a)ptaouchnok.lrde.epita.fr>
ChangeLog mistake.
- * scribo/ChangeLog: Move 2010-07-08 entry in...
- * scribo/sandbox/ChangeLog:...this.
+ * ChangeLog: Move 2010-07-08 entry in...
+ * sandbox/ChangeLog:...this.
2010-06-30 Arthur Crepin-Leblond <crepin(a)stockholm.lrde.epita.fr>
@@ -78,12 +90,12 @@
Small fix in Qt interface.
- * scribo/demo/viewer/viewer.cc,
- * scribo/demo/viewer/image_region.hxx: Disable item click if
+ * demo/viewer/viewer.cc,
+ * demo/viewer/image_region.hxx: Disable item click if
unchecked in item list.
- * scribo/demo/viewer/key_widget.cc,
- * scribo/demo/viewer/key_widget.hh: Add KeyWidget::checkAll.
+ * demo/viewer/key_widget.cc,
+ * demo/viewer/key_widget.hh: Add KeyWidget::checkAll.
2010-08-27 Guillaume Lazzara <z(a)lrde.epita.fr>
diff --git a/scribo/demo/viewer/browser_widget.cc b/scribo/demo/viewer/browser_widget.cc
index bd70648..220a719 100644
--- a/scribo/demo/viewer/browser_widget.cc
+++ b/scribo/demo/viewer/browser_widget.cc
@@ -66,7 +66,9 @@ BrowserWidget::BrowserWidget(QDirModel* files, QString dir)
QStringList files_filters;
files_filters << "*.png" << "*.jpg"
- << "*.tif" << "*.ppm" << "*.pgm" << "*.pbm" << "pnm";
+ << "*.tif" << "*.ppm"
+ << "*.pgm" << "*.pbm"
+ << "*.pnm" << "*.xmle";
files->setNameFilters(files_filters);
}
@@ -95,7 +97,10 @@ BrowserWidget::activate(const QModelIndex& index, bool b)
first_time_ = false;
- emit activated(files_->filePath(index), b);
+ if (files_->filePath(index).endsWith(".xmlc"))
+ emit activated(files_->filePath(index), b, true);
+ else
+ emit activated(files_->filePath(index), b, false);
}
void
diff --git a/scribo/demo/viewer/browser_widget.hh b/scribo/demo/viewer/browser_widget.hh
index a0fbe43..9266832 100644
--- a/scribo/demo/viewer/browser_widget.hh
+++ b/scribo/demo/viewer/browser_widget.hh
@@ -33,7 +33,7 @@ public slots:
void prev() { change_pos(false); }
signals:
- void activated(QString filename, bool b);
+ void activated(QString filename, bool b, bool x);
private:
void change_pos(bool next);
diff --git a/scribo/demo/viewer/image_scene.cc b/scribo/demo/viewer/image_scene.cc
index bbc75c3..62b4b46 100644
--- a/scribo/demo/viewer/image_scene.cc
+++ b/scribo/demo/viewer/image_scene.cc
@@ -40,7 +40,7 @@ ImageScene::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
ImageRegion* item = dynamic_cast<ImageRegion*>(elt);
if (item)
- {
+ {
if (item != selected_)
{
if (selected_)
@@ -49,7 +49,7 @@ ImageScene::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
int item_area = item->boundingRect().size().height() * item->boundingRect().size().width();
int selected_area = selected_->boundingRect().size().height() * selected_->boundingRect().size().width();
-
+
if (selected_area < item_area && selection_is_clicked)
return;
else
@@ -66,15 +66,15 @@ ImageScene::mousePressEvent(QGraphicsSceneMouseEvent* event)
selected_ = 0;
}
}
- selected_ = item;
+ selected_ = item;
item->select();
emit selected(item->index());
- return;
+ return;
}
}
else
{
- if ( (selected_)
+ if ( (selected_)
&& (items_list.size() == 1) )// no ImageRegion, only the picture
{
selected_->deselect();
diff --git a/scribo/demo/viewer/step_widget.cc b/scribo/demo/viewer/step_widget.cc
index 1020c6a..207796d 100644
--- a/scribo/demo/viewer/step_widget.cc
+++ b/scribo/demo/viewer/step_widget.cc
@@ -68,57 +68,64 @@ void StepWidget::activate(QListWidgetItem* item)
}
-void StepWidget::fill_steps(QString file, bool step)
+void StepWidget::fill_steps(QString file, bool step, bool container)
{
view_->clear();
map_.clear();
- // image is loaded once
- emit load_image(file);
+ if (container)
+ {
+ emit load_image(file, true);
+ emit load_xml(file);
+ }
+ else
+ {
+ // image is loaded once
+ emit load_image(file, false);
- int cut = file.lastIndexOf(QChar('/'));
- QString path = file.left(cut+1);
- QString filename = file.mid(cut+1);
+ int cut = file.lastIndexOf(QChar('/'));
+ QString path = file.left(cut+1);
+ QString filename = file.mid(cut+1);
- cut = filename.lastIndexOf(QChar('.'));
+ cut = filename.lastIndexOf(QChar('.'));
- QString file_with_no_ext = filename.left(cut);
- // view_->addItem(file_with_no_ext);
+ QString file_with_no_ext = filename.left(cut);
+ // view_->addItem(file_with_no_ext);
- QDir dir(path);
+ QDir dir(path);
- if (dir.isReadable())
- {
- QStringList filter;
- filter << "*.xml";
- QStringList xml_list = dir.entryList(filter);
- for (int i = 0; i < xml_list.size(); ++i)
+ if (dir.isReadable())
{
- if (xml_list.at(i).startsWith(file_with_no_ext))
+ QStringList filter;
+ filter << "*.xml";
+ QStringList xml_list = dir.entryList(filter);
+ for (int i = 0; i < xml_list.size(); ++i)
{
- cut = xml_list.at(i).lastIndexOf(QChar('.'));
- QString key = xml_list.at(i).left(cut);
- key.replace(file_with_no_ext + QString("_"), QString(""));
- key.replace(QRegExp("^step([0-9])"), "Step \\1");
- key.replace(QRegExp("^Step ([0-9])_"), "Step \\1 : ");
- key.replace("_", " ");
- QString value = path;
- map_.insertMulti(key, value.append(xml_list.at(i)));
- view_->addItem(key);
+ if (xml_list.at(i).startsWith(file_with_no_ext))
+ {
+ cut = xml_list.at(i).lastIndexOf(QChar('.'));
+ QString key = xml_list.at(i).left(cut);
+ key.replace(file_with_no_ext + QString("_"), QString(""));
+ key.replace(QRegExp("^step([0-9])"), "Step \\1");
+ key.replace(QRegExp("^Step ([0-9])_"), "Step \\1 : ");
+ key.replace("_", " ");
+ QString value = path;
+ map_.insertMulti(key, value.append(xml_list.at(i)));
+ view_->addItem(key);
+ }
}
}
- }
+ if ( (step && step_ != QString::Null()))
+ {
+ QList<QListWidgetItem*> list = view_->findItems(step_, Qt::MatchContains);
- if (step && step_ != QString::Null())
- {
- QList<QListWidgetItem*> list = view_->findItems(step_, Qt::MatchContains);
-
- if (!list.isEmpty())
- emit activated(list.first());
+ if (!list.isEmpty())
+ emit activated(list.first());
+ }
+ else
+ step_ = QString::Null();
}
- else
- step_ = QString::Null();
}
void StepWidget::add_element(const QString& element)
diff --git a/scribo/demo/viewer/step_widget.hh b/scribo/demo/viewer/step_widget.hh
index 928e503..32602b0 100644
--- a/scribo/demo/viewer/step_widget.hh
+++ b/scribo/demo/viewer/step_widget.hh
@@ -42,12 +42,12 @@ public:
void add_element(const QString& element);
signals:
- void load_image(QString);
+ void load_image(QString, bool);
void load_xml(QString);
void activated(QListWidgetItem*);
public slots:
- void fill_steps(QString file, bool = false);
+ void fill_steps(QString file, bool step = false, bool container = false);
void activate(QListWidgetItem* item);
private:
diff --git a/scribo/demo/viewer/viewer.cc b/scribo/demo/viewer/viewer.cc
index b3fd6f5..e5ec717 100644
--- a/scribo/demo/viewer/viewer.cc
+++ b/scribo/demo/viewer/viewer.cc
@@ -169,11 +169,11 @@ Viewer::Viewer(int &argc, char** argv)
h_sizes << 200 << 700;
h_splitter->setSizes(h_sizes);
- connect(browser_wgt, SIGNAL(activated(QString, bool)),
- step_widget, SLOT(fill_steps(QString, bool)));
+ connect(browser_wgt, SIGNAL(activated(QString, bool, bool)),
+ step_widget, SLOT(fill_steps(QString, bool, bool)));
- connect(step_widget, SIGNAL(load_image(QString)),
- this, SLOT(load(QString)));
+ connect(step_widget, SIGNAL(load_image(QString, bool)),
+ this, SLOT(load(QString, bool)));
connect(step_widget, SIGNAL(load_xml(QString)),
this, SLOT(load_xml(QString)));
@@ -429,18 +429,20 @@ Viewer::xml_to_layout()
}
void
-Viewer::load(QString filename)
+Viewer::load(QString filename, bool b)
{
app_->setOverrideCursor(QCursor(Qt::WaitCursor));
scene_->clear();
scene_->update();
image_ = 0;
- // xml_file_ = "";
// Load the image in a pixmap that is directly shown on screen.
// This is very slow when used with the normal rendering system.
// OpenGL might speed up things a bit.
- image_ = new QGraphicsPixmapItem(QPixmap(filename));
+ if (b)
+ image_ = new QGraphicsPixmapItem(load_base64(filename));
+ else
+ image_ = new QGraphicsPixmapItem(QPixmap(filename));
image_->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
image_->setZValue(0);
scene_->addItem(image_);
@@ -511,4 +513,48 @@ Viewer::useCache(bool b)
image_->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
}
+QPixmap Viewer::load_base64(QString xml)
+{
+ QPixmap pix;
+ QFile f_in(xml);
+ f_in.open(QIODevice::ReadOnly);
+
+ QDomDocument doc;
+ doc.setContent(&f_in);
+ f_in.close();
+
+ QDomElement root = doc.documentElement();
+ QDomNode child = root.firstChild();
+
+ while (!child.isNull() && !child.toElement().tagName().contains("page"))
+ child = child.nextSibling();
+
+ child = child.firstChild();
+ while (!child.isNull())
+ {
+ if (child.toElement().tagName().contains(QRegExp("image_region")))
+ {
+ QDomNode node = child.firstChild();
+ QString id = child.toElement().attribute("id", "none");
+
+ while (!node.isNull() && !node.toElement().tagName().contains("container"))
+ node = node.nextSibling();
+
+ if (!node.isNull())
+ {
+ QString data = node.firstChildElement("data").text();
+ QByteArray ba;
+ ba = ba.append(data);
+ QByteArray out_ba = QByteArray::fromBase64(ba);
+ pix.loadFromData(out_ba);
+
+ return pix;
+ }
+ }
+ child = child.nextSibling();
+ }
+
+ return pix;
+}
+
// LocalWords: hh
diff --git a/scribo/demo/viewer/viewer.hh b/scribo/demo/viewer/viewer.hh
index d13ef91..7093da8 100644
--- a/scribo/demo/viewer/viewer.hh
+++ b/scribo/demo/viewer/viewer.hh
@@ -38,7 +38,7 @@ public:
public slots:
// Load the file as an image, load the layout if xml with the same
// name is found.
- void load(QString filename);
+ void load(QString filename, bool b);
void help();
void load_xml(QString filename);
void maybeChangeCacheMode(qreal scale);
@@ -59,6 +59,7 @@ private:
Viewer();
void xml_to_layout();
+ QPixmap load_base64(QString xml);
QApplication* app_;
QMainWindow* win_;
--
1.5.6.5
1
0