View Issue Details

IDProjectCategoryView StatusLast Update
0015550ScribusFontspublic2019-06-04 20:55
Reporterale Assigned Tojghali  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Fixed in Version1.5.5.svn 
Summary0015550: Add a tab to Preferences > Fonts with the rejected fonts
DescriptionPeople often wonder if Scribus could find or not their fonts.

Listing the faulty fonts in the preferences (with or without the reason for rejection) could help them to find out what happened...
Tagspatch
PatchYes

Relationships

has duplicate 0009546 closedjghali Don't silently discard bad fonts, but show them as non selectable 

Activities

Arran

2019-01-23 15:19

reporter   ~0045844

I support ale. It is often a great pain not to find a font which is used in several other applications. Mentioning the Font does not fulfil the standards of Scribus and at the same time suggesting alternatives out of the fonts installed, is my added suggestion
.

jghali

2019-01-23 17:21

administrator   ~0045848

Good idea.

ale

2019-03-01 17:42

manager   ~0045946

a patch:
rejectedfonts.diff (7,610 bytes)   
diff --git a/scribus/scfonts.cpp b/scribus/scfonts.cpp
index 35c538718b..49ed1f813e 100644
--- a/scribus/scfonts.cpp
+++ b/scribus/scfonts.cpp
@@ -660,15 +660,19 @@ bool SCFonts::AddScalableFont(const QString& filename, FT_Library &library, cons
 		if (face != nullptr)
 			FT_Done_Face(face);
 		checkedFonts.insert(filename, foCache);
+		auto errorMessage = QObject::tr("Font %1 is broken, discarding it. Error message: \"%2\"").arg(filename, getFtError(error));
+		addRejectedFont(filename, errorMessage);
 		if (showFontInformation)
-			sDebug(QObject::tr("Font %1 is broken, discarding it. Error message: \"%2\"").arg(filename, getFtError(error)));
+			qDebug() << errorMessage;
 		return true;
 	}
 	getFontFormat(face, format, type);
 	if (format == ScFace::UNKNOWN_FORMAT) 
 	{
+		auto errorMessage = QObject::tr("Failed to load font %1 - font type unknown").arg(filename);
+		addRejectedFont(filename, errorMessage);
 		if (showFontInformation)
-			sDebug(QObject::tr("Failed to load font %1 - font type unknown").arg(filename));
+			sDebug(errorMessage);
 		FT_Done_Face(face);
 		checkedFonts.insert(filename, foCache);
 		return true;
@@ -677,8 +681,10 @@ bool SCFonts::AddScalableFont(const QString& filename, FT_Library &library, cons
 	// and do not provide a valid value for units_per_EM
 	if (face->units_per_EM == 0)
 	{
+		auto errorMessage = QObject::tr("Failed to load font %1 - font is not scalable").arg(filename);
+		addRejectedFont(filename, errorMessage);
 		if (showFontInformation)
-			sDebug(QObject::tr("Failed to load font %1 - font is not scalable").arg(filename));
+			sDebug(errorMessage);
 		FT_Done_Face(face);
 		checkedFonts.insert(filename, foCache);
 		return true;
@@ -696,12 +702,14 @@ bool SCFonts::AddScalableFont(const QString& filename, FT_Library &library, cons
 			error = FT_Load_Glyph(face, gindex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP);
 			if (error)
 			{
-				if (showFontInformation)
-					sDebug(QObject::tr("Font %1 has broken glyph %2 (charcode U+%3). Error message: \"%4\"")
+				auto errorMessage = QObject::tr("Font %1 has broken glyph %2 (charcode U+%3). Error message: \"%4\"")
 							   .arg(filename)
 							   .arg(gindex)
 							   .arg(charcode, 4, 16, QChar('0'))
-							   .arg(getFtError(error)));
+							   .arg(getFtError(error));
+				addRejectedFont(filename, errorMessage);
+				if (showFontInformation)
+					sDebug(errorMessage);
 				FT_Done_Face(face);
 				checkedFonts.insert(filename, foCache);
 				return true;
@@ -737,12 +745,14 @@ bool SCFonts::AddScalableFont(const QString& filename, FT_Library &library, cons
 				error = FT_Load_Glyph(face, gindex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP);
 				if (error)
 				{
-					if (showFontInformation)
-						sDebug(QObject::tr("Font %1 has broken glyph %2 (charcode U+%3). Error message: \"%4\"")
+					auto errorMessage = QObject::tr("Font %1 has broken glyph %2 (charcode U+%3). Error message: \"%4\"")
 								   .arg(filename)
 								   .arg(gindex)
 								   .arg(charcode, 4, 16, QChar('0'))
-								   .arg(getFtError(error)));
+								   .arg(getFtError(error));
+					addRejectedFont(filename, errorMessage);
+					if (showFontInformation)
+						sDebug(errorMessage);
 					FT_Done_Face(face);
 					checkedFonts.insert(filename, foCache);
 					return true;
@@ -1021,7 +1031,11 @@ void SCFonts::AddFontconfigFonts()
 		}
 		else
 			if (showFontInformation)
-				sDebug(QObject::tr("Failed to load a font - freetype2 couldn't find the font file"));
+			{
+				auto errorMessage = QObject::tr("Failed to load a font - freetype2 couldn't find the font file");
+				addRejectedFont(QString((char*)file), errorMessage);
+				sDebug(errorMessage);
+			}
 	}
 	FT_Done_FreeType(library);
 	FcFontSetDestroy(fs);
@@ -1221,3 +1235,8 @@ void SCFonts::GetFonts(const QString& pf, bool showFontInfo)
 	updateFontMap();
 	WriteCacheList(pf);
 }
+
+void SCFonts::addRejectedFont(QString fontPath, QString message)
+{
+	m_rejectedFonts.append({fontPath, message});
+}
diff --git a/scribus/scfonts.h b/scribus/scfonts.h
index bb2d85915c..b5daeffc36 100644
--- a/scribus/scfonts.h
+++ b/scribus/scfonts.h
@@ -12,6 +12,8 @@ for which a new license (GPL+exception) is in place.
 #include <QFont>
 #include <QList>
 #include <QMap>
+#include <QVector>
+#include <QPair>
 #include <QString>
 #include <QStringList>
 
@@ -54,6 +56,7 @@ class SCRIBUS_API SCFonts : public QMap<QString,ScFace>
 		void WriteCacheList();
 		/// maps family name to face variants
 		QMap<QString, QStringList> fontMap;
+		QVector<QPair<QString, QString>> m_rejectedFonts;
 	private:
 		void ReadCacheList(const QString& pf);
 		void WriteCacheList(const QString& pf);
@@ -77,6 +80,7 @@ class SCRIBUS_API SCFonts : public QMap<QString,ScFace>
 			QDateTime lastMod;
 		};
 		QMap<QString, testCache> checkedFonts;
+		void addRejectedFont(QString fontPath, QString message);
 	protected:
 		bool showFontInformation;
 };
diff --git a/scribus/ui/prefs_fonts.cpp b/scribus/ui/prefs_fonts.cpp
index 38a076a69f..fef102704a 100644
--- a/scribus/ui/prefs_fonts.cpp
+++ b/scribus/ui/prefs_fonts.cpp
@@ -47,7 +47,7 @@ Prefs_Fonts::Prefs_Fonts(QWidget* parent, ScribusDoc* doc)
 	CurrentPath = "";
 	m_askBeforeSubstitute = true;
 
-	setMinimumSize(fontMetrics().width( tr( "Available Fonts" )+ tr( "Font Substitutions" )+ tr( "Additional Paths" ))+180, 200);
+	setMinimumSize(fontMetrics().width( tr( "Available Fonts" )+ tr( "Font Substitutions" )+ tr( "Additional Paths" )+ tr( "Rejected Fonts" ))+180, 200);
 
 	fontListTableView->setModel(new FontListModel(fontListTableView, m_doc, true));
 
@@ -206,6 +206,23 @@ void Prefs_Fonts::restoreDefaults(struct ApplicationPrefs *prefsData)
 		a++;
 	}
 	deleteSubstitutionButton->setEnabled(false);
+	// fontsRejectedTableWidget->headerView()->resizeSection(0, 500);
+	auto headerView = fontsRejectedTableWidget->horizontalHeader();
+	headerView->resizeSection(0, 150);
+	headerView->resizeSection(1, 250);
+	headerView->setStretchLastSection(true);
+	int i{0};
+	for (const auto& font: prefsData->fontPrefs.AvailFonts.m_rejectedFonts)
+	{
+		fontsRejectedTableWidget->insertRow (i);
+		fontsRejectedTableWidget->setItem(i, 0,
+			new QTableWidgetItem(QFileInfo(font.second).baseName()));
+		fontsRejectedTableWidget->setItem(i, 1,
+			new QTableWidgetItem(font.second));
+		fontsRejectedTableWidget->setItem(i, 2,
+			new QTableWidgetItem(font.first));
+		i++;
+	}
 	updateFontList();
 }
 
diff --git a/scribus/ui/prefs_fontsbase.ui b/scribus/ui/prefs_fontsbase.ui
index 0610623242..cd359066c9 100644
--- a/scribus/ui/prefs_fontsbase.ui
+++ b/scribus/ui/prefs_fontsbase.ui
@@ -186,6 +186,35 @@
        </item>
       </layout>
      </widget>
+     <widget class="QWidget" name="rejectedFontsTab">
+      <attribute name="title">
+       <string>Rejected Fonts</string>
+      </attribute>
+      <layout class="QGridLayout" name="gridLayout">
+       <item row="0" column="0">
+        <widget class="QTableWidget" name="fontsRejectedTableWidget">
+         <property name="columnCount">
+          <number>3</number>
+         </property>
+         <column>
+          <property name="text">
+           <string>Font name</string>
+          </property>
+         </column>
+         <column>
+          <property name="text">
+           <string>Error message</string>
+          </property>
+         </column>
+         <column>
+          <property name="text">
+           <string>Font file</string>
+          </property>
+         </column>
+        </widget>
+       </item>
+      </layout>
+     </widget>
     </widget>
    </item>
   </layout>
rejectedfonts.diff (7,610 bytes)   

ale

2019-03-01 17:52

manager  

rejeected-fonts.png (116,616 bytes)   
rejeected-fonts.png (116,616 bytes)   

