r21172 by jghali -

scribus-commit scribus-commit at lists.scribus.net
Fri Apr 8 20:27:04 UTC 2016


Author: jghali
Date: Fri Apr  8 20:27:04 2016
New Revision: 21172

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=21172
Log:
#13925: Non persistent setting when trying to enable Arial Regular subsetting

Modified:
    trunk/Scribus/scribus/fontlistmodel.cpp
    trunk/Scribus/scribus/fontlistmodel.h
    trunk/Scribus/scribus/ui/fontlistview.cpp
    trunk/Scribus/scribus/ui/fontlistview.h
    trunk/Scribus/scribus/ui/prefs_fonts.cpp

Modified: trunk/Scribus/scribus/fontlistmodel.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21172&path=/trunk/Scribus/scribus/fontlistmodel.cpp
==============================================================================
--- trunk/Scribus/scribus/fontlistmodel.cpp	(original)
+++ trunk/Scribus/scribus/fontlistmodel.cpp	Fri Apr  8 20:27:04 2016
@@ -22,8 +22,14 @@
 	otfFont = IconManager::instance()->loadPixmap("font_otf16.png");
 	psFont = IconManager::instance()->loadPixmap("font_type1_16.png");
 	substFont = IconManager::instance()->loadPixmap("font_subst16.png");
+
 	m_font_values = m_fonts.values();
 	m_font_names = m_fonts.keys();
+	for (int i = 0; i < m_font_names.length(); ++i)
+	{
+		ScFace font = m_fonts[m_font_names[i]];
+		m_enabledFonts.append(font.usable());
+	}
 }
 
 void FontListModel::setFonts(QList<QString> f)
@@ -31,12 +37,17 @@
 	beginResetModel();
 	m_font_names = f;
 	m_font_values.clear();
-	m_embedMethod.clear();
+	m_enabledFonts.clear();
+	m_embedFlags.clear();
 	for (int i = 0; i < m_font_names.length(); ++i)
 	{
 		ScFace font = m_fonts[m_font_names[i]];
 		m_font_values.append(font);
-		m_embedMethod.append(font.subset()? SubsetFont : font.embedPs()? EmbedFont : DontEmbed);
+		m_enabledFonts.append(font.usable());
+		int embedFlags = 0;
+		embedFlags |= font.embedPs() ? EmbedPS : 0;
+		embedFlags |= font.subset()  ? SubsetPDF : 0;
+		m_embedFlags.append(embedFlags);
 	}
 	endResetModel();
 }
@@ -53,7 +64,7 @@
 
 int FontListModel::columnCount(const QModelIndex&) const
 {
-	return 10;
+	return 9;
 }
 
 QVariant FontListModel::headerData(int section,
@@ -75,33 +86,18 @@
 				return tr("Font Name");
 			case FontListModel::FontUsable:
 				return isDisplayRole? QString("✓") : tr("Use Font");
-//			case FontListModel::FontFamily:
-//				return tr("Family");
-//			case FontListModel::FontStyle:
-//				return tr("Style");
-//			case FontListModel::FontVariant:
-//				return tr("Variant");
 			case FontListModel::FontType:
 				return tr("Type");
-//				return isDisplayRole? QString("a") : tr("Type");
 			case FontListModel::FontFormat:
 				return tr("Format");
-//				return isDisplayRole? QString("b") : tr("Format");
 			case FontListModel::FontEmbed:
 				return tr("Embed in PostScript");
-//				return isDisplayRole? QString("c") : tr("Embed in PostScript");
 			case FontListModel::FontSubset:
 				return tr("Subset");
-//				return isDisplayRole? QString("d") : tr("Subset");
-			case FontListModel::FontOutline:
-				return tr("Outline");
-//				return isDisplayRole? QString("e") : tr("Outline");
 			case FontListModel::FontAccess:
 				return tr("Access");
-//				return isDisplayRole? QString("f") : tr("Access");
 			case FontListModel::FontInDoc:
 				return tr("Used in Doc");
-//				return isDisplayRole? QString("g") : tr("Used in Doc");
 			case FontListModel::FontFile:
 				return tr("Path to Font File");
 			default:
@@ -117,7 +113,6 @@
 QVariant FontListModel::data(const QModelIndex & index,
 							 int role) const
 {
-//	ScFace font = m_fonts[m_fonts.keys().at(index.row())];
 	ScFace font = m_font_values[index.row()];
 
 	if (role == Qt::DecorationRole && index.column() == FontListModel::FontType)
@@ -148,12 +143,6 @@
 					tr("Family") + ":\t" + font.family() + "\n"
 					+ tr("Style") + ":\t" + font.style() + "\n"
 					+ tr("Variant") + ":\t" + font.variant();
-//			case FontListModel::FontFamily:
-//				return font.family();
-//			case FontListModel::FontStyle:
-//				return font.style();
-//			case FontListModel::FontVariant:
-//				return font.variant();
 			case FontListModel::FontType:
 			{
 				if (role == Qt::DisplayRole)
@@ -213,7 +202,6 @@
 					(index.column() == FontListModel::FontUsable
 					 || index.column() == FontListModel::FontEmbed
 					 || index.column() == FontListModel::FontSubset
-					 || index.column() == FontListModel::FontOutline
 					 )
 					)
 				{
@@ -222,31 +210,27 @@
 				return QVariant();
 		};
 	}
-
-	
 	
 	if (role == Qt::CheckStateRole && index.column() == FontListModel::FontUsable)
-		return !isLive() || (font.usable() ? Qt::Checked : Qt::Unchecked);
+	{
+		if (isLive())
+			return (font.usable() ? Qt::Checked : Qt::Unchecked);
+		else
+			return (m_enabledFonts[index.row()] ? Qt::Checked : Qt::Unchecked);
+	}
 	if (role == Qt::CheckStateRole && index.column() == FontListModel::FontEmbed)
 	{
 		if (isLive())
 			return (font.embedPs() ? Qt::Checked : Qt::Unchecked);
 		else
-			return (m_embedMethod[index.row()] >= EmbedFont ? Qt::Checked : Qt::Unchecked);
+			return ((m_embedFlags[index.row()] & EmbedPS) ? Qt::Checked : Qt::Unchecked);
 	}
 	if (role == Qt::CheckStateRole && index.column() == FontListModel::FontSubset)
 	{
 		if (isLive())
 			return (font.subset() ? Qt::Checked : Qt::Unchecked);
 		else
-			return (m_embedMethod[index.row()] >= SubsetFont ? Qt::Checked : Qt::Unchecked);
-	}
-	if (role == Qt::CheckStateRole && index.column() == FontListModel::FontOutline)
-	{
-		if (isLive())
-			return (font.outline() ? Qt::Checked : Qt::Unchecked);
-		else
-			return (m_embedMethod[index.row()] >= OutlineFont ? Qt::Checked : Qt::Unchecked);
+			return ((m_embedFlags[index.row()] & SubsetPDF) ? Qt::Checked : Qt::Unchecked);
 	}
 
 	return QVariant();
@@ -260,7 +244,6 @@
 		return QAbstractTableModel::flags(index);
 	if (index.column() == FontListModel::FontUsable
 		   || index.column() == FontListModel::FontEmbed
-		   || index.column() == FontListModel::FontOutline
 		   || index.column() == FontListModel::FontSubset)
 		return Qt::ItemIsUserCheckable | /*Qt::ItemIsEditable |*/ defaultFlags;
 	else
@@ -298,38 +281,36 @@
 			f.embedPs(!f.embedPs());
 		else if (idx.column() == FontListModel::FontSubset)
 			f.subset(!f.subset());
-		else if (idx.column() == FontListModel::FontOutline)
-			f.outline(!f.outline());
 		else
 			qDebug("FontListModel::setData() out of defined editable columns");
 	}
 	else
 	{
+		if (idx.column() == FontListModel::FontUsable && role == Qt::CheckStateRole)
+		{
+			Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());
+			m_enabledFonts[idx.row()] = (checkState == Qt::Checked);
+		}
 		if (idx.column() == FontListModel::FontEmbed)
 		{
-			if (m_embedMethod[idx.row()] == EmbedFont)
-				m_embedMethod[idx.row()] = DontEmbed;
-			else
-				m_embedMethod[idx.row()] = EmbedFont;
+			Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());
+			m_embedFlags[idx.row()] &= ~EmbedPS;
+			m_embedFlags[idx.row()] |= (checkState == Qt::Checked) ? EmbedPS : 0;
 		}
 		else if (idx.column() == FontListModel::FontSubset)
 		{
-			if (m_embedMethod[idx.row()] == SubsetFont)
-				m_embedMethod[idx.row()] = EmbedFont;
-			else
-				m_embedMethod[idx.row()] = SubsetFont;
+			Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());
+			m_embedFlags[idx.row()] &= ~SubsetPDF;
+			m_embedFlags[idx.row()] |= (checkState == Qt::Checked) ? SubsetPDF : 0;
 		}
