Line data Source code
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_HEADLESS_SVPGDI_HXX
21 : #define INCLUDED_VCL_INC_HEADLESS_SVPGDI_HXX
22 :
23 : #include <basebmp/bitmapdevice.hxx>
24 : #include <basebmp/color.hxx>
25 : #include <vcl/sysdata.hxx>
26 : #include <vcl/metric.hxx>
27 :
28 : #include "salgdi.hxx"
29 : #include "sallayout.hxx"
30 :
31 : #ifdef IOS
32 : #include "quartz/salgdi.h"
33 : #include <premac.h>
34 : #include <Foundation/Foundation.h>
35 : #include <CoreGraphics/CoreGraphics.h>
36 : #include <postmac.h>
37 : #endif
38 :
39 : class ServerFont;
40 :
41 : #ifdef IOS
42 : // To keep changes to the CoreText code shared with AOO to a minimum,
43 : // let's continue calling the SalGraphics subclass "AquaSalGraphics" even if it
44 : // is used by us also on iOS, where of course the term "Aqua" has no meaning at all.
45 : // (Note that even on OS X, using the term "Aqua" is a misunderstanding or obsolete.)
46 : #define SvpSalGraphics AquaSalGraphics
47 : #endif
48 :
49 : class SvpSalGraphics : public SalGraphics
50 : {
51 : #ifndef IOS
52 : basebmp::BitmapDeviceSharedPtr m_aDevice;
53 : basebmp::BitmapDeviceSharedPtr m_aOrigDevice;
54 :
55 : basebmp::BitmapDeviceSharedPtr m_aClipMap;
56 :
57 : bool m_bUseLineColor;
58 : basebmp::Color m_aLineColor;
59 : bool m_bUseFillColor;
60 : basebmp::Color m_aFillColor;
61 :
62 : basebmp::DrawMode m_aDrawMode;
63 :
64 : // These fields are used only when we use FreeType to draw into a
65 : // headless backend, i.e. not on iOS.
66 : basebmp::Color m_aTextColor;
67 : ServerFont* m_pServerFont[ MAX_FALLBACK ];
68 : basebmp::Format m_eTextFmt;
69 :
70 : protected:
71 : basegfx::B2IVector GetSize() { return m_aOrigDevice->getSize(); }
72 :
73 : private:
74 : bool m_bClipSetup;
75 : struct ClipUndoHandle {
76 : SvpSalGraphics &m_rGfx;
77 : basebmp::BitmapDeviceSharedPtr m_aDevice;
78 3962499 : ClipUndoHandle( SvpSalGraphics *pGfx ) : m_rGfx( *pGfx ) {}
79 : ~ClipUndoHandle();
80 : };
81 : bool isClippedSetup( const basegfx::B2IBox &aRange, ClipUndoHandle &rUndo );
82 : void ensureClip();
83 :
84 : public:
85 : void setDevice( basebmp::BitmapDeviceSharedPtr& rDevice );
86 :
87 : #else
88 : friend class CTLayout;
89 :
90 : CGLayerRef mxLayer;
91 : // mirror AquaSalVirtualDevice::mbForeignContext for SvpSalGraphics objects related to such
92 : bool mbForeignContext;
93 : CGContextRef mrContext;
94 : int mnContextStackDepth;
95 : class XorEmulation* mpXorEmulation;
96 : int mnXorMode; // 0: off 1: on 2: invert only
97 : int mnWidth;
98 : int mnHeight;
99 : int mnBitmapDepth; // zero unless bitmap
100 :
101 : /// path representing current clip region
102 : CGMutablePathRef mxClipPath;
103 :
104 : /// Drawing colors
105 : /// pen color RGBA
106 : RGBAColor maLineColor;
107 : /// brush color RGBA
108 : RGBAColor maFillColor;
109 :
110 : // Device Font settings
111 : const CoreTextFontData* mpFontData;
112 : CoreTextStyle* mpTextStyle;
113 : RGBAColor maTextColor;
114 : /// allows text to be rendered without antialiasing
115 : bool mbNonAntialiasedText;
116 :
117 : /// is this a printer graphics
118 : bool mbPrinter;
119 : /// is this a virtual device graphics
120 : bool mbVirDev;
121 : #endif
122 :
123 : protected:
124 : vcl::Region m_aClipRegion;
125 :
126 : protected:
127 : virtual bool drawAlphaBitmap( const SalTwoRect&, const SalBitmap& rSourceBitmap, const SalBitmap& rAlphaBitmap ) SAL_OVERRIDE;
128 : virtual bool drawTransformedBitmap(
129 : const basegfx::B2DPoint& rNull,
130 : const basegfx::B2DPoint& rX,
131 : const basegfx::B2DPoint& rY,
132 : const SalBitmap& rSourceBitmap,
133 : const SalBitmap* pAlphaBitmap) SAL_OVERRIDE;
134 : virtual bool drawAlphaRect( long nX, long nY, long nWidth, long nHeight, sal_uInt8 nTransparency ) SAL_OVERRIDE;
135 :
136 : public:
137 : SvpSalGraphics();
138 : virtual ~SvpSalGraphics();
139 :
140 : virtual void GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY ) SAL_OVERRIDE;
141 : virtual sal_uInt16 GetBitCount() const SAL_OVERRIDE;
142 : virtual long GetGraphicsWidth() const SAL_OVERRIDE;
143 :
144 : virtual void ResetClipRegion() SAL_OVERRIDE;
145 : virtual bool setClipRegion( const vcl::Region& ) SAL_OVERRIDE;
146 :
147 : virtual void SetLineColor() SAL_OVERRIDE;
148 : virtual void SetLineColor( SalColor nSalColor ) SAL_OVERRIDE;
149 : virtual void SetFillColor() SAL_OVERRIDE;
150 : virtual void SetFillColor( SalColor nSalColor ) SAL_OVERRIDE;
151 :
152 : virtual void SetXORMode( bool bSet, bool ) SAL_OVERRIDE;
153 :
154 : virtual void SetROPLineColor( SalROPColor nROPColor ) SAL_OVERRIDE;
155 : virtual void SetROPFillColor( SalROPColor nROPColor ) SAL_OVERRIDE;
156 :
157 : virtual void SetTextColor( SalColor nSalColor ) SAL_OVERRIDE;
158 : virtual sal_uInt16 SetFont( FontSelectPattern*, int nFallbackLevel ) SAL_OVERRIDE;
159 : virtual void GetFontMetric( ImplFontMetricData*, int nFallbackLevel ) SAL_OVERRIDE;
160 : virtual const FontCharMapPtr GetFontCharMap() const SAL_OVERRIDE;
161 : virtual bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const SAL_OVERRIDE;
162 : virtual void GetDevFontList( PhysicalFontCollection* ) SAL_OVERRIDE;
163 : virtual void ClearDevFontCache() SAL_OVERRIDE;
164 : virtual bool AddTempDevFont( PhysicalFontCollection*, const OUString& rFileURL, const OUString& rFontName ) SAL_OVERRIDE;
165 : virtual bool CreateFontSubset( const OUString& rToFile,
166 : const PhysicalFontFace*,
167 : sal_GlyphId* pGlyphIds,
168 : sal_uInt8* pEncoding,
169 : sal_Int32* pWidths,
170 : int nGlyphs,
171 : FontSubsetInfo& rInfo
172 : ) SAL_OVERRIDE;
173 : virtual const Ucs2SIntMap* GetFontEncodingVector( const PhysicalFontFace*, const Ucs2OStrMap** ppNonEncoded ) SAL_OVERRIDE;
174 : virtual const void* GetEmbedFontData( const PhysicalFontFace*,
175 : const sal_Ucs* pUnicodes,
176 : sal_Int32* pWidths,
177 : FontSubsetInfo& rInfo,
178 : long* pDataLen ) SAL_OVERRIDE;
179 : virtual void FreeEmbedFontData( const void* pData, long nDataLen ) SAL_OVERRIDE;
180 : virtual void GetGlyphWidths( const PhysicalFontFace*,
181 : bool bVertical,
182 : Int32Vector& rWidths,
183 : Ucs2UIntMap& rUnicodeEnc ) SAL_OVERRIDE;
184 : virtual bool GetGlyphBoundRect( sal_GlyphId nIndex, Rectangle& ) SAL_OVERRIDE;
185 : virtual bool GetGlyphOutline( sal_GlyphId nIndex, ::basegfx::B2DPolyPolygon& ) SAL_OVERRIDE;
186 : virtual SalLayout* GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) SAL_OVERRIDE;
187 : virtual void DrawServerFontLayout( const ServerFontLayout& ) SAL_OVERRIDE;
188 : virtual bool supportsOperation( OutDevSupportType ) const SAL_OVERRIDE;
189 : virtual void drawPixel( long nX, long nY ) SAL_OVERRIDE;
190 : virtual void drawPixel( long nX, long nY, SalColor nSalColor ) SAL_OVERRIDE;
191 : virtual void drawLine( long nX1, long nY1, long nX2, long nY2 ) SAL_OVERRIDE;
192 : virtual void drawRect( long nX, long nY, long nWidth, long nHeight ) SAL_OVERRIDE;
193 : virtual bool drawPolyPolygon( const ::basegfx::B2DPolyPolygon&, double fTransparency ) SAL_OVERRIDE;
194 : virtual bool drawPolyLine( const ::basegfx::B2DPolygon&,
195 : double fTransparency,
196 : const ::basegfx::B2DVector& rLineWidths,
197 : basegfx::B2DLineJoin,
198 : com::sun::star::drawing::LineCap) SAL_OVERRIDE;
199 : virtual void drawPolyLine( sal_uInt32 nPoints, const SalPoint* pPtAry ) SAL_OVERRIDE;
200 : virtual void drawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry ) SAL_OVERRIDE;
201 : virtual void drawPolyPolygon( sal_uInt32 nPoly,
202 : const sal_uInt32* pPoints,
203 : PCONSTSALPOINT* pPtAry ) SAL_OVERRIDE;
204 : virtual bool drawPolyLineBezier( sal_uInt32 nPoints,
205 : const SalPoint* pPtAry,
206 : const sal_uInt8* pFlgAry ) SAL_OVERRIDE;
207 : virtual bool drawPolygonBezier( sal_uInt32 nPoints,
208 : const SalPoint* pPtAry,
209 : const sal_uInt8* pFlgAry ) SAL_OVERRIDE;
210 : virtual bool drawPolyPolygonBezier( sal_uInt32 nPoly,
211 : const sal_uInt32* pPoints,
212 : const SalPoint* const* pPtAry,
213 : const sal_uInt8* const* pFlgAry ) SAL_OVERRIDE;
214 :
215 : virtual void copyArea( long nDestX,
216 : long nDestY,
217 : long nSrcX,
218 : long nSrcY,
219 : long nSrcWidth,
220 : long nSrcHeight,
221 : sal_uInt16 nFlags ) SAL_OVERRIDE;
222 : virtual void copyBits( const SalTwoRect& rPosAry,
223 : SalGraphics* pSrcGraphics ) SAL_OVERRIDE;
224 : virtual void drawBitmap( const SalTwoRect& rPosAry,
225 : const SalBitmap& rSalBitmap ) SAL_OVERRIDE;
226 : virtual void drawBitmap( const SalTwoRect& rPosAry,
227 : const SalBitmap& rSalBitmap,
228 : SalColor nTransparentColor ) SAL_OVERRIDE;
229 : virtual void drawBitmap( const SalTwoRect& rPosAry,
230 : const SalBitmap& rSalBitmap,
231 : const SalBitmap& rTransparentBitmap ) SAL_OVERRIDE;
232 : virtual void drawMask( const SalTwoRect& rPosAry,
233 : const SalBitmap& rSalBitmap,
234 : SalColor nMaskColor ) SAL_OVERRIDE;
235 : virtual SalBitmap* getBitmap( long nX, long nY, long nWidth, long nHeight ) SAL_OVERRIDE;
236 : virtual SalColor getPixel( long nX, long nY ) SAL_OVERRIDE;
237 : virtual void invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags ) SAL_OVERRIDE;
238 : virtual void invert( sal_uInt32 nPoints, const SalPoint* pPtAry, SalInvert nFlags ) SAL_OVERRIDE;
239 :
240 : virtual bool drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uLong nSize ) SAL_OVERRIDE;
241 :
242 : virtual SystemGraphicsData GetGraphicsData() const SAL_OVERRIDE;
243 : virtual SystemFontData GetSysFontData( int nFallbacklevel ) const SAL_OVERRIDE;
244 :
245 : #ifdef IOS
246 : void SetVirDevGraphics( CGLayerRef xLayer, CGContextRef xContext, int = 0 );
247 :
248 : bool CheckContext();
249 : CGContextRef GetContext();
250 : bool GetRawFontData( const PhysicalFontFace* pFontData,
251 : std::vector<unsigned char>& rBuffer,
252 : bool* pJustCFF );
253 : void RefreshRect( const CGRect& ) { };
254 : void RefreshRect(float lX, float lY, float lWidth, float lHeight);
255 : void SetState();
256 : void UnsetState();
257 : void InvalidateContext();
258 : bool IsPenVisible() const { return maLineColor.IsVisible(); }
259 : bool IsBrushVisible() const { return maFillColor.IsVisible(); }
260 : void ImplDrawPixel( long nX, long nY, const RGBAColor& ); // helper to draw single pixels
261 : CGPoint* makeCGptArray(sal_uInt32 nPoints, const SalPoint* pPtAry);
262 : bool IsFlipped() const { return false; }
263 : void ApplyXorContext();
264 : void Pattern50Fill();
265 : #endif
266 : };
267 :
268 : #endif // INCLUDED_VCL_INC_HEADLESS_SVPGDI_HXX
269 :
270 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|