bump product version to 4.1.6.2
[LibreOffice.git] / vcl / inc / coretext / salgdi2.h
blob532c5d732211cbde698703ef646fffdb17689550
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 _SV_SALGDI_H
21 #define _SV_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 "aqua/aquavcltypes.h"
31 #include "aqua/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>
40 #include "outfont.hxx"
41 #include "salgdi.hxx"
43 #include "quartz/salgdicommon.hxx"
45 class AquaSalFrame;
46 class ImplDevFontAttributes;
47 class ImplMacTextStyle;
49 struct CGRect;
51 typedef sal_uInt32 sal_GlyphId;
52 typedef std::vector<unsigned char> ByteVector;
54 #ifndef CGFLOAT_TYPE
55 typedef float CGFloat;
56 #endif
58 // mac specific physically available font face
59 class ImplMacFontData : public PhysicalFontFace
61 public:
62 ImplMacFontData( const ImplDevFontAttributes&, sal_IntPtr nFontID );
64 virtual ~ImplMacFontData();
66 virtual PhysicalFontFace* Clone() const = 0;
67 virtual ImplFontEntry* CreateFontInstance( FontSelectPattern& ) const;
68 virtual sal_IntPtr GetFontId() const;
70 virtual ImplMacTextStyle* CreateMacTextStyle( const FontSelectPattern& ) const = 0;
71 virtual int GetFontTable( const char pTagName[5], unsigned char* ) const = 0;
73 const ImplFontCharMap* GetImplFontCharMap() const;
74 bool GetImplFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const;
75 bool HasChar( sal_uInt32 cChar ) const;
77 void ReadOs2Table() const;
78 void ReadMacCmapEncoding() const;
80 protected:
81 ImplMacFontData( const ImplMacFontData&);
82 private:
83 const sal_IntPtr mnFontId;
84 mutable const ImplFontCharMap* mpCharMap;
85 mutable vcl::FontCapabilities maFontCapabilities;
86 mutable bool mbOs2Read; // true if OS2-table related info is valid
87 mutable bool mbHasOs2Table;
88 mutable bool mbCmapEncodingRead; // true if cmap encoding of Mac font is read
89 mutable bool mbFontCapabilitiesRead;
92 // --------------------
93 // - ImplMacTextStyle -
94 // --------------------
95 class ImplMacTextStyle
97 public:
98 explicit ImplMacTextStyle( const FontSelectPattern& );
99 virtual ~ImplMacTextStyle( void );
101 virtual SalLayout* GetTextLayout( void ) const = 0;
103 virtual void GetFontMetric( float fPDIY, ImplFontMetricData& ) const = 0;
104 virtual bool GetGlyphBoundRect( sal_GlyphId, Rectangle& ) const = 0;
105 virtual bool GetGlyphOutline( sal_GlyphId, basegfx::B2DPolyPolygon& ) const = 0;
107 virtual void SetTextColor( const RGBAColor& ) = 0;
109 //###protected:
110 const ImplMacFontData* mpFontData;
111 /// <1.0: font is squeezed, >1.0 font is stretched, else 1.0
112 float mfFontStretch;
113 /// text rotation in radian
114 float mfFontRotation;
117 // ------------------
118 // - SystemFontList -
119 // TODO: move into cross-platform headers
120 // ------------------
121 class SystemFontList
123 public:
124 virtual ~SystemFontList( void );
126 virtual void AnnounceFonts( ImplDevFontList& ) const = 0;
127 virtual ImplMacFontData* GetFontDataFromId( sal_IntPtr nFontId ) const = 0;
130 #ifdef MACOSX
132 // -------------------
133 // - AquaSalGraphics -
134 // -------------------
135 class AquaSalGraphics : public SalGraphics
137 friend class ATSLayout;
138 friend class CTLayout;
139 protected:
140 AquaSalFrame* mpFrame;
141 CGLayerRef mxLayer; // Quartz graphics layer
142 CGContextRef mrContext; // Quartz drawing context
143 class 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;
151 /// some graphics implementations (e.g. AquaSalInfoPrinter) scale
152 /// everything down by a factor (see SetupPrinterGraphics for details)
153 /// so we have to compensate for it with the inverse factor
154 double mfFakeDPIScale;
156 /// path representing current clip region
157 CGMutablePathRef mxClipPath;
159 /// Drawing colors
160 /// pen color RGBA
161 RGBAColor maLineColor;
162 /// brush color RGBA
163 RGBAColor maFillColor;
165 // Device Font settings
166 const ImplMacFontData* mpMacFontData;
167 ImplMacTextStyle* mpMacTextStyle;
168 RGBAColor maTextColor;
169 /// allows text to be rendered without antialiasing
170 bool mbNonAntialiasedText;
172 // Graphics types
174 /// is this a printer graphics
175 bool mbPrinter;
176 /// is this a virtual device graphics
177 bool mbVirDev;
178 /// is this a window graphics
179 bool mbWindow;
181 public:
182 AquaSalGraphics();
183 virtual ~AquaSalGraphics();
185 bool IsPenVisible() const { return maLineColor.IsVisible(); }
186 bool IsBrushVisible() const { return maFillColor.IsVisible(); }
188 void SetWindowGraphics( AquaSalFrame* pFrame );
189 void SetPrinterGraphics( CGContextRef, long nRealDPIX, long nRealDPIY, double fFakeScale );
190 void SetVirDevGraphics( CGLayerRef, CGContextRef, int nBitDepth = 0 );
192 void initResolution( NSWindow* );
193 void copyResolution( AquaSalGraphics& );
194 void updateResolution();
196 bool IsWindowGraphics() const { return mbWindow; }
197 AquaSalFrame* getGraphicsFrame() const { return mpFrame; }
198 void setGraphicsFrame( AquaSalFrame* pFrame ) { mpFrame = pFrame; }
200 void ImplDrawPixel( long nX, long nY, const RGBAColor& ); // helper to draw single pixels
202 bool CheckContext();
203 CGContextRef GetContext();
204 void UpdateWindow( NSRect& ); // delivered in NSView coordinates
205 #if !defined(__LP64__) && !defined(NS_BUILD_32_LIKE_64)
206 void RefreshRect( const CGRect& );
207 #endif
208 void RefreshRect( const NSRect& );
209 void RefreshRect(float lX, float lY, float lWidth, float lHeight);
211 void SetState();
212 void UnsetState();
213 // InvalidateContext does an UnsetState and sets mrContext to 0
214 void InvalidateContext();
216 virtual bool setClipRegion( const Region& );
218 // draw --> LineColor and FillColor and RasterOp and ClipRegion
219 virtual void drawPixel( long nX, long nY );
220 virtual void drawPixel( long nX, long nY, SalColor nSalColor );
221 virtual void drawLine( long nX1, long nY1, long nX2, long nY2 );
222 virtual void drawRect( long nX, long nY, long nWidth, long nHeight );
223 virtual void drawPolyLine( sal_uLong nPoints, const SalPoint* pPtAry );
224 virtual void drawPolygon( sal_uLong nPoints, const SalPoint* pPtAry );
225 virtual void drawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* pPoints, PCONSTSALPOINT* pPtAry );
226 virtual bool drawPolyPolygon( const ::basegfx::B2DPolyPolygon&, double fTransparency );
227 virtual sal_Bool drawPolyLineBezier( sal_uLong nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry );
228 virtual sal_Bool drawPolygonBezier( sal_uLong nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry );
229 virtual sal_Bool drawPolyPolygonBezier( sal_uInt32 nPoly, const sal_uInt32* pPoints, const SalPoint* const* pPtAry, const sal_uInt8* const* pFlgAry );
230 virtual bool drawPolyLine(
231 const ::basegfx::B2DPolygon&,
232 double fTransparency,
233 const ::basegfx::B2DVector& rLineWidths,
234 basegfx::B2DLineJoin,
235 com::sun::star::drawing::LineCap eLineCap);
237 // CopyArea --> No RasterOp, but ClipRegion
238 virtual void copyArea( long nDestX, long nDestY, long nSrcX, long nSrcY, long nSrcWidth,
239 long nSrcHeight, sal_uInt16 nFlags );
241 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
242 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
243 virtual void copyBits( const SalTwoRect* pPosAry, SalGraphics* pSrcGraphics );
244 virtual void drawBitmap( const SalTwoRect* pPosAry, const SalBitmap& rSalBitmap );
245 virtual void drawBitmap( const SalTwoRect* pPosAry,
246 const SalBitmap& rSalBitmap,
247 SalColor nTransparentColor );
248 virtual void drawBitmap( const SalTwoRect* pPosAry,
249 const SalBitmap& rSalBitmap,
250 const SalBitmap& rTransparentBitmap );
251 virtual void drawMask( const SalTwoRect* pPosAry,
252 const SalBitmap& rSalBitmap,
253 SalColor nMaskColor );
255 virtual SalBitmap* getBitmap( long nX, long nY, long nWidth, long nHeight );
256 virtual SalColor getPixel( long nX, long nY );
258 // invert --> ClipRegion (only Windows or VirDevs)
259 virtual void invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags);
260 virtual void invert( sal_uLong nPoints, const SalPoint* pPtAry, SalInvert nFlags );
262 virtual sal_Bool drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uLong nSize );
264 virtual bool drawAlphaBitmap( const SalTwoRect&,
265 const SalBitmap& rSourceBitmap,
266 const SalBitmap& rAlphaBitmap );
268 virtual bool drawAlphaRect( long nX, long nY, long nWidth,
269 long nHeight, sal_uInt8 nTransparency );
271 CGPoint* makeCGptArray(sal_uLong nPoints, const SalPoint* pPtAry);
272 // native widget rendering methods that require mirroring
273 virtual sal_Bool hitTestNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion,
274 const Point& aPos, sal_Bool& rIsInside );
275 virtual sal_Bool drawNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion,
276 ControlState nState, const ImplControlValue& aValue,
277 const OUString& aCaption );
278 virtual sal_Bool getNativeControlRegion( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, ControlState nState,
279 const ImplControlValue& aValue, const OUString& aCaption,
280 Rectangle &rNativeBoundingRegion, Rectangle &rNativeContentRegion );
282 // get device resolution
283 virtual void GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY );
284 // get the depth of the device
285 virtual sal_uInt16 GetBitCount() const;
286 // get the width of the device
287 virtual long GetGraphicsWidth() const;
289 // set the clip region to empty
290 virtual void ResetClipRegion();
292 // set the line color to transparent (= don't draw lines)
293 virtual void SetLineColor();
294 // set the line color to a specific color
295 virtual void SetLineColor( SalColor nSalColor );
296 // set the fill color to transparent (= don't fill)
297 virtual void SetFillColor();
298 // set the fill color to a specific color, shapes will be
299 // filled accordingly
300 virtual void SetFillColor( SalColor nSalColor );
301 // enable/disable XOR drawing
302 virtual void SetXORMode( bool bSet, bool bInvertOnly );
303 // set line color for raster operations
304 virtual void SetROPLineColor( SalROPColor nROPColor );
305 // set fill color for raster operations
306 virtual void SetROPFillColor( SalROPColor nROPColor );
307 // set the text color to a specific color
308 virtual void SetTextColor( SalColor nSalColor );
309 // set the font
310 virtual sal_uInt16 SetFont( FontSelectPattern*, int nFallbackLevel );
311 // get the current font's etrics
312 virtual void GetFontMetric( ImplFontMetricData*, int nFallbackLevel );
313 // get kernign pairs of the current font
314 // return only PairCount if (pKernPairs == NULL)
315 virtual sal_uLong GetKernPairs( sal_uLong nPairs, ImplKernPairData* pKernPairs );
316 // get the repertoire of the current font
317 virtual const ImplFontCharMap* GetImplFontCharMap() const;
318 virtual bool GetImplFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const;
319 // graphics must fill supplied font list
320 virtual void GetDevFontList( ImplDevFontList* );
321 // graphics must drop any cached font info
322 virtual void ClearDevFontCache();
323 // graphics should call ImplAddDevFontSubstitute on supplied
324 // OutputDevice for all its device specific preferred font substitutions
325 virtual void GetDevFontSubstList( OutputDevice* );
326 virtual bool AddTempDevFont( ImplDevFontList*, const OUString& rFileURL, const OUString& rFontName );
327 // CreateFontSubset: a method to get a subset of glyhps of a font
328 // inside a new valid font file
329 // returns TRUE if creation of subset was successful
330 // parameters: rToFile: contains a osl file URL to write the subset to
331 // pFont: describes from which font to create a subset
332 // pGlyphIDs: the glyph ids to be extracted
333 // pEncoding: the character code corresponding to each glyph
334 // pWidths: the advance widths of the correspoding glyphs (in PS font units)
335 // nGlyphs: the number of glyphs
336 // rInfo: additional outgoing information
337 // implementation note: encoding 0 with glyph id 0 should be added implicitly
338 // as "undefined character"
339 virtual sal_Bool CreateFontSubset( const OUString& rToFile,
340 const PhysicalFontFace* pFont,
341 sal_Int32* pGlyphIDs,
342 sal_uInt8* pEncoding,
343 sal_Int32* pWidths,
344 int nGlyphs,
345 FontSubsetInfo& rInfo // out parameter
348 // GetFontEncodingVector: a method to get the encoding map Unicode
349 // to font encoded character; this is only used for type1 fonts and
350 // may return NULL in case of unknown encoding vector
351 // if ppNonEncoded is set and non encoded characters (that is type1
352 // glyphs with only a name) exist it is set to the corresponding
353 // map for non encoded glyphs; the encoding vector contains -1
354 // as encoding for these cases
355 virtual const Ucs2SIntMap* GetFontEncodingVector( const PhysicalFontFace*, const Ucs2OStrMap** ppNonEncoded );
357 // GetEmbedFontData: gets the font data for a font marked
358 // embeddable by GetDevFontList or NULL in case of error
359 // parameters: pFont: describes the font in question
360 // pWidths: the widths of all glyphs from char code 0 to 255
361 // pWidths MUST support at least 256 members;
362 // rInfo: additional outgoing information
363 // pDataLen: out parameter, contains the byte length of the returned buffer
364 virtual const void* GetEmbedFontData( const PhysicalFontFace*,
365 const sal_Ucs* pUnicodes,
366 sal_Int32* pWidths,
367 FontSubsetInfo& rInfo,
368 long* pDataLen );
369 // frees the font data again
370 virtual void FreeEmbedFontData( const void* pData, long nDataLen );
372 virtual void GetGlyphWidths( const PhysicalFontFace*,
373 bool bVertical,
374 Int32Vector& rWidths,
375 Ucs2UIntMap& rUnicodeEnc );
377 virtual sal_Bool GetGlyphBoundRect( sal_GlyphId nIndex, Rectangle& );
378 virtual sal_Bool GetGlyphOutline( sal_GlyphId nIndex, basegfx::B2DPolyPolygon& );
380 virtual SalLayout* GetTextLayout( ImplLayoutArgs&, int nFallbackLevel );
381 virtual void DrawServerFontLayout( const ServerFontLayout& );
382 virtual bool supportsOperation( OutDevSupportType ) const;
384 // Query the platform layer for control support
385 virtual sal_Bool IsNativeControlSupported( ControlType nType, ControlPart nPart );
387 virtual SystemGraphicsData GetGraphicsData() const;
388 virtual SystemFontData GetSysFontData( int /* nFallbacklevel */ ) const;
390 private:
391 // differences between VCL, Quartz and kHiThemeOrientation coordinate systems
392 // make some graphics seem to be vertically-mirrored from a VCL perspective
393 bool IsFlipped() const { return mbWindow; }
395 void ApplyXorContext();
396 void Pattern50Fill();
397 UInt32 getState( ControlState nState );
398 UInt32 getTrackState( ControlState nState );
399 bool GetRawFontData( const PhysicalFontFace* pFontData,
400 std::vector<unsigned char>& rBuffer,
401 bool* pJustCFF );
404 // --- some trivial inlines
406 #if !defined(__LP64__) && !defined(NS_BUILD_32_LIKE_64)
408 inline void AquaSalGraphics::RefreshRect( const CGRect& rRect )
410 RefreshRect( rRect.origin.x, rRect.origin.y, rRect.size.width, rRect.size.height );
413 #endif
415 inline void AquaSalGraphics::RefreshRect( const NSRect& rRect )
417 RefreshRect( rRect.origin.x, rRect.origin.y, rRect.size.width, rRect.size.height );
420 #endif
422 #endif // _SV_SALGDI_H
424 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */