25 #include <QApplication>
30 #include <QDomDocument>
32 #include <QDomElement>
45 #include "macosx/klfmacclipboard.h"
48 #define OPENOFFICE_DRAWING_MIMETYPE "application/x-openoffice-drawing;windows_formatname=\"Drawing Format\""
61 klfDbg(
"key = "<<key<<
" ; result="<<result) ;
69 initMimeExporterList();
72 for (k = 0; k < p_mimeExporterList.
size(); ++k) {
73 klfDbg(
"Testing exporter #"<<k<<
": "<<p_mimeExporterList[k]);
76 return p_mimeExporterList[k];
86 initMimeExporterList();
89 for (k = 0; k < p_mimeExporterList.
size(); ++k)
91 if (key.
isEmpty() || p_mimeExporterList[k]->supportsKey(key))
92 return p_mimeExporterList[k];
103 initMimeExporterList();
104 return p_mimeExporterList;
112 initMimeExporterList();
115 "Cannot register a NULL exporter!",
119 klfDbg(
"want to register exporter "<<ename<<
", making sure no duplicate names...") ;
123 for (k = 0; k < p_mimeExporterList.
size(); ++k) {
124 klfDbg(
"making sure p_mimeExporterList["<<k<<
"]->exporterName() [="<<p_mimeExporterList[k]->
exporterName()<<
"]"
125 <<
" != ename [="<<ename<<
"]") ;
127 "An exporter with same name "<<ename<<
" is already registered!",
131 klfDbg(
"registering exporter "<<ename<<
", overrides="<<overrides) ;
146 void KLFMimeExporter::initMimeExporterList()
149 if (p_mimeExporterList.
isEmpty()) {
169 : p_profileName(pname), p_description(desc), p_exportTypes(exporttypes)
174 : p_profileName(o.p_profileName), p_description(o.p_description),
175 p_exportTypes(o.p_exportTypes)
184 "Index "<<k<<
" out of bounds (size="<<p_exportTypes.size()<<
")",
188 if ( ! p_exportTypes[k].exporter.isEmpty() ) {
198 "Can't find exporter "<<p_exportTypes[k].exporter<<
" for export-type #"<<k
199 <<
"for key "<<p_exportTypes[k].mimetype,
return NULL ) ;
209 for (k = 0; k < p_exportTypes.size(); ++k)
210 mimetypes << p_exportTypes[k].mimetype;
219 for (k = 0; k < p_exportTypes.size(); ++k)
220 if (p_exportTypes[k].mimetype == mimeType)
231 for (k = 0; k < p_exportTypes.size(); ++k)
240 "Index "<<k<<
" out of bounds (size="<<p_exportTypes.size()<<
")",
243 if ( ! p_exportTypes[k].wintype.isEmpty() )
244 return p_exportTypes[k].wintype;
247 if (exporter == NULL)
259 for (k = 0; k < p_exportTypes.size(); ++k) {
261 oktypes << p_exportTypes[k].mimetype;
275 ensureLoadedExportProfileList();
276 return p_exportProfileList;
283 ensureLoadedExportProfileList();
284 p_exportProfileList.
push_front(exportProfile);
291 ensureLoadedExportProfileList();
294 for (k = 0; k < p_exportProfileList.
size(); ++k)
296 return p_exportProfileList[k];
299 return p_exportProfileList[0];
302 void KLFMimeExportProfile::ensureLoadedExportProfileList()
306 if ( ! p_exportProfileList.
isEmpty())
317 <<
":/conf/export_mime_profiles.d";
319 for (j = 0; j < dirs.size(); ++j) {
324 for (k = 0; k < entrylist.size(); ++k)
325 fcandidates << d.filePath(entrylist[k]);
328 for (k = 0; k < fcandidates.size(); ++k) {
330 loadFromXMLFile(fcandidates[k]);
338 for (k = 0; k < mimetypes.size(); ++k) {
339 if (mimetypes[k].startsWith(
"image/") || mimetypes[k] ==
"application/x-qt-image")
340 exporttypes << ExportType(mimetypes[k], imgexporter.windowsFormatName(mimetypes[k]));
346 p_exportProfileList << allimgfmts;
352 void KLFMimeExportProfile::loadFromXMLFile(
const QString& fname)
359 if ( ! file.open(QIODevice::ReadOnly) ) {
360 qWarning()<<
KLF_FUNC_NAME<<
": Error: Can't open export mime profiles XML file "<<fname<<
": "
361 <<file.errorString()<<
"!";
366 QString errMsg;
int errLine, errCol;
367 bool r = doc.setContent(&file,
false, &errMsg, &errLine, &errCol);
369 qWarning()<<
KLF_FUNC_NAME<<
": Error parsing file "<<fname<<
": "<<errMsg<<
" at line "<<errLine<<
", col "<<errCol;
375 if (root.nodeName() !=
"export-profile-list") {
376 qWarning(
"%s: Error parsing XML for export mime profiles from file `%s': Bad root node `%s'.\n",
377 KLF_FUNC_NAME, qPrintable(fname), qPrintable(root.nodeName()));
387 if ( e.isNull() || n.
nodeType() != QDomNode::ElementNode )
389 if ( e.nodeName() ==
"add-macosx-type-rules" ) {
391 __klf_add_macosx_type_rules(fname, e);
393 klfDbg(
"Ignoring Mac OS X type rules on non-mac window system") ;
397 if ( e.nodeName() !=
"profile" ) {
398 qWarning(
"%s: WARNING in parsing XML \"%s\" : ignoring unexpected tag `%s', expected <profile>.\n",
399 KLF_FUNC_NAME, qPrintable(fname), qPrintable(e.nodeName()));
407 klfDbg(
"Reading profile "<<pname<<
" ...") ;
419 if ( en.
nodeName() ==
"description" ) {
422 klfDbg(
"<description>: lang="<<lang<<
"; hasAttribute(xml:lang)="<<ee.
hasAttribute(
"xml:lang")
423 <<
"; current description="<<description<<
",lang="<<curDescriptionLang) ;
429 description = qApp->translate(
"xmltr_exportprofiles", ee.
text().toUtf8().constData(),
430 "[[tag: <description>]]", QCoreApplication::UnicodeUTF8);
432 curDescriptionLang = lang;
441 description = ee.
text();
442 curDescriptionLang = lang;
448 if ( en.
nodeName() !=
"export-type" ) {
449 qWarning(
"%s: WARNING in parsing XML '%s': ignoring unexpected tag `%s' in profile `%s'!\n",
450 KLF_FUNC_NAME, qPrintable(fname), qPrintable(en.
nodeName()), qPrintable(pname));
454 if (mimetypetags.
size() != 1) {
455 qWarning()<<
KLF_FUNC_NAME<<
": in XML file "<<fname<<
", profile "<<pname
456 <<
": exactly ONE <mime-type> tag must be present in each <export-type>...</export-type>.";
460 if (wintypetags.
size() > 1) {
461 qWarning()<<
KLF_FUNC_NAME<<
": in XML file "<<fname<<
", profile "<<pname
462 <<
": expecting at most ONE <windows-type> tag in each <export-type>...</export-type>.";
466 if (exporternametags.
size() > 1) {
467 qWarning()<<
KLF_FUNC_NAME<<
": in XML file "<<fname<<
", profile "<<pname
468 <<
": expected at most ONE <exporter-name> tag in each <export-type>...</export-type>.";
471 QString mimetype = mimetypetags.
at(0).toElement().text().trimmed();
473 if (wintypetags.
size() == 1) {
474 wintype = wintypetags.
at(0).toElement().text().trimmed();
477 if (exporternametags.
size() == 1) {
478 exportername = exporternametags.
at(0).toElement().text().trimmed();
481 exporttypes << ExportType(mimetype, wintype, exportername);
489 for (kp = 0; kp < p_exportProfileList.
size(); ++kp) {
490 if (p_exportProfileList[kp].
profileName() == pname) {
494 if (kp == p_exportProfileList.
size()) {
496 klfDbg(
"Adding profile "<<pname<<
" to mime export profiles") ;
497 if (pname ==
"default") {
499 p_exportProfileList.
prepend(profile);
501 p_exportProfileList << profile;
503 descriptionLangs << curDescriptionLang;
510 (descriptionLangs[kp].isEmpty() || curDescriptionLang.
startsWith(descriptionLangs[kp]))) {
518 p_exportProfileList[kp] = finalp;
539 set_possible_qt_image_data();
547 void KLFMimeData::set_possible_qt_image_data()
556 if (exporter != NULL) {
561 for (k = 0; k < try_formats.
size() && img.
isNull(); ++k)
564 "Can't get image for application/x-qt-image for profile "<<pExportProfile.
profileName(),
576 if (fmts.
contains(
"application/x-qt-image")) {
577 if (pQtOwnedFormats.size() == 0)
579 fmts << pQtOwnedFormats;
582 klfDbg(
"format list: "<<fmts) ;
598 klfDbg(
"Can't find mime-type "<<mimetype<<
" in export profile "<<pExportProfile.
profileName()
603 klfDbg(
"exporting "<<mimetype<<
" ...");
607 "Can't find an exporter for mime-type "<<mimetype<<
"." ,
613 klfDbg(
"exporting mimetype "<<mimetype<<
": data length is "<<data.
size());
615 return QVariant::fromValue<QByteArray>(
data);
631 for (k = 0; k < qtimgfmts.
size(); ++k) {
632 if ( imageFormats.
key(qtimgfmts[k]).isEmpty() ) {
634 imageFormats[mime] = qtimgfmts[k];
648 =
QStringList() <<
"image/png" <<
"image/eps" <<
"application/eps" <<
"application/postscript"
651 <<
"image/x-win-png-office-art";
657 for (it = ifmts.
begin(); it != ifmts.
end(); ++it) {
661 if (staticKeys.
indexOf(mime) == -1)
662 imageFormats[mime] = qtfmt;
665 if (mime ==
"image/bmp") {
666 imageFormats[
"image/x-win-bmp"] = qtfmt;
667 }
else if (mime ==
"image/jpeg") {
668 imageFormats[
"image/x-win-jfif"] = qtfmt;
669 imageFormats[
"image/x-win-jfif-office-art"] = qtfmt;
670 }
else if (mime ==
"image/png") {
671 imageFormats[
"image/x-win-png-office-art"] = qtfmt;
679 keys <<
"application/pdf";
681 keys << imageFormats.
keys();
691 if (mime ==
"application/pdf")
693 else if (mime ==
"application/eps")
694 return "Encapsulated PostScript";
695 else if (mime ==
"image/png")
697 else if (mime ==
"image/jpg" || mime ==
"image/jpeg")
700 else if (mime ==
"image/x-win-jfif")
702 else if (mime ==
"image/x-win-jfif-office-art")
703 return "JFIF+Office Art";
704 else if (mime ==
"image/x-win-png-office-art")
705 return "PNG+Office Art";
706 else if (mime ==
"image/bmp")
708 else if (mime ==
"image/x-win-bmp")
709 return "Windows Bitmap";
711 return "Drawing Format";
712 else if (mime ==
"application/x-qt-image")
727 if (key ==
"image/png")
729 if (key ==
"image/eps" || key ==
"application/eps" || key ==
"application/postscript")
731 if (key ==
"application/pdf") {
734 klfDbg(
"---warning: don't have PDF data ---") ;
740 if (key ==
"application/x-qt-image")
744 klfDbg(
"Will use Qt's image format exporting");
750 QBuffer imgdatawriter(&imgdata);
751 imgdatawriter.open(QIODevice::WriteOnly);
752 klfoutput.
result.
save(&imgdatawriter, imageFormats[key]);
753 imgdatawriter.close();
768 return QStringList() <<
"text/x-moz-url" <<
"text/uri-list";
778 if (tempFilesForImageCacheKey.
contains(imgcachekey)) {
779 tempfilename = tempFilesForImageCacheKey[imgcachekey];
785 if (tempfile->
open() ==
false) {
786 qWarning(
"Can't open temp png file for mimetype text/uri-list: template is %s",
795 tempfilename = tempfile->
fileName();
796 tempfile->write(output.
pngdata);
799 tempFilesForImageCacheKey[imgcachekey] = tempfilename;
823 if (mime ==
"text/x-moz-url")
836 QRegExp replaceCharsRX(
"([^a-zA-Z0-9/ ._-])");
838 while ((pos = replaceCharsRX.
indexIn(s, pos)) != -1) {
840 klfDbg(
"replacing char at pos="<<pos<<
" by entity="<<entity<<
": s(pos...pos+5)="<<s.
mid(pos,5));
844 klfDbg(
"final string: "<<s);
866 qWarning()<<
KLF_FUNC_NAME<<
": key="<<key<<
" is not \"text/html\"";
880 latexlines.removeAt(0);
881 latex = latexlines.
join(
"\n");
893 QString(
"<img src=\"file://%1\" alt=\"%2\" title=\"%3\" "
894 " style=\"width: %4in; height: %5in; vertical-align: middle;\">")
895 .arg(fn, l, l, win, hin);
898 return html.toUtf8();
922 QFile templfile(
":/data/ooodrawingtemplate");
923 templfile.
open(QIODevice::ReadOnly);
959 const double DPI_FACTOR = 1.6;
977 klfDbg(
"final templ: "<<templ);
1005 if (encoder == NULL) {
1012 Qt::SmoothTransformation),
1018 qWarning()<<
KLF_FUNC_NAME<<
": "<<key<<
" encoder returned empty data!";
1020 klfDbg(
"got data, size="<<data.size());
1033 return QStringList() <<
"image/png" <<
"application/x-qt-image";
1045 img.
fill(qRgba(0,0,0,0));
1056 buf.open(QIODevice::WriteOnly);
1057 img.
save(&buf,
"PNG");
QString profileName() const
QStringList availableExporterMimeTypes() const
elementsByTagName(const QString &tagname)
fromUnicode(const QString &str)
virtual QString windowsFormatName(const QString &key) const
static void unregisterMimeExporter(KLFMimeExporter *exporter)
loadFromData(const uchar *data, int len, const char *format=0)
data(const QString &mimeType)
retrieveData(const QString &mimeType, QVariant::Type type)
QString locale
When setting this, don't forget to call QLocale::setDefault().
An export profile grouping several mime types.
static KLFMimeExportProfile findExportProfile(const QString &pname)
push_back(const T &value)
QStringList mimeTypes() const
virtual QString windowsFormatName(const QString &key) const
QList< KLFLibEntry > KLFLibEntryList
save(const QString &fileName, const char *format=0, int quality=-1)
split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive)
virtual QByteArray data(const QString &key, const KLFBackend::klfOutput &klfoutput)=0
contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive)
virtual QByteArray data(const QString &key, const KLFBackend::klfOutput &klfoutput)
push_front(const T &value)
#define klfDbg(streamableItems)
static QString tempFileForOutput(const KLFBackend::klfOutput &klfoutput)
#define KLF_DEBUG_BLOCK(msg)
QByteArray klf_openoffice_drawing(const KLFBackend::klfOutput &klfoutput)
replace(int pos, int len, const QByteArray &after)
QStringList respectiveWinTypes() const
join(const QString &separator)
int indexOfMimeType(const QString &mimeType) const
static QMap< QString, QByteArray > get_qt_image_formats()
tr(const char *sourceText, const char *comment=0, int n=-1)
virtual QStringList keys() const
static KLFMimeExporter * mimeExporterLookupByName(const QString &exporter, const QString &key=QString())
static QStringList allEncodingMimeTypes()
#define KLF_ASSERT_NOT_NULL(ptr, msg, failaction)
replace(int position, int n, const QString &after)
void __klf_init_the_macpasteboardmime()
static QList< KLFMimeExportProfile > exportProfileList()
indexIn(const QString &str, int offset=0, CaretMode caretMode=CaretAtZero)
number(long n, int base=10)
KLFMimeExporter * exporterLookupFor(int n, bool warnNotFound=true) const
QString respectiveWinType(int k) const
virtual QString windowsFormatName(const QString &key) const
virtual bool supportsKey(const QString &key) const
Shortcut function (do not reimplement in subclasses)
QStringList formats() const
hasAttribute(const QString &name)
virtual QByteArray data(const QString &key, const KLFBackend::klfOutput &klfoutput)
A helper class to export KLF output to other applications.
removeAll(const T &value)
startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive)
virtual QByteArray data(const QString &key, const KLFBackend::klfOutput &klfoutput)
virtual QStringList keys() const
setImageData(const QVariant &image)
static QByteArray toAttrText(const QString &sbase)
static void registerMimeExporter(KLFMimeExporter *exporter, bool overrides=true)
QString description() const
static void addExportProfile(const KLFMimeExportProfile &exportProfile)
struct KLFConfig::@3 BackendSettings
QList< ExportType > exportTypes() const
mid(int position, int n=-1)
static KLFMimeExporter * mimeExporterLookup(const QString &key)
virtual QStringList keys() const
An entry (single formula) in the library.
scaled(const QSize &size, Qt::AspectRatioMode aspectRatioMode=Qt::IgnoreAspectRatio, Qt::TransformationMode transformMode=Qt::FastTransformation)
virtual QString windowsFormatName(const QString &key) const
virtual QStringList keys() const
KLFMimeData(const QString &exportProfileName, const KLFBackend::klfOutput &output)
codecForName(const QByteArray &name)
KLFMimeExportProfile(const QString &pname, const QString &desc, const QList< ExportType > &exporttypes)
static KLFAbstractLibEntryMimeEncoder * findEncoderFor(const QString &mimeType, bool warnIfNotFound=true)
translate(const QPointF &offset)
static bool saveOutputToFile(const klfOutput &output, const QString &fileName, const QString &format=QString(), QString *errorString=NULL)
QVariant retrieveData(const QString &mimetype, QVariant::Type type) const
KLF_EXPORT void klfDrawGlowedImage(QPainter *p, const QImage &foreground, const QColor &glowcol, int r, bool also_draw_image)
virtual QByteArray data(const QString &key, const KLFBackend::klfOutput &klfoutput)
#define OPENOFFICE_DRAWING_MIMETYPE
fromLatin1(const char *str, int size=-1)
static QString toAttrTextS(const QString &sbase)
Helper class to encode an entry list as mime data (abstract interface)
virtual QByteArray data(const QString &key, const KLFBackend::klfOutput &klfoutput)
indexOf(const QRegExp &rx, int from=0)
virtual QByteArray encodeMime(const KLFLibEntryList &entryList, const QVariantMap &metaData, const QString &mimeType) const =0
QSize labelOutputFixedSize
#define KLF_ASSERT_CONDITION(expr, msg, failaction)
exactMatch(const QString &str)
virtual QStringList keys() const
virtual QStringList keys() const =0
fromLocalFile(const QString &localFile)
virtual QString exporterName() const =0
attribute(const QString &name, const QString &defValue=QString()
static QList< KLFMimeExporter * > mimeExporterList()