1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
25 #include "basegfx/polygon/b2dpolypolygon.hxx"
29 #include <ApplicationServices/ApplicationServices.h>
30 #include "osx/osxvcltypes.h"
31 #include "osx/salframe.h"
33 #include <CoreGraphics/CoreGraphics.h>
34 #include <CoreText/CoreText.h>
38 #include <vcl/fontcapabilities.hxx>
39 #include <vcl/metric.hxx>
41 #include "outfont.hxx"
42 #include "PhysicalFontFace.hxx"
45 #include "quartz/salgdicommon.hxx"
46 #include <unordered_map>
49 class ImplDevFontAttributes
;
52 typedef sal_uInt32 sal_GlyphId
;
53 typedef std::vector
<unsigned char> ByteVector
;
55 // CoreText-specific physically available font face
56 class CoreTextFontData
: public PhysicalFontFace
59 CoreTextFontData( const ImplDevFontAttributes
&, sal_IntPtr nFontID
);
60 virtual ~CoreTextFontData();
62 PhysicalFontFace
* Clone() const SAL_OVERRIDE
;
63 ImplFontEntry
* CreateFontInstance( FontSelectPattern
& ) const SAL_OVERRIDE
;
64 sal_IntPtr
GetFontId() const SAL_OVERRIDE
;
66 int GetFontTable( const char pTagName
[5], unsigned char* ) const;
68 const FontCharMapPtr
GetFontCharMap() const;
69 bool GetFontCapabilities(vcl::FontCapabilities
&rFontCapabilities
) const;
70 bool HasChar( sal_uInt32 cChar
) const;
72 void ReadOs2Table() const;
73 void ReadMacCmapEncoding() const;
76 CoreTextFontData( const CoreTextFontData
& );
79 const sal_IntPtr mnFontId
;
80 mutable FontCharMapPtr mpCharMap
;
81 mutable vcl::FontCapabilities maFontCapabilities
;
82 mutable bool mbOs2Read
; // true if OS2-table related info is valid
83 mutable bool mbHasOs2Table
;
84 mutable bool mbCmapEncodingRead
; // true if cmap encoding of Mac font is read
85 mutable bool mbFontCapabilitiesRead
;
91 CoreTextStyle( const FontSelectPattern
& );
92 ~CoreTextStyle( void );
94 SalLayout
* GetTextLayout( void ) const;
96 void GetFontMetric( ImplFontMetricData
& ) const;
97 bool GetGlyphBoundRect( sal_GlyphId
, Rectangle
& ) const;
98 bool GetGlyphOutline( sal_GlyphId
, basegfx::B2DPolyPolygon
& ) const;
100 const CoreTextFontData
* mpFontData
;
101 /// <1.0: font is squeezed, >1.0 font is stretched, else 1.0
103 /// text rotation in radian
104 float mfFontRotation
;
107 /// CoreText text style object
108 CFMutableDictionaryRef mpStyleDict
;
110 friend class CTLayout
;
111 CFMutableDictionaryRef
GetStyleDict( void ) const { return mpStyleDict
; }
114 // - SystemFontList -
115 // TODO: move into cross-platform headers
120 SystemFontList( void );
121 ~SystemFontList( void );
124 void AddFont( CoreTextFontData
* );
126 void AnnounceFonts( PhysicalFontCollection
& ) const;
127 CoreTextFontData
* GetFontDataFromId( sal_IntPtr nFontId
) const;
130 CTFontCollectionRef mpCTFontCollection
;
131 CFArrayRef mpCTFontArray
;
133 typedef std::unordered_map
<sal_IntPtr
,CoreTextFontData
*> CTFontContainer
;
134 CTFontContainer maFontContainer
;
137 // - AquaSalGraphics -
139 class AquaSalGraphics
: public SalGraphics
141 friend class CTLayout
;
144 AquaSalFrame
* mpFrame
;
146 CGLayerRef mxLayer
; // Quartz graphics layer
147 CGContextRef mrContext
; // Quartz drawing context
148 int mnContextStackDepth
;
149 class XorEmulation
* mpXorEmulation
;
150 int mnXorMode
; // 0: off 1: on 2: invert only
153 int mnBitmapDepth
; // zero unless bitmap
154 /// device resolution of this graphics
158 /// path representing current clip region
159 CGMutablePathRef mxClipPath
;
163 RGBAColor maLineColor
;
165 RGBAColor maFillColor
;
167 // Device Font settings
168 const CoreTextFontData
* mpFontData
;
169 CoreTextStyle
* mpTextStyle
;
170 RGBAColor maTextColor
;
171 /// allows text to be rendered without antialiasing
172 bool mbNonAntialiasedText
;
176 /// is this a printer graphics
178 /// is this a virtual device graphics
181 /// is this a window graphics
186 // mirror AquaSalVirtualDevice::mbForeignContext for SvpSalGraphics objects related to such
187 bool mbForeignContext
;
193 virtual ~AquaSalGraphics();
195 bool IsPenVisible() const { return maLineColor
.IsVisible(); }
196 bool IsBrushVisible() const { return maFillColor
.IsVisible(); }
198 void SetWindowGraphics( AquaSalFrame
* pFrame
);
199 void SetPrinterGraphics( CGContextRef
, long nRealDPIX
, long nRealDPIY
);
200 void SetVirDevGraphics( CGLayerRef
, CGContextRef
, int nBitDepth
= 0 );
202 void initResolution( NSWindow
* );
203 void copyResolution( AquaSalGraphics
& );
204 void updateResolution();
206 bool IsWindowGraphics() const { return mbWindow
; }
207 AquaSalFrame
* getGraphicsFrame() const { return mpFrame
; }
208 void setGraphicsFrame( AquaSalFrame
* pFrame
) { mpFrame
= pFrame
; }
211 void ImplDrawPixel( long nX
, long nY
, const RGBAColor
& ); // helper to draw single pixels
214 CGContextRef
GetContext();
216 void UpdateWindow( NSRect
& ); // delivered in NSView coordinates
217 void RefreshRect( const NSRect
& );
219 void RefreshRect( const CGRect
& ) {}
221 void RefreshRect(float lX
, float lY
, float lWidth
, float lHeight
);
225 // InvalidateContext does an UnsetState and sets mrContext to 0
226 void InvalidateContext();
228 virtual SalGraphicsImpl
* GetImpl() const SAL_OVERRIDE
;
230 virtual bool setClipRegion( const vcl::Region
& ) SAL_OVERRIDE
;
232 // draw --> LineColor and FillColor and RasterOp and ClipRegion
233 virtual void drawPixel( long nX
, long nY
) SAL_OVERRIDE
;
234 virtual void drawPixel( long nX
, long nY
, SalColor nSalColor
) SAL_OVERRIDE
;
235 virtual void drawLine( long nX1
, long nY1
, long nX2
, long nY2
) SAL_OVERRIDE
;
236 virtual void drawRect( long nX
, long nY
, long nWidth
, long nHeight
) SAL_OVERRIDE
;
237 virtual void drawPolyLine( sal_uInt32 nPoints
, const SalPoint
* pPtAry
) SAL_OVERRIDE
;
238 virtual void drawPolygon( sal_uInt32 nPoints
, const SalPoint
* pPtAry
) SAL_OVERRIDE
;
239 virtual void drawPolyPolygon( sal_uInt32 nPoly
, const sal_uInt32
* pPoints
, PCONSTSALPOINT
* pPtAry
) SAL_OVERRIDE
;
240 virtual bool drawPolyPolygon( const ::basegfx::B2DPolyPolygon
&, double fTransparency
) SAL_OVERRIDE
;
241 virtual bool drawPolyLineBezier( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, const sal_uInt8
* pFlgAry
) SAL_OVERRIDE
;
242 virtual bool drawPolygonBezier( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, const sal_uInt8
* pFlgAry
) SAL_OVERRIDE
;
243 virtual bool drawPolyPolygonBezier( sal_uInt32 nPoly
, const sal_uInt32
* pPoints
, const SalPoint
* const* pPtAry
, const sal_uInt8
* const* pFlgAry
) SAL_OVERRIDE
;
244 virtual bool drawPolyLine(
245 const ::basegfx::B2DPolygon
&,
246 double fTransparency
,
247 const ::basegfx::B2DVector
& rLineWidths
,
248 basegfx::B2DLineJoin
,
249 com::sun::star::drawing::LineCap eLineCap
) SAL_OVERRIDE
;
250 virtual bool drawGradient( const tools::PolyPolygon
&, const Gradient
& ) SAL_OVERRIDE
{ return false; };
252 // CopyArea --> No RasterOp, but ClipRegion
253 virtual void copyArea( long nDestX
, long nDestY
, long nSrcX
, long nSrcY
, long nSrcWidth
,
254 long nSrcHeight
, sal_uInt16 nFlags
) SAL_OVERRIDE
;
256 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
257 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
258 virtual void copyBits( const SalTwoRect
& rPosAry
, SalGraphics
* pSrcGraphics
) SAL_OVERRIDE
;
259 virtual void drawBitmap( const SalTwoRect
& rPosAry
, const SalBitmap
& rSalBitmap
) SAL_OVERRIDE
;
260 virtual void drawBitmap( const SalTwoRect
& rPosAry
,
261 const SalBitmap
& rSalBitmap
,
262 SalColor nTransparentColor
) SAL_OVERRIDE
;
263 virtual void drawBitmap( const SalTwoRect
& rPosAry
,
264 const SalBitmap
& rSalBitmap
,
265 const SalBitmap
& rTransparentBitmap
) SAL_OVERRIDE
;
266 virtual void drawMask( const SalTwoRect
& rPosAry
,
267 const SalBitmap
& rSalBitmap
,
268 SalColor nMaskColor
) SAL_OVERRIDE
;
270 virtual SalBitmap
* getBitmap( long nX
, long nY
, long nWidth
, long nHeight
) SAL_OVERRIDE
;
271 virtual SalColor
getPixel( long nX
, long nY
) SAL_OVERRIDE
;
273 // invert --> ClipRegion (only Windows or VirDevs)
274 virtual void invert( long nX
, long nY
, long nWidth
, long nHeight
, SalInvert nFlags
) SAL_OVERRIDE
;
275 virtual void invert( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, SalInvert nFlags
) SAL_OVERRIDE
;
277 virtual bool drawEPS( long nX
, long nY
, long nWidth
, long nHeight
, void* pPtr
, sal_uLong nSize
) SAL_OVERRIDE
;
279 virtual bool blendBitmap( const SalTwoRect
&,
280 const SalBitmap
& rBitmap
) SAL_OVERRIDE
;
282 virtual bool blendAlphaBitmap( const SalTwoRect
&,
283 const SalBitmap
& rSrcBitmap
,
284 const SalBitmap
& rMaskBitmap
,
285 const SalBitmap
& rAlphaBitmap
) SAL_OVERRIDE
;
287 virtual bool drawAlphaBitmap( const SalTwoRect
&,
288 const SalBitmap
& rSourceBitmap
,
289 const SalBitmap
& rAlphaBitmap
) SAL_OVERRIDE
;
291 bool drawTransformedBitmap(
292 const basegfx::B2DPoint
& rNull
,
293 const basegfx::B2DPoint
& rX
,
294 const basegfx::B2DPoint
& rY
,
295 const SalBitmap
& rSourceBitmap
,
296 const SalBitmap
* pAlphaBitmap
) SAL_OVERRIDE
;
298 virtual bool drawAlphaRect( long nX
, long nY
, long nWidth
,
299 long nHeight
, sal_uInt8 nTransparency
) SAL_OVERRIDE
;
301 // native widget rendering methods that require mirroring
303 virtual bool hitTestNativeControl( ControlType nType
, ControlPart nPart
, const Rectangle
& rControlRegion
,
304 const Point
& aPos
, bool& rIsInside
) SAL_OVERRIDE
;
305 virtual bool drawNativeControl( ControlType nType
, ControlPart nPart
, const Rectangle
& rControlRegion
,
306 ControlState nState
, const ImplControlValue
& aValue
,
307 const OUString
& aCaption
) SAL_OVERRIDE
;
308 virtual bool getNativeControlRegion( ControlType nType
, ControlPart nPart
, const Rectangle
& rControlRegion
, ControlState nState
,
309 const ImplControlValue
& aValue
, const OUString
& aCaption
,
310 Rectangle
&rNativeBoundingRegion
, Rectangle
&rNativeContentRegion
) SAL_OVERRIDE
;
313 // get device resolution
314 virtual void GetResolution( sal_Int32
& rDPIX
, sal_Int32
& rDPIY
) SAL_OVERRIDE
;
315 // get the depth of the device
316 virtual sal_uInt16
GetBitCount() const SAL_OVERRIDE
;
317 // get the width of the device
318 virtual long GetGraphicsWidth() const SAL_OVERRIDE
;
320 // set the clip region to empty
321 virtual void ResetClipRegion() SAL_OVERRIDE
;
323 // set the line color to transparent (= don't draw lines)
324 virtual void SetLineColor() SAL_OVERRIDE
;
325 // set the line color to a specific color
326 virtual void SetLineColor( SalColor nSalColor
) SAL_OVERRIDE
;
327 // set the fill color to transparent (= don't fill)
328 virtual void SetFillColor() SAL_OVERRIDE
;
329 // set the fill color to a specific color, shapes will be
330 // filled accordingly
331 virtual void SetFillColor( SalColor nSalColor
) SAL_OVERRIDE
;
332 // enable/disable XOR drawing
333 virtual void SetXORMode( bool bSet
, bool bInvertOnly
) SAL_OVERRIDE
;
334 // set line color for raster operations
335 virtual void SetROPLineColor( SalROPColor nROPColor
) SAL_OVERRIDE
;
336 // set fill color for raster operations
337 virtual void SetROPFillColor( SalROPColor nROPColor
) SAL_OVERRIDE
;
338 // set the text color to a specific color
339 virtual void SetTextColor( SalColor nSalColor
) SAL_OVERRIDE
;
341 virtual sal_uInt16
SetFont( FontSelectPattern
*, int nFallbackLevel
) SAL_OVERRIDE
;
342 // get the current font's metrics
343 virtual void GetFontMetric( ImplFontMetricData
*, int nFallbackLevel
) SAL_OVERRIDE
;
344 // get the repertoire of the current font
345 virtual const FontCharMapPtr
GetFontCharMap() const SAL_OVERRIDE
;
346 virtual bool GetFontCapabilities(vcl::FontCapabilities
&rFontCapabilities
) const SAL_OVERRIDE
;
347 // graphics must fill supplied font list
348 virtual void GetDevFontList( PhysicalFontCollection
* ) SAL_OVERRIDE
;
349 // graphics must drop any cached font info
350 virtual void ClearDevFontCache() SAL_OVERRIDE
;
351 virtual bool AddTempDevFont( PhysicalFontCollection
*, const OUString
& rFileURL
, const OUString
& rFontName
) SAL_OVERRIDE
;
352 // CreateFontSubset: a method to get a subset of glyhps of a font
353 // inside a new valid font file
354 // returns TRUE if creation of subset was successful
355 // parameters: rToFile: contains a osl file URL to write the subset to
356 // pFont: describes from which font to create a subset
357 // pGlyphIDs: the glyph ids to be extracted
358 // pEncoding: the character code corresponding to each glyph
359 // pWidths: the advance widths of the correspoding glyphs (in PS font units)
360 // nGlyphs: the number of glyphs
361 // rInfo: additional outgoing information
362 // implementation note: encoding 0 with glyph id 0 should be added implicitly
363 // as "undefined character"
364 virtual bool CreateFontSubset( const OUString
& rToFile
,
365 const PhysicalFontFace
* pFont
,
366 const sal_GlyphId
* pGlyphIds
,
367 const sal_uInt8
* pEncoding
,
370 FontSubsetInfo
& rInfo
// out parameter
373 // GetFontEncodingVector: a method to get the encoding map Unicode
374 // to font encoded character; this is only used for type1 fonts and
375 // may return NULL in case of unknown encoding vector
376 // if ppNonEncoded is set and non encoded characters (that is type1
377 // glyphs with only a name) exist it is set to the corresponding
378 // map for non encoded glyphs; the encoding vector contains -1
379 // as encoding for these cases
380 virtual const Ucs2SIntMap
* GetFontEncodingVector( const PhysicalFontFace
*, const Ucs2OStrMap
** ppNonEncoded
, std::set
<sal_Unicode
> const** ) SAL_OVERRIDE
;
382 // GetEmbedFontData: gets the font data for a font marked
383 // embeddable by GetDevFontList or NULL in case of error
384 // parameters: pFont: describes the font in question
385 // pWidths: the widths of all glyphs from char code 0 to 255
386 // pWidths MUST support at least 256 members;
387 // rInfo: additional outgoing information
388 // pDataLen: out parameter, contains the byte length of the returned buffer
389 virtual const void* GetEmbedFontData( const PhysicalFontFace
*,
390 const sal_Ucs
* pUnicodes
,
393 FontSubsetInfo
& rInfo
,
394 long* pDataLen
) SAL_OVERRIDE
;
395 // frees the font data again
396 virtual void FreeEmbedFontData( const void* pData
, long nDataLen
) SAL_OVERRIDE
;
398 virtual void GetGlyphWidths( const PhysicalFontFace
*,
400 Int32Vector
& rWidths
,
401 Ucs2UIntMap
& rUnicodeEnc
) SAL_OVERRIDE
;
403 virtual bool GetGlyphBoundRect( sal_GlyphId
, Rectangle
& ) SAL_OVERRIDE
;
404 virtual bool GetGlyphOutline( sal_GlyphId
, basegfx::B2DPolyPolygon
& ) SAL_OVERRIDE
;
406 virtual SalLayout
* GetTextLayout( ImplLayoutArgs
&, int nFallbackLevel
) SAL_OVERRIDE
;
407 virtual void DrawServerFontLayout( const ServerFontLayout
& ) SAL_OVERRIDE
;
408 virtual bool supportsOperation( OutDevSupportType
) const SAL_OVERRIDE
;
411 // Query the platform layer for control support
412 virtual bool IsNativeControlSupported( ControlType nType
, ControlPart nPart
) SAL_OVERRIDE
;
415 virtual SystemGraphicsData
416 GetGraphicsData() const SAL_OVERRIDE
;
417 virtual bool SupportsCairo() const SAL_OVERRIDE
;
418 virtual cairo::SurfaceSharedPtr
CreateSurface(const cairo::CairoSurfaceSharedPtr
& rSurface
) const SAL_OVERRIDE
;
419 virtual cairo::SurfaceSharedPtr
CreateSurface(const OutputDevice
& rRefDevice
, int x
, int y
, int width
, int height
) const SAL_OVERRIDE
;
420 virtual cairo::SurfaceSharedPtr
CreateBitmapSurface(const OutputDevice
& rRefDevice
, const BitmapSystemData
& rData
, const Size
& rSize
) const SAL_OVERRIDE
;
421 virtual css::uno::Any
GetNativeSurfaceHandle(cairo::SurfaceSharedPtr
& rSurface
, const ::basegfx::B2ISize
& rSize
) const SAL_OVERRIDE
;
422 virtual SystemFontData
GetSysFontData( int /* nFallbacklevel */ ) const SAL_OVERRIDE
;
425 // differences between VCL, Quartz and kHiThemeOrientation coordinate systems
426 // make some graphics seem to be vertically-mirrored from a VCL perspective
427 bool IsFlipped() const;
429 void ApplyXorContext();
430 void Pattern50Fill();
431 UInt32
getState( ControlState nState
);
432 UInt32
getTrackState( ControlState nState
);
433 static bool GetRawFontData( const PhysicalFontFace
* pFontData
,
434 std::vector
<unsigned char>& rBuffer
,
438 // --- some trivial inlines
442 inline void AquaSalGraphics::RefreshRect( const NSRect
& rRect
)
444 RefreshRect( rRect
.origin
.x
, rRect
.origin
.y
, rRect
.size
.width
, rRect
.size
.height
);
449 #endif // INCLUDED_VCL_INC_QUARTZ_SALGDI_H
451 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */