add more spacing
[personal-kdebase.git] / workspace / kcontrol / kfontinst / thumbnail / FontThumbnail.cpp
blobda3c2f575b812f93f6ead541d0e016fae52cef53
1 /*
2 * KFontInst - KDE Font Installer
4 * Copyright 2003-2007 Craig Drummond <craig@kde.org>
6 * ----
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"
26 #include "FcEngine.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>
34 #include <KDE/KUrl>
35 #include <KDE/KZip>
36 #include <KDE/KTempDir>
37 #include <KDE/KMimeType>
38 #include <KDE/KStandardDirs>
39 #include <KDE/KDebug>
41 #define KFI_DBUG kDebug(7115)
43 extern "C"
45 KDE_EXPORT ThumbCreator *new_creator()
47 return new KFI::CFontThumbnail;
51 namespace KFI
54 CFontThumbnail::CFontThumbnail()
56 KGlobal::locale()->insertCatalog(KFI_CATALOGUE);
59 bool CFontThumbnail::create(const QString &path, int width, int height, QImage &img)
61 QPixmap pix;
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())
72 KZip zip(path);
74 if(zip.open(QIODevice::ReadOnly))
76 const KArchiveDirectory *zipDir=zip.directory();
78 if(zipDir)
80 QStringList fonts(zipDir->entries());
82 if(fonts.count())
84 QStringList::ConstIterator it(fonts.begin()),
85 end(fonts.end());
87 for(; it!=end; ++it)
89 const KArchiveEntry *entry=zipDir->entry(*it);
91 if(entry && entry->isFile())
93 delete tempDir;
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();
105 break;
107 else
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);
119 delete tempDir;
120 return true;
123 delete tempDir;
124 return false;
127 ThumbCreator::Flags CFontThumbnail::flags() const
129 return None;