r14311 by jghali - #8509 (second part) : allow scribus to run with a single installed font - fix issues in font combo widget which could potentially show non usable fonts - fix a bug in missing font dialog which could return a wrong remplacement font - modify a bit the way prefs file is written so as to detect is one try to use a non usable font as default font
scribus-commit
scribus-commit at lists.scribus.net
Thu Nov 19 23:05:25 CET 2009
Revision: 14311
Author: jghali
Date: 2009-11-19T13:22:58.530219Z
Commit message: #8509 (second part) : allow scribus to run with a single installed font
- fix issues in font combo widget which could potentially show non usable fonts
- fix a bug in missing font dialog which could return a wrong remplacement font
- modify a bit the way prefs file is written so as to detect is one try to use a non usable font as default font
Changeset:
M /branches/Version135/Scribus/scribus/missing.cpp
M /branches/Version135/Scribus/scribus/prefsmanager.cpp
M /branches/Version135/Scribus/scribus/fontcombo.cpp
Diffs:
Index: scribus/prefsmanager.cpp
===================================================================
--- scribus/prefsmanager.cpp (revision 14310)
+++ scribus/prefsmanager.cpp (revision 14311)
@@ -1295,6 +1295,29 @@
dc1a.setAttribute("RANDF", static_cast<int>(appPrefs.marginColored));
dc1a.setAttribute("DScale", ScCLocale::toQStringC(appPrefs.DisScale));
elem.appendChild(dc1a);
+ // Font information must be written before FONTS element so that face "usable"
+ // member is set properly before one try to set default font. Allows to check
+ // that default font is indeed usable, problems expected otherwise
+ for ( SCFontsIterator itf(appPrefs.AvailFonts); itf.hasNext(); itf.next())
+ {
+ if (!itf.currentKey().isEmpty())
+ {
+ QDomElement fn=docu.createElement("FONT");
+ fn.setAttribute("NAME",itf.currentKey());
+ fn.setAttribute("EMBED",static_cast<int>(itf.current().embedPs()));
+ fn.setAttribute("USE", static_cast<int>(itf.current().usable()));
+ fn.setAttribute("SUBSET", static_cast<int>(itf.current().subset()));
+ elem.appendChild(fn);
+ }
+ }
+ QMap<QString,QString>::Iterator itfsu;
+ for (itfsu = appPrefs.GFontSub.begin(); itfsu != appPrefs.GFontSub.end(); ++itfsu)
+ {
+ QDomElement fosu = docu.createElement("Substitute");
+ fosu.setAttribute("Name",itfsu.key());
+ fosu.setAttribute("Replace",itfsu.value());
+ elem.appendChild(fosu);
+ }
QDomElement dc2=docu.createElement("FONTS");
dc2.setAttribute("FACE",appPrefs.toolSettings.defFont);
dc2.setAttribute("SIZE",appPrefs.toolSettings.defSize / 10.0);
@@ -1548,18 +1571,6 @@
co.setAttribute("Register", static_cast<int>(itc.value().isRegistrationColor()));
elem.appendChild(co);
}
- for ( SCFontsIterator itf(appPrefs.AvailFonts); itf.hasNext(); itf.next())
- {
- if (!itf.currentKey().isEmpty())
- {
- QDomElement fn=docu.createElement("FONT");
- fn.setAttribute("NAME",itf.currentKey());
- fn.setAttribute("EMBED",static_cast<int>(itf.current().embedPs()));
- fn.setAttribute("USE", static_cast<int>(itf.current().usable()));
- fn.setAttribute("SUBSET", static_cast<int>(itf.current().subset()));
- elem.appendChild(fn);
- }
- }
for (int rd=0; rd<appPrefs.RecentDocs.count(); ++rd)
{
QDomElement rde=docu.createElement("RECENT");
@@ -1575,14 +1586,6 @@
kscc.setAttribute("SEQUENCE",TabKeyboardShortcutsWidget::getKeyText(ksc.value().keySequence));
elem.appendChild(kscc);
}
- QMap<QString,QString>::Iterator itfsu;
- for (itfsu = appPrefs.GFontSub.begin(); itfsu != appPrefs.GFontSub.end(); ++itfsu)
- {
- QDomElement fosu = docu.createElement("Substitute");
- fosu.setAttribute("Name",itfsu.key());
- fosu.setAttribute("Replace",itfsu.value());
- elem.appendChild(fosu);
- }
for (int ccs=0; ccs<appPrefs.CustomColorSets.count(); ++ccs)
{
QDomElement cos=docu.createElement("COLORSET");
@@ -2181,7 +2184,7 @@
if (!tmpf.isEmpty())
{
QString newFont = "";
- if (!appPrefs.AvailFonts.contains(tmpf))
+ if (!appPrefs.AvailFonts.contains(tmpf) || !appPrefs.AvailFonts[tmpf].usable())
{
ScCore->showSplash(false);
MissingFont *dia = new MissingFont(0, tmpf, 0);
@@ -2202,9 +2205,10 @@
QString tmpf(dc.attribute("NAME"));
if (!tmpf.isEmpty() && appPrefs.AvailFonts.contains(tmpf))
{
- appPrefs.AvailFonts[tmpf].embedPs(static_cast<bool>(dc.attribute("EMBED").toInt()));
- appPrefs.AvailFonts[tmpf].usable(appPrefs.AvailFonts[tmpf].usable() && static_cast<bool>(dc.attribute("USE", "1").toInt()));
- appPrefs.AvailFonts[tmpf].subset(static_cast<bool>(dc.attribute("SUBSET", "0").toInt()));
+ ScFace& face(appPrefs.AvailFonts[tmpf]);
+ face.embedPs(static_cast<bool>(dc.attribute("EMBED").toInt()));
+ face.usable(face.usable() && static_cast<bool>(dc.attribute("USE", "1").toInt()));
+ face.subset(static_cast<bool>(dc.attribute("SUBSET", "0").toInt()));
}
}
if (dc.tagName()=="COLOR")
Index: scribus/missing.cpp
===================================================================
--- scribus/missing.cpp (revision 14310)
+++ scribus/missing.cpp (revision 14311)
@@ -323,15 +323,10 @@
missingFontGridLayout->addWidget( useLabel, 1, 1 );
replaceFontCombo = new FontCombo(this);
if (doc != 0)
- {
setCurrentComboItem(replaceFontCombo, doc->toolSettings.defFont);
- replacementFont = doc->toolSettings.defFont;
- }
else
- {
setCurrentComboItem(replaceFontCombo, PrefsManager::instance()->appPrefs.toolSettings.defFont);
- replacementFont = PrefsManager::instance()->appPrefs.toolSettings.defFont;
- }
+ replacementFont = replaceFontCombo->currentText();
missingFontGridLayout->addWidget( replaceFontCombo, 1, 2 );
insteadLabel = new QLabel( tr( "instead" ), this );
missingFontGridLayout->addWidget( insteadLabel, 1, 3 );
Index: scribus/fontcombo.cpp
===================================================================
--- scribus/fontcombo.cpp (revision 14310)
+++ scribus/fontcombo.cpp (revision 14311)
@@ -157,7 +157,18 @@
disconnect(fontStyle, SIGNAL(activated(int)), this, SLOT(styleSelected(int)));
QString curr = fontStyle->currentText();
fontStyle->clear();
- QStringList slist = prefsManager->appPrefs.AvailFonts.fontMap[fontFamily->itemText(id)];
+ QString fntFamily = fontFamily->itemText(id);
+ QStringList slist, styleList = prefsManager->appPrefs.AvailFonts.fontMap[fntFamily];
+ for (QStringList::ConstIterator it = styleList.begin(); it != styleList.end(); ++it)
+ {
+ SCFonts::ConstIterator fIt = prefsManager->appPrefs.AvailFonts.find(fntFamily + " " + *it);
+ if (fIt != prefsManager->appPrefs.AvailFonts.end())
+ {
+ if (!fIt->usable() || fIt->isReplacement())
+ continue;
+ slist.append(*it);
+ }
+ }
slist.sort();
fontStyle->addItems(slist);
if (slist.contains(curr))
@@ -191,13 +202,18 @@
QStringList slist = prefsManager->appPrefs.AvailFonts.fontMap[family];
slist.sort();
QStringList ilist;
- ilist.clear();
if (currDoc != NULL)
{
for (QStringList::ConstIterator it3 = slist.begin(); it3 != slist.end(); ++it3)
{
- if ((currDoc->DocName == prefsManager->appPrefs.AvailFonts[family + " " + *it3].localForDocument()) || (prefsManager->appPrefs.AvailFonts[family + " " + *it3].localForDocument().isEmpty()))
- ilist.append(*it3);
+ SCFonts::ConstIterator fIt = prefsManager->appPrefs.AvailFonts.find(family + " " + *it3);
+ if (fIt != prefsManager->appPrefs.AvailFonts.end())
+ {
+ if (!fIt->usable() || fIt->isReplacement())
+ continue;
+ if ((currDoc->DocName == fIt->localForDocument()) || (fIt->localForDocument().isEmpty()))
+ ilist.append(*it3);
+ }
}
fontStyle->addItems(ilist);
}
@@ -216,7 +232,7 @@
fontFamily->clear();
fontStyle->clear();
QStringList rlist = prefsManager->appPrefs.AvailFonts.fontMap.keys();
- QMap<QString, QString> flist;
+ QMap<QString, ScFace::FontType> flist;
flist.clear();
for (QStringList::ConstIterator it2 = rlist.begin(); it2 != rlist.end(); ++it2)
{
@@ -224,53 +240,70 @@
{
QStringList slist = prefsManager->appPrefs.AvailFonts.fontMap[*it2];
slist.sort();
- QStringList ilist;
- ilist.clear();
for (QStringList::ConstIterator it3 = slist.begin(); it3 != slist.end(); ++it3)
{
if ( prefsManager->appPrefs.AvailFonts.contains(*it2 + " " + *it3))
{
const ScFace& fon(prefsManager->appPrefs.AvailFonts[*it2 + " " + *it3]);
- if (fon.usable() && !fon.isReplacement() && (currentDoc->DocName == fon.localForDocument() || fon.localForDocument().isEmpty()))
- ilist.append(*it3);
+ ScFace::FontType type = fon.type();
+ if (!fon.usable() || fon.isReplacement() || !(currentDoc->DocName == fon.localForDocument() || fon.localForDocument().isEmpty()))
+ continue;
+ if ((forAnnotation) && ((type == ScFace::TYPE1) || (type == ScFace::OTF) || (fon.subset())))
+ continue;
+ if ((forSubstitute) && fon.isReplacement())
+ continue;
+ flist.insert(*it2, fon.type());
+ break;
}
}
- if (!ilist.isEmpty())
- flist.insert((*it2).toLower(), *it2);
}
else
- flist.insert((*it2).toLower(), *it2);
+ {
+ QMap<QString, QStringList>::ConstIterator fmIt = prefsManager->appPrefs.AvailFonts.fontMap.find(*it2);
+ if (fmIt == prefsManager->appPrefs.AvailFonts.fontMap.end())
+ continue;
+ if (fmIt->count() <= 0)
+ continue;
+ QString fullFontName = (*it2) + " " + fmIt->at(0);
+ ScFace fon = prefsManager->appPrefs.AvailFonts[fullFontName];
+ if ( !fon.usable() || fon.isReplacement() )
+ continue;
+ ScFace::FontType type = fon.type();
+ if ((forAnnotation) && ((type == ScFace::TYPE1) || (type == ScFace::OTF) || (fon.subset())))
+ continue;
+ if ((forSubstitute) && fon.isReplacement())
+ continue;
+ flist.insert(*it2, fon.type());
+ }
}
- for (QMap<QString,QString>::Iterator it2a = flist.begin(); it2a != flist.end(); ++it2a)
+ for (QMap<QString, ScFace::FontType>::Iterator it2a = flist.begin(); it2a != flist.end(); ++it2a)
{
- ScFace fon = prefsManager->appPrefs.AvailFonts[it2a.value()+" "+prefsManager->appPrefs.AvailFonts.fontMap[it2a.value()][0]];
- if ( !fon.usable() || fon.isReplacement() )
- continue;
- ScFace::FontType type = fon.type();
- if ((forAnnotation) && ((type == ScFace::TYPE1) || (type == ScFace::OTF) || (fon.subset())))
- continue;
- if ((forSubstitute) && fon.isReplacement())
- continue;
- if (fon.isReplacement())
+ ScFace::FontType type = it2a.value();
+ // Replacement fonts were systematically discarded in previous code
+ /*if (fon.isReplacement())
fontFamily->addItem(substFont, it2a.value());
- else if (type == ScFace::OTF)
- fontFamily->addItem(otfFont, it2a.value());
+ else */if (type == ScFace::OTF)
+ fontFamily->addItem(otfFont, it2a.key());
else if (type == ScFace::TYPE1)
- fontFamily->addItem(psFont, it2a.value());
+ fontFamily->addItem(psFont, it2a.key());
else if (type == ScFace::TTF)
- fontFamily->addItem(ttfFont, it2a.value());
+ fontFamily->addItem(ttfFont, it2a.key());
}
QString family = fontFamily->currentText();
QStringList slist = prefsManager->appPrefs.AvailFonts.fontMap[family];
slist.sort();
QStringList ilist;
- ilist.clear();
if (currentDoc != NULL)
{
- for (QStringList::ConstIterator it3 = slist.begin(); it3 != slist.end(); ++it3)
+ for (QStringList::ConstIterator it = slist.begin(); it != slist.end(); ++it)
{
- if (prefsManager->appPrefs.AvailFonts.contains(family + " " + *it3) && (currentDoc->DocName == prefsManager->appPrefs.AvailFonts[family + " " + *it3].localForDocument() || prefsManager->appPrefs.AvailFonts[family + " " + *it3].localForDocument().isEmpty()))
- ilist.append(*it3);
+ SCFonts::ConstIterator fIt = prefsManager->appPrefs.AvailFonts.find(family + " " + *it);
+ if (fIt != prefsManager->appPrefs.AvailFonts.end())
+ {
+ if (!fIt->usable() || fIt->isReplacement())
+ continue;
+ ilist.append(*it);
+ }
}
fontStyle->addItems(ilist);
}
More information about the scribus-commit
mailing list