Debian Codegraph @

src/lib/MWAWPictData.cxx

raw
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3 /* libmwaw
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2002 William Lachance ([email protected])
18 * Copyright (C) 2002,2004 Marc Maurer ([email protected])
19 * Copyright (C) 2004-2006 Fridrich Strba ([email protected])
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent ([email protected])
22 *
23 *
24 * All Rights Reserved.
25 *
26 * For minor contributions see the git repository.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30 * in which case the provisions of the LGPLv2+ are applicable
31 * instead of those above.
32 */
33
34 /* This header contains code specific to a pict mac file
35 */
36
37 #include <librevenge/librevenge.h>
38
39 #include "libmwaw_internal.hxx"
40 #include "MWAWInputStream.hxx"
41
42 #include "MWAWPictData.hxx"
43 #include "MWAWPictMac.hxx"
44
45 MWAWPictData::~MWAWPictData()
46 {
47 }
48
49 bool MWAWPictData::createFileData(librevenge::RVNGBinaryData const &orig, librevenge::RVNGBinaryData &result)
50 {
51 unsigned char buf[512];
52 for (unsigned char &i : buf) i = 0;
53 result.clear();
54 result.append(buf, 512);
55 result.append(orig);
56 return true;
57 }
58
59 MWAWPictData::ReadResult MWAWPictData::checkOrGet
60 (MWAWInputStreamPtr input, int size, MWAWBox2f &box, MWAWPictData **result)
61 {
62 if (result) *result=nullptr;
63 box = MWAWBox2f();
64
65 if (size <= 0) return MWAW_R_BAD;
66
67 // we can not read the data, ...
68 long actualPos = input->tell();
69 if (!input->checkPosition(actualPos+size))
70 return MWAW_R_BAD;
71 auto ok = MWAW_R_BAD;
72 if (ok == MWAW_R_BAD) {
73 input->seek(actualPos,librevenge::RVNG_SEEK_SET);
74 ok = MWAWPictMac::checkOrGet(input, size, box, result);
75 }
76 if (ok == MWAW_R_BAD) {
77 input->seek(actualPos,librevenge::RVNG_SEEK_SET);
78 ok = MWAWPictDB3::checkOrGet(input, size, result);
79 }
80 if (ok == MWAW_R_BAD) {
81 input->seek(actualPos,librevenge::RVNG_SEEK_SET);
82 ok = MWAWPictDUnknown::checkOrGet(input, size, result);
83 }
84
85 if (ok == MWAW_R_BAD) return MWAW_R_BAD;
86
87 if (result && *result && ok != MWAW_R_OK_EMPTY) {
88 // we must read the data
89 input->seek(actualPos, librevenge::RVNG_SEEK_SET);
90 input->readDataBlock(size, (*result)->m_data);
91 }
92 else
93 input->seek(actualPos+size, librevenge::RVNG_SEEK_SET);
94 return ok;
95 }
96
97 ////////////////////////////////////////////////////////////
98 ////////////////////////////////////////////////////////////
99 MWAWPictDB3::~MWAWPictDB3()
100 {
101 }
102
103 MWAWPictDB3::ReadResult MWAWPictDB3::checkOrGet
104 (MWAWInputStreamPtr input, int size, MWAWPictData **result)
105 {
106 if (result) *result=nullptr;
107
108 // we can not read the data, ...
109 long actualPos = input->tell();
110 input->seek(actualPos,librevenge::RVNG_SEEK_SET);
111 if (size <= 0xd || // to short, we ignore
112 long(input->readULong(2)) != size) {
113 return MWAW_R_BAD;
114 }
115
116 input->seek(actualPos+10,librevenge::RVNG_SEEK_SET);
117 if (input->readLong(2) != 0x11) return MWAW_R_BAD;
118
119 if (result) *result = new MWAWPictDB3;
120 return MWAW_R_OK;
121 }
122
123 ////////////////////////////////////////////////////////////
124 ////////////////////////////////////////////////////////////
125 MWAWPictDUnknown::~MWAWPictDUnknown()
126 {
127 }
128
129 MWAWPictDUnknown::ReadResult MWAWPictDUnknown::checkOrGet
130 (MWAWInputStreamPtr /*input*/, int size, MWAWPictData **result)
131 {
132 if (result) *result=nullptr;
133
134 // too small or too dangerous
135 if (size < 0xD || size > 1000) return MWAW_R_BAD;
136 if (result) *result = new MWAWPictDUnknown;
137 return MWAW_R_MAYBE;
138 }
139 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: