MWAWPictMac.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
00002 
00003 /* libmwaw
00004 * Version: MPL 2.0 / LGPLv2+
00005 *
00006 * The contents of this file are subject to the Mozilla Public License Version
00007 * 2.0 (the "License"); you may not use this file except in compliance with
00008 * the License or as specified alternatively below. You may obtain a copy of
00009 * the License at http://www.mozilla.org/MPL/
00010 *
00011 * Software distributed under the License is distributed on an "AS IS" basis,
00012 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013 * for the specific language governing rights and limitations under the
00014 * License.
00015 *
00016 * Major Contributor(s):
00017 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00018 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
00019 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00020 * Copyright (C) 2006, 2007 Andrew Ziem
00021 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
00022 *
00023 *
00024 * All Rights Reserved.
00025 *
00026 * For minor contributions see the git repository.
00027 *
00028 * Alternatively, the contents of this file may be used under the terms of
00029 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00030 * in which case the provisions of the LGPLv2+ are applicable
00031 * instead of those above.
00032 */
00033 
00034 /* This header contains code specific to a pict mac file
00035  * see http://developer.apple.com/legacy/mac/library/documentation/mac/QuickDraw/QuickDraw-458.html
00036  */
00037 
00038 #ifndef MWAW_PICT_MWAW
00039 #  define MWAW_PICT_MWAW
00040 
00041 #  include <assert.h>
00042 #  include <ostream>
00043 #  include <string>
00044 
00045 #  include <libwpd/libwpd.h>
00046 
00047 #  include "libmwaw_internal.hxx"
00048 #  include "MWAWPictData.hxx"
00049 
00051 class MWAWPictMac : public MWAWPictData
00052 {
00053 public:
00054 
00056   virtual SubType getSubType() const {
00057     return MWAWPictData::PictMac;
00058   }
00059 
00061   virtual bool getBinary(WPXBinaryData &res, std::string &s) const {
00062     if (!valid() || isEmpty()) return false;
00063 
00064     s = "image/pict";
00065     if (m_version == 1) {
00066       WPXBinaryData dataV2;
00067       if (convertPict1To2(m_data, dataV2)) {
00068         createFileData(dataV2, res);
00069         return true;
00070       }
00071     }
00072     createFileData(m_data, res);
00073     return true;
00074   }
00075 
00077   virtual bool valid() const {
00078     return (m_version >= 1) && (m_version <= 2);
00079   }
00080 
00083   virtual int cmp(MWAWPict const &a) const {
00084     int diff = MWAWPictData::cmp(a);
00085     if (diff) return diff;
00086     MWAWPictMac const &aPict = static_cast<MWAWPictMac const &>(a);
00087 
00088     diff = m_version - (int) aPict.m_version;
00089     if (diff) return (diff < 0) ? -1 : 1;
00090     diff = m_subVersion - (int) aPict.m_subVersion;
00091     if (diff) return (diff < 0) ? -1 : 1;
00092 
00093     return 0;
00094   }
00095 
00097   static bool convertPict1To2(WPXBinaryData const &orig, WPXBinaryData &result);
00098 
00102   static void parsePict1(WPXBinaryData const &orig, std::string const &fname);
00103 
00107   static void parsePict2(WPXBinaryData const &orig, std::string const &fname);
00108 
00109 protected:
00111   MWAWPictMac(Box2f box) : MWAWPictData(box), m_version(-1), m_subVersion(-1) {
00112     extendBDBox(1.0);
00113   }
00114 
00115   friend class MWAWPictData;
00122   static ReadResult checkOrGet(MWAWInputStreamPtr input, int size,
00123                                Box2f &box, MWAWPictData **result = 0L);
00124 
00126   int m_version;
00128   int m_subVersion;
00129 };
00130 
00131 #endif
00132 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: