~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/poppler/poppler/PDFDocFactory.cc

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//========================================================================
 
2
//
 
3
// PDFDocFactory.cc
 
4
//
 
5
// This file is licensed under the GPLv2 or later
 
6
//
 
7
// Copyright 2010 Hib Eris <hib@hiberis.nl>
 
8
// Copyright 2010 Albert Astals Cid <aacid@kde.org>
 
9
//
 
10
//========================================================================
 
11
 
 
12
#include <config.h>
 
13
 
 
14
#include "PDFDocFactory.h"
 
15
 
 
16
#include "goo/GooList.h"
 
17
#include "goo/GooString.h"
 
18
#include "PDFDoc.h"
 
19
#include "LocalPDFDocBuilder.h"
 
20
#include "StdinPDFDocBuilder.h"
 
21
#if ENABLE_LIBCURL
 
22
#include "CurlPDFDocBuilder.h"
 
23
#endif
 
24
#include "ErrorCodes.h"
 
25
 
 
26
//------------------------------------------------------------------------
 
27
// PDFDocFactory
 
28
//------------------------------------------------------------------------
 
29
 
 
30
PDFDocFactory::PDFDocFactory(GooList *pdfDocBuilders)
 
31
{
 
32
  if (pdfDocBuilders) {
 
33
    builders = pdfDocBuilders;
 
34
  } else {
 
35
    builders = new GooList();
 
36
  }
 
37
#if ENABLE_LIBCURL
 
38
  builders->insert(0, new CurlPDFDocBuilder());
 
39
#endif
 
40
  builders->insert(0, new StdinPDFDocBuilder());
 
41
  builders->insert(0, new LocalPDFDocBuilder());
 
42
}
 
43
 
 
44
PDFDocFactory::~PDFDocFactory()
 
45
{
 
46
  if (builders) {
 
47
    deleteGooList(builders, PDFDocBuilder);
 
48
  }
 
49
}
 
50
 
 
51
PDFDoc *
 
52
PDFDocFactory::createPDFDoc(const GooString &uri, GooString *ownerPassword,
 
53
                                    GooString *userPassword, void *guiDataA)
 
54
{
 
55
  for (int i = builders->getLength() - 1; i >= 0 ; i--) {
 
56
    PDFDocBuilder *builder = (PDFDocBuilder *) builders->get(i);
 
57
    if (builder->supports(uri)) {
 
58
      return builder->buildPDFDoc(uri, ownerPassword, userPassword, guiDataA);
 
59
    }
 
60
  }
 
61
 
 
62
  error(-1, "Cannot handle URI '%s'.", uri.getCString());
 
63
  GooString *fileName = uri.copy();
 
64
  return PDFDoc::ErrorPDFDoc(errOpenFile, fileName);
 
65
}
 
66
 
 
67
void PDFDocFactory::registerPDFDocBuilder(PDFDocBuilder *pdfDocBuilder)
 
68
{
 
69
  builders->append(pdfDocBuilder);
 
70
}
 
71
 
 
72