summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFridrich Štrba <fridrich.strba@bluewin.ch>2011-11-09 11:33:52 +0100
committerFridrich Štrba <fridrich.strba@bluewin.ch>2011-11-09 11:33:52 +0100
commitd778b25513c6ca10f737719c92d5c81e1230ccfd (patch)
tree6f28f473a7fb2daf777451ef13d16d532c559049 /src
parenteb6ebcd3a64dcffde12239e892363936e8c6d755 (diff)
Some more text field parsing work
Diffstat (limited to 'src')
-rw-r--r--src/lib/VSD11Parser.cpp3
-rw-r--r--src/lib/VSD6Parser.cpp3
-rw-r--r--src/lib/VSDXContentCollector.cpp68
-rw-r--r--src/lib/VSDXContentCollector.h13
-rw-r--r--src/lib/VSDXFieldList.cpp67
-rw-r--r--src/lib/VSDXFieldList.h21
6 files changed, 127 insertions, 48 deletions
diff --git a/src/lib/VSD11Parser.cpp b/src/lib/VSD11Parser.cpp
index 42ad474..bb8ecd9 100644
--- a/src/lib/VSD11Parser.cpp
+++ b/src/lib/VSD11Parser.cpp
@@ -228,10 +228,9 @@ void libvisio::VSD11Parser::readFillAndShadow(WPXInputStream *input)
void libvisio::VSD11Parser::readName(WPXInputStream *input)
{
- input->seek(8, WPX_SEEK_CUR);
::WPXBinaryData name;
- for (unsigned bytesRead = 8; bytesRead < m_header.dataLength; bytesRead++)
+ for (unsigned bytesRead = 0; bytesRead < m_header.dataLength; bytesRead++)
name.append(readU8(input));
if (m_isStencilStarted)
diff --git a/src/lib/VSD6Parser.cpp b/src/lib/VSD6Parser.cpp
index ef80a95..fc3c6ac 100644
--- a/src/lib/VSD6Parser.cpp
+++ b/src/lib/VSD6Parser.cpp
@@ -201,10 +201,9 @@ void libvisio::VSD6Parser::readFillAndShadow(WPXInputStream *input)
void libvisio::VSD6Parser::readName(WPXInputStream *input)
{
- input->seek(8, WPX_SEEK_CUR);
::WPXBinaryData name;
- for (unsigned bytesRead = 8; bytesRead < m_header.dataLength; bytesRead++)
+ for (unsigned bytesRead = 0; bytesRead < m_header.dataLength; bytesRead++)
name.append(readU8(input));
if (m_isStencilStarted)
diff --git a/src/lib/VSDXContentCollector.cpp b/src/lib/VSDXContentCollector.cpp
index 6dbbcc7..8a5741d 100644
--- a/src/lib/VSDXContentCollector.cpp
+++ b/src/lib/VSDXContentCollector.cpp
@@ -65,7 +65,7 @@ libvisio::VSDXContentCollector::VSDXContentCollector(
m_currentPageNumber(0), m_shapeOutputDrawing(0), m_shapeOutputText(0),
m_pageOutputDrawing(), m_pageOutputText(), m_documentPageShapeOrders(documentPageShapeOrders),
m_pageShapeOrder(documentPageShapeOrders[0]), m_isFirstGeometry(true),
- m_NURBSData(), m_polylineData(), m_textStream(), m_names(), m_textFormat(VSD_TEXT_ANSI),
+ m_NURBSData(), m_polylineData(), m_textStream(), m_names(), m_fields(), m_textFormat(VSD_TEXT_ANSI),
m_charFormats(), m_paraFormats(), m_textBlockStyle(),
m_defaultCharStyle(), m_defaultParaStyle(), m_styles(styles),
m_stencils(stencils), m_stencilShape(0), m_isStencilStarted(false), m_currentGeometryCount(0),
@@ -1588,10 +1588,9 @@ void libvisio::VSDXContentCollector::collectShape(unsigned id, unsigned level, u
if (masterPage != 0xffffffff && masterShape != 0xffffffff)
{
const VSDXStencil *stencil = m_stencils.getStencil(masterPage);
- if (stencil) m_stencilShape = stencil->getStencilShape(masterShape);
- // Set the foreign types and foreign data if the stencil has foreign
- // If the shape itself overrides them, they will be overwritten in the
- // collectForeignDataType and collectForeignData calls
+ if (stencil)
+ m_stencilShape = stencil->getStencilShape(masterShape);
+ // Initialize the shape from stencil content
if (m_stencilShape)
{
if (m_stencilShape->m_foreign)
@@ -1604,6 +1603,16 @@ void libvisio::VSDXContentCollector::collectShape(unsigned id, unsigned level, u
m_textStream = m_stencilShape->m_text;
m_textFormat = m_stencilShape->m_textFormat;
+ m_names.clear();
+ for (std::vector<WPXBinaryData>::const_iterator iterData = m_stencilShape->m_names.begin(); iterData != m_stencilShape->m_names.end(); ++iterData)
+ {
+ WPXString nameString;
+ _convertDataToString(nameString, *(iterData), m_stencilShape->m_textFormat);
+ m_names.push_back(nameString);
+ }
+
+ m_stencilShape->m_fields.toVector(m_fields);
+
if (m_stencilShape->m_lineStyleId)
lineStyleFromStyleSheet(m_stencilShape->m_lineStyleId);
if (m_stencilShape->m_lineStyle)
@@ -1662,26 +1671,10 @@ void libvisio::VSDXContentCollector::collectColours(const std::vector<Colour> &c
m_colours.push_back(colours[i]);
}
-void libvisio::VSDXContentCollector::collectFont(unsigned short fontID, const ::WPXBinaryData &textStream, TextFormat format)
+void libvisio::VSDXContentCollector::collectFont(unsigned short fontID, const WPXBinaryData &textStream, TextFormat format)
{
WPXString fontname;
- const unsigned char *pTextStream = textStream.getDataBuffer();
- if (format == VSD_TEXT_ANSI)
- {
- for (unsigned i = 0; i < textStream.size(); i++)
- {
- if (pTextStream[i] <= 0x20)
- _appendUCS4(fontname, (unsigned) 0x20);
- else
- _appendUCS4(fontname, (unsigned) pTextStream[i]);
- }
- }
- else if (format == VSD_TEXT_UTF16)
- {
- VSDInternalStream tmpStream(pTextStream, textStream.size());
- _appendUTF16LE(fontname, &tmpStream);
- }
-
+ _convertDataToString(fontname, textStream, format);
m_fonts[fontID] = fontname;
}
@@ -1725,7 +1718,7 @@ void libvisio::VSDXContentCollector::collectSplineEnd()
}
-void libvisio::VSDXContentCollector::collectText(unsigned /*id*/, unsigned level, const ::WPXBinaryData &textStream, TextFormat format)
+void libvisio::VSDXContentCollector::collectText(unsigned /*id*/, unsigned level, const WPXBinaryData &textStream, TextFormat format)
{
_handleLevelChange(level);
@@ -1768,12 +1761,33 @@ void libvisio::VSDXContentCollector::collectNameList(unsigned /*id*/, unsigned l
m_names.clear();
}
-void libvisio::VSDXContentCollector::collectName(unsigned /*id*/, unsigned level, const ::WPXBinaryData &name, TextFormat format)
+void libvisio::VSDXContentCollector::_convertDataToString(WPXString &result, const WPXBinaryData &data, TextFormat format)
+{
+ WPXInputStream *pStream = const_cast<WPXInputStream *>(data.getDataStream());
+ if (format == VSD_TEXT_ANSI)
+ {
+ while (!pStream->atEOS())
+ {
+ unsigned char character = readU8(pStream);
+ if (character <= 0x20)
+ _appendUCS4(result, (unsigned) 0x20);
+ else
+ _appendUCS4(result, (unsigned) character);
+ }
+ }
+ else if (format == VSD_TEXT_UTF16)
+ {
+ _appendUTF16LE(result, pStream);
+ }
+}
+
+void libvisio::VSDXContentCollector::collectName(unsigned /*id*/, unsigned level, const WPXBinaryData &name, TextFormat format)
{
_handleLevelChange(level);
- m_names.push_back(name);
- m_textFormat = format;
+ WPXString nameString;
+ _convertDataToString(nameString, name, format);
+ m_names.push_back(nameString);
}
void libvisio::VSDXContentCollector::collectStyleSheet(unsigned /* id */, unsigned level, unsigned /* parentLineStyle */, unsigned /* parentFillStyle */, unsigned /* parentTextStyle */)
diff --git a/src/lib/VSDXContentCollector.h b/src/lib/VSDXContentCollector.h
index 4ac3720..6bb5d75 100644
--- a/src/lib/VSDXContentCollector.h
+++ b/src/lib/VSDXContentCollector.h
@@ -101,8 +101,8 @@ public:
void collectUnhandledChunk(unsigned id, unsigned level);
void collectColours(const std::vector<Colour> &colours);
- void collectFont(unsigned short fontID, const ::WPXBinaryData &textStream, TextFormat format);
- void collectText(unsigned id, unsigned level, const ::WPXBinaryData &textStream, TextFormat format);
+ void collectFont(unsigned short fontID, const WPXBinaryData &textStream, TextFormat format);
+ void collectText(unsigned id, unsigned level, const WPXBinaryData &textStream, TextFormat format);
void collectVSDXCharStyle(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, unsigned langId,
double fontSize, bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, WPXString fontFace);
@@ -111,7 +111,7 @@ public:
void collectTextBlock(unsigned id, unsigned level, double leftMargin, double rightMargin, double topMargin, double bottomMargin, unsigned char verticalAlign,
unsigned char bgClrId, const Colour &bgColour, double defaultTabStop, unsigned char textDirection);
void collectNameList(unsigned id, unsigned level);
- void collectName(unsigned id, unsigned level, const ::WPXBinaryData &name, TextFormat format);
+ void collectName(unsigned id, unsigned level, const WPXBinaryData &name, TextFormat format);
// Style collectors
@@ -175,6 +175,8 @@ private:
unsigned fillFGTransparency, unsigned fillBGTransparency,
unsigned shadowPattern, Colour shfgc, double shadowOffsetX, double shadowOffsetY);
+ void _convertDataToString(WPXString &result, const WPXBinaryData &data, TextFormat format);
+
bool m_isPageStarted;
double m_pageWidth;
double m_pageHeight;
@@ -221,8 +223,9 @@ private:
std::map<unsigned, NURBSData> m_NURBSData;
std::map<unsigned, PolylineData> m_polylineData;
- ::WPXBinaryData m_textStream;
- std::vector< ::WPXBinaryData> m_names;
+ WPXBinaryData m_textStream;
+ std::vector<WPXString> m_names;
+ std::vector<VSDXFieldListElement *> m_fields;
TextFormat m_textFormat;
std::vector<VSDXCharStyle> m_charFormats;
std::vector<VSDXParaStyle> m_paraFormats;
diff --git a/src/lib/VSDXFieldList.cpp b/src/lib/VSDXFieldList.cpp
index f0f4977..46a720e 100644
--- a/src/lib/VSDXFieldList.cpp
+++ b/src/lib/VSDXFieldList.cpp
@@ -28,21 +28,13 @@
* instead of those above.
*/
+#include <libwpd/libwpd.h>
#include "VSDXCollector.h"
#include "VSDXFieldList.h"
namespace libvisio
{
-class VSDXFieldListElement
-{
-public:
- VSDXFieldListElement() {}
- virtual ~VSDXFieldListElement() {}
- virtual void handle(VSDXCollector *collector) = 0;
- virtual VSDXFieldListElement *clone() = 0;
-};
-
class VSDXTextField : public VSDXFieldListElement
{
public:
@@ -53,6 +45,13 @@ public:
~VSDXTextField() {}
void handle(VSDXCollector *collector);
VSDXFieldListElement *clone();
+ WPXString getString(const std::vector<WPXString> &strVec)
+ {
+ if (m_nameId >= strVec.size())
+ return WPXString();
+ else
+ return strVec[m_nameId];
+ }
private:
unsigned m_id, m_level, m_nameId;
};
@@ -68,11 +67,34 @@ public:
~VSDXNumericField() {}
void handle(VSDXCollector *collector);
VSDXFieldListElement *clone();
+ WPXString getString(const std::vector<WPXString> &)
+ {
+ WPXString result;
+ WPXProperty *pProp = WPXPropertyFactory::newDoubleProp(m_number);
+ if (pProp)
+ {
+ result = pProp->getStr();
+ delete pProp;
+ }
+ return result;
+ }
private:
unsigned m_id, m_level, m_format;
double m_number;
};
+#define MAX_BUFFER 1024
+
+static WPXString datetimeToString(const char *format, double datetime)
+{
+ WPXString result;
+ char buffer[MAX_BUFFER];
+ time_t timer = (time_t)(86400 * datetime - 2209161600.0);
+ strftime(&buffer[0], MAX_BUFFER-1, format, gmtime(&timer));
+ result.append(&buffer[0]);
+ return result;
+}
+
class VSDXDatetimeField : public VSDXFieldListElement
{
public:
@@ -84,6 +106,10 @@ public:
~VSDXDatetimeField() {}
void handle(VSDXCollector *collector);
VSDXFieldListElement *clone();
+ WPXString getString(const std::vector<WPXString> &)
+ {
+ return datetimeToString("%x %X", m_timeValue);
+ }
private:
unsigned m_id, m_level, m_format;
unsigned long m_timeValue;
@@ -175,6 +201,29 @@ libvisio::VSDXFieldList &libvisio::VSDXFieldList::operator=(const libvisio::VSDX
return *this;
}
+void libvisio::VSDXFieldList::toVector(std::vector<libvisio::VSDXFieldListElement *> &vec) const
+{
+ if (!vec.empty())
+ vec.clear();
+ if (empty())
+ return;
+ std::map<unsigned, VSDXFieldListElement *>::const_iterator iter;
+ if (m_elementsOrder.size())
+ {
+ for (unsigned i = 0; i < m_elementsOrder.size(); i++)
+ {
+ iter = m_elements.find(m_elementsOrder[i]);
+ if (iter != m_elements.end())
+ vec.push_back(iter->second);
+ }
+ }
+ else
+ {
+ for (iter = m_elements.begin(); iter != m_elements.end(); iter++)
+ vec.push_back(iter->second);
+ }
+}
+
libvisio::VSDXFieldList::~VSDXFieldList()
{
clear();
diff --git a/src/lib/VSDXFieldList.h b/src/lib/VSDXFieldList.h
index e066ed0..a09c083 100644
--- a/src/lib/VSDXFieldList.h
+++ b/src/lib/VSDXFieldList.h
@@ -33,20 +33,35 @@
#include <vector>
#include <map>
+#include <libwpd/libwpd.h>
+#include <VSDXTypes.h>
namespace libvisio
{
-class VSDXFieldListElement;
class VSDXCollector;
+class VSDXFieldListElement
+{
+public:
+ VSDXFieldListElement() {}
+ virtual ~VSDXFieldListElement() {}
+ virtual void handle(VSDXCollector *collector) = 0;
+ virtual VSDXFieldListElement *clone() = 0;
+ virtual WPXString getString(const std::vector<WPXString>&)
+ {
+ return WPXString();
+ };
+};
+
class VSDXFieldList
{
public:
VSDXFieldList();
- VSDXFieldList(const VSDXFieldList &paraList);
+ VSDXFieldList(const VSDXFieldList &fieldList);
~VSDXFieldList();
- VSDXFieldList &operator=(const VSDXFieldList &paraList);
+ VSDXFieldList &operator=(const VSDXFieldList &fieldList);
+ void toVector(std::vector<VSDXFieldListElement *> &vec) const;
void setElementsOrder(const std::vector<unsigned> &m_elementsOrder);
void addTextField(unsigned id, unsigned level, unsigned nameId);
void addNumericField(unsigned id, unsigned level, unsigned format, double number);