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 "Qt5FontFace.hxx"
21 #include "Qt5Font.hxx"
22 #include "Qt5Tools.hxx"
25 #include <impfontcharmap.hxx>
26 #include <fontinstance.hxx>
27 #include <fontselect.hxx>
28 #include <PhysicalFontCollection.hxx>
30 #include <QtGui/QFont>
31 #include <QtGui/QRawFont>
35 Qt5FontFace::Qt5FontFace(const Qt5FontFace
& rSrc
)
36 : PhysicalFontFace(rSrc
)
37 , m_aFontId(rSrc
.m_aFontId
)
39 if (rSrc
.m_xCharMap
.is())
40 m_xCharMap
= rSrc
.m_xCharMap
;
43 Qt5FontFace
* Qt5FontFace::fromQFont(const QFont
& rFont
)
46 aFA
.SetFamilyName(toOUString(rFont
.family()));
47 aFA
.SetStyleName(toOUString(rFont
.styleName()));
48 aFA
.SetItalic(rFont
.italic() ? ITALIC_NORMAL
: ITALIC_NONE
);
50 return new Qt5FontFace(aFA
, rFont
.toString());
53 Qt5FontFace::Qt5FontFace(const FontAttributes
& rFA
, const QString
& rFontID
)
54 : PhysicalFontFace(rFA
)
56 , m_bFontCapabilitiesRead(false)
60 Qt5FontFace::~Qt5FontFace() {}
62 sal_IntPtr
Qt5FontFace::GetFontId() const { return reinterpret_cast<sal_IntPtr
>(&m_aFontId
); }
64 LogicalFontInstance
* Qt5FontFace::CreateFontInstance(const FontSelectPattern
& rFSD
) const
66 return new Qt5Font(*this, rFSD
);
69 const FontCharMapRef
Qt5FontFace::GetFontCharMap() const
75 aFont
.fromString(m_aFontId
);
76 QRawFont
aRawFont(QRawFont::fromFont(aFont
));
77 QByteArray aCMapTable
= aRawFont
.fontTable("cmap");
78 if (aCMapTable
.isEmpty())
80 m_xCharMap
= new FontCharMap();
84 CmapResult aCmapResult
;
85 if (ParseCMAP(reinterpret_cast<const unsigned char*>(aCMapTable
.data()), aCMapTable
.size(),
87 m_xCharMap
= new FontCharMap(aCmapResult
);
92 bool Qt5FontFace::GetFontCapabilities(vcl::FontCapabilities
& rFontCapabilities
) const
94 // read this only once per font
95 if (m_bFontCapabilitiesRead
)
97 rFontCapabilities
= m_aFontCapabilities
;
98 return rFontCapabilities
.oUnicodeRange
|| rFontCapabilities
.oCodePageRange
;
100 m_bFontCapabilitiesRead
= true;
103 aFont
.fromString(m_aFontId
);
104 QRawFont
aRawFont(QRawFont::fromFont(aFont
));
105 QByteArray aOS2Table
= aRawFont
.fontTable("OS/2");
106 if (!aOS2Table
.isEmpty())
108 vcl::getTTCoverage(m_aFontCapabilities
.oUnicodeRange
, m_aFontCapabilities
.oCodePageRange
,
109 reinterpret_cast<const unsigned char*>(aOS2Table
.data()),
113 rFontCapabilities
= m_aFontCapabilities
;
114 return rFontCapabilities
.oUnicodeRange
|| rFontCapabilities
.oCodePageRange
;
117 PhysicalFontFace
* Qt5FontFace::Clone() const { return new Qt5FontFace(*this); }
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */