1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * The Contents of this file are made available subject to 6*cdf0e10cSrcweir * the terms of GNU General Public License Version 2. 7*cdf0e10cSrcweir * 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * GNU General Public License, version 2 10*cdf0e10cSrcweir * ============================================= 11*cdf0e10cSrcweir * Copyright 2005 by Sun Microsystems, Inc. 12*cdf0e10cSrcweir * 901 San Antonio Road, Palo Alto, CA 94303, USA 13*cdf0e10cSrcweir * 14*cdf0e10cSrcweir * This program is free software; you can redistribute it and/or 15*cdf0e10cSrcweir * modify it under the terms of the GNU General Public License as 16*cdf0e10cSrcweir * published by the Free Software Foundation; either version 2 of 17*cdf0e10cSrcweir * the License, or (at your option) any later version. 18*cdf0e10cSrcweir * 19*cdf0e10cSrcweir * This program is distributed in the hope that it will be useful, 20*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 21*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22*cdf0e10cSrcweir * GNU General Public License for more details. 23*cdf0e10cSrcweir * 24*cdf0e10cSrcweir * You should have received a copy of the GNU General Public 25*cdf0e10cSrcweir * License along with this program; if not, write to the Free 26*cdf0e10cSrcweir * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 27*cdf0e10cSrcweir * Boston, MA 02110-1301, USA. 28*cdf0e10cSrcweir * 29*cdf0e10cSrcweir ************************************************************************/ 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #ifndef INCLUDED_PDFI_OUTDEV_HXX 32*cdf0e10cSrcweir #define INCLUDED_PDFI_OUTDEV_HXX 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #if defined __GNUC__ 35*cdf0e10cSrcweir #pragma GCC system_header 36*cdf0e10cSrcweir #elif defined __SUNPRO_CC 37*cdf0e10cSrcweir #pragma disable_warn 38*cdf0e10cSrcweir #elif defined _MSC_VER 39*cdf0e10cSrcweir #pragma warning(push, 1) 40*cdf0e10cSrcweir #endif 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #include "GfxState.h" 43*cdf0e10cSrcweir #include "GfxFont.h" 44*cdf0e10cSrcweir #include "UnicodeMap.h" 45*cdf0e10cSrcweir #include "Link.h" 46*cdf0e10cSrcweir #include "Object.h" 47*cdf0e10cSrcweir #include "OutputDev.h" 48*cdf0e10cSrcweir #ifndef SYSTEM_POPPLER 49*cdf0e10cSrcweir # include "parseargs.h" 50*cdf0e10cSrcweir #endif 51*cdf0e10cSrcweir #include "GlobalParams.h" 52*cdf0e10cSrcweir #include "PDFDoc.h" 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir #if defined __SUNPRO_CC 55*cdf0e10cSrcweir #pragma enable_warn 56*cdf0e10cSrcweir #elif defined _MSC_VER 57*cdf0e10cSrcweir #pragma warning(pop) 58*cdf0e10cSrcweir #endif 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir #include <hash_map> 61*cdf0e10cSrcweir #include <vector> 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir class GfxPath; 64*cdf0e10cSrcweir class GfxFont; 65*cdf0e10cSrcweir class PDFDoc; 66*cdf0e10cSrcweir #ifndef SYSTEM_POPPLER 67*cdf0e10cSrcweir typedef GString GooString; 68*cdf0e10cSrcweir #endif 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir namespace pdfi 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir struct FontAttributes 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir FontAttributes( const GooString& familyName_, 75*cdf0e10cSrcweir bool isEmbedded_, 76*cdf0e10cSrcweir bool isBold_, 77*cdf0e10cSrcweir bool isItalic_, 78*cdf0e10cSrcweir bool isUnderline_, 79*cdf0e10cSrcweir double size_ ) : 80*cdf0e10cSrcweir familyName(), 81*cdf0e10cSrcweir isEmbedded(isEmbedded_), 82*cdf0e10cSrcweir isBold(isBold_), 83*cdf0e10cSrcweir isItalic(isItalic_), 84*cdf0e10cSrcweir isUnderline(isUnderline_), 85*cdf0e10cSrcweir size(size_) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir familyName.append(const_cast<GooString*>(&familyName_)); 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir FontAttributes() : 91*cdf0e10cSrcweir familyName(), 92*cdf0e10cSrcweir isEmbedded(false), 93*cdf0e10cSrcweir isBold(false), 94*cdf0e10cSrcweir isItalic(false), 95*cdf0e10cSrcweir isUnderline(false), 96*cdf0e10cSrcweir size(0.0) 97*cdf0e10cSrcweir {} 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir // xdpf goo stuff is so totally borked... 100*cdf0e10cSrcweir // ...need to hand-code assignment 101*cdf0e10cSrcweir FontAttributes( const FontAttributes& rSrc ) : 102*cdf0e10cSrcweir familyName(), 103*cdf0e10cSrcweir isEmbedded(rSrc.isEmbedded), 104*cdf0e10cSrcweir isBold(rSrc.isBold), 105*cdf0e10cSrcweir isItalic(rSrc.isItalic), 106*cdf0e10cSrcweir isUnderline(rSrc.isUnderline), 107*cdf0e10cSrcweir size(rSrc.size) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir familyName.append(const_cast<GooString*>(&rSrc.familyName)); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir FontAttributes& operator=( const FontAttributes& rSrc ) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir familyName.clear(); 115*cdf0e10cSrcweir familyName.append(const_cast<GooString*>(&rSrc.familyName)); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir isEmbedded = rSrc.isEmbedded; 118*cdf0e10cSrcweir isBold = rSrc.isBold; 119*cdf0e10cSrcweir isItalic = rSrc.isItalic; 120*cdf0e10cSrcweir isUnderline = rSrc.isUnderline; 121*cdf0e10cSrcweir size = rSrc.size; 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir return *this; 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir bool operator==(const FontAttributes& rFont) const 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir return const_cast<GooString*>(&familyName)->cmp( 129*cdf0e10cSrcweir const_cast<GooString*>(&rFont.familyName))==0 && 130*cdf0e10cSrcweir isEmbedded == rFont.isEmbedded && 131*cdf0e10cSrcweir isBold == rFont.isBold && 132*cdf0e10cSrcweir isItalic == rFont.isItalic && 133*cdf0e10cSrcweir isUnderline == rFont.isUnderline && 134*cdf0e10cSrcweir size == rFont.size; 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir GooString familyName; 138*cdf0e10cSrcweir bool isEmbedded; 139*cdf0e10cSrcweir bool isBold; 140*cdf0e10cSrcweir bool isItalic; 141*cdf0e10cSrcweir bool isUnderline; 142*cdf0e10cSrcweir double size; 143*cdf0e10cSrcweir }; 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir class PDFOutDev : public OutputDev 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir // not owned by this class 148*cdf0e10cSrcweir PDFDoc* m_pDoc; 149*cdf0e10cSrcweir mutable std::hash_map< long long, 150*cdf0e10cSrcweir FontAttributes > m_aFontMap; 151*cdf0e10cSrcweir UnicodeMap* m_pUtf8Map; 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir int parseFont( long long nNewId, GfxFont* pFont, GfxState* state ) const; 154*cdf0e10cSrcweir void writeFontFile( GfxFont* gfxFont ) const; 155*cdf0e10cSrcweir void printPath( GfxPath* pPath ) const; 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir public: 158*cdf0e10cSrcweir explicit PDFOutDev( PDFDoc* pDoc ); 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir //----- get info about output device 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir // Does this device use upside-down coordinates? 163*cdf0e10cSrcweir // (Upside-down means (0,0) is the top left corner of the page.) 164*cdf0e10cSrcweir virtual GBool upsideDown() { return gTrue; } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir // Does this device use drawChar() or drawString()? 167*cdf0e10cSrcweir virtual GBool useDrawChar() { return gTrue; } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir // Does this device use beginType3Char/endType3Char? Otherwise, 170*cdf0e10cSrcweir // text in Type 3 fonts will be drawn with drawChar/drawString. 171*cdf0e10cSrcweir virtual GBool interpretType3Chars() { return gFalse; } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir // Does this device need non-text content? 174*cdf0e10cSrcweir virtual GBool needNonText() { return gTrue; } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir //----- initialization and control 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir // Set default transform matrix. 179*cdf0e10cSrcweir virtual void setDefaultCTM(double *ctm); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir // Start a page. 182*cdf0e10cSrcweir virtual void startPage(int pageNum, GfxState *state); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir // End a page. 185*cdf0e10cSrcweir virtual void endPage(); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir // Dump page contents to display. 188*cdf0e10cSrcweir // virtual void dump() {} 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir //----- coordinate conversion 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir // Convert between device and user coordinates. 193*cdf0e10cSrcweir // virtual void cvtDevToUser(double dx, double dy, double *ux, double *uy); 194*cdf0e10cSrcweir // virtual void cvtUserToDev(double ux, double uy, int *dx, int *dy); 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir //----- link borders 197*cdf0e10cSrcweir virtual void processLink(Link *link, Catalog *catalog); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir //----- save/restore graphics state 200*cdf0e10cSrcweir virtual void saveState(GfxState *state); 201*cdf0e10cSrcweir virtual void restoreState(GfxState *state); 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir //----- update graphics state 204*cdf0e10cSrcweir // virtual void updateAll(GfxState *state); 205*cdf0e10cSrcweir virtual void updateCTM(GfxState *state, double m11, double m12, 206*cdf0e10cSrcweir double m21, double m22, double m31, double m32); 207*cdf0e10cSrcweir virtual void updateLineDash(GfxState *state); 208*cdf0e10cSrcweir virtual void updateFlatness(GfxState *state); 209*cdf0e10cSrcweir virtual void updateLineJoin(GfxState *state); 210*cdf0e10cSrcweir virtual void updateLineCap(GfxState *state); 211*cdf0e10cSrcweir virtual void updateMiterLimit(GfxState *state); 212*cdf0e10cSrcweir virtual void updateLineWidth(GfxState *state); 213*cdf0e10cSrcweir virtual void updateFillColor(GfxState *state); 214*cdf0e10cSrcweir virtual void updateStrokeColor(GfxState *state); 215*cdf0e10cSrcweir virtual void updateFillOpacity(GfxState *state); 216*cdf0e10cSrcweir virtual void updateStrokeOpacity(GfxState *state); 217*cdf0e10cSrcweir virtual void updateBlendMode(GfxState *state); 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir //----- update text state 220*cdf0e10cSrcweir virtual void updateFont(GfxState *state); 221*cdf0e10cSrcweir // virtual void updateTextMat(GfxState *state); 222*cdf0e10cSrcweir // virtual void updateCharSpace(GfxState *state) {} 223*cdf0e10cSrcweir virtual void updateRender(GfxState *state); 224*cdf0e10cSrcweir // virtual void updateRise(GfxState *state) {} 225*cdf0e10cSrcweir // virtual void updateWordSpace(GfxState *state) {} 226*cdf0e10cSrcweir // virtual void updateHorizScaling(GfxState *state) {} 227*cdf0e10cSrcweir // virtual void updateTextPos(GfxState *state) {} 228*cdf0e10cSrcweir // virtual void updateTextShift(GfxState *state, double shift) {} 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir //----- path painting 231*cdf0e10cSrcweir virtual void stroke(GfxState *state); 232*cdf0e10cSrcweir virtual void fill(GfxState *state); 233*cdf0e10cSrcweir virtual void eoFill(GfxState *state); 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir //----- path clipping 236*cdf0e10cSrcweir virtual void clip(GfxState *state); 237*cdf0e10cSrcweir virtual void eoClip(GfxState *state); 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir //----- text drawing 240*cdf0e10cSrcweir virtual void drawChar(GfxState *state, double x, double y, 241*cdf0e10cSrcweir double dx, double dy, 242*cdf0e10cSrcweir double originX, double originY, 243*cdf0e10cSrcweir CharCode code, int nBytes, Unicode *u, int uLen); 244*cdf0e10cSrcweir virtual void drawString(GfxState *state, GooString *s); 245*cdf0e10cSrcweir virtual void endTextObject(GfxState *state); 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir //----- image drawing 248*cdf0e10cSrcweir virtual void drawImageMask(GfxState *state, Object *ref, Stream *str, 249*cdf0e10cSrcweir int width, int height, GBool invert, 250*cdf0e10cSrcweir GBool inlineImg); 251*cdf0e10cSrcweir virtual void drawImage(GfxState *state, Object *ref, Stream *str, 252*cdf0e10cSrcweir int width, int height, GfxImageColorMap *colorMap, 253*cdf0e10cSrcweir int *maskColors, GBool inlineImg); 254*cdf0e10cSrcweir virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str, 255*cdf0e10cSrcweir int width, int height, 256*cdf0e10cSrcweir GfxImageColorMap *colorMap, 257*cdf0e10cSrcweir Stream *maskStr, int maskWidth, int maskHeight, 258*cdf0e10cSrcweir GBool maskInvert); 259*cdf0e10cSrcweir virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str, 260*cdf0e10cSrcweir int width, int height, 261*cdf0e10cSrcweir GfxImageColorMap *colorMap, 262*cdf0e10cSrcweir Stream *maskStr, 263*cdf0e10cSrcweir int maskWidth, int maskHeight, 264*cdf0e10cSrcweir GfxImageColorMap *maskColorMap); 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir //----- OPI functions 267*cdf0e10cSrcweir // virtual void opiBegin(GfxState *state, Dict *opiDict); 268*cdf0e10cSrcweir // virtual void opiEnd(GfxState *state, Dict *opiDict); 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir //----- Type 3 font operators 271*cdf0e10cSrcweir // virtual void type3D0(GfxState *state, double wx, double wy) {} 272*cdf0e10cSrcweir // virtual void type3D1(GfxState *state, double wx, double wy, 273*cdf0e10cSrcweir // double llx, double lly, double urx, double ury) {} 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir //----- PostScript XObjects 276*cdf0e10cSrcweir // virtual void psXObject(Stream *psStream, Stream *level1Stream) {} 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir void setPageNum( int nNumPages ); 279*cdf0e10cSrcweir }; 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir extern FILE* g_binary_out; 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir // note: if you ever hcange Output_t, please keep in mind that the current code 285*cdf0e10cSrcweir // relies on it being of 8 bit size 286*cdf0e10cSrcweir typedef char Output_t; 287*cdf0e10cSrcweir typedef std::vector< Output_t > OutputBuffer; 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir #endif /* INCLUDED_PDFI_OUTDEV_HXX */ 290*cdf0e10cSrcweir 291