1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 cp workdir/LinkTarget/Executable/fftester instdir/program
23 LD_LIBRARY_PATH=`pwd`/instdir/program instdir/program/fftester <foo> png
26 cp workdir/LinkTarget/Executable/fftester instdir/LibreOfficeDev.app/Contents/MacOS/
27 DYLD_LIBRARY_PATH=`pwd`/instdir/LibreOfficeDev.app/Contents/Frameworks instdir/LibreOfficeDev.app/Contents/MacOS/fftester <foo> png
30 #include <sal/config.h>
32 #include <string_view>
35 #include <tools/extendapplicationenvironment.hxx>
37 #include <cppuhelper/bootstrap.hxx>
38 #include <comphelper/processfactory.hxx>
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 #include <com/sun/star/ucb/XContentProvider.hpp>
42 #include <com/sun/star/ucb/XUniversalContentBroker.hpp>
43 #include <com/sun/star/uno/XComponentContext.hpp>
44 #include <unotools/configmgr.hxx>
45 #include <vcl/dibtools.hxx>
46 #include <vcl/event.hxx>
47 #include <vcl/graphicfilter.hxx>
48 #include <vcl/filter/PngImageReader.hxx>
49 #include <vcl/svapp.hxx>
50 #include <vcl/wmf.hxx>
51 #include <vcl/wrkwin.hxx>
52 #include <fltcall.hxx>
53 #include <filter/TiffReader.hxx>
54 #include <filter/TgaReader.hxx>
55 #include <filter/PictReader.hxx>
56 #include <filter/MetReader.hxx>
57 #include <filter/RasReader.hxx>
58 #include <filter/PcxReader.hxx>
59 #include <filter/EpsReader.hxx>
60 #include <filter/PsdReader.hxx>
61 #include <filter/PcdReader.hxx>
62 #include <filter/PbmReader.hxx>
63 #include <filter/DxfReader.hxx>
64 #include <filter/XpmReader.hxx>
65 #include <osl/file.hxx>
66 #include <osl/module.hxx>
67 #include <rtl/bootstrap.hxx>
68 #include <tools/stream.hxx>
69 #include <vcl/gdimtf.hxx>
71 #include "../source/filter/igif/gifread.hxx"
72 #include "../source/filter/ixbm/xbmread.hxx"
73 #include "../source/filter/jpeg/jpeg.hxx"
75 using namespace ::com::sun::star::uno
;
76 using namespace ::com::sun::star::lang
;
79 typedef bool (*FFilterCall
)(SvStream
&rStream
);
81 #ifndef DISABLE_DYNLOADING
84 FFilterCall
load(std::u16string_view library
, char const * function
) {
85 OUString path
= OUString::Concat("$LO_LIB_DIR/") + library
;
86 rtl::Bootstrap::expandMacros(path
); //TODO: check for failure
87 osl::Module
aLibrary(path
, SAL_LOADMODULE_LAZY
);
88 auto const fn
= reinterpret_cast<FFilterCall
>(aLibrary
.getFunctionSymbol(function
));
96 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc
, argv
)
103 fprintf(stderr
, "Usage: fftester <filename> <wmf|jpg>\n");
107 setenv("SAL_USE_VCLPLUGIN", "svp", 1);
108 setenv("JPEGMEM", "768M", 1);
109 setenv("SC_MAX_MATRIX_ELEMENTS", "60000000", 1);
110 setenv("SC_NO_THREADED_CALCULATION", "1", 1);
111 setenv("SAL_DISABLE_PRINTERLIST", "1", 1);
112 setenv("SAL_DISABLE_DEFAULTPRINTER", "1", 1);
113 setenv("SAL_NO_FONT_LOOKUP", "1", 1);
115 OUString
in(argv
[1], strlen(argv
[1]), RTL_TEXTENCODING_UTF8
);
117 osl::File::getFileURLFromSystemPath(in
, out
);
119 tools::extendApplicationEnvironment();
121 Reference
< XComponentContext
> xContext
= defaultBootstrap_InitialComponentContext();
122 Reference
< XMultiServiceFactory
> xServiceManager( xContext
->getServiceManager(), UNO_QUERY
);
123 if( !xServiceManager
.is() )
124 Application::Abort( "Failed to bootstrap" );
125 comphelper::setProcessServiceFactory( xServiceManager
);
126 utl::ConfigManager::EnableFuzzing();
128 // initialise unconfigured UCB:
129 css::uno::Reference
<css::ucb::XUniversalContentBroker
> xUcb(comphelper::getProcessServiceFactory()->
130 createInstance("com.sun.star.ucb.UniversalContentBroker"), css::uno::UNO_QUERY_THROW
);
131 css::uno::Sequence
<css::uno::Any
> aArgs(1);
132 aArgs
[0] <<= OUString("NoConfig");
133 css::uno::Reference
<css::ucb::XContentProvider
> xFileProvider(comphelper::getProcessServiceFactory()->
134 createInstanceWithArguments("com.sun.star.ucb.FileContentProvider", aArgs
), css::uno::UNO_QUERY_THROW
);
135 xUcb
->registerContentProvider(xFileProvider
, "file", true);
137 Application::EnableHeadlessMode(false);
140 if (strcmp(argv
[2], "wmf") == 0 || strcmp(argv
[2], "emf") == 0)
142 GDIMetaFile aGDIMetaFile
;
143 SvFileStream
aFileStream(out
, StreamMode::READ
);
144 ret
= static_cast<int>(ReadWindowMetafile(aFileStream
, aGDIMetaFile
));
146 else if (strcmp(argv
[2], "jpg") == 0)
149 SvFileStream
aFileStream(out
, StreamMode::READ
);
150 ret
= static_cast<int>(ImportJPEG(aFileStream
, aGraphic
, GraphicFilterImportFlags::NONE
, nullptr));
152 else if (strcmp(argv
[2], "gif") == 0)
154 SvFileStream
aFileStream(out
, StreamMode::READ
);
156 ret
= static_cast<int>(ImportGIF(aFileStream
, aGraphic
));
158 else if (strcmp(argv
[2], "xbm") == 0)
161 SvFileStream
aFileStream(out
, StreamMode::READ
);
162 ret
= static_cast<int>(ImportXBM(aFileStream
, aGraphic
));
164 else if (strcmp(argv
[2], "xpm") == 0)
167 SvFileStream
aFileStream(out
, StreamMode::READ
);
168 ret
= static_cast<int>(ImportXPM(aFileStream
, aGraphic
));
170 else if (strcmp(argv
[2], "png") == 0)
172 SvFileStream
aFileStream(out
, StreamMode::READ
);
173 vcl::PngImageReader
aReader(aFileStream
);
174 ret
= static_cast<int>(!aReader
.read().IsEmpty());
176 else if (strcmp(argv
[2], "bmp") == 0)
179 SvFileStream
aFileStream(out
, StreamMode::READ
);
180 ret
= static_cast<int>(ReadDIB(aTarget
, aFileStream
, true));
182 else if (strcmp(argv
[2], "svm") == 0)
184 GDIMetaFile aGDIMetaFile
;
185 SvFileStream
aFileStream(out
, StreamMode::READ
);
186 ReadGDIMetaFile(aFileStream
, aGDIMetaFile
);
188 else if (strcmp(argv
[2], "pcd") == 0)
191 SvFileStream
aFileStream(out
, StreamMode::READ
);
192 ret
= static_cast<int>(ImportPcdGraphic(aFileStream
, aGraphic
, nullptr));
194 else if (strcmp(argv
[2], "dxf") == 0)
197 SvFileStream
aFileStream(out
, StreamMode::READ
);
198 ret
= static_cast<int>(ImportDxfGraphic(aFileStream
, aGraphic
));
200 else if (strcmp(argv
[2], "met") == 0)
203 SvFileStream
aFileStream(out
, StreamMode::READ
);
204 ret
= static_cast<int>(ImportMetGraphic(aFileStream
, aGraphic
));
206 else if ((strcmp(argv
[2], "pbm") == 0) || strcmp(argv
[2], "ppm") == 0)
209 SvFileStream
aFileStream(out
, StreamMode::READ
);
210 ret
= static_cast<int>(ImportPbmGraphic(aFileStream
, aGraphic
));
212 else if (strcmp(argv
[2], "psd") == 0)
215 SvFileStream
aFileStream(out
, StreamMode::READ
);
216 ret
= static_cast<int>(ImportPsdGraphic(aFileStream
, aGraphic
));
218 else if (strcmp(argv
[2], "eps") == 0)
221 SvFileStream
aFileStream(out
, StreamMode::READ
);
222 ret
= static_cast<int>(ImportEpsGraphic(aFileStream
, aGraphic
));
224 else if (strcmp(argv
[2], "pct") == 0)
227 SvFileStream
aFileStream(out
, StreamMode::READ
);
228 ret
= static_cast<int>(ImportPictGraphic(aFileStream
, aGraphic
));
230 else if (strcmp(argv
[2], "pcx") == 0)
233 SvFileStream
aFileStream(out
, StreamMode::READ
);
234 ret
= static_cast<int>(ImportPcxGraphic(aFileStream
, aGraphic
));
236 else if (strcmp(argv
[2], "ras") == 0)
239 SvFileStream
aFileStream(out
, StreamMode::READ
);
240 ret
= static_cast<int>(ImportRasGraphic(aFileStream
, aGraphic
));
242 else if (strcmp(argv
[2], "tga") == 0)
245 SvFileStream
aFileStream(out
, StreamMode::READ
);
246 ret
= static_cast<int>(ImportTgaGraphic(aFileStream
, aGraphic
));
248 else if (strcmp(argv
[2], "tif") == 0)
251 SvFileStream
aFileStream(out
, StreamMode::READ
);
252 ret
= static_cast<int>(ImportTiffGraphicImport(aFileStream
, aGraphic
));
254 #ifndef DISABLE_DYNLOADING
255 else if ((strcmp(argv
[2], "doc") == 0) || (strcmp(argv
[2], "ww8") == 0))
257 static FFilterCall
pfnImport(nullptr);
260 pfnImport
= load(u
"libmswordlo.so", "TestImportWW8");
262 SvFileStream
aFileStream(out
, StreamMode::READ
);
263 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
265 else if (strcmp(argv
[2], "ww6") == 0)
267 static FFilterCall
pfnImport(nullptr);
270 pfnImport
= load(u
"libmswordlo.so", "TestImportWW6");
272 SvFileStream
aFileStream(out
, StreamMode::READ
);
273 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
275 else if (strcmp(argv
[2], "ww2") == 0)
277 static FFilterCall
pfnImport(nullptr);
280 pfnImport
= load(u
"libmswordlo.so", "TestImportWW2");
282 SvFileStream
aFileStream(out
, StreamMode::READ
);
283 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
285 else if (strcmp(argv
[2], "rtf") == 0)
287 static FFilterCall
pfnImport(nullptr);
290 pfnImport
= load(u
"libmswordlo.so", "TestImportRTF");
292 SvFileStream
aFileStream(out
, StreamMode::READ
);
293 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
295 else if (strcmp(argv
[2], "html") == 0)
297 static FFilterCall
pfnImport(nullptr);
300 pfnImport
= load(u
"libswlo.so", "TestImportHTML");
302 SvFileStream
aFileStream(out
, StreamMode::READ
);
303 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
305 else if (strcmp(argv
[2], "fodt") == 0)
307 static FFilterCall
pfnImport(nullptr);
310 pfnImport
= load(u
"libswlo.so", "TestImportFODT");
312 SvFileStream
aFileStream(out
, StreamMode::READ
);
313 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
315 else if (strcmp(argv
[2], "docx") == 0)
317 static FFilterCall
pfnImport(nullptr);
320 pfnImport
= load(u
"libswlo.so", "TestImportDOCX");
322 SvFileStream
aFileStream(out
, StreamMode::READ
);
323 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
325 else if (strcmp(argv
[2], "fods") == 0)
327 static FFilterCall
pfnImport(nullptr);
330 pfnImport
= load(u
"libsclo.so", "TestImportFODS");
332 SvFileStream
aFileStream(out
, StreamMode::READ
);
333 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
335 else if (strcmp(argv
[2], "xlsx") == 0)
337 static FFilterCall
pfnImport(nullptr);
340 pfnImport
= load(u
"libsclo.so", "TestImportXLSX");
342 SvFileStream
aFileStream(out
, StreamMode::READ
);
343 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
345 else if (strcmp(argv
[2], "fodp") == 0)
347 static FFilterCall
pfnImport(nullptr);
350 pfnImport
= load(u
"libsdlo.so", "TestImportFODP");
352 SvFileStream
aFileStream(out
, StreamMode::READ
);
353 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
355 else if (strcmp(argv
[2], "pptx") == 0)
357 static FFilterCall
pfnImport(nullptr);
360 pfnImport
= load(u
"libsdlo.so", "TestImportPPTX");
362 SvFileStream
aFileStream(out
, StreamMode::READ
);
363 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
365 else if (strcmp(argv
[2], "xls") == 0)
367 static FFilterCall
pfnImport(nullptr);
370 pfnImport
= load(u
"libscfiltlo.so", "TestImportXLS");
372 SvFileStream
aFileStream(out
, StreamMode::READ
);
373 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
375 else if (strcmp(argv
[2], "wks") == 0)
377 static FFilterCall
pfnImport(nullptr);
380 pfnImport
= load(u
"libscfiltlo.so", "TestImportWKS");
382 SvFileStream
aFileStream(out
, StreamMode::READ
);
383 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
385 else if (strcmp(argv
[2], "hwp") == 0)
387 static FFilterCall
pfnImport(nullptr);
390 pfnImport
= load(u
"libhwplo.so", "TestImportHWP");
392 SvFileStream
aFileStream(out
, StreamMode::READ
);
393 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
395 else if (strcmp(argv
[2], "602") == 0)
397 static FFilterCall
pfnImport(nullptr);
400 pfnImport
= load(u
"libt602filterlo.so", "TestImport602");
402 SvFileStream
aFileStream(out
, StreamMode::READ
);
403 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
405 else if (strcmp(argv
[2], "lwp") == 0)
407 static FFilterCall
pfnImport(nullptr);
410 pfnImport
= load(u
"liblwpftlo.so", "TestImportLWP");
412 SvFileStream
aFileStream(out
, StreamMode::READ
);
413 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
415 else if (strcmp(argv
[2], "ppt") == 0)
417 static FFilterCall
pfnImport(nullptr);
420 pfnImport
= load(u
"libsdfiltlo.so", "TestImportPPT");
422 SvFileStream
aFileStream(out
, StreamMode::READ
);
423 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
425 else if (strcmp(argv
[2], "cgm") == 0)
427 static FFilterCall
pfnImport(nullptr);
430 pfnImport
= load(u
"libsdlo.so", "TestImportCGM");
432 SvFileStream
aFileStream(out
, StreamMode::READ
);
433 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
435 else if (strcmp(argv
[2], "qpw") == 0)
437 static FFilterCall
pfnImport(nullptr);
440 pfnImport
= load(u
"libscfiltlo.so", "TestImportQPW");
442 SvFileStream
aFileStream(out
, StreamMode::READ
);
443 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
445 else if (strcmp(argv
[2], "dif") == 0)
447 static FFilterCall
pfnImport(nullptr);
450 pfnImport
= load(u
"libscfiltlo.so", "TestImportDIF");
452 SvFileStream
aFileStream(out
, StreamMode::READ
);
453 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
455 else if (strcmp(argv
[2], "sc-rtf") == 0)
457 static FFilterCall
pfnImport(nullptr);
460 pfnImport
= load(u
"libscfiltlo.so", "TestImportCalcRTF");
462 SvFileStream
aFileStream(out
, StreamMode::READ
);
463 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
465 else if (strcmp(argv
[2], "slk") == 0)
467 static FFilterCall
pfnImport(nullptr);
470 pfnImport
= load(u
"libsclo.so", "TestImportSLK");
472 SvFileStream
aFileStream(out
, StreamMode::READ
);
473 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
475 else if (strcmp(argv
[2], "ole") == 0)
477 static FFilterCall
pfnImport(nullptr);
480 pfnImport
= load(u
"libsotlo.so", "TestImportOLE2");
482 SvFileStream
aFileStream(out
, StreamMode::READ
);
483 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
485 else if (strcmp(argv
[2], "mml") == 0)
487 static FFilterCall
pfnImport(nullptr);
490 pfnImport
= load(u
"libsmlo.so", "TestImportMML");
492 SvFileStream
aFileStream(out
, StreamMode::READ
);
493 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
495 else if (strcmp(argv
[2], "mtp") == 0)
497 static FFilterCall
pfnImport(nullptr);
500 pfnImport
= load(u
"libsmlo.so", "TestImportMathType");
502 SvFileStream
aFileStream(out
, StreamMode::READ
);
503 ret
= static_cast<int>((*pfnImport
)(aFileStream
));
505 else if (strcmp(argv
[2], "sft") == 0)
507 SvFileStream
aFileStream(out
, StreamMode::READ
);
508 std::vector
<sal_uInt8
> aData(aFileStream
.remainingSize());
509 aFileStream
.ReadBytes(aData
.data(), aData
.size());
510 (void)vcl::Font::identifyFont(aData
.data(), aData
.size());
523 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */