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 QByteArray aHheaTable
= aRawFont
.fontTable("hhea");
63 std::vector
<uint8_t> rHhea(aHheaTable
.data(), aHheaTable
.data() + aHheaTable
.size());
65 QByteArray aOs2Table
= aRawFont
.fontTable("OS/2");
66 std::vector
<uint8_t> rOS2(aOs2Table
.data(), aOs2Table
.data() + aOs2Table
.size());
68 rFMD
->ImplCalcLineSpacing(rHhea
, rOS2
, aRawFont
.unitsPerEm());
71 rFMD
->SetWidth(aRawFont
.averageCharWidth());
73 rFMD
->SetMinKashida(m_pTextStyle
[nFallbackLevel
]->GetKashidaWidth());
76 const FontCharMapRef
Qt5Graphics::GetFontCharMap() const
79 return FontCharMapRef(new FontCharMap());
80 return static_cast<const Qt5FontFace
*>(m_pTextStyle
[0]->GetFontFace())->GetFontCharMap();
83 bool Qt5Graphics::GetFontCapabilities(vcl::FontCapabilities
& rFontCapabilities
) const
87 return static_cast<const Qt5FontFace
*>(m_pTextStyle
[0]->GetFontFace())
88 ->GetFontCapabilities(rFontCapabilities
);
91 void Qt5Graphics::GetDevFontList(PhysicalFontCollection
* pPFC
)
93 static const bool bUseFontconfig
= (nullptr == getenv("SAL_VCL_QT5_NO_FONTCONFIG"));
95 m_pFontCollection
= pPFC
;
100 GlyphCache
& rGC
= GlyphCache::GetInstance();
101 psp::PrintFontManager
& rMgr
= psp::PrintFontManager::get();
102 ::std::vector
<psp::fontID
> aList
;
103 psp::FastPrintFontInfo aInfo
;
105 rMgr
.getFontList(aList
);
106 for (auto const& elem
: aList
)
108 if (!rMgr
.getFontFastInfo(elem
, aInfo
))
111 // normalize face number to the GlyphCache
112 int nFaceNum
= rMgr
.getFontFaceNumber(aInfo
.m_nID
);
113 int nVariantNum
= rMgr
.getFontFaceVariation(aInfo
.m_nID
);
115 // inform GlyphCache about this font provided by the PsPrint subsystem
116 FontAttributes aDFA
= GenPspGraphics::Info2FontAttributes(aInfo
);
117 aDFA
.IncreaseQualityBy(4096);
118 const OString
& rFileName
= rMgr
.getFontFileSysPath(aInfo
.m_nID
);
119 rGC
.AddFontFile(rFileName
, nFaceNum
, nVariantNum
, aInfo
.m_nID
, aDFA
);
123 SalGenericInstance::RegisterFontSubstitutors(pPFC
);
125 for (auto& family
: aFDB
.families())
126 for (auto& style
: aFDB
.styles(family
))
127 pPFC
->Add(Qt5FontFace::fromQFontDatabase(family
, style
));
130 void Qt5Graphics::ClearDevFontCache() {}
132 bool Qt5Graphics::AddTempDevFont(PhysicalFontCollection
*, const OUString
& /*rFileURL*/,
133 const OUString
& /*rFontName*/)
138 bool Qt5Graphics::CreateFontSubset(const OUString
& /*rToFile*/, const PhysicalFontFace
* /*pFont*/,
139 const sal_GlyphId
* /*pGlyphIds*/, const sal_uInt8
* /*pEncoding*/,
140 sal_Int32
* /*pWidths*/, int /*nGlyphs*/,
141 FontSubsetInfo
& /*rInfo*/)
146 const void* Qt5Graphics::GetEmbedFontData(const PhysicalFontFace
*, long* /*pDataLen*/)
151 void Qt5Graphics::FreeEmbedFontData(const void* /*pData*/, long /*nDataLen*/) {}
153 void Qt5Graphics::GetGlyphWidths(const PhysicalFontFace
* /*pPFF*/, bool /*bVertical*/,
154 std::vector
<sal_Int32
>& /*rWidths*/, Ucs2UIntMap
& /*rUnicodeEnc*/)
158 class Qt5CommonSalLayout
: public GenericSalLayout
161 Qt5CommonSalLayout(LogicalFontInstance
& rLFI
)
162 : GenericSalLayout(rLFI
)
166 void SetOrientation(int nOrientation
) { mnOrientation
= nOrientation
; }
169 std::unique_ptr
<GenericSalLayout
> Qt5Graphics::GetTextLayout(int nFallbackLevel
)
171 assert(m_pTextStyle
[nFallbackLevel
]);
172 if (!m_pTextStyle
[nFallbackLevel
])
174 return std::make_unique
<Qt5CommonSalLayout
>(*m_pTextStyle
[nFallbackLevel
]);
177 void Qt5Graphics::DrawTextLayout(const GenericSalLayout
& rLayout
)
179 const Qt5Font
* pFont
= static_cast<const Qt5Font
*>(&rLayout
.GetFont());
181 QRawFont
aRawFont(QRawFont::fromFont(*pFont
));
183 QVector
<quint32
> glyphIndexes
;
184 QVector
<QPointF
> positions
;
186 // prevent glyph rotation inside the SalLayout
187 // probably better to add a parameter to GetNextGlyphs?
188 Qt5CommonSalLayout
* pQt5Layout
189 = static_cast<Qt5CommonSalLayout
*>(const_cast<GenericSalLayout
*>(&rLayout
));
190 int nOrientation
= rLayout
.GetOrientation();
192 pQt5Layout
->SetOrientation(0);
195 const GlyphItem
* pGlyph
;
197 while (rLayout
.GetNextGlyph(&pGlyph
, aPos
, nStart
))
199 glyphIndexes
.push_back(pGlyph
->m_aGlyphId
);
200 positions
.push_back(QPointF(aPos
.X(), aPos
.Y()));
204 pQt5Layout
->SetOrientation(nOrientation
);
207 aGlyphRun
.setPositions(positions
);
208 aGlyphRun
.setGlyphIndexes(glyphIndexes
);
209 aGlyphRun
.setRawFont(aRawFont
);
211 Qt5Painter
aPainter(*this);
212 QColor aColor
= toQColor(m_aTextColor
);
213 aPainter
.setPen(aColor
);
217 // make text position the center of the rotation
218 // then rotate and move back
219 QRect window
= aPainter
.window();
220 window
.moveTo(-positions
[0].x(), -positions
[0].y());
221 aPainter
.setWindow(window
);
224 p
.rotate(-static_cast<qreal
>(nOrientation
) / 10.0);
225 p
.translate(-positions
[0].x(), -positions
[0].y());
226 aPainter
.setTransform(p
);
229 aPainter
.drawGlyphRun(QPointF(), aGlyphRun
);
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */