Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 74.63 KB | None | 0 0
  1. diff --git a/configure.ac b/configure.ac
  2. index 018a540..699954a 100644
  3. --- a/configure.ac
  4. +++ b/configure.ac
  5. @@ -7,7 +7,7 @@ AC_PREREQ([2.65])
  6.  # ====================
  7.  m4_define([libvisio_version_major],[0])
  8.  m4_define([libvisio_version_minor],[0])
  9. -m4_define([libvisio_version_micro],[17])
  10. +m4_define([libvisio_version_micro],[18])
  11.  m4_define([libvisio_version],[libvisio_version_major.libvisio_version_minor.libvisio_version_micro])
  12.  
  13.  # =============
  14. @@ -78,11 +78,13 @@ AS_CASE([$host],
  15.         native_win32=yes
  16.         LIBVISIO_WIN32_RESOURCE=libvisio-win32res.lo
  17.         VSD2RAW_WIN32_RESOURCE=vsd2raw-win32res.lo
  18. +       VSD2TEXT_WIN32_RESOURCE=vsd2raw-win32res.lo
  19.         VSD2XHTML_WIN32_RESOURCE=vsd2xhtml-win32res.lo
  20.     ], [
  21.         native_win32=no
  22.         LIBVISIO_WIN32_RESOURCE=
  23.         VSD2RAW_WIN32_RESOURCE=
  24. +       VSD2TEXT_WIN32_RESOURCE=
  25.         VSD2XHTML_WIN32_RESOURCE=
  26.     ]
  27.  )
  28. @@ -90,6 +92,7 @@ AC_MSG_RESULT([$native_win32])
  29.  AM_CONDITIONAL(OS_WIN32, [test "x$native_win32" = "xyes"])
  30.  AC_SUBST(LIBVISIO_WIN32_RESOURCE)
  31.  AC_SUBST(VSD2RAW_WIN32_RESOURCE)
  32. +AC_SUBST(VSD2TEXT_WIN32_RESOURCE)
  33.  AC_SUBST(VSD2XHTML_WIN32_RESOURCE)
  34.  AC_MSG_CHECKING([for Win32 platform in general])
  35.  AS_CASE([$host],
  36. @@ -132,13 +135,13 @@ AS_IF([test "x$native_win32" = "xyes"], [
  37.             AC_MSG_WARN([produced libraries might be incompatible with MSVC-compiled code])
  38.         ])
  39.     ])
  40. -   CFLAGS="$CFLAGS -Wall -pedantic"
  41. -   CXXFLAGS="$CXXFLAGS -Wall -pedantic"
  42. +   CFLAGS="$CFLAGS -Wall -Wextra -pedantic"
  43. +   CXXFLAGS="$CXXFLAGS -Wall -Wextra -Wshadow -pedantic"
  44.  ], [
  45.     AS_IF([test x"$GCC" = xyes], [
  46.         # Be tough with warnings and produce less careless code
  47. -       CFLAGS="$CFLAGS -Wall -pedantic"
  48. -       CXXFLAGS="$CXXFLAGS -Wall -pedantic -Weffc++"
  49. +       CFLAGS="$CFLAGS -Wall -Wextra -pedantic"
  50. +       CXXFLAGS="$CXXFLAGS -Wall -Wextra -Wshadow -pedantic -Weffc++"
  51.     ])
  52.  ])
  53.  LIBVISIO_CXXFLAGS="$LIBVISIO_CFLAGS"
  54. @@ -154,6 +157,8 @@ AC_ARG_ENABLE([debug],
  55.  )
  56.  AS_IF([test "x$enable_debug" = "xyes"], [
  57.     DEBUG_CXXFLAGS="-DDEBUG -g"
  58. +   CXXFLAGS="$CXXFLAGS -O0"
  59. +   CFLAGS="$CFLAGS -O0"
  60.  ], [
  61.     DEBUG_CXXFLAGS="-DNDEBUG"
  62.  ])
  63. @@ -203,6 +208,8 @@ src/conv/raw/Makefile
  64.  src/conv/raw/vsd2raw.rc
  65.  src/conv/svg/Makefile
  66.  src/conv/svg/vsd2xhtml.rc
  67. +src/conv/text/Makefile
  68. +src/conv/text/vsd2text.rc
  69.  src/lib/Makefile
  70.  src/lib/libvisio.rc
  71.  build/Makefile
  72. diff --git a/src/conv/Makefile.am b/src/conv/Makefile.am
  73. index 2295b76..189bcd4 100644
  74. --- a/src/conv/Makefile.am
  75. +++ b/src/conv/Makefile.am
  76. @@ -1 +1 @@
  77. -SUBDIRS = raw svg
  78. +SUBDIRS = raw svg text
  79. diff --git a/src/conv/text/.gitignore b/src/conv/text/.gitignore
  80. new file mode 100644
  81. index 0000000..e772592
  82. --- /dev/null
  83. +++ b/src/conv/text/.gitignore
  84. @@ -0,0 +1,9 @@
  85. +.deps
  86. +.libs
  87. +*.lo
  88. +*.la
  89. +*.o
  90. +Makefile
  91. +Makefile.in
  92. +vsd2text
  93. +*.rc
  94. diff --git a/src/conv/text/Makefile.am b/src/conv/text/Makefile.am
  95. new file mode 100644
  96. index 0000000..0350218
  97. --- /dev/null
  98. +++ b/src/conv/text/Makefile.am
  99. @@ -0,0 +1,30 @@
  100. +bin_PROGRAMS = vsd2text
  101. +
  102. +AM_CXXFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib $(LIBVISIO_CXXFLAGS) $(DEBUG_CXXFLAGS)
  103. +
  104. +vsd2text_DEPENDENCIES = @VSD2TEXT_WIN32_RESOURCE@
  105. +
  106. +if STATIC_TOOLS
  107. +vsd2text_LDADD = ../../lib/@VSD_OBJDIR@/libvisio-@VSD_MAJOR_VERSION@.@VSD_MINOR_VERSION@.a $(LIBVISIO_LIBS) @VSD2TEXT_WIN32_RESOURCE@
  108. +vsd2text_LDFLAGS = -all-static
  109. +else
  110. +vsd2text_LDADD = ../../lib/libvisio-@VSD_MAJOR_VERSION@.@VSD_MINOR_VERSION@.la $(LIBVISIO_LIBS) @VSD2TEXT_WIN32_RESOURCE@
  111. +endif
  112. +
  113. +vsd2text_SOURCES = \
  114. +   vsd2text.cpp
  115. +
  116. +if OS_WIN32
  117. +
  118. +@VSD2TEXT_WIN32_RESOURCE@ : vsd2text.rc $(vsd2text_OBJECTS)
  119. +   chmod +x $(top_srcdir)/build/win32/*compile-resource
  120. +   WINDRES=@WINDRES@ $(top_srcdir)/build/win32/lt-compile-resource vsd2text.rc @VSD2TEXT_WIN32_RESOURCE@
  121. +endif
  122. +
  123. +EXTRA_DIST = \
  124. +   $(vsd2text_SOURCES) \
  125. +   vsd2text.rc.in
  126. +
  127. +# These may be in the builddir too
  128. +BUILD_EXTRA_DIST = \
  129. +   vsd2text.rc  
  130. diff --git a/src/conv/text/vsd2text.cpp b/src/conv/text/vsd2text.cpp
  131. new file mode 100644
  132. index 0000000..f0e17f9
  133. --- /dev/null
  134. +++ b/src/conv/text/vsd2text.cpp
  135. @@ -0,0 +1,131 @@
  136. +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  137. +/* libvisio
  138. + * Version: MPL 1.1 / GPLv2+ / LGPLv2+
  139. + *
  140. + * The contents of this file are subject to the Mozilla Public License Version
  141. + * 1.1 (the "License"); you may not use this file except in compliance with
  142. + * the License or as specified alternatively below. You may obtain a copy of
  143. + * the License at http://www.mozilla.org/MPL/
  144. + *
  145. + * Software distributed under the License is distributed on an "AS IS" basis,
  146. + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  147. + * for the specific language governing rights and limitations under the
  148. + * License.
  149. + *
  150. + * Major Contributor(s):
  151. + * Copyright (C) 2011 Fridrich Strba <fridrich.strba@bluewin.ch>
  152. + * Copyright (C) 2011 Eilidh McAdam <tibbylickle@gmail.com>
  153. + *
  154. + *
  155. + * All Rights Reserved.
  156. + *
  157. + * For minor contributions see the git repository.
  158. + *
  159. + * Alternatively, the contents of this file may be used under the terms of
  160. + * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
  161. + * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
  162. + * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
  163. + * instead of those above.
  164. + */
  165. +
  166. +#include <stdio.h>
  167. +#include <string.h>
  168. +
  169. +#include "libvisio.h"
  170. +#include <libwpd-stream/libwpd-stream.h>
  171. +#include <libwpd/libwpd.h>
  172. +
  173. +class TextPainter : public libwpg::WPGPaintInterface
  174. +{
  175. +public:
  176. +  TextPainter();
  177. +
  178. +  void startGraphics(const ::WPXPropertyList &) {}
  179. +  void endGraphics() {}
  180. +  void startLayer(const ::WPXPropertyList &) {}
  181. +  void endLayer() {}
  182. +  void startEmbeddedGraphics(const ::WPXPropertyList &) {}
  183. +  void endEmbeddedGraphics() {}
  184. +
  185. +  void setStyle(const ::WPXPropertyList &, const ::WPXPropertyListVector &) {}
  186. +
  187. +  void drawRectangle(const ::WPXPropertyList &) {}
  188. +  void drawEllipse(const ::WPXPropertyList &) {}
  189. +  void drawPolyline(const ::WPXPropertyListVector &) {}
  190. +  void drawPolygon(const ::WPXPropertyListVector &) {}
  191. +  void drawPath(const ::WPXPropertyListVector &) {}
  192. +  void drawGraphicObject(const ::WPXPropertyList &, const ::WPXBinaryData &) {}
  193. +  void startTextObject(const ::WPXPropertyList &, const ::WPXPropertyListVector &) {}
  194. +  void endTextObject() {}
  195. +  void startTextLine(const ::WPXPropertyList &) {}
  196. +  void endTextLine();
  197. +  void startTextSpan(const ::WPXPropertyList &) {}
  198. +  void endTextSpan() {}
  199. +  void insertText(const ::WPXString &str);
  200. +};
  201. +
  202. +TextPainter::TextPainter(): libwpg::WPGPaintInterface()
  203. +{
  204. +}
  205. +
  206. +void TextPainter::insertText(const ::WPXString &str)
  207. +{
  208. +  printf("%s", str.cstr());
  209. +}
  210. +
  211. +void TextPainter::endTextLine()
  212. +{
  213. +  printf("\n");
  214. +}
  215. +
  216. +namespace
  217. +{
  218. +
  219. +int printUsage()
  220. +{
  221. +  printf("Usage: vsd2text [OPTION] <Visio Document File>\n");
  222. +  printf("\n");
  223. +  printf("Options:\n");
  224. +  printf("--help                Shows this help message\n");
  225. +  return -1;
  226. +}
  227. +
  228. +} // anonymous namespace
  229. +
  230. +int main(int argc, char *argv[])
  231. +{
  232. +  if (argc < 2)
  233. +    return printUsage();
  234. +
  235. +  char *file = 0;
  236. +
  237. +  for (int i = 1; i < argc; i++)
  238. +  {
  239. +    if (!file && strncmp(argv[i], "--", 2))
  240. +      file = argv[i];
  241. +    else
  242. +      return printUsage();
  243. +  }
  244. +
  245. +  if (!file)
  246. +    return printUsage();
  247. +
  248. +  WPXFileStream input(file);
  249. +
  250. +  if (!libvisio::VisioDocument::isSupported(&input))
  251. +  {
  252. +    fprintf(stderr, "ERROR: Unsupported file format (unsupported version) or file is encrypted!\n");
  253. +    return 1;
  254. +  }
  255. +
  256. +  TextPainter painter;
  257. +  if (!libvisio::VisioDocument::parse(&input, &painter))
  258. +  {
  259. +    fprintf(stderr, "ERROR: Parsing of document failed!\n");
  260. +    return 1;
  261. +  }
  262. +
  263. +  return 0;
  264. +}
  265. +
  266. +/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
  267. diff --git a/src/conv/text/vsd2text.rc.in b/src/conv/text/vsd2text.rc.in
  268. new file mode 100644
  269. index 0000000..b02bc0a
  270. --- /dev/null
  271. +++ b/src/conv/text/vsd2text.rc.in
  272. @@ -0,0 +1,31 @@
  273. +#include <winver.h>
  274. +
  275. +VS_VERSION_INFO VERSIONINFO
  276. +  FILEVERSION @VSD_MAJOR_VERSION@,@VSD_MINOR_VERSION@,@VSD_MICRO_VERSION@,BUILDNUMBER
  277. +  PRODUCTVERSION @VSD_MAJOR_VERSION@,@VSD_MINOR_VERSION@,@VSD_MICRO_VERSION@,0
  278. +  FILEFLAGSMASK 0
  279. +  FILEFLAGS 0
  280. +  FILEOS VOS__WINDOWS32
  281. +  FILETYPE VFT_APP
  282. +  FILESUBTYPE VFT2_UNKNOWN
  283. +  BEGIN
  284. +    BLOCK "StringFileInfo"
  285. +    BEGIN
  286. +      BLOCK "040904B0"
  287. +      BEGIN
  288. +   VALUE "CompanyName", "The libvisio developer community"
  289. +   VALUE "FileDescription", "vsd2text"
  290. +   VALUE "FileVersion", "@VSD_MAJOR_VERSION@.@VSD_MINOR_VERSION@.@VSD_MICRO_VERSION@.BUILDNUMBER"
  291. +   VALUE "InternalName", "vsd2text"
  292. +   VALUE "LegalCopyright", "Copyright (C) 2011 Fridrich Strba, other contribut0rs"
  293. +   VALUE "OriginalFilename", "vsd2text.exe"
  294. +   VALUE "ProductName", "libvisio"
  295. +   VALUE "ProductVersion", "@VSD_MAJOR_VERSION@.@VSD_MINOR_VERSION@.@VSD_MICRO_VERSION@"
  296. +      END
  297. +    END
  298. +    BLOCK "VarFileInfo"
  299. +    BEGIN
  300. +      VALUE "Translation", 0x409, 1200
  301. +    END
  302. +  END
  303. +
  304. diff --git a/src/lib/VSD11Parser.cpp b/src/lib/VSD11Parser.cpp
  305. index 3f4847f..9d848a8 100644
  306. --- a/src/lib/VSD11Parser.cpp
  307. +++ b/src/lib/VSD11Parser.cpp
  308. @@ -123,7 +123,7 @@ void libvisio::VSD11Parser::readText(WPXInputStream *input)
  309.  
  310.  void libvisio::VSD11Parser::readCharIX(WPXInputStream *input)
  311.  {
  312. -  WPXString fontFace("Arial");
  313. +  VSDXFont fontFace;
  314.    unsigned charCount = readU32(input);
  315.    unsigned short fontID = readU16(input);
  316.    input->seek(1, WPX_SEEK_CUR);  // Color ID
  317. @@ -164,23 +164,20 @@ void libvisio::VSD11Parser::readCharIX(WPXInputStream *input)
  318.    if (fontMod & 4) strikeout = true;
  319.    if (fontMod & 0x20) doublestrikeout = true;
  320.  
  321. -  input->seek(42, WPX_SEEK_CUR);
  322. -  unsigned langId = readU32(input);
  323. -
  324.    if (m_isInStyles)
  325. -    m_collector->collectCharIXStyle(m_header.id, m_header.level, charCount, fontID, fontColour, langId, fontSize,
  326. +    m_collector->collectCharIXStyle(m_header.id, m_header.level, charCount, fontID, fontColour, fontSize,
  327.                                      bold, italic, underline, doubleunderline, strikeout, doublestrikeout,
  328.                                      allcaps, initcaps, smallcaps, superscript, subscript, fontFace);
  329.    else if (m_isStencilStarted)
  330.    {
  331.      VSD_DEBUG_MSG(("Found stencil character style\n"));
  332.      if (!m_stencilShape.m_charStyle)
  333. -      m_stencilShape.m_charStyle= new VSDXCharStyle(charCount, fontID, fontColour, langId, fontSize,
  334. +      m_stencilShape.m_charStyle= new VSDXCharStyle(charCount, fontID, fontColour, fontSize,
  335.            bold, italic, underline, doubleunderline, strikeout, doublestrikeout,
  336.            allcaps, initcaps, smallcaps, superscript, subscript, fontFace);
  337.    }
  338.    else
  339. -    m_charList->addCharIX(m_header.id, m_header.level, charCount, fontID, fontColour, langId, fontSize,
  340. +    m_charList->addCharIX(m_header.id, m_header.level, charCount, fontID, fontColour, fontSize,
  341.                            bold, italic, underline, doubleunderline, strikeout, doublestrikeout,
  342.                            allcaps, initcaps, smallcaps, superscript, subscript, fontFace);
  343.  }
  344. diff --git a/src/lib/VSD6Parser.cpp b/src/lib/VSD6Parser.cpp
  345. index c09543b..2ed034f 100644
  346. --- a/src/lib/VSD6Parser.cpp
  347. +++ b/src/lib/VSD6Parser.cpp
  348. @@ -104,7 +104,7 @@ void libvisio::VSD6Parser::readText(WPXInputStream *input)
  349.  
  350.  void libvisio::VSD6Parser::readCharIX(WPXInputStream *input)
  351.  {
  352. -  WPXString fontFace = "Arial";
  353. +  VSDXFont fontFace;
  354.    unsigned charCount = readU32(input);
  355.    unsigned short fontID = readU16(input);
  356.    input->seek(1, WPX_SEEK_CUR);  // Color ID
  357. @@ -145,23 +145,20 @@ void libvisio::VSD6Parser::readCharIX(WPXInputStream *input)
  358.    if (fontMod & 4) strikeout = true;
  359.    if (fontMod & 0x20) doublestrikeout = true;
  360.  
  361. -  input->seek(42, WPX_SEEK_CUR);
  362. -  unsigned langId = readU32(input);
  363. -
  364.    if (m_isInStyles)
  365. -    m_collector->collectCharIXStyle(m_header.id, m_header.level, charCount, fontID, fontColour, langId, fontSize,
  366. +    m_collector->collectCharIXStyle(m_header.id, m_header.level, charCount, fontID, fontColour, fontSize,
  367.                                      bold, italic, underline, doubleunderline, strikeout, doublestrikeout,
  368.                                      allcaps, initcaps, smallcaps, superscript, subscript, fontFace);
  369.    else if (m_isStencilStarted)
  370.    {
  371.      VSD_DEBUG_MSG(("Found stencil character style\n"));
  372.      if (!m_stencilShape.m_charStyle)
  373. -      m_stencilShape.m_charStyle= new VSDXCharStyle(charCount, fontID, fontColour, langId, fontSize,
  374. +      m_stencilShape.m_charStyle= new VSDXCharStyle(charCount, fontID, fontColour, fontSize,
  375.            bold, italic, underline, doubleunderline, strikeout, doublestrikeout,
  376.            allcaps, initcaps, smallcaps, superscript, subscript, fontFace);
  377.    }
  378.    else
  379. -    m_charList->addCharIX(m_header.id, m_header.level, charCount, fontID, fontColour, langId, fontSize,
  380. +    m_charList->addCharIX(m_header.id, m_header.level, charCount, fontID, fontColour, fontSize,
  381.                            bold, italic, underline, doubleunderline, strikeout, doublestrikeout,
  382.                            allcaps, initcaps, smallcaps, superscript, subscript, fontFace);
  383.  }
  384. diff --git a/src/lib/VSDSVGGenerator.cpp b/src/lib/VSDSVGGenerator.cpp
  385. index d4072b4..b39779a 100644
  386. --- a/src/lib/VSDSVGGenerator.cpp
  387. +++ b/src/lib/VSDSVGGenerator.cpp
  388. @@ -336,7 +336,9 @@ void libvisio::VSDSVGGenerator::setStyle(const ::WPXPropertyList &propList, cons
  389.  
  390.  void libvisio::VSDSVGGenerator::startLayer(const ::WPXPropertyList &propList)
  391.  {
  392. -  m_outputSink << "<svg:g id=\"Layer" << propList["svg:id"]->getInt() << "\"";
  393. +  m_outputSink << "<svg:g";
  394. +  if (propList["svg:id"])
  395. +    m_outputSink << " id=\"Layer" << propList["svg:id"]->getInt() << "\"";
  396.    if (propList["svg:fill-rule"])
  397.      m_outputSink << " fill-rule=\"" << propList["svg:fill-rule"]->getStr().cstr() << "\"";
  398.    m_outputSink << " >\n";
  399. @@ -505,7 +507,6 @@ void libvisio::VSDSVGGenerator::startTextObject(const ::WPXPropertyList &propLis
  400.  {
  401.    double x = 0.0;
  402.    double y = 0.0;
  403. -  double width = 0.0;
  404.    double height = 0.0;
  405.    m_outputSink << "<svg:text ";
  406.    if (propList["svg:x"] && propList["svg:y"])
  407. @@ -519,7 +520,7 @@ void libvisio::VSDSVGGenerator::startTextObject(const ::WPXPropertyList &propLis
  408.  
  409.    if (propList["svg:width"])
  410.    {
  411. -    width = propList["svg:width"]->getDouble();
  412. +    double width = propList["svg:width"]->getDouble();
  413.      xmiddle += width / 2.0;
  414.    }
  415.  
  416. diff --git a/src/lib/VSDStringVector.cpp b/src/lib/VSDStringVector.cpp
  417. index 26bb5cd..ae3a9e0 100644
  418. --- a/src/lib/VSDStringVector.cpp
  419. +++ b/src/lib/VSDStringVector.cpp
  420. @@ -59,6 +59,9 @@ libvisio::VSDStringVector::~VSDStringVector()
  421.  
  422.  libvisio::VSDStringVector &libvisio::VSDStringVector::operator=(const VSDStringVector &vec)
  423.  {
  424. +  // Check for self-assignment
  425. +  if (this == &vec)
  426. +    return *this;
  427.    if (m_pImpl)
  428.      delete m_pImpl;
  429.    m_pImpl = new VSDStringVectorImpl(*(vec.m_pImpl));
  430. diff --git a/src/lib/VSDXCharacterList.cpp b/src/lib/VSDXCharacterList.cpp
  431. index b88cf20..6aa2edc 100644
  432. --- a/src/lib/VSDXCharacterList.cpp
  433. +++ b/src/lib/VSDXCharacterList.cpp
  434. @@ -46,12 +46,12 @@ public:
  435.  class VSDXCharIX : public VSDXCharacterListElement
  436.  {
  437.  public:
  438. -  VSDXCharIX(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, unsigned langId,
  439. -             double fontSize, bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
  440. -             bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, WPXString fontFace) :
  441. -    m_id(id), m_level(level), m_charCount(charCount), m_fontID(fontID), m_fontColour(fontColour), m_langId(langId),
  442. -    m_fontSize(fontSize), m_bold(bold), m_italic(italic), m_underline(underline), m_doubleunderline(doubleunderline),
  443. -    m_strikeout(strikeout), m_doublestrikeout(doublestrikeout), m_allcaps(allcaps), m_initcaps(initcaps), m_smallcaps(smallcaps),
  444. +  VSDXCharIX(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, double fontSize,
  445. +             bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
  446. +             bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, VSDXFont fontFace) :
  447. +    m_id(id), m_level(level), m_charCount(charCount), m_fontID(fontID), m_fontColour(fontColour), m_fontSize(fontSize),
  448. +    m_bold(bold), m_italic(italic), m_underline(underline), m_doubleunderline(doubleunderline), m_strikeout(strikeout),
  449. +    m_doublestrikeout(doublestrikeout), m_allcaps(allcaps), m_initcaps(initcaps), m_smallcaps(smallcaps),
  450.      m_superscript(superscript), m_subscript(subscript), m_fontFace(fontFace) {}
  451.    ~VSDXCharIX() {}
  452.    void handle(VSDXCollector *collector);
  453. @@ -61,25 +61,24 @@ private:
  454.    unsigned m_charCount;
  455.    unsigned short m_fontID;
  456.    Colour m_fontColour;
  457. -  unsigned m_langId;
  458.    double m_fontSize;
  459.    bool m_bold, m_italic, m_underline, m_doubleunderline, m_strikeout, m_doublestrikeout;
  460.    bool m_allcaps, m_initcaps, m_smallcaps, m_superscript, m_subscript;
  461. -  WPXString m_fontFace;
  462. +  VSDXFont m_fontFace;
  463.  };
  464.  } // namespace libvisio
  465.  
  466.  
  467.  void libvisio::VSDXCharIX::handle(VSDXCollector *collector)
  468.  {
  469. -  collector->collectVSDXCharStyle(m_id, m_level, m_charCount, m_fontID, m_fontColour, m_langId, m_fontSize, m_bold, m_italic, m_underline,
  470. +  collector->collectVSDXCharStyle(m_id, m_level, m_charCount, m_fontID, m_fontColour, m_fontSize, m_bold, m_italic, m_underline,
  471.                                    m_doubleunderline, m_strikeout, m_doublestrikeout, m_allcaps, m_initcaps, m_smallcaps,
  472.                                    m_superscript, m_subscript, m_fontFace);
  473.  }
  474.  
  475.  libvisio::VSDXCharacterListElement *libvisio::VSDXCharIX::clone()
  476.  {
  477. -  return new VSDXCharIX(m_id, m_level, m_charCount, m_fontID, m_fontColour, m_langId, m_fontSize, m_bold, m_italic, m_underline,
  478. +  return new VSDXCharIX(m_id, m_level, m_charCount, m_fontID, m_fontColour, m_fontSize, m_bold, m_italic, m_underline,
  479.                          m_doubleunderline, m_strikeout, m_doublestrikeout, m_allcaps, m_initcaps, m_smallcaps,
  480.                          m_superscript, m_subscript, m_fontFace);
  481.  }
  482. @@ -115,11 +114,11 @@ libvisio::VSDXCharacterList::~VSDXCharacterList()
  483.    clear();
  484.  }
  485.  
  486. -void libvisio::VSDXCharacterList::addCharIX(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, unsigned langId,
  487. +void libvisio::VSDXCharacterList::addCharIX(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour,
  488.      double fontSize, bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
  489. -    bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, WPXString fontFace)
  490. +    bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, VSDXFont fontFace)
  491.  {
  492. -  m_elements[id] = new VSDXCharIX(id, level, charCount, fontID, fontColour, langId, fontSize, bold, italic, underline, doubleunderline,
  493. +  m_elements[id] = new VSDXCharIX(id, level, charCount, fontID, fontColour, fontSize, bold, italic, underline, doubleunderline,
  494.                                    strikeout, doublestrikeout, allcaps, initcaps, smallcaps, superscript, subscript, fontFace);
  495.  }
  496.  
  497. diff --git a/src/lib/VSDXCharacterList.h b/src/lib/VSDXCharacterList.h
  498. index bd737c5..1ceed63 100644
  499. --- a/src/lib/VSDXCharacterList.h
  500. +++ b/src/lib/VSDXCharacterList.h
  501. @@ -33,6 +33,7 @@
  502.  
  503.  #include <vector>
  504.  #include <map>
  505. +#include "VSDXTypes.h"
  506.  
  507.  namespace libvisio
  508.  {
  509. @@ -47,15 +48,15 @@ public:
  510.    VSDXCharacterList(const VSDXCharacterList &charList);
  511.    ~VSDXCharacterList();
  512.    VSDXCharacterList &operator=(const VSDXCharacterList &charList);
  513. -  void addCharIX(unsigned id, unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, unsigned langId, double fontSize,
  514. +  void addCharIX(unsigned id, unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, double fontSize,
  515.                   bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
  516. -                 bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, WPXString fontFace);
  517. +                 bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, VSDXFont fontFace);
  518.    void setElementsOrder(const std::vector<unsigned> &m_elementsOrder);
  519.    void handle(VSDXCollector *collector);
  520.    void clear();
  521.    bool empty() const
  522.    {
  523. -    return (!m_elements.size());
  524. +    return (m_elements.empty());
  525.    }
  526.  private:
  527.    std::map<unsigned, VSDXCharacterListElement *> m_elements;
  528. diff --git a/src/lib/VSDXCollector.h b/src/lib/VSDXCollector.h
  529. index 615fedf..5bf198f 100644
  530. --- a/src/lib/VSDXCollector.h
  531. +++ b/src/lib/VSDXCollector.h
  532. @@ -83,9 +83,9 @@ public:
  533.    virtual void collectColours(const std::vector<Colour> &colours) = 0;
  534.    virtual void collectFont(unsigned short fontID, const ::WPXBinaryData &textStream, TextFormat format) = 0;
  535.    virtual void collectText(unsigned id, unsigned level, const ::WPXBinaryData &textStream, TextFormat format) = 0;
  536. -  virtual void collectVSDXCharStyle(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, unsigned langId,
  537. -                                    double fontSize, bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
  538. -                                    bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, WPXString fontFace) = 0;
  539. +  virtual void collectVSDXCharStyle(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, double fontSize,
  540. +                                    bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
  541. +                                    bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, VSDXFont fontFace) = 0;
  542.    virtual void collectVSDXParaStyle(unsigned id , unsigned level, unsigned charCount, double indFirst, double indLeft, double indRight,
  543.                                      double spLine, double spBefore, double spAfter, unsigned char align, unsigned flags) = 0;
  544.    virtual void collectTextBlock(unsigned id, unsigned level, double leftMargin, double rightMargin, double topMargin, double bottomMargin,
  545. @@ -102,9 +102,9 @@ public:
  546.                                  double shadowOffsetX, double shadowOffsetY) = 0;
  547.    virtual void collectFillStyle(unsigned id, unsigned level, unsigned char colourIndexFG, unsigned char colourIndexBG, unsigned char fillPattern,
  548.                                  unsigned char fillFGTransparency, unsigned char fillBGTransparency, unsigned char shadowPattern, Colour shfgc) = 0;
  549. -  virtual void collectCharIXStyle(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, unsigned langId,
  550. -                                  double fontSize, bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
  551. -                                  bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, WPXString fontFace) = 0;
  552. +  virtual void collectCharIXStyle(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, double fontSize,
  553. +                                  bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
  554. +                                  bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, VSDXFont fontFace) = 0;
  555.    virtual void collectParaIXStyle(unsigned id , unsigned level, unsigned charCount, double indFirst, double indLeft, double indRight,
  556.                                    double spLine, double spBefore, double spAfter, unsigned char align, unsigned flags) = 0;
  557.    virtual void collectTextBlockStyle(unsigned id, unsigned level, double leftMargin, double rightMargin, double topMargin, double bottomMargin,
  558. diff --git a/src/lib/VSDXContentCollector.cpp b/src/lib/VSDXContentCollector.cpp
  559. index ec25fb4..d1ae0b6 100644
  560. --- a/src/lib/VSDXContentCollector.cpp
  561. +++ b/src/lib/VSDXContentCollector.cpp
  562. @@ -28,6 +28,7 @@
  563.   * instead of those above.
  564.   */
  565.  
  566. +#include <string.h> // for memcpy
  567.  #include <stack>
  568.  #include <boost/spirit/include/classic.hpp>
  569.  
  570. @@ -46,6 +47,62 @@ static unsigned bitmapId = 0;
  571.  #define M_PI 3.14159265358979323846
  572.  #endif
  573.  
  574. +#define SURROGATE_VALUE(h,l) (((h) - 0xd800) * 0x400 + (l) - 0xdc00 + 0x10000)
  575. +
  576. +namespace
  577. +{
  578. +
  579. +static void _appendUCS4(WPXString &text, unsigned ucs4Character)
  580. +{
  581. +  unsigned char first;
  582. +  int len;
  583. +  if (ucs4Character < 0x80)
  584. +  {
  585. +    first = 0;
  586. +    len = 1;
  587. +  }
  588. +  else if (ucs4Character < 0x800)
  589. +  {
  590. +    first = 0xc0;
  591. +    len = 2;
  592. +  }
  593. +  else if (ucs4Character < 0x10000)
  594. +  {
  595. +    first = 0xe0;
  596. +    len = 3;
  597. +  }
  598. +  else if (ucs4Character < 0x200000)
  599. +  {
  600. +    first = 0xf0;
  601. +    len = 4;
  602. +  }
  603. +  else if (ucs4Character < 0x4000000)
  604. +  {
  605. +    first = 0xf8;
  606. +    len = 5;
  607. +  }
  608. +  else
  609. +  {
  610. +    first = 0xfc;
  611. +    len = 6;
  612. +  }
  613. +
  614. +  unsigned char outbuf[6] = { 0, 0, 0, 0, 0, 0 };
  615. +  int i;
  616. +  for (i = len - 1; i > 0; --i)
  617. +  {
  618. +    outbuf[i] = (ucs4Character & 0x3f) | 0x80;
  619. +    ucs4Character >>= 6;
  620. +  }
  621. +  outbuf[0] = (ucs4Character & 0xff) | first;
  622. +
  623. +  for (i = 0; i < len; i++)
  624. +    text.append(outbuf[i]);
  625. +}
  626. +
  627. +} // anonymous namespace
  628. +
  629. +
  630.  libvisio::VSDXContentCollector::VSDXContentCollector(
  631.    libwpg::WPGPaintInterface *painter,
  632.    std::vector<std::map<unsigned, XForm> > &groupXFormsSequence,
  633. @@ -91,7 +148,12 @@ void libvisio::VSDXContentCollector::_fillAndShadowProperties(unsigned colourInd
  634.    else if (m_fillPattern == 1)
  635.    {
  636.      m_fillType = "solid";
  637. -    m_styleProps.insert("draw:fill-color", getColourString(m_colours[colourIndexFG]));
  638. +    if (colourIndexFG < m_colours.size())
  639. +      m_styleProps.insert("draw:fill-color", getColourString(m_colours[colourIndexFG]));
  640. +#ifdef DEBUG
  641. +    else
  642. +      VSD_DEBUG_MSG(("_fillAndShadowProperties: colourIndexFG out of bonds\n"));
  643. +#endif
  644.      if (m_fillFGTransparency > 0)
  645.        m_styleProps.insert("draw:opacity", (double)(1 - m_fillFGTransparency/255.0), WPX_PERCENT);
  646.      else
  647. @@ -101,8 +163,18 @@ void libvisio::VSDXContentCollector::_fillAndShadowProperties(unsigned colourInd
  648.    {
  649.      m_fillType = "gradient";
  650.      m_styleProps.insert("draw:style", "axial");
  651. -    m_styleProps.insert("draw:start-color", getColourString(m_colours[colourIndexFG]));
  652. -    m_styleProps.insert("draw:end-color", getColourString(m_colours[colourIndexBG]));
  653. +    if (colourIndexFG < m_colours.size())
  654. +      m_styleProps.insert("draw:start-color", getColourString(m_colours[colourIndexFG]));
  655. +#ifdef DEBUG
  656. +    else
  657. +      VSD_DEBUG_MSG(("_fillAndShadowProperties: colourIndexFG out of bonds\n"));
  658. +#endif
  659. +    if (colourIndexBG < m_colours.size())
  660. +      m_styleProps.insert("draw:end-color", getColourString(m_colours[colourIndexBG]));
  661. +#ifdef DEBUG
  662. +    else
  663. +      VSD_DEBUG_MSG(("_fillAndShadowProperties: colourIndexBG out of bonds\n"));
  664. +#endif
  665.      m_styleProps.remove("draw:opacity");
  666.      if (m_fillBGTransparency > 0)
  667.        m_styleProps.insert("libwpg:start-opacity", (double)(1 - m_fillBGTransparency/255.0), WPX_PERCENT);
  668. @@ -123,8 +195,18 @@ void libvisio::VSDXContentCollector::_fillAndShadowProperties(unsigned colourInd
  669.    {
  670.      m_fillType = "gradient";
  671.      m_styleProps.insert("draw:style", "linear");
  672. -    m_styleProps.insert("draw:start-color", getColourString(m_colours[colourIndexBG]));
  673. -    m_styleProps.insert("draw:end-color", getColourString(m_colours[colourIndexFG]));
  674. +    if (colourIndexBG < m_colours.size())
  675. +      m_styleProps.insert("draw:start-color", getColourString(m_colours[colourIndexBG]));
  676. +#ifdef DEBUG
  677. +    else
  678. +      VSD_DEBUG_MSG(("_fillAndShadowProperties: colourIndexBG out of bonds\n"));
  679. +#endif
  680. +    if (colourIndexFG < m_colours.size())
  681. +      m_styleProps.insert("draw:end-color", getColourString(m_colours[colourIndexFG]));
  682. +#ifdef DEBUG
  683. +    else
  684. +      VSD_DEBUG_MSG(("_fillAndShadowProperties: colourIndexFG out of bonds\n"));
  685. +#endif
  686.      m_styleProps.remove("draw:opacity");
  687.      if (m_fillBGTransparency > 0)
  688.        m_styleProps.insert("libwpg:start-opacity", (double)(1 - m_fillBGTransparency/255.0), WPX_PERCENT);
  689. @@ -170,8 +252,18 @@ void libvisio::VSDXContentCollector::_fillAndShadowProperties(unsigned colourInd
  690.      m_styleProps.insert("draw:style", "rectangular");
  691.      m_styleProps.insert("svg:cx", 0.5, WPX_PERCENT);
  692.      m_styleProps.insert("svg:cy", 0.5, WPX_PERCENT);
  693. -    m_styleProps.insert("draw:start-color", getColourString(m_colours[colourIndexBG]));
  694. -    m_styleProps.insert("draw:end-color", getColourString(m_colours[colourIndexFG]));
  695. +    if (colourIndexBG < m_colours.size())
  696. +      m_styleProps.insert("draw:start-color", getColourString(m_colours[colourIndexBG]));
  697. +#ifdef DEBUG
  698. +    else
  699. +      VSD_DEBUG_MSG(("_fillAndShadowProperties: colourIndexBG out of bonds\n"));
  700. +#endif
  701. +    if (colourIndexFG < m_colours.size())
  702. +      m_styleProps.insert("draw:end-color", getColourString(m_colours[colourIndexFG]));
  703. +#ifdef DEBUG
  704. +    else
  705. +      VSD_DEBUG_MSG(("_fillAndShadowProperties: colourIndexFG out of bonds\n"));
  706. +#endif
  707.      m_styleProps.remove("draw:opacity");
  708.      if (m_fillBGTransparency > 0)
  709.        m_styleProps.insert("libwpg:start-opacity", (double)(1 - m_fillBGTransparency/255.0), WPX_PERCENT);
  710. @@ -188,8 +280,18 @@ void libvisio::VSDXContentCollector::_fillAndShadowProperties(unsigned colourInd
  711.    {
  712.      m_fillType = "gradient";
  713.      m_styleProps.insert("draw:style", "radial");
  714. -    m_styleProps.insert("draw:start-color", getColourString(m_colours[colourIndexBG]));
  715. -    m_styleProps.insert("draw:end-color", getColourString(m_colours[colourIndexFG]));
  716. +    if (colourIndexBG < m_colours.size())
  717. +      m_styleProps.insert("draw:start-color", getColourString(m_colours[colourIndexBG]));
  718. +#ifdef DEBUG
  719. +    else
  720. +      VSD_DEBUG_MSG(("_fillAndShadowProperties: colourIndexBG out of bonds\n"));
  721. +#endif
  722. +    if (colourIndexFG < m_colours.size())
  723. +      m_styleProps.insert("draw:end-color", getColourString(m_colours[colourIndexFG]));
  724. +#ifdef DEBUG
  725. +    else
  726. +      VSD_DEBUG_MSG(("_fillAndShadowProperties: colourIndexFG out of bonds\n"));
  727. +#endif
  728.      m_styleProps.remove("draw:opacity");
  729.      if (m_fillBGTransparency > 0)
  730.        m_styleProps.insert("libwpg:start-opacity", (double)(1 - m_fillBGTransparency/255.0), WPX_PERCENT);
  731. @@ -229,7 +331,12 @@ void libvisio::VSDXContentCollector::_fillAndShadowProperties(unsigned colourInd
  732.      // fill types we don't handle right, but let us approximate with solid fill
  733.    {
  734.      m_fillType = "solid";
  735. -    m_styleProps.insert("draw:fill-color", getColourString(m_colours[colourIndexBG]));
  736. +    if (colourIndexBG < m_colours.size())
  737. +      m_styleProps.insert("draw:fill-color", getColourString(m_colours[colourIndexBG]));
  738. +#ifdef DEBUG
  739. +    else
  740. +      VSD_DEBUG_MSG(("_fillAndShadowProperties: colourIndexBG out of bonds\n"));
  741. +#endif
  742.    }
  743.  
  744.    if (shadowPattern != 0)
  745. @@ -574,8 +681,6 @@ void libvisio::VSDXContentCollector::_flushCurrentPath()
  746.    fillPathProps.insert("draw:stroke", "none");
  747.    WPXPropertyList linePathProps(m_styleProps);
  748.    linePathProps.insert("draw:fill", "none");
  749. -  bool firstPoint = true;
  750. -  bool wasMove = false;
  751.    bool needsGroup = true;
  752.  
  753.    if (!m_styleProps["draw:fill"] || m_styleProps["draw:fill"]->getStr() == "none")
  754. @@ -592,6 +697,8 @@ void libvisio::VSDXContentCollector::_flushCurrentPath()
  755.  
  756.    if (m_styleProps["draw:fill"] && m_styleProps["draw:fill"]->getStr() != "none")
  757.    {
  758. +    bool firstPoint = true;
  759. +    bool wasMove = false;
  760.      for (unsigned i = 0; i < m_currentFillGeometry.size(); i++)
  761.      {
  762.        if (firstPoint)
  763. @@ -770,50 +877,24 @@ void libvisio::VSDXContentCollector::_flushText()
  764.      m_shapeOutputText->addStartTextLine(paraProps);
  765.  
  766.      paraCharCount = (*paraIt).charCount;
  767. +
  768. +    TextFormat encoding = libvisio::VSD_TEXT_ANSI;
  769.      // Find char format that overlaps
  770.      while (charIndex < m_charFormats.size() && paraCharCount)
  771.      {
  772.        paraCharCount -= m_charFormats[charIndex].charCount;
  773.  
  774. -      WPXString text;
  775. -
  776. -      if (m_textFormat == VSD_TEXT_UTF16)
  777. +      WPXPropertyList textProps;
  778. +      if (m_fonts[m_charFormats[charIndex].faceID].name == "")
  779.        {
  780. -        unsigned long max = m_charFormats[charIndex].charCount <= (m_textStream.size()/2) ? m_charFormats[charIndex].charCount : (m_textStream.size()/2);
  781. -        VSD_DEBUG_MSG(("Charcount: %d, max: %lu, stream size: %lu\n", m_charFormats[charIndex].charCount, max, (unsigned long)m_textStream.size()));
  782. -        max = (m_charFormats[charIndex].charCount == 0 && m_textStream.size()) ? m_textStream.size()/2 : max;
  783. -        VSD_DEBUG_MSG(("Charcount: %d, max: %lu, stream size: %lu\n", m_charFormats[charIndex].charCount, max, (unsigned long)m_textStream.size()));
  784. -        VSDInternalStream tmpStream(&pTextBuffer[textBufferPosition], max*2);
  785. -        _appendUTF16LE(text, &tmpStream);
  786. -        textBufferPosition += max*2;
  787. +        textProps.insert("style:font-name", m_charFormats[charIndex].face.name);
  788. +        encoding = m_charFormats[charIndex].face.encoding;
  789.        }
  790.        else
  791.        {
  792. -        unsigned long max = m_charFormats[charIndex].charCount <= m_textStream.size() ? m_charFormats[charIndex].charCount : m_textStream.size();
  793. -        max = (m_charFormats[charIndex].charCount == 0 && m_textStream.size()) ? m_textStream.size() : max;
  794. -        VSDInternalStream tmpStream(&pTextBuffer[textBufferPosition], max);
  795. -        while (!tmpStream.atEOS())
  796. -        {
  797. -          unsigned char character = readU8(&tmpStream);
  798. -          if (character == 0x1e)
  799. -          {
  800. -            if (m_fieldIndex < m_fields.size())
  801. -              text.append(m_fields[m_fieldIndex++].cstr());
  802. -            else
  803. -              m_fieldIndex++;
  804. -          }
  805. -          else if (character <= 0x20)
  806. -            _appendUCS4(text, (unsigned) 0x20);
  807. -          else
  808. -            _appendUCS4(text, (unsigned) character);
  809. -        }
  810. -        textBufferPosition += max;
  811. +        textProps.insert("style:font-name", m_fonts[m_charFormats[charIndex].faceID].name);
  812. +        encoding = m_fonts[m_charFormats[charIndex].faceID].encoding;
  813.        }
  814. -      WPXPropertyList textProps;
  815. -      if (m_fonts[m_charFormats[charIndex].faceID] == "")
  816. -        textProps.insert("style:font-name", m_charFormats[charIndex].face);
  817. -      else
  818. -        textProps.insert("style:font-name", m_fonts[m_charFormats[charIndex].faceID]);
  819.  
  820.        if (m_charFormats[charIndex].bold) textProps.insert("fo:font-weight", "bold");
  821.        if (m_charFormats[charIndex].italic) textProps.insert("fo:font-style", "italic");
  822. @@ -843,6 +924,29 @@ void libvisio::VSDXContentCollector::_flushText()
  823.  #endif
  824.        }
  825.  
  826. +      WPXString text;
  827. +
  828. +      if (m_textFormat == VSD_TEXT_UTF16)
  829. +      {
  830. +        unsigned long max = m_charFormats[charIndex].charCount <= (m_textStream.size()/2) ? m_charFormats[charIndex].charCount : (m_textStream.size()/2);
  831. +        VSD_DEBUG_MSG(("Charcount: %d, max: %lu, stream size: %lu\n", m_charFormats[charIndex].charCount, max, (unsigned long)m_textStream.size()));
  832. +        max = (m_charFormats[charIndex].charCount == 0 && m_textStream.size()) ? m_textStream.size()/2 : max;
  833. +        VSD_DEBUG_MSG(("Charcount: %d, max: %lu, stream size: %lu\n", m_charFormats[charIndex].charCount, max, (unsigned long)m_textStream.size()));
  834. +        std::vector<unsigned char> tmpBuffer(max*2);
  835. +        memcpy(&tmpBuffer[0], &pTextBuffer[textBufferPosition], max*2);
  836. +        appendCharacters(text, tmpBuffer);
  837. +        textBufferPosition += max*2;
  838. +      }
  839. +      else
  840. +      {
  841. +        unsigned long max = m_charFormats[charIndex].charCount <= m_textStream.size() ? m_charFormats[charIndex].charCount : m_textStream.size();
  842. +        max = (m_charFormats[charIndex].charCount == 0 && m_textStream.size()) ? m_textStream.size() : max;
  843. +        std::vector<unsigned char> tmpBuffer(max);
  844. +        memcpy(&tmpBuffer[0], &pTextBuffer[textBufferPosition], max);
  845. +        appendCharacters(text, tmpBuffer, encoding);
  846. +        textBufferPosition += max;
  847. +      }
  848. +
  849.        VSD_DEBUG_MSG(("Text: %s\n", text.cstr()));
  850.        m_shapeOutputText->addStartTextSpan(textProps);
  851.        m_shapeOutputText->addInsertText(text);
  852. @@ -1131,14 +1235,17 @@ void libvisio::VSDXContentCollector::collectInfiniteLine(unsigned /* id */, unsi
  853.      if (x <= m_pageWidth && x >= 0)
  854.        points[x] = y;
  855.  
  856. -    xmove = points.begin()->first;
  857. -    ymove = points.begin()->second;
  858. -    for (std::map<double, double>::iterator iter = points.begin(); iter != points.end(); ++iter)
  859. +    if (!points.empty())
  860.      {
  861. -      if (iter->first != xmove || iter->second != ymove)
  862. +      xmove = points.begin()->first;
  863. +      ymove = points.begin()->second;
  864. +      for (std::map<double, double>::iterator iter = points.begin(); iter != points.end(); ++iter)
  865.        {
  866. -        xline = iter->first;
  867. -        yline = iter->second;
  868. +        if (iter->first != xmove || iter->second != ymove)
  869. +        {
  870. +          xline = iter->first;
  871. +          yline = iter->second;
  872. +        }
  873.        }
  874.      }
  875.    }
  876. @@ -1429,7 +1536,10 @@ void libvisio::VSDXContentCollector::collectNURBSTo(unsigned /* id */, unsigned
  877.  
  878.    // Fill in end knots
  879.    while (knotVector.size() < (controlPoints.size() + degree + 2))
  880. -    knotVector.push_back(knotVector.back());
  881. +  {
  882. +    double tmpBack = knotVector.back();
  883. +    knotVector.push_back(tmpBack);
  884. +  }
  885.  
  886.    // Convert control points to static co-ordinates
  887.    for (std::vector<std::pair<double, double> >::iterator it = controlPoints.begin();
  888. @@ -1598,6 +1708,7 @@ void libvisio::VSDXContentCollector::collectPolylineTo(unsigned /* id */ , unsig
  889.  void libvisio::VSDXContentCollector::collectPolylineTo(unsigned id, unsigned level, double x, double y, unsigned dataID)
  890.  {
  891.    std::map<unsigned, PolylineData>::const_iterator iter;
  892. +  std::map<unsigned, PolylineData>::const_iterator iterEnd;
  893.    if (dataID == 0xFFFFFFFE) // Use stencil polyline data
  894.    {
  895.      if (!m_stencilShape || m_stencilShape->m_geometries.size() < m_currentGeometryCount)
  896. @@ -1610,13 +1721,15 @@ void libvisio::VSDXContentCollector::collectPolylineTo(unsigned id, unsigned lev
  897.      VSDXGeometryListElement *element = m_stencilShape->m_geometries[m_currentGeometryCount-1].getElement(id);
  898.      dataID = dynamic_cast<VSDXPolylineTo2 *>(element)->m_dataID;
  899.      iter = m_stencilShape->m_polylineData.find(dataID);
  900. +    iterEnd = m_stencilShape->m_polylineData.end();
  901.    }
  902.    else // No stencils involved, directly get dataID
  903.    {
  904.      iter = m_polylineData.find(dataID);
  905. +    iterEnd = m_polylineData.end();
  906.    }
  907.  
  908. -  if (iter != m_polylineData.end())
  909. +  if (iter != iterEnd)
  910.    {
  911.      PolylineData data = iter->second;
  912.      collectPolylineTo(id, level, x, y, data.xType, data.yType, data.points);
  913. @@ -1969,9 +2082,10 @@ void libvisio::VSDXContentCollector::collectColours(const std::vector<Colour> &c
  914.  
  915.  void libvisio::VSDXContentCollector::collectFont(unsigned short fontID, const WPXBinaryData &textStream, TextFormat format)
  916.  {
  917. -  WPXString fontname;
  918. -  _convertDataToString(fontname, textStream, format);
  919. -  m_fonts[fontID] = fontname;
  920. +  VSDXFont font;
  921. +  _convertDataToString(font.name, textStream, format);
  922. +  font.encoding = format;
  923. +  m_fonts[fontID] = font;
  924.  }
  925.  
  926.  
  927. @@ -1998,7 +2112,7 @@ void libvisio::VSDXContentCollector::collectSplineKnot(unsigned /* id */, unsign
  928.  
  929.  void libvisio::VSDXContentCollector::collectSplineEnd()
  930.  {
  931. -  if (!m_splineKnotVector.size() || !m_splineControlPoints.size())
  932. +  if (m_splineKnotVector.empty() || m_splineControlPoints.empty())
  933.    {
  934.      m_splineKnotVector.clear();
  935.      m_splineControlPoints.clear();
  936. @@ -2030,13 +2144,13 @@ void libvisio::VSDXContentCollector::collectVSDXParaStyle(unsigned /* id */ , un
  937.    m_paraFormats.push_back(format);
  938.  }
  939.  
  940. -void libvisio::VSDXContentCollector::collectVSDXCharStyle(unsigned /*id*/ , unsigned level, unsigned charCount, unsigned short fontID,
  941. -    Colour fontColour, unsigned langId, double fontSize, bool bold, bool italic,
  942. +void libvisio::VSDXContentCollector::collectVSDXCharStyle(unsigned /*id*/ , unsigned level, unsigned charCount,
  943. +    unsigned short fontID, Colour fontColour, double fontSize, bool bold, bool italic,
  944.      bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
  945. -    bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, WPXString fontFace)
  946. +    bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, VSDXFont fontFace)
  947.  {
  948.    _handleLevelChange(level);
  949. -  VSDXCharStyle format(charCount, fontID, fontColour, langId, fontSize, bold, italic,
  950. +  VSDXCharStyle format(charCount, fontID, fontColour, fontSize, bold, italic,
  951.                         underline, doubleunderline, strikeout, doublestrikeout,
  952.                         allcaps, initcaps, smallcaps, superscript, subscript, fontFace);
  953.    m_charFormats.push_back(format);
  954. @@ -2059,22 +2173,11 @@ void libvisio::VSDXContentCollector::collectNameList(unsigned /*id*/, unsigned l
  955.  
  956.  void libvisio::VSDXContentCollector::_convertDataToString(WPXString &result, const WPXBinaryData &data, TextFormat format)
  957.  {
  958. -  WPXInputStream *pStream = const_cast<WPXInputStream *>(data.getDataStream());
  959. -  if (format == VSD_TEXT_ANSI)
  960. -  {
  961. -    while (!pStream->atEOS())
  962. -    {
  963. -      unsigned char character = readU8(pStream);
  964. -      if (character <= 0x20)
  965. -        _appendUCS4(result, (unsigned) 0x20);
  966. -      else
  967. -        _appendUCS4(result, (unsigned) character);
  968. -    }
  969. -  }
  970. -  else if (format == VSD_TEXT_UTF16)
  971. -  {
  972. -    _appendUTF16LE(result, pStream);
  973. -  }
  974. +  if (!data.size())
  975. +    return;
  976. +  std::vector<unsigned char> tmpData(data.size());
  977. +  memcpy(&tmpData[0], data.getDataBuffer(), data.size());
  978. +  appendCharacters(result, tmpData, format);
  979.  }
  980.  
  981.  void libvisio::VSDXContentCollector::collectName(unsigned id, unsigned level, const WPXBinaryData &name, TextFormat format)
  982. @@ -2106,9 +2209,9 @@ void libvisio::VSDXContentCollector::collectFillStyle(unsigned /*id*/, unsigned
  983.    _handleLevelChange(level);
  984.  }
  985.  
  986. -void libvisio::VSDXContentCollector::collectCharIXStyle(unsigned /*id*/ , unsigned level, unsigned /*charCount*/, unsigned short /*fontID*/, Colour /*fontColour*/, unsigned /*langId*/, double /*fontSize*/,
  987. +void libvisio::VSDXContentCollector::collectCharIXStyle(unsigned /*id*/ , unsigned level, unsigned /*charCount*/, unsigned short /*fontID*/, Colour /*fontColour*/, double /*fontSize*/,
  988.      bool /*bold*/, bool /*italic*/, bool /*underline*/, bool /* doubleunderline */, bool /* strikeout */, bool /* doublestrikeout */,
  989. -    bool /* allcaps */, bool /* initcaps */, bool /* smallcaps */, bool /* superscript */, bool /* subscript */, WPXString /*fontFace*/)
  990. +    bool /* allcaps */, bool /* initcaps */, bool /* smallcaps */, bool /* superscript */, bool /* subscript */, VSDXFont /*fontFace*/)
  991.  {
  992.    _handleLevelChange(level);
  993.  }
  994. @@ -2256,7 +2359,6 @@ void libvisio::VSDXContentCollector::_handleLevelChange(unsigned level)
  995.    m_currentLevel = level;
  996.  }
  997.  
  998. -
  999.  void libvisio::VSDXContentCollector::startPage()
  1000.  {
  1001.    if (m_isShapeStarted)
  1002. @@ -2301,24 +2403,324 @@ void libvisio::VSDXContentCollector::endPages(const std::vector<unsigned> &pageO
  1003.    m_pages.draw(m_painter);
  1004.  }
  1005.  
  1006. -#define SURROGATE_VALUE(h,l) (((h) - 0xd800) * 0x400 + (l) - 0xdc00 + 0x10000)
  1007. +bool libvisio::VSDXContentCollector::parseFormatId( const char *formatString, unsigned short &result )
  1008. +{
  1009. +  using namespace ::boost::spirit::classic;
  1010. +
  1011. +  result = 0xffff;
  1012. +
  1013. +  uint_parser<unsigned short,10,1,5> ushort_p;
  1014. +  if (parse(formatString,
  1015. +            // Begin grammar
  1016. +            (
  1017. +              (
  1018. +                str_p("{<") >>
  1019. +                ushort_p[assign_a(result)]
  1020. +                >> str_p(">}")
  1021. +              )
  1022. +              |
  1023. +              (
  1024. +                str_p("esc(") >>
  1025. +                ushort_p[assign_a(result)]
  1026. +                >> ')'
  1027. +              )
  1028. +            )>> end_p,
  1029. +            // End grammar
  1030. +            space_p).full )
  1031. +  {
  1032. +    return true;
  1033. +  }
  1034. +  return false;
  1035. +}
  1036.  
  1037. -void libvisio::VSDXContentCollector::_appendUTF16LE(WPXString &text, WPXInputStream *input)
  1038. +void libvisio::VSDXContentCollector::appendCharacters(WPXString &text, const std::vector<unsigned char> &characters, TextFormat format)
  1039.  {
  1040. -  while (!input->atEOS())
  1041. +  if (format == VSD_TEXT_UTF16)
  1042. +    return appendCharacters(text, characters);
  1043. +
  1044. +  static const unsigned short cp874map[] =
  1045. +  {
  1046. +    0x20AC, 0x0020, 0x0020, 0x0020, 0x0020, 0x2026, 0x0020, 0x0020,
  1047. +    0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
  1048. +    0x0020, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
  1049. +    0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
  1050. +    0x00A0, 0x0E01, 0x0E02, 0x0E03, 0x0E04, 0x0E05, 0x0E06, 0x0E07,
  1051. +    0x0E08, 0x0E09, 0x0E0A, 0x0E0B, 0x0E0C, 0x0E0D, 0x0E0E, 0x0E0F,
  1052. +    0x0E10, 0x0E11, 0x0E12, 0x0E13, 0x0E14, 0x0E15, 0x0E16, 0x0E17,
  1053. +    0x0E18, 0x0E19, 0x0E1A, 0x0E1B, 0x0E1C, 0x0E1D, 0x0E1E, 0x0E1F,
  1054. +    0x0E20, 0x0E21, 0x0E22, 0x0E23, 0x0E24, 0x0E25, 0x0E26, 0x0E27,
  1055. +    0x0E28, 0x0E29, 0x0E2A, 0x0E2B, 0x0E2C, 0x0E2D, 0x0E2E, 0x0E2F,
  1056. +    0x0E30, 0x0E31, 0x0E32, 0x0E33, 0x0E34, 0x0E35, 0x0E36, 0x0E37,
  1057. +    0x0E38, 0x0E39, 0x0E3A, 0x0020, 0x0020, 0x0020, 0x0020, 0x0E3F,
  1058. +    0x0E40, 0x0E41, 0x0E42, 0x0E43, 0x0E44, 0x0E45, 0x0E46, 0x0E47,
  1059. +    0x0E48, 0x0E49, 0x0E4A, 0x0E4B, 0x0E4C, 0x0E4D, 0x0E4E, 0x0E4F,
  1060. +    0x0E50, 0x0E51, 0x0E52, 0x0E53, 0x0E54, 0x0E55, 0x0E56, 0x0E57,
  1061. +    0x0E58, 0x0E59, 0x0E5A, 0x0E5B, 0x0020, 0x0020, 0x0020, 0x0020
  1062. +  };
  1063. +
  1064. +  static const unsigned short cp1250map[] =
  1065. +  {
  1066. +    0x20AC, 0x0020, 0x201A, 0x0020, 0x201E, 0x2026, 0x2020, 0x2021,
  1067. +    0x0020, 0x2030, 0x0160, 0x2039, 0x015A, 0x0164, 0x017D, 0x0179,
  1068. +    0x0020, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
  1069. +    0x0020, 0x2122, 0x0161, 0x203A, 0x015B, 0x0165, 0x017E, 0x017A,
  1070. +    0x00A0, 0x02C7, 0x02D8, 0x0141, 0x00A4, 0x0104, 0x00A6, 0x00A7,
  1071. +    0x00A8, 0x00A9, 0x015E, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x017B,
  1072. +    0x00B0, 0x00B1, 0x02DB, 0x0142, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
  1073. +    0x00B8, 0x0105, 0x015F, 0x00BB, 0x013D, 0x02DD, 0x013E, 0x017C,
  1074. +    0x0154, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x0139, 0x0106, 0x00C7,
  1075. +    0x010C, 0x00C9, 0x0118, 0x00CB, 0x011A, 0x00CD, 0x00CE, 0x010E,
  1076. +    0x0110, 0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150, 0x00D6, 0x00D7,
  1077. +    0x0158, 0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162, 0x00DF,
  1078. +    0x0155, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7,
  1079. +    0x010D, 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F,
  1080. +    0x0111, 0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7,
  1081. +    0x0159, 0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9
  1082. +  };
  1083. +
  1084. +  static const unsigned short cp1251map[] =
  1085. +  {
  1086. +    0x0402, 0x0403, 0x201A, 0x0453, 0x201E, 0x2026, 0x2020, 0x2021,
  1087. +    0x20AC, 0x2030, 0x0409, 0x2039, 0x040A, 0x040C, 0x040B, 0x040F,
  1088. +    0x0452, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
  1089. +    0x0020, 0x2122, 0x0459, 0x203A, 0x045A, 0x045C, 0x045B, 0x045F,
  1090. +    0x00A0, 0x040E, 0x045E, 0x0408, 0x00A4, 0x0490, 0x00A6, 0x00A7,
  1091. +    0x0401, 0x00A9, 0x0404, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x0407,
  1092. +    0x00B0, 0x00B1, 0x0406, 0x0456, 0x0491, 0x00B5, 0x00B6, 0x00B7,
  1093. +    0x0451, 0x2116, 0x0454, 0x00BB, 0x0458, 0x0405, 0x0455, 0x0457,
  1094. +    0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
  1095. +    0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
  1096. +    0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
  1097. +    0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
  1098. +    0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
  1099. +    0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
  1100. +    0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,
  1101. +    0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F
  1102. +  };
  1103. +
  1104. +  static const unsigned short cp1252map[] =
  1105. +  {
  1106. +    0x20AC, 0x0020, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
  1107. +    0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0020, 0x017D, 0x0020,
  1108. +    0x0020, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
  1109. +    0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0020, 0x017E, 0x0178,
  1110. +    0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
  1111. +    0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
  1112. +    0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
  1113. +    0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
  1114. +    0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
  1115. +    0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
  1116. +    0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
  1117. +    0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF,
  1118. +    0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
  1119. +    0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
  1120. +    0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
  1121. +    0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF
  1122. +  };
  1123. +
  1124. +  static const unsigned short cp1253map[] =
  1125. +  {
  1126. +    0x20AC, 0x0020, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
  1127. +    0x0020, 0x2030, 0x0020, 0x2039, 0x0020, 0x0020, 0x0020, 0x0020,
  1128. +    0x0020, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
  1129. +    0x0020, 0x2122, 0x0020, 0x203A, 0x0020, 0x0020, 0x0020, 0x0020,
  1130. +    0x00A0, 0x0385, 0x0386, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
  1131. +    0x00A8, 0x00A9, 0x0020, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x2015,
  1132. +    0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x0384, 0x00B5, 0x00B6, 0x00B7,
  1133. +    0x0388, 0x0389, 0x038A, 0x00BB, 0x038C, 0x00BD, 0x038E, 0x038F,
  1134. +    0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397,
  1135. +    0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F,
  1136. +    0x03A0, 0x03A1, 0x0020, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7,
  1137. +    0x03A8, 0x03A9, 0x03AA, 0x03AB, 0x03AC, 0x03AD, 0x03AE, 0x03AF,
  1138. +    0x03B0, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7,
  1139. +    0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF,
  1140. +    0x03C0, 0x03C1, 0x03C2, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 0x03C7,
  1141. +    0x03C8, 0x03C9, 0x03CA, 0x03CB, 0x03CC, 0x03CD, 0x03CE, 0x0020
  1142. +  };
  1143. +
  1144. +  static const unsigned short cp1254map[] =
  1145. +  {
  1146. +    0x20AC, 0x0020, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
  1147. +    0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0020, 0x0020, 0x0020,
  1148. +    0x0020, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
  1149. +    0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0020, 0x0020, 0x0178,
  1150. +    0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
  1151. +    0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
  1152. +    0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
  1153. +    0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
  1154. +    0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
  1155. +    0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
  1156. +    0x011E, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
  1157. +    0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x0130, 0x015E, 0x00DF,
  1158. +    0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
  1159. +    0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
  1160. +    0x011F, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
  1161. +    0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x0131, 0x015F, 0x00FF
  1162. +  };
  1163. +
  1164. +  static const unsigned short cp1255map[] =
  1165. +  {
  1166. +    0x20AC, 0x0020, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
  1167. +    0x02C6, 0x2030, 0x0020, 0x2039, 0x0020, 0x0020, 0x0020, 0x0020,
  1168. +    0x0020, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
  1169. +    0x02DC, 0x2122, 0x0020, 0x203A, 0x0020, 0x0020, 0x0020, 0x0020,
  1170. +    0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x20AA, 0x00A5, 0x00A6, 0x00A7,
  1171. +    0x00A8, 0x00A9, 0x00D7, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
  1172. +    0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
  1173. +    0x00B8, 0x00B9, 0x00F7, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
  1174. +    0x05B0, 0x05B1, 0x05B2, 0x05B3, 0x05B4, 0x05B5, 0x05B6, 0x05B7,
  1175. +    0x05B8, 0x05B9, 0x0020, 0x05BB, 0x05BC, 0x05BD, 0x05BE, 0x05BF,
  1176. +    0x05C0, 0x05C1, 0x05C2, 0x05C3, 0x05F0, 0x05F1, 0x05F2, 0x05F3,
  1177. +    0x05F4, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
  1178. +    0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7,
  1179. +    0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
  1180. +    0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7,
  1181. +    0x05E8, 0x05E9, 0x05EA, 0x0020, 0x0020, 0x200E, 0x200F, 0x0020
  1182. +  };
  1183. +
  1184. +  static const unsigned short cp1256map[] =
  1185. +  {
  1186. +    0x20AC, 0x067E, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
  1187. +    0x02C6, 0x2030, 0x0679, 0x2039, 0x0152, 0x0686, 0x0698, 0x0688,
  1188. +    0x06AF, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
  1189. +    0x06A9, 0x2122, 0x0691, 0x203A, 0x0153, 0x200C, 0x200D, 0x06BA,
  1190. +    0x00A0, 0x060C, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
  1191. +    0x00A8, 0x00A9, 0x06BE, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
  1192. +    0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
  1193. +    0x00B8, 0x00B9, 0x061B, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x061F,
  1194. +    0x06C1, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627,
  1195. +    0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F,
  1196. +    0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x00D7,
  1197. +    0x0637, 0x0638, 0x0639, 0x063A, 0x0640, 0x0641, 0x0642, 0x0643,
  1198. +    0x00E0, 0x0644, 0x00E2, 0x0645, 0x0646, 0x0647, 0x0648, 0x00E7,
  1199. +    0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0649, 0x064A, 0x00EE, 0x00EF,
  1200. +    0x064B, 0x064C, 0x064D, 0x064E, 0x00F4, 0x064F, 0x0650, 0x00F7,
  1201. +    0x0651, 0x00F9, 0x0652, 0x00FB, 0x00FC, 0x200E, 0x200F, 0x06D2
  1202. +  };
  1203. +
  1204. +  static const unsigned short cp1257map[] =
  1205. +  {
  1206. +    0x20AC, 0x0020, 0x201A, 0x0020, 0x201E, 0x2026, 0x2020, 0x2021,
  1207. +    0x0020, 0x2030, 0x0020, 0x2039, 0x0020, 0x00A8, 0x02C7, 0x00B8,
  1208. +    0x0020, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
  1209. +    0x0020, 0x2122, 0x0020, 0x203A, 0x0020, 0x00AF, 0x02DB, 0x0020,
  1210. +    0x00A0, 0x0020, 0x00A2, 0x00A3, 0x00A4, 0x0020, 0x00A6, 0x00A7,
  1211. +    0x00D8, 0x00A9, 0x0156, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00C6,
  1212. +    0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
  1213. +    0x00F8, 0x00B9, 0x0157, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00E6,
  1214. +    0x0104, 0x012E, 0x0100, 0x0106, 0x00C4, 0x00C5, 0x0118, 0x0112,
  1215. +    0x010C, 0x00C9, 0x0179, 0x0116, 0x0122, 0x0136, 0x012A, 0x013B,
  1216. +    0x0160, 0x0143, 0x0145, 0x00D3, 0x014C, 0x00D5, 0x00D6, 0x00D7,
  1217. +    0x0172, 0x0141, 0x015A, 0x016A, 0x00DC, 0x017B, 0x017D, 0x00DF,
  1218. +    0x0105, 0x012F, 0x0101, 0x0107, 0x00E4, 0x00E5, 0x0119, 0x0113,
  1219. +    0x010D, 0x00E9, 0x017A, 0x0117, 0x0123, 0x0137, 0x012B, 0x013C,
  1220. +    0x0161, 0x0144, 0x0146, 0x00F3, 0x014D, 0x00F5, 0x00F6, 0x00F7,
  1221. +    0x0173, 0x0142, 0x015B, 0x016B, 0x00FC, 0x017C, 0x017E, 0x02D9
  1222. +  };
  1223. +
  1224. +  static const unsigned short cp1258map[] =
  1225. +  {
  1226. +    0x20AC, 0x0020, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
  1227. +    0x02C6, 0x2030, 0x0020, 0x2039, 0x0152, 0x0020, 0x0020, 0x0020,
  1228. +    0x0020, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
  1229. +    0x02DC, 0x2122, 0x0020, 0x203A, 0x0153, 0x0020, 0x0020, 0x0178,
  1230. +    0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
  1231. +    0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
  1232. +    0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
  1233. +    0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
  1234. +    0x00C0, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
  1235. +    0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x0300, 0x00CD, 0x00CE, 0x00CF,
  1236. +    0x0110, 0x00D1, 0x0309, 0x00D3, 0x00D4, 0x01A0, 0x00D6, 0x00D7,
  1237. +    0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x01AF, 0x0303, 0x00DF,
  1238. +    0x00E0, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
  1239. +    0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0301, 0x00ED, 0x00EE, 0x00EF,
  1240. +    0x0111, 0x00F1, 0x0323, 0x00F3, 0x00F4, 0x01A1, 0x00F6, 0x00F7,
  1241. +    0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x01B0, 0x20AB, 0x00FF
  1242. +  };
  1243. +
  1244. +  std::vector<unsigned char>::const_iterator iter = characters.begin();
  1245. +  while (iter != characters.end())
  1246. +  {
  1247. +    uint32_t ucs4Character = 0;
  1248. +    if (*iter == 0x1e)
  1249. +    {
  1250. +      if (m_fieldIndex < m_fields.size())
  1251. +        text.append(m_fields[m_fieldIndex++].cstr());
  1252. +      else
  1253. +        m_fieldIndex++;
  1254. +    }
  1255. +    else if (*iter < 0x20)
  1256. +    {
  1257. +      ucs4Character = 0x20;
  1258. +      ++iter;
  1259. +    }
  1260. +    else if (*iter >= 0x20 && *iter < 0x7f)
  1261. +      ucs4Character = *iter++;
  1262. +    else if (*iter == 0x7f)
  1263. +    {
  1264. +      ucs4Character = 0x20;
  1265. +      ++iter;
  1266. +    }
  1267. +    else
  1268. +    {
  1269. +      switch (format)
  1270. +      {
  1271. +      case VSD_TEXT_ANSI:
  1272. +        ucs4Character = cp1252map[*iter++ - 0x80];
  1273. +        break;
  1274. +      case VSD_TEXT_GREEK:
  1275. +        ucs4Character = cp1253map[*iter++ - 0x80];
  1276. +        break;
  1277. +      case VSD_TEXT_TURKISH:
  1278. +        ucs4Character = cp1254map[*iter++ - 0x80];
  1279. +        break;
  1280. +      case VSD_TEXT_VIETNAMESE:
  1281. +        ucs4Character = cp1258map[*iter++ - 0x80];
  1282. +        break;
  1283. +      case VSD_TEXT_HEBREW:
  1284. +        ucs4Character = cp1255map[*iter++ - 0x80];
  1285. +        break;
  1286. +      case VSD_TEXT_ARABIC:
  1287. +        ucs4Character = cp1256map[*iter++ - 0x80];
  1288. +        break;
  1289. +      case VSD_TEXT_BALTIC:
  1290. +        ucs4Character = cp1257map[*iter++ - 0x80];
  1291. +        break;
  1292. +      case VSD_TEXT_RUSSIAN:
  1293. +        ucs4Character = cp1251map[*iter++ - 0x80];
  1294. +        break;
  1295. +      case VSD_TEXT_THAI:
  1296. +        ucs4Character = cp874map[*iter++ - 0x80];
  1297. +        break;
  1298. +      case VSD_TEXT_CENTRAL_EUROPE:
  1299. +        ucs4Character = cp1250map[*iter++ - 0x80];
  1300. +        break;
  1301. +      default:
  1302. +        ucs4Character = *iter++;
  1303. +        break;
  1304. +      }
  1305. +    }
  1306. +    _appendUCS4(text, ucs4Character);
  1307. +  }
  1308. +}
  1309. +
  1310. +void libvisio::VSDXContentCollector::appendCharacters(WPXString &text, const std::vector<unsigned char> &characters)
  1311. +{
  1312. +  for (std::vector<unsigned char>::const_iterator iter = characters.begin();
  1313. +       iter != characters.end();)
  1314.    {
  1315.      uint16_t high_surrogate = 0;
  1316.      bool fail = false;
  1317.      uint32_t ucs4Character = 0;
  1318. -    uint16_t character = 0;
  1319.      while (true)
  1320.      {
  1321. -      if (input->atEOS())
  1322. +      if (iter == characters.end())
  1323.        {
  1324.          fail = true;
  1325.          break;
  1326.        }
  1327. -      character = readU16(input);
  1328. +      uint16_t character = *iter++;
  1329. +      character |= (uint16_t)(*iter++) << 8;
  1330.        if (character == 0xfffc)
  1331.        {
  1332.          if (m_fieldIndex < m_fields.size())
  1333. @@ -2357,88 +2759,10 @@ void libvisio::VSDXContentCollector::_appendUTF16LE(WPXString &text, WPXInputStr
  1334.        }
  1335.      }
  1336.      if (fail)
  1337. -      throw GenericException();
  1338. +      throw libvisio::GenericException();
  1339.  
  1340.      _appendUCS4(text, ucs4Character);
  1341.    }
  1342.  }
  1343.  
  1344. -void libvisio::VSDXContentCollector::_appendUCS4(WPXString &text, unsigned ucs4Character)
  1345. -{
  1346. -  unsigned char first;
  1347. -  int len;
  1348. -  if (ucs4Character < 0x80)
  1349. -  {
  1350. -    first = 0;
  1351. -    len = 1;
  1352. -  }
  1353. -  else if (ucs4Character < 0x800)
  1354. -  {
  1355. -    first = 0xc0;
  1356. -    len = 2;
  1357. -  }
  1358. -  else if (ucs4Character < 0x10000)
  1359. -  {
  1360. -    first = 0xe0;
  1361. -    len = 3;
  1362. -  }
  1363. -  else if (ucs4Character < 0x200000)
  1364. -  {
  1365. -    first = 0xf0;
  1366. -    len = 4;
  1367. -  }
  1368. -  else if (ucs4Character < 0x4000000)
  1369. -  {
  1370. -    first = 0xf8;
  1371. -    len = 5;
  1372. -  }
  1373. -  else
  1374. -  {
  1375. -    first = 0xfc;
  1376. -    len = 6;
  1377. -  }
  1378. -
  1379. -  unsigned char outbuf[6] = { 0, 0, 0, 0, 0, 0 };
  1380. -  int i;
  1381. -  for (i = len - 1; i > 0; --i)
  1382. -  {
  1383. -    outbuf[i] = (ucs4Character & 0x3f) | 0x80;
  1384. -    ucs4Character >>= 6;
  1385. -  }
  1386. -  outbuf[0] = (ucs4Character & 0xff) | first;
  1387. -
  1388. -  for (i = 0; i < len; i++)
  1389. -    text.append(outbuf[i]);
  1390. -}
  1391. -
  1392. -bool libvisio::VSDXContentCollector::parseFormatId( const char *formatString, unsigned short &result )
  1393. -{
  1394. -  using namespace ::boost::spirit::classic;
  1395. -
  1396. -  result = 0xffff;
  1397. -
  1398. -  uint_parser<unsigned short,10,1,5> ushort_p;
  1399. -  if (parse(formatString,
  1400. -            // Begin grammar
  1401. -            (
  1402. -              (
  1403. -                str_p("{<") >>
  1404. -                ushort_p[assign_a(result)]
  1405. -                >> str_p(">}")
  1406. -              )
  1407. -              |
  1408. -              (
  1409. -                str_p("esc(") >>
  1410. -                ushort_p[assign_a(result)]
  1411. -                >> ')'
  1412. -              )
  1413. -            )>> end_p,
  1414. -            // End grammar
  1415. -            space_p).full )
  1416. -  {
  1417. -    return true;
  1418. -  }
  1419. -  return false;
  1420. -}
  1421. -
  1422.  /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
  1423. diff --git a/src/lib/VSDXContentCollector.h b/src/lib/VSDXContentCollector.h
  1424. index c381610..b786a2a 100644
  1425. --- a/src/lib/VSDXContentCollector.h
  1426. +++ b/src/lib/VSDXContentCollector.h
  1427. @@ -105,9 +105,9 @@ public:
  1428.    void collectColours(const std::vector<Colour> &colours);
  1429.    void collectFont(unsigned short fontID, const WPXBinaryData &textStream, TextFormat format);
  1430.    void collectText(unsigned id, unsigned level, const WPXBinaryData &textStream, TextFormat format);
  1431. -  void collectVSDXCharStyle(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, unsigned langId,
  1432. -                            double fontSize, bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
  1433. -                            bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, WPXString fontFace);
  1434. +  void collectVSDXCharStyle(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, double fontSize,
  1435. +                            bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
  1436. +                            bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, VSDXFont fontFace);
  1437.    void collectVSDXParaStyle(unsigned id , unsigned level, unsigned charCount, double indFirst, double indLeft, double indRight,
  1438.                              double spLine, double spBefore, double spAfter, unsigned char align, unsigned flags);
  1439.    void collectTextBlock(unsigned id, unsigned level, double leftMargin, double rightMargin, double topMargin, double bottomMargin, unsigned char verticalAlign,
  1440. @@ -124,9 +124,9 @@ public:
  1441.                          double shadowOffsetX, double shadowOffsetY);
  1442.    void collectFillStyle(unsigned id, unsigned level, unsigned char colourIndexFG, unsigned char colourIndexBG, unsigned char fillPattern,
  1443.                          unsigned char fillFGTransparency, unsigned char fillBGTransparency, unsigned char shadowPattern, Colour shfgc);
  1444. -  void collectCharIXStyle(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, unsigned langId,
  1445. -                          double fontSize, bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
  1446. -                          bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, WPXString fontFace);
  1447. +  void collectCharIXStyle(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, double fontSize,
  1448. +                          bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
  1449. +                          bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, VSDXFont fontFace);
  1450.    void collectParaIXStyle(unsigned id , unsigned level, unsigned charCount, double indFirst, double indLeft, double indRight,
  1451.                            double spLine, double spBefore, double spAfter, unsigned char align, unsigned flags);
  1452.    void collectTextBlockStyle(unsigned id, unsigned level, double leftMargin, double rightMargin, double topMargin, double bottomMargin, unsigned char verticalAlign,
  1453. @@ -161,8 +161,6 @@ private:
  1454.    void _flushCurrentPage();
  1455.  
  1456.    void _handleLevelChange(unsigned level);
  1457. -  void _appendUTF16LE(WPXString &text, WPXInputStream *input);
  1458. -  void _appendUCS4(WPXString &text, unsigned ucs4Character);
  1459.  
  1460.    void _handleForeignData(const WPXBinaryData &data);
  1461.  
  1462. @@ -180,6 +178,8 @@ private:
  1463.                                  unsigned fillFGTransparency, unsigned fillBGTransparency,
  1464.                                  unsigned shadowPattern, Colour shfgc, double shadowOffsetX, double shadowOffsetY);
  1465.  
  1466. +  void appendCharacters(WPXString &text, const std::vector<unsigned char> &characters, TextFormat format);
  1467. +  void appendCharacters(WPXString &text, const std::vector<unsigned char> &characters);
  1468.    void _convertDataToString(WPXString &result, const WPXBinaryData &data, TextFormat format);
  1469.    bool parseFormatId( const char *formatString, unsigned short &result );
  1470.  
  1471. @@ -219,7 +219,7 @@ private:
  1472.    bool m_noFill;
  1473.    bool m_noShow;
  1474.    std::vector<Colour> m_colours;
  1475. -  std::map<unsigned short, WPXString> m_fonts;
  1476. +  std::map<unsigned short, VSDXFont> m_fonts;
  1477.    unsigned m_currentLevel;
  1478.    bool m_isShapeStarted;
  1479.    std::map<unsigned, unsigned> &m_groupMemberships;
  1480. diff --git a/src/lib/VSDXFieldList.h b/src/lib/VSDXFieldList.h
  1481. index 7a9e9cd..7ae9cd8 100644
  1482. --- a/src/lib/VSDXFieldList.h
  1483. +++ b/src/lib/VSDXFieldList.h
  1484. @@ -119,7 +119,7 @@ public:
  1485.    }
  1486.    bool empty() const
  1487.    {
  1488. -    return (!m_elements.size());
  1489. +    return (m_elements.empty());
  1490.    }
  1491.    VSDXFieldListElement *getElement(unsigned index);
  1492.  private:
  1493. diff --git a/src/lib/VSDXGeometryList.h b/src/lib/VSDXGeometryList.h
  1494. index 3d53816..af96a38 100644
  1495. --- a/src/lib/VSDXGeometryList.h
  1496. +++ b/src/lib/VSDXGeometryList.h
  1497. @@ -66,7 +66,7 @@ public:
  1498.    void clear();
  1499.    bool empty() const
  1500.    {
  1501. -    return (!m_elements.size());
  1502. +    return (m_elements.empty());
  1503.    }
  1504.    VSDXGeometryListElement *getElement(unsigned index) const;
  1505.    std::vector<unsigned> getElementsOrder() const
  1506. diff --git a/src/lib/VSDXParagraphList.h b/src/lib/VSDXParagraphList.h
  1507. index dd1c893..1df29ec 100644
  1508. --- a/src/lib/VSDXParagraphList.h
  1509. +++ b/src/lib/VSDXParagraphList.h
  1510. @@ -55,7 +55,7 @@ public:
  1511.    void clear();
  1512.    bool empty() const
  1513.    {
  1514. -    return (!m_elements.size());
  1515. +    return (m_elements.empty());
  1516.    }
  1517.  private:
  1518.    std::map<unsigned, VSDXParagraphListElement *> m_elements;
  1519. diff --git a/src/lib/VSDXParser.cpp b/src/lib/VSDXParser.cpp
  1520. index 9085cb7..4764686 100644
  1521. --- a/src/lib/VSDXParser.cpp
  1522. +++ b/src/lib/VSDXParser.cpp
  1523. @@ -134,7 +134,6 @@ bool libvisio::VSDXParser::parseDocument(WPXInputStream *input)
  1524.  
  1525.      if (ptr.Type == VSD_FONTFACES)
  1526.        PtrList.insert(PtrList.begin(),ptr);
  1527. -//      PtrList.push_back(ptr);
  1528.      else if (ptr.Type != 0)
  1529.        PtrList.push_back(ptr);
  1530.    }
  1531. @@ -1669,7 +1668,9 @@ void libvisio::VSDXParser::readFont(WPXInputStream *input, unsigned fontID)
  1532.  
  1533.  void libvisio::VSDXParser::readFontIX(WPXInputStream *input)
  1534.  {
  1535. -  input->seek(6, WPX_SEEK_CUR);
  1536. +  input->seek(2, WPX_SEEK_CUR);
  1537. +  unsigned char codePage = readU8(input);
  1538. +  input->seek(3, WPX_SEEK_CUR);
  1539.    ::WPXBinaryData textStream;
  1540.  
  1541.    for (unsigned i = 0; i < m_header.dataLength - 6; i++)
  1542. @@ -1679,7 +1680,43 @@ void libvisio::VSDXParser::readFontIX(WPXInputStream *input)
  1543.        break;
  1544.      textStream.append(curchar);
  1545.    }
  1546. -  m_collector->collectFont((unsigned short) m_header.id, textStream, libvisio::VSD_TEXT_ANSI);
  1547. +  TextFormat format = libvisio::VSD_TEXT_ANSI;
  1548. +  switch (codePage)
  1549. +  {
  1550. +  case 0: // ANSI
  1551. +    format = libvisio::VSD_TEXT_ANSI;
  1552. +    break;
  1553. +  case 0xa1: // GREEK
  1554. +    format = libvisio::VSD_TEXT_GREEK;
  1555. +    break;
  1556. +  case 0xa2: // TURKISH
  1557. +    format = libvisio::VSD_TEXT_TURKISH;
  1558. +    break;
  1559. +  case 0xa3: // VIETNAMESE
  1560. +    format = libvisio::VSD_TEXT_VIETNAMESE;
  1561. +    break;
  1562. +  case 0xb1: // HEBREW
  1563. +    format = libvisio::VSD_TEXT_HEBREW;
  1564. +    break;
  1565. +  case 0xb2: // ARABIC
  1566. +    format = libvisio::VSD_TEXT_ARABIC;
  1567. +    break;
  1568. +  case 0xba: // BALTIC
  1569. +    format = libvisio::VSD_TEXT_BALTIC;
  1570. +    break;
  1571. +  case 0xcc: // RUSSIAN
  1572. +    format = libvisio::VSD_TEXT_RUSSIAN;
  1573. +    break;
  1574. +  case 0xde: // THAI
  1575. +    format = libvisio::VSD_TEXT_THAI;
  1576. +    break;
  1577. +  case 0xee: // CENTRAL EUROPE
  1578. +    format = libvisio::VSD_TEXT_CENTRAL_EUROPE;
  1579. +    break;
  1580. +  default:
  1581. +    break;
  1582. +  }
  1583. +  m_collector->collectFont((unsigned short) m_header.id, textStream, format);
  1584.  }
  1585.  
  1586.  /* StyleSheet readers */
  1587. diff --git a/src/lib/VSDXShapeList.h b/src/lib/VSDXShapeList.h
  1588. index 6bb6967..17ae708 100644
  1589. --- a/src/lib/VSDXShapeList.h
  1590. +++ b/src/lib/VSDXShapeList.h
  1591. @@ -50,7 +50,7 @@ public:
  1592.    void clear();
  1593.    bool empty() const
  1594.    {
  1595. -    return (!m_elements.size());
  1596. +    return (m_elements.empty());
  1597.    }
  1598.  private:
  1599.    std::map<unsigned, VSDXShapeListElement *> m_elements;
  1600. diff --git a/src/lib/VSDXStyles.h b/src/lib/VSDXStyles.h
  1601. index a58990c..3d610aa 100644
  1602. --- a/src/lib/VSDXStyles.h
  1603. +++ b/src/lib/VSDXStyles.h
  1604. @@ -89,7 +89,6 @@ struct VSDXCharStyle
  1605.      charCount(0),
  1606.      faceID(0),
  1607.      colour(),
  1608. -    langID(0),
  1609.      size(12.0/72.0),
  1610.      bold(false),
  1611.      italic(false),
  1612. @@ -102,12 +101,11 @@ struct VSDXCharStyle
  1613.      smallcaps(false),
  1614.      superscript(false),
  1615.      subscript(false),
  1616. -    face("Arial") {}
  1617. -  VSDXCharStyle(unsigned cc, unsigned short id, Colour c, unsigned lang, double s, bool b, bool i, bool u, bool du, bool so, bool dso, bool ac, bool ic, bool sc, bool super, bool sub, WPXString f) :
  1618. +    face() {}
  1619. +  VSDXCharStyle(unsigned cc, unsigned short id, Colour c, double s, bool b, bool i, bool u, bool du, bool so, bool dso, bool ac, bool ic, bool sc, bool super, bool sub, VSDXFont f) :
  1620.      charCount(cc),
  1621.      faceID(id),
  1622.      colour(c),
  1623. -    langID(lang),
  1624.      size(s),
  1625.      bold(b),
  1626.      italic(i),
  1627. @@ -125,7 +123,6 @@ struct VSDXCharStyle
  1628.    unsigned charCount;
  1629.    unsigned short faceID;
  1630.    Colour colour;
  1631. -  unsigned langID;
  1632.    double size;
  1633.    bool bold;
  1634.    bool italic;
  1635. @@ -138,7 +135,7 @@ struct VSDXCharStyle
  1636.    bool smallcaps;
  1637.    bool superscript;
  1638.    bool subscript;
  1639. -  WPXString face;
  1640. +  VSDXFont face;
  1641.  };
  1642.  
  1643.  struct VSDXParaStyle
  1644. diff --git a/src/lib/VSDXStylesCollector.cpp b/src/lib/VSDXStylesCollector.cpp
  1645. index 74ea41c..402cf62 100644
  1646. --- a/src/lib/VSDXStylesCollector.cpp
  1647. +++ b/src/lib/VSDXStylesCollector.cpp
  1648. @@ -243,10 +243,10 @@ void libvisio::VSDXStylesCollector::collectVSDXParaStyle(unsigned /* id */ , uns
  1649.    _handleLevelChange(level);
  1650.  }
  1651.  
  1652. -void libvisio::VSDXStylesCollector::collectVSDXCharStyle(unsigned /*id*/ , unsigned level, unsigned /*charCount*/, unsigned short /*fontID*/, Colour /*fontColour*/,
  1653. -    unsigned /*langId*/, double /*fontSize*/, bool /*bold*/, bool /*italic*/, bool /*underline*/,
  1654. +void libvisio::VSDXStylesCollector::collectVSDXCharStyle(unsigned /*id*/ , unsigned level, unsigned /*charCount*/, unsigned short /*fontID*/,
  1655. +    Colour /*fontColour*/, double /*fontSize*/, bool /*bold*/, bool /*italic*/, bool /*underline*/,
  1656.      bool /* doubleunderline */, bool /* strikeout */, bool /* doublestrikeout */, bool /* allcaps */,
  1657. -    bool /* initcaps */, bool /* smallcaps */, bool /* superscript */, bool /* subscript */, WPXString /*fontFace*/)
  1658. +    bool /* initcaps */, bool /* smallcaps */, bool /* superscript */, bool /* subscript */, VSDXFont /*fontFace*/)
  1659.  {
  1660.    _handleLevelChange(level);
  1661.  }
  1662. @@ -324,14 +324,14 @@ void libvisio::VSDXStylesCollector::collectParaIXStyle(unsigned /*id*/, unsigned
  1663.  }
  1664.  
  1665.  
  1666. -void libvisio::VSDXStylesCollector::collectCharIXStyle(unsigned /*id*/ , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour,
  1667. -    unsigned langID, double fontSize, bool bold, bool italic, bool underline, bool doubleunderline,
  1668. +void libvisio::VSDXStylesCollector::collectCharIXStyle(unsigned /*id*/ , unsigned level, unsigned charCount, unsigned short fontID,
  1669. +    Colour fontColour, double fontSize, bool bold, bool italic, bool underline, bool doubleunderline,
  1670.      bool strikeout, bool doublestrikeout, bool allcaps, bool initcaps, bool smallcaps,
  1671. -    bool superscript, bool subscript, WPXString fontFace)
  1672. +    bool superscript, bool subscript, VSDXFont fontFace)
  1673.  {
  1674.    _handleLevelChange(level);
  1675.    if (!m_charStyle)
  1676. -    m_charStyle = new VSDXCharStyle(charCount, fontID, fontColour, langID, fontSize, bold, italic, underline, doubleunderline, strikeout, doublestrikeout,
  1677. +    m_charStyle = new VSDXCharStyle(charCount, fontID, fontColour, fontSize, bold, italic, underline, doubleunderline, strikeout, doublestrikeout,
  1678.                                      allcaps, initcaps, smallcaps, superscript, subscript, fontFace);
  1679.  }
  1680.  
  1681. diff --git a/src/lib/VSDXStylesCollector.h b/src/lib/VSDXStylesCollector.h
  1682. index 9aa8497..302d41f 100644
  1683. --- a/src/lib/VSDXStylesCollector.h
  1684. +++ b/src/lib/VSDXStylesCollector.h
  1685. @@ -96,9 +96,9 @@ public:
  1686.    void collectFont(unsigned short fontID, const ::WPXBinaryData &textStream, TextFormat format);
  1687.  
  1688.    void collectText(unsigned id, unsigned level, const ::WPXBinaryData &textStream, TextFormat format);
  1689. -  void collectVSDXCharStyle(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, unsigned langId,
  1690. +  void collectVSDXCharStyle(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour,
  1691.                              double fontSize, bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
  1692. -                            bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, WPXString fontFace);
  1693. +                            bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, VSDXFont fontFace);
  1694.    void collectVSDXParaStyle(unsigned id , unsigned level, unsigned charCount, double indFirst, double indLeft, double indRight,
  1695.                              double spLine, double spBefore, double spAfter, unsigned char align, unsigned flags);
  1696.    void collectTextBlock(unsigned id, unsigned level, double leftMargin, double rightMargin, double topMargin, double bottomMargin, unsigned char verticalAlign,
  1697. @@ -117,9 +117,9 @@ public:
  1698.                          double shadowOffsetX, double shadowOffsetY);
  1699.    void collectFillStyle(unsigned id, unsigned level, unsigned char colourIndexFG, unsigned char colourIndexBG, unsigned char fillPattern,
  1700.                          unsigned char fillFGTransparency, unsigned char fillBGTransparency, unsigned char shadowPattern, Colour shfgc);
  1701. -  void collectCharIXStyle(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, unsigned langId,
  1702. +  void collectCharIXStyle(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour,
  1703.                            double fontSize, bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
  1704. -                          bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, WPXString fontFace);
  1705. +                          bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, VSDXFont fontFace);
  1706.    void collectParaIXStyle(unsigned id , unsigned level, unsigned charCount, double indFirst, double indLeft, double indRight,
  1707.                            double spLine, double spBefore, double spAfter, unsigned char align, unsigned flags);
  1708.    void collectTextBlockStyle(unsigned id, unsigned level, double leftMargin, double rightMargin, double topMargin, double bottomMargin, unsigned char verticalAlign,
  1709. diff --git a/src/lib/VSDXTypes.h b/src/lib/VSDXTypes.h
  1710. index 4c9b8d2..4d5d0c3 100644
  1711. --- a/src/lib/VSDXTypes.h
  1712. +++ b/src/lib/VSDXTypes.h
  1713. @@ -176,7 +176,20 @@ struct ForeignData
  1714.        data(fd.data) {}
  1715.  };
  1716.  
  1717. -enum TextFormat { VSD_TEXT_ANSI, VSD_TEXT_UTF16 };
  1718. +enum TextFormat
  1719. +{
  1720. +  VSD_TEXT_ANSI = 0,
  1721. +  VSD_TEXT_GREEK,
  1722. +  VSD_TEXT_TURKISH,
  1723. +  VSD_TEXT_VIETNAMESE,
  1724. +  VSD_TEXT_HEBREW,
  1725. +  VSD_TEXT_ARABIC,
  1726. +  VSD_TEXT_BALTIC,
  1727. +  VSD_TEXT_RUSSIAN,
  1728. +  VSD_TEXT_THAI,
  1729. +  VSD_TEXT_CENTRAL_EUROPE,
  1730. +  VSD_TEXT_UTF16
  1731. +};
  1732.  
  1733.  class VSDXName
  1734.  {
  1735. @@ -198,6 +211,13 @@ public:
  1736.    TextFormat m_format;
  1737.  };
  1738.  
  1739. +struct VSDXFont
  1740. +{
  1741. +  WPXString name;
  1742. +  TextFormat encoding;
  1743. +  VSDXFont() : name("Arial"), encoding(libvisio::VSD_TEXT_ANSI) {}
  1744. +};
  1745. +
  1746.  } // namespace libvisio
  1747.  
  1748.  #endif /* VSDXTYPES_H */
  1749. diff --git a/src/lib/libvisio_utils.cpp b/src/lib/libvisio_utils.cpp
  1750. index 05e04cf..f881bdb 100644
  1751. --- a/src/lib/libvisio_utils.cpp
  1752. +++ b/src/lib/libvisio_utils.cpp
  1753. @@ -108,4 +108,5 @@ double libvisio::readDouble(WPXInputStream *input)
  1754.  
  1755.    return tmpUnion.d;
  1756.  }
  1757. +
  1758.  /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
  1759. diff --git a/src/lib/libvisio_utils.h b/src/lib/libvisio_utils.h
  1760. index 23dd559..593e419 100644
  1761. --- a/src/lib/libvisio_utils.h
  1762. +++ b/src/lib/libvisio_utils.h
  1763. @@ -31,7 +31,10 @@
  1764.  #ifndef __LIBVISIO_UTILS_H__
  1765.  #define __LIBVISIO_UTILS_H__
  1766.  
  1767. +#include <vector>
  1768.  #include <stdio.h>
  1769. +#include <libwpd/libwpd.h>
  1770. +#include "VSDXTypes.h"
  1771.  
  1772.  #ifdef _MSC_VER
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement