calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / vcl / qt5 / QtFont.cxx
blob384f56774ffdfc33e71dbb8b91bdd54681c63a40
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 <sal/config.h>
22 #include <QtFont.hxx>
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)
31 switch (eWeight)
33 case WEIGHT_THIN:
34 rFont.setWeight(QFont::Thin);
35 break;
36 case WEIGHT_ULTRALIGHT:
37 rFont.setWeight(QFont::ExtraLight);
38 break;
39 case WEIGHT_LIGHT:
40 rFont.setWeight(QFont::Light);
41 break;
42 case WEIGHT_SEMILIGHT:
43 [[fallthrough]];
44 case WEIGHT_NORMAL:
45 rFont.setWeight(QFont::Normal);
46 break;
47 case WEIGHT_MEDIUM:
48 rFont.setWeight(QFont::Medium);
49 break;
50 case WEIGHT_SEMIBOLD:
51 rFont.setWeight(QFont::DemiBold);
52 break;
53 case WEIGHT_BOLD:
54 rFont.setWeight(QFont::Bold);
55 break;
56 case WEIGHT_ULTRABOLD:
57 rFont.setWeight(QFont::ExtraBold);
58 break;
59 case WEIGHT_BLACK:
60 rFont.setWeight(QFont::Black);
61 break;
62 default:
63 break;
67 static inline void applyStretch(QtFont& rFont, FontWidth eWidthType)
69 switch (eWidthType)
71 case WIDTH_DONTKNOW:
72 rFont.setStretch(QFont::AnyStretch);
73 break;
74 case WIDTH_ULTRA_CONDENSED:
75 rFont.setStretch(QFont::UltraCondensed);
76 break;
77 case WIDTH_EXTRA_CONDENSED:
78 rFont.setStretch(QFont::ExtraCondensed);
79 break;
80 case WIDTH_CONDENSED:
81 rFont.setStretch(QFont::Condensed);
82 break;
83 case WIDTH_SEMI_CONDENSED:
84 rFont.setStretch(QFont::SemiCondensed);
85 break;
86 case WIDTH_NORMAL:
87 rFont.setStretch(QFont::Unstretched);
88 break;
89 case WIDTH_SEMI_EXPANDED:
90 rFont.setStretch(QFont::SemiExpanded);
91 break;
92 case WIDTH_EXPANDED:
93 rFont.setStretch(QFont::Expanded);
94 break;
95 case WIDTH_EXTRA_EXPANDED:
96 rFont.setStretch(QFont::ExtraExpanded);
97 break;
98 case WIDTH_ULTRA_EXPANDED:
99 rFont.setStretch(QFont::UltraExpanded);
100 break;
101 default:
102 break;
106 static inline void applyStyle(QtFont& rFont, FontItalic eItalic)
108 switch (eItalic)
110 case ITALIC_NONE:
111 rFont.setStyle(QFont::Style::StyleNormal);
112 break;
113 case ITALIC_OBLIQUE:
114 rFont.setStyle(QFont::Style::StyleOblique);
115 break;
116 case ITALIC_NORMAL:
117 rFont.setStyle(QFont::Style::StyleItalic);
118 break;
119 default:
120 break;
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:
149 if (aPart.count())
151 aPart.setClosed(true);
152 rB2DPolyPoly.append(aPart);
153 aPart.clear();
156 aPart.append(basegfx::B2DPoint(aQElement.x, aQElement.y));
157 break;
159 case QPainterPath::LineToElement:
161 aPart.append(basegfx::B2DPoint(aQElement.x, aQElement.y));
162 break;
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));
171 break;
173 case QPainterPath::CurveToDataElement:
175 break;
180 if (aPart.count())
182 aPart.setClosed(true);
183 rB2DPolyPoly.append(aPart);
184 aPart.clear();
187 return true;
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());
194 return true;
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */