MWAWPictData.hxx
Go to the documentation of this file.
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 (wrlach@gmail.com)
18 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
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 which can be stored in a
35  * WPXBinaryData, this includes :
36  * - the mac Pict format (in MWAWPictMac)
37  * - some old data names db3
38  * - some potential short data file
39  */
40 
41 #ifndef MWAW_PICT_DATA
42 # define MWAW_PICT_DATA
43 
44 # include <assert.h>
45 # include <ostream>
46 
47 # include <libwpd/libwpd.h>
48 
49 # include "libmwaw_internal.hxx"
50 # include "MWAWPict.hxx"
51 
52 class WPXBinaryData;
54 typedef shared_ptr<MWAWInputStream> MWAWInputStreamPtr;
55 
57 class MWAWPictData : public MWAWPict
58 {
59 public:
61  enum SubType { PictMac, DB3, Unknown };
63  virtual Type getType() const {
64  return MWAWPict::PictData;
65  }
67  virtual SubType getSubType() const = 0;
68 
70  virtual bool getBinary(WPXBinaryData &res, std::string &s) const {
71  if (!valid() || isEmpty()) return false;
72 
73  s = "image/pict";
74  createFileData(m_data, res);
75  return true;
76  }
77 
79  virtual bool sure() const {
80  return getSubType() != Unknown;
81  }
82 
84  virtual bool valid() const {
85  return false;
86  }
87 
89  bool isEmpty() const {
90  return m_empty;
91  }
92 
97  static ReadResult check(MWAWInputStreamPtr input, int size, Box2f &box) {
98  return checkOrGet(input, size, box, 0L);
99  }
100 
104  static MWAWPictData *get(MWAWInputStreamPtr input, int size) {
105  MWAWPictData *res = 0L;
106  Box2f box;
107  if (checkOrGet(input, size, box, &res) == MWAW_R_BAD) return 0L;
108  if (res) { // if the bdbox is good, we set it
109  Vec2f sz = box.size();
110  if (sz.x()>0 && sz.y()>0) res->setBdBox(box);
111  }
112  return res;
113  }
114 
117  virtual int cmp(MWAWPict const &a) const {
118  int diff = MWAWPict::cmp(a);
119  if (diff) return diff;
120  MWAWPictData const &aPict = static_cast<MWAWPictData const &>(a);
121 
122  diff = (int) m_empty - (int) aPict.m_empty;
123  if (diff) return (diff < 0) ? -1 : 1;
124  // the type
125  diff = getSubType() - aPict.getSubType();
126  if (diff) return (diff < 0) ? -1 : 1;
127 
128  if (m_data.size() < aPict.m_data.size())
129  return 1;
130  if (m_data.size() > aPict.m_data.size())
131  return -1;
132  unsigned char const *data=m_data.getDataBuffer();
133  unsigned char const *aData=m_data.getDataBuffer();
134  for (unsigned long c=0; c < m_data.size(); c++, data++, aData++) {
135  if (*data < *aData) return -1;
136  if (*data > *aData) return 1;
137  }
138  return 0;
139  }
140 
141 protected:
144  static bool createFileData(WPXBinaryData const &orig, WPXBinaryData &result);
145 
147  MWAWPictData(): m_data(), m_empty(false) { }
148  MWAWPictData(Box2f &): m_data(), m_empty(false) { }
149 
155  static ReadResult checkOrGet(MWAWInputStreamPtr input, int size,
156  Box2f &box, MWAWPictData **result = 0L);
157 
159  WPXBinaryData m_data;
160 
162  bool m_empty;
163 };
164 
166 class MWAWPictDB3 : public MWAWPictData
167 {
168 public:
170  virtual SubType getSubType() const {
171  return DB3;
172  }
173 
175  virtual bool valid() const {
176  return m_data.size() != 0;
177  }
178 
181  virtual int cmp(MWAWPict const &a) const {
182  return MWAWPictData::cmp(a);
183  }
184 
185 protected:
186 
189  m_empty = false;
190  }
191 
192  friend class MWAWPictData;
198  static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = 0L);
199 };
200 
203 {
204 public:
206  virtual SubType getSubType() const {
207  return Unknown;
208  }
209 
211  virtual bool valid() const {
212  return m_data.size() != 0;
213  }
214 
217  virtual int cmp(MWAWPict const &a) const {
218  return MWAWPictData::cmp(a);
219  }
220 
221 protected:
222 
225  m_empty = false;
226  }
227 
228  friend class MWAWPictData;
229 
235  static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = 0L);
236 };
237 
238 #endif
239 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Wed May 22 2013 18:12:38 for libmwaw by doxygen 1.8.1.2