Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _PSPRINT_PRINTERGFX_HXX_
30 : : #define _PSPRINT_PRINTERGFX_HXX_
31 : :
32 : : #include "vcl/helper.hxx"
33 : : #include "sallayout.hxx"
34 : : #include "osl/file.hxx"
35 : : #include "tools/gen.hxx"
36 : : #include "vclpluginapi.h"
37 : :
38 : : #include <list>
39 : : #include <boost/unordered_map.hpp>
40 : :
41 : : namespace psp {
42 : :
43 : : // forwards
44 : : struct JobData;
45 : :
46 : : /*
47 : : * lightweight container to handle RGB values
48 : : */
49 : :
50 : : class PrinterColor
51 : : {
52 : : public:
53 : :
54 : : enum ColorSpace { eInvalid, eRGB };
55 : :
56 : : private:
57 : :
58 : : sal_uInt8 mnRed;
59 : : sal_uInt8 mnGreen;
60 : : sal_uInt8 mnBlue;
61 : : ColorSpace meColorspace;
62 : :
63 : : public:
64 : :
65 : 218 : PrinterColor () :
66 : 218 : meColorspace(eInvalid)
67 : 218 : {}
68 : 327 : PrinterColor (sal_uInt16 nRed, sal_uInt16 nGreen,
69 : : sal_uInt16 nBlue) :
70 : : mnRed (nRed),
71 : : mnGreen (nGreen),
72 : : mnBlue (nBlue),
73 : 327 : meColorspace (eRGB)
74 : 327 : {}
75 : 0 : PrinterColor (sal_uInt32 nRGB) :
76 : : mnRed ((nRGB & 0x00ff0000) >> 16),
77 : : mnGreen ((nRGB & 0x0000ff00) >> 8),
78 : : mnBlue ((nRGB & 0x000000ff) ),
79 : 0 : meColorspace (eRGB)
80 : 0 : {}
81 : 644 : ~PrinterColor ()
82 : 644 : {}
83 : :
84 : 0 : sal_Bool Is () const
85 : 0 : { return meColorspace != eInvalid; }
86 : :
87 : : ColorSpace GetColorSpace () const
88 : : { return meColorspace; }
89 : 0 : sal_uInt16 GetRed () const
90 : 0 : { return mnRed; }
91 : 0 : sal_uInt16 GetGreen () const
92 : 0 : { return mnGreen; }
93 : 0 : sal_uInt16 GetBlue () const
94 : 0 : { return mnBlue; }
95 : 0 : sal_Bool operator== (const PrinterColor& aColor) const
96 : : {
97 : 0 : return aColor.Is() && this->Is()
98 : : && mnRed == aColor.mnRed
99 : : && mnGreen == aColor.mnGreen
100 [ # # ][ # # ]: 0 : && mnBlue == aColor.mnBlue;
[ # # ]
[ # # # # ]
101 : : }
102 : 0 : sal_Bool operator!= (const PrinterColor& aColor) const
103 : 0 : { return ! (aColor==*this); }
104 : 0 : PrinterColor& operator= (const PrinterColor& aColor)
105 : : {
106 : 0 : meColorspace = aColor.meColorspace;
107 : 0 : mnRed = aColor.mnRed;
108 : 0 : mnGreen = aColor.mnGreen;
109 : 0 : mnBlue = aColor.mnBlue;
110 : :
111 : 0 : return *this;
112 : : }
113 : :
114 : : PrinterColor& operator= (sal_uInt32 nRGB)
115 : : {
116 : : meColorspace = eRGB;
117 : : mnBlue = (nRGB & 0x000000ff);
118 : : mnGreen = (nRGB & 0x0000ff00) >> 8;
119 : : mnRed = (nRGB & 0x00ff0000) >> 16;
120 : :
121 : : return *this;
122 : : }
123 : : };
124 : :
125 : : /*
126 : : * forward declarations
127 : : */
128 : :
129 : : class Font3;
130 : : class GlyphSet;
131 : : class PrinterJob;
132 : : class PrintFontManager;
133 : : struct KernPair;
134 : : struct CharacterMetric;
135 : :
136 : : /*
137 : : * Bitmap Interface, this has to be filled with your actual bitmap implementation
138 : : * sample implementations can be found in:
139 : : * psprint/workben/cui/pspdem.cxx
140 : : * vcl/unx/source/gdi/salgdi2.cxx
141 : : */
142 : :
143 : 0 : class VCL_DLLPUBLIC PrinterBmp
144 : : {
145 : : public:
146 : :
147 : : virtual ~PrinterBmp () = 0;
148 : : virtual sal_uInt32 GetPaletteColor (sal_uInt32 nIdx) const = 0;
149 : : virtual sal_uInt32 GetPaletteEntryCount () const = 0;
150 : : virtual sal_uInt32 GetPixelRGB (sal_uInt32 nRow, sal_uInt32 nColumn) const = 0;
151 : : virtual sal_uInt8 GetPixelGray (sal_uInt32 nRow, sal_uInt32 nColumn) const = 0;
152 : : virtual sal_uInt8 GetPixelIdx (sal_uInt32 nRow, sal_uInt32 nColumn) const = 0;
153 : : virtual sal_uInt32 GetWidth () const = 0;
154 : : virtual sal_uInt32 GetHeight () const = 0;
155 : : virtual sal_uInt32 GetDepth () const = 0;
156 : : };
157 : :
158 : : typedef enum {
159 : : InvalidType = 0,
160 : : TrueColorImage,
161 : : MonochromeImage,
162 : : PaletteImage,
163 : : GrayScaleImage
164 : : } ImageType;
165 : :
166 : : /*
167 : : * printer raster operations
168 : : */
169 : :
170 : 432 : struct GraphicsStatus
171 : : {
172 : : rtl::OString maFont;
173 : : rtl_TextEncoding maEncoding;
174 : : bool mbArtItalic;
175 : : bool mbArtBold;
176 : : sal_Int32 mnTextHeight;
177 : : sal_Int32 mnTextWidth;
178 : : PrinterColor maColor;
179 : : double mfLineWidth;
180 : :
181 : : GraphicsStatus();
182 : : };
183 : :
184 : : class Font3;
185 : :
186 : : class VCL_DLLPUBLIC PrinterGfx
187 : : {
188 : : private:
189 : :
190 : : /* common settings */
191 : :
192 : : double mfScaleX;
193 : : double mfScaleY;
194 : :
195 : : sal_uInt32 mnDpi;
196 : : sal_uInt16 mnDepth;
197 : :
198 : : sal_uInt16 mnPSLevel;
199 : : sal_Bool mbColor;
200 : : sal_Bool mbUploadPS42Fonts;
201 : :
202 : : osl::File* mpPageHeader;
203 : : osl::File* mpPageBody;
204 : :
205 : : void TranslateCoordinates (sal_Int32 &rXOut, sal_Int32 &rYOut,
206 : : sal_Int32 nXIn, sal_Int32 nYIn )
207 : : { rXOut = nXIn; rYOut = nYIn; }
208 : : void TranslateCoordinates (Point& rOut, const Point& rIn)
209 : : { rOut = rIn; }
210 : :
211 : : /* text/font related data, for a type1 font it has to be checked
212 : : whether this font has already been downloaded. A TrueType font
213 : : will be converted into one or more Type3 fonts, containing glyphs
214 : : in no particular order. In addition to the existence of the
215 : : glyph in one of the subfonts, the mapping from unicode to the
216 : : glyph has to be remembered */
217 : :
218 : : std::list< sal_Int32 > maPS1Font;
219 : : std::list< GlyphSet > maPS3Font;
220 : :
221 : : sal_Int32 mnFontID;
222 : : sal_Int32 mnFallbackID;
223 : : sal_Int32 mnTextAngle;
224 : : bool mbTextVertical;
225 : : PrintFontManager& mrFontMgr;
226 : :
227 : : /* bitmap drawing implementation */
228 : :
229 : : sal_Bool mbCompressBmp;
230 : :
231 : : void DrawPS1GrayImage (const PrinterBmp& rBitmap, const Rectangle& rArea);
232 : : void writePS2ImageHeader (const Rectangle& rArea, psp::ImageType nType);
233 : : void writePS2Colorspace (const PrinterBmp& rBitmap, psp::ImageType nType);
234 : : void DrawPS2GrayImage (const PrinterBmp& rBitmap, const Rectangle& rArea);
235 : : void DrawPS2PaletteImage (const PrinterBmp& rBitmap, const Rectangle& rArea);
236 : : void DrawPS2TrueColorImage (const PrinterBmp& rBitmap, const Rectangle& rArea);
237 : : void DrawPS2MonoImage (const PrinterBmp& rBitmap, const Rectangle& rArea);
238 : :
239 : : /* clip region */
240 : :
241 : : std::list< Rectangle > maClipRegion;
242 : : sal_Bool JoinVerticalClipRectangles( std::list< Rectangle >::iterator& it,
243 : : Point& aOldPoint, sal_Int32& nColumn );
244 : :
245 : : /* color settings */
246 : : PrinterColor maFillColor;
247 : : PrinterColor maTextColor;
248 : : PrinterColor maLineColor;
249 : :
250 : : /* graphics state */
251 : : GraphicsStatus maVirtualStatus;
252 : : std::list< GraphicsStatus > maGraphicsStack;
253 : 0 : GraphicsStatus& currentState() { return maGraphicsStack.front(); }
254 : :
255 : : /* font / font substitution */
256 : : friend class Font3;
257 : : const ::boost::unordered_map< fontID, fontID >* mpFontSubstitutes;
258 : : int getCharWidth (sal_Bool b_vert, sal_Unicode n_char,
259 : : CharacterMetric *p_bbox);
260 : : fontID getCharMetric (const Font3 &rFont, sal_Unicode n_char,
261 : : CharacterMetric *p_bbox);
262 : : fontID getFontSubstitute () const;
263 : 0 : fontID getFallbackID () const { return mnFallbackID; }
264 : :
265 : : public:
266 : : /* grahics status update */
267 : : void PSSetColor ();
268 : : void PSSetLineWidth ();
269 : : void PSSetFont ();
270 : :
271 : : /* graphics status functions */
272 : 0 : void PSSetColor (const PrinterColor& rColor)
273 : 0 : { maVirtualStatus.maColor = rColor; }
274 : :
275 : : void PSUploadPS1Font (sal_Int32 nFontID);
276 : 0 : void PSSetFont (const rtl::OString& rName,
277 : : rtl_TextEncoding nEncoding = RTL_TEXTENCODING_DONTKNOW)
278 : 0 : { maVirtualStatus.maFont = rName; maVirtualStatus.maEncoding = nEncoding; }
279 : :
280 : : /* graphics status stack */
281 : : void PSGSave ();
282 : : void PSGRestore ();
283 : :
284 : :
285 : : /* PS helpers */
286 : : enum pspath_t { moveto = 0, lineto = 1 };
287 : : void PSBinLineTo (const Point& rCurrent, Point& rOld,
288 : : sal_Int32& nColumn);
289 : : void PSBinMoveTo (const Point& rCurrent, Point& rOld,
290 : : sal_Int32& nColumn);
291 : : void PSBinStartPath ();
292 : : void PSBinEndPath ();
293 : : void PSBinCurrentPath (sal_uInt32 nPoints, const Point* pPath);
294 : : void PSBinPath (const Point& rCurrent, Point& rOld,
295 : : pspath_t eType, sal_Int32& nColumn);
296 : :
297 : : void PSRotate (sal_Int32 nAngle);
298 : : void PSTranslate (const Point& rPoint);
299 : : void PSMoveTo (const Point& rPoint);
300 : : void PSScale (double fScaleX, double fScaleY);
301 : : void PSLineTo(const Point& rPoint );
302 : : void PSPointOp (const Point& rPoint, const sal_Char* pOperator);
303 : : void PSHexString (const sal_uChar* pString, sal_Int16 nLen);
304 : : void PSDeltaArray (const sal_Int32 *pArray, sal_Int16 nEntries);
305 : : void PSShowText (const sal_uChar* pString,
306 : : sal_Int16 nGlyphs, sal_Int16 nBytes,
307 : : const sal_Int32* pDeltaArray = NULL);
308 : : void PSComment (const sal_Char* pComment );
309 : : void LicenseWarning (const Point& rPoint, const sal_Unicode* pStr,
310 : : sal_Int16 nLen, const sal_Int32* pDeltaArray);
311 : :
312 : : void OnEndPage ();
313 : : void OnEndJob ();
314 : : void writeResources( osl::File* pFile, std::list< rtl::OString >& rSuppliedFonts, std::list< rtl::OString >& rNeededFonts );
315 : 271 : PrintFontManager& GetFontMgr () { return mrFontMgr; }
316 : :
317 : : void drawVerticalizedText (const Point& rPoint,
318 : : const sal_Unicode* pStr,
319 : : sal_Int16 nLen,
320 : : const sal_Int32* pDeltaArray );
321 : : void drawText (const Point& rPoint,
322 : : const sal_Unicode* pStr, sal_Int16 nLen,
323 : : const sal_Int32* pDeltaArray = NULL);
324 : :
325 : : void drawGlyphs( const Point& rPoint,
326 : : sal_GlyphId* pGlyphIds,
327 : : sal_Unicode* pUnicodes,
328 : : sal_Int16 nLen,
329 : : sal_Int32* pDeltaArray );
330 : : public:
331 : : PrinterGfx();
332 : : ~PrinterGfx();
333 : : sal_Bool Init (PrinterJob &rPrinterSpec);
334 : : sal_Bool Init (const JobData& rData);
335 : : void Clear();
336 : :
337 : : // query depth
338 : : sal_uInt16 GetBitCount ();
339 : :
340 : : // clip region
341 : : void ResetClipRegion ();
342 : : void BeginSetClipRegion (sal_uInt32);
343 : : sal_Bool UnionClipRegion (sal_Int32 nX, sal_Int32 nY,
344 : : sal_Int32 nDX, sal_Int32 nDY);
345 : : void EndSetClipRegion ();
346 : :
347 : : // set xy color
348 : 0 : void SetLineColor (const PrinterColor& rLineColor = PrinterColor())
349 : 0 : { maLineColor = rLineColor; }
350 : 0 : void SetFillColor (const PrinterColor& rFillColor = PrinterColor())
351 : 0 : { maFillColor = rFillColor; }
352 : :
353 : : // drawing primitives
354 : : void DrawPixel (const Point& rPoint, const PrinterColor& rPixelColor);
355 : 0 : void DrawPixel (const Point& rPoint)
356 : 0 : { DrawPixel (rPoint, maLineColor); }
357 : : void DrawLine (const Point& rFrom, const Point& rTo);
358 : : void DrawRect (const Rectangle& rRectangle);
359 : : void DrawPolyLine (sal_uInt32 nPoints, const Point* pPath );
360 : : void DrawPolygon (sal_uInt32 nPoints, const Point* pPath);
361 : : void DrawPolyPolygon (sal_uInt32 nPoly,
362 : : const sal_uInt32 *pPolygonSize,
363 : : const Point** pPolygonList);
364 : : void DrawPolyLineBezier (sal_uInt32 nPoints,
365 : : const Point* pPath,
366 : : const sal_uInt8* pFlgAry );
367 : : void DrawPolygonBezier (sal_uInt32 nPoints,
368 : : const Point* pPath,
369 : : const sal_uInt8* pFlgAry);
370 : : void DrawPolyPolygonBezier (sal_uInt32 nPoly,
371 : : const sal_uInt32* pPoints,
372 : : const Point* const* pPtAry,
373 : : const sal_uInt8* const* pFlgAry);
374 : :
375 : : // eps
376 : : sal_Bool DrawEPS ( const Rectangle& rBoundingBox, void* pPtr, sal_uInt32 nSize);
377 : :
378 : : // image drawing
379 : : void DrawBitmap (const Rectangle& rDest, const Rectangle& rSrc,
380 : : const PrinterBmp& rBitmap);
381 : :
382 : : // font and text handling
383 : : sal_uInt16 SetFont (
384 : : sal_Int32 nFontID,
385 : : sal_Int32 nPointHeight,
386 : : sal_Int32 nPointWidth,
387 : : sal_Int32 nAngle,
388 : : bool bVertical,
389 : : bool bArtItalic,
390 : : bool bArtBold
391 : : );
392 : 121 : sal_Int32 GetFontAngle () const
393 : 121 : { return mnTextAngle; }
394 : 20665 : sal_Int32 GetFontID () const
395 : 20665 : { return mnFontID; }
396 : 10272 : bool GetFontVertical() const
397 : 10272 : { return mbTextVertical; }
398 : 10393 : sal_Int32 GetFontHeight () const
399 : 10393 : { return maVirtualStatus.mnTextHeight; }
400 : 10393 : sal_Int32 GetFontWidth () const
401 : 10393 : { return maVirtualStatus.mnTextWidth; }
402 : 10272 : bool GetArtificialItalic() const
403 : 10272 : { return maVirtualStatus.mbArtItalic; }
404 : 10272 : bool GetArtificialBold() const
405 : 10272 : { return maVirtualStatus.mbArtBold; }
406 : : void DrawText (const Point& rPoint,
407 : : const sal_Unicode* pStr, sal_Int16 nLen,
408 : : const sal_Int32* pDeltaArray = NULL);
409 : 0 : void SetTextColor (PrinterColor& rTextColor)
410 : 0 : { maTextColor = rTextColor; }
411 : : sal_Int32 GetCharWidth (sal_uInt16 nFrom, sal_uInt16 nTo,
412 : : long *pWidthArray);
413 : : const ::std::list< KernPair >& getKernPairs( bool bVertical = false ) const;
414 : :
415 : : // for CTL
416 : : void DrawGlyphs( const Point& rPoint,
417 : : sal_GlyphId* pGlyphIds,
418 : : sal_Unicode* pUnicodes,
419 : : sal_Int16 nLen,
420 : : sal_Int32* pDeltaArray );
421 : :
422 : : };
423 : :
424 : : } /* namespace psp */
425 : :
426 : :
427 : : #endif /* _PSPRINT_PRINTERGFX_HXX_ */
428 : :
429 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|