Compare commits

..

No commits in common. "master" and "0.2.5" have entirely different histories.

4 changed files with 70 additions and 86 deletions

View file

@ -850,75 +850,73 @@ cnki_pdf_hn(cnki_t **param)
for (int i = 0, j = 0; i < ptr->text_size - 1;) { for (int i = 0, j = 0; i < ptr->text_size - 1;) {
switch (((unsigned char) ptr->text[i + 1] << 8) + (unsigned char) ptr->text[i]) { switch (((unsigned char) ptr->text[i + 1] << 8) + (unsigned char) ptr->text[i]) {
case 0x8001: case 0x8001:
if (ptr->address_next <= ptr->address) { if (ptr->address_next > ptr->address)
if (i + 7 >= ptr->text_size) { strcat(dictionary, "T*\n");
i += 2;
break;
}
conv_src[0] = ptr->text[i + 7];
conv_src[1] = ptr->text[i + 6];
//snprintf(buf, 64, "1 0 0 1 %d %d Tm\n")
//strcat(dictionary, buf);
conv_size = 6;
if (strconv(&conv_dst, "UTF-16BE",
conv_src, "GB18030", &conv_size) == 0) {
if (conv_size - 2 > 0) {
strcat(dictionary, "<");
for (int k = 0; k < conv_size - 2; k++) {
snprintf(conv_hex, 3,
"%02x", (unsigned char) conv_dst[k]);
strcat(dictionary, conv_hex);
}
strcat(dictionary, "> Tj\n");
}
free(conv_dst);
}
i += 8;
break;
}
strcat(dictionary, "T*\n");
case 0x8070: case 0x8070:
i += 4; if (ptr->address_next > ptr->address) {
i += 4;
if (ptr->address_next <= ptr->address) for (;;) {
break; if (i + 3 >= ptr->text_size ||
(unsigned char) ptr->text[i + 1] == 0x80)
break;
for (;;) { conv_src[0] = ptr->text[i + 3];
if (i + 3 >= ptr->text_size || conv_src[1] = ptr->text[i + 2];
(unsigned char) ptr->text[i + 1] == 0x80)
break;
conv_src[0] = ptr->text[i + 3]; //snprintf(buf, 64, "%f %f Td\n");
conv_src[1] = ptr->text[i + 2]; //strcat(dictionary, buf);
//snprintf(buf, 64, "1 0 0 1 %d %d Tm\n") conv_size = 6;
//strcat(dictionary, buf);
conv_size = 6; if (strconv(&conv_dst, "UTF-16BE",
conv_src, "GB18030", &conv_size) == 0) {
if (strconv(&conv_dst, "UTF-16BE", if (conv_size - 2 > 0) {
conv_src, "GB18030", &conv_size) == 0) { strcat(dictionary, "<feff");
if (conv_size - 2 > 0) { for (int k = 0; k < conv_size - 2; k++) {
strcat(dictionary, "<"); snprintf(conv_hex, 3,
for (int k = 0; k < conv_size - 2; k++) { "%02x", (unsigned char) conv_dst[k]);
snprintf(conv_hex, 3, strcat(dictionary, conv_hex);
"%02x", (unsigned char) conv_dst[k]); }
strcat(dictionary, conv_hex); strcat(dictionary, "> Tj\n");
} }
strcat(dictionary, "> Tj\n"); free(conv_dst);
} }
free(conv_dst);
i += 4;
} }
i += 4; break;
} }
if (i + 7 >= ptr->text_size) {
i += 2;
break;
}
conv_src[0] = ptr->text[i + 7];
conv_src[1] = ptr->text[i + 6];
//snprintf(buf, 64, "%f %f Td\n");
//strcat(dictionary, buf);
conv_size = 6;
if (strconv(&conv_dst, "UTF-16BE",
conv_src, "GB18030", &conv_size) == 0) {
if (conv_size - 2 > 0) {
strcat(dictionary, "<feff");
for (int k = 0; k < conv_size - 2; k++) {
snprintf(conv_hex, 3,
"%02x", (unsigned char) conv_dst[k]);
strcat(dictionary, conv_hex);
}
strcat(dictionary, "> Tj\n");
}
free(conv_dst);
}
i += 8;
break; break;
case 0x800a: case 0x800a:
if (i + 27 >= ptr->text_size || j >= ptr->image_length) { if (i + 27 >= ptr->text_size || j >= ptr->image_length) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022-2023, yzrh <yzrh@noema.org> * Copyright (c) 2022, yzrh <yzrh@noema.org>
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -31,6 +31,5 @@ strdec_jbig2(char **bitmap,
} }
jbig2_release_page(ctx, image); jbig2_release_page(ctx, image);
jbig2_ctx_free(ctx);
return 0; return 0;
} }

View file

@ -1,39 +1,19 @@
/* /*
* Copyright (c) 2020-2023, yzrh <yzrh@noema.org> * Copyright (c) 2020-2022, yzrh <yzrh@noema.org>
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <time.h> #include <time.h>
#include "version.h"
#include "md5.h" #include "md5.h"
#include "pdf.h" #include "pdf.h"
static int
_info_obj(pdf_object_t **pdf)
{
char dictionary[128] = "<<\n"
"/Producer (Melon " VERSION "." RELEASE "." PATCH EXTRA ")\n"
"/CreationDate (D:";
char buf[64];
time_t timestamp = time(NULL);
strftime(buf, 64, "%Y%m%d%H%M%S", gmtime(&timestamp));
strcat(dictionary, buf);
strcat(dictionary, "+00'00')\n>>");
return pdf_obj_append(pdf, 0, NULL, dictionary, NULL, 0);
}
int int
pdf_dump_obj(pdf_object_t **pdf, FILE **fp) pdf_dump_obj(pdf_object_t **pdf, FILE **fp)
{ {
if (*pdf == NULL || *fp == NULL || _info_obj(pdf) != 0) if (*pdf == NULL || *fp == NULL)
return 1; return 1;
long cur; long cur;
@ -172,11 +152,18 @@ pdf_dump_trailer(pdf_object_t **pdf, FILE **fp, int xref)
while (ptr->next != NULL) while (ptr->next != NULL)
ptr = ptr->next; ptr = ptr->next;
/*
* TODO: Document information dictionary
* `"/Producer (Melon)"'
* `"/CreationDate (D:YYYYMMDDHHmmSS+00'00')"'
*
* Trailer dictionary
* `"/Info %d 0 R"'
*/
fprintf(*fp, fprintf(*fp,
"/Size %d\n/Root %d 0 R\n/Info %d 0 R\n", "/Size %d\n/Root %d 0 R\n",
ptr->id + 1, ptr->id + 1,
pdf_get_catalog_id(pdf), pdf_get_catalog_id(pdf));
ptr->id);
fputs("/ID [", *fp); fputs("/ID [", *fp);

View file

@ -5,6 +5,6 @@
*/ */
#define VERSION "0" #define VERSION "0"
#define RELEASE "3" #define RELEASE "2"
#define PATCH "0" #define PATCH "5"
#define EXTRA "" #define EXTRA ""