vcl: allow for overriding the default PDF rendering resolution
[LibreOffice.git] / sdext / source / pdfimport / services.cxx
blob410776e5011ce0d11b68146206233f04f825af28
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 .
21 #include "pdfiadaptor.hxx"
22 #include "filterdet.hxx"
23 #include <treevisitorfactory.hxx>
25 #include <cppuhelper/factory.hxx>
26 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
28 using namespace ::com::sun::star;
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::lang;
31 using namespace ::com::sun::star::registry;
34 namespace
36 Reference< XInterface > Create_PDFIHybridAdaptor( const Reference< XComponentContext >& _rxContext )
38 return *(new pdfi::PDFIHybridAdaptor( _rxContext ));
41 Reference< XInterface > Create_PDFIRawAdaptor_Writer( const Reference< XComponentContext >& _rxContext )
43 pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( "org.libreoffice.comp.documents.WriterPDFImport", _rxContext );
45 pAdaptor->setTreeVisitorFactory(pdfi::createWriterTreeVisitorFactory());
47 return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor));
50 Reference< XInterface > Create_PDFIRawAdaptor_Draw( const Reference< XComponentContext >& _rxContext )
52 pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( "org.libreoffice.comp.documents.DrawPDFImport", _rxContext );
54 pAdaptor->setTreeVisitorFactory(pdfi::createDrawTreeVisitorFactory());
56 return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor));
59 Reference< XInterface > Create_PDFIRawAdaptor_Impress( const Reference< XComponentContext >& _rxContext )
61 pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( "org.libreoffice.comp.documents.ImpressPDFImport", _rxContext );
63 pAdaptor->setTreeVisitorFactory(pdfi::createImpressTreeVisitorFactory());
65 return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor));
68 Reference< XInterface > Create_PDFDetector( const Reference< XComponentContext >& _rxContext )
70 return *(new pdfi::PDFDetector( _rxContext ) );
74 namespace
76 typedef Reference< XInterface > (* ComponentFactory)( const Reference< XComponentContext >& );
78 struct ComponentDescription
80 const sal_Char* pAsciiServiceName;
81 const sal_Char* pAsciiImplementationName;
82 ComponentFactory const pFactory;
84 ComponentDescription()
85 :pAsciiServiceName( nullptr )
86 ,pAsciiImplementationName( nullptr )
87 ,pFactory( nullptr )
90 ComponentDescription( const sal_Char* _pAsciiServiceName, const sal_Char* _pAsciiImplementationName, ComponentFactory _pFactory )
91 :pAsciiServiceName( _pAsciiServiceName )
92 ,pAsciiImplementationName( _pAsciiImplementationName )
93 ,pFactory( _pFactory )
98 const ComponentDescription* lcl_getComponents()
100 static const ComponentDescription aDescriptions[] = {
101 ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.HybridPDFImport", Create_PDFIHybridAdaptor ),
102 ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.WriterPDFImport", Create_PDFIRawAdaptor_Writer ),
103 ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.DrawPDFImport", Create_PDFIRawAdaptor_Draw ),
104 ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.ImpressPDFImport", Create_PDFIRawAdaptor_Impress ),
105 ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.PDFDetector", Create_PDFDetector ),
106 ComponentDescription()
108 return aDescriptions;
112 extern "C" SAL_DLLPUBLIC_EXPORT void* pdfimport_component_getFactory(
113 const sal_Char* pImplementationName,
114 SAL_UNUSED_PARAMETER void* /*pServiceManager*/,
115 SAL_UNUSED_PARAMETER void* /*pRegistryKey*/ )
117 OUString sImplementationName( OUString::createFromAscii( pImplementationName ) );
119 Reference< XSingleComponentFactory > xFactory;
121 const ComponentDescription* pComponents = lcl_getComponents();
122 while ( pComponents->pAsciiServiceName != nullptr )
124 if ( sImplementationName.equalsAscii( pComponents->pAsciiImplementationName ) )
126 Sequence< OUString > sServices(1);
127 sServices[0] = OUString::createFromAscii( pComponents->pAsciiServiceName );
129 xFactory = ::cppu::createSingleComponentFactory(
130 pComponents->pFactory,
131 sImplementationName,
132 sServices
134 break;
137 ++pComponents;
140 // by definition, objects returned via this C API need to ber acquired once
141 xFactory->acquire();
142 return xFactory.get();
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */