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