jghali

2019-03-12 10:52

administrator   ~0045991

Last edited: 2019-03-12 10:53

Patch committed. I did a few modifications like storing rejected font data in a map instead of a QVector<QPair< > >, and shortening error messages displayed in the new tab.

Issue History

Date Modified Username Field Change
2019-01-23 14:55 ale New Issue
2019-01-23 15:19 Arran Note Added: 0045844
2019-01-23 17:21 jghali Note Added: 0045848
2019-01-24 15:38 ale Relationship added related to 0009546
2019-03-01 17:42 ale File Added: rejectedfonts.diff
2019-03-01 17:42 ale Note Added: 0045946
2019-03-01 17:43 ale Summary Add a tab to Preferences > Fonts with the rejected fonts => [Patch] Add a tab to Preferences > Fonts with the rejected fonts
2019-03-01 17:43 ale Patch No => Yes
2019-03-01 17:45 ale Tag Attached: patch
2019-03-01 17:52 ale File Added: rejeected-fonts.png
2019-03-12 10:38 jghali Summary [Patch] Add a tab to Preferences > Fonts with the rejected fonts => Add a tab to Preferences > Fonts with the rejected fonts
2019-03-12 10:52 jghali Note Added: 0045991
2019-03-12 10:53 jghali Note Edited: 0045991
2019-03-12 10:55 jghali Assigned To => jghali
2019-03-12 10:55 jghali Status new => resolved
2019-03-12 10:55 jghali Resolution open => fixed
2019-03-12 10:55 jghali Fixed in Version => 1.5.5.svn
2019-03-14 13:58 jghali Relationship replaced has duplicate 0009546
2019-06-04 20:55 cbradney Status resolved => closed