Commit bb96499b613265b3d9cf2146af09283a4b99ef13

Authored by Jay Berkenbilt
1 parent 0e3d4cdc

Update docs and prepare QPDF::writeJSON for changes

Add additional parameters that will be needed to call QPDF::writeJSON
in partial mode.
... ... @@ -69,24 +69,9 @@ Soon: Break ground on "Document-level work"
69 69 JSON v2 fixes
70 70 =============
71 71  
72   -* Get rid of separate format for --json and --json-output. Instead,
73   - --json-output can just require an outfile and change some defaults
74   - like which keys are present and json-stream-data. This makes it
75   - easier to support use cases like being able to use information in
76   - other top-level keys ("pages", "attachments", etc.) to drive
77   - modifications made to objects without having to run qpdf twice. I
78   - think --json-output should make the default key be only "qpdf" and
79   - the default json-stream-data mode be inline, but make it so you can
80   - use --json-stream-data and --json-stream-prefix with --json and
81   - --json-keys with --json-output. These would be exactly the same:
82   -
83   - --json-output --json-keys=all -
84   - --json --json-stream-data=inline
85   -
86   - And these:
87   -
88   - --json-output -
89   - --json --json-stream-data=inline --json-key=qpdf
  72 +* Unify code between QPDFJob::doJSONObjects and QPDF::writeJSON. Make
  73 + sure that the "qpdf" key is always present when json-output is
  74 + specified.
90 75  
91 76 * Change the name of the "qpdf-v2" key to "qpdf". Use that in place of
92 77 "objects" and change its content to a two-element array whose first
... ... @@ -114,9 +99,10 @@ JSON v2 fixes
114 99  
115 100 This implies a few things:
116 101  
117   - * QPDF::writeJSON will have to take an argument indicating whether
118   - additional keys are being written which determines whether it
119   - outputs the outer braces or not.
  102 + * Fix --json-help
  103 +
  104 + * --json-key=objects is only valid for v1. --json-key=qpdf is only
  105 + valid for v2.
120 106  
121 107 * This changes the policy about additional extra keys. Have a
122 108 guarantee that qpdf will never add a key whose name is or starts
... ...
include/qpdf/QPDF.hh
... ... @@ -134,8 +134,17 @@ class QPDF
134 134 void updateFromJSON(std::shared_ptr<InputSource>);
135 135  
136 136 // Write qpdf json format to the pipeline "p". The only supported
137   - // version is 2. The finish() method is called on the pipeline at
138   - // the end. The decode_level parameter controls which streams are
  137 + // version is 2.
  138 + //
  139 + // If the value of "complete" is true, a complete JSON object
  140 + // containing only the "qpdf" key is written to the pipeline, and
  141 + // finish() is called on the pipeline at the end. If the value of
  142 + // "complete" is false, the "qpdf" key and its value are written
  143 + // to the pipeline assuming that a dictionary is already open, and
  144 + // finish() is not called. The parameter first_key indicates
  145 + // whether this is the first key if in-progress dictionary.
  146 + //
  147 + // The decode_level parameter controls which streams are
139 148 // uncompressed in the JSON. Use qpdf_dl_none to preserve all
140 149 // stream data exactly as it appears in the input. The possible
141 150 // values for json_stream_data can be found in qpdf/Constants.h
... ... @@ -158,6 +167,8 @@ class QPDF
158 167 void writeJSON(
159 168 int version,
160 169 Pipeline* p,
  170 + bool complete,
  171 + bool first_key,
161 172 qpdf_stream_decode_level_e decode_level,
162 173 qpdf_json_stream_data_e json_stream_data,
163 174 std::string const& file_prefix,
... ...
job.sums
... ... @@ -8,10 +8,10 @@ include/qpdf/auto_job_c_pages.hh b3cc0f21029f6d89efa043dcdbfa183cb59325b6506001c
8 8 include/qpdf/auto_job_c_uo.hh ae21b69a1efa9333050f4833d465f6daff87e5b38e5106e49bbef5d4132e4ed1
9 9 job.yml 3b2b3c6f92b48f6c76109711cbfdd74669fa31a80cd17379548b09f8e76be05d
10 10 libqpdf/qpdf/auto_job_decl.hh 74df4d7fdbdf51ecd0d58ce1e9844bb5525b9adac5a45f7c9a787ecdda2868df
11   -libqpdf/qpdf/auto_job_help.hh 3aaae4cde004e5314d3ac6d554da575e40209c0f0611f6a308957986f9c7967b
  11 +libqpdf/qpdf/auto_job_help.hh db2e4350c700e064b204e3e20d4fee4eddfe312b28092afcf608b4b6863d30e5
12 12 libqpdf/qpdf/auto_job_init.hh 7ea8e0641dc26fdfba6e283e14dbbff0c016654e174cdace8054f8bef53750fd
13 13 libqpdf/qpdf/auto_job_json_decl.hh 06caa46eaf71db8a50c046f91866baa8087745a9474319fb7c86d92634cc8297
14 14 libqpdf/qpdf/auto_job_json_init.hh 5f6b53e3c81d4b54ce5c4cf9c3f52d0c02f987c53bf8841c0280367bad23e335
15 15 libqpdf/qpdf/auto_job_schema.hh 9d543cd4a43eafffc2c4b8a6fee29e399c271c52cb6f7d417ae5497b3c1127dc
16 16 manual/_ext/qpdf.py 6add6321666031d55ed4aedf7c00e5662bba856dfcd66ccb526563bffefbb580
17   -manual/cli.rst ad8b234c24569e41c7929f729bb2188f86cd94b8fea5905b71802673cec92eed
  17 +manual/cli.rst 8e1f443c6fa000e023e516c318df4d04d58233d4d8648907c4a71f0ea5722bca
... ...
libqpdf/QPDFJob.cc
... ... @@ -3381,6 +3381,8 @@ QPDFJob::writeJSON(QPDF&amp; pdf)
3381 3381 pdf.writeJSON(
3382 3382 this->m->json_output,
3383 3383 fp.get(),
  3384 + true,
  3385 + true,
3384 3386 this->m->decode_level,
3385 3387 this->m->json_stream_data,
3386 3388 file_prefix,
... ...
libqpdf/QPDFJob_config.cc
... ... @@ -312,6 +312,9 @@ QPDFJob::Config::jsonOutput(std::string const&amp; parameter)
312 312 if (!o.m->decode_level_set) {
313 313 o.m->decode_level = qpdf_dl_none;
314 314 }
  315 + if (o.m->json_keys.empty()) {
  316 + o.m->json_keys.insert("qpdf");
  317 + }
315 318 return this;
316 319 }
317 320  
... ...
libqpdf/QPDF_json.cc
... ... @@ -764,6 +764,8 @@ void
764 764 QPDF::writeJSON(
765 765 int version,
766 766 Pipeline* p,
  767 + bool complete,
  768 + bool first_key,
767 769 qpdf_stream_decode_level_e decode_level,
768 770 qpdf_json_stream_data_e json_stream_data,
769 771 std::string const& file_prefix,
... ... @@ -818,7 +820,9 @@ QPDF::writeJSON(
818 820 }
819 821 JSON::writeDictionaryClose(p, first_object, 2);
820 822 JSON::writeDictionaryClose(p, first_qpdf, 1);
821   - JSON::writeDictionaryClose(p, first, 0);
822   - *p << "\n";
823   - p->finish();
  823 + if (complete) {
  824 + JSON::writeDictionaryClose(p, first, 0);
  825 + *p << "\n";
  826 + p->finish();
  827 + }
824 828 }
... ...
libqpdf/qpdf/auto_job_help.hh
... ... @@ -821,16 +821,18 @@ objects will be shown.
821 821 )");
822 822 ap.addOptionHelp("--json-stream-data", "json", "how to handle streams in json output", R"(--json-stream-data={none|inline|file}
823 823  
824   -When used with --json-output, this option controls whether
825   -streams in json output should be omitted, written inline
826   -(base64-encoded) or written to a file. If "file" is chosen, the
827   -file will be the name of the output file appended with -nnn where
828   -nnn is the object number. The prefix can be overridden with
829   ---json-stream-prefix.
  824 +When used with --json, this option controls whether streams in
  825 +json output should be omitted, written inline (base64-encoded)
  826 +or written to a file. If "file" is chosen, the file will be the
  827 +name of the output file appended with -nnn where nnn is the
  828 +object number. The prefix can be overridden with
  829 +--json-stream-prefix. The default is "none", except
  830 +when --json-output is specified, in which case the default is
  831 +"inline".
830 832 )");
831 833 ap.addOptionHelp("--json-stream-prefix", "json", "prefix for json stream data files", R"(--json-stream-prefix=file-prefix
832 834  
833   -When used with --json-output, --json-stream-data=file-prefix
  835 +When used with --json-stream-data=file, --json-stream-data=file-prefix
834 836 sets the prefix for stream data files, overriding the default,
835 837 which is to use the output file name. Whatever is given here
836 838 will be appended with -nnn to create the name of the file that
... ...
manual/cli.rst
... ... @@ -3220,7 +3220,9 @@ Related Options
3220 3220 This option is repeatable. If given, only the specified top-level
3221 3221 keys will be included in the JSON output. Otherwise, all keys will
3222 3222 be included. ``version`` and ``parameters`` will always appear in
3223   - the output.
  3223 + the output. If not given, all keys will be included, unless
  3224 + :qpdf:ref:`--json-output` was specified, in which case, only the
  3225 + ``"qpdf"`` key will be included by default.
3224 3226  
3225 3227 .. qpdf:option:: --json-object={trailer|obj[,gen]}
3226 3228  
... ... @@ -3241,39 +3243,41 @@ Related Options
3241 3243  
3242 3244 .. help: how to handle streams in json output
3243 3245  
3244   - When used with --json-output, this option controls whether
3245   - streams in json output should be omitted, written inline
3246   - (base64-encoded) or written to a file. If "file" is chosen, the
3247   - file will be the name of the output file appended with -nnn where
3248   - nnn is the object number. The prefix can be overridden with
3249   - --json-stream-prefix.
  3246 + When used with --json, this option controls whether streams in
  3247 + json output should be omitted, written inline (base64-encoded)
  3248 + or written to a file. If "file" is chosen, the file will be the
  3249 + name of the output file appended with -nnn where nnn is the
  3250 + object number. The prefix can be overridden with
  3251 + --json-stream-prefix. The default is "none", except
  3252 + when --json-output is specified, in which case the default is
  3253 + "inline".
3250 3254  
3251   - When used with :qpdf:ref:`--json-output`, this option controls
  3255 + When used with :qpdf:ref:`--json`, this option controls
3252 3256 whether streams in JSON output should be omitted, written inline
3253 3257 (base64-encoded) or written to a file. If ``file`` is chosen, the
3254 3258 file will be the name of the output file appended with
3255 3259 :samp:`-{nnn}` where :samp:`{nnn}` is the object number. The stream
3256 3260 data file prefix can be overridden with
3257   - :qpdf:ref:`--json-stream-prefix`. This option only applies when
3258   - used with :qpdf:ref:`--json-output`.
  3261 + :qpdf:ref:`--json-stream-prefix`. The default value is ``none``,
  3262 + except when :qpdf:ref:`--json-output` is specified, in which case
  3263 + the default is ``inline``.
3259 3264  
3260 3265 .. qpdf:option:: --json-stream-prefix=file-prefix
3261 3266  
3262 3267 .. help: prefix for json stream data files
3263 3268  
3264   - When used with --json-output, --json-stream-data=file-prefix
  3269 + When used with --json-stream-data=file, --json-stream-data=file-prefix
3265 3270 sets the prefix for stream data files, overriding the default,
3266 3271 which is to use the output file name. Whatever is given here
3267 3272 will be appended with -nnn to create the name of the file that
3268 3273 will contain the data for the stream stream in object nnn.
3269 3274  
3270   - When used with :qpdf:ref:`--json-output`,
  3275 + When used with ``--json-stream-data=file``,
3271 3276 ``--json-stream-data=file-prefix`` sets the prefix for stream data
3272 3277 files, overriding the default, which is to use the output file
3273 3278 name. Whatever is given here will be appended with :samp:`-{nnn}`
3274 3279 to create the name of the file that will contain the data for the
3275   - stream stream in object :samp:`{nnn}`. This option only applies
3276   - when used with :qpdf:ref:`--json-output`.
  3280 + stream stream in object :samp:`{nnn}`.
3277 3281  
3278 3282 .. qpdf:option:: --json-output[=version]
3279 3283  
... ... @@ -3288,12 +3292,22 @@ Related Options
3288 3292 in qpdf JSON format at the given version. ``version`` may be a
3289 3293 specific version or ``latest`` (the default). The only supported
3290 3294 version is 2. See also :qpdf:ref:`--json-stream-data` and
3291   - :qpdf:ref:`--json-stream-prefix`. When this option is specified,
3292   - the default decode level for stream data is ``none``, but you can
3293   - override it with :qpdf:ref:`--decode-level`. If you want to look at
3294   - the contents of streams easily as you would in QDF mode (see
3295   - :ref:`qdf`), you can use ``--decode-level=generalized`` and
3296   - ``--json-stream-data=file`` for a convenient way to do that.
  3295 + :qpdf:ref:`--json-stream-prefix`. This option also changes the
  3296 + following defaults:
  3297 +
  3298 + - The default value for :qpdf:ref:`--json-stream-data` changes from
  3299 + ``none`` to ``inline``.
  3300 +
  3301 + - The default decode level for stream data becomes ``none``, but you can
  3302 + override it with :qpdf:ref:`--decode-level`.
  3303 +
  3304 + - Only the ``"qpdf"`` key is included in the JSON output, but you
  3305 + can add additional keys with :qpdf:ref:`--json-key`.
  3306 +
  3307 + If you want to look at the contents of streams easily as you would
  3308 + in QDF mode (see :ref:`qdf`), you can use
  3309 + ``--decode-level=generalized`` and ``--json-stream-data=file`` for
  3310 + a convenient way to do that.
3297 3311  
3298 3312 .. qpdf:option:: --json-input
3299 3313  
... ...