[Libreoffice-commits] libcdr.git: 4 commits - configure.ac src/lib

David Tardon dtardon at redhat.com
Tue May 16 14:27:02 UTC 2017


 configure.ac                  |    6 +-
 src/lib/CDRContentCollector.h |    2 
 src/lib/CDRParser.cpp         |  107 ++++++++++++++++++++----------------------
 3 files changed, 58 insertions(+), 57 deletions(-)

New commits:
commit 157f80cc4f4cd295588eba55bdcbe56889e9225a
Author: David Tardon <dtardon at redhat.com>
Date:   Tue May 16 16:18:35 2017 +0200

    use a lookup table to get codepage from font name
    
    Change-Id: Ia45f9aeb1d2993d751cf29e1855d640a90b3e2d3

diff --git a/configure.ac b/configure.ac
index 5fa92c6..78b34f4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -129,6 +129,7 @@ AC_SUBST(ICU_LIBS)
 # ===========================
 
 AC_CHECK_HEADERS(
+	boost/algorithm/string.hpp \
 	boost/cstdint.hpp \
 	boost/optional.hpp \
 	boost/property_tree/json_parser.hpp \
diff --git a/src/lib/CDRParser.cpp b/src/lib/CDRParser.cpp
index becf7c5..43748fe 100644
--- a/src/lib/CDRParser.cpp
+++ b/src/lib/CDRParser.cpp
@@ -15,6 +15,7 @@
 #ifndef BOOST_ALL_NO_LIB
 #define BOOST_ALL_NO_LIB 1
 #endif
+#include <boost/algorithm/string.hpp>
 #include <boost/optional.hpp>
 #include <boost/property_tree/json_parser.hpp>
 #include <boost/property_tree/ptree.hpp>
@@ -73,44 +74,35 @@ struct CDRStltRecord
 
 static void processNameForEncoding(librevenge::RVNGString &name, unsigned short &encoding)
 {
-  std::string fontName(name.cstr());
-  size_t length = fontName.length();
-  size_t found = std::string::npos;
+  namespace qi = boost::spirit::qi;
+
+  qi::symbols<char, unsigned short> codepage;
+  codepage.add
+  ("EC ", 0xee)
+  ("cilliryC ", 0xcc)
+  ("ryC ", 0xcc)
+  ("RYC ", 0xcc)
+  ("citlaB ", 0xba)
+  ("keerG ", 0xa1)
+  ("ruT ", 0xa2)
+  ("RUT ", 0xa2)
+  ("werbeH ", 0xb1)
+  ("cibarA ", 0xb2)
+  ("iahT ", 0xde)
+  ;
 
-  if (length > 3 && (found=fontName.find(" CE", length - 3)) != std::string::npos)
-    encoding = 0xee;
-  else if (length > 9 && (found=fontName.rfind(" Cyrillic", length - 9)) != std::string::npos)
-    encoding = 0xcc;
-  else if (length > 4 && (found=fontName.rfind(" Cyr", length - 4)) != std::string::npos)
-    encoding = 0xcc;
-  else if (length > 4 && (found=fontName.rfind(" CYR", length - 4)) != std::string::npos)
-    encoding = 0xcc;
-  else if (length > 7 && (found=fontName.rfind(" Baltic", length - 7)) != std::string::npos)
-    encoding = 0xba;
-  else if (length > 6 && (found=fontName.rfind(" Greek", length - 6)) != std::string::npos)
-    encoding = 0xa1;
-  else if (length > 4 && (found=fontName.rfind(" Tur", length - 4)) != std::string::npos)
-    encoding = 0xa2;
-  else if (length > 4 && (found=fontName.rfind(" TUR", length - 4)) != std::string::npos)
-    encoding = 0xa2;
-  else if (length > 7 && (found=fontName.rfind(" Hebrew", length - 7)) != std::string::npos)
-    encoding = 0xb1;
-  else if (length > 7 && (found=fontName.rfind(" Arabic", length - 7)) != std::string::npos)
-    encoding = 0xb2;
-  else if (length > 5 && (found=fontName.rfind(" Thai", length - 5)) != std::string::npos)
-    encoding = 0xde;
-  else if (length >= 4 && (found=fontName.find("GOST", 0, 4)) != std::string::npos)
+  std::string fontName(name.cstr());
+  unsigned short enc = encoding;
+  std::string revName;
+  if (qi::parse(fontName.rbegin(), fontName.rend(), codepage >> +qi::char_, enc, revName))
   {
-    encoding = 0xcc;
-    found = std::string::npos;
+    encoding = enc;
+    name = std::string(revName.rbegin(), revName.rend()).c_str();
   }
-
-  if (found != std::string::npos)
+  else if (boost::starts_with(fontName, "GOST"))
   {
-    fontName.erase(found, std::string::npos);
-    name = fontName.c_str();
+    encoding = 0xcc;
   }
-  return;
 }
 
 static int parseColourString(const char *colourString, libcdr::CDRColor &colour, double &opacity)
commit 622861c10a26941233ec120528c281e69605a355
Author: David Tardon <dtardon at redhat.com>
Date:   Tue May 16 15:48:45 2017 +0200

    convert from Spirit.Classic to Qi
    
    Change-Id: Id6dcd006cbc23f2928f0f7b0be90003dfd07f945

diff --git a/configure.ac b/configure.ac
index e7c1bef..5fa92c6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -133,7 +133,7 @@ AC_CHECK_HEADERS(
 	boost/optional.hpp \
 	boost/property_tree/json_parser.hpp \
 	boost/property_tree/ptree.hpp \
-	boost/spirit/include/classic.hpp \
+	boost/spirit/include/qi.hpp \
         ,
 	[],
 	[AC_MSG_ERROR(Required boost headers not found. Install boost >= 1.41.0)],
diff --git a/src/lib/CDRParser.cpp b/src/lib/CDRParser.cpp
index 3610349..becf7c5 100644
--- a/src/lib/CDRParser.cpp
+++ b/src/lib/CDRParser.cpp
@@ -18,7 +18,7 @@
 #include <boost/optional.hpp>
 #include <boost/property_tree/json_parser.hpp>
 #include <boost/property_tree/ptree.hpp>
-#include <boost/spirit/include/classic.hpp>
+#include <boost/spirit/include/qi.hpp>
 #include "libcdr_utils.h"
 #include "CDRDocumentStructure.h"
 #include "CDRInternalStream.h"
@@ -115,37 +115,44 @@ static void processNameForEncoding(librevenge::RVNGString &name, unsigned short
 
 static int parseColourString(const char *colourString, libcdr::CDRColor &colour, double &opacity)
 {
-  using namespace boost::spirit::classic;
+  using namespace boost::spirit::qi;
   bool bRes = false;
 
-  std::string colourModel;
+  boost::optional<unsigned> colourModel;
   unsigned val0, val1, val2, val3, val4;
 
   if (colourString)
   {
-    bRes = parse(colourString,
-                 //  Begin grammar
-                 (
-                   (repeat_p(1, more)[alnum_p])[assign_a(colourModel)] >> (',' | eps_p)
-                   >> (repeat_p(1, more)[alnum_p]) >> (',' | eps_p)
-                   >> int_p[assign_a(val0)] >> (',' | eps_p)
-                   >> int_p[assign_a(val1)] >> (',' | eps_p)
-                   >> int_p[assign_a(val2)] >> (',' | eps_p)
-                   >> int_p[assign_a(val3)] >> (',' | eps_p)
-                   >> int_p[assign_a(val4)] >> (',' | eps_p)
-                   >> (repeat_p(8)[alnum_p] >> ('-') >> repeat_p(3)[repeat_p(4)[alnum_p] >> ('-')] >> repeat_p(12)[alnum_p])
-                 ) >> end_p,
-                 //  End grammar
-                 space_p).full;
+    symbols<char, unsigned> cmodel;
+    cmodel.add
+    ("CMYK", 2)
+    ("CMYK255", 3)
+    ;
+    auto it = colourString;
+    const auto end = it + std::strlen(it);
+    bRes = phrase_parse(it, end,
+                        //  Begin grammar
+                        (
+                          (cmodel | omit[+alnum]) >> -lit(',')
+                          >> omit[+alnum] >> -lit(',')
+                          >> uint_ >> -lit(',')
+                          >> uint_ >> -lit(',')
+                          >> uint_ >> -lit(',')
+                          >> uint_ >> -lit(',')
+                          >> uint_ >> -lit(',')
+                          >> (repeat(8)[alnum] >> '-' >> repeat(3)[repeat(4)[alnum] >> '-'] >> repeat(12)[alnum])
+                        ),
+                        //  End grammar
+                        space,
+                        colourModel, val0, val1, val2, val3, val4)
+           && it == end;
   }
 
   if (!bRes)
     return -1;
 
-  if (colourModel == "CMYK")
-    colour.m_colorModel = 2;
-  else if (colourModel == "CMYK255")
-    colour.m_colorModel = 3;
+  if (colourModel)
+    colour.m_colorModel = get(colourModel);
   colour.m_colorValue = val0 | (val1 << 8) | (val2 << 16) | (val3 << 24);
   opacity = (double)val4 / 100.0;
 
commit 701116d56e4acea578fec5fc4205b406dd538b85
Author: David Tardon <dtardon at redhat.com>
Date:   Tue May 16 15:39:53 2017 +0200

    sort lexicographically
    
    Change-Id: Ia52662eddcb8672c07c60798341ddee5ffc90606

diff --git a/configure.ac b/configure.ac
index f0ef4da..e7c1bef 100644
--- a/configure.ac
+++ b/configure.ac
@@ -131,9 +131,10 @@ AC_SUBST(ICU_LIBS)
 AC_CHECK_HEADERS(
 	boost/cstdint.hpp \
 	boost/optional.hpp \
+	boost/property_tree/json_parser.hpp \
 	boost/property_tree/ptree.hpp \
 	boost/spirit/include/classic.hpp \
-	boost/property_tree/json_parser.hpp,
+        ,
 	[],
 	[AC_MSG_ERROR(Required boost headers not found. Install boost >= 1.41.0)],
 	[]
commit 7d11cf51b0087efe295a180af6476eacb744d266
Author: David Tardon <dtardon at redhat.com>
Date:   Tue May 16 09:45:57 2017 +0200

    drop :: prefix
    
    Change-Id: I64cdccb97a3b130484a13bd7c713abc79cfed394

diff --git a/src/lib/CDRContentCollector.h b/src/lib/CDRContentCollector.h
index 30c1546..79faf54 100644
--- a/src/lib/CDRContentCollector.h
+++ b/src/lib/CDRContentCollector.h
@@ -27,7 +27,7 @@ namespace libcdr
 class CDRContentCollector : public CDRCollector
 {
 public:
-  CDRContentCollector(CDRParserState &ps, ::librevenge::RVNGDrawingInterface *painter, bool reverseOrder = true);
+  CDRContentCollector(CDRParserState &ps, librevenge::RVNGDrawingInterface *painter, bool reverseOrder = true);
   virtual ~CDRContentCollector();
 
   // collector functions
diff --git a/src/lib/CDRParser.cpp b/src/lib/CDRParser.cpp
index fd6c58a..3610349 100644
--- a/src/lib/CDRParser.cpp
+++ b/src/lib/CDRParser.cpp
@@ -115,7 +115,7 @@ static void processNameForEncoding(librevenge::RVNGString &name, unsigned short
 
 static int parseColourString(const char *colourString, libcdr::CDRColor &colour, double &opacity)
 {
-  using namespace ::boost::spirit::classic;
+  using namespace boost::spirit::classic;
   bool bRes = false;
 
   std::string colourModel;


More information about the Libreoffice-commits mailing list