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

« back to all changes in this revision

Viewing changes to tests/poppler/utils/pdffonts.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
// pdffonts.cc
 
4
//
 
5
// Copyright 2001-2007 Glyph & Cog, LLC
 
6
//
 
7
//========================================================================
 
8
 
 
9
//========================================================================
 
10
//
 
11
// Modified under the Poppler project - http://poppler.freedesktop.org
 
12
//
 
13
// All changes made under the Poppler project to this file are licensed
 
14
// under GPL version 2 or later
 
15
//
 
16
// Copyright (C) 2006 Dominic Lachowicz <cinamod@hotmail.com>
 
17
// Copyright (C) 2007-2008, 2010 Albert Astals Cid <aacid@kde.org>
 
18
// Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
 
19
//
 
20
// To see a description of the changes please see the Changelog file that
 
21
// came with your tarball or type make ChangeLog if you are building from git
 
22
//
 
23
//========================================================================
 
24
 
 
25
#include "config.h"
 
26
#include <poppler-config.h>
 
27
#include <stdio.h>
 
28
#include <stdlib.h>
 
29
#include <stddef.h>
 
30
#include <string.h>
 
31
#include <math.h>
 
32
#include "parseargs.h"
 
33
#include "goo/GooString.h"
 
34
#include "goo/gmem.h"
 
35
#include "GlobalParams.h"
 
36
#include "Object.h"
 
37
#include "PDFDoc.h"
 
38
#include "PDFDocFactory.h"
 
39
#include "FontInfo.h"
 
40
 
 
41
static char *fontTypeNames[] = {
 
42
  "unknown",
 
43
  "Type 1",
 
44
  "Type 1C",
 
45
  "Type 1C (OT)",
 
46
  "Type 3",
 
47
  "TrueType",
 
48
  "TrueType (OT)",
 
49
  "CID Type 0",
 
50
  "CID Type 0C",
 
51
  "CID Type 0C (OT)",
 
52
  "CID TrueType",
 
53
  "CID TrueType (OT)"
 
54
};
 
55
 
 
56
static int firstPage = 1;
 
57
static int lastPage = 0;
 
58
static char ownerPassword[33] = "\001";
 
59
static char userPassword[33] = "\001";
 
60
static GBool printVersion = gFalse;
 
61
static GBool printHelp = gFalse;
 
62
 
 
63
static const ArgDesc argDesc[] = {
 
64
  {"-f",      argInt,      &firstPage,     0,
 
65
   "first page to examine"},
 
66
  {"-l",      argInt,      &lastPage,      0,
 
67
   "last page to examine"},
 
68
  {"-opw",    argString,   ownerPassword,  sizeof(ownerPassword),
 
69
   "owner password (for encrypted files)"},
 
70
  {"-upw",    argString,   userPassword,   sizeof(userPassword),
 
71
   "user password (for encrypted files)"},
 
72
  {"-v",      argFlag,     &printVersion,  0,
 
73
   "print copyright and version info"},
 
74
  {"-h",      argFlag,     &printHelp,     0,
 
75
   "print usage information"},
 
76
  {"-help",   argFlag,     &printHelp,     0,
 
77
   "print usage information"},
 
78
  {"--help",  argFlag,     &printHelp,     0,
 
79
   "print usage information"},
 
80
  {"-?",      argFlag,     &printHelp,     0,
 
81
   "print usage information"},
 
82
  {NULL}
 
83
};
 
84
 
 
85
int main(int argc, char *argv[]) {
 
86
  PDFDoc *doc;
 
87
  GooString *fileName;
 
88
  GooString *ownerPW, *userPW;
 
89
  GBool ok;
 
90
  int exitCode;
 
91
 
 
92
  exitCode = 99;
 
93
 
 
94
  // parse args
 
95
  ok = parseArgs(argDesc, &argc, argv);
 
96
  if (!ok || argc != 2 || printVersion || printHelp) {
 
97
    fprintf(stderr, "pdffonts version %s\n", PACKAGE_VERSION);
 
98
    fprintf(stderr, "%s\n", popplerCopyright);
 
99
    fprintf(stderr, "%s\n", xpdfCopyright);
 
100
    if (!printVersion) {
 
101
      printUsage("pdffonts", "<PDF-file>", argDesc);
 
102
    }
 
103
    if (printVersion || printHelp)
 
104
      exitCode = 0;
 
105
    goto err0;
 
106
  }
 
107
  fileName = new GooString(argv[1]);
 
108
 
 
109
  // read config file
 
110
  globalParams = new GlobalParams();
 
111
 
 
112
  // open PDF file
 
113
  if (ownerPassword[0] != '\001') {
 
114
    ownerPW = new GooString(ownerPassword);
 
115
  } else {
 
116
    ownerPW = NULL;
 
117
  }
 
118
  if (userPassword[0] != '\001') {
 
119
    userPW = new GooString(userPassword);
 
120
  } else {
 
121
    userPW = NULL;
 
122
  }
 
123
  if (fileName->cmp("-") == 0) {
 
124
      delete fileName;
 
125
      fileName = new GooString("fd://0");
 
126
  }
 
127
 
 
128
  doc = PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW);
 
129
  delete fileName;
 
130
 
 
131
  if (userPW) {
 
132
    delete userPW;
 
133
  }
 
134
  if (ownerPW) {
 
135
    delete ownerPW;
 
136
  }
 
137
  if (!doc->isOk()) {
 
138
    exitCode = 1;
 
139
    goto err1;
 
140
  }
 
141
 
 
142
  // get page range
 
143
  if (firstPage < 1) {
 
144
    firstPage = 1;
 
145
  }
 
146
  if (lastPage < 1 || lastPage > doc->getNumPages()) {
 
147
    lastPage = doc->getNumPages();
 
148
  }
 
149
 
 
150
  // get the fonts
 
151
  {
 
152
    FontInfoScanner scanner(doc, firstPage - 1);
 
153
    GooList *fonts = scanner.scan(lastPage - firstPage + 1);
 
154
 
 
155
    // print the font info
 
156
    printf("name                                 type              emb sub uni object ID\n");
 
157
    printf("------------------------------------ ----------------- --- --- --- ---------\n");
 
158
    if (fonts) {
 
159
      for (int i = 0; i < fonts->getLength(); ++i) {
 
160
        FontInfo *font = (FontInfo *)fonts->get(i);
 
161
        printf("%-36s %-17s %-3s %-3s %-3s",
 
162
              font->getName() ? font->getName()->getCString() : "[none]",
 
163
              fontTypeNames[font->getType()],
 
164
              font->getEmbedded() ? "yes" : "no",
 
165
              font->getSubset() ? "yes" : "no",
 
166
              font->getToUnicode() ? "yes" : "no");
 
167
        const Ref fontRef = font->getRef();
 
168
        if (fontRef.gen >= 100000) {
 
169
          printf(" [none]\n");
 
170
        } else {
 
171
          printf(" %6d %2d\n", fontRef.num, fontRef.gen);
 
172
        }
 
173
        delete font;
 
174
      }
 
175
      delete fonts;
 
176
    }
 
177
  }
 
178
 
 
179
  exitCode = 0;
 
180
 
 
181
 err1:
 
182
  delete doc;
 
183
  delete globalParams;
 
184
 err0:
 
185
 
 
186
  // check for memory leaks
 
187
  Object::memCheck(stderr);
 
188
  gMemReport(stderr);
 
189
 
 
190
  return exitCode;
 
191
}
 
192
 
 
193