LibreOffice Module vcl (master) 1
printergfx.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef INCLUDED_VCL_INC_GENERIC_PRINTERGFX_HXX
21#define INCLUDED_VCL_INC_GENERIC_PRINTERGFX_HXX
22
23#include <osl/file.hxx>
24#include <tools/gen.hxx>
25#include <vcl/dllapi.h>
26
27#include <impglyphitem.hxx>
28
29#include <list>
30#include <vector>
31
32enum class PolyFlags : sal_uInt8;
33
34namespace psp {
35
36struct JobData;
37
38/*
39 * lightweight container to handle RGB values
40 */
41
43{
44public:
45
46 enum class ColorSpace { eInvalid, eRGB };
47
48private:
49
54
55public:
56
58 : mnRed(0)
59 , mnGreen(0)
60 , mnBlue(0)
61 , meColorspace(ColorSpace::eInvalid)
62 {}
63 PrinterColor (sal_uInt16 nRed, sal_uInt16 nGreen,
64 sal_uInt16 nBlue) :
65 mnRed (nRed),
66 mnGreen (nGreen),
67 mnBlue (nBlue),
69 {}
70 PrinterColor (sal_uInt32 nRGB) :
71 mnRed ((nRGB & 0x00ff0000) >> 16),
72 mnGreen ((nRGB & 0x0000ff00) >> 8),
73 mnBlue ((nRGB & 0x000000ff) ),
75 {}
76
77 bool Is () const
79
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
87 {
88 return aColor.Is() && Is()
89 && mnRed == aColor.mnRed
90 && mnGreen == aColor.mnGreen
91 && mnBlue == aColor.mnBlue;
92 }
93 bool operator!= (const PrinterColor& aColor) const
94 { return ! (aColor==*this); }
95
96 PrinterColor& operator= (sal_uInt32 nRGB)
97 {
99 mnBlue = (nRGB & 0x000000ff);
100 mnGreen = (nRGB & 0x0000ff00) >> 8;
101 mnRed = (nRGB & 0x00ff0000) >> 16;
102
103 return *this;
104 }
105};
106
107class GlyphSet;
108class PrinterJob;
109class PrintFontManager;
110struct CharacterMetric;
111
112/*
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
117 */
118
120{
121public:
122
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;
130};
131
132enum class ImageType {
137};
138
139/*
140 * printer raster operations
141 */
142
144{
145 OString maFont;
146 rtl_TextEncoding maEncoding;
149 sal_Int32 mnTextHeight;
150 sal_Int32 mnTextWidth;
153
155};
156
158{
159private:
160
161 /* common settings */
162
163 double mfScaleX;
164 double mfScaleY;
165
166 sal_uInt32 mnDpi;
167 sal_uInt16 mnDepth;
168
169 sal_uInt16 mnPSLevel;
172
173 osl::File* mpPageBody;
174
175 /* text/font related data, for a type1 font it has to be checked
176 whether this font has already been downloaded. A TrueType font
177 will be converted into one or more Type3 fonts, containing glyphs
178 in no particular order. In addition to the existence of the
179 glyph in one of the subfonts, the mapping from unicode to the
180 glyph has to be remembered */
181
182 std::vector< GlyphSet > maPS3Font;
183
184 sal_Int32 mnFontID;
188
189 /* bitmap drawing implementation */
190
191 void DrawPS1GrayImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea);
193 void writePS2Colorspace (const PrinterBmp& rBitmap, psp::ImageType nType);
194 void DrawPS2GrayImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea);
195 void DrawPS2PaletteImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea);
196 void DrawPS2TrueColorImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea);
197 void DrawPS2MonoImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea);
198
199 /* clip region */
200
201 std::list< tools::Rectangle > maClipRegion;
202 bool JoinVerticalClipRectangles( std::list< tools::Rectangle >::iterator& it,
203 Point& aOldPoint, sal_Int32& nColumn );
204
205 /* color settings */
209
210 /* graphics state */
212 std::list< GraphicsStatus > maGraphicsStack;
214
215public:
216 /* graphics status update */
217 void PSSetColor ();
219 void PSSetFont ();
220
221 /* graphics status functions */
222 void PSSetColor (const PrinterColor& rColor)
223 { maVirtualStatus.maColor = rColor; }
224
225 void PSSetFont (const OString& rName,
226 rtl_TextEncoding nEncoding)
227 { maVirtualStatus.maFont = rName; maVirtualStatus.maEncoding = nEncoding; }
228
229 /* graphics status stack */
230 void PSGSave ();
231 void PSGRestore ();
232
233 /* PS helpers */
234 enum pspath_t { moveto = 0, lineto = 1 };
235 void PSBinLineTo (const Point& rCurrent, Point& rOld,
236 sal_Int32& nColumn);
237 void PSBinMoveTo (const Point& rCurrent, Point& rOld,
238 sal_Int32& nColumn);
241 void PSBinCurrentPath (sal_uInt32 nPoints, const Point* pPath);
242 void PSBinPath (const Point& rCurrent, Point& rOld,
243 pspath_t eType, sal_Int32& nColumn);
244
245 void PSRotate (Degree10 nAngle);
246 void PSTranslate (const Point& rPoint);
247 void PSMoveTo (const Point& rPoint);
248 void PSScale (double fScaleX, double fScaleY);
249 void PSLineTo(const Point& rPoint );
250 void PSPointOp (const Point& rPoint, const char* pOperator);
251 void PSHexString (const unsigned char* pString, sal_Int16 nLen);
252 void PSShowGlyph (const unsigned char nGlyphId);
253
254 void OnEndJob ();
255 void writeResources( osl::File* pFile, std::vector< OString >& rSuppliedFonts );
257
258 void drawGlyph(const Point& rPoint,
259 sal_GlyphId aGlyphId);
260public:
263 void Init (PrinterJob &rPrinterSpec);
264 void Init (const JobData& rData);
265 void Clear();
266
267 // query depth
268 sal_uInt16 GetBitCount () const { return mnDepth;}
269
270 // clip region
273 void UnionClipRegion (sal_Int32 nX, sal_Int32 nY,
274 sal_Int32 nDX, sal_Int32 nDY);
276
277 // set xy color
278 void SetLineColor (const PrinterColor& rLineColor = PrinterColor())
279 { maLineColor = rLineColor; }
280 void SetFillColor (const PrinterColor& rFillColor = PrinterColor())
281 { maFillColor = rFillColor; }
282
283 // drawing primitives
284 void DrawPixel (const Point& rPoint, const PrinterColor& rPixelColor);
285 void DrawPixel (const Point& rPoint)
286 { DrawPixel (rPoint, maLineColor); }
287 void DrawLine (const Point& rFrom, const Point& rTo);
288 void DrawRect (const tools::Rectangle& rRectangle);
289 void DrawPolyLine (sal_uInt32 nPoints, const Point* pPath );
290 void DrawPolygon (sal_uInt32 nPoints, const Point* pPath);
291 void DrawPolyPolygon (sal_uInt32 nPoly,
292 const sal_uInt32 *pPolygonSize,
293 const Point** pPolygonList);
294 void DrawPolyLineBezier (sal_uInt32 nPoints,
295 const Point* pPath,
296 const PolyFlags* pFlgAry );
297 void DrawPolygonBezier (sal_uInt32 nPoints,
298 const Point* pPath,
299 const PolyFlags* pFlgAry);
300 void DrawPolyPolygonBezier (sal_uInt32 nPoly,
301 const sal_uInt32* pPoints,
302 const Point* const* pPtAry,
303 const PolyFlags* const* pFlgAry);
304
305 // eps
306 bool DrawEPS ( const tools::Rectangle& rBoundingBox, void* pPtr, sal_uInt32 nSize);
307
308 // image drawing
309 void DrawBitmap (const tools::Rectangle& rDest, const tools::Rectangle& rSrc,
310 const PrinterBmp& rBitmap);
311
312 // font and text handling
313 void SetFont (
314 sal_Int32 nFontID,
315 sal_Int32 nPointHeight,
316 sal_Int32 nPointWidth,
317 Degree10 nAngle,
318 bool bVertical,
319 bool bArtItalic,
320 bool bArtBold
321 );
322 sal_Int32 GetFontID () const
323 { return mnFontID; }
324 bool GetFontVertical() const
325 { return mbTextVertical; }
326 sal_Int32 GetFontHeight () const
327 { return maVirtualStatus.mnTextHeight; }
328 sal_Int32 GetFontWidth () const
329 { return maVirtualStatus.mnTextWidth; }
331 { return maVirtualStatus.mbArtItalic; }
332 bool GetArtificialBold() const
333 { return maVirtualStatus.mbArtBold; }
334 void SetTextColor (PrinterColor const & rTextColor)
335 { maTextColor = rTextColor; }
336
337 void DrawGlyph(const Point& rPoint,
338 const GlyphItem& rGlyph);
339
340};
341
342} /* namespace psp */
343
344#endif // INCLUDED_VCL_INC_GENERIC_PRINTERGFX_HXX
345
346/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_uInt8 GetPixelGray(sal_uInt32 nRow, sal_uInt32 nColumn) const =0
virtual ~PrinterBmp()=0
virtual sal_uInt32 GetPixelRGB(sal_uInt32 nRow, sal_uInt32 nColumn) const =0
virtual sal_uInt32 GetPaletteEntryCount() const =0
virtual sal_uInt32 GetDepth() const =0
virtual sal_uInt8 GetPixelIdx(sal_uInt32 nRow, sal_uInt32 nColumn) const =0
virtual sal_uInt32 GetPaletteColor(sal_uInt32 nIdx) const =0
sal_uInt16 GetRed() const
Definition: printergfx.hxx:80
sal_uInt8 mnBlue
Definition: printergfx.hxx:52
bool Is() const
Definition: printergfx.hxx:77
PrinterColor & operator=(sal_uInt32 nRGB)
Definition: printergfx.hxx:96
sal_uInt16 GetBlue() const
Definition: printergfx.hxx:84
PrinterColor(sal_uInt16 nRed, sal_uInt16 nGreen, sal_uInt16 nBlue)
Definition: printergfx.hxx:63
bool operator==(const PrinterColor &aColor) const
Definition: printergfx.hxx:86
sal_uInt16 GetGreen() const
Definition: printergfx.hxx:82
ColorSpace meColorspace
Definition: printergfx.hxx:53
PrinterColor(sal_uInt32 nRGB)
Definition: printergfx.hxx:70
sal_uInt8 mnGreen
Definition: printergfx.hxx:51
bool operator!=(const PrinterColor &aColor) const
Definition: printergfx.hxx:93
sal_Int32 GetFontHeight() const
Definition: printergfx.hxx:326
void PSScale(double fScaleX, double fScaleY)
bool GetArtificialBold() const
Definition: printergfx.hxx:332
void UnionClipRegion(sal_Int32 nX, sal_Int32 nY, sal_Int32 nDX, sal_Int32 nDY)
PrintFontManager & GetFontMgr()
Definition: printergfx.hxx:256
sal_uInt16 GetBitCount() const
Definition: printergfx.hxx:268
sal_uInt32 mnDpi
Definition: printergfx.hxx:166
void PSHexString(const unsigned char *pString, sal_Int16 nLen)
sal_Int32 mnFontID
Definition: printergfx.hxx:184
void DrawPixel(const Point &rPoint)
Definition: printergfx.hxx:285
void PSSetFont(const OString &rName, rtl_TextEncoding nEncoding)
Definition: printergfx.hxx:225
void BeginSetClipRegion()
void DrawRect(const tools::Rectangle &rRectangle)
void EndSetClipRegion()
void Init(PrinterJob &rPrinterSpec)
void SetTextColor(PrinterColor const &rTextColor)
Definition: printergfx.hxx:334
void PSBinLineTo(const Point &rCurrent, Point &rOld, sal_Int32 &nColumn)
Degree10 mnTextAngle
Definition: printergfx.hxx:185
osl::File * mpPageBody
Definition: printergfx.hxx:173
sal_uInt16 mnPSLevel
Definition: printergfx.hxx:169
void DrawPolygon(sal_uInt32 nPoints, const Point *pPath)
void SetLineColor(const PrinterColor &rLineColor=PrinterColor())
Definition: printergfx.hxx:278
void PSPointOp(const Point &rPoint, const char *pOperator)
PrintFontManager & mrFontMgr
Definition: printergfx.hxx:187
void DrawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32 *pPolygonSize, const Point **pPolygonList)
void writeResources(osl::File *pFile, std::vector< OString > &rSuppliedFonts)
bool GetArtificialItalic() const
Definition: printergfx.hxx:330
bool JoinVerticalClipRectangles(std::list< tools::Rectangle >::iterator &it, Point &aOldPoint, sal_Int32 &nColumn)
void DrawPolyPolygonBezier(sal_uInt32 nPoly, const sal_uInt32 *pPoints, const Point *const *pPtAry, const PolyFlags *const *pFlgAry)
void DrawLine(const Point &rFrom, const Point &rTo)
void PSBinCurrentPath(sal_uInt32 nPoints, const Point *pPath)
void ResetClipRegion()
std::list< GraphicsStatus > maGraphicsStack
Definition: printergfx.hxx:212
void writePS2ImageHeader(const tools::Rectangle &rArea, psp::ImageType nType)
void PSLineTo(const Point &rPoint)
sal_Int32 GetFontID() const
Definition: printergfx.hxx:322
std::vector< GlyphSet > maPS3Font
Definition: printergfx.hxx:182
std::list< tools::Rectangle > maClipRegion
Definition: printergfx.hxx:201
sal_uInt16 mnDepth
Definition: printergfx.hxx:167
void PSSetColor(const PrinterColor &rColor)
Definition: printergfx.hxx:222
void DrawPS2MonoImage(const PrinterBmp &rBitmap, const tools::Rectangle &rArea)
void DrawPS1GrayImage(const PrinterBmp &rBitmap, const tools::Rectangle &rArea)
void DrawBitmap(const tools::Rectangle &rDest, const tools::Rectangle &rSrc, const PrinterBmp &rBitmap)
sal_Int32 GetFontWidth() const
Definition: printergfx.hxx:328
void PSTranslate(const Point &rPoint)
void Init(const JobData &rData)
void PSBinMoveTo(const Point &rCurrent, Point &rOld, sal_Int32 &nColumn)
void PSMoveTo(const Point &rPoint)
PrinterColor maFillColor
Definition: printergfx.hxx:206
PrinterColor maLineColor
Definition: printergfx.hxx:208
void DrawGlyph(const Point &rPoint, const GlyphItem &rGlyph)
GraphicsStatus maVirtualStatus
Definition: printergfx.hxx:211
GraphicsStatus & currentState()
Definition: printergfx.hxx:213
void DrawPixel(const Point &rPoint, const PrinterColor &rPixelColor)
void PSSetLineWidth()
void DrawPolygonBezier(sal_uInt32 nPoints, const Point *pPath, const PolyFlags *pFlgAry)
void writePS2Colorspace(const PrinterBmp &rBitmap, psp::ImageType nType)
void PSShowGlyph(const unsigned char nGlyphId)
void DrawPolyLineBezier(sal_uInt32 nPoints, const Point *pPath, const PolyFlags *pFlgAry)
void DrawPS2TrueColorImage(const PrinterBmp &rBitmap, const tools::Rectangle &rArea)
void DrawPS2PaletteImage(const PrinterBmp &rBitmap, const tools::Rectangle &rArea)
void DrawPolyLine(sal_uInt32 nPoints, const Point *pPath)
PrinterColor maTextColor
Definition: printergfx.hxx:207
void DrawPS2GrayImage(const PrinterBmp &rBitmap, const tools::Rectangle &rArea)
bool DrawEPS(const tools::Rectangle &rBoundingBox, void *pPtr, sal_uInt32 nSize)
void PSBinPath(const Point &rCurrent, Point &rOld, pspath_t eType, sal_Int32 &nColumn)
bool GetFontVertical() const
Definition: printergfx.hxx:324
void drawGlyph(const Point &rPoint, sal_GlyphId aGlyphId)
void PSRotate(Degree10 nAngle)
void SetFont(sal_Int32 nFontID, sal_Int32 nPointHeight, sal_Int32 nPointWidth, Degree10 nAngle, bool bVertical, bool bArtItalic, bool bArtBold)
void PSBinStartPath()
void SetFillColor(const PrinterColor &rFillColor=PrinterColor())
Definition: printergfx.hxx:280
uint32_t sal_GlyphId
Definition: glyphid.hxx:24
PolyFlags
PrinterColor maColor
Definition: printergfx.hxx:151
sal_Int32 mnTextHeight
Definition: printergfx.hxx:149
rtl_TextEncoding maEncoding
Definition: printergfx.hxx:146
unsigned char sal_uInt8