19f62ea84SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 39f62ea84SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 49f62ea84SAndrew Rist * or more contributor license agreements. See the NOTICE file 59f62ea84SAndrew Rist * distributed with this work for additional information 69f62ea84SAndrew Rist * regarding copyright ownership. The ASF licenses this file 79f62ea84SAndrew Rist * to you under the Apache License, Version 2.0 (the 89f62ea84SAndrew Rist * "License"); you may not use this file except in compliance 99f62ea84SAndrew Rist * with the License. You may obtain a copy of the License at 109f62ea84SAndrew Rist * 119f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 129f62ea84SAndrew Rist * 139f62ea84SAndrew Rist * Unless required by applicable law or agreed to in writing, 149f62ea84SAndrew Rist * software distributed under the License is distributed on an 159f62ea84SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 169f62ea84SAndrew Rist * KIND, either express or implied. See the License for the 179f62ea84SAndrew Rist * specific language governing permissions and limitations 189f62ea84SAndrew Rist * under the License. 199f62ea84SAndrew Rist * 209f62ea84SAndrew Rist *************************************************************/ 219f62ea84SAndrew Rist 22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 23cdf0e10cSrcweir #include "precompiled_vcl.hxx" 24cdf0e10cSrcweir 25cdf0e10cSrcweir #include "osl/file.hxx" 26cdf0e10cSrcweir #include "osl/process.h" 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include "vos/mutex.hxx" 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include "rtl/bootstrap.h" 31cdf0e10cSrcweir #include "rtl/strbuf.hxx" 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include "basegfx/range/b2drectangle.hxx" 34cdf0e10cSrcweir #include "basegfx/polygon/b2dpolygon.hxx" 35cdf0e10cSrcweir #include "basegfx/polygon/b2dpolygontools.hxx" 36cdf0e10cSrcweir #include "basegfx/matrix/b2dhommatrix.hxx" 37cdf0e10cSrcweir #include "basegfx/matrix/b2dhommatrixtools.hxx" 38cdf0e10cSrcweir 39cdf0e10cSrcweir #include "vcl/sysdata.hxx" 40cdf0e10cSrcweir #include "vcl/svapp.hxx" 41cdf0e10cSrcweir 42cdf0e10cSrcweir #include "aqua/salconst.h" 43cdf0e10cSrcweir #include "aqua/salgdi.h" 44cdf0e10cSrcweir #include "aqua/salbmp.h" 45cdf0e10cSrcweir #include "aqua/salframe.h" 46cdf0e10cSrcweir #include "aqua/salcolorutils.hxx" 47e26449d3SHerbert Dürr #ifdef USE_ATSU 4851747b8eSHerbert Dürr #include "atsfonts.hxx" 49e26449d3SHerbert Dürr #else // !USE_ATSU 50e26449d3SHerbert Dürr #include "ctfonts.hxx" 51e26449d3SHerbert Dürr #endif 52cdf0e10cSrcweir 53cdf0e10cSrcweir #include "fontsubset.hxx" 54cdf0e10cSrcweir #include "impfont.hxx" 55cdf0e10cSrcweir #include "sallayout.hxx" 56cdf0e10cSrcweir #include "sft.hxx" 57cdf0e10cSrcweir 58cdf0e10cSrcweir using namespace vcl; 59cdf0e10cSrcweir 60e26449d3SHerbert Dürr // ======================================================================= 61cdf0e10cSrcweir 62e26449d3SHerbert Dürr SystemFontList::~SystemFontList( void ) 63e26449d3SHerbert Dürr {} 64cdf0e10cSrcweir 65cdf0e10cSrcweir // ======================================================================= 66cdf0e10cSrcweir 67e26449d3SHerbert Dürr ImplMacTextStyle::ImplMacTextStyle( const ImplFontSelectData& rReqFont ) 68e26449d3SHerbert Dürr : mpFontData( (ImplMacFontData*)rReqFont.mpFontData ) 69e26449d3SHerbert Dürr , mfFontScale( 1.0 ) 70e26449d3SHerbert Dürr , mfFontStretch( 1.0 ) 71e26449d3SHerbert Dürr , mfFontRotation( 0.0 ) 72e26449d3SHerbert Dürr {} 73e26449d3SHerbert Dürr 74e26449d3SHerbert Dürr // ----------------------------------------------------------------------- 75e26449d3SHerbert Dürr 76e26449d3SHerbert Dürr ImplMacTextStyle::~ImplMacTextStyle( void ) 77e26449d3SHerbert Dürr {} 78e26449d3SHerbert Dürr 79e26449d3SHerbert Dürr // ======================================================================= 80e26449d3SHerbert Dürr 81e26449d3SHerbert Dürr ImplMacFontData::ImplMacFontData( const ImplDevFontAttributes& rDFA, sal_IntPtr nFontId ) 82e26449d3SHerbert Dürr : ImplFontData( rDFA, 0 ) 83e26449d3SHerbert Dürr , mnFontId( nFontId ) 84cdf0e10cSrcweir , mpCharMap( NULL ) 85cdf0e10cSrcweir , mbOs2Read( false ) 86cdf0e10cSrcweir , mbHasOs2Table( false ) 87cdf0e10cSrcweir , mbCmapEncodingRead( false ) 88cdf0e10cSrcweir , mbHasCJKSupport( false ) 89cdf0e10cSrcweir {} 90cdf0e10cSrcweir 91cdf0e10cSrcweir // ----------------------------------------------------------------------- 92cdf0e10cSrcweir 93e26449d3SHerbert Dürr ImplMacFontData::ImplMacFontData( const ImplMacFontData& rSrc ) 94e26449d3SHerbert Dürr : ImplFontData( rSrc) 95e26449d3SHerbert Dürr , mnFontId( rSrc.mnFontId) 96e26449d3SHerbert Dürr , mpCharMap( rSrc.mpCharMap) 97e26449d3SHerbert Dürr , mbOs2Read( rSrc.mbOs2Read) 98e26449d3SHerbert Dürr , mbHasOs2Table( rSrc.mbHasOs2Table) 99e26449d3SHerbert Dürr , mbCmapEncodingRead( rSrc.mbCmapEncodingRead) 100e26449d3SHerbert Dürr , mbHasCJKSupport( rSrc.mbHasCJKSupport) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir if( mpCharMap ) 103e26449d3SHerbert Dürr mpCharMap->AddReference(); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir // ----------------------------------------------------------------------- 107cdf0e10cSrcweir 108e26449d3SHerbert Dürr ImplMacFontData::~ImplMacFontData() 109cdf0e10cSrcweir { 110e26449d3SHerbert Dürr if( mpCharMap ) 111e26449d3SHerbert Dürr mpCharMap->DeReference(); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir // ----------------------------------------------------------------------- 115cdf0e10cSrcweir 116e26449d3SHerbert Dürr sal_IntPtr ImplMacFontData::GetFontId() const 117cdf0e10cSrcweir { 118e26449d3SHerbert Dürr return reinterpret_cast<sal_IntPtr>( mnFontId); 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir // ----------------------------------------------------------------------- 122cdf0e10cSrcweir 123cdf0e10cSrcweir ImplFontEntry* ImplMacFontData::CreateFontInstance(ImplFontSelectData& rFSD) const 124cdf0e10cSrcweir { 125e26449d3SHerbert Dürr return new ImplFontEntry(rFSD); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir // ----------------------------------------------------------------------- 129cdf0e10cSrcweir 130cdf0e10cSrcweir static unsigned GetUShort( const unsigned char* p ){return((p[0]<<8)+p[1]);} 131cdf0e10cSrcweir static unsigned GetUInt( const unsigned char* p ) { return((p[0]<<24)+(p[1]<<16)+(p[2]<<8)+p[3]);} 132cdf0e10cSrcweir 133cdf0e10cSrcweir const ImplFontCharMap* ImplMacFontData::GetImplFontCharMap() const 134cdf0e10cSrcweir { 135cdf0e10cSrcweir // return the cached charmap 136cdf0e10cSrcweir if( mpCharMap ) 137cdf0e10cSrcweir return mpCharMap; 138cdf0e10cSrcweir 139cdf0e10cSrcweir // set the default charmap 140cdf0e10cSrcweir mpCharMap = ImplFontCharMap::GetDefaultMap(); 141cdf0e10cSrcweir mpCharMap->AddReference(); 142cdf0e10cSrcweir 143cdf0e10cSrcweir // get the CMAP byte size 144cdf0e10cSrcweir // allocate a buffer for the CMAP raw data 145e26449d3SHerbert Dürr const int nBufSize = GetFontTable( "cmap", NULL ); 146e26449d3SHerbert Dürr DBG_ASSERT( (nBufSize > 0), "ImplMacFontData::GetImplFontCharMap : FontGetTable1 failed!\n"); 147e26449d3SHerbert Dürr if( nBufSize <= 0 ) 148e26449d3SHerbert Dürr return mpCharMap; 149cdf0e10cSrcweir 150cdf0e10cSrcweir // get the CMAP raw data 151e26449d3SHerbert Dürr ByteVector aBuffer( nBufSize ); 152e26449d3SHerbert Dürr const int nRawSize = GetFontTable( "cmap", &aBuffer[0] ); 153e26449d3SHerbert Dürr DBG_ASSERT( (nRawSize > 0), "ImplMacFontData::GetImplFontCharMap : ATSFontGetTable2 failed!\n"); 154e26449d3SHerbert Dürr if( nRawSize <= 0 ) 155cdf0e10cSrcweir return mpCharMap; 156e26449d3SHerbert Dürr DBG_ASSERT( (nBufSize==nRawSize), "ImplMacFontData::GetImplFontCharMap : ByteCount mismatch!\n"); 157cdf0e10cSrcweir 158cdf0e10cSrcweir // parse the CMAP 159cdf0e10cSrcweir CmapResult aCmapResult; 160e26449d3SHerbert Dürr if( ParseCMAP( &aBuffer[0], nRawSize, aCmapResult ) ) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir // create the matching charmap 163cdf0e10cSrcweir mpCharMap->DeReference(); 164cdf0e10cSrcweir mpCharMap = new ImplFontCharMap( aCmapResult ); 165cdf0e10cSrcweir mpCharMap->AddReference(); 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir return mpCharMap; 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir // ----------------------------------------------------------------------- 172cdf0e10cSrcweir 173cdf0e10cSrcweir void ImplMacFontData::ReadOs2Table( void ) const 174cdf0e10cSrcweir { 175cdf0e10cSrcweir // read this only once per font 176cdf0e10cSrcweir if( mbOs2Read ) 177cdf0e10cSrcweir return; 178cdf0e10cSrcweir mbOs2Read = true; 179e26449d3SHerbert Dürr mbHasOs2Table = false; 180cdf0e10cSrcweir 181cdf0e10cSrcweir // prepare to get the OS/2 table raw data 182e26449d3SHerbert Dürr const int nBufSize = GetFontTable( "OS/2", NULL ); 183e26449d3SHerbert Dürr DBG_ASSERT( (nBufSize > 0), "ImplMacFontData::ReadOs2Table : FontGetTable1 failed!\n"); 184e26449d3SHerbert Dürr if( nBufSize <= 0 ) 185cdf0e10cSrcweir return; 186cdf0e10cSrcweir 187cdf0e10cSrcweir // get the OS/2 raw data 188e26449d3SHerbert Dürr ByteVector aBuffer( nBufSize ); 189e26449d3SHerbert Dürr const int nRawSize = GetFontTable( "cmap", &aBuffer[0] ); 190e26449d3SHerbert Dürr DBG_ASSERT( (nRawSize > 0), "ImplMacFontData::ReadOs2Table : ATSFontGetTable2 failed!\n"); 191e26449d3SHerbert Dürr if( nRawSize <= 0 ) 192cdf0e10cSrcweir return; 193e26449d3SHerbert Dürr DBG_ASSERT( (nBufSize == nRawSize), "ImplMacFontData::ReadOs2Table : ByteCount mismatch!\n"); 194cdf0e10cSrcweir mbHasOs2Table = true; 195cdf0e10cSrcweir 196cdf0e10cSrcweir // parse the OS/2 raw data 197cdf0e10cSrcweir // TODO: also analyze panose info, etc. 198cdf0e10cSrcweir 199cdf0e10cSrcweir // check if the fonts needs the "CJK extra leading" heuristic 200cdf0e10cSrcweir const unsigned char* pOS2map = &aBuffer[0]; 201e26449d3SHerbert Dürr const sal_uInt32 nVersion = GetUShort( pOS2map ); 202e26449d3SHerbert Dürr if( nVersion >= 0x0001 ) 203e26449d3SHerbert Dürr { 204e26449d3SHerbert Dürr const sal_uInt32 ulUnicodeRange2 = GetUInt( pOS2map + 46 ); 205e26449d3SHerbert Dürr if( ulUnicodeRange2 & 0x2DF00000 ) 206e26449d3SHerbert Dürr mbHasCJKSupport = true; 207e26449d3SHerbert Dürr } 208cdf0e10cSrcweir } 209cdf0e10cSrcweir 210cdf0e10cSrcweir void ImplMacFontData::ReadMacCmapEncoding( void ) const 211cdf0e10cSrcweir { 212e26449d3SHerbert Dürr // read this only once per font 213e26449d3SHerbert Dürr if( mbCmapEncodingRead ) 214e26449d3SHerbert Dürr return; 215e26449d3SHerbert Dürr mbCmapEncodingRead = true; 216cdf0e10cSrcweir 217e26449d3SHerbert Dürr const int nBufSize = GetFontTable( "cmap", NULL ); 218e26449d3SHerbert Dürr if( nBufSize <= 0 ) 219e26449d3SHerbert Dürr return; 220cdf0e10cSrcweir 221e26449d3SHerbert Dürr // get the CMAP raw data 222e26449d3SHerbert Dürr ByteVector aBuffer( nBufSize ); 223e26449d3SHerbert Dürr const int nRawSize = GetFontTable( "cmap", &aBuffer[0] ); 224e26449d3SHerbert Dürr if( nRawSize < 24 ) 225e26449d3SHerbert Dürr return; 226cdf0e10cSrcweir 227e26449d3SHerbert Dürr const unsigned char* pCmap = &aBuffer[0]; 228e26449d3SHerbert Dürr if( GetUShort( pCmap ) != 0x0000 ) 229e26449d3SHerbert Dürr return; 230cdf0e10cSrcweir 231e26449d3SHerbert Dürr // check if the fonts needs the "CJK extra leading" heuristic 232e26449d3SHerbert Dürr int nSubTables = GetUShort( pCmap + 2 ); 233e26449d3SHerbert Dürr for( const unsigned char* p = pCmap + 4; --nSubTables >= 0; p += 8 ) 234e26449d3SHerbert Dürr { 235e26449d3SHerbert Dürr int nPlatform = GetUShort( p ); 236e26449d3SHerbert Dürr if( nPlatform == kFontMacintoshPlatform ) { 237e26449d3SHerbert Dürr const int nEncoding = GetUShort (p + 2 ); 238e26449d3SHerbert Dürr if( nEncoding == kFontJapaneseScript || 239e26449d3SHerbert Dürr nEncoding == kFontTraditionalChineseScript || 240e26449d3SHerbert Dürr nEncoding == kFontKoreanScript || 241e26449d3SHerbert Dürr nEncoding == kFontSimpleChineseScript ) 242e26449d3SHerbert Dürr { 243e26449d3SHerbert Dürr mbHasCJKSupport = true; 244e26449d3SHerbert Dürr break; 245e26449d3SHerbert Dürr } 246e26449d3SHerbert Dürr } 247e26449d3SHerbert Dürr } 248cdf0e10cSrcweir } 249cdf0e10cSrcweir 250cdf0e10cSrcweir // ----------------------------------------------------------------------- 251cdf0e10cSrcweir 252cdf0e10cSrcweir bool ImplMacFontData::HasCJKSupport( void ) const 253cdf0e10cSrcweir { 254cdf0e10cSrcweir ReadOs2Table(); 255e26449d3SHerbert Dürr if( !mbHasOs2Table ) 256e26449d3SHerbert Dürr ReadMacCmapEncoding(); 257cdf0e10cSrcweir 258cdf0e10cSrcweir return mbHasCJKSupport; 259cdf0e10cSrcweir } 260cdf0e10cSrcweir 261cdf0e10cSrcweir // ======================================================================= 262cdf0e10cSrcweir 263cdf0e10cSrcweir AquaSalGraphics::AquaSalGraphics() 264cdf0e10cSrcweir : mpFrame( NULL ) 265cdf0e10cSrcweir , mxLayer( NULL ) 266cdf0e10cSrcweir , mrContext( NULL ) 267cdf0e10cSrcweir , mpXorEmulation( NULL ) 268cdf0e10cSrcweir , mnXorMode( 0 ) 269cdf0e10cSrcweir , mnWidth( 0 ) 270cdf0e10cSrcweir , mnHeight( 0 ) 271cdf0e10cSrcweir , mnBitmapDepth( 0 ) 272cdf0e10cSrcweir , mnRealDPIX( 0 ) 273cdf0e10cSrcweir , mnRealDPIY( 0 ) 274cdf0e10cSrcweir , mfFakeDPIScale( 1.0 ) 275cdf0e10cSrcweir , mxClipPath( NULL ) 276cdf0e10cSrcweir , maLineColor( COL_WHITE ) 277cdf0e10cSrcweir , maFillColor( COL_BLACK ) 278e26449d3SHerbert Dürr , mpMacFontData( NULL ) 279e26449d3SHerbert Dürr , mpMacTextStyle( NULL ) 280e26449d3SHerbert Dürr , maTextColor( COL_BLACK ) 281cdf0e10cSrcweir , mbNonAntialiasedText( false ) 282cdf0e10cSrcweir , mbPrinter( false ) 283cdf0e10cSrcweir , mbVirDev( false ) 284cdf0e10cSrcweir , mbWindow( false ) 285e26449d3SHerbert Dürr {} 286cdf0e10cSrcweir 287cdf0e10cSrcweir // ----------------------------------------------------------------------- 288cdf0e10cSrcweir 289cdf0e10cSrcweir AquaSalGraphics::~AquaSalGraphics() 290cdf0e10cSrcweir { 291e26449d3SHerbert Dürr CGPathRelease( mxClipPath ); 292e26449d3SHerbert Dürr 293e26449d3SHerbert Dürr delete mpMacTextStyle; 294cdf0e10cSrcweir 295cdf0e10cSrcweir if( mpXorEmulation ) 296cdf0e10cSrcweir delete mpXorEmulation; 297cdf0e10cSrcweir 298cdf0e10cSrcweir if( mxLayer ) 299e26449d3SHerbert Dürr CGLayerRelease( mxLayer ); 300cdf0e10cSrcweir else if( mrContext && mbWindow ) 301cdf0e10cSrcweir { 302cdf0e10cSrcweir // destroy backbuffer bitmap context that we created ourself 303cdf0e10cSrcweir CGContextRelease( mrContext ); 304cdf0e10cSrcweir mrContext = NULL; 305e26449d3SHerbert Dürr // memory is freed automatically by maOwnContextMemory 306cdf0e10cSrcweir } 307cdf0e10cSrcweir } 308cdf0e10cSrcweir 309cdf0e10cSrcweir bool AquaSalGraphics::supportsOperation( OutDevSupportType eType ) const 310cdf0e10cSrcweir { 311e26449d3SHerbert Dürr bool bRet = false; 312e26449d3SHerbert Dürr switch( eType ) 313e26449d3SHerbert Dürr { 314e26449d3SHerbert Dürr case OutDevSupport_TransparentRect: 315e26449d3SHerbert Dürr case OutDevSupport_B2DClip: 316e26449d3SHerbert Dürr case OutDevSupport_B2DDraw: 317e26449d3SHerbert Dürr bRet = true; 318e26449d3SHerbert Dürr break; 319e26449d3SHerbert Dürr default: 320e26449d3SHerbert Dürr break; 321e26449d3SHerbert Dürr } 322e26449d3SHerbert Dürr return bRet; 323cdf0e10cSrcweir } 324cdf0e10cSrcweir 325cdf0e10cSrcweir // ======================================================================= 326cdf0e10cSrcweir 327cdf0e10cSrcweir void AquaSalGraphics::updateResolution() 328cdf0e10cSrcweir { 329cdf0e10cSrcweir DBG_ASSERT( mbWindow, "updateResolution on inappropriate graphics" ); 330cdf0e10cSrcweir 331bde8a4bdSHerbert Dürr initResolution( (mbWindow && mpFrame) ? mpFrame->getNSWindow() : nil ); 332cdf0e10cSrcweir } 333cdf0e10cSrcweir 334cdf0e10cSrcweir void AquaSalGraphics::initResolution( NSWindow* ) 335cdf0e10cSrcweir { 336cdf0e10cSrcweir // #i100617# read DPI only once; there is some kind of weird caching going on 337cdf0e10cSrcweir // if the main screen changes 338cdf0e10cSrcweir // FIXME: this is really unfortunate and needs to be investigated 339cdf0e10cSrcweir 340cdf0e10cSrcweir SalData* pSalData = GetSalData(); 341cdf0e10cSrcweir if( pSalData->mnDPIX == 0 || pSalData->mnDPIY == 0 ) 342cdf0e10cSrcweir { 343cdf0e10cSrcweir NSScreen* pScreen = nil; 344cdf0e10cSrcweir 345cdf0e10cSrcweir /* #i91301# 346cdf0e10cSrcweir many woes went into the try to have different resolutions 347cdf0e10cSrcweir on different screens. The result of these trials is that OOo is not ready 348cdf0e10cSrcweir for that yet, vcl and applications would need to be adapted. 349cdf0e10cSrcweir 350cdf0e10cSrcweir Unfortunately this is not possible in the 3.0 timeframe. 351cdf0e10cSrcweir So let's stay with one resolution for all Windows and VirtualDevices 352cdf0e10cSrcweir which is the resolution of the main screen 353cdf0e10cSrcweir 354cdf0e10cSrcweir This of course also means that measurements are exact only on the main screen. 355cdf0e10cSrcweir For activating different resolutions again just comment out the two lines below. 356cdf0e10cSrcweir 357cdf0e10cSrcweir if( pWin ) 358cdf0e10cSrcweir pScreen = [pWin screen]; 359cdf0e10cSrcweir */ 360cdf0e10cSrcweir if( pScreen == nil ) 361cdf0e10cSrcweir { 362cdf0e10cSrcweir NSArray* pScreens = [NSScreen screens]; 363cdf0e10cSrcweir if( pScreens ) 364cdf0e10cSrcweir pScreen = [pScreens objectAtIndex: 0]; 365cdf0e10cSrcweir } 366cdf0e10cSrcweir 367cdf0e10cSrcweir mnRealDPIX = mnRealDPIY = 96; 368cdf0e10cSrcweir if( pScreen ) 369cdf0e10cSrcweir { 370cdf0e10cSrcweir NSDictionary* pDev = [pScreen deviceDescription]; 371cdf0e10cSrcweir if( pDev ) 372cdf0e10cSrcweir { 373cdf0e10cSrcweir NSNumber* pVal = [pDev objectForKey: @"NSScreenNumber"]; 374cdf0e10cSrcweir if( pVal ) 375cdf0e10cSrcweir { 376cdf0e10cSrcweir // FIXME: casting a long to CGDirectDisplayID is evil, but 377cdf0e10cSrcweir // Apple suggest to do it this way 378cdf0e10cSrcweir const CGDirectDisplayID nDisplayID = (CGDirectDisplayID)[pVal longValue]; 379cdf0e10cSrcweir const CGSize aSize = CGDisplayScreenSize( nDisplayID ); // => result is in millimeters 380cdf0e10cSrcweir mnRealDPIX = static_cast<long>((CGDisplayPixelsWide( nDisplayID ) * 25.4) / aSize.width); 381cdf0e10cSrcweir mnRealDPIY = static_cast<long>((CGDisplayPixelsHigh( nDisplayID ) * 25.4) / aSize.height); 382cdf0e10cSrcweir } 383cdf0e10cSrcweir else 384cdf0e10cSrcweir { 385cdf0e10cSrcweir DBG_ERROR( "no resolution found in device description" ); 386cdf0e10cSrcweir } 387cdf0e10cSrcweir } 388cdf0e10cSrcweir else 389cdf0e10cSrcweir { 390cdf0e10cSrcweir DBG_ERROR( "no device description" ); 391cdf0e10cSrcweir } 392cdf0e10cSrcweir } 393cdf0e10cSrcweir else 394cdf0e10cSrcweir { 395cdf0e10cSrcweir DBG_ERROR( "no screen found" ); 396cdf0e10cSrcweir } 397cdf0e10cSrcweir 398cdf0e10cSrcweir // #i107076# maintaining size-WYSIWYG-ness causes many problems for 399cdf0e10cSrcweir // low-DPI, high-DPI or for mis-reporting devices 400cdf0e10cSrcweir // => it is better to limit the calculation result then 401cdf0e10cSrcweir static const int nMinDPI = 72; 402cdf0e10cSrcweir if( (mnRealDPIX < nMinDPI) || (mnRealDPIY < nMinDPI) ) 403cdf0e10cSrcweir mnRealDPIX = mnRealDPIY = nMinDPI; 404cdf0e10cSrcweir static const int nMaxDPI = 200; 405cdf0e10cSrcweir if( (mnRealDPIX > nMaxDPI) || (mnRealDPIY > nMaxDPI) ) 406cdf0e10cSrcweir mnRealDPIX = mnRealDPIY = nMaxDPI; 407cdf0e10cSrcweir 408cdf0e10cSrcweir // for OSX any anisotropy reported for the display resolution is best ignored (e.g. TripleHead2Go) 409cdf0e10cSrcweir mnRealDPIX = mnRealDPIY = (mnRealDPIX + mnRealDPIY + 1) / 2; 410cdf0e10cSrcweir 411cdf0e10cSrcweir pSalData->mnDPIX = mnRealDPIX; 412cdf0e10cSrcweir pSalData->mnDPIY = mnRealDPIY; 413cdf0e10cSrcweir } 414cdf0e10cSrcweir else 415cdf0e10cSrcweir { 416cdf0e10cSrcweir mnRealDPIX = pSalData->mnDPIX; 417cdf0e10cSrcweir mnRealDPIY = pSalData->mnDPIY; 418cdf0e10cSrcweir } 419cdf0e10cSrcweir 420cdf0e10cSrcweir mfFakeDPIScale = 1.0; 421cdf0e10cSrcweir } 422cdf0e10cSrcweir 4238a718ffcSHerbert Dürr void AquaSalGraphics::GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY ) 424cdf0e10cSrcweir { 425cdf0e10cSrcweir if( !mnRealDPIY ) 426bde8a4bdSHerbert Dürr initResolution( (mbWindow && mpFrame) ? mpFrame->getNSWindow() : nil ); 427cdf0e10cSrcweir 4288a718ffcSHerbert Dürr rDPIX = lrint( mfFakeDPIScale * mnRealDPIX); 4298a718ffcSHerbert Dürr rDPIY = lrint( mfFakeDPIScale * mnRealDPIY); 430cdf0e10cSrcweir } 431cdf0e10cSrcweir 432cdf0e10cSrcweir void AquaSalGraphics::copyResolution( AquaSalGraphics& rGraphics ) 433cdf0e10cSrcweir { 434cdf0e10cSrcweir if( !rGraphics.mnRealDPIY && rGraphics.mbWindow && rGraphics.mpFrame ) 435bde8a4bdSHerbert Dürr rGraphics.initResolution( rGraphics.mpFrame->getNSWindow() ); 436cdf0e10cSrcweir 437cdf0e10cSrcweir mnRealDPIX = rGraphics.mnRealDPIX; 438cdf0e10cSrcweir mnRealDPIY = rGraphics.mnRealDPIY; 439cdf0e10cSrcweir mfFakeDPIScale = rGraphics.mfFakeDPIScale; 440cdf0e10cSrcweir } 441cdf0e10cSrcweir 442cdf0e10cSrcweir // ----------------------------------------------------------------------- 443cdf0e10cSrcweir 444cdf0e10cSrcweir sal_uInt16 AquaSalGraphics::GetBitCount() 445cdf0e10cSrcweir { 446cdf0e10cSrcweir sal_uInt16 nBits = mnBitmapDepth ? mnBitmapDepth : 32;//24; 447cdf0e10cSrcweir return nBits; 448cdf0e10cSrcweir } 449cdf0e10cSrcweir 450cdf0e10cSrcweir // ----------------------------------------------------------------------- 451cdf0e10cSrcweir 452cdf0e10cSrcweir static const basegfx::B2DPoint aHalfPointOfs ( 0.5, 0.5 ); 453cdf0e10cSrcweir 454cdf0e10cSrcweir static void AddPolygonToPath( CGMutablePathRef xPath, 455cdf0e10cSrcweir const ::basegfx::B2DPolygon& rPolygon, bool bClosePath, bool bPixelSnap, bool bLineDraw ) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir // short circuit if there is nothing to do 458cdf0e10cSrcweir const int nPointCount = rPolygon.count(); 459cdf0e10cSrcweir if( nPointCount <= 0 ) 460cdf0e10cSrcweir return; 461cdf0e10cSrcweir 462cdf0e10cSrcweir (void)bPixelSnap; // TODO 463cdf0e10cSrcweir const CGAffineTransform* pTransform = NULL; 464cdf0e10cSrcweir 465cdf0e10cSrcweir const bool bHasCurves = rPolygon.areControlPointsUsed(); 466cdf0e10cSrcweir for( int nPointIdx = 0, nPrevIdx = 0;; nPrevIdx = nPointIdx++ ) 467cdf0e10cSrcweir { 468cdf0e10cSrcweir int nClosedIdx = nPointIdx; 469cdf0e10cSrcweir if( nPointIdx >= nPointCount ) 470cdf0e10cSrcweir { 471cdf0e10cSrcweir // prepare to close last curve segment if needed 472cdf0e10cSrcweir if( bClosePath && (nPointIdx == nPointCount) ) 473cdf0e10cSrcweir nClosedIdx = 0; 474cdf0e10cSrcweir else 475cdf0e10cSrcweir break; 476cdf0e10cSrcweir } 477cdf0e10cSrcweir 478cdf0e10cSrcweir ::basegfx::B2DPoint aPoint = rPolygon.getB2DPoint( nClosedIdx ); 479cdf0e10cSrcweir 480cdf0e10cSrcweir if( bPixelSnap) 481cdf0e10cSrcweir { 482cdf0e10cSrcweir // snap device coordinates to full pixels 483cdf0e10cSrcweir aPoint.setX( basegfx::fround( aPoint.getX() ) ); 484cdf0e10cSrcweir aPoint.setY( basegfx::fround( aPoint.getY() ) ); 485cdf0e10cSrcweir } 486cdf0e10cSrcweir 487cdf0e10cSrcweir if( bLineDraw ) 488cdf0e10cSrcweir aPoint += aHalfPointOfs; 489cdf0e10cSrcweir 490cdf0e10cSrcweir if( !nPointIdx ) { // first point => just move there 491cdf0e10cSrcweir CGPathMoveToPoint( xPath, pTransform, aPoint.getX(), aPoint.getY() ); 492cdf0e10cSrcweir continue; 493cdf0e10cSrcweir } 494cdf0e10cSrcweir 495cdf0e10cSrcweir bool bPendingCurve = false; 496cdf0e10cSrcweir if( bHasCurves ) 497cdf0e10cSrcweir { 498cdf0e10cSrcweir bPendingCurve = rPolygon.isNextControlPointUsed( nPrevIdx ); 499cdf0e10cSrcweir bPendingCurve |= rPolygon.isPrevControlPointUsed( nClosedIdx ); 500cdf0e10cSrcweir } 501cdf0e10cSrcweir 502cdf0e10cSrcweir if( !bPendingCurve ) // line segment 503cdf0e10cSrcweir CGPathAddLineToPoint( xPath, pTransform, aPoint.getX(), aPoint.getY() ); 504cdf0e10cSrcweir else // cubic bezier segment 505cdf0e10cSrcweir { 506cdf0e10cSrcweir basegfx::B2DPoint aCP1 = rPolygon.getNextControlPoint( nPrevIdx ); 507cdf0e10cSrcweir basegfx::B2DPoint aCP2 = rPolygon.getPrevControlPoint( nClosedIdx ); 508cdf0e10cSrcweir if( bLineDraw ) 509cdf0e10cSrcweir { 510cdf0e10cSrcweir aCP1 += aHalfPointOfs; 511cdf0e10cSrcweir aCP2 += aHalfPointOfs; 512cdf0e10cSrcweir } 513cdf0e10cSrcweir CGPathAddCurveToPoint( xPath, pTransform, aCP1.getX(), aCP1.getY(), 514cdf0e10cSrcweir aCP2.getX(), aCP2.getY(), aPoint.getX(), aPoint.getY() ); 515cdf0e10cSrcweir } 516cdf0e10cSrcweir } 517cdf0e10cSrcweir 518cdf0e10cSrcweir if( bClosePath ) 519cdf0e10cSrcweir CGPathCloseSubpath( xPath ); 520cdf0e10cSrcweir } 521cdf0e10cSrcweir 522cdf0e10cSrcweir static void AddPolyPolygonToPath( CGMutablePathRef xPath, 523cdf0e10cSrcweir const ::basegfx::B2DPolyPolygon& rPolyPoly, bool bPixelSnap, bool bLineDraw ) 524cdf0e10cSrcweir { 525cdf0e10cSrcweir // short circuit if there is nothing to do 526cdf0e10cSrcweir const int nPolyCount = rPolyPoly.count(); 527cdf0e10cSrcweir if( nPolyCount <= 0 ) 528cdf0e10cSrcweir return; 529cdf0e10cSrcweir 530cdf0e10cSrcweir for( int nPolyIdx = 0; nPolyIdx < nPolyCount; ++nPolyIdx ) 531cdf0e10cSrcweir { 532cdf0e10cSrcweir const ::basegfx::B2DPolygon rPolygon = rPolyPoly.getB2DPolygon( nPolyIdx ); 533cdf0e10cSrcweir AddPolygonToPath( xPath, rPolygon, true, bPixelSnap, bLineDraw ); 534cdf0e10cSrcweir } 535cdf0e10cSrcweir } 536cdf0e10cSrcweir 537cdf0e10cSrcweir // ----------------------------------------------------------------------- 538cdf0e10cSrcweir 539cdf0e10cSrcweir void AquaSalGraphics::ResetClipRegion() 540cdf0e10cSrcweir { 541cdf0e10cSrcweir // release old path and indicate no clipping 542cdf0e10cSrcweir if( mxClipPath ) 543cdf0e10cSrcweir { 544cdf0e10cSrcweir CGPathRelease( mxClipPath ); 545cdf0e10cSrcweir mxClipPath = NULL; 546cdf0e10cSrcweir } 547cdf0e10cSrcweir if( CheckContext() ) 548cdf0e10cSrcweir SetState(); 549cdf0e10cSrcweir } 550cdf0e10cSrcweir 551cdf0e10cSrcweir // ----------------------------------------------------------------------- 552cdf0e10cSrcweir 553cdf0e10cSrcweir bool AquaSalGraphics::setClipRegion( const Region& i_rClip ) 554cdf0e10cSrcweir { 555cdf0e10cSrcweir // release old clip path 556cdf0e10cSrcweir if( mxClipPath ) 557cdf0e10cSrcweir { 558cdf0e10cSrcweir CGPathRelease( mxClipPath ); 559cdf0e10cSrcweir mxClipPath = NULL; 560cdf0e10cSrcweir } 561cdf0e10cSrcweir mxClipPath = CGPathCreateMutable(); 562cdf0e10cSrcweir 563cdf0e10cSrcweir // set current path, either as polypolgon or sequence of rectangles 564e6f63103SArmin Le Grand if(i_rClip.HasPolyPolygonOrB2DPolyPolygon()) 565cdf0e10cSrcweir { 566e6f63103SArmin Le Grand const basegfx::B2DPolyPolygon aClip(i_rClip.GetAsB2DPolyPolygon()); 567e6f63103SArmin Le Grand 568cdf0e10cSrcweir AddPolyPolygonToPath( mxClipPath, aClip, !getAntiAliasB2DDraw(), false ); 569cdf0e10cSrcweir } 570cdf0e10cSrcweir else 571cdf0e10cSrcweir { 572e6f63103SArmin Le Grand RectangleVector aRectangles; 573e6f63103SArmin Le Grand i_rClip.GetRegionRectangles(aRectangles); 574e6f63103SArmin Le Grand 575e6f63103SArmin Le Grand for(RectangleVector::const_iterator aRectIter(aRectangles.begin()); aRectIter != aRectangles.end(); aRectIter++) 576cdf0e10cSrcweir { 577e6f63103SArmin Le Grand const long nW(aRectIter->Right() - aRectIter->Left() + 1); // uses +1 logic in original 578e6f63103SArmin Le Grand 579e6f63103SArmin Le Grand if(nW) 580cdf0e10cSrcweir { 581e6f63103SArmin Le Grand const long nH(aRectIter->Bottom() - aRectIter->Top() + 1); // uses +1 logic in original 582e6f63103SArmin Le Grand 583e6f63103SArmin Le Grand if(nH) 584e6f63103SArmin Le Grand { 585a94c8ebdSHerbert Dürr const CGRect aRect = CGRectMake( aRectIter->Left(), aRectIter->Top(), nW, nH); 586e6f63103SArmin Le Grand CGPathAddRect( mxClipPath, NULL, aRect ); 587e6f63103SArmin Le Grand } 588cdf0e10cSrcweir } 589cdf0e10cSrcweir } 590cdf0e10cSrcweir } 591cdf0e10cSrcweir // set the current path as clip region 592cdf0e10cSrcweir if( CheckContext() ) 593cdf0e10cSrcweir SetState(); 594cdf0e10cSrcweir return true; 595cdf0e10cSrcweir } 596cdf0e10cSrcweir 597cdf0e10cSrcweir // ----------------------------------------------------------------------- 598cdf0e10cSrcweir 599cdf0e10cSrcweir void AquaSalGraphics::SetLineColor() 600cdf0e10cSrcweir { 601cdf0e10cSrcweir maLineColor.SetAlpha( 0.0 ); // transparent 602cdf0e10cSrcweir if( CheckContext() ) 603cdf0e10cSrcweir CGContextSetStrokeColor( mrContext, maLineColor.AsArray() ); 604cdf0e10cSrcweir } 605cdf0e10cSrcweir 606cdf0e10cSrcweir // ----------------------------------------------------------------------- 607cdf0e10cSrcweir 608cdf0e10cSrcweir void AquaSalGraphics::SetLineColor( SalColor nSalColor ) 609cdf0e10cSrcweir { 610cdf0e10cSrcweir maLineColor = RGBAColor( nSalColor ); 611cdf0e10cSrcweir if( CheckContext() ) 612cdf0e10cSrcweir CGContextSetStrokeColor( mrContext, maLineColor.AsArray() ); 613cdf0e10cSrcweir } 614cdf0e10cSrcweir 615cdf0e10cSrcweir // ----------------------------------------------------------------------- 616cdf0e10cSrcweir 617cdf0e10cSrcweir void AquaSalGraphics::SetFillColor() 618cdf0e10cSrcweir { 619cdf0e10cSrcweir maFillColor.SetAlpha( 0.0 ); // transparent 620cdf0e10cSrcweir if( CheckContext() ) 621cdf0e10cSrcweir CGContextSetFillColor( mrContext, maFillColor.AsArray() ); 622cdf0e10cSrcweir } 623cdf0e10cSrcweir 624cdf0e10cSrcweir // ----------------------------------------------------------------------- 625cdf0e10cSrcweir 626cdf0e10cSrcweir void AquaSalGraphics::SetFillColor( SalColor nSalColor ) 627cdf0e10cSrcweir { 628cdf0e10cSrcweir maFillColor = RGBAColor( nSalColor ); 629cdf0e10cSrcweir if( CheckContext() ) 630cdf0e10cSrcweir CGContextSetFillColor( mrContext, maFillColor.AsArray() ); 631cdf0e10cSrcweir } 632cdf0e10cSrcweir 633cdf0e10cSrcweir // ----------------------------------------------------------------------- 634cdf0e10cSrcweir 635cdf0e10cSrcweir static SalColor ImplGetROPSalColor( SalROPColor nROPColor ) 636cdf0e10cSrcweir { 637cdf0e10cSrcweir SalColor nSalColor; 638cdf0e10cSrcweir if ( nROPColor == SAL_ROP_0 ) 639cdf0e10cSrcweir nSalColor = MAKE_SALCOLOR( 0, 0, 0 ); 640cdf0e10cSrcweir else 641cdf0e10cSrcweir nSalColor = MAKE_SALCOLOR( 255, 255, 255 ); 642cdf0e10cSrcweir return nSalColor; 643cdf0e10cSrcweir } 644cdf0e10cSrcweir 645cdf0e10cSrcweir void AquaSalGraphics::SetROPLineColor( SalROPColor nROPColor ) 646cdf0e10cSrcweir { 647cdf0e10cSrcweir if( ! mbPrinter ) 648cdf0e10cSrcweir SetLineColor( ImplGetROPSalColor( nROPColor ) ); 649cdf0e10cSrcweir } 650cdf0e10cSrcweir 651cdf0e10cSrcweir // ----------------------------------------------------------------------- 652cdf0e10cSrcweir 653cdf0e10cSrcweir void AquaSalGraphics::SetROPFillColor( SalROPColor nROPColor ) 654cdf0e10cSrcweir { 655cdf0e10cSrcweir if( ! mbPrinter ) 656cdf0e10cSrcweir SetFillColor( ImplGetROPSalColor( nROPColor ) ); 657cdf0e10cSrcweir } 658cdf0e10cSrcweir 659cdf0e10cSrcweir // ----------------------------------------------------------------------- 660cdf0e10cSrcweir 661cdf0e10cSrcweir void AquaSalGraphics::ImplDrawPixel( long nX, long nY, const RGBAColor& rColor ) 662cdf0e10cSrcweir { 663cdf0e10cSrcweir if( !CheckContext() ) 664cdf0e10cSrcweir return; 665cdf0e10cSrcweir 666cdf0e10cSrcweir // overwrite the fill color 667cdf0e10cSrcweir CGContextSetFillColor( mrContext, rColor.AsArray() ); 668cdf0e10cSrcweir // draw 1x1 rect, there is no pixel drawing in Quartz 669a94c8ebdSHerbert Dürr const CGRect aDstRect = CGRectMake( nX, nY, 1, 1); 670cdf0e10cSrcweir CGContextFillRect( mrContext, aDstRect ); 671cdf0e10cSrcweir RefreshRect( aDstRect ); 672cdf0e10cSrcweir // reset the fill color 673cdf0e10cSrcweir CGContextSetFillColor( mrContext, maFillColor.AsArray() ); 674cdf0e10cSrcweir } 675cdf0e10cSrcweir 676cdf0e10cSrcweir void AquaSalGraphics::drawPixel( long nX, long nY ) 677cdf0e10cSrcweir { 678cdf0e10cSrcweir // draw pixel with current line color 679cdf0e10cSrcweir ImplDrawPixel( nX, nY, maLineColor ); 680cdf0e10cSrcweir } 681cdf0e10cSrcweir 682cdf0e10cSrcweir void AquaSalGraphics::drawPixel( long nX, long nY, SalColor nSalColor ) 683cdf0e10cSrcweir { 684cdf0e10cSrcweir const RGBAColor aPixelColor( nSalColor ); 685cdf0e10cSrcweir ImplDrawPixel( nX, nY, aPixelColor ); 686cdf0e10cSrcweir } 687cdf0e10cSrcweir 688cdf0e10cSrcweir // ----------------------------------------------------------------------- 689cdf0e10cSrcweir 690cdf0e10cSrcweir void AquaSalGraphics::drawLine( long nX1, long nY1, long nX2, long nY2 ) 691cdf0e10cSrcweir { 692cdf0e10cSrcweir if( nX1 == nX2 && nY1 == nY2 ) 693cdf0e10cSrcweir { 694cdf0e10cSrcweir // #i109453# platform independent code expects at least one pixel to be drawn 695cdf0e10cSrcweir drawPixel( nX1, nY1 ); 696cdf0e10cSrcweir return; 697cdf0e10cSrcweir } 698cdf0e10cSrcweir 699cdf0e10cSrcweir if( !CheckContext() ) 700cdf0e10cSrcweir return; 701cdf0e10cSrcweir 702cdf0e10cSrcweir CGContextBeginPath( mrContext ); 703cdf0e10cSrcweir CGContextMoveToPoint( mrContext, static_cast<float>(nX1)+0.5, static_cast<float>(nY1)+0.5 ); 704cdf0e10cSrcweir CGContextAddLineToPoint( mrContext, static_cast<float>(nX2)+0.5, static_cast<float>(nY2)+0.5 ); 705cdf0e10cSrcweir CGContextDrawPath( mrContext, kCGPathStroke ); 706cdf0e10cSrcweir 707cdf0e10cSrcweir Rectangle aRefreshRect( nX1, nY1, nX2, nY2 ); 708cdf0e10cSrcweir } 709cdf0e10cSrcweir 710cdf0e10cSrcweir // ----------------------------------------------------------------------- 711cdf0e10cSrcweir 712cdf0e10cSrcweir void AquaSalGraphics::drawRect( long nX, long nY, long nWidth, long nHeight ) 713cdf0e10cSrcweir { 714cdf0e10cSrcweir if( !CheckContext() ) 715cdf0e10cSrcweir return; 716cdf0e10cSrcweir 717cdf0e10cSrcweir CGRect aRect( CGRectMake(nX, nY, nWidth, nHeight) ); 718cdf0e10cSrcweir if( IsPenVisible() ) 719cdf0e10cSrcweir { 720cdf0e10cSrcweir aRect.origin.x += 0.5; 721cdf0e10cSrcweir aRect.origin.y += 0.5; 722cdf0e10cSrcweir aRect.size.width -= 1; 723cdf0e10cSrcweir aRect.size.height -= 1; 724cdf0e10cSrcweir } 725cdf0e10cSrcweir 726cdf0e10cSrcweir if( IsBrushVisible() ) 727cdf0e10cSrcweir CGContextFillRect( mrContext, aRect ); 728cdf0e10cSrcweir 729cdf0e10cSrcweir if( IsPenVisible() ) 730cdf0e10cSrcweir CGContextStrokeRect( mrContext, aRect ); 731cdf0e10cSrcweir 732cdf0e10cSrcweir RefreshRect( nX, nY, nWidth, nHeight ); 733cdf0e10cSrcweir } 734cdf0e10cSrcweir 735cdf0e10cSrcweir // ----------------------------------------------------------------------- 736cdf0e10cSrcweir 73754ae6a37SHerbert Dürr static void getBoundRect( sal_uInt32 nPoints, const SalPoint* pPtAry, long &rX, long& rY, long& rWidth, long& rHeight ) 738cdf0e10cSrcweir { 739cdf0e10cSrcweir long nX1 = pPtAry->mnX; 740cdf0e10cSrcweir long nX2 = nX1; 741cdf0e10cSrcweir long nY1 = pPtAry->mnY; 742cdf0e10cSrcweir long nY2 = nY1; 74354ae6a37SHerbert Dürr for( sal_uInt32 n = 1; n < nPoints; ++n ) 744cdf0e10cSrcweir { 745cdf0e10cSrcweir if( pPtAry[n].mnX < nX1 ) 746cdf0e10cSrcweir nX1 = pPtAry[n].mnX; 747cdf0e10cSrcweir else if( pPtAry[n].mnX > nX2 ) 748cdf0e10cSrcweir nX2 = pPtAry[n].mnX; 749cdf0e10cSrcweir 750cdf0e10cSrcweir if( pPtAry[n].mnY < nY1 ) 751cdf0e10cSrcweir nY1 = pPtAry[n].mnY; 752cdf0e10cSrcweir else if( pPtAry[n].mnY > nY2 ) 753cdf0e10cSrcweir nY2 = pPtAry[n].mnY; 754cdf0e10cSrcweir } 755cdf0e10cSrcweir rX = nX1; 756cdf0e10cSrcweir rY = nY1; 757cdf0e10cSrcweir rWidth = nX2 - nX1 + 1; 758cdf0e10cSrcweir rHeight = nY2 - nY1 + 1; 759cdf0e10cSrcweir } 760cdf0e10cSrcweir 761cdf0e10cSrcweir static inline void alignLinePoint( const SalPoint* i_pIn, float& o_fX, float& o_fY ) 762cdf0e10cSrcweir { 763cdf0e10cSrcweir o_fX = static_cast<float>(i_pIn->mnX ) + 0.5; 764cdf0e10cSrcweir o_fY = static_cast<float>(i_pIn->mnY ) + 0.5; 765cdf0e10cSrcweir } 766cdf0e10cSrcweir 76754ae6a37SHerbert Dürr void AquaSalGraphics::drawPolyLine( sal_uInt32 nPoints, const SalPoint* pPtAry ) 768cdf0e10cSrcweir { 769cdf0e10cSrcweir if( nPoints < 1 ) 770cdf0e10cSrcweir return; 771cdf0e10cSrcweir if( !CheckContext() ) 772cdf0e10cSrcweir return; 773cdf0e10cSrcweir 774cdf0e10cSrcweir long nX = 0, nY = 0, nWidth = 0, nHeight = 0; 775cdf0e10cSrcweir getBoundRect( nPoints, pPtAry, nX, nY, nWidth, nHeight ); 776cdf0e10cSrcweir 777cdf0e10cSrcweir float fX, fY; 778cdf0e10cSrcweir 779cdf0e10cSrcweir CGContextBeginPath( mrContext ); 780cdf0e10cSrcweir alignLinePoint( pPtAry, fX, fY ); 781cdf0e10cSrcweir CGContextMoveToPoint( mrContext, fX, fY ); 782cdf0e10cSrcweir pPtAry++; 78354ae6a37SHerbert Dürr for( sal_uInt32 nPoint = 1; nPoint < nPoints; ++nPoint, ++pPtAry ) 784cdf0e10cSrcweir { 785cdf0e10cSrcweir alignLinePoint( pPtAry, fX, fY ); 786cdf0e10cSrcweir CGContextAddLineToPoint( mrContext, fX, fY ); 787cdf0e10cSrcweir } 788cdf0e10cSrcweir CGContextDrawPath( mrContext, kCGPathStroke ); 789cdf0e10cSrcweir 790cdf0e10cSrcweir RefreshRect( nX, nY, nWidth, nHeight ); 791cdf0e10cSrcweir } 792cdf0e10cSrcweir 793cdf0e10cSrcweir // ----------------------------------------------------------------------- 794cdf0e10cSrcweir 79554ae6a37SHerbert Dürr void AquaSalGraphics::drawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry ) 796cdf0e10cSrcweir { 797cdf0e10cSrcweir if( nPoints <= 1 ) 798cdf0e10cSrcweir return; 799cdf0e10cSrcweir if( !CheckContext() ) 800cdf0e10cSrcweir return; 801cdf0e10cSrcweir 802cdf0e10cSrcweir long nX = 0, nY = 0, nWidth = 0, nHeight = 0; 803cdf0e10cSrcweir getBoundRect( nPoints, pPtAry, nX, nY, nWidth, nHeight ); 804cdf0e10cSrcweir 805cdf0e10cSrcweir CGPathDrawingMode eMode; 806cdf0e10cSrcweir if( IsBrushVisible() && IsPenVisible() ) 807cdf0e10cSrcweir eMode = kCGPathEOFillStroke; 808cdf0e10cSrcweir else if( IsPenVisible() ) 809cdf0e10cSrcweir eMode = kCGPathStroke; 810cdf0e10cSrcweir else if( IsBrushVisible() ) 811cdf0e10cSrcweir eMode = kCGPathEOFill; 812cdf0e10cSrcweir else 813cdf0e10cSrcweir return; 814cdf0e10cSrcweir 815cdf0e10cSrcweir CGContextBeginPath( mrContext ); 816cdf0e10cSrcweir 817cdf0e10cSrcweir if( IsPenVisible() ) 818cdf0e10cSrcweir { 819cdf0e10cSrcweir float fX, fY; 820cdf0e10cSrcweir alignLinePoint( pPtAry, fX, fY ); 821cdf0e10cSrcweir CGContextMoveToPoint( mrContext, fX, fY ); 822cdf0e10cSrcweir pPtAry++; 82354ae6a37SHerbert Dürr for( sal_uInt32 nPoint = 1; nPoint < nPoints; ++nPoint, ++pPtAry ) 824cdf0e10cSrcweir { 825cdf0e10cSrcweir alignLinePoint( pPtAry, fX, fY ); 826cdf0e10cSrcweir CGContextAddLineToPoint( mrContext, fX, fY ); 827cdf0e10cSrcweir } 828cdf0e10cSrcweir } 829cdf0e10cSrcweir else 830cdf0e10cSrcweir { 831cdf0e10cSrcweir CGContextMoveToPoint( mrContext, pPtAry->mnX, pPtAry->mnY ); 832cdf0e10cSrcweir pPtAry++; 83354ae6a37SHerbert Dürr for( sal_uInt32 nPoint = 1; nPoint < nPoints; ++nPoint, ++pPtAry ) 834cdf0e10cSrcweir CGContextAddLineToPoint( mrContext, pPtAry->mnX, pPtAry->mnY ); 835cdf0e10cSrcweir } 836cdf0e10cSrcweir 837cdf0e10cSrcweir CGContextDrawPath( mrContext, eMode ); 838cdf0e10cSrcweir RefreshRect( nX, nY, nWidth, nHeight ); 839cdf0e10cSrcweir } 840cdf0e10cSrcweir 841cdf0e10cSrcweir // ----------------------------------------------------------------------- 842cdf0e10cSrcweir 84354ae6a37SHerbert Dürr void AquaSalGraphics::drawPolyPolygon( sal_uInt32 nPolyCount, const sal_uInt32* pPoints, PCONSTSALPOINT* ppPtAry ) 844cdf0e10cSrcweir { 845cdf0e10cSrcweir if( nPolyCount <= 0 ) 846cdf0e10cSrcweir return; 847cdf0e10cSrcweir if( !CheckContext() ) 848cdf0e10cSrcweir return; 849cdf0e10cSrcweir 850cdf0e10cSrcweir // find bound rect 851cdf0e10cSrcweir long leftX = 0, topY = 0, maxWidth = 0, maxHeight = 0; 852cdf0e10cSrcweir getBoundRect( pPoints[0], ppPtAry[0], leftX, topY, maxWidth, maxHeight ); 853cdf0e10cSrcweir for( sal_uLong n = 1; n < nPolyCount; n++ ) 854cdf0e10cSrcweir { 855cdf0e10cSrcweir long nX = leftX, nY = topY, nW = maxWidth, nH = maxHeight; 856cdf0e10cSrcweir getBoundRect( pPoints[n], ppPtAry[n], nX, nY, nW, nH ); 857cdf0e10cSrcweir if( nX < leftX ) 858cdf0e10cSrcweir { 859cdf0e10cSrcweir maxWidth += leftX - nX; 860cdf0e10cSrcweir leftX = nX; 861cdf0e10cSrcweir } 862cdf0e10cSrcweir if( nY < topY ) 863cdf0e10cSrcweir { 864cdf0e10cSrcweir maxHeight += topY - nY; 865cdf0e10cSrcweir topY = nY; 866cdf0e10cSrcweir } 867cdf0e10cSrcweir if( nX + nW > leftX + maxWidth ) 868cdf0e10cSrcweir maxWidth = nX + nW - leftX; 869cdf0e10cSrcweir if( nY + nH > topY + maxHeight ) 870cdf0e10cSrcweir maxHeight = nY + nH - topY; 871cdf0e10cSrcweir } 872cdf0e10cSrcweir 873cdf0e10cSrcweir // prepare drawing mode 874cdf0e10cSrcweir CGPathDrawingMode eMode; 875cdf0e10cSrcweir if( IsBrushVisible() && IsPenVisible() ) 876cdf0e10cSrcweir eMode = kCGPathEOFillStroke; 877cdf0e10cSrcweir else if( IsPenVisible() ) 878cdf0e10cSrcweir eMode = kCGPathStroke; 879cdf0e10cSrcweir else if( IsBrushVisible() ) 880cdf0e10cSrcweir eMode = kCGPathEOFill; 881cdf0e10cSrcweir else 882cdf0e10cSrcweir return; 883cdf0e10cSrcweir 884cdf0e10cSrcweir // convert to CGPath 885cdf0e10cSrcweir CGContextBeginPath( mrContext ); 886cdf0e10cSrcweir if( IsPenVisible() ) 887cdf0e10cSrcweir { 888cdf0e10cSrcweir for( sal_uLong nPoly = 0; nPoly < nPolyCount; nPoly++ ) 889cdf0e10cSrcweir { 89054ae6a37SHerbert Dürr const sal_uInt32 nPoints = pPoints[nPoly]; 891cdf0e10cSrcweir if( nPoints > 1 ) 892cdf0e10cSrcweir { 893cdf0e10cSrcweir const SalPoint *pPtAry = ppPtAry[nPoly]; 894cdf0e10cSrcweir float fX, fY; 895cdf0e10cSrcweir alignLinePoint( pPtAry, fX, fY ); 896cdf0e10cSrcweir CGContextMoveToPoint( mrContext, fX, fY ); 897cdf0e10cSrcweir pPtAry++; 89854ae6a37SHerbert Dürr for( sal_uInt32 nPoint = 1; nPoint < nPoints; ++nPoint, ++pPtAry ) 899cdf0e10cSrcweir { 900cdf0e10cSrcweir alignLinePoint( pPtAry, fX, fY ); 901cdf0e10cSrcweir CGContextAddLineToPoint( mrContext, fX, fY ); 902cdf0e10cSrcweir } 903cdf0e10cSrcweir CGContextClosePath(mrContext); 904cdf0e10cSrcweir } 905cdf0e10cSrcweir } 906cdf0e10cSrcweir } 907cdf0e10cSrcweir else 908cdf0e10cSrcweir { 909cdf0e10cSrcweir for( sal_uLong nPoly = 0; nPoly < nPolyCount; nPoly++ ) 910cdf0e10cSrcweir { 91154ae6a37SHerbert Dürr const sal_uInt32 nPoints = pPoints[nPoly]; 912cdf0e10cSrcweir if( nPoints > 1 ) 913cdf0e10cSrcweir { 914cdf0e10cSrcweir const SalPoint *pPtAry = ppPtAry[nPoly]; 915cdf0e10cSrcweir CGContextMoveToPoint( mrContext, pPtAry->mnX, pPtAry->mnY ); 916cdf0e10cSrcweir pPtAry++; 91754ae6a37SHerbert Dürr for( sal_uInt32 nPoint = 1; nPoint < nPoints; ++nPoint, ++pPtAry ) 918cdf0e10cSrcweir CGContextAddLineToPoint( mrContext, pPtAry->mnX, pPtAry->mnY ); 919cdf0e10cSrcweir CGContextClosePath(mrContext); 920cdf0e10cSrcweir } 921cdf0e10cSrcweir } 922cdf0e10cSrcweir } 923cdf0e10cSrcweir 924cdf0e10cSrcweir CGContextDrawPath( mrContext, eMode ); 925cdf0e10cSrcweir 926cdf0e10cSrcweir RefreshRect( leftX, topY, maxWidth, maxHeight ); 927cdf0e10cSrcweir } 928cdf0e10cSrcweir 929cdf0e10cSrcweir // ----------------------------------------------------------------------- 930cdf0e10cSrcweir 931cdf0e10cSrcweir bool AquaSalGraphics::drawPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly, 932cdf0e10cSrcweir double fTransparency ) 933cdf0e10cSrcweir { 934cdf0e10cSrcweir // short circuit if there is nothing to do 935cdf0e10cSrcweir const int nPolyCount = rPolyPoly.count(); 936cdf0e10cSrcweir if( nPolyCount <= 0 ) 937cdf0e10cSrcweir return true; 938cdf0e10cSrcweir 939cdf0e10cSrcweir // ignore invisible polygons 940cdf0e10cSrcweir if( (fTransparency >= 1.0) || (fTransparency < 0) ) 941cdf0e10cSrcweir return true; 942cdf0e10cSrcweir 943cdf0e10cSrcweir // setup poly-polygon path 944cdf0e10cSrcweir CGMutablePathRef xPath = CGPathCreateMutable(); 945cdf0e10cSrcweir for( int nPolyIdx = 0; nPolyIdx < nPolyCount; ++nPolyIdx ) 946cdf0e10cSrcweir { 947cdf0e10cSrcweir const ::basegfx::B2DPolygon rPolygon = rPolyPoly.getB2DPolygon( nPolyIdx ); 948cdf0e10cSrcweir AddPolygonToPath( xPath, rPolygon, true, !getAntiAliasB2DDraw(), IsPenVisible() ); 949cdf0e10cSrcweir } 950cdf0e10cSrcweir 951cdf0e10cSrcweir const CGRect aRefreshRect = CGPathGetBoundingBox( xPath ); 952cdf0e10cSrcweir #ifndef NO_I97317_WORKAROUND 953cdf0e10cSrcweir // #i97317# workaround for Quartz having problems with drawing small polygons 954cdf0e10cSrcweir if( ! ((aRefreshRect.size.width <= 0.125) && (aRefreshRect.size.height <= 0.125)) ) 955cdf0e10cSrcweir #endif 956cdf0e10cSrcweir { 957cdf0e10cSrcweir // use the path to prepare the graphics context 958cdf0e10cSrcweir CGContextSaveGState( mrContext ); 959cdf0e10cSrcweir CGContextBeginPath( mrContext ); 960cdf0e10cSrcweir CGContextAddPath( mrContext, xPath ); 961cdf0e10cSrcweir 962cdf0e10cSrcweir // draw path with antialiased polygon 963cdf0e10cSrcweir CGContextSetShouldAntialias( mrContext, true ); 964cdf0e10cSrcweir CGContextSetAlpha( mrContext, 1.0 - fTransparency ); 965cdf0e10cSrcweir CGContextDrawPath( mrContext, kCGPathEOFillStroke ); 966cdf0e10cSrcweir CGContextRestoreGState( mrContext ); 967cdf0e10cSrcweir 968cdf0e10cSrcweir // mark modified rectangle as updated 969cdf0e10cSrcweir RefreshRect( aRefreshRect ); 970cdf0e10cSrcweir } 971cdf0e10cSrcweir 972cdf0e10cSrcweir CGPathRelease( xPath ); 973cdf0e10cSrcweir 974cdf0e10cSrcweir return true; 975cdf0e10cSrcweir } 976cdf0e10cSrcweir 977cdf0e10cSrcweir // ----------------------------------------------------------------------- 978cdf0e10cSrcweir 9795aaf853bSArmin Le Grand bool AquaSalGraphics::drawPolyLine( 9805aaf853bSArmin Le Grand const ::basegfx::B2DPolygon& rPolyLine, 981cdf0e10cSrcweir double fTransparency, 982cdf0e10cSrcweir const ::basegfx::B2DVector& rLineWidths, 9835aaf853bSArmin Le Grand basegfx::B2DLineJoin eLineJoin, 9845aaf853bSArmin Le Grand com::sun::star::drawing::LineCap eLineCap) 985cdf0e10cSrcweir { 986cdf0e10cSrcweir // short circuit if there is nothing to do 987cdf0e10cSrcweir const int nPointCount = rPolyLine.count(); 988cdf0e10cSrcweir if( nPointCount <= 0 ) 989cdf0e10cSrcweir return true; 990cdf0e10cSrcweir 991cdf0e10cSrcweir // reject requests that cannot be handled yet 992cdf0e10cSrcweir if( rLineWidths.getX() != rLineWidths.getY() ) 993cdf0e10cSrcweir return false; 994cdf0e10cSrcweir 995cdf0e10cSrcweir // #i101491# Aqua does not support B2DLINEJOIN_NONE; return false to use 996cdf0e10cSrcweir // the fallback (own geometry preparation) 997cdf0e10cSrcweir // #i104886# linejoin-mode and thus the above only applies to "fat" lines 998cdf0e10cSrcweir if( (basegfx::B2DLINEJOIN_NONE == eLineJoin) 999cdf0e10cSrcweir && (rLineWidths.getX() > 1.3) ) 1000cdf0e10cSrcweir return false; 1001cdf0e10cSrcweir 1002cdf0e10cSrcweir // setup line attributes 1003cdf0e10cSrcweir CGLineJoin aCGLineJoin = kCGLineJoinMiter; 1004cdf0e10cSrcweir switch( eLineJoin ) { 1005cdf0e10cSrcweir case ::basegfx::B2DLINEJOIN_NONE: aCGLineJoin = /*TODO?*/kCGLineJoinMiter; break; 1006cdf0e10cSrcweir case ::basegfx::B2DLINEJOIN_MIDDLE: aCGLineJoin = /*TODO?*/kCGLineJoinMiter; break; 1007cdf0e10cSrcweir case ::basegfx::B2DLINEJOIN_BEVEL: aCGLineJoin = kCGLineJoinBevel; break; 1008cdf0e10cSrcweir case ::basegfx::B2DLINEJOIN_MITER: aCGLineJoin = kCGLineJoinMiter; break; 1009cdf0e10cSrcweir case ::basegfx::B2DLINEJOIN_ROUND: aCGLineJoin = kCGLineJoinRound; break; 1010cdf0e10cSrcweir } 1011cdf0e10cSrcweir 10123324c5beSArmin Le Grand // setup cap attribute 10133324c5beSArmin Le Grand CGLineCap aCGLineCap(kCGLineCapButt); 10143324c5beSArmin Le Grand 10153324c5beSArmin Le Grand switch(eLineCap) 10163324c5beSArmin Le Grand { 10173324c5beSArmin Le Grand default: // com::sun::star::drawing::LineCap_BUTT: 10183324c5beSArmin Le Grand { 10193324c5beSArmin Le Grand aCGLineCap = kCGLineCapButt; 10203324c5beSArmin Le Grand break; 10213324c5beSArmin Le Grand } 10223324c5beSArmin Le Grand case com::sun::star::drawing::LineCap_ROUND: 10233324c5beSArmin Le Grand { 10243324c5beSArmin Le Grand aCGLineCap = kCGLineCapRound; 10253324c5beSArmin Le Grand break; 10263324c5beSArmin Le Grand } 10273324c5beSArmin Le Grand case com::sun::star::drawing::LineCap_SQUARE: 10283324c5beSArmin Le Grand { 10293324c5beSArmin Le Grand aCGLineCap = kCGLineCapSquare; 10303324c5beSArmin Le Grand break; 10313324c5beSArmin Le Grand } 10323324c5beSArmin Le Grand } 10333324c5beSArmin Le Grand 1034cdf0e10cSrcweir // setup poly-polygon path 1035cdf0e10cSrcweir CGMutablePathRef xPath = CGPathCreateMutable(); 1036cdf0e10cSrcweir AddPolygonToPath( xPath, rPolyLine, rPolyLine.isClosed(), !getAntiAliasB2DDraw(), true ); 1037cdf0e10cSrcweir 1038cdf0e10cSrcweir const CGRect aRefreshRect = CGPathGetBoundingBox( xPath ); 1039cdf0e10cSrcweir #ifndef NO_I97317_WORKAROUND 1040cdf0e10cSrcweir // #i97317# workaround for Quartz having problems with drawing small polygons 1041cdf0e10cSrcweir if( ! ((aRefreshRect.size.width <= 0.125) && (aRefreshRect.size.height <= 0.125)) ) 1042cdf0e10cSrcweir #endif 1043cdf0e10cSrcweir { 1044cdf0e10cSrcweir // use the path to prepare the graphics context 1045cdf0e10cSrcweir CGContextSaveGState( mrContext ); 1046cdf0e10cSrcweir CGContextAddPath( mrContext, xPath ); 1047cdf0e10cSrcweir // draw path with antialiased line 1048cdf0e10cSrcweir CGContextSetShouldAntialias( mrContext, true ); 1049cdf0e10cSrcweir CGContextSetAlpha( mrContext, 1.0 - fTransparency ); 1050cdf0e10cSrcweir CGContextSetLineJoin( mrContext, aCGLineJoin ); 10513324c5beSArmin Le Grand CGContextSetLineCap( mrContext, aCGLineCap ); 1052cdf0e10cSrcweir CGContextSetLineWidth( mrContext, rLineWidths.getX() ); 1053cdf0e10cSrcweir CGContextDrawPath( mrContext, kCGPathStroke ); 1054cdf0e10cSrcweir CGContextRestoreGState( mrContext ); 1055cdf0e10cSrcweir 1056cdf0e10cSrcweir // mark modified rectangle as updated 1057cdf0e10cSrcweir RefreshRect( aRefreshRect ); 1058cdf0e10cSrcweir } 1059cdf0e10cSrcweir 1060cdf0e10cSrcweir CGPathRelease( xPath ); 1061cdf0e10cSrcweir 1062cdf0e10cSrcweir return true; 1063cdf0e10cSrcweir } 1064cdf0e10cSrcweir 1065cdf0e10cSrcweir // ----------------------------------------------------------------------- 1066cdf0e10cSrcweir 106754ae6a37SHerbert Dürr sal_Bool AquaSalGraphics::drawPolyLineBezier( sal_uInt32, const SalPoint*, const sal_uInt8* ) 1068cdf0e10cSrcweir { 1069cdf0e10cSrcweir return sal_False; 1070cdf0e10cSrcweir } 1071cdf0e10cSrcweir 1072cdf0e10cSrcweir // ----------------------------------------------------------------------- 1073cdf0e10cSrcweir 107454ae6a37SHerbert Dürr sal_Bool AquaSalGraphics::drawPolygonBezier( sal_uInt32, const SalPoint*, const sal_uInt8* ) 1075cdf0e10cSrcweir { 1076cdf0e10cSrcweir return sal_False; 1077cdf0e10cSrcweir } 1078cdf0e10cSrcweir 1079cdf0e10cSrcweir // ----------------------------------------------------------------------- 1080cdf0e10cSrcweir 108154ae6a37SHerbert Dürr sal_Bool AquaSalGraphics::drawPolyPolygonBezier( sal_uInt32, const sal_uInt32*, 1082cdf0e10cSrcweir const SalPoint* const*, const sal_uInt8* const* ) 1083cdf0e10cSrcweir { 1084cdf0e10cSrcweir return sal_False; 1085cdf0e10cSrcweir } 1086cdf0e10cSrcweir 1087cdf0e10cSrcweir // ----------------------------------------------------------------------- 1088cdf0e10cSrcweir 10895f27b83cSArmin Le Grand void AquaSalGraphics::copyBits( const SalTwoRect& rPosAry, SalGraphics *pSrcGraphics ) 1090cdf0e10cSrcweir { 1091cdf0e10cSrcweir if( !pSrcGraphics ) 1092cdf0e10cSrcweir pSrcGraphics = this; 1093cdf0e10cSrcweir 1094cdf0e10cSrcweir //from unix salgdi2.cxx 1095cdf0e10cSrcweir //[FIXME] find a better way to prevent calc from crashing when width and height are negative 10965f27b83cSArmin Le Grand if( rPosAry.mnSrcWidth <= 0 10975f27b83cSArmin Le Grand || rPosAry.mnSrcHeight <= 0 10985f27b83cSArmin Le Grand || rPosAry.mnDestWidth <= 0 10995f27b83cSArmin Le Grand || rPosAry.mnDestHeight <= 0 ) 1100cdf0e10cSrcweir { 1101cdf0e10cSrcweir return; 1102cdf0e10cSrcweir } 1103cdf0e10cSrcweir 1104cdf0e10cSrcweir // accelerate trivial operations 1105cdf0e10cSrcweir /*const*/ AquaSalGraphics* pSrc = static_cast<AquaSalGraphics*>(pSrcGraphics); 1106cdf0e10cSrcweir const bool bSameGraphics = (this == pSrc) || (mbWindow && mpFrame && pSrc->mbWindow && (mpFrame == pSrc->mpFrame)); 1107cdf0e10cSrcweir if( bSameGraphics 11085f27b83cSArmin Le Grand && (rPosAry.mnSrcWidth == rPosAry.mnDestWidth) 11095f27b83cSArmin Le Grand && (rPosAry.mnSrcHeight == rPosAry.mnDestHeight)) 1110cdf0e10cSrcweir { 1111cdf0e10cSrcweir // short circuit if there is nothing to do 11125f27b83cSArmin Le Grand if( (rPosAry.mnSrcX == rPosAry.mnDestX) 11135f27b83cSArmin Le Grand && (rPosAry.mnSrcY == rPosAry.mnDestY)) 1114cdf0e10cSrcweir return; 1115cdf0e10cSrcweir // use copyArea() if source and destination context are identical 11165f27b83cSArmin Le Grand copyArea( rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnSrcX, rPosAry.mnSrcY, 11175f27b83cSArmin Le Grand rPosAry.mnSrcWidth, rPosAry.mnSrcHeight, 0 ); 1118cdf0e10cSrcweir return; 1119cdf0e10cSrcweir } 1120cdf0e10cSrcweir 1121cdf0e10cSrcweir ApplyXorContext(); 1122cdf0e10cSrcweir pSrc->ApplyXorContext(); 1123cdf0e10cSrcweir 1124cdf0e10cSrcweir DBG_ASSERT( pSrc->mxLayer!=NULL, "AquaSalGraphics::copyBits() from non-layered graphics" ); 1125cdf0e10cSrcweir 1126a94c8ebdSHerbert Dürr const CGPoint aDstPoint = CGPointMake( +rPosAry.mnDestX - rPosAry.mnSrcX, rPosAry.mnDestY - rPosAry.mnSrcY); 11275f27b83cSArmin Le Grand if( (rPosAry.mnSrcWidth == rPosAry.mnDestWidth && rPosAry.mnSrcHeight == rPosAry.mnDestHeight) && 1128cdf0e10cSrcweir (!mnBitmapDepth || (aDstPoint.x + pSrc->mnWidth) <= mnWidth) ) // workaround a Quartz crasher 1129cdf0e10cSrcweir { 1130cdf0e10cSrcweir // in XOR mode the drawing context is redirected to the XOR mask 1131cdf0e10cSrcweir // if source and target are identical then copyBits() paints onto the target context though 1132cdf0e10cSrcweir CGContextRef xCopyContext = mrContext; 1133cdf0e10cSrcweir if( mpXorEmulation && mpXorEmulation->IsEnabled() ) 1134cdf0e10cSrcweir if( pSrcGraphics == this ) 1135cdf0e10cSrcweir xCopyContext = mpXorEmulation->GetTargetContext(); 1136cdf0e10cSrcweir 1137cdf0e10cSrcweir CGContextSaveGState( xCopyContext ); 1138a94c8ebdSHerbert Dürr const CGRect aDstRect = CGRectMake( rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth, rPosAry.mnDestHeight); 1139cdf0e10cSrcweir CGContextClipToRect( xCopyContext, aDstRect ); 1140cdf0e10cSrcweir 1141cdf0e10cSrcweir // draw at new destination 1142cdf0e10cSrcweir // NOTE: flipped drawing gets disabled for this, else the subimage would be drawn upside down 1143cdf0e10cSrcweir if( pSrc->IsFlipped() ) 1144cdf0e10cSrcweir { CGContextTranslateCTM( xCopyContext, 0, +mnHeight ); CGContextScaleCTM( xCopyContext, +1, -1 ); } 1145cdf0e10cSrcweir // TODO: pSrc->size() != this->size() 1146cdf0e10cSrcweir ::CGContextDrawLayerAtPoint( xCopyContext, aDstPoint, pSrc->mxLayer ); 1147cdf0e10cSrcweir CGContextRestoreGState( xCopyContext ); 1148cdf0e10cSrcweir // mark the destination rectangle as updated 1149cdf0e10cSrcweir RefreshRect( aDstRect ); 1150cdf0e10cSrcweir } 1151cdf0e10cSrcweir else 1152cdf0e10cSrcweir { 11535f27b83cSArmin Le Grand SalBitmap* pBitmap = pSrc->getBitmap( rPosAry.mnSrcX, rPosAry.mnSrcY, rPosAry.mnSrcWidth, rPosAry.mnSrcHeight ); 1154cdf0e10cSrcweir 1155cdf0e10cSrcweir if( pBitmap ) 1156cdf0e10cSrcweir { 11575f27b83cSArmin Le Grand SalTwoRect aPosAry( rPosAry ); 1158cdf0e10cSrcweir aPosAry.mnSrcX = 0; 1159cdf0e10cSrcweir aPosAry.mnSrcY = 0; 11605f27b83cSArmin Le Grand drawBitmap( aPosAry, *pBitmap ); 1161cdf0e10cSrcweir delete pBitmap; 1162cdf0e10cSrcweir } 1163cdf0e10cSrcweir } 1164cdf0e10cSrcweir } 1165cdf0e10cSrcweir 1166cdf0e10cSrcweir // ----------------------------------------------------------------------- 1167cdf0e10cSrcweir 1168cdf0e10cSrcweir void AquaSalGraphics::copyArea( long nDstX, long nDstY,long nSrcX, long nSrcY, long nSrcWidth, long nSrcHeight, sal_uInt16 /*nFlags*/ ) 1169cdf0e10cSrcweir { 1170cdf0e10cSrcweir ApplyXorContext(); 1171cdf0e10cSrcweir 1172cdf0e10cSrcweir #if 0 // TODO: make AquaSalBitmap as fast as the alternative implementation below 1173cdf0e10cSrcweir SalBitmap* pBitmap = getBitmap( nSrcX, nSrcY, nSrcWidth, nSrcHeight ); 1174cdf0e10cSrcweir if( pBitmap ) 1175cdf0e10cSrcweir { 1176cdf0e10cSrcweir SalTwoRect aPosAry; 1177cdf0e10cSrcweir aPosAry.mnSrcX = 0; 1178cdf0e10cSrcweir aPosAry.mnSrcY = 0; 1179cdf0e10cSrcweir aPosAry.mnSrcWidth = nSrcWidth; 1180cdf0e10cSrcweir aPosAry.mnSrcHeight = nSrcHeight; 1181cdf0e10cSrcweir aPosAry.mnDestX = nDstX; 1182cdf0e10cSrcweir aPosAry.mnDestY = nDstY; 1183cdf0e10cSrcweir aPosAry.mnDestWidth = nSrcWidth; 1184cdf0e10cSrcweir aPosAry.mnDestHeight = nSrcHeight; 11855f27b83cSArmin Le Grand drawBitmap( aPosAry, *pBitmap ); 1186cdf0e10cSrcweir delete pBitmap; 1187cdf0e10cSrcweir } 1188cdf0e10cSrcweir #else 1189cdf0e10cSrcweir DBG_ASSERT( mxLayer!=NULL, "AquaSalGraphics::copyArea() for non-layered graphics" ); 1190cdf0e10cSrcweir 1191cdf0e10cSrcweir // in XOR mode the drawing context is redirected to the XOR mask 1192cdf0e10cSrcweir // copyArea() always works on the target context though 1193cdf0e10cSrcweir CGContextRef xCopyContext = mrContext; 1194cdf0e10cSrcweir if( mpXorEmulation && mpXorEmulation->IsEnabled() ) 1195cdf0e10cSrcweir xCopyContext = mpXorEmulation->GetTargetContext(); 1196cdf0e10cSrcweir 1197cdf0e10cSrcweir // drawing a layer onto its own context causes trouble on OSX => copy it first 1198cdf0e10cSrcweir // TODO: is it possible to get rid of this unneeded copy more often? 1199cdf0e10cSrcweir // e.g. on OSX>=10.5 only this situation causes problems: 1200cdf0e10cSrcweir // mnBitmapDepth && (aDstPoint.x + pSrc->mnWidth) > mnWidth 1201cdf0e10cSrcweir CGLayerRef xSrcLayer = mxLayer; 1202cdf0e10cSrcweir // TODO: if( mnBitmapDepth > 0 ) 1203cdf0e10cSrcweir { 1204a94c8ebdSHerbert Dürr const CGSize aSrcSize = CGSizeMake( nSrcWidth, nSrcHeight); 1205cdf0e10cSrcweir xSrcLayer = ::CGLayerCreateWithContext( xCopyContext, aSrcSize, NULL ); 1206cdf0e10cSrcweir const CGContextRef xSrcContext = CGLayerGetContext( xSrcLayer ); 1207a94c8ebdSHerbert Dürr CGPoint aSrcPoint = CGPointMake( -nSrcX, -nSrcY); 1208cdf0e10cSrcweir if( IsFlipped() ) 1209cdf0e10cSrcweir { 1210cdf0e10cSrcweir ::CGContextTranslateCTM( xSrcContext, 0, +nSrcHeight ); 1211cdf0e10cSrcweir ::CGContextScaleCTM( xSrcContext, +1, -1 ); 1212cdf0e10cSrcweir aSrcPoint.y = (nSrcY + nSrcHeight) - mnHeight; 1213cdf0e10cSrcweir } 1214cdf0e10cSrcweir ::CGContextDrawLayerAtPoint( xSrcContext, aSrcPoint, mxLayer ); 1215cdf0e10cSrcweir } 1216cdf0e10cSrcweir 1217cdf0e10cSrcweir // draw at new destination 1218a94c8ebdSHerbert Dürr const CGPoint aDstPoint = CGPointMake( +nDstX, +nDstY); 1219cdf0e10cSrcweir ::CGContextDrawLayerAtPoint( xCopyContext, aDstPoint, xSrcLayer ); 1220cdf0e10cSrcweir 1221cdf0e10cSrcweir // cleanup 1222cdf0e10cSrcweir if( xSrcLayer != mxLayer ) 1223cdf0e10cSrcweir CGLayerRelease( xSrcLayer ); 1224cdf0e10cSrcweir 1225cdf0e10cSrcweir // mark the destination rectangle as updated 1226cdf0e10cSrcweir RefreshRect( nDstX, nDstY, nSrcWidth, nSrcHeight ); 1227cdf0e10cSrcweir #endif 1228cdf0e10cSrcweir } 1229cdf0e10cSrcweir 1230cdf0e10cSrcweir // ----------------------------------------------------------------------- 1231cdf0e10cSrcweir 12325f27b83cSArmin Le Grand void AquaSalGraphics::drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap ) 1233cdf0e10cSrcweir { 1234cdf0e10cSrcweir if( !CheckContext() ) 1235cdf0e10cSrcweir return; 1236cdf0e10cSrcweir 1237cdf0e10cSrcweir const AquaSalBitmap& rBitmap = static_cast<const AquaSalBitmap&>(rSalBitmap); 12385f27b83cSArmin Le Grand CGImageRef xImage = rBitmap.CreateCroppedImage( (int)rPosAry.mnSrcX, (int)rPosAry.mnSrcY, (int)rPosAry.mnSrcWidth, (int)rPosAry.mnSrcHeight ); 1239cdf0e10cSrcweir if( !xImage ) 1240cdf0e10cSrcweir return; 1241cdf0e10cSrcweir 1242a94c8ebdSHerbert Dürr const CGRect aDstRect = CGRectMake( rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth, rPosAry.mnDestHeight); 1243cdf0e10cSrcweir CGContextDrawImage( mrContext, aDstRect, xImage ); 1244cdf0e10cSrcweir CGImageRelease( xImage ); 1245cdf0e10cSrcweir RefreshRect( aDstRect ); 1246cdf0e10cSrcweir } 1247cdf0e10cSrcweir 1248cdf0e10cSrcweir // ----------------------------------------------------------------------- 1249cdf0e10cSrcweir 12505f27b83cSArmin Le Grand void AquaSalGraphics::drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap,SalColor ) 1251cdf0e10cSrcweir { 1252a94c8ebdSHerbert Dürr DBG_ERROR( "not implemented for color masking!"); 12535f27b83cSArmin Le Grand drawBitmap( rPosAry, rSalBitmap ); 1254cdf0e10cSrcweir } 1255cdf0e10cSrcweir 1256cdf0e10cSrcweir // ----------------------------------------------------------------------- 1257cdf0e10cSrcweir 12585f27b83cSArmin Le Grand void AquaSalGraphics::drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap, const SalBitmap& rTransparentBitmap ) 1259cdf0e10cSrcweir { 1260cdf0e10cSrcweir if( !CheckContext() ) 1261cdf0e10cSrcweir return; 1262cdf0e10cSrcweir 1263cdf0e10cSrcweir const AquaSalBitmap& rBitmap = static_cast<const AquaSalBitmap&>(rSalBitmap); 1264cdf0e10cSrcweir const AquaSalBitmap& rMask = static_cast<const AquaSalBitmap&>(rTransparentBitmap); 12655f27b83cSArmin Le Grand CGImageRef xMaskedImage( rBitmap.CreateWithMask( rMask, rPosAry.mnSrcX, rPosAry.mnSrcY, rPosAry.mnSrcWidth, rPosAry.mnSrcHeight ) ); 1266cdf0e10cSrcweir if( !xMaskedImage ) 1267cdf0e10cSrcweir return; 1268cdf0e10cSrcweir 1269a94c8ebdSHerbert Dürr const CGRect aDstRect = CGRectMake( rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth, rPosAry.mnDestHeight); 1270cdf0e10cSrcweir CGContextDrawImage( mrContext, aDstRect, xMaskedImage ); 1271cdf0e10cSrcweir CGImageRelease( xMaskedImage ); 1272cdf0e10cSrcweir RefreshRect( aDstRect ); 1273cdf0e10cSrcweir } 1274cdf0e10cSrcweir 1275cdf0e10cSrcweir // ----------------------------------------------------------------------- 1276cdf0e10cSrcweir 12775f27b83cSArmin Le Grand void AquaSalGraphics::drawMask( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap, SalColor nMaskColor ) 1278cdf0e10cSrcweir { 1279cdf0e10cSrcweir if( !CheckContext() ) 1280cdf0e10cSrcweir return; 1281cdf0e10cSrcweir 1282cdf0e10cSrcweir const AquaSalBitmap& rBitmap = static_cast<const AquaSalBitmap&>(rSalBitmap); 12835f27b83cSArmin Le Grand CGImageRef xImage = rBitmap.CreateColorMask( rPosAry.mnSrcX, rPosAry.mnSrcY, rPosAry.mnSrcWidth, rPosAry.mnSrcHeight, nMaskColor ); 1284cdf0e10cSrcweir if( !xImage ) 1285cdf0e10cSrcweir return; 1286cdf0e10cSrcweir 1287a94c8ebdSHerbert Dürr const CGRect aDstRect = CGRectMake( rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth, rPosAry.mnDestHeight); 1288cdf0e10cSrcweir CGContextDrawImage( mrContext, aDstRect, xImage ); 1289cdf0e10cSrcweir CGImageRelease( xImage ); 1290cdf0e10cSrcweir RefreshRect( aDstRect ); 1291cdf0e10cSrcweir } 1292cdf0e10cSrcweir 1293cdf0e10cSrcweir // ----------------------------------------------------------------------- 1294cdf0e10cSrcweir 1295cdf0e10cSrcweir SalBitmap* AquaSalGraphics::getBitmap( long nX, long nY, long nDX, long nDY ) 1296cdf0e10cSrcweir { 1297cdf0e10cSrcweir DBG_ASSERT( mxLayer, "AquaSalGraphics::getBitmap() with no layer" ); 1298cdf0e10cSrcweir 1299cdf0e10cSrcweir ApplyXorContext(); 1300cdf0e10cSrcweir 1301cdf0e10cSrcweir AquaSalBitmap* pBitmap = new AquaSalBitmap; 1302cdf0e10cSrcweir if( !pBitmap->Create( mxLayer, mnBitmapDepth, nX, nY, nDX, nDY, !mbWindow ) ) 1303cdf0e10cSrcweir { 1304cdf0e10cSrcweir delete pBitmap; 1305cdf0e10cSrcweir pBitmap = NULL; 1306cdf0e10cSrcweir } 1307cdf0e10cSrcweir 1308cdf0e10cSrcweir return pBitmap; 1309cdf0e10cSrcweir } 1310cdf0e10cSrcweir 1311cdf0e10cSrcweir // ----------------------------------------------------------------------- 1312cdf0e10cSrcweir 1313cdf0e10cSrcweir SalColor AquaSalGraphics::getPixel( long nX, long nY ) 1314cdf0e10cSrcweir { 1315cdf0e10cSrcweir // return default value on printers or when out of bounds 1316cdf0e10cSrcweir if( !mxLayer 1317cdf0e10cSrcweir || (nX < 0) || (nX >= mnWidth) 1318cdf0e10cSrcweir || (nY < 0) || (nY >= mnHeight)) 1319cdf0e10cSrcweir return COL_BLACK; 1320cdf0e10cSrcweir 1321cdf0e10cSrcweir // prepare creation of matching a CGBitmapContext 1322cdf0e10cSrcweir CGColorSpaceRef aCGColorSpace = GetSalData()->mxRGBSpace; 1323cdf0e10cSrcweir CGBitmapInfo aCGBmpInfo = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Big; 1324cdf0e10cSrcweir #if __BIG_ENDIAN__ 1325cdf0e10cSrcweir struct{ unsigned char b, g, r, a; } aPixel; 1326cdf0e10cSrcweir #else 1327cdf0e10cSrcweir struct{ unsigned char a, r, g, b; } aPixel; 1328cdf0e10cSrcweir #endif 1329cdf0e10cSrcweir 1330cdf0e10cSrcweir // create a one-pixel bitmap context 1331cdf0e10cSrcweir // TODO: is it worth to cache it? 1332cdf0e10cSrcweir CGContextRef xOnePixelContext = ::CGBitmapContextCreate( &aPixel, 1333cdf0e10cSrcweir 1, 1, 8, sizeof(aPixel), aCGColorSpace, aCGBmpInfo ); 1334cdf0e10cSrcweir 1335cdf0e10cSrcweir // update this graphics layer 1336cdf0e10cSrcweir ApplyXorContext(); 1337cdf0e10cSrcweir 1338cdf0e10cSrcweir // copy the requested pixel into the bitmap context 1339cdf0e10cSrcweir if( IsFlipped() ) 1340cdf0e10cSrcweir nY = mnHeight - nY; 1341a94c8ebdSHerbert Dürr const CGPoint aCGPoint = CGPointMake( -nX, -nY); 1342cdf0e10cSrcweir CGContextDrawLayerAtPoint( xOnePixelContext, aCGPoint, mxLayer ); 1343cdf0e10cSrcweir CGContextRelease( xOnePixelContext ); 1344cdf0e10cSrcweir 1345cdf0e10cSrcweir SalColor nSalColor = MAKE_SALCOLOR( aPixel.r, aPixel.g, aPixel.b ); 1346cdf0e10cSrcweir return nSalColor; 1347cdf0e10cSrcweir } 1348cdf0e10cSrcweir 1349cdf0e10cSrcweir // ----------------------------------------------------------------------- 1350cdf0e10cSrcweir 1351cdf0e10cSrcweir 1352cdf0e10cSrcweir static void DrawPattern50( void*, CGContextRef rContext ) 1353cdf0e10cSrcweir { 1354cdf0e10cSrcweir static const CGRect aRects[2] = { { {0,0}, { 2, 2 } }, { { 2, 2 }, { 2, 2 } } }; 1355cdf0e10cSrcweir CGContextAddRects( rContext, aRects, 2 ); 1356cdf0e10cSrcweir CGContextFillPath( rContext ); 1357cdf0e10cSrcweir } 1358cdf0e10cSrcweir 1359cdf0e10cSrcweir void AquaSalGraphics::Pattern50Fill() 1360cdf0e10cSrcweir { 136124a22e85SHerbert Dürr static const CGFloat aFillCol[4] = { 1,1,1,1 }; 1362cdf0e10cSrcweir static const CGPatternCallbacks aCallback = { 0, &DrawPattern50, NULL }; 1363cdf0e10cSrcweir if( ! GetSalData()->mxP50Space ) 1364cdf0e10cSrcweir GetSalData()->mxP50Space = CGColorSpaceCreatePattern( GetSalData()->mxRGBSpace ); 1365cdf0e10cSrcweir if( ! GetSalData()->mxP50Pattern ) 1366cdf0e10cSrcweir GetSalData()->mxP50Pattern = CGPatternCreate( NULL, CGRectMake( 0, 0, 4, 4 ), 1367cdf0e10cSrcweir CGAffineTransformIdentity, 4, 4, 1368cdf0e10cSrcweir kCGPatternTilingConstantSpacing, 1369cdf0e10cSrcweir false, &aCallback ); 1370cdf0e10cSrcweir 1371cdf0e10cSrcweir CGContextSetFillColorSpace( mrContext, GetSalData()->mxP50Space ); 1372cdf0e10cSrcweir CGContextSetFillPattern( mrContext, GetSalData()->mxP50Pattern, aFillCol ); 1373cdf0e10cSrcweir CGContextFillPath( mrContext ); 1374cdf0e10cSrcweir } 1375cdf0e10cSrcweir 1376cdf0e10cSrcweir void AquaSalGraphics::invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags ) 1377cdf0e10cSrcweir { 1378cdf0e10cSrcweir if ( CheckContext() ) 1379cdf0e10cSrcweir { 1380cdf0e10cSrcweir CGRect aCGRect = CGRectMake( nX, nY, nWidth, nHeight); 1381cdf0e10cSrcweir CGContextSaveGState(mrContext); 1382cdf0e10cSrcweir 1383cdf0e10cSrcweir if ( nFlags & SAL_INVERT_TRACKFRAME ) 1384cdf0e10cSrcweir { 138524a22e85SHerbert Dürr const CGFloat dashLengths[2] = { 4.0, 4.0 }; // for drawing dashed line 1386cdf0e10cSrcweir CGContextSetBlendMode( mrContext, kCGBlendModeDifference ); 1387cdf0e10cSrcweir CGContextSetRGBStrokeColor ( mrContext, 1.0, 1.0, 1.0, 1.0 ); 1388cdf0e10cSrcweir CGContextSetLineDash ( mrContext, 0, dashLengths, 2 ); 1389cdf0e10cSrcweir CGContextSetLineWidth( mrContext, 2.0); 1390cdf0e10cSrcweir CGContextStrokeRect ( mrContext, aCGRect ); 1391cdf0e10cSrcweir } 1392cdf0e10cSrcweir else if ( nFlags & SAL_INVERT_50 ) 1393cdf0e10cSrcweir { 1394cdf0e10cSrcweir //CGContextSetAllowsAntialiasing( mrContext, false ); 1395cdf0e10cSrcweir CGContextSetBlendMode(mrContext, kCGBlendModeDifference); 1396cdf0e10cSrcweir CGContextAddRect( mrContext, aCGRect ); 1397cdf0e10cSrcweir Pattern50Fill(); 1398cdf0e10cSrcweir } 1399cdf0e10cSrcweir else // just invert 1400cdf0e10cSrcweir { 1401cdf0e10cSrcweir CGContextSetBlendMode(mrContext, kCGBlendModeDifference); 1402cdf0e10cSrcweir CGContextSetRGBFillColor ( mrContext,1.0, 1.0, 1.0 , 1.0 ); 1403cdf0e10cSrcweir CGContextFillRect ( mrContext, aCGRect ); 1404cdf0e10cSrcweir } 1405cdf0e10cSrcweir CGContextRestoreGState( mrContext); 1406cdf0e10cSrcweir RefreshRect( aCGRect ); 1407cdf0e10cSrcweir } 1408cdf0e10cSrcweir } 1409cdf0e10cSrcweir 1410cdf0e10cSrcweir // ----------------------------------------------------------------------- 1411cdf0e10cSrcweir 141254ae6a37SHerbert Dürr void AquaSalGraphics::invert( sal_uInt32 nPoints, const SalPoint* pPtAry, SalInvert nSalFlags ) 1413cdf0e10cSrcweir { 1414cdf0e10cSrcweir CGPoint* CGpoints ; 1415cdf0e10cSrcweir if ( CheckContext() ) 1416cdf0e10cSrcweir { 1417cdf0e10cSrcweir CGContextSaveGState(mrContext); 1418cdf0e10cSrcweir CGpoints = makeCGptArray(nPoints,pPtAry); 1419cdf0e10cSrcweir CGContextAddLines ( mrContext, CGpoints, nPoints ); 1420cdf0e10cSrcweir if ( nSalFlags & SAL_INVERT_TRACKFRAME ) 1421cdf0e10cSrcweir { 142224a22e85SHerbert Dürr const CGFloat dashLengths[2] = { 4.0, 4.0 }; // for drawing dashed line 1423cdf0e10cSrcweir CGContextSetBlendMode( mrContext, kCGBlendModeDifference ); 1424cdf0e10cSrcweir CGContextSetRGBStrokeColor ( mrContext, 1.0, 1.0, 1.0, 1.0 ); 1425cdf0e10cSrcweir CGContextSetLineDash ( mrContext, 0, dashLengths, 2 ); 1426cdf0e10cSrcweir CGContextSetLineWidth( mrContext, 2.0); 1427cdf0e10cSrcweir CGContextStrokePath ( mrContext ); 1428cdf0e10cSrcweir } 1429cdf0e10cSrcweir else if ( nSalFlags & SAL_INVERT_50 ) 1430cdf0e10cSrcweir { 1431cdf0e10cSrcweir CGContextSetBlendMode(mrContext, kCGBlendModeDifference); 1432cdf0e10cSrcweir Pattern50Fill(); 1433cdf0e10cSrcweir } 1434cdf0e10cSrcweir else // just invert 1435cdf0e10cSrcweir { 1436cdf0e10cSrcweir CGContextSetBlendMode( mrContext, kCGBlendModeDifference ); 1437cdf0e10cSrcweir CGContextSetRGBFillColor( mrContext, 1.0, 1.0, 1.0, 1.0 ); 1438cdf0e10cSrcweir CGContextFillPath( mrContext ); 1439cdf0e10cSrcweir } 1440cdf0e10cSrcweir const CGRect aRefreshRect = CGContextGetClipBoundingBox(mrContext); 1441cdf0e10cSrcweir CGContextRestoreGState( mrContext); 1442cdf0e10cSrcweir delete [] CGpoints; 1443cdf0e10cSrcweir RefreshRect( aRefreshRect ); 1444cdf0e10cSrcweir } 1445cdf0e10cSrcweir } 1446cdf0e10cSrcweir 1447cdf0e10cSrcweir // ----------------------------------------------------------------------- 1448cdf0e10cSrcweir 1449cdf0e10cSrcweir sal_Bool AquaSalGraphics::drawEPS( long nX, long nY, long nWidth, long nHeight, 1450cdf0e10cSrcweir void* pEpsData, sal_uLong nByteCount ) 1451cdf0e10cSrcweir { 1452cdf0e10cSrcweir // convert the raw data to an NSImageRef 1453cdf0e10cSrcweir NSData* xNSData = [NSData dataWithBytes:(void*)pEpsData length:(int)nByteCount]; 1454cdf0e10cSrcweir NSImageRep* xEpsImage = [NSEPSImageRep imageRepWithData: xNSData]; 1455cdf0e10cSrcweir if( !xEpsImage ) 1456cdf0e10cSrcweir return false; 1457cdf0e10cSrcweir 1458cdf0e10cSrcweir // get the target context 1459cdf0e10cSrcweir if( !CheckContext() ) 1460cdf0e10cSrcweir return false; 1461cdf0e10cSrcweir 1462cdf0e10cSrcweir // NOTE: flip drawing, else the nsimage would be drawn upside down 1463cdf0e10cSrcweir CGContextSaveGState( mrContext ); 1464cdf0e10cSrcweir // CGContextTranslateCTM( mrContext, 0, +mnHeight ); 1465cdf0e10cSrcweir CGContextScaleCTM( mrContext, +1, -1 ); 1466cdf0e10cSrcweir nY = /*mnHeight*/ - (nY + nHeight); 1467cdf0e10cSrcweir 1468cdf0e10cSrcweir // prepare the target context 1469cdf0e10cSrcweir NSGraphicsContext* pOrigNSCtx = [NSGraphicsContext currentContext]; 1470cdf0e10cSrcweir [pOrigNSCtx retain]; 1471cdf0e10cSrcweir 1472cdf0e10cSrcweir // create new context 1473cdf0e10cSrcweir NSGraphicsContext* pDrawNSCtx = [NSGraphicsContext graphicsContextWithGraphicsPort: mrContext flipped: IsFlipped()]; 1474cdf0e10cSrcweir // set it, setCurrentContext also releases the prviously set one 1475cdf0e10cSrcweir [NSGraphicsContext setCurrentContext: pDrawNSCtx]; 1476cdf0e10cSrcweir 1477cdf0e10cSrcweir // draw the EPS 1478a94c8ebdSHerbert Dürr const NSRect aDstRect = NSMakeRect( nX, nY, nWidth, nHeight); 1479cdf0e10cSrcweir const BOOL bOK = [xEpsImage drawInRect: aDstRect]; 1480cdf0e10cSrcweir 1481cdf0e10cSrcweir // restore the NSGraphicsContext 1482cdf0e10cSrcweir [NSGraphicsContext setCurrentContext: pOrigNSCtx]; 1483cdf0e10cSrcweir [pOrigNSCtx release]; // restore the original retain count 1484cdf0e10cSrcweir 1485cdf0e10cSrcweir CGContextRestoreGState( mrContext ); 1486cdf0e10cSrcweir // mark the destination rectangle as updated 1487cdf0e10cSrcweir RefreshRect( aDstRect ); 1488cdf0e10cSrcweir 1489cdf0e10cSrcweir return bOK; 1490cdf0e10cSrcweir } 1491cdf0e10cSrcweir 1492cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 1493cdf0e10cSrcweir bool AquaSalGraphics::drawAlphaBitmap( const SalTwoRect& rTR, 1494cdf0e10cSrcweir const SalBitmap& rSrcBitmap, const SalBitmap& rAlphaBmp ) 1495cdf0e10cSrcweir { 1496cdf0e10cSrcweir // An image mask can't have a depth > 8 bits (should be 1 to 8 bits) 1497cdf0e10cSrcweir if( rAlphaBmp.GetBitCount() > 8 ) 1498cdf0e10cSrcweir return false; 1499cdf0e10cSrcweir 1500cdf0e10cSrcweir // are these two tests really necessary? (see vcl/unx/source/gdi/salgdi2.cxx) 1501cdf0e10cSrcweir // horizontal/vertical mirroring not implemented yet 1502cdf0e10cSrcweir if( rTR.mnDestWidth < 0 || rTR.mnDestHeight < 0 ) 1503cdf0e10cSrcweir return false; 1504cdf0e10cSrcweir 1505cdf0e10cSrcweir const AquaSalBitmap& rSrcSalBmp = static_cast<const AquaSalBitmap&>(rSrcBitmap); 1506cdf0e10cSrcweir const AquaSalBitmap& rMaskSalBmp = static_cast<const AquaSalBitmap&>(rAlphaBmp); 1507cdf0e10cSrcweir 1508cdf0e10cSrcweir CGImageRef xMaskedImage = rSrcSalBmp.CreateWithMask( rMaskSalBmp, rTR.mnSrcX, rTR.mnSrcY, rTR.mnSrcWidth, rTR.mnSrcHeight ); 1509cdf0e10cSrcweir if( !xMaskedImage ) 1510cdf0e10cSrcweir return false; 1511cdf0e10cSrcweir 1512cdf0e10cSrcweir if ( CheckContext() ) 1513cdf0e10cSrcweir { 1514a94c8ebdSHerbert Dürr const CGRect aDstRect = CGRectMake( rTR.mnDestX, rTR.mnDestY, rTR.mnDestWidth, rTR.mnDestHeight); 1515cdf0e10cSrcweir CGContextDrawImage( mrContext, aDstRect, xMaskedImage ); 1516cdf0e10cSrcweir RefreshRect( aDstRect ); 1517cdf0e10cSrcweir } 1518cdf0e10cSrcweir 1519cdf0e10cSrcweir CGImageRelease(xMaskedImage); 1520cdf0e10cSrcweir return true; 1521cdf0e10cSrcweir } 1522cdf0e10cSrcweir 15235f27b83cSArmin Le Grand // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 15245f27b83cSArmin Le Grand bool AquaSalGraphics::drawTransformedBitmap( 1525afab9726SHerbert Dürr const basegfx::B2DPoint& rNull, const basegfx::B2DPoint& rX, const basegfx::B2DPoint& rY, 1526afab9726SHerbert Dürr const SalBitmap& rSrcBitmap, const SalBitmap* pAlphaBmp ) 15275f27b83cSArmin Le Grand { 1528afab9726SHerbert Dürr if( !CheckContext() ) 1529afab9726SHerbert Dürr return true; 1530afab9726SHerbert Dürr 1531afab9726SHerbert Dürr // get the Quartz image 1532afab9726SHerbert Dürr CGImageRef xImage = NULL; 1533afab9726SHerbert Dürr const Size aSize = rSrcBitmap.GetSize(); 1534afab9726SHerbert Dürr const AquaSalBitmap& rSrcSalBmp = static_cast<const AquaSalBitmap&>(rSrcBitmap); 1535afab9726SHerbert Dürr const AquaSalBitmap* pMaskSalBmp = static_cast<const AquaSalBitmap*>(pAlphaBmp); 1536afab9726SHerbert Dürr if( !pMaskSalBmp) 1537afab9726SHerbert Dürr xImage = rSrcSalBmp.CreateCroppedImage( 0, 0, (int)aSize.Width(), (int)aSize.Height() ); 1538afab9726SHerbert Dürr else 1539afab9726SHerbert Dürr xImage = rSrcSalBmp.CreateWithMask( *pMaskSalBmp, 0, 0, (int)aSize.Width(), (int)aSize.Height() ); 1540afab9726SHerbert Dürr if( !xImage ) 1541afab9726SHerbert Dürr return false; 1542afab9726SHerbert Dürr 1543afab9726SHerbert Dürr // setup the image transformation 1544afab9726SHerbert Dürr // using the rNull,rX,rY points as destinations for the (0,0),(0,Width),(Height,0) source points 1545afab9726SHerbert Dürr CGContextSaveGState( mrContext ); 1546afab9726SHerbert Dürr const basegfx::B2DVector aXRel = rX - rNull; 1547afab9726SHerbert Dürr const basegfx::B2DVector aYRel = rY - rNull; 1548afab9726SHerbert Dürr const CGAffineTransform aCGMat = CGAffineTransformMake( 1549afab9726SHerbert Dürr aXRel.getX()/aSize.Width(), aXRel.getY()/aSize.Width(), 1550afab9726SHerbert Dürr aYRel.getX()/aSize.Height(), aYRel.getY()/aSize.Height(), 1551afab9726SHerbert Dürr rNull.getX(), rNull.getY()); 1552afab9726SHerbert Dürr CGContextConcatCTM( mrContext, aCGMat ); 1553afab9726SHerbert Dürr 1554afab9726SHerbert Dürr // draw the transformed image 1555a94c8ebdSHerbert Dürr const CGRect aSrcRect = CGRectMake( 0, 0, aSize.Width(), aSize.Height()); 1556afab9726SHerbert Dürr CGContextDrawImage( mrContext, aSrcRect, xImage ); 1557afab9726SHerbert Dürr CGImageRelease( xImage ); 1558afab9726SHerbert Dürr // restore the Quartz graphics state 1559afab9726SHerbert Dürr CGContextRestoreGState(mrContext); 1560afab9726SHerbert Dürr 1561afab9726SHerbert Dürr // mark the destination as painted 1562afab9726SHerbert Dürr const CGRect aDstRect = CGRectApplyAffineTransform( aSrcRect, aCGMat ); 1563afab9726SHerbert Dürr RefreshRect( aDstRect ); 1564afab9726SHerbert Dürr return true; 15655f27b83cSArmin Le Grand } 15665f27b83cSArmin Le Grand 1567cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 1568cdf0e10cSrcweir bool AquaSalGraphics::drawAlphaRect( long nX, long nY, long nWidth, 1569cdf0e10cSrcweir long nHeight, sal_uInt8 nTransparency ) 1570cdf0e10cSrcweir { 1571a94c8ebdSHerbert Dürr if( !CheckContext() ) 1572a94c8ebdSHerbert Dürr return true; 1573cdf0e10cSrcweir 1574cdf0e10cSrcweir // save the current state 1575cdf0e10cSrcweir CGContextSaveGState( mrContext ); 1576cdf0e10cSrcweir CGContextSetAlpha( mrContext, (100-nTransparency) * (1.0/100) ); 1577cdf0e10cSrcweir 1578a94c8ebdSHerbert Dürr CGRect aRect = CGRectMake( nX, nY, nWidth-1, nHeight-1); 1579cdf0e10cSrcweir if( IsPenVisible() ) 1580cdf0e10cSrcweir { 1581cdf0e10cSrcweir aRect.origin.x += 0.5; 1582cdf0e10cSrcweir aRect.origin.y += 0.5; 1583cdf0e10cSrcweir } 1584cdf0e10cSrcweir 1585cdf0e10cSrcweir CGContextBeginPath( mrContext ); 1586cdf0e10cSrcweir CGContextAddRect( mrContext, aRect ); 1587cdf0e10cSrcweir CGContextDrawPath( mrContext, kCGPathFill ); 1588cdf0e10cSrcweir 1589cdf0e10cSrcweir // restore state 1590cdf0e10cSrcweir CGContextRestoreGState(mrContext); 1591cdf0e10cSrcweir RefreshRect( aRect ); 1592e26449d3SHerbert Dürr return true; 1593cdf0e10cSrcweir } 1594cdf0e10cSrcweir 1595cdf0e10cSrcweir // ----------------------------------------------------------------------- 1596cdf0e10cSrcweir 1597cdf0e10cSrcweir void AquaSalGraphics::SetTextColor( SalColor nSalColor ) 1598cdf0e10cSrcweir { 1599e26449d3SHerbert Dürr maTextColor = RGBAColor( nSalColor ); 1600e26449d3SHerbert Dürr if( mpMacTextStyle) 1601e26449d3SHerbert Dürr mpMacTextStyle->SetTextColor( maTextColor ); 1602cdf0e10cSrcweir } 1603cdf0e10cSrcweir 1604cdf0e10cSrcweir // ----------------------------------------------------------------------- 1605cdf0e10cSrcweir 1606e26449d3SHerbert Dürr void AquaSalGraphics::GetFontMetric( ImplFontMetricData* pMetric, int /*nFallbackLevel*/ ) 1607cdf0e10cSrcweir { 1608e26449d3SHerbert Dürr mpMacTextStyle->GetFontMetric( mfFakeDPIScale, *pMetric ); 1609cdf0e10cSrcweir } 1610cdf0e10cSrcweir 1611cdf0e10cSrcweir // ----------------------------------------------------------------------- 1612cdf0e10cSrcweir 1613cdf0e10cSrcweir sal_uLong AquaSalGraphics::GetKernPairs( sal_uLong, ImplKernPairData* ) 1614cdf0e10cSrcweir { 1615cdf0e10cSrcweir return 0; 1616cdf0e10cSrcweir } 1617cdf0e10cSrcweir 1618cdf0e10cSrcweir // ----------------------------------------------------------------------- 1619cdf0e10cSrcweir 1620cdf0e10cSrcweir static bool AddTempFontDir( const char* pDir ) 1621cdf0e10cSrcweir { 1622cdf0e10cSrcweir FSRef aPathFSRef; 1623cdf0e10cSrcweir Boolean bIsDirectory = true; 1624cdf0e10cSrcweir OSStatus eStatus = FSPathMakeRef( reinterpret_cast<const UInt8*>(pDir), &aPathFSRef, &bIsDirectory ); 1625cdf0e10cSrcweir DBG_ASSERTWARNING( (eStatus==noErr) && bIsDirectory, "vcl AddTempFontDir() with invalid directory name!" ); 1626cdf0e10cSrcweir if( eStatus != noErr ) 1627cdf0e10cSrcweir return false; 1628cdf0e10cSrcweir 1629cdf0e10cSrcweir // TODO: deactivate ATSFontContainerRef when closing app 1630cdf0e10cSrcweir ATSFontContainerRef aATSFontContainer; 1631cdf0e10cSrcweir 1632cdf0e10cSrcweir const ATSFontContext eContext = kATSFontContextLocal; // TODO: *Global??? 1633cdf0e10cSrcweir #if defined(MAC_OS_X_VERSION_10_5) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) 1634cdf0e10cSrcweir eStatus = ::ATSFontActivateFromFileReference( &aPathFSRef, 1635cdf0e10cSrcweir eContext, kATSFontFormatUnspecified, NULL, kATSOptionFlagsDefault, 1636cdf0e10cSrcweir &aATSFontContainer ); 1637cdf0e10cSrcweir #else 1638cdf0e10cSrcweir FSSpec aPathFSSpec; 1639cdf0e10cSrcweir eStatus = ::FSGetCatalogInfo( &aPathFSRef, kFSCatInfoNone, 1640cdf0e10cSrcweir NULL, NULL, &aPathFSSpec, NULL ); 1641cdf0e10cSrcweir if( eStatus != noErr ) 1642cdf0e10cSrcweir return false; 1643cdf0e10cSrcweir 1644cdf0e10cSrcweir eStatus = ::ATSFontActivateFromFileSpecification( &aPathFSSpec, 1645cdf0e10cSrcweir eContext, kATSFontFormatUnspecified, NULL, kATSOptionFlagsDefault, 1646cdf0e10cSrcweir &aATSFontContainer ); 1647cdf0e10cSrcweir #endif 1648cdf0e10cSrcweir if( eStatus != noErr ) 1649cdf0e10cSrcweir return false; 1650cdf0e10cSrcweir 1651cdf0e10cSrcweir return true; 1652cdf0e10cSrcweir } 1653cdf0e10cSrcweir 1654cdf0e10cSrcweir static bool AddLocalTempFontDirs( void ) 1655cdf0e10cSrcweir { 1656cdf0e10cSrcweir static bool bFirst = true; 1657cdf0e10cSrcweir if( !bFirst ) 1658cdf0e10cSrcweir return false; 1659cdf0e10cSrcweir bFirst = false; 1660cdf0e10cSrcweir 1661910823aeSJürgen Schmidt // add private font files found in office base dir 1662cdf0e10cSrcweir 1663910823aeSJürgen Schmidt // rtl::OUString aBrandStr( RTL_CONSTASCII_USTRINGPARAM( "$OOO_BASE_DIR" ) ); 1664910823aeSJürgen Schmidt // rtl_bootstrap_expandMacros( &aBrandStr.pData ); 1665910823aeSJürgen Schmidt // rtl::OUString aBrandSysPath; 1666910823aeSJürgen Schmidt // OSL_VERIFY( osl_getSystemPathFromFileURL( aBrandStr.pData, &aBrandSysPath.pData ) == osl_File_E_None ); 1667cdf0e10cSrcweir 1668910823aeSJürgen Schmidt // rtl::OStringBuffer aBrandFontDir( aBrandSysPath.getLength()*2 ); 1669910823aeSJürgen Schmidt // aBrandFontDir.append( rtl::OUStringToOString( aBrandSysPath, RTL_TEXTENCODING_UTF8 ) ); 1670910823aeSJürgen Schmidt // aBrandFontDir.append( "/share/fonts/truetype/" ); 1671910823aeSJürgen Schmidt // bool bBrandSuccess = AddTempFontDir( aBrandFontDir.getStr() ); 1672cdf0e10cSrcweir 1673cdf0e10cSrcweir rtl::OUString aBaseStr( RTL_CONSTASCII_USTRINGPARAM( "$OOO_BASE_DIR" ) ); 1674cdf0e10cSrcweir rtl_bootstrap_expandMacros( &aBaseStr.pData ); 1675cdf0e10cSrcweir rtl::OUString aBaseSysPath; 1676cdf0e10cSrcweir OSL_VERIFY( osl_getSystemPathFromFileURL( aBaseStr.pData, &aBaseSysPath.pData ) == osl_File_E_None ); 1677cdf0e10cSrcweir 1678cdf0e10cSrcweir rtl::OStringBuffer aBaseFontDir( aBaseSysPath.getLength()*2 ); 1679cdf0e10cSrcweir aBaseFontDir.append( rtl::OUStringToOString( aBaseSysPath, RTL_TEXTENCODING_UTF8 ) ); 1680cdf0e10cSrcweir aBaseFontDir.append( "/share/fonts/truetype/" ); 1681cdf0e10cSrcweir bool bBaseSuccess = AddTempFontDir( aBaseFontDir.getStr() ); 1682cdf0e10cSrcweir 1683910823aeSJürgen Schmidt // return bBrandSuccess && bBaseSuccess; 1684910823aeSJürgen Schmidt return bBaseSuccess; 1685cdf0e10cSrcweir } 1686cdf0e10cSrcweir 1687cdf0e10cSrcweir void AquaSalGraphics::GetDevFontList( ImplDevFontList* pFontList ) 1688cdf0e10cSrcweir { 1689cdf0e10cSrcweir DBG_ASSERT( pFontList, "AquaSalGraphics::GetDevFontList(NULL) !"); 1690cdf0e10cSrcweir 1691e26449d3SHerbert Dürr AddLocalTempFontDirs(); 1692cdf0e10cSrcweir 1693cdf0e10cSrcweir // The idea is to cache the list of system fonts once it has been generated. 1694cdf0e10cSrcweir // SalData seems to be a good place for this caching. However we have to 1695cdf0e10cSrcweir // carefully make the access to the font list thread-safe. If we register 1696cdf0e10cSrcweir // a font-change event handler to update the font list in case fonts have 1697cdf0e10cSrcweir // changed on the system we have to lock access to the list. The right 1698e26449d3SHerbert Dürr // way to do that is the solar mutex since GetDevFontList is protected 1699e26449d3SHerbert Dürr // through it as should be all event handlers 1700cdf0e10cSrcweir 1701cdf0e10cSrcweir SalData* pSalData = GetSalData(); 1702e26449d3SHerbert Dürr #ifdef USE_ATSU 1703e26449d3SHerbert Dürr SystemFontList* GetAtsFontList(void); // forward declaration 1704e26449d3SHerbert Dürr if( !pSalData->mpFontList ) 1705e26449d3SHerbert Dürr pSalData->mpFontList = GetAtsFontList(); 1706e26449d3SHerbert Dürr #else 1707e26449d3SHerbert Dürr SystemFontList* GetCoretextFontList(void); // forward declaration 1708e26449d3SHerbert Dürr if( !pSalData->mpFontList ) 1709e26449d3SHerbert Dürr pSalData->mpFontList = GetCoretextFontList(); 1710e26449d3SHerbert Dürr #endif // DISABLE_ATSUI 1711cdf0e10cSrcweir 1712cdf0e10cSrcweir // Copy all ImplFontData objects contained in the SystemFontList 1713cdf0e10cSrcweir pSalData->mpFontList->AnnounceFonts( *pFontList ); 1714cdf0e10cSrcweir } 1715cdf0e10cSrcweir 1716cdf0e10cSrcweir // ----------------------------------------------------------------------- 1717cdf0e10cSrcweir 1718cdf0e10cSrcweir bool AquaSalGraphics::AddTempDevFont( ImplDevFontList*, 1719cdf0e10cSrcweir const String& rFontFileURL, const String& /*rFontName*/ ) 1720cdf0e10cSrcweir { 1721cdf0e10cSrcweir ::rtl::OUString aUSytemPath; 1722cdf0e10cSrcweir OSL_VERIFY( !osl::FileBase::getSystemPathFromFileURL( rFontFileURL, aUSytemPath ) ); 1723cdf0e10cSrcweir 1724cdf0e10cSrcweir FSRef aNewRef; 1725cdf0e10cSrcweir Boolean bIsDirectory = true; 1726cdf0e10cSrcweir ::rtl::OString aCFileName = rtl::OUStringToOString( aUSytemPath, RTL_TEXTENCODING_UTF8 ); 1727cdf0e10cSrcweir OSStatus eStatus = FSPathMakeRef( (UInt8*)aCFileName.getStr(), &aNewRef, &bIsDirectory ); 1728cdf0e10cSrcweir DBG_ASSERT( (eStatus==noErr) && !bIsDirectory, "vcl AddTempDevFont() with invalid fontfile name!" ); 1729cdf0e10cSrcweir if( eStatus != noErr ) 1730cdf0e10cSrcweir return false; 1731cdf0e10cSrcweir 1732cdf0e10cSrcweir ATSFontContainerRef oContainer; 1733cdf0e10cSrcweir 1734cdf0e10cSrcweir const ATSFontContext eContext = kATSFontContextLocal; // TODO: *Global??? 1735cdf0e10cSrcweir #if defined(MAC_OS_X_VERSION_10_5) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) 1736cdf0e10cSrcweir eStatus = ::ATSFontActivateFromFileReference( &aNewRef, 1737cdf0e10cSrcweir eContext, kATSFontFormatUnspecified, NULL, kATSOptionFlagsDefault, 1738cdf0e10cSrcweir &oContainer ); 1739cdf0e10cSrcweir #else 1740cdf0e10cSrcweir FSSpec aFontFSSpec; 1741cdf0e10cSrcweir eStatus = ::FSGetCatalogInfo( &aNewRef, kFSCatInfoNone, 1742cdf0e10cSrcweir NULL, NULL, &aFontFSSpec, NULL ); 1743cdf0e10cSrcweir if( eStatus != noErr ) 1744cdf0e10cSrcweir return false; 1745cdf0e10cSrcweir 1746cdf0e10cSrcweir eStatus = ::ATSFontActivateFromFileSpecification( &aFontFSSpec, 1747cdf0e10cSrcweir eContext, kATSFontFormatUnspecified, NULL, kATSOptionFlagsDefault, 1748cdf0e10cSrcweir &oContainer ); 1749cdf0e10cSrcweir #endif 1750cdf0e10cSrcweir if( eStatus != noErr ) 1751cdf0e10cSrcweir return false; 1752cdf0e10cSrcweir 1753cdf0e10cSrcweir // TODO: ATSFontDeactivate( oContainer ) when fonts are no longer needed 1754cdf0e10cSrcweir // TODO: register new ImplMacFontdata in pFontList 1755cdf0e10cSrcweir return true; 1756cdf0e10cSrcweir } 1757cdf0e10cSrcweir 1758cdf0e10cSrcweir // ----------------------------------------------------------------------- 1759cdf0e10cSrcweir 1760cdf0e10cSrcweir long AquaSalGraphics::GetGraphicsWidth() const 1761cdf0e10cSrcweir { 1762cdf0e10cSrcweir long w = 0; 1763cdf0e10cSrcweir if( mrContext && (mbWindow || mbVirDev) ) 1764cdf0e10cSrcweir { 1765cdf0e10cSrcweir w = mnWidth; 1766cdf0e10cSrcweir } 1767cdf0e10cSrcweir 1768cdf0e10cSrcweir if( w == 0 ) 1769cdf0e10cSrcweir { 1770cdf0e10cSrcweir if( mbWindow && mpFrame ) 1771cdf0e10cSrcweir w = mpFrame->maGeometry.nWidth; 1772cdf0e10cSrcweir } 1773cdf0e10cSrcweir 1774cdf0e10cSrcweir return w; 1775cdf0e10cSrcweir } 1776cdf0e10cSrcweir 1777cdf0e10cSrcweir // ----------------------------------------------------------------------- 1778cdf0e10cSrcweir 1779248a599fSHerbert Dürr bool AquaSalGraphics::GetGlyphBoundRect( sal_GlyphId aGlyphId, Rectangle& rRect ) 1780cdf0e10cSrcweir { 1781e26449d3SHerbert Dürr const bool bRC = mpMacTextStyle->GetGlyphBoundRect( aGlyphId, rRect ); 1782e26449d3SHerbert Dürr return bRC; 1783e26449d3SHerbert Dürr } 1784cdf0e10cSrcweir 1785e26449d3SHerbert Dürr // ----------------------------------------------------------------------- 1786e26449d3SHerbert Dürr 1787e26449d3SHerbert Dürr bool AquaSalGraphics::GetGlyphOutline( sal_GlyphId aGlyphId, basegfx::B2DPolyPolygon& rPolyPoly ) 1788e26449d3SHerbert Dürr { 1789e26449d3SHerbert Dürr const bool bRC = mpMacTextStyle->GetGlyphOutline( aGlyphId, rPolyPoly ); 1790e26449d3SHerbert Dürr return bRC; 1791cdf0e10cSrcweir } 1792cdf0e10cSrcweir 1793cdf0e10cSrcweir // ----------------------------------------------------------------------- 1794cdf0e10cSrcweir 1795cdf0e10cSrcweir void AquaSalGraphics::GetDevFontSubstList( OutputDevice* ) 1796cdf0e10cSrcweir { 1797cdf0e10cSrcweir // nothing to do since there are no device-specific fonts on Aqua 1798cdf0e10cSrcweir } 1799cdf0e10cSrcweir 1800cdf0e10cSrcweir // ----------------------------------------------------------------------- 1801cdf0e10cSrcweir 1802cdf0e10cSrcweir void AquaSalGraphics::DrawServerFontLayout( const ServerFontLayout& ) 1803e26449d3SHerbert Dürr {} 1804cdf0e10cSrcweir 1805cdf0e10cSrcweir // ----------------------------------------------------------------------- 1806cdf0e10cSrcweir 1807cdf0e10cSrcweir sal_uInt16 AquaSalGraphics::SetFont( ImplFontSelectData* pReqFont, int /*nFallbackLevel*/ ) 1808cdf0e10cSrcweir { 1809e26449d3SHerbert Dürr // release the text style 1810e26449d3SHerbert Dürr delete mpMacTextStyle; 1811e26449d3SHerbert Dürr mpMacTextStyle = NULL; 1812cdf0e10cSrcweir 1813e26449d3SHerbert Dürr // handle NULL request meaning: release-font-resources request 1814e26449d3SHerbert Dürr if( !pReqFont ) 1815e26449d3SHerbert Dürr { 1816e26449d3SHerbert Dürr mpMacFontData = NULL; 1817e26449d3SHerbert Dürr return 0; 1818e26449d3SHerbert Dürr } 1819cdf0e10cSrcweir 1820e26449d3SHerbert Dürr // update the text style 1821e26449d3SHerbert Dürr mpMacFontData = static_cast<const ImplMacFontData*>( pReqFont->mpFontData ); 1822e26449d3SHerbert Dürr mpMacTextStyle = mpMacFontData->CreateMacTextStyle( *pReqFont ); 1823e26449d3SHerbert Dürr mpMacTextStyle->SetTextColor( maTextColor ); 1824e26449d3SHerbert Dürr 1825e26449d3SHerbert Dürr #if (OSL_DEBUG_LEVEL > 3) 1826e26449d3SHerbert Dürr fprintf( stderr, "SetFont to (\"%s\", \"%s\", fontid=%d) for (\"%s\" \"%s\" weight=%d, slant=%d size=%dx%d orientation=%d)\n", 1827e26449d3SHerbert Dürr ::rtl::OUStringToOString( mpMacFontData->GetFamilyName(), RTL_TEXTENCODING_UTF8 ).getStr(), 1828e26449d3SHerbert Dürr ::rtl::OUStringToOString( mpMacFontData->GetStyleName(), RTL_TEXTENCODING_UTF8 ).getStr(), 1829e26449d3SHerbert Dürr (int)pMacFont->GetFontId(), 1830e26449d3SHerbert Dürr ::rtl::OUStringToOString( mpMacFontData->GetFamilyName(), RTL_TEXTENCODING_UTF8 ).getStr(), 1831e26449d3SHerbert Dürr ::rtl::OUStringToOString( mpMacFontData->GetStyleName(), RTL_TEXTENCODING_UTF8 ).getStr(), 1832e26449d3SHerbert Dürr pReqFont->GetWeight(), 1833e26449d3SHerbert Dürr pReqFont->GetSlant(), 1834e26449d3SHerbert Dürr pReqFont->mnHeight, 1835e26449d3SHerbert Dürr pReqFont->mnWidth, 1836e26449d3SHerbert Dürr pReqFont->mnOrientation); 1837cdf0e10cSrcweir #endif 1838cdf0e10cSrcweir 1839cdf0e10cSrcweir return 0; 1840cdf0e10cSrcweir } 1841cdf0e10cSrcweir 1842cdf0e10cSrcweir // ----------------------------------------------------------------------- 1843cdf0e10cSrcweir 1844e26449d3SHerbert Dürr SalLayout* AquaSalGraphics::GetTextLayout( ImplLayoutArgs& /*rArgs*/, int /*nFallbackLevel*/ ) 1845e26449d3SHerbert Dürr { 1846e26449d3SHerbert Dürr SalLayout* pSalLayout = mpMacTextStyle->GetTextLayout(); 1847e26449d3SHerbert Dürr return pSalLayout; 1848e26449d3SHerbert Dürr } 1849e26449d3SHerbert Dürr 1850e26449d3SHerbert Dürr // ----------------------------------------------------------------------- 1851e26449d3SHerbert Dürr 1852cdf0e10cSrcweir const ImplFontCharMap* AquaSalGraphics::GetImplFontCharMap() const 1853cdf0e10cSrcweir { 1854cdf0e10cSrcweir if( !mpMacFontData ) 1855cdf0e10cSrcweir return ImplFontCharMap::GetDefaultMap(); 1856cdf0e10cSrcweir 1857cdf0e10cSrcweir return mpMacFontData->GetImplFontCharMap(); 1858cdf0e10cSrcweir } 1859cdf0e10cSrcweir 1860cdf0e10cSrcweir // ----------------------------------------------------------------------- 1861cdf0e10cSrcweir 1862cdf0e10cSrcweir // fake a SFNT font directory entry for a font table 1863cdf0e10cSrcweir // see http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6.html#Directory 1864e26449d3SHerbert Dürr static void FakeDirEntry( const char aTag[5], ByteCount nOfs, ByteCount nLen, 1865cdf0e10cSrcweir const unsigned char* /*pData*/, unsigned char*& rpDest ) 1866cdf0e10cSrcweir { 1867cdf0e10cSrcweir // write entry tag 1868e26449d3SHerbert Dürr rpDest[ 0] = aTag[0]; 1869e26449d3SHerbert Dürr rpDest[ 1] = aTag[1]; 1870e26449d3SHerbert Dürr rpDest[ 2] = aTag[2]; 1871e26449d3SHerbert Dürr rpDest[ 3] = aTag[3]; 1872cdf0e10cSrcweir // TODO: get entry checksum and write it 1873e26449d3SHerbert Dürr // not too important since the subsetter doesn't care currently 1874e26449d3SHerbert Dürr // for( pData+nOfs ... pData+nOfs+nLen ) 1875cdf0e10cSrcweir // write entry offset 1876cdf0e10cSrcweir rpDest[ 8] = (char)(nOfs >> 24); 1877cdf0e10cSrcweir rpDest[ 9] = (char)(nOfs >> 16); 1878cdf0e10cSrcweir rpDest[10] = (char)(nOfs >> 8); 1879cdf0e10cSrcweir rpDest[11] = (char)(nOfs >> 0); 1880cdf0e10cSrcweir // write entry length 1881cdf0e10cSrcweir rpDest[12] = (char)(nLen >> 24); 1882cdf0e10cSrcweir rpDest[13] = (char)(nLen >> 16); 1883cdf0e10cSrcweir rpDest[14] = (char)(nLen >> 8); 1884cdf0e10cSrcweir rpDest[15] = (char)(nLen >> 0); 1885cdf0e10cSrcweir // advance to next entry 1886cdf0e10cSrcweir rpDest += 16; 1887cdf0e10cSrcweir } 1888cdf0e10cSrcweir 1889e26449d3SHerbert Dürr // fake a TTF or CFF font as directly accessing font file is not possible 1890e26449d3SHerbert Dürr // when only the fontid is known. This approach also handles *.dfont fonts. 1891cdf0e10cSrcweir static bool GetRawFontData( const ImplFontData* pFontData, 1892cdf0e10cSrcweir ByteVector& rBuffer, bool* pJustCFF ) 1893cdf0e10cSrcweir { 1894cdf0e10cSrcweir const ImplMacFontData* pMacFont = static_cast<const ImplMacFontData*>(pFontData); 1895cdf0e10cSrcweir 1896e26449d3SHerbert Dürr // short circuit for CFF-only fonts 1897e26449d3SHerbert Dürr const int nCffSize = pMacFont->GetFontTable( "CFF ", NULL); 1898cdf0e10cSrcweir if( pJustCFF != NULL ) 1899cdf0e10cSrcweir { 1900e26449d3SHerbert Dürr *pJustCFF = (nCffSize > 0); 1901e26449d3SHerbert Dürr if( *pJustCFF) 1902cdf0e10cSrcweir { 1903e26449d3SHerbert Dürr rBuffer.resize( nCffSize); 1904e26449d3SHerbert Dürr const int nCffRead = pMacFont->GetFontTable( "CFF ", &rBuffer[0]); 1905e26449d3SHerbert Dürr if( nCffRead != nCffSize) 1906cdf0e10cSrcweir return false; 1907cdf0e10cSrcweir return true; 1908cdf0e10cSrcweir } 1909cdf0e10cSrcweir } 1910cdf0e10cSrcweir 1911cdf0e10cSrcweir // get font table availability and size in bytes 1912e26449d3SHerbert Dürr const int nHeadSize = pMacFont->GetFontTable( "head", NULL); 1913e26449d3SHerbert Dürr if( nHeadSize <= 0) 1914cdf0e10cSrcweir return false; 1915e26449d3SHerbert Dürr const int nMaxpSize = pMacFont->GetFontTable( "maxp", NULL); 1916e26449d3SHerbert Dürr if( nMaxpSize <= 0) 1917cdf0e10cSrcweir return false; 1918e26449d3SHerbert Dürr const int nCmapSize = pMacFont->GetFontTable( "cmap", NULL); 1919e26449d3SHerbert Dürr if( nCmapSize <= 0) 1920cdf0e10cSrcweir return false; 1921e26449d3SHerbert Dürr const int nNameSize = pMacFont->GetFontTable( "name", NULL); 1922e26449d3SHerbert Dürr if( nNameSize <= 0) 1923cdf0e10cSrcweir return false; 1924e26449d3SHerbert Dürr const int nHheaSize = pMacFont->GetFontTable( "hhea", NULL); 1925e26449d3SHerbert Dürr if( nHheaSize <= 0) 1926cdf0e10cSrcweir return false; 1927e26449d3SHerbert Dürr const int nHmtxSize = pMacFont->GetFontTable( "hmtx", NULL); 1928e26449d3SHerbert Dürr if( nHmtxSize <= 0) 1929cdf0e10cSrcweir return false; 1930cdf0e10cSrcweir 1931e26449d3SHerbert Dürr // get the ttf-glyf outline tables 1932e26449d3SHerbert Dürr int nLocaSize = 0; 1933e26449d3SHerbert Dürr int nGlyfSize = 0; 1934e26449d3SHerbert Dürr if( nCffSize <= 0) 1935cdf0e10cSrcweir { 1936e26449d3SHerbert Dürr nLocaSize = pMacFont->GetFontTable( "loca", NULL); 1937e26449d3SHerbert Dürr if( nLocaSize <= 0) 1938cdf0e10cSrcweir return false; 1939e26449d3SHerbert Dürr nGlyfSize = pMacFont->GetFontTable( "glyf", NULL); 1940e26449d3SHerbert Dürr if( nGlyfSize <= 0) 1941cdf0e10cSrcweir return false; 1942cdf0e10cSrcweir } 1943cdf0e10cSrcweir 1944e26449d3SHerbert Dürr int nPrepSize = 0, nCvtSize = 0, nFpgmSize = 0; 1945e26449d3SHerbert Dürr if( nGlyfSize) // TODO: reduce PDF size by making hint subsetting optional 1946cdf0e10cSrcweir { 1947e26449d3SHerbert Dürr nPrepSize = pMacFont->GetFontTable( "prep", NULL); 1948e26449d3SHerbert Dürr nCvtSize = pMacFont->GetFontTable( "cvt ", NULL); 1949e26449d3SHerbert Dürr nFpgmSize = pMacFont->GetFontTable( "fpgm", NULL); 1950cdf0e10cSrcweir } 1951cdf0e10cSrcweir 1952cdf0e10cSrcweir // prepare a byte buffer for a fake font 1953cdf0e10cSrcweir int nTableCount = 7; 1954e26449d3SHerbert Dürr nTableCount += (nPrepSize>0) + (nCvtSize>0) + (nFpgmSize>0) + (nGlyfSize>0); 1955e26449d3SHerbert Dürr const ByteCount nFdirSize = 12 + 16*nTableCount; 1956e26449d3SHerbert Dürr ByteCount nTotalSize = nFdirSize; 1957e26449d3SHerbert Dürr nTotalSize += nHeadSize + nMaxpSize + nNameSize + nCmapSize; 1958e26449d3SHerbert Dürr if( nGlyfSize ) 1959e26449d3SHerbert Dürr nTotalSize += nLocaSize + nGlyfSize; 1960cdf0e10cSrcweir else 1961e26449d3SHerbert Dürr nTotalSize += nCffSize; 1962e26449d3SHerbert Dürr nTotalSize += nHheaSize + nHmtxSize; 1963e26449d3SHerbert Dürr nTotalSize += nPrepSize + nCvtSize + nFpgmSize; 1964e26449d3SHerbert Dürr rBuffer.resize( nTotalSize ); 1965cdf0e10cSrcweir 1966cdf0e10cSrcweir // fake a SFNT font directory header 1967cdf0e10cSrcweir if( nTableCount < 16 ) 1968cdf0e10cSrcweir { 1969cdf0e10cSrcweir int nLog2 = 0; 1970cdf0e10cSrcweir while( (nTableCount >> nLog2) > 1 ) ++nLog2; 1971cdf0e10cSrcweir rBuffer[ 1] = 1; // Win-TTF style scaler 1972cdf0e10cSrcweir rBuffer[ 5] = nTableCount; // table count 1973cdf0e10cSrcweir rBuffer[ 7] = nLog2*16; // searchRange 1974cdf0e10cSrcweir rBuffer[ 9] = nLog2; // entrySelector 1975cdf0e10cSrcweir rBuffer[11] = (nTableCount-nLog2)*16; // rangeShift 1976cdf0e10cSrcweir } 1977cdf0e10cSrcweir 1978cdf0e10cSrcweir // get font table raw data and update the fake directory entries 1979e26449d3SHerbert Dürr ByteCount nOfs = nFdirSize; 1980cdf0e10cSrcweir unsigned char* pFakeEntry = &rBuffer[12]; 1981e26449d3SHerbert Dürr if( nCmapSize != pMacFont->GetFontTable( "cmap", &rBuffer[nOfs])) 1982e26449d3SHerbert Dürr return false; 1983e26449d3SHerbert Dürr FakeDirEntry( "cmap", nOfs, nCmapSize, &rBuffer[0], pFakeEntry ); 1984e26449d3SHerbert Dürr nOfs += nCmapSize; 1985e26449d3SHerbert Dürr if( nCvtSize ) { 1986e26449d3SHerbert Dürr if( nCvtSize != pMacFont->GetFontTable( "cvt ", &rBuffer[nOfs])) 1987e26449d3SHerbert Dürr return false; 1988e26449d3SHerbert Dürr FakeDirEntry( "cvt ", nOfs, nCvtSize, &rBuffer[0], pFakeEntry ); 1989e26449d3SHerbert Dürr nOfs += nCvtSize; 1990cdf0e10cSrcweir } 1991e26449d3SHerbert Dürr if( nFpgmSize ) { 1992e26449d3SHerbert Dürr if( nFpgmSize != pMacFont->GetFontTable( "fpgm", &rBuffer[nOfs])) 1993e26449d3SHerbert Dürr return false; 1994e26449d3SHerbert Dürr FakeDirEntry( "fpgm", nOfs, nFpgmSize, &rBuffer[0], pFakeEntry ); 1995e26449d3SHerbert Dürr nOfs += nFpgmSize; 1996cdf0e10cSrcweir } 1997e26449d3SHerbert Dürr if( nCffSize ) { 1998e26449d3SHerbert Dürr if( nCffSize != pMacFont->GetFontTable( "CFF ", &rBuffer[nOfs])) 1999e26449d3SHerbert Dürr return false; 2000e26449d3SHerbert Dürr FakeDirEntry( "CFF ", nOfs, nCffSize, &rBuffer[0], pFakeEntry ); 2001e26449d3SHerbert Dürr nOfs += nGlyfSize; 2002cdf0e10cSrcweir } else { 2003e26449d3SHerbert Dürr if( nGlyfSize != pMacFont->GetFontTable( "glyf", &rBuffer[nOfs])) 2004e26449d3SHerbert Dürr return false; 2005e26449d3SHerbert Dürr FakeDirEntry( "glyf", nOfs, nGlyfSize, &rBuffer[0], pFakeEntry ); 2006e26449d3SHerbert Dürr nOfs += nGlyfSize; 2007e26449d3SHerbert Dürr if( nLocaSize != pMacFont->GetFontTable( "loca", &rBuffer[nOfs])) 2008e26449d3SHerbert Dürr return false; 2009e26449d3SHerbert Dürr FakeDirEntry( "loca", nOfs, nLocaSize, &rBuffer[0], pFakeEntry ); 2010e26449d3SHerbert Dürr nOfs += nLocaSize; 2011cdf0e10cSrcweir } 2012e26449d3SHerbert Dürr if( nHeadSize != pMacFont->GetFontTable( "head", &rBuffer[nOfs])) 2013e26449d3SHerbert Dürr return false; 2014e26449d3SHerbert Dürr FakeDirEntry( "head", nOfs, nHeadSize, &rBuffer[0], pFakeEntry ); 2015e26449d3SHerbert Dürr nOfs += nHeadSize; 2016e26449d3SHerbert Dürr if( nHheaSize != pMacFont->GetFontTable( "hhea", &rBuffer[nOfs])) 2017e26449d3SHerbert Dürr return false; 2018e26449d3SHerbert Dürr FakeDirEntry( "hhea", nOfs, nHheaSize, &rBuffer[0], pFakeEntry ); 2019e26449d3SHerbert Dürr nOfs += nHheaSize; 2020e26449d3SHerbert Dürr if( nHmtxSize != pMacFont->GetFontTable( "hmtx", &rBuffer[nOfs])) 2021e26449d3SHerbert Dürr return false; 2022e26449d3SHerbert Dürr FakeDirEntry( "hmtx", nOfs, nHmtxSize, &rBuffer[0], pFakeEntry ); 2023e26449d3SHerbert Dürr nOfs += nHmtxSize; 2024e26449d3SHerbert Dürr if( nMaxpSize != pMacFont->GetFontTable( "maxp", &rBuffer[nOfs])) 2025e26449d3SHerbert Dürr return false; 2026e26449d3SHerbert Dürr FakeDirEntry( "maxp", nOfs, nMaxpSize, &rBuffer[0], pFakeEntry ); 2027e26449d3SHerbert Dürr nOfs += nMaxpSize; 2028e26449d3SHerbert Dürr if( nNameSize != pMacFont->GetFontTable( "name", &rBuffer[nOfs])) 2029e26449d3SHerbert Dürr return false; 2030e26449d3SHerbert Dürr FakeDirEntry( "name", nOfs, nNameSize, &rBuffer[0], pFakeEntry ); 2031e26449d3SHerbert Dürr nOfs += nNameSize; 2032e26449d3SHerbert Dürr if( nPrepSize ) { 2033e26449d3SHerbert Dürr if( nPrepSize != pMacFont->GetFontTable( "prep", &rBuffer[nOfs])) 2034e26449d3SHerbert Dürr return false; 2035e26449d3SHerbert Dürr FakeDirEntry( "prep", nOfs, nPrepSize, &rBuffer[0], pFakeEntry ); 2036e26449d3SHerbert Dürr nOfs += nPrepSize; 2037cdf0e10cSrcweir } 2038cdf0e10cSrcweir 2039e26449d3SHerbert Dürr DBG_ASSERT( (nOfs==nTotalSize), "AquaSalGraphics::CreateFontSubset (nOfs!=nTotalSize)"); 2040cdf0e10cSrcweir 2041e26449d3SHerbert Dürr return true; 2042cdf0e10cSrcweir } 2043cdf0e10cSrcweir 2044cdf0e10cSrcweir sal_Bool AquaSalGraphics::CreateFontSubset( const rtl::OUString& rToFile, 2045248a599fSHerbert Dürr const ImplFontData* pFontData, sal_GlyphId* pGlyphIds, sal_uInt8* pEncoding, 2046cdf0e10cSrcweir sal_Int32* pGlyphWidths, int nGlyphCount, FontSubsetInfo& rInfo ) 2047cdf0e10cSrcweir { 2048cdf0e10cSrcweir // TODO: move more of the functionality here into the generic subsetter code 2049cdf0e10cSrcweir 2050cdf0e10cSrcweir // prepare the requested file name for writing the font-subset file 2051cdf0e10cSrcweir rtl::OUString aSysPath; 2052cdf0e10cSrcweir if( osl_File_E_None != osl_getSystemPathFromFileURL( rToFile.pData, &aSysPath.pData ) ) 2053cdf0e10cSrcweir return sal_False; 2054cdf0e10cSrcweir const rtl_TextEncoding aThreadEncoding = osl_getThreadTextEncoding(); 2055cdf0e10cSrcweir const ByteString aToFile( rtl::OUStringToOString( aSysPath, aThreadEncoding ) ); 2056cdf0e10cSrcweir 2057cdf0e10cSrcweir // get the raw-bytes from the font to be subset 2058cdf0e10cSrcweir ByteVector aBuffer; 2059cdf0e10cSrcweir bool bCffOnly = false; 2060cdf0e10cSrcweir if( !GetRawFontData( pFontData, aBuffer, &bCffOnly ) ) 2061cdf0e10cSrcweir return sal_False; 2062cdf0e10cSrcweir 2063cdf0e10cSrcweir // handle CFF-subsetting 2064cdf0e10cSrcweir if( bCffOnly ) 2065cdf0e10cSrcweir { 2066cdf0e10cSrcweir // provide the raw-CFF data to the subsetter 2067e26449d3SHerbert Dürr const ByteCount nCffLen = aBuffer.size(); 2068cdf0e10cSrcweir rInfo.LoadFont( FontSubsetInfo::CFF_FONT, &aBuffer[0], nCffLen ); 2069cdf0e10cSrcweir 2070cdf0e10cSrcweir // NOTE: assuming that all glyphids requested on Aqua are fully translated 2071cdf0e10cSrcweir 2072cdf0e10cSrcweir // make the subsetter provide the requested subset 2073cdf0e10cSrcweir FILE* pOutFile = fopen( aToFile.GetBuffer(), "wb" ); 2074cdf0e10cSrcweir bool bRC = rInfo.CreateFontSubset( FontSubsetInfo::TYPE1_PFB, pOutFile, NULL, 2075248a599fSHerbert Dürr pGlyphIds, pEncoding, nGlyphCount, pGlyphWidths ); 2076cdf0e10cSrcweir fclose( pOutFile ); 2077cdf0e10cSrcweir return bRC; 2078cdf0e10cSrcweir } 2079cdf0e10cSrcweir 2080cdf0e10cSrcweir // TODO: modernize psprint's horrible fontsubset C-API 2081cdf0e10cSrcweir // this probably only makes sense after the switch to another SCM 2082cdf0e10cSrcweir // that can preserve change history after file renames 2083cdf0e10cSrcweir 2084cdf0e10cSrcweir // prepare data for psprint's font subsetter 2085cdf0e10cSrcweir TrueTypeFont* pSftFont = NULL; 2086cdf0e10cSrcweir int nRC = ::OpenTTFontBuffer( (void*)&aBuffer[0], aBuffer.size(), 0, &pSftFont); 2087cdf0e10cSrcweir if( nRC != SF_OK ) 2088cdf0e10cSrcweir return sal_False; 2089cdf0e10cSrcweir 2090cdf0e10cSrcweir // get details about the subsetted font 2091cdf0e10cSrcweir TTGlobalFontInfo aTTInfo; 2092cdf0e10cSrcweir ::GetTTGlobalFontInfo( pSftFont, &aTTInfo ); 2093cdf0e10cSrcweir rInfo.m_nFontType = FontSubsetInfo::SFNT_TTF; 2094cdf0e10cSrcweir rInfo.m_aPSName = String( aTTInfo.psname, RTL_TEXTENCODING_UTF8 ); 2095e26449d3SHerbert Dürr rInfo.m_aFontBBox = Rectangle( Point( aTTInfo.xMin, aTTInfo.yMin ), 2096cdf0e10cSrcweir Point( aTTInfo.xMax, aTTInfo.yMax ) ); 2097e26449d3SHerbert Dürr rInfo.m_nCapHeight = aTTInfo.yMax; // Well ... 209859213536SEike Rathke rInfo.m_nAscent = aTTInfo.winAscent; 209959213536SEike Rathke rInfo.m_nDescent = aTTInfo.winDescent; 2100cdf0e10cSrcweir // mac fonts usually do not have an OS2-table 2101cdf0e10cSrcweir // => get valid ascent/descent values from other tables 2102cdf0e10cSrcweir if( !rInfo.m_nAscent ) 2103cdf0e10cSrcweir rInfo.m_nAscent = +aTTInfo.typoAscender; 2104cdf0e10cSrcweir if( !rInfo.m_nAscent ) 2105cdf0e10cSrcweir rInfo.m_nAscent = +aTTInfo.ascender; 2106cdf0e10cSrcweir if( !rInfo.m_nDescent ) 2107cdf0e10cSrcweir rInfo.m_nDescent = +aTTInfo.typoDescender; 2108cdf0e10cSrcweir if( !rInfo.m_nDescent ) 2109cdf0e10cSrcweir rInfo.m_nDescent = -aTTInfo.descender; 2110cdf0e10cSrcweir 2111cdf0e10cSrcweir // subset glyphs and get their properties 2112cdf0e10cSrcweir // take care that subset fonts require the NotDef glyph in pos 0 2113cdf0e10cSrcweir int nOrigCount = nGlyphCount; 2114e26449d3SHerbert Dürr sal_uInt16 aShortIDs[ 256 ]; 2115cdf0e10cSrcweir sal_uInt8 aTempEncs[ 256 ]; 2116cdf0e10cSrcweir 2117cdf0e10cSrcweir int nNotDef = -1; 2118cdf0e10cSrcweir for( int i = 0; i < nGlyphCount; ++i ) 2119cdf0e10cSrcweir { 2120cdf0e10cSrcweir aTempEncs[i] = pEncoding[i]; 2121248a599fSHerbert Dürr sal_GlyphId aGlyphId( pGlyphIds[i] & GF_IDXMASK); 2122248a599fSHerbert Dürr if( pGlyphIds[i] & GF_ISCHAR ) 2123cdf0e10cSrcweir { 2124248a599fSHerbert Dürr bool bVertical = (pGlyphIds[i] & GF_ROTMASK) != 0; 2125248a599fSHerbert Dürr aGlyphId = ::MapChar( pSftFont, static_cast<sal_uInt16>(aGlyphId), bVertical ); 2126248a599fSHerbert Dürr if( aGlyphId == 0 && pFontData->IsSymbolFont() ) 2127cdf0e10cSrcweir { 2128cdf0e10cSrcweir // #i12824# emulate symbol aliasing U+FXXX <-> U+0XXX 2129248a599fSHerbert Dürr aGlyphId = pGlyphIds[i] & GF_IDXMASK; 2130248a599fSHerbert Dürr aGlyphId = (aGlyphId & 0xF000) ? (aGlyphId & 0x00FF) : (aGlyphId | 0xF000 ); 2131248a599fSHerbert Dürr aGlyphId = ::MapChar( pSftFont, static_cast<sal_uInt16>(aGlyphId), bVertical ); 2132cdf0e10cSrcweir } 2133cdf0e10cSrcweir } 2134248a599fSHerbert Dürr aShortIDs[i] = static_cast<sal_uInt16>( aGlyphId ); 2135248a599fSHerbert Dürr if( !aGlyphId ) 2136cdf0e10cSrcweir if( nNotDef < 0 ) 2137cdf0e10cSrcweir nNotDef = i; // first NotDef glyph found 2138cdf0e10cSrcweir } 2139cdf0e10cSrcweir 2140cdf0e10cSrcweir if( nNotDef != 0 ) 2141cdf0e10cSrcweir { 2142cdf0e10cSrcweir // add fake NotDef glyph if needed 2143cdf0e10cSrcweir if( nNotDef < 0 ) 2144cdf0e10cSrcweir nNotDef = nGlyphCount++; 2145cdf0e10cSrcweir 2146cdf0e10cSrcweir // NotDef glyph must be in pos 0 => swap glyphids 2147cdf0e10cSrcweir aShortIDs[ nNotDef ] = aShortIDs[0]; 2148cdf0e10cSrcweir aTempEncs[ nNotDef ] = aTempEncs[0]; 2149cdf0e10cSrcweir aShortIDs[0] = 0; 2150cdf0e10cSrcweir aTempEncs[0] = 0; 2151cdf0e10cSrcweir } 2152cdf0e10cSrcweir DBG_ASSERT( nGlyphCount < 257, "too many glyphs for subsetting" ); 2153cdf0e10cSrcweir 2154cdf0e10cSrcweir // TODO: where to get bVertical? 2155cdf0e10cSrcweir const bool bVertical = false; 2156cdf0e10cSrcweir 2157cdf0e10cSrcweir // fill the pGlyphWidths array 2158cdf0e10cSrcweir // while making sure that the NotDef glyph is at index==0 2159cdf0e10cSrcweir TTSimpleGlyphMetrics* pGlyphMetrics = 2160cdf0e10cSrcweir ::GetTTSimpleGlyphMetrics( pSftFont, aShortIDs, nGlyphCount, bVertical ); 2161cdf0e10cSrcweir if( !pGlyphMetrics ) 2162cdf0e10cSrcweir return sal_False; 2163cdf0e10cSrcweir sal_uInt16 nNotDefAdv = pGlyphMetrics[0].adv; 2164cdf0e10cSrcweir pGlyphMetrics[0].adv = pGlyphMetrics[nNotDef].adv; 2165cdf0e10cSrcweir pGlyphMetrics[nNotDef].adv = nNotDefAdv; 2166cdf0e10cSrcweir for( int i = 0; i < nOrigCount; ++i ) 2167cdf0e10cSrcweir pGlyphWidths[i] = pGlyphMetrics[i].adv; 2168cdf0e10cSrcweir free( pGlyphMetrics ); 2169cdf0e10cSrcweir 2170cdf0e10cSrcweir // write subset into destination file 2171cdf0e10cSrcweir nRC = ::CreateTTFromTTGlyphs( pSftFont, aToFile.GetBuffer(), aShortIDs, 2172cdf0e10cSrcweir aTempEncs, nGlyphCount, 0, NULL, 0 ); 2173cdf0e10cSrcweir ::CloseTTFont(pSftFont); 2174cdf0e10cSrcweir return (nRC == SF_OK); 2175cdf0e10cSrcweir } 2176cdf0e10cSrcweir 2177cdf0e10cSrcweir // ----------------------------------------------------------------------- 2178cdf0e10cSrcweir 2179cdf0e10cSrcweir void AquaSalGraphics::GetGlyphWidths( const ImplFontData* pFontData, bool bVertical, 2180cdf0e10cSrcweir Int32Vector& rGlyphWidths, Ucs2UIntMap& rUnicodeEnc ) 2181cdf0e10cSrcweir { 2182cdf0e10cSrcweir rGlyphWidths.clear(); 2183cdf0e10cSrcweir rUnicodeEnc.clear(); 2184cdf0e10cSrcweir 2185cdf0e10cSrcweir if( pFontData->IsSubsettable() ) 2186e26449d3SHerbert Dürr { 2187cdf0e10cSrcweir ByteVector aBuffer; 2188cdf0e10cSrcweir if( !GetRawFontData( pFontData, aBuffer, NULL ) ) 2189cdf0e10cSrcweir return; 2190cdf0e10cSrcweir 2191cdf0e10cSrcweir // TODO: modernize psprint's horrible fontsubset C-API 2192cdf0e10cSrcweir // this probably only makes sense after the switch to another SCM 2193cdf0e10cSrcweir // that can preserve change history after file renames 2194cdf0e10cSrcweir 2195cdf0e10cSrcweir // use the font subsetter to get the widths 2196cdf0e10cSrcweir TrueTypeFont* pSftFont = NULL; 2197cdf0e10cSrcweir int nRC = ::OpenTTFontBuffer( (void*)&aBuffer[0], aBuffer.size(), 0, &pSftFont); 2198cdf0e10cSrcweir if( nRC != SF_OK ) 2199cdf0e10cSrcweir return; 2200cdf0e10cSrcweir 2201cdf0e10cSrcweir const int nGlyphCount = ::GetTTGlyphCount( pSftFont ); 2202cdf0e10cSrcweir if( nGlyphCount > 0 ) 2203cdf0e10cSrcweir { 2204cdf0e10cSrcweir // get glyph metrics 2205cdf0e10cSrcweir rGlyphWidths.resize(nGlyphCount); 2206cdf0e10cSrcweir std::vector<sal_uInt16> aGlyphIds(nGlyphCount); 2207cdf0e10cSrcweir for( int i = 0; i < nGlyphCount; i++ ) 2208cdf0e10cSrcweir aGlyphIds[i] = static_cast<sal_uInt16>(i); 2209cdf0e10cSrcweir const TTSimpleGlyphMetrics* pGlyphMetrics = ::GetTTSimpleGlyphMetrics( 2210cdf0e10cSrcweir pSftFont, &aGlyphIds[0], nGlyphCount, bVertical ); 2211cdf0e10cSrcweir if( pGlyphMetrics ) 2212cdf0e10cSrcweir { 2213cdf0e10cSrcweir for( int i = 0; i < nGlyphCount; ++i ) 2214cdf0e10cSrcweir rGlyphWidths[i] = pGlyphMetrics[i].adv; 2215cdf0e10cSrcweir free( (void*)pGlyphMetrics ); 2216cdf0e10cSrcweir } 2217cdf0e10cSrcweir 2218cdf0e10cSrcweir const ImplFontCharMap* pMap = mpMacFontData->GetImplFontCharMap(); 2219cdf0e10cSrcweir DBG_ASSERT( pMap && pMap->GetCharCount(), "no charmap" ); 2220cdf0e10cSrcweir pMap->AddReference(); // TODO: add and use RAII object instead 2221cdf0e10cSrcweir 2222cdf0e10cSrcweir // get unicode<->glyph encoding 2223cdf0e10cSrcweir // TODO? avoid sft mapping by using the pMap itself 2224cdf0e10cSrcweir int nCharCount = pMap->GetCharCount(); 2225cdf0e10cSrcweir sal_uInt32 nChar = pMap->GetFirstChar(); 2226cdf0e10cSrcweir for(; --nCharCount >= 0; nChar = pMap->GetNextChar( nChar ) ) 2227cdf0e10cSrcweir { 2228cdf0e10cSrcweir if( nChar > 0xFFFF ) // TODO: allow UTF-32 chars 2229cdf0e10cSrcweir break; 2230cdf0e10cSrcweir sal_Ucs nUcsChar = static_cast<sal_Ucs>(nChar); 2231cdf0e10cSrcweir sal_uInt32 nGlyph = ::MapChar( pSftFont, nUcsChar, bVertical ); 2232cdf0e10cSrcweir if( nGlyph > 0 ) 2233cdf0e10cSrcweir rUnicodeEnc[ nUcsChar ] = nGlyph; 2234cdf0e10cSrcweir } 2235cdf0e10cSrcweir 2236cdf0e10cSrcweir pMap->DeReference(); // TODO: add and use RAII object instead 2237cdf0e10cSrcweir } 2238cdf0e10cSrcweir 2239cdf0e10cSrcweir ::CloseTTFont( pSftFont ); 2240cdf0e10cSrcweir } 2241cdf0e10cSrcweir else if( pFontData->IsEmbeddable() ) 2242cdf0e10cSrcweir { 2243cdf0e10cSrcweir // get individual character widths 2244cdf0e10cSrcweir #if 0 // FIXME 2245cdf0e10cSrcweir rWidths.reserve( 224 ); 2246cdf0e10cSrcweir for( sal_Unicode i = 32; i < 256; ++i ) 2247cdf0e10cSrcweir { 2248cdf0e10cSrcweir int nCharWidth = 0; 2249cdf0e10cSrcweir if( ::GetCharWidth32W( mhDC, i, i, &nCharWidth ) ) 2250cdf0e10cSrcweir { 2251cdf0e10cSrcweir rUnicodeEnc[ i ] = rWidths.size(); 2252cdf0e10cSrcweir rWidths.push_back( nCharWidth ); 2253cdf0e10cSrcweir } 2254cdf0e10cSrcweir } 2255cdf0e10cSrcweir #else 2256cdf0e10cSrcweir DBG_ERROR("not implemented for non-subsettable fonts!\n"); 2257cdf0e10cSrcweir #endif 2258cdf0e10cSrcweir } 2259cdf0e10cSrcweir } 2260cdf0e10cSrcweir 2261cdf0e10cSrcweir // ----------------------------------------------------------------------- 2262cdf0e10cSrcweir 2263cdf0e10cSrcweir const Ucs2SIntMap* AquaSalGraphics::GetFontEncodingVector( 2264cdf0e10cSrcweir const ImplFontData*, const Ucs2OStrMap** /*ppNonEncoded*/ ) 2265cdf0e10cSrcweir { 2266e26449d3SHerbert Dürr return NULL; 2267cdf0e10cSrcweir } 2268cdf0e10cSrcweir 2269cdf0e10cSrcweir // ----------------------------------------------------------------------- 2270cdf0e10cSrcweir 2271cdf0e10cSrcweir const void* AquaSalGraphics::GetEmbedFontData( const ImplFontData*, 2272cdf0e10cSrcweir const sal_Ucs* /*pUnicodes*/, 2273cdf0e10cSrcweir sal_Int32* /*pWidths*/, 2274cdf0e10cSrcweir FontSubsetInfo&, 2275cdf0e10cSrcweir long* /*pDataLen*/ ) 2276cdf0e10cSrcweir { 2277e26449d3SHerbert Dürr return NULL; 2278cdf0e10cSrcweir } 2279cdf0e10cSrcweir 2280cdf0e10cSrcweir // ----------------------------------------------------------------------- 2281cdf0e10cSrcweir 2282cdf0e10cSrcweir void AquaSalGraphics::FreeEmbedFontData( const void* pData, long /*nDataLen*/ ) 2283cdf0e10cSrcweir { 2284e26449d3SHerbert Dürr // TODO: implementing this only makes sense when the implementation of 2285cdf0e10cSrcweir // AquaSalGraphics::GetEmbedFontData() returns non-NULL 2286cdf0e10cSrcweir (void)pData; 2287cdf0e10cSrcweir DBG_ASSERT( (pData!=NULL), "AquaSalGraphics::FreeEmbedFontData() is not implemented\n"); 2288cdf0e10cSrcweir } 2289cdf0e10cSrcweir 2290cdf0e10cSrcweir // ----------------------------------------------------------------------- 2291cdf0e10cSrcweir 2292cdf0e10cSrcweir SystemFontData AquaSalGraphics::GetSysFontData( int /* nFallbacklevel */ ) const 2293cdf0e10cSrcweir { 2294cdf0e10cSrcweir SystemFontData aSysFontData; 2295cdf0e10cSrcweir aSysFontData.nSize = sizeof( SystemFontData ); 2296cdf0e10cSrcweir 2297e26449d3SHerbert Dürr #ifdef USE_ATSU 2298cdf0e10cSrcweir // NOTE: Native ATSU font fallbacks are used, not the VCL fallbacks. 2299cdf0e10cSrcweir ATSUFontID fontId; 2300e26449d3SHerbert Dürr OSStatus err; 2301cdf0e10cSrcweir err = ATSUGetAttribute( maATSUStyle, kATSUFontTag, sizeof(fontId), &fontId, 0 ); 2302cdf0e10cSrcweir if (err) fontId = 0; 2303cdf0e10cSrcweir aSysFontData.aATSUFontID = (void *) fontId; 2304cdf0e10cSrcweir 2305cdf0e10cSrcweir Boolean bFbold; 2306cdf0e10cSrcweir err = ATSUGetAttribute( maATSUStyle, kATSUQDBoldfaceTag, sizeof(bFbold), &bFbold, 0 ); 2307cdf0e10cSrcweir if (err) bFbold = FALSE; 2308cdf0e10cSrcweir aSysFontData.bFakeBold = (bool) bFbold; 2309cdf0e10cSrcweir 2310cdf0e10cSrcweir Boolean bFItalic; 2311cdf0e10cSrcweir err = ATSUGetAttribute( maATSUStyle, kATSUQDItalicTag, sizeof(bFItalic), &bFItalic, 0 ); 2312cdf0e10cSrcweir if (err) bFItalic = FALSE; 2313cdf0e10cSrcweir aSysFontData.bFakeItalic = (bool) bFItalic; 2314cdf0e10cSrcweir 2315cdf0e10cSrcweir ATSUVerticalCharacterType aVerticalCharacterType; 2316cdf0e10cSrcweir err = ATSUGetAttribute( maATSUStyle, kATSUVerticalCharacterTag, sizeof(aVerticalCharacterType), &aVerticalCharacterType, 0 ); 2317cdf0e10cSrcweir if (!err && aVerticalCharacterType == kATSUStronglyVertical) { 2318cdf0e10cSrcweir aSysFontData.bVerticalCharacterType = true; 2319cdf0e10cSrcweir } else { 2320cdf0e10cSrcweir aSysFontData.bVerticalCharacterType = false; 2321cdf0e10cSrcweir } 2322e26449d3SHerbert Dürr #endif // USE_ATSU 2323cdf0e10cSrcweir 2324cdf0e10cSrcweir aSysFontData.bAntialias = !mbNonAntialiasedText; 2325cdf0e10cSrcweir 2326cdf0e10cSrcweir return aSysFontData; 2327cdf0e10cSrcweir } 2328cdf0e10cSrcweir 2329cdf0e10cSrcweir // ----------------------------------------------------------------------- 2330cdf0e10cSrcweir 2331cdf0e10cSrcweir SystemGraphicsData AquaSalGraphics::GetGraphicsData() const 2332cdf0e10cSrcweir { 2333cdf0e10cSrcweir SystemGraphicsData aRes; 2334cdf0e10cSrcweir aRes.nSize = sizeof(aRes); 2335cdf0e10cSrcweir aRes.rCGContext = mrContext; 2336cdf0e10cSrcweir return aRes; 2337cdf0e10cSrcweir } 2338cdf0e10cSrcweir 2339cdf0e10cSrcweir // ----------------------------------------------------------------------- 2340cdf0e10cSrcweir 2341cdf0e10cSrcweir void AquaSalGraphics::SetXORMode( bool bSet, bool bInvertOnly ) 2342cdf0e10cSrcweir { 2343cdf0e10cSrcweir // return early if XOR mode remains unchanged 2344cdf0e10cSrcweir if( mbPrinter ) 2345cdf0e10cSrcweir return; 2346cdf0e10cSrcweir 2347cdf0e10cSrcweir if( ! bSet && mnXorMode == 2 ) 2348cdf0e10cSrcweir { 2349cdf0e10cSrcweir CGContextSetBlendMode( mrContext, kCGBlendModeNormal ); 2350cdf0e10cSrcweir mnXorMode = 0; 2351cdf0e10cSrcweir return; 2352cdf0e10cSrcweir } 2353cdf0e10cSrcweir else if( bSet && bInvertOnly && mnXorMode == 0) 2354cdf0e10cSrcweir { 2355cdf0e10cSrcweir CGContextSetBlendMode( mrContext, kCGBlendModeDifference ); 2356cdf0e10cSrcweir mnXorMode = 2; 2357cdf0e10cSrcweir return; 2358cdf0e10cSrcweir } 2359cdf0e10cSrcweir 2360cdf0e10cSrcweir if( (mpXorEmulation == NULL) && !bSet ) 2361cdf0e10cSrcweir return; 2362cdf0e10cSrcweir if( (mpXorEmulation != NULL) && (bSet == mpXorEmulation->IsEnabled()) ) 2363cdf0e10cSrcweir return; 2364cdf0e10cSrcweir if( !CheckContext() ) 2365cdf0e10cSrcweir return; 2366cdf0e10cSrcweir 2367cdf0e10cSrcweir // prepare XOR emulation 2368cdf0e10cSrcweir if( !mpXorEmulation ) 2369cdf0e10cSrcweir { 2370cdf0e10cSrcweir mpXorEmulation = new XorEmulation(); 2371cdf0e10cSrcweir mpXorEmulation->SetTarget( mnWidth, mnHeight, mnBitmapDepth, mrContext, mxLayer ); 2372cdf0e10cSrcweir } 2373cdf0e10cSrcweir 2374cdf0e10cSrcweir // change the XOR mode 2375cdf0e10cSrcweir if( bSet ) 2376cdf0e10cSrcweir { 2377cdf0e10cSrcweir mpXorEmulation->Enable(); 2378cdf0e10cSrcweir mrContext = mpXorEmulation->GetMaskContext(); 2379cdf0e10cSrcweir mnXorMode = 1; 2380cdf0e10cSrcweir } 2381cdf0e10cSrcweir else 2382cdf0e10cSrcweir { 2383cdf0e10cSrcweir mpXorEmulation->UpdateTarget(); 2384cdf0e10cSrcweir mpXorEmulation->Disable(); 2385cdf0e10cSrcweir mrContext = mpXorEmulation->GetTargetContext(); 2386cdf0e10cSrcweir mnXorMode = 0; 2387cdf0e10cSrcweir } 2388cdf0e10cSrcweir } 2389cdf0e10cSrcweir 2390cdf0e10cSrcweir // ----------------------------------------------------------------------- 2391cdf0e10cSrcweir 2392cdf0e10cSrcweir // apply the XOR mask to the target context if active and dirty 2393cdf0e10cSrcweir void AquaSalGraphics::ApplyXorContext() 2394cdf0e10cSrcweir { 2395cdf0e10cSrcweir if( !mpXorEmulation ) 2396cdf0e10cSrcweir return; 2397cdf0e10cSrcweir if( mpXorEmulation->UpdateTarget() ) 2398cdf0e10cSrcweir RefreshRect( 0, 0, mnWidth, mnHeight ); // TODO: refresh minimal changerect 2399cdf0e10cSrcweir } 2400cdf0e10cSrcweir 2401cdf0e10cSrcweir // ====================================================================== 2402cdf0e10cSrcweir 2403cdf0e10cSrcweir XorEmulation::XorEmulation() 2404cdf0e10cSrcweir : mxTargetLayer( NULL ) 2405cdf0e10cSrcweir , mxTargetContext( NULL ) 2406cdf0e10cSrcweir , mxMaskContext( NULL ) 2407cdf0e10cSrcweir , mxTempContext( NULL ) 2408cdf0e10cSrcweir , mpMaskBuffer( NULL ) 2409cdf0e10cSrcweir , mpTempBuffer( NULL ) 2410cdf0e10cSrcweir , mnBufferLongs( 0 ) 2411cdf0e10cSrcweir , mbIsEnabled( false ) 2412cdf0e10cSrcweir {} 2413cdf0e10cSrcweir 2414cdf0e10cSrcweir // ---------------------------------------------------------------------- 2415cdf0e10cSrcweir 2416cdf0e10cSrcweir XorEmulation::~XorEmulation() 2417cdf0e10cSrcweir { 2418cdf0e10cSrcweir Disable(); 2419cdf0e10cSrcweir SetTarget( 0, 0, 0, NULL, NULL ); 2420cdf0e10cSrcweir } 2421cdf0e10cSrcweir 2422cdf0e10cSrcweir // ----------------------------------------------------------------------- 2423cdf0e10cSrcweir 2424cdf0e10cSrcweir void XorEmulation::SetTarget( int nWidth, int nHeight, int nTargetDepth, 2425cdf0e10cSrcweir CGContextRef xTargetContext, CGLayerRef xTargetLayer ) 2426cdf0e10cSrcweir { 2427cdf0e10cSrcweir // prepare to replace old mask+temp context 2428cdf0e10cSrcweir if( mxMaskContext ) 2429cdf0e10cSrcweir { 2430cdf0e10cSrcweir // cleanup the mask context 2431cdf0e10cSrcweir CGContextRelease( mxMaskContext ); 2432cdf0e10cSrcweir delete[] mpMaskBuffer; 2433cdf0e10cSrcweir mxMaskContext = NULL; 2434cdf0e10cSrcweir mpMaskBuffer = NULL; 2435cdf0e10cSrcweir 2436cdf0e10cSrcweir // cleanup the temp context if needed 2437cdf0e10cSrcweir if( mxTempContext ) 2438cdf0e10cSrcweir { 2439cdf0e10cSrcweir CGContextRelease( mxTempContext ); 2440cdf0e10cSrcweir delete[] mpTempBuffer; 2441cdf0e10cSrcweir mxTempContext = NULL; 2442cdf0e10cSrcweir mpTempBuffer = NULL; 2443cdf0e10cSrcweir } 2444cdf0e10cSrcweir } 2445cdf0e10cSrcweir 2446cdf0e10cSrcweir // return early if there is nothing more to do 2447cdf0e10cSrcweir if( !xTargetContext ) 2448cdf0e10cSrcweir return; 2449cdf0e10cSrcweir 2450cdf0e10cSrcweir // retarget drawing operations to the XOR mask 2451cdf0e10cSrcweir mxTargetLayer = xTargetLayer; 2452cdf0e10cSrcweir mxTargetContext = xTargetContext; 2453cdf0e10cSrcweir 2454cdf0e10cSrcweir // prepare creation of matching CGBitmaps 2455cdf0e10cSrcweir CGColorSpaceRef aCGColorSpace = GetSalData()->mxRGBSpace; 2456cdf0e10cSrcweir CGBitmapInfo aCGBmpInfo = kCGImageAlphaNoneSkipFirst; 2457cdf0e10cSrcweir int nBitDepth = nTargetDepth; 2458cdf0e10cSrcweir if( !nBitDepth ) 2459cdf0e10cSrcweir nBitDepth = 32; 2460cdf0e10cSrcweir int nBytesPerRow = (nBitDepth == 16) ? 2 : 4; 2461cdf0e10cSrcweir const size_t nBitsPerComponent = (nBitDepth == 16) ? 5 : 8; 2462cdf0e10cSrcweir if( nBitDepth <= 8 ) 2463cdf0e10cSrcweir { 2464cdf0e10cSrcweir aCGColorSpace = GetSalData()->mxGraySpace; 2465cdf0e10cSrcweir aCGBmpInfo = kCGImageAlphaNone; 2466cdf0e10cSrcweir nBytesPerRow = 1; 2467cdf0e10cSrcweir } 2468cdf0e10cSrcweir nBytesPerRow *= nWidth; 2469cdf0e10cSrcweir mnBufferLongs = (nHeight * nBytesPerRow + sizeof(sal_uLong)-1) / sizeof(sal_uLong); 2470cdf0e10cSrcweir 2471cdf0e10cSrcweir // create a XorMask context 2472cdf0e10cSrcweir mpMaskBuffer = new sal_uLong[ mnBufferLongs ]; 2473cdf0e10cSrcweir mxMaskContext = ::CGBitmapContextCreate( mpMaskBuffer, 2474cdf0e10cSrcweir nWidth, nHeight, nBitsPerComponent, nBytesPerRow, 2475cdf0e10cSrcweir aCGColorSpace, aCGBmpInfo ); 2476cdf0e10cSrcweir // reset the XOR mask to black 2477cdf0e10cSrcweir memset( mpMaskBuffer, 0, mnBufferLongs * sizeof(sal_uLong) ); 2478cdf0e10cSrcweir 2479cdf0e10cSrcweir // a bitmap context will be needed for manual XORing 2480cdf0e10cSrcweir // create one unless the target context is a bitmap context 2481cdf0e10cSrcweir if( nTargetDepth ) 2482cdf0e10cSrcweir mpTempBuffer = (sal_uLong*)CGBitmapContextGetData( mxTargetContext ); 2483cdf0e10cSrcweir if( !mpTempBuffer ) 2484cdf0e10cSrcweir { 2485cdf0e10cSrcweir // create a bitmap context matching to the target context 2486cdf0e10cSrcweir mpTempBuffer = new sal_uLong[ mnBufferLongs ]; 2487cdf0e10cSrcweir mxTempContext = ::CGBitmapContextCreate( mpTempBuffer, 2488cdf0e10cSrcweir nWidth, nHeight, nBitsPerComponent, nBytesPerRow, 2489cdf0e10cSrcweir aCGColorSpace, aCGBmpInfo ); 2490cdf0e10cSrcweir } 2491cdf0e10cSrcweir 2492cdf0e10cSrcweir // initialize XOR mask context for drawing 2493cdf0e10cSrcweir CGContextSetFillColorSpace( mxMaskContext, aCGColorSpace ); 2494cdf0e10cSrcweir CGContextSetStrokeColorSpace( mxMaskContext, aCGColorSpace ); 2495cdf0e10cSrcweir CGContextSetShouldAntialias( mxMaskContext, false ); 2496cdf0e10cSrcweir 2497cdf0e10cSrcweir // improve the XorMask's XOR emulation a litte 2498cdf0e10cSrcweir // NOTE: currently only enabled for monochrome contexts 2499cdf0e10cSrcweir if( aCGColorSpace == GetSalData()->mxGraySpace ) 2500cdf0e10cSrcweir CGContextSetBlendMode( mxMaskContext, kCGBlendModeDifference ); 2501cdf0e10cSrcweir 2502*509df7cbSJohn Bampton // initialize the transformation matrix to the drawing target 2503cdf0e10cSrcweir const CGAffineTransform aCTM = CGContextGetCTM( xTargetContext ); 2504cdf0e10cSrcweir CGContextConcatCTM( mxMaskContext, aCTM ); 2505cdf0e10cSrcweir if( mxTempContext ) 2506cdf0e10cSrcweir CGContextConcatCTM( mxTempContext, aCTM ); 2507cdf0e10cSrcweir 2508cdf0e10cSrcweir // initialize the default XorMask graphics state 2509cdf0e10cSrcweir CGContextSaveGState( mxMaskContext ); 2510cdf0e10cSrcweir } 2511cdf0e10cSrcweir 2512cdf0e10cSrcweir // ---------------------------------------------------------------------- 2513cdf0e10cSrcweir 2514cdf0e10cSrcweir bool XorEmulation::UpdateTarget() 2515cdf0e10cSrcweir { 2516cdf0e10cSrcweir if( !IsEnabled() ) 2517cdf0e10cSrcweir return false; 2518cdf0e10cSrcweir 2519cdf0e10cSrcweir // update the temp bitmap buffer if needed 2520cdf0e10cSrcweir if( mxTempContext ) 2521cdf0e10cSrcweir CGContextDrawLayerAtPoint( mxTempContext, CGPointZero, mxTargetLayer ); 2522cdf0e10cSrcweir 2523cdf0e10cSrcweir // do a manual XOR with the XorMask 2524cdf0e10cSrcweir // this approach suffices for simple color manipulations 2525cdf0e10cSrcweir // and also the complex-clipping-XOR-trick used in metafiles 2526cdf0e10cSrcweir const sal_uLong* pSrc = mpMaskBuffer; 2527cdf0e10cSrcweir sal_uLong* pDst = mpTempBuffer; 2528cdf0e10cSrcweir for( int i = mnBufferLongs; --i >= 0;) 2529cdf0e10cSrcweir *(pDst++) ^= *(pSrc++); 2530cdf0e10cSrcweir 2531cdf0e10cSrcweir // write back the XOR results to the target context 2532cdf0e10cSrcweir if( mxTempContext ) 2533cdf0e10cSrcweir { 2534cdf0e10cSrcweir CGImageRef xXorImage = CGBitmapContextCreateImage( mxTempContext ); 2535cdf0e10cSrcweir const int nWidth = (int)CGImageGetWidth( xXorImage ); 2536cdf0e10cSrcweir const int nHeight = (int)CGImageGetHeight( xXorImage ); 2537cdf0e10cSrcweir // TODO: update minimal changerect 2538a94c8ebdSHerbert Dürr const CGRect aFullRect = CGRectMake( 0, 0, nWidth, nHeight); 2539cdf0e10cSrcweir CGContextDrawImage( mxTargetContext, aFullRect, xXorImage ); 2540cdf0e10cSrcweir CGImageRelease( xXorImage ); 2541cdf0e10cSrcweir } 2542cdf0e10cSrcweir 2543cdf0e10cSrcweir // reset the XorMask to black again 2544cdf0e10cSrcweir // TODO: not needed for last update 2545cdf0e10cSrcweir memset( mpMaskBuffer, 0, mnBufferLongs * sizeof(sal_uLong) ); 2546cdf0e10cSrcweir 2547cdf0e10cSrcweir // TODO: return FALSE if target was not changed 2548cdf0e10cSrcweir return true; 2549cdf0e10cSrcweir } 2550cdf0e10cSrcweir 2551cdf0e10cSrcweir // ======================================================================= 2552