1c3bb05abSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3c3bb05abSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4c3bb05abSAndrew Rist * or more contributor license agreements. See the NOTICE file 5c3bb05abSAndrew Rist * distributed with this work for additional information 6c3bb05abSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7c3bb05abSAndrew Rist * to you under the Apache License, Version 2.0 (the 8c3bb05abSAndrew Rist * "License"); you may not use this file except in compliance 9c3bb05abSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11c3bb05abSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13c3bb05abSAndrew Rist * Unless required by applicable law or agreed to in writing, 14c3bb05abSAndrew Rist * software distributed under the License is distributed on an 15c3bb05abSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16c3bb05abSAndrew Rist * KIND, either express or implied. See the License for the 17c3bb05abSAndrew Rist * specific language governing permissions and limitations 18c3bb05abSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20c3bb05abSAndrew Rist *************************************************************/ 21cdf0e10cSrcweir 22cdf0e10cSrcweir #ifndef INCLUDED_PDFI_OUTDEV_HXX 23cdf0e10cSrcweir #define INCLUDED_PDFI_OUTDEV_HXX 24cdf0e10cSrcweir 25cdf0e10cSrcweir #if defined __GNUC__ 26cdf0e10cSrcweir #pragma GCC system_header 27cdf0e10cSrcweir #elif defined __SUNPRO_CC 28cdf0e10cSrcweir #pragma disable_warn 29cdf0e10cSrcweir #elif defined _MSC_VER 30cdf0e10cSrcweir #pragma warning(push, 1) 31cdf0e10cSrcweir #endif 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include "GfxState.h" 34cdf0e10cSrcweir #include "GfxFont.h" 35cdf0e10cSrcweir #include "UnicodeMap.h" 36cdf0e10cSrcweir #include "Link.h" 37cdf0e10cSrcweir #include "Object.h" 38cdf0e10cSrcweir #include "OutputDev.h" 3974e62aedSDamjan Jovanovic #include "Stream.h" 40cdf0e10cSrcweir #include "GlobalParams.h" 41cdf0e10cSrcweir #include "PDFDoc.h" 42cdf0e10cSrcweir 43cdf0e10cSrcweir #if defined __SUNPRO_CC 44cdf0e10cSrcweir #pragma enable_warn 45cdf0e10cSrcweir #elif defined _MSC_VER 46cdf0e10cSrcweir #pragma warning(pop) 47cdf0e10cSrcweir #endif 48cdf0e10cSrcweir 49cdf0e10cSrcweir #include <hash_map> 50cdf0e10cSrcweir #include <vector> 51cdf0e10cSrcweir 52cdf0e10cSrcweir class GfxPath; 53cdf0e10cSrcweir class GfxFont; 54cdf0e10cSrcweir class PDFDoc; 55cdf0e10cSrcweir 56cdf0e10cSrcweir namespace pdfi 57cdf0e10cSrcweir { 58cdf0e10cSrcweir struct FontAttributes 59cdf0e10cSrcweir { FontAttributespdfi::FontAttributes60cdf0e10cSrcweir FontAttributes( const GooString& familyName_, 61cdf0e10cSrcweir bool isEmbedded_, 62cdf0e10cSrcweir bool isBold_, 63cdf0e10cSrcweir bool isItalic_, 64cdf0e10cSrcweir bool isUnderline_, 65cdf0e10cSrcweir double size_ ) : 66cdf0e10cSrcweir familyName(), 67cdf0e10cSrcweir isEmbedded(isEmbedded_), 68cdf0e10cSrcweir isBold(isBold_), 69cdf0e10cSrcweir isItalic(isItalic_), 70cdf0e10cSrcweir isUnderline(isUnderline_), 71cdf0e10cSrcweir size(size_) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir familyName.append(const_cast<GooString*>(&familyName_)); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir FontAttributespdfi::FontAttributes76cdf0e10cSrcweir FontAttributes() : 77cdf0e10cSrcweir familyName(), 78cdf0e10cSrcweir isEmbedded(false), 79cdf0e10cSrcweir isBold(false), 80cdf0e10cSrcweir isItalic(false), 81cdf0e10cSrcweir isUnderline(false), 82cdf0e10cSrcweir size(0.0) 83cdf0e10cSrcweir {} 84cdf0e10cSrcweir 85*565bea5dSJohn Bampton // xpdf goo stuff is so totally borked... 86cdf0e10cSrcweir // ...need to hand-code assignment FontAttributespdfi::FontAttributes87cdf0e10cSrcweir FontAttributes( const FontAttributes& rSrc ) : 88cdf0e10cSrcweir familyName(), 89cdf0e10cSrcweir isEmbedded(rSrc.isEmbedded), 90cdf0e10cSrcweir isBold(rSrc.isBold), 91cdf0e10cSrcweir isItalic(rSrc.isItalic), 92cdf0e10cSrcweir isUnderline(rSrc.isUnderline), 93cdf0e10cSrcweir size(rSrc.size) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir familyName.append(const_cast<GooString*>(&rSrc.familyName)); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir operator =pdfi::FontAttributes98cdf0e10cSrcweir FontAttributes& operator=( const FontAttributes& rSrc ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir familyName.clear(); 101cdf0e10cSrcweir familyName.append(const_cast<GooString*>(&rSrc.familyName)); 102cdf0e10cSrcweir 103cdf0e10cSrcweir isEmbedded = rSrc.isEmbedded; 104cdf0e10cSrcweir isBold = rSrc.isBold; 105cdf0e10cSrcweir isItalic = rSrc.isItalic; 106cdf0e10cSrcweir isUnderline = rSrc.isUnderline; 107cdf0e10cSrcweir size = rSrc.size; 108cdf0e10cSrcweir 109cdf0e10cSrcweir return *this; 110cdf0e10cSrcweir } 111cdf0e10cSrcweir operator ==pdfi::FontAttributes112cdf0e10cSrcweir bool operator==(const FontAttributes& rFont) const 113cdf0e10cSrcweir { 114cdf0e10cSrcweir return const_cast<GooString*>(&familyName)->cmp( 115cdf0e10cSrcweir const_cast<GooString*>(&rFont.familyName))==0 && 116cdf0e10cSrcweir isEmbedded == rFont.isEmbedded && 117cdf0e10cSrcweir isBold == rFont.isBold && 118cdf0e10cSrcweir isItalic == rFont.isItalic && 119cdf0e10cSrcweir isUnderline == rFont.isUnderline && 120cdf0e10cSrcweir size == rFont.size; 121cdf0e10cSrcweir } 122cdf0e10cSrcweir 123cdf0e10cSrcweir GooString familyName; 124cdf0e10cSrcweir bool isEmbedded; 125cdf0e10cSrcweir bool isBold; 126cdf0e10cSrcweir bool isItalic; 127cdf0e10cSrcweir bool isUnderline; 128cdf0e10cSrcweir double size; 129cdf0e10cSrcweir }; 130cdf0e10cSrcweir 131cdf0e10cSrcweir class PDFOutDev : public OutputDev 132cdf0e10cSrcweir { 133cdf0e10cSrcweir // not owned by this class 134cdf0e10cSrcweir PDFDoc* m_pDoc; 135cdf0e10cSrcweir mutable std::hash_map< long long, 136cdf0e10cSrcweir FontAttributes > m_aFontMap; 137cdf0e10cSrcweir UnicodeMap* m_pUtf8Map; 138cdf0e10cSrcweir 139cdf0e10cSrcweir int parseFont( long long nNewId, GfxFont* pFont, GfxState* state ) const; 140cdf0e10cSrcweir void writeFontFile( GfxFont* gfxFont ) const; 141cdf0e10cSrcweir void printPath( GfxPath* pPath ) const; 142cdf0e10cSrcweir 143cdf0e10cSrcweir public: 144cdf0e10cSrcweir explicit PDFOutDev( PDFDoc* pDoc ); 145cdf0e10cSrcweir 146cdf0e10cSrcweir //----- get info about output device 147cdf0e10cSrcweir 148cdf0e10cSrcweir // Does this device use upside-down coordinates? 149cdf0e10cSrcweir // (Upside-down means (0,0) is the top left corner of the page.) upsideDown()150cdf0e10cSrcweir virtual GBool upsideDown() { return gTrue; } 151cdf0e10cSrcweir 152cdf0e10cSrcweir // Does this device use drawChar() or drawString()? useDrawChar()153cdf0e10cSrcweir virtual GBool useDrawChar() { return gTrue; } 154cdf0e10cSrcweir 155cdf0e10cSrcweir // Does this device use beginType3Char/endType3Char? Otherwise, 156cdf0e10cSrcweir // text in Type 3 fonts will be drawn with drawChar/drawString. interpretType3Chars()157cdf0e10cSrcweir virtual GBool interpretType3Chars() { return gFalse; } 158cdf0e10cSrcweir 159cdf0e10cSrcweir // Does this device need non-text content? needNonText()160cdf0e10cSrcweir virtual GBool needNonText() { return gTrue; } 161cdf0e10cSrcweir 162cdf0e10cSrcweir //----- initialization and control 163cdf0e10cSrcweir 164cdf0e10cSrcweir // Set default transform matrix. 165cdf0e10cSrcweir virtual void setDefaultCTM(double *ctm); 166cdf0e10cSrcweir 167cdf0e10cSrcweir // Start a page. 168a8186aa4SPedro Giffuni virtual void startPage(int pageNum, GfxState *state, XRef *xref); 169cdf0e10cSrcweir 170cdf0e10cSrcweir // End a page. 171cdf0e10cSrcweir virtual void endPage(); 172cdf0e10cSrcweir 173cdf0e10cSrcweir // Dump page contents to display. 174cdf0e10cSrcweir // virtual void dump() {} 175cdf0e10cSrcweir 176cdf0e10cSrcweir //----- coordinate conversion 177cdf0e10cSrcweir 178cdf0e10cSrcweir // Convert between device and user coordinates. 179cdf0e10cSrcweir // virtual void cvtDevToUser(double dx, double dy, double *ux, double *uy); 180cdf0e10cSrcweir // virtual void cvtUserToDev(double ux, double uy, int *dx, int *dy); 181cdf0e10cSrcweir 182cdf0e10cSrcweir //----- link borders 183a8186aa4SPedro Giffuni virtual void processLink(AnnotLink *link); 184cdf0e10cSrcweir 185cdf0e10cSrcweir //----- save/restore graphics state 186cdf0e10cSrcweir virtual void saveState(GfxState *state); 187cdf0e10cSrcweir virtual void restoreState(GfxState *state); 188cdf0e10cSrcweir 189cdf0e10cSrcweir //----- update graphics state 190cdf0e10cSrcweir // virtual void updateAll(GfxState *state); 191cdf0e10cSrcweir virtual void updateCTM(GfxState *state, double m11, double m12, 192cdf0e10cSrcweir double m21, double m22, double m31, double m32); 193cdf0e10cSrcweir virtual void updateLineDash(GfxState *state); 194cdf0e10cSrcweir virtual void updateFlatness(GfxState *state); 195cdf0e10cSrcweir virtual void updateLineJoin(GfxState *state); 196cdf0e10cSrcweir virtual void updateLineCap(GfxState *state); 197cdf0e10cSrcweir virtual void updateMiterLimit(GfxState *state); 198cdf0e10cSrcweir virtual void updateLineWidth(GfxState *state); 199cdf0e10cSrcweir virtual void updateFillColor(GfxState *state); 200cdf0e10cSrcweir virtual void updateStrokeColor(GfxState *state); 201cdf0e10cSrcweir virtual void updateFillOpacity(GfxState *state); 202cdf0e10cSrcweir virtual void updateStrokeOpacity(GfxState *state); 203cdf0e10cSrcweir virtual void updateBlendMode(GfxState *state); 204cdf0e10cSrcweir 205cdf0e10cSrcweir //----- update text state 206cdf0e10cSrcweir virtual void updateFont(GfxState *state); 207cdf0e10cSrcweir // virtual void updateTextMat(GfxState *state); 208cdf0e10cSrcweir // virtual void updateCharSpace(GfxState *state) {} 209cdf0e10cSrcweir virtual void updateRender(GfxState *state); 210cdf0e10cSrcweir // virtual void updateRise(GfxState *state) {} 211cdf0e10cSrcweir // virtual void updateWordSpace(GfxState *state) {} 212cdf0e10cSrcweir // virtual void updateHorizScaling(GfxState *state) {} 213cdf0e10cSrcweir // virtual void updateTextPos(GfxState *state) {} 214cdf0e10cSrcweir // virtual void updateTextShift(GfxState *state, double shift) {} 215cdf0e10cSrcweir 216cdf0e10cSrcweir //----- path painting 217cdf0e10cSrcweir virtual void stroke(GfxState *state); 218cdf0e10cSrcweir virtual void fill(GfxState *state); 219cdf0e10cSrcweir virtual void eoFill(GfxState *state); 220cdf0e10cSrcweir 221cdf0e10cSrcweir //----- path clipping 222cdf0e10cSrcweir virtual void clip(GfxState *state); 223cdf0e10cSrcweir virtual void eoClip(GfxState *state); 224cdf0e10cSrcweir 225cdf0e10cSrcweir //----- text drawing 226cdf0e10cSrcweir virtual void drawChar(GfxState *state, double x, double y, 227cdf0e10cSrcweir double dx, double dy, 228cdf0e10cSrcweir double originX, double originY, 229cdf0e10cSrcweir CharCode code, int nBytes, Unicode *u, int uLen); 230cdf0e10cSrcweir virtual void drawString(GfxState *state, GooString *s); 231cdf0e10cSrcweir virtual void endTextObject(GfxState *state); 232cdf0e10cSrcweir 233cdf0e10cSrcweir //----- image drawing 234cdf0e10cSrcweir virtual void drawImageMask(GfxState *state, Object *ref, Stream *str, 235cdf0e10cSrcweir int width, int height, GBool invert, 236cdf0e10cSrcweir GBool inlineImg); 237cdf0e10cSrcweir virtual void drawImage(GfxState *state, Object *ref, Stream *str, 238cdf0e10cSrcweir int width, int height, GfxImageColorMap *colorMap, 239cdf0e10cSrcweir int *maskColors, GBool inlineImg); 240cdf0e10cSrcweir virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str, 241cdf0e10cSrcweir int width, int height, 242cdf0e10cSrcweir GfxImageColorMap *colorMap, 243cdf0e10cSrcweir Stream *maskStr, int maskWidth, int maskHeight, 244cdf0e10cSrcweir GBool maskInvert); 245cdf0e10cSrcweir virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str, 246cdf0e10cSrcweir int width, int height, 247cdf0e10cSrcweir GfxImageColorMap *colorMap, 248cdf0e10cSrcweir Stream *maskStr, 249cdf0e10cSrcweir int maskWidth, int maskHeight, 250cdf0e10cSrcweir GfxImageColorMap *maskColorMap); 251cdf0e10cSrcweir 252cdf0e10cSrcweir //----- OPI functions 253cdf0e10cSrcweir // virtual void opiBegin(GfxState *state, Dict *opiDict); 254cdf0e10cSrcweir // virtual void opiEnd(GfxState *state, Dict *opiDict); 255cdf0e10cSrcweir 256cdf0e10cSrcweir //----- Type 3 font operators 257cdf0e10cSrcweir // virtual void type3D0(GfxState *state, double wx, double wy) {} 258cdf0e10cSrcweir // virtual void type3D1(GfxState *state, double wx, double wy, 259cdf0e10cSrcweir // double llx, double lly, double urx, double ury) {} 260cdf0e10cSrcweir 261cdf0e10cSrcweir //----- PostScript XObjects 262cdf0e10cSrcweir // virtual void psXObject(Stream *psStream, Stream *level1Stream) {} 263cdf0e10cSrcweir 264cdf0e10cSrcweir void setPageNum( int nNumPages ); 265cdf0e10cSrcweir }; 266cdf0e10cSrcweir } 267cdf0e10cSrcweir 268cdf0e10cSrcweir extern FILE* g_binary_out; 269cdf0e10cSrcweir 270cdf0e10cSrcweir // note: if you ever hcange Output_t, please keep in mind that the current code 271cdf0e10cSrcweir // relies on it being of 8 bit size 272cdf0e10cSrcweir typedef char Output_t; 273cdf0e10cSrcweir typedef std::vector< Output_t > OutputBuffer; 274cdf0e10cSrcweir 275cdf0e10cSrcweir #endif /* INCLUDED_PDFI_OUTDEV_HXX */ 276