summaryrefslogtreecommitdiff
path: root/Build
diff options
context:
space:
mode:
authorAkira Kakuto <kakuto@fuk.kindai.ac.jp>2016-12-18 09:59:24 +0000
committerAkira Kakuto <kakuto@fuk.kindai.ac.jp>2016-12-18 09:59:24 +0000
commitb22cb23cdeac4ab3438e64d1687205825d432f51 (patch)
tree3260ca585f4bcb83d4a1c3a7fb927db106ef927c /Build
parent92c0a963ad9468c08d01c2a487d8ae382925389c (diff)
dvipdfm-x: Merge libdpx by Clerk Ma at https://github.com/clerkma/ptex-ng
git-svn-id: svn://tug.org/texlive/trunk@42741 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build')
-rw-r--r--Build/source/texk/dvipdfm-x/ChangeLog6
-rw-r--r--Build/source/texk/dvipdfm-x/dvi.c11
-rw-r--r--Build/source/texk/dvipdfm-x/dvi.h2
-rw-r--r--Build/source/texk/dvipdfm-x/dvipdfmx.c10
-rw-r--r--Build/source/texk/dvipdfm-x/mpost.c8
-rw-r--r--Build/source/texk/dvipdfm-x/pdfencoding.c2
-rw-r--r--Build/source/texk/dvipdfm-x/pdfobj.c12
-rw-r--r--Build/source/texk/dvipdfm-x/pdfparse.c4
-rw-r--r--Build/source/texk/dvipdfm-x/pdfparse.h2
-rw-r--r--Build/source/texk/dvipdfm-x/tt_cmap.c16
-rw-r--r--Build/source/texk/dvipdfm-x/type0.c3
-rw-r--r--Build/source/texk/dvipdfm-x/type1.c35
-rw-r--r--Build/source/texk/dvipdfm-x/vf.c5
-rw-r--r--Build/source/texk/dvipdfm-x/xbb.c176
14 files changed, 244 insertions, 48 deletions
diff --git a/Build/source/texk/dvipdfm-x/ChangeLog b/Build/source/texk/dvipdfm-x/ChangeLog
index 071a569e606..4f22fd02c72 100644
--- a/Build/source/texk/dvipdfm-x/ChangeLog
+++ b/Build/source/texk/dvipdfm-x/ChangeLog
@@ -1,3 +1,9 @@
+2016-12-18 Akira Kakuto <kakuto@fuk.kindai.ac.jp>
+
+ * dvi.c, dvi.h, dvipdfmx.c, mpost.c, pdfencoding.c, pdfobj.c,
+ pdfparse.c, pdfparse.h, tt_cmap.c, type0.c, type1.c, vf.c, xbb.c:
+ Merge libdpx by Clerk Ma at https://github.com/clerkma/ptex-ng.
+
2016-10-30 Akira Kakuto <kakuto@fuk.kindai.ac.jp>
* pdffont.c, pdfobj.h: Use (time_t)-1 for INVALID_EPOCH_VALUE.
diff --git a/Build/source/texk/dvipdfm-x/dvi.c b/Build/source/texk/dvipdfm-x/dvi.c
index cea0ef0a3e5..47e2feb63b0 100644
--- a/Build/source/texk/dvipdfm-x/dvi.c
+++ b/Build/source/texk/dvipdfm-x/dvi.c
@@ -942,7 +942,11 @@ dvi_locate_font (const char *tfm_name, spt_t ptsize)
return cur_id;
}
+#if defined(LIBDPX)
+int
+#else
static int
+#endif /* LIBDPX */
dvi_locate_native_font (const char *filename, uint32_t index,
spt_t ptsize, int layout_dir, int extend, int slant, int embolden)
{
@@ -1302,10 +1306,10 @@ dvi_rule (int32_t width, int32_t height)
}
void
-dvi_dir (unsigned char dir)
+dvi_dirchg (unsigned char dir)
{
if (verbose)
- fprintf(stderr, " > dvi_dir %d\n", dir);
+ fprintf(stderr, " > dvi_dirchg %d\n", dir);
dvi_state.d = dir;
pdf_dev_set_dirmode(dvi_state.d); /* 0: horizontal, 1,3: vertical */
}
@@ -2528,3 +2532,6 @@ dvi_scan_specials (int page_no,
return;
}
+#if defined(LIBDPX)
+#include "dvi_ng.c"
+#endif /* LIBDPX */
diff --git a/Build/source/texk/dvipdfm-x/dvi.h b/Build/source/texk/dvipdfm-x/dvi.h
index 38f137d5da8..77652ecd31e 100644
--- a/Build/source/texk/dvipdfm-x/dvi.h
+++ b/Build/source/texk/dvipdfm-x/dvi.h
@@ -67,7 +67,7 @@ extern void dvi_y (int32_t ch);
extern void dvi_y0 (void);
extern void dvi_z (int32_t ch);
extern void dvi_z0 (void);
-extern void dvi_dir (unsigned char dir);
+extern void dvi_dirchg(unsigned char dir);
extern void dvi_do_page (double paper_height, double x_offset, double y_offset);
extern void dvi_scan_specials (int page_no,
diff --git a/Build/source/texk/dvipdfm-x/dvipdfmx.c b/Build/source/texk/dvipdfm-x/dvipdfmx.c
index b089dbc225f..fb68318841c 100644
--- a/Build/source/texk/dvipdfm-x/dvipdfmx.c
+++ b/Build/source/texk/dvipdfm-x/dvipdfmx.c
@@ -66,7 +66,11 @@
int is_xdv = 0;
int translate_origin = 0;
+#if defined(LIBDPX)
+const char *my_name = "ApTeX";
+#else
const char *my_name;
+#endif /* LIBDPX */
int compat_mode = 0; /* 0 = dvipdfmx, 1 = dvipdfm */
@@ -916,6 +920,7 @@ do_mps_pages (void)
}
}
+#if !defined(LIBDPX)
/* Support to make DLL in W32TeX */
#define DLLPROC dlldvipdfmxmain
@@ -924,6 +929,7 @@ extern __declspec(dllexport) int DLLPROC (int argc, char *argv[]);
#else
#undef DLLPROC
#endif
+#endif /* !LIBDPX */
#if defined(MIKTEX)
# define main Main
@@ -933,7 +939,11 @@ int
#if defined(DLLPROC)
DLLPROC (int argc, char *argv[])
#else
+#if defined(LIBDPX)
+dvipdfmx_main (int argc, char *argv[])
+#else
main (int argc, char *argv[])
+#endif /* LIBDPX */
#endif
{
double dvi2pts;
diff --git a/Build/source/texk/dvipdfm-x/mpost.c b/Build/source/texk/dvipdfm-x/mpost.c
index 4be2adb6319..33b12f6f9af 100644
--- a/Build/source/texk/dvipdfm-x/mpost.c
+++ b/Build/source/texk/dvipdfm-x/mpost.c
@@ -263,7 +263,7 @@ mps_scan_bbox (const char **pp, const char *endptr, pdf_rect *bbox)
return 0;
}
}
- skip_line (pp, endptr);
+ pdfparse_skip_line (pp, endptr);
while (*pp < endptr && isspace((unsigned char)**pp))
(*pp)++;
}
@@ -285,13 +285,13 @@ skip_prolog (const char **start, const char *end)
break;
if (!strncmp(*start, "%%EndProlog", 11)) {
found_prolog = 1;
- skip_line(start, end);
+ pdfparse_skip_line(start, end);
break;
} else if (!strncmp(*start, "%%Page:", 7)) {
- skip_line(start, end);
+ pdfparse_skip_line(start, end);
break;
}
- skip_line(start, end);
+ pdfparse_skip_line(start, end);
}
if (!found_prolog) {
*start = save;
diff --git a/Build/source/texk/dvipdfm-x/pdfencoding.c b/Build/source/texk/dvipdfm-x/pdfencoding.c
index c792f47e431..ca8b4c6feff 100644
--- a/Build/source/texk/dvipdfm-x/pdfencoding.c
+++ b/Build/source/texk/dvipdfm-x/pdfencoding.c
@@ -318,7 +318,7 @@ load_encoding_file (const char *filename)
* Skip comment lines.
*/
while (p < endptr && p[0] == '%') {
- skip_line (&p, endptr);
+ pdfparse_skip_line (&p, endptr);
skip_white(&p, endptr);
}
if (p[0] == '/')
diff --git a/Build/source/texk/dvipdfm-x/pdfobj.c b/Build/source/texk/dvipdfm-x/pdfobj.c
index 3dadf0a140d..2076a83f8ed 100644
--- a/Build/source/texk/dvipdfm-x/pdfobj.c
+++ b/Build/source/texk/dvipdfm-x/pdfobj.c
@@ -455,6 +455,14 @@ dump_xref_stream (void)
pdf_release_obj(xref_stream);
}
+#if defined(LIBDPX)
+long
+pdf_output_stats (void)
+{
+ return pdf_output_file_position;
+}
+#endif /* LIBDPX */
+
void
pdf_out_flush (void)
{
@@ -496,14 +504,18 @@ pdf_out_flush (void)
pdf_out(pdf_output_file, format_buffer, length);
pdf_out(pdf_output_file, "%%EOF\n", 6);
+#if !defined(LIBDPX)
MESG("\n");
+#endif /* !LIBDPX */
if (verbose) {
if (compression_level > 0) {
MESG("Compression saved %ld bytes%s\n", compression_saved,
pdf_version < 5 ? ". Try \"-V 5\" for better compression" : "");
}
}
+#if !defined(LIBDPX)
MESG("%ld bytes written", pdf_output_file_position);
+#endif /* !LIBDPX */
MFCLOSE(pdf_output_file);
}
diff --git a/Build/source/texk/dvipdfm-x/pdfparse.c b/Build/source/texk/dvipdfm-x/pdfparse.c
index 182a64d6b3c..050eb988230 100644
--- a/Build/source/texk/dvipdfm-x/pdfparse.c
+++ b/Build/source/texk/dvipdfm-x/pdfparse.c
@@ -95,7 +95,7 @@ dump (const char *start, const char *end)
} while (0)
void
-skip_line (const char **start, const char *end)
+pdfparse_skip_line (const char **start, const char *end)
{
while (*start < end && **start != '\n' && **start != '\r')
(*start)++;
@@ -121,7 +121,7 @@ skip_white (const char **start, const char *end)
*/
while (*start < end && (is_space(**start) || **start == '%')) {
if (**start == '%')
- skip_line(start, end);
+ pdfparse_skip_line(start, end);
else
(*start)++;
}
diff --git a/Build/source/texk/dvipdfm-x/pdfparse.h b/Build/source/texk/dvipdfm-x/pdfparse.h
index c5adc1db778..f55469864c0 100644
--- a/Build/source/texk/dvipdfm-x/pdfparse.h
+++ b/Build/source/texk/dvipdfm-x/pdfparse.h
@@ -29,7 +29,7 @@
/* Please remove this */
extern void dump (const char *start, const char *end);
-extern void skip_line (const char **start, const char *end);
+extern void pdfparse_skip_line (const char **start, const char *end);
extern void skip_white (const char **start, const char *end);
extern char *parse_number (const char **start, const char *end);
diff --git a/Build/source/texk/dvipdfm-x/tt_cmap.c b/Build/source/texk/dvipdfm-x/tt_cmap.c
index f554dff9bed..9da12913f5b 100644
--- a/Build/source/texk/dvipdfm-x/tt_cmap.c
+++ b/Build/source/texk/dvipdfm-x/tt_cmap.c
@@ -902,10 +902,12 @@ handle_subst_glyphs (CMap *cmap,
}
#undef MAX_UNICODES
if (unicode_count == -1) {
- if (name)
- MESG("No Unicode mapping available: GID=%u, name=%s\n", gid, name);
- else
- MESG("No Unicode mapping available: GID=%u\n", gid);
+ if(verbose > VERBOSE_LEVEL_MIN) {
+ if (name)
+ MESG("No Unicode mapping available: GID=%u, name=%s\n", gid, name);
+ else
+ MESG("No Unicode mapping available: GID=%u\n", gid);
+ }
} else {
/* the Unicode characters go into wbuf[2] and following, in UTF16BE */
/* we rely on WBUF_SIZE being more than adequate for MAX_UNICODES */
@@ -1267,7 +1269,7 @@ otf_create_ToUnicode_stream (const char *font_name,
break;
}
}
- if (cmap_obj == NULL)
+ if (cmap_obj == NULL && verbose > VERBOSE_LEVEL_MIN)
WARN("Unable to read OpenType/TrueType Unicode cmap table.");
tt_cmap_release(ttcmap);
CMap_set_silent(0);
@@ -1871,7 +1873,11 @@ otf_load_Unicode_CMap (const char *map_name, int ttc_index, /* 0 for non-TTC fon
ttcmap = tt_cmap_read(sfont, 3, 1); /* Microsoft UCS2 */
if (!ttcmap) {
ttcmap = tt_cmap_read(sfont, 0, 3); /* Unicode 2.0 or later */
+#if defined(LIBDPX)
+ if (!ttcmap && verbose > VERBOSE_LEVEL_MIN) {
+#else
if (!ttcmap) {
+#endif /* LIBDPX */
ERROR("Unable to read OpenType/TrueType Unicode cmap table.");
}
}
diff --git a/Build/source/texk/dvipdfm-x/type0.c b/Build/source/texk/dvipdfm-x/type0.c
index a20e80dbe5a..493d7ef7a08 100644
--- a/Build/source/texk/dvipdfm-x/type0.c
+++ b/Build/source/texk/dvipdfm-x/type0.c
@@ -254,7 +254,8 @@ add_ToUnicode (Type0Font *font)
pdf_add_dict(font->fontdict,
pdf_new_name("ToUnicode"), tounicode);
} else {
- WARN("Failed to load ToUnicode CMap for font \"%s\"", fontname);
+ if (__verbose)
+ WARN("Failed to load ToUnicode CMap for font \"%s\"", fontname);
}
return;
diff --git a/Build/source/texk/dvipdfm-x/type1.c b/Build/source/texk/dvipdfm-x/type1.c
index 008c97d4ee1..b74030c986f 100644
--- a/Build/source/texk/dvipdfm-x/type1.c
+++ b/Build/source/texk/dvipdfm-x/type1.c
@@ -324,28 +324,14 @@ add_metrics (pdf_font *font, cff_font *cffont, char **enc_vec, double *widths, i
pdf_release_obj(tmp_array);
return;
}
- /* PLEASE FIX THIS
- * It's wrong to use TFM width here... We should warn if TFM width
- * and actual glyph width are different.
- */
tfm_id = tfm_open(pdf_font_get_mapname(font), 0);
for (code = firstchar; code <= lastchar; code++) {
if (usedchars[code]) {
double width;
if (tfm_id < 0) /* tfm is not found */
width = scaling * widths[cff_glyph_lookup(cffont, enc_vec[code])];
- else {
- double diff;
+ else
width = 1000. * tfm_get_width(tfm_id, code);
- diff = width -
- scaling * widths[cff_glyph_lookup(cffont, enc_vec[code])];
- if (fabs(diff) > 1.) {
- WARN("Glyph width mismatch for TFM and font (%s)",
- pdf_font_get_mapname(font));
- WARN("TFM: %g vs. Type1 font: %g",
- width, widths[cff_glyph_lookup(cffont, enc_vec[code])]);
- }
- }
pdf_add_array(tmp_array,
pdf_new_number(ROUND(width, 0.1)));
} else {
@@ -370,7 +356,7 @@ add_metrics (pdf_font *font, cff_font *cffont, char **enc_vec, double *widths, i
static int
-write_fontfile (pdf_font *font, cff_font *cffont, pdf_obj *pdfcharset)
+write_fontfile (pdf_font *font, cff_font *cffont)
{
pdf_obj *descriptor;
pdf_obj *fontfile, *stream_dict;
@@ -481,10 +467,7 @@ write_fontfile (pdf_font *font, cff_font *cffont, pdf_obj *pdfcharset)
pdf_new_name("Subtype"), pdf_new_name("Type1C"));
pdf_add_stream (fontfile, (void *) stream_data_ptr, offset);
pdf_release_obj(fontfile);
- pdf_add_dict(descriptor,
- pdf_new_name("CharSet"),
- pdf_new_string(pdf_stream_dataptr(pdfcharset),
- pdf_stream_length(pdfcharset)));
+
RELEASE(stream_data_ptr);
return offset;
@@ -495,7 +478,6 @@ int
pdf_font_load_type1 (pdf_font *font)
{
pdf_obj *fontdict;
- pdf_obj *pdfcharset; /* Actually string object */
int encoding_id;
char *usedchars, *ident;
char *fontname, *uniqueTag;
@@ -598,7 +580,6 @@ pdf_font_load_type1 (pdf_font *font)
/* Create CFF encoding, charset, sort glyphs */
#define MAX_GLYPHS 1024
GIDMap = NEW(MAX_GLYPHS, card16);
- pdfcharset = pdf_new_stream(0);
{
int prev, duplicate;
int gid;
@@ -671,11 +652,7 @@ pdf_font_load_type1 (pdf_font *font)
if (verbose > 2) {
MESG("/%s", glyph);
}
- /* CharSet is actually string object. */
- {
- pdf_add_stream(pdfcharset, "/", 1);
- pdf_add_stream(pdfcharset, glyph, strlen(glyph));
- }
+
}
}
if (cffont->encoding->num_supps > 0) {
@@ -799,12 +776,10 @@ pdf_font_load_type1 (pdf_font *font)
add_metrics(font, cffont, enc_vec, widths, num_glyphs);
- offset = write_fontfile(font, cffont, pdfcharset);
+ offset = write_fontfile(font, cffont);
if (verbose > 1)
MESG("[%u glyphs][%ld bytes]", num_glyphs, offset);
- pdf_release_obj(pdfcharset);
-
cff_close(cffont);
/* Cleanup */
diff --git a/Build/source/texk/dvipdfm-x/vf.c b/Build/source/texk/dvipdfm-x/vf.c
index 63a4810e1ab..a2b1a60f26a 100644
--- a/Build/source/texk/dvipdfm-x/vf.c
+++ b/Build/source/texk/dvipdfm-x/vf.c
@@ -504,7 +504,7 @@ void vf_set_char(int32_t ch, int vf_font)
}
break;
case PTEXDIR:
- dvi_dir (unsigned_byte (&start, end));
+ dvi_dirchg (unsigned_byte (&start, end));
break;
default:
if (opcode <= SET_CHAR_127) {
@@ -557,3 +557,6 @@ void vf_close_all_fonts(void)
RELEASE (vf_fonts);
return;
}
+#if defined(LIBDPX)
+#include "vf_ng.c"
+#endif /* LIBDPX */
diff --git a/Build/source/texk/dvipdfm-x/xbb.c b/Build/source/texk/dvipdfm-x/xbb.c
index 70fb5d3557d..6a0fda169b0 100644
--- a/Build/source/texk/dvipdfm-x/xbb.c
+++ b/Build/source/texk/dvipdfm-x/xbb.c
@@ -398,3 +398,179 @@ int extractbb (int argc, char *argv[])
return 0;
}
+
+#if defined(LIBDPX)
+static void do_aptex_bmp (FILE *fp, char *filename, pdf_rect * box)
+{
+ int width, height;
+ double xdensity, ydensity;
+
+ if (bmp_get_bbox(fp, &width, &height, &xdensity, &ydensity) < 0) {
+ WARN("%s does not look like a BMP file...\n", filename);
+ return;
+ }
+
+ box->llx = 0.0;
+ box->lly = 0.0;
+ box->urx = xdensity*width;
+ box->ury = ydensity*height;
+ return;
+}
+
+static void do_aptex_jpeg (FILE *fp, char *filename, pdf_rect * box)
+{
+ int width, height;
+ double xdensity, ydensity;
+
+ if (jpeg_get_bbox(fp, &width, &height, &xdensity, &ydensity) < 0) {
+ WARN("%s does not look like a JPEG file...\n", filename);
+ return;
+ }
+
+ box->llx = 0.0;
+ box->lly = 0.0;
+ box->urx = xdensity*width;
+ box->ury = ydensity*height;
+ return;
+}
+
+static void do_aptex_jp2 (FILE *fp, char *filename, pdf_rect * box)
+{
+ int width, height;
+ double xdensity, ydensity;
+
+ if (jp2_get_bbox(fp, &width, &height, &xdensity, &ydensity) < 0) {
+ WARN("%s does not look like a JP2/JPX file...\n", filename);
+ return;
+ }
+
+ box->llx = 0.0;
+ box->lly = 0.0;
+ box->urx = xdensity*width;
+ box->ury = ydensity*height;
+ return;
+}
+
+#ifdef HAVE_LIBPNG
+static void do_aptex_png (FILE *fp, char *filename, pdf_rect * box)
+{
+ uint32_t width, height;
+ double xdensity, ydensity;
+
+ if (png_get_bbox(fp, &width, &height, &xdensity, &ydensity) < 0) {
+ WARN("%s does not look like a PNG file...\n", filename);
+ return;
+ }
+
+ box->llx = 0.0;
+ box->lly = 0.0;
+ box->urx = xdensity*width;
+ box->ury = ydensity*height;
+ return;
+}
+#endif /* HAVE_LIBPNG */
+
+static void do_aptex_pdf (FILE *fp, char *filename, pdf_rect * box)
+{
+ pdf_obj *page;
+ pdf_file *pf;
+ int page_no = Include_Page;
+ int count;
+ pdf_rect bbox;
+
+ pf = pdf_open(filename, fp);
+ if (!pf) {
+ WARN("%s does not look like a PDF file...\n", filename);
+ return;
+ }
+ count = pdf_doc_get_page_count(pf);
+ page = pdf_doc_get_page(pf, page_no, PageBox, &bbox, NULL);
+
+ pdf_close(pf);
+
+ if (!page)
+ return;
+
+ pdf_release_obj(page);
+
+ box->llx = bbox.llx;
+ box->lly = bbox.lly;
+ box->urx = bbox.urx;
+ box->ury = bbox.ury;
+}
+
+void aptex_extractbb (char * pict, uint32_t page, uint32_t rect, pdf_rect * bbox)
+{
+ FILE *infile = NULL;
+ char *kpse_file_name = NULL;
+ int pictwd, pictht;
+ double xdensity, ydensity;
+
+ if (page == 0)
+ Include_Page = 1;
+ else
+ Include_Page = page;
+
+ PageBox = rect;
+
+ if (kpse_in_name_ok(pict))
+ {
+ infile = MFOPEN(pict, FOPEN_RBIN_MODE);
+ if (infile)
+ {
+ kpse_file_name = xstrdup(pict);
+ }
+ else
+ {
+ kpse_file_name = kpse_find_pict(pict);
+ if (kpse_file_name && kpse_in_name_ok(kpse_file_name))
+ infile = MFOPEN(kpse_file_name, FOPEN_RBIN_MODE);
+ }
+ }
+ if (infile == NULL)
+ {
+ WARN("Can't find file (%s), or it is forbidden to read ...skipping\n", pict);
+ goto cont;
+ }
+ if (check_for_bmp(infile))
+ {
+ do_aptex_bmp(infile, kpse_file_name, bbox);
+ goto cont;
+ }
+ if (check_for_jpeg(infile))
+ {
+ do_aptex_jpeg(infile, kpse_file_name, bbox);
+ goto cont;
+ }
+ if (check_for_jp2(infile))
+ {
+ do_aptex_jp2(infile, kpse_file_name, bbox);
+ goto cont;
+ }
+ if (check_for_pdf(infile))
+ {
+ pdf_files_init();
+ pdf_set_version(PDF_VERSION_MAX);
+ do_aptex_pdf(infile, kpse_file_name, bbox);
+ pdf_files_close();
+ goto cont;
+ }
+#ifdef HAVE_LIBPNG
+ if (check_for_png(infile))
+ {
+ do_aptex_png(infile, kpse_file_name, bbox);
+ goto cont;
+ }
+#endif /* HAVE_LIBPNG */
+ WARN("Can't handle file type for file named %s\n", pict);
+ bbox->llx = 0.0;
+ bbox->lly = 0.0;
+ bbox->urx = 0.0;
+ bbox->ury = 0.0;
+cont:
+ if (kpse_file_name)
+ RELEASE(kpse_file_name);
+ if (infile)
+ MFCLOSE(infile);
+}
+#endif /* LIBDPX */