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 _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"
30 #include <boost/unordered_map.hpp>
38 * lightweight container to handle RGB values
45 enum ColorSpace
{ eInvalid
, eRGB
};
52 ColorSpace meColorspace
;
57 meColorspace(eInvalid
)
59 PrinterColor (sal_uInt16 nRed
, sal_uInt16 nGreen
,
66 PrinterColor (sal_uInt32 nRGB
) :
67 mnRed ((nRGB
& 0x00ff0000) >> 16),
68 mnGreen ((nRGB
& 0x0000ff00) >> 8),
69 mnBlue ((nRGB
& 0x000000ff) ),
76 { return meColorspace
!= eInvalid
; }
78 ColorSpace
GetColorSpace () const
79 { return meColorspace
; }
80 sal_uInt16
GetRed () const
82 sal_uInt16
GetGreen () const
84 sal_uInt16
GetBlue () const
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
;
99 mnGreen
= aColor
.mnGreen
;
100 mnBlue
= aColor
.mnBlue
;
105 PrinterColor
& operator= (sal_uInt32 nRGB
)
108 mnBlue
= (nRGB
& 0x000000ff);
109 mnGreen
= (nRGB
& 0x0000ff00) >> 8;
110 mnRed
= (nRGB
& 0x00ff0000) >> 16;
117 * forward declarations
123 class PrintFontManager
;
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
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;
158 * printer raster operations
161 struct GraphicsStatus
164 rtl_TextEncoding maEncoding
;
167 sal_Int32 mnTextHeight
;
168 sal_Int32 mnTextWidth
;
169 PrinterColor maColor
;
177 class VCL_DLLPUBLIC PrinterGfx
181 /* common settings */
189 sal_uInt16 mnPSLevel
;
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
)
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
;
213 sal_Int32 mnFallbackID
;
214 sal_Int32 mnTextAngle
;
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
);
232 std::list
< Rectangle
> maClipRegion
;
233 sal_Bool
JoinVerticalClipRectangles( std::list
< Rectangle
>::iterator
& it
,
234 Point
& aOldPoint
, sal_Int32
& nColumn
);
237 PrinterColor maFillColor
;
238 PrinterColor maTextColor
;
239 PrinterColor maLineColor
;
242 GraphicsStatus maVirtualStatus
;
243 std::list
< GraphicsStatus
> maGraphicsStack
;
244 GraphicsStatus
& currentState() { return maGraphicsStack
.front(); }
246 /* font / font substitution */
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
; }
257 /* grahics status update */
259 void PSSetLineWidth ();
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 */
277 enum pspath_t
{ moveto
= 0, lineto
= 1 };
278 void PSBinLineTo (const Point
& rCurrent
, Point
& rOld
,
280 void PSBinMoveTo (const Point
& rCurrent
, Point
& rOld
,
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
);
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
,
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
,
320 sal_Int32
* pDeltaArray
);
324 sal_Bool
Init (PrinterJob
&rPrinterSpec
);
325 sal_Bool
Init (const JobData
& rData
);
329 sal_uInt16
GetBitCount ();
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 ();
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
,
357 const sal_uInt8
* pFlgAry
);
358 void DrawPolygonBezier (sal_uInt32 nPoints
,
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
);
367 sal_Bool
DrawEPS ( const Rectangle
& rBoundingBox
, void* pPtr
, sal_uInt32 nSize
);
370 void DrawBitmap (const Rectangle
& rDest
, const Rectangle
& rSrc
,
371 const PrinterBmp
& rBitmap
);
373 // font and text handling
376 sal_Int32 nPointHeight
,
377 sal_Int32 nPointWidth
,
383 sal_Int32
GetFontAngle () const
384 { return mnTextAngle
; }
385 sal_Int32
GetFontID () const
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
,
404 const ::std::list
< KernPair
>& getKernPairs( bool bVertical
= false ) const;
407 void DrawGlyphs( const Point
& rPoint
,
408 sal_GlyphId
* pGlyphIds
,
409 sal_Unicode
* pUnicodes
,
411 sal_Int32
* pDeltaArray
);
415 } /* namespace psp */
418 #endif /* _PSPRINT_PRINTERGFX_HXX_ */
420 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */