Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / vcl / inc / unx / printergfx.hxx
blobf1fc5229ced388a4be4d3b3c5e5d930b107541cd
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 <unx/helper.hxx>
24 #include "sallayout.hxx"
25 #include "osl/file.hxx"
26 #include "tools/gen.hxx"
27 #include "vclpluginapi.h"
29 #include <list>
30 #include <vector>
32 enum class PolyFlags : sal_uInt8;
34 namespace psp {
36 struct JobData;
39 * lightweight container to handle RGB values
42 class PrinterColor
44 public:
46 enum ColorSpace { eInvalid, eRGB };
48 private:
50 sal_uInt8 mnRed;
51 sal_uInt8 mnGreen;
52 sal_uInt8 mnBlue;
53 ColorSpace meColorspace;
55 public:
57 PrinterColor()
58 : mnRed(0)
59 , mnGreen(0)
60 , mnBlue(0)
61 , meColorspace(eInvalid)
63 PrinterColor (sal_uInt16 nRed, sal_uInt16 nGreen,
64 sal_uInt16 nBlue) :
65 mnRed (nRed),
66 mnGreen (nGreen),
67 mnBlue (nBlue),
68 meColorspace (eRGB)
70 PrinterColor (sal_uInt32 nRGB) :
71 mnRed ((nRGB & 0x00ff0000) >> 16),
72 mnGreen ((nRGB & 0x0000ff00) >> 8),
73 mnBlue ((nRGB & 0x000000ff) ),
74 meColorspace (eRGB)
77 bool Is () const
78 { return meColorspace != eInvalid; }
80 sal_uInt16 GetRed () const
81 { return mnRed; }
82 sal_uInt16 GetGreen () const
83 { return mnGreen; }
84 sal_uInt16 GetBlue () const
85 { return mnBlue; }
86 bool operator== (const PrinterColor& aColor) const
88 return aColor.Is() && this->Is()
89 && mnRed == aColor.mnRed
90 && mnGreen == aColor.mnGreen
91 && mnBlue == aColor.mnBlue;
93 bool operator!= (const PrinterColor& aColor) const
94 { return ! (aColor==*this); }
96 PrinterColor& operator= (sal_uInt32 nRGB)
98 meColorspace = eRGB;
99 mnBlue = (nRGB & 0x000000ff);
100 mnGreen = (nRGB & 0x0000ff00) >> 8;
101 mnRed = (nRGB & 0x00ff0000) >> 16;
103 return *this;
107 class GlyphSet;
108 class PrinterJob;
109 class PrintFontManager;
110 struct CharacterMetric;
113 * Bitmap Interface, this has to be filled with your actual bitmap implementation
114 * sample implementations can be found in:
115 * psprint/workben/cui/pspdem.cxx
116 * vcl/unx/source/gdi/salgdi2.cxx
119 class VCL_DLLPUBLIC PrinterBmp
121 public:
123 virtual ~PrinterBmp () = 0;
124 virtual sal_uInt32 GetPaletteColor (sal_uInt32 nIdx) const = 0;
125 virtual sal_uInt32 GetPaletteEntryCount () const = 0;
126 virtual sal_uInt32 GetPixelRGB (sal_uInt32 nRow, sal_uInt32 nColumn) const = 0;
127 virtual sal_uInt8 GetPixelGray (sal_uInt32 nRow, sal_uInt32 nColumn) const = 0;
128 virtual sal_uInt8 GetPixelIdx (sal_uInt32 nRow, sal_uInt32 nColumn) const = 0;
129 virtual sal_uInt32 GetDepth () const = 0;
132 enum class ImageType {
133 TrueColorImage,
134 MonochromeImage,
135 PaletteImage,
136 GrayScaleImage
140 * printer raster operations
143 struct GraphicsStatus
145 OString maFont;
146 rtl_TextEncoding maEncoding;
147 bool mbArtItalic;
148 bool mbArtBold;
149 sal_Int32 mnTextHeight;
150 sal_Int32 mnTextWidth;
151 PrinterColor maColor;
152 double mfLineWidth;
154 GraphicsStatus();
157 class VCL_DLLPUBLIC PrinterGfx
159 private:
161 /* common settings */
163 double mfScaleX;
164 double mfScaleY;
166 sal_uInt32 mnDpi;
167 sal_uInt16 mnDepth;
169 sal_uInt16 mnPSLevel;
170 bool mbColor;
171 bool mbUploadPS42Fonts;
173 osl::File* mpPageHeader;
174 osl::File* mpPageBody;
176 /* text/font related data, for a type1 font it has to be checked
177 whether this font has already been downloaded. A TrueType font
178 will be converted into one or more Type3 fonts, containing glyphs
179 in no particular order. In addition to the existence of the
180 glyph in one of the subfonts, the mapping from unicode to the
181 glyph has to be remembered */
183 std::list< GlyphSet > maPS3Font;
185 sal_Int32 mnFontID;
186 sal_Int32 mnTextAngle;
187 bool mbTextVertical;
188 PrintFontManager& mrFontMgr;
190 /* bitmap drawing implementation */
192 void DrawPS1GrayImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea);
193 void writePS2ImageHeader (const tools::Rectangle& rArea, psp::ImageType nType);
194 void writePS2Colorspace (const PrinterBmp& rBitmap, psp::ImageType nType);
195 void DrawPS2GrayImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea);
196 void DrawPS2PaletteImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea);
197 void DrawPS2TrueColorImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea);
198 void DrawPS2MonoImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea);
200 /* clip region */
202 std::list< tools::Rectangle > maClipRegion;
203 bool JoinVerticalClipRectangles( std::list< tools::Rectangle >::iterator& it,
204 Point& aOldPoint, sal_Int32& nColumn );
206 /* color settings */
207 PrinterColor maFillColor;
208 PrinterColor maTextColor;
209 PrinterColor maLineColor;
211 /* graphics state */
212 GraphicsStatus maVirtualStatus;
213 std::list< GraphicsStatus > maGraphicsStack;
214 GraphicsStatus& currentState() { return maGraphicsStack.front(); }
216 public:
217 /* graphics status update */
218 void PSSetColor ();
219 void PSSetLineWidth ();
220 void PSSetFont ();
222 /* graphics status functions */
223 void PSSetColor (const PrinterColor& rColor)
224 { maVirtualStatus.maColor = rColor; }
226 void PSSetFont (const OString& rName,
227 rtl_TextEncoding nEncoding)
228 { maVirtualStatus.maFont = rName; maVirtualStatus.maEncoding = nEncoding; }
230 /* graphics status stack */
231 void PSGSave ();
232 void PSGRestore ();
234 /* PS helpers */
235 enum pspath_t { moveto = 0, lineto = 1 };
236 void PSBinLineTo (const Point& rCurrent, Point& rOld,
237 sal_Int32& nColumn);
238 void PSBinMoveTo (const Point& rCurrent, Point& rOld,
239 sal_Int32& nColumn);
240 void PSBinStartPath ();
241 void PSBinEndPath ();
242 void PSBinCurrentPath (sal_uInt32 nPoints, const Point* pPath);
243 void PSBinPath (const Point& rCurrent, Point& rOld,
244 pspath_t eType, sal_Int32& nColumn);
246 void PSRotate (sal_Int32 nAngle);
247 void PSTranslate (const Point& rPoint);
248 void PSMoveTo (const Point& rPoint);
249 void PSScale (double fScaleX, double fScaleY);
250 void PSLineTo(const Point& rPoint );
251 void PSPointOp (const Point& rPoint, const sal_Char* pOperator);
252 void PSHexString (const unsigned char* pString, sal_Int16 nLen);
253 void PSShowGlyph (const unsigned char nGlyphId);
255 void OnEndJob ();
256 void writeResources( osl::File* pFile, std::list< OString >& rSuppliedFonts );
257 PrintFontManager& GetFontMgr () { return mrFontMgr; }
259 void drawGlyph(const Point& rPoint,
260 sal_GlyphId aGlyphId,
261 sal_Int32 nDelta);
262 public:
263 PrinterGfx();
264 ~PrinterGfx();
265 void Init (PrinterJob &rPrinterSpec);
266 void Init (const JobData& rData);
267 void Clear();
269 // query depth
270 sal_uInt16 GetBitCount () { return mnDepth;}
272 // clip region
273 void ResetClipRegion ();
274 void BeginSetClipRegion();
275 void UnionClipRegion (sal_Int32 nX, sal_Int32 nY,
276 sal_Int32 nDX, sal_Int32 nDY);
277 void EndSetClipRegion ();
279 // set xy color
280 void SetLineColor (const PrinterColor& rLineColor = PrinterColor())
281 { maLineColor = rLineColor; }
282 void SetFillColor (const PrinterColor& rFillColor = PrinterColor())
283 { maFillColor = rFillColor; }
285 // drawing primitives
286 void DrawPixel (const Point& rPoint, const PrinterColor& rPixelColor);
287 void DrawPixel (const Point& rPoint)
288 { DrawPixel (rPoint, maLineColor); }
289 void DrawLine (const Point& rFrom, const Point& rTo);
290 void DrawRect (const tools::Rectangle& rRectangle);
291 void DrawPolyLine (sal_uInt32 nPoints, const Point* pPath );
292 void DrawPolygon (sal_uInt32 nPoints, const Point* pPath);
293 void DrawPolyPolygon (sal_uInt32 nPoly,
294 const sal_uInt32 *pPolygonSize,
295 const Point** pPolygonList);
296 void DrawPolyLineBezier (sal_uInt32 nPoints,
297 const Point* pPath,
298 const PolyFlags* pFlgAry );
299 void DrawPolygonBezier (sal_uInt32 nPoints,
300 const Point* pPath,
301 const PolyFlags* pFlgAry);
302 void DrawPolyPolygonBezier (sal_uInt32 nPoly,
303 const sal_uInt32* pPoints,
304 const Point* const* pPtAry,
305 const PolyFlags* const* pFlgAry);
307 // eps
308 bool DrawEPS ( const tools::Rectangle& rBoundingBox, void* pPtr, sal_uInt32 nSize);
310 // image drawing
311 void DrawBitmap (const tools::Rectangle& rDest, const tools::Rectangle& rSrc,
312 const PrinterBmp& rBitmap);
314 // font and text handling
315 void SetFont (
316 sal_Int32 nFontID,
317 sal_Int32 nPointHeight,
318 sal_Int32 nPointWidth,
319 sal_Int32 nAngle,
320 bool bVertical,
321 bool bArtItalic,
322 bool bArtBold
324 sal_Int32 GetFontID () const
325 { return mnFontID; }
326 bool GetFontVertical() const
327 { return mbTextVertical; }
328 sal_Int32 GetFontHeight () const
329 { return maVirtualStatus.mnTextHeight; }
330 sal_Int32 GetFontWidth () const
331 { return maVirtualStatus.mnTextWidth; }
332 bool GetArtificialItalic() const
333 { return maVirtualStatus.mbArtItalic; }
334 bool GetArtificialBold() const
335 { return maVirtualStatus.mbArtBold; }
336 void SetTextColor (PrinterColor& rTextColor)
337 { maTextColor = rTextColor; }
339 void DrawGlyph(const Point& rPoint,
340 const GlyphItem& rGlyph,
341 sal_Int32 nDelta);
345 } /* namespace psp */
347 #endif // INCLUDED_VCL_INC_GENERIC_PRINTERGFX_HXX
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */