1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
25 #include <rtl/alloc.h>
26 #include <rtl/ustrbuf.hxx>
28 #include <quartz/utils.h>
30 OUString
GetOUString( CFStringRef rStr
)
37 CFIndex nLength
= CFStringGetLength( rStr
);
43 const UniChar
* pConstStr
= CFStringGetCharactersPtr( rStr
);
46 return OUString( reinterpret_cast<sal_Unicode
const *>(pConstStr
), nLength
);
49 std::unique_ptr
<UniChar
[]> pStr(new UniChar
[nLength
]);
50 CFRange aRange
= { 0, nLength
};
51 CFStringGetCharacters( rStr
, aRange
, pStr
.get() );
53 OUString
aRet( reinterpret_cast<sal_Unicode
*>(pStr
.get()), nLength
);
57 OUString
GetOUString( const NSString
* pStr
)
64 int nLen
= [pStr length
];
70 OUStringBuffer
aBuf( nLen
+1 );
71 aBuf
.setLength( nLen
);
73 reinterpret_cast<unichar
*>(const_cast<sal_Unicode
*>(aBuf
.getStr()))];
75 return aBuf
.makeStringAndClear();
78 CFStringRef
CreateCFString( const OUString
& rStr
)
80 return CFStringCreateWithCharacters(kCFAllocatorDefault
, reinterpret_cast<UniChar
const *>(rStr
.getStr()), rStr
.getLength() );
83 NSString
* CreateNSString( const OUString
& rStr
)
85 return [[NSString alloc
] initWithCharacters
: reinterpret_cast<unichar
const *>(rStr
.getStr()) length
: rStr
.getLength()];
88 OUString
NSStringArrayToOUString(NSArray
* array
)
90 OUString result
= "[";
92 for (NSUInteger i
= 0; i
< [array count
]; i
++)
94 result
= result
+ sep
+ OUString::fromUtf8([[array objectAtIndex
:i
] UTF8String
]);
97 result
= result
+ "]";
101 OUString
NSDictionaryKeysToOUString(NSDictionary
* dict
)
103 OUString result
= "{";
105 for (NSString
*key in dict
)
107 result
= result
+ sep
+ OUString::fromUtf8([key UTF8String
]);
110 result
= result
+ "}";
114 std::ostream
&operator <<(std::ostream
& s
, const CGRect
&rRect
)
119 if (CGRectIsNull(rRect
))
125 s
<< rRect
.size
<< "@" << rRect
.origin
;
131 std::ostream
&operator <<(std::ostream
& s
, const CGPoint
&rPoint
)
136 s
<< "(" << rPoint
.x
<< "," << rPoint
.y
<< ")";
141 std::ostream
&operator <<(std::ostream
& s
, const CGSize
&rSize
)
146 s
<< rSize
.width
<< "x" << rSize
.height
;
151 std::ostream
&operator <<(std::ostream
& s
, CGColorRef pColor
)
156 CFStringRef colorString
= CFCopyDescription(pColor
);
159 s
<< GetOUString(colorString
);
160 CFRelease(colorString
);
170 std::ostream
&operator <<(std::ostream
& s
, const CGAffineTransform
&aXform
)
175 if (CGAffineTransformIsIdentity(aXform
))
181 s
<< "[" << aXform
.a
<< "," << aXform
.b
<< "," << aXform
.c
<< "," << aXform
.d
<< "," << aXform
.tx
<< "," << aXform
.ty
<< "]";
187 std::ostream
&operator <<(std::ostream
& s
, CGColorSpaceRef cs
)
198 CGColorSpaceModel model
= CGColorSpaceGetModel(cs
);
201 case kCGColorSpaceModelUnknown
:
204 case kCGColorSpaceModelMonochrome
:
207 case kCGColorSpaceModelRGB
:
209 if (CGColorSpaceIsWideGamutRGB(cs
))
210 s
<< " (wide gamut)";
212 case kCGColorSpaceModelCMYK
:
215 case kCGColorSpaceModelLab
:
218 case kCGColorSpaceModelDeviceN
:
221 case kCGColorSpaceModelIndexed
:
222 s
<< "Indexed (" << CGColorSpaceGetColorTableCount(cs
) << ")";
224 case kCGColorSpaceModelPattern
:
227 case kCGColorSpaceModelXYZ
:
231 s
<< "?(" << model
<< ")";
235 CFStringRef name
= CGColorSpaceCopyName(cs
);
237 s
<< " (" << [static_cast<NSString
*>(name
) UTF8String
] << ")";
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */