bump product version to 6.4.0.3
[LibreOffice.git] / vcl / qt5 / Qt5Font.cxx
blobee9d339266b237ed8e9c960f1b394f5e6878d450
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 QFont::Weight GetQFontWeight(FontWeight eWeight)
28 switch (eWeight)
30 case WEIGHT_THIN:
31 return QFont::Thin;
32 case WEIGHT_ULTRALIGHT:
33 return QFont::ExtraLight;
34 case WEIGHT_LIGHT:
35 return QFont::Light;
36 case WEIGHT_SEMILIGHT:
37 [[fallthrough]];
38 case WEIGHT_DONTKNOW:
39 [[fallthrough]];
40 case WEIGHT_NORMAL:
41 return QFont::Normal;
42 case WEIGHT_MEDIUM:
43 return QFont::Medium;
44 case WEIGHT_SEMIBOLD:
45 return QFont::DemiBold;
46 case WEIGHT_BOLD:
47 return QFont::Bold;
48 case WEIGHT_ULTRABOLD:
49 return QFont::ExtraBold;
50 case WEIGHT_BLACK:
51 return QFont::Black;
52 case FontWeight_FORCE_EQUAL_SIZE:
53 assert(false && "FontWeight_FORCE_EQUAL_SIZE not implementable for QFont");
56 // so we would get enum not handled warning
57 return QFont::Normal;
60 Qt5Font::Qt5Font(const PhysicalFontFace& rPFF, const FontSelectPattern& rFSP)
61 : LogicalFontInstance(rPFF, rFSP)
63 setFamily(toQString(rPFF.GetFamilyName()));
64 setWeight(GetQFontWeight(rPFF.GetWeight()));
65 setPixelSize(rFSP.mnHeight);
66 switch (rFSP.GetItalic())
68 case ITALIC_DONTKNOW:
69 case FontItalic_FORCE_EQUAL_SIZE:
70 break;
71 case ITALIC_NONE:
72 setStyle(Style::StyleNormal);
73 break;
74 case ITALIC_OBLIQUE:
75 setStyle(Style::StyleOblique);
76 break;
77 case ITALIC_NORMAL:
78 setStyle(Style::StyleItalic);
79 break;
83 static hb_blob_t* getFontTable(hb_face_t*, hb_tag_t nTableTag, void* pUserData)
85 char pTagName[5];
86 LogicalFontInstance::DecodeOpenTypeTag(nTableTag, pTagName);
88 Qt5Font* pFont = static_cast<Qt5Font*>(pUserData);
89 QRawFont aRawFont(QRawFont::fromFont(*pFont));
90 QByteArray aTable = aRawFont.fontTable(pTagName);
91 const sal_uInt32 nLength = aTable.size();
93 hb_blob_t* pBlob = nullptr;
94 if (nLength > 0)
95 pBlob = hb_blob_create(aTable.data(), nLength, HB_MEMORY_MODE_DUPLICATE, nullptr, nullptr);
96 return pBlob;
99 hb_font_t* Qt5Font::ImplInitHbFont()
101 return InitHbFont(hb_face_create_for_tables(getFontTable, this, nullptr));
104 bool Qt5Font::GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const { return false; }
106 bool Qt5Font::ImplGetGlyphBoundRect(sal_GlyphId nId, tools::Rectangle& rRect, bool) const
108 QRawFont aRawFont(QRawFont::fromFont(*this));
109 rRect = toRectangle(aRawFont.boundingRect(nId).toAlignedRect());
110 return true;
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */