1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
36 * lightweight container to handle RGB values
43 enum ColorSpace
{ eInvalid
, eRGB
};
50 ColorSpace meColorspace
;
58 , meColorspace(eInvalid
)
60 PrinterColor (sal_uInt16 nRed
, sal_uInt16 nGreen
,
67 PrinterColor (sal_uInt32 nRGB
) :
68 mnRed ((nRGB
& 0x00ff0000) >> 16),
69 mnGreen ((nRGB
& 0x0000ff00) >> 8),
70 mnBlue ((nRGB
& 0x000000ff) ),
77 { return meColorspace
!= eInvalid
; }
79 ColorSpace
GetColorSpace () const
80 { return meColorspace
; }
81 sal_uInt16
GetRed () const
83 sal_uInt16
GetGreen () const
85 sal_uInt16
GetBlue () const
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
;
100 mnGreen
= aColor
.mnGreen
;
101 mnBlue
= aColor
.mnBlue
;
106 PrinterColor
& operator= (sal_uInt32 nRGB
)
109 mnBlue
= (nRGB
& 0x000000ff);
110 mnGreen
= (nRGB
& 0x0000ff00) >> 8;
111 mnRed
= (nRGB
& 0x00ff0000) >> 16;
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
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;
154 * printer raster operations
157 struct GraphicsStatus
160 rtl_TextEncoding maEncoding
;
163 sal_Int32 mnTextHeight
;
164 sal_Int32 mnTextWidth
;
165 PrinterColor maColor
;
173 class VCL_DLLPUBLIC PrinterGfx
177 /* common settings */
185 sal_uInt16 mnPSLevel
;
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
)
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
;
209 sal_Int32 mnFallbackID
;
210 sal_Int32 mnTextAngle
;
212 PrintFontManager
& mrFontMgr
;
214 /* bitmap drawing implementation */
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
);
228 std::list
< Rectangle
> maClipRegion
;
229 bool JoinVerticalClipRectangles( std::list
< Rectangle
>::iterator
& it
,
230 Point
& aOldPoint
, sal_Int32
& nColumn
);
233 PrinterColor maFillColor
;
234 PrinterColor maTextColor
;
235 PrinterColor maLineColor
;
238 GraphicsStatus maVirtualStatus
;
239 std::list
< GraphicsStatus
> maGraphicsStack
;
240 GraphicsStatus
& currentState() { return maGraphicsStack
.front(); }
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
; }
251 /* grahics status update */
253 void PSSetLineWidth ();
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 */
270 enum pspath_t
{ moveto
= 0, lineto
= 1 };
271 void PSBinLineTo (const Point
& rCurrent
, Point
& rOld
,
273 void PSBinMoveTo (const Point
& rCurrent
, Point
& rOld
,
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
);
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
,
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
,
312 sal_Int32
* pDeltaArray
);
316 bool Init (PrinterJob
&rPrinterSpec
);
317 bool Init (const JobData
& rData
);
321 sal_uInt16
GetBitCount () { return mnDepth
;}
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 ();
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
,
349 const sal_uInt8
* pFlgAry
);
350 void DrawPolygonBezier (sal_uInt32 nPoints
,
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
);
359 bool DrawEPS ( const Rectangle
& rBoundingBox
, void* pPtr
, sal_uInt32 nSize
);
362 void DrawBitmap (const Rectangle
& rDest
, const Rectangle
& rSrc
,
363 const PrinterBmp
& rBitmap
);
365 // font and text handling
368 sal_Int32 nPointHeight
,
369 sal_Int32 nPointWidth
,
375 sal_Int32
GetFontAngle () const
376 { return mnTextAngle
; }
377 sal_Int32
GetFontID () const
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
,
397 void DrawGlyphs( const Point
& rPoint
,
398 sal_GlyphId
* pGlyphIds
,
399 sal_Unicode
* pUnicodes
,
401 sal_Int32
* pDeltaArray
);
405 } /* namespace psp */
407 #endif // INCLUDED_VCL_INC_GENERIC_PRINTERGFX_HXX
409 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */