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 <Qt5Graphics.hxx>
21 #include <Qt5FontFace.hxx>
22 #include <Qt5Font.hxx>
23 #include <Qt5Painter.hxx>
25 #include <vcl/fontcharmap.hxx>
26 #include <unx/geninst.h>
27 #include <unx/fontmanager.hxx>
28 #include <unx/glyphcache.hxx>
29 #include <unx/genpspgraphics.h>
31 #include <sallayout.hxx>
32 #include <PhysicalFontCollection.hxx>
34 #include <QtGui/QGlyphRun>
35 #include <QtGui/QFontDatabase>
36 #include <QtGui/QRawFont>
37 #include <QtCore/QStringList>
39 void Qt5Graphics::SetTextColor(Color nColor
) { m_aTextColor
= nColor
; }
41 void Qt5Graphics::SetFont(LogicalFontInstance
* pReqFont
, int nFallbackLevel
)
43 // release the text styles
44 for (int i
= nFallbackLevel
; i
< MAX_FALLBACK
; ++i
)
48 m_pTextStyle
[i
].clear();
54 m_pTextStyle
[nFallbackLevel
] = static_cast<Qt5Font
*>(pReqFont
);
57 void Qt5Graphics::GetFontMetric(ImplFontMetricDataRef
& rFMD
, int nFallbackLevel
)
59 QRawFont
aRawFont(QRawFont::fromFont(*m_pTextStyle
[nFallbackLevel
]));
60 Qt5FontFace::fillAttributesFromQFont(*m_pTextStyle
[nFallbackLevel
], *rFMD
);
62 rFMD
->ImplCalcLineSpacing(m_pTextStyle
[nFallbackLevel
].get());
65 rFMD
->SetWidth(aRawFont
.averageCharWidth());
67 rFMD
->SetMinKashida(m_pTextStyle
[nFallbackLevel
]->GetKashidaWidth());
70 FontCharMapRef
Qt5Graphics::GetFontCharMap() const
73 return FontCharMapRef(new FontCharMap());
74 return static_cast<const Qt5FontFace
*>(m_pTextStyle
[0]->GetFontFace())->GetFontCharMap();
77 bool Qt5Graphics::GetFontCapabilities(vcl::FontCapabilities
& rFontCapabilities
) const
81 return static_cast<const Qt5FontFace
*>(m_pTextStyle
[0]->GetFontFace())
82 ->GetFontCapabilities(rFontCapabilities
);
85 void Qt5Graphics::GetDevFontList(PhysicalFontCollection
* pPFC
)
87 static const bool bUseFontconfig
= (nullptr == getenv("SAL_VCL_QT5_NO_FONTCONFIG"));
89 m_pFontCollection
= pPFC
;
94 GlyphCache
& rGC
= GlyphCache::GetInstance();
95 psp::PrintFontManager
& rMgr
= psp::PrintFontManager::get();
96 ::std::vector
<psp::fontID
> aList
;
97 psp::FastPrintFontInfo aInfo
;
99 rMgr
.getFontList(aList
);
100 for (auto const& elem
: aList
)
102 if (!rMgr
.getFontFastInfo(elem
, aInfo
))
105 // normalize face number to the GlyphCache
106 int nFaceNum
= rMgr
.getFontFaceNumber(aInfo
.m_nID
);
107 int nVariantNum
= rMgr
.getFontFaceVariation(aInfo
.m_nID
);
109 // inform GlyphCache about this font provided by the PsPrint subsystem
110 FontAttributes aDFA
= GenPspGraphics::Info2FontAttributes(aInfo
);
111 aDFA
.IncreaseQualityBy(4096);
112 const OString
& rFileName
= rMgr
.getFontFileSysPath(aInfo
.m_nID
);
113 rGC
.AddFontFile(rFileName
, nFaceNum
, nVariantNum
, aInfo
.m_nID
, aDFA
);
117 SalGenericInstance::RegisterFontSubstitutors(pPFC
);
119 for (auto& family
: aFDB
.families())
120 for (auto& style
: aFDB
.styles(family
))
121 pPFC
->Add(Qt5FontFace::fromQFontDatabase(family
, style
));
124 void Qt5Graphics::ClearDevFontCache() {}
126 bool Qt5Graphics::AddTempDevFont(PhysicalFontCollection
*, const OUString
& /*rFileURL*/,
127 const OUString
& /*rFontName*/)
132 bool Qt5Graphics::CreateFontSubset(const OUString
& /*rToFile*/, const PhysicalFontFace
* /*pFont*/,
133 const sal_GlyphId
* /*pGlyphIds*/, const sal_uInt8
* /*pEncoding*/,
134 sal_Int32
* /*pWidths*/, int /*nGlyphs*/,
135 FontSubsetInfo
& /*rInfo*/)
140 const void* Qt5Graphics::GetEmbedFontData(const PhysicalFontFace
*, long* /*pDataLen*/)
145 void Qt5Graphics::FreeEmbedFontData(const void* /*pData*/, long /*nDataLen*/) {}
147 void Qt5Graphics::GetGlyphWidths(const PhysicalFontFace
* /*pPFF*/, bool /*bVertical*/,
148 std::vector
<sal_Int32
>& /*rWidths*/, Ucs2UIntMap
& /*rUnicodeEnc*/)
152 class Qt5CommonSalLayout
: public GenericSalLayout
155 Qt5CommonSalLayout(LogicalFontInstance
& rLFI
)
156 : GenericSalLayout(rLFI
)
160 void SetOrientation(int nOrientation
) { mnOrientation
= nOrientation
; }
163 std::unique_ptr
<GenericSalLayout
> Qt5Graphics::GetTextLayout(int nFallbackLevel
)
165 assert(m_pTextStyle
[nFallbackLevel
]);
166 if (!m_pTextStyle
[nFallbackLevel
])
168 return std::make_unique
<Qt5CommonSalLayout
>(*m_pTextStyle
[nFallbackLevel
]);
171 void Qt5Graphics::DrawTextLayout(const GenericSalLayout
& rLayout
)
173 const Qt5Font
* pFont
= static_cast<const Qt5Font
*>(&rLayout
.GetFont());
175 QRawFont
aRawFont(QRawFont::fromFont(*pFont
));
177 QVector
<quint32
> glyphIndexes
;
178 QVector
<QPointF
> positions
;
180 // prevent glyph rotation inside the SalLayout
181 // probably better to add a parameter to GetNextGlyphs?
182 Qt5CommonSalLayout
* pQt5Layout
183 = static_cast<Qt5CommonSalLayout
*>(const_cast<GenericSalLayout
*>(&rLayout
));
184 int nOrientation
= rLayout
.GetOrientation();
186 pQt5Layout
->SetOrientation(0);
189 const GlyphItem
* pGlyph
;
191 while (rLayout
.GetNextGlyph(&pGlyph
, aPos
, nStart
))
193 glyphIndexes
.push_back(pGlyph
->glyphId());
194 positions
.push_back(QPointF(aPos
.X(), aPos
.Y()));
198 pQt5Layout
->SetOrientation(nOrientation
);
201 aGlyphRun
.setPositions(positions
);
202 aGlyphRun
.setGlyphIndexes(glyphIndexes
);
203 aGlyphRun
.setRawFont(aRawFont
);
205 Qt5Painter
aPainter(*this);
206 QColor aColor
= toQColor(m_aTextColor
);
207 aPainter
.setPen(aColor
);
211 // make text position the center of the rotation
212 // then rotate and move back
213 QRect window
= aPainter
.window();
214 window
.moveTo(-positions
[0].x(), -positions
[0].y());
215 aPainter
.setWindow(window
);
218 p
.rotate(-static_cast<qreal
>(nOrientation
) / 10.0);
219 p
.translate(-positions
[0].x(), -positions
[0].y());
220 aPainter
.setTransform(p
);
223 aPainter
.drawGlyphRun(QPointF(), aGlyphRun
);
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */