CDRCollector.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 __CDRCOLLECTOR_H__
00031 #define __CDRCOLLECTOR_H__
00032 
00033 #include <map>
00034 #include <vector>
00035 #include <stack>
00036 #include <libwpg/libwpg.h>
00037 #include <libwpd-stream/libwpd-stream.h>
00038 #include <lcms2.h>
00039 #include "CDRTypes.h"
00040 #include "CDRPath.h"
00041 #include "CDROutputElementList.h"
00042 #include "libcdr_utils.h"
00043 
00044 namespace
00045 {
00046 #include "CDRColorProfiles.h"
00047 }
00048 
00049 namespace libcdr
00050 {
00051 
00052 class CDRParserState
00053 {
00054 public:
00055   CDRParserState();
00056   ~CDRParserState();
00057   std::map<unsigned, WPXBinaryData> m_bmps;
00058   std::map<unsigned, CDRPattern> m_patterns;
00059   std::map<unsigned, WPXBinaryData> m_vects;
00060   std::vector<CDRPage> m_pages;
00061   std::map<unsigned, CDRColor> m_documentPalette;
00062   std::map<unsigned, std::vector<CDRTextLine> > m_texts;
00063 
00064   unsigned _getRGBColor(const CDRColor &color);
00065   unsigned getBMPColor(const CDRColor &color);
00066   WPXString getRGBColorString(const CDRColor &color);
00067   cmsHTRANSFORM m_colorTransformCMYK2RGB;
00068   cmsHTRANSFORM m_colorTransformLab2RGB;
00069   cmsHTRANSFORM m_colorTransformRGB2RGB;
00070 
00071   void setColorTransform(const std::vector<unsigned char> &profile);
00072   void setColorTransform(WPXInputStream *input);
00073 
00074 private:
00075   CDRParserState(const CDRParserState &);
00076   CDRParserState &operator=(const CDRParserState &);
00077 };
00078 
00079 class CDRCollector
00080 {
00081 public:
00082   CDRCollector() {}
00083   virtual ~CDRCollector() {}
00084 
00085   // collector functions
00086   virtual void collectPage(unsigned level) = 0;
00087   virtual void collectObject(unsigned level) = 0;
00088   virtual void collectGroup(unsigned level) = 0;
00089   virtual void collectVect(unsigned level) = 0;
00090   virtual void collectOtherList() = 0;
00091   virtual void collectCubicBezier(double x1, double y1, double x2, double y2, double x, double y) = 0;
00092   virtual void collectQuadraticBezier(double x1, double y1, double x, double y) = 0;
00093   virtual void collectMoveTo(double x, double y) = 0;
00094   virtual void collectLineTo(double x, double y) = 0;
00095   virtual void collectArcTo(double rx, double ry, bool largeArc, bool sweep, double x, double y) = 0;
00096   virtual void collectClosePath() = 0;
00097   virtual void collectLevel(unsigned level) = 0;
00098   virtual void collectTransform(const CDRTransforms &transforms, bool considerGroupTransform) = 0;
00099   virtual void collectFillStyle(unsigned short fillType, const CDRColor &color1, const CDRColor &color2, const CDRGradient &gradient, const CDRImageFill &imageFill) = 0;
00100   virtual void collectLineStyle(unsigned short lineType, unsigned short capsType, unsigned short joinType, double lineWidth,
00101                                 double stretch, double angle, const CDRColor &color, const std::vector<unsigned> &dashArray,
00102                                 unsigned startMarkerId, unsigned endMarkerId) = 0;
00103   virtual void collectRotate(double angle, double cx, double cy) = 0;
00104   virtual void collectFlags(unsigned flags, bool considerFlags) = 0;
00105   virtual void collectPageSize(double width, double height, double offsetX, double offsetY) = 0;
00106   virtual void collectPolygonTransform(unsigned numAngles, unsigned nextPoint, double rx, double ry, double cx, double cy) = 0;
00107   virtual void collectBitmap(unsigned imageId, double x1, double x2, double y1, double y2) = 0;
00108   virtual void collectBmp(unsigned imageId, unsigned colorModel, unsigned width, unsigned height, unsigned bpp, const std::vector<unsigned> &palette, const std::vector<unsigned char> &bitmap) = 0;
00109   virtual void collectBmp(unsigned imageId, const std::vector<unsigned char> &bitmap) = 0;
00110   virtual void collectBmpf(unsigned patternId, unsigned width, unsigned height, const std::vector<unsigned char> &pattern) = 0;
00111   virtual void collectPpdt(const std::vector<std::pair<double, double> > &points, const std::vector<unsigned> &knotVector) = 0;
00112   virtual void collectFillTransform(const CDRTransforms &fillTrafos) = 0;
00113   virtual void collectFillOpacity(double opacity) = 0;
00114   virtual void collectPolygon() = 0;
00115   virtual void collectSpline() = 0;
00116   virtual void collectColorProfile(const std::vector<unsigned char> &profile) = 0;
00117   virtual void collectBBox(double x0, double y0, double x1, double y1) = 0;
00118   virtual void collectSpnd(unsigned spnd) = 0;
00119   virtual void collectVectorPattern(unsigned id, const WPXBinaryData &data) = 0;
00120   virtual void collectPaletteEntry(unsigned colorId, unsigned userId, const CDRColor &color) = 0;
00121   virtual void collectText(unsigned textId, unsigned styleId, const std::vector<unsigned char> &data,
00122                            const std::vector<unsigned char> &charDescriptions, const std::map<unsigned, CDRCharacterStyle> &styleOverrides) = 0;
00123   virtual void collectArtisticText(double x, double y) = 0;
00124   virtual void collectParagraphText(double x, double y, double width, double height) = 0;
00125   virtual void collectStld(unsigned id, const CDRCharacterStyle &charStyle) = 0;
00126 };
00127 
00128 } // namespace libcdr
00129 
00130 #endif /* __CDRCOLLECTOR_H__ */
00131 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */