Hi all,
the attached patch removes Qt3 bits from generators/dvi/fontpool.* and
shows font information of DVI documents in the properties dialog.
I'd like to add some new values for FontInfo::FontType (and the
corresponding string in descriptionForFontType in propertiesdialog.cpp).
Can we still add new strings?
Regards,
--
Luigi
Index: generators/dvi/generator_dvi.h
===================================================================
--- generators/dvi/generator_dvi.h (revision 1048147)
+++ generators/dvi/generator_dvi.h (working copy)
@@ -36,6 +36,9 @@
// table of contents
const Okular::DocumentSynopsis *generateDocumentSynopsis();
+ // list of fonts
+ Okular::FontInfo::List fontsForPage( int page );
+
bool print( QPrinter &printer );
QVariant metaData( const QString & key, const QVariant & option ) const;
@@ -45,8 +48,9 @@
QImage image( Okular::PixmapRequest * request );
Okular::TextPage* textPage( Okular::Page *page );
- private:
+ private:
double m_resolution;
+ bool m_fontExtracted;
Okular::DocumentInfo *m_docInfo;
Okular::DocumentSynopsis *m_docSynopsis;
Index: generators/dvi/fontpool.cpp
===================================================================
--- generators/dvi/fontpool.cpp (revision 1048147)
+++ generators/dvi/fontpool.cpp (working copy)
@@ -54,7 +54,6 @@
useFontHints = useFontHinting;
CMperDVIunit = 0;
extraSearchPath.clear();
- fontList.setAutoDelete(true);
#ifdef HAVE_FREETYPE
// Initialize the Freetype Library
@@ -109,6 +108,12 @@
#endif
// need to manually clear the fonts _before_ freetype gets unloaded
+ QMutableListIterator<TeXFontDefinition*> i(fontList);
+ while (i.hasNext()) {
+ TeXFontDefinition* f = i.next();
+ i.remove();
+ delete f;
+ }
fontList.clear();
#ifdef HAVE_FREETYPE
@@ -123,10 +128,10 @@
// Check if glyphs need to be cleared
if (_useFontHints != useFontHints) {
double displayResolution = displayResolution_in_dpi;
- TeXFontDefinition *fontp = fontList.first();
- while(fontp != 0 ) {
+ QList<TeXFontDefinition*>::iterator it_fontp = fontList.begin();
+ for (; it_fontp != fontList.end(); ++it_fontp) {
+ TeXFontDefinition *fontp = *it_fontp;
fontp->setDisplayResolution(displayResolution * fontp->enlargement);
- fontp=fontList.next();
}
}
@@ -139,21 +144,21 @@
// Reuse font if possible: check if a font with that name and
// natural resolution is already in the fontpool, and use that, if
// possible.
- TeXFontDefinition *fontp = fontList.first();
- while( fontp != 0 ) {
+ QList<TeXFontDefinition*>::iterator it_fontp = fontList.begin();
+ for (; it_fontp != fontList.end(); ++it_fontp) {
+ TeXFontDefinition *fontp = *it_fontp;
if ((fontname == fontp->fontname) && ( (int)(enlargement*1000.0+0.5)) == (int)(fontp->enlargement*1000.0+0.5)) {
// if font is already in the list
fontp->mark_as_used();
return fontp;
}
- fontp=fontList.next();
}
// If font doesn't exist yet, we have to generate a new font.
double displayResolution = displayResolution_in_dpi;
- fontp = new TeXFontDefinition(fontname, displayResolution*enlargement, checksum, scale, this, enlargement);
+ TeXFontDefinition *fontp = new TeXFontDefinition(fontname, displayResolution*enlargement, checksum, scale, this, enlargement);
if (fontp == 0) {
kError(kvs::dvi) << "Could not allocate memory for a font structure";
exit(0);
@@ -191,8 +196,9 @@
.arg(i18n("Encoding"))
.arg(i18n("Comment")) );
- TeXFontDefinition *fontp = fontList.first();
- while ( fontp != 0 ) {
+ QList<TeXFontDefinition*>::const_iterator cit_fontp = fontList.constBegin();
+ for (; cit_fontp != fontList.constEnd(); ++cit_fontp) {
+ TeXFontDefinition *fontp = *cit_fontp;
QString errMsg, encoding;
if (!(fontp->flags & TeXFontDefinition::FONT_VIRTUAL)) {
@@ -215,7 +221,6 @@
.arg(errMsg);
#endif
- fontp=fontList.next();
}
tmp.sort();
@@ -233,11 +238,11 @@
#endif
// Is there a font whose name we did not try to find out yet?
- TeXFontDefinition *fontp = fontList.first();
- while( fontp != 0 ) {
+ QList<TeXFontDefinition*>::const_iterator cit_fontp = fontList.constBegin();
+ for (; cit_fontp != fontList.constEnd(); ++cit_fontp) {
+ TeXFontDefinition *fontp = *cit_fontp;
if ( !fontp->isLocated() )
return false;
- fontp=fontList.next();
}
#ifdef DEBUG_FONTPOOL
@@ -306,8 +311,9 @@
// Names of fonts that shall be located
quint16 numFontsInJob = 0;
- TeXFontDefinition *fontp = fontList.first();
- while ( fontp != 0 ) {
+ QList<TeXFontDefinition*>::const_iterator cit_fontp = fontList.constBegin();
+ for (; cit_fontp != fontList.constEnd(); ++cit_fontp) {
+ TeXFontDefinition *fontp = *cit_fontp;
if (!fontp->isLocated()) {
numFontsInJob++;
@@ -325,7 +331,6 @@
<< QString("%1.1200pk").arg(fontp->fontname);
}
}
- fontp=fontList.next();
}
if (numFontsInJob == 0)
@@ -396,8 +401,10 @@
QString(kpsewhich_.readAll()).split('\n', QString::SkipEmptyParts);
// Now associate the file names found with the fonts
- fontp=fontList.first();
- while ( fontp != 0 ) {
+ QList<TeXFontDefinition*>::iterator it_fontp = fontList.begin();
+ for (; it_fontp != fontList.end(); ++it_fontp) {
+ TeXFontDefinition *fontp = *it_fontp;
+
if (fontp->filename.isEmpty() == true) {
QStringList matchingFiles;
#ifdef HAVE_FREETYPE
@@ -421,12 +428,11 @@
// Constructing a virtual font will most likely insert other
// fonts into the fontList. After that, fontList.next() will
// no longer work. It is therefore safer to start over.
- fontp=fontList.first();
+ it_fontp=fontList.begin();
continue;
}
}
} // of if (fontp->filename.isEmpty() == true)
- fontp = fontList.next();
}
}
@@ -442,10 +448,10 @@
CMperDVIunit = _CMperDVI;
- TeXFontDefinition *fontp = fontList.first();
- while(fontp != 0 ) {
+ QList<TeXFontDefinition*>::iterator it_fontp = fontList.begin();
+ for (; it_fontp != fontList.end(); ++it_fontp) {
+ TeXFontDefinition *fontp = *it_fontp;
fontp->setDisplayResolution(displayResolution_in_dpi * fontp->enlargement);
- fontp=fontList.next();
}
}
@@ -470,10 +476,10 @@
displayResolution_in_dpi = _displayResolution_in_dpi;
double displayResolution = displayResolution_in_dpi;
- TeXFontDefinition *fontp = fontList.first();
- while(fontp != 0 ) {
+ QList<TeXFontDefinition*>::iterator it_fontp = fontList.begin();
+ for (; it_fontp != fontList.end(); ++it_fontp) {
+ TeXFontDefinition *fontp = *it_fontp;
fontp->setDisplayResolution(displayResolution * fontp->enlargement);
- fontp=fontList.next();
}
// Do something that causes re-rendering of the dvi-window
@@ -485,10 +491,10 @@
void fontPool::markFontsAsLocated()
{
- TeXFontDefinition *fontp=fontList.first();
- while ( fontp != 0 ) {
+ QList<TeXFontDefinition*>::iterator it_fontp = fontList.begin();
+ for (; it_fontp != fontList.end(); ++it_fontp) {
+ TeXFontDefinition *fontp = *it_fontp;
fontp->markAsLocated();
- fontp = fontList.next();
}
}
@@ -500,10 +506,10 @@
kDebug(kvs::dvi) << "fontPool::mark_fonts_as_unused() called";
#endif
- TeXFontDefinition *fontp = fontList.first();
- while ( fontp != 0 ) {
+ QList<TeXFontDefinition*>::iterator it_fontp = fontList.begin();
+ for (; it_fontp != fontList.end(); ++it_fontp) {
+ TeXFontDefinition *fontp = *it_fontp;
fontp->flags &= ~TeXFontDefinition::FONT_IN_USE;
- fontp=fontList.next();
}
}
@@ -514,13 +520,17 @@
kDebug(kvs::dvi) << "Release_fonts";
#endif
- TeXFontDefinition *fontp = fontList.first();
- while(fontp != 0) {
+ QList<TeXFontDefinition*>::iterator it_fontp = fontList.begin();
+ while (it_fontp != fontList.end()) {
+ TeXFontDefinition *fontp = *it_fontp;
+
if ((fontp->flags & TeXFontDefinition::FONT_IN_USE) != TeXFontDefinition::FONT_IN_USE) {
- fontList.removeRef(fontp);
- fontp = fontList.first();
+
+ it_fontp = fontList.erase(it_fontp);
+ delete (*it_fontp);
+ it_fontp = fontList.begin();
} else
- fontp = fontList.next();
+ ++it_fontp;
}
}
Index: generators/dvi/fontpool.h
===================================================================
--- generators/dvi/fontpool.h (revision 1048147)
+++ generators/dvi/fontpool.h (working copy)
@@ -12,7 +12,7 @@
#include "fontprogress.h"
#include "TeXFontDefinition.h"
-#include <Q3PtrList>
+#include <QList>
#include <QObject>
#include <QProcess>
@@ -83,7 +83,7 @@
QString status();
// This is the list which actually holds pointers to the fonts
- Q3PtrList<TeXFontDefinition> fontList;
+ QList<TeXFontDefinition*> fontList;
// This method marks all fonts in the fontpool as "not in use". The
// fonts are, however, not removed from memory until the method
Index: generators/dvi/generator_dvi.cpp
===================================================================
--- generators/dvi/generator_dvi.cpp (revision 1048147)
+++ generators/dvi/generator_dvi.cpp (working copy)
@@ -62,10 +62,11 @@
OKULAR_EXPORT_PLUGIN( DviGenerator, createAboutData() )
DviGenerator::DviGenerator( QObject *parent, const QVariantList &args ) : Okular::Generator( parent, args ),
- m_docInfo( 0 ), m_docSynopsis( 0 ), m_dviRenderer( 0 )
+ m_fontExtracted( false ), m_docInfo( 0 ), m_docSynopsis( 0 ), m_dviRenderer( 0 )
{
setFeature( Threaded );
setFeature( TextExtraction );
+ setFeature( FontInfo );
setFeature( PrintPostscript );
if ( Okular::FilePrinter::ps2pdfAvailable() )
setFeature( PrintToFile );
@@ -402,6 +403,57 @@
return m_docSynopsis;
}
+Okular::FontInfo::List DviGenerator::fontsForPage( int page )
+{
+ Q_UNUSED( page );
+
+ Okular::FontInfo::List list;
+
+ // the list of the fonts is extracted once
+ if ( m_fontExtracted )
+ return list;
+
+ if ( m_dviRenderer && m_dviRenderer->dviFile &&
+ m_dviRenderer->dviFile->font_pool )
+ {
+ QList<TeXFontDefinition*> fonts = m_dviRenderer->dviFile->font_pool->fontList;
+
+ foreach (const TeXFontDefinition* font, fonts)
+ {
+ Okular::FontInfo of;
+ QString name;
+ int zoom = (int)(font->enlargement*100 + 0.5);
+ if ( font->getFullFontName().isEmpty() )
+ {
+ name = QString( "%1, %2%" )
+ .arg( font->fontname )
+ .arg( zoom );
+ }
+ else
+ {
+ name = QString( "%1 (%2), %3%" )
+ .arg( font->fontname )
+ .arg( font->getFullFontName() )
+ .arg( zoom );
+ }
+ of.setName( name );
+
+ of.setFile( font->filename );
+
+ // DVI has not the concept of "font embedding"
+ of.setEmbedType( Okular::FontInfo::NotEmbedded );
+ of.setCanBeExtracted( false );
+
+ list.append( of );
+ }
+
+ m_fontExtracted = true;
+
+ }
+
+ return list;
+}
+
void DviGenerator::loadPages( QVector< Okular::Page * > &pagesVector )
{
QSize pageRequiredSize;
_______________________________________________
Okular-devel mailing list
Okular-devel@kde.org
https://mail.kde.org/mailman/listinfo/okular-devel