calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / vcl / workben / fftester.cxx
blob2d624b8e4c433837105943046cf37e27bd8c9442
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 /* e.g.
21 make
22 cp workdir/LinkTarget/Executable/fftester instdir/program
23 LD_LIBRARY_PATH=`pwd`/instdir/program instdir/program/fftester <foo> png
24 or on macOS
25 make
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>
34 #include <sal/main.h>
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/filter/SvmReader.hxx>
50 #include <vcl/svapp.hxx>
51 #include <vcl/virdev.hxx>
52 #include <vcl/wmf.hxx>
53 #include <vcl/wrkwin.hxx>
54 #include <fltcall.hxx>
55 #include <filter/TiffReader.hxx>
56 #include <filter/TgaReader.hxx>
57 #include <filter/PictReader.hxx>
58 #include <filter/MetReader.hxx>
59 #include <filter/RasReader.hxx>
60 #include <filter/PcxReader.hxx>
61 #include <filter/EpsReader.hxx>
62 #include <filter/PsdReader.hxx>
63 #include <filter/PcdReader.hxx>
64 #include <filter/PbmReader.hxx>
65 #include <filter/DxfReader.hxx>
66 #include <filter/WebpReader.hxx>
67 #include <filter/XpmReader.hxx>
68 #include <osl/file.hxx>
69 #include <osl/module.hxx>
70 #include <rtl/bootstrap.hxx>
71 #include <tools/stream.hxx>
72 #include <vcl/gdimtf.hxx>
73 #include <fontsubset.hxx>
75 #include "../source/filter/igif/gifread.hxx"
76 #include "../source/filter/ixbm/xbmread.hxx"
77 #include "../source/filter/jpeg/jpeg.hxx"
79 using namespace ::com::sun::star::uno;
80 using namespace ::com::sun::star::lang;
81 using namespace cppu;
83 typedef bool (*FFilterCall)(SvStream &rStream);
85 #ifndef DISABLE_DYNLOADING
86 namespace {
88 FFilterCall load(std::u16string_view library, char const * function) {
89 OUString path = OUString::Concat("$LO_LIB_DIR/") + library;
90 rtl::Bootstrap::expandMacros(path); //TODO: check for failure
91 osl::Module aLibrary(path, SAL_LOADMODULE_LAZY);
92 auto const fn = reinterpret_cast<FFilterCall>(aLibrary.getFunctionSymbol(function));
93 aLibrary.release();
94 return fn;
98 #endif
100 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
102 int ret = -1;
105 if (argc < 3)
107 fprintf(stderr, "Usage: fftester <filename> <wmf|jpg>\n");
108 return -1;
111 setenv("SAL_USE_VCLPLUGIN", "svp", 1);
112 setenv("JPEGMEM", "768M", 1);
113 setenv("SC_MAX_MATRIX_ELEMENTS", "60000000", 1);
114 setenv("SC_NO_THREADED_CALCULATION", "1", 1);
115 setenv("SAL_DISABLE_PRINTERLIST", "1", 1);
116 setenv("SAL_DISABLE_DEFAULTPRINTER", "1", 1);
117 setenv("SAL_NO_FONT_LOOKUP", "1", 1);
119 OUString in(argv[1], strlen(argv[1]), RTL_TEXTENCODING_UTF8);
120 OUString out;
121 osl::File::getFileURLFromSystemPath(in, out);
123 tools::extendApplicationEnvironment();
125 Reference< XComponentContext > xContext = defaultBootstrap_InitialComponentContext();
126 Reference< XMultiServiceFactory > xServiceManager( xContext->getServiceManager(), UNO_QUERY );
127 if( !xServiceManager.is() )
128 Application::Abort( "Failed to bootstrap" );
129 comphelper::setProcessServiceFactory( xServiceManager );
130 utl::ConfigManager::EnableFuzzing();
132 // initialise unconfigured UCB:
133 css::uno::Reference<css::ucb::XUniversalContentBroker> xUcb(comphelper::getProcessServiceFactory()->
134 createInstance("com.sun.star.ucb.UniversalContentBroker"), css::uno::UNO_QUERY_THROW);
135 css::uno::Sequence<css::uno::Any> aArgs{ css::uno::Any(OUString("NoConfig")) };
136 css::uno::Reference<css::ucb::XContentProvider> xFileProvider(comphelper::getProcessServiceFactory()->
137 createInstanceWithArguments("com.sun.star.ucb.FileContentProvider", aArgs), css::uno::UNO_QUERY_THROW);
138 xUcb->registerContentProvider(xFileProvider, "file", true);
140 Application::EnableHeadlessMode(false);
141 InitVCL();
143 if (strcmp(argv[2], "wmf") == 0 || strcmp(argv[2], "emf") == 0)
145 GDIMetaFile aGDIMetaFile;
146 SvFileStream aFileStream(out, StreamMode::READ);
147 ret = static_cast<int>(ReadWindowMetafile(aFileStream, aGDIMetaFile));
149 else if (strcmp(argv[2], "jpg") == 0)
151 Graphic aGraphic;
152 SvFileStream aFileStream(out, StreamMode::READ);
153 ret = static_cast<int>(ImportJPEG(aFileStream, aGraphic, GraphicFilterImportFlags::NONE, nullptr));
155 else if (strcmp(argv[2], "gif") == 0)
157 SvFileStream aFileStream(out, StreamMode::READ);
158 Graphic aGraphic;
159 ret = static_cast<int>(ImportGIF(aFileStream, aGraphic));
161 else if (strcmp(argv[2], "xbm") == 0)
163 Graphic aGraphic;
164 SvFileStream aFileStream(out, StreamMode::READ);
165 ret = static_cast<int>(ImportXBM(aFileStream, aGraphic));
167 else if (strcmp(argv[2], "xpm") == 0)
169 Graphic aGraphic;
170 SvFileStream aFileStream(out, StreamMode::READ);
171 ret = static_cast<int>(ImportXPM(aFileStream, aGraphic));
173 else if (strcmp(argv[2], "png") == 0)
175 SvFileStream aFileStream(out, StreamMode::READ);
176 vcl::PngImageReader aReader(aFileStream);
177 ret = static_cast<int>(!aReader.read().IsEmpty());
179 else if (strcmp(argv[2], "bmp") == 0)
181 Bitmap aTarget;
182 SvFileStream aFileStream(out, StreamMode::READ);
183 ret = static_cast<int>(ReadDIB(aTarget, aFileStream, true));
185 else if (strcmp(argv[2], "pcd") == 0)
187 Graphic aGraphic;
188 SvFileStream aFileStream(out, StreamMode::READ);
189 ret = static_cast<int>(ImportPcdGraphic(aFileStream, aGraphic, nullptr));
191 else if (strcmp(argv[2], "dxf") == 0)
193 Graphic aGraphic;
194 SvFileStream aFileStream(out, StreamMode::READ);
195 ret = static_cast<int>(ImportDxfGraphic(aFileStream, aGraphic));
197 else if (strcmp(argv[2], "met") == 0)
199 Graphic aGraphic;
200 SvFileStream aFileStream(out, StreamMode::READ);
201 ret = static_cast<int>(ImportMetGraphic(aFileStream, aGraphic));
203 else if ((strcmp(argv[2], "pbm") == 0) || strcmp(argv[2], "ppm") == 0)
205 Graphic aGraphic;
206 SvFileStream aFileStream(out, StreamMode::READ);
207 ret = static_cast<int>(ImportPbmGraphic(aFileStream, aGraphic));
209 else if (strcmp(argv[2], "psd") == 0)
211 Graphic aGraphic;
212 SvFileStream aFileStream(out, StreamMode::READ);
213 ret = static_cast<int>(ImportPsdGraphic(aFileStream, aGraphic));
215 else if (strcmp(argv[2], "eps") == 0)
217 Graphic aGraphic;
218 SvFileStream aFileStream(out, StreamMode::READ);
219 ret = static_cast<int>(ImportEpsGraphic(aFileStream, aGraphic));
221 else if (strcmp(argv[2], "pct") == 0)
223 Graphic aGraphic;
224 SvFileStream aFileStream(out, StreamMode::READ);
225 ret = static_cast<int>(ImportPictGraphic(aFileStream, aGraphic));
227 else if (strcmp(argv[2], "pcx") == 0)
229 Graphic aGraphic;
230 SvFileStream aFileStream(out, StreamMode::READ);
231 ret = static_cast<int>(ImportPcxGraphic(aFileStream, aGraphic));
233 else if (strcmp(argv[2], "ras") == 0)
235 Graphic aGraphic;
236 SvFileStream aFileStream(out, StreamMode::READ);
237 ret = static_cast<int>(ImportRasGraphic(aFileStream, aGraphic));
239 else if (strcmp(argv[2], "tga") == 0)
241 Graphic aGraphic;
242 SvFileStream aFileStream(out, StreamMode::READ);
243 ret = static_cast<int>(ImportTgaGraphic(aFileStream, aGraphic));
245 else if (strcmp(argv[2], "tif") == 0)
247 Graphic aGraphic;
248 SvFileStream aFileStream(out, StreamMode::READ);
249 ret = static_cast<int>(ImportTiffGraphicImport(aFileStream, aGraphic));
251 else if (strcmp(argv[2], "webp") == 0)
253 Graphic aGraphic;
254 SvFileStream aFileStream(out, StreamMode::READ);
255 ret = static_cast<int>(ImportWebpGraphic(aFileStream, aGraphic));
257 else if (strcmp(argv[2], "sft") == 0)
259 SvFileStream aFileStream(out, StreamMode::READ);
260 std::vector<sal_uInt8> aData(aFileStream.remainingSize());
261 aFileStream.ReadBytes(aData.data(), aData.size());
262 ret = TestFontSubset(aData.data(), aData.size());
264 #ifndef DISABLE_DYNLOADING
265 else if ((strcmp(argv[2], "doc") == 0) || (strcmp(argv[2], "ww8") == 0))
267 static FFilterCall pfnImport(nullptr);
268 if (!pfnImport)
270 pfnImport = load(u"libmswordlo.so", "TestImportWW8");
272 SvFileStream aFileStream(out, StreamMode::READ);
273 ret = static_cast<int>((*pfnImport)(aFileStream));
275 else if (strcmp(argv[2], "ww6") == 0)
277 static FFilterCall pfnImport(nullptr);
278 if (!pfnImport)
280 pfnImport = load(u"libmswordlo.so", "TestImportWW6");
282 SvFileStream aFileStream(out, StreamMode::READ);
283 ret = static_cast<int>((*pfnImport)(aFileStream));
285 else if (strcmp(argv[2], "ww2") == 0)
287 static FFilterCall pfnImport(nullptr);
288 if (!pfnImport)
290 pfnImport = load(u"libmswordlo.so", "TestImportWW2");
292 SvFileStream aFileStream(out, StreamMode::READ);
293 ret = static_cast<int>((*pfnImport)(aFileStream));
295 else if (strcmp(argv[2], "rtf") == 0)
297 static FFilterCall pfnImport(nullptr);
298 if (!pfnImport)
300 pfnImport = load(u"libmswordlo.so", "TestImportRTF");
302 SvFileStream aFileStream(out, StreamMode::READ);
303 ret = static_cast<int>((*pfnImport)(aFileStream));
305 else if (strcmp(argv[2], "html") == 0)
307 static FFilterCall pfnImport(nullptr);
308 if (!pfnImport)
310 pfnImport = load(u"libswlo.so", "TestImportHTML");
312 SvFileStream aFileStream(out, StreamMode::READ);
313 ret = static_cast<int>((*pfnImport)(aFileStream));
315 else if (strcmp(argv[2], "fodt") == 0)
317 static FFilterCall pfnImport(nullptr);
318 if (!pfnImport)
320 pfnImport = load(u"libswlo.so", "TestImportFODT");
322 SvFileStream aFileStream(out, StreamMode::READ);
323 ret = static_cast<int>((*pfnImport)(aFileStream));
325 else if (strcmp(argv[2], "docx") == 0)
327 static FFilterCall pfnImport(nullptr);
328 if (!pfnImport)
330 pfnImport = load(u"libswlo.so", "TestImportDOCX");
332 SvFileStream aFileStream(out, StreamMode::READ);
333 ret = static_cast<int>((*pfnImport)(aFileStream));
335 else if (strcmp(argv[2], "fods") == 0)
337 static FFilterCall pfnImport(nullptr);
338 if (!pfnImport)
340 pfnImport = load(u"libsclo.so", "TestImportFODS");
342 SvFileStream aFileStream(out, StreamMode::READ);
343 ret = static_cast<int>((*pfnImport)(aFileStream));
345 else if (strcmp(argv[2], "xlsx") == 0)
347 static FFilterCall pfnImport(nullptr);
348 if (!pfnImport)
350 pfnImport = load(u"libsclo.so", "TestImportXLSX");
352 SvFileStream aFileStream(out, StreamMode::READ);
353 ret = static_cast<int>((*pfnImport)(aFileStream));
355 else if (strcmp(argv[2], "fodp") == 0)
357 static FFilterCall pfnImport(nullptr);
358 if (!pfnImport)
360 pfnImport = load(u"libsdlo.so", "TestImportFODP");
362 SvFileStream aFileStream(out, StreamMode::READ);
363 ret = static_cast<int>((*pfnImport)(aFileStream));
365 else if (strcmp(argv[2], "pptx") == 0)
367 static FFilterCall pfnImport(nullptr);
368 if (!pfnImport)
370 pfnImport = load(u"libsdlo.so", "TestImportPPTX");
372 SvFileStream aFileStream(out, StreamMode::READ);
373 ret = static_cast<int>((*pfnImport)(aFileStream));
375 else if (strcmp(argv[2], "xls") == 0)
377 static FFilterCall pfnImport(nullptr);
378 if (!pfnImport)
380 pfnImport = load(u"libscfiltlo.so", "TestImportXLS");
382 SvFileStream aFileStream(out, StreamMode::READ);
383 ret = static_cast<int>((*pfnImport)(aFileStream));
385 else if (strcmp(argv[2], "wks") == 0)
387 static FFilterCall pfnImport(nullptr);
388 if (!pfnImport)
390 pfnImport = load(u"libscfiltlo.so", "TestImportWKS");
392 SvFileStream aFileStream(out, StreamMode::READ);
393 ret = static_cast<int>((*pfnImport)(aFileStream));
395 else if (strcmp(argv[2], "hwp") == 0)
397 static FFilterCall pfnImport(nullptr);
398 if (!pfnImport)
400 pfnImport = load(u"libhwplo.so", "TestImportHWP");
402 SvFileStream aFileStream(out, StreamMode::READ);
403 ret = static_cast<int>((*pfnImport)(aFileStream));
405 else if (strcmp(argv[2], "602") == 0)
407 static FFilterCall pfnImport(nullptr);
408 if (!pfnImport)
410 pfnImport = load(u"libt602filterlo.so", "TestImport602");
412 SvFileStream aFileStream(out, StreamMode::READ);
413 ret = static_cast<int>((*pfnImport)(aFileStream));
415 else if (strcmp(argv[2], "lwp") == 0)
417 static FFilterCall pfnImport(nullptr);
418 if (!pfnImport)
420 pfnImport = load(u"liblwpftlo.so", "TestImportLWP");
422 SvFileStream aFileStream(out, StreamMode::READ);
423 ret = static_cast<int>((*pfnImport)(aFileStream));
425 else if (strcmp(argv[2], "ppt") == 0)
427 static FFilterCall pfnImport(nullptr);
428 if (!pfnImport)
430 pfnImport = load(u"libsdlo.so", "TestImportPPT");
432 SvFileStream aFileStream(out, StreamMode::READ);
433 ret = static_cast<int>((*pfnImport)(aFileStream));
435 else if (strcmp(argv[2], "cgm") == 0)
437 static FFilterCall pfnImport(nullptr);
438 if (!pfnImport)
440 pfnImport = load(u"libsdlo.so", "TestImportCGM");
442 SvFileStream aFileStream(out, StreamMode::READ);
443 ret = static_cast<int>((*pfnImport)(aFileStream));
445 else if (strcmp(argv[2], "qpw") == 0)
447 static FFilterCall pfnImport(nullptr);
448 if (!pfnImport)
450 pfnImport = load(u"libscfiltlo.so", "TestImportQPW");
452 SvFileStream aFileStream(out, StreamMode::READ);
453 ret = static_cast<int>((*pfnImport)(aFileStream));
455 else if (strcmp(argv[2], "dbf") == 0)
457 static FFilterCall pfnImport(nullptr);
458 if (!pfnImport)
460 pfnImport = load(u"libsclo.so", "TestImportDBF");
462 SvFileStream aFileStream(out, StreamMode::READ);
463 ret = static_cast<int>((*pfnImport)(aFileStream));
465 else if (strcmp(argv[2], "dif") == 0)
467 static FFilterCall pfnImport(nullptr);
468 if (!pfnImport)
470 pfnImport = load(u"libscfiltlo.so", "TestImportDIF");
472 SvFileStream aFileStream(out, StreamMode::READ);
473 ret = static_cast<int>((*pfnImport)(aFileStream));
475 else if (strcmp(argv[2], "sc-rtf") == 0)
477 static FFilterCall pfnImport(nullptr);
478 if (!pfnImport)
480 pfnImport = load(u"libscfiltlo.so", "TestImportCalcRTF");
482 SvFileStream aFileStream(out, StreamMode::READ);
483 ret = static_cast<int>((*pfnImport)(aFileStream));
485 else if (strcmp(argv[2], "slk") == 0)
487 static FFilterCall pfnImport(nullptr);
488 if (!pfnImport)
490 pfnImport = load(u"libsclo.so", "TestImportSLK");
492 SvFileStream aFileStream(out, StreamMode::READ);
493 ret = static_cast<int>((*pfnImport)(aFileStream));
495 else if (strcmp(argv[2], "ole") == 0)
497 static FFilterCall pfnImport(nullptr);
498 if (!pfnImport)
500 pfnImport = load(u"libsotlo.so", "TestImportOLE2");
502 SvFileStream aFileStream(out, StreamMode::READ);
503 ret = static_cast<int>((*pfnImport)(aFileStream));
505 else if (strcmp(argv[2], "mml") == 0)
507 static FFilterCall pfnImport(nullptr);
508 if (!pfnImport)
510 pfnImport = load(u"libsmlo.so", "TestImportMML");
512 SvFileStream aFileStream(out, StreamMode::READ);
513 ret = static_cast<int>((*pfnImport)(aFileStream));
515 else if (strcmp(argv[2], "mtp") == 0)
517 static FFilterCall pfnImport(nullptr);
518 if (!pfnImport)
520 pfnImport = load(u"libsmlo.so", "TestImportMathType");
522 SvFileStream aFileStream(out, StreamMode::READ);
523 ret = static_cast<int>((*pfnImport)(aFileStream));
525 else if (strcmp(argv[2], "svm") == 0)
527 static FFilterCall pfnImport(nullptr);
528 if (!pfnImport)
530 pfnImport = load(u"libvcllo.so", "TestImportSVM");
532 SvFileStream aFileStream(out, StreamMode::READ);
533 ret = static_cast<int>((*pfnImport)(aFileStream));
535 #endif
537 catch (...)
539 abort();
542 return ret;
545 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */