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