diff options
author | David Tardon <dtardon@redhat.com> | 2016-03-27 15:46:39 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2016-03-27 15:46:39 +0200 |
commit | af0216198ce999033ae55800df7507aedd69873b (patch) | |
tree | deea9acbdd2ae8699c56efe472ed10f7d7de7596 | |
parent | 28311e11c8611f5e9f19a3052810257d3cae998a (diff) |
add skeleton charset converter
-rw-r--r-- | src/lib/Makefile.am | 2 | ||||
-rw-r--r-- | src/lib/SW602Cell.cpp | 6 | ||||
-rw-r--r-- | src/lib/SW602Cell.h | 3 | ||||
-rw-r--r-- | src/lib/SW602CharsetConverter.cpp | 27 | ||||
-rw-r--r-- | src/lib/SW602CharsetConverter.h | 37 | ||||
-rw-r--r-- | src/lib/SW602GraphicListener.cpp | 4 | ||||
-rw-r--r-- | src/lib/SW602Parser.cpp | 2 | ||||
-rw-r--r-- | src/lib/SW602Parser.h | 6 | ||||
-rw-r--r-- | src/lib/SW602SpreadsheetListener.cpp | 7 | ||||
-rw-r--r-- | src/lib/SW602TextListener.cpp | 5 |
10 files changed, 85 insertions, 14 deletions
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index f8006b7..5c79425 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -38,6 +38,8 @@ libsw602_@SW602_MAJOR_VERSION@_@SW602_MINOR_VERSION@_la_SOURCES = \ libsw602_internal_la_SOURCES = \ SW602Cell.cpp \ SW602Cell.h \ + SW602CharsetConverter.cpp \ + SW602CharsetConverter.h \ SW602Chart.cpp \ SW602Chart.h \ SW602Debug.cpp \ diff --git a/src/lib/SW602Cell.cpp b/src/lib/SW602Cell.cpp index 0c38426..10ef0b2 100644 --- a/src/lib/SW602Cell.cpp +++ b/src/lib/SW602Cell.cpp @@ -22,6 +22,7 @@ #include <librevenge/librevenge.h> +#include "SW602CharsetConverter.h" #include "SW602Listener.h" namespace libsw602 @@ -808,7 +809,7 @@ std::ostream &operator<<(std::ostream &o, SW602CellContent const &content) } // ---------- WKSContentListener::FormulaInstruction ------------------ -librevenge::RVNGPropertyList SW602CellContent::FormulaInstruction::getPropertyList() const +librevenge::RVNGPropertyList SW602CellContent::FormulaInstruction::getPropertyList(const SW602CharsetConverter &converter) const { librevenge::RVNGPropertyList pList; switch (m_type) @@ -829,8 +830,7 @@ librevenge::RVNGPropertyList SW602CellContent::FormulaInstruction::getPropertyLi for (size_t i=0; i<m_content.size(); ++i) { char c=m_content[i]; - // TODO: handle - int unicode=c; + const int unicode = converter.unicode(c); if (unicode==-1) { if (c < 0x20 && c!=9) diff --git a/src/lib/SW602Cell.h b/src/lib/SW602Cell.h index 26c81b5..975ba19 100644 --- a/src/lib/SW602Cell.h +++ b/src/lib/SW602Cell.h @@ -24,6 +24,7 @@ namespace libsw602 { +class SW602CharsetConverter; class SW602Table; /** a structure used to define a cell and its format */ @@ -351,7 +352,7 @@ public: } } /** returns a proplist corresponding to a instruction using a font converter to send the t ext */ - librevenge::RVNGPropertyList getPropertyList() const; + librevenge::RVNGPropertyList getPropertyList(const SW602CharsetConverter &converter) const; //! operator<< friend std::ostream &operator<<(std::ostream &o, FormulaInstruction const &inst); //! the type diff --git a/src/lib/SW602CharsetConverter.cpp b/src/lib/SW602CharsetConverter.cpp new file mode 100644 index 0000000..09ef899 --- /dev/null +++ b/src/lib/SW602CharsetConverter.cpp @@ -0,0 +1,27 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * This file is part of the libsw602 project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "SW602CharsetConverter.h" + +namespace libsw602 +{ + +SW602CharsetConverter::~SW602CharsetConverter() +{ +} + +boost::shared_ptr<SW602CharsetConverter> SW602CharsetConverter::create(const SW602Document::Encoding /*encoding*/) +{ + // TODO: implement me + return boost::shared_ptr<SW602CharsetConverter>(); +} + +} + +/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/lib/SW602CharsetConverter.h b/src/lib/SW602CharsetConverter.h new file mode 100644 index 0000000..9cfcc70 --- /dev/null +++ b/src/lib/SW602CharsetConverter.h @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * This file is part of the libsw602 project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_SW602_CHARSETCONVERTER_H +#define INCLUDED_SW602_CHARSETCONVERTER_H + +#include <boost/shared_ptr.hpp> + +#include <libsw602/libsw602.h> + +#include "libsw602_utils.h" + +namespace libsw602 +{ + +class SW602CharsetConverter +{ +public: + virtual ~SW602CharsetConverter() = 0; + + virtual uint32_t unicode(char c) const = 0; + +public: + static boost::shared_ptr<SW602CharsetConverter> create(SW602Document::Encoding encoding); +}; + +} + +#endif + +/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/lib/SW602GraphicListener.cpp b/src/lib/SW602GraphicListener.cpp index a8f4320..7f711a2 100644 --- a/src/lib/SW602GraphicListener.cpp +++ b/src/lib/SW602GraphicListener.cpp @@ -18,6 +18,7 @@ #include <librevenge/librevenge.h> #include "SW602Cell.h" +#include "SW602CharsetConverter.h" #include "SW602Font.h" #include "SW602GraphicEncoder.h" #include "SW602GraphicShape.h" @@ -200,8 +201,7 @@ void SW602GraphicListener::insertCharacter(unsigned char c) SW602_DEBUG_MSG(("SW602GraphicListener::insertCharacter: called outside a text zone\n")); return; } - // TODO: handle - int unicode = c; + const int unicode = m_parserState.m_converter->unicode(c); if (unicode == -1) { if (c < 0x20) diff --git a/src/lib/SW602Parser.cpp b/src/lib/SW602Parser.cpp index 528ad0f..a74ce52 100644 --- a/src/lib/SW602Parser.cpp +++ b/src/lib/SW602Parser.cpp @@ -19,7 +19,7 @@ namespace libsw602 { SW602ParserState::SW602ParserState(SW602ParserState::Type type, boost::shared_ptr<librevenge::RVNGInputStream> input) : - m_type(type), m_kind(SW602Document::KIND_TEXT), m_version(0), m_input(input), m_pageSpan(), + m_type(type), m_kind(SW602Document::KIND_TEXT), m_version(0), m_input(input), m_pageSpan(), m_converter(), m_graphicListener(), m_listManager(), m_spreadsheetListener(), m_textListener(), m_asciiFile(input) { m_listManager.reset(new SW602ListManager); diff --git a/src/lib/SW602Parser.h b/src/lib/SW602Parser.h index 7e5190d..389595c 100644 --- a/src/lib/SW602Parser.h +++ b/src/lib/SW602Parser.h @@ -14,6 +14,8 @@ #include <string> #include <vector> +#include <boost/shared_ptr.hpp> + #include <libsw602/libsw602.h> #include "SW602Debug.h" @@ -23,6 +25,8 @@ namespace libsw602 { +class SW602CharsetConverter; + /** a class to define the parser state */ class SW602ParserState { @@ -45,6 +49,8 @@ public: boost::shared_ptr<librevenge::RVNGInputStream> m_input; //! the actual document size SW602PageSpan m_pageSpan; + //! the charset converter + boost::shared_ptr<SW602CharsetConverter> m_converter; //! the graphic listener SW602GraphicListenerPtr m_graphicListener; diff --git a/src/lib/SW602SpreadsheetListener.cpp b/src/lib/SW602SpreadsheetListener.cpp index e2a598a..22a1b75 100644 --- a/src/lib/SW602SpreadsheetListener.cpp +++ b/src/lib/SW602SpreadsheetListener.cpp @@ -25,6 +25,7 @@ #include <librevenge/librevenge.h> #include "SW602Cell.h" +#include "SW602CharsetConverter.h" #include "SW602Chart.h" #include "SW602Font.h" #include "SW602GraphicListener.h" @@ -240,9 +241,7 @@ void SW602SpreadsheetListener::insertCharacter(unsigned char c) SW602_DEBUG_MSG(("SW602SpreadsheetListener::insertCharacter: called outside a text zone\n")); return; } - // TODO: handle - // int unicode = m_parserState.m_fontConverter->unicode(m_ps->m_font.id(), c); - int unicode = c; + const int unicode = m_parserState.m_converter->unicode(c); if (unicode == -1) { if (c < 0x20) @@ -1723,7 +1722,7 @@ void SW602SpreadsheetListener::openSheetCell(SW602Cell const &cell, SW602CellCon { librevenge::RVNGPropertyListVector formulaVect; for (size_t i=0; i < content.m_formula.size(); ++i) - formulaVect.append(content.m_formula[i].getPropertyList()); + formulaVect.append(content.m_formula[i].getPropertyList(*m_parserState.m_converter)); propList.insert("librevenge:formula", formulaVect); } bool hasFormula=!content.m_formula.empty(); diff --git a/src/lib/SW602TextListener.cpp b/src/lib/SW602TextListener.cpp index 73066b9..5903fb4 100644 --- a/src/lib/SW602TextListener.cpp +++ b/src/lib/SW602TextListener.cpp @@ -24,6 +24,7 @@ #include <librevenge/librevenge.h> #include "SW602Cell.h" +#include "SW602CharsetConverter.h" #include "SW602Font.h" #include "SW602GraphicEncoder.h" #include "SW602GraphicListener.h" @@ -205,9 +206,7 @@ void SW602TextListener::insertChar(uint8_t character) void SW602TextListener::insertCharacter(unsigned char c) { - // TODO: handle - // int unicode = m_parserState.m_fontConverter->unicode(m_ps->m_font.id(), c); - int unicode = c; + const int unicode = m_parserState.m_converter->unicode(c); if (unicode == -1) { if (c < 0x20) |