Update git submodules
[LibreOffice.git] / vcl / qt5 / Qt5Font.cxx
blob2ab614043639459a662ba16c578e7bd6b8c7eba6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <Qt5Font.hxx>
21 #include <Qt5Tools.hxx>
23 #include <QtGui/QFont>
24 #include <QtGui/QRawFont>
26 static inline void applyWeight(Qt5Font& rFont, FontWeight eWeight)
28 switch (eWeight)
30 case WEIGHT_THIN:
31 rFont.setWeight(QFont::Thin);
32 break;
33 case WEIGHT_ULTRALIGHT:
34 rFont.setWeight(QFont::ExtraLight);
35 break;
36 case WEIGHT_LIGHT:
37 rFont.setWeight(QFont::Light);
38 break;
39 case WEIGHT_SEMILIGHT:
40 [[fallthrough]];
41 case WEIGHT_NORMAL:
42 rFont.setWeight(QFont::Normal);
43 break;
44 case WEIGHT_MEDIUM:
45 rFont.setWeight(QFont::Medium);
46 break;
47 case WEIGHT_SEMIBOLD:
48 rFont.setWeight(QFont::DemiBold);
49 break;
50 case WEIGHT_BOLD:
51 rFont.setWeight(QFont::Bold);
52 break;
53 case WEIGHT_ULTRABOLD:
54 rFont.setWeight(QFont::ExtraBold);
55 break;
56 case WEIGHT_BLACK:
57 rFont.setWeight(QFont::Black);
58 break;
59 default:
60 break;
64 static inline void applyStretch(Qt5Font& rFont, FontWidth eWidthType)
66 switch (eWidthType)
68 case WIDTH_DONTKNOW:
69 rFont.setStretch(QFont::AnyStretch);
70 break;
71 case WIDTH_ULTRA_CONDENSED:
72 rFont.setStretch(QFont::UltraCondensed);
73 break;
74 case WIDTH_EXTRA_CONDENSED:
75 rFont.setStretch(QFont::ExtraCondensed);
76 break;
77 case WIDTH_CONDENSED:
78 rFont.setStretch(QFont::Condensed);
79 break;
80 case WIDTH_SEMI_CONDENSED:
81 rFont.setStretch(QFont::SemiCondensed);
82 break;
83 case WIDTH_NORMAL:
84 rFont.setStretch(QFont::Unstretched);
85 break;
86 case WIDTH_SEMI_EXPANDED:
87 rFont.setStretch(QFont::SemiExpanded);
88 break;
89 case WIDTH_EXPANDED:
90 rFont.setStretch(QFont::Expanded);
91 break;
92 case WIDTH_EXTRA_EXPANDED:
93 rFont.setStretch(QFont::ExtraExpanded);
94 break;
95 case WIDTH_ULTRA_EXPANDED:
96 rFont.setStretch(QFont::UltraExpanded);
97 break;
98 default:
99 break;
103 static inline void applyStyle(Qt5Font& rFont, FontItalic eItalic)
105 switch (eItalic)
107 case ITALIC_NONE:
108 rFont.setStyle(QFont::Style::StyleNormal);
109 break;
110 case ITALIC_OBLIQUE:
111 rFont.setStyle(QFont::Style::StyleOblique);
112 break;
113 case ITALIC_NORMAL:
114 rFont.setStyle(QFont::Style::StyleItalic);
115 break;
116 default:
117 break;
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)
133 char pTagName[5];
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;
142 if (nLength > 0)
143 pBlob = hb_blob_create(aTable.data(), nLength, HB_MEMORY_MODE_DUPLICATE, nullptr, nullptr);
144 return pBlob;
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());
158 return true;
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */