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 <sal/config.h>
23 #include <QtTools.hxx>
25 #include <QtGui/QFont>
26 #include <QtGui/QRawFont>
27 #include <QtGui/QPainterPath>
29 static inline void applyWeight(QtFont
& rFont
, FontWeight eWeight
)
34 rFont
.setWeight(QFont::Thin
);
36 case WEIGHT_ULTRALIGHT
:
37 rFont
.setWeight(QFont::ExtraLight
);
40 rFont
.setWeight(QFont::Light
);
42 case WEIGHT_SEMILIGHT
:
45 rFont
.setWeight(QFont::Normal
);
48 rFont
.setWeight(QFont::Medium
);
51 rFont
.setWeight(QFont::DemiBold
);
54 rFont
.setWeight(QFont::Bold
);
56 case WEIGHT_ULTRABOLD
:
57 rFont
.setWeight(QFont::ExtraBold
);
60 rFont
.setWeight(QFont::Black
);
67 static inline void applyStretch(QtFont
& rFont
, FontWidth eWidthType
)
72 rFont
.setStretch(QFont::AnyStretch
);
74 case WIDTH_ULTRA_CONDENSED
:
75 rFont
.setStretch(QFont::UltraCondensed
);
77 case WIDTH_EXTRA_CONDENSED
:
78 rFont
.setStretch(QFont::ExtraCondensed
);
81 rFont
.setStretch(QFont::Condensed
);
83 case WIDTH_SEMI_CONDENSED
:
84 rFont
.setStretch(QFont::SemiCondensed
);
87 rFont
.setStretch(QFont::Unstretched
);
89 case WIDTH_SEMI_EXPANDED
:
90 rFont
.setStretch(QFont::SemiExpanded
);
93 rFont
.setStretch(QFont::Expanded
);
95 case WIDTH_EXTRA_EXPANDED
:
96 rFont
.setStretch(QFont::ExtraExpanded
);
98 case WIDTH_ULTRA_EXPANDED
:
99 rFont
.setStretch(QFont::UltraExpanded
);
106 static inline void applyStyle(QtFont
& rFont
, FontItalic eItalic
)
111 rFont
.setStyle(QFont::Style::StyleNormal
);
114 rFont
.setStyle(QFont::Style::StyleOblique
);
117 rFont
.setStyle(QFont::Style::StyleItalic
);
124 QtFont::QtFont(const vcl::font::PhysicalFontFace
& rPFF
, const vcl::font::FontSelectPattern
& rFSP
)
125 : LogicalFontInstance(rPFF
, rFSP
)
127 setFamily(toQString(rPFF
.GetFamilyName()));
128 applyWeight(*this, rPFF
.GetWeight());
129 setPixelSize(rFSP
.mnHeight
);
130 applyStretch(*this, rPFF
.GetWidthType());
131 applyStyle(*this, rFSP
.GetItalic());
134 bool QtFont::GetGlyphOutline(sal_GlyphId nId
, basegfx::B2DPolyPolygon
& rB2DPolyPoly
, bool) const
136 rB2DPolyPoly
.clear();
137 basegfx::B2DPolygon aPart
;
138 QRawFont
aRawFont(QRawFont::fromFont(*this));
139 QPainterPath aQPath
= aRawFont
.pathForGlyph(nId
);
141 for (int a(0); a
< aQPath
.elementCount(); a
++)
143 const QPainterPath::Element aQElement
= aQPath
.elementAt(a
);
145 switch (aQElement
.type
)
147 case QPainterPath::MoveToElement
:
151 aPart
.setClosed(true);
152 rB2DPolyPoly
.append(aPart
);
156 aPart
.append(basegfx::B2DPoint(aQElement
.x
, aQElement
.y
));
159 case QPainterPath::LineToElement
:
161 aPart
.append(basegfx::B2DPoint(aQElement
.x
, aQElement
.y
));
164 case QPainterPath::CurveToElement
:
166 const QPainterPath::Element aQ2
= aQPath
.elementAt(++a
);
167 const QPainterPath::Element aQ3
= aQPath
.elementAt(++a
);
168 aPart
.appendBezierSegment(basegfx::B2DPoint(aQElement
.x
, aQElement
.y
),
169 basegfx::B2DPoint(aQ2
.x
, aQ2
.y
),
170 basegfx::B2DPoint(aQ3
.x
, aQ3
.y
));
173 case QPainterPath::CurveToDataElement
:
182 aPart
.setClosed(true);
183 rB2DPolyPoly
.append(aPart
);
190 bool QtFont::ImplGetGlyphBoundRect(sal_GlyphId nId
, tools::Rectangle
& rRect
, bool) const
192 QRawFont
aRawFont(QRawFont::fromFont(*this));
193 rRect
= toRectangle(aRawFont
.boundingRect(nId
).toAlignedRect());
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */