Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / inc / generic / printergfx.hxx
blob77ae365076b23595716d1d914f0a1a0f55ec33d0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_INC_GENERIC_PRINTERGFX_HXX
21 #define INCLUDED_VCL_INC_GENERIC_PRINTERGFX_HXX
23 #include "vcl/helper.hxx"
24 #include "sallayout.hxx"
25 #include "osl/file.hxx"
26 #include "tools/gen.hxx"
27 #include "vclpluginapi.h"
29 #include <list>
31 namespace psp {
33 struct JobData;
36 * lightweight container to handle RGB values
39 class PrinterColor
41 public:
43 enum ColorSpace { eInvalid, eRGB };
45 private:
47 sal_uInt8 mnRed;
48 sal_uInt8 mnGreen;
49 sal_uInt8 mnBlue;
50 ColorSpace meColorspace;
52 public:
54 PrinterColor()
55 : mnRed(0)
56 , mnGreen(0)
57 , mnBlue(0)
58 , meColorspace(eInvalid)
60 PrinterColor (sal_uInt16 nRed, sal_uInt16 nGreen,
61 sal_uInt16 nBlue) :
62 mnRed (nRed),
63 mnGreen (nGreen),
64 mnBlue (nBlue),
65 meColorspace (eRGB)
67 PrinterColor (sal_uInt32 nRGB) :
68 mnRed ((nRGB & 0x00ff0000) >> 16),
69 mnGreen ((nRGB & 0x0000ff00) >> 8),
70 mnBlue ((nRGB & 0x000000ff) ),
71 meColorspace (eRGB)
73 ~PrinterColor ()
76 bool Is () const
77 { return meColorspace != eInvalid; }
79 ColorSpace GetColorSpace () const
80 { return meColorspace; }
81 sal_uInt16 GetRed () const
82 { return mnRed; }
83 sal_uInt16 GetGreen () const
84 { return mnGreen; }
85 sal_uInt16 GetBlue () const
86 { return mnBlue; }
87 bool operator== (const PrinterColor& aColor) const
89 return aColor.Is() && this->Is()
90 && mnRed == aColor.mnRed
91 && mnGreen == aColor.mnGreen
92 && mnBlue == aColor.mnBlue;
94 bool operator!= (const PrinterColor& aColor) const
95 { return ! (aColor==*this); }
96 PrinterColor& operator= (const PrinterColor& aColor)
98 meColorspace = aColor.meColorspace;
99 mnRed = aColor.mnRed;
100 mnGreen = aColor.mnGreen;
101 mnBlue = aColor.mnBlue;
103 return *this;
106 PrinterColor& operator= (sal_uInt32 nRGB)
108 meColorspace = eRGB;
109 mnBlue = (nRGB & 0x000000ff);
110 mnGreen = (nRGB & 0x0000ff00) >> 8;
111 mnRed = (nRGB & 0x00ff0000) >> 16;
113 return *this;
117 class Font2;
118 class GlyphSet;
119 class PrinterJob;
120 class PrintFontManager;
121 struct CharacterMetric;
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
130 class VCL_DLLPUBLIC PrinterBmp
132 public:
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;
145 typedef enum {
146 InvalidType = 0,
147 TrueColorImage,
148 MonochromeImage,
149 PaletteImage,
150 GrayScaleImage
151 } ImageType;
154 * printer raster operations
157 struct GraphicsStatus
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;
168 GraphicsStatus();
171 class Font2;
173 class VCL_DLLPUBLIC PrinterGfx
175 private:
177 /* common settings */
179 double mfScaleX;
180 double mfScaleY;
182 sal_uInt32 mnDpi;
183 sal_uInt16 mnDepth;
185 sal_uInt16 mnPSLevel;
186 bool mbColor;
187 bool mbUploadPS42Fonts;
189 osl::File* mpPageHeader;
190 osl::File* mpPageBody;
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; }
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 */
205 std::list< sal_Int32 > maPS1Font;
206 std::list< GlyphSet > maPS3Font;
208 sal_Int32 mnFontID;
209 sal_Int32 mnFallbackID;
210 sal_Int32 mnTextAngle;
211 bool mbTextVertical;
212 PrintFontManager& mrFontMgr;
214 /* bitmap drawing implementation */
216 bool mbCompressBmp;
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);
226 /* clip region */
228 std::list< Rectangle > maClipRegion;
229 bool JoinVerticalClipRectangles( std::list< Rectangle >::iterator& it,
230 Point& aOldPoint, sal_Int32& nColumn );
232 /* color settings */
233 PrinterColor maFillColor;
234 PrinterColor maTextColor;
235 PrinterColor maLineColor;
237 /* graphics state */
238 GraphicsStatus maVirtualStatus;
239 std::list< GraphicsStatus > maGraphicsStack;
240 GraphicsStatus& currentState() { return maGraphicsStack.front(); }
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 fontID getFallbackID () const { return mnFallbackID; }
250 public:
251 /* grahics status update */
252 void PSSetColor ();
253 void PSSetLineWidth ();
254 void PSSetFont ();
256 /* graphics status functions */
257 void PSSetColor (const PrinterColor& rColor)
258 { maVirtualStatus.maColor = rColor; }
260 void PSUploadPS1Font (sal_Int32 nFontID);
261 void PSSetFont (const OString& rName,
262 rtl_TextEncoding nEncoding = RTL_TEXTENCODING_DONTKNOW)
263 { maVirtualStatus.maFont = rName; maVirtualStatus.maEncoding = nEncoding; }
265 /* graphics status stack */
266 void PSGSave ();
267 void PSGRestore ();
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);
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);
296 void OnEndJob ();
297 void writeResources( osl::File* pFile, std::list< OString >& rSuppliedFonts );
298 PrintFontManager& GetFontMgr () { return mrFontMgr; }
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);
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();
320 // query depth
321 sal_uInt16 GetBitCount () { return mnDepth;}
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 ();
330 // set xy color
331 void SetLineColor (const PrinterColor& rLineColor = PrinterColor())
332 { maLineColor = rLineColor; }
333 void SetFillColor (const PrinterColor& rFillColor = PrinterColor())
334 { maFillColor = rFillColor; }
336 // drawing primitives
337 void DrawPixel (const Point& rPoint, const PrinterColor& rPixelColor);
338 void DrawPixel (const Point& rPoint)
339 { 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);
358 // eps
359 bool DrawEPS ( const Rectangle& rBoundingBox, void* pPtr, sal_uInt32 nSize);
361 // image drawing
362 void DrawBitmap (const Rectangle& rDest, const Rectangle& rSrc,
363 const PrinterBmp& rBitmap);
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
375 sal_Int32 GetFontAngle () const
376 { return mnTextAngle; }
377 sal_Int32 GetFontID () const
378 { return mnFontID; }
379 bool GetFontVertical() const
380 { return mbTextVertical; }
381 sal_Int32 GetFontHeight () const
382 { return maVirtualStatus.mnTextHeight; }
383 sal_Int32 GetFontWidth () const
384 { return maVirtualStatus.mnTextWidth; }
385 bool GetArtificialItalic() const
386 { return maVirtualStatus.mbArtItalic; }
387 bool GetArtificialBold() const
388 { return maVirtualStatus.mbArtBold; }
389 void DrawText (const Point& rPoint,
390 const sal_Unicode* pStr, sal_Int16 nLen,
391 const sal_Int32* pDeltaArray = NULL);
392 void SetTextColor (PrinterColor& rTextColor)
393 { 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 );
405 } /* namespace psp */
407 #endif // INCLUDED_VCL_INC_GENERIC_PRINTERGFX_HXX
409 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */