1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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>
21 #include <sal/log.hxx>
24 #include <osx/saldata.hxx>
25 #include <osx/salinst.h>
27 #include <font/LogicalFontInstance.hxx>
28 #include <quartz/CoreTextFont.hxx>
29 #include <quartz/CoreTextFontFace.hxx>
30 #include <quartz/salgdi.h>
31 #include <quartz/utils.h>
33 CoreTextFontFace::CoreTextFontFace(const FontAttributes
& rDFA
, CTFontDescriptorRef xFontDescriptor
)
34 : vcl::font::PhysicalFontFace(rDFA
)
35 , mxFontDescriptor(xFontDescriptor
)
37 CFRetain(mxFontDescriptor
);
40 CoreTextFontFace::~CoreTextFontFace() { CFRelease(mxFontDescriptor
); }
42 sal_IntPtr
CoreTextFontFace::GetFontId() const
44 return reinterpret_cast<sal_IntPtr
>(mxFontDescriptor
);
47 const std::vector
<hb_variation_t
>& CoreTextFontFace::GetVariations(const LogicalFontInstance
&) const
51 mxVariations
.emplace();
52 CTFontRef pFont
= CTFontCreateWithFontDescriptor(mxFontDescriptor
, 0.0, nullptr);
55 CFArrayRef pAxes
= CTFontCopyVariationAxes(pFont
);
58 CFDictionaryRef pVariations
= CTFontCopyVariation(pFont
);
61 CFIndex nAxes
= CFArrayGetCount(pAxes
);
62 for (CFIndex i
= 0; i
< nAxes
; ++i
)
64 auto pAxis
= static_cast<CFDictionaryRef
>(CFArrayGetValueAtIndex(pAxes
, i
));
68 auto pTag
= static_cast<CFNumberRef
>(
69 CFDictionaryGetValue(pAxis
, kCTFontVariationAxisIdentifierKey
));
72 CFNumberGetValue(pTag
, kCFNumberIntType
, &nTag
);
76 = static_cast<CFNumberRef
>(CFDictionaryGetValue(pVariations
, pTag
));
79 CFNumberGetValue(pValue
, kCFNumberFloatType
, &fValue
);
81 mxVariations
->push_back({ nTag
, fValue
});
84 CFRelease(pVariations
);
95 rtl::Reference
<LogicalFontInstance
>
96 CoreTextFontFace::CreateFontInstance(const vcl::font::FontSelectPattern
& rFSD
) const
98 return new CoreTextFont(*this, rFSD
);
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */