From a738c98c2082fb603db5bac953cd5993e2319552 Mon Sep 17 00:00:00 2001 From: Jan Grulich Date: Sat, 10 Aug 2019 01:54:25 +0200 Subject: [PATCH] Add information about substituting font into properties dialog Reviewers: aacid Subscribers: pino, ngraham, okular-devel Tags: #okular Differential Revision: https://phabricator.kde.org/D23027 --- core/fontinfo.cpp | 12 ++++++++++++ core/fontinfo.h | 10 ++++++++++ generators/poppler/CMakeLists.txt | 10 ++++++++++ generators/poppler/config-okular-poppler.h.cmake | 3 +++ generators/poppler/generator_pdf.cpp | 3 +++ ui/propertiesdialog.cpp | 7 ++++++- 6 files changed, 44 insertions(+), 1 deletion(-) diff --git a/core/fontinfo.cpp b/core/fontinfo.cpp index f7ca0458a..056168a57 100644 --- a/core/fontinfo.cpp +++ b/core/fontinfo.cpp @@ -27,6 +27,7 @@ class Okular::FontInfoPrivate bool operator==( const FontInfoPrivate &rhs ) const { return name == rhs.name && + substituteName == rhs.substituteName && type == rhs.type && embedType == rhs.embedType && file == rhs.file && @@ -34,6 +35,7 @@ class Okular::FontInfoPrivate } QString name; + QString substituteName; FontInfo::FontType type; FontInfo::EmbedType embedType; bool canBeExtracted; @@ -66,6 +68,16 @@ void FontInfo::setName( const QString& name ) d->name = name; } +QString FontInfo::substituteName() const +{ + return d->substituteName; +} + +void FontInfo::setSubstituteName( const QString& substituteName ) +{ + d->substituteName = substituteName; +} + FontInfo::FontType FontInfo::type() const { return d->type; diff --git a/core/fontinfo.h b/core/fontinfo.h index b0f7fdb72..9423e05bb 100644 --- a/core/fontinfo.h +++ b/core/fontinfo.h @@ -84,6 +84,16 @@ class OKULARCORE_EXPORT FontInfo */ void setName( const QString& name ); + /** + * Returns the substitute name for the font. + */ + QString substituteName() const; + + /** + * Sets a new substitute name for the font. + */ + void setSubstituteName( const QString& substituteName ); + /** * Returns the type of the font. */ diff --git a/generators/poppler/CMakeLists.txt b/generators/poppler/CMakeLists.txt index c5ef51d4b..8735826c1 100644 --- a/generators/poppler/CMakeLists.txt +++ b/generators/poppler/CMakeLists.txt @@ -156,6 +156,16 @@ int main() } " HAVE_POPPLER_0_79) +check_cxx_source_compiles(" +#include +int main() +{ + Poppler::FontInfo info; + QString substituteName = info.substituteName(); + return 0; +} +" HAVE_POPPLER_0_80) + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/config-okular-poppler.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-okular-poppler.h diff --git a/generators/poppler/config-okular-poppler.h.cmake b/generators/poppler/config-okular-poppler.h.cmake index 7a34989c2..8a39ca395 100644 --- a/generators/poppler/config-okular-poppler.h.cmake +++ b/generators/poppler/config-okular-poppler.h.cmake @@ -48,3 +48,6 @@ /* Defined if we have the 0.79 version of the Poppler library */ #cmakedefine HAVE_POPPLER_0_79 1 + +/* Defined if we have the 0.80 version of the Poppler library */ +#cmakedefine HAVE_POPPLER_0_80 1 diff --git a/generators/poppler/generator_pdf.cpp b/generators/poppler/generator_pdf.cpp index 0e4ca05c7..73d265790 100644 --- a/generators/poppler/generator_pdf.cpp +++ b/generators/poppler/generator_pdf.cpp @@ -942,6 +942,9 @@ Okular::FontInfo::List PDFGenerator::fontsForPage( int page ) { Okular::FontInfo of; of.setName( font.name() ); +#ifdef HAVE_POPPLER_0_80 + of.setSubstituteName( font.substituteName() ); +#endif of.setType( convertPopplerFontInfoTypeToOkularFontInfoType( font.type() ) ); of.setEmbedType( embedTypeForPopplerFontInfo( font) ); of.setFile( font.file() ); diff --git a/ui/propertiesdialog.cpp b/ui/propertiesdialog.cpp index c782e6602..3ccfe04ab 100644 --- a/ui/propertiesdialog.cpp +++ b/ui/propertiesdialog.cpp @@ -355,7 +355,12 @@ QVariant FontsListModel::data( const QModelIndex &index, int role ) const { case 0: { - QString fontname = m_fonts.at( index.row() ).name(); + const Okular::FontInfo &fi = m_fonts.at( index.row() ); + const QString fontname = fi.name(); + const QString substituteName = fi.substituteName(); + if ( fi.embedType() == Okular::FontInfo::NotEmbedded && !substituteName.isEmpty() && !fontname.isEmpty() && substituteName != fontname ) { + return i18nc("Replacing missing font with another one", "%1 (substituting with %2)", fontname, substituteName); + } return fontname.isEmpty() ? i18nc( "font name not available (empty)", "[n/a]" ) : fontname; break; }