summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac4
-rw-r--r--src/lib/T602Header.cpp119
-rw-r--r--src/lib/T602Header.h25
3 files changed, 147 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index da9f487..fce7d1e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -53,6 +53,10 @@ AC_SUBST(REVENGE_LIBS)
AC_CHECK_HEADERS(
boost/iterator/iterator_facade.hpp \
boost/optional.hpp \
+ boost/spirit/include/phoenix_core.hpp \
+ boost/spirit/include/phoenix_operator.hpp \
+ boost/spirit/include/qi_core.hpp \
+ boost/spirit/include/qi_eol.hpp \
boost/scoped_ptr.hpp \
boost/shared_ptr.hpp \
,
diff --git a/src/lib/T602Header.cpp b/src/lib/T602Header.cpp
index 454e21e..5ae7591 100644
--- a/src/lib/T602Header.cpp
+++ b/src/lib/T602Header.cpp
@@ -9,16 +9,83 @@
#include "T602Header.h"
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+#include <boost/spirit/include/qi_core.hpp>
+#include <boost/spirit/include/qi_eol.hpp>
+
+#include "SW602StreamIterator.h"
+
namespace libsw602
{
T602Header::T602Header()
: m_valid(false)
+ , m_encoding(SW602Document::ENCODING_UNSPECIFIED)
+ , m_header()
+ , m_footer()
+ , m_lineHeight(1)
+ , m_leftMargin(0)
+ , m_rightMargin(0)
+ , m_topMargin(0)
+ , m_bottomMargin(0)
+ , m_pageLength(0)
+ , m_tabStr()
{
}
-void T602Header::construct(librevenge::RVNGInputStream &/*input*/)
+void T602Header::construct(librevenge::RVNGInputStream &input)
{
+ namespace qi = boost::spirit::qi;
+ namespace phx = boost::phoenix;
+ using qi::_1;
+ using qi::ascii::upper;
+ using qi::ascii::char_;
+ using qi::eol;
+ using qi::lit;
+ using qi::repeat;
+ using qi::uint_;
+
+ qi::symbols<char, SW602Document::Encoding> encoding;
+ encoding.add
+ ("0", SW602Document::ENCODING_KEYBCS2)
+ ("1", SW602Document::ENCODING_LATIN2)
+ ("2", SW602Document::ENCODING_KOI8CS)
+ ;
+ qi::symbols<char, double> lineHeight;
+ lineHeight.add
+ ("3", 2)
+ ("4", 1.5)
+ ("6", 1)
+ ;
+
+ bool known = false;
+ SW602StreamIterator it(input);
+ const bool result =
+ qi::parse(it, SW602StreamIterator(),
+ +(
+ lit('@')
+ > (
+ (
+ (lit("CT") > ' ' > encoding[phx::ref(m_encoding) = _1])
+ | (lit("HE") > ' ' > +(char_ - '\r')[phx::ref(m_header) += _1])
+ | (lit("FO") > ' ' > +(char_ - '\r')[phx::ref(m_footer) += _1])
+ | (lit("LH") > ' ' > lineHeight[phx::ref(m_lineHeight) = _1])
+ | (lit("LM") > ' ' > uint_[phx::ref(m_leftMargin) = _1])
+ | (lit("MT") > ' ' > uint_[phx::ref(m_topMargin) = _1])
+ | (lit("MB") > ' ' > uint_[phx::ref(m_bottomMargin) = _1])
+ | (lit("PL") > ' ' > uint_[phx::ref(m_pageLength) = _1])
+ | (lit("RM") > ' ' > uint_[phx::ref(m_rightMargin) = _1])
+ | (lit("TB") > ' ' > +(char_ - '\r')[phx::ref(m_tabStr) += _1])
+ )[phx::ref(known) = true]
+ | (repeat(2)[upper] > ' ' > *(char_ - '\r')) // unhandled controls
+ )
+ > eol
+ )
+ )
+ ;
+
+ m_valid = result && known;
}
bool T602Header::isValid() const
@@ -26,6 +93,56 @@ bool T602Header::isValid() const
return m_valid;
}
+SW602Document::Encoding T602Header::encoding() const
+{
+ return m_encoding;
+}
+
+const std::string &T602Header::header() const
+{
+ return m_header;
+}
+
+const std::string &T602Header::footer() const
+{
+ return m_footer;
+}
+
+double T602Header::lineHeight() const
+{
+ return m_lineHeight;
+}
+
+unsigned T602Header::leftMargin() const
+{
+ return m_leftMargin;
+}
+
+unsigned T602Header::rightMargin() const
+{
+ return m_rightMargin;
+}
+
+unsigned T602Header::topMargin() const
+{
+ return m_topMargin;
+}
+
+unsigned T602Header::bottomMargin() const
+{
+ return m_bottomMargin;
+}
+
+unsigned T602Header::pageLength() const
+{
+ return m_pageLength;
+}
+
+const std::string &T602Header::tabs() const
+{
+ return m_tabStr;
+}
+
} // namespace libsw602
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/lib/T602Header.h b/src/lib/T602Header.h
index da5dd65..bd6ccd0 100644
--- a/src/lib/T602Header.h
+++ b/src/lib/T602Header.h
@@ -10,8 +10,12 @@
#ifndef INCLUDED_T602HEADER_H
#define INCLUDED_T602HEADER_H
+#include <string>
+
#include <librevenge-stream/librevenge-stream.h>
+#include <libsw602/libsw602.h>
+
namespace libsw602
{
@@ -24,8 +28,29 @@ public:
bool isValid() const;
+ SW602Document::Encoding encoding() const;
+ const std::string &header() const;
+ const std::string &footer() const;
+ double lineHeight() const;
+ unsigned leftMargin() const;
+ unsigned rightMargin() const;
+ unsigned topMargin() const;
+ unsigned bottomMargin() const;
+ unsigned pageLength() const;
+ const std::string &tabs() const;
+
private:
bool m_valid;
+ SW602Document::Encoding m_encoding;
+ std::string m_header;
+ std::string m_footer;
+ double m_lineHeight;
+ unsigned m_leftMargin;
+ unsigned m_rightMargin;
+ unsigned m_topMargin;
+ unsigned m_bottomMargin;
+ unsigned m_pageLength;
+ std::string m_tabStr;
};
} // namespace libsw602