示例#1
0
KoFilter::ConversionStatus WPGImport::convert(const QByteArray& from, const QByteArray& to)
{
    if (from != "application/x-wpg")
        return KoFilter::NotImplemented;

    if (to != "image/svg+xml")
        return KoFilter::NotImplemented;

#if LIBWPG_VERSION_MINOR<2
    WPXInputStream* input = new libwpg::WPGFileStream(m_chain->inputFile().toLocal8Bit());
    if (input->isOLEStream()) {
        WPXInputStream* olestream = input->getDocumentOLEStream();
        if (olestream) {
            delete input;
            input = olestream;
        }
    }
    libwpg::WPGString output;
#else
    WPXInputStream* input = new WPXFileStream(m_chain->inputFile().toLocal8Bit());
    if (input->isOLEStream()) {
        WPXInputStream* olestream = input->getDocumentOLEStream("Anything");
        if (olestream) {
            delete input;
            input = olestream;
        }
     }
     ::WPXString output;
#endif

    if (!libwpg::WPGraphics::isSupported(input)) {
        kWarning() << "ERROR: Unsupported file format (unsupported version) or file is encrypted!";
        delete input;
        return KoFilter::NotImplemented;
    }

    if (!libwpg::WPGraphics::generateSVG(input, output)) {
        kWarning() << "ERROR: SVG Generation failed!";
        delete input;
        return KoFilter::ParsingError;
    }

    delete input;

    QFile outputFile(m_chain->outputFile());
    if(!outputFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
        kWarning() << "ERROR: Could not open output file" << m_chain->outputFile();
        return KoFilter::InternalError;
    }
    outputFile.write(output.cstr());
    outputFile.close();

    return KoFilter::OK;
}
示例#2
0
/**
Parses the input stream content. It will make callbacks to the functions provided by a
WPGPaintInterface class implementation when needed. This is often commonly called the
'main parsing routine'.
\param input The input stream
\param painter A WPGPainterInterface implementation
\return A value that indicates whether the parsing was successful
*/
bool libwpg::WPGraphics::parse(::WPXInputStream* input, libwpg::WPGPaintInterface* painter)
{
	input->seek(0, WPX_SEEK_CUR);
	WPGXParser *parser = 0;
	
	WPXInputStream *graphics = 0;
	bool isDocumentOLE = false;

	if (input->isOLEStream())
	{
		graphics = input->getDocumentOLEStream();
		if (graphics)
			isDocumentOLE = true;
		else
			return false;
	}
	else
		graphics = input;

	WPG_DEBUG_MSG(("Loading header...\n"));
	WPGHeader header;
	if(!header.load(graphics))
	{
		if (graphics && isDocumentOLE)
			delete graphics;
		return false;
	}
	
	if(!header.isSupported())
	{
		WPG_DEBUG_MSG(("Unsupported file format!\n"));
		if (graphics && isDocumentOLE)
			delete graphics;
		return false;  
	}

	graphics->seek(header.startOfDocument(), WPX_SEEK_SET);

	bool retval;
	switch (header.majorVersion()) {
		case 0x01: // WPG1
			WPG_DEBUG_MSG(("Parsing WPG1\n"));
			parser = new WPG1Parser(graphics, painter);
			retval = parser->parse();
			break;
		case 0x02: // WPG2
			WPG_DEBUG_MSG(("Parsing WPG2\n"));
			parser = new WPG2Parser(graphics, painter);
			retval = parser->parse();
			break;
		default: // other :-)
			WPG_DEBUG_MSG(("Unknown format\n"));
			if (graphics && isDocumentOLE)
				delete graphics;
			return false;
	}
	
	if (parser)
		delete parser;
	if (graphics && isDocumentOLE)
		delete graphics;
	
	return retval;
}
示例#3
0
KoFilter::ConversionStatus WPGImport::convert( const QByteArray& from, const QByteArray& to )
{
  if ( from != "application/x-wpg" )
    return KoFilter::NotImplemented;

  if ( to != "application/vnd.oasis.opendocument.graphics" )
    return KoFilter::NotImplemented;


  WPXInputStream* input = new libwpg::WPGFileStream( m_chain->inputFile().toLocal8Bit() );
  if (input->isOLEStream())
  {
    WPXInputStream* olestream = input->getDocumentOLEStream();
    if (olestream)
    {
      delete input;
      input = olestream;
    }
  }

  if (!libwpg::WPGraphics::isSupported(input))
  {
    std::cerr << "ERROR: Unsupported file format (unsupported version) or file is encrypted!" << std::endl;
    delete input;
    return KoFilter::NotImplemented;
  }

  // do the conversion
  std::ostringstream tmpStringStream;
  FileOutputHandler tmpHandler(tmpStringStream);
  OdgExporter exporter(&tmpHandler);
  libwpg::WPGraphics::parse(input, &exporter);
  delete input;


  // create output store
  KoStore* storeout;
  storeout = KoStore::createStore( m_chain->outputFile(), KoStore::Write,
    "application/vnd.oasis.opendocument.graphics", KoStore::Zip );

  if ( !storeout )
  {
    kWarning() << "Couldn't open the requested file.";
    return KoFilter::FileNotFound;
  }

#if 0
  if ( !storeout->open( "styles.xml" ) )
  {
    kWarning() << "Couldn't open the file 'styles.xml'.";
    return KoFilter::CreationError;
  }
  //storeout->write( createStyles() );
  storeout->close();
#endif

  if ( !storeout->open( "content.xml" ) )
  {
    kWarning() << "Couldn't open the file 'content.xml'.";
    return KoFilter::CreationError;
  }
  storeout->write(tmpStringStream.str().c_str());
  storeout->close();

  // store document manifest
  storeout->enterDirectory( "META-INF" );
  if ( !storeout->open( "manifest.xml" ) )
  {
     kWarning() << "Couldn't open the file 'META-INF/manifest.xml'.";
     return KoFilter::CreationError;
  }
  storeout->write( createManifest() );
  storeout->close();

  // we are done!
  delete storeout;

  return KoFilter::OK;
}