1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/
#include <unx/GenPspGfxBackend.hxx>
#include <unx/printergfx.hxx>
#include <vcl/BitmapReadAccess.hxx>
#include <salbmp.hxx>
// ----- Implementation of PrinterBmp by means of SalBitmap/BitmapBuffer ---------------
namespace
{
class SalPrinterBmp : public psp::PrinterBmp
{
private:
BitmapBuffer* mpBmpBuffer;
FncGetPixel mpFncGetPixel;
Scanline mpScanAccess;
sal_PtrDiff mnScanOffset;
public:
explicit SalPrinterBmp(BitmapBuffer* pBitmap);
virtual sal_uInt32 GetPaletteColor(sal_uInt32 nIdx) const override;
virtual sal_uInt32 GetPaletteEntryCount() const override;
virtual sal_uInt32 GetPixelRGB(sal_uInt32 nRow, sal_uInt32 nColumn) const override;
virtual sal_uInt8 GetPixelGray(sal_uInt32 nRow, sal_uInt32 nColumn) const override;
virtual sal_uInt8 GetPixelIdx(sal_uInt32 nRow, sal_uInt32 nColumn) const override;
virtual sal_uInt32 GetDepth() const override;
};
}
SalPrinterBmp::SalPrinterBmp(BitmapBuffer* pBuffer)
: mpBmpBuffer(pBuffer)
{
assert(mpBmpBuffer && "SalPrinterBmp::SalPrinterBmp () can't acquire Bitmap");
// calibrate scanline buffer
if (mpBmpBuffer->mnFormat & ScanlineFormat::TopDown)
{
mpScanAccess = mpBmpBuffer->mpBits;
mnScanOffset = mpBmpBuffer->mnScanlineSize;
}
else
{
mpScanAccess
= mpBmpBuffer->mpBits + (mpBmpBuffer->mnHeight - 1) * mpBmpBuffer->mnScanlineSize;
mnScanOffset = -mpBmpBuffer->mnScanlineSize;
}
// request read access to the pixels
mpFncGetPixel = BitmapReadAccess::GetPixelFunction(mpBmpBuffer->mnFormat);
}
sal_uInt32 SalPrinterBmp::GetDepth() const
{
sal_uInt32 nDepth;
switch (mpBmpBuffer->mnBitCount)
{
case 1:
nDepth = 1;
break;
case 4:
case 8:
nDepth = 8;
break;
case 24:
case 32:
nDepth = 24;
break;
default:
nDepth = 1;
assert(false && "Error: unsupported bitmap depth in SalPrinterBmp::GetDepth()");
break;
}
return nDepth;
}
sal_uInt32 SalPrinterBmp::GetPaletteEntryCount() const
{
return mpBmpBuffer->maPalette.GetEntryCount();
}
sal_uInt32 SalPrinterBmp::GetPaletteColor(sal_uInt32 nIdx) const
{
BitmapColor aColor(mpBmpBuffer->maPalette[nIdx]);
return ((aColor.GetBlue()) & 0x000000ff) | ((aColor.GetGreen() << 8) & 0x0000ff00)
| ((aColor.GetRed() << 16) & 0x00ff0000);
}
sal_uInt32 SalPrinterBmp::GetPixelRGB(sal_uInt32 nRow, sal_uInt32 nColumn) const
{
Scanline pScan = mpScanAccess + nRow * mnScanOffset;
BitmapColor aColor = mpFncGetPixel(pScan, nColumn, mpBmpBuffer->maColorMask);
if (!!mpBmpBuffer->maPalette)
GetPaletteColor(aColor.GetIndex());
return ((aColor.GetBlue()) & 0x000000ff) | ((aColor.GetGreen() << 8) & 0x0000ff00)
| ((aColor.GetRed() << 16) & 0x00ff0000);
}
sal_uInt8 SalPrinterBmp::GetPixelGray(sal_uInt32 nRow, sal_uInt32 nColumn) const
{
Scanline pScan = mpScanAccess + nRow * mnScanOffset;
BitmapColor aColor = mpFncGetPixel(pScan, nColumn, mpBmpBuffer->maColorMask);
if (!!mpBmpBuffer->maPalette)
aColor = mpBmpBuffer->maPalette[aColor.GetIndex()];
return (aColor.GetBlue() * 28UL + aColor.GetGreen() * 151UL + aColor.GetRed() * 77UL) >> 8;
}
sal_uInt8 SalPrinterBmp::GetPixelIdx(sal_uInt32 nRow, sal_uInt32 nColumn) const
{
Scanline pScan = mpScanAccess + nRow * mnScanOffset;
BitmapColor aColor = mpFncGetPixel(pScan, nColumn, mpBmpBuffer->maColorMask);
if (!!mpBmpBuffer->maPalette)
return aColor.GetIndex();
else
return 0;
}
GenPspGfxBackend::GenPspGfxBackend(psp::PrinterGfx* pPrinterGfx)
: m_pPrinterGfx(pPrinterGfx)
{
}
GenPspGfxBackend::~GenPspGfxBackend() {}
void GenPspGfxBackend::Init() {}
void GenPspGfxBackend::freeResources() {}
bool GenPspGfxBackend::setClipRegion(vcl::Region const& rRegion)
{
// TODO: support polygonal clipregions here
RectangleVector aRectangles;
rRegion.GetRegionRectangles(aRectangles);
m_pPrinterGfx->BeginSetClipRegion();
for (auto const& rectangle : aRectangles)
{
const tools::Long nWidth(rectangle.GetWidth());
const tools::Long nHeight(rectangle.GetHeight());
if (nWidth && nHeight)
{
m_pPrinterGfx->UnionClipRegion(rectangle.Left(), rectangle.Top(), nWidth, nHeight);
}
}
m_pPrinterGfx->EndSetClipRegion();
return true;
}
void GenPspGfxBackend::ResetClipRegion() { m_pPrinterGfx->ResetClipRegion(); }
sal_uInt16 GenPspGfxBackend::GetBitCount() const { return m_pPrinterGfx->GetBitCount(); }
tools::Long GenPspGfxBackend::GetGraphicsWidth() const { return 0; }
void GenPspGfxBackend::SetLineColor() { m_pPrinterGfx->SetLineColor(); }
void GenPspGfxBackend::SetLineColor(Color nColor)
{
psp::PrinterColor aColor(nColor.GetRed(), nColor.GetGreen(), nColor.GetBlue());
m_pPrinterGfx->SetLineColor(aColor);
}
void GenPspGfxBackend::SetFillColor() { m_pPrinterGfx->SetFillColor(); }
void GenPspGfxBackend::SetFillColor(Color nColor)
{
psp::PrinterColor aColor(nColor.GetRed(), nColor.GetGreen(), nColor.GetBlue());
m_pPrinterGfx->SetFillColor(aColor);
}
void GenPspGfxBackend::SetXORMode(bool bSet, bool /*bInvertOnly*/)
{
SAL_WARN_IF(bSet, "vcl", "Error: PrinterGfx::SetXORMode() not implemented");
}
void GenPspGfxBackend::SetROPLineColor(SalROPColor /*nROPColor*/)
{
SAL_WARN("vcl", "Error: PrinterGfx::SetROPLineColor() not implemented");
}
void GenPspGfxBackend::SetROPFillColor(SalROPColor /*nROPColor*/)
{
SAL_WARN("vcl", "Error: PrinterGfx::SetROPFillColor() not implemented");
}
void GenPspGfxBackend::drawPixel(tools::Long nX, tools::Long nY)
{
m_pPrinterGfx->DrawPixel(Point(nX, nY));
}
void GenPspGfxBackend::drawPixel(tools::Long nX, tools::Long nY, Color nColor)
{
psp::PrinterColor aColor(nColor.GetRed(), nColor.GetGreen(), nColor.GetBlue());
m_pPrinterGfx->DrawPixel(Point(nX, nY), aColor);
}
void GenPspGfxBackend::drawLine(tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2)
{
m_pPrinterGfx->DrawLine(Point(nX1, nY1), Point(nX2, nY2));
}
void GenPspGfxBackend::drawRect(tools::Long nX, tools::Long nY, tools::Long nWidth,
tools::Long nHeight)
{
m_pPrinterGfx->DrawRect(tools::Rectangle(Point(nX, nY), Size(nWidth, nHeight)));
}
void GenPspGfxBackend::drawPolyLine(sal_uInt32 nPoints, const Point* pPointArray)
{
m_pPrinterGfx->DrawPolyLine(nPoints, pPointArray);
}
void GenPspGfxBackend::drawPolygon(sal_uInt32 nPoints, const Point* pPointArray)
{
// Point must be equal to Point! see include/vcl/salgtype.hxx
m_pPrinterGfx->DrawPolygon(nPoints, pPointArray);
}
void GenPspGfxBackend::drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32* pPoints,
const Point** pPointArray)
{
m_pPrinterGfx->DrawPolyPolygon(nPoly, pPoints, pPointArray);
}
bool GenPspGfxBackend::drawPolyPolygon(const basegfx::B2DHomMatrix& /*rObjectToDevice*/,
const basegfx::B2DPolyPolygon&, double /*fTransparency*/)
{
// TODO: implement and advertise OutDevSupportType::B2DDraw support
return false;
}
bool GenPspGfxBackend::drawPolyLine(const basegfx::B2DHomMatrix& /*rObjectToDevice*/,
const basegfx::B2DPolygon& /*rPolygon*/,
double /*fTransparency*/, double /*fLineWidth*/,
const std::vector<double>* /*pStroke*/, basegfx::B2DLineJoin,
css::drawing::LineCap, double /*fMiterMinimumAngle*/,
bool /*bPixelSnapHairline*/)
{
// TODO: a PS printer can draw B2DPolyLines almost directly
return false;
}
bool GenPspGfxBackend::drawPolyLineBezier(sal_uInt32 nPoints, const Point* pPointArray,
const PolyFlags* pFlagArray)
{
m_pPrinterGfx->DrawPolyLineBezier(nPoints, pPointArray, pFlagArray);
return true;
}
bool GenPspGfxBackend::drawPolygonBezier(sal_uInt32 nPoints, const Point* pPointArray,
const PolyFlags* pFlagArray)
{
m_pPrinterGfx->DrawPolygonBezier(nPoints, pPointArray, pFlagArray);
return true;
}
bool GenPspGfxBackend::drawPolyPolygonBezier(sal_uInt32 nPoly, const sal_uInt32* pPoints,
const Point* const* pPointArray,
const PolyFlags* const* pFlagArray)
{
// Point must be equal to Point! see include/vcl/salgtype.hxx
m_pPrinterGfx->DrawPolyPolygonBezier(nPoly, pPoints, pPointArray, pFlagArray);
return true;
}
void GenPspGfxBackend::copyArea(tools::Long /*nDestX*/, tools::Long /*nDestY*/,
tools::Long /*nSrcX*/, tools::Long /*nSrcY*/,
tools::Long /*nSrcWidth*/, tools::Long /*nSrcHeight*/,
bool /*bWindowInvalidate*/)
{
OSL_FAIL("Error: PrinterGfx::CopyArea() not implemented");
}
void GenPspGfxBackend::copyBits(const SalTwoRect& /*rPosAry*/, SalGraphics* /*pSrcGraphics*/)
{
OSL_FAIL("Error: PrinterGfx::CopyBits() not implemented");
}
void GenPspGfxBackend::drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap)
{
tools::Rectangle aSrc(Point(rPosAry.mnSrcX, rPosAry.mnSrcY),
Size(rPosAry.mnSrcWidth, rPosAry.mnSrcHeight));
tools::Rectangle aDst(Point(rPosAry.mnDestX, rPosAry.mnDestY),
Size(rPosAry.mnDestWidth, rPosAry.mnDestHeight));
BitmapBuffer* pBuffer
= const_cast<SalBitmap&>(rSalBitmap).AcquireBuffer(BitmapAccessMode::Read);
SalPrinterBmp aBmp(pBuffer);
m_pPrinterGfx->DrawBitmap(aDst, aSrc, aBmp);
const_cast<SalBitmap&>(rSalBitmap).ReleaseBuffer(pBuffer, BitmapAccessMode::Read);
}
void GenPspGfxBackend::drawBitmap(const SalTwoRect& /*rPosAry*/, const SalBitmap& /*rSalBitmap*/,
const SalBitmap& /*rMaskBitmap*/)
{
OSL_FAIL("Error: no PrinterGfx::DrawBitmap() for transparent bitmap");
}
void GenPspGfxBackend::drawMask(const SalTwoRect& /*rPosAry*/, const SalBitmap& /*rSalBitmap*/,
Color /*nMaskColor*/)
{
OSL_FAIL("Error: PrinterGfx::DrawMask() not implemented");
}
std::shared_ptr<SalBitmap> GenPspGfxBackend::getBitmap(tools::Long /*nX*/, tools::Long /*nY*/,
tools::Long /*nWidth*/,
tools::Long /*nHeight*/)
{
SAL_INFO("vcl", "Warning: PrinterGfx::GetBitmap() not implemented");
return nullptr;
}
Color GenPspGfxBackend::getPixel(tools::Long /*nX*/, tools::Long /*nY*/)
{
OSL_FAIL("Warning: PrinterGfx::GetPixel() not implemented");
return Color();
}
void GenPspGfxBackend::invert(tools::Long /*nX*/, tools::Long /*nY*/, tools::Long /*nWidth*/,
tools::Long /*nHeight*/, SalInvert /*nFlags*/)
{
OSL_FAIL("Warning: PrinterGfx::Invert() not implemented");
}
void GenPspGfxBackend::invert(sal_uInt32 /*nPoints*/, const Point* /*pPtAry*/, SalInvert /*nFlags*/)
{
SAL_WARN("vcl", "Error: PrinterGfx::Invert() not implemented");
}
bool GenPspGfxBackend::drawEPS(tools::Long nX, tools::Long nY, tools::Long nWidth,
tools::Long nHeight, void* pPtr, sal_uInt32 nSize)
{
return m_pPrinterGfx->DrawEPS(tools::Rectangle(Point(nX, nY), Size(nWidth, nHeight)), pPtr,
nSize);
}
bool GenPspGfxBackend::blendBitmap(const SalTwoRect& /*rPosAry*/, const SalBitmap& /*rBitmap*/)
{
return false;
}
bool GenPspGfxBackend::blendAlphaBitmap(const SalTwoRect& /*rPosAry*/,
const SalBitmap& /*rSrcBitmap*/,
const SalBitmap& /*rMaskBitmap*/,
const SalBitmap& /*rAlphaBitmap*/)
{
return false;
}
bool GenPspGfxBackend::drawAlphaBitmap(const SalTwoRect& /*rPosAry*/,
const SalBitmap& /*rSourceBitmap*/,
const SalBitmap& /*rAlphaBitmap*/)
{
return false;
}
bool GenPspGfxBackend::drawTransformedBitmap(const basegfx::B2DPoint& /*rNull*/,
const basegfx::B2DPoint& /*rX*/,
const basegfx::B2DPoint& /*rY*/,
const SalBitmap& /*rSourceBitmap*/,
const SalBitmap* /*pAlphaBitmap*/, double /*fAlpha*/)
{
return false;
}
bool GenPspGfxBackend::hasFastDrawTransformedBitmap() const { return false; }
bool GenPspGfxBackend::drawAlphaRect(tools::Long /*nX*/, tools::Long /*nY*/, tools::Long /*nWidth*/,
tools::Long /*nHeight*/, sal_uInt8 /*nTransparency*/)
{
return false;
}
bool GenPspGfxBackend::drawGradient(const tools::PolyPolygon& /*rPolygon*/,
const Gradient& /*rGradient*/)
{
return false;
}
bool GenPspGfxBackend::implDrawGradient(basegfx::B2DPolyPolygon const& /*rPolyPolygon*/,
SalGradient const& /*rGradient*/)
{
return false;
}
bool GenPspGfxBackend::supportsOperation(OutDevSupportType /*eType*/) const { return false; }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|