2017-10-31 01:10:36 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
|
|
|
|
2018-06-01 15:28:26 +02:00
|
|
|
#include <Qt5FontFace.hxx>
|
2017-12-26 15:14:31 +00:00
|
|
|
#include "Qt5Font.hxx"
|
2018-06-01 15:28:26 +02:00
|
|
|
#include <Qt5Tools.hxx>
|
2017-10-31 01:10:36 +01:00
|
|
|
|
|
|
|
#include <sft.hxx>
|
|
|
|
#include <impfontcharmap.hxx>
|
|
|
|
#include <fontinstance.hxx>
|
|
|
|
#include <fontselect.hxx>
|
|
|
|
#include <PhysicalFontCollection.hxx>
|
|
|
|
|
|
|
|
#include <QtGui/QFont>
|
2018-03-12 09:56:18 +01:00
|
|
|
#include <QtGui/QFontInfo>
|
2017-10-31 01:10:36 +01:00
|
|
|
#include <QtGui/QRawFont>
|
|
|
|
|
|
|
|
using namespace vcl;
|
|
|
|
|
2017-11-08 11:28:04 +01:00
|
|
|
Qt5FontFace::Qt5FontFace(const Qt5FontFace& rSrc)
|
|
|
|
: PhysicalFontFace(rSrc)
|
|
|
|
, m_aFontId(rSrc.m_aFontId)
|
2017-10-31 01:10:36 +01:00
|
|
|
{
|
2017-11-08 11:28:04 +01:00
|
|
|
if (rSrc.m_xCharMap.is())
|
2017-10-31 01:10:36 +01:00
|
|
|
m_xCharMap = rSrc.m_xCharMap;
|
|
|
|
}
|
|
|
|
|
2017-11-08 11:28:04 +01:00
|
|
|
Qt5FontFace* Qt5FontFace::fromQFont(const QFont& rFont)
|
2017-10-31 01:10:36 +01:00
|
|
|
{
|
|
|
|
FontAttributes aFA;
|
2017-11-08 11:28:04 +01:00
|
|
|
aFA.SetFamilyName(toOUString(rFont.family()));
|
|
|
|
aFA.SetStyleName(toOUString(rFont.styleName()));
|
|
|
|
aFA.SetItalic(rFont.italic() ? ITALIC_NORMAL : ITALIC_NONE);
|
2017-10-31 01:10:36 +01:00
|
|
|
|
2017-11-08 11:28:04 +01:00
|
|
|
return new Qt5FontFace(aFA, rFont.toString());
|
2017-10-31 01:10:36 +01:00
|
|
|
}
|
|
|
|
|
2017-11-08 11:28:04 +01:00
|
|
|
Qt5FontFace::Qt5FontFace(const FontAttributes& rFA, const QString& rFontID)
|
|
|
|
: PhysicalFontFace(rFA)
|
|
|
|
, m_aFontId(rFontID)
|
|
|
|
, m_bFontCapabilitiesRead(false)
|
2017-10-31 01:10:36 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-11-08 11:28:04 +01:00
|
|
|
Qt5FontFace::~Qt5FontFace() {}
|
2017-10-31 01:10:36 +01:00
|
|
|
|
2017-11-08 11:28:04 +01:00
|
|
|
sal_IntPtr Qt5FontFace::GetFontId() const { return reinterpret_cast<sal_IntPtr>(&m_aFontId); }
|
2017-10-31 01:10:36 +01:00
|
|
|
|
2017-12-26 15:58:21 +01:00
|
|
|
LogicalFontInstance* Qt5FontFace::CreateFontInstance(const FontSelectPattern& rFSD) const
|
|
|
|
{
|
|
|
|
return new Qt5Font(*this, rFSD);
|
|
|
|
}
|
|
|
|
|
2017-10-30 19:05:41 +01:00
|
|
|
const FontCharMapRef Qt5FontFace::GetFontCharMap() const
|
2017-10-31 01:10:36 +01:00
|
|
|
{
|
2017-11-08 11:28:04 +01:00
|
|
|
if (m_xCharMap.is())
|
2017-10-31 01:10:36 +01:00
|
|
|
return m_xCharMap;
|
|
|
|
|
|
|
|
QFont aFont;
|
2017-11-08 11:28:04 +01:00
|
|
|
aFont.fromString(m_aFontId);
|
|
|
|
QRawFont aRawFont(QRawFont::fromFont(aFont));
|
|
|
|
QByteArray aCMapTable = aRawFont.fontTable("cmap");
|
|
|
|
if (aCMapTable.isEmpty())
|
2017-10-31 01:10:36 +01:00
|
|
|
{
|
|
|
|
m_xCharMap = new FontCharMap();
|
|
|
|
return m_xCharMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
CmapResult aCmapResult;
|
2017-11-08 11:28:04 +01:00
|
|
|
if (ParseCMAP(reinterpret_cast<const unsigned char*>(aCMapTable.data()), aCMapTable.size(),
|
|
|
|
aCmapResult))
|
|
|
|
m_xCharMap = new FontCharMap(aCmapResult);
|
2017-10-31 01:10:36 +01:00
|
|
|
|
|
|
|
return m_xCharMap;
|
|
|
|
}
|
|
|
|
|
2017-11-08 11:28:04 +01:00
|
|
|
bool Qt5FontFace::GetFontCapabilities(vcl::FontCapabilities& rFontCapabilities) const
|
2017-10-31 01:10:36 +01:00
|
|
|
{
|
|
|
|
// read this only once per font
|
2017-11-08 11:28:04 +01:00
|
|
|
if (m_bFontCapabilitiesRead)
|
2017-10-31 01:10:36 +01:00
|
|
|
{
|
|
|
|
rFontCapabilities = m_aFontCapabilities;
|
|
|
|
return rFontCapabilities.oUnicodeRange || rFontCapabilities.oCodePageRange;
|
|
|
|
}
|
|
|
|
m_bFontCapabilitiesRead = true;
|
|
|
|
|
|
|
|
QFont aFont;
|
2017-11-08 11:28:04 +01:00
|
|
|
aFont.fromString(m_aFontId);
|
|
|
|
QRawFont aRawFont(QRawFont::fromFont(aFont));
|
|
|
|
QByteArray aOS2Table = aRawFont.fontTable("OS/2");
|
|
|
|
if (!aOS2Table.isEmpty())
|
2017-10-31 01:10:36 +01:00
|
|
|
{
|
2017-11-08 11:28:04 +01:00
|
|
|
vcl::getTTCoverage(m_aFontCapabilities.oUnicodeRange, m_aFontCapabilities.oCodePageRange,
|
|
|
|
reinterpret_cast<const unsigned char*>(aOS2Table.data()),
|
|
|
|
aOS2Table.size());
|
2017-10-31 01:10:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rFontCapabilities = m_aFontCapabilities;
|
|
|
|
return rFontCapabilities.oUnicodeRange || rFontCapabilities.oCodePageRange;
|
|
|
|
}
|
|
|
|
|
2018-06-05 14:48:51 +02:00
|
|
|
rtl::Reference<PhysicalFontFace> Qt5FontFace::Clone() const { return new Qt5FontFace(*this); }
|
2017-10-31 01:10:36 +01:00
|
|
|
|
2017-12-14 18:42:57 +01:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|