[Libreoffice-commits] libmspub.git: src/lib

David Tardon dtardon at redhat.com
Sat Dec 30 15:49:20 UTC 2017


 src/lib/MSPUBBlockID.h     |    1 +
 src/lib/MSPUBCollector.cpp |   24 ++++++++++++++++++++++++
 src/lib/MSPUBParser.cpp    |    3 +++
 src/lib/MSPUBTypes.h       |    2 ++
 4 files changed, 30 insertions(+)

New commits:
commit 99e33fec6e9372840dc0c2e6d29a2b08a311e00a
Author: David Tardon <dtardon at redhat.com>
Date:   Sat Dec 30 16:39:25 2017 +0100

    parse locale information
    
    Change-Id: If47fadac1a24c6bebb73f530d9623e6b950d7a3f

diff --git a/src/lib/MSPUBBlockID.h b/src/lib/MSPUBBlockID.h
index bf92664..38f6139 100644
--- a/src/lib/MSPUBBlockID.h
+++ b/src/lib/MSPUBBlockID.h
@@ -37,6 +37,7 @@ enum MSPUBBlockID // Don't be alarmed by multiple elements with the same value;
   UNDERLINE_ID = 0x1E,
   OUTLINE_ID = 0x4,
   SHADOW_ID = 0x5,
+  LOCALE_ID = 0x12,
   SMALL_CAPS_ID = 0x13,
   ALL_CAPS_ID = 0x14,
   EMBOSS_ID = 0x16,
diff --git a/src/lib/MSPUBCollector.cpp b/src/lib/MSPUBCollector.cpp
index 24c8d08..95a463b 100644
--- a/src/lib/MSPUBCollector.cpp
+++ b/src/lib/MSPUBCollector.cpp
@@ -14,6 +14,7 @@
 #include <boost/multi_array.hpp>
 
 #include <unicode/ucsdet.h>
+#include <unicode/uloc.h>
 
 #include "Coordinate.h"
 #include "MSPUBConstants.h"
@@ -314,6 +315,25 @@ void fillUnderline(librevenge::RVNGPropertyList &props, const Underline underlin
   }
 }
 
+void fillLocale(librevenge::RVNGPropertyList &props, const unsigned lcid)
+{
+  char locale[ULOC_FULLNAME_CAPACITY];
+  UErrorCode status = U_ZERO_ERROR;
+  uloc_getLocaleForLCID(lcid, locale, ULOC_FULLNAME_CAPACITY, &status);
+  if (!U_SUCCESS(status))
+    return;
+  char component[ULOC_FULLNAME_CAPACITY];
+  int32_t len = uloc_getLanguage(locale, component, ULOC_FULLNAME_CAPACITY, &status);
+  if (U_SUCCESS(status) && len > 0)
+    props.insert("fo:language", component);
+  len = uloc_getCountry(locale, component, ULOC_FULLNAME_CAPACITY, &status);
+  if (U_SUCCESS(status) && len > 0)
+    props.insert("fo:country", component);
+  len = uloc_getScript(locale, component, ULOC_FULLNAME_CAPACITY, &status);
+  if (U_SUCCESS(status) && len > 0)
+    props.insert("fo:script", component);
+}
+
 } // anonymous namespace
 
 void MSPUBCollector::collectMetaData(const librevenge::RVNGPropertyList &metaData)
@@ -1680,6 +1700,10 @@ librevenge::RVNGPropertyList MSPUBCollector::getCharStyleProps(const CharacterSt
   default:
     break;
   }
+  if (style.lcid)
+    fillLocale(ret, get(style.lcid));
+  else if (defaultCharStyle.lcid)
+    fillLocale(ret, get(defaultCharStyle.lcid));
   return ret;
 }
 
diff --git a/src/lib/MSPUBParser.cpp b/src/lib/MSPUBParser.cpp
index b6d6bbb..8a307eb 100644
--- a/src/lib/MSPUBParser.cpp
+++ b/src/lib/MSPUBParser.cpp
@@ -1465,6 +1465,9 @@ CharacterStyle MSPUBParser::getCharacterStyle(librevenge::RVNGInputStream *input
     case SCALING_ID:
       style.textScale = double(info.data) / 10;
       break;
+    case LOCALE_ID:
+      style.lcid = info.data;
+      break;
     default:
       break;
     }
diff --git a/src/lib/MSPUBTypes.h b/src/lib/MSPUBTypes.h
index ec1aa5c..04219d0 100644
--- a/src/lib/MSPUBTypes.h
+++ b/src/lib/MSPUBTypes.h
@@ -121,6 +121,7 @@ struct CharacterStyle
     , emboss(false)
     , engrave(false)
     , textScale()
+    , lcid()
   {
   }
   boost::optional<Underline> underline;
@@ -137,6 +138,7 @@ struct CharacterStyle
   bool emboss;
   bool engrave;
   boost::optional<double> textScale;
+  boost::optional<unsigned> lcid;
 };
 
 enum LineSpacingType


More information about the Libreoffice-commits mailing list