/*************************************************************************** * Copyright (C) 2011 by Pierre Marchand * * pierre@oep-h.com * * * * 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 * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "ufotemplate.h" #include UFOTemplate::UFOTemplate(const QString &name, const QString &dirPath) { fName = name; QString ufoDirName(name.split(" ").first() + ".ufo"); fPath = dirPath + QDir::separator() + ufoDirName; if(QFile::exists(fPath)) removeDir(fPath); if(fDir.mkpath(fPath) && fDir.cd(fPath)) { makeUFO(); } } void UFOTemplate::makeUFO() { QString features("table GDEF {} GDEF;"); QString fontinfo("\n\ \n\ \n\n\ familyName %1\n \ styleName Medium\n \ copyright Created by Fonzie\n \ unitsPerEm 1000\n \ ascender 800\n \ descender -200\n \ italicAngle 0\n \ note %2: Created.\n \ openTypeHeadCreated %3\n \ openTypeNameVersion Version 001.000\n \ postscriptFontName %4\n \ postscriptFullName %5\n \ postscriptWeightName Medium\n \ postscriptUnderlineThickness 50\n \ postscriptUnderlinePosition -100\n \ \n \ \n"); QString groups(" "); QString kerning(groups); QString metainfo(" creator org.constantvzw.OSP.Fonzie formatVersion 2 "); QString content(" space space.glif "); QString space(" "); QFile fFeature(fDir.absoluteFilePath("features.fea")); if(fFeature.open(QIODevice::WriteOnly)) { fFeature.write(features.toUtf8()); fFeature.close(); } QFile ffontinfo(fDir.absoluteFilePath("fontinfo.plist")); if(ffontinfo.open(QIODevice::WriteOnly)) { ffontinfo.write(fontinfo .arg(fName) // familyName .arg(QDate::currentDate().toString()) // note .arg(QDate::currentDate().toString(Qt::ISODate)) // openTypeHeadCreated .arg(fName.replace(" ", "")) // postscriptFontName .arg(fName) // postscriptFullName .toUtf8()); ffontinfo.close(); } QFile fgroups(fDir.absoluteFilePath("groups.plist")); if(fgroups.open(QIODevice::WriteOnly)) { fgroups.write(groups.toUtf8()); fgroups.close(); } QFile fkerning(fDir.absoluteFilePath("kerning.plist")); if(fkerning.open(QIODevice::WriteOnly)) { fkerning.write(kerning.toUtf8()); fkerning.close(); } QFile fmetainfo(fDir.absoluteFilePath("metainfo.plist")); if(fmetainfo.open(QIODevice::WriteOnly)) { fmetainfo.write(metainfo.toUtf8()); fmetainfo.close(); } if(fDir.mkdir("glyphs") && fDir.cd("glyphs")) { QFile fcontent(fDir.absoluteFilePath("contents.plist")); if(fcontent.open(QIODevice::WriteOnly)) { fcontent.write(content.toUtf8()); fcontent.close(); } QFile fspace(fDir.absoluteFilePath("space.glif")); if(fspace.open(QIODevice::WriteOnly)) { fspace.write(space.toUtf8()); fspace.close(); } } } bool UFOTemplate::removeDir(const QString &dirName) { bool result = true; QDir dir(dirName); if (dir.exists(dirName)) { Q_FOREACH(QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) { if (info.isDir()) { result = removeDir(info.absoluteFilePath()); } else { result = QFile::remove(info.absoluteFilePath()); } if (!result) { return result; } } result = dir.rmdir(dirName); } return result; } QString UFOTemplate::path() const { return fPath; }