summaryrefslogtreecommitdiff
path: root/source/pdf/pdf-stream.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2018-03-29 22:25:09 +0200
committerTor Andersson <tor.andersson@artifex.com>2018-04-24 16:47:43 +0200
commit51b8205a513e86c62121a927a067632c1a933839 (patch)
treec2882a6c253a715bfc2ea72854c75350f0b2024b /source/pdf/pdf-stream.c
parent67a7449fc1f186f318942b9c6b8d66d4458b7d87 (diff)
downloadmupdf-51b8205a513e86c62121a927a067632c1a933839.tar.xz
Remove need for namedump by using macros and preprocessor.
Add a PDF_NAME(Foo) macro that evaluates to a pdf_obj for /Foo. Use the C preprocessor to create the enum values and string table from one include file instead of using a separate code generator tool.
Diffstat (limited to 'source/pdf/pdf-stream.c')
-rw-r--r--source/pdf/pdf-stream.c74
1 files changed, 37 insertions, 37 deletions
diff --git a/source/pdf/pdf-stream.c b/source/pdf/pdf-stream.c
index e8ce2fab..2cb10d12 100644
--- a/source/pdf/pdf-stream.c
+++ b/source/pdf/pdf-stream.c
@@ -38,10 +38,10 @@ pdf_stream_has_crypt(fz_context *ctx, pdf_obj *stm)
pdf_obj *obj;
int i;
- filters = pdf_dict_geta(ctx, stm, PDF_NAME_Filter, PDF_NAME_F);
+ filters = pdf_dict_geta(ctx, stm, PDF_NAME(Filter), PDF_NAME(F));
if (filters)
{
- if (pdf_name_eq(ctx, filters, PDF_NAME_Crypt))
+ if (pdf_name_eq(ctx, filters, PDF_NAME(Crypt)))
return 1;
if (pdf_is_array(ctx, filters))
{
@@ -49,7 +49,7 @@ pdf_stream_has_crypt(fz_context *ctx, pdf_obj *stm)
for (i = 0; i < n; i++)
{
obj = pdf_array_get(ctx, filters, i);
- if (pdf_name_eq(ctx, obj, PDF_NAME_Crypt))
+ if (pdf_name_eq(ctx, obj, PDF_NAME(Crypt)))
return 1;
}
}
@@ -93,22 +93,22 @@ pdf_load_jbig2_globals(fz_context *ctx, pdf_document *doc, pdf_obj *dict)
static void
build_compression_params(fz_context *ctx, pdf_obj *f, pdf_obj *p, fz_compression_params *params)
{
- int predictor = pdf_to_int(ctx, pdf_dict_get(ctx, p, PDF_NAME_Predictor));
- pdf_obj *columns_obj = pdf_dict_get(ctx, p, PDF_NAME_Columns);
+ int predictor = pdf_to_int(ctx, pdf_dict_get(ctx, p, PDF_NAME(Predictor)));
+ pdf_obj *columns_obj = pdf_dict_get(ctx, p, PDF_NAME(Columns));
int columns = pdf_to_int(ctx, columns_obj);
- int colors = pdf_to_int(ctx, pdf_dict_get(ctx, p, PDF_NAME_Colors));
- int bpc = pdf_to_int(ctx, pdf_dict_get(ctx, p, PDF_NAME_BitsPerComponent));
+ int colors = pdf_to_int(ctx, pdf_dict_get(ctx, p, PDF_NAME(Colors)));
+ int bpc = pdf_to_int(ctx, pdf_dict_get(ctx, p, PDF_NAME(BitsPerComponent)));
params->type = FZ_IMAGE_RAW;
- if (pdf_name_eq(ctx, f, PDF_NAME_CCITTFaxDecode) || pdf_name_eq(ctx, f, PDF_NAME_CCF))
+ if (pdf_name_eq(ctx, f, PDF_NAME(CCITTFaxDecode)) || pdf_name_eq(ctx, f, PDF_NAME(CCF)))
{
- pdf_obj *k = pdf_dict_get(ctx, p, PDF_NAME_K);
- pdf_obj *eol = pdf_dict_get(ctx, p, PDF_NAME_EndOfLine);
- pdf_obj *eba = pdf_dict_get(ctx, p, PDF_NAME_EncodedByteAlign);
- pdf_obj *rows = pdf_dict_get(ctx, p, PDF_NAME_Rows);
- pdf_obj *eob = pdf_dict_get(ctx, p, PDF_NAME_EndOfBlock);
- pdf_obj *bi1 = pdf_dict_get(ctx, p, PDF_NAME_BlackIs1);
+ pdf_obj *k = pdf_dict_get(ctx, p, PDF_NAME(K));
+ pdf_obj *eol = pdf_dict_get(ctx, p, PDF_NAME(EndOfLine));
+ pdf_obj *eba = pdf_dict_get(ctx, p, PDF_NAME(EncodedByteAlign));
+ pdf_obj *rows = pdf_dict_get(ctx, p, PDF_NAME(Rows));
+ pdf_obj *eob = pdf_dict_get(ctx, p, PDF_NAME(EndOfBlock));
+ pdf_obj *bi1 = pdf_dict_get(ctx, p, PDF_NAME(BlackIs1));
params->type = FZ_IMAGE_FAX;
params->u.fax.k = (k ? pdf_to_int(ctx, k) : 0);
@@ -119,18 +119,18 @@ build_compression_params(fz_context *ctx, pdf_obj *f, pdf_obj *p, fz_compression
params->u.fax.end_of_block = (eob ? pdf_to_bool(ctx, eob) : 1);
params->u.fax.black_is_1 = (bi1 ? pdf_to_bool(ctx, bi1) : 0);
}
- else if (pdf_name_eq(ctx, f, PDF_NAME_DCTDecode) || pdf_name_eq(ctx, f, PDF_NAME_DCT))
+ else if (pdf_name_eq(ctx, f, PDF_NAME(DCTDecode)) || pdf_name_eq(ctx, f, PDF_NAME(DCT)))
{
- pdf_obj *ct = pdf_dict_get(ctx, p, PDF_NAME_ColorTransform);
+ pdf_obj *ct = pdf_dict_get(ctx, p, PDF_NAME(ColorTransform));
params->type = FZ_IMAGE_JPEG;
params->u.jpeg.color_transform = (ct ? pdf_to_int(ctx, ct) : -1);
}
- else if (pdf_name_eq(ctx, f, PDF_NAME_RunLengthDecode) || pdf_name_eq(ctx, f, PDF_NAME_RL))
+ else if (pdf_name_eq(ctx, f, PDF_NAME(RunLengthDecode)) || pdf_name_eq(ctx, f, PDF_NAME(RL)))
{
params->type = FZ_IMAGE_RLD;
}
- else if (pdf_name_eq(ctx, f, PDF_NAME_FlateDecode) || pdf_name_eq(ctx, f, PDF_NAME_Fl))
+ else if (pdf_name_eq(ctx, f, PDF_NAME(FlateDecode)) || pdf_name_eq(ctx, f, PDF_NAME(Fl)))
{
params->type = FZ_IMAGE_FLATE;
params->u.flate.predictor = predictor;
@@ -138,9 +138,9 @@ build_compression_params(fz_context *ctx, pdf_obj *f, pdf_obj *p, fz_compression
params->u.flate.colors = colors;
params->u.flate.bpc = bpc;
}
- else if (pdf_name_eq(ctx, f, PDF_NAME_LZWDecode) || pdf_name_eq(ctx, f, PDF_NAME_LZW))
+ else if (pdf_name_eq(ctx, f, PDF_NAME(LZWDecode)) || pdf_name_eq(ctx, f, PDF_NAME(LZW)))
{
- pdf_obj *ec = pdf_dict_get(ctx, p, PDF_NAME_EarlyChange);
+ pdf_obj *ec = pdf_dict_get(ctx, p, PDF_NAME(EarlyChange));
params->type = FZ_IMAGE_LZW;
params->u.lzw.predictor = predictor;
@@ -173,16 +173,16 @@ build_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_obj *f, p
else if (params->type != FZ_IMAGE_RAW)
return fz_open_image_decomp_stream(ctx, chain, params, NULL);
- else if (pdf_name_eq(ctx, f, PDF_NAME_ASCIIHexDecode) || pdf_name_eq(ctx, f, PDF_NAME_AHx))
+ else if (pdf_name_eq(ctx, f, PDF_NAME(ASCIIHexDecode)) || pdf_name_eq(ctx, f, PDF_NAME(AHx)))
return fz_open_ahxd(ctx, chain);
- else if (pdf_name_eq(ctx, f, PDF_NAME_ASCII85Decode) || pdf_name_eq(ctx, f, PDF_NAME_A85))
+ else if (pdf_name_eq(ctx, f, PDF_NAME(ASCII85Decode)) || pdf_name_eq(ctx, f, PDF_NAME(A85)))
return fz_open_a85d(ctx, chain);
- else if (pdf_name_eq(ctx, f, PDF_NAME_JBIG2Decode))
+ else if (pdf_name_eq(ctx, f, PDF_NAME(JBIG2Decode)))
{
fz_jbig2_globals *globals = NULL;
- pdf_obj *obj = pdf_dict_get(ctx, p, PDF_NAME_JBIG2Globals);
+ pdf_obj *obj = pdf_dict_get(ctx, p, PDF_NAME(JBIG2Globals));
if (obj)
{
if (!pdf_is_stream(ctx, obj))
@@ -193,16 +193,16 @@ build_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_obj *f, p
return fz_open_jbig2d(ctx, chain, globals); /* takes ownership of jbig2_globals */
}
- else if (pdf_name_eq(ctx, f, PDF_NAME_JPXDecode))
+ else if (pdf_name_eq(ctx, f, PDF_NAME(JPXDecode)))
return fz_keep_stream(ctx, chain); /* JPX decoding is special cased in the image loading code */
- else if (pdf_name_eq(ctx, f, PDF_NAME_Crypt))
+ else if (pdf_name_eq(ctx, f, PDF_NAME(Crypt)))
{
if (!doc->crypt)
fz_warn(ctx, "crypt filter in unencrypted document");
else
{
- pdf_obj *name = pdf_dict_get(ctx, p, PDF_NAME_Name);
+ pdf_obj *name = pdf_dict_get(ctx, p, PDF_NAME(Name));
if (pdf_is_name(ctx, name))
return pdf_open_crypt_with_filter(ctx, chain, doc->crypt, name, num, gen);
}
@@ -294,7 +294,7 @@ pdf_open_raw_filter(fz_context *ctx, fz_stream *file_stm, pdf_document *doc, pdf
}
hascrypt = pdf_stream_has_crypt(ctx, stmobj);
- len = pdf_to_int(ctx, pdf_dict_get(ctx, stmobj, PDF_NAME_Length));
+ len = pdf_to_int(ctx, pdf_dict_get(ctx, stmobj, PDF_NAME(Length)));
null_stm = fz_open_null(ctx, file_stm, len, offset);
if (doc->crypt && !hascrypt)
{
@@ -316,8 +316,8 @@ pdf_open_raw_filter(fz_context *ctx, fz_stream *file_stm, pdf_document *doc, pdf
static fz_stream *
pdf_open_filter(fz_context *ctx, pdf_document *doc, fz_stream *file_stm, pdf_obj *stmobj, int num, int64_t offset, fz_compression_params *imparams)
{
- pdf_obj *filters = pdf_dict_geta(ctx, stmobj, PDF_NAME_Filter, PDF_NAME_F);
- pdf_obj *params = pdf_dict_geta(ctx, stmobj, PDF_NAME_DecodeParms, PDF_NAME_DP);
+ pdf_obj *filters = pdf_dict_geta(ctx, stmobj, PDF_NAME(Filter), PDF_NAME(F));
+ pdf_obj *params = pdf_dict_geta(ctx, stmobj, PDF_NAME(DecodeParms), PDF_NAME(DP));
int orig_num, orig_gen;
fz_stream *rstm, *fstm;
@@ -346,8 +346,8 @@ pdf_open_filter(fz_context *ctx, pdf_document *doc, fz_stream *file_stm, pdf_obj
fz_stream *
pdf_open_inline_stream(fz_context *ctx, pdf_document *doc, pdf_obj *stmobj, int length, fz_stream *file_stm, fz_compression_params *imparams)
{
- pdf_obj *filters = pdf_dict_geta(ctx, stmobj, PDF_NAME_Filter, PDF_NAME_F);
- pdf_obj *params = pdf_dict_geta(ctx, stmobj, PDF_NAME_DecodeParms, PDF_NAME_DP);
+ pdf_obj *filters = pdf_dict_geta(ctx, stmobj, PDF_NAME(Filter), PDF_NAME(F));
+ pdf_obj *params = pdf_dict_geta(ctx, stmobj, PDF_NAME(DecodeParms), PDF_NAME(DP));
if (pdf_is_name(ctx, filters))
return build_filter(ctx, file_stm, doc, filters, params, 0, 0, imparams);
@@ -471,7 +471,7 @@ pdf_load_raw_stream_number(fz_context *ctx, pdf_document *doc, int num)
dict = pdf_load_object(ctx, doc, num);
- len = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME_Length));
+ len = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME(Length)));
pdf_drop_obj(ctx, dict);
@@ -522,12 +522,12 @@ can_reuse_buffer(fz_context *ctx, pdf_xref_entry *entry, fz_compression_params *
if (params)
params->type = FZ_IMAGE_RAW;
- f = pdf_dict_geta(ctx, entry->obj, PDF_NAME_Filter, PDF_NAME_F);
+ f = pdf_dict_geta(ctx, entry->obj, PDF_NAME(Filter), PDF_NAME(F));
/* If there are no filters, it's uncompressed, and we can use it */
if (!f)
return 1;
- p = pdf_dict_geta(ctx, entry->obj, PDF_NAME_DecodeParms, PDF_NAME_DP);
+ p = pdf_dict_geta(ctx, entry->obj, PDF_NAME(DecodeParms), PDF_NAME(DP));
if (pdf_is_array(ctx, f))
{
int len = pdf_array_len(ctx, f);
@@ -576,8 +576,8 @@ pdf_load_image_stream(fz_context *ctx, pdf_document *doc, int num, fz_compressio
dict = pdf_load_object(ctx, doc, num);
- len = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME_Length));
- obj = pdf_dict_get(ctx, dict, PDF_NAME_Filter);
+ len = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME(Length)));
+ obj = pdf_dict_get(ctx, dict, PDF_NAME(Filter));
len = pdf_guess_filter_length(len, pdf_to_name(ctx, obj));
n = pdf_array_len(ctx, obj);
for (i = 0; i < n; i++)