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 <Qt5Font.hxx>
21 #include <Qt5Tools.hxx>
23 #include <QtGui/QFont>
24 #include <QtGui/QRawFont>
26 static inline void applyWeight(Qt5Font
& rFont
, FontWeight eWeight
)
31 rFont
.setWeight(QFont::Thin
);
33 case WEIGHT_ULTRALIGHT
:
34 rFont
.setWeight(QFont::ExtraLight
);
37 rFont
.setWeight(QFont::Light
);
39 case WEIGHT_SEMILIGHT
:
42 rFont
.setWeight(QFont::Normal
);
45 rFont
.setWeight(QFont::Medium
);
48 rFont
.setWeight(QFont::DemiBold
);
51 rFont
.setWeight(QFont::Bold
);
53 case WEIGHT_ULTRABOLD
:
54 rFont
.setWeight(QFont::ExtraBold
);
57 rFont
.setWeight(QFont::Black
);
64 static inline void applyStretch(Qt5Font
& rFont
, FontWidth eWidthType
)
69 rFont
.setStretch(QFont::AnyStretch
);
71 case WIDTH_ULTRA_CONDENSED
:
72 rFont
.setStretch(QFont::UltraCondensed
);
74 case WIDTH_EXTRA_CONDENSED
:
75 rFont
.setStretch(QFont::ExtraCondensed
);
78 rFont
.setStretch(QFont::Condensed
);
80 case WIDTH_SEMI_CONDENSED
:
81 rFont
.setStretch(QFont::SemiCondensed
);
84 rFont
.setStretch(QFont::Unstretched
);
86 case WIDTH_SEMI_EXPANDED
:
87 rFont
.setStretch(QFont::SemiExpanded
);
90 rFont
.setStretch(QFont::Expanded
);
92 case WIDTH_EXTRA_EXPANDED
:
93 rFont
.setStretch(QFont::ExtraExpanded
);
95 case WIDTH_ULTRA_EXPANDED
:
96 rFont
.setStretch(QFont::UltraExpanded
);
103 static inline void applyStyle(Qt5Font
& rFont
, FontItalic eItalic
)
108 rFont
.setStyle(QFont::Style::StyleNormal
);
111 rFont
.setStyle(QFont::Style::StyleOblique
);
114 rFont
.setStyle(QFont::Style::StyleItalic
);
121 Qt5Font::Qt5Font(const PhysicalFontFace
& rPFF
, const FontSelectPattern
& rFSP
)
122 : LogicalFontInstance(rPFF
, rFSP
)
124 setFamily(toQString(rPFF
.GetFamilyName()));
125 applyWeight(*this, rPFF
.GetWeight());
126 setPixelSize(rFSP
.mnHeight
);
127 applyStretch(*this, rPFF
.GetWidthType());
128 applyStyle(*this, rFSP
.GetItalic());
131 static hb_blob_t
* getFontTable(hb_face_t
*, hb_tag_t nTableTag
, void* pUserData
)
134 LogicalFontInstance::DecodeOpenTypeTag(nTableTag
, pTagName
);
136 Qt5Font
* pFont
= static_cast<Qt5Font
*>(pUserData
);
137 QRawFont
aRawFont(QRawFont::fromFont(*pFont
));
138 QByteArray aTable
= aRawFont
.fontTable(pTagName
);
139 const sal_uInt32 nLength
= aTable
.size();
141 hb_blob_t
* pBlob
= nullptr;
143 pBlob
= hb_blob_create(aTable
.data(), nLength
, HB_MEMORY_MODE_DUPLICATE
, nullptr, nullptr);
147 hb_font_t
* Qt5Font::ImplInitHbFont()
149 return InitHbFont(hb_face_create_for_tables(getFontTable
, this, nullptr));
152 bool Qt5Font::GetGlyphOutline(sal_GlyphId
, basegfx::B2DPolyPolygon
&, bool) const { return false; }
154 bool Qt5Font::ImplGetGlyphBoundRect(sal_GlyphId nId
, tools::Rectangle
& rRect
, bool) const
156 QRawFont
aRawFont(QRawFont::fromFont(*this));
157 rRect
= toRectangle(aRawFont
.boundingRect(nId
).toAlignedRect());
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */