1 // -*- C++ -*- 2 // -------------------------------------------------------------------- 3 // Various utility classes 4 // -------------------------------------------------------------------- 5 /* 6 7 This file is part of the extensible drawing editor Ipe. 8 Copyright (c) 1993-2020 Otfried Cheong 9 10 Ipe is free software; you can redistribute it and/or modify it 11 under the terms of the GNU General Public License as published by 12 the Free Software Foundation; either version 3 of the License, or 13 (at your option) any later version. 14 15 As a special exception, you have permission to link Ipe with the 16 CGAL library and distribute executables, as long as you follow the 17 requirements of the Gnu General Public License in regard to all of 18 the software in the executable aside from CGAL. 19 20 Ipe is distributed in the hope that it will be useful, but WITHOUT 21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 23 License for more details. 24 25 You should have received a copy of the GNU General Public License 26 along with Ipe; if not, you can find it at 27 "http://www.gnu.org/copyleft/gpl.html", or write to the Free 28 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 29 30 */ 31 32 #ifndef IPEUTILS_H 33 #define IPEUTILS_H 34 35 #include "ipebitmap.h" 36 #include "ipepainter.h" 37 38 // -------------------------------------------------------------------- 39 40 namespace ipe { 41 42 class Page; 43 44 class BitmapFinder : public Visitor { 45 public: 46 void scanPage(const Page *page); 47 48 virtual void visitGroup(const Group *obj); 49 virtual void visitImage(const Image *obj); 50 public: 51 std::vector<Bitmap> iBitmaps; 52 }; 53 54 class BBoxPainter : public Painter { 55 public: 56 BBoxPainter(const Cascade *style); bbox()57 Rect bbox() const { return iBBox; } 58 59 protected: 60 virtual void doPush(); 61 virtual void doPop(); 62 virtual void doNewPath(); 63 virtual void doMoveTo(const Vector &v); 64 virtual void doLineTo(const Vector &v); 65 virtual void doCurveTo(const Vector &v1, const Vector &v2, 66 const Vector &v3); 67 virtual void doDrawPath(TPathMode mode); 68 virtual void doDrawBitmap(Bitmap bitmap); 69 virtual void doDrawText(const Text *text); 70 virtual void doAddClipPath(); 71 72 private: 73 Rect iBBox; 74 Vector iV; 75 Rect iPathBox; 76 std::list<Rect> iClipBox; 77 }; 78 79 class A85Stream : public Stream { 80 public: 81 A85Stream(Stream &stream); 82 virtual void putChar(char ch); 83 virtual void close(); 84 private: 85 Stream &iStream; 86 uint8_t iCh[4]; 87 int iN; 88 int iCol; 89 }; 90 91 class Base64Stream : public Stream { 92 public: 93 Base64Stream(Stream &stream); 94 virtual void putChar(char ch); 95 virtual void close(); 96 private: 97 Stream &iStream; 98 uint8_t iCh[3]; 99 int iN; 100 int iCol; 101 }; 102 103 class DeflateStream : public Stream { 104 public: 105 DeflateStream(Stream &stream, int level); 106 virtual ~DeflateStream(); 107 virtual void putChar(char ch); 108 virtual void close(); 109 110 static Buffer deflate(const char *data, int size, 111 int &deflatedSize, int compressLevel); 112 113 private: 114 struct Private; 115 116 Stream &iStream; 117 Private *iPriv; 118 int iN; 119 Buffer iIn; 120 Buffer iOut; 121 }; 122 123 class A85Source : public DataSource { 124 public: 125 A85Source(DataSource &source); 126 //! Get one more character, or EOF. 127 virtual int getChar(); 128 private: 129 DataSource &iSource; 130 bool iEof; 131 int iN; 132 int iIndex; 133 uint8_t iBuf[4]; 134 }; 135 136 class Base64Source : public DataSource { 137 public: 138 Base64Source(DataSource &source); 139 //! Get one more character, or EOF. 140 virtual int getChar(); 141 private: 142 DataSource &iSource; 143 bool iEof; 144 int iIndex; 145 int iBufLen; 146 uint8_t iBuf[3]; 147 }; 148 149 class InflateSource : public DataSource { 150 public: 151 InflateSource(DataSource &source); 152 virtual ~InflateSource(); 153 //! Get one more character, or EOF. 154 virtual int getChar(); 155 156 private: 157 void fillBuffer(); 158 159 private: 160 struct Private; 161 162 DataSource &iSource; 163 Private *iPriv; 164 char *iP; 165 Buffer iIn; 166 Buffer iOut; 167 }; 168 169 } // namespace 170 171 // -------------------------------------------------------------------- 172 #endif 173