r14312 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:48 CET 2009
Revision: 14312
Author: jghali
Date: 2009-11-19T13:23:59.644688Z
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 /trunk/Scribus/scribus/prefsmanager.cpp
M /trunk/Scribus/scribus/ui/fontcombo.cpp
M /trunk/Scribus/scribus/ui/missing.cpp
Diffs:
Index: scribus/prefsmanager.cpp
===================================================================
--- scribus/prefsmanager.cpp (revision 14311)
+++ scribus/prefsmanager.cpp (revision 14312)
@@ -1304,6 +1304,29 @@
dc1a.setAttribute("RANDF", static_cast<int>(appPrefs.displayPrefs.marginColored));
dc1a.setAttribute("DScale", ScCLocale::toQStringC(appPrefs.displayPrefs.displayScale));
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.fontPrefs.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.fontPrefs.GFontSub.begin(); itfsu != appPrefs.fontPrefs.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.itemToolPrefs.textFont);
dc2.setAttribute("SIZE",appPrefs.itemToolPrefs.textSize / 10.0);
@@ -1580,18 +1603,6 @@
}
elem.appendChild(grad);
}
- for ( SCFontsIterator itf(appPrefs.fontPrefs.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.uiPrefs.RecentDocs.count(); ++rd)
{
QDomElement rde=docu.createElement("RECENT");
@@ -1607,14 +1618,6 @@
kscc.setAttribute("SEQUENCE",TabKeyboardShortcutsWidget::getKeyText(ksc.value().keySequence));
elem.appendChild(kscc);
}
- QMap<QString,QString>::Iterator itfsu;
- for (itfsu = appPrefs.fontPrefs.GFontSub.begin(); itfsu != appPrefs.fontPrefs.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.colorPrefs.CustomColorSets.count(); ++ccs)
{
QDomElement cos=docu.createElement("COLORSET");
@@ -2245,7 +2248,7 @@
if (!tmpf.isEmpty())
{
QString newFont = "";
- if (!appPrefs.fontPrefs.AvailFonts.contains(tmpf))
+ if (!appPrefs.fontPrefs.AvailFonts.contains(tmpf) || !appPrefs.fontPrefs.AvailFonts[tmpf].usable())
{
ScCore->showSplash(false);
MissingFont *dia = new MissingFont(0, tmpf, 0);
@@ -2266,9 +2269,10 @@
QString tmpf(dc.attribute("NAME"));
if (!tmpf.isEmpty() && appPrefs.fontPrefs.AvailFonts.contains(tmpf))
{
- appPrefs.fontPrefs.AvailFonts[tmpf].embedPs(static_cast<bool>(dc.attribute("EMBED").toInt()));
- appPrefs.fontPrefs.AvailFonts[tmpf].usable(appPrefs.fontPrefs.AvailFonts[tmpf].usable() && static_cast<bool>(dc.attribute("USE", "1").toInt()));
- appPrefs.fontPrefs.AvailFonts[tmpf].subset(static_cast<bool>(dc.attribute("SUBSET", "0").toInt()));
+ ScFace& face(appPrefs.fontPrefs.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/ui/missing.cpp
===================================================================
--- scribus/ui/missing.cpp (revision 14311)
+++ scribus/ui/missing.cpp (revision 14312)
@@ -323,15 +323,10 @@
missingFontGridLayout->addWidget( useLabel, 1, 1 );
replaceFontCombo = new FontCombo(this);
if (doc != 0)
- {
setCurrentComboItem(replaceFontCombo, doc->itemToolPrefs.textFont);
- replacementFont = doc->itemToolPrefs.textFont;
- }
else
- {
setCurrentComboItem(replaceFontCombo, PrefsManager::instance()->appPrefs.itemToolPrefs.textFont);
- replacementFont = PrefsManager::instance()->appPrefs.itemToolPrefs.textFont;
- }
+ replacementFont = replaceFontCombo->currentText();
missingFontGridLayout->addWidget( replaceFontCombo, 1, 2 );
insteadLabel = new QLabel( tr( "instead" ), this );
missingFontGridLayout->addWidget( insteadLabel, 1, 3 );
Index: scribus/ui/fontcombo.cpp
===================================================================
--- scribus/ui/fontcombo.cpp (revision 14311)
+++ scribus/ui/fontcombo.cpp (revision 14312)
@@ -157,7 +157,18 @@
disconnect(fontStyle, SIGNAL(activated(int)), this, SLOT(styleSelected(int)));
QString curr = fontStyle->currentText();
fontStyle->clear();
- QStringList slist = prefsManager->appPrefs.fontPrefs.AvailFonts.fontMap[fontFamily->itemText(id)];
+ QString fntFamily = fontFamily->itemText(id);
+ QStringList slist, styleList = prefsManager->appPrefs.fontPrefs.AvailFonts.fontMap[fntFamily];
+ for (QStringList::ConstIterator it = styleList.begin(); it != styleList.end(); ++it)
+ {
+ SCFonts::ConstIterator fIt = prefsManager->appPrefs.fontPrefs.AvailFonts.find(fntFamily + " " + *it);
+ if (fIt != prefsManager->appPrefs.fontPrefs.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.fontPrefs.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.fontPrefs.AvailFonts[family + " " + *it3].localForDocument()) || (prefsManager->appPrefs.fontPrefs.AvailFonts[family + " " + *it3].localForDocument().isEmpty()))
- ilist.append(*it3);
+ SCFonts::ConstIterator fIt = prefsManager->appPrefs.fontPrefs.AvailFonts.find(family + " " + *it3);
+ if (fIt != prefsManager->appPrefs.fontPrefs.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.fontPrefs.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.fontPrefs.AvailFonts.fontMap[*it2];
slist.sort();
- QStringList ilist;
- ilist.clear();
for (QStringList::ConstIterator it3 = slist.begin(); it3 != slist.end(); ++it3)
{
if ( prefsManager->appPrefs.fontPrefs.AvailFonts.contains(*it2 + " " + *it3))
{
const ScFace& fon(prefsManager->appPrefs.fontPrefs.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.fontPrefs.AvailFonts.fontMap.find(*it2);
+ if (fmIt == prefsManager->appPrefs.fontPrefs.AvailFonts.fontMap.end())
+ continue;
+ if (fmIt->count() <= 0)
+ continue;
+ QString fullFontName = (*it2) + " " + fmIt->at(0);
+ ScFace fon = prefsManager->appPrefs.fontPrefs.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.fontPrefs.AvailFonts[it2a.value()+" "+prefsManager->appPrefs.fontPrefs.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.fontPrefs.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.fontPrefs.AvailFonts.contains(family + " " + *it3) && (currentDoc->DocName == prefsManager->appPrefs.fontPrefs.AvailFonts[family + " " + *it3].localForDocument() || prefsManager->appPrefs.fontPrefs.AvailFonts[family + " " + *it3].localForDocument().isEmpty()))
- ilist.append(*it3);
+ SCFonts::ConstIterator fIt = prefsManager->appPrefs.fontPrefs.AvailFonts.find(family + " " + *it);
+ if (fIt != prefsManager->appPrefs.fontPrefs.AvailFonts.end())
+ {
+ if (!fIt->usable() || fIt->isReplacement())
+ continue;
+ ilist.append(*it);
+ }
}
fontStyle->addItems(ilist);
}
More information about the scribus-commit
mailing list