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"
24 #include <vcl/fontcharmap.hxx>
26 #include <sallayout.hxx>
27 #include <PhysicalFontCollection.hxx>
29 #include <QtGui/QFontDatabase>
30 #include <QtGui/QRawFont>
31 #include <QtCore/QStringList>
33 void Qt5Graphics::SetTextColor(Color nColor
) { m_aTextColor
= nColor
; }
35 void Qt5Graphics::SetFont(const FontSelectPattern
* pReqFont
, int nFallbackLevel
)
37 // release the text styles
38 for (int i
= nFallbackLevel
; i
< MAX_FALLBACK
; ++i
)
42 m_pTextStyle
[i
]->Release();
43 m_pTextStyle
[i
] = nullptr;
48 assert(pReqFont
->mpFontInstance
);
49 if (!pReqFont
->mpFontInstance
)
52 m_pTextStyle
[nFallbackLevel
] = static_cast<Qt5Font
*>(pReqFont
->mpFontInstance
);
53 m_pTextStyle
[nFallbackLevel
]->Acquire();
56 void Qt5Graphics::GetFontMetric(ImplFontMetricDataRef
& rFMD
, int nFallbackLevel
)
58 QRawFont
aRawFont(QRawFont::fromFont(*m_pTextStyle
[nFallbackLevel
]));
60 QByteArray aHheaTable
= aRawFont
.fontTable("hhea");
61 std::vector
<uint8_t> rHhea(aHheaTable
.data(), aHheaTable
.data() + aHheaTable
.size());
63 QByteArray aOs2Table
= aRawFont
.fontTable("OS/2");
64 std::vector
<uint8_t> rOS2(aHheaTable
.data(), aHheaTable
.data() + aHheaTable
.size());
66 rFMD
->ImplCalcLineSpacing(rHhea
, rOS2
, aRawFont
.unitsPerEm());
68 rFMD
->SetWidth(aRawFont
.averageCharWidth());
70 rFMD
->SetMinKashida(m_pTextStyle
[nFallbackLevel
]->GetKashidaWidth());
73 const FontCharMapRef
Qt5Graphics::GetFontCharMap() const
76 return FontCharMapRef(new FontCharMap());
77 return static_cast<const Qt5FontFace
*>(m_pTextStyle
[0]->GetFontFace())->GetFontCharMap();
80 bool Qt5Graphics::GetFontCapabilities(vcl::FontCapabilities
& rFontCapabilities
) const
84 return static_cast<const Qt5FontFace
*>(m_pTextStyle
[0]->GetFontFace())
85 ->GetFontCapabilities(rFontCapabilities
);
88 void Qt5Graphics::GetDevFontList(PhysicalFontCollection
* pPFC
)
90 m_pFontCollection
= pPFC
;
95 for (auto& family
: aFDB
.families())
96 for (auto& style
: aFDB
.styles(family
))
98 // Just get any size - we don't care
99 QList
<int> sizes
= aFDB
.smoothSizes(family
, style
);
100 pPFC
->Add(Qt5FontFace::fromQFont(aFDB
.font(family
, style
, *sizes
.begin())));
104 void Qt5Graphics::ClearDevFontCache() {}
106 bool Qt5Graphics::AddTempDevFont(PhysicalFontCollection
*, const OUString
& /*rFileURL*/,
107 const OUString
& /*rFontName*/)
112 bool Qt5Graphics::CreateFontSubset(const OUString
& /*rToFile*/, const PhysicalFontFace
* /*pFont*/,
113 const sal_GlyphId
* /*pGlyphIds*/, const sal_uInt8
* /*pEncoding*/,
114 sal_Int32
* /*pWidths*/, int /*nGlyphs*/,
115 FontSubsetInfo
& /*rInfo*/)
120 const void* Qt5Graphics::GetEmbedFontData(const PhysicalFontFace
*, long* /*pDataLen*/)
125 void Qt5Graphics::FreeEmbedFontData(const void* /*pData*/, long /*nDataLen*/) {}
127 void Qt5Graphics::GetGlyphWidths(const PhysicalFontFace
* /*pPFF*/, bool /*bVertical*/,
128 std::vector
<sal_Int32
>& /*rWidths*/, Ucs2UIntMap
& /*rUnicodeEnc*/)
132 bool Qt5Graphics::GetGlyphBoundRect(const GlyphItem
&, tools::Rectangle
&) { return false; }
134 bool Qt5Graphics::GetGlyphOutline(const GlyphItem
&, basegfx::B2DPolyPolygon
&) { return false; }
136 std::unique_ptr
<SalLayout
> Qt5Graphics::GetTextLayout(ImplLayoutArgs
&, int nFallbackLevel
)
138 if (m_pTextStyle
[nFallbackLevel
])
139 return std::unique_ptr
<SalLayout
>(new GenericSalLayout(*m_pTextStyle
[nFallbackLevel
]));
140 return std::unique_ptr
<SalLayout
>();
143 void Qt5Graphics::DrawTextLayout(const GenericSalLayout
&) {}
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */