1 /************************************************************************
2 **
3 **  Copyright (C) 2015-2019 Kevin B. Hendricks, Stratford Ontario Canada
4 **  Copyright (C) 2009-2011 Strahinja Markovic  <strahinja.markovic@gmail.com>
5 **
6 **  This file is part of Sigil.
7 **
8 **  Sigil is free software: you can redistribute it and/or modify
9 **  it under the terms of the GNU General Public License as published by
10 **  the Free Software Foundation, either version 3 of the License, or
11 **  (at your option) any later version.
12 **
13 **  Sigil is distributed in the hope that it will be useful,
14 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 **  GNU General Public License for more details.
17 **
18 **  You should have received a copy of the GNU General Public License
19 **  along with Sigil.  If not, see <http://www.gnu.org/licenses/>.
20 **
21 *************************************************************************/
22 
23 #include <QRawFont>
24 #include <QFont>
25 
26 #include "Misc/Utility.h"
27 #include "ResourceObjects/FontResource.h"
28 
FontResource(const QString & mainfolder,const QString & fullfilepath,QObject * parent)29 FontResource::FontResource(const QString &mainfolder, const QString &fullfilepath, QObject *parent)
30     : Resource(mainfolder, fullfilepath, parent)
31 {
32 }
33 
34 
Type() const35 Resource::ResourceType FontResource::Type() const
36 {
37     return Resource::FontResourceType;
38 }
39 
40 
GetObfuscationAlgorithm() const41 QString FontResource::GetObfuscationAlgorithm() const
42 {
43     return m_ObfuscationAlgorithm;
44 }
45 
GetDescription() const46 QString FontResource::GetDescription() const
47 {
48     QRawFont rawfont(GetFullPath(), 16.0);
49     QString desc = rawfont.familyName();
50     QString weight_name;
51     QString style_name;
52     if (rawfont.weight() <  QFont::ExtraLight)      weight_name = " Thin";
53     else if (rawfont.weight() <  QFont::Light)      weight_name = " ExtraLight";
54     else if (rawfont.weight() <  QFont::Normal)     weight_name = " Light";
55     else if (rawfont.weight() <  QFont::Medium)     weight_name = " Normal";
56     else if (rawfont.weight() <  QFont::DemiBold)   weight_name = " Medium";
57     else if (rawfont.weight() <  QFont::Bold)       weight_name = " DemiBold";
58     else if (rawfont.weight() <  QFont::ExtraBold)  weight_name = " Bold";
59     else if (rawfont.weight() <  QFont::Black)      weight_name = " ExtraBold";
60     else if (rawfont.weight() >= QFont::Black)      weight_name = " Black";
61     if (desc != "") {
62         if (desc.contains(weight_name)) weight_name = "";
63         desc = desc + weight_name;
64     }
65 
66     if (rawfont.style()      == QFont::StyleItalic)  style_name = " Italic";
67     else if (rawfont.style() == QFont::StyleOblique) style_name = " Oblique";
68 
69     if (desc != "") desc = desc + style_name;
70     else desc = tr("No reliable font data");
71     return desc;
72 }
73 
SetObfuscationAlgorithm(const QString & algorithm)74 void FontResource::SetObfuscationAlgorithm(const QString &algorithm)
75 {
76     m_ObfuscationAlgorithm = algorithm;
77 }
78 
LoadFromDisk()79 bool FontResource::LoadFromDisk()
80 {
81     emit Modified();
82     return true;
83 }
84