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  long diffL = (long) m_data.size() - (long) aPict.m_data.size();
125  if (diffL) return (diff < 0) ? -1 : 1;
126 
127  // the type
128  diff = getSubType() - aPict.getSubType();
129  if (diff) return (diff < 0) ? -1 : 1;
130 
131  return 0;
132  }
133 
134 protected:
137  static bool createFileData(WPXBinaryData const &orig, WPXBinaryData &result);
138 
140  MWAWPictData(): m_data(), m_empty(false) { }
141  MWAWPictData(Box2f &): m_data(), m_empty(false) { }
142 
148  static ReadResult checkOrGet(MWAWInputStreamPtr input, int size,
149  Box2f &box, MWAWPictData **result = 0L);
150 
152  WPXBinaryData m_data;
153 
155  bool m_empty;
156 };
157 
159 class MWAWPictDB3 : public MWAWPictData
160 {
161 public:
163  virtual SubType getSubType() const {
164  return DB3;
165  }
166 
168  virtual bool valid() const {
169  return m_data.size() != 0;
170  }
171 
174  virtual int cmp(MWAWPict const &a) const {
175  return MWAWPictData::cmp(a);
176  }
177 
178 protected:
179 
182  m_empty = false;
183  }
184 
185  friend class MWAWPictData;
191  static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = 0L);
192 };
193 
196 {
197 public:
199  virtual SubType getSubType() const {
200  return Unknown;
201  }
202 
204  virtual bool valid() const {
205  return m_data.size() != 0;
206  }
207 
210  virtual int cmp(MWAWPict const &a) const {
211  return MWAWPictData::cmp(a);
212  }
213 
214 protected:
215 
218  m_empty = false;
219  }
220 
221  friend class MWAWPictData;
222 
228  static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = 0L);
229 };
230 
231 #endif
232 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Sat May 4 2013 20:11:08 for libmwaw by doxygen 1.8.3.1