File: config.hh

package info (click to toggle)
pdf2djvu 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,388 kB
  • ctags: 771
  • sloc: cpp: 5,869; sh: 4,283; xml: 780; makefile: 160; python: 24
file content (149 lines) | stat: -rw-r--r-- 2,868 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* Copyright © 2007, 2008, 2009, 2010 Jakub Wilk
 * Copyright © 2009 Mateusz Turcza
 *
 * This package is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 dated June, 1991.
 */

#ifndef PDF2DJVU_CONFIG_H
#define PDF2DJVU_CONFIG_H

#include <climits>
#include <memory>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>

#include "i18n.hh"
#include "sexpr.hh"
#include "string-format.hh"

class Config
{
protected:
  static string_format::Template *default_pageid_template(const std::string &pageid_prefix);
public:
  class Hyperlinks
  {
  public:
    bool extract;
    bool border_always_visible;
    std::string border_color;
    Hyperlinks()
    : extract(true), border_always_visible(false)
    { };
  };

  enum
  {
    FG_COLORS_DEFAULT = UINT_MAX,
    FG_COLORS_WEB = UINT_MAX - 1,
    FG_COLORS_BLACK = UINT_MAX - 2,
  };
  enum text_t
  {
    TEXT_NONE = 0,
    TEXT_WORDS,
    TEXT_LINES
  };
  enum format_t
  {
    FORMAT_BUNDLED,
    FORMAT_INDIRECT
  };
  format_t format;
  text_t text;
  bool text_nfkc;
  bool text_crop;
  std::string output;
  bool output_stdout;
  int verbose;
  int dpi;
  bool guess_dpi;
  std::pair<int, int> preferred_page_size;
  bool use_media_box;
  unsigned int bg_subsample;
  unsigned int fg_colors;
  bool monochrome;
  int loss_level;
  bool antialias;
  Hyperlinks hyperlinks;
  bool extract_metadata;
  bool adjust_metadata;
  bool extract_outline;
  bool no_render;
  char *bg_slices;
  std::vector< std::pair<int, int> > pages;
  char *file_name;
  std::auto_ptr<string_format::Template> pageid_template;
  std::auto_ptr<string_format::Template> page_title_template;
  std::string text_filter_command_line;
  int n_jobs;

  Config();

  class NeedVersion
  { };

  class Error : public std::runtime_error
  {
  public:
    explicit Error(const std::string &message)
    : std::runtime_error(message)
    { };
    virtual bool is_quiet() const
    {
      return false;
    }
    virtual bool is_already_printed() const
    {
      return false;
    }
    virtual ~Error() throw () { /* just to shut up compilers */ }
  };

  class NoPagesSelected : public Error
  {
  public:
    NoPagesSelected()
    : Error(_("No pages selected"))
    { }
  };

  class NeedHelp : public Error
  {
  public:
    NeedHelp()
    : Error("")
    { };
    virtual bool is_quiet() const
    {
      return true;
    }
  };

  class InvalidOption : public Error
  {
  public:
    InvalidOption()
    : Error("")
    { };
    virtual bool is_quiet() const
    {
      return true;
    }
    virtual bool is_already_printed() const
    {
      return true;
    }
  };

  void read_config(int argc, char * const argv[]);
  void usage(const Error &error) const;
};

#endif

// vim:ts=2 sw=2 et