tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / vcl / quartz / CoreTextFontFace.cxx
blob47792fff7a58d9d6c7548c7150cc68588065f179
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
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>
23 #ifdef MACOSX
24 #include <osx/saldata.hxx>
25 #include <osx/salinst.h>
26 #endif
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
49 if (!mxVariations)
51 mxVariations.emplace();
52 CTFontRef pFont = CTFontCreateWithFontDescriptor(mxFontDescriptor, 0.0, nullptr);
53 if (pFont)
55 CFArrayRef pAxes = CTFontCopyVariationAxes(pFont);
56 if (pAxes)
58 CFDictionaryRef pVariations = CTFontCopyVariation(pFont);
59 if (pVariations)
61 CFIndex nAxes = CFArrayGetCount(pAxes);
62 for (CFIndex i = 0; i < nAxes; ++i)
64 auto pAxis = static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(pAxes, i));
65 if (pAxis)
67 hb_tag_t nTag;
68 auto pTag = static_cast<CFNumberRef>(
69 CFDictionaryGetValue(pAxis, kCTFontVariationAxisIdentifierKey));
70 if (!pTag)
71 continue;
72 CFNumberGetValue(pTag, kCFNumberIntType, &nTag);
74 float fValue;
75 auto pValue
76 = static_cast<CFNumberRef>(CFDictionaryGetValue(pVariations, pTag));
77 if (!pValue)
78 continue;
79 CFNumberGetValue(pValue, kCFNumberFloatType, &fValue);
81 mxVariations->push_back({ nTag, fValue });
84 CFRelease(pVariations);
86 CFRelease(pAxes);
88 CFRelease(pFont);
92 return *mxVariations;
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: */