diff --git a/CMakeLists.txt b/CMakeLists.txt index a2476784..c27416f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -248,6 +248,14 @@ set_package_properties(LibSpectre PROPERTIES PURPOSE "Postscript metadata extraction" ) +kde4_optional_find_package(Freetype) +set_package_properties(Freetype PROPERTIES + DESCRIPTION "Freely available software library to render fonts" + URL "https://www.freetype.org" + TYPE RECOMMENDED + PURPOSE "Fonts metadata extraction" +) + kde4_optional_find_package(OpenSSL) set_package_properties(OpenSSL PROPERTIES DESCRIPTION "Robust, commercial-grade, full-featured toolkit for general-purpose cryptography and secure communication" diff --git a/kio/kio/kfilemetainfo.cpp b/kio/kio/kfilemetainfo.cpp index a43a6fb7..e381b48e 100644 --- a/kio/kio/kfilemetainfo.cpp +++ b/kio/kio/kfilemetainfo.cpp @@ -298,6 +298,7 @@ QString KFileMetaInfo::name(const QString& key) { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#isoSpeedRatings", i18nc("@label EXIF", "ISO Speed Ratings") }, { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#meteringMode", i18nc("@label EXIF", "Metering Mode") }, { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#whiteBalance", i18nc("@label EXIF", "White Balance") }, + { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fontFamily", i18nc("@label", "Family") }, // to be used by plugins { "http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#Email", i18nc("@label", "Creator E-Mail") }, { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#hashValue", i18nc("@label", "Hash Value") }, @@ -327,7 +328,6 @@ QString KFileMetaInfo::name(const QString& key) { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#audioBitDepth", i18nc("@label", "Audio Bit Depth") }, { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#videoBitDepth", i18nc("@label", "Video Bit Depth") }, { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#aspectRatio", i18nc("@label", "Aspect Ratio") }, - { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fontFamily", i18nc("@label", "Family") }, { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#foundry", i18nc("@label", "Foundry") }, }; diff --git a/kio/metadata/CMakeLists.txt b/kio/metadata/CMakeLists.txt index f8f9b0bb..a5298f04 100644 --- a/kio/metadata/CMakeLists.txt +++ b/kio/metadata/CMakeLists.txt @@ -125,3 +125,25 @@ if (LIBSPECTRE_FOUND) DESTINATION ${KDE4_SERVICES_INSTALL_DIR} ) endif() + +if (FREETYPE_FOUND) + include_directories(${FREETYPE_INCLUDE_DIRS}) + + set(kfilemetadata_freetype_SRCS kfilemetadata_freetype.cpp) + + kde4_add_plugin(kfilemetadata_freetype ${kfilemetadata_freetype_SRCS}) + target_link_libraries(kfilemetadata_freetype + ${KDE4_KIO_LIBS} + ${FREETYPE_LIBRARIES} + ) + + install( + TARGETS kfilemetadata_freetype + DESTINATION ${KDE4_PLUGIN_INSTALL_DIR} + ) + + install( + FILES kfilemetadata_freetype.desktop + DESTINATION ${KDE4_SERVICES_INSTALL_DIR} + ) +endif() diff --git a/kio/metadata/kfilemetadata_freetype.cpp b/kio/metadata/kfilemetadata_freetype.cpp new file mode 100644 index 00000000..1d6df6b1 --- /dev/null +++ b/kio/metadata/kfilemetadata_freetype.cpp @@ -0,0 +1,105 @@ +/* This file is part of the KDE libraries + Copyright (C) 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kfilemetadata_freetype.h" +#include "kpluginfactory.h" +#include "kdebug.h" + +#include +#include FT_FREETYPE_H +#include FT_TYPE1_TABLES_H + +KFileMetaDataFreetypePlugin::KFileMetaDataFreetypePlugin(QObject* parent, const QVariantList &args) + : KFileMetaDataPlugin(parent) +{ + Q_UNUSED(args); +} + +KFileMetaDataFreetypePlugin::~KFileMetaDataFreetypePlugin() +{ +} + +QStringList KFileMetaDataFreetypePlugin::keys() const +{ + static const QStringList result = QStringList() + << QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fontFamily") + << QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#copyright"); + return result; +} + +QStringList KFileMetaDataFreetypePlugin::mimeTypes() const +{ + static const QStringList result = QStringList() + << QString::fromLatin1("font/ttf") + << QString::fromLatin1("application/x-font-ttf") + << QString::fromLatin1("application/x-font-type1") + << QString::fromLatin1("font/otf") + << QString::fromLatin1("application/x-font-otf") + << QString::fromLatin1("application/x-font-afm") + << QString::fromLatin1("application/x-font-ttx") + << QString::fromLatin1("font/woff"); + return result; +} + +QList KFileMetaDataFreetypePlugin::metaData(const KUrl &url, const KFileMetaInfo::WhatFlags flags) +{ + Q_UNUSED(flags); + QList result; + const QByteArray urlpath = url.toLocalFile().toLocal8Bit(); + FT_Library ftlibrary; + FT_Init_FreeType(&ftlibrary); + if (!ftlibrary) { + kWarning() << "Could not initialize"; + return result; + } + FT_Face ftface; + if (FT_New_Face(ftlibrary, urlpath.constData(), 0, &ftface) != 0) { + kWarning() << "Could not open" << urlpath; + FT_Done_FreeType(ftlibrary); + return result; + } + const QString ftfamily = QString::fromUtf8(ftface->family_name); + if (!ftfamily.isEmpty()) { + result.append( + KFileMetaInfoItem( + QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fontFamily"), + ftfamily + ) + ); + } + PS_FontInfoRec ftfontinfo; + if (FT_Get_PS_Font_Info(ftface, &ftfontinfo) == 0) { + const QString ftnotice = QString::fromUtf8(ftfontinfo.notice); + if (!ftnotice.isEmpty()) { + result.append( + KFileMetaInfoItem( + QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#copyright"), + ftnotice + ) + ); + } + } + FT_Done_Face(ftface); + FT_Done_FreeType(ftlibrary); + return result; +} + +K_PLUGIN_FACTORY(KFileMetaDataFreetypePluginFactory, registerPlugin();) +K_EXPORT_PLUGIN(KFileMetaDataFreetypePluginFactory("kfilemetadata_freetype")) + +#include "moc_kfilemetadata_freetype.cpp" diff --git a/kio/metadata/kfilemetadata_freetype.desktop b/kio/metadata/kfilemetadata_freetype.desktop new file mode 100644 index 00000000..defe6eb0 --- /dev/null +++ b/kio/metadata/kfilemetadata_freetype.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Type=Service +Name=KFileMetaDataFreetypePlugin +GenericName=Freetype +Comment=Extracts metadata from fonts +X-KDE-Library=kfilemetadata_freetype +X-KDE-ServiceTypes=KFileMetaData/Plugin +InitialPreference=1 diff --git a/kio/metadata/kfilemetadata_freetype.h b/kio/metadata/kfilemetadata_freetype.h new file mode 100644 index 00000000..98cd53b4 --- /dev/null +++ b/kio/metadata/kfilemetadata_freetype.h @@ -0,0 +1,37 @@ +/* This file is part of the KDE libraries + Copyright (C) 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KFILEMETADATA_FREETYPE_H +#define KFILEMETADATA_FREETYPE_H + +#include "kfilemetadata.h" + +class KFileMetaDataFreetypePlugin : public KFileMetaDataPlugin +{ + Q_OBJECT +public: + KFileMetaDataFreetypePlugin(QObject* parent, const QVariantList &args); + ~KFileMetaDataFreetypePlugin(); + + QStringList keys() const final; + QStringList mimeTypes() const final; + + QList metaData(const KUrl &url, const KFileMetaInfo::WhatFlags flags) final; +}; + +#endif // KFILEMETADATA_FREETYPE_H