/src/libwpd/src/lib/WP1PictureGroup.cpp
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ |
2 | | /* libwpd |
3 | | * Version: MPL 2.0 / LGPLv2.1+ |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * Major Contributor(s): |
10 | | * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch) |
11 | | * |
12 | | * For minor contributions see the git repository. |
13 | | * |
14 | | * Alternatively, the contents of this file may be used under the terms |
15 | | * of the GNU Lesser General Public License Version 2.1 or later |
16 | | * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are |
17 | | * applicable instead of those above. |
18 | | * |
19 | | * For further information visit http://libwpd.sourceforge.net |
20 | | */ |
21 | | |
22 | | /* "This product is not manufactured, approved, or supported by |
23 | | * Corel Corporation or Corel Corporation Limited." |
24 | | */ |
25 | | |
26 | | #include "WP1PictureGroup.h" |
27 | | #include "libwpd_internal.h" |
28 | | |
29 | | #ifndef DUMP_PICTURE |
30 | | #define DUMP_PICTURE 0 |
31 | | #endif |
32 | | |
33 | | #if DUMP_PICTURE |
34 | | static unsigned pictureId = 0; |
35 | | #include <sstream> |
36 | | #endif |
37 | | |
38 | | WP1PictureGroup::WP1PictureGroup(librevenge::RVNGInputStream *input, WPXEncryption *encryption, unsigned char group) : |
39 | 0 | WP1VariableLengthGroup(group), |
40 | 0 | m_binaryData(), |
41 | 0 | m_width(0), |
42 | 0 | m_height(0) |
43 | 0 | { |
44 | 0 | _read(input, encryption); |
45 | 0 | } |
46 | | |
47 | | WP1PictureGroup::~WP1PictureGroup() |
48 | 0 | { |
49 | 0 | } |
50 | | |
51 | | void WP1PictureGroup::_readContents(librevenge::RVNGInputStream *input, WPXEncryption *encryption) |
52 | 0 | { |
53 | 0 | m_binaryData.clear(); |
54 | 0 | unsigned char tmpWhatNot = readU8(input, encryption); |
55 | 0 | if (tmpWhatNot) |
56 | 0 | input->seek(1, librevenge::RVNG_SEEK_CUR); |
57 | 0 | m_width = readU16(input, encryption, true); |
58 | 0 | m_height = readU16(input, encryption, true); |
59 | 0 | input->seek(6, librevenge::RVNG_SEEK_CUR); |
60 | 0 | unsigned dataSize = readU16(input, encryption, true); |
61 | 0 | WPD_DEBUG_MSG(("WP1PictureGroup: Offset = 0x%.4x, Width = %i, Height = %i, Data Size = 0x%.4x\n", (unsigned)input->tell(), m_width, m_height, dataSize)); |
62 | 0 | if (dataSize + 13 > getSize()) |
63 | 0 | return; |
64 | 0 | for (int i = 0; i < 512; i++) |
65 | 0 | m_binaryData.append((unsigned char)0); |
66 | 0 | m_binaryData.append((unsigned char)((dataSize + 512)>>8)); |
67 | 0 | m_binaryData.append((unsigned char)(dataSize + 512)); |
68 | 0 | for (unsigned long j = 2; j < dataSize && !input->isEnd(); j++) |
69 | 0 | m_binaryData.append(readU8(input, encryption)); |
70 | | #if DUMP_PICTURE |
71 | | std::ostringstream filename; |
72 | | filename << "binarydump" << pictureId++ << ".pct"; |
73 | | FILE *f = fopen(filename.str().c_str(), "wb"); |
74 | | if (f) |
75 | | { |
76 | | librevenge::RVNGInputStream *tmpStream = m_binaryData.getDataStream(); |
77 | | while (!tmpStream->isEnd()) |
78 | | fprintf(f, "%c", readU8(tmpStream, 0)); |
79 | | fclose(f); |
80 | | } |
81 | | #endif |
82 | 0 | } |
83 | | |
84 | | void WP1PictureGroup::parse(WP1Listener *listener) |
85 | 0 | { |
86 | 0 | WPD_DEBUG_MSG(("WordPerfect: handling a Picture group\n")); |
87 | 0 | listener->insertPicture(m_width, m_height, m_binaryData); |
88 | 0 | } |
89 | | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |