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 void RefreshRect( const NSRect& ); 178 void RefreshRect(float lX, float lY, float lWidth, float lHeight); 179 180 void SetState(); 181 void UnsetState(); 182 // InvalidateContext does an UnsetState and sets mrContext to 0 183 void InvalidateContext(); 184 185 virtual bool setClipRegion( const Region& ); 186 187 // draw --> LineColor and FillColor and RasterOp and ClipRegion 188 virtual void drawPixel( long nX, long nY ); 189 virtual void drawPixel( long nX, long nY, SalColor nSalColor ); 190 virtual void drawLine( long nX1, long nY1, long nX2, long nY2 ); 191 virtual void drawRect( long nX, long nY, long nWidth, long nHeight ); 192 virtual void drawPolyLine( sal_uInt32 nPoints, const SalPoint* pPtAry ); 193 virtual void drawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry ); 194 virtual void drawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* pPoints, PCONSTSALPOINT* pPtAry ); 195 virtual bool drawPolyPolygon( const ::basegfx::B2DPolyPolygon&, double fTransparency ); 196 virtual sal_Bool drawPolyLineBezier( sal_uInt32 nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry ); 197 virtual sal_Bool drawPolygonBezier( sal_uInt32 nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry ); 198 virtual sal_Bool drawPolyPolygonBezier( sal_uInt32 nPoly, const sal_uInt32* pPoints, const SalPoint* const* pPtAry, const sal_uInt8* const* pFlgAry ); 199 virtual bool drawPolyLine( 200 const ::basegfx::B2DPolygon&, 201 double fTransparency, 202 const ::basegfx::B2DVector& rLineWidths, 203 basegfx::B2DLineJoin, 204 com::sun::star::drawing::LineCap eLineCap); 205 206 // CopyArea --> No RasterOp, but ClipRegion 207 virtual void copyArea( long nDestX, long nDestY, long nSrcX, long nSrcY, long nSrcWidth, 208 long nSrcHeight, sal_uInt16 nFlags ); 209 210 // CopyBits and DrawBitmap --> RasterOp and ClipRegion 211 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics 212 virtual void copyBits( const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics ); 213 virtual void drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap ); 214 virtual void drawBitmap( const SalTwoRect& rPosAry, 215 const SalBitmap& rSalBitmap, 216 SalColor nTransparentColor ); 217 virtual void drawBitmap( const SalTwoRect& rPosAry, 218 const SalBitmap& rSalBitmap, 219 const SalBitmap& rTransparentBitmap ); 220 virtual void drawMask( const SalTwoRect& rPosAry, 221 const SalBitmap& rSalBitmap, 222 SalColor nMaskColor ); 223 224 virtual SalBitmap* getBitmap( long nX, long nY, long nWidth, long nHeight ); 225 virtual SalColor getPixel( long nX, long nY ); 226 227 // invert --> ClipRegion (only Windows or VirDevs) 228 virtual void invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags); 229 virtual void invert( sal_uInt32 nPoints, const SalPoint* pPtAry, SalInvert nFlags ); 230 231 virtual sal_Bool drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uLong nSize ); 232 233 virtual bool drawAlphaBitmap( const SalTwoRect&, 234 const SalBitmap& rSourceBitmap, 235 const SalBitmap& rAlphaBitmap ); 236 virtual bool drawTransformedBitmap( 237 const basegfx::B2DPoint& rNull, 238 const basegfx::B2DPoint& rX, 239 const basegfx::B2DPoint& rY, 240 const SalBitmap& rSourceBitmap, 241 const SalBitmap* pAlphaBitmap); 242 243 virtual bool drawAlphaRect( long nX, long nY, long nWidth, 244 long nHeight, sal_uInt8 nTransparency ); 245 246 CGPoint* makeCGptArray(sal_uLong nPoints, const SalPoint* pPtAry); 247 // native widget rendering methods that require mirroring 248 virtual sal_Bool hitTestNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, 249 const Point& aPos, sal_Bool& rIsInside ); 250 virtual sal_Bool drawNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, 251 ControlState nState, const ImplControlValue& aValue, 252 const rtl::OUString& aCaption ); 253 virtual sal_Bool drawNativeControlText( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, 254 ControlState nState, const ImplControlValue& aValue, 255 const rtl::OUString& aCaption ); 256 virtual sal_Bool getNativeControlRegion( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, ControlState nState, 257 const ImplControlValue& aValue, const rtl::OUString& aCaption, 258 Rectangle &rNativeBoundingRegion, Rectangle &rNativeContentRegion ); 259 260 // get device resolution 261 virtual void GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY ); 262 // get the depth of the device 263 virtual sal_uInt16 GetBitCount(); 264 // get the width of the device 265 virtual long GetGraphicsWidth() const; 266 267 // set the clip region to empty 268 virtual void ResetClipRegion(); 269 270 // set the line color to transparent (= don't draw lines) 271 virtual void SetLineColor(); 272 // set the line color to a specific color 273 virtual void SetLineColor( SalColor nSalColor ); 274 // set the fill color to transparent (= don't fill) 275 virtual void SetFillColor(); 276 // set the fill color to a specific color, shapes will be 277 // filled accordingly 278 virtual void SetFillColor( SalColor nSalColor ); 279 // enable/disable XOR drawing 280 virtual void SetXORMode( bool bSet, bool bInvertOnly ); 281 // set line color for raster operations 282 virtual void SetROPLineColor( SalROPColor nROPColor ); 283 // set fill color for raster operations 284 virtual void SetROPFillColor( SalROPColor nROPColor ); 285 // set the text color to a specific color 286 virtual void SetTextColor( SalColor nSalColor ); 287 // set the font 288 virtual sal_uInt16 SetFont( ImplFontSelectData*, int nFallbackLevel ); 289 // get the current font's etrics 290 virtual void GetFontMetric( ImplFontMetricData*, int nFallbackLevel ); 291 // get kernign pairs of the current font 292 // return only PairCount if (pKernPairs == NULL) 293 virtual sal_uLong GetKernPairs( sal_uLong nPairs, ImplKernPairData* pKernPairs ); 294 // get the repertoire of the current font 295 virtual const ImplFontCharMap* GetImplFontCharMap() const; 296 // graphics must fill supplied font list 297 virtual void GetDevFontList( ImplDevFontList* ); 298 // graphics should call ImplAddDevFontSubstitute on supplied 299 // OutputDevice for all its device specific preferred font substitutions 300 virtual void GetDevFontSubstList( OutputDevice* ); 301 virtual bool AddTempDevFont( ImplDevFontList*, const String& rFileURL, const String& rFontName ); 302 // CreateFontSubset: a method to get a subset of glyhps of a font 303 // inside a new valid font file 304 // returns TRUE if creation of subset was successfull 305 // parameters: rToFile: contains a osl file URL to write the subset to 306 // pFont: describes from which font to create a subset 307 // pGlyphIDs: the glyph ids to be extracted 308 // pEncoding: the character code corresponding to each glyph 309 // pWidths: the advance widths of the correspoding glyphs (in PS font units) 310 // nGlyphs: the number of glyphs 311 // rInfo: additional outgoing information 312 // implementation note: encoding 0 with glyph id 0 should be added implicitly 313 // as "undefined character" 314 virtual sal_Bool CreateFontSubset( const rtl::OUString& rToFile, 315 const ImplFontData* pFont, 316 sal_GlyphId* pGlyphIds, 317 sal_uInt8* pEncoding, 318 sal_Int32* pWidths, 319 int nGlyphs, 320 FontSubsetInfo& rInfo // out parameter 321 ); 322 323 // GetFontEncodingVector: a method to get the encoding map Unicode 324 // to font encoded character; this is only used for type1 fonts and 325 // may return NULL in case of unknown encoding vector 326 // if ppNonEncoded is set and non encoded characters (that is type1 327 // glyphs with only a name) exist it is set to the corresponding 328 // map for non encoded glyphs; the encoding vector contains -1 329 // as encoding for these cases 330 virtual const Ucs2SIntMap* GetFontEncodingVector( const ImplFontData*, const Ucs2OStrMap** ppNonEncoded ); 331 332 // GetEmbedFontData: gets the font data for a font marked 333 // embeddable by GetDevFontList or NULL in case of error 334 // parameters: pFont: describes the font in question 335 // pWidths: the widths of all glyphs from char code 0 to 255 336 // pWidths MUST support at least 256 members; 337 // rInfo: additional outgoing information 338 // pDataLen: out parameter, contains the byte length of the returned buffer 339 virtual const void* GetEmbedFontData( const ImplFontData*, 340 const sal_Ucs* pUnicodes, 341 sal_Int32* pWidths, 342 FontSubsetInfo& rInfo, 343 long* pDataLen ); 344 // frees the font data again 345 virtual void FreeEmbedFontData( const void* pData, long nDataLen ); 346 347 virtual void GetGlyphWidths( const ImplFontData*, 348 bool bVertical, 349 Int32Vector& rWidths, 350 Ucs2UIntMap& rUnicodeEnc ); 351 352 virtual bool GetGlyphBoundRect( sal_GlyphId, Rectangle& ); 353 virtual bool GetGlyphOutline( sal_GlyphId, basegfx::B2DPolyPolygon& ); 354 355 virtual SalLayout* GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ); 356 virtual void DrawServerFontLayout( const ServerFontLayout& ); 357 virtual bool supportsOperation( OutDevSupportType ) const; 358 359 // Query the platform layer for control support 360 virtual sal_Bool IsNativeControlSupported( ControlType nType, ControlPart nPart ); 361 362 virtual SystemGraphicsData GetGraphicsData() const; 363 virtual SystemFontData GetSysFontData( int /* nFallbacklevel */ ) const; 364 365 private: 366 // differences between VCL, Quartz and kHiThemeOrientation coordinate systems 367 // make some graphics seem to be vertically-mirrored from a VCL perspective 368 bool IsFlipped() const { return mbWindow; } 369 370 void ApplyXorContext(); 371 void Pattern50Fill(); 372 UInt32 getState( ControlState nState ); 373 UInt32 getTrackState( ControlState nState ); 374 }; 375 376 class XorEmulation 377 { 378 public: 379 XorEmulation(); 380 /*final*/ ~XorEmulation(); 381 382 void SetTarget( int nWidth, int nHeight, int nBitmapDepth, CGContextRef, CGLayerRef ); 383 bool UpdateTarget(); 384 void Enable() { mbIsEnabled = true; } 385 void Disable() { mbIsEnabled = false; } 386 bool IsEnabled() const { return mbIsEnabled; } 387 CGContextRef GetTargetContext() const { return mxTargetContext; } 388 CGContextRef GetMaskContext() const { return (mbIsEnabled ? mxMaskContext : NULL); } 389 390 private: 391 CGLayerRef mxTargetLayer; 392 CGContextRef mxTargetContext; 393 CGContextRef mxMaskContext; 394 CGContextRef mxTempContext; 395 sal_uLong* mpMaskBuffer; 396 sal_uLong* mpTempBuffer; 397 int mnBufferLongs; 398 bool mbIsEnabled; 399 }; 400 401 402 // --- some trivial inlines 403 404 inline void AquaSalGraphics::RefreshRect( const CGRect& rRect ) 405 { 406 RefreshRect( rRect.origin.x, rRect.origin.y, rRect.size.width, rRect.size.height ); 407 } 408 409 inline void AquaSalGraphics::RefreshRect( const NSRect& rRect ) 410 { 411 RefreshRect( rRect.origin.x, rRect.origin.y, rRect.size.width, rRect.size.height ); 412 } 413 414 inline RGBAColor::RGBAColor( SalColor nSalColor ) 415 { 416 mfRGBA[0] = SALCOLOR_RED( nSalColor) * (1.0/255); 417 mfRGBA[1] = SALCOLOR_GREEN(nSalColor) * (1.0/255); 418 mfRGBA[2] = SALCOLOR_BLUE( nSalColor) * (1.0/255); 419 mfRGBA[3] = 1.0; // default to opaque 420 } 421 422 inline RGBAColor::RGBAColor( float fRed, float fGreen, float fBlue, float fAlpha ) 423 { 424 mfRGBA[0] = fRed; 425 mfRGBA[1] = fGreen; 426 mfRGBA[2] = fBlue; 427 mfRGBA[3] = fAlpha; 428 } 429 430 #endif // _SV_SALGDI_H 431 432