fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sdext / source / pdfimport / sax / emitcontext.cxx
blobbae84b6bf83a4d6bea6e53f88a9ed83f2bdf6e2e
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 "saxemitter.hxx"
22 #include "emitcontext.hxx"
23 #include "saxattrlist.hxx"
25 #include <rtl/strbuf.hxx>
26 #include <osl/diagnose.h>
27 #include <cppuhelper/exc_hlp.hxx>
28 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
30 #if OSL_DEBUG_LEVEL > 1
31 #include <osl/file.hxx>
32 static osl::File* pStream = NULL;
33 static int nIndent = 0;
34 #endif
36 using namespace com::sun::star;
38 namespace pdfi
41 SaxEmitter::SaxEmitter( const uno::Reference< xml::sax::XDocumentHandler >& xDocHdl ) :
42 m_xDocHdl( xDocHdl )
44 OSL_PRECOND(m_xDocHdl.is(), "SaxEmitter(): invalid doc handler");
45 try
47 m_xDocHdl->startDocument();
49 catch( xml::sax::SAXException& )
52 #if OSL_DEBUG_LEVEL > 1
53 static const char* pDir = getenv( "DBG_PDFIMPORT_DIR" );
54 if( pDir )
56 OUString aStr( OStringToOUString( pDir, RTL_TEXTENCODING_UTF8 ) );
57 OUString aFileURL;
58 osl_getFileURLFromSystemPath( aStr.pData, &aFileURL.pData );
59 OUStringBuffer aBuf( 256 );
60 aBuf.append( aFileURL );
61 aBuf.appendAscii( "/pdfimport.xml" );
62 pStream = new osl::File( aBuf.makeStringAndClear() );
63 if( pStream->open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Create ) )
65 pStream->open( osl_File_OpenFlag_Write );
66 pStream->setSize( 0 );
69 else
70 pStream = 0;
71 #endif
74 SaxEmitter::~SaxEmitter()
76 try
78 m_xDocHdl->endDocument();
80 catch( xml::sax::SAXException& )
83 #if OSL_DEBUG_LEVEL > 1
84 if( pStream )
86 pStream->close();
87 delete pStream;
88 pStream = 0;
90 #endif
93 void SaxEmitter::beginTag( const char* pTag, const PropertyMap& rProperties )
95 OUString aTag = OUString::createFromAscii( pTag );
96 uno::Reference< xml::sax::XAttributeList > xAttr(
97 new SaxAttrList( rProperties ) );
98 try
100 m_xDocHdl->startElement( aTag, xAttr );
102 catch( xml::sax::SAXException& )
105 #if OSL_DEBUG_LEVEL > 1
106 if( pStream )
108 sal_uInt64 nWritten = 0;
109 for( int i = 0; i < nIndent; i++ )
110 pStream->write( " ", 4, nWritten );
112 OStringBuffer aBuf( 1024 );
113 aBuf.append( '<' );
114 aBuf.append( pTag );
115 for( PropertyMap::const_iterator it = rProperties.begin(); it != rProperties.end(); ++it )
117 aBuf.append( ' ' );
118 aBuf.append( OUStringToOString( it->first, RTL_TEXTENCODING_UTF8 ) );
119 aBuf.append( "=\"" );
120 aBuf.append( OUStringToOString( it->second, RTL_TEXTENCODING_UTF8 ) );
121 aBuf.append( "\"" );
123 aBuf.append( ">\n" );
124 pStream->write( aBuf.getStr(), aBuf.getLength(), nWritten );
125 nIndent++;
127 #endif
130 void SaxEmitter::write( const OUString& rText )
134 m_xDocHdl->characters( rText );
136 catch( xml::sax::SAXException& )
139 #if OSL_DEBUG_LEVEL > 1
140 if( pStream )
142 OString aStr( OUStringToOString( rText, RTL_TEXTENCODING_UTF8 ) );
143 sal_uInt64 nWritten = 0;
144 pStream->write( aStr.getStr(), aStr.getLength(), nWritten );
146 #endif
149 void SaxEmitter::endTag( const char* pTag )
151 OUString aTag = OUString::createFromAscii( pTag );
154 m_xDocHdl->endElement( aTag );
156 catch( xml::sax::SAXException& )
159 #if OSL_DEBUG_LEVEL > 1
160 if( pStream )
162 sal_uInt64 nWritten = 0;
163 for( int i = 0; i < nIndent; i++ )
164 pStream->write( " ", 4, nWritten );
166 OStringBuffer aBuf( 1024 );
167 aBuf.append( "</" );
168 aBuf.append( pTag );
169 aBuf.append( ">\n" );
170 pStream->write( aBuf.getStr(), aBuf.getLength(), nWritten );
171 nIndent--;
173 #endif
176 XmlEmitterSharedPtr createSaxEmitter( const uno::Reference< xml::sax::XDocumentHandler >& xDocHdl )
178 return XmlEmitterSharedPtr(new SaxEmitter(xDocHdl));
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */