2 * KFontInst - KDE Font Installer
4 * Copyright 2003-2007 Craig Drummond <craig@kde.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; see the file COPYING. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
24 #include "FontThumbnail.h"
25 #include "KfiConstants.h"
27 #include <QtGui/QImage>
28 #include <QtGui/QPixmap>
29 #include <QtGui/QApplication>
30 #include <QtGui/QPalette>
31 #include <QtCore/QFile>
32 #include <KDE/KGlobalSettings>
33 #include <KDE/KLocale>
36 #include <KDE/KTempDir>
37 #include <KDE/KMimeType>
38 #include <KDE/KStandardDirs>
41 #define KFI_DBUG kDebug(7115)
45 KDE_EXPORT ThumbCreator
*new_creator()
47 return new KFI::CFontThumbnail
;
54 CFontThumbnail::CFontThumbnail()
56 KGlobal::locale()->insertCatalog(KFI_CATALOGUE
);
59 bool CFontThumbnail::create(const QString
&path
, int width
, int height
, QImage
&img
)
62 QString
realPath(path
);
63 KTempDir
*tempDir
= 0;
65 CFcEngine::setTextCol(QApplication::palette().color(QPalette::Text
));
67 KFI_DBUG
<< "Create font thumbnail for:" << path
<< endl
;
69 // Is this a fonts/package file? If so, extract 1 scalable font...
70 if(Misc::isPackage(path
) || "application/zip"==KMimeType::findByFileContent(path
)->name())
74 if(zip
.open(QIODevice::ReadOnly
))
76 const KArchiveDirectory
*zipDir
=zip
.directory();
80 QStringList
fonts(zipDir
->entries());
84 QStringList::ConstIterator
it(fonts
.begin()),
89 const KArchiveEntry
*entry
=zipDir
->entry(*it
);
91 if(entry
&& entry
->isFile())
94 tempDir
=new KTempDir(KStandardDirs::locateLocal("tmp", KFI_TMP_DIR_PREFIX
));
95 tempDir
->setAutoRemove(true);
97 ((KArchiveFile
*)entry
)->copyTo(tempDir
->name());
99 QString
mime(KMimeType::findByPath(tempDir
->name()+entry
->name())->name());
101 if(mime
=="application/x-font-ttf" || mime
=="application/x-font-otf" ||
102 mime
=="application/x-font-type1")
104 realPath
=tempDir
->name()+entry
->name();
108 ::unlink(QFile::encodeName(tempDir
->name()+entry
->name()).data());
116 if(itsEngine
.draw(KUrl(realPath
), width
, height
, pix
, 0, true))
118 img
=pix
.toImage().convertToFormat(QImage::Format_ARGB32
);
127 ThumbCreator::Flags
CFontThumbnail::flags() const