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>
22 #include <unotools/fontdefs.hxx>
24 #include <Qt5FontFace.hxx>
25 #include <Qt5Font.hxx>
26 #include <Qt5Tools.hxx>
29 #include <impfontcharmap.hxx>
30 #include <fontinstance.hxx>
31 #include <fontselect.hxx>
32 #include <PhysicalFontCollection.hxx>
34 #include <QtGui/QFont>
35 #include <QtGui/QFontDatabase>
36 #include <QtGui/QFontInfo>
37 #include <QtGui/QRawFont>
41 Qt5FontFace::Qt5FontFace(const Qt5FontFace
& rSrc
)
42 : PhysicalFontFace(rSrc
)
43 , m_aFontId(rSrc
.m_aFontId
)
45 if (rSrc
.m_xCharMap
.is())
46 m_xCharMap
= rSrc
.m_xCharMap
;
49 static FontWeight
fromQFontWeight(int nWeight
)
51 FontWeight eWeight
= WEIGHT_DONTKNOW
;
55 eWeight
= WEIGHT_THIN
;
57 case QFont::ExtraLight
:
58 eWeight
= WEIGHT_ULTRALIGHT
;
61 eWeight
= WEIGHT_LIGHT
;
64 eWeight
= WEIGHT_NORMAL
;
67 eWeight
= WEIGHT_MEDIUM
;
70 eWeight
= WEIGHT_SEMIBOLD
;
73 eWeight
= WEIGHT_BOLD
;
75 case QFont::ExtraBold
:
76 eWeight
= WEIGHT_ULTRABOLD
;
79 eWeight
= WEIGHT_BLACK
;
85 void Qt5FontFace::fillAttributesFromQFont(const QFont
& rFont
, FontAttributes
& rFA
)
87 QFontInfo
aFontInfo(rFont
);
89 rFA
.SetFamilyName(toOUString(aFontInfo
.family()));
90 if (IsStarSymbol(toOUString(aFontInfo
.family())))
91 rFA
.SetSymbolFlag(true);
92 rFA
.SetStyleName(toOUString(aFontInfo
.styleName()));
93 rFA
.SetPitch(aFontInfo
.fixedPitch() ? PITCH_FIXED
: PITCH_VARIABLE
);
94 rFA
.SetWeight(fromQFontWeight(aFontInfo
.weight()));
96 switch (aFontInfo
.style())
98 case QFont::StyleNormal
:
99 rFA
.SetItalic(ITALIC_NONE
);
101 case QFont::StyleItalic
:
102 rFA
.SetItalic(ITALIC_NORMAL
);
104 case QFont::StyleOblique
:
105 rFA
.SetItalic(ITALIC_OBLIQUE
);
110 Qt5FontFace
* Qt5FontFace::fromQFont(const QFont
& rFont
)
113 fillAttributesFromQFont(rFont
, aFA
);
114 return new Qt5FontFace(aFA
, rFont
.toString());
117 Qt5FontFace
* Qt5FontFace::fromQFontDatabase(const QString
& aFamily
, const QString
& aStyle
)
121 aFA
.SetFamilyName(toOUString(aFamily
));
122 if (IsStarSymbol(aFA
.GetFamilyName()))
123 aFA
.SetSymbolFlag(true);
124 aFA
.SetStyleName(toOUString(aStyle
));
125 aFA
.SetPitch(aFDB
.isFixedPitch(aFamily
, aStyle
) ? PITCH_FIXED
: PITCH_VARIABLE
);
126 aFA
.SetWeight(fromQFontWeight(aFDB
.weight(aFamily
, aStyle
)));
127 aFA
.SetItalic(aFDB
.italic(aFamily
, aStyle
) ? ITALIC_NORMAL
: ITALIC_NONE
);
128 return new Qt5FontFace(aFA
, aFamily
+ "," + aStyle
);
131 Qt5FontFace::Qt5FontFace(const FontAttributes
& rFA
, const QString
& rFontID
)
132 : PhysicalFontFace(rFA
)
134 , m_bFontCapabilitiesRead(false)
138 sal_IntPtr
Qt5FontFace::GetFontId() const { return reinterpret_cast<sal_IntPtr
>(&m_aFontId
); }
140 rtl::Reference
<LogicalFontInstance
>
141 Qt5FontFace::CreateFontInstance(const FontSelectPattern
& rFSD
) const
143 return new Qt5Font(*this, rFSD
);
146 const FontCharMapRef
& Qt5FontFace::GetFontCharMap() const
152 aFont
.fromString(m_aFontId
);
153 QRawFont
aRawFont(QRawFont::fromFont(aFont
));
154 QByteArray aCMapTable
= aRawFont
.fontTable("cmap");
155 if (aCMapTable
.isEmpty())
157 m_xCharMap
= new FontCharMap();
161 CmapResult aCmapResult
;
162 if (ParseCMAP(reinterpret_cast<const unsigned char*>(aCMapTable
.data()), aCMapTable
.size(),
164 m_xCharMap
= new FontCharMap(aCmapResult
);
169 bool Qt5FontFace::GetFontCapabilities(vcl::FontCapabilities
& rFontCapabilities
) const
171 // read this only once per font
172 if (m_bFontCapabilitiesRead
)
174 rFontCapabilities
= m_aFontCapabilities
;
175 return rFontCapabilities
.oUnicodeRange
|| rFontCapabilities
.oCodePageRange
;
177 m_bFontCapabilitiesRead
= true;
180 aFont
.fromString(m_aFontId
);
181 QRawFont
aRawFont(QRawFont::fromFont(aFont
));
182 QByteArray aOS2Table
= aRawFont
.fontTable("OS/2");
183 if (!aOS2Table
.isEmpty())
185 vcl::getTTCoverage(m_aFontCapabilities
.oUnicodeRange
, m_aFontCapabilities
.oCodePageRange
,
186 reinterpret_cast<const unsigned char*>(aOS2Table
.data()),
190 rFontCapabilities
= m_aFontCapabilities
;
191 return rFontCapabilities
.oUnicodeRange
|| rFontCapabilities
.oCodePageRange
;
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */