Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / vcl / inc / quartz / salgdi.h
blob6d29fccb1d6ac3ecbd151496dcd626b625eed0b1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 INCLUDED_VCL_INC_QUARTZ_SALGDI_H
21 #define INCLUDED_VCL_INC_QUARTZ_SALGDI_H
23 #include <vector>
25 #include "basegfx/polygon/b2dpolypolygon.hxx"
27 #include "premac.h"
28 #ifdef MACOSX
29 #include <ApplicationServices/ApplicationServices.h>
30 #include "osx/osxvcltypes.h"
31 #include "osx/salframe.h"
32 #else
33 #include <CoreGraphics/CoreGraphics.h>
34 #include <CoreText/CoreText.h>
35 #endif
36 #include "postmac.h"
38 #include <vcl/fontcapabilities.hxx>
39 #include <vcl/metric.hxx>
41 #include "fontinstance.hxx"
42 #include "impfontmetricdata.hxx"
43 #include "PhysicalFontFace.hxx"
44 #include "salgdi.hxx"
46 #include "quartz/salgdicommon.hxx"
47 #include <unordered_map>
48 #include <hb-ot.h>
50 class AquaSalFrame;
51 class FontAttributes;
52 class CoreTextStyle;
53 class XorEmulation;
54 class CommonSalLayout;
56 typedef sal_uInt32 sal_GlyphId;
58 // CoreText-specific physically available font face
59 class CoreTextFontFace : public PhysicalFontFace
61 public:
62 CoreTextFontFace( const FontAttributes&, sal_IntPtr nFontID );
63 virtual ~CoreTextFontFace() override;
65 PhysicalFontFace* Clone() const override;
66 LogicalFontInstance* CreateFontInstance( FontSelectPattern& ) const override;
67 sal_IntPtr GetFontId() const override;
69 int GetFontTable( const char pTagName[5], unsigned char* ) const;
71 const FontCharMapRef GetFontCharMap() const;
72 bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const;
73 bool HasChar( sal_uInt32 cChar ) const;
75 protected:
76 CoreTextFontFace( const CoreTextFontFace& );
78 private:
79 const sal_IntPtr mnFontId;
80 mutable FontCharMapRef mxCharMap;
81 mutable vcl::FontCapabilities maFontCapabilities;
82 mutable bool mbFontCapabilitiesRead;
85 class CoreTextStyle
87 public:
88 CoreTextStyle( const FontSelectPattern& );
89 ~CoreTextStyle( void );
91 void GetFontMetric( ImplFontMetricDataRef& ) const;
92 bool GetGlyphBoundRect(const GlyphItem&, tools::Rectangle&) const;
93 bool GetGlyphOutline(const GlyphItem&, basegfx::B2DPolyPolygon&) const;
94 hb_font_t* GetHbFont() const { return mpHbFont; }
95 void SetHbFont(hb_font_t* pHbFont) const { mpHbFont = pHbFont; }
97 CFMutableDictionaryRef GetStyleDict( void ) const { return mpStyleDict; }
99 const CoreTextFontFace* mpFontData;
100 /// <1.0: font is squeezed, >1.0 font is stretched, else 1.0
101 float mfFontStretch;
102 /// text rotation in radian
103 float mfFontRotation;
104 FontSelectPattern maFontSelData;
106 private:
107 /// CoreText text style object
108 CFMutableDictionaryRef mpStyleDict;
109 mutable hb_font_t* mpHbFont;
112 // TODO: move into cross-platform headers
114 class SystemFontList
116 public:
117 SystemFontList( void );
118 ~SystemFontList( void );
120 bool Init( void );
121 void AddFont( CoreTextFontFace* );
123 void AnnounceFonts( PhysicalFontCollection& ) const;
124 CoreTextFontFace* GetFontDataFromId( sal_IntPtr nFontId ) const;
126 private:
127 CTFontCollectionRef mpCTFontCollection;
128 CFArrayRef mpCTFontArray;
130 typedef std::unordered_map<sal_IntPtr,CoreTextFontFace*> CTFontContainer;
131 CTFontContainer maFontContainer;
135 class AquaSalGraphics : public SalGraphics
137 CGLayerRef mxLayer; // Quartz graphics layer
138 CGContextRef mrContext; // Quartz drawing context
139 #ifdef MACOSX
140 AquaSalFrame* mpFrame;
141 #endif
142 int mnContextStackDepth;
143 XorEmulation* mpXorEmulation;
144 int mnXorMode; // 0: off 1: on 2: invert only
145 int mnWidth;
146 int mnHeight;
147 int mnBitmapDepth; // zero unless bitmap
148 /// device resolution of this graphics
149 long mnRealDPIX;
150 long mnRealDPIY;
152 /// path representing current clip region
153 CGMutablePathRef mxClipPath;
155 /// Drawing colors
156 /// pen color RGBA
157 RGBAColor maLineColor;
158 /// brush color RGBA
159 RGBAColor maFillColor;
161 // Device Font settings
162 const CoreTextFontFace* mpFontData[MAX_FALLBACK];
163 CoreTextStyle* mpTextStyle[MAX_FALLBACK];
164 RGBAColor maTextColor;
165 /// allows text to be rendered without antialiasing
166 bool mbNonAntialiasedText;
168 // Graphics types
170 /// is this a printer graphics
171 bool mbPrinter;
172 /// is this a virtual device graphics
173 bool mbVirDev;
174 #ifdef MACOSX
175 /// is this a window graphics
176 bool mbWindow;
178 #else // IOS
180 // mirror AquaSalVirtualDevice::mbForeignContext for SvpSalGraphics objects related to such
181 bool mbForeignContext;
183 #endif
185 public:
186 AquaSalGraphics();
187 virtual ~AquaSalGraphics() override;
189 bool IsPenVisible() const { return maLineColor.IsVisible(); }
190 bool IsBrushVisible() const { return maFillColor.IsVisible(); }
192 void SetWindowGraphics( AquaSalFrame* pFrame );
193 void SetPrinterGraphics( CGContextRef, long nRealDPIX, long nRealDPIY );
194 void SetVirDevGraphics( CGLayerRef, CGContextRef, int nBitDepth = 0 );
195 #ifdef MACOSX
196 void initResolution( NSWindow* );
197 void copyResolution( AquaSalGraphics& );
198 void updateResolution();
200 bool IsWindowGraphics() const { return mbWindow; }
201 AquaSalFrame* getGraphicsFrame() const { return mpFrame; }
202 void setGraphicsFrame( AquaSalFrame* pFrame ) { mpFrame = pFrame; }
203 #endif
205 void ImplDrawPixel( long nX, long nY, const RGBAColor& ); // helper to draw single pixels
207 bool CheckContext();
208 CGContextRef GetContext();
209 #ifdef MACOSX
210 void UpdateWindow( NSRect& ); // delivered in NSView coordinates
211 void RefreshRect( const NSRect& );
212 #else
213 void RefreshRect( const CGRect& ) {}
214 #endif
215 void RefreshRect(float lX, float lY, float lWidth, float lHeight);
217 void SetState();
218 void UnsetState();
219 // InvalidateContext does an UnsetState and sets mrContext to 0
220 void InvalidateContext();
222 virtual SalGraphicsImpl* GetImpl() const override;
224 virtual bool setClipRegion( const vcl::Region& ) override;
226 // draw --> LineColor and FillColor and RasterOp and ClipRegion
227 virtual void drawPixel( long nX, long nY ) override;
228 virtual void drawPixel( long nX, long nY, SalColor nSalColor ) override;
229 virtual void drawLine( long nX1, long nY1, long nX2, long nY2 ) override;
230 virtual void drawRect( long nX, long nY, long nWidth, long nHeight ) override;
231 virtual void drawPolyLine( sal_uInt32 nPoints, const SalPoint* pPtAry ) override;
232 virtual void drawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry ) override;
233 virtual void drawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* pPoints, PCONSTSALPOINT* pPtAry ) override;
234 virtual bool drawPolyPolygon( const basegfx::B2DPolyPolygon&, double fTransparency ) override;
235 virtual bool drawPolyLineBezier( sal_uInt32 nPoints, const SalPoint* pPtAry, const PolyFlags* pFlgAry ) override;
236 virtual bool drawPolygonBezier( sal_uInt32 nPoints, const SalPoint* pPtAry, const PolyFlags* pFlgAry ) override;
237 virtual bool drawPolyPolygonBezier( sal_uInt32 nPoly, const sal_uInt32* pPoints, const SalPoint* const* pPtAry, const PolyFlags* const* pFlgAry ) override;
238 virtual bool drawPolyLine(
239 const basegfx::B2DPolygon&,
240 double fTransparency,
241 const basegfx::B2DVector& rLineWidths,
242 basegfx::B2DLineJoin,
243 css::drawing::LineCap eLineCap,
244 double fMiterMinimumAngle) override;
245 virtual bool drawGradient( const tools::PolyPolygon&, const Gradient& ) override { return false; };
247 // CopyArea --> No RasterOp, but ClipRegion
248 virtual void copyArea( long nDestX, long nDestY, long nSrcX, long nSrcY, long nSrcWidth,
249 long nSrcHeight, bool bWindowInvalidate ) override;
251 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
252 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
253 virtual void copyBits( const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics ) override;
254 virtual void drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap ) override;
255 virtual void drawBitmap( const SalTwoRect& rPosAry,
256 const SalBitmap& rSalBitmap,
257 const SalBitmap& rTransparentBitmap ) override;
258 virtual void drawMask( const SalTwoRect& rPosAry,
259 const SalBitmap& rSalBitmap,
260 SalColor nMaskColor ) override;
262 virtual SalBitmap* getBitmap( long nX, long nY, long nWidth, long nHeight ) override;
263 virtual SalColor getPixel( long nX, long nY ) override;
265 // invert --> ClipRegion (only Windows or VirDevs)
266 virtual void invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags) override;
267 virtual void invert( sal_uInt32 nPoints, const SalPoint* pPtAry, SalInvert nFlags ) override;
269 virtual bool drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uLong nSize ) override;
271 virtual bool blendBitmap( const SalTwoRect&,
272 const SalBitmap& rBitmap ) override;
274 virtual bool blendAlphaBitmap( const SalTwoRect&,
275 const SalBitmap& rSrcBitmap,
276 const SalBitmap& rMaskBitmap,
277 const SalBitmap& rAlphaBitmap ) override;
279 virtual bool drawAlphaBitmap( const SalTwoRect&,
280 const SalBitmap& rSourceBitmap,
281 const SalBitmap& rAlphaBitmap ) override;
283 bool drawTransformedBitmap(
284 const basegfx::B2DPoint& rNull,
285 const basegfx::B2DPoint& rX,
286 const basegfx::B2DPoint& rY,
287 const SalBitmap& rSourceBitmap,
288 const SalBitmap* pAlphaBitmap) override;
290 virtual bool drawAlphaRect( long nX, long nY, long nWidth,
291 long nHeight, sal_uInt8 nTransparency ) override;
293 // native widget rendering methods that require mirroring
294 #ifdef MACOSX
295 virtual bool hitTestNativeControl( ControlType nType, ControlPart nPart, const tools::Rectangle& rControlRegion,
296 const Point& aPos, bool& rIsInside ) override;
297 virtual bool drawNativeControl( ControlType nType, ControlPart nPart, const tools::Rectangle& rControlRegion,
298 ControlState nState, const ImplControlValue& aValue,
299 const OUString& aCaption ) override;
300 virtual bool getNativeControlRegion( ControlType nType, ControlPart nPart, const tools::Rectangle& rControlRegion, ControlState nState,
301 const ImplControlValue& aValue, const OUString& aCaption,
302 tools::Rectangle &rNativeBoundingRegion, tools::Rectangle &rNativeContentRegion ) override;
303 #endif
305 // get device resolution
306 virtual void GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY ) override;
307 // get the depth of the device
308 virtual sal_uInt16 GetBitCount() const override;
309 // get the width of the device
310 virtual long GetGraphicsWidth() const override;
312 // set the clip region to empty
313 virtual void ResetClipRegion() override;
315 // set the line color to transparent (= don't draw lines)
316 virtual void SetLineColor() override;
317 // set the line color to a specific color
318 virtual void SetLineColor( SalColor nSalColor ) override;
319 // set the fill color to transparent (= don't fill)
320 virtual void SetFillColor() override;
321 // set the fill color to a specific color, shapes will be
322 // filled accordingly
323 virtual void SetFillColor( SalColor nSalColor ) override;
324 // enable/disable XOR drawing
325 virtual void SetXORMode( bool bSet ) override;
326 // set line color for raster operations
327 virtual void SetROPLineColor( SalROPColor nROPColor ) override;
328 // set fill color for raster operations
329 virtual void SetROPFillColor( SalROPColor nROPColor ) override;
330 // set the text color to a specific color
331 virtual void SetTextColor( SalColor nSalColor ) override;
332 // set the font
333 virtual void SetFont( FontSelectPattern*, int nFallbackLevel ) override;
334 // get the current font's metrics
335 virtual void GetFontMetric( ImplFontMetricDataRef&, int nFallbackLevel ) override;
336 // get the repertoire of the current font
337 virtual const FontCharMapRef GetFontCharMap() const override;
338 virtual bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const override;
339 // graphics must fill supplied font list
340 virtual void GetDevFontList( PhysicalFontCollection* ) override;
341 // graphics must drop any cached font info
342 virtual void ClearDevFontCache() override;
343 virtual bool AddTempDevFont( PhysicalFontCollection*, const OUString& rFileURL, const OUString& rFontName ) override;
344 // CreateFontSubset: a method to get a subset of glyhps of a font
345 // inside a new valid font file
346 // returns TRUE if creation of subset was successful
347 // parameters: rToFile: contains a osl file URL to write the subset to
348 // pFont: describes from which font to create a subset
349 // pGlyphIDs: the glyph ids to be extracted
350 // pEncoding: the character code corresponding to each glyph
351 // pWidths: the advance widths of the corresponding glyphs (in PS font units)
352 // nGlyphs: the number of glyphs
353 // rInfo: additional outgoing information
354 // implementation note: encoding 0 with glyph id 0 should be added implicitly
355 // as "undefined character"
356 virtual bool CreateFontSubset( const OUString& rToFile,
357 const PhysicalFontFace* pFont,
358 const sal_GlyphId* pGlyphIds,
359 const sal_uInt8* pEncoding,
360 sal_Int32* pWidths,
361 int nGlyphs,
362 FontSubsetInfo& rInfo // out parameter
363 ) override;
365 // GetEmbedFontData: gets the font data for a font marked
366 // embeddable by GetDevFontList or NULL in case of error
367 // parameters: pFont: describes the font in question
368 // pDataLen: out parameter, contains the byte length of the returned buffer
369 virtual const void* GetEmbedFontData(const PhysicalFontFace*, long* pDataLen) override;
370 // frees the font data again
371 virtual void FreeEmbedFontData( const void* pData, long nDataLen ) override;
373 virtual void GetGlyphWidths( const PhysicalFontFace*,
374 bool bVertical,
375 std::vector< sal_Int32 >& rWidths,
376 Ucs2UIntMap& rUnicodeEnc ) override;
378 virtual bool GetGlyphBoundRect(const GlyphItem&, tools::Rectangle&) override;
379 virtual bool GetGlyphOutline(const GlyphItem&, basegfx::B2DPolyPolygon&) override;
381 virtual SalLayout* GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) override;
382 virtual void DrawTextLayout( const CommonSalLayout& ) override;
383 virtual bool supportsOperation( OutDevSupportType ) const override;
385 #ifdef MACOSX
386 // Query the platform layer for control support
387 virtual bool IsNativeControlSupported( ControlType nType, ControlPart nPart ) override;
388 #endif
390 virtual SystemGraphicsData
391 GetGraphicsData() const override;
393 private:
394 // differences between VCL, Quartz and kHiThemeOrientation coordinate systems
395 // make some graphics seem to be vertically-mirrored from a VCL perspective
396 bool IsFlipped() const;
398 void ApplyXorContext();
399 void Pattern50Fill();
400 UInt32 getState( ControlState nState );
401 UInt32 getTrackState( ControlState nState );
402 static bool GetRawFontData( const PhysicalFontFace* pFontData,
403 std::vector<unsigned char>& rBuffer,
404 bool* pJustCFF );
407 // --- some trivial inlines
409 #ifdef MACOSX
411 inline void AquaSalGraphics::RefreshRect( const NSRect& rRect )
413 RefreshRect( rRect.origin.x, rRect.origin.y, rRect.size.width, rRect.size.height );
416 #endif
418 #endif // INCLUDED_VCL_INC_QUARTZ_SALGDI_H
420 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */