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 QFont::Weight
GetQFontWeight(FontWeight eWeight
)
32 case WEIGHT_ULTRALIGHT
:
33 return QFont::ExtraLight
;
36 case WEIGHT_SEMILIGHT
:
45 return QFont::DemiBold
;
48 case WEIGHT_ULTRABOLD
:
49 return QFont::ExtraBold
;
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
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())
69 case FontItalic_FORCE_EQUAL_SIZE
:
72 setStyle(Style::StyleNormal
);
75 setStyle(Style::StyleOblique
);
78 setStyle(Style::StyleItalic
);
83 static hb_blob_t
* getFontTable(hb_face_t
*, hb_tag_t nTableTag
, void* pUserData
)
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;
95 pBlob
= hb_blob_create(aTable
.data(), nLength
, HB_MEMORY_MODE_DUPLICATE
, nullptr, nullptr);
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());
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */