CDRContentCollector.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* libcdr
00003  * Version: MPL 1.1 / GPLv2+ / LGPLv2+
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License or as specified alternatively below. You may obtain a copy of
00008  * the License at http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * Major Contributor(s):
00016  * Copyright (C) 2012 Fridrich Strba <fridrich.strba@bluewin.ch>
00017  *
00018  *
00019  * All Rights Reserved.
00020  *
00021  * For minor contributions see the git repository.
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
00025  * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00026  * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
00027  * instead of those above.
00028  */
00029 
00030 #ifndef __CDRCONTENTCOLLECTOR_H__
00031 #define __CDRCONTENTCOLLECTOR_H__
00032 
00033 #include <map>
00034 #include <vector>
00035 #include <stack>
00036 #include <libwpg/libwpg.h>
00037 #include <lcms2.h>
00038 #include "CDRTypes.h"
00039 #include "CDRPath.h"
00040 #include "CDROutputElementList.h"
00041 #include "CDRCollector.h"
00042 
00043 namespace libcdr
00044 {
00045 
00046 class CDRContentCollector : public CDRCollector
00047 {
00048 public:
00049   CDRContentCollector(CDRParserState &ps, ::libwpg::WPGPaintInterface *painter);
00050   virtual ~CDRContentCollector();
00051 
00052   // collector functions
00053   void collectPage(unsigned level);
00054   void collectObject(unsigned level);
00055   void collectGroup(unsigned level);
00056   void collectVect(unsigned level);
00057   void collectOtherList();
00058   void collectCubicBezier(double x1, double y1, double x2, double y2, double x, double y);
00059   void collectQuadraticBezier(double x1, double y1, double x, double y);
00060   void collectMoveTo(double x, double y);
00061   void collectLineTo(double x, double y);
00062   void collectArcTo(double rx, double ry, bool largeArc, bool sweep, double x, double y);
00063   void collectClosePath();
00064   void collectLevel(unsigned level);
00065   void collectTransform(const CDRTransforms &transforms, bool considerGroupTransform);
00066   void collectFillStyle(unsigned short fillType, const CDRColor &color1, const CDRColor &color2, const CDRGradient &gradient, const CDRImageFill &imageFill);
00067   void collectLineStyle(unsigned short lineType, unsigned short capsType, unsigned short joinType, double lineWidth,
00068                         double stretch, double angle, const CDRColor &color, const std::vector<unsigned> &dashArray,
00069                         unsigned startMarkerId, unsigned endMarkerId);
00070   void collectRotate(double angle, double cx, double cy);
00071   void collectFlags(unsigned flags, bool considerFlags);
00072   void collectPageSize(double, double, double, double) {}
00073   void collectPolygonTransform(unsigned numAngles, unsigned nextPoint, double rx, double ry, double cx, double cy);
00074   void collectBitmap(unsigned imageId, double x1, double x2, double y1, double y2);
00075   void collectBmp(unsigned, unsigned, unsigned, unsigned, unsigned, const std::vector<unsigned> &, const std::vector<unsigned char> &) {}
00076   void collectBmp(unsigned, const std::vector<unsigned char> &) {}
00077   void collectBmpf(unsigned, unsigned, unsigned, const std::vector<unsigned char> &) {}
00078   void collectPpdt(const std::vector<std::pair<double, double> > &points, const std::vector<unsigned> &knotVector);
00079   void collectFillTransform(const CDRTransforms &fillTrafo);
00080   void collectFillOpacity(double opacity);
00081   void collectPolygon();
00082   void collectSpline();
00083   void collectColorProfile(const std::vector<unsigned char> &) {}
00084   void collectBBox(double x0, double y0, double x1, double y1);
00085   void collectSpnd(unsigned spnd);
00086   void collectVectorPattern(unsigned id, const WPXBinaryData &data);
00087   void collectPaletteEntry(unsigned, unsigned, const CDRColor &) {}
00088   void collectText(unsigned, unsigned, const std::vector<unsigned char> &,
00089                    const std::vector<unsigned char> &, const std::map<unsigned, CDRCharacterStyle> &) {}
00090   void collectArtisticText(double x, double y);
00091   void collectParagraphText(double x, double y, double width, double height);
00092   void collectStld(unsigned, const CDRCharacterStyle &) {}
00093 
00094 private:
00095   CDRContentCollector(const CDRContentCollector &);
00096   CDRContentCollector &operator=(const CDRContentCollector &);
00097 
00098   // helper functions
00099   void _startPage(double width, double height);
00100   void _endPage();
00101   void _flushCurrentPath();
00102 
00103   void _fillProperties(WPXPropertyList &propList, WPXPropertyListVector &vec);
00104   void _lineProperties(WPXPropertyList &propList);
00105   void _generateBitmapFromPattern(WPXBinaryData &bitmap, const CDRPattern &pattern, const CDRColor &fgColor, const CDRColor &bgColor);
00106 
00107   libwpg::WPGPaintInterface *m_painter;
00108 
00109   bool m_isPageProperties;
00110   bool m_isPageStarted;
00111   bool m_ignorePage;
00112 
00113   CDRPage m_page;
00114   unsigned m_pageIndex;
00115   CDRFillStyle m_currentFillStyle;
00116   CDRLineStyle m_currentLineStyle;
00117   unsigned m_spnd;
00118   unsigned m_currentObjectLevel, m_currentGroupLevel, m_currentVectLevel, m_currentPageLevel;
00119   CDRImage m_currentImage;
00120   const std::vector<CDRTextLine> *m_currentText;
00121   CDRBox m_currentBBox;
00122   CDRBox m_currentTextBox;
00123 
00124   CDRPath m_currentPath;
00125   CDRTransforms m_currentTransforms;
00126   CDRTransforms m_fillTransforms;
00127   CDRPolygon *m_polygon;
00128   bool m_isInPolygon;
00129   bool m_isInSpline;
00130   std::stack<CDROutputElementList> *m_outputElements;
00131   std::stack<CDROutputElementList> m_contentOutputElements;
00132   std::stack<CDROutputElementList> m_fillOutputElements;
00133   std::stack<unsigned> m_groupLevels;
00134   std::stack<CDRTransforms> m_groupTransforms;
00135   CDRSplineData m_splineData;
00136   double m_fillOpacity;
00137 
00138   CDRParserState &m_ps;
00139 };
00140 
00141 } // namespace libcdr
00142 
00143 #endif /* __CDRCOLLECTOR_H__ */
00144 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */