"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/fontplugin.cpp" between
krename-4.0.9.tar.gz and krename-4.90.90.tar.gz

About: KRename is a batch file-renamer (KDE).

fontplugin.cpp  (krename-4.0.9):fontplugin.cpp  (krename-4.90.90)
skipping to change at line 18 skipping to change at line 18
/*************************************************************************** /***************************************************************************
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or * * the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. * * (at your option) any later version. *
* * * *
***************************************************************************/ ***************************************************************************/
#include "../config-krename.h"
#ifdef HAVE_FREETYPE
#include "batchrenamer.h"
#include "fontplugin.h" #include "fontplugin.h"
#include "batchrenamer.h"
#include "tokenhelpdialog.h" #include "tokenhelpdialog.h"
#include <ft2build.h> #include <ft2build.h>
#include FT_FREETYPE_H #include FT_FREETYPE_H
#include <klocale.h> #include <KLocalizedString>
FontPlugin::FontPlugin( PluginLoader* loader ) FontPlugin::FontPlugin(PluginLoader *loader)
: FilePlugin( loader ) : FilePlugin(loader)
{ {
const QString prefix("font"); const QString prefix("font");
this->addSupportedToken("fontpostscript"); this->addSupportedToken("fontpostscript");
this->addSupportedToken("fontfamily"); this->addSupportedToken("fontfamily");
this->addSupportedToken("fontstyle"); this->addSupportedToken("fontstyle");
m_help.append( "[fontPostscript]" + TokenHelpDialog::getTokenSeparator() + i m_help.append("[fontPostscript]" + TokenHelpDialog::getTokenSeparator() + i1
18n("Insert the Postscript name for Type1 and TrueType fonts.") ); 8n("Insert the PostScript name for Type1 and TrueType fonts."));
m_help.append( "[fontFamily]" + TokenHelpDialog::getTokenSeparator() + i18n( m_help.append("[fontFamily]" + TokenHelpDialog::getTokenSeparator() + i18n("
"Insert the (usually English) name of the font family.") ); Insert the (usually English) name of the font family."));
m_help.append( "[fontStyle]" + TokenHelpDialog::getTokenSeparator() + i18n(" m_help.append("[fontStyle]" + TokenHelpDialog::getTokenSeparator() + i18n("I
Insert the (usually English) name of the font style.") ); nsert the (usually English) name of the font style."));
m_name = i18n("Font (FreeType2) Plugin"); m_name = i18n("Font (FreeType2) Plugin");
m_comment = i18n("<qt>This plugin supports reading tags from " m_comment = i18n("<qt>This plugin supports reading tags from "
"font files.</qt>"); "font files.</qt>");
m_icon = "application-x-font-ttf"; m_icon = "application-x-font-ttf";
FT_Error error = FT_Init_FreeType( &m_library ); FT_Error error = FT_Init_FreeType(&m_library);
if( error ) if (error) {
{ qDebug("Freetype initialization error %i.", error);
qDebug("Freetype initialization error %i.", error ); m_library = nullptr;
m_library = NULL;
} }
} }
FontPlugin::~FontPlugin() FontPlugin::~FontPlugin()
{ {
FT_Done_FreeType( m_library ); FT_Done_FreeType(m_library);
m_library = NULL; m_library = nullptr;
} }
QString FontPlugin::processFile( BatchRenamer* b, int index, const QString & fil enameOrToken, EPluginType ) QString FontPlugin::processFile(BatchRenamer *b, int index, const QString &filen ameOrToken, EPluginType)
{ {
QString token( filenameOrToken.toLower() ); QString token(filenameOrToken.toLower());
QString filename = (*b->files())[index].srcUrl().path(); QString filename = (*b->files())[index].srcUrl().path();
if( !this->supports( token ) ) if (!this->supports(token)) {
return QString(""); return QString("");
}
if( !m_library ) if (!m_library) {
{
return QString("Cannot initialize FreeType"); return QString("Cannot initialize FreeType");
} }
FT_Face face; FT_Face face;
FT_Error error = FT_New_Face( m_library, FT_Error error = FT_New_Face(m_library,
filename.toUtf8().data(), filename.toUtf8().data(),
0, 0,
&face ); &face);
QString result = QString(""); QString result = QString("");
if ( error == FT_Err_Unknown_File_Format ) if (error == FT_Err_Unknown_File_Format) {
{ face = nullptr;
face = NULL;
result = QString("Unknown font file format error: %1").arg(error); result = QString("Unknown font file format error: %1").arg(error);
} } else if (error) {
else if ( error ) face = nullptr;
{
face = NULL;
result = QString("Unknown error: %1.").arg(error); result = QString("Unknown error: %1.").arg(error);
} } else {
else if (token == "fontpostscript") {
{ result = QString::fromLocal8Bit(FT_Get_Postscript_Name(face));
if( token == "fontpostscript" ) } else if (token == "fontfamily" && face->family_name) {
{ result = QString::fromLocal8Bit(face->family_name);
result = QString::fromAscii( FT_Get_Postscript_Name( face ) ); } else if (token == "fontstyle" && face->style_name) {
} result = QString::fromLocal8Bit(face->style_name);
else if( token == "fontfamily" && face->family_name )
{
result = QString::fromAscii( face->family_name );
}
else if( token == "fontstyle" && face->style_name )
{
result = QString::fromAscii( face->style_name );
} }
} }
if( face ) if (face) {
{ FT_Done_Face(face);
FT_Done_Face( face );
} }
return result; return result;
} }
#endif // HAVE_FREETYPE
 End of changes. 18 change blocks. 
53 lines changed or deleted 38 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)