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