-		else if (idx.column() == FontListModel::FontOutline)
-		{
-			if (m_embedMethod[idx.row()] == OutlineFont)
-				m_embedMethod[idx.row()] = SubsetFont;
-			else
-				m_embedMethod[idx.row()] = OutlineFont;
-		}
 		else
 			qDebug("FontListModel::setData() out of defined editable columns");
 	}
-	emit dataChanged(index(idx.row(),FontListModel::FontEmbed), index(idx.row(),FontListModel::FontOutline));
+
+	if (idx.column() == FontListModel::FontUsable)
+		emit dataChanged(index(idx.row(), FontListModel::FontUsable), index(idx.row(), FontListModel::FontUsable));
+	else
+		emit dataChanged(index(idx.row(), FontListModel::FontEmbed), index(idx.row(), FontListModel::FontSubset));
 
 	return true;
 }

Modified: trunk/Scribus/scribus/fontlistmodel.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21172&path=/trunk/Scribus/scribus/fontlistmodel.h
==============================================================================
--- trunk/Scribus/scribus/fontlistmodel.h	(original)
+++ trunk/Scribus/scribus/fontlistmodel.h	Fri Apr  8 20:27:04 2016
@@ -37,14 +37,10 @@
 		enum ColumnTypes {
             FontUsable = 0,
 			FontName,
-//			FontFamily,
-//			FontStyle,
-//			FontVariant,
 			FontType,
 			FontFormat,
 			FontEmbed,
 			FontSubset,
-            FontOutline,
 			FontAccess,
 			FontInDoc,
 			FontFile,
@@ -83,22 +79,28 @@
 		*/
 		QString nameForIndex(const QModelIndex & index);
 
-        bool isLive() const { return m_embedMethod.count() == 0; }
+        bool isLive() const { return m_embedFlags.count() == 0; }
 	private:
     
-    enum EmbedMethod {
-        DontEmbed = 0,
-        EmbedFont = 1,
-        SubsetFont = 2,
-        OutlineFont = 3
-    };
+		enum EmbedMethod {
+			DontEmbed = 0,
+			EmbedFont = 1,
+			SubsetFont = 2,
+			OutlineFont = 3
+		};
+
+		enum EmbedFlags {
+			EmbedPS = 1,
+			SubsetPDF = 2
+		};
     
 		ScribusDoc * m_doc;
 		//! Scribus fonts. \note: It's shared!
 		SCFonts m_fonts;
-		QList<ScFace> m_font_values;
+		QList<ScFace>  m_font_values;
         QList<QString> m_font_names;
-        QList<EmbedMethod> m_embedMethod;
+		QList<bool>    m_enabledFonts;
+        QList<int>     m_embedFlags;
     
 		//! Display icons by the Qt::DecorationRole
 		QPixmap ttfFont;

Modified: trunk/Scribus/scribus/ui/fontlistview.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21172&path=/trunk/Scribus/scribus/ui/fontlistview.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/fontlistview.cpp	(original)
+++ trunk/Scribus/scribus/ui/fontlistview.cpp	Fri Apr  8 20:27:04 2016
@@ -32,3 +32,37 @@
 	if (!isSortingEnabled())
 		sortByColumn(FontListModel::SortIndex, Qt::AscendingOrder);
 }
+
+QString FontListView::fontName(int i)
+{
+	FontListModel* fontModel = qobject_cast<FontListModel*>(model());
+	QModelIndex cellIndex = fontModel->index(i, FontListModel::FontName);
+	return fontModel->nameForIndex(cellIndex);
+}
+
+bool FontListView::isFontUsable(int i)
+{
+	FontListModel* fontModel = qobject_cast<FontListModel*>(model());
+	QModelIndex cellIndex = fontModel->index(i, FontListModel::FontUsable);
+	QVariant    checkData = fontModel->data(cellIndex, Qt::CheckStateRole);
+	Qt::CheckState checkState = static_cast<Qt::CheckState>(checkData.toInt());
+	return (checkState == Qt::Checked);
+}
+
+bool FontListView::isFontSubsetted(int i)
+{
+	FontListModel* fontModel = qobject_cast<FontListModel*>(model());
+	QModelIndex cellIndex = fontModel->index(i, FontListModel::FontSubset);
+	QVariant    checkData = fontModel->data(cellIndex, Qt::CheckStateRole);
+	Qt::CheckState checkState = static_cast<Qt::CheckState>(checkData.toInt());
+	return (checkState == Qt::Checked);
+}
+
+bool FontListView::isFontEmbeddedInPS(int i)
+{
+	FontListModel* fontModel = qobject_cast<FontListModel*>(model());
+	QModelIndex cellIndex = fontModel->index(i, FontListModel::FontEmbed);
+	QVariant    checkData = fontModel->data(cellIndex, Qt::CheckStateRole);
+	Qt::CheckState checkState = static_cast<Qt::CheckState>(checkData.toInt());
+	return (checkState == Qt::Checked);
+}

Modified: trunk/Scribus/scribus/ui/fontlistview.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21172&path=/trunk/Scribus/scribus/ui/fontlistview.h
==============================================================================
--- trunk/Scribus/scribus/ui/fontlistview.h	(original)
+++ trunk/Scribus/scribus/ui/fontlistview.h	Fri Apr  8 20:27:04 2016
@@ -23,8 +23,14 @@
 
 	public:
 		FontListView(QWidget * parent = 0);
+
 		void setModel(QAbstractItemModel * model);
 		void setFonts(SCFonts f);
+
+		QString fontName(int i);
+		bool    isFontUsable(int i);
+		bool    isFontSubsetted(int i);
+		bool    isFontEmbeddedInPS(int i);
 };
 
 #endif

Modified: trunk/Scribus/scribus/ui/prefs_fonts.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21172&path=/trunk/Scribus/scribus/ui/prefs_fonts.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/prefs_fonts.cpp	(original)
+++ trunk/Scribus/scribus/ui/prefs_fonts.cpp	Fri Apr  8 20:27:04 2016
@@ -211,13 +211,24 @@
 
 void Prefs_Fonts::saveGuiToPrefs(struct ApplicationPrefs *prefsData) const
 {
+	int fontCount = fontListTableView->model()->rowCount();
+	for (int i = 0; i < fontCount; ++i)
+	{
+		QString fontName = fontListTableView->fontName(i);
+		ScFace face = m_availFonts[fontName];
+
+		face.usable(fontListTableView->isFontUsable(i));
+		face.subset(fontListTableView->isFontSubsetted(i));
+		face.embedPs(fontListTableView->isFontEmbeddedInPS(i));
+	}
+
 	if (m_doc==0)
 		writePaths();
+
 	prefsData->fontPrefs.GFontSub.clear();
 	uint a = 0;
 	for (QMap<QString,QString>::ConstIterator itfsu = RList.begin(); itfsu != RList.end(); ++itfsu)
 		prefsData->fontPrefs.GFontSub[itfsu.key()] = FlagsRepl.at(a++)->currentText();
-
 }
 
 void Prefs_Fonts::changeUnit(ApplicationPrefs *prefsData) const




More information about the scribus-commit mailing list