1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: salgdi.h,v $
10 * $Revision: 1.45.14.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
35 #include <ApplicationServices/ApplicationServices.h>
39 #include "vcl/outfont.hxx"
40 #include "vcl/salgdi.hxx"
41 #include "aquavcltypes.h"
43 #include "basegfx/polygon/b2dpolypolygon.hxx"
49 class ImplDevFontAttributes
;
53 // mac specific physically available font face
54 class ImplMacFontData
: public ImplFontData
57 ImplMacFontData( const ImplDevFontAttributes
&, ATSUFontID
);
59 virtual ~ImplMacFontData();
61 virtual ImplFontData
* Clone() const;
62 virtual ImplFontEntry
* CreateFontInstance( ImplFontSelectData
& ) const;
63 virtual sal_IntPtr
GetFontId() const;
65 ImplFontCharMap
* GetImplFontCharMap() const;
66 bool HasChar( sal_uInt32 cChar
) const;
68 void ReadOs2Table() const;
69 void ReadMacCmapEncoding() const;
70 bool HasCJKSupport() const;
73 const ATSUFontID mnFontId
;
74 mutable ImplFontCharMap
* mpCharMap
;
75 mutable bool mbOs2Read
; // true if OS2-table related info is valid
76 mutable bool mbHasOs2Table
;
77 mutable bool mbCmapEncodingRead
; // true if cmap encoding of Mac font is read
78 mutable bool mbHasCJKSupport
; // #i78970# CJK fonts need extra leading
81 // abstracting quartz color instead of having to use an CGFloat[] array
85 RGBAColor( SalColor
);
86 RGBAColor( float fRed
, float fGreen
, float fBlue
, float fAlpha
); //NOTUSEDYET
87 const float* AsArray() const { return &mfRed
; }
88 bool IsVisible() const { return (mfAlpha
> 0); }
89 void SetAlpha( float fAlpha
) { mfAlpha
= fAlpha
; }
91 float mfRed
, mfGreen
, mfBlue
, mfAlpha
;
94 // -------------------
95 // - AquaSalGraphics -
96 // -------------------
97 class AquaSalGraphics
: public SalGraphics
99 friend class ATSLayout
;
101 AquaSalFrame
* mpFrame
;
102 CGLayerRef mxLayer
; // Quartz graphics layer
103 CGContextRef mrContext
; // Quartz drawing context
104 class XorEmulation
* mpXorEmulation
;
105 int mnXorMode
; // 0: off 1: on 2: invert only
108 int mnBitmapDepth
; // zero unless bitmap
109 /// device resolution of this graphics
112 /// some graphics implementations (e.g. AquaSalInfoPrinter) scale
113 /// everything down by a factor (see SetupPrinterGraphics for details)
114 /// so we have to compensate for it with the inverse factor
115 double mfFakeDPIScale
;
117 /// path representing current clip region
118 CGMutablePathRef mxClipPath
;
122 RGBAColor maLineColor
;
124 RGBAColor maFillColor
;
126 // Device Font settings
127 const ImplMacFontData
* mpMacFontData
;
128 /// ATSU style object which carries all font attributes
129 ATSUStyle maATSUStyle
;
130 /// text rotation as ATSU angle
131 Fixed mnATSUIRotation
;
132 /// workaround to prevent ATSU overflows for huge font sizes
134 /// <1.0: font is squeezed, >1.0 font is stretched, else 1.0
136 /// allows text to be rendered without antialiasing
137 bool mbNonAntialiasedText
;
141 /// is this a printer graphics
143 /// is this a virtual device graphics
145 /// is this a window graphics
150 virtual ~AquaSalGraphics();
152 bool IsPenVisible() const { return maLineColor
.IsVisible(); }
153 bool IsBrushVisible() const { return maFillColor
.IsVisible(); }
155 void SetWindowGraphics( AquaSalFrame
* pFrame
);
156 void SetPrinterGraphics( CGContextRef
, long nRealDPIX
, long nRealDPIY
, double fFakeScale
);
157 void SetVirDevGraphics( CGLayerRef
, CGContextRef
, int nBitDepth
= 0 );
159 void initResolution( NSWindow
* );
160 void copyResolution( AquaSalGraphics
& );
161 void updateResolution();
163 bool IsWindowGraphics() const { return mbWindow
; }
164 bool IsPrinterGraphics() const { return mbPrinter
; }
165 bool IsVirDevGraphics() const { return mbVirDev
; }
166 AquaSalFrame
* getGraphicsFrame() const { return mpFrame
; }
167 void setGraphicsFrame( AquaSalFrame
* pFrame
) { mpFrame
= pFrame
; }
169 void ImplDrawPixel( long nX
, long nY
, const RGBAColor
& ); // helper to draw single pixels
172 void UpdateWindow( NSRect
& ); // delivered in NSView coordinates
173 void RefreshRect( const CGRect
& );
174 void RefreshRect( const NSRect
& );
175 void RefreshRect(float lX
, float lY
, float lWidth
, float lHeight
);
179 virtual BOOL
unionClipRegion( long nX
, long nY
, long nWidth
, long nHeight
);
180 virtual bool unionClipRegion( const ::basegfx::B2DPolyPolygon
& );
182 // draw --> LineColor and FillColor and RasterOp and ClipRegion
183 virtual void drawPixel( long nX
, long nY
);
184 virtual void drawPixel( long nX
, long nY
, SalColor nSalColor
);
185 virtual void drawLine( long nX1
, long nY1
, long nX2
, long nY2
);
186 virtual void drawRect( long nX
, long nY
, long nWidth
, long nHeight
);
187 virtual void drawPolyLine( ULONG nPoints
, const SalPoint
* pPtAry
);
188 virtual void drawPolygon( ULONG nPoints
, const SalPoint
* pPtAry
);
189 virtual void drawPolyPolygon( ULONG nPoly
, const ULONG
* pPoints
, PCONSTSALPOINT
* pPtAry
);
190 virtual bool drawPolyPolygon( const ::basegfx::B2DPolyPolygon
&, double fTransparency
);
191 virtual sal_Bool
drawPolyLineBezier( ULONG nPoints
, const SalPoint
* pPtAry
, const BYTE
* pFlgAry
);
192 virtual sal_Bool
drawPolygonBezier( ULONG nPoints
, const SalPoint
* pPtAry
, const BYTE
* pFlgAry
);
193 virtual sal_Bool
drawPolyPolygonBezier( ULONG nPoly
, const ULONG
* pPoints
, const SalPoint
* const* pPtAry
, const BYTE
* const* pFlgAry
);
194 virtual bool drawPolyLine( const ::basegfx::B2DPolygon
&, const ::basegfx::B2DVector
& rLineWidths
, basegfx::B2DLineJoin
);
196 // CopyArea --> No RasterOp, but ClipRegion
197 virtual void copyArea( long nDestX
, long nDestY
, long nSrcX
, long nSrcY
, long nSrcWidth
,
198 long nSrcHeight
, USHORT nFlags
);
200 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
201 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
202 virtual void copyBits( const SalTwoRect
* pPosAry
, SalGraphics
* pSrcGraphics
);
203 virtual void drawBitmap( const SalTwoRect
* pPosAry
, const SalBitmap
& rSalBitmap
);
204 virtual void drawBitmap( const SalTwoRect
* pPosAry
,
205 const SalBitmap
& rSalBitmap
,
206 SalColor nTransparentColor
);
207 virtual void drawBitmap( const SalTwoRect
* pPosAry
,
208 const SalBitmap
& rSalBitmap
,
209 const SalBitmap
& rTransparentBitmap
);
210 virtual void drawMask( const SalTwoRect
* pPosAry
,
211 const SalBitmap
& rSalBitmap
,
212 SalColor nMaskColor
);
214 virtual SalBitmap
* getBitmap( long nX
, long nY
, long nWidth
, long nHeight
);
215 virtual SalColor
getPixel( long nX
, long nY
);
217 // invert --> ClipRegion (only Windows or VirDevs)
218 virtual void invert( long nX
, long nY
, long nWidth
, long nHeight
, SalInvert nFlags
);
219 virtual void invert( ULONG nPoints
, const SalPoint
* pPtAry
, SalInvert nFlags
);
221 virtual BOOL
drawEPS( long nX
, long nY
, long nWidth
, long nHeight
, void* pPtr
, ULONG nSize
);
223 virtual bool drawAlphaBitmap( const SalTwoRect
&,
224 const SalBitmap
& rSourceBitmap
,
225 const SalBitmap
& rAlphaBitmap
);
227 virtual bool drawAlphaRect( long nX
, long nY
, long nWidth
,
228 long nHeight
, sal_uInt8 nTransparency
);
230 CGPoint
* makeCGptArray(ULONG nPoints
, const SalPoint
* pPtAry
);
231 // native widget rendering methods that require mirroring
232 virtual BOOL
hitTestNativeControl( ControlType nType
, ControlPart nPart
, const Region
& rControlRegion
,
233 const Point
& aPos
, SalControlHandle
& rControlHandle
, BOOL
& rIsInside
);
234 virtual BOOL
drawNativeControl( ControlType nType
, ControlPart nPart
, const Region
& rControlRegion
,
235 ControlState nState
, const ImplControlValue
& aValue
, SalControlHandle
& rControlHandle
,
236 const rtl::OUString
& aCaption
);
237 virtual BOOL
drawNativeControlText( ControlType nType
, ControlPart nPart
, const Region
& rControlRegion
,
238 ControlState nState
, const ImplControlValue
& aValue
,
239 SalControlHandle
& rControlHandle
, const rtl::OUString
& aCaption
);
240 virtual BOOL
getNativeControlRegion( ControlType nType
, ControlPart nPart
, const Region
& rControlRegion
, ControlState nState
,
241 const ImplControlValue
& aValue
, SalControlHandle
& rControlHandle
, const rtl::OUString
& aCaption
,
242 Region
&rNativeBoundingRegion
, Region
&rNativeContentRegion
);
244 // get device resolution
245 virtual void GetResolution( long& rDPIX
, long& rDPIY
);
246 // get the depth of the device
247 virtual USHORT
GetBitCount();
248 // get the width of the device
249 virtual long GetGraphicsWidth() const;
251 // set the clip region to empty
252 virtual void ResetClipRegion();
253 // begin setting the clip region, add rectangles to the
254 // region with the UnionClipRegion call
255 virtual void BeginSetClipRegion( ULONG nCount
);
256 // all rectangles were added and the clip region should be set now
257 virtual void EndSetClipRegion();
259 // set the line color to transparent (= don't draw lines)
260 virtual void SetLineColor();
261 // set the line color to a specific color
262 virtual void SetLineColor( SalColor nSalColor
);
263 // set the fill color to transparent (= don't fill)
264 virtual void SetFillColor();
265 // set the fill color to a specific color, shapes will be
266 // filled accordingly
267 virtual void SetFillColor( SalColor nSalColor
);
268 // enable/disable XOR drawing
269 virtual void SetXORMode( bool bSet
, bool bInvertOnly
);
270 // set line color for raster operations
271 virtual void SetROPLineColor( SalROPColor nROPColor
);
272 // set fill color for raster operations
273 virtual void SetROPFillColor( SalROPColor nROPColor
);
274 // set the text color to a specific color
275 virtual void SetTextColor( SalColor nSalColor
);
277 virtual USHORT
SetFont( ImplFontSelectData
*, int nFallbackLevel
);
278 // get the current font's etrics
279 virtual void GetFontMetric( ImplFontMetricData
* );
280 // get kernign pairs of the current font
281 // return only PairCount if (pKernPairs == NULL)
282 virtual ULONG
GetKernPairs( ULONG nPairs
, ImplKernPairData
* pKernPairs
);
283 // get the repertoire of the current font
284 virtual ImplFontCharMap
* GetImplFontCharMap() const;
285 // graphics must fill supplied font list
286 virtual void GetDevFontList( ImplDevFontList
* );
287 // graphics should call ImplAddDevFontSubstitute on supplied
288 // OutputDevice for all its device specific preferred font substitutions
289 virtual void GetDevFontSubstList( OutputDevice
* );
290 virtual bool AddTempDevFont( ImplDevFontList
*, const String
& rFileURL
, const String
& rFontName
);
291 // CreateFontSubset: a method to get a subset of glyhps of a font
292 // inside a new valid font file
293 // returns TRUE if creation of subset was successfull
294 // parameters: rToFile: contains a osl file URL to write the subset to
295 // pFont: describes from which font to create a subset
296 // pGlyphIDs: the glyph ids to be extracted
297 // pEncoding: the character code corresponding to each glyph
298 // pWidths: the advance widths of the correspoding glyphs (in PS font units)
299 // nGlyphs: the number of glyphs
300 // rInfo: additional outgoing information
301 // implementation note: encoding 0 with glyph id 0 should be added implicitly
302 // as "undefined character"
303 virtual BOOL
CreateFontSubset( const rtl::OUString
& rToFile
,
304 const ImplFontData
* pFont
,
306 sal_uInt8
* pEncoding
,
309 FontSubsetInfo
& rInfo
// out parameter
312 // GetFontEncodingVector: a method to get the encoding map Unicode
313 // to font encoded character; this is only used for type1 fonts and
314 // may return NULL in case of unknown encoding vector
315 // if ppNonEncoded is set and non encoded characters (that is type1
316 // glyphs with only a name) exist it is set to the corresponding
317 // map for non encoded glyphs; the encoding vector contains -1
318 // as encoding for these cases
319 virtual const Ucs2SIntMap
* GetFontEncodingVector( const ImplFontData
*, const Ucs2OStrMap
** ppNonEncoded
);
321 // GetEmbedFontData: gets the font data for a font marked
322 // embeddable by GetDevFontList or NULL in case of error
323 // parameters: pFont: describes the font in question
324 // pWidths: the widths of all glyphs from char code 0 to 255
325 // pWidths MUST support at least 256 members;
326 // rInfo: additional outgoing information
327 // pDataLen: out parameter, contains the byte length of the returned buffer
328 virtual const void* GetEmbedFontData( const ImplFontData
*,
329 const sal_Ucs
* pUnicodes
,
331 FontSubsetInfo
& rInfo
,
333 // frees the font data again
334 virtual void FreeEmbedFontData( const void* pData
, long nDataLen
);
336 virtual void GetGlyphWidths( const ImplFontData
*,
338 Int32Vector
& rWidths
,
339 Ucs2UIntMap
& rUnicodeEnc
);
341 virtual BOOL
GetGlyphBoundRect( long nIndex
, Rectangle
& );
342 virtual BOOL
GetGlyphOutline( long nIndex
, basegfx::B2DPolyPolygon
& );
344 virtual SalLayout
* GetTextLayout( ImplLayoutArgs
&, int nFallbackLevel
);
345 virtual void DrawServerFontLayout( const ServerFontLayout
& );
346 virtual bool supportsOperation( OutDevSupportType
) const;
348 // Query the platform layer for control support
349 virtual BOOL
IsNativeControlSupported( ControlType nType
, ControlPart nPart
);
351 virtual SystemGraphicsData
GetGraphicsData() const;
352 virtual SystemFontData
GetSysFontData( int /* nFallbacklevel */ ) const;
355 // differences between VCL, Quartz and kHiThemeOrientation coordinate systems
356 // make some graphics seem to be vertically-mirrored from a VCL perspective
357 bool IsFlipped() const { return mbWindow
; }
359 void ApplyXorContext();
360 void Pattern50Fill();
367 /*final*/ ~XorEmulation();
369 void SetTarget( int nWidth
, int nHeight
, int nBitmapDepth
, CGContextRef
, CGLayerRef
);
371 void Enable() { mbIsEnabled
= true; }
372 void Disable() { mbIsEnabled
= false; }
373 bool IsEnabled() const { return mbIsEnabled
; }
374 CGContextRef
GetTargetContext() const { return mxTargetContext
; }
375 CGContextRef
GetMaskContext() const { return (mbIsEnabled
? mxMaskContext
: NULL
); }
378 CGLayerRef mxTargetLayer
;
379 CGContextRef mxTargetContext
;
380 CGContextRef mxMaskContext
;
381 CGContextRef mxTempContext
;
389 // --- some trivial inlines
391 inline void AquaSalGraphics::RefreshRect( const CGRect
& rRect
)
393 RefreshRect( rRect
.origin
.x
, rRect
.origin
.y
, rRect
.size
.width
, rRect
.size
.height
);
396 inline void AquaSalGraphics::RefreshRect( const NSRect
& rRect
)
398 RefreshRect( rRect
.origin
.x
, rRect
.origin
.y
, rRect
.size
.width
, rRect
.size
.height
);
401 inline RGBAColor::RGBAColor( SalColor nSalColor
)
402 : mfRed( SALCOLOR_RED(nSalColor
) * (1.0/255))
403 , mfGreen( SALCOLOR_GREEN(nSalColor
) * (1.0/255))
404 , mfBlue( SALCOLOR_BLUE(nSalColor
) * (1.0/255))
405 , mfAlpha( 1.0 ) // opaque
408 inline RGBAColor::RGBAColor( float fRed
, float fGreen
, float fBlue
, float fAlpha
)
415 #endif // _SV_SALGDI_H