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