~ubuntu-branches/ubuntu/vivid/libe-book/vivid-proposed

« back to all changes in this revision

Viewing changes to src/lib/ZTXTParser.cpp

  • Committer: Package Import Robot
  • Author(s): Rene Engelhard
  • Date: 2014-08-07 23:08:06 UTC
  • mfrom: (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20140807230806-o06a0n2dspjavqfm
Tags: 0.1.1-2
* upload to unstable

* fix debian/copyright; this is MPL-2.0 only 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
 
/* libe-book
3
 
 * Version: MPL 2.0 / LGPLv2.1+
 
2
/*
 
3
 * This file is part of the libe-book project.
4
4
 *
5
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 
 *
9
 
 * Alternatively, the contents of this file may be used under the terms
10
 
 * of the GNU Lesser General Public License Version 2.1 or later
11
 
 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
12
 
 * applicable instead of those above.
13
 
 *
14
 
 * For further information visit http://libebook.sourceforge.net
15
8
 */
16
9
 
17
 
#include <libwpd/WPXDocumentInterface.h>
18
 
#include <libwpd/WPXString.h>
19
 
 
20
 
#include <libwpd-stream/libwpd-stream.h>
 
10
#include <librevenge/librevenge.h>
 
11
#include <librevenge-stream/librevenge-stream.h>
21
12
 
22
13
#include "libebook_utils.h"
23
14
#include "EBOOKZlibStream.h"
31
22
static const uint32_t ZTXT_TYPE = PDX_CODE("zTXT");
32
23
static const uint32_t ZTXT_CREATOR = PDX_CODE("GPlm");
33
24
 
34
 
ZTXTParser::ZTXTParser(WPXInputStream *const input, WPXDocumentInterface *const document)
35
 
  : PDXParser(input, document)
 
25
ZTXTParser::ZTXTParser(librevenge::RVNGInputStream *const input, librevenge::RVNGTextInterface *const document)
 
26
  : PDXParser(input, document, ZTXT_TYPE, ZTXT_CREATOR)
36
27
  , m_recordCount(0)
37
28
  , m_size(0)
38
29
  , m_recordSize(0)
39
30
{
40
31
}
41
32
 
42
 
bool ZTXTParser::isFormatSupported(const unsigned type, const unsigned creator)
 
33
bool ZTXTParser::checkType(const unsigned type, const unsigned creator)
43
34
{
44
35
  return (ZTXT_TYPE == type) && (ZTXT_CREATOR == creator);
45
36
}
46
37
 
47
 
void ZTXTParser::readAppInfoRecord(WPXInputStream *)
48
 
{
49
 
}
50
 
 
51
 
void ZTXTParser::readSortInfoRecord(WPXInputStream *)
52
 
{
53
 
}
54
 
 
55
 
void ZTXTParser::readIndexRecord(WPXInputStream *const record)
 
38
void ZTXTParser::readAppInfoRecord(librevenge::RVNGInputStream *)
 
39
{
 
40
}
 
41
 
 
42
void ZTXTParser::readSortInfoRecord(librevenge::RVNGInputStream *)
 
43
{
 
44
}
 
45
 
 
46
void ZTXTParser::readIndexRecord(librevenge::RVNGInputStream *const record)
56
47
{
57
48
  readU16(record, true);
58
49
  m_recordCount = readU16(record, true);
61
52
  // the rest is not interesting...
62
53
}
63
54
 
64
 
void ZTXTParser::readDataRecord(WPXInputStream *const record, bool)
 
55
void ZTXTParser::readDataRecord(librevenge::RVNGInputStream *const record, bool)
65
56
{
66
 
  WPXString text;
67
 
  while (!record->atEOS())
 
57
  librevenge::RVNGString text;
 
58
  while (!record->isEnd())
68
59
  {
69
60
    const uint8_t c = readU8(record);
70
61
    if ('\n' == c)
82
73
 
83
74
void ZTXTParser::readDataRecords()
84
75
{
85
 
  const scoped_ptr<WPXInputStream> block(getDataRecords(0, m_recordCount - 1));
 
76
  const scoped_ptr<librevenge::RVNGInputStream> block(getDataRecords(0, m_recordCount - 1));
86
77
  EBOOKZlibStream input(block.get());
87
78
  openDocument();
88
79
  readDataRecord(&input);
91
82
 
92
83
void ZTXTParser::openDocument()
93
84
{
94
 
  WPXPropertyList metadata;
95
 
  metadata.insert("dc:title", WPXString(getName()));
 
85
  getDocument()->startDocument(librevenge::RVNGPropertyList());
96
86
 
97
 
  getDocument()->startDocument();
 
87
  librevenge::RVNGPropertyList metadata;
 
88
  metadata.insert("dc:title", librevenge::RVNGString(getName()));
98
89
  getDocument()->setDocumentMetaData(metadata);
99
 
  getDocument()->openPageSpan(WPXPropertyList());
 
90
 
 
91
  getDocument()->openPageSpan(librevenge::RVNGPropertyList());
100
92
}
101
93
 
102
94
void ZTXTParser::closeDocument()
105
97
  getDocument()->endDocument();
106
98
}
107
99
 
108
 
void ZTXTParser::handleText(const WPXString &text)
 
100
void ZTXTParser::handleText(const librevenge::RVNGString &text)
109
101
{
110
 
  getDocument()->openParagraph(WPXPropertyList(), WPXPropertyListVector());
111
 
  getDocument()->openSpan(WPXPropertyList());
 
102
  getDocument()->openParagraph(librevenge::RVNGPropertyList());
 
103
  getDocument()->openSpan(librevenge::RVNGPropertyList());
112
104
  getDocument()->insertText(text);
113
105
  getDocument()->closeSpan();
114
106
  getDocument()->closeParagraph();