Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / vcl / inc / generic / printergfx.hxx
blobd69837e05d9798f5a4cd60aefa2cb8a80983fac8
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 _PSPRINT_PRINTERGFX_HXX_
21 #define _PSPRINT_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>
30 #include <boost/unordered_map.hpp>
32 namespace psp {
34 // forwards
35 struct JobData;
38 * lightweight container to handle RGB values
41 class PrinterColor
43 public:
45 enum ColorSpace { eInvalid, eRGB };
47 private:
49 sal_uInt8 mnRed;
50 sal_uInt8 mnGreen;
51 sal_uInt8 mnBlue;
52 ColorSpace meColorspace;
54 public:
56 PrinterColor () :
57 meColorspace(eInvalid)
59 PrinterColor (sal_uInt16 nRed, sal_uInt16 nGreen,
60 sal_uInt16 nBlue) :
61 mnRed (nRed),
62 mnGreen (nGreen),
63 mnBlue (nBlue),
64 meColorspace (eRGB)
66 PrinterColor (sal_uInt32 nRGB) :
67 mnRed ((nRGB & 0x00ff0000) >> 16),
68 mnGreen ((nRGB & 0x0000ff00) >> 8),
69 mnBlue ((nRGB & 0x000000ff) ),
70 meColorspace (eRGB)
72 ~PrinterColor ()
75 sal_Bool Is () const
76 { return meColorspace != eInvalid; }
78 ColorSpace GetColorSpace () const
79 { return meColorspace; }
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 sal_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 sal_Bool operator!= (const PrinterColor& aColor) const
94 { return ! (aColor==*this); }
95 PrinterColor& operator= (const PrinterColor& aColor)
97 meColorspace = aColor.meColorspace;
98 mnRed = aColor.mnRed;
99 mnGreen = aColor.mnGreen;
100 mnBlue = aColor.mnBlue;
102 return *this;
105 PrinterColor& operator= (sal_uInt32 nRGB)
107 meColorspace = eRGB;
108 mnBlue = (nRGB & 0x000000ff);
109 mnGreen = (nRGB & 0x0000ff00) >> 8;
110 mnRed = (nRGB & 0x00ff0000) >> 16;
112 return *this;
117 * forward declarations
120 class Font3;
121 class GlyphSet;
122 class PrinterJob;
123 class PrintFontManager;
124 struct KernPair;
125 struct CharacterMetric;
128 * Bitmap Interface, this has to be filled with your actual bitmap implementation
129 * sample implementations can be found in:
130 * psprint/workben/cui/pspdem.cxx
131 * vcl/unx/source/gdi/salgdi2.cxx
134 class VCL_DLLPUBLIC PrinterBmp
136 public:
138 virtual ~PrinterBmp () = 0;
139 virtual sal_uInt32 GetPaletteColor (sal_uInt32 nIdx) const = 0;
140 virtual sal_uInt32 GetPaletteEntryCount () const = 0;
141 virtual sal_uInt32 GetPixelRGB (sal_uInt32 nRow, sal_uInt32 nColumn) const = 0;
142 virtual sal_uInt8 GetPixelGray (sal_uInt32 nRow, sal_uInt32 nColumn) const = 0;
143 virtual sal_uInt8 GetPixelIdx (sal_uInt32 nRow, sal_uInt32 nColumn) const = 0;
144 virtual sal_uInt32 GetWidth () const = 0;
145 virtual sal_uInt32 GetHeight () const = 0;
146 virtual sal_uInt32 GetDepth () const = 0;
149 typedef enum {
150 InvalidType = 0,
151 TrueColorImage,
152 MonochromeImage,
153 PaletteImage,
154 GrayScaleImage
155 } ImageType;
158 * printer raster operations
161 struct GraphicsStatus
163 rtl::OString maFont;
164 rtl_TextEncoding maEncoding;
165 bool mbArtItalic;
166 bool mbArtBold;
167 sal_Int32 mnTextHeight;
168 sal_Int32 mnTextWidth;
169 PrinterColor maColor;
170 double mfLineWidth;
172 GraphicsStatus();
175 class Font3;
177 class VCL_DLLPUBLIC PrinterGfx
179 private:
181 /* common settings */
183 double mfScaleX;
184 double mfScaleY;
186 sal_uInt32 mnDpi;
187 sal_uInt16 mnDepth;
189 sal_uInt16 mnPSLevel;
190 sal_Bool mbColor;
191 sal_Bool mbUploadPS42Fonts;
193 osl::File* mpPageHeader;
194 osl::File* mpPageBody;
196 void TranslateCoordinates (sal_Int32 &rXOut, sal_Int32 &rYOut,
197 sal_Int32 nXIn, sal_Int32 nYIn )
198 { rXOut = nXIn; rYOut = nYIn; }
199 void TranslateCoordinates (Point& rOut, const Point& rIn)
200 { rOut = rIn; }
202 /* text/font related data, for a type1 font it has to be checked
203 whether this font has already been downloaded. A TrueType font
204 will be converted into one or more Type3 fonts, containing glyphs
205 in no particular order. In addition to the existence of the
206 glyph in one of the subfonts, the mapping from unicode to the
207 glyph has to be remembered */
209 std::list< sal_Int32 > maPS1Font;
210 std::list< GlyphSet > maPS3Font;
212 sal_Int32 mnFontID;
213 sal_Int32 mnFallbackID;
214 sal_Int32 mnTextAngle;
215 bool mbTextVertical;
216 PrintFontManager& mrFontMgr;
218 /* bitmap drawing implementation */
220 sal_Bool mbCompressBmp;
222 void DrawPS1GrayImage (const PrinterBmp& rBitmap, const Rectangle& rArea);
223 void writePS2ImageHeader (const Rectangle& rArea, psp::ImageType nType);
224 void writePS2Colorspace (const PrinterBmp& rBitmap, psp::ImageType nType);
225 void DrawPS2GrayImage (const PrinterBmp& rBitmap, const Rectangle& rArea);
226 void DrawPS2PaletteImage (const PrinterBmp& rBitmap, const Rectangle& rArea);
227 void DrawPS2TrueColorImage (const PrinterBmp& rBitmap, const Rectangle& rArea);
228 void DrawPS2MonoImage (const PrinterBmp& rBitmap, const Rectangle& rArea);
230 /* clip region */
232 std::list< Rectangle > maClipRegion;
233 sal_Bool JoinVerticalClipRectangles( std::list< Rectangle >::iterator& it,
234 Point& aOldPoint, sal_Int32& nColumn );
236 /* color settings */
237 PrinterColor maFillColor;
238 PrinterColor maTextColor;
239 PrinterColor maLineColor;
241 /* graphics state */
242 GraphicsStatus maVirtualStatus;
243 std::list< GraphicsStatus > maGraphicsStack;
244 GraphicsStatus& currentState() { return maGraphicsStack.front(); }
246 /* font / font substitution */
247 friend class Font3;
248 const ::boost::unordered_map< fontID, fontID >* mpFontSubstitutes;
249 int getCharWidth (sal_Bool b_vert, sal_Unicode n_char,
250 CharacterMetric *p_bbox);
251 fontID getCharMetric (const Font3 &rFont, sal_Unicode n_char,
252 CharacterMetric *p_bbox);
253 fontID getFontSubstitute () const;
254 fontID getFallbackID () const { return mnFallbackID; }
256 public:
257 /* grahics status update */
258 void PSSetColor ();
259 void PSSetLineWidth ();
260 void PSSetFont ();
262 /* graphics status functions */
263 void PSSetColor (const PrinterColor& rColor)
264 { maVirtualStatus.maColor = rColor; }
266 void PSUploadPS1Font (sal_Int32 nFontID);
267 void PSSetFont (const rtl::OString& rName,
268 rtl_TextEncoding nEncoding = RTL_TEXTENCODING_DONTKNOW)
269 { maVirtualStatus.maFont = rName; maVirtualStatus.maEncoding = nEncoding; }
271 /* graphics status stack */
272 void PSGSave ();
273 void PSGRestore ();
276 /* PS helpers */
277 enum pspath_t { moveto = 0, lineto = 1 };
278 void PSBinLineTo (const Point& rCurrent, Point& rOld,
279 sal_Int32& nColumn);
280 void PSBinMoveTo (const Point& rCurrent, Point& rOld,
281 sal_Int32& nColumn);
282 void PSBinStartPath ();
283 void PSBinEndPath ();
284 void PSBinCurrentPath (sal_uInt32 nPoints, const Point* pPath);
285 void PSBinPath (const Point& rCurrent, Point& rOld,
286 pspath_t eType, sal_Int32& nColumn);
288 void PSRotate (sal_Int32 nAngle);
289 void PSTranslate (const Point& rPoint);
290 void PSMoveTo (const Point& rPoint);
291 void PSScale (double fScaleX, double fScaleY);
292 void PSLineTo(const Point& rPoint );
293 void PSPointOp (const Point& rPoint, const sal_Char* pOperator);
294 void PSHexString (const sal_uChar* pString, sal_Int16 nLen);
295 void PSDeltaArray (const sal_Int32 *pArray, sal_Int16 nEntries);
296 void PSShowText (const sal_uChar* pString,
297 sal_Int16 nGlyphs, sal_Int16 nBytes,
298 const sal_Int32* pDeltaArray = NULL);
299 void PSComment (const sal_Char* pComment );
300 void LicenseWarning (const Point& rPoint, const sal_Unicode* pStr,
301 sal_Int16 nLen, const sal_Int32* pDeltaArray);
303 void OnEndPage ();
304 void OnEndJob ();
305 void writeResources( osl::File* pFile, std::list< rtl::OString >& rSuppliedFonts, std::list< rtl::OString >& rNeededFonts );
306 PrintFontManager& GetFontMgr () { return mrFontMgr; }
308 void drawVerticalizedText (const Point& rPoint,
309 const sal_Unicode* pStr,
310 sal_Int16 nLen,
311 const sal_Int32* pDeltaArray );
312 void drawText (const Point& rPoint,
313 const sal_Unicode* pStr, sal_Int16 nLen,
314 const sal_Int32* pDeltaArray = NULL);
316 void drawGlyphs( const Point& rPoint,
317 sal_GlyphId* pGlyphIds,
318 sal_Unicode* pUnicodes,
319 sal_Int16 nLen,
320 sal_Int32* pDeltaArray );
321 public:
322 PrinterGfx();
323 ~PrinterGfx();
324 sal_Bool Init (PrinterJob &rPrinterSpec);
325 sal_Bool Init (const JobData& rData);
326 void Clear();
328 // query depth
329 sal_uInt16 GetBitCount ();
331 // clip region
332 void ResetClipRegion ();
333 void BeginSetClipRegion (sal_uInt32);
334 sal_Bool UnionClipRegion (sal_Int32 nX, sal_Int32 nY,
335 sal_Int32 nDX, sal_Int32 nDY);
336 void EndSetClipRegion ();
338 // set xy color
339 void SetLineColor (const PrinterColor& rLineColor = PrinterColor())
340 { maLineColor = rLineColor; }
341 void SetFillColor (const PrinterColor& rFillColor = PrinterColor())
342 { maFillColor = rFillColor; }
344 // drawing primitives
345 void DrawPixel (const Point& rPoint, const PrinterColor& rPixelColor);
346 void DrawPixel (const Point& rPoint)
347 { DrawPixel (rPoint, maLineColor); }
348 void DrawLine (const Point& rFrom, const Point& rTo);
349 void DrawRect (const Rectangle& rRectangle);
350 void DrawPolyLine (sal_uInt32 nPoints, const Point* pPath );
351 void DrawPolygon (sal_uInt32 nPoints, const Point* pPath);
352 void DrawPolyPolygon (sal_uInt32 nPoly,
353 const sal_uInt32 *pPolygonSize,
354 const Point** pPolygonList);
355 void DrawPolyLineBezier (sal_uInt32 nPoints,
356 const Point* pPath,
357 const sal_uInt8* pFlgAry );
358 void DrawPolygonBezier (sal_uInt32 nPoints,
359 const Point* pPath,
360 const sal_uInt8* pFlgAry);
361 void DrawPolyPolygonBezier (sal_uInt32 nPoly,
362 const sal_uInt32* pPoints,
363 const Point* const* pPtAry,
364 const sal_uInt8* const* pFlgAry);
366 // eps
367 sal_Bool DrawEPS ( const Rectangle& rBoundingBox, void* pPtr, sal_uInt32 nSize);
369 // image drawing
370 void DrawBitmap (const Rectangle& rDest, const Rectangle& rSrc,
371 const PrinterBmp& rBitmap);
373 // font and text handling
374 sal_uInt16 SetFont (
375 sal_Int32 nFontID,
376 sal_Int32 nPointHeight,
377 sal_Int32 nPointWidth,
378 sal_Int32 nAngle,
379 bool bVertical,
380 bool bArtItalic,
381 bool bArtBold
383 sal_Int32 GetFontAngle () const
384 { return mnTextAngle; }
385 sal_Int32 GetFontID () const
386 { return mnFontID; }
387 bool GetFontVertical() const
388 { return mbTextVertical; }
389 sal_Int32 GetFontHeight () const
390 { return maVirtualStatus.mnTextHeight; }
391 sal_Int32 GetFontWidth () const
392 { return maVirtualStatus.mnTextWidth; }
393 bool GetArtificialItalic() const
394 { return maVirtualStatus.mbArtItalic; }
395 bool GetArtificialBold() const
396 { return maVirtualStatus.mbArtBold; }
397 void DrawText (const Point& rPoint,
398 const sal_Unicode* pStr, sal_Int16 nLen,
399 const sal_Int32* pDeltaArray = NULL);
400 void SetTextColor (PrinterColor& rTextColor)
401 { maTextColor = rTextColor; }
402 sal_Int32 GetCharWidth (sal_uInt16 nFrom, sal_uInt16 nTo,
403 long *pWidthArray);
404 const ::std::list< KernPair >& getKernPairs( bool bVertical = false ) const;
406 // for CTL
407 void DrawGlyphs( const Point& rPoint,
408 sal_GlyphId* pGlyphIds,
409 sal_Unicode* pUnicodes,
410 sal_Int16 nLen,
411 sal_Int32* pDeltaArray );
415 } /* namespace psp */
418 #endif /* _PSPRINT_PRINTERGFX_HXX_ */
420 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */