View Issue Details

IDProjectCategoryView StatusLast Update
0006543ScribusFontspublic2008-01-16 20:38
Reporterbrunod Assigned Tosubik  
PrioritynormalSeverityfeatureReproducibilityhave not tried
Status closedResolutionfixed 
PlatformX86 32bitOSUbuntu (latest)OS Version7.10 32 bit
Product Version1.3.5svn 
Fixed in Version1.3.5svn 
Summary0006543: trouble in extra/font preview
Description1) Numbers in font preview starts at 0000002. There is no number one.
2) But the preview is not the preview of the font choosen, it's the preview of the previous one in the list.
I checked this using Scribus 1.3.4 & 1.3.5svn at the same time to be sure.

NB : i suppose i have a bad police in first position but this shouldn't appear anyway.
Thanks
TagsNo tags attached.
Patch

Activities

cbradney

2007-12-02 23:46

administrator   ~0018134

I think your 2) relates to your 1)

brunod

2007-12-05 22:21

reporter   ~0018177

I removed the first police in the list and it still the same. Not so sure about the bad police.

subik

2007-12-06 08:34

manager   ~0018185

Bruno, I suppose you're building 1.3.5svn from sources, right? Are you able to recompile the scribus with a special debug-included file I'll send you?

brunod

2007-12-06 11:06

reporter   ~0018188

All right if you explain me step by step how to because i'm not used to compile. Scribus made me make that step forward ! If file is not too big, you can send it to delsupexhe(at)gmail(dot)com

2007-12-07 09:22

 

fontpreview.cpp (8,551 bytes)   
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/

#include <QStandardItemModel>
#include <QSortFilterProxyModel>
#include <QHeaderView>

#include "fontpreview.h"
#include "scribus.h"
#include "prefsfile.h"
#include "commonstrings.h"
#include "prefsmanager.h"
#include "selection.h"
#include "sampleitem.h"
#include "util_icon.h"


#include <QtDebug>
void d(QString t)
{
	qDebug() << "FontPreview: " << t;
}


FontPreview::FontPreview(QString fontName, QWidget* parent, ScribusDoc* doc)
	: QDialog(parent, 0)
{
	setupUi(this);
	setModal(true);
	setWindowIcon(loadIcon("AppIcon.png"));
	m_Doc=doc;

	sampleItem = new SampleItem(m_Doc);

	languageChange();

	resetDisplayButton->setIcon(QIcon(loadIcon("u_undo16.png")));

	ttfFont = loadIcon("font_truetype16.png");
	otfFont = loadIcon("font_otf16.png");
	psFont = loadIcon("font_type1_16.png");
	okIcon = loadIcon("ok.png");

	fontModel = new QStandardItemModel(0, 5, this);
	fontModel->setHeaderData(0, Qt::Horizontal, tr("Font Name"), Qt::DisplayRole);
	fontModel->setHeaderData(1, Qt::Horizontal, tr("Doc"), Qt::DisplayRole);
	fontModel->setHeaderData(2, Qt::Horizontal, tr("Type"), Qt::DisplayRole);
	fontModel->setHeaderData(3, Qt::Horizontal, tr("Subset"), Qt::DisplayRole);
	fontModel->setHeaderData(4, Qt::Horizontal, tr("Access"), Qt::DisplayRole);

	QList<QStandardItem *> fontRow;
	
	d(QString("fonts installed = %1").arg(PrefsManager::instance()->appPrefs.AvailFonts.count()));
	
	for (SCFontsIterator fontIter(PrefsManager::instance()->appPrefs.AvailFonts);
			fontIter.hasNext(); fontIter.next())
	{
		d(QString("font name = %1").arg(fontIter.current().scName()));
		if (!fontIter.current().usable())
		{
			d("unusable!");
			continue;
		}

		fontRow.clear();
		QStandardItem * col0 = new QStandardItem();
		QStandardItem * col1 = new QStandardItem();
		QStandardItem * col2 = new QStandardItem();
		QStandardItem * col3 = new QStandardItem();
		QStandardItem * col4 = new QStandardItem();

		col0->setEditable(false);
		col1->setEditable(false);
		col2->setEditable(false);
		col3->setEditable(false);
		col4->setEditable(false);

		col0->setText(fontIter.current().scName());

		if (m_Doc->UsedFonts.contains(fontIter.current().scName()))
			col1->setIcon(okIcon);

		ScFace::FontType type = fontIter.current().type();
		if (type == ScFace::OTF)
		{
			col2->setIcon(otfFont);
			col2->setText("OpenType");
		}
		else
			if (fontIter.current().subset())
				col3->setIcon(okIcon);

		if (type == ScFace::TYPE1) // type1
		{
			col2->setIcon(psFont);
			col2->setText("Type1");
		}

		if (type == ScFace::TTF)
		{
			col2->setIcon(ttfFont);
			col2->setText("TrueType");
		}

		QFileInfo fi(fontIter.current().fontFilePath());
		fi.absoluteFilePath().contains(QDir::homePath()) ?
				col4->setText(tr("User", "font preview")):
				col4->setText(tr("System", "font preview"));

		fontRow << col0 << col1 << col2 << col3 << col4;
		fontModel->appendRow(fontRow);
		d("appended");
	}
// 	fontList->setModel(fontModel); // displaying is handled by proxyModel

	proxyModel = new QSortFilterProxyModel();
	proxyModel->setDynamicSortFilter(true);
	proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
	proxyModel->setSourceModel(fontModel);
	proxyModel->setFilterKeyColumn(0);
	proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
	fontList->setModel(proxyModel);
	
	d(QString("Proxymodel count = %1").arg(proxyModel->rowCount()));
	d(QString("Fontmodel count = %1").arg(fontModel->rowCount()));
	d("checking for hidden rows...");
	for (int i = 0; i < fontList->model()->rowCount(); ++i)
		if (fontList->isRowHidden(i))
			d(QString("Row is hidden = %1").arg(i+1));
	d("checking for hidden rows... done.");

	// scribus config
	defaultStr = tr("Woven silk pyjamas exchanged for blue quartz", "font preview");
	prefs = PrefsManager::instance()->prefsFile->getPluginContext("fontpreview");

	proxyModel->sort(prefs->getUInt("sortColumn", 0));

	xsize = prefs->getUInt("xsize", 640);
	ysize = prefs->getUInt("ysize", 480);
	sizeSpin->setValue(prefs->getUInt("fontSize", 18));
	QString ph = prefs->get("phrase", defaultStr);
	displayEdit->setText(ph);
	displayButton_clicked();
	resize(QSize(xsize, ysize).expandedTo(minimumSizeHint()));

	connect(displayButton, SIGNAL(clicked()), this, SLOT(displayButton_clicked()));
	connect(searchEdit, SIGNAL(textChanged(QString)), this, SLOT(searchEdit_textChanged(QString)));
	connect(searchButton, SIGNAL(clicked()), this, SLOT(searchButton_clicked()));
	connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelButton_clicked()));
	connect(resetDisplayButton, SIGNAL(clicked()), this, SLOT(resetDisplayButton_clicked()));
	connect(sizeSpin, SIGNAL(valueChanged(int)), this, SLOT(sizeSpin_valueChanged(int)));
	connect(fontList->selectionModel(), SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)),
			this, SLOT(fontList_currentChanged(const QModelIndex &, const QModelIndex &)));

	QString searchName;
	if (!fontName.isEmpty())
		searchName = fontName;
	else
	{
		Q_ASSERT(m_Doc!=0);
		if (m_Doc->m_Selection->count() != 0)
			searchName = m_Doc->currentStyle.charStyle().font().scName();
		else
			searchName = PrefsManager::instance()->appPrefs.toolSettings.defFont;
	}
	QList<QStandardItem *> found = fontModel->findItems(searchName);
	if (found.size() > 0)
	{
		fontList->scrollTo(found.at(0)->index(), QAbstractItemView::PositionAtCenter);
		fontList->selectRow(found.at(0)->index().row());
	}
	fontList->resizeColumnsToContents();
}

FontPreview::~FontPreview()
{
	prefs->set("sortColumn", fontList->horizontalHeader()->sortIndicatorSection());
	prefs->set("xsize", width());
	prefs->set("ysize", height());
	prefs->set("fontSize", sizeSpin->value());
	prefs->set("phrase", displayEdit->text());
	sampleItem->cleanupTemporary(); // just to be sure
}

void FontPreview::languageChange()
{
	cancelButton->setToolTip(tr("Leave preview", "font preview"));
	searchEdit->setToolTip("<qt>" + tr("Typing the text here provides quick searching in the font names. Searching is case insensitive. You can provide a common wild cards (*, ?, [...]) in your phrase. Examples: t* will list all fonts starting with t or T. *bold* will list all fonts with word bold, bolder etc. in the name.") + "</qt>");
	searchButton->setToolTip(tr("Start searching"));
	sizeSpin->setToolTip(tr("Size of the selected font"));
}

bool FontPreview::allowSample()
{
	if (fontModel->rowCount() != 0)
		return true;
	fontPreview->setText("No font selected");
	return false;
}

void FontPreview::paintSample()
{
	if (!allowSample())
		return;

	QString fontName(getCurrentFont());
	if (fontName.isNull())
		return;

	sampleItem->setFontSize(sizeSpin->value() * 10, true);
	sampleItem->setFont(fontName);
	QPixmap pixmap = sampleItem->getSample(fontPreview->maximumWidth(),
										   fontPreview->maximumHeight());
	fontPreview->clear();
	if (!pixmap.isNull())
		fontPreview->setPixmap(pixmap);
}

void FontPreview::searchEdit_textChanged(const QString &/*s*/)
{
	searchButton_clicked();
}

void FontPreview::searchButton_clicked()
{
	disconnect(fontList->selectionModel(), SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)),
			   this, SLOT(fontList_currentChanged(const QModelIndex &, const QModelIndex &)));
	QString s(searchEdit->text());
	if (s.isEmpty())
		fontList->setModel(fontModel);
	else
	{
		QRegExp regExp(QString("*%1*").arg(s), Qt::CaseInsensitive, QRegExp::Wildcard);
		proxyModel->setFilterRegExp(regExp);
		fontList->setModel(proxyModel);
	}
	fontList->resizeColumnsToContents();
	connect(fontList->selectionModel(), SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)),
			this, SLOT(fontList_currentChanged(const QModelIndex &, const QModelIndex &)));
}

QString FontPreview::getCurrentFont()
{
	QModelIndex ix(fontList->currentIndex());
	if (!ix.isValid())
		return QString();
	return fontModel->item(ix.row(), 0)->text();
}

void FontPreview::displayButton_clicked()
{
	sampleItem->setText(displayEdit->text());
	paintSample();
}

void FontPreview::cancelButton_clicked()
{
	reject();
}

void FontPreview::resetDisplayButton_clicked()
{
	displayEdit->setText(defaultStr);
	displayButton_clicked();
}

void FontPreview::sizeSpin_valueChanged( int )
{
	paintSample();
}

void FontPreview::fontList_currentChanged(const QModelIndex &, const QModelIndex &)
{
	paintSample();
}
fontpreview.cpp (8,551 bytes)   

subik

2007-12-07 09:26

manager   ~0018217

Bruno, at first - sorry for delay.

So. Download fontpreview.cpp file (attached above), please. Save it in your Scribus source code tree: SCRIBUSDIR/scribus/plugins/fontpreview

Then recompile scribus and don't forget to make install.

run scribus from console/terminal and look for its output. The show me this output ;)

Hint:
./scribus 2>~/fontpreview.log

saves all required text into new file.

2007-12-07 18:26

 

nouveau dossier 1.tar.gz (261,857 bytes)

brunod

2007-12-07 18:28

reporter   ~0018219

Last edited: 2007-12-08 08:55

Done !
It's in nouveau dossier 1.tar.gz, included two screen copies of the font list.
Look if i did do well, otherwise let me know and i would be pleased to retry.
(I could not create the log file, so i cut and paste the content of the terminal into it).
Bruno

subik

2007-12-08 20:52

manager   ~0018233

heh, I've installed the latest ubuntu into virtalbox and I see completelly different behaviour in th font prevuew dialog. Maybe is their Qt4 lib patched in strange way...

But -- what you see in File/Preferences/Fonts table? Are the fonts correct there?

brunod

2007-12-08 21:27

reporter   ~0018234

Last edited: 2007-12-08 21:37

Hard to say : no numbers, no font preview either...
But it doesn't start with the same one : Aachen is in number 2; it doesn't end with the same either even if i now have activated all the fonts (one by one, it would be nice to be able to select groups in the list) and resorted them. Ii seems the key for sorting is not the same, even if i click to sort by name. Preview sorts according alphabetic order, no matter CAPS or not; preference sort by alphabetic order but all CAPS first, then all minus (don't know the name in english, the non-CAPS i mean).
But i think i have more fonts here in File/Preferences/Fonts table than in extra/font preview
(i won't count because it's about 2700 according to extra/font preview).

subik

2007-12-18 12:23

manager   ~0018343

I've rewrote the font listing backend. Can you test it again with the latest svn, please?

brunod

2007-12-18 18:19

reporter   ~0018348

Yes, It seems perfect now !
Thanks !

brunod

2007-12-18 19:45

reporter   ~0018349

It still seems the key for sorting is not the same for Preview (alphabetic order), and preference sort (still CAPS first). But it's a minor problem. The rest ist solved for me.

christoph_s

2007-12-18 22:33

administrator   ~0018351

subik: seems to be fixed.

christoph_s

2008-01-16 20:38

administrator   ~0018609

Tested, fixed. Thanks.

Issue History

Date Modified Username Field Change
2007-12-01 12:02 brunod New Issue
2007-12-02 23:46 cbradney Note Added: 0018134
2007-12-02 23:46 cbradney Status new => assigned
2007-12-02 23:46 cbradney Assigned To => subik
2007-12-05 22:21 brunod Note Added: 0018177
2007-12-06 08:34 subik Note Added: 0018185
2007-12-06 11:06 brunod Note Added: 0018188
2007-12-07 09:22 subik File Added: fontpreview.cpp
2007-12-07 09:26 subik Note Added: 0018217
2007-12-07 18:26 brunod File Added: nouveau dossier 1.tar.gz
2007-12-07 18:28 brunod Note Added: 0018219
2007-12-08 08:54 brunod Note Edited: 0018219
2007-12-08 08:55 brunod Note Edited: 0018219
2007-12-08 20:52 subik Note Added: 0018233
2007-12-08 21:27 brunod Note Added: 0018234
2007-12-08 21:37 brunod Note Edited: 0018234
2007-12-18 12:23 subik Note Added: 0018343
2007-12-18 18:19 brunod Note Added: 0018348
2007-12-18 19:45 brunod Note Added: 0018349
2007-12-18 22:33 christoph_s Note Added: 0018351
2008-01-16 14:27 subik Status assigned => resolved
2008-01-16 14:27 subik Fixed in Version => 1.3.5svn
2008-01-16 14:27 subik Resolution open => fixed
2008-01-16 20:38 christoph_s Status resolved => closed
2008-01-16 20:38 christoph_s Note Added: 0018609