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 #include <vcl/glyphitem.hxx>
27 
28 #include <impglyphitem.hxx>
29 
30 #include <list>
31 #include <vector>
32 
33 enum class PolyFlags : sal_uInt8;
34 
35 namespace psp {
36 
37 struct JobData;
38 
39 /*
40  * lightweight container to handle RGB values
41  */
42 
44 {
45 public:
46 
47  enum ColorSpace { eInvalid, eRGB };
48 
49 private:
50 
55 
56 public:
57 
59  : mnRed(0)
60  , mnGreen(0)
61  , mnBlue(0)
62  , meColorspace(eInvalid)
63  {}
64  PrinterColor (sal_uInt16 nRed, sal_uInt16 nGreen,
65  sal_uInt16 nBlue) :
66  mnRed (nRed),
67  mnGreen (nGreen),
68  mnBlue (nBlue),
69  meColorspace (eRGB)
70  {}
71  PrinterColor (sal_uInt32 nRGB) :
72  mnRed ((nRGB & 0x00ff0000) >> 16),
73  mnGreen ((nRGB & 0x0000ff00) >> 8),
74  mnBlue ((nRGB & 0x000000ff) ),
75  meColorspace (eRGB)
76  {}
77 
78  bool Is () const
79  { return meColorspace != eInvalid; }
80 
81  sal_uInt16 GetRed () const
82  { return mnRed; }
83  sal_uInt16 GetGreen () const
84  { return mnGreen; }
85  sal_uInt16 GetBlue () const
86  { return mnBlue; }
87  bool operator== (const PrinterColor& aColor) const
88  {
89  return aColor.Is() && Is()
90  && mnRed == aColor.mnRed
91  && mnGreen == aColor.mnGreen
92  && mnBlue == aColor.mnBlue;
93  }
94  bool operator!= (const PrinterColor& aColor) const
95  { return ! (aColor==*this); }
96 
97  PrinterColor& operator= (sal_uInt32 nRGB)
98  {
99  meColorspace = eRGB;
100  mnBlue = (nRGB & 0x000000ff);
101  mnGreen = (nRGB & 0x0000ff00) >> 8;
102  mnRed = (nRGB & 0x00ff0000) >> 16;
103 
104  return *this;
105  }
106 };
107 
108 class GlyphSet;
109 class PrinterJob;
110 class PrintFontManager;
111 struct CharacterMetric;
112 
113 /*
114  * Bitmap Interface, this has to be filled with your actual bitmap implementation
115  * sample implementations can be found in:
116  * psprint/workben/cui/pspdem.cxx
117  * vcl/unx/source/gdi/salgdi2.cxx
118  */
119 
121 {
122 public:
123 
124  virtual ~PrinterBmp () = 0;
125  virtual sal_uInt32 GetPaletteColor (sal_uInt32 nIdx) const = 0;
126  virtual sal_uInt32 GetPaletteEntryCount () const = 0;
127  virtual sal_uInt32 GetPixelRGB (sal_uInt32 nRow, sal_uInt32 nColumn) const = 0;
128  virtual sal_uInt8 GetPixelGray (sal_uInt32 nRow, sal_uInt32 nColumn) const = 0;
129  virtual sal_uInt8 GetPixelIdx (sal_uInt32 nRow, sal_uInt32 nColumn) const = 0;
130  virtual sal_uInt32 GetDepth () const = 0;
131 };
132 
133 enum class ImageType {
136  PaletteImage,
138 };
139 
140 /*
141  * printer raster operations
142  */
143 
145 {
146  OString maFont;
147  rtl_TextEncoding maEncoding;
149  bool mbArtBold;
150  sal_Int32 mnTextHeight;
151  sal_Int32 mnTextWidth;
153  double mfLineWidth;
154 
155  GraphicsStatus();
156 };
157 
159 {
160 private:
161 
162  /* common settings */
163 
164  double mfScaleX;
165  double mfScaleY;
166 
167  sal_uInt32 mnDpi;
168  sal_uInt16 mnDepth;
169 
170  sal_uInt16 mnPSLevel;
171  bool mbColor;
173 
174  osl::File* mpPageBody;
175 
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 */
182 
183  std::vector< GlyphSet > maPS3Font;
184 
185  sal_Int32 mnFontID;
186  sal_Int32 mnTextAngle;
189 
190  /* bitmap drawing implementation */
191 
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);
199 
200  /* clip region */
201 
202  std::list< tools::Rectangle > maClipRegion;
203  bool JoinVerticalClipRectangles( std::list< tools::Rectangle >::iterator& it,
204  Point& aOldPoint, sal_Int32& nColumn );
205 
206  /* color settings */
210 
211  /* graphics state */
213  std::list< GraphicsStatus > maGraphicsStack;
214  GraphicsStatus& currentState() { return maGraphicsStack.front(); }
215 
216 public:
217  /* graphics status update */
218  void PSSetColor ();
219  void PSSetLineWidth ();
220  void PSSetFont ();
221 
222  /* graphics status functions */
223  void PSSetColor (const PrinterColor& rColor)
224  { maVirtualStatus.maColor = rColor; }
225 
226  void PSSetFont (const OString& rName,
227  rtl_TextEncoding nEncoding)
228  { maVirtualStatus.maFont = rName; maVirtualStatus.maEncoding = nEncoding; }
229 
230  /* graphics status stack */
231  void PSGSave ();
232  void PSGRestore ();
233 
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);
245 
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);
254 
255  void OnEndJob ();
256  void writeResources( osl::File* pFile, std::vector< OString >& rSuppliedFonts );
257  PrintFontManager& GetFontMgr () { return mrFontMgr; }
258 
259  void drawGlyph(const Point& rPoint,
260  sal_GlyphId aGlyphId);
261 public:
262  PrinterGfx();
263  ~PrinterGfx();
264  void Init (PrinterJob &rPrinterSpec);
265  void Init (const JobData& rData);
266  void Clear();
267 
268  // query depth
269  sal_uInt16 GetBitCount () const { return mnDepth;}
270 
271  // clip region
272  void ResetClipRegion ();
273  void BeginSetClipRegion();
274  void UnionClipRegion (sal_Int32 nX, sal_Int32 nY,
275  sal_Int32 nDX, sal_Int32 nDY);
276  void EndSetClipRegion ();
277 
278  // set xy color
279  void SetLineColor (const PrinterColor& rLineColor = PrinterColor())
280  { maLineColor = rLineColor; }
281  void SetFillColor (const PrinterColor& rFillColor = PrinterColor())
282  { maFillColor = rFillColor; }
283 
284  // drawing primitives
285  void DrawPixel (const Point& rPoint, const PrinterColor& rPixelColor);
286  void DrawPixel (const Point& rPoint)
287  { DrawPixel (rPoint, maLineColor); }
288  void DrawLine (const Point& rFrom, const Point& rTo);
289  void DrawRect (const tools::Rectangle& rRectangle);
290  void DrawPolyLine (sal_uInt32 nPoints, const Point* pPath );
291  void DrawPolygon (sal_uInt32 nPoints, const Point* pPath);
292  void DrawPolyPolygon (sal_uInt32 nPoly,
293  const sal_uInt32 *pPolygonSize,
294  const Point** pPolygonList);
295  void DrawPolyLineBezier (sal_uInt32 nPoints,
296  const Point* pPath,
297  const PolyFlags* pFlgAry );
298  void DrawPolygonBezier (sal_uInt32 nPoints,
299  const Point* pPath,
300  const PolyFlags* pFlgAry);
301  void DrawPolyPolygonBezier (sal_uInt32 nPoly,
302  const sal_uInt32* pPoints,
303  const Point* const* pPtAry,
304  const PolyFlags* const* pFlgAry);
305 
306  // eps
307  bool DrawEPS ( const tools::Rectangle& rBoundingBox, void* pPtr, sal_uInt32 nSize);
308 
309  // image drawing
310  void DrawBitmap (const tools::Rectangle& rDest, const tools::Rectangle& rSrc,
311  const PrinterBmp& rBitmap);
312 
313  // font and text handling
314  void SetFont (
315  sal_Int32 nFontID,
316  sal_Int32 nPointHeight,
317  sal_Int32 nPointWidth,
318  sal_Int32 nAngle,
319  bool bVertical,
320  bool bArtItalic,
321  bool bArtBold
322  );
323  sal_Int32 GetFontID () const
324  { return mnFontID; }
325  bool GetFontVertical() const
326  { return mbTextVertical; }
327  sal_Int32 GetFontHeight () const
328  { return maVirtualStatus.mnTextHeight; }
329  sal_Int32 GetFontWidth () const
330  { return maVirtualStatus.mnTextWidth; }
331  bool GetArtificialItalic() const
332  { return maVirtualStatus.mbArtItalic; }
333  bool GetArtificialBold() const
334  { return maVirtualStatus.mbArtBold; }
335  void SetTextColor (PrinterColor const & rTextColor)
336  { maTextColor = rTextColor; }
337 
338  void DrawGlyph(const Point& rPoint,
339  const GlyphItem& rGlyph);
340 
341 };
342 
343 } /* namespace psp */
344 
345 #endif // INCLUDED_VCL_INC_GENERIC_PRINTERGFX_HXX
346 
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool GetArtificialItalic() const
Definition: printergfx.hxx:331
PrintFontManager & GetFontMgr()
Definition: printergfx.hxx:257
sal_uInt8 mnBlue
Definition: printergfx.hxx:53
bool operator!=(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:208
void Init()
bool Is() const
Definition: printergfx.hxx:78
void SetLineColor(const PrinterColor &rLineColor=PrinterColor())
Definition: printergfx.hxx:279
PrintFontManager & mrFontMgr
Definition: printergfx.hxx:188
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
PrinterColor(sal_uInt32 nRGB)
Definition: printergfx.hxx:71
GraphicsStatus maVirtualStatus
Definition: printergfx.hxx:212
void PSSetColor(const PrinterColor &rColor)
Definition: printergfx.hxx:223
std::list< tools::Rectangle > maClipRegion
Definition: printergfx.hxx:202
osl::File * mpPageBody
Definition: printergfx.hxx:174
sal_Int32 GetFontWidth() const
Definition: printergfx.hxx:329
sal_uInt16 sal_GlyphId
Definition: glyphitem.hxx:26
PrinterColor(sal_uInt16 nRed, sal_uInt16 nGreen, sal_uInt16 nBlue)
Definition: printergfx.hxx:64
char sal_Char
ColorSpace meColorspace
Definition: printergfx.hxx:54
Is
PrinterColor maTextColor
Definition: printergfx.hxx:208
bool operator==(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:203
sal_uInt32 mnDpi
Definition: printergfx.hxx:167
sal_Int32 GetFontHeight() const
Definition: printergfx.hxx:327
bool GetArtificialBold() const
Definition: printergfx.hxx:333
sal_uInt16 GetRed() const
Definition: printergfx.hxx:81
void DrawPixel(const Point &rPoint)
Definition: printergfx.hxx:286
rtl_TextEncoding maEncoding
Definition: printergfx.hxx:147
sal_uInt16 mnDepth
Definition: printergfx.hxx:168
void SetFillColor(const PrinterColor &rFillColor=PrinterColor())
Definition: printergfx.hxx:281
PrinterColor maLineColor
Definition: printergfx.hxx:209
void PSSetFont(const OString &rName, rtl_TextEncoding nEncoding)
Definition: printergfx.hxx:226
sal_uInt16 GetBitCount() const
Definition: printergfx.hxx:269
sal_uInt16 mnPSLevel
Definition: printergfx.hxx:170
sal_Int32 mnTextHeight
Definition: printergfx.hxx:150
bool GetFontVertical() const
Definition: printergfx.hxx:325
sal_Int32 mnTextAngle
Definition: printergfx.hxx:186
sal_uInt16 GetGreen() const
Definition: printergfx.hxx:83
unsigned char sal_uInt8
sal_uInt16 GetBlue() const
Definition: printergfx.hxx:85
std::vector< GlyphSet > maPS3Font
Definition: printergfx.hxx:183
PrinterColor maColor
Definition: printergfx.hxx:152
std::list< GraphicsStatus > maGraphicsStack
Definition: printergfx.hxx:213
void SetTextColor(PrinterColor const &rTextColor)
Definition: printergfx.hxx:335
PrinterColor maFillColor
Definition: printergfx.hxx:207
sal_uInt8 mnGreen
Definition: printergfx.hxx:52
GraphicsStatus & currentState()
Definition: printergfx.hxx:214
PolyFlags
sal_Int32 mnFontID
Definition: printergfx.hxx:185
sal_Int32 GetFontID() const
Definition: printergfx.hxx:323