Avoid potential negative array index access to cached text.
[LibreOffice.git] / vcl / quartz / CoreTextFontFace.cxx
blob662b439a9eae3f0419b60391d213f0e4670dca7a
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 CTFontRef pFont = CTFontCreateWithFontDescriptor(mxFontDescriptor, 0.0, nullptr);
51 if (!mxVariations)
53 mxVariations.emplace();
54 CFArrayRef pAxes = CTFontCopyVariationAxes(pFont);
55 if (pAxes)
57 CFDictionaryRef pVariations = CTFontCopyVariation(pFont);
58 if (pVariations)
60 CFIndex nAxes = CFArrayGetCount(pAxes);
61 for (CFIndex i = 0; i < nAxes; ++i)
63 auto pAxis = static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(pAxes, i));
64 if (pAxis)
66 hb_tag_t nTag;
67 auto pTag = static_cast<CFNumberRef>(
68 CFDictionaryGetValue(pAxis, kCTFontVariationAxisIdentifierKey));
69 if (!pTag)
70 continue;
71 CFNumberGetValue(pTag, kCFNumberIntType, &nTag);
73 float fValue;
74 auto pValue
75 = static_cast<CFNumberRef>(CFDictionaryGetValue(pVariations, pTag));
76 if (!pValue)
77 continue;
78 CFNumberGetValue(pValue, kCFNumberFloatType, &fValue);
80 mxVariations->push_back({ nTag, fValue });
83 CFRelease(pVariations);
85 CFRelease(pAxes);
89 return *mxVariations;
92 rtl::Reference<LogicalFontInstance>
93 CoreTextFontFace::CreateFontInstance(const vcl::font::FontSelectPattern& rFSD) const
95 return new CoreTextFont(*this, rFSD);
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */