Debian Codegraph @

texk/web2c/xetexdir/XeTeXFontInst_Mac.cpp

raw
1 /****************************************************************************\
2 Part of the XeTeX typesetting system
3 Copyright (c) 1994-2008 by SIL International
4 Copyright (c) 2009 by Jonathan Kew
5 Copyright (c) 2012, 2013 by Jiang Jiang
6 Copyright (c) 2012-2015 by Khaled Hosny
7
8 SIL Author(s): Jonathan Kew
9
10 Permission is hereby granted, free of charge, to any person obtaining
11 a copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sublicense, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
17
18 The above copyright notice and this permission notice shall be
19 included in all copies or substantial portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
25 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
26 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29 Except as contained in this notice, the name of the copyright holders
30 shall not be used in advertising or otherwise to promote the sale,
31 use or other dealings in this Software without prior written
32 authorization from the copyright holders.
33 \****************************************************************************/
34
35 /*
36 * file name: XeTeXFontInst_Mac.cpp
37 *
38 * created on: 2005-10-22
39 * created by: Jonathan Kew
40 */
41
42 #include <w2c/config.h>
43
44 #include "XeTeXFontInst_Mac.h"
45 #include "XeTeX_ext.h"
46
47 XeTeXFontInst_Mac::XeTeXFontInst_Mac(CTFontDescriptorRef descriptor, float pointSize, int &status)
48 : XeTeXFontInst(NULL, 0, pointSize, status)
49 , m_descriptor(descriptor)
50 , m_fontRef(0)
51 {
52 initialize(status);
53 }
54
55 XeTeXFontInst_Mac::~XeTeXFontInst_Mac()
56 {
57 if (m_descriptor != 0)
58 CFRelease(m_descriptor);
59 if (m_fontRef != 0)
60 CFRelease(m_fontRef);
61 }
62
63 void
64 XeTeXFontInst_Mac::initialize(int &status)
65 {
66 if (m_descriptor == 0) {
67 status = 1;
68 return;
69 }
70
71 if (status != 0)
72 m_descriptor = 0;
73
74 // Create a copy of original font descriptor with font cascading (fallback) disabled
75 CFArrayRef emptyCascadeList = CFArrayCreate(NULL, NULL, 0, &kCFTypeArrayCallBacks);
76 const void* values[] = { emptyCascadeList };
77 static const void* attributeKeys[] = { kCTFontCascadeListAttribute };
78 CFDictionaryRef attributes = CFDictionaryCreate(NULL, attributeKeys, values, 1,
79 &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
80 CFRelease(emptyCascadeList);
81
82 m_descriptor = CTFontDescriptorCreateCopyWithAttributes(m_descriptor, attributes);
83 CFRelease(attributes);
84 m_fontRef = CTFontCreateWithFontDescriptor(m_descriptor, m_pointSize * 72.0 / 72.27, NULL);
85 if (m_fontRef) {
86 char *pathname;
87 uint32_t index;
88 pathname = getFileNameFromCTFont(m_fontRef, &index);
89
90 XeTeXFontInst::initialize(pathname, index, status);
91 } else {
92 status = 1;
93 CFRelease(m_descriptor);
94 m_descriptor = 0;
95 }
96 }