From 5545f2236f9abc704ba6cc442841363b0ac5eb1b Mon Sep 17 00:00:00 2001 From: Peter Breitenlohner Date: Wed, 10 Jul 2013 15:35:21 +0000 Subject: dvipdfm-x: Continue merging dvipdfmx and xdvipdfmx git-svn-id: svn://tug.org/texlive/trunk@31156 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/dvipdfm-x/ChangeLog | 13 +- Build/source/texk/dvipdfm-x/Makefile.am | 18 +- Build/source/texk/dvipdfm-x/Makefile.in | 185 ++- Build/source/texk/dvipdfm-x/cff.c | 1507 ++++++++++++++++++++++++ Build/source/texk/dvipdfm-x/dvi.h | 109 ++ Build/source/texk/dvipdfm-x/mpost.c | 1686 +++++++++++++++++++++++++++ Build/source/texk/dvipdfm-x/pdfdev.h | 235 ++++ Build/source/texk/dvipdfm-x/pdfdoc.h | 157 +++ Build/source/texk/dvipdfm-x/pdfdraw.h | 184 +++ Build/source/texk/dvipdfm-x/src/cff.c | 1501 ------------------------ Build/source/texk/dvipdfm-x/src/dvi.c | 603 +++++++++- Build/source/texk/dvipdfm-x/src/dvi.h | 96 -- Build/source/texk/dvipdfm-x/src/dvipdfmx.c | 145 +-- Build/source/texk/dvipdfm-x/src/epdf.c | 3 - Build/source/texk/dvipdfm-x/src/mpost.c | 1674 -------------------------- Build/source/texk/dvipdfm-x/src/pdfdev.h | 228 ---- Build/source/texk/dvipdfm-x/src/pdfdoc.h | 143 --- Build/source/texk/dvipdfm-x/src/pdfdraw.h | 167 --- Build/source/texk/dvipdfm-x/src/xbb.c | 31 +- Build/source/texk/dvipdfm-x/xsrc/cff.c | 1501 ------------------------ Build/source/texk/dvipdfm-x/xsrc/dvi.c | 55 +- Build/source/texk/dvipdfm-x/xsrc/dvi.h | 105 -- Build/source/texk/dvipdfm-x/xsrc/dvipdfmx.c | 51 +- Build/source/texk/dvipdfm-x/xsrc/epdf.c | 3 - Build/source/texk/dvipdfm-x/xsrc/mpost.c | 1671 -------------------------- Build/source/texk/dvipdfm-x/xsrc/pdfdev.h | 233 ---- Build/source/texk/dvipdfm-x/xsrc/pdfdoc.h | 137 --- Build/source/texk/dvipdfm-x/xsrc/pdfdraw.h | 172 --- Build/source/texk/dvipdfm-x/xsrc/xbb.c | 57 +- 29 files changed, 4718 insertions(+), 7952 deletions(-) create mode 100644 Build/source/texk/dvipdfm-x/cff.c create mode 100644 Build/source/texk/dvipdfm-x/dvi.h create mode 100644 Build/source/texk/dvipdfm-x/mpost.c create mode 100644 Build/source/texk/dvipdfm-x/pdfdev.h create mode 100644 Build/source/texk/dvipdfm-x/pdfdoc.h create mode 100644 Build/source/texk/dvipdfm-x/pdfdraw.h delete mode 100644 Build/source/texk/dvipdfm-x/src/cff.c delete mode 100644 Build/source/texk/dvipdfm-x/src/dvi.h delete mode 100644 Build/source/texk/dvipdfm-x/src/mpost.c delete mode 100644 Build/source/texk/dvipdfm-x/src/pdfdev.h delete mode 100644 Build/source/texk/dvipdfm-x/src/pdfdoc.h delete mode 100644 Build/source/texk/dvipdfm-x/src/pdfdraw.h delete mode 100644 Build/source/texk/dvipdfm-x/xsrc/cff.c delete mode 100644 Build/source/texk/dvipdfm-x/xsrc/dvi.h delete mode 100644 Build/source/texk/dvipdfm-x/xsrc/mpost.c delete mode 100644 Build/source/texk/dvipdfm-x/xsrc/pdfdev.h delete mode 100644 Build/source/texk/dvipdfm-x/xsrc/pdfdoc.h delete mode 100644 Build/source/texk/dvipdfm-x/xsrc/pdfdraw.h (limited to 'Build/source/texk/dvipdfm-x') diff --git a/Build/source/texk/dvipdfm-x/ChangeLog b/Build/source/texk/dvipdfm-x/ChangeLog index d36393c5ad7..0b1fa9bb906 100644 --- a/Build/source/texk/dvipdfm-x/ChangeLog +++ b/Build/source/texk/dvipdfm-x/ChangeLog @@ -1,3 +1,14 @@ +2013-07-10 Peter Breitenlohner + + * Removed diffs between src/ and xsrc/ version of these files + and moved them to the top-level: cff.c, dvi.h, mpost.c, + pdfdev.h, pdfdoc.h, pdfdraw.h. + + * Reduced dvipdfmx/xdvipdfmx diffs in these files: + dvi.c, dvipdfmx.c, epdf.c, xbb.c. + + * *src/dvipdfmx.c: Use FILESTRCASEEQ instead of !STRN_CMP. + 2013-07-08 Peter Breitenlohner * Removed diffs between src/ and xsrc/ version of these files @@ -10,7 +21,7 @@ 2013-07-06 Akira Kakuto - * src/dvi.c, xsrc/dvi.c: Use !FILESTRCASEEQ instead of STR_CMP + * xsrc/dvi.c: Use !FILESTRCASEEQ instead of STR_CMP. 2013-07-05 Peter Breitenlohner diff --git a/Build/source/texk/dvipdfm-x/Makefile.am b/Build/source/texk/dvipdfm-x/Makefile.am index c650cc326fa..2bacfc0cd31 100644 --- a/Build/source/texk/dvipdfm-x/Makefile.am +++ b/Build/source/texk/dvipdfm-x/Makefile.am @@ -35,6 +35,7 @@ common_sources = \ agl.h \ bmpimage.c \ bmpimage.h \ + cff.c \ cff.h \ cff_dict.h \ cff_limits.h \ @@ -64,6 +65,7 @@ common_sources = \ dpxfile.h \ dpxutil.c \ dpxutil.h \ + dvi.h \ dvicodes.h \ epdf.h \ error.c \ @@ -75,6 +77,7 @@ common_sources = \ mem.h \ mfileio.c \ mfileio.h \ + mpost.c \ mpost.h \ numbers.c \ numbers.h \ @@ -83,6 +86,9 @@ common_sources = \ otl_opt.c \ otl_opt.h \ pdfcolor.h \ + pdfdev.h \ + pdfdoc.h \ + pdfdraw.h \ pdfencoding.c \ pdfencoding.h \ pdfencrypt.h \ @@ -146,23 +152,17 @@ common_sources = \ xbb.h dvipdfmx_sources = \ - src/cff.c \ src/cff_dict.c \ src/cidtype0.c \ src/dvi.c \ - src/dvi.h \ src/dvipdfmx.c \ dvipdfmx.h \ src/epdf.c \ src/jpegimage.c \ - src/mpost.c \ src/pdfcolor.c \ src/pdfdev.c \ - src/pdfdev.h \ src/pdfdoc.c \ - src/pdfdoc.h \ src/pdfdraw.c \ - src/pdfdraw.h \ src/pdfencrypt.c \ src/pdfnames.c \ src/pdfnames.h \ @@ -182,22 +182,16 @@ dvipdfmx_sources = \ src/xbb.c xdvipdfmx_sources = \ - xsrc/cff.c \ xsrc/cff_dict.c \ xsrc/cidtype0.c \ xsrc/dvi.c \ - xsrc/dvi.h \ xsrc/dvipdfmx.c \ xsrc/epdf.c \ xsrc/jpegimage.c \ - xsrc/mpost.c \ xsrc/pdfcolor.c \ xsrc/pdfdev.c \ - xsrc/pdfdev.h \ xsrc/pdfdoc.c \ - xsrc/pdfdoc.h \ xsrc/pdfdraw.c \ - xsrc/pdfdraw.h \ xsrc/pdfencrypt.c \ xsrc/pdfnames.c \ xsrc/pdfnames.h \ diff --git a/Build/source/texk/dvipdfm-x/Makefile.in b/Build/source/texk/dvipdfm-x/Makefile.in index 9ebe190797f..10d6a860a6e 100644 --- a/Build/source/texk/dvipdfm-x/Makefile.in +++ b/Build/source/texk/dvipdfm-x/Makefile.in @@ -154,13 +154,14 @@ am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = am__objects_1 = dvipdfmx-agl.$(OBJEXT) dvipdfmx-bmpimage.$(OBJEXT) \ - dvipdfmx-cid.$(OBJEXT) dvipdfmx-cidtype2.$(OBJEXT) \ - dvipdfmx-cmap.$(OBJEXT) dvipdfmx-cmap_read.$(OBJEXT) \ - dvipdfmx-cmap_write.$(OBJEXT) dvipdfmx-cs_type2.$(OBJEXT) \ - dvipdfmx-dpxconf.$(OBJEXT) dvipdfmx-dpxcrypt.$(OBJEXT) \ - dvipdfmx-dpxfile.$(OBJEXT) dvipdfmx-dpxutil.$(OBJEXT) \ - dvipdfmx-error.$(OBJEXT) dvipdfmx-fontmap.$(OBJEXT) \ - dvipdfmx-mem.$(OBJEXT) dvipdfmx-mfileio.$(OBJEXT) \ + dvipdfmx-cff.$(OBJEXT) dvipdfmx-cid.$(OBJEXT) \ + dvipdfmx-cidtype2.$(OBJEXT) dvipdfmx-cmap.$(OBJEXT) \ + dvipdfmx-cmap_read.$(OBJEXT) dvipdfmx-cmap_write.$(OBJEXT) \ + dvipdfmx-cs_type2.$(OBJEXT) dvipdfmx-dpxconf.$(OBJEXT) \ + dvipdfmx-dpxcrypt.$(OBJEXT) dvipdfmx-dpxfile.$(OBJEXT) \ + dvipdfmx-dpxutil.$(OBJEXT) dvipdfmx-error.$(OBJEXT) \ + dvipdfmx-fontmap.$(OBJEXT) dvipdfmx-mem.$(OBJEXT) \ + dvipdfmx-mfileio.$(OBJEXT) dvipdfmx-mpost.$(OBJEXT) \ dvipdfmx-numbers.$(OBJEXT) dvipdfmx-otl_conf.$(OBJEXT) \ dvipdfmx-otl_opt.$(OBJEXT) dvipdfmx-pdfencoding.$(OBJEXT) \ dvipdfmx-pdffont.$(OBJEXT) dvipdfmx-pdfparse.$(OBJEXT) \ @@ -175,11 +176,10 @@ am__objects_1 = dvipdfmx-agl.$(OBJEXT) dvipdfmx-bmpimage.$(OBJEXT) \ dvipdfmx-tt_table.$(OBJEXT) dvipdfmx-type0.$(OBJEXT) \ dvipdfmx-unicode.$(OBJEXT) dvipdfmx-vf.$(OBJEXT) am__dirstamp = $(am__leading_dot)dirstamp -am__objects_2 = src/dvipdfmx-cff.$(OBJEXT) \ - src/dvipdfmx-cff_dict.$(OBJEXT) \ +am__objects_2 = src/dvipdfmx-cff_dict.$(OBJEXT) \ src/dvipdfmx-cidtype0.$(OBJEXT) src/dvipdfmx-dvi.$(OBJEXT) \ src/dvipdfmx-dvipdfmx.$(OBJEXT) src/dvipdfmx-epdf.$(OBJEXT) \ - src/dvipdfmx-jpegimage.$(OBJEXT) src/dvipdfmx-mpost.$(OBJEXT) \ + src/dvipdfmx-jpegimage.$(OBJEXT) \ src/dvipdfmx-pdfcolor.$(OBJEXT) src/dvipdfmx-pdfdev.$(OBJEXT) \ src/dvipdfmx-pdfdoc.$(OBJEXT) src/dvipdfmx-pdfdraw.$(OBJEXT) \ src/dvipdfmx-pdfencrypt.$(OBJEXT) \ @@ -199,13 +199,14 @@ am__DEPENDENCIES_1 = dvipdfmx_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_1) am__objects_3 = xdvipdfmx-agl.$(OBJEXT) xdvipdfmx-bmpimage.$(OBJEXT) \ - xdvipdfmx-cid.$(OBJEXT) xdvipdfmx-cidtype2.$(OBJEXT) \ - xdvipdfmx-cmap.$(OBJEXT) xdvipdfmx-cmap_read.$(OBJEXT) \ - xdvipdfmx-cmap_write.$(OBJEXT) xdvipdfmx-cs_type2.$(OBJEXT) \ - xdvipdfmx-dpxconf.$(OBJEXT) xdvipdfmx-dpxcrypt.$(OBJEXT) \ - xdvipdfmx-dpxfile.$(OBJEXT) xdvipdfmx-dpxutil.$(OBJEXT) \ - xdvipdfmx-error.$(OBJEXT) xdvipdfmx-fontmap.$(OBJEXT) \ - xdvipdfmx-mem.$(OBJEXT) xdvipdfmx-mfileio.$(OBJEXT) \ + xdvipdfmx-cff.$(OBJEXT) xdvipdfmx-cid.$(OBJEXT) \ + xdvipdfmx-cidtype2.$(OBJEXT) xdvipdfmx-cmap.$(OBJEXT) \ + xdvipdfmx-cmap_read.$(OBJEXT) xdvipdfmx-cmap_write.$(OBJEXT) \ + xdvipdfmx-cs_type2.$(OBJEXT) xdvipdfmx-dpxconf.$(OBJEXT) \ + xdvipdfmx-dpxcrypt.$(OBJEXT) xdvipdfmx-dpxfile.$(OBJEXT) \ + xdvipdfmx-dpxutil.$(OBJEXT) xdvipdfmx-error.$(OBJEXT) \ + xdvipdfmx-fontmap.$(OBJEXT) xdvipdfmx-mem.$(OBJEXT) \ + xdvipdfmx-mfileio.$(OBJEXT) xdvipdfmx-mpost.$(OBJEXT) \ xdvipdfmx-numbers.$(OBJEXT) xdvipdfmx-otl_conf.$(OBJEXT) \ xdvipdfmx-otl_opt.$(OBJEXT) xdvipdfmx-pdfencoding.$(OBJEXT) \ xdvipdfmx-pdffont.$(OBJEXT) xdvipdfmx-pdfparse.$(OBJEXT) \ @@ -219,13 +220,11 @@ am__objects_3 = xdvipdfmx-agl.$(OBJEXT) xdvipdfmx-bmpimage.$(OBJEXT) \ xdvipdfmx-tt_gsub.$(OBJEXT) xdvipdfmx-tt_post.$(OBJEXT) \ xdvipdfmx-tt_table.$(OBJEXT) xdvipdfmx-type0.$(OBJEXT) \ xdvipdfmx-unicode.$(OBJEXT) xdvipdfmx-vf.$(OBJEXT) -am__objects_4 = xsrc/xdvipdfmx-cff.$(OBJEXT) \ - xsrc/xdvipdfmx-cff_dict.$(OBJEXT) \ +am__objects_4 = xsrc/xdvipdfmx-cff_dict.$(OBJEXT) \ xsrc/xdvipdfmx-cidtype0.$(OBJEXT) xsrc/xdvipdfmx-dvi.$(OBJEXT) \ xsrc/xdvipdfmx-dvipdfmx.$(OBJEXT) \ xsrc/xdvipdfmx-epdf.$(OBJEXT) \ xsrc/xdvipdfmx-jpegimage.$(OBJEXT) \ - xsrc/xdvipdfmx-mpost.$(OBJEXT) \ xsrc/xdvipdfmx-pdfcolor.$(OBJEXT) \ xsrc/xdvipdfmx-pdfdev.$(OBJEXT) \ xsrc/xdvipdfmx-pdfdoc.$(OBJEXT) \ @@ -683,6 +682,7 @@ common_sources = \ agl.h \ bmpimage.c \ bmpimage.h \ + cff.c \ cff.h \ cff_dict.h \ cff_limits.h \ @@ -712,6 +712,7 @@ common_sources = \ dpxfile.h \ dpxutil.c \ dpxutil.h \ + dvi.h \ dvicodes.h \ epdf.h \ error.c \ @@ -723,6 +724,7 @@ common_sources = \ mem.h \ mfileio.c \ mfileio.h \ + mpost.c \ mpost.h \ numbers.c \ numbers.h \ @@ -731,6 +733,9 @@ common_sources = \ otl_opt.c \ otl_opt.h \ pdfcolor.h \ + pdfdev.h \ + pdfdoc.h \ + pdfdraw.h \ pdfencoding.c \ pdfencoding.h \ pdfencrypt.h \ @@ -794,23 +799,17 @@ common_sources = \ xbb.h dvipdfmx_sources = \ - src/cff.c \ src/cff_dict.c \ src/cidtype0.c \ src/dvi.c \ - src/dvi.h \ src/dvipdfmx.c \ dvipdfmx.h \ src/epdf.c \ src/jpegimage.c \ - src/mpost.c \ src/pdfcolor.c \ src/pdfdev.c \ - src/pdfdev.h \ src/pdfdoc.c \ - src/pdfdoc.h \ src/pdfdraw.c \ - src/pdfdraw.h \ src/pdfencrypt.c \ src/pdfnames.c \ src/pdfnames.h \ @@ -830,22 +829,16 @@ dvipdfmx_sources = \ src/xbb.c xdvipdfmx_sources = \ - xsrc/cff.c \ xsrc/cff_dict.c \ xsrc/cidtype0.c \ xsrc/dvi.c \ - xsrc/dvi.h \ xsrc/dvipdfmx.c \ xsrc/epdf.c \ xsrc/jpegimage.c \ - xsrc/mpost.c \ xsrc/pdfcolor.c \ xsrc/pdfdev.c \ - xsrc/pdfdev.h \ xsrc/pdfdoc.c \ - xsrc/pdfdoc.h \ xsrc/pdfdraw.c \ - xsrc/pdfdraw.h \ xsrc/pdfencrypt.c \ xsrc/pdfnames.c \ xsrc/pdfnames.h \ @@ -1009,8 +1002,6 @@ src/$(am__dirstamp): src/$(DEPDIR)/$(am__dirstamp): @$(MKDIR_P) src/$(DEPDIR) @: > src/$(DEPDIR)/$(am__dirstamp) -src/dvipdfmx-cff.$(OBJEXT): src/$(am__dirstamp) \ - src/$(DEPDIR)/$(am__dirstamp) src/dvipdfmx-cff_dict.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/dvipdfmx-cidtype0.$(OBJEXT): src/$(am__dirstamp) \ @@ -1023,8 +1014,6 @@ src/dvipdfmx-epdf.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/dvipdfmx-jpegimage.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) -src/dvipdfmx-mpost.$(OBJEXT): src/$(am__dirstamp) \ - src/$(DEPDIR)/$(am__dirstamp) src/dvipdfmx-pdfcolor.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/dvipdfmx-pdfdev.$(OBJEXT): src/$(am__dirstamp) \ @@ -1073,8 +1062,6 @@ xsrc/$(am__dirstamp): xsrc/$(DEPDIR)/$(am__dirstamp): @$(MKDIR_P) xsrc/$(DEPDIR) @: > xsrc/$(DEPDIR)/$(am__dirstamp) -xsrc/xdvipdfmx-cff.$(OBJEXT): xsrc/$(am__dirstamp) \ - xsrc/$(DEPDIR)/$(am__dirstamp) xsrc/xdvipdfmx-cff_dict.$(OBJEXT): xsrc/$(am__dirstamp) \ xsrc/$(DEPDIR)/$(am__dirstamp) xsrc/xdvipdfmx-cidtype0.$(OBJEXT): xsrc/$(am__dirstamp) \ @@ -1087,8 +1074,6 @@ xsrc/xdvipdfmx-epdf.$(OBJEXT): xsrc/$(am__dirstamp) \ xsrc/$(DEPDIR)/$(am__dirstamp) xsrc/xdvipdfmx-jpegimage.$(OBJEXT): xsrc/$(am__dirstamp) \ xsrc/$(DEPDIR)/$(am__dirstamp) -xsrc/xdvipdfmx-mpost.$(OBJEXT): xsrc/$(am__dirstamp) \ - xsrc/$(DEPDIR)/$(am__dirstamp) xsrc/xdvipdfmx-pdfcolor.$(OBJEXT): xsrc/$(am__dirstamp) \ xsrc/$(DEPDIR)/$(am__dirstamp) xsrc/xdvipdfmx-pdfdev.$(OBJEXT): xsrc/$(am__dirstamp) \ @@ -1178,6 +1163,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/call_dvipdfmx-callexe.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dvipdfmx-agl.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dvipdfmx-bmpimage.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dvipdfmx-cff.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dvipdfmx-cid.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dvipdfmx-cidtype2.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dvipdfmx-cmap.Po@am__quote@ @@ -1192,6 +1178,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dvipdfmx-fontmap.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dvipdfmx-mem.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dvipdfmx-mfileio.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dvipdfmx-mpost.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dvipdfmx-numbers.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dvipdfmx-otl_conf.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dvipdfmx-otl_opt.Po@am__quote@ @@ -1220,6 +1207,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dvipdfmx-vf.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xdvipdfmx-agl.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xdvipdfmx-bmpimage.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xdvipdfmx-cff.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xdvipdfmx-cid.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xdvipdfmx-cidtype2.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xdvipdfmx-cmap.Po@am__quote@ @@ -1234,6 +1222,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xdvipdfmx-fontmap.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xdvipdfmx-mem.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xdvipdfmx-mfileio.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xdvipdfmx-mpost.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xdvipdfmx-numbers.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xdvipdfmx-otl_conf.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xdvipdfmx-otl_opt.Po@am__quote@ @@ -1261,14 +1250,12 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xdvipdfmx-type0.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xdvipdfmx-unicode.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xdvipdfmx-vf.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dvipdfmx-cff.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dvipdfmx-cff_dict.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dvipdfmx-cidtype0.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dvipdfmx-dvi.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dvipdfmx-dvipdfmx.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dvipdfmx-epdf.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dvipdfmx-jpegimage.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dvipdfmx-mpost.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dvipdfmx-pdfcolor.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dvipdfmx-pdfdev.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dvipdfmx-pdfdoc.Po@am__quote@ @@ -1288,14 +1275,12 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dvipdfmx-type1.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dvipdfmx-type1c.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dvipdfmx-xbb.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@xsrc/$(DEPDIR)/xdvipdfmx-cff.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@xsrc/$(DEPDIR)/xdvipdfmx-cff_dict.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@xsrc/$(DEPDIR)/xdvipdfmx-cidtype0.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@xsrc/$(DEPDIR)/xdvipdfmx-dvi.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@xsrc/$(DEPDIR)/xdvipdfmx-dvipdfmx.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@xsrc/$(DEPDIR)/xdvipdfmx-epdf.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@xsrc/$(DEPDIR)/xdvipdfmx-jpegimage.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@xsrc/$(DEPDIR)/xdvipdfmx-mpost.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@xsrc/$(DEPDIR)/xdvipdfmx-pdfcolor.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@xsrc/$(DEPDIR)/xdvipdfmx-pdfdev.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@xsrc/$(DEPDIR)/xdvipdfmx-pdfdoc.Po@am__quote@ @@ -1382,6 +1367,20 @@ dvipdfmx-bmpimage.obj: bmpimage.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o dvipdfmx-bmpimage.obj `if test -f 'bmpimage.c'; then $(CYGPATH_W) 'bmpimage.c'; else $(CYGPATH_W) '$(srcdir)/bmpimage.c'; fi` +dvipdfmx-cff.o: cff.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT dvipdfmx-cff.o -MD -MP -MF $(DEPDIR)/dvipdfmx-cff.Tpo -c -o dvipdfmx-cff.o `test -f 'cff.c' || echo '$(srcdir)/'`cff.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/dvipdfmx-cff.Tpo $(DEPDIR)/dvipdfmx-cff.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cff.c' object='dvipdfmx-cff.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o dvipdfmx-cff.o `test -f 'cff.c' || echo '$(srcdir)/'`cff.c + +dvipdfmx-cff.obj: cff.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT dvipdfmx-cff.obj -MD -MP -MF $(DEPDIR)/dvipdfmx-cff.Tpo -c -o dvipdfmx-cff.obj `if test -f 'cff.c'; then $(CYGPATH_W) 'cff.c'; else $(CYGPATH_W) '$(srcdir)/cff.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/dvipdfmx-cff.Tpo $(DEPDIR)/dvipdfmx-cff.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cff.c' object='dvipdfmx-cff.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o dvipdfmx-cff.obj `if test -f 'cff.c'; then $(CYGPATH_W) 'cff.c'; else $(CYGPATH_W) '$(srcdir)/cff.c'; fi` + dvipdfmx-cid.o: cid.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT dvipdfmx-cid.o -MD -MP -MF $(DEPDIR)/dvipdfmx-cid.Tpo -c -o dvipdfmx-cid.o `test -f 'cid.c' || echo '$(srcdir)/'`cid.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/dvipdfmx-cid.Tpo $(DEPDIR)/dvipdfmx-cid.Po @@ -1578,6 +1577,20 @@ dvipdfmx-mfileio.obj: mfileio.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o dvipdfmx-mfileio.obj `if test -f 'mfileio.c'; then $(CYGPATH_W) 'mfileio.c'; else $(CYGPATH_W) '$(srcdir)/mfileio.c'; fi` +dvipdfmx-mpost.o: mpost.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT dvipdfmx-mpost.o -MD -MP -MF $(DEPDIR)/dvipdfmx-mpost.Tpo -c -o dvipdfmx-mpost.o `test -f 'mpost.c' || echo '$(srcdir)/'`mpost.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/dvipdfmx-mpost.Tpo $(DEPDIR)/dvipdfmx-mpost.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mpost.c' object='dvipdfmx-mpost.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o dvipdfmx-mpost.o `test -f 'mpost.c' || echo '$(srcdir)/'`mpost.c + +dvipdfmx-mpost.obj: mpost.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT dvipdfmx-mpost.obj -MD -MP -MF $(DEPDIR)/dvipdfmx-mpost.Tpo -c -o dvipdfmx-mpost.obj `if test -f 'mpost.c'; then $(CYGPATH_W) 'mpost.c'; else $(CYGPATH_W) '$(srcdir)/mpost.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/dvipdfmx-mpost.Tpo $(DEPDIR)/dvipdfmx-mpost.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mpost.c' object='dvipdfmx-mpost.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o dvipdfmx-mpost.obj `if test -f 'mpost.c'; then $(CYGPATH_W) 'mpost.c'; else $(CYGPATH_W) '$(srcdir)/mpost.c'; fi` + dvipdfmx-numbers.o: numbers.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT dvipdfmx-numbers.o -MD -MP -MF $(DEPDIR)/dvipdfmx-numbers.Tpo -c -o dvipdfmx-numbers.o `test -f 'numbers.c' || echo '$(srcdir)/'`numbers.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/dvipdfmx-numbers.Tpo $(DEPDIR)/dvipdfmx-numbers.Po @@ -1942,20 +1955,6 @@ dvipdfmx-vf.obj: vf.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o dvipdfmx-vf.obj `if test -f 'vf.c'; then $(CYGPATH_W) 'vf.c'; else $(CYGPATH_W) '$(srcdir)/vf.c'; fi` -src/dvipdfmx-cff.o: src/cff.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/dvipdfmx-cff.o -MD -MP -MF src/$(DEPDIR)/dvipdfmx-cff.Tpo -c -o src/dvipdfmx-cff.o `test -f 'src/cff.c' || echo '$(srcdir)/'`src/cff.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/dvipdfmx-cff.Tpo src/$(DEPDIR)/dvipdfmx-cff.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/cff.c' object='src/dvipdfmx-cff.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/dvipdfmx-cff.o `test -f 'src/cff.c' || echo '$(srcdir)/'`src/cff.c - -src/dvipdfmx-cff.obj: src/cff.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/dvipdfmx-cff.obj -MD -MP -MF src/$(DEPDIR)/dvipdfmx-cff.Tpo -c -o src/dvipdfmx-cff.obj `if test -f 'src/cff.c'; then $(CYGPATH_W) 'src/cff.c'; else $(CYGPATH_W) '$(srcdir)/src/cff.c'; fi` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/dvipdfmx-cff.Tpo src/$(DEPDIR)/dvipdfmx-cff.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/cff.c' object='src/dvipdfmx-cff.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/dvipdfmx-cff.obj `if test -f 'src/cff.c'; then $(CYGPATH_W) 'src/cff.c'; else $(CYGPATH_W) '$(srcdir)/src/cff.c'; fi` - src/dvipdfmx-cff_dict.o: src/cff_dict.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/dvipdfmx-cff_dict.o -MD -MP -MF src/$(DEPDIR)/dvipdfmx-cff_dict.Tpo -c -o src/dvipdfmx-cff_dict.o `test -f 'src/cff_dict.c' || echo '$(srcdir)/'`src/cff_dict.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/dvipdfmx-cff_dict.Tpo src/$(DEPDIR)/dvipdfmx-cff_dict.Po @@ -2040,20 +2039,6 @@ src/dvipdfmx-jpegimage.obj: src/jpegimage.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/dvipdfmx-jpegimage.obj `if test -f 'src/jpegimage.c'; then $(CYGPATH_W) 'src/jpegimage.c'; else $(CYGPATH_W) '$(srcdir)/src/jpegimage.c'; fi` -src/dvipdfmx-mpost.o: src/mpost.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/dvipdfmx-mpost.o -MD -MP -MF src/$(DEPDIR)/dvipdfmx-mpost.Tpo -c -o src/dvipdfmx-mpost.o `test -f 'src/mpost.c' || echo '$(srcdir)/'`src/mpost.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/dvipdfmx-mpost.Tpo src/$(DEPDIR)/dvipdfmx-mpost.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/mpost.c' object='src/dvipdfmx-mpost.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/dvipdfmx-mpost.o `test -f 'src/mpost.c' || echo '$(srcdir)/'`src/mpost.c - -src/dvipdfmx-mpost.obj: src/mpost.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/dvipdfmx-mpost.obj -MD -MP -MF src/$(DEPDIR)/dvipdfmx-mpost.Tpo -c -o src/dvipdfmx-mpost.obj `if test -f 'src/mpost.c'; then $(CYGPATH_W) 'src/mpost.c'; else $(CYGPATH_W) '$(srcdir)/src/mpost.c'; fi` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/dvipdfmx-mpost.Tpo src/$(DEPDIR)/dvipdfmx-mpost.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/mpost.c' object='src/dvipdfmx-mpost.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/dvipdfmx-mpost.obj `if test -f 'src/mpost.c'; then $(CYGPATH_W) 'src/mpost.c'; else $(CYGPATH_W) '$(srcdir)/src/mpost.c'; fi` - src/dvipdfmx-pdfcolor.o: src/pdfcolor.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(dvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/dvipdfmx-pdfcolor.o -MD -MP -MF src/$(DEPDIR)/dvipdfmx-pdfcolor.Tpo -c -o src/dvipdfmx-pdfcolor.o `test -f 'src/pdfcolor.c' || echo '$(srcdir)/'`src/pdfcolor.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/dvipdfmx-pdfcolor.Tpo src/$(DEPDIR)/dvipdfmx-pdfcolor.Po @@ -2348,6 +2333,20 @@ xdvipdfmx-bmpimage.obj: bmpimage.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o xdvipdfmx-bmpimage.obj `if test -f 'bmpimage.c'; then $(CYGPATH_W) 'bmpimage.c'; else $(CYGPATH_W) '$(srcdir)/bmpimage.c'; fi` +xdvipdfmx-cff.o: cff.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT xdvipdfmx-cff.o -MD -MP -MF $(DEPDIR)/xdvipdfmx-cff.Tpo -c -o xdvipdfmx-cff.o `test -f 'cff.c' || echo '$(srcdir)/'`cff.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/xdvipdfmx-cff.Tpo $(DEPDIR)/xdvipdfmx-cff.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cff.c' object='xdvipdfmx-cff.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o xdvipdfmx-cff.o `test -f 'cff.c' || echo '$(srcdir)/'`cff.c + +xdvipdfmx-cff.obj: cff.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT xdvipdfmx-cff.obj -MD -MP -MF $(DEPDIR)/xdvipdfmx-cff.Tpo -c -o xdvipdfmx-cff.obj `if test -f 'cff.c'; then $(CYGPATH_W) 'cff.c'; else $(CYGPATH_W) '$(srcdir)/cff.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/xdvipdfmx-cff.Tpo $(DEPDIR)/xdvipdfmx-cff.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cff.c' object='xdvipdfmx-cff.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o xdvipdfmx-cff.obj `if test -f 'cff.c'; then $(CYGPATH_W) 'cff.c'; else $(CYGPATH_W) '$(srcdir)/cff.c'; fi` + xdvipdfmx-cid.o: cid.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT xdvipdfmx-cid.o -MD -MP -MF $(DEPDIR)/xdvipdfmx-cid.Tpo -c -o xdvipdfmx-cid.o `test -f 'cid.c' || echo '$(srcdir)/'`cid.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/xdvipdfmx-cid.Tpo $(DEPDIR)/xdvipdfmx-cid.Po @@ -2544,6 +2543,20 @@ xdvipdfmx-mfileio.obj: mfileio.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o xdvipdfmx-mfileio.obj `if test -f 'mfileio.c'; then $(CYGPATH_W) 'mfileio.c'; else $(CYGPATH_W) '$(srcdir)/mfileio.c'; fi` +xdvipdfmx-mpost.o: mpost.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT xdvipdfmx-mpost.o -MD -MP -MF $(DEPDIR)/xdvipdfmx-mpost.Tpo -c -o xdvipdfmx-mpost.o `test -f 'mpost.c' || echo '$(srcdir)/'`mpost.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/xdvipdfmx-mpost.Tpo $(DEPDIR)/xdvipdfmx-mpost.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mpost.c' object='xdvipdfmx-mpost.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o xdvipdfmx-mpost.o `test -f 'mpost.c' || echo '$(srcdir)/'`mpost.c + +xdvipdfmx-mpost.obj: mpost.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT xdvipdfmx-mpost.obj -MD -MP -MF $(DEPDIR)/xdvipdfmx-mpost.Tpo -c -o xdvipdfmx-mpost.obj `if test -f 'mpost.c'; then $(CYGPATH_W) 'mpost.c'; else $(CYGPATH_W) '$(srcdir)/mpost.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/xdvipdfmx-mpost.Tpo $(DEPDIR)/xdvipdfmx-mpost.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mpost.c' object='xdvipdfmx-mpost.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o xdvipdfmx-mpost.obj `if test -f 'mpost.c'; then $(CYGPATH_W) 'mpost.c'; else $(CYGPATH_W) '$(srcdir)/mpost.c'; fi` + xdvipdfmx-numbers.o: numbers.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT xdvipdfmx-numbers.o -MD -MP -MF $(DEPDIR)/xdvipdfmx-numbers.Tpo -c -o xdvipdfmx-numbers.o `test -f 'numbers.c' || echo '$(srcdir)/'`numbers.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/xdvipdfmx-numbers.Tpo $(DEPDIR)/xdvipdfmx-numbers.Po @@ -2908,20 +2921,6 @@ xdvipdfmx-vf.obj: vf.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o xdvipdfmx-vf.obj `if test -f 'vf.c'; then $(CYGPATH_W) 'vf.c'; else $(CYGPATH_W) '$(srcdir)/vf.c'; fi` -xsrc/xdvipdfmx-cff.o: xsrc/cff.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT xsrc/xdvipdfmx-cff.o -MD -MP -MF xsrc/$(DEPDIR)/xdvipdfmx-cff.Tpo -c -o xsrc/xdvipdfmx-cff.o `test -f 'xsrc/cff.c' || echo '$(srcdir)/'`xsrc/cff.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) xsrc/$(DEPDIR)/xdvipdfmx-cff.Tpo xsrc/$(DEPDIR)/xdvipdfmx-cff.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='xsrc/cff.c' object='xsrc/xdvipdfmx-cff.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o xsrc/xdvipdfmx-cff.o `test -f 'xsrc/cff.c' || echo '$(srcdir)/'`xsrc/cff.c - -xsrc/xdvipdfmx-cff.obj: xsrc/cff.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT xsrc/xdvipdfmx-cff.obj -MD -MP -MF xsrc/$(DEPDIR)/xdvipdfmx-cff.Tpo -c -o xsrc/xdvipdfmx-cff.obj `if test -f 'xsrc/cff.c'; then $(CYGPATH_W) 'xsrc/cff.c'; else $(CYGPATH_W) '$(srcdir)/xsrc/cff.c'; fi` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) xsrc/$(DEPDIR)/xdvipdfmx-cff.Tpo xsrc/$(DEPDIR)/xdvipdfmx-cff.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='xsrc/cff.c' object='xsrc/xdvipdfmx-cff.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o xsrc/xdvipdfmx-cff.obj `if test -f 'xsrc/cff.c'; then $(CYGPATH_W) 'xsrc/cff.c'; else $(CYGPATH_W) '$(srcdir)/xsrc/cff.c'; fi` - xsrc/xdvipdfmx-cff_dict.o: xsrc/cff_dict.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT xsrc/xdvipdfmx-cff_dict.o -MD -MP -MF xsrc/$(DEPDIR)/xdvipdfmx-cff_dict.Tpo -c -o xsrc/xdvipdfmx-cff_dict.o `test -f 'xsrc/cff_dict.c' || echo '$(srcdir)/'`xsrc/cff_dict.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) xsrc/$(DEPDIR)/xdvipdfmx-cff_dict.Tpo xsrc/$(DEPDIR)/xdvipdfmx-cff_dict.Po @@ -3006,20 +3005,6 @@ xsrc/xdvipdfmx-jpegimage.obj: xsrc/jpegimage.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o xsrc/xdvipdfmx-jpegimage.obj `if test -f 'xsrc/jpegimage.c'; then $(CYGPATH_W) 'xsrc/jpegimage.c'; else $(CYGPATH_W) '$(srcdir)/xsrc/jpegimage.c'; fi` -xsrc/xdvipdfmx-mpost.o: xsrc/mpost.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT xsrc/xdvipdfmx-mpost.o -MD -MP -MF xsrc/$(DEPDIR)/xdvipdfmx-mpost.Tpo -c -o xsrc/xdvipdfmx-mpost.o `test -f 'xsrc/mpost.c' || echo '$(srcdir)/'`xsrc/mpost.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) xsrc/$(DEPDIR)/xdvipdfmx-mpost.Tpo xsrc/$(DEPDIR)/xdvipdfmx-mpost.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='xsrc/mpost.c' object='xsrc/xdvipdfmx-mpost.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o xsrc/xdvipdfmx-mpost.o `test -f 'xsrc/mpost.c' || echo '$(srcdir)/'`xsrc/mpost.c - -xsrc/xdvipdfmx-mpost.obj: xsrc/mpost.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT xsrc/xdvipdfmx-mpost.obj -MD -MP -MF xsrc/$(DEPDIR)/xdvipdfmx-mpost.Tpo -c -o xsrc/xdvipdfmx-mpost.obj `if test -f 'xsrc/mpost.c'; then $(CYGPATH_W) 'xsrc/mpost.c'; else $(CYGPATH_W) '$(srcdir)/xsrc/mpost.c'; fi` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) xsrc/$(DEPDIR)/xdvipdfmx-mpost.Tpo xsrc/$(DEPDIR)/xdvipdfmx-mpost.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='xsrc/mpost.c' object='xsrc/xdvipdfmx-mpost.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o xsrc/xdvipdfmx-mpost.obj `if test -f 'xsrc/mpost.c'; then $(CYGPATH_W) 'xsrc/mpost.c'; else $(CYGPATH_W) '$(srcdir)/xsrc/mpost.c'; fi` - xsrc/xdvipdfmx-pdfcolor.o: xsrc/pdfcolor.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(xdvipdfmx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT xsrc/xdvipdfmx-pdfcolor.o -MD -MP -MF xsrc/$(DEPDIR)/xdvipdfmx-pdfcolor.Tpo -c -o xsrc/xdvipdfmx-pdfcolor.o `test -f 'xsrc/pdfcolor.c' || echo '$(srcdir)/'`xsrc/pdfcolor.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) xsrc/$(DEPDIR)/xdvipdfmx-pdfcolor.Tpo xsrc/$(DEPDIR)/xdvipdfmx-pdfcolor.Po diff --git a/Build/source/texk/dvipdfm-x/cff.c b/Build/source/texk/dvipdfm-x/cff.c new file mode 100644 index 00000000000..2b8201d985c --- /dev/null +++ b/Build/source/texk/dvipdfm-x/cff.c @@ -0,0 +1,1507 @@ +/* + + This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. + + Copyright (C) 2002-2012 by Jin-Hwan Cho and Shunsaku Hirata, + the dvipdfmx project team. + + This program 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; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include "system.h" +#include "mem.h" +#include "error.h" +#include "mfileio.h" + +#include "cff_limits.h" +#include "cff_types.h" +#include "cff_stdstr.h" +#include "cff_dict.h" + +#include "cff.h" + +#define CFF_DEBUG 5 +#define CFF_DEBUG_STR "CFF" + +#ifdef XETEX +#define SFNT_OR_FILE sfnt +#define SFONT_OR_STREAM sfont +#define get_card8(s) sfnt_get_byte((s)) +#define get_card16(s) sfnt_get_ushort((s)) +#define cff_read(d, l) sfnt_read(d, l, cff->sfont) +#else +#define SFNT_OR_FILE FILE +#define SFONT_OR_STREAM stream +#define get_card8(s) get_unsigned_byte((s)) +#define get_card16(s) get_unsigned_pair((s)) +#define cff_read(d, l) fread(d, 1, l, cff->stream) +#endif + +static unsigned long get_unsigned (SFNT_OR_FILE *SFONT_OR_STREAM, int n) +{ + unsigned long v = 0; + + while (n-- > 0) + v = v*0x100u + get_card8(SFONT_OR_STREAM); + + return v; +} + +#define get_offset(s, n) get_unsigned((s), (n)) + +/* + * Read Header, Name INDEX, Top DICT INDEX, and String INDEX. + */ +cff_font *cff_open(SFNT_OR_FILE *SFONT_OR_STREAM, long offset, int n) +{ + cff_font *cff; + cff_index *idx; + + cff = NEW(1, cff_font); + + cff->fontname = NULL; + cff->index = n; + cff->SFONT_OR_STREAM = SFONT_OR_STREAM; + cff->offset = offset; + cff->filter = 0; /* not used */ + cff->flag = 0; + + cff->name = NULL; + cff->gsubr = NULL; + cff->encoding = NULL; + cff->charsets = NULL; + cff->fdselect = NULL; + cff->cstrings = NULL; + cff->fdarray = NULL; + cff->private = NULL; + cff->subrs = NULL; + + cff->num_glyphs = 0; + cff->num_fds = 0; + cff->_string = NULL; + + cff_seek_set(cff, 0); + cff->header.major = get_card8(cff->SFONT_OR_STREAM); + cff->header.minor = get_card8(cff->SFONT_OR_STREAM); + cff->header.hdr_size = get_card8(cff->SFONT_OR_STREAM); + cff->header.offsize = get_card8(cff->SFONT_OR_STREAM); + if (cff->header.offsize < 1 || + cff->header.offsize > 4) + ERROR("invalid offsize data"); + + if (cff->header.major > 1 || + cff->header.minor > 0) { + WARN("%s: CFF version %u.%u not supported.", + CFF_DEBUG_STR, cff->header.major, cff->header.minor); + cff_close(cff); + return NULL; + } + + cff_seek_set(cff, (cff->header).hdr_size); + + /* Name INDEX */ + idx = cff_get_index(cff); + if (n > idx->count - 1) { + WARN("%s: Invalid CFF fontset index number.", CFF_DEBUG_STR); + cff_close(cff); + return NULL; + } + + cff->name = idx; + + cff->fontname = cff_get_name(cff); + + /* Top DICT INDEX */ + idx = cff_get_index(cff); + if (n > idx->count - 1) + ERROR("CFF Top DICT not exist..."); + cff->topdict = cff_dict_unpack(idx->data + idx->offset[n] - 1, + idx->data + idx->offset[n + 1] - 1); + if (!cff->topdict) + ERROR("Parsing CFF Top DICT data failed..."); + cff_release_index(idx); + + if (cff_dict_known(cff->topdict, "CharstringType") && + cff_dict_get(cff->topdict, "CharstringType", 0) != 2) { + WARN("Only Type 2 Charstrings supported..."); + cff_close(cff); + return NULL; + } + + if (cff_dict_known(cff->topdict, "SyntheticBase")) { + WARN("CFF Synthetic font not supported."); + cff_close(cff); + return NULL; + } + + /* String INDEX */ + cff->string = cff_get_index(cff); + + /* offset to GSubr */ +#ifdef XETEX + cff->gsubr_offset = cff->sfont->loc - offset; +#else + cff->gsubr_offset = tell_position(cff->stream) - offset; +#endif + + /* Number of glyphs */ + offset = (long) cff_dict_get(cff->topdict, "CharStrings", 0); + cff_seek_set(cff, offset); + cff->num_glyphs = get_card16(cff->SFONT_OR_STREAM); + + /* Check for font type */ + if (cff_dict_known(cff->topdict, "ROS")) { + cff->flag |= FONTTYPE_CIDFONT; + } else { + cff->flag |= FONTTYPE_FONT; + } + + /* Check for encoding */ + if (cff_dict_known(cff->topdict, "Encoding")) { + offset = (long) cff_dict_get(cff->topdict, "Encoding", 0); + if (offset == 0) { /* predefined */ + cff->flag |= ENCODING_STANDARD; + } else if (offset == 1) { + cff->flag |= ENCODING_EXPERT; + } + } else { + cff->flag |= ENCODING_STANDARD; + } + + /* Check for charset */ + if (cff_dict_known(cff->topdict, "charset")) { + offset = (long) cff_dict_get(cff->topdict, "charset", 0); + if (offset == 0) { /* predefined */ + cff->flag |= CHARSETS_ISOADOBE; + } else if (offset == 1) { + cff->flag |= CHARSETS_EXPERT; + } else if (offset == 2) { + cff->flag |= CHARSETS_EXPSUB; + } + } else { + cff->flag |= CHARSETS_ISOADOBE; + } + + cff_seek_set(cff, cff->gsubr_offset); /* seek back to GSubr */ + +#ifdef XETEX + cff->ft_to_gid = NULL; +#endif + + return cff; +} + +void +cff_close (cff_font *cff) +{ + card16 i; + + if (cff) { + if (cff->fontname) RELEASE(cff->fontname); + if (cff->name) cff_release_index(cff->name); + if (cff->topdict) cff_release_dict(cff->topdict); + if (cff->string) cff_release_index(cff->string); + if (cff->gsubr) cff_release_index(cff->gsubr); + if (cff->encoding) cff_release_encoding(cff->encoding); + if (cff->charsets) cff_release_charsets(cff->charsets); + if (cff->fdselect) cff_release_fdselect(cff->fdselect); + if (cff->cstrings) cff_release_index(cff->cstrings); + if (cff->fdarray) { + for (i=0;inum_fds;i++) { + if (cff->fdarray[i]) cff_release_dict(cff->fdarray[i]); + } + RELEASE(cff->fdarray); + } + if (cff->private) { + for (i=0;inum_fds;i++) { + if (cff->private[i]) cff_release_dict(cff->private[i]); + } + RELEASE(cff->private); + } + if (cff->subrs) { + for (i=0;inum_fds;i++) { + if (cff->subrs[i]) cff_release_index(cff->subrs[i]); + } + RELEASE(cff->subrs); + } + if (cff->_string) + cff_release_index(cff->_string); + +#ifdef XETEX + if (cff->ft_to_gid) + RELEASE(cff->ft_to_gid); +#endif + + RELEASE(cff); + } + + return; +} + +char * +cff_get_name (cff_font *cff) +{ + char *fontname; + l_offset len; + cff_index *idx; + + idx = cff->name; + len = idx->offset[cff->index + 1] - idx->offset[cff->index]; + fontname = NEW(len + 1, char); + memcpy(fontname, idx->data + idx->offset[cff->index] - 1, len); + fontname[len] = '\0'; + + return fontname; +} + +long +cff_set_name (cff_font *cff, char *name) +{ + cff_index *idx; + + if (strlen(name) > 127) + ERROR("FontName string length too large..."); + + if (cff->name) + cff_release_index(cff->name); + + cff->name = idx = NEW(1, cff_index); + idx->count = 1; + idx->offsize = 1; + idx->offset = NEW(2, l_offset); + (idx->offset)[0] = 1; + (idx->offset)[1] = strlen(name) + 1; + idx->data = NEW(strlen(name), card8); + memmove(idx->data, name, strlen(name)); /* no trailing '\0' */ + + return 5 + strlen(name); +} + +long +cff_put_header (cff_font *cff, card8 *dest, long destlen) +{ + if (destlen < 4) + ERROR("Not enough space available..."); + + *(dest++) = cff->header.major; + *(dest++) = cff->header.minor; + *(dest++) = 4; /* Additional data in between header and + * Name INDEX ignored. + */ + /* We will set all offset (0) to four-byte integer. */ + *(dest++) = 4; + cff->header.offsize = 4; + + return 4; +} + +/* Only read header part but not body */ +cff_index * +cff_get_index_header (cff_font *cff) +{ + cff_index *idx; + card16 i, count; + + idx = NEW(1, cff_index); + + idx->count = count = get_card16(cff->SFONT_OR_STREAM); + if (count > 0) { + idx->offsize = get_card8(cff->SFONT_OR_STREAM); + if (idx->offsize < 1 || idx->offsize > 4) + ERROR("invalid offsize data"); + + idx->offset = NEW(count+1, l_offset); + for (i=0;ioffset)[i] = get_offset(cff->SFONT_OR_STREAM, idx->offsize); + } + + if (idx->offset[0] != 1) + ERROR("cff_get_index(): invalid index data"); + + idx->data = NULL; + } else { + idx->offsize = 0; + idx->offset = NULL; + idx->data = NULL; + } + + return idx; +} + +cff_index * +cff_get_index (cff_font *cff) +{ + cff_index *idx; + card16 i, count; + long length, nb_read, offset; + + idx = NEW(1, cff_index); + + idx->count = count = get_card16(cff->SFONT_OR_STREAM); + if (count > 0) { + idx->offsize = get_card8(cff->SFONT_OR_STREAM); + if (idx->offsize < 1 || idx->offsize > 4) + ERROR("invalid offsize data"); + + idx->offset = NEW(count + 1, l_offset); + for (i = 0 ; i < count + 1; i++) { + idx->offset[i] = get_offset(cff->SFONT_OR_STREAM, idx->offsize); + } + + if (idx->offset[0] != 1) + ERROR("Invalid CFF Index offset data"); + + length = idx->offset[count] - idx->offset[0]; + + idx->data = NEW(length, card8); + offset = 0; + while (length > 0) { + nb_read = cff_read(idx->data + offset, length); + offset += nb_read; + length -= nb_read; + } + } else { + idx->offsize = 0; + idx->offset = NULL; + idx->data = NULL; + } + + return idx; +} + +long +cff_pack_index (cff_index *idx, card8 *dest, long destlen) +{ + long len = 0; + long datalen; + card16 i; + + if (idx->count < 1) { + if (destlen < 2) + ERROR("Not enough space available..."); + memset(dest, 0, 2); + return 2; + } + + len = cff_index_size(idx); + datalen = idx->offset[idx->count] - 1; + + if (destlen < len) + ERROR("Not enough space available..."); + + *(dest++) = (idx->count >> 8) & 0xff; + *(dest++) = idx->count & 0xff; + + if (datalen < 0xffUL) { + idx->offsize = 1; + *(dest++) = 1; + for (i = 0; i <= idx->count; i++) { + *(dest++) = (card8) (idx->offset[i] & 0xff); + } + } else if (datalen < 0xffffUL) { + idx->offsize = 2; + *(dest++) = 2; + for (i = 0; i <= idx->count; i++) { + *(dest++) = (card8) ((idx->offset[i] >> 8) & 0xff); + *(dest++) = (card8) ( idx->offset[i] & 0xff); + } + } else if (datalen < 0xffffffUL) { + idx->offsize = 3; + *(dest++) = 3; + for (i = 0; i <= idx->count; i++) { + *(dest++) = (card8)((idx->offset[i] >> 16) & 0xff); + *(dest++) = (card8)((idx->offset[i] >> 8) & 0xff); + *(dest++) = (card8)(idx->offset[i] & 0xff); + } + } else { + idx->offsize = 4; + *(dest++) = 4; + for (i = 0; i <= idx->count; i++) { + *(dest++) = (card8)((idx->offset[i] >> 24) & 0xff); + *(dest++) = (card8)((idx->offset[i] >> 16) & 0xff); + *(dest++) = (card8)((idx->offset[i] >> 8) & 0xff); + *(dest++) = (card8)(idx->offset[i] & 0xff); + } + } + + memmove(dest, idx->data, idx->offset[idx->count] - 1); + + return len; +} + +long +cff_index_size (cff_index *idx) +{ + if (idx->count > 0) { + l_offset datalen; + + datalen = idx->offset[idx->count] - 1; + if (datalen < 0xffUL) { + idx->offsize = 1; + } else if (datalen < 0xffffUL) { + idx->offsize = 2; + } else if (datalen < 0xffffffUL) { + idx->offsize = 3; + } else { + idx->offsize = 4; + } + return (3 + (idx->offsize)*(idx->count + 1) + datalen); + } else { + return 2; + } +} + + +cff_index *cff_new_index (card16 count) +{ + cff_index *idx; + + idx = NEW(1, cff_index); + idx->count = count; + idx->offsize = 0; + + if (count > 0) { + idx->offset = NEW(count + 1, l_offset); + (idx->offset)[0] = 1; + } else { + idx->offset = NULL; + } + idx->data = NULL; + + return idx; +} + +void cff_release_index (cff_index *idx) +{ + if (idx) { + if (idx->data) { + RELEASE(idx->data); + } + if (idx->offset) { + RELEASE(idx->offset); + } + RELEASE(idx); + } +} + +/* Strings */ +char *cff_get_string (cff_font *cff, s_SID id) +{ + char *result = NULL; + long len; + + if (id < CFF_STDSTR_MAX) { + len = strlen(cff_stdstr[id]); + result = NEW(len+1, char); + memcpy(result, cff_stdstr[id], len); + result[len] = '\0'; + } else if (cff && cff->string) { + cff_index *strings = cff->string; + id -= CFF_STDSTR_MAX; + if (id < strings->count) { + len = (strings->offset)[id+1] - (strings->offset)[id]; + result = NEW(len + 1, char); + memmove(result, strings->data + (strings->offset)[id] - 1, len); + result[len] = '\0'; + } + } + + return result; +} + +long cff_get_sid (cff_font *cff, const char *str) +{ + card16 i; + + if (!cff || !str) + return -1; + + /* I search String INDEX first. */ + if (cff && cff->string) { + cff_index *idx = cff->string; + for (i = 0; i < idx->count; i++) { + if (strlen(str) == (idx->offset)[i+1] - (idx->offset)[i] && + !memcmp(str, (idx->data)+(idx->offset)[i]-1, strlen(str))) + return (i + CFF_STDSTR_MAX); + } + } + + for (i = 0; i < CFF_STDSTR_MAX; i++) { + if (!strcmp(str, cff_stdstr[i])) + return i; + } + + return -1; +} + +long cff_get_seac_sid (cff_font *cff, const char *str) +{ + card16 i; + + if (!cff || !str) + return -1; + + for (i = 0; i < CFF_STDSTR_MAX; i++) { + if (!strcmp(str, cff_stdstr[i])) + return i; + } + + return -1; +} + +int cff_match_string (cff_font *cff, const char *str, s_SID sid) +{ + card16 i; + + if (sid < CFF_STDSTR_MAX) { + return ((!strcmp(str, cff_stdstr[sid])) ? 1 : 0); + } else { + i = sid - CFF_STDSTR_MAX; + if (cff == NULL || cff->string == NULL || i >= cff->string->count) + ERROR("Invalid SID"); + if (strlen(str) == (cff->string->offset)[i+1] - (cff->string->offset)[i]) + return (!memcmp(str, + (cff->string->data)+(cff->string->offset)[i]-1, + strlen(str))) ? 1 : 0; + } + + return 0; +} + +void cff_update_string (cff_font *cff) +{ + if (cff == NULL) + ERROR("CFF font not opened."); + + if (cff->string) + cff_release_index(cff->string); + cff->string = cff->_string; + cff->_string = NULL; +} + +s_SID cff_add_string (cff_font *cff, const char *str, int unique) +/* Setting unique == 1 eliminates redundant or predefined strings. */ +{ + card16 idx; + cff_index *strings; + l_offset offset, size; + long len = strlen(str); + + if (cff == NULL) + ERROR("CFF font not opened."); + + if (cff->_string == NULL) + cff->_string = cff_new_index(0); + strings = cff->_string; + + if (unique) { + /* TODO: do binary search to speed things up */ + for (idx = 0; idx < CFF_STDSTR_MAX; idx++) { + if (cff_stdstr[idx] && !strcmp(cff_stdstr[idx], str)) + return idx; + } + for (idx = 0; idx < strings->count; idx++) { + size = strings->offset[idx+1] - strings->offset[idx]; + offset = strings->offset[idx]; + if (size == len && !memcmp(strings->data+offset-1, str, len)) + return (idx + CFF_STDSTR_MAX); + } + } + + offset = (strings->count > 0) ? strings->offset[strings->count] : 1; + strings->offset = RENEW(strings->offset, strings->count+2, l_offset); + if (strings->count == 0) + strings->offset[0] = 1; + idx = strings->count; + strings->count += 1; + strings->offset[strings->count] = offset + len; + strings->data = RENEW(strings->data, offset+len-1, card8); + memcpy(strings->data+offset-1, str, len); + + return (idx + CFF_STDSTR_MAX); +} + +/* + * Encoding and Charset + * + * Encoding and Charset arrays always begin with GID = 1. + */ +long cff_read_encoding (cff_font *cff) +{ + cff_encoding *encoding; + long offset, length; + card8 i; + + if (cff->topdict == NULL) { + ERROR("Top DICT data not found"); + } + + if (!cff_dict_known(cff->topdict, "Encoding")) { + cff->flag |= ENCODING_STANDARD; + cff->encoding = NULL; + return 0; + } + + offset = (long) cff_dict_get(cff->topdict, "Encoding", 0); + if (offset == 0) { /* predefined */ + cff->flag |= ENCODING_STANDARD; + cff->encoding = NULL; + return 0; + } else if (offset == 1) { + cff->flag |= ENCODING_EXPERT; + cff->encoding = NULL; + return 0; + } + + cff_seek_set(cff, offset); + cff->encoding = encoding = NEW(1, cff_encoding); + encoding->format = get_card8(cff->SFONT_OR_STREAM); + length = 1; + + switch (encoding->format & (~0x80)) { + case 0: + encoding->num_entries = get_card8(cff->SFONT_OR_STREAM); + (encoding->data).codes = NEW(encoding->num_entries, card8); + for (i=0;i<(encoding->num_entries);i++) { + (encoding->data).codes[i] = get_card8(cff->SFONT_OR_STREAM); + } + length += encoding->num_entries + 1; + break; + case 1: + { + cff_range1 *ranges; + encoding->num_entries = get_card8(cff->SFONT_OR_STREAM); + encoding->data.range1 = ranges + = NEW(encoding->num_entries, cff_range1); + for (i=0;i<(encoding->num_entries);i++) { + ranges[i].first = get_card8(cff->SFONT_OR_STREAM); + ranges[i].n_left = get_card8(cff->SFONT_OR_STREAM); + } + length += (encoding->num_entries) * 2 + 1; + } + break; + default: + RELEASE(encoding); + ERROR("Unknown Encoding format"); + break; + } + + /* Supplementary data */ + if ((encoding->format) & 0x80) { + cff_map *map; + encoding->num_supps = get_card8(cff->SFONT_OR_STREAM); + encoding->supp = map = NEW(encoding->num_supps, cff_map); + for (i=0;i<(encoding->num_supps);i++) { + map[i].code = get_card8(cff->SFONT_OR_STREAM); + map[i].glyph = get_card16(cff->SFONT_OR_STREAM); /* SID */ + } + length += (encoding->num_supps) * 3 + 1; + } else { + encoding->num_supps = 0; + encoding->supp = NULL; + } + + return length; +} + +long cff_pack_encoding (cff_font *cff, card8 *dest, long destlen) +{ + long len = 0; + cff_encoding *encoding; + card16 i; + + if (cff->flag & HAVE_STANDARD_ENCODING || cff->encoding == NULL) + return 0; + + if (destlen < 2) + ERROR("in cff_pack_encoding(): Buffer overflow"); + + encoding = cff->encoding; + + dest[len++] = encoding->format; + dest[len++] = encoding->num_entries; + switch (encoding->format & (~0x80)) { + case 0: + if (destlen < len + encoding->num_entries) + ERROR("in cff_pack_encoding(): Buffer overflow"); + for (i=0;i<(encoding->num_entries);i++) { + dest[len++] = (encoding->data).codes[i]; + } + break; + case 1: + { + if (destlen < len + (encoding->num_entries)*2) + ERROR("in cff_pack_encoding(): Buffer overflow"); + for (i=0;i<(encoding->num_entries);i++) { + dest[len++] = (encoding->data).range1[i].first & 0xff; + dest[len++] = (encoding->data).range1[i].n_left; + } + } + break; + default: + ERROR("Unknown Encoding format"); + break; + } + + if ((encoding->format) & 0x80) { + if (destlen < len + (encoding->num_supps)*3 + 1) + ERROR("in cff_pack_encoding(): Buffer overflow"); + dest[len++] = encoding->num_supps; + for (i=0;i<(encoding->num_supps);i++) { + dest[len++] = (encoding->supp)[i].code; + dest[len++] = ((encoding->supp)[i].glyph >> 8) & 0xff; + dest[len++] = (encoding->supp)[i].glyph & 0xff; + } + } + + return len; +} + +/* input: code, output: glyph index */ +card16 cff_encoding_lookup (cff_font *cff, card8 code) +{ + card16 gid = 0; + cff_encoding *encoding; + card16 i; + + if (cff->flag & (ENCODING_STANDARD|ENCODING_EXPERT)) { + ERROR("Predefined CFF encoding not supported yet"); + } else if (cff->encoding == NULL) { + ERROR("Encoding data not available"); + } + + encoding = cff->encoding; + + gid = 0; + switch (encoding->format & (~0x80)) { + case 0: + for (i = 0; i < encoding->num_entries; i++) { + if (code == (encoding->data).codes[i]) { + gid = i + 1; + break; + } + } + break; + case 1: + for (i = 0; i < encoding->num_entries; i++) { + if (code >= (encoding->data).range1[i].first && + code <= (encoding->data).range1[i].first + (encoding->data).range1[i].n_left) { + gid += code - (encoding->data).range1[i].first + 1; + break; + } + gid += (encoding->data).range1[i].n_left + 1; + } + if (i == encoding->num_entries) + gid = 0; + break; + default: + ERROR("Unknown Encoding format."); + } + + /* Supplementary data */ + if (gid == 0 && ((encoding->format) & 0x80)) { + cff_map *map; + if (!encoding->supp) + ERROR("No CFF supplementary encoding data read."); + map = encoding->supp; + for (i=0;i<(encoding->num_supps);i++) { + if (code == map[i].code) { + gid = cff_charsets_lookup(cff, map[i].glyph); + break; + } + } + } + + return gid; +} + +void cff_release_encoding (cff_encoding *encoding) +{ + if (encoding) { + switch (encoding->format & (~0x80)) { + case 0: + if (encoding->data.codes) + RELEASE(encoding->data.codes); + break; + case 1: + if (encoding->data.range1) + RELEASE(encoding->data.range1); + break; + default: + ERROR("Unknown Encoding format."); + } + if (encoding->format & 0x80) { + if (encoding->supp) + RELEASE(encoding->supp); + } + RELEASE(encoding); + } +} + +long cff_read_charsets (cff_font *cff) +{ + cff_charsets *charset; + long offset, length; + card16 count, i; + + if (cff->topdict == NULL) + ERROR("Top DICT not available"); + + if (!cff_dict_known(cff->topdict, "charset")) { + cff->flag |= CHARSETS_ISOADOBE; + cff->charsets = NULL; + return 0; + } + + offset = (long) cff_dict_get(cff->topdict, "charset", 0); + + if (offset == 0) { /* predefined */ + cff->flag |= CHARSETS_ISOADOBE; + cff->charsets = NULL; + return 0; + } else if (offset == 1) { + cff->flag |= CHARSETS_EXPERT; + cff->charsets = NULL; + return 0; + } else if (offset == 2) { + cff->flag |= CHARSETS_EXPSUB; + cff->charsets = NULL; + return 0; + } + + cff_seek_set(cff, offset); + cff->charsets = charset = NEW(1, cff_charsets); + charset->format = get_card8(cff->SFONT_OR_STREAM); + charset->num_entries = 0; + + count = cff->num_glyphs - 1; + length = 1; + + /* Not sure. Not well documented. */ + switch (charset->format) { + case 0: + charset->num_entries = cff->num_glyphs - 1; /* no .notdef */ + charset->data.glyphs = NEW(charset->num_entries, s_SID); + length += (charset->num_entries) * 2; + for (i=0;i<(charset->num_entries);i++) { + charset->data.glyphs[i] = get_card16(cff->SFONT_OR_STREAM); + } + count = 0; + break; + case 1: + { + cff_range1 *ranges = NULL; + while (count > 0 && charset->num_entries < cff->num_glyphs) { + ranges = RENEW(ranges, charset->num_entries + 1, cff_range1); + ranges[charset->num_entries].first = get_card16(cff->SFONT_OR_STREAM); + ranges[charset->num_entries].n_left = get_card8(cff->SFONT_OR_STREAM); + count -= ranges[charset->num_entries].n_left + 1; /* no-overrap */ + charset->num_entries += 1; + charset->data.range1 = ranges; + } + length += (charset->num_entries) * 3; + } + break; + case 2: + { + cff_range2 *ranges = NULL; + while (count > 0 && charset->num_entries < cff->num_glyphs) { + ranges = RENEW(ranges, charset->num_entries + 1, cff_range2); + ranges[charset->num_entries].first = get_card16(cff->SFONT_OR_STREAM); + ranges[charset->num_entries].n_left = get_card16(cff->SFONT_OR_STREAM); + count -= ranges[charset->num_entries].n_left + 1; /* non-overrapping */ + charset->num_entries += 1; + } + charset->data.range2 = ranges; + length += (charset->num_entries) * 4; + } + break; + default: + RELEASE(charset); + ERROR("Unknown Charset format"); + break; + } + + if (count > 0) + ERROR("Charset data possibly broken"); + + return length; +} + +long cff_pack_charsets (cff_font *cff, card8 *dest, long destlen) +{ + long len = 0; + card16 i; + cff_charsets *charset; + + if (cff->flag & HAVE_STANDARD_CHARSETS || cff->charsets == NULL) + return 0; + + if (destlen < 1) + ERROR("in cff_pack_charsets(): Buffer overflow"); + + charset = cff->charsets; + + dest[len++] = charset->format; + switch (charset->format) { + case 0: + if (destlen < len + (charset->num_entries)*2) + ERROR("in cff_pack_charsets(): Buffer overflow"); + for (i=0;i<(charset->num_entries);i++) { + s_SID sid = (charset->data).glyphs[i]; /* or CID */ + dest[len++] = (sid >> 8) & 0xff; + dest[len++] = sid & 0xff; + } + break; + case 1: + { + if (destlen < len + (charset->num_entries)*3) + ERROR("in cff_pack_charsets(): Buffer overflow"); + for (i=0;i<(charset->num_entries);i++) { + dest[len++] = ((charset->data).range1[i].first >> 8) & 0xff; + dest[len++] = (charset->data).range1[i].first & 0xff; + dest[len++] = (charset->data).range1[i].n_left; + } + } + break; + case 2: + { + if (destlen < len + (charset->num_entries)*4) + ERROR("in cff_pack_charsets(): Buffer overflow"); + for (i=0;i<(charset->num_entries);i++) { + dest[len++] = ((charset->data).range2[i].first >> 8) & 0xff; + dest[len++] = (charset->data).range2[i].first & 0xff; + dest[len++] = ((charset->data).range2[i].n_left >> 8) & 0xff; + dest[len++] = (charset->data).range2[i].n_left & 0xff; + } + } + break; + default: + ERROR("Unknown Charset format"); + break; + } + + return len; +} + +card16 cff_glyph_lookup (cff_font *cff, const char *glyph) +{ + card16 gid; + cff_charsets *charset; + card16 i, n; + + if (cff->flag & (CHARSETS_ISOADOBE|CHARSETS_EXPERT|CHARSETS_EXPSUB)) { + ERROR("Predefined CFF charsets not supported yet"); + } else if (cff->charsets == NULL) { + ERROR("Charsets data not available"); + } + + /* .notdef always have glyph index 0 */ + if (!glyph || !strcmp(glyph, ".notdef")) { + return 0; + } + + charset = cff->charsets; + + gid = 0; + switch (charset->format) { + case 0: + for (i = 0; i < charset->num_entries; i++) { + gid++; + if (cff_match_string(cff, glyph, charset->data.glyphs[i])) { + return gid; + } + } + break; + case 1: + for (i = 0; i < charset->num_entries; i++) { + for (n = 0; + n <= charset->data.range1[i].n_left; n++) { + gid++; + if (cff_match_string(cff, glyph, + (s_SID)(charset->data.range1[i].first + n))) { + return gid; + } + } + } + break; + case 2: + for (i = 0; i num_entries; i++) { + for (n = 0; + n <= charset->data.range2[i].n_left; n++) { + gid++; + if (cff_match_string(cff, glyph, + (s_SID)(charset->data.range2[i].first + n))) { + return gid; + } + } + } + break; + default: + ERROR("Unknown Charset format"); + } + + return 0; /* not found, returns .notdef */ +} + +/* Input : SID or CID (16-bit unsigned int) + * Output: glyph index + */ +card16 +cff_charsets_lookup (cff_font *cff, card16 cid) +{ + card16 gid = 0; + cff_charsets *charset; + card16 i; + + if (cff->flag & (CHARSETS_ISOADOBE|CHARSETS_EXPERT|CHARSETS_EXPSUB)) { + ERROR("Predefined CFF charsets not supported yet"); + } else if (cff->charsets == NULL) { + ERROR("Charsets data not available"); + } + + if (cid == 0) { + return 0; /* GID 0 (.notdef) */ + } + + charset = cff->charsets; + + gid = 0; + switch (charset->format) { + case 0: + for (i = 0; i num_entries; i++) { + if (cid == charset->data.glyphs[i]) { + gid = i + 1; + return gid; + } + } + break; + case 1: + for (i = 0; i < charset->num_entries; i++) { + if (cid >= charset->data.range1[i].first && + cid <= charset->data.range1[i].first + charset->data.range1[i].n_left) { + gid += cid - charset->data.range1[i].first + 1; + return gid; + } + gid += charset->data.range1[i].n_left + 1; + } + break; + case 2: + for (i = 0; i < charset->num_entries; i++) { + if (cid >= charset->data.range2[i].first && + cid <= charset->data.range2[i].first + charset->data.range2[i].n_left) { + gid += cid - charset->data.range2[i].first + 1; + return gid; + } + gid += charset->data.range2[i].n_left + 1; + } + break; + default: + ERROR("Unknown Charset format"); + } + + return 0; /* not found */ +} + +/* Input : GID + * Output: SID/CID (card16) + */ +card16 +cff_charsets_lookup_inverse (cff_font *cff, card16 gid) +{ + card16 sid = 0; + cff_charsets *charset; + card16 i; + + if (cff->flag & (CHARSETS_ISOADOBE|CHARSETS_EXPERT|CHARSETS_EXPSUB)) { + ERROR("Predefined CFF charsets not supported yet"); + } else if (cff->charsets == NULL) { + ERROR("Charsets data not available"); + } + + if (gid == 0) { + return 0; /* .notdef */ + } + + charset = cff->charsets; + + sid = 0; + switch (charset->format) { + case 0: + if (gid - 1 >= charset->num_entries) + ERROR("Invalid GID."); + sid = charset->data.glyphs[gid - 1]; + break; + case 1: + for (i = 0; i < charset->num_entries; i++) { + if (gid <= charset->data.range1[i].n_left + 1) { + sid = gid + charset->data.range1[i].first - 1; + break; + } + gid -= charset->data.range1[i].n_left + 1; + } + if (i == charset->num_entries) + ERROR("Invalid GID"); + break; + case 2: + for (i = 0; i < charset->num_entries; i++) { + if (gid <= charset->data.range2[i].n_left + 1) { + sid = gid + charset->data.range2[i].first - 1; + break; + } + gid -= charset->data.range2[i].n_left + 1; + } + if (i == charset->num_entries) + ERROR("Invalid GID"); + break; + default: + ERROR("Unknown Charset format"); + } + + return sid; +} + +void +cff_release_charsets (cff_charsets *charset) +{ + if (charset) { + switch (charset->format) { + case 0: + if (charset->data.glyphs) + RELEASE(charset->data.glyphs); + break; + case 1: + if (charset->data.range1) + RELEASE(charset->data.range1); + break; + case 2: + if (charset->data.range2) + RELEASE(charset->data.range2); + break; + default: + break; + } + RELEASE(charset); + } +} + +/* CID-Keyed font specific */ +long cff_read_fdselect (cff_font *cff) +{ + cff_fdselect *fdsel; + long offset, length; + card16 i; + + if (cff->topdict == NULL) + ERROR("Top DICT not available"); + + if (!(cff->flag & FONTTYPE_CIDFONT)) + return 0; + + offset = (long) cff_dict_get(cff->topdict, "FDSelect", 0); + cff_seek_set(cff, offset); + cff->fdselect = fdsel = NEW(1, cff_fdselect); + fdsel->format = get_card8(cff->SFONT_OR_STREAM); + + length = 1; + + switch (fdsel->format) { + case 0: + fdsel->num_entries = cff->num_glyphs; + (fdsel->data).fds = NEW(fdsel->num_entries, card8); + for (i=0;i<(fdsel->num_entries);i++) { + (fdsel->data).fds[i] = get_card8(cff->SFONT_OR_STREAM); + } + length += fdsel->num_entries; + break; + case 3: + { + cff_range3 *ranges; + fdsel->num_entries = get_card16(cff->SFONT_OR_STREAM); + fdsel->data.ranges = ranges = NEW(fdsel->num_entries, cff_range3); + for (i=0;i<(fdsel->num_entries);i++) { + ranges[i].first = get_card16(cff->SFONT_OR_STREAM); + ranges[i].fd = get_card8(cff->SFONT_OR_STREAM); + } + if (ranges[0].first != 0) + ERROR("Range not starting with 0."); + if (cff->num_glyphs != get_card16(cff->SFONT_OR_STREAM)) + ERROR("Sentinel value mismatched with number of glyphs."); + length += (fdsel->num_entries) * 3 + 4; + } + break; + default: + RELEASE(fdsel); + ERROR("Unknown FDSelect format."); + break; + } + + return length; +} + +long cff_pack_fdselect (cff_font *cff, card8 *dest, long destlen) +{ + cff_fdselect *fdsel; + long len = 0; + card16 i; + + if (cff->fdselect == NULL) + return 0; + + if (destlen < 1) + ERROR("in cff_pack_fdselect(): Buffur overflow"); + + fdsel = cff->fdselect; + + dest[len++] = fdsel->format; + switch (fdsel->format) { + case 0: + if (fdsel->num_entries != cff->num_glyphs) + ERROR("in cff_pack_fdselect(): Invalid data"); + if (destlen < len + fdsel->num_entries) + ERROR("in cff_pack_fdselect(): Buffer overflow"); + for (i=0;inum_entries;i++) { + dest[len++] = (fdsel->data).fds[i]; + } + break; + case 3: + { + if (destlen < len + 2) + ERROR("in cff_pack_fdselect(): Buffer overflow"); + len += 2; + for (i=0;i<(fdsel->num_entries);i++) { + if (destlen < len + 3) + ERROR("in cff_pack_fdselect(): Buffer overflow"); + dest[len++] = ((fdsel->data).ranges[i].first >> 8) & 0xff; + dest[len++] = (fdsel->data).ranges[i].first & 0xff; + dest[len++] = (fdsel->data).ranges[i].fd; + } + if (destlen < len + 2) + ERROR("in cff_pack_fdselect(): Buffer overflow"); + dest[len++] = (cff->num_glyphs >> 8) & 0xff; + dest[len++] = cff->num_glyphs & 0xff; + dest[1] = ((len/3 - 1) >> 8) & 0xff; + dest[2] = (len/3 - 1) & 0xff; + } + break; + default: + ERROR("Unknown FDSelect format."); + break; + } + + return len; +} + +void cff_release_fdselect (cff_fdselect *fdselect) +{ + if (fdselect) { + if (fdselect->format == 0) { + if (fdselect->data.fds) RELEASE(fdselect->data.fds); + } else if (fdselect->format == 3) { + if (fdselect->data.ranges) RELEASE(fdselect->data.ranges); + } + RELEASE(fdselect); + } +} + +card8 cff_fdselect_lookup (cff_font *cff, card16 gid) +{ + card8 fd = 0xff; + cff_fdselect *fdsel; + + if (cff->fdselect == NULL) + ERROR("in cff_fdselect_lookup(): FDSelect not available"); + + fdsel = cff->fdselect; + + if (gid >= cff->num_glyphs) + ERROR("in cff_fdselect_lookup(): Invalid glyph index"); + + switch (fdsel->format) { + case 0: + fd = fdsel->data.fds[gid]; + break; + case 3: + { + if (gid == 0) { + fd = (fdsel->data).ranges[0].fd; + } else { + card16 i; + for (i=1;i<(fdsel->num_entries);i++) { + if (gid < (fdsel->data).ranges[i].first) + break; + } + fd = (fdsel->data).ranges[i-1].fd; + } + } + break; + default: + ERROR("in cff_fdselect_lookup(): Invalid FDSelect format"); + break; + } + + if (fd >= cff->num_fds) + ERROR("in cff_fdselect_lookup(): Invalid Font DICT index"); + + return fd; +} + +long cff_read_subrs (cff_font *cff) +{ + long len = 0; + long offset; + int i; + + if ((cff->flag & FONTTYPE_CIDFONT) && cff->fdarray == NULL) { + cff_read_fdarray(cff); + } + + if (cff->private == NULL) + cff_read_private(cff); + + if (cff->gsubr == NULL) { + cff_seek_set(cff, cff->gsubr_offset); + cff->gsubr = cff_get_index(cff); + } + + cff->subrs = NEW(cff->num_fds, cff_index *); + if (cff->flag & FONTTYPE_CIDFONT) { + for (i=0;inum_fds;i++) { + if (cff->private[i] == NULL || + !cff_dict_known(cff->private[i], "Subrs")) { + (cff->subrs)[i] = NULL; + } else { + offset = (long) cff_dict_get(cff->fdarray[i], "Private", 1); + offset += (long) cff_dict_get(cff->private[i], "Subrs", 0); + cff_seek_set(cff, offset); + (cff->subrs)[i] = cff_get_index(cff); + len += cff_index_size((cff->subrs)[i]); + } + } + } else { + if (cff->private[0] == NULL || + !cff_dict_known(cff->private[0], "Subrs")) { + (cff->subrs)[0] = NULL; + } else { + offset = (long) cff_dict_get(cff->topdict, "Private", 1); + offset += (long) cff_dict_get(cff->private[0], "Subrs", 0); + cff_seek_set(cff, offset); + (cff->subrs)[0] = cff_get_index(cff); + len += cff_index_size((cff->subrs)[0]); + } + } + + return len; +} + +long cff_read_fdarray (cff_font *cff) +{ + long len = 0; + cff_index *idx; + long offset, size; + card16 i; + + if (cff->topdict == NULL) + ERROR("in cff_read_fdarray(): Top DICT not found"); + + if (!(cff->flag & FONTTYPE_CIDFONT)) + return 0; + + /* must exist */ + offset = (long) cff_dict_get(cff->topdict, "FDArray", 0); + cff_seek_set(cff, offset); + idx = cff_get_index(cff); + cff->num_fds = (card8)idx->count; + cff->fdarray = NEW(idx->count, cff_dict *); + for (i=0;icount;i++) { + card8 *data = idx->data + (idx->offset)[i] - 1; + size = (idx->offset)[i+1] - (idx->offset)[i]; + if (size > 0) { + (cff->fdarray)[i] = cff_dict_unpack(data, data+size); + } else { + (cff->fdarray)[i] = NULL; + } + } + len = cff_index_size(idx); + cff_release_index(idx); + + return len; +} + +long cff_read_private (cff_font *cff) +{ + long len = 0; + card8 *data; + long offset, size; + + if (cff->flag & FONTTYPE_CIDFONT) { + int i; + + if (cff->fdarray == NULL) + cff_read_fdarray(cff); + + cff->private = NEW(cff->num_fds, cff_dict *); + for (i=0;inum_fds;i++) { + if (cff->fdarray[i] != NULL && + cff_dict_known(cff->fdarray[i], "Private") && + (size = (long) cff_dict_get(cff->fdarray[i], "Private", 0)) + > 0) { + offset = (long) cff_dict_get(cff->fdarray[i], "Private", 1); + cff_seek_set(cff, offset); + data = NEW(size, card8); + if (cff_read(data, size) != size) + ERROR("reading file failed"); + (cff->private)[i] = cff_dict_unpack(data, data+size); + RELEASE(data); + len += size; + } else { + (cff->private)[i] = NULL; + } + } + } else { + cff->num_fds = 1; + cff->private = NEW(1, cff_dict *); + if (cff_dict_known(cff->topdict, "Private") && + (size = (long) cff_dict_get(cff->topdict, "Private", 0)) > 0) { + offset = (long) cff_dict_get(cff->topdict, "Private", 1); + cff_seek_set(cff, offset); + data = NEW(size, card8); + if (cff_read(data, size) != size) + ERROR("reading file failed"); + cff->private[0] = cff_dict_unpack(data, data+size); + RELEASE(data); + len += size; + } else { + (cff->private)[0] = NULL; + len = 0; + } + } + + return len; +} + +#ifdef XETEX +unsigned short* cff_get_ft_to_gid(cff_font *cff) +{ + return cff->ft_to_gid; +} +#endif diff --git a/Build/source/texk/dvipdfm-x/dvi.h b/Build/source/texk/dvipdfm-x/dvi.h new file mode 100644 index 00000000000..41944db5504 --- /dev/null +++ b/Build/source/texk/dvipdfm-x/dvi.h @@ -0,0 +1,109 @@ +/* + + This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. + + Copyright (C) 2002-2012 by Jin-Hwan Cho and Shunsaku Hirata, + the dvipdfmx project team. + + Copyright (C) 1998, 1999 by Mark A. Wicks + + This program 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; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +*/ + +#ifndef _DVI_H_ +#define _DVI_H_ + +#include "error.h" +#include "numbers.h" +/* spt_t */ +#include "pdfdev.h" + +#ifdef XETEX +/* instantiated in dvipdfmx.c */ +extern double paper_width, paper_height; +extern char landscape_mode; + +extern double get_origin (int x); +#endif + +extern void dvi_set_verbose (void); + +/* returns scale (dvi2pts) */ +extern double dvi_init (char *dvi_filename, double mag); /* may append .dvi or .xdv to filename */ +extern void dvi_close (void); /* Closes data structures created by dvi_open */ + +extern double dvi_tell_mag (void); +#ifdef XETEX +extern double dvi_unit_size (void); +#endif +extern double dvi_dev_xpos (void); +extern double dvi_dev_ypos (void); +extern unsigned dvi_npages (void); +extern const char *dvi_comment (void); + +extern void dvi_vf_init (int dev_font_id); +extern void dvi_vf_finish (void); + +extern void dvi_set_font (int font_id); +extern void dvi_set (SIGNED_QUAD ch); +extern void dvi_rule (SIGNED_QUAD width, SIGNED_QUAD height); + +extern void dvi_right (SIGNED_QUAD x); +extern void dvi_put (SIGNED_QUAD ch); +extern void dvi_push (void); +extern void dvi_pop (void); +extern void dvi_w0 (void); +extern void dvi_w (SIGNED_QUAD ch); +extern void dvi_x0 (void); +extern void dvi_x (SIGNED_QUAD ch); +extern void dvi_down (SIGNED_QUAD y); +extern void dvi_y (SIGNED_QUAD ch); +extern void dvi_y0 (void); +extern void dvi_z (SIGNED_QUAD ch); +extern void dvi_z0 (void); +extern void dvi_dir (UNSIGNED_BYTE dir); + +extern void dvi_do_page (long page_no, + double paper_width, double paper_height, + double x_offset, double y_offset); +extern void dvi_scan_specials (long page_no, + double *width, double *height, + double *x_offset, double *y_offset, + char *landscape, unsigned *minorversion, + int *do_enc, unsigned *key_bits, unsigned *permission, char *owner_pw, char *user_pw); +extern int dvi_locate_font (const char *name, spt_t ptsize); + +/* link or nolink: + * See dvipdfm (not x) user's manual on pdf:link and pdf:nolink. + * This is workaround for preventing inclusion of pagenation artifact such as + * footnote and page number in link annotation. + */ +extern void dvi_link_annot (int flag); +/* The followings are for calculating bounding box of text for annotation. + * DVI uses push/pop to do line-feed-carriage-return. So line breaking is + * handled by inspecting current depth of DVI register stack. + */ +extern void dvi_tag_depth (void); +extern void dvi_untag_depth (void); +extern void dvi_compute_boxes (int flag); + +extern void dvi_do_special (const void *buffer, UNSIGNED_QUAD size); + +#ifdef XETEX +/* allow other modules (pdfdev) to ask whether we're collecting box areas */ +int dvi_is_tracking_boxes(void); +#endif + +#endif /* _DVI_H_ */ diff --git a/Build/source/texk/dvipdfm-x/mpost.c b/Build/source/texk/dvipdfm-x/mpost.c new file mode 100644 index 00000000000..c5feb0cb1b6 --- /dev/null +++ b/Build/source/texk/dvipdfm-x/mpost.c @@ -0,0 +1,1686 @@ +/* + + This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. + + Copyright (C) 2007-2012 by Jin-Hwan Cho and Shunsaku Hirata, + the dvipdfmx project team. + + Copyright (C) 1998, 1999 by Mark A. Wicks + + This program 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; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include "system.h" +#include "mem.h" +#include "error.h" +#include "mfileio.h" +#include "numbers.h" + +#include "tfm.h" + +#include "pdfobj.h" +#include "pdfparse.h" +#include "pdfdev.h" +#include "pdfdoc.h" + +#include "pdfcolor.h" +#include "pdfdraw.h" + +#include "fontmap.h" +#include "subfont.h" + +#include "pdfximage.h" + +#include "mpost.h" + +/* + * In PDF, current path is not a part of graphics state parameter. + * Hence, current path is not saved by the "q" operator and is not + * recovered by the "Q" operator. This means that the following PS + * code + * + * gsave grestore ... + * + * can't be translated to PDF code + * + * q Q ... + * + * . Only clipping path (which is graphics state parameter in PDF + * too) is treated in the same way. So, we write clipping path + * immediately and forget about it but remember current path. + */ + +static int mp_parse_body (const char **start, const char *end, double x_user, double y_user); + +static struct mp_font +{ + char *font_name; + int font_id; + int tfm_id; /* Used for text width calculation */ + int subfont_id; + double pt_size; +} font_stack[PDF_GSAVE_MAX] = { + {NULL, -1, -1, -1, 0} +}; +static int currentfont = -1; + +#define CURRENT_FONT() ((currentfont < 0) ? NULL : &font_stack[currentfont]) + +/* Compatibility */ +#define MP_CMODE_MPOST 0 +#define MP_CMODE_DVIPSK 1 +#define MP_CMODE_PTEXVERT 2 +static int mp_cmode = MP_CMODE_MPOST; + +static int +mp_setfont (const char *font_name, double pt_size) +{ + const char *name = font_name; + struct mp_font *font; + int subfont_id = -1; + fontmap_rec *mrec; + + font = CURRENT_FONT(); + + if (font) { + if (!strcmp(font->font_name, font_name) && + font->pt_size == pt_size) + return 0; + } else { /* No currentfont */ +/* ***TODO*** Here some problem exists! */ + font = &font_stack[0]; + font->font_name = NULL; + currentfont = 0; + } + + mrec = pdf_lookup_fontmap_record(font_name); + if (mrec && mrec->charmap.sfd_name && mrec->charmap.subfont_id) { + subfont_id = sfd_load_record(mrec->charmap.sfd_name, mrec->charmap.subfont_id); + } + + /* See comments in dvi_locate_font() in dvi.c. */ + if (mrec && mrec->map_name) { + name = mrec->map_name; + } else { + name = font_name; + } + + if (font->font_name) + RELEASE(font->font_name); + font->font_name = NEW(strlen(font_name) + 1, char); + strcpy(font->font_name, font_name); + font->subfont_id = subfont_id; + font->pt_size = pt_size; + font->tfm_id = tfm_open(font_name, 0); /* Need not exist in MP mode */ + font->font_id = pdf_dev_locate_font(name, + (spt_t) (pt_size * dev_unit_dviunit())); + + if (font->font_id < 0) { + ERROR("MPOST: No physical font assigned for \"%s\".", font_name); + return 1; + } + + return 0; +} + +static void +save_font (void) +{ + struct mp_font *current, *next; + + if (currentfont < 0) { + font_stack[0].font_name = NEW(strlen("Courier") + 1, char); + strcpy(font_stack[0].font_name, "Courier"); + font_stack[0].pt_size = 1; + font_stack[0].tfm_id = 0; + font_stack[0].subfont_id = 0; + currentfont = 0; + } + + current = &font_stack[currentfont++]; + next = &font_stack[currentfont ]; + next->font_name = NEW(strlen(current->font_name)+1, char); + strcpy(next->font_name, current->font_name); + next->pt_size = current->pt_size; + + next->subfont_id = current->subfont_id; + next->tfm_id = current->tfm_id; +} + +static void +restore_font (void) +{ + struct mp_font *current; + + current = CURRENT_FONT(); + if (current) { + if (current->font_name) + RELEASE(current->font_name); + current->font_name = NULL; + } else { + ERROR("No currentfont..."); + } + + currentfont--; +} + +static void +clear_fonts (void) +{ + while (currentfont >= 0) { + if (font_stack[currentfont].font_name) + RELEASE(font_stack[currentfont].font_name); + currentfont--; + } +} + +static int +is_fontname (const char *token) +{ + fontmap_rec *mrec; + + mrec = pdf_lookup_fontmap_record(token); + if (mrec) + return 1; + + return tfm_exists(token); +} + +int +mps_scan_bbox (const char **pp, const char *endptr, pdf_rect *bbox) +{ + char *number; + double values[4]; + int i; + + /* skip_white() skips lines starting '%'... */ + while (*pp < endptr && isspace(**pp)) + (*pp)++; + + /* Scan for bounding box record */ + while (*pp < endptr && **pp == '%') { + if (*pp + 14 < endptr && + !strncmp(*pp, "%%BoundingBox:", 14)) { + + *pp += 14; + + for (i = 0; i < 4; i++) { + skip_white(pp, endptr); + number = parse_number(pp, endptr); + if (!number) { + break; + } + values[i] = atof(number); + RELEASE(number); + } + if (i < 4) { + return -1; + } else { + bbox->llx = values[0]; + bbox->lly = values[1]; + bbox->urx = values[2]; + bbox->ury = values[3]; + + return 0; + } + } + skip_line (pp, endptr); + while (*pp < endptr && isspace(**pp)) + (*pp)++; + } + + return -1; +} + +static void +skip_prolog (const char **start, const char *end) +{ + int found_prolog = 0; + const char *save; + + save = *start; + while (*start < end) { + if (**start != '%') + skip_white(start, end); + if (*start >= end) + break; + if (!strncmp(*start, "%%EndProlog", 11)) { + found_prolog = 1; + skip_line(start, end); + break; + } else if (!strncmp(*start, "%%Page:", 7)) { + skip_line(start, end); + break; + } + skip_line(start, end); + } + if (!found_prolog) { + *start = save; + } + + return; +} + +/* PostScript Operators */ + +#define ADD 1 +#define SUB 2 +#define MUL 3 +#define DIV 4 +#define NEG 5 +#define TRUNCATE 6 + +#define CLEAR 10 +#define EXCH 11 +#define POP 12 + +#define NEWPATH 31 +#define CLOSEPATH 32 +#define MOVETO 33 +#define RMOVETO 34 +#define CURVETO 35 +#define RCURVETO 36 +#define LINETO 37 +#define RLINETO 38 +#define ARC 39 +#define ARCN 40 + +#define FILL 41 +#define STROKE 42 +#define SHOW 43 + +#define CLIP 44 +#define EOCLIP 45 + +#define SHOWPAGE 49 + +#define GSAVE 50 +#define GRESTORE 51 + +#define CONCAT 52 +#define SCALE 53 +#define TRANSLATE 54 +#define ROTATE 55 + +#define SETLINEWIDTH 60 +#define SETDASH 61 +#define SETLINECAP 62 +#define SETLINEJOIN 63 +#define SETMITERLIMIT 64 + +#define SETGRAY 70 +#define SETRGBCOLOR 71 +#define SETCMYKCOLOR 72 + +#define CURRENTPOINT 80 +#define IDTRANSFORM 81 +#define DTRANSFORM 82 + +#define FINDFONT 201 +#define SCALEFONT 202 +#define SETFONT 203 +#define CURRENTFONT 204 + +#define STRINGWIDTH 210 + +#define DEF 999 + +#define FSHOW 1001 +#define STEXFIG 1002 +#define ETEXFIG 1003 +#define HLW 1004 +#define VLW 1005 +#define RD 1006 +#define B 1007 + +static struct operators +{ + const char *token; + int opcode; +} ps_operators[] = { + {"add", ADD}, + {"mul", MUL}, + {"div", DIV}, + {"neg", NEG}, + {"sub", SUB}, + {"truncate", TRUNCATE}, + + {"clear", CLEAR}, + {"exch", EXCH}, + {"pop", POP}, + + {"clip", CLIP}, + {"eoclip", EOCLIP}, + {"closepath", CLOSEPATH}, + {"concat", CONCAT}, + + {"newpath", NEWPATH}, + {"moveto", MOVETO}, + {"rmoveto", RMOVETO}, + {"lineto", LINETO}, + {"rlineto", RLINETO}, + {"curveto", CURVETO}, + {"rcurveto", RCURVETO}, + {"arc", ARC}, + {"arcn", ARCN}, + + {"stroke", STROKE}, + {"fill", FILL}, + {"show", SHOW}, + {"showpage", SHOWPAGE}, + + {"gsave", GSAVE}, + {"grestore", GRESTORE}, + {"translate", TRANSLATE}, + {"rotate", ROTATE}, + {"scale", SCALE}, + + {"setlinecap", SETLINECAP}, + {"setlinejoin", SETLINEJOIN}, + {"setlinewidth", SETLINEWIDTH}, + {"setmiterlimit", SETMITERLIMIT}, + {"setdash", SETDASH}, + + {"setgray", SETGRAY}, + {"setrgbcolor", SETRGBCOLOR}, + {"setcmykcolor", SETCMYKCOLOR}, + + {"currentpoint", CURRENTPOINT}, /* This is here for rotate support + in graphics package-not MP support */ + {"dtransform", DTRANSFORM}, + {"idtransform", IDTRANSFORM}, + + {"findfont", FINDFONT}, + {"scalefont", SCALEFONT}, + {"setfont", SETFONT}, + {"currentfont", CURRENTFONT}, + + {"stringwidth", STRINGWIDTH}, + + {"def", DEF} /* not implemented yet; just work with mptopdf */ +}; + +static struct operators mps_operators[] = { + {"fshow", FSHOW}, /* exch findfont exch scalefont setfont show */ + {"startTexFig", STEXFIG}, + {"endTexFig", ETEXFIG}, + {"hlw", HLW}, /* 0 dtransform exch truncate exch idtransform pop setlinewidth */ + {"vlw", VLW}, /* 0 exch dtransform truncate idtransform pop setlinewidth pop */ + {"l", LINETO}, + {"r", RLINETO}, + {"c", CURVETO}, + {"m", MOVETO}, + {"p", CLOSEPATH}, + {"n", NEWPATH}, + {"C", SETCMYKCOLOR}, + {"G", SETGRAY}, + {"R", SETRGBCOLOR}, + {"lj", SETLINEJOIN}, + {"ml", SETMITERLIMIT}, + {"lc", SETLINECAP}, + {"S", STROKE}, + {"F", FILL}, + {"q", GSAVE}, + {"Q", GRESTORE}, + {"s", SCALE}, + {"t", CONCAT}, + {"sd", SETDASH}, + {"rd", RD}, /* [] 0 setdash */ + {"P", SHOWPAGE}, + {"B", B}, /* gsave fill grestore */ + {"W", CLIP} +}; + +#define NUM_PS_OPERATORS (sizeof(ps_operators)/sizeof(ps_operators[0])) +#define NUM_MPS_OPERATORS (sizeof(mps_operators)/sizeof(mps_operators[0])) +static int +get_opcode (const char *token) +{ + int i; + + for (i = 0; i < NUM_PS_OPERATORS; i++) { + if (!strcmp(token, ps_operators[i].token)) { + return ps_operators[i].opcode; + } + } + + for (i = 0; i < NUM_MPS_OPERATORS; i++) { + if (!strcmp(token, mps_operators[i].token)) { + return mps_operators[i].opcode; + } + } + + return -1; +} + +#define PS_STACK_SIZE 1024 + +static pdf_obj *stack[PS_STACK_SIZE]; +static unsigned top_stack = 0; + +#define POP_STACK() ((top_stack > 0) ? stack[--top_stack] : NULL) +#define PUSH_STACK(o,e) { \ + if (top_stack < PS_STACK_SIZE) { \ + stack[top_stack++] = (o); \ + } else { \ + WARN("PS stack overflow including MetaPost file or inline PS code"); \ + *(e) = 1; \ + } \ +} + +static int +do_exch (void) +{ + pdf_obj *tmp; + + if (top_stack < 2) + return -1; + + tmp = stack[top_stack-1]; + stack[top_stack-1] = stack[top_stack-2]; + stack[top_stack-2] = tmp; + + return 0; +} + +static int +do_clear (void) +{ + pdf_obj *tmp; + + while (top_stack > 0) { + tmp = POP_STACK(); + if (tmp) + pdf_release_obj(tmp); + } + + return 0; +} + +/* This should be set_bottom and clear (or + * have independent stack) to ensure stack + * depth do not go below real stack bottom. + */ +static void +mps_stack_clear_to (int depth) +{ + pdf_obj *tmp; + + while (top_stack > depth) { + tmp = POP_STACK(); + if (tmp) + pdf_release_obj(tmp); + } + + return; +} + +static int +pop_get_numbers (double *values, int count) +{ + pdf_obj *tmp; + + while (count-- > 0) { + tmp = POP_STACK(); + if (!tmp) { + WARN("mpost: Stack underflow."); + break; + } else if (!PDF_OBJ_NUMBERTYPE(tmp)) { + WARN("mpost: Not a number!"); + pdf_release_obj(tmp); + break; + } + values[count] = pdf_number_value(tmp); + pdf_release_obj(tmp); + } + + return (count + 1); +} + +static int +cvr_array (pdf_obj *array, double *values, int count) +{ + if (!PDF_OBJ_ARRAYTYPE(array)) { + WARN("mpost: Not an array!"); + } else { + pdf_obj *tmp; + + while (count-- > 0) { + tmp = pdf_get_array(array, count); + if (!PDF_OBJ_NUMBERTYPE(tmp)) { + WARN("mpost: Not a number!"); + break; + } + values[count] = pdf_number_value(tmp); + } + } + if (array) + pdf_release_obj(array); + + return (count + 1); +} + +static int +is_fontdict (pdf_obj *dict) +{ + pdf_obj *tmp; + + if (!PDF_OBJ_DICTTYPE(dict)) + return 0; + + tmp = pdf_lookup_dict(dict, "Type"); + if (!tmp || !PDF_OBJ_NAMETYPE(tmp) || + strcmp(pdf_name_value(tmp), "Font")) { + return 0; + } + + tmp = pdf_lookup_dict(dict, "FontName"); + if (!tmp || !PDF_OBJ_NAMETYPE(tmp)) { + return 0; + } + + tmp = pdf_lookup_dict(dict, "FontScale"); + if (!tmp || !PDF_OBJ_NUMBERTYPE(tmp)) { + return 0; + } + + return 1; +} + +static int +do_findfont (void) +{ + int error = 0; + pdf_obj *font_dict, *font_name; + + font_name = POP_STACK(); + if (!font_name) + return 1; + else if (PDF_OBJ_STRINGTYPE(font_name) || + PDF_OBJ_NAMETYPE(font_name)) { + /* Do not check the existence... + * The reason for this is that we cannot locate PK font without + * font scale. + */ + font_dict = pdf_new_dict(); + pdf_add_dict(font_dict, + pdf_new_name("Type"), pdf_new_name("Font")); + if (PDF_OBJ_STRINGTYPE(font_name)) { + pdf_add_dict(font_dict, + pdf_new_name("FontName"), + pdf_new_name(pdf_string_value(font_name))); + pdf_release_obj(font_name); + } else { + pdf_add_dict(font_dict, + pdf_new_name("FontName"), font_name); + } + pdf_add_dict(font_dict, + pdf_new_name("FontScale"), pdf_new_number(1.0)); + + if (top_stack < PS_STACK_SIZE) { + stack[top_stack++] = font_dict; + } else { + WARN("PS stack overflow including MetaPost file or inline PS code"); + pdf_release_obj(font_dict); + error = 1; + } + } else { + error = 1; + } + + return error; +} + +static int +do_scalefont (void) +{ + int error = 0; + pdf_obj *font_dict; + pdf_obj *font_scale; + double scale; + + error = pop_get_numbers(&scale, 1); + if (error) + return error; + + font_dict = POP_STACK(); + if (!font_dict) + error = 1; + else if (is_fontdict(font_dict)) { + font_scale = pdf_lookup_dict(font_dict, "FontScale"); + pdf_set_number(font_scale, pdf_number_value(font_scale)*scale); + if (top_stack < PS_STACK_SIZE) { + stack[top_stack++] = font_dict; + } else { + WARN("PS stack overflow including MetaPost file or inline PS code"); + pdf_release_obj(font_dict); + error = 1; + } + } else { + error = 1; + } + + return error; +} + +static int +do_setfont (void) +{ + int error = 0; + char *font_name; + double font_scale; + pdf_obj *font_dict; + + font_dict = POP_STACK(); + if (!is_fontdict(font_dict)) + error = 1; + else { + /* Subfont support prevent us from managing + * font in a single place... + */ + font_name = pdf_name_value (pdf_lookup_dict(font_dict, "FontName")); + font_scale = pdf_number_value(pdf_lookup_dict(font_dict, "FontScale")); + + error = mp_setfont(font_name, font_scale); + } + pdf_release_obj(font_dict); + + return error; +} + +/* Push dummy font dict onto PS stack */ +static int +do_currentfont (void) +{ + int error = 0; + struct mp_font *font; + pdf_obj *font_dict; + + font = CURRENT_FONT(); + if (!font) { + WARN("Currentfont undefined..."); + return 1; + } else { + font_dict = pdf_new_dict(); + pdf_add_dict(font_dict, + pdf_new_name("Type"), + pdf_new_name("Font")); + pdf_add_dict(font_dict, + pdf_new_name("FontName"), + pdf_new_name(font->font_name)); + pdf_add_dict(font_dict, + pdf_new_name("FontScale"), + pdf_new_number(font->pt_size)); + if (top_stack < PS_STACK_SIZE) { + stack[top_stack++] = font_dict; + } else { + WARN("PS stack overflow..."); + pdf_release_obj(font_dict); + error = 1; + } + } + + return error; +} + +static int +do_show (void) +{ + struct mp_font *font; + pdf_coord cp; + pdf_obj *text_str; + int length; + unsigned char *strptr; + double text_width; + + font = CURRENT_FONT(); + if (!font) { + WARN("Currentfont not set."); /* Should not be error... */ + return 1; + } + + pdf_dev_currentpoint(&cp); + + text_str = POP_STACK(); + if (!PDF_OBJ_STRINGTYPE(text_str)) { + if (text_str) + pdf_release_obj(text_str); + return 1; + } + if (font->font_id < 0) { + WARN("mpost: not set."); /* Should not be error... */ + pdf_release_obj(text_str); + return 1; + } + + strptr = pdf_string_value (text_str); + length = pdf_string_length(text_str); + + if (font->tfm_id < 0) { + WARN("mpost: TFM not found for \"%s\".", font->font_name); + WARN("mpost: Text width not calculated..."); + } + + text_width = 0.0; + if (font->subfont_id >= 0) { + unsigned short uch; + unsigned char *ustr; + int i; + + ustr = NEW(length * 2, unsigned char); + for (i = 0; i < length; i++) { + uch = lookup_sfd_record(font->subfont_id, strptr[i]); + ustr[2*i ] = uch >> 8; + ustr[2*i+1] = uch & 0xff; + if (font->tfm_id >= 0) { + text_width += tfm_get_width(font->tfm_id, strptr[i]); + } + } + text_width *= font->pt_size; + + pdf_dev_set_string((spt_t)(cp.x * dev_unit_dviunit()), + (spt_t)(cp.y * dev_unit_dviunit()), + ustr, length * 2, + (spt_t)(text_width*dev_unit_dviunit()), + font->font_id, 0); + RELEASE(ustr); + } else { +#define FWBASE ((double) (1<<20)) + if (font->tfm_id >= 0) { + text_width = (double) tfm_string_width(font->tfm_id, strptr, length)/FWBASE; + text_width *= font->pt_size; + } + pdf_dev_set_string((spt_t)(cp.x * dev_unit_dviunit()), + (spt_t)(cp.y * dev_unit_dviunit()), + strptr, length, + (spt_t)(text_width*dev_unit_dviunit()), + font->font_id, 0); + } + + if (pdf_dev_get_font_wmode(font->font_id)) { + pdf_dev_rmoveto(0.0, -text_width); + } else { + pdf_dev_rmoveto(text_width, 0.0); + } + + graphics_mode(); + pdf_release_obj(text_str); + + return 0; +} + +static int +do_mpost_bind_def (const char *ps_code, double x_user, double y_user) +{ + int error = 0; + const char *start, *end; + + start = ps_code; + end = start + strlen(start); + + error = mp_parse_body(&start, end, x_user, y_user); + + return error; +} + +static int +do_texfig_operator (int opcode, double x_user, double y_user) +{ + static transform_info fig_p; + static int in_tfig = 0; + static int xobj_id = -1; + static int count = 0; + double values[6]; + int error = 0; + + switch (opcode) { + case STEXFIG: + error = pop_get_numbers(values, 6); + if (!error) { + double dvi2pts; + char resname[256]; + + transform_info_clear(&fig_p); + dvi2pts = 1.0/dev_unit_dviunit(); + + fig_p.width = values[0] * dvi2pts; + fig_p.height = values[1] * dvi2pts; + fig_p.bbox.llx = values[2] * dvi2pts; + fig_p.bbox.lly = -values[3] * dvi2pts; + fig_p.bbox.urx = values[4] * dvi2pts; + fig_p.bbox.ury = -values[5] * dvi2pts; + fig_p.flags |= INFO_HAS_USER_BBOX; + + sprintf(resname, "__tf%d__", count); + xobj_id = pdf_doc_begin_grabbing(resname, + fig_p.bbox.llx, fig_p.bbox.ury, &fig_p.bbox); + + in_tfig = 1; + count++; + } + break; + case ETEXFIG: + if (!in_tfig) + ERROR("endTexFig without valid startTexFig!."); + + pdf_doc_end_grabbing(NULL); + pdf_dev_put_image(xobj_id, &fig_p, x_user, y_user); + in_tfig = 0; + break; + default: + error = 1; + } + + return error; +} + +/* + * buggy... + */ + +/* + * CTM(Current Transformation Matrix) means the transformation of User Space + * to Device Space coordinates. Because DVIPDFMx does not know the resolution + * of Device Space, we assume that the resolution is 1/1000. + */ +#define DEVICE_RESOLUTION 1000 +static int +ps_dev_CTM (pdf_tmatrix *M) +{ + pdf_dev_currentmatrix(M); + M->a *= DEVICE_RESOLUTION; M->b *= DEVICE_RESOLUTION; + M->c *= DEVICE_RESOLUTION; M->d *= DEVICE_RESOLUTION; + M->e *= DEVICE_RESOLUTION; M->f *= DEVICE_RESOLUTION; + + return 0; +} + +/* + * Again, the only piece that needs x_user and y_user is + * that piece dealing with texfig. + */ +static int +do_operator (const char *token, double x_user, double y_user) +{ + int error = 0; + int opcode = 0; + double values[12]; + pdf_obj *tmp = NULL; + pdf_tmatrix matrix; + pdf_coord cp; + pdf_color color; + +#define PUSH(o) { \ + if (top_stack < PS_STACK_SIZE) { \ + stack[top_stack++] = (o); \ + } else { \ + WARN("PS stack overflow including MetaPost file or inline PS code"); \ + error=1; \ + break;\ + } \ +} + + opcode = get_opcode(token); + + switch (opcode) { + + /* + * Arithmetic operators + */ + case ADD: + error = pop_get_numbers(values, 2); + if (!error) + PUSH(pdf_new_number(values[0] + values[1])); + break; + case MUL: + error = pop_get_numbers(values, 2); + if (!error) + PUSH(pdf_new_number(values[0]*values[1])); + break; + case NEG: + error = pop_get_numbers(values, 1); + if (!error) + PUSH(pdf_new_number(-values[0])); + break; + case SUB: + error = pop_get_numbers(values, 2); + if (!error) + PUSH(pdf_new_number(values[0] - values[1])); + break; + case DIV: + error = pop_get_numbers(values, 2); + if (!error) + PUSH(pdf_new_number(values[0]/values[1])); + break; + case TRUNCATE: /* Round toward zero. */ + error = pop_get_numbers(values, 1); + if (!error) + PUSH(pdf_new_number(((values[0] > 0) ? floor(values[0]) : ceil(values[0])))); + break; + + /* Stack operation */ + case CLEAR: + error = do_clear(); + break; + case POP: + tmp = POP_STACK(); + if (tmp) + pdf_release_obj(tmp); + break; + case EXCH: + error = do_exch(); + break; + + /* Path construction */ + case MOVETO: + error = pop_get_numbers(values, 2); + if (!error) + error = pdf_dev_moveto(values[0], values[1]); + break; + case RMOVETO: + error = pop_get_numbers(values, 2); + if (!error) + error = pdf_dev_rmoveto(values[0], values[1]); + break; + case LINETO: + error = pop_get_numbers(values, 2); + if (!error) + error = pdf_dev_lineto(values[0], values[1]); + break; + case RLINETO: + error = pop_get_numbers(values, 2); + if (!error) + error = pdf_dev_rlineto(values[0], values[1]); + break; + case CURVETO: + error = pop_get_numbers(values, 6); + if (!error) + error = pdf_dev_curveto(values[0], values[1], + values[2], values[3], + values[4], values[5]); + break; + case RCURVETO: + error = pop_get_numbers(values, 6); + if (!error) + error = pdf_dev_rcurveto(values[0], values[1], + values[2], values[3], + values[4], values[5]); + break; + case CLOSEPATH: + error = pdf_dev_closepath(); + break; + case ARC: + error = pop_get_numbers(values, 5); + if (!error) + error = pdf_dev_arc(values[0], values[1], + values[2], /* rad */ + values[3], values[4]); + break; + case ARCN: + error = pop_get_numbers(values, 5); + if (!error) + error = pdf_dev_arcn(values[0], values[1], + values[2], /* rad */ + values[3], values[4]); + break; + + case NEWPATH: + pdf_dev_newpath(); + break; + case STROKE: + /* fill rule not supported yet */ + pdf_dev_flushpath('S', PDF_FILL_RULE_NONZERO); + break; + case FILL: + pdf_dev_flushpath('f', PDF_FILL_RULE_NONZERO); + break; + + case CLIP: + error = pdf_dev_clip(); + break; + case EOCLIP: + error = pdf_dev_eoclip(); + break; + + /* Graphics state operators: */ + case GSAVE: + error = pdf_dev_gsave(); + save_font(); + break; + case GRESTORE: + error = pdf_dev_grestore(); + restore_font(); + break; + + case CONCAT: + tmp = POP_STACK(); + error = cvr_array(tmp, values, 6); /* This does pdf_release_obj() */ + tmp = NULL; + if (error) + WARN("Missing array before \"concat\"."); + else { + pdf_setmatrix(&matrix, + values[0], values[1], + values[2], values[3], + values[4], values[5]); + error = pdf_dev_concat(&matrix); + } + break; + case SCALE: + error = pop_get_numbers(values, 2); + if (!error) { + switch (mp_cmode) { +#ifndef WITHOUT_ASCII_PTEX + case MP_CMODE_PTEXVERT: + pdf_setmatrix(&matrix, + values[1], 0.0, + 0.0 , values[0], + 0.0 , 0.0); + break; +#endif /* !WITHOUT_ASCII_PTEX */ + default: + pdf_setmatrix(&matrix, + values[0], 0.0, + 0.0 , values[1], + 0.0 , 0.0); + break; + } + + error = pdf_dev_concat(&matrix); + } + break; + /* Positive angle means clock-wise direction in graphicx-dvips??? */ + case ROTATE: + error = pop_get_numbers(values, 1); + if (!error) { + values[0] = values[0] * M_PI / 180; + + switch (mp_cmode) { + case MP_CMODE_DVIPSK: + case MP_CMODE_MPOST: /* Really? */ +#ifndef WITHOUT_ASCII_PTEX + case MP_CMODE_PTEXVERT: +#endif /* !WITHOUT_ASCII_PTEX */ + pdf_setmatrix(&matrix, + cos(values[0]), -sin(values[0]), + sin(values[0]), cos(values[0]), + 0.0, 0.0); + break; + default: + pdf_setmatrix(&matrix, + cos(values[0]) , sin(values[0]), + -sin(values[0]), cos(values[0]), + 0.0, 0.0); + break; + } + error = pdf_dev_concat(&matrix); + } + break; + case TRANSLATE: + error = pop_get_numbers(values, 2); + if (!error) { + pdf_setmatrix(&matrix, + 1.0, 0.0, + 0.0, 1.0, + values[0], values[1]); + error = pdf_dev_concat(&matrix); + } + break; + + case SETDASH: + error = pop_get_numbers(values, 1); + if (!error) { + pdf_obj *pattern, *dash; + int i, num_dashes; + double dash_values[PDF_DASH_SIZE_MAX]; + double offset; + + offset = values[0]; + pattern = POP_STACK(); + if (!PDF_OBJ_ARRAYTYPE(pattern)) { + if (pattern) + pdf_release_obj(pattern); + error = 1; + break; + } + num_dashes = pdf_array_length(pattern); + if (num_dashes > PDF_DASH_SIZE_MAX) { + WARN("Too many dashes..."); + pdf_release_obj(pattern); + error = 1; + break; + } + for (i = 0; + i < num_dashes && !error ; i++) { + dash = pdf_get_array(pattern, i); + if (!PDF_OBJ_NUMBERTYPE(dash)) + error = 1; + else { + dash_values[i] = pdf_number_value(dash); + } + } + pdf_release_obj(pattern); + if (!error) { + error = pdf_dev_setdash(num_dashes, dash_values, offset); + } + } + break; + case SETLINECAP: + error = pop_get_numbers(values, 1); + if (!error) + error = pdf_dev_setlinecap((int)values[0]); + break; + case SETLINEJOIN: + error = pop_get_numbers(values, 1); + if (!error) + error = pdf_dev_setlinejoin((int)values[0]); + break; + case SETLINEWIDTH: + error = pop_get_numbers(values, 1); + if (!error) + error = pdf_dev_setlinewidth(values[0]); + break; + case SETMITERLIMIT: + error = pop_get_numbers(values, 1); + if (!error) + error = pdf_dev_setmiterlimit(values[0]); + break; + + case SETCMYKCOLOR: + error = pop_get_numbers(values, 4); + /* Not handled properly */ + if (!error) { + pdf_color_cmykcolor(&color, + values[0], values[1], + values[2], values[3]); +#ifdef XETEX + pdf_dev_set_color(&color); +#else + pdf_dev_set_strokingcolor(&color); + pdf_dev_set_nonstrokingcolor(&color); +#endif + } + break; + case SETGRAY: + /* Not handled properly */ + error = pop_get_numbers(values, 1); + if (!error) { + pdf_color_graycolor(&color, values[0]); +#ifdef XETEX + pdf_dev_set_color(&color); +#else + pdf_dev_set_strokingcolor(&color); + pdf_dev_set_nonstrokingcolor(&color); +#endif + } + break; + case SETRGBCOLOR: + error = pop_get_numbers(values, 3); + if (!error) { + pdf_color_rgbcolor(&color, + values[0], values[1], values[2]); +#ifdef XETEX + pdf_dev_set_color(&color); +#else + pdf_dev_set_strokingcolor(&color); + pdf_dev_set_nonstrokingcolor(&color); +#endif + } + break; + + case SHOWPAGE: /* Let's ignore this for now */ + break; + + case CURRENTPOINT: + error = pdf_dev_currentpoint(&cp); + if (!error) { + PUSH(pdf_new_number(cp.x)); + PUSH(pdf_new_number(cp.y)); + } + break; + + case DTRANSFORM: + { + int has_matrix = 0; + + tmp = POP_STACK(); + if (PDF_OBJ_ARRAYTYPE(tmp)) { + error = cvr_array(tmp, values, 6); /* This does pdf_release_obj() */ + tmp = NULL; + if (error) + break; + pdf_setmatrix(&matrix, + values[0], values[1], + values[2], values[3], + values[4], values[5]); + tmp = POP_STACK(); + has_matrix = 1; + } + + if (!PDF_OBJ_NUMBERTYPE(tmp)) { + error = 1; + break; + } + cp.y = pdf_number_value(tmp); + pdf_release_obj(tmp); + + tmp = POP_STACK(); + if (!PDF_OBJ_NUMBERTYPE(tmp)) { + error = 1; + break; + } + cp.x = pdf_number_value(tmp); + pdf_release_obj(tmp); + + if (!has_matrix) { + ps_dev_CTM(&matrix); /* Here, we need real PostScript CTM */ + } + pdf_dev_dtransform(&cp, &matrix); + PUSH(pdf_new_number(cp.x)); + PUSH(pdf_new_number(cp.y)); + } + break; + + case IDTRANSFORM: + { + int has_matrix = 0; + + tmp = POP_STACK(); + if (PDF_OBJ_ARRAYTYPE(tmp)) { + error = cvr_array(tmp, values, 6); /* This does pdf_release_obj() */ + tmp = NULL; + if (error) + break; + pdf_setmatrix(&matrix, + values[0], values[1], + values[2], values[3], + values[4], values[5]); + tmp = POP_STACK(); + has_matrix = 1; + } + + if (!PDF_OBJ_NUMBERTYPE(tmp)) { + error = 1; + break; + } + cp.y = pdf_number_value(tmp); + pdf_release_obj(tmp); + + tmp = POP_STACK(); + if (!PDF_OBJ_NUMBERTYPE(tmp)) { + error = 1; + break; + } + cp.x = pdf_number_value(tmp); + pdf_release_obj(tmp); + + if (!has_matrix) { + ps_dev_CTM(&matrix); /* Here, we need real PostScript CTM */ + } + pdf_dev_idtransform(&cp, &matrix); + PUSH(pdf_new_number(cp.x)); + PUSH(pdf_new_number(cp.y)); + break; + } + + case FINDFONT: + error = do_findfont(); + break; + case SCALEFONT: + error = do_scalefont(); + break; + case SETFONT: + error = do_setfont(); + break; + case CURRENTFONT: + error = do_currentfont(); + break; + + case SHOW: + error = do_show(); + break; + + case STRINGWIDTH: + error = 1; + break; + + /* Extensions */ + case FSHOW: + error = do_mpost_bind_def("exch findfont exch scalefont setfont show", x_user, y_user); + break; + case STEXFIG: + case ETEXFIG: + error = do_texfig_operator(opcode, x_user, y_user); + break; + case HLW: + error = do_mpost_bind_def("0 dtransform exch truncate exch idtransform pop setlinewidth", x_user, y_user); + break; + case VLW: + error = do_mpost_bind_def("0 exch dtransform truncate idtransform setlinewidth pop", x_user, y_user); + break; + case RD: + error = do_mpost_bind_def("[] 0 setdash", x_user, y_user); + break; + case B: + error = do_mpost_bind_def("gsave fill grestore", x_user, y_user); + break; + + case DEF: + tmp = POP_STACK(); + tmp = POP_STACK(); + /* do nothing; not implemented yet */ + break; + + default: + if (is_fontname(token)) { + PUSH(pdf_new_name(token)); + } else { + WARN("Unknown token \"%s\"", token); + error = 1; + } + break; + } + + return error; +} + +/* + * The only sections that need to know x_user and y _user are those + * dealing with texfig. + */ +static int +mp_parse_body (const char **start, const char *end, double x_user, double y_user) +{ + char *token; + pdf_obj *obj; + int error = 0; + + skip_white(start, end); + while (*start < end && !error) { + if (isdigit(**start) || + (*start < end - 1 && + (**start == '+' || **start == '-' || **start == '.' ))) { + double value; + char *next; + + value = strtod(*start, &next); + if (next < end && !strchr("<([{/%", *next) && !isspace(*next)) { + WARN("Unkown PostScript operator."); + dump(*start, next); + error = 1; + } else { + PUSH(pdf_new_number(value)); + *start = next; + } + /* + * PDF parser can't handle PS operator inside arrays. + * This shouldn't use parse_pdf_array(). + */ + } else if (**start == '[' && + (obj = parse_pdf_array(start, end, NULL))) { + PUSH(obj); + /* This cannot handle ASCII85 string. */ + } else if (*start < end - 1 && + (**start == '<' && *(*start+1) == '<') && + (obj = parse_pdf_dict(start, end, NULL))) { + PUSH(obj); + } else if ((**start == '(' || **start == '<') && + (obj = parse_pdf_string (start, end))) { + PUSH(obj); + } else if (**start == '/' && + (obj = parse_pdf_name(start, end))) { + PUSH(obj); + } else { + token = parse_ident(start, end); + if (!token) + error = 1; + else { + error = do_operator(token, x_user, y_user); + RELEASE(token); + } + } + skip_white(start, end); + } + + return error; +} + +void +mps_eop_cleanup (void) +{ + clear_fonts(); + do_clear(); +} + +int +mps_stack_depth (void) +{ + return top_stack; +} + +int +mps_exec_inline (const char **p, const char *endptr, + double x_user, double y_user) +{ + int error; + int dirmode, autorotate; + + /* Compatibility for dvipsk. */ + dirmode = pdf_dev_get_dirmode(); + if (dirmode) { + mp_cmode = MP_CMODE_PTEXVERT; + } else { + mp_cmode = MP_CMODE_DVIPSK; + } + + autorotate = pdf_dev_get_param(PDF_DEV_PARAM_AUTOROTATE); + pdf_dev_set_param(PDF_DEV_PARAM_AUTOROTATE, 0); + //pdf_color_push(); /* ... */ + + /* Comment in dvipdfm: + * Remember that x_user and y_user are off by 0.02 % + */ + pdf_dev_moveto(x_user, y_user); + error = mp_parse_body(p, endptr, x_user, y_user); + + //pdf_color_pop(); /* ... */ + pdf_dev_set_param(PDF_DEV_PARAM_AUTOROTATE, autorotate); + pdf_dev_set_dirmode(dirmode); + + return error; +} + +/* mp inclusion is a bit of a hack. The routine + * starts a form at the lower left corner of + * the page and then calls begin_form_xobj telling + * it to record the image drawn there and bundle it + * up in an xojbect. This allows us to use the coordinates + * in the MP file directly. This appears to be the + * easiest way to be able to use the pdf_dev_set_string() + * command (with its scaled and extended fonts) without + * getting all confused about the coordinate system. + * After the xobject is created, the whole thing can + * be scaled any way the user wants + */ + +/* Should implement save and restore. */ +int +mps_include_page (const char *ident, FILE *fp) +{ + int form_id; + xform_info info; + int st_depth, gs_depth; + char *buffer; + const char *p, *endptr; + long length, nb_read; + int dirmode, autorotate, error; + + rewind(fp); + + length = file_size(fp); + if (length < 1) { + WARN("Can't read any byte in the MPS file."); + return -1; + } + + buffer = NEW(length + 1, char); + buffer[length] = '\0'; + p = buffer; + endptr = p + length; + + while (length > 0) { + nb_read = fread(buffer, sizeof(char), length, fp); + if (nb_read < 0) { + RELEASE(buffer); + WARN("Reading file failed..."); + return -1; + } + length -= nb_read; + } + + error = mps_scan_bbox(&p, endptr, &(info.bbox)); + if (error) { + WARN("Error occured while scanning MetaPost file headers: Could not find BoundingBox."); + RELEASE(buffer); + return -1; + } + skip_prolog(&p, endptr); + + dirmode = pdf_dev_get_dirmode(); + autorotate = pdf_dev_get_param(PDF_DEV_PARAM_AUTOROTATE); + pdf_dev_set_param(PDF_DEV_PARAM_AUTOROTATE, 0); + //pdf_color_push(); + + form_id = pdf_doc_begin_grabbing(ident, 0.0, 0.0, &(info.bbox)); + + mp_cmode = MP_CMODE_MPOST; + gs_depth = pdf_dev_current_depth(); + st_depth = mps_stack_depth(); + /* At this point the gstate must be initialized, since it starts a new + * XObject. Note that it increase gs_depth by 1. */ + pdf_dev_push_gstate(); + + error = mp_parse_body(&p, endptr, 0.0, 0.0); + RELEASE(buffer); + + if (error) { + WARN("Errors occured while interpreting MPS file."); + /* WARN("Leaving garbage in output PDF file."); */ + form_id = -1; + } + + /* It's time to pop the new gstate above. */ + pdf_dev_pop_gstate(); + mps_stack_clear_to (st_depth); + pdf_dev_grestore_to(gs_depth); + + pdf_doc_end_grabbing(NULL); + + //pdf_color_pop(); + pdf_dev_set_param(PDF_DEV_PARAM_AUTOROTATE, autorotate); + pdf_dev_set_dirmode(dirmode); + + return form_id; +} + +int +mps_do_page (FILE *image_file) +{ + int error = 0; + pdf_rect bbox; + char *buffer; + const char *start, *end; + long size; + int dir_mode; + + rewind(image_file); + if ((size = file_size(image_file)) == 0) { + WARN("Can't read any byte in the MPS file."); + return -1; + } + + buffer = NEW(size+1, char); + fread(buffer, sizeof(char), size, image_file); + buffer[size] = 0; + start = buffer; + end = buffer + size; + + error = mps_scan_bbox(&start, end, &bbox); + if (error) { + WARN("Error occured while scanning MetaPost file headers: Could not find BoundingBox."); + RELEASE(buffer); + return -1; + } + + mp_cmode = MP_CMODE_MPOST; + + pdf_doc_begin_page (1.0, 0.0, 0.0); /* scale, xorig, yorig */ + pdf_doc_set_mediabox(pdf_doc_current_page_number(), &bbox); + + dir_mode = pdf_dev_get_dirmode(); + pdf_dev_set_autorotate(0); + + skip_prolog(&start, end); + + error = mp_parse_body(&start, end, 0.0, 0.0); + + if (error) { + WARN("Errors occured while interpreting MetaPost file."); + } + + pdf_dev_set_autorotate(1); + pdf_dev_set_dirmode(dir_mode); + + pdf_doc_end_page(); + + RELEASE(buffer); + + /* + * The reason why we don't return XObject itself is + * PDF inclusion may not be made so. + */ + return (error ? -1 : 0); +} + +int +check_for_mp (FILE *image_file) +{ + int try_count = 10; + + rewind (image_file); + mfgets(work_buffer, WORK_BUFFER_SIZE, image_file); + if (strncmp(work_buffer, "%!PS", 4)) + return 0; + + while (try_count > 0) { + mfgets(work_buffer, WORK_BUFFER_SIZE, image_file); + if (!strncmp(work_buffer, "%%Creator:", 10)) { + if (strlen(work_buffer+10) >= 8 && + strstr(work_buffer+10, "MetaPost")) + break; + } + try_count--; + } + + return ((try_count > 0) ? 1 : 0); +} diff --git a/Build/source/texk/dvipdfm-x/pdfdev.h b/Build/source/texk/dvipdfm-x/pdfdev.h new file mode 100644 index 00000000000..f8a3a3f65b1 --- /dev/null +++ b/Build/source/texk/dvipdfm-x/pdfdev.h @@ -0,0 +1,235 @@ +/* + + This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. + + Copyright (C) 2002-2012 by Jin-Hwan Cho and Shunsaku Hirata, + the dvipdfmx project team. + + Copyright (C) 1998, 1999 by Mark A. Wicks + + This program 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; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +*/ + +#ifndef _PDFDEV_H_ +#define _PDFDEV_H_ + +#include "numbers.h" +#include "pdfobj.h" +#include "pdfcolor.h" + +typedef signed long spt_t; + +typedef struct pdf_tmatrix +{ + double a, b, c, d, e, f; +} pdf_tmatrix; + +typedef struct pdf_rect +{ + double llx, lly, urx, ury; +} pdf_rect; + +typedef struct pdf_coord +{ + double x, y; +} pdf_coord; + +/* The name transform_info is misleading. + * I'll put this here for a moment... + */ +typedef struct +{ + /* Physical dimensions + * + * If those values are given, images will be scaled + * and/or shifted to fit within a box described by + * those values. + */ + double width; + double height; + double depth; + + pdf_tmatrix matrix; /* transform matrix */ + pdf_rect bbox; /* user_bbox */ + + int flags; +} transform_info; +#define INFO_HAS_USER_BBOX (1 << 0) +#define INFO_HAS_WIDTH (1 << 1) +#define INFO_HAS_HEIGHT (1 << 2) +#define INFO_DO_CLIP (1 << 3) +#define INFO_DO_HIDE (1 << 4) +extern void transform_info_clear (transform_info *info); + + +extern void pdf_dev_set_verbose (void); + +/* Not in spt_t. */ +extern int pdf_sprint_matrix (char *buf, const pdf_tmatrix *p); +extern int pdf_sprint_rect (char *buf, const pdf_rect *p); +extern int pdf_sprint_coord (char *buf, const pdf_coord *p); +extern int pdf_sprint_length (char *buf, double value); +extern int pdf_sprint_number (char *buf, double value); + +/* unit_conv: multiplier for input unit (spt_t) to bp conversion. + * precision: How many fractional digits preserved in output (not real + * accuracy control). + * is_bw: Ignore color related special instructions. + */ +extern void pdf_init_device (double unit_conv, int precision, int is_bw); +extern void pdf_close_device (void); + +/* returns 1.0/unit_conv */ +extern double dev_unit_dviunit (void); + +#if 0 +/* DVI interpreter knows text positioning in relative motion. + * However, pdf_dev_set_string() recieves text string with placement + * in absolute position in user space, and it convert absolute + * positioning back to relative positioning. It is quite wasteful. + * + * TeX using DVI register stack operation to do CR and then use down + * command for LF. DVI interpreter knows hint for current leading + * and others (raised or lowered), but they are mostly lost in + * pdf_dev_set_string(). + */ + +typedef struct +{ + int argc; + + struct { + int is_kern; /* kern or string */ + + spt_t kern; /* negative kern means space */ + + int offset; /* offset to sbuf */ + int length; /* length of string */ + } args[]; + + unsigned char sbuf[PDF_STRING_LEN_MAX]; + +} pdf_text_string; + +/* Something for handling raise, leading, etc. here. */ + +#endif + +/* Draw texts and rules: + * + * xpos, ypos, width, and height are all fixed-point numbers + * converted to big-points by multiplying unit_conv (dvi2pts). + * They must be position in the user space. + * + * ctype: + * 0 - input string is in multi-byte encoding. + * 1 - input string is in 8-bit encoding. + * 2 - input string is in 16-bit encoding. + */ +extern void pdf_dev_set_string (spt_t xpos, spt_t ypos, + const void *instr_ptr, int instr_len, + spt_t text_width, + int font_id, int ctype); +extern void pdf_dev_set_rule (spt_t xpos, spt_t ypos, + spt_t width, spt_t height); + +/* Place XObject */ +extern int pdf_dev_put_image (int xobj_id, + transform_info *p, double ref_x, double ref_y); + +/* The design_size and ptsize required by PK font support... + */ +extern int pdf_dev_locate_font (const char *font_name, spt_t ptsize); + +extern int pdf_dev_setfont (const char *font_name, spt_t ptsize); + +/* The following two routines are NOT WORKING. + * Dvipdfmx doesn't manage gstate well.. + */ +#ifdef XETEX +/* pdf_dev_translate() or pdf_dev_concat() should be used. */ +extern void pdf_dev_set_origin (double orig_x, double orig_y); +#endif +/* Always returns 1.0, please rename this. */ +extern double pdf_dev_scale (void); + +/* Access text state parameters. */ +#if 0 +extern int pdf_dev_currentfont (void); /* returns font_id */ +extern double pdf_dev_get_font_ptsize (int font_id); +#endif +extern int pdf_dev_get_font_wmode (int font_id); /* ps: special support want this (pTeX). */ + +/* Text composition (direction) mode + * This affects only when auto_rotate is enabled. + */ +extern int pdf_dev_get_dirmode (void); +extern void pdf_dev_set_dirmode (int dir_mode); + +/* Set rect to rectangle in device space. + * Unit conversion spt_t to bp and transformation applied within it. + */ +extern void pdf_dev_set_rect (pdf_rect *rect, + spt_t x_pos, spt_t y_pos, + spt_t width, spt_t height, spt_t depth); + +/* Accessor to various device parameters. + */ +#define PDF_DEV_PARAM_AUTOROTATE 1 +#define PDF_DEV_PARAM_COLORMODE 2 + +extern int pdf_dev_get_param (int param_type); +extern void pdf_dev_set_param (int param_type, int value); + +/* Text composition mode is ignored (always same as font's + * writing mode) and glyph rotation is not enabled if + * auto_rotate is unset. + */ +#define pdf_dev_set_autorotate(v) pdf_dev_set_param(PDF_DEV_PARAM_AUTOROTATE, (v)) +#define pdf_dev_set_colormode(v) pdf_dev_set_param(PDF_DEV_PARAM_COLORMODE, (v)) + +/* + * For pdf_doc, pdf_draw and others. + */ + +/* Force reselecting font and color: + * XFrom (content grabbing) and Metapost support want them. + */ +extern void pdf_dev_reset_fonts (void); + +#ifdef XETEX +extern void pdf_dev_reset_color (void); +extern void pdf_dev_set_color (pdf_color *color); +extern void pdf_dev_set_strokingcolor (pdf_color *color); +extern void pdf_dev_set_nonstrokingcolor (pdf_color *color); +#endif + +/* Initialization of transformation matrix with M and others. + * They are called within pdf_doc_begin_page() and pdf_doc_end_page(). + */ +extern void pdf_dev_bop (const pdf_tmatrix *M); +extern void pdf_dev_eop (void); + +/* Text is normal and line art is not normal in dvipdfmx. So we don't have + * begin_text (BT in PDF) and end_text (ET), but instead we have graphics_mode() + * to terminate text section. pdf_dev_flushpath() and others call this. + */ +extern void graphics_mode (void); + +extern void pdf_dev_get_coord(double *xpos, double *ypos); +extern void pdf_dev_push_coord(double xpos, double ypos); +extern void pdf_dev_pop_coord(void); + +#endif /* _PDFDEV_H_ */ diff --git a/Build/source/texk/dvipdfm-x/pdfdoc.h b/Build/source/texk/dvipdfm-x/pdfdoc.h new file mode 100644 index 00000000000..c42fbd55410 --- /dev/null +++ b/Build/source/texk/dvipdfm-x/pdfdoc.h @@ -0,0 +1,157 @@ +/* + + This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. + + Copyright (C) 2007-2012 by Jin-Hwan Cho and Shunsaku Hirata, + the dvipdfmx project team. + + Copyright (C) 1998, 1999 by Mark A. Wicks + + This program 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; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +*/ + +#ifndef _PDFDOC_H_ +#define _PDFDOC_H_ + +#include "pdfobj.h" +#include "pdfdev.h" + +#define PDF_DOC_GRABBING_NEST_MAX 4 + +extern void pdf_doc_set_verbose (void); + +#ifdef XETEX +extern void pdf_open_document (const char *filename, + int do_encryption, + double media_width, double media_height, + double annot_grow_amount, int bookmark_open_depth); +#else +extern void pdf_open_document (const char *filename, + int do_encryption, + double media_width, double media_height, + double annot_grow_amount, int bookmark_open_depth, + int check_gotos); +#endif +extern void pdf_close_document (void); + + +/* PDF document metadata */ +extern void pdf_doc_set_creator (const char *creator); + + +/* They just return PDF dictionary object. + * Callers are completely responsible for doing right thing... + */ +extern pdf_obj *pdf_doc_get_dictionary (const char *category); +extern pdf_obj *pdf_doc_get_reference (const char *category); + +#define pdf_doc_page_tree() pdf_doc_get_dictionary("Pages") +#define pdf_doc_catalog() pdf_doc_get_dictionary("Catalog") +#define pdf_doc_docinfo() pdf_doc_get_dictionary("Info") +#define pdf_doc_names() pdf_doc_get_dictionary("Names") +#define pdf_doc_this_page() pdf_doc_get_dictionary("@THISPAGE") + +#ifndef XETEX +extern pdf_obj *pdf_doc_get_page (pdf_file *pf, long page_no, long *count_p, + pdf_rect *bbox, pdf_obj **resources_p); +#endif + +extern long pdf_doc_current_page_number (void); +extern pdf_obj *pdf_doc_current_page_resources (void); + +extern pdf_obj *pdf_doc_ref_page (unsigned long page_no); +#define pdf_doc_this_page_ref() pdf_doc_get_reference("@THISPAGE") +#define pdf_doc_next_page_ref() pdf_doc_get_reference("@NEXTPAGE") +#define pdf_doc_prev_page_ref() pdf_doc_get_reference("@PREVPAGE") + +/* Not really managing tree... + * There should be something for number tree. + */ +extern int pdf_doc_add_names (const char *category, + const void *key, int keylen, pdf_obj *value); + +extern void pdf_doc_set_bop_content (const char *str, unsigned length); +extern void pdf_doc_set_eop_content (const char *str, unsigned length); + +/* Page */ +extern void pdf_doc_begin_page (double scale, double x_origin, double y_origin); +extern void pdf_doc_end_page (void); + +extern void pdf_doc_set_mediabox (unsigned page_no, const pdf_rect *mediabox); +extern void pdf_doc_get_mediabox (unsigned page_no, pdf_rect *mediabox); + +extern void pdf_doc_add_page_content (const char *buffer, unsigned length); +extern void pdf_doc_add_page_resource (const char *category, + const char *resource_name, pdf_obj *resources); + +/* Article thread */ +extern void pdf_doc_begin_article (const char *article_id, pdf_obj *info); +#if 0 +extern void pdf_doc_end_article (const char *article_id); /* Do nothing... */ +#endif +extern void pdf_doc_make_article (const char *article_id, + const char **bead_order, int num_beads); +extern void pdf_doc_add_bead (const char *article_id, + const char *bead_id, + long page_no, const pdf_rect *rect); + +/* Bookmarks */ +extern int pdf_doc_bookmarks_up (void); +extern int pdf_doc_bookmarks_down (void); +extern void pdf_doc_bookmarks_add (pdf_obj *dict, int is_open); +extern int pdf_doc_bookmarks_depth (void); + + +/* Returns xobj_id of started xform. */ +extern int pdf_doc_begin_grabbing (const char *ident, + double ref_x, double ref_y, + const pdf_rect *cropbox); +extern void pdf_doc_end_grabbing (pdf_obj *attrib); + + +/* Annotation */ +#ifdef XETEX +extern void pdf_doc_add_annot (unsigned page_no, + const pdf_rect *rect, pdf_obj *annot_dict); +#else +extern void pdf_doc_add_annot (unsigned page_no, + const pdf_rect *rect, + pdf_obj *annot_dict, + int dest_is_new); +#endif + +/* Annotation with auto- clip and line (or page) break */ +extern void pdf_doc_begin_annot (pdf_obj *dict); +extern void pdf_doc_end_annot (void); + +extern void pdf_doc_break_annot (void); +extern void pdf_doc_expand_box (const pdf_rect *rect); + +/* Manual thumbnail */ +extern void pdf_doc_enable_manual_thumbnails (void); + +#if 0 +/* PageLabels - */ +extern void pdf_doc_set_pagelabel (long page_start, + const char *type, + const void *prefix, int pfrx_len, + long counter_start); +#endif + +/* Similar to bop_content */ +#include "pdfcolor.h" +extern void pdf_doc_set_bgcolor (const pdf_color *color); + +#endif /* _PDFDOC_H_ */ diff --git a/Build/source/texk/dvipdfm-x/pdfdraw.h b/Build/source/texk/dvipdfm-x/pdfdraw.h new file mode 100644 index 00000000000..f27c943b566 --- /dev/null +++ b/Build/source/texk/dvipdfm-x/pdfdraw.h @@ -0,0 +1,184 @@ +/* + + This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. + + Copyright (C) 2002-2012 by Jin-Hwan Cho and Shunsaku Hirata, + the dvipdfmx project team. + + Copyright (C) 1998, 1999 by Mark A. Wicks + + This program 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; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +*/ + +#ifndef _PDF_DRAW_H_ +#define _PDF_DRAW_H_ + +#include "pdfcolor.h" +#include "pdfdev.h" + +#define PDF_DASH_SIZE_MAX 16 +#define PDF_GSAVE_MAX 256 + +extern void pdf_dev_init_gstates (void); +extern void pdf_dev_clear_gstates (void); + +#define pdf_copymatrix(m,n) do {\ + (m)->a = (n)->a; (m)->b = (n)->b;\ + (m)->c = (n)->c; (m)->d = (n)->d;\ + (m)->e = (n)->e; (m)->f = (n)->f;\ +} while (0) + +#define pdf_setmatrix(m,p,q,r,s,t,u) do {\ + (m)->a = (p); (m)->b = (q);\ + (m)->c = (r); (m)->d = (s);\ + (m)->e = (t); (m)->f = (u);\ +} while (0) + +/* m -> n x m */ +#define pdf_concatmatrix(m,n) do {\ + double _tmp_a, _tmp_b, _tmp_c, _tmp_d; \ + _tmp_a = (m)->a; _tmp_b = (m)->b; \ + _tmp_c = (m)->c; _tmp_d = (m)->d; \ + (m)->a = ((n)->a) * _tmp_a + ((n)->b) * _tmp_c; \ + (m)->b = ((n)->a) * _tmp_b + ((n)->b) * _tmp_d; \ + (m)->c = ((n)->c) * _tmp_a + ((n)->d) * _tmp_c; \ + (m)->d = ((n)->c) * _tmp_b + ((n)->d) * _tmp_d; \ + (m)->e += ((n)->e) * _tmp_a + ((n)->f) * _tmp_c; \ + (m)->f += ((n)->e) * _tmp_b + ((n)->f) * _tmp_d; \ +} while (0) + +typedef struct pdf_path_ pdf_path; + +extern int pdf_dev_currentmatrix (pdf_tmatrix *M); +extern int pdf_dev_currentpoint (pdf_coord *cp); + +extern int pdf_dev_setlinewidth (double width); +extern int pdf_dev_setmiterlimit (double mlimit); +extern int pdf_dev_setlinecap (int style); +extern int pdf_dev_setlinejoin (int style); +extern int pdf_dev_setdash (int count, + double *pattern, + double offset); +#if 0 +extern int pdf_dev_setflat (int flatness); +#endif + +/* Path Construction */ +extern int pdf_dev_moveto (double x , double y); +extern int pdf_dev_rmoveto (double x , double y); +extern int pdf_dev_closepath (void); + +extern int pdf_dev_lineto (double x0 , double y0); +extern int pdf_dev_rlineto (double x0 , double y0); +extern int pdf_dev_curveto (double x0 , double y0, + double x1 , double y1, + double x2 , double y2); +#ifdef XETEX +extern int pdf_dev_vcurveto (double x0 , double y0, + double x1 , double y1); +extern int pdf_dev_ycurveto (double x0 , double y0, + double x1 , double y1); +#endif +extern int pdf_dev_rcurveto (double x0 , double y0, + double x1 , double y1, + double x2 , double y2); +extern int pdf_dev_arc (double c_x, double c_y, double r, + double a_0, double a_1); +extern int pdf_dev_arcn (double c_x, double c_y, double r, + double a_0, double a_1); + +#define PDF_FILL_RULE_NONZERO 0 +#define PDF_FILL_RULE_EVENODD 1 + +extern int pdf_dev_newpath (void); + +/* Path Painting */ +extern int pdf_dev_clip (void); +extern int pdf_dev_eoclip (void); + +#if 0 +extern int pdf_dev_rectstroke (double x, double y, + double w, double h, + const pdf_tmatrix *M /* optional */ + ); +#endif + +extern int pdf_dev_rectfill (double x, double y, double w, double h); +extern int pdf_dev_rectclip (double x, double y, double w, double h); +#ifdef XETEX +extern int pdf_dev_rectadd (double x, double y, double w, double h); +#endif + +extern int pdf_dev_flushpath (char p_op, int fill_rule); + +#define pdf_dev_fill() pdf_dev_flushpath('f', PDF_FILL_RULE_NONZERO) +#define pdf_dev_eofill() pdf_dev_flushpath('f', PDF_FILL_RULE_EVENODD) +#define pdf_dev_stroke() pdf_dev_flushpath('S', PDF_FILL_RULE_NONZERO) +#define pdf_dev_fillstroke() pdf_dev_flushpath('B', PDF_FILL_RULE_NONZERO) + +extern int pdf_dev_concat (const pdf_tmatrix *M); +/* NULL pointer of M mean apply current transformation */ +extern void pdf_dev_dtransform (pdf_coord *p, const pdf_tmatrix *M); +extern void pdf_dev_idtransform (pdf_coord *p, const pdf_tmatrix *M); +extern void pdf_dev_transform (pdf_coord *p, const pdf_tmatrix *M); +#if 0 +extern void pdf_dev_itransform (pdf_coord *p, const pdf_tmatrix *M); +#endif + +extern int pdf_dev_gsave (void); +extern int pdf_dev_grestore (void); + +/* Requires from mpost.c because new MetaPost graphics must initialize + * the current gstate. */ +extern int pdf_dev_push_gstate (void); +extern int pdf_dev_pop_gstate (void); + + +/* extension */ +extern int pdf_dev_arcx (double c_x, double c_y, + double r_x, double r_y, + double a_0, double a_1, + int a_d, /* arc direction */ + double xar /* x-axis-rotation */ + ); +extern int pdf_dev_bspline (double x0, double y0, + double x1, double y1, + double x2, double y2); + + +extern void pdf_invertmatrix (pdf_tmatrix *M); + +/* The depth here is the depth of q/Q nesting. + * We must remember current depth of nesting when starting a page or xform, + * and must recover until that depth at the end of page/xform. + */ +extern int pdf_dev_current_depth (void); +extern void pdf_dev_grestore_to (int depth); +#define pdf_dev_grestoreall() pdf_dev_grestore_to(0); + +#ifdef XETEX +extern int pdf_dev_currentcolor (pdf_color *color, int is_fill); +extern int pdf_dev_setcolor (const pdf_color *color, int is_fill); + +extern void pdf_dev_set_fixed_point (double x, double y); +extern void pdf_dev_get_fixed_point (pdf_coord *p); +#else +extern void pdf_dev_set_color (const pdf_color *color, char mask, int force); +#define pdf_dev_set_strokingcolor(c) pdf_dev_set_color(c, 0, 0); +#define pdf_dev_set_nonstrokingcolor(c) pdf_dev_set_color(c, 0x20, 0); +extern void pdf_dev_reset_color (int force); +#endif + +#endif /* _PDF_DRAW_H_ */ diff --git a/Build/source/texk/dvipdfm-x/src/cff.c b/Build/source/texk/dvipdfm-x/src/cff.c deleted file mode 100644 index b5e78f5791a..00000000000 --- a/Build/source/texk/dvipdfm-x/src/cff.c +++ /dev/null @@ -1,1501 +0,0 @@ -/* - - This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - - Copyright (C) 2002-2012 by Jin-Hwan Cho and Shunsaku Hirata, - the dvipdfmx project team. - - This program 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; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -*/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -#include "system.h" -#include "mem.h" -#include "error.h" -#include "mfileio.h" - -#include "cff_limits.h" -#include "cff_types.h" -#include "cff_stdstr.h" -#include "cff_dict.h" - -#include "cff.h" - -#define CFF_DEBUG 5 -#define CFF_DEBUG_STR "CFF" - -#ifdef XETEX -#define SFNT_OR_FILE sfnt -#define SFONT_OR_STREAM sfont -#define get_card8(s) sfnt_get_byte((s)) -#define get_card16(s) sfnt_get_ushort((s)) -#else -#define SFNT_OR_FILE FILE -#define SFONT_OR_STREAM stream -#define get_card8(s) get_unsigned_byte((s)) -#define get_card16(s) get_unsigned_pair((s)) -#endif - -static unsigned long get_unsigned (SFNT_OR_FILE *SFONT_OR_STREAM, int n) -{ - unsigned long v = 0; - - while (n-- > 0) - v = v*0x100u + get_card8(SFONT_OR_STREAM); - - return v; -} - -#define get_offset(s, n) get_unsigned((s), (n)) - -/* - * Read Header, Name INDEX, Top DICT INDEX, and String INDEX. - */ -cff_font *cff_open(SFNT_OR_FILE *SFONT_OR_STREAM, long offset, int n) -{ - cff_font *cff; - cff_index *idx; - - cff = NEW(1, cff_font); - - cff->fontname = NULL; - cff->index = n; - cff->SFONT_OR_STREAM = SFONT_OR_STREAM; - cff->offset = offset; - cff->filter = 0; /* not used */ - cff->flag = 0; - - cff->name = NULL; - cff->gsubr = NULL; - cff->encoding = NULL; - cff->charsets = NULL; - cff->fdselect = NULL; - cff->cstrings = NULL; - cff->fdarray = NULL; - cff->private = NULL; - cff->subrs = NULL; - - cff->num_glyphs = 0; - cff->num_fds = 0; - cff->_string = NULL; - - cff_seek_set(cff, 0); - cff->header.major = get_card8(cff->SFONT_OR_STREAM); - cff->header.minor = get_card8(cff->SFONT_OR_STREAM); - cff->header.hdr_size = get_card8(cff->SFONT_OR_STREAM); - cff->header.offsize = get_card8(cff->SFONT_OR_STREAM); - if (cff->header.offsize < 1 || - cff->header.offsize > 4) - ERROR("invalid offsize data"); - - if (cff->header.major > 1 || - cff->header.minor > 0) { - WARN("%s: CFF version %u.%u not supported.", - CFF_DEBUG_STR, cff->header.major, cff->header.minor); - cff_close(cff); - return NULL; - } - - cff_seek_set(cff, (cff->header).hdr_size); - - /* Name INDEX */ - idx = cff_get_index(cff); - if (n > idx->count - 1) { - WARN("%s: Invalid CFF fontset index number.", CFF_DEBUG_STR); - cff_close(cff); - return NULL; - } - - cff->name = idx; - - cff->fontname = cff_get_name(cff); - - /* Top DICT INDEX */ - idx = cff_get_index(cff); - if (n > idx->count - 1) - ERROR("CFF Top DICT not exist..."); - cff->topdict = cff_dict_unpack(idx->data + idx->offset[n] - 1, - idx->data + idx->offset[n + 1] - 1); - if (!cff->topdict) - ERROR("Parsing CFF Top DICT data failed..."); - cff_release_index(idx); - - if (cff_dict_known(cff->topdict, "CharstringType") && - cff_dict_get(cff->topdict, "CharstringType", 0) != 2) { - WARN("Only Type 2 Charstrings supported..."); - cff_close(cff); - return NULL; - } - - if (cff_dict_known(cff->topdict, "SyntheticBase")) { - WARN("CFF Synthetic font not supported."); - cff_close(cff); - return NULL; - } - - /* String INDEX */ - cff->string = cff_get_index(cff); - - /* offset to GSubr */ - cff->gsubr_offset = tell_position(cff->stream) - offset; - - /* Number of glyphs */ - offset = (long) cff_dict_get(cff->topdict, "CharStrings", 0); - cff_seek_set(cff, offset); - cff->num_glyphs = get_card16(cff->SFONT_OR_STREAM); - - /* Check for font type */ - if (cff_dict_known(cff->topdict, "ROS")) { - cff->flag |= FONTTYPE_CIDFONT; - } else { - cff->flag |= FONTTYPE_FONT; - } - - /* Check for encoding */ - if (cff_dict_known(cff->topdict, "Encoding")) { - offset = (long) cff_dict_get(cff->topdict, "Encoding", 0); - if (offset == 0) { /* predefined */ - cff->flag |= ENCODING_STANDARD; - } else if (offset == 1) { - cff->flag |= ENCODING_EXPERT; - } - } else { - cff->flag |= ENCODING_STANDARD; - } - - /* Check for charset */ - if (cff_dict_known(cff->topdict, "charset")) { - offset = (long) cff_dict_get(cff->topdict, "charset", 0); - if (offset == 0) { /* predefined */ - cff->flag |= CHARSETS_ISOADOBE; - } else if (offset == 1) { - cff->flag |= CHARSETS_EXPERT; - } else if (offset == 2) { - cff->flag |= CHARSETS_EXPSUB; - } - } else { - cff->flag |= CHARSETS_ISOADOBE; - } - - cff_seek_set(cff, cff->gsubr_offset); /* seek back to GSubr */ - -#ifdef XETEX - cff->ft_to_gid = NULL; -#endif - - return cff; -} - -void -cff_close (cff_font *cff) -{ - card16 i; - - if (cff) { - if (cff->fontname) RELEASE(cff->fontname); - if (cff->name) cff_release_index(cff->name); - if (cff->topdict) cff_release_dict(cff->topdict); - if (cff->string) cff_release_index(cff->string); - if (cff->gsubr) cff_release_index(cff->gsubr); - if (cff->encoding) cff_release_encoding(cff->encoding); - if (cff->charsets) cff_release_charsets(cff->charsets); - if (cff->fdselect) cff_release_fdselect(cff->fdselect); - if (cff->cstrings) cff_release_index(cff->cstrings); - if (cff->fdarray) { - for (i=0;inum_fds;i++) { - if (cff->fdarray[i]) cff_release_dict(cff->fdarray[i]); - } - RELEASE(cff->fdarray); - } - if (cff->private) { - for (i=0;inum_fds;i++) { - if (cff->private[i]) cff_release_dict(cff->private[i]); - } - RELEASE(cff->private); - } - if (cff->subrs) { - for (i=0;inum_fds;i++) { - if (cff->subrs[i]) cff_release_index(cff->subrs[i]); - } - RELEASE(cff->subrs); - } - if (cff->_string) - cff_release_index(cff->_string); - -#ifdef XETEX - if (cff->ft_to_gid) - RELEASE(cff->ft_to_gid); -#endif - - RELEASE(cff); - } - - return; -} - -char * -cff_get_name (cff_font *cff) -{ - char *fontname; - l_offset len; - cff_index *idx; - - idx = cff->name; - len = idx->offset[cff->index + 1] - idx->offset[cff->index]; - fontname = NEW(len + 1, char); - memcpy(fontname, idx->data + idx->offset[cff->index] - 1, len); - fontname[len] = '\0'; - - return fontname; -} - -long -cff_set_name (cff_font *cff, char *name) -{ - cff_index *idx; - - if (strlen(name) > 127) - ERROR("FontName string length too large..."); - - if (cff->name) - cff_release_index(cff->name); - - cff->name = idx = NEW(1, cff_index); - idx->count = 1; - idx->offsize = 1; - idx->offset = NEW(2, l_offset); - (idx->offset)[0] = 1; - (idx->offset)[1] = strlen(name) + 1; - idx->data = NEW(strlen(name), card8); - memmove(idx->data, name, strlen(name)); /* no trailing '\0' */ - - return 5 + strlen(name); -} - -long -cff_put_header (cff_font *cff, card8 *dest, long destlen) -{ - if (destlen < 4) - ERROR("Not enough space available..."); - - *(dest++) = cff->header.major; - *(dest++) = cff->header.minor; - *(dest++) = 4; /* Additional data in between header and - * Name INDEX ignored. - */ - /* We will set all offset (0) to four-byte integer. */ - *(dest++) = 4; - cff->header.offsize = 4; - - return 4; -} - -/* Only read header part but not body */ -cff_index * -cff_get_index_header (cff_font *cff) -{ - cff_index *idx; - card16 i, count; - - idx = NEW(1, cff_index); - - idx->count = count = get_card16(cff->SFONT_OR_STREAM); - if (count > 0) { - idx->offsize = get_card8(cff->SFONT_OR_STREAM); - if (idx->offsize < 1 || idx->offsize > 4) - ERROR("invalid offsize data"); - - idx->offset = NEW(count+1, l_offset); - for (i=0;ioffset)[i] = get_offset(cff->SFONT_OR_STREAM, idx->offsize); - } - - if (idx->offset[0] != 1) - ERROR("cff_get_index(): invalid index data"); - - idx->data = NULL; - } else { - idx->offsize = 0; - idx->offset = NULL; - idx->data = NULL; - } - - return idx; -} - -cff_index * -cff_get_index (cff_font *cff) -{ - cff_index *idx; - card16 i, count; - long length, nb_read, offset; - - idx = NEW(1, cff_index); - - idx->count = count = get_card16(cff->SFONT_OR_STREAM); - if (count > 0) { - idx->offsize = get_card8(cff->SFONT_OR_STREAM); - if (idx->offsize < 1 || idx->offsize > 4) - ERROR("invalid offsize data"); - - idx->offset = NEW(count + 1, l_offset); - for (i = 0 ; i < count + 1; i++) { - idx->offset[i] = get_offset(cff->SFONT_OR_STREAM, idx->offsize); - } - - if (idx->offset[0] != 1) - ERROR("Invalid CFF Index offset data"); - - length = idx->offset[count] - idx->offset[0]; - - idx->data = NEW(length, card8); - offset = 0; - while (length > 0) { - nb_read = fread(idx->data + offset, 1, length, cff->stream); - offset += nb_read; - length -= nb_read; - } - } else { - idx->offsize = 0; - idx->offset = NULL; - idx->data = NULL; - } - - return idx; -} - -long -cff_pack_index (cff_index *idx, card8 *dest, long destlen) -{ - long len = 0; - long datalen; - card16 i; - - if (idx->count < 1) { - if (destlen < 2) - ERROR("Not enough space available..."); - memset(dest, 0, 2); - return 2; - } - - len = cff_index_size(idx); - datalen = idx->offset[idx->count] - 1; - - if (destlen < len) - ERROR("Not enough space available..."); - - *(dest++) = (idx->count >> 8) & 0xff; - *(dest++) = idx->count & 0xff; - - if (datalen < 0xffUL) { - idx->offsize = 1; - *(dest++) = 1; - for (i = 0; i <= idx->count; i++) { - *(dest++) = (card8) (idx->offset[i] & 0xff); - } - } else if (datalen < 0xffffUL) { - idx->offsize = 2; - *(dest++) = 2; - for (i = 0; i <= idx->count; i++) { - *(dest++) = (card8) ((idx->offset[i] >> 8) & 0xff); - *(dest++) = (card8) ( idx->offset[i] & 0xff); - } - } else if (datalen < 0xffffffUL) { - idx->offsize = 3; - *(dest++) = 3; - for (i = 0; i <= idx->count; i++) { - *(dest++) = (card8)((idx->offset[i] >> 16) & 0xff); - *(dest++) = (card8)((idx->offset[i] >> 8) & 0xff); - *(dest++) = (card8)(idx->offset[i] & 0xff); - } - } else { - idx->offsize = 4; - *(dest++) = 4; - for (i = 0; i <= idx->count; i++) { - *(dest++) = (card8)((idx->offset[i] >> 24) & 0xff); - *(dest++) = (card8)((idx->offset[i] >> 16) & 0xff); - *(dest++) = (card8)((idx->offset[i] >> 8) & 0xff); - *(dest++) = (card8)(idx->offset[i] & 0xff); - } - } - - memmove(dest, idx->data, idx->offset[idx->count] - 1); - - return len; -} - -long -cff_index_size (cff_index *idx) -{ - if (idx->count > 0) { - l_offset datalen; - - datalen = idx->offset[idx->count] - 1; - if (datalen < 0xffUL) { - idx->offsize = 1; - } else if (datalen < 0xffffUL) { - idx->offsize = 2; - } else if (datalen < 0xffffffUL) { - idx->offsize = 3; - } else { - idx->offsize = 4; - } - return (3 + (idx->offsize)*(idx->count + 1) + datalen); - } else { - return 2; - } -} - - -cff_index *cff_new_index (card16 count) -{ - cff_index *idx; - - idx = NEW(1, cff_index); - idx->count = count; - idx->offsize = 0; - - if (count > 0) { - idx->offset = NEW(count + 1, l_offset); - (idx->offset)[0] = 1; - } else { - idx->offset = NULL; - } - idx->data = NULL; - - return idx; -} - -void cff_release_index (cff_index *idx) -{ - if (idx) { - if (idx->data) { - RELEASE(idx->data); - } - if (idx->offset) { - RELEASE(idx->offset); - } - RELEASE(idx); - } -} - -/* Strings */ -char *cff_get_string (cff_font *cff, s_SID id) -{ - char *result = NULL; - long len; - - if (id < CFF_STDSTR_MAX) { - len = strlen(cff_stdstr[id]); - result = NEW(len+1, char); - memcpy(result, cff_stdstr[id], len); - result[len] = '\0'; - } else if (cff && cff->string) { - cff_index *strings = cff->string; - id -= CFF_STDSTR_MAX; - if (id < strings->count) { - len = (strings->offset)[id+1] - (strings->offset)[id]; - result = NEW(len + 1, char); - memmove(result, strings->data + (strings->offset)[id] - 1, len); - result[len] = '\0'; - } - } - - return result; -} - -long cff_get_sid (cff_font *cff, const char *str) -{ - card16 i; - - if (!cff || !str) - return -1; - - /* I search String INDEX first. */ - if (cff && cff->string) { - cff_index *idx = cff->string; - for (i = 0; i < idx->count; i++) { - if (strlen(str) == (idx->offset)[i+1] - (idx->offset)[i] && - !memcmp(str, (idx->data)+(idx->offset)[i]-1, strlen(str))) - return (i + CFF_STDSTR_MAX); - } - } - - for (i = 0; i < CFF_STDSTR_MAX; i++) { - if (!strcmp(str, cff_stdstr[i])) - return i; - } - - return -1; -} - -long cff_get_seac_sid (cff_font *cff, const char *str) -{ - card16 i; - - if (!cff || !str) - return -1; - - for (i = 0; i < CFF_STDSTR_MAX; i++) { - if (!strcmp(str, cff_stdstr[i])) - return i; - } - - return -1; -} - -int cff_match_string (cff_font *cff, const char *str, s_SID sid) -{ - card16 i; - - if (sid < CFF_STDSTR_MAX) { - return ((!strcmp(str, cff_stdstr[sid])) ? 1 : 0); - } else { - i = sid - CFF_STDSTR_MAX; - if (cff == NULL || cff->string == NULL || i >= cff->string->count) - ERROR("Invalid SID"); - if (strlen(str) == (cff->string->offset)[i+1] - (cff->string->offset)[i]) - return (!memcmp(str, - (cff->string->data)+(cff->string->offset)[i]-1, - strlen(str))) ? 1 : 0; - } - - return 0; -} - -void cff_update_string (cff_font *cff) -{ - if (cff == NULL) - ERROR("CFF font not opened."); - - if (cff->string) - cff_release_index(cff->string); - cff->string = cff->_string; - cff->_string = NULL; -} - -s_SID cff_add_string (cff_font *cff, const char *str, int unique) -/* Setting unique == 1 eliminates redundant or predefined strings. */ -{ - card16 idx; - cff_index *strings; - l_offset offset, size; - long len = strlen(str); - - if (cff == NULL) - ERROR("CFF font not opened."); - - if (cff->_string == NULL) - cff->_string = cff_new_index(0); - strings = cff->_string; - - if (unique) { - /* TODO: do binary search to speed things up */ - for (idx = 0; idx < CFF_STDSTR_MAX; idx++) { - if (cff_stdstr[idx] && !strcmp(cff_stdstr[idx], str)) - return idx; - } - for (idx = 0; idx < strings->count; idx++) { - size = strings->offset[idx+1] - strings->offset[idx]; - offset = strings->offset[idx]; - if (size == len && !memcmp(strings->data+offset-1, str, len)) - return (idx + CFF_STDSTR_MAX); - } - } - - offset = (strings->count > 0) ? strings->offset[strings->count] : 1; - strings->offset = RENEW(strings->offset, strings->count+2, l_offset); - if (strings->count == 0) - strings->offset[0] = 1; - idx = strings->count; - strings->count += 1; - strings->offset[strings->count] = offset + len; - strings->data = RENEW(strings->data, offset+len-1, card8); - memcpy(strings->data+offset-1, str, len); - - return (idx + CFF_STDSTR_MAX); -} - -/* - * Encoding and Charset - * - * Encoding and Charset arrays always begin with GID = 1. - */ -long cff_read_encoding (cff_font *cff) -{ - cff_encoding *encoding; - long offset, length; - card8 i; - - if (cff->topdict == NULL) { - ERROR("Top DICT data not found"); - } - - if (!cff_dict_known(cff->topdict, "Encoding")) { - cff->flag |= ENCODING_STANDARD; - cff->encoding = NULL; - return 0; - } - - offset = (long) cff_dict_get(cff->topdict, "Encoding", 0); - if (offset == 0) { /* predefined */ - cff->flag |= ENCODING_STANDARD; - cff->encoding = NULL; - return 0; - } else if (offset == 1) { - cff->flag |= ENCODING_EXPERT; - cff->encoding = NULL; - return 0; - } - - cff_seek_set(cff, offset); - cff->encoding = encoding = NEW(1, cff_encoding); - encoding->format = get_card8(cff->SFONT_OR_STREAM); - length = 1; - - switch (encoding->format & (~0x80)) { - case 0: - encoding->num_entries = get_card8(cff->SFONT_OR_STREAM); - (encoding->data).codes = NEW(encoding->num_entries, card8); - for (i=0;i<(encoding->num_entries);i++) { - (encoding->data).codes[i] = get_card8(cff->SFONT_OR_STREAM); - } - length += encoding->num_entries + 1; - break; - case 1: - { - cff_range1 *ranges; - encoding->num_entries = get_card8(cff->SFONT_OR_STREAM); - encoding->data.range1 = ranges - = NEW(encoding->num_entries, cff_range1); - for (i=0;i<(encoding->num_entries);i++) { - ranges[i].first = get_card8(cff->SFONT_OR_STREAM); - ranges[i].n_left = get_card8(cff->SFONT_OR_STREAM); - } - length += (encoding->num_entries) * 2 + 1; - } - break; - default: - RELEASE(encoding); - ERROR("Unknown Encoding format"); - break; - } - - /* Supplementary data */ - if ((encoding->format) & 0x80) { - cff_map *map; - encoding->num_supps = get_card8(cff->SFONT_OR_STREAM); - encoding->supp = map = NEW(encoding->num_supps, cff_map); - for (i=0;i<(encoding->num_supps);i++) { - map[i].code = get_card8(cff->SFONT_OR_STREAM); - map[i].glyph = get_card16(cff->SFONT_OR_STREAM); /* SID */ - } - length += (encoding->num_supps) * 3 + 1; - } else { - encoding->num_supps = 0; - encoding->supp = NULL; - } - - return length; -} - -long cff_pack_encoding (cff_font *cff, card8 *dest, long destlen) -{ - long len = 0; - cff_encoding *encoding; - card16 i; - - if (cff->flag & HAVE_STANDARD_ENCODING || cff->encoding == NULL) - return 0; - - if (destlen < 2) - ERROR("in cff_pack_encoding(): Buffer overflow"); - - encoding = cff->encoding; - - dest[len++] = encoding->format; - dest[len++] = encoding->num_entries; - switch (encoding->format & (~0x80)) { - case 0: - if (destlen < len + encoding->num_entries) - ERROR("in cff_pack_encoding(): Buffer overflow"); - for (i=0;i<(encoding->num_entries);i++) { - dest[len++] = (encoding->data).codes[i]; - } - break; - case 1: - { - if (destlen < len + (encoding->num_entries)*2) - ERROR("in cff_pack_encoding(): Buffer overflow"); - for (i=0;i<(encoding->num_entries);i++) { - dest[len++] = (encoding->data).range1[i].first & 0xff; - dest[len++] = (encoding->data).range1[i].n_left; - } - } - break; - default: - ERROR("Unknown Encoding format"); - break; - } - - if ((encoding->format) & 0x80) { - if (destlen < len + (encoding->num_supps)*3 + 1) - ERROR("in cff_pack_encoding(): Buffer overflow"); - dest[len++] = encoding->num_supps; - for (i=0;i<(encoding->num_supps);i++) { - dest[len++] = (encoding->supp)[i].code; - dest[len++] = ((encoding->supp)[i].glyph >> 8) & 0xff; - dest[len++] = (encoding->supp)[i].glyph & 0xff; - } - } - - return len; -} - -/* input: code, output: glyph index */ -card16 cff_encoding_lookup (cff_font *cff, card8 code) -{ - card16 gid = 0; - cff_encoding *encoding; - card16 i; - - if (cff->flag & (ENCODING_STANDARD|ENCODING_EXPERT)) { - ERROR("Predefined CFF encoding not supported yet"); - } else if (cff->encoding == NULL) { - ERROR("Encoding data not available"); - } - - encoding = cff->encoding; - - gid = 0; - switch (encoding->format & (~0x80)) { - case 0: - for (i = 0; i < encoding->num_entries; i++) { - if (code == (encoding->data).codes[i]) { - gid = i + 1; - break; - } - } - break; - case 1: - for (i = 0; i < encoding->num_entries; i++) { - if (code >= (encoding->data).range1[i].first && - code <= (encoding->data).range1[i].first + (encoding->data).range1[i].n_left) { - gid += code - (encoding->data).range1[i].first + 1; - break; - } - gid += (encoding->data).range1[i].n_left + 1; - } - if (i == encoding->num_entries) - gid = 0; - break; - default: - ERROR("Unknown Encoding format."); - } - - /* Supplementary data */ - if (gid == 0 && ((encoding->format) & 0x80)) { - cff_map *map; - if (!encoding->supp) - ERROR("No CFF supplementary encoding data read."); - map = encoding->supp; - for (i=0;i<(encoding->num_supps);i++) { - if (code == map[i].code) { - gid = cff_charsets_lookup(cff, map[i].glyph); - break; - } - } - } - - return gid; -} - -void cff_release_encoding (cff_encoding *encoding) -{ - if (encoding) { - switch (encoding->format & (~0x80)) { - case 0: - if (encoding->data.codes) - RELEASE(encoding->data.codes); - break; - case 1: - if (encoding->data.range1) - RELEASE(encoding->data.range1); - break; - default: - ERROR("Unknown Encoding format."); - } - if (encoding->format & 0x80) { - if (encoding->supp) - RELEASE(encoding->supp); - } - RELEASE(encoding); - } -} - -long cff_read_charsets (cff_font *cff) -{ - cff_charsets *charset; - long offset, length; - card16 count, i; - - if (cff->topdict == NULL) - ERROR("Top DICT not available"); - - if (!cff_dict_known(cff->topdict, "charset")) { - cff->flag |= CHARSETS_ISOADOBE; - cff->charsets = NULL; - return 0; - } - - offset = (long) cff_dict_get(cff->topdict, "charset", 0); - - if (offset == 0) { /* predefined */ - cff->flag |= CHARSETS_ISOADOBE; - cff->charsets = NULL; - return 0; - } else if (offset == 1) { - cff->flag |= CHARSETS_EXPERT; - cff->charsets = NULL; - return 0; - } else if (offset == 2) { - cff->flag |= CHARSETS_EXPSUB; - cff->charsets = NULL; - return 0; - } - - cff_seek_set(cff, offset); - cff->charsets = charset = NEW(1, cff_charsets); - charset->format = get_card8(cff->SFONT_OR_STREAM); - charset->num_entries = 0; - - count = cff->num_glyphs - 1; - length = 1; - - /* Not sure. Not well documented. */ - switch (charset->format) { - case 0: - charset->num_entries = cff->num_glyphs - 1; /* no .notdef */ - charset->data.glyphs = NEW(charset->num_entries, s_SID); - length += (charset->num_entries) * 2; - for (i=0;i<(charset->num_entries);i++) { - charset->data.glyphs[i] = get_card16(cff->SFONT_OR_STREAM); - } - count = 0; - break; - case 1: - { - cff_range1 *ranges = NULL; - while (count > 0 && charset->num_entries < cff->num_glyphs) { - ranges = RENEW(ranges, charset->num_entries + 1, cff_range1); - ranges[charset->num_entries].first = get_card16(cff->SFONT_OR_STREAM); - ranges[charset->num_entries].n_left = get_card8(cff->SFONT_OR_STREAM); - count -= ranges[charset->num_entries].n_left + 1; /* no-overrap */ - charset->num_entries += 1; - charset->data.range1 = ranges; - } - length += (charset->num_entries) * 3; - } - break; - case 2: - { - cff_range2 *ranges = NULL; - while (count > 0 && charset->num_entries < cff->num_glyphs) { - ranges = RENEW(ranges, charset->num_entries + 1, cff_range2); - ranges[charset->num_entries].first = get_card16(cff->SFONT_OR_STREAM); - ranges[charset->num_entries].n_left = get_card16(cff->SFONT_OR_STREAM); - count -= ranges[charset->num_entries].n_left + 1; /* non-overrapping */ - charset->num_entries += 1; - } - charset->data.range2 = ranges; - length += (charset->num_entries) * 4; - } - break; - default: - RELEASE(charset); - ERROR("Unknown Charset format"); - break; - } - - if (count > 0) - ERROR("Charset data possibly broken"); - - return length; -} - -long cff_pack_charsets (cff_font *cff, card8 *dest, long destlen) -{ - long len = 0; - card16 i; - cff_charsets *charset; - - if (cff->flag & HAVE_STANDARD_CHARSETS || cff->charsets == NULL) - return 0; - - if (destlen < 1) - ERROR("in cff_pack_charsets(): Buffer overflow"); - - charset = cff->charsets; - - dest[len++] = charset->format; - switch (charset->format) { - case 0: - if (destlen < len + (charset->num_entries)*2) - ERROR("in cff_pack_charsets(): Buffer overflow"); - for (i=0;i<(charset->num_entries);i++) { - s_SID sid = (charset->data).glyphs[i]; /* or CID */ - dest[len++] = (sid >> 8) & 0xff; - dest[len++] = sid & 0xff; - } - break; - case 1: - { - if (destlen < len + (charset->num_entries)*3) - ERROR("in cff_pack_charsets(): Buffer overflow"); - for (i=0;i<(charset->num_entries);i++) { - dest[len++] = ((charset->data).range1[i].first >> 8) & 0xff; - dest[len++] = (charset->data).range1[i].first & 0xff; - dest[len++] = (charset->data).range1[i].n_left; - } - } - break; - case 2: - { - if (destlen < len + (charset->num_entries)*4) - ERROR("in cff_pack_charsets(): Buffer overflow"); - for (i=0;i<(charset->num_entries);i++) { - dest[len++] = ((charset->data).range2[i].first >> 8) & 0xff; - dest[len++] = (charset->data).range2[i].first & 0xff; - dest[len++] = ((charset->data).range2[i].n_left >> 8) & 0xff; - dest[len++] = (charset->data).range2[i].n_left & 0xff; - } - } - break; - default: - ERROR("Unknown Charset format"); - break; - } - - return len; -} - -card16 cff_glyph_lookup (cff_font *cff, const char *glyph) -{ - card16 gid; - cff_charsets *charset; - card16 i, n; - - if (cff->flag & (CHARSETS_ISOADOBE|CHARSETS_EXPERT|CHARSETS_EXPSUB)) { - ERROR("Predefined CFF charsets not supported yet"); - } else if (cff->charsets == NULL) { - ERROR("Charsets data not available"); - } - - /* .notdef always have glyph index 0 */ - if (!glyph || !strcmp(glyph, ".notdef")) { - return 0; - } - - charset = cff->charsets; - - gid = 0; - switch (charset->format) { - case 0: - for (i = 0; i < charset->num_entries; i++) { - gid++; - if (cff_match_string(cff, glyph, charset->data.glyphs[i])) { - return gid; - } - } - break; - case 1: - for (i = 0; i < charset->num_entries; i++) { - for (n = 0; - n <= charset->data.range1[i].n_left; n++) { - gid++; - if (cff_match_string(cff, glyph, - (s_SID)(charset->data.range1[i].first + n))) { - return gid; - } - } - } - break; - case 2: - for (i = 0; i num_entries; i++) { - for (n = 0; - n <= charset->data.range2[i].n_left; n++) { - gid++; - if (cff_match_string(cff, glyph, - (s_SID)(charset->data.range2[i].first + n))) { - return gid; - } - } - } - break; - default: - ERROR("Unknown Charset format"); - } - - return 0; /* not found, returns .notdef */ -} - -/* Input : SID or CID (16-bit unsigned int) - * Output: glyph index - */ -card16 -cff_charsets_lookup (cff_font *cff, card16 cid) -{ - card16 gid = 0; - cff_charsets *charset; - card16 i; - - if (cff->flag & (CHARSETS_ISOADOBE|CHARSETS_EXPERT|CHARSETS_EXPSUB)) { - ERROR("Predefined CFF charsets not supported yet"); - } else if (cff->charsets == NULL) { - ERROR("Charsets data not available"); - } - - if (cid == 0) { - return 0; /* GID 0 (.notdef) */ - } - - charset = cff->charsets; - - gid = 0; - switch (charset->format) { - case 0: - for (i = 0; i num_entries; i++) { - if (cid == charset->data.glyphs[i]) { - gid = i + 1; - return gid; - } - } - break; - case 1: - for (i = 0; i < charset->num_entries; i++) { - if (cid >= charset->data.range1[i].first && - cid <= charset->data.range1[i].first + charset->data.range1[i].n_left) { - gid += cid - charset->data.range1[i].first + 1; - return gid; - } - gid += charset->data.range1[i].n_left + 1; - } - break; - case 2: - for (i = 0; i < charset->num_entries; i++) { - if (cid >= charset->data.range2[i].first && - cid <= charset->data.range2[i].first + charset->data.range2[i].n_left) { - gid += cid - charset->data.range2[i].first + 1; - return gid; - } - gid += charset->data.range2[i].n_left + 1; - } - break; - default: - ERROR("Unknown Charset format"); - } - - return 0; /* not found */ -} - -/* Input : GID - * Output: SID/CID (card16) - */ -card16 -cff_charsets_lookup_inverse (cff_font *cff, card16 gid) -{ - card16 sid = 0; - cff_charsets *charset; - card16 i; - - if (cff->flag & (CHARSETS_ISOADOBE|CHARSETS_EXPERT|CHARSETS_EXPSUB)) { - ERROR("Predefined CFF charsets not supported yet"); - } else if (cff->charsets == NULL) { - ERROR("Charsets data not available"); - } - - if (gid == 0) { - return 0; /* .notdef */ - } - - charset = cff->charsets; - - sid = 0; - switch (charset->format) { - case 0: - if (gid - 1 >= charset->num_entries) - ERROR("Invalid GID."); - sid = charset->data.glyphs[gid - 1]; - break; - case 1: - for (i = 0; i < charset->num_entries; i++) { - if (gid <= charset->data.range1[i].n_left + 1) { - sid = gid + charset->data.range1[i].first - 1; - break; - } - gid -= charset->data.range1[i].n_left + 1; - } - if (i == charset->num_entries) - ERROR("Invalid GID"); - break; - case 2: - for (i = 0; i < charset->num_entries; i++) { - if (gid <= charset->data.range2[i].n_left + 1) { - sid = gid + charset->data.range2[i].first - 1; - break; - } - gid -= charset->data.range2[i].n_left + 1; - } - if (i == charset->num_entries) - ERROR("Invalid GID"); - break; - default: - ERROR("Unknown Charset format"); - } - - return sid; -} - -void -cff_release_charsets (cff_charsets *charset) -{ - if (charset) { - switch (charset->format) { - case 0: - if (charset->data.glyphs) - RELEASE(charset->data.glyphs); - break; - case 1: - if (charset->data.range1) - RELEASE(charset->data.range1); - break; - case 2: - if (charset->data.range2) - RELEASE(charset->data.range2); - break; - default: - break; - } - RELEASE(charset); - } -} - -/* CID-Keyed font specific */ -long cff_read_fdselect (cff_font *cff) -{ - cff_fdselect *fdsel; - long offset, length; - card16 i; - - if (cff->topdict == NULL) - ERROR("Top DICT not available"); - - if (!(cff->flag & FONTTYPE_CIDFONT)) - return 0; - - offset = (long) cff_dict_get(cff->topdict, "FDSelect", 0); - cff_seek_set(cff, offset); - cff->fdselect = fdsel = NEW(1, cff_fdselect); - fdsel->format = get_card8(cff->SFONT_OR_STREAM); - - length = 1; - - switch (fdsel->format) { - case 0: - fdsel->num_entries = cff->num_glyphs; - (fdsel->data).fds = NEW(fdsel->num_entries, card8); - for (i=0;i<(fdsel->num_entries);i++) { - (fdsel->data).fds[i] = get_card8(cff->SFONT_OR_STREAM); - } - length += fdsel->num_entries; - break; - case 3: - { - cff_range3 *ranges; - fdsel->num_entries = get_card16(cff->SFONT_OR_STREAM); - fdsel->data.ranges = ranges = NEW(fdsel->num_entries, cff_range3); - for (i=0;i<(fdsel->num_entries);i++) { - ranges[i].first = get_card16(cff->SFONT_OR_STREAM); - ranges[i].fd = get_card8(cff->SFONT_OR_STREAM); - } - if (ranges[0].first != 0) - ERROR("Range not starting with 0."); - if (cff->num_glyphs != get_card16(cff->SFONT_OR_STREAM)) - ERROR("Sentinel value mismatched with number of glyphs."); - length += (fdsel->num_entries) * 3 + 4; - } - break; - default: - RELEASE(fdsel); - ERROR("Unknown FDSelect format."); - break; - } - - return length; -} - -long cff_pack_fdselect (cff_font *cff, card8 *dest, long destlen) -{ - cff_fdselect *fdsel; - long len = 0; - card16 i; - - if (cff->fdselect == NULL) - return 0; - - if (destlen < 1) - ERROR("in cff_pack_fdselect(): Buffur overflow"); - - fdsel = cff->fdselect; - - dest[len++] = fdsel->format; - switch (fdsel->format) { - case 0: - if (fdsel->num_entries != cff->num_glyphs) - ERROR("in cff_pack_fdselect(): Invalid data"); - if (destlen < len + fdsel->num_entries) - ERROR("in cff_pack_fdselect(): Buffer overflow"); - for (i=0;inum_entries;i++) { - dest[len++] = (fdsel->data).fds[i]; - } - break; - case 3: - { - if (destlen < len + 2) - ERROR("in cff_pack_fdselect(): Buffer overflow"); - len += 2; - for (i=0;i<(fdsel->num_entries);i++) { - if (destlen < len + 3) - ERROR("in cff_pack_fdselect(): Buffer overflow"); - dest[len++] = ((fdsel->data).ranges[i].first >> 8) & 0xff; - dest[len++] = (fdsel->data).ranges[i].first & 0xff; - dest[len++] = (fdsel->data).ranges[i].fd; - } - if (destlen < len + 2) - ERROR("in cff_pack_fdselect(): Buffer overflow"); - dest[len++] = (cff->num_glyphs >> 8) & 0xff; - dest[len++] = cff->num_glyphs & 0xff; - dest[1] = ((len/3 - 1) >> 8) & 0xff; - dest[2] = (len/3 - 1) & 0xff; - } - break; - default: - ERROR("Unknown FDSelect format."); - break; - } - - return len; -} - -void cff_release_fdselect (cff_fdselect *fdselect) -{ - if (fdselect) { - if (fdselect->format == 0) { - if (fdselect->data.fds) RELEASE(fdselect->data.fds); - } else if (fdselect->format == 3) { - if (fdselect->data.ranges) RELEASE(fdselect->data.ranges); - } - RELEASE(fdselect); - } -} - -card8 cff_fdselect_lookup (cff_font *cff, card16 gid) -{ - card8 fd = 0xff; - cff_fdselect *fdsel; - - if (cff->fdselect == NULL) - ERROR("in cff_fdselect_lookup(): FDSelect not available"); - - fdsel = cff->fdselect; - - if (gid >= cff->num_glyphs) - ERROR("in cff_fdselect_lookup(): Invalid glyph index"); - - switch (fdsel->format) { - case 0: - fd = fdsel->data.fds[gid]; - break; - case 3: - { - if (gid == 0) { - fd = (fdsel->data).ranges[0].fd; - } else { - card16 i; - for (i=1;i<(fdsel->num_entries);i++) { - if (gid < (fdsel->data).ranges[i].first) - break; - } - fd = (fdsel->data).ranges[i-1].fd; - } - } - break; - default: - ERROR("in cff_fdselect_lookup(): Invalid FDSelect format"); - break; - } - - if (fd >= cff->num_fds) - ERROR("in cff_fdselect_lookup(): Invalid Font DICT index"); - - return fd; -} - -long cff_read_subrs (cff_font *cff) -{ - long len = 0; - long offset; - int i; - - if ((cff->flag & FONTTYPE_CIDFONT) && cff->fdarray == NULL) { - cff_read_fdarray(cff); - } - - if (cff->private == NULL) - cff_read_private(cff); - - if (cff->gsubr == NULL) { - cff_seek_set(cff, cff->gsubr_offset); - cff->gsubr = cff_get_index(cff); - } - - cff->subrs = NEW(cff->num_fds, cff_index *); - if (cff->flag & FONTTYPE_CIDFONT) { - for (i=0;inum_fds;i++) { - if (cff->private[i] == NULL || - !cff_dict_known(cff->private[i], "Subrs")) { - (cff->subrs)[i] = NULL; - } else { - offset = (long) cff_dict_get(cff->fdarray[i], "Private", 1); - offset += (long) cff_dict_get(cff->private[i], "Subrs", 0); - cff_seek_set(cff, offset); - (cff->subrs)[i] = cff_get_index(cff); - len += cff_index_size((cff->subrs)[i]); - } - } - } else { - if (cff->private[0] == NULL || - !cff_dict_known(cff->private[0], "Subrs")) { - (cff->subrs)[0] = NULL; - } else { - offset = (long) cff_dict_get(cff->topdict, "Private", 1); - offset += (long) cff_dict_get(cff->private[0], "Subrs", 0); - cff_seek_set(cff, offset); - (cff->subrs)[0] = cff_get_index(cff); - len += cff_index_size((cff->subrs)[0]); - } - } - - return len; -} - -long cff_read_fdarray (cff_font *cff) -{ - long len = 0; - cff_index *idx; - long offset, size; - card16 i; - - if (cff->topdict == NULL) - ERROR("in cff_read_fdarray(): Top DICT not found"); - - if (!(cff->flag & FONTTYPE_CIDFONT)) - return 0; - - /* must exist */ - offset = (long) cff_dict_get(cff->topdict, "FDArray", 0); - cff_seek_set(cff, offset); - idx = cff_get_index(cff); - cff->num_fds = (card8)idx->count; - cff->fdarray = NEW(idx->count, cff_dict *); - for (i=0;icount;i++) { - card8 *data = idx->data + (idx->offset)[i] - 1; - size = (idx->offset)[i+1] - (idx->offset)[i]; - if (size > 0) { - (cff->fdarray)[i] = cff_dict_unpack(data, data+size); - } else { - (cff->fdarray)[i] = NULL; - } - } - len = cff_index_size(idx); - cff_release_index(idx); - - return len; -} - -long cff_read_private (cff_font *cff) -{ - long len = 0; - card8 *data; - long offset, size; - - if (cff->flag & FONTTYPE_CIDFONT) { - int i; - - if (cff->fdarray == NULL) - cff_read_fdarray(cff); - - cff->private = NEW(cff->num_fds, cff_dict *); - for (i=0;inum_fds;i++) { - if (cff->fdarray[i] != NULL && - cff_dict_known(cff->fdarray[i], "Private") && - (size = (long) cff_dict_get(cff->fdarray[i], "Private", 0)) - > 0) { - offset = (long) cff_dict_get(cff->fdarray[i], "Private", 1); - cff_seek_set(cff, offset); - data = NEW(size, card8); - if (fread(data, 1, size, cff->stream) != size) - ERROR("reading file failed"); - (cff->private)[i] = cff_dict_unpack(data, data+size); - RELEASE(data); - len += size; - } else { - (cff->private)[i] = NULL; - } - } - } else { - cff->num_fds = 1; - cff->private = NEW(1, cff_dict *); - if (cff_dict_known(cff->topdict, "Private") && - (size = (long) cff_dict_get(cff->topdict, "Private", 0)) > 0) { - offset = (long) cff_dict_get(cff->topdict, "Private", 1); - cff_seek_set(cff, offset); - data = NEW(size, card8); - if (fread(data, 1, size, cff->stream) != size) - ERROR("reading file failed"); - cff->private[0] = cff_dict_unpack(data, data+size); - RELEASE(data); - len += size; - } else { - (cff->private)[0] = NULL; - len = 0; - } - } - - return len; -} - -#ifdef XETEX -unsigned short* cff_get_ft_to_gid(cff_font *cff) -{ - return cff->ft_to_gid; -} -#endif diff --git a/Build/source/texk/dvipdfm-x/src/dvi.c b/Build/source/texk/dvipdfm-x/src/dvi.c index 61a8ab8e456..9328866cb16 100644 --- a/Build/source/texk/dvipdfm-x/src/dvi.c +++ b/Build/source/texk/dvipdfm-x/src/dvi.c @@ -99,6 +99,13 @@ static struct dvi_header static double dev_origin_x = 72.0, dev_origin_y = 770.0; +#ifdef XETEX +double get_origin (int x) +{ + return x ? dev_origin_x : dev_origin_y; +} +#endif + #define PHYSICAL 1 #define VIRTUAL 2 #define SUBFONT 3 @@ -168,6 +175,234 @@ static int num_def_fonts = 0, max_def_fonts = 0; static int compute_boxes = 0, link_annot = 1; static int verbose = 0; +#ifdef XETEX +#define DVI_PAGE_BUF_CHUNK 0x10000UL /* 64K should be plenty for most pages */ + +static unsigned char* dvi_page_buffer; +static unsigned long dvi_page_buf_size; +static unsigned long dvi_page_buf_index; + +/* functions to read numbers from the dvi file and store them in dvi_page_buffer */ +static UNSIGNED_BYTE get_and_buffer_unsigned_byte (FILE *file) +{ + int ch; + if ((ch = fgetc (file)) < 0) + ERROR ("File ended prematurely\n"); + if (dvi_page_buf_index >= dvi_page_buf_size) { + dvi_page_buf_size += DVI_PAGE_BUF_CHUNK; + dvi_page_buffer = RENEW(dvi_page_buffer, dvi_page_buf_size, unsigned char); + } + dvi_page_buffer[dvi_page_buf_index++] = ch; + return (UNSIGNED_BYTE) ch; +} + +#if 0 +/* Not used */ +static SIGNED_BYTE get_and_buffer_signed_byte (FILE *file) +{ + int byte; + byte = get_and_buffer_unsigned_byte(file); + if (byte >= 0x80) + byte -= 0x100; + return (SIGNED_BYTE) byte; +} +#endif + +static UNSIGNED_PAIR get_and_buffer_unsigned_pair (FILE *file) +{ + int i; + UNSIGNED_BYTE byte; + UNSIGNED_PAIR pair = 0; + for (i=0; i<2; i++) { + byte = get_and_buffer_unsigned_byte(file); + pair = pair*0x100u + byte; + } + return pair; +} + +static SIGNED_PAIR get_and_buffer_signed_pair (FILE *file) +{ + int i; + long pair = 0; + for (i=0; i<2; i++) { + pair = pair*0x100 + get_and_buffer_unsigned_byte(file); + } + if (pair >= 0x8000) { + pair -= 0x10000l; + } + return (SIGNED_PAIR) pair; +} + +static UNSIGNED_TRIPLE get_and_buffer_unsigned_triple(FILE *file) +{ + int i; + long triple = 0; + for (i=0; i<3; i++) { + triple = triple*0x100u + get_and_buffer_unsigned_byte(file); + } + return (UNSIGNED_TRIPLE) triple; +} + +static SIGNED_TRIPLE get_and_buffer_signed_triple(FILE *file) +{ + int i; + long triple = 0; + for (i=0; i<3; i++) { + triple = triple*0x100 + get_and_buffer_unsigned_byte(file); + } + if (triple >= 0x800000l) + triple -= 0x1000000l; + return (SIGNED_TRIPLE) triple; +} + +static SIGNED_QUAD get_and_buffer_signed_quad(FILE *file) +{ + int byte, i; + long quad = 0; + + /* Check sign on first byte before reading others */ + byte = get_and_buffer_unsigned_byte(file); + quad = byte; + if (quad >= 0x80) + quad = byte - 0x100; + for (i=0; i<3; i++) { + quad = quad*0x100 + get_and_buffer_unsigned_byte(file); + } + return (SIGNED_QUAD) quad; +} + +static UNSIGNED_QUAD get_and_buffer_unsigned_quad(FILE *file) +{ + int i; + unsigned long quad = 0; + for (i=0; i<4; i++) { + quad = quad*0x100u + get_and_buffer_unsigned_byte(file); + } + return (UNSIGNED_QUAD) quad; +} + +static void get_and_buffer_bytes(FILE *file, unsigned int count) +{ + if (dvi_page_buf_index + count >= dvi_page_buf_size) { + dvi_page_buf_size = dvi_page_buf_index + count + DVI_PAGE_BUF_CHUNK; + dvi_page_buffer = RENEW(dvi_page_buffer, dvi_page_buf_size, unsigned char); + } + if (fread(dvi_page_buffer + dvi_page_buf_index, 1, count, file) != count) + ERROR ("File ended prematurely\n"); + dvi_page_buf_index += count; +} + +/* functions to fetch values from dvi_page_buffer */ + +static UNSIGNED_BYTE get_buffered_unsigned_byte (void) +{ + return dvi_page_buffer[dvi_page_buf_index++]; +} + +static SIGNED_BYTE get_buffered_signed_byte (void) +{ + int byte; + byte = dvi_page_buffer[dvi_page_buf_index++]; + if (byte >= 0x80) + byte -= 0x100; + return (SIGNED_BYTE) byte; +} + +static UNSIGNED_PAIR get_buffered_unsigned_pair (void) +{ + int i; + UNSIGNED_BYTE byte; + UNSIGNED_PAIR pair = 0; + for (i=0; i<2; i++) { + byte = dvi_page_buffer[dvi_page_buf_index++]; + pair = pair*0x100u + byte; + } + return pair; +} + +static SIGNED_PAIR get_buffered_signed_pair (void) +{ + int i; + long pair = 0; + for (i=0; i<2; i++) { + pair = pair*0x100 + dvi_page_buffer[dvi_page_buf_index++]; + } + if (pair >= 0x8000) { + pair -= 0x10000l; + } + return (SIGNED_PAIR) pair; +} + +static UNSIGNED_TRIPLE get_buffered_unsigned_triple(void) +{ + int i; + long triple = 0; + for (i=0; i<3; i++) { + triple = triple*0x100u + dvi_page_buffer[dvi_page_buf_index++]; + } + return (UNSIGNED_TRIPLE) triple; +} + +static SIGNED_TRIPLE get_buffered_signed_triple(void) +{ + int i; + long triple = 0; + for (i=0; i<3; i++) { + triple = triple*0x100 + dvi_page_buffer[dvi_page_buf_index++]; + } + if (triple >= 0x800000l) + triple -= 0x1000000l; + return (SIGNED_TRIPLE) triple; +} + +static SIGNED_QUAD get_buffered_signed_quad(void) +{ + int byte, i; + long quad = 0; + + /* Check sign on first byte before reading others */ + byte = dvi_page_buffer[dvi_page_buf_index++]; + quad = byte; + if (quad >= 0x80) + quad = byte - 0x100; + for (i=0; i<3; i++) { + quad = quad*0x100 + dvi_page_buffer[dvi_page_buf_index++]; + } + return (SIGNED_QUAD) quad; +} + +static UNSIGNED_QUAD get_buffered_unsigned_quad(void) +{ + int i; + unsigned long quad = 0; + for (i=0; i<4; i++) { + quad = quad*0x100u + dvi_page_buffer[dvi_page_buf_index++]; + } + return (UNSIGNED_QUAD) quad; +} +#else +#define get_and_buffer_unsigned_byte(fp) get_unsigned_byte(fp) +#if 0 +#define get_and_buffer_signed_byte(fp) get_signed_byte(fp) +#endif +#define get_and_buffer_unsigned_pair(fp) get_unsigned_pair(fp) +#define get_and_buffer_signed_pair(fp) get_signed_pair(fp) +#define get_and_buffer_unsigned_triple(fp) get_unsigned_triple(fp) +#define get_and_buffer_signed_triple(fp) get_signed_triple(fp) +#define get_and_buffer_signed_quad(fp) get_unsigned_quad(fp) +#define get_and_buffer_unsigned_quad(fp) get_unsigned_quad(fp) +#define get_and_buffer_bytes(fp, ct) seek_relative(fp, ct) + +#define get_buffered_unsigned_byte() get_unsigned_byte(dvi_file) +#define get_buffered_signed_byte() get_signed_byte(dvi_file) +#define get_buffered_unsigned_pair() get_unsigned_pair(dvi_file) +#define get_buffered_signed_pair() get_signed_pair(dvi_file) +#define get_buffered_unsigned_triple() get_unsigned_triple(dvi_file) +#define get_buffered_signed_triple() get_signed_triple(dvi_file) +#define get_buffered_signed_quad() get_signed_quad(dvi_file) +#define get_buffered_unsigned_quad() get_unsigned_quad(dvi_file) +#endif + void dvi_set_verbose (void) { @@ -211,8 +446,12 @@ find_post (void) /* file_position now points to last non padding character or * beginning of file */ - if (dvi_file_size - current < 4 || - current == 0 || !(ch == DVI_ID || ch == DVIV_ID)) { + if (dvi_file_size - current < 4 || current == 0 || +#ifdef XETEX + !(ch == DVI_ID || ch == DVIV_ID || ch == XDVI_ID)) { +#else + !(ch == DVI_ID || ch == DVIV_ID)) { +#endif MESG("DVI ID = %d\n", ch); ERROR(invalid_signature); } @@ -371,12 +610,20 @@ get_dvi_fonts (long post_location) tex_id = get_unsigned_triple(dvi_file); break; case FNT_DEF4: +#ifdef XETEX + case XDV_NATIVE_FONT_DEF: +#endif tex_id = get_signed_quad(dvi_file); break; default: MESG("Unexpected op code: %3d\n", code); ERROR(invalid_signature); } +#ifdef XETEX + if (code == XDV_NATIVE_FONT_DEF) + read_native_font_record(tex_id); + else +#endif read_font_record(tex_id); } if (verbose > 2) { @@ -962,19 +1209,19 @@ dvi_dir (UNSIGNED_BYTE dir) /* how? */ static void do_set1 (void) { - dvi_set(get_unsigned_byte(dvi_file)); + dvi_set(get_buffered_unsigned_byte()); } static void do_set2 (void) { - dvi_set(get_unsigned_pair(dvi_file)); + dvi_set(get_buffered_unsigned_pair()); } static void do_set3 (void) { - dvi_set(get_unsigned_triple(dvi_file)); + dvi_set(get_buffered_unsigned_triple()); } static void @@ -982,8 +1229,8 @@ do_setrule (void) { SIGNED_QUAD width, height; - height = get_signed_quad(dvi_file); - width = get_signed_quad(dvi_file); + height = get_buffered_signed_quad(); + width = get_buffered_signed_quad(); if (width > 0 && height > 0) { dvi_rule(width, height); } @@ -995,8 +1242,8 @@ do_putrule (void) { SIGNED_QUAD width, height; - height = get_signed_quad (dvi_file); - width = get_signed_quad (dvi_file); + height = get_buffered_signed_quad (); + width = get_buffered_signed_quad (); if (width > 0 && height > 0) { dvi_rule(width, height); } @@ -1005,19 +1252,19 @@ do_putrule (void) static void do_put1 (void) { - dvi_put(get_unsigned_byte(dvi_file)); + dvi_put(get_buffered_unsigned_byte()); } static void do_put2 (void) { - dvi_put(get_unsigned_pair(dvi_file)); + dvi_put(get_buffered_unsigned_pair()); } static void do_put3 (void) { - dvi_put(get_unsigned_triple(dvi_file)); + dvi_put(get_buffered_unsigned_triple()); } void @@ -1044,25 +1291,25 @@ dvi_pop (void) static void do_right1 (void) { - dvi_right(get_signed_byte(dvi_file)); + dvi_right(get_buffered_signed_byte()); } static void do_right2 (void) { - dvi_right(get_signed_pair(dvi_file)); + dvi_right(get_buffered_signed_pair()); } static void do_right3 (void) { - dvi_right(get_signed_triple(dvi_file)); + dvi_right(get_buffered_signed_triple()); } static void do_right4 (void) { - dvi_right(get_signed_quad(dvi_file)); + dvi_right(get_buffered_signed_quad()); } void @@ -1081,25 +1328,25 @@ dvi_w0 (void) static void do_w1 (void) { - dvi_w(get_signed_byte(dvi_file)); + dvi_w(get_buffered_signed_byte()); } static void do_w2 (void) { - dvi_w(get_signed_pair(dvi_file)); + dvi_w(get_buffered_signed_pair()); } static void do_w3 (void) { - dvi_w(get_signed_triple(dvi_file)); + dvi_w(get_buffered_signed_triple()); } static void do_w4 (void) { - dvi_w(get_signed_quad(dvi_file)); + dvi_w(get_buffered_signed_quad()); } void @@ -1118,49 +1365,49 @@ dvi_x0 (void) static void do_x1 (void) { - dvi_x(get_signed_byte(dvi_file)); + dvi_x(get_buffered_signed_byte()); } static void do_x2 (void) { - dvi_x(get_signed_pair(dvi_file)); + dvi_x(get_buffered_signed_pair()); } static void do_x3 (void) { - dvi_x(get_signed_triple(dvi_file)); + dvi_x(get_buffered_signed_triple()); } static void do_x4 (void) { - dvi_x(get_signed_quad(dvi_file)); + dvi_x(get_buffered_signed_quad()); } static void do_down1 (void) { - dvi_down(get_signed_byte(dvi_file)); + dvi_down(get_buffered_signed_byte()); } static void do_down2 (void) { - dvi_down(get_signed_pair(dvi_file)); + dvi_down(get_buffered_signed_pair()); } static void do_down3 (void) { - dvi_down(get_signed_triple(dvi_file)); + dvi_down(get_buffered_signed_triple()); } static void do_down4 (void) { - dvi_down(get_signed_quad(dvi_file)); + dvi_down(get_buffered_signed_quad()); } void @@ -1179,25 +1426,25 @@ dvi_y0 (void) static void do_y1 (void) { - dvi_y(get_signed_byte(dvi_file)); + dvi_y(get_buffered_signed_byte()); } static void do_y2 (void) { - dvi_y(get_signed_pair(dvi_file)); + dvi_y(get_buffered_signed_pair()); } static void do_y3 (void) { - dvi_y(get_signed_triple(dvi_file)); + dvi_y(get_buffered_signed_triple()); } static void do_y4 (void) { - dvi_y(get_signed_quad(dvi_file)); + dvi_y(get_buffered_signed_quad()); } void @@ -1216,25 +1463,25 @@ dvi_z0 (void) static void do_z1 (void) { - dvi_z(get_signed_byte(dvi_file)); + dvi_z(get_buffered_signed_byte()); } static void do_z2 (void) { - dvi_z(get_signed_pair(dvi_file)); + dvi_z(get_buffered_signed_pair()); } static void do_z3 (void) { - dvi_z(get_signed_triple(dvi_file)); + dvi_z(get_buffered_signed_triple()); } static void do_z4 (void) { - dvi_z(get_signed_quad(dvi_file)); + dvi_z(get_buffered_signed_quad()); } static void @@ -1316,7 +1563,7 @@ do_fnt1 (void) { SIGNED_QUAD tex_id; - tex_id = get_unsigned_byte(dvi_file); + tex_id = get_buffered_unsigned_byte(); do_fnt(tex_id); } @@ -1325,7 +1572,7 @@ do_fnt2 (void) { SIGNED_QUAD tex_id; - tex_id = get_unsigned_pair(dvi_file); + tex_id = get_buffered_unsigned_pair(); do_fnt(tex_id); } @@ -1334,7 +1581,7 @@ do_fnt3 (void) { SIGNED_QUAD tex_id; - tex_id = get_unsigned_triple(dvi_file); + tex_id = get_buffered_unsigned_triple(); do_fnt(tex_id); } @@ -1343,22 +1590,27 @@ do_fnt4 (void) { SIGNED_QUAD tex_id; - tex_id = get_signed_quad(dvi_file); + tex_id = get_buffered_signed_quad(); do_fnt(tex_id); } static void do_xxx (UNSIGNED_QUAD size) { +#ifdef XETEX + dvi_do_special(dvi_page_buffer + dvi_page_buf_index, size); + dvi_page_buf_index += size; +#else UNSIGNED_QUAD i; Ubyte *buffer; buffer = NEW(size+1, Ubyte); for (i = 0; i < size; i++) { - buffer[i] = get_unsigned_byte(dvi_file); + buffer[i] = get_buffered_unsigned_byte(); } dvi_do_special(buffer, size); RELEASE(buffer); +#endif } static void @@ -1366,7 +1618,7 @@ do_xxx1 (void) { SIGNED_QUAD size; - size = get_unsigned_byte(dvi_file); + size = get_buffered_unsigned_byte(); do_xxx(size); } @@ -1375,7 +1627,7 @@ do_xxx2 (void) { SIGNED_QUAD size; - size = get_unsigned_pair(dvi_file); + size = get_buffered_unsigned_pair(); do_xxx(size); } @@ -1384,7 +1636,7 @@ do_xxx3 (void) { SIGNED_QUAD size; - size = get_unsigned_triple(dvi_file); + size = get_buffered_unsigned_triple(); do_xxx(size); } @@ -1393,7 +1645,7 @@ do_xxx4 (void) { SIGNED_QUAD size; - size = get_unsigned_quad(dvi_file); + size = get_buffered_unsigned_quad(); do_xxx(size); } @@ -1407,12 +1659,12 @@ do_bop (void) /* For now, ignore TeX's count registers */ for (i = 0; i < 10; i++) { - get_signed_quad(dvi_file); + get_buffered_signed_quad(); } /* Ignore previous page pointer since we have already * saved this information */ - get_signed_quad(dvi_file); + get_buffered_signed_quad(); clear_state(); processing_page = 1; @@ -1444,6 +1696,168 @@ do_dir (void) pdf_dev_set_dirmode(dvi_state.d); /* 0: horizontal, 1: vertical */ } +#ifdef XETEX +static void +do_native_font_def (int scanning) +{ + if (scanning) { + SIGNED_QUAD tex_id = get_signed_quad(dvi_file); + if (linear) { + read_native_font_record(tex_id); + } else { + UNSIGNED_PAIR flags; + int name_length, nvars, i; + + get_unsigned_quad(dvi_file); /* skip point size */ + flags = get_unsigned_pair(dvi_file); + name_length = (int) get_unsigned_byte(dvi_file); + name_length += (int) get_unsigned_byte(dvi_file); + name_length += (int) get_unsigned_byte(dvi_file); + for (i = 0; i < name_length; ++i) + get_unsigned_byte(dvi_file); + if (flags & XDV_FLAG_COLORED) { + get_unsigned_quad(dvi_file); + } + if (flags & XDV_FLAG_VARIATIONS) { + nvars = get_unsigned_pair(dvi_file); + for (i = 0; i < nvars * 2; ++i) + get_unsigned_quad(dvi_file); /* skip axis and value for each variation setting */ + } + } + --dvi_page_buf_index; /* don't buffer the opcode */ + } +} + +static void +do_glyph_array (int yLocsPresent) +{ + struct loaded_font *font; + spt_t width, height, depth, *xloc, *yloc, glyph_width = 0; + unsigned char wbuf[2]; + unsigned int i, glyph_id, slen = 0; + + if (current_font < 0) + ERROR("No font selected!"); + + font = &loaded_fonts[current_font]; + + width = get_buffered_signed_quad(); + + slen = (unsigned int) get_buffered_unsigned_pair(); + xloc = NEW(slen, spt_t); + yloc = NEW(slen, spt_t); + for (i = 0; i < slen; i++) { + xloc[i] = get_buffered_signed_quad(); + yloc[i] = yLocsPresent ? get_buffered_signed_quad() : 0; + } + + if (font->rgba_color != 0xffffffff) { + pdf_color color; + pdf_color_rgbcolor(&color, + (double)((unsigned char)(font->rgba_color >> 24) & 0xff) / 255, + (double)((unsigned char)(font->rgba_color >> 16) & 0xff) / 255, + (double)((unsigned char)(font->rgba_color >> 8) & 0xff) / 255); + pdf_color_push(&color, &color); + } + + for (i = 0; i < slen; i++) { + glyph_id = get_buffered_unsigned_pair(); /* freetype glyph index */ + if (glyph_id < font->ft_face->num_glyphs) { + FT_Error error; + FT_Fixed advance; + int flags = FT_LOAD_NO_SCALE; + + if (font->layout_dir == 1) + flags |= FT_LOAD_VERTICAL_LAYOUT; + + error = FT_Get_Advance(font->ft_face, glyph_id, flags, &advance); + if (error) + advance = 0; + + glyph_width = (double)font->size * (double)advance / (double)font->ft_face->units_per_EM; + glyph_width = glyph_width * font->extend; + if (compute_boxes && link_annot && marked_depth >= tagged_depth) { + pdf_rect rect; + height = (double)font->size * (double)font->ft_face->ascender / (double)font->ft_face->units_per_EM; + depth = (double)font->size * -(double)font->ft_face->descender / (double)font->ft_face->units_per_EM; + pdf_dev_set_rect(&rect, dvi_state.h + xloc[i], -dvi_state.v - yloc[i], glyph_width, height, depth); + pdf_doc_expand_box(&rect); + } + } + + wbuf[0] = glyph_id >> 8; + wbuf[1] = glyph_id & 0xff; + pdf_dev_set_string(dvi_state.h + xloc[i], -dvi_state.v - yloc[i], wbuf, 2, + glyph_width, font->font_id, -1); + } + + if (font->rgba_color != 0xffffffff) { + pdf_color_pop(); + } + RELEASE(xloc); + RELEASE(yloc); + + if (!dvi_state.d) { + dvi_state.h += width; + } else { + dvi_state.v += width; + } + + return; +} + +static void +do_pic_file(void) + /* parameters for XDV_PIC_FILE opcode: pdf_box[1] t[4][6] p[2] len[2] path[l] */ +{ + int page_no; + UNSIGNED_PAIR len; + char *path; + int i; + int xobj_id; + transform_info ti; + + transform_info_clear(&ti); + + /* pdf_box = */ get_buffered_unsigned_byte(); + + ti.matrix.a = get_buffered_signed_quad() / 65536.0; /* convert 16.16 Fixed to floating-point */ + ti.matrix.b = get_buffered_signed_quad() / 65536.0; + ti.matrix.c = get_buffered_signed_quad() / 65536.0; + ti.matrix.d = get_buffered_signed_quad() / 65536.0; + ti.matrix.e = get_buffered_signed_quad() / 65536.0; + ti.matrix.f = get_buffered_signed_quad() / 65536.0; + + page_no = get_buffered_signed_pair(); + len = get_buffered_unsigned_pair(); + path = NEW(len + 1, char); + for (i = 0; i < len; ++i) + path[i] = get_buffered_unsigned_byte(); + path[len] = 0; + + /* + now we need to place page /page_no/ of the graphic file from /path/, applying /transform/ + if pdf_box=0 the file is a raster image (.jpg, .png, .tif, etc; need to determine format + by examining the file) + else it is a PDF document, pdf_box tells which PDF box (media, trim, crop, etc) to use + page_no is currently only used with PDF documents, though in theory could be used + with multi-page TIFFs, etc + transform is a 3x2 affine transform matrix expressed in fixed-point values + */ + + xobj_id = pdf_ximage_findresource(path, page_no, NULL); + if (xobj_id >= 0) { + /* FIXME: this seems to work for 72dpi JPEGs, but isn't right for others; + need to take the actual image resolution into account in pdf_dev_put_image, + not just assume the "original" size is 100dpi + */ + pdf_dev_put_image(xobj_id, &ti, dvi_dev_xpos(), dvi_dev_ypos()); + } + + RELEASE(path); +} +#endif + /* Note to be absolutely certain that the string escape buffer doesn't * hit its limit, FORMAT_BUF_SIZE should set to 4 times S_BUFFER_SIZE * in pdfobj.c. Is there any application that genenerate words with @@ -1478,7 +1892,7 @@ dvi_do_page (long n, /* The most likely opcodes are individual setchars. * These are buffered for speed. */ slen = 0; - while ((opcode = fgetc(dvi_file)) <= SET_CHAR_127 && + while ((opcode = get_buffered_unsigned_byte()) <= SET_CHAR_127 && slen < SBUF_SIZE) { sbuf[slen++] = opcode; } @@ -1604,7 +2018,31 @@ dvi_do_page (long n, do_dir(); break; - case PRE: case POST: case POST_POST: +#ifdef XETEX + /* XeTeX extension */ + case XDV_GLYPH_STRING: + do_glyph_array(0); + break; + case XDV_GLYPH_ARRAY: + do_glyph_array(1); + break; + case XDV_NATIVE_FONT_DEF: + do_native_font_def(0); /* should not occur - processed during pre-scanning */ + break; + case XDV_PIC_FILE: + do_pic_file(); + break; +#endif + + case POST: +#ifdef XETEX + if (linear && !processing_page) { + /* for linear processing, this means there are no more pages */ + num_pages = 0; /* force loop to terminate */ + return; + } + /* else fall through to error case */ +#endif ERROR("Unexpected preamble or postamble in dvi file"); break; default: @@ -1614,7 +2052,7 @@ dvi_do_page (long n, } double -dvi_init (const char *dvi_filename, double mag) +dvi_init (char *dvi_filename, double mag) { long post_location; @@ -1938,50 +2376,50 @@ dvi_scan_specials (long page_no, UNSIGNED_QUAD size = 0UL; char buf[1024]; switch (opcode) { - case XXX1: size = get_unsigned_byte(fp); break; - case XXX2: size = get_unsigned_pair(fp); break; - case XXX3: size = get_unsigned_triple(fp); break; - case XXX4: size = get_unsigned_quad(fp); break; + case XXX1: size = get_and_buffer_unsigned_byte(fp); break; + case XXX2: size = get_and_buffer_unsigned_pair(fp); break; + case XXX3: size = get_and_buffer_unsigned_triple(fp); break; + case XXX4: size = get_and_buffer_unsigned_quad(fp); break; } size = MIN(size, 1024); if (fread(buf, sizeof(char), size, fp) != size) ERROR("Reading DVI file failed!"); if (scan_special(page_width, page_height, x_offset, y_offset, landscape, minorversion, do_enc, key_bits, permission, owner_pw, user_pw, buf, size)) - WARN("Reading special command failed: \"%.*s\"", size, buf); + WARN("Reading special command failed: \"%.*s\"", size, buf); continue; } /* Skipping... */ switch (opcode) { case BOP: - seek_relative(fp, 44); + get_and_buffer_bytes(fp, 44); break; case NOP: case PUSH: case POP: case W0: case X0: case Y0: case Z0: break; case SET1: case PUT1: case RIGHT1: case DOWN1: case W1: case X1: case Y1: case Z1: case FNT1: - get_unsigned_byte(fp); + get_and_buffer_unsigned_byte(fp); break; case SET2: case PUT2: case RIGHT2: case DOWN2: case W2: case X2: case Y2: case Z2: case FNT2: - get_signed_pair(fp); + get_and_buffer_signed_pair(fp); break; case SET3: case PUT3: case RIGHT3: case DOWN3: case W3: case X3: case Y3: case Z3: case FNT3: - get_signed_triple(fp); + get_and_buffer_signed_triple(fp); break; case SET4: case PUT4: case RIGHT4: case DOWN4: case W4: case X4: case Y4: case Z4: case FNT4: - get_signed_quad(fp); + get_and_buffer_signed_quad(fp); break; case SET_RULE: case PUT_RULE: - seek_relative(fp, 8); + get_and_buffer_bytes(fp, 8); break; case FNT_DEF1: do_fntdef1(); break; @@ -1989,11 +2427,50 @@ dvi_scan_specials (long page_no, case FNT_DEF3: do_fntdef3(); break; case FNT_DEF4: do_fntdef4(); break; +#ifdef XETEX + case XDV_GLYPH_STRING: + { + UNSIGNED_PAIR count; + get_and_buffer_unsigned_quad(fp); /* width */ + count = get_and_buffer_unsigned_pair(fp); /* glyph count */ + get_and_buffer_bytes(fp, count * 6); /* 2 bytes ID + 4 bytes x-location per glyph */ + } + break; + case XDV_GLYPH_ARRAY: + { + UNSIGNED_PAIR count; + get_and_buffer_unsigned_quad(fp); /* width */ + count = get_and_buffer_unsigned_pair(fp); /* glyph count */ + get_and_buffer_bytes(fp, count * 10); /* 2 bytes ID + 8 bytes x,y-location per glyph */ + } + break; + case XDV_NATIVE_FONT_DEF: + do_native_font_def(1); + break; + case XDV_PIC_FILE: + /* params: flags[1] t[4][6] p[2] len[2] path[l] */ + { + UNSIGNED_PAIR len; + get_and_buffer_bytes(fp, 1 + 4 * 6 + 2); + len = get_and_buffer_unsigned_pair(fp); /* length of pathname */ + get_and_buffer_bytes(fp, len); + } + break; +#endif + case PTEXDIR: - get_unsigned_byte(fp); + get_and_buffer_unsigned_byte(fp); break; - default: /* case PRE: case POST: case POST_POST: and others */ + case POST: +#ifdef XETEX + if (linear && dvi_page_buf_index == 1) { + /* this is actually an indication that we've reached the end of the input */ + return; + } + /* else fall through to error case */ +#endif + default: /* case PRE: case POST_POST: and others */ ERROR("Unexpected opcode %d at pos=0x%x", opcode, tell_position(fp)); break; } diff --git a/Build/source/texk/dvipdfm-x/src/dvi.h b/Build/source/texk/dvipdfm-x/src/dvi.h deleted file mode 100644 index f827bcafeaf..00000000000 --- a/Build/source/texk/dvipdfm-x/src/dvi.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - - This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - - Copyright (C) 2002-2012 by Jin-Hwan Cho and Shunsaku Hirata, - the dvipdfmx project team. - - Copyright (C) 1998, 1999 by Mark A. Wicks - - This program 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; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -*/ - -#ifndef _DVI_H_ -#define _DVI_H_ - -#include "error.h" -#include "numbers.h" -/* spt_t */ -#include "pdfdev.h" - -extern void dvi_set_verbose (void); - -/* returns scale (dvi2pts) */ -extern double dvi_init (const char *dvi_filename, double mag); -extern void dvi_close (void); /* Closes data structures created by dvi_open */ - -extern double dvi_tell_mag (void); -#ifdef XETEX -extern double dvi_unit_size (void); -#endif -extern double dvi_dev_xpos (void); -extern double dvi_dev_ypos (void); -extern unsigned dvi_npages (void); -extern const char *dvi_comment (void); - -extern void dvi_vf_init (int dev_font_id); -extern void dvi_vf_finish (void); - -extern void dvi_set_font (int font_id); -extern void dvi_set (SIGNED_QUAD ch); -extern void dvi_rule (SIGNED_QUAD width, SIGNED_QUAD height); - -extern void dvi_right (SIGNED_QUAD x); -extern void dvi_put (SIGNED_QUAD ch); -extern void dvi_push (void); -extern void dvi_pop (void); -extern void dvi_w0 (void); -extern void dvi_w (SIGNED_QUAD ch); -extern void dvi_x0 (void); -extern void dvi_x (SIGNED_QUAD ch); -extern void dvi_down (SIGNED_QUAD y); -extern void dvi_y (SIGNED_QUAD ch); -extern void dvi_y0 (void); -extern void dvi_z (SIGNED_QUAD ch); -extern void dvi_z0 (void); -extern void dvi_dir (UNSIGNED_BYTE dir); - -extern void dvi_do_page (long page_no, - double paper_width, double paper_height, - double x_offset, double y_offset); -extern void dvi_scan_specials (long page_no, - double *width, double *height, - double *x_offset, double *y_offset, - char *landscape, unsigned *minorversion, - int *do_enc, unsigned *key_bits, unsigned *permission, char *owner_pw, char *user_pw); -extern int dvi_locate_font (const char *name, spt_t ptsize); - -/* link or nolink: - * See dvipdfm (not x) user's manual on pdf:link and pdf:nolink. - * This is workaround for preventing inclusion of pagenation artifact such as - * footnote and page number in link annotation. - */ -extern void dvi_link_annot (int flag); -/* The followings are for calculating bounding box of text for annotation. - * DVI uses push/pop to do line-feed-carriage-return. So line breaking is - * handled by inspecting current depth of DVI register stack. - */ -extern void dvi_tag_depth (void); -extern void dvi_untag_depth (void); -extern void dvi_compute_boxes (int flag); - -extern void dvi_do_special (const void *buffer, UNSIGNED_QUAD size); - -#endif /* _DVI_H_ */ diff --git a/Build/source/texk/dvipdfm-x/src/dvipdfmx.c b/Build/source/texk/dvipdfm-x/src/dvipdfmx.c index 9cbfeef9145..0b4ea307fe9 100644 --- a/Build/source/texk/dvipdfm-x/src/dvipdfmx.c +++ b/Build/source/texk/dvipdfm-x/src/dvipdfmx.c @@ -3,7 +3,7 @@ This is DVIPDFMx, an eXtended version of DVIPDFM by Mark A. Wicks. Copyright (C) 2002-2013 by Jin-Hwan Cho, Matthias Franz, and Shunsaku Hirata, - the dvipdfmx project team. + the DVIPDFMx project team. Copyright (C) 1998, 1999 by Mark A. Wicks @@ -61,6 +61,10 @@ #include "error.h" +#ifdef XETEX +#include "tt_aux.h" +#endif + int compat_mode = 0; /* 0 = dvipdfmx, 1 = dvipdfm */ static int verbose = 0; @@ -110,12 +114,6 @@ char *dvi_filename = NULL, *pdf_filename = NULL; static void read_config_file (const char *config); -#ifdef WIN32 -#define STRN_CMP strncasecmp -#else -#define STRN_CMP strncmp -#endif - static void set_default_pdf_filename(void) { @@ -124,12 +122,16 @@ set_default_pdf_filename(void) dvi_base = xbasename(dvi_filename); if (mp_mode && strlen(dvi_base) > 4 && - !STRN_CMP(".mps", dvi_base + strlen(dvi_base) - 4, 4)) { + FILESTRCASEEQ(".mps", dvi_base + strlen(dvi_base) - 4)) { pdf_filename = NEW(strlen(dvi_base)+1, char); strncpy(pdf_filename, dvi_base, strlen(dvi_base) - 4); pdf_filename[strlen(dvi_base)-4] = '\0'; } else if (strlen(dvi_base) > 4 && - !STRN_CMP(".dvi", dvi_base+strlen(dvi_base)-4, 4)) { + (FILESTRCASEEQ(".dvi", dvi_base+strlen(dvi_base)-4) +#ifdef XETEX + || FILESTRCASEEQ(".xdv", dvi_base+strlen(dvi_base)-4) +#endif + )) { pdf_filename = NEW(strlen(dvi_base)+1, char); strncpy(pdf_filename, dvi_base, strlen(dvi_base)-4); pdf_filename[strlen(dvi_base)-4] = '\0'; @@ -144,61 +146,61 @@ set_default_pdf_filename(void) static void show_version (void) { - fprintf(stdout, "\nThis is %s-%s by the DVIPDFMx project team,\n", PACKAGE, VERSION); - fprintf(stdout, "modified for TeX Live,\n"); - fprintf(stdout, "an extended version of dvipdfm-0.13.2c developed by Mark A. Wicks.\n"); - fprintf(stdout, "\nCopyright (C) 2002-2013 by the DVIPDFMx project team\n"); - fprintf(stdout, "\nThis is free software; you can redistribute it and/or modify\n"); - fprintf(stdout, "it under the terms of the GNU General Public License as published by\n"); - fprintf(stdout, "the Free Software Foundation; either version 2 of the License, or\n"); - fprintf(stdout, "(at your option) any later version.\n"); + fprintf (stdout, "\nThis is dvipdfmx-%s by the DVIPDFMx project team,\n", VERSION); + fprintf (stdout, "modified for TeX Live,\n"); + fprintf (stdout, "an extended version of dvipdfm-0.13.2c developed by Mark A. Wicks.\n"); + fprintf (stdout, "\nCopyright (C) 2002-2013 by the DVIPDFMx project team\n"); + fprintf (stdout, "\nThis is free software; you can redistribute it and/or modify\n"); + fprintf (stdout, "it under the terms of the GNU General Public License as published by\n"); + fprintf (stdout, "the Free Software Foundation; either version 2 of the License, or\n"); + fprintf (stdout, "(at your option) any later version.\n"); } static void show_usage (void) { - fprintf(stdout, "\nUsage: dvipdfmx [options] dvifile\n"); - fprintf(stdout, "-c \t\tIgnore color specials (for B&W printing)\n"); - fprintf(stdout, "-d number\tSet PDF decimal digits (0-5) [2]\n"); - fprintf(stdout, "-f filename\tSet font map file name [cid-x.map]\n"); - fprintf(stdout, "-g dimension\tAnnotation \"grow\" amount [0.0in]\n"); - fprintf(stdout, "-l \t\tLandscape mode\n"); - fprintf(stdout, "-m number\tSet additional magnification\n"); - fprintf(stdout, "-o filename\tSet output file name [dvifile.pdf]\n"); - fprintf(stdout, "-p papersize\tSet papersize [a4]\n"); - fprintf(stdout, "-q \t\tBe quiet\n"); - fprintf(stdout, "-r resolution\tSet resolution (in DPI) for raster fonts [600]\n"); - fprintf(stdout, "-s pages\tSelect page ranges (-)\n"); - fprintf(stdout, "-t \t\tEmbed thumbnail images of PNG format [dvifile.1] \n"); - fprintf(stdout, "-x dimension\tSet horizontal offset [1.0in]\n"); - fprintf(stdout, "-y dimension\tSet vertical offset [1.0in]\n"); - fprintf(stdout, "-z number \tSet zlib compression level (0-9) [9]\n"); - - fprintf(stdout, "-v \t\tBe verbose\n"); - fprintf(stdout, "-vv\t\tBe more verbose\n"); - fprintf(stdout, "-C number\tSpecify miscellaneous option flags [0]:\n"); - fprintf(stdout, "\t\t 0x0001 reserved\n"); - fprintf(stdout, "\t\t 0x0002 Use semi-transparent filling for tpic shading command,\n"); - fprintf(stdout, "\t\t\t instead of opaque gray color. (requires PDF 1.4)\n"); - fprintf(stdout, "\t\t 0x0004 Treat all CIDFont as fixed-pitch font.\n"); - fprintf(stdout, "\t\t 0x0008 Do not replace duplicate fontmap entries.\n"); - fprintf(stdout, "\t\t 0x0010 Do not optimize PDF destinations.\n"); - fprintf(stdout, "\t\tPositive values are always ORed with previously given flags.\n"); - fprintf(stdout, "\t\tAnd negative values replace old values.\n"); - fprintf(stdout, "-D template\tPS->PDF conversion command line template [none]\n"); - fprintf(stdout, "-E \t\tEnable DVIPDFM emulation mode\n"); - fprintf(stdout, "-I number\tImage cache life in hours [-2]\n"); - fprintf(stdout, " \t 0: erase all old images and leave new images\n"); - fprintf(stdout, " \t-1: erase all old images and also erase new images\n"); - fprintf(stdout, " \t-2: ignore image cache\n"); - fprintf(stdout, "-K number\tEncryption key length [40]\n"); - fprintf(stdout, "-O number\tSet maximum depth of open bookmark items [0]\n"); - fprintf(stdout, "-P number\tSet permission flags for PDF encryption [0x003C]\n"); - fprintf(stdout, "-S \t\tEnable PDF encryption\n"); - fprintf(stdout, "-V number\tSet PDF minor version [4]\n"); - fprintf(stdout, "\nAll dimensions entered on the command line are \"true\" TeX dimensions.\n"); - fprintf(stdout, "Argument of \"-s\" lists physical page ranges separated by commas, e.g., \"-s 1-3,5-6\"\n"); - fprintf(stdout, "Papersize is specified by paper format (e.g., \"a4\") or by w,h (e.g., \"20cm,30cm\").\n"); + fprintf (stdout, "\nUsage: dvipdfmx [options] dvifile\n"); + fprintf (stdout, "-c \t\tIgnore color specials (for B&W printing)\n"); + fprintf (stdout, "-d number\tSet PDF decimal digits (0-5) [2]\n"); + fprintf (stdout, "-f filename\tSet font map file name [cid-x.map]\n"); + fprintf (stdout, "-g dimension\tAnnotation \"grow\" amount [0.0in]\n"); + fprintf (stdout, "-l \t\tLandscape mode\n"); + fprintf (stdout, "-m number\tSet additional magnification\n"); + fprintf (stdout, "-o filename\tSet output file name [dvifile.pdf]\n"); + fprintf (stdout, "-p papersize\tSet papersize [a4]\n"); + fprintf (stdout, "-q \t\tBe quiet\n"); + fprintf (stdout, "-r resolution\tSet resolution (in DPI) for raster fonts [600]\n"); + fprintf (stdout, "-s pages\tSelect page ranges (-)\n"); + fprintf (stdout, "-t \t\tEmbed thumbnail images of PNG format [dvifile.1] \n"); + fprintf (stdout, "-x dimension\tSet horizontal offset [1.0in]\n"); + fprintf (stdout, "-y dimension\tSet vertical offset [1.0in]\n"); + fprintf (stdout, "-z number \tSet zlib compression level (0-9) [9]\n"); + + fprintf (stdout, "-v \t\tBe verbose\n"); + fprintf (stdout, "-vv\t\tBe more verbose\n"); + fprintf (stdout, "-C number\tSpecify miscellaneous option flags [0]:\n"); + fprintf (stdout, "\t\t 0x0001 reserved\n"); + fprintf (stdout, "\t\t 0x0002 Use semi-transparent filling for tpic shading command,\n"); + fprintf (stdout, "\t\t\t instead of opaque gray color. (requires PDF 1.4)\n"); + fprintf (stdout, "\t\t 0x0004 Treat all CIDFont as fixed-pitch font.\n"); + fprintf (stdout, "\t\t 0x0008 Do not replace duplicate fontmap entries.\n"); + fprintf (stdout, "\t\t 0x0010 Do not optimize PDF destinations.\n"); + fprintf (stdout, "\t\tPositive values are always ORed with previously given flags.\n"); + fprintf (stdout, "\t\tAnd negative values replace old values.\n"); + fprintf (stdout, "-D template\tPS->PDF conversion command line template [none]\n"); + fprintf (stdout, "-E \t\tEnable DVIPDFM emulation mode\n"); + fprintf (stdout, "-I number\tImage cache life in hours [-2]\n"); + fprintf (stdout, " \t 0: erase all old images and leave new images\n"); + fprintf (stdout, " \t-1: erase all old images and also erase new images\n"); + fprintf (stdout, " \t-2: ignore image cache\n"); + fprintf (stdout, "-K number\tEncryption key length [40]\n"); + fprintf (stdout, "-O number\tSet maximum depth of open bookmark items [0]\n"); + fprintf (stdout, "-P number\tSet permission flags for PDF encryption [0x003C]\n"); + fprintf (stdout, "-S \t\tEnable PDF encryption\n"); + fprintf (stdout, "-V number\tSet PDF minor version [4]\n"); + fprintf (stdout, "\nAll dimensions entered on the command line are \"true\" TeX dimensions.\n"); + fprintf (stdout, "Argument of \"-s\" lists physical page ranges separated by commas, e.g., \"-s 1-3,5-6\"\n"); + fprintf (stdout, "Papersize is specified by paper format (e.g., \"a4\") or by w,h (e.g., \"20cm,30cm\").\n"); } static void @@ -618,7 +620,7 @@ do_args (int argc, char *argv[]) * do_args was called from config file. In that case, there is * no dvi file name. Check for that case . */ - if (!mp_mode && STRN_CMP(".dvi", argv[0] + strlen(argv[0]) - 4, 4)) { + if (!mp_mode && !FILESTRCASEEQ(".dvi", argv[0] + strlen(argv[0]) - 4)) { dvi_filename = NEW(strlen(argv[0]) + 5, char); strcpy(dvi_filename, argv[0]); strcat(dvi_filename, ".dvi"); @@ -865,18 +867,17 @@ main (int argc, char *argv[]) { double dvi2pts; - { - const char *base = xbasename(argv[0]); + char *base = kpse_program_basename (argv[0]); + + if (FILESTRCASEEQ (base, "extractbb") || FILESTRCASEEQ (base, "xbb")) + return extractbb (argc, argv, XBB_OUTPUT); + if (FILESTRCASEEQ (base, "ebb")) + return extractbb (argc, argv, EBB_OUTPUT); + + if (FILESTRCASEEQ (base, "dvipdfm")) + compat_mode = 1; - if (STRN_CMP(base, "dvipdfmx", 8) != 0 && - (STRN_CMP(base, "dvipdfm",7) == 0 || STRN_CMP(base, "ebb", 3) == 0)) - compat_mode = 1; - - if (STRN_CMP(base, "extractbb", 9) == 0 || - STRN_CMP(base, "xbb", 3) == 0 || - STRN_CMP(base, "ebb", 3) == 0) - return extractbb(argc, argv, 0); - } + free (base); if (argc < 2) { if (!really_quiet) @@ -888,7 +889,7 @@ main (int argc, char *argv[]) #ifdef MIKTEX miktex_initialize(); #else - kpse_set_program_name(argv[0], PACKAGE); + kpse_set_program_name(argv[0], "dvipdfmx"); /* we pretend to be dvipdfmx for kpse purposes */ #endif paperinit(); diff --git a/Build/source/texk/dvipdfm-x/src/epdf.c b/Build/source/texk/dvipdfm-x/src/epdf.c index edb4ee6f5e4..46e1a75d15c 100644 --- a/Build/source/texk/dvipdfm-x/src/epdf.c +++ b/Build/source/texk/dvipdfm-x/src/epdf.c @@ -39,10 +39,7 @@ #include "mem.h" #include "mfileio.h" #include "error.h" - -#ifndef XETEX #include "dvipdfmx.h" -#endif #include "pdfobj.h" #include "pdfdev.h" diff --git a/Build/source/texk/dvipdfm-x/src/mpost.c b/Build/source/texk/dvipdfm-x/src/mpost.c deleted file mode 100644 index 703d0b45a36..00000000000 --- a/Build/source/texk/dvipdfm-x/src/mpost.c +++ /dev/null @@ -1,1674 +0,0 @@ -/* - - This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - - Copyright (C) 2007-2012 by Jin-Hwan Cho and Shunsaku Hirata, - the dvipdfmx project team. - - Copyright (C) 1998, 1999 by Mark A. Wicks - - This program 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; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -*/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#include "system.h" -#include "mem.h" -#include "error.h" -#include "mfileio.h" -#include "numbers.h" - -#include "tfm.h" - -#include "pdfobj.h" -#include "pdfparse.h" -#include "pdfdev.h" -#include "pdfdoc.h" - -#include "pdfcolor.h" -#include "pdfdraw.h" - -#include "fontmap.h" -#include "subfont.h" - -#include "pdfximage.h" - -#include "mpost.h" - -/* - * In PDF, current path is not a part of graphics state parameter. - * Hence, current path is not saved by the "q" operator and is not - * recovered by the "Q" operator. This means that the following PS - * code - * - * gsave grestore ... - * - * can't be translated to PDF code - * - * q Q ... - * - * . Only clipping path (which is graphics state parameter in PDF - * too) is treated in the same way. So, we write clipping path - * immediately and forget about it but remember current path. - */ - -static int mp_parse_body (const char **start, const char *end, double x_user, double y_user); - -static struct mp_font -{ - char *font_name; - int font_id; - int tfm_id; /* Used for text width calculation */ - int subfont_id; - double pt_size; -} font_stack[PDF_GSAVE_MAX] = { - {NULL, -1, -1, -1, 0} -}; -static int currentfont = -1; - -#define CURRENT_FONT() ((currentfont < 0) ? NULL : &font_stack[currentfont]) - -/* Compatibility */ -#define MP_CMODE_MPOST 0 -#define MP_CMODE_DVIPSK 1 -#define MP_CMODE_PTEXVERT 2 -static int mp_cmode = MP_CMODE_MPOST; - -static int -mp_setfont (const char *font_name, double pt_size) -{ - const char *name = font_name; - struct mp_font *font; - int subfont_id = -1; - fontmap_rec *mrec; - - font = CURRENT_FONT(); - - if (font) { - if (!strcmp(font->font_name, font_name) && - font->pt_size == pt_size) - return 0; - } else { /* No currentfont */ -/* ***TODO*** Here some problem exists! */ - font = &font_stack[0]; - font->font_name = NULL; - currentfont = 0; - } - - mrec = pdf_lookup_fontmap_record(font_name); - if (mrec && mrec->charmap.sfd_name && mrec->charmap.subfont_id) { - subfont_id = sfd_load_record(mrec->charmap.sfd_name, mrec->charmap.subfont_id); - } - - /* See comments in dvi_locate_font() in dvi.c. */ - if (mrec && mrec->map_name) { - name = mrec->map_name; - } else { - name = font_name; - } - - if (font->font_name) - RELEASE(font->font_name); - font->font_name = NEW(strlen(font_name) + 1, char); - strcpy(font->font_name, font_name); - font->subfont_id = subfont_id; - font->pt_size = pt_size; - font->tfm_id = tfm_open(font_name, 0); /* Need not exist in MP mode */ - font->font_id = pdf_dev_locate_font(name, - (spt_t) (pt_size * dev_unit_dviunit())); - - if (font->font_id < 0) { - ERROR("MPOST: No physical font assigned for \"%s\".", font_name); - return 1; - } - - return 0; -} - -static void -save_font (void) -{ - struct mp_font *current, *next; - - if (currentfont < 0) { - font_stack[0].font_name = NEW(strlen("Courier") + 1, char); - strcpy(font_stack[0].font_name, "Courier"); - font_stack[0].pt_size = 1; - font_stack[0].tfm_id = 0; - font_stack[0].subfont_id = 0; - currentfont = 0; - } - - current = &font_stack[currentfont++]; - next = &font_stack[currentfont ]; - next->font_name = NEW(strlen(current->font_name)+1, char); - strcpy(next->font_name, current->font_name); - next->pt_size = current->pt_size; - - next->subfont_id = current->subfont_id; - next->tfm_id = current->tfm_id; -} - -static void -restore_font (void) -{ - struct mp_font *current; - - current = CURRENT_FONT(); - if (current) { - if (current->font_name) - RELEASE(current->font_name); - current->font_name = NULL; - } else { - ERROR("No currentfont..."); - } - - currentfont--; -} - -static void -clear_fonts (void) -{ - while (currentfont >= 0) { - if (font_stack[currentfont].font_name) - RELEASE(font_stack[currentfont].font_name); - currentfont--; - } -} - -static int -is_fontname (const char *token) -{ - fontmap_rec *mrec; - - mrec = pdf_lookup_fontmap_record(token); - if (mrec) - return 1; - - return tfm_exists(token); -} - -int -mps_scan_bbox (const char **pp, const char *endptr, pdf_rect *bbox) -{ - char *number; - double values[4]; - int i; - - /* skip_white() skips lines starting '%'... */ - while (*pp < endptr && isspace(**pp)) - (*pp)++; - - /* Scan for bounding box record */ - while (*pp < endptr && **pp == '%') { - if (*pp + 14 < endptr && - !strncmp(*pp, "%%BoundingBox:", 14)) { - - *pp += 14; - - for (i = 0; i < 4; i++) { - skip_white(pp, endptr); - number = parse_number(pp, endptr); - if (!number) { - break; - } - values[i] = atof(number); - RELEASE(number); - } - if (i < 4) { - return -1; - } else { - bbox->llx = values[0]; - bbox->lly = values[1]; - bbox->urx = values[2]; - bbox->ury = values[3]; - - return 0; - } - } - skip_line (pp, endptr); - while (*pp < endptr && isspace(**pp)) - (*pp)++; - } - - return -1; -} - -static void -skip_prolog (const char **start, const char *end) -{ - int found_prolog = 0; - const char *save; - - save = *start; - while (*start < end) { - if (**start != '%') - skip_white(start, end); - if (*start >= end) - break; - if (!strncmp(*start, "%%EndProlog", 11)) { - found_prolog = 1; - skip_line(start, end); - break; - } else if (!strncmp(*start, "%%Page:", 7)) { - skip_line(start, end); - break; - } - skip_line(start, end); - } - if (!found_prolog) { - *start = save; - } - - return; -} - -/* PostScript Operators */ - -#define ADD 1 -#define SUB 2 -#define MUL 3 -#define DIV 4 -#define NEG 5 -#define TRUNCATE 6 - -#define CLEAR 10 -#define EXCH 11 -#define POP 12 - -#define NEWPATH 31 -#define CLOSEPATH 32 -#define MOVETO 33 -#define RMOVETO 34 -#define CURVETO 35 -#define RCURVETO 36 -#define LINETO 37 -#define RLINETO 38 -#define ARC 39 -#define ARCN 40 - -#define FILL 41 -#define STROKE 42 -#define SHOW 43 - -#define CLIP 44 -#define EOCLIP 45 - -#define SHOWPAGE 49 - -#define GSAVE 50 -#define GRESTORE 51 - -#define CONCAT 52 -#define SCALE 53 -#define TRANSLATE 54 -#define ROTATE 55 - -#define SETLINEWIDTH 60 -#define SETDASH 61 -#define SETLINECAP 62 -#define SETLINEJOIN 63 -#define SETMITERLIMIT 64 - -#define SETGRAY 70 -#define SETRGBCOLOR 71 -#define SETCMYKCOLOR 72 - -#define CURRENTPOINT 80 -#define IDTRANSFORM 81 -#define DTRANSFORM 82 - -#define FINDFONT 201 -#define SCALEFONT 202 -#define SETFONT 203 -#define CURRENTFONT 204 - -#define STRINGWIDTH 210 - -#define DEF 999 - -#define FSHOW 1001 -#define STEXFIG 1002 -#define ETEXFIG 1003 -#define HLW 1004 -#define VLW 1005 -#define RD 1006 -#define B 1007 - -static struct operators -{ - const char *token; - int opcode; -} ps_operators[] = { - {"add", ADD}, - {"mul", MUL}, - {"div", DIV}, - {"neg", NEG}, - {"sub", SUB}, - {"truncate", TRUNCATE}, - - {"clear", CLEAR}, - {"exch", EXCH}, - {"pop", POP}, - - {"clip", CLIP}, - {"eoclip", EOCLIP}, - {"closepath", CLOSEPATH}, - {"concat", CONCAT}, - - {"newpath", NEWPATH}, - {"moveto", MOVETO}, - {"rmoveto", RMOVETO}, - {"lineto", LINETO}, - {"rlineto", RLINETO}, - {"curveto", CURVETO}, - {"rcurveto", RCURVETO}, - {"arc", ARC}, - {"arcn", ARCN}, - - {"stroke", STROKE}, - {"fill", FILL}, - {"show", SHOW}, - {"showpage", SHOWPAGE}, - - {"gsave", GSAVE}, - {"grestore", GRESTORE}, - {"translate", TRANSLATE}, - {"rotate", ROTATE}, - {"scale", SCALE}, - - {"setlinecap", SETLINECAP}, - {"setlinejoin", SETLINEJOIN}, - {"setlinewidth", SETLINEWIDTH}, - {"setmiterlimit", SETMITERLIMIT}, - {"setdash", SETDASH}, - - {"setgray", SETGRAY}, - {"setrgbcolor", SETRGBCOLOR}, - {"setcmykcolor", SETCMYKCOLOR}, - - {"currentpoint", CURRENTPOINT}, /* This is here for rotate support - in graphics package-not MP support */ - {"dtransform", DTRANSFORM}, - {"idtransform", IDTRANSFORM}, - - {"findfont", FINDFONT}, - {"scalefont", SCALEFONT}, - {"setfont", SETFONT}, - {"currentfont", CURRENTFONT}, - - {"stringwidth", STRINGWIDTH}, - - {"def", DEF} /* not implemented yet; just work with mptopdf */ -}; - -static struct operators mps_operators[] = { - {"fshow", FSHOW}, /* exch findfont exch scalefont setfont show */ - {"startTexFig", STEXFIG}, - {"endTexFig", ETEXFIG}, - {"hlw", HLW}, /* 0 dtransform exch truncate exch idtransform pop setlinewidth */ - {"vlw", VLW}, /* 0 exch dtransform truncate idtransform pop setlinewidth pop */ - {"l", LINETO}, - {"r", RLINETO}, - {"c", CURVETO}, - {"m", MOVETO}, - {"p", CLOSEPATH}, - {"n", NEWPATH}, - {"C", SETCMYKCOLOR}, - {"G", SETGRAY}, - {"R", SETRGBCOLOR}, - {"lj", SETLINEJOIN}, - {"ml", SETMITERLIMIT}, - {"lc", SETLINECAP}, - {"S", STROKE}, - {"F", FILL}, - {"q", GSAVE}, - {"Q", GRESTORE}, - {"s", SCALE}, - {"t", CONCAT}, - {"sd", SETDASH}, - {"rd", RD}, /* [] 0 setdash */ - {"P", SHOWPAGE}, - {"B", B}, /* gsave fill grestore */ - {"W", CLIP} -}; - -#define NUM_PS_OPERATORS (sizeof(ps_operators)/sizeof(ps_operators[0])) -#define NUM_MPS_OPERATORS (sizeof(mps_operators)/sizeof(mps_operators[0])) -static int -get_opcode (const char *token) -{ - int i; - - for (i = 0; i < NUM_PS_OPERATORS; i++) { - if (!strcmp(token, ps_operators[i].token)) { - return ps_operators[i].opcode; - } - } - - for (i = 0; i < NUM_MPS_OPERATORS; i++) { - if (!strcmp(token, mps_operators[i].token)) { - return mps_operators[i].opcode; - } - } - - return -1; -} - -#define PS_STACK_SIZE 1024 - -static pdf_obj *stack[PS_STACK_SIZE]; -static unsigned top_stack = 0; - -#define POP_STACK() ((top_stack > 0) ? stack[--top_stack] : NULL) -#define PUSH_STACK(o,e) { \ - if (top_stack < PS_STACK_SIZE) { \ - stack[top_stack++] = (o); \ - } else { \ - WARN("PS stack overflow including MetaPost file or inline PS code"); \ - *(e) = 1; \ - } \ -} - -static int -do_exch (void) -{ - pdf_obj *tmp; - - if (top_stack < 2) - return -1; - - tmp = stack[top_stack-1]; - stack[top_stack-1] = stack[top_stack-2]; - stack[top_stack-2] = tmp; - - return 0; -} - -static int -do_clear (void) -{ - pdf_obj *tmp; - - while (top_stack > 0) { - tmp = POP_STACK(); - if (tmp) - pdf_release_obj(tmp); - } - - return 0; -} - -/* This should be set_bottom and clear (or - * have independent stack) to ensure stack - * depth do not go below real stack bottom. - */ -static void -mps_stack_clear_to (int depth) -{ - pdf_obj *tmp; - - while (top_stack > depth) { - tmp = POP_STACK(); - if (tmp) - pdf_release_obj(tmp); - } - - return; -} - -static int -pop_get_numbers (double *values, int count) -{ - pdf_obj *tmp; - - while (count-- > 0) { - tmp = POP_STACK(); - if (!tmp) { - WARN("mpost: Stack underflow."); - break; - } else if (!PDF_OBJ_NUMBERTYPE(tmp)) { - WARN("mpost: Not a number!"); - pdf_release_obj(tmp); - break; - } - values[count] = pdf_number_value(tmp); - pdf_release_obj(tmp); - } - - return (count + 1); -} - -static int -cvr_array (pdf_obj *array, double *values, int count) -{ - if (!PDF_OBJ_ARRAYTYPE(array)) { - WARN("mpost: Not an array!"); - } else { - pdf_obj *tmp; - - while (count-- > 0) { - tmp = pdf_get_array(array, count); - if (!PDF_OBJ_NUMBERTYPE(tmp)) { - WARN("mpost: Not a number!"); - break; - } - values[count] = pdf_number_value(tmp); - } - } - if (array) - pdf_release_obj(array); - - return (count + 1); -} - -static int -is_fontdict (pdf_obj *dict) -{ - pdf_obj *tmp; - - if (!PDF_OBJ_DICTTYPE(dict)) - return 0; - - tmp = pdf_lookup_dict(dict, "Type"); - if (!tmp || !PDF_OBJ_NAMETYPE(tmp) || - strcmp(pdf_name_value(tmp), "Font")) { - return 0; - } - - tmp = pdf_lookup_dict(dict, "FontName"); - if (!tmp || !PDF_OBJ_NAMETYPE(tmp)) { - return 0; - } - - tmp = pdf_lookup_dict(dict, "FontScale"); - if (!tmp || !PDF_OBJ_NUMBERTYPE(tmp)) { - return 0; - } - - return 1; -} - -static int -do_findfont (void) -{ - int error = 0; - pdf_obj *font_dict, *font_name; - - font_name = POP_STACK(); - if (!font_name) - return 1; - else if (PDF_OBJ_STRINGTYPE(font_name) || - PDF_OBJ_NAMETYPE(font_name)) { - /* Do not check the existence... - * The reason for this is that we cannot locate PK font without - * font scale. - */ - font_dict = pdf_new_dict(); - pdf_add_dict(font_dict, - pdf_new_name("Type"), pdf_new_name("Font")); - if (PDF_OBJ_STRINGTYPE(font_name)) { - pdf_add_dict(font_dict, - pdf_new_name("FontName"), - pdf_new_name(pdf_string_value(font_name))); - pdf_release_obj(font_name); - } else { - pdf_add_dict(font_dict, - pdf_new_name("FontName"), font_name); - } - pdf_add_dict(font_dict, - pdf_new_name("FontScale"), pdf_new_number(1.0)); - - if (top_stack < PS_STACK_SIZE) { - stack[top_stack++] = font_dict; - } else { - WARN("PS stack overflow including MetaPost file or inline PS code"); - pdf_release_obj(font_dict); - error = 1; - } - } else { - error = 1; - } - - return error; -} - -static int -do_scalefont (void) -{ - int error = 0; - pdf_obj *font_dict; - pdf_obj *font_scale; - double scale; - - error = pop_get_numbers(&scale, 1); - if (error) - return error; - - font_dict = POP_STACK(); - if (!font_dict) - error = 1; - else if (is_fontdict(font_dict)) { - font_scale = pdf_lookup_dict(font_dict, "FontScale"); - pdf_set_number(font_scale, pdf_number_value(font_scale)*scale); - if (top_stack < PS_STACK_SIZE) { - stack[top_stack++] = font_dict; - } else { - WARN("PS stack overflow including MetaPost file or inline PS code"); - pdf_release_obj(font_dict); - error = 1; - } - } else { - error = 1; - } - - return error; -} - -static int -do_setfont (void) -{ - int error = 0; - char *font_name; - double font_scale; - pdf_obj *font_dict; - - font_dict = POP_STACK(); - if (!is_fontdict(font_dict)) - error = 1; - else { - /* Subfont support prevent us from managing - * font in a single place... - */ - font_name = pdf_name_value (pdf_lookup_dict(font_dict, "FontName")); - font_scale = pdf_number_value(pdf_lookup_dict(font_dict, "FontScale")); - - error = mp_setfont(font_name, font_scale); - } - pdf_release_obj(font_dict); - - return error; -} - -/* Push dummy font dict onto PS stack */ -static int -do_currentfont (void) -{ - int error = 0; - struct mp_font *font; - pdf_obj *font_dict; - - font = CURRENT_FONT(); - if (!font) { - WARN("Currentfont undefined..."); - return 1; - } else { - font_dict = pdf_new_dict(); - pdf_add_dict(font_dict, - pdf_new_name("Type"), - pdf_new_name("Font")); - pdf_add_dict(font_dict, - pdf_new_name("FontName"), - pdf_new_name(font->font_name)); - pdf_add_dict(font_dict, - pdf_new_name("FontScale"), - pdf_new_number(font->pt_size)); - if (top_stack < PS_STACK_SIZE) { - stack[top_stack++] = font_dict; - } else { - WARN("PS stack overflow..."); - pdf_release_obj(font_dict); - error = 1; - } - } - - return error; -} - -static int -do_show (void) -{ - struct mp_font *font; - pdf_coord cp; - pdf_obj *text_str; - int length; - unsigned char *strptr; - double text_width; - - font = CURRENT_FONT(); - if (!font) { - WARN("Currentfont not set."); /* Should not be error... */ - return 1; - } - - pdf_dev_currentpoint(&cp); - - text_str = POP_STACK(); - if (!PDF_OBJ_STRINGTYPE(text_str)) { - if (text_str) - pdf_release_obj(text_str); - return 1; - } - if (font->font_id < 0) { - WARN("mpost: not set."); /* Should not be error... */ - pdf_release_obj(text_str); - return 1; - } - - strptr = pdf_string_value (text_str); - length = pdf_string_length(text_str); - - if (font->tfm_id < 0) { - WARN("mpost: TFM not found for \"%s\".", font->font_name); - WARN("mpost: Text width not calculated..."); - } - - text_width = 0.0; - if (font->subfont_id >= 0) { - unsigned short uch; - unsigned char *ustr; - int i; - - ustr = NEW(length * 2, unsigned char); - for (i = 0; i < length; i++) { - uch = lookup_sfd_record(font->subfont_id, strptr[i]); - ustr[2*i ] = uch >> 8; - ustr[2*i+1] = uch & 0xff; - if (font->tfm_id >= 0) { - text_width += tfm_get_width(font->tfm_id, strptr[i]); - } - } - text_width *= font->pt_size; - - pdf_dev_set_string((spt_t)(cp.x * dev_unit_dviunit()), - (spt_t)(cp.y * dev_unit_dviunit()), - ustr, length * 2, - (spt_t)(text_width*dev_unit_dviunit()), - font->font_id, 0); - RELEASE(ustr); - } else { -#define FWBASE ((double) (1<<20)) - if (font->tfm_id >= 0) { - text_width = (double) tfm_string_width(font->tfm_id, strptr, length)/FWBASE; - text_width *= font->pt_size; - } - pdf_dev_set_string((spt_t)(cp.x * dev_unit_dviunit()), - (spt_t)(cp.y * dev_unit_dviunit()), - strptr, length, - (spt_t)(text_width*dev_unit_dviunit()), - font->font_id, 0); - } - - if (pdf_dev_get_font_wmode(font->font_id)) { - pdf_dev_rmoveto(0.0, -text_width); - } else { - pdf_dev_rmoveto(text_width, 0.0); - } - - graphics_mode(); - pdf_release_obj(text_str); - - return 0; -} - -static int -do_mpost_bind_def (const char *ps_code, double x_user, double y_user) -{ - int error = 0; - const char *start, *end; - - start = ps_code; - end = start + strlen(start); - - error = mp_parse_body(&start, end, x_user, y_user); - - return error; -} - -static int -do_texfig_operator (int opcode, double x_user, double y_user) -{ - static transform_info fig_p; - static int in_tfig = 0; - static int xobj_id = -1; - static int count = 0; - double values[6]; - int error = 0; - - switch (opcode) { - case STEXFIG: - error = pop_get_numbers(values, 6); - if (!error) { - double dvi2pts; - char resname[256]; - - transform_info_clear(&fig_p); - dvi2pts = 1.0/dev_unit_dviunit(); - - fig_p.width = values[0] * dvi2pts; - fig_p.height = values[1] * dvi2pts; - fig_p.bbox.llx = values[2] * dvi2pts; - fig_p.bbox.lly = -values[3] * dvi2pts; - fig_p.bbox.urx = values[4] * dvi2pts; - fig_p.bbox.ury = -values[5] * dvi2pts; - fig_p.flags |= INFO_HAS_USER_BBOX; - - sprintf(resname, "__tf%d__", count); - xobj_id = pdf_doc_begin_grabbing(resname, - fig_p.bbox.llx, fig_p.bbox.ury, &fig_p.bbox); - - in_tfig = 1; - count++; - } - break; - case ETEXFIG: - if (!in_tfig) - ERROR("endTexFig without valid startTexFig!."); - - pdf_doc_end_grabbing(NULL); - pdf_dev_put_image(xobj_id, &fig_p, x_user, y_user); - in_tfig = 0; - break; - default: - error = 1; - } - - return error; -} - -/* - * buggy... - */ - -/* - * CTM(Current Transformation Matrix) means the transformation of User Space - * to Device Space coordinates. Because DVIPDFMx does not know the resolution - * of Device Space, we assume that the resolution is 1/1000. - */ -#define DEVICE_RESOLUTION 1000 -static int -ps_dev_CTM (pdf_tmatrix *M) -{ - pdf_dev_currentmatrix(M); - M->a *= DEVICE_RESOLUTION; M->b *= DEVICE_RESOLUTION; - M->c *= DEVICE_RESOLUTION; M->d *= DEVICE_RESOLUTION; - M->e *= DEVICE_RESOLUTION; M->f *= DEVICE_RESOLUTION; - - return 0; -} - -/* - * Again, the only piece that needs x_user and y_user is - * that piece dealing with texfig. - */ -static int -do_operator (const char *token, double x_user, double y_user) -{ - int error = 0; - int opcode = 0; - double values[12]; - pdf_obj *tmp = NULL; - pdf_tmatrix matrix; - pdf_coord cp; - pdf_color color; - -#define PUSH(o) { \ - if (top_stack < PS_STACK_SIZE) { \ - stack[top_stack++] = (o); \ - } else { \ - WARN("PS stack overflow including MetaPost file or inline PS code"); \ - error=1; \ - break;\ - } \ -} - - opcode = get_opcode(token); - - switch (opcode) { - - /* - * Arithmetic operators - */ - case ADD: - error = pop_get_numbers(values, 2); - if (!error) - PUSH(pdf_new_number(values[0] + values[1])); - break; - case MUL: - error = pop_get_numbers(values, 2); - if (!error) - PUSH(pdf_new_number(values[0]*values[1])); - break; - case NEG: - error = pop_get_numbers(values, 1); - if (!error) - PUSH(pdf_new_number(-values[0])); - break; - case SUB: - error = pop_get_numbers(values, 2); - if (!error) - PUSH(pdf_new_number(values[0] - values[1])); - break; - case DIV: - error = pop_get_numbers(values, 2); - if (!error) - PUSH(pdf_new_number(values[0]/values[1])); - break; - case TRUNCATE: /* Round toward zero. */ - error = pop_get_numbers(values, 1); - if (!error) - PUSH(pdf_new_number(((values[0] > 0) ? floor(values[0]) : ceil(values[0])))); - break; - - /* Stack operation */ - case CLEAR: - error = do_clear(); - break; - case POP: - tmp = POP_STACK(); - if (tmp) - pdf_release_obj(tmp); - break; - case EXCH: - error = do_exch(); - break; - - /* Path construction */ - case MOVETO: - error = pop_get_numbers(values, 2); - if (!error) - error = pdf_dev_moveto(values[0], values[1]); - break; - case RMOVETO: - error = pop_get_numbers(values, 2); - if (!error) - error = pdf_dev_rmoveto(values[0], values[1]); - break; - case LINETO: - error = pop_get_numbers(values, 2); - if (!error) - error = pdf_dev_lineto(values[0], values[1]); - break; - case RLINETO: - error = pop_get_numbers(values, 2); - if (!error) - error = pdf_dev_rlineto(values[0], values[1]); - break; - case CURVETO: - error = pop_get_numbers(values, 6); - if (!error) - error = pdf_dev_curveto(values[0], values[1], - values[2], values[3], - values[4], values[5]); - break; - case RCURVETO: - error = pop_get_numbers(values, 6); - if (!error) - error = pdf_dev_rcurveto(values[0], values[1], - values[2], values[3], - values[4], values[5]); - break; - case CLOSEPATH: - error = pdf_dev_closepath(); - break; - case ARC: - error = pop_get_numbers(values, 5); - if (!error) - error = pdf_dev_arc(values[0], values[1], - values[2], /* rad */ - values[3], values[4]); - break; - case ARCN: - error = pop_get_numbers(values, 5); - if (!error) - error = pdf_dev_arcn(values[0], values[1], - values[2], /* rad */ - values[3], values[4]); - break; - - case NEWPATH: - pdf_dev_newpath(); - break; - case STROKE: - /* fill rule not supported yet */ - pdf_dev_flushpath('S', PDF_FILL_RULE_NONZERO); - break; - case FILL: - pdf_dev_flushpath('f', PDF_FILL_RULE_NONZERO); - break; - - case CLIP: - error = pdf_dev_clip(); - break; - case EOCLIP: - error = pdf_dev_eoclip(); - break; - - /* Graphics state operators: */ - case GSAVE: - error = pdf_dev_gsave(); - save_font(); - break; - case GRESTORE: - error = pdf_dev_grestore(); - restore_font(); - break; - - case CONCAT: - tmp = POP_STACK(); - error = cvr_array(tmp, values, 6); /* This does pdf_release_obj() */ - tmp = NULL; - if (error) - WARN("Missing array before \"concat\"."); - else { - pdf_setmatrix(&matrix, - values[0], values[1], - values[2], values[3], - values[4], values[5]); - error = pdf_dev_concat(&matrix); - } - break; - case SCALE: - error = pop_get_numbers(values, 2); - if (!error) { - switch (mp_cmode) { -#ifndef WITHOUT_ASCII_PTEX - case MP_CMODE_PTEXVERT: - pdf_setmatrix(&matrix, - values[1], 0.0, - 0.0 , values[0], - 0.0 , 0.0); - break; -#endif /* !WITHOUT_ASCII_PTEX */ - default: - pdf_setmatrix(&matrix, - values[0], 0.0, - 0.0 , values[1], - 0.0 , 0.0); - break; - } - - error = pdf_dev_concat(&matrix); - } - break; - /* Positive angle means clock-wise direction in graphicx-dvips??? */ - case ROTATE: - error = pop_get_numbers(values, 1); - if (!error) { - values[0] = values[0] * M_PI / 180; - - switch (mp_cmode) { - case MP_CMODE_DVIPSK: - case MP_CMODE_MPOST: /* Really? */ -#ifndef WITHOUT_ASCII_PTEX - case MP_CMODE_PTEXVERT: -#endif /* !WITHOUT_ASCII_PTEX */ - pdf_setmatrix(&matrix, - cos(values[0]), -sin(values[0]), - sin(values[0]), cos(values[0]), - 0.0, 0.0); - break; - default: - pdf_setmatrix(&matrix, - cos(values[0]) , sin(values[0]), - -sin(values[0]), cos(values[0]), - 0.0, 0.0); - break; - } - error = pdf_dev_concat(&matrix); - } - break; - case TRANSLATE: - error = pop_get_numbers(values, 2); - if (!error) { - pdf_setmatrix(&matrix, - 1.0, 0.0, - 0.0, 1.0, - values[0], values[1]); - error = pdf_dev_concat(&matrix); - } - break; - - case SETDASH: - error = pop_get_numbers(values, 1); - if (!error) { - pdf_obj *pattern, *dash; - int i, num_dashes; - double dash_values[PDF_DASH_SIZE_MAX]; - double offset; - - offset = values[0]; - pattern = POP_STACK(); - if (!PDF_OBJ_ARRAYTYPE(pattern)) { - if (pattern) - pdf_release_obj(pattern); - error = 1; - break; - } - num_dashes = pdf_array_length(pattern); - if (num_dashes > PDF_DASH_SIZE_MAX) { - WARN("Too many dashes..."); - pdf_release_obj(pattern); - error = 1; - break; - } - for (i = 0; - i < num_dashes && !error ; i++) { - dash = pdf_get_array(pattern, i); - if (!PDF_OBJ_NUMBERTYPE(dash)) - error = 1; - else { - dash_values[i] = pdf_number_value(dash); - } - } - pdf_release_obj(pattern); - if (!error) { - error = pdf_dev_setdash(num_dashes, dash_values, offset); - } - } - break; - case SETLINECAP: - error = pop_get_numbers(values, 1); - if (!error) - error = pdf_dev_setlinecap((int)values[0]); - break; - case SETLINEJOIN: - error = pop_get_numbers(values, 1); - if (!error) - error = pdf_dev_setlinejoin((int)values[0]); - break; - case SETLINEWIDTH: - error = pop_get_numbers(values, 1); - if (!error) - error = pdf_dev_setlinewidth(values[0]); - break; - case SETMITERLIMIT: - error = pop_get_numbers(values, 1); - if (!error) - error = pdf_dev_setmiterlimit(values[0]); - break; - - case SETCMYKCOLOR: - error = pop_get_numbers(values, 4); - /* Not handled properly */ - if (!error) { - pdf_color_cmykcolor(&color, - values[0], values[1], - values[2], values[3]); - pdf_dev_set_strokingcolor(&color); - pdf_dev_set_nonstrokingcolor(&color); - } - break; - case SETGRAY: - /* Not handled properly */ - error = pop_get_numbers(values, 1); - if (!error) { - pdf_color_graycolor(&color, values[0]); - pdf_dev_set_strokingcolor(&color); - pdf_dev_set_nonstrokingcolor(&color); - } - break; - case SETRGBCOLOR: - error = pop_get_numbers(values, 3); - if (!error) { - pdf_color_rgbcolor(&color, - values[0], values[1], values[2]); - pdf_dev_set_strokingcolor(&color); - pdf_dev_set_nonstrokingcolor(&color); - } - break; - - case SHOWPAGE: /* Let's ignore this for now */ - break; - - case CURRENTPOINT: - error = pdf_dev_currentpoint(&cp); - if (!error) { - PUSH(pdf_new_number(cp.x)); - PUSH(pdf_new_number(cp.y)); - } - break; - - case DTRANSFORM: - { - int has_matrix = 0; - - tmp = POP_STACK(); - if (PDF_OBJ_ARRAYTYPE(tmp)) { - error = cvr_array(tmp, values, 6); /* This does pdf_release_obj() */ - tmp = NULL; - if (error) - break; - pdf_setmatrix(&matrix, - values[0], values[1], - values[2], values[3], - values[4], values[5]); - tmp = POP_STACK(); - has_matrix = 1; - } - - if (!PDF_OBJ_NUMBERTYPE(tmp)) { - error = 1; - break; - } - cp.y = pdf_number_value(tmp); - pdf_release_obj(tmp); - - tmp = POP_STACK(); - if (!PDF_OBJ_NUMBERTYPE(tmp)) { - error = 1; - break; - } - cp.x = pdf_number_value(tmp); - pdf_release_obj(tmp); - - if (!has_matrix) { - ps_dev_CTM(&matrix); /* Here, we need real PostScript CTM */ - } - pdf_dev_dtransform(&cp, &matrix); - PUSH(pdf_new_number(cp.x)); - PUSH(pdf_new_number(cp.y)); - } - break; - - case IDTRANSFORM: - { - int has_matrix = 0; - - tmp = POP_STACK(); - if (PDF_OBJ_ARRAYTYPE(tmp)) { - error = cvr_array(tmp, values, 6); /* This does pdf_release_obj() */ - tmp = NULL; - if (error) - break; - pdf_setmatrix(&matrix, - values[0], values[1], - values[2], values[3], - values[4], values[5]); - tmp = POP_STACK(); - has_matrix = 1; - } - - if (!PDF_OBJ_NUMBERTYPE(tmp)) { - error = 1; - break; - } - cp.y = pdf_number_value(tmp); - pdf_release_obj(tmp); - - tmp = POP_STACK(); - if (!PDF_OBJ_NUMBERTYPE(tmp)) { - error = 1; - break; - } - cp.x = pdf_number_value(tmp); - pdf_release_obj(tmp); - - if (!has_matrix) { - ps_dev_CTM(&matrix); /* Here, we need real PostScript CTM */ - } - pdf_dev_idtransform(&cp, &matrix); - PUSH(pdf_new_number(cp.x)); - PUSH(pdf_new_number(cp.y)); - break; - } - - case FINDFONT: - error = do_findfont(); - break; - case SCALEFONT: - error = do_scalefont(); - break; - case SETFONT: - error = do_setfont(); - break; - case CURRENTFONT: - error = do_currentfont(); - break; - - case SHOW: - error = do_show(); - break; - - case STRINGWIDTH: - error = 1; - break; - - /* Extensions */ - case FSHOW: - error = do_mpost_bind_def("exch findfont exch scalefont setfont show", x_user, y_user); - break; - case STEXFIG: - case ETEXFIG: - error = do_texfig_operator(opcode, x_user, y_user); - break; - case HLW: - error = do_mpost_bind_def("0 dtransform exch truncate exch idtransform pop setlinewidth", x_user, y_user); - break; - case VLW: - error = do_mpost_bind_def("0 exch dtransform truncate idtransform setlinewidth pop", x_user, y_user); - break; - case RD: - error = do_mpost_bind_def("[] 0 setdash", x_user, y_user); - break; - case B: - error = do_mpost_bind_def("gsave fill grestore", x_user, y_user); - break; - - case DEF: - tmp = POP_STACK(); - tmp = POP_STACK(); - /* do nothing; not implemented yet */ - break; - - default: - if (is_fontname(token)) { - PUSH(pdf_new_name(token)); - } else { - WARN("Unknown token \"%s\"", token); - error = 1; - } - break; - } - - return error; -} - -/* - * The only sections that need to know x_user and y _user are those - * dealing with texfig. - */ -static int -mp_parse_body (const char **start, const char *end, double x_user, double y_user) -{ - char *token; - pdf_obj *obj; - int error = 0; - - skip_white(start, end); - while (*start < end && !error) { - if (isdigit(**start) || - (*start < end - 1 && - (**start == '+' || **start == '-' || **start == '.' ))) { - double value; - char *next; - - value = strtod(*start, &next); - if (next < end && !strchr("<([{/%", *next) && !isspace(*next)) { - WARN("Unkown PostScript operator."); - dump(*start, next); - error = 1; - } else { - PUSH(pdf_new_number(value)); - *start = next; - } - /* - * PDF parser can't handle PS operator inside arrays. - * This shouldn't use parse_pdf_array(). - */ - } else if (**start == '[' && - (obj = parse_pdf_array(start, end, NULL))) { - PUSH(obj); - /* This cannot handle ASCII85 string. */ - } else if (*start < end - 1 && - (**start == '<' && *(*start+1) == '<') && - (obj = parse_pdf_dict(start, end, NULL))) { - PUSH(obj); - } else if ((**start == '(' || **start == '<') && - (obj = parse_pdf_string (start, end))) { - PUSH(obj); - } else if (**start == '/' && - (obj = parse_pdf_name(start, end))) { - PUSH(obj); - } else { - token = parse_ident(start, end); - if (!token) - error = 1; - else { - error = do_operator(token, x_user, y_user); - RELEASE(token); - } - } - skip_white(start, end); - } - - return error; -} - -void -mps_eop_cleanup (void) -{ - clear_fonts(); - do_clear(); -} - -int -mps_stack_depth (void) -{ - return top_stack; -} - -int -mps_exec_inline (const char **p, const char *endptr, - double x_user, double y_user) -{ - int error; - int dirmode, autorotate; - - /* Compatibility for dvipsk. */ - dirmode = pdf_dev_get_dirmode(); - if (dirmode) { - mp_cmode = MP_CMODE_PTEXVERT; - } else { - mp_cmode = MP_CMODE_DVIPSK; - } - - autorotate = pdf_dev_get_param(PDF_DEV_PARAM_AUTOROTATE); - pdf_dev_set_param(PDF_DEV_PARAM_AUTOROTATE, 0); - //pdf_color_push(); /* ... */ - - /* Comment in dvipdfm: - * Remember that x_user and y_user are off by 0.02 % - */ - pdf_dev_moveto(x_user, y_user); - error = mp_parse_body(p, endptr, x_user, y_user); - - //pdf_color_pop(); /* ... */ - pdf_dev_set_param(PDF_DEV_PARAM_AUTOROTATE, autorotate); - pdf_dev_set_dirmode(dirmode); - - return error; -} - -/* mp inclusion is a bit of a hack. The routine - * starts a form at the lower left corner of - * the page and then calls begin_form_xobj telling - * it to record the image drawn there and bundle it - * up in an xojbect. This allows us to use the coordinates - * in the MP file directly. This appears to be the - * easiest way to be able to use the pdf_dev_set_string() - * command (with its scaled and extended fonts) without - * getting all confused about the coordinate system. - * After the xobject is created, the whole thing can - * be scaled any way the user wants - */ - -/* Should implement save and restore. */ -int -mps_include_page (const char *ident, FILE *fp) -{ - int form_id; - xform_info info; - int st_depth, gs_depth; - char *buffer; - const char *p, *endptr; - long length, nb_read; - int dirmode, autorotate, error; - - rewind(fp); - - length = file_size(fp); - if (length < 1) { - WARN("Can't read any byte in the MPS file."); - return -1; - } - - buffer = NEW(length + 1, char); - buffer[length] = '\0'; - p = buffer; - endptr = p + length; - - while (length > 0) { - nb_read = fread(buffer, sizeof(char), length, fp); - if (nb_read < 0) { - RELEASE(buffer); - WARN("Reading file failed..."); - return -1; - } - length -= nb_read; - } - - error = mps_scan_bbox(&p, endptr, &(info.bbox)); - if (error) { - WARN("Error occured while scanning MetaPost file headers: Could not find BoundingBox."); - RELEASE(buffer); - return -1; - } - skip_prolog(&p, endptr); - - dirmode = pdf_dev_get_dirmode(); - autorotate = pdf_dev_get_param(PDF_DEV_PARAM_AUTOROTATE); - pdf_dev_set_param(PDF_DEV_PARAM_AUTOROTATE, 0); - //pdf_color_push(); - - form_id = pdf_doc_begin_grabbing(ident, 0.0, 0.0, &(info.bbox)); - - mp_cmode = MP_CMODE_MPOST; - gs_depth = pdf_dev_current_depth(); - st_depth = mps_stack_depth(); - /* At this point the gstate must be initialized, since it starts a new - * XObject. Note that it increase gs_depth by 1. */ - pdf_dev_push_gstate(); - - error = mp_parse_body(&p, endptr, 0.0, 0.0); - RELEASE(buffer); - - if (error) { - WARN("Errors occured while interpreting MPS file."); - /* WARN("Leaving garbage in output PDF file."); */ - form_id = -1; - } - - /* It's time to pop the new gstate above. */ - pdf_dev_pop_gstate(); - mps_stack_clear_to (st_depth); - pdf_dev_grestore_to(gs_depth); - - pdf_doc_end_grabbing(NULL); - - //pdf_color_pop(); - pdf_dev_set_param(PDF_DEV_PARAM_AUTOROTATE, autorotate); - pdf_dev_set_dirmode(dirmode); - - return form_id; -} - -int -mps_do_page (FILE *image_file) -{ - int error = 0; - pdf_rect bbox; - char *buffer; - const char *start, *end; - long size; - int dir_mode; - - rewind(image_file); - if ((size = file_size(image_file)) == 0) { - WARN("Can't read any byte in the MPS file."); - return -1; - } - - buffer = NEW(size+1, char); - fread(buffer, sizeof(char), size, image_file); - buffer[size] = 0; - start = buffer; - end = buffer + size; - - error = mps_scan_bbox(&start, end, &bbox); - if (error) { - WARN("Error occured while scanning MetaPost file headers: Could not find BoundingBox."); - RELEASE(buffer); - return -1; - } - - mp_cmode = MP_CMODE_MPOST; - - pdf_doc_begin_page (1.0, 0.0, 0.0); /* scale, xorig, yorig */ - pdf_doc_set_mediabox(pdf_doc_current_page_number(), &bbox); - - dir_mode = pdf_dev_get_dirmode(); - pdf_dev_set_autorotate(0); - - skip_prolog(&start, end); - - error = mp_parse_body(&start, end, 0.0, 0.0); - - if (error) { - WARN("Errors occured while interpreting MetaPost file."); - } - - pdf_dev_set_autorotate(1); - pdf_dev_set_dirmode(dir_mode); - - pdf_doc_end_page(); - - RELEASE(buffer); - - /* - * The reason why we don't return XObject itself is - * PDF inclusion may not be made so. - */ - return (error ? -1 : 0); -} - -int -check_for_mp (FILE *image_file) -{ - int try_count = 10; - - rewind (image_file); - mfgets(work_buffer, WORK_BUFFER_SIZE, image_file); - if (strncmp(work_buffer, "%!PS", 4)) - return 0; - - while (try_count > 0) { - mfgets(work_buffer, WORK_BUFFER_SIZE, image_file); - if (!strncmp(work_buffer, "%%Creator:", 10)) { - if (strlen(work_buffer+10) >= 8 && - strstr(work_buffer+10, "MetaPost")) - break; - } - try_count--; - } - - return ((try_count > 0) ? 1 : 0); -} diff --git a/Build/source/texk/dvipdfm-x/src/pdfdev.h b/Build/source/texk/dvipdfm-x/src/pdfdev.h deleted file mode 100644 index 6b3d5bb65e8..00000000000 --- a/Build/source/texk/dvipdfm-x/src/pdfdev.h +++ /dev/null @@ -1,228 +0,0 @@ -/* - - This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - - Copyright (C) 2002-2012 by Jin-Hwan Cho and Shunsaku Hirata, - the dvipdfmx project team. - - Copyright (C) 1998, 1999 by Mark A. Wicks - - This program 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; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -*/ - -#ifndef _PDFDEV_H_ -#define _PDFDEV_H_ - -#include "numbers.h" -#include "pdfobj.h" -#include "pdfcolor.h" - -typedef signed long spt_t; - -typedef struct pdf_tmatrix -{ - double a, b, c, d, e, f; -} pdf_tmatrix; - -typedef struct pdf_rect -{ - double llx, lly, urx, ury; -} pdf_rect; - -typedef struct pdf_coord -{ - double x, y; -} pdf_coord; - -/* The name transform_info is misleading. - * I'll put this here for a moment... - */ -typedef struct -{ - /* Physical dimensions - * - * If those values are given, images will be scaled - * and/or shifted to fit within a box described by - * those values. - */ - double width; - double height; - double depth; - - pdf_tmatrix matrix; /* transform matrix */ - pdf_rect bbox; /* user_bbox */ - - int flags; -} transform_info; -#define INFO_HAS_USER_BBOX (1 << 0) -#define INFO_HAS_WIDTH (1 << 1) -#define INFO_HAS_HEIGHT (1 << 2) -#define INFO_DO_CLIP (1 << 3) -#define INFO_DO_HIDE (1 << 4) -extern void transform_info_clear (transform_info *info); - - -extern void pdf_dev_set_verbose (void); - -/* Not in spt_t. */ -extern int pdf_sprint_matrix (char *buf, const pdf_tmatrix *p); -extern int pdf_sprint_rect (char *buf, const pdf_rect *p); -extern int pdf_sprint_coord (char *buf, const pdf_coord *p); -extern int pdf_sprint_length (char *buf, double value); -extern int pdf_sprint_number (char *buf, double value); - -/* unit_conv: multiplier for input unit (spt_t) to bp conversion. - * precision: How many fractional digits preserved in output (not real - * accuracy control). - * is_bw: Ignore color related special instructions. - */ -extern void pdf_init_device (double unit_conv, int precision, int is_bw); -extern void pdf_close_device (void); - -/* returns 1.0/unit_conv */ -extern double dev_unit_dviunit (void); - -#if 0 -/* DVI interpreter knows text positioning in relative motion. - * However, pdf_dev_set_string() recieves text string with placement - * in absolute position in user space, and it convert absolute - * positioning back to relative positioning. It is quite wasteful. - * - * TeX using DVI register stack operation to do CR and then use down - * command for LF. DVI interpreter knows hint for current leading - * and others (raised or lowered), but they are mostly lost in - * pdf_dev_set_string(). - */ - -typedef struct -{ - int argc; - - struct { - int is_kern; /* kern or string */ - - spt_t kern; /* negative kern means space */ - - int offset; /* offset to sbuf */ - int length; /* length of string */ - } args[]; - - unsigned char sbuf[PDF_STRING_LEN_MAX]; - -} pdf_text_string; - -/* Something for handling raise, leading, etc. here. */ - -#endif - -/* Draw texts and rules: - * - * xpos, ypos, width, and height are all fixed-point numbers - * converted to big-points by multiplying unit_conv (dvi2pts). - * They must be position in the user space. - * - * ctype: - * 0 - input string is in multi-byte encoding. - * 1 - input string is in 8-bit encoding. - * 2 - input string is in 16-bit encoding. - */ -extern void pdf_dev_set_string (spt_t xpos, spt_t ypos, - const void *instr_ptr, int instr_len, - spt_t text_width, - int font_id, int ctype); -extern void pdf_dev_set_rule (spt_t xpos, spt_t ypos, - spt_t width, spt_t height); - -/* Place XObject */ -extern int pdf_dev_put_image (int xobj_id, - transform_info *p, double ref_x, double ref_y); - -/* The design_size and ptsize required by PK font support... - */ -extern int pdf_dev_locate_font (const char *font_name, spt_t ptsize); - -extern int pdf_dev_setfont (const char *font_name, spt_t ptsize); - -/* The following two routines are NOT WORKING. - * Dvipdfmx doesn't manage gstate well.. - */ -#ifdef XETEX -/* pdf_dev_translate() or pdf_dev_concat() should be used. */ -extern void pdf_dev_set_origin (double orig_x, double orig_y); -#endif -/* Always returns 1.0, please rename this. */ -extern double pdf_dev_scale (void); - -/* Access text state parameters. */ -#if 0 -extern int pdf_dev_currentfont (void); /* returns font_id */ -extern double pdf_dev_get_font_ptsize (int font_id); -#endif -extern int pdf_dev_get_font_wmode (int font_id); /* ps: special support want this (pTeX). */ - -/* Text composition (direction) mode - * This affects only when auto_rotate is enabled. - */ -extern int pdf_dev_get_dirmode (void); -extern void pdf_dev_set_dirmode (int dir_mode); - -/* Set rect to rectangle in device space. - * Unit conversion spt_t to bp and transformation applied within it. - */ -extern void pdf_dev_set_rect (pdf_rect *rect, - spt_t x_pos, spt_t y_pos, - spt_t width, spt_t height, spt_t depth); - -/* Accessor to various device parameters. - */ -#define PDF_DEV_PARAM_AUTOROTATE 1 -#define PDF_DEV_PARAM_COLORMODE 2 - -extern int pdf_dev_get_param (int param_type); -extern void pdf_dev_set_param (int param_type, int value); - -/* Text composition mode is ignored (always same as font's - * writing mode) and glyph rotation is not enabled if - * auto_rotate is unset. - */ -#define pdf_dev_set_autorotate(v) pdf_dev_set_param(PDF_DEV_PARAM_AUTOROTATE, (v)) -#define pdf_dev_set_colormode(v) pdf_dev_set_param(PDF_DEV_PARAM_COLORMODE, (v)) - -/* - * For pdf_doc, pdf_draw and others. - */ - -/* Force reselecting font: - * XFrom (content grabbing) and Metapost support want them. - */ -extern void pdf_dev_reset_fonts (void); - -/* Initialization of transformation matrix with M and others. - * They are called within pdf_doc_begin_page() and pdf_doc_end_page(). - */ -extern void pdf_dev_bop (const pdf_tmatrix *M); -extern void pdf_dev_eop (void); - -/* Text is normal and line art is not normal in dvipdfmx. So we don't have - * begin_text (BT in PDF) and end_text (ET), but instead we have graphics_mode() - * to terminate text section. pdf_dev_flushpath() and others call this. - */ -extern void graphics_mode (void); - -extern void pdf_dev_get_coord(double *xpos, double *ypos); -extern void pdf_dev_push_coord(double xpos, double ypos); -extern void pdf_dev_pop_coord(void); - -#endif /* _PDFDEV_H_ */ diff --git a/Build/source/texk/dvipdfm-x/src/pdfdoc.h b/Build/source/texk/dvipdfm-x/src/pdfdoc.h deleted file mode 100644 index 2281f036fd2..00000000000 --- a/Build/source/texk/dvipdfm-x/src/pdfdoc.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - - This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - - Copyright (C) 2007-2012 by Jin-Hwan Cho and Shunsaku Hirata, - the dvipdfmx project team. - - Copyright (C) 1998, 1999 by Mark A. Wicks - - This program 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; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -*/ - -#ifndef _PDFDOC_H_ -#define _PDFDOC_H_ - -#include "pdfobj.h" -#include "pdfdev.h" - -#define PDF_DOC_GRABBING_NEST_MAX 4 - -extern void pdf_doc_set_verbose (void); - -extern void pdf_open_document (const char *filename, - int do_encryption, - double media_width, double media_height, - double annot_grow_amount, int bookmark_open_depth, - int check_gotos); -extern void pdf_close_document (void); - - -/* PDF document metadata */ -extern void pdf_doc_set_creator (const char *creator); - - -/* They just return PDF dictionary object. - * Callers are completely responsible for doing right thing... - */ -extern pdf_obj *pdf_doc_get_dictionary (const char *category); -extern pdf_obj *pdf_doc_get_reference (const char *category); - -#define pdf_doc_page_tree() pdf_doc_get_dictionary("Pages") -#define pdf_doc_catalog() pdf_doc_get_dictionary("Catalog") -#define pdf_doc_docinfo() pdf_doc_get_dictionary("Info") -#define pdf_doc_names() pdf_doc_get_dictionary("Names") -#define pdf_doc_this_page() pdf_doc_get_dictionary("@THISPAGE") - -extern pdf_obj *pdf_doc_get_page (pdf_file *pf, long page_no, long *count_p, - pdf_rect *bbox, pdf_obj **resources_p); - -extern long pdf_doc_current_page_number (void); -extern pdf_obj *pdf_doc_current_page_resources (void); - -extern pdf_obj *pdf_doc_ref_page (unsigned long page_no); -#define pdf_doc_this_page_ref() pdf_doc_get_reference("@THISPAGE") -#define pdf_doc_next_page_ref() pdf_doc_get_reference("@NEXTPAGE") -#define pdf_doc_prev_page_ref() pdf_doc_get_reference("@PREVPAGE") - -/* Not really managing tree... - * There should be something for number tree. - */ -extern int pdf_doc_add_names (const char *category, - const void *key, int keylen, pdf_obj *value); - -extern void pdf_doc_set_bop_content (const char *str, unsigned length); -extern void pdf_doc_set_eop_content (const char *str, unsigned length); - -/* Page */ -extern void pdf_doc_begin_page (double scale, double x_origin, double y_origin); -extern void pdf_doc_end_page (void); - -extern void pdf_doc_set_mediabox (unsigned page_no, const pdf_rect *mediabox); -extern void pdf_doc_get_mediabox (unsigned page_no, pdf_rect *mediabox); - -extern void pdf_doc_add_page_content (const char *buffer, unsigned length); -extern void pdf_doc_add_page_resource (const char *category, - const char *resource_name, pdf_obj *resources); - -/* Article thread */ -extern void pdf_doc_begin_article (const char *article_id, pdf_obj *info); -#if 0 -extern void pdf_doc_end_article (const char *article_id); /* Do nothing... */ -#endif -extern void pdf_doc_make_article (const char *article_id, - const char **bead_order, int num_beads); -extern void pdf_doc_add_bead (const char *article_id, - const char *bead_id, - long page_no, const pdf_rect *rect); - -/* Bookmarks */ -extern int pdf_doc_bookmarks_up (void); -extern int pdf_doc_bookmarks_down (void); -extern void pdf_doc_bookmarks_add (pdf_obj *dict, int is_open); -extern int pdf_doc_bookmarks_depth (void); - - -/* Returns xobj_id of started xform. */ -extern int pdf_doc_begin_grabbing (const char *ident, - double ref_x, double ref_y, - const pdf_rect *cropbox); -extern void pdf_doc_end_grabbing (pdf_obj *attrib); - - -/* Annotation */ -extern void pdf_doc_add_annot (unsigned page_no, - const pdf_rect *rect, - pdf_obj *annot_dict, - int dest_is_new); - -/* Annotation with auto- clip and line (or page) break */ -extern void pdf_doc_begin_annot (pdf_obj *dict); -extern void pdf_doc_end_annot (void); - -extern void pdf_doc_break_annot (void); -extern void pdf_doc_expand_box (const pdf_rect *rect); - -/* Manual thumbnail */ -extern void pdf_doc_enable_manual_thumbnails (void); - -#if 0 -/* PageLabels - */ -extern void pdf_doc_set_pagelabel (long page_start, - const char *type, - const void *prefix, int pfrx_len, - long counter_start); -#endif - -/* Similar to bop_content */ -#include "pdfcolor.h" -extern void pdf_doc_set_bgcolor (const pdf_color *color); - -#endif /* _PDFDOC_H_ */ diff --git a/Build/source/texk/dvipdfm-x/src/pdfdraw.h b/Build/source/texk/dvipdfm-x/src/pdfdraw.h deleted file mode 100644 index a2b8638a742..00000000000 --- a/Build/source/texk/dvipdfm-x/src/pdfdraw.h +++ /dev/null @@ -1,167 +0,0 @@ -/* - - This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - - Copyright (C) 2002-2012 by Jin-Hwan Cho and Shunsaku Hirata, - the dvipdfmx project team. - - Copyright (C) 1998, 1999 by Mark A. Wicks - - This program 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; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -*/ - -#ifndef _PDF_DRAW_H_ -#define _PDF_DRAW_H_ - -#include "pdfcolor.h" -#include "pdfdev.h" - -#define PDF_DASH_SIZE_MAX 16 -#define PDF_GSAVE_MAX 256 - -extern void pdf_dev_init_gstates (void); -extern void pdf_dev_clear_gstates (void); - -#define pdf_copymatrix(m,n) do {\ - (m)->a = (n)->a; (m)->b = (n)->b;\ - (m)->c = (n)->c; (m)->d = (n)->d;\ - (m)->e = (n)->e; (m)->f = (n)->f;\ -} while (0) - -#define pdf_setmatrix(m,p,q,r,s,t,u) do {\ - (m)->a = (p); (m)->b = (q);\ - (m)->c = (r); (m)->d = (s);\ - (m)->e = (t); (m)->f = (u);\ -} while (0) - -/* m -> n x m */ -#define pdf_concatmatrix(m,n) do {\ - double _tmp_a, _tmp_b, _tmp_c, _tmp_d; \ - _tmp_a = (m)->a; _tmp_b = (m)->b; \ - _tmp_c = (m)->c; _tmp_d = (m)->d; \ - (m)->a = ((n)->a) * _tmp_a + ((n)->b) * _tmp_c; \ - (m)->b = ((n)->a) * _tmp_b + ((n)->b) * _tmp_d; \ - (m)->c = ((n)->c) * _tmp_a + ((n)->d) * _tmp_c; \ - (m)->d = ((n)->c) * _tmp_b + ((n)->d) * _tmp_d; \ - (m)->e += ((n)->e) * _tmp_a + ((n)->f) * _tmp_c; \ - (m)->f += ((n)->e) * _tmp_b + ((n)->f) * _tmp_d; \ -} while (0) - -typedef struct pdf_path_ pdf_path; - -extern int pdf_dev_currentmatrix (pdf_tmatrix *M); -extern int pdf_dev_currentpoint (pdf_coord *cp); - -extern int pdf_dev_setlinewidth (double width); -extern int pdf_dev_setmiterlimit (double mlimit); -extern int pdf_dev_setlinecap (int style); -extern int pdf_dev_setlinejoin (int style); -extern int pdf_dev_setdash (int count, - double *pattern, - double offset); -#if 0 -extern int pdf_dev_setflat (int flatness); -#endif - -/* Path Construction */ -extern int pdf_dev_moveto (double x , double y); -extern int pdf_dev_rmoveto (double x , double y); -extern int pdf_dev_closepath (void); - -extern int pdf_dev_lineto (double x0 , double y0); -extern int pdf_dev_rlineto (double x0 , double y0); -extern int pdf_dev_curveto (double x0 , double y0, - double x1 , double y1, - double x2 , double y2); -extern int pdf_dev_rcurveto (double x0 , double y0, - double x1 , double y1, - double x2 , double y2); -extern int pdf_dev_arc (double c_x, double c_y, double r, - double a_0, double a_1); -extern int pdf_dev_arcn (double c_x, double c_y, double r, - double a_0, double a_1); - -#define PDF_FILL_RULE_NONZERO 0 -#define PDF_FILL_RULE_EVENODD 1 - -extern int pdf_dev_newpath (void); - -/* Path Painting */ -extern int pdf_dev_clip (void); -extern int pdf_dev_eoclip (void); - - -#if 0 -extern int pdf_dev_rectstroke (double x, double y, - double w, double h, - const pdf_tmatrix *M /* optional */ - ); -#endif -extern int pdf_dev_rectfill (double x, double y, double w, double h); -extern int pdf_dev_rectclip (double x, double y, double w, double h); - -extern int pdf_dev_flushpath (char p_op, int fill_rule); - -#define pdf_dev_fill() pdf_dev_flushpath('f', PDF_FILL_RULE_NONZERO) -#define pdf_dev_eofill() pdf_dev_flushpath('f', PDF_FILL_RULE_EVENODD) -#define pdf_dev_stroke() pdf_dev_flushpath('S', PDF_FILL_RULE_NONZERO) -#define pdf_dev_fillstroke() pdf_dev_flushpath('B', PDF_FILL_RULE_NONZERO) - -extern int pdf_dev_concat (const pdf_tmatrix *M); -/* NULL pointer of M mean apply current transformation */ -extern void pdf_dev_dtransform (pdf_coord *p, const pdf_tmatrix *M); -extern void pdf_dev_idtransform (pdf_coord *p, const pdf_tmatrix *M); -extern void pdf_dev_transform (pdf_coord *p, const pdf_tmatrix *M); -#if 0 -extern void pdf_dev_itransform (pdf_coord *p, const pdf_tmatrix *M); -#endif - -extern int pdf_dev_gsave (void); -extern int pdf_dev_grestore (void); - -/* Requires from mpost.c because new MetaPost graphics must initialize - * the current gstate. */ -extern int pdf_dev_push_gstate (void); -extern int pdf_dev_pop_gstate (void); - - -/* extension */ -extern int pdf_dev_arcx (double c_x, double c_y, - double r_x, double r_y, - double a_0, double a_1, - int a_d, /* arc direction */ - double xar /* x-axis-rotation */ - ); -extern int pdf_dev_bspline (double x0, double y0, - double x1, double y1, - double x2, double y2); - - -extern void pdf_invertmatrix (pdf_tmatrix *M); - -/* The depth here is the depth of q/Q nesting. - * We must remember current depth of nesting when starting a page or xform, - * and must recover until that depth at the end of page/xform. - */ -extern int pdf_dev_current_depth (void); -extern void pdf_dev_grestore_to (int depth); -#define pdf_dev_grestoreall() pdf_dev_grestore_to(0); - -extern void pdf_dev_set_color (const pdf_color *color, char mask, int force); -#define pdf_dev_set_strokingcolor(c) pdf_dev_set_color(c, 0, 0); -#define pdf_dev_set_nonstrokingcolor(c) pdf_dev_set_color(c, 0x20, 0); -extern void pdf_dev_reset_color (int force); - -#endif /* _PDF_DRAW_H_ */ diff --git a/Build/source/texk/dvipdfm-x/src/xbb.c b/Build/source/texk/dvipdfm-x/src/xbb.c index c074ef40cff..f11640e6b17 100644 --- a/Build/source/texk/dvipdfm-x/src/xbb.c +++ b/Build/source/texk/dvipdfm-x/src/xbb.c @@ -54,28 +54,29 @@ static void show_version(void) { if (really_quiet) return; - fprintf(stdout, "%s, version %s, Copyright (C) 2009 by Jin-Hwan Cho and Matthias Franz\n", XBB_PROGRAM, XBB_VERSION); - fprintf(stdout, "A bounding box extraction utility from PDF, PNG, and JPEG.\n"); - fprintf(stdout, "\nThis is free software; you can redistribute it and/or modify\n"); - fprintf(stdout, "it under the terms of the GNU General Public License as published by\n"); - fprintf(stdout, "the Free Software Foundation; either version 2 of the License, or\n"); - fprintf(stdout, "(at your option) any later version.\n"); + fprintf (stdout, "%s, version %s, Copyright (C) 2009 by Jin-Hwan Cho and Matthias Franz\n", + XBB_PROGRAM, XBB_VERSION); + fprintf (stdout, "A bounding box extraction utility from PDF, PNG, and JPEG.\n"); + fprintf (stdout, "\nThis is free software; you can redistribute it and/or modify\n"); + fprintf (stdout, "it under the terms of the GNU General Public License as published by\n"); + fprintf (stdout, "the Free Software Foundation; either version 2 of the License, or\n"); + fprintf (stdout, "(at your option) any later version.\n"); } static void show_usage(void) { if (really_quiet) return; - fprintf(stdout, "\nUsage: %s [-v|-q] [-O] [-m|-x] [files]\n", XBB_PROGRAM); - fprintf(stdout, "\t-v\tBe verbose\n"); - fprintf(stdout, "\t-q\tBe quiet\n"); - fprintf(stdout, "\t-O\tWrite output to stdout\n"); + fprintf (stdout, "\nUsage: %s [-v|-q] [-O] [-m|-x] [files]\n", XBB_PROGRAM); + fprintf (stdout, "\t-v\tBe verbose\n"); + fprintf (stdout, "\t-q\tBe quiet\n"); + fprintf (stdout, "\t-O\tWrite output to stdout\n"); if(compat_mode) { - fprintf(stdout, "\t-m\tOutput .bb file used in DVIPDFM (default)\n"); - fprintf(stdout, "\t-x\tOutput .xbb file used in DVIPDFMx\n"); + fprintf (stdout, "\t-m\tOutput .bb file used in DVIPDFM (default)\n"); + fprintf (stdout, "\t-x\tOutput .xbb file used in DVIPDFMx\n"); } else { - fprintf(stdout, "\t-m\tOutput .bb file used in DVIPDFM\n"); - fprintf(stdout, "\t-x\tOutput .xbb file used in DVIPDFMx (default)\n"); + fprintf (stdout, "\t-m\tOutput .bb file used in DVIPDFM\n"); + fprintf (stdout, "\t-x\tOutput .xbb file used in DVIPDFMx (default)\n"); } } @@ -244,6 +245,8 @@ static void do_pdf (FILE *fp, char *filename) int extractbb (int argc, char *argv[], int mode) { + compat_mode = (mode == EBB_OUTPUT); + pdf_files_init(); pdf_set_version(5); diff --git a/Build/source/texk/dvipdfm-x/xsrc/cff.c b/Build/source/texk/dvipdfm-x/xsrc/cff.c deleted file mode 100644 index 082d3d873e9..00000000000 --- a/Build/source/texk/dvipdfm-x/xsrc/cff.c +++ /dev/null @@ -1,1501 +0,0 @@ -/* - - This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - - Copyright (C) 2002-2012 by Jin-Hwan Cho and Shunsaku Hirata, - the dvipdfmx project team. - - This program 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; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -*/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -#include "system.h" -#include "mem.h" -#include "error.h" -#include "mfileio.h" - -#include "cff_limits.h" -#include "cff_types.h" -#include "cff_stdstr.h" -#include "cff_dict.h" - -#include "cff.h" - -#define CFF_DEBUG 5 -#define CFF_DEBUG_STR "CFF" - -#ifdef XETEX -#define SFNT_OR_FILE sfnt -#define SFONT_OR_STREAM sfont -#define get_card8(s) sfnt_get_byte((s)) -#define get_card16(s) sfnt_get_ushort((s)) -#else -#define SFNT_OR_FILE FILE -#define SFONT_OR_STREAM stream -#define get_card8(s) get_unsigned_byte((s)) -#define get_card16(s) get_unsigned_pair((s)) -#endif - -static unsigned long get_unsigned (SFNT_OR_FILE *SFONT_OR_STREAM, int n) -{ - unsigned long v = 0; - - while (n-- > 0) - v = v*0x100u + get_card8(SFONT_OR_STREAM); - - return v; -} - -#define get_offset(s, n) get_unsigned((s), (n)) - -/* - * Read Header, Name INDEX, Top DICT INDEX, and String INDEX. - */ -cff_font *cff_open(SFNT_OR_FILE *SFONT_OR_STREAM, long offset, int n) -{ - cff_font *cff; - cff_index *idx; - - cff = NEW(1, cff_font); - - cff->fontname = NULL; - cff->index = n; - cff->SFONT_OR_STREAM = SFONT_OR_STREAM; - cff->offset = offset; - cff->filter = 0; /* not used */ - cff->flag = 0; - - cff->name = NULL; - cff->gsubr = NULL; - cff->encoding = NULL; - cff->charsets = NULL; - cff->fdselect = NULL; - cff->cstrings = NULL; - cff->fdarray = NULL; - cff->private = NULL; - cff->subrs = NULL; - - cff->num_glyphs = 0; - cff->num_fds = 0; - cff->_string = NULL; - - cff_seek_set(cff, 0); - cff->header.major = get_card8(cff->SFONT_OR_STREAM); - cff->header.minor = get_card8(cff->SFONT_OR_STREAM); - cff->header.hdr_size = get_card8(cff->SFONT_OR_STREAM); - cff->header.offsize = get_card8(cff->SFONT_OR_STREAM); - if (cff->header.offsize < 1 || - cff->header.offsize > 4) - ERROR("invalid offsize data"); - - if (cff->header.major > 1 || - cff->header.minor > 0) { - WARN("%s: CFF version %u.%u not supported.", - CFF_DEBUG_STR, cff->header.major, cff->header.minor); - cff_close(cff); - return NULL; - } - - cff_seek_set(cff, (cff->header).hdr_size); - - /* Name INDEX */ - idx = cff_get_index(cff); - if (n > idx->count - 1) { - WARN("%s: Invalid CFF fontset index number.", CFF_DEBUG_STR); - cff_close(cff); - return NULL; - } - - cff->name = idx; - - cff->fontname = cff_get_name(cff); - - /* Top DICT INDEX */ - idx = cff_get_index(cff); - if (n > idx->count - 1) - ERROR("CFF Top DICT not exist..."); - cff->topdict = cff_dict_unpack(idx->data + idx->offset[n] - 1, - idx->data + idx->offset[n + 1] - 1); - if (!cff->topdict) - ERROR("Parsing CFF Top DICT data failed..."); - cff_release_index(idx); - - if (cff_dict_known(cff->topdict, "CharstringType") && - cff_dict_get(cff->topdict, "CharstringType", 0) != 2) { - WARN("Only Type 2 Charstrings supported..."); - cff_close(cff); - return NULL; - } - - if (cff_dict_known(cff->topdict, "SyntheticBase")) { - WARN("CFF Synthetic font not supported."); - cff_close(cff); - return NULL; - } - - /* String INDEX */ - cff->string = cff_get_index(cff); - - /* offset to GSubr */ - cff->gsubr_offset = cff->sfont->loc - offset; - - /* Number of glyphs */ - offset = (long) cff_dict_get(cff->topdict, "CharStrings", 0); - cff_seek_set(cff, offset); - cff->num_glyphs = get_card16(cff->SFONT_OR_STREAM); - - /* Check for font type */ - if (cff_dict_known(cff->topdict, "ROS")) { - cff->flag |= FONTTYPE_CIDFONT; - } else { - cff->flag |= FONTTYPE_FONT; - } - - /* Check for encoding */ - if (cff_dict_known(cff->topdict, "Encoding")) { - offset = (long) cff_dict_get(cff->topdict, "Encoding", 0); - if (offset == 0) { /* predefined */ - cff->flag |= ENCODING_STANDARD; - } else if (offset == 1) { - cff->flag |= ENCODING_EXPERT; - } - } else { - cff->flag |= ENCODING_STANDARD; - } - - /* Check for charset */ - if (cff_dict_known(cff->topdict, "charset")) { - offset = (long) cff_dict_get(cff->topdict, "charset", 0); - if (offset == 0) { /* predefined */ - cff->flag |= CHARSETS_ISOADOBE; - } else if (offset == 1) { - cff->flag |= CHARSETS_EXPERT; - } else if (offset == 2) { - cff->flag |= CHARSETS_EXPSUB; - } - } else { - cff->flag |= CHARSETS_ISOADOBE; - } - - cff_seek_set(cff, cff->gsubr_offset); /* seek back to GSubr */ - -#ifdef XETEX - cff->ft_to_gid = NULL; -#endif - - return cff; -} - -void -cff_close (cff_font *cff) -{ - card16 i; - - if (cff) { - if (cff->fontname) RELEASE(cff->fontname); - if (cff->name) cff_release_index(cff->name); - if (cff->topdict) cff_release_dict(cff->topdict); - if (cff->string) cff_release_index(cff->string); - if (cff->gsubr) cff_release_index(cff->gsubr); - if (cff->encoding) cff_release_encoding(cff->encoding); - if (cff->charsets) cff_release_charsets(cff->charsets); - if (cff->fdselect) cff_release_fdselect(cff->fdselect); - if (cff->cstrings) cff_release_index(cff->cstrings); - if (cff->fdarray) { - for (i=0;inum_fds;i++) { - if (cff->fdarray[i]) cff_release_dict(cff->fdarray[i]); - } - RELEASE(cff->fdarray); - } - if (cff->private) { - for (i=0;inum_fds;i++) { - if (cff->private[i]) cff_release_dict(cff->private[i]); - } - RELEASE(cff->private); - } - if (cff->subrs) { - for (i=0;inum_fds;i++) { - if (cff->subrs[i]) cff_release_index(cff->subrs[i]); - } - RELEASE(cff->subrs); - } - if (cff->_string) - cff_release_index(cff->_string); - -#ifdef XETEX - if (cff->ft_to_gid) - RELEASE(cff->ft_to_gid); -#endif - - RELEASE(cff); - } - - return; -} - -char * -cff_get_name (cff_font *cff) -{ - char *fontname; - l_offset len; - cff_index *idx; - - idx = cff->name; - len = idx->offset[cff->index + 1] - idx->offset[cff->index]; - fontname = NEW(len + 1, char); - memcpy(fontname, idx->data + idx->offset[cff->index] - 1, len); - fontname[len] = '\0'; - - return fontname; -} - -long -cff_set_name (cff_font *cff, char *name) -{ - cff_index *idx; - - if (strlen(name) > 127) - ERROR("FontName string length too large..."); - - if (cff->name) - cff_release_index(cff->name); - - cff->name = idx = NEW(1, cff_index); - idx->count = 1; - idx->offsize = 1; - idx->offset = NEW(2, l_offset); - (idx->offset)[0] = 1; - (idx->offset)[1] = strlen(name) + 1; - idx->data = NEW(strlen(name), card8); - memmove(idx->data, name, strlen(name)); /* no trailing '\0' */ - - return 5 + strlen(name); -} - -long -cff_put_header (cff_font *cff, card8 *dest, long destlen) -{ - if (destlen < 4) - ERROR("Not enough space available..."); - - *(dest++) = cff->header.major; - *(dest++) = cff->header.minor; - *(dest++) = 4; /* Additional data in between header and - * Name INDEX ignored. - */ - /* We will set all offset (0) to four-byte integer. */ - *(dest++) = 4; - cff->header.offsize = 4; - - return 4; -} - -/* Only read header part but not body */ -cff_index * -cff_get_index_header (cff_font *cff) -{ - cff_index *idx; - card16 i, count; - - idx = NEW(1, cff_index); - - idx->count = count = get_card16(cff->SFONT_OR_STREAM); - if (count > 0) { - idx->offsize = get_card8(cff->SFONT_OR_STREAM); - if (idx->offsize < 1 || idx->offsize > 4) - ERROR("invalid offsize data"); - - idx->offset = NEW(count+1, l_offset); - for (i=0;ioffset)[i] = get_offset(cff->SFONT_OR_STREAM, idx->offsize); - } - - if (idx->offset[0] != 1) - ERROR("cff_get_index(): invalid index data"); - - idx->data = NULL; - } else { - idx->offsize = 0; - idx->offset = NULL; - idx->data = NULL; - } - - return idx; -} - -cff_index * -cff_get_index (cff_font *cff) -{ - cff_index *idx; - card16 i, count; - long length, nb_read, offset; - - idx = NEW(1, cff_index); - - idx->count = count = get_card16(cff->SFONT_OR_STREAM); - if (count > 0) { - idx->offsize = get_card8(cff->SFONT_OR_STREAM); - if (idx->offsize < 1 || idx->offsize > 4) - ERROR("invalid offsize data"); - - idx->offset = NEW(count + 1, l_offset); - for (i = 0 ; i < count + 1; i++) { - idx->offset[i] = get_offset(cff->SFONT_OR_STREAM, idx->offsize); - } - - if (idx->offset[0] != 1) - ERROR("Invalid CFF Index offset data"); - - length = idx->offset[count] - idx->offset[0]; - - idx->data = NEW(length, card8); - offset = 0; - while (length > 0) { - nb_read = sfnt_read(idx->data + offset, length, cff->sfont); - offset += nb_read; - length -= nb_read; - } - } else { - idx->offsize = 0; - idx->offset = NULL; - idx->data = NULL; - } - - return idx; -} - -long -cff_pack_index (cff_index *idx, card8 *dest, long destlen) -{ - long len = 0; - long datalen; - card16 i; - - if (idx->count < 1) { - if (destlen < 2) - ERROR("Not enough space available..."); - memset(dest, 0, 2); - return 2; - } - - len = cff_index_size(idx); - datalen = idx->offset[idx->count] - 1; - - if (destlen < len) - ERROR("Not enough space available..."); - - *(dest++) = (idx->count >> 8) & 0xff; - *(dest++) = idx->count & 0xff; - - if (datalen < 0xffUL) { - idx->offsize = 1; - *(dest++) = 1; - for (i = 0; i <= idx->count; i++) { - *(dest++) = (card8) (idx->offset[i] & 0xff); - } - } else if (datalen < 0xffffUL) { - idx->offsize = 2; - *(dest++) = 2; - for (i = 0; i <= idx->count; i++) { - *(dest++) = (card8) ((idx->offset[i] >> 8) & 0xff); - *(dest++) = (card8) ( idx->offset[i] & 0xff); - } - } else if (datalen < 0xffffffUL) { - idx->offsize = 3; - *(dest++) = 3; - for (i = 0; i <= idx->count; i++) { - *(dest++) = (card8)((idx->offset[i] >> 16) & 0xff); - *(dest++) = (card8)((idx->offset[i] >> 8) & 0xff); - *(dest++) = (card8)(idx->offset[i] & 0xff); - } - } else { - idx->offsize = 4; - *(dest++) = 4; - for (i = 0; i <= idx->count; i++) { - *(dest++) = (card8)((idx->offset[i] >> 24) & 0xff); - *(dest++) = (card8)((idx->offset[i] >> 16) & 0xff); - *(dest++) = (card8)((idx->offset[i] >> 8) & 0xff); - *(dest++) = (card8)(idx->offset[i] & 0xff); - } - } - - memmove(dest, idx->data, idx->offset[idx->count] - 1); - - return len; -} - -long -cff_index_size (cff_index *idx) -{ - if (idx->count > 0) { - l_offset datalen; - - datalen = idx->offset[idx->count] - 1; - if (datalen < 0xffUL) { - idx->offsize = 1; - } else if (datalen < 0xffffUL) { - idx->offsize = 2; - } else if (datalen < 0xffffffUL) { - idx->offsize = 3; - } else { - idx->offsize = 4; - } - return (3 + (idx->offsize)*(idx->count + 1) + datalen); - } else { - return 2; - } -} - - -cff_index *cff_new_index (card16 count) -{ - cff_index *idx; - - idx = NEW(1, cff_index); - idx->count = count; - idx->offsize = 0; - - if (count > 0) { - idx->offset = NEW(count + 1, l_offset); - (idx->offset)[0] = 1; - } else { - idx->offset = NULL; - } - idx->data = NULL; - - return idx; -} - -void cff_release_index (cff_index *idx) -{ - if (idx) { - if (idx->data) { - RELEASE(idx->data); - } - if (idx->offset) { - RELEASE(idx->offset); - } - RELEASE(idx); - } -} - -/* Strings */ -char *cff_get_string (cff_font *cff, s_SID id) -{ - char *result = NULL; - long len; - - if (id < CFF_STDSTR_MAX) { - len = strlen(cff_stdstr[id]); - result = NEW(len+1, char); - memcpy(result, cff_stdstr[id], len); - result[len] = '\0'; - } else if (cff && cff->string) { - cff_index *strings = cff->string; - id -= CFF_STDSTR_MAX; - if (id < strings->count) { - len = (strings->offset)[id+1] - (strings->offset)[id]; - result = NEW(len + 1, char); - memmove(result, strings->data + (strings->offset)[id] - 1, len); - result[len] = '\0'; - } - } - - return result; -} - -long cff_get_sid (cff_font *cff, const char *str) -{ - card16 i; - - if (!cff || !str) - return -1; - - /* I search String INDEX first. */ - if (cff && cff->string) { - cff_index *idx = cff->string; - for (i = 0; i < idx->count; i++) { - if (strlen(str) == (idx->offset)[i+1] - (idx->offset)[i] && - !memcmp(str, (idx->data)+(idx->offset)[i]-1, strlen(str))) - return (i + CFF_STDSTR_MAX); - } - } - - for (i = 0; i < CFF_STDSTR_MAX; i++) { - if (!strcmp(str, cff_stdstr[i])) - return i; - } - - return -1; -} - -long cff_get_seac_sid (cff_font *cff, const char *str) -{ - card16 i; - - if (!cff || !str) - return -1; - - for (i = 0; i < CFF_STDSTR_MAX; i++) { - if (!strcmp(str, cff_stdstr[i])) - return i; - } - - return -1; -} - -int cff_match_string (cff_font *cff, const char *str, s_SID sid) -{ - card16 i; - - if (sid < CFF_STDSTR_MAX) { - return ((!strcmp(str, cff_stdstr[sid])) ? 1 : 0); - } else { - i = sid - CFF_STDSTR_MAX; - if (cff == NULL || cff->string == NULL || i >= cff->string->count) - ERROR("Invalid SID"); - if (strlen(str) == (cff->string->offset)[i+1] - (cff->string->offset)[i]) - return (!memcmp(str, - (cff->string->data)+(cff->string->offset)[i]-1, - strlen(str))) ? 1 : 0; - } - - return 0; -} - -void cff_update_string (cff_font *cff) -{ - if (cff == NULL) - ERROR("CFF font not opened."); - - if (cff->string) - cff_release_index(cff->string); - cff->string = cff->_string; - cff->_string = NULL; -} - -s_SID cff_add_string (cff_font *cff, const char *str, int unique) -/* Setting unique == 1 eliminates redundant or predefined strings. */ -{ - card16 idx; - cff_index *strings; - l_offset offset, size; - long len = strlen(str); - - if (cff == NULL) - ERROR("CFF font not opened."); - - if (cff->_string == NULL) - cff->_string = cff_new_index(0); - strings = cff->_string; - - if (unique) { - /* TODO: do binary search to speed things up */ - for (idx = 0; idx < CFF_STDSTR_MAX; idx++) { - if (cff_stdstr[idx] && !strcmp(cff_stdstr[idx], str)) - return idx; - } - for (idx = 0; idx < strings->count; idx++) { - size = strings->offset[idx+1] - strings->offset[idx]; - offset = strings->offset[idx]; - if (size == len && !memcmp(strings->data+offset-1, str, len)) - return (idx + CFF_STDSTR_MAX); - } - } - - offset = (strings->count > 0) ? strings->offset[strings->count] : 1; - strings->offset = RENEW(strings->offset, strings->count+2, l_offset); - if (strings->count == 0) - strings->offset[0] = 1; - idx = strings->count; - strings->count += 1; - strings->offset[strings->count] = offset + len; - strings->data = RENEW(strings->data, offset+len-1, card8); - memcpy(strings->data+offset-1, str, len); - - return (idx + CFF_STDSTR_MAX); -} - -/* - * Encoding and Charset - * - * Encoding and Charset arrays always begin with GID = 1. - */ -long cff_read_encoding (cff_font *cff) -{ - cff_encoding *encoding; - long offset, length; - card8 i; - - if (cff->topdict == NULL) { - ERROR("Top DICT data not found"); - } - - if (!cff_dict_known(cff->topdict, "Encoding")) { - cff->flag |= ENCODING_STANDARD; - cff->encoding = NULL; - return 0; - } - - offset = (long) cff_dict_get(cff->topdict, "Encoding", 0); - if (offset == 0) { /* predefined */ - cff->flag |= ENCODING_STANDARD; - cff->encoding = NULL; - return 0; - } else if (offset == 1) { - cff->flag |= ENCODING_EXPERT; - cff->encoding = NULL; - return 0; - } - - cff_seek_set(cff, offset); - cff->encoding = encoding = NEW(1, cff_encoding); - encoding->format = get_card8(cff->SFONT_OR_STREAM); - length = 1; - - switch (encoding->format & (~0x80)) { - case 0: - encoding->num_entries = get_card8(cff->SFONT_OR_STREAM); - (encoding->data).codes = NEW(encoding->num_entries, card8); - for (i=0;i<(encoding->num_entries);i++) { - (encoding->data).codes[i] = get_card8(cff->SFONT_OR_STREAM); - } - length += encoding->num_entries + 1; - break; - case 1: - { - cff_range1 *ranges; - encoding->num_entries = get_card8(cff->SFONT_OR_STREAM); - encoding->data.range1 = ranges - = NEW(encoding->num_entries, cff_range1); - for (i=0;i<(encoding->num_entries);i++) { - ranges[i].first = get_card8(cff->SFONT_OR_STREAM); - ranges[i].n_left = get_card8(cff->SFONT_OR_STREAM); - } - length += (encoding->num_entries) * 2 + 1; - } - break; - default: - RELEASE(encoding); - ERROR("Unknown Encoding format"); - break; - } - - /* Supplementary data */ - if ((encoding->format) & 0x80) { - cff_map *map; - encoding->num_supps = get_card8(cff->SFONT_OR_STREAM); - encoding->supp = map = NEW(encoding->num_supps, cff_map); - for (i=0;i<(encoding->num_supps);i++) { - map[i].code = get_card8(cff->SFONT_OR_STREAM); - map[i].glyph = get_card16(cff->SFONT_OR_STREAM); /* SID */ - } - length += (encoding->num_supps) * 3 + 1; - } else { - encoding->num_supps = 0; - encoding->supp = NULL; - } - - return length; -} - -long cff_pack_encoding (cff_font *cff, card8 *dest, long destlen) -{ - long len = 0; - cff_encoding *encoding; - card16 i; - - if (cff->flag & HAVE_STANDARD_ENCODING || cff->encoding == NULL) - return 0; - - if (destlen < 2) - ERROR("in cff_pack_encoding(): Buffer overflow"); - - encoding = cff->encoding; - - dest[len++] = encoding->format; - dest[len++] = encoding->num_entries; - switch (encoding->format & (~0x80)) { - case 0: - if (destlen < len + encoding->num_entries) - ERROR("in cff_pack_encoding(): Buffer overflow"); - for (i=0;i<(encoding->num_entries);i++) { - dest[len++] = (encoding->data).codes[i]; - } - break; - case 1: - { - if (destlen < len + (encoding->num_entries)*2) - ERROR("in cff_pack_encoding(): Buffer overflow"); - for (i=0;i<(encoding->num_entries);i++) { - dest[len++] = (encoding->data).range1[i].first & 0xff; - dest[len++] = (encoding->data).range1[i].n_left; - } - } - break; - default: - ERROR("Unknown Encoding format"); - break; - } - - if ((encoding->format) & 0x80) { - if (destlen < len + (encoding->num_supps)*3 + 1) - ERROR("in cff_pack_encoding(): Buffer overflow"); - dest[len++] = encoding->num_supps; - for (i=0;i<(encoding->num_supps);i++) { - dest[len++] = (encoding->supp)[i].code; - dest[len++] = ((encoding->supp)[i].glyph >> 8) & 0xff; - dest[len++] = (encoding->supp)[i].glyph & 0xff; - } - } - - return len; -} - -/* input: code, output: glyph index */ -card16 cff_encoding_lookup (cff_font *cff, card8 code) -{ - card16 gid = 0; - cff_encoding *encoding; - card16 i; - - if (cff->flag & (ENCODING_STANDARD|ENCODING_EXPERT)) { - ERROR("Predefined CFF encoding not supported yet"); - } else if (cff->encoding == NULL) { - ERROR("Encoding data not available"); - } - - encoding = cff->encoding; - - gid = 0; - switch (encoding->format & (~0x80)) { - case 0: - for (i = 0; i < encoding->num_entries; i++) { - if (code == (encoding->data).codes[i]) { - gid = i + 1; - break; - } - } - break; - case 1: - for (i = 0; i < encoding->num_entries; i++) { - if (code >= (encoding->data).range1[i].first && - code <= (encoding->data).range1[i].first + (encoding->data).range1[i].n_left) { - gid += code - (encoding->data).range1[i].first + 1; - break; - } - gid += (encoding->data).range1[i].n_left + 1; - } - if (i == encoding->num_entries) - gid = 0; - break; - default: - ERROR("Unknown Encoding format."); - } - - /* Supplementary data */ - if (gid == 0 && ((encoding->format) & 0x80)) { - cff_map *map; - if (!encoding->supp) - ERROR("No CFF supplementary encoding data read."); - map = encoding->supp; - for (i=0;i<(encoding->num_supps);i++) { - if (code == map[i].code) { - gid = cff_charsets_lookup(cff, map[i].glyph); - break; - } - } - } - - return gid; -} - -void cff_release_encoding (cff_encoding *encoding) -{ - if (encoding) { - switch (encoding->format & (~0x80)) { - case 0: - if (encoding->data.codes) - RELEASE(encoding->data.codes); - break; - case 1: - if (encoding->data.range1) - RELEASE(encoding->data.range1); - break; - default: - ERROR("Unknown Encoding format."); - } - if (encoding->format & 0x80) { - if (encoding->supp) - RELEASE(encoding->supp); - } - RELEASE(encoding); - } -} - -long cff_read_charsets (cff_font *cff) -{ - cff_charsets *charset; - long offset, length; - card16 count, i; - - if (cff->topdict == NULL) - ERROR("Top DICT not available"); - - if (!cff_dict_known(cff->topdict, "charset")) { - cff->flag |= CHARSETS_ISOADOBE; - cff->charsets = NULL; - return 0; - } - - offset = (long) cff_dict_get(cff->topdict, "charset", 0); - - if (offset == 0) { /* predefined */ - cff->flag |= CHARSETS_ISOADOBE; - cff->charsets = NULL; - return 0; - } else if (offset == 1) { - cff->flag |= CHARSETS_EXPERT; - cff->charsets = NULL; - return 0; - } else if (offset == 2) { - cff->flag |= CHARSETS_EXPSUB; - cff->charsets = NULL; - return 0; - } - - cff_seek_set(cff, offset); - cff->charsets = charset = NEW(1, cff_charsets); - charset->format = get_card8(cff->SFONT_OR_STREAM); - charset->num_entries = 0; - - count = cff->num_glyphs - 1; - length = 1; - - /* Not sure. Not well documented. */ - switch (charset->format) { - case 0: - charset->num_entries = cff->num_glyphs - 1; /* no .notdef */ - charset->data.glyphs = NEW(charset->num_entries, s_SID); - length += (charset->num_entries) * 2; - for (i=0;i<(charset->num_entries);i++) { - charset->data.glyphs[i] = get_card16(cff->SFONT_OR_STREAM); - } - count = 0; - break; - case 1: - { - cff_range1 *ranges = NULL; - while (count > 0 && charset->num_entries < cff->num_glyphs) { - ranges = RENEW(ranges, charset->num_entries + 1, cff_range1); - ranges[charset->num_entries].first = get_card16(cff->SFONT_OR_STREAM); - ranges[charset->num_entries].n_left = get_card8(cff->SFONT_OR_STREAM); - count -= ranges[charset->num_entries].n_left + 1; /* no-overrap */ - charset->num_entries += 1; - charset->data.range1 = ranges; - } - length += (charset->num_entries) * 3; - } - break; - case 2: - { - cff_range2 *ranges = NULL; - while (count > 0 && charset->num_entries < cff->num_glyphs) { - ranges = RENEW(ranges, charset->num_entries + 1, cff_range2); - ranges[charset->num_entries].first = get_card16(cff->SFONT_OR_STREAM); - ranges[charset->num_entries].n_left = get_card16(cff->SFONT_OR_STREAM); - count -= ranges[charset->num_entries].n_left + 1; /* non-overrapping */ - charset->num_entries += 1; - } - charset->data.range2 = ranges; - length += (charset->num_entries) * 4; - } - break; - default: - RELEASE(charset); - ERROR("Unknown Charset format"); - break; - } - - if (count > 0) - ERROR("Charset data possibly broken"); - - return length; -} - -long cff_pack_charsets (cff_font *cff, card8 *dest, long destlen) -{ - long len = 0; - card16 i; - cff_charsets *charset; - - if (cff->flag & HAVE_STANDARD_CHARSETS || cff->charsets == NULL) - return 0; - - if (destlen < 1) - ERROR("in cff_pack_charsets(): Buffer overflow"); - - charset = cff->charsets; - - dest[len++] = charset->format; - switch (charset->format) { - case 0: - if (destlen < len + (charset->num_entries)*2) - ERROR("in cff_pack_charsets(): Buffer overflow"); - for (i=0;i<(charset->num_entries);i++) { - s_SID sid = (charset->data).glyphs[i]; /* or CID */ - dest[len++] = (sid >> 8) & 0xff; - dest[len++] = sid & 0xff; - } - break; - case 1: - { - if (destlen < len + (charset->num_entries)*3) - ERROR("in cff_pack_charsets(): Buffer overflow"); - for (i=0;i<(charset->num_entries);i++) { - dest[len++] = ((charset->data).range1[i].first >> 8) & 0xff; - dest[len++] = (charset->data).range1[i].first & 0xff; - dest[len++] = (charset->data).range1[i].n_left; - } - } - break; - case 2: - { - if (destlen < len + (charset->num_entries)*4) - ERROR("in cff_pack_charsets(): Buffer overflow"); - for (i=0;i<(charset->num_entries);i++) { - dest[len++] = ((charset->data).range2[i].first >> 8) & 0xff; - dest[len++] = (charset->data).range2[i].first & 0xff; - dest[len++] = ((charset->data).range2[i].n_left >> 8) & 0xff; - dest[len++] = (charset->data).range2[i].n_left & 0xff; - } - } - break; - default: - ERROR("Unknown Charset format"); - break; - } - - return len; -} - -card16 cff_glyph_lookup (cff_font *cff, const char *glyph) -{ - card16 gid; - cff_charsets *charset; - card16 i, n; - - if (cff->flag & (CHARSETS_ISOADOBE|CHARSETS_EXPERT|CHARSETS_EXPSUB)) { - ERROR("Predefined CFF charsets not supported yet"); - } else if (cff->charsets == NULL) { - ERROR("Charsets data not available"); - } - - /* .notdef always have glyph index 0 */ - if (!glyph || !strcmp(glyph, ".notdef")) { - return 0; - } - - charset = cff->charsets; - - gid = 0; - switch (charset->format) { - case 0: - for (i = 0; i < charset->num_entries; i++) { - gid++; - if (cff_match_string(cff, glyph, charset->data.glyphs[i])) { - return gid; - } - } - break; - case 1: - for (i = 0; i < charset->num_entries; i++) { - for (n = 0; - n <= charset->data.range1[i].n_left; n++) { - gid++; - if (cff_match_string(cff, glyph, - (s_SID)(charset->data.range1[i].first + n))) { - return gid; - } - } - } - break; - case 2: - for (i = 0; i num_entries; i++) { - for (n = 0; - n <= charset->data.range2[i].n_left; n++) { - gid++; - if (cff_match_string(cff, glyph, - (s_SID)(charset->data.range2[i].first + n))) { - return gid; - } - } - } - break; - default: - ERROR("Unknown Charset format"); - } - - return 0; /* not found, returns .notdef */ -} - -/* Input : SID or CID (16-bit unsigned int) - * Output: glyph index - */ -card16 -cff_charsets_lookup (cff_font *cff, card16 cid) -{ - card16 gid = 0; - cff_charsets *charset; - card16 i; - - if (cff->flag & (CHARSETS_ISOADOBE|CHARSETS_EXPERT|CHARSETS_EXPSUB)) { - ERROR("Predefined CFF charsets not supported yet"); - } else if (cff->charsets == NULL) { - ERROR("Charsets data not available"); - } - - if (cid == 0) { - return 0; /* GID 0 (.notdef) */ - } - - charset = cff->charsets; - - gid = 0; - switch (charset->format) { - case 0: - for (i = 0; i num_entries; i++) { - if (cid == charset->data.glyphs[i]) { - gid = i + 1; - return gid; - } - } - break; - case 1: - for (i = 0; i < charset->num_entries; i++) { - if (cid >= charset->data.range1[i].first && - cid <= charset->data.range1[i].first + charset->data.range1[i].n_left) { - gid += cid - charset->data.range1[i].first + 1; - return gid; - } - gid += charset->data.range1[i].n_left + 1; - } - break; - case 2: - for (i = 0; i < charset->num_entries; i++) { - if (cid >= charset->data.range2[i].first && - cid <= charset->data.range2[i].first + charset->data.range2[i].n_left) { - gid += cid - charset->data.range2[i].first + 1; - return gid; - } - gid += charset->data.range2[i].n_left + 1; - } - break; - default: - ERROR("Unknown Charset format"); - } - - return 0; /* not found */ -} - -/* Input : GID - * Output: SID/CID (card16) - */ -card16 -cff_charsets_lookup_inverse (cff_font *cff, card16 gid) -{ - card16 sid = 0; - cff_charsets *charset; - card16 i; - - if (cff->flag & (CHARSETS_ISOADOBE|CHARSETS_EXPERT|CHARSETS_EXPSUB)) { - ERROR("Predefined CFF charsets not supported yet"); - } else if (cff->charsets == NULL) { - ERROR("Charsets data not available"); - } - - if (gid == 0) { - return 0; /* .notdef */ - } - - charset = cff->charsets; - - sid = 0; - switch (charset->format) { - case 0: - if (gid - 1 >= charset->num_entries) - ERROR("Invalid GID."); - sid = charset->data.glyphs[gid - 1]; - break; - case 1: - for (i = 0; i < charset->num_entries; i++) { - if (gid <= charset->data.range1[i].n_left + 1) { - sid = gid + charset->data.range1[i].first - 1; - break; - } - gid -= charset->data.range1[i].n_left + 1; - } - if (i == charset->num_entries) - ERROR("Invalid GID"); - break; - case 2: - for (i = 0; i < charset->num_entries; i++) { - if (gid <= charset->data.range2[i].n_left + 1) { - sid = gid + charset->data.range2[i].first - 1; - break; - } - gid -= charset->data.range2[i].n_left + 1; - } - if (i == charset->num_entries) - ERROR("Invalid GID"); - break; - default: - ERROR("Unknown Charset format"); - } - - return sid; -} - -void -cff_release_charsets (cff_charsets *charset) -{ - if (charset) { - switch (charset->format) { - case 0: - if (charset->data.glyphs) - RELEASE(charset->data.glyphs); - break; - case 1: - if (charset->data.range1) - RELEASE(charset->data.range1); - break; - case 2: - if (charset->data.range2) - RELEASE(charset->data.range2); - break; - default: - break; - } - RELEASE(charset); - } -} - -/* CID-Keyed font specific */ -long cff_read_fdselect (cff_font *cff) -{ - cff_fdselect *fdsel; - long offset, length; - card16 i; - - if (cff->topdict == NULL) - ERROR("Top DICT not available"); - - if (!(cff->flag & FONTTYPE_CIDFONT)) - return 0; - - offset = (long) cff_dict_get(cff->topdict, "FDSelect", 0); - cff_seek_set(cff, offset); - cff->fdselect = fdsel = NEW(1, cff_fdselect); - fdsel->format = get_card8(cff->SFONT_OR_STREAM); - - length = 1; - - switch (fdsel->format) { - case 0: - fdsel->num_entries = cff->num_glyphs; - (fdsel->data).fds = NEW(fdsel->num_entries, card8); - for (i=0;i<(fdsel->num_entries);i++) { - (fdsel->data).fds[i] = get_card8(cff->SFONT_OR_STREAM); - } - length += fdsel->num_entries; - break; - case 3: - { - cff_range3 *ranges; - fdsel->num_entries = get_card16(cff->SFONT_OR_STREAM); - fdsel->data.ranges = ranges = NEW(fdsel->num_entries, cff_range3); - for (i=0;i<(fdsel->num_entries);i++) { - ranges[i].first = get_card16(cff->SFONT_OR_STREAM); - ranges[i].fd = get_card8(cff->SFONT_OR_STREAM); - } - if (ranges[0].first != 0) - ERROR("Range not starting with 0."); - if (cff->num_glyphs != get_card16(cff->SFONT_OR_STREAM)) - ERROR("Sentinel value mismatched with number of glyphs."); - length += (fdsel->num_entries) * 3 + 4; - } - break; - default: - RELEASE(fdsel); - ERROR("Unknown FDSelect format."); - break; - } - - return length; -} - -long cff_pack_fdselect (cff_font *cff, card8 *dest, long destlen) -{ - cff_fdselect *fdsel; - long len = 0; - card16 i; - - if (cff->fdselect == NULL) - return 0; - - if (destlen < 1) - ERROR("in cff_pack_fdselect(): Buffur overflow"); - - fdsel = cff->fdselect; - - dest[len++] = fdsel->format; - switch (fdsel->format) { - case 0: - if (fdsel->num_entries != cff->num_glyphs) - ERROR("in cff_pack_fdselect(): Invalid data"); - if (destlen < len + fdsel->num_entries) - ERROR("in cff_pack_fdselect(): Buffer overflow"); - for (i=0;inum_entries;i++) { - dest[len++] = (fdsel->data).fds[i]; - } - break; - case 3: - { - if (destlen < len + 2) - ERROR("in cff_pack_fdselect(): Buffer overflow"); - len += 2; - for (i=0;i<(fdsel->num_entries);i++) { - if (destlen < len + 3) - ERROR("in cff_pack_fdselect(): Buffer overflow"); - dest[len++] = ((fdsel->data).ranges[i].first >> 8) & 0xff; - dest[len++] = (fdsel->data).ranges[i].first & 0xff; - dest[len++] = (fdsel->data).ranges[i].fd; - } - if (destlen < len + 2) - ERROR("in cff_pack_fdselect(): Buffer overflow"); - dest[len++] = (cff->num_glyphs >> 8) & 0xff; - dest[len++] = cff->num_glyphs & 0xff; - dest[1] = ((len/3 - 1) >> 8) & 0xff; - dest[2] = (len/3 - 1) & 0xff; - } - break; - default: - ERROR("Unknown FDSelect format."); - break; - } - - return len; -} - -void cff_release_fdselect (cff_fdselect *fdselect) -{ - if (fdselect) { - if (fdselect->format == 0) { - if (fdselect->data.fds) RELEASE(fdselect->data.fds); - } else if (fdselect->format == 3) { - if (fdselect->data.ranges) RELEASE(fdselect->data.ranges); - } - RELEASE(fdselect); - } -} - -card8 cff_fdselect_lookup (cff_font *cff, card16 gid) -{ - card8 fd = 0xff; - cff_fdselect *fdsel; - - if (cff->fdselect == NULL) - ERROR("in cff_fdselect_lookup(): FDSelect not available"); - - fdsel = cff->fdselect; - - if (gid >= cff->num_glyphs) - ERROR("in cff_fdselect_lookup(): Invalid glyph index"); - - switch (fdsel->format) { - case 0: - fd = fdsel->data.fds[gid]; - break; - case 3: - { - if (gid == 0) { - fd = (fdsel->data).ranges[0].fd; - } else { - card16 i; - for (i=1;i<(fdsel->num_entries);i++) { - if (gid < (fdsel->data).ranges[i].first) - break; - } - fd = (fdsel->data).ranges[i-1].fd; - } - } - break; - default: - ERROR("in cff_fdselect_lookup(): Invalid FDSelect format"); - break; - } - - if (fd >= cff->num_fds) - ERROR("in cff_fdselect_lookup(): Invalid Font DICT index"); - - return fd; -} - -long cff_read_subrs (cff_font *cff) -{ - long len = 0; - long offset; - int i; - - if ((cff->flag & FONTTYPE_CIDFONT) && cff->fdarray == NULL) { - cff_read_fdarray(cff); - } - - if (cff->private == NULL) - cff_read_private(cff); - - if (cff->gsubr == NULL) { - cff_seek_set(cff, cff->gsubr_offset); - cff->gsubr = cff_get_index(cff); - } - - cff->subrs = NEW(cff->num_fds, cff_index *); - if (cff->flag & FONTTYPE_CIDFONT) { - for (i=0;inum_fds;i++) { - if (cff->private[i] == NULL || - !cff_dict_known(cff->private[i], "Subrs")) { - (cff->subrs)[i] = NULL; - } else { - offset = (long) cff_dict_get(cff->fdarray[i], "Private", 1); - offset += (long) cff_dict_get(cff->private[i], "Subrs", 0); - cff_seek_set(cff, offset); - (cff->subrs)[i] = cff_get_index(cff); - len += cff_index_size((cff->subrs)[i]); - } - } - } else { - if (cff->private[0] == NULL || - !cff_dict_known(cff->private[0], "Subrs")) { - (cff->subrs)[0] = NULL; - } else { - offset = (long) cff_dict_get(cff->topdict, "Private", 1); - offset += (long) cff_dict_get(cff->private[0], "Subrs", 0); - cff_seek_set(cff, offset); - (cff->subrs)[0] = cff_get_index(cff); - len += cff_index_size((cff->subrs)[0]); - } - } - - return len; -} - -long cff_read_fdarray (cff_font *cff) -{ - long len = 0; - cff_index *idx; - long offset, size; - card16 i; - - if (cff->topdict == NULL) - ERROR("in cff_read_fdarray(): Top DICT not found"); - - if (!(cff->flag & FONTTYPE_CIDFONT)) - return 0; - - /* must exist */ - offset = (long) cff_dict_get(cff->topdict, "FDArray", 0); - cff_seek_set(cff, offset); - idx = cff_get_index(cff); - cff->num_fds = (card8)idx->count; - cff->fdarray = NEW(idx->count, cff_dict *); - for (i=0;icount;i++) { - card8 *data = idx->data + (idx->offset)[i] - 1; - size = (idx->offset)[i+1] - (idx->offset)[i]; - if (size > 0) { - (cff->fdarray)[i] = cff_dict_unpack(data, data+size); - } else { - (cff->fdarray)[i] = NULL; - } - } - len = cff_index_size(idx); - cff_release_index(idx); - - return len; -} - -long cff_read_private (cff_font *cff) -{ - long len = 0; - card8 *data; - long offset, size; - - if (cff->flag & FONTTYPE_CIDFONT) { - int i; - - if (cff->fdarray == NULL) - cff_read_fdarray(cff); - - cff->private = NEW(cff->num_fds, cff_dict *); - for (i=0;inum_fds;i++) { - if (cff->fdarray[i] != NULL && - cff_dict_known(cff->fdarray[i], "Private") && - (size = (long) cff_dict_get(cff->fdarray[i], "Private", 0)) - > 0) { - offset = (long) cff_dict_get(cff->fdarray[i], "Private", 1); - cff_seek_set(cff, offset); - data = NEW(size, card8); - if (sfnt_read(data, size, cff->sfont) != size) - ERROR("reading file failed"); - (cff->private)[i] = cff_dict_unpack(data, data+size); - RELEASE(data); - len += size; - } else { - (cff->private)[i] = NULL; - } - } - } else { - cff->num_fds = 1; - cff->private = NEW(1, cff_dict *); - if (cff_dict_known(cff->topdict, "Private") && - (size = (long) cff_dict_get(cff->topdict, "Private", 0)) > 0) { - offset = (long) cff_dict_get(cff->topdict, "Private", 1); - cff_seek_set(cff, offset); - data = NEW(size, card8); - if (sfnt_read(data, size, cff->sfont) != size) - ERROR("reading file failed"); - cff->private[0] = cff_dict_unpack(data, data+size); - RELEASE(data); - len += size; - } else { - (cff->private)[0] = NULL; - len = 0; - } - } - - return len; -} - -#ifdef XETEX -unsigned short* cff_get_ft_to_gid(cff_font *cff) -{ - return cff->ft_to_gid; -} -#endif diff --git a/Build/source/texk/dvipdfm-x/xsrc/dvi.c b/Build/source/texk/dvipdfm-x/xsrc/dvi.c index c540706e6d6..3e7f5e3cdd0 100644 --- a/Build/source/texk/dvipdfm-x/xsrc/dvi.c +++ b/Build/source/texk/dvipdfm-x/xsrc/dvi.c @@ -96,10 +96,12 @@ static struct dvi_header static double dev_origin_x = 72.0, dev_origin_y = 770.0; +#ifdef XETEX double get_origin (int x) { return x ? dev_origin_x : dev_origin_y; } +#endif #define PHYSICAL 1 #define VIRTUAL 2 @@ -170,6 +172,7 @@ static int num_def_fonts = 0, max_def_fonts = 0; static int compute_boxes = 0, link_annot = 1; static int verbose = 0; +#ifdef XETEX #define DVI_PAGE_BUF_CHUNK 0x10000UL /* 64K should be plenty for most pages */ static unsigned char* dvi_page_buffer; @@ -374,8 +377,28 @@ static UNSIGNED_QUAD get_buffered_unsigned_quad(void) } return (UNSIGNED_QUAD) quad; } - - +#else +#define get_and_buffer_unsigned_byte(fp) get_unsigned_byte(fp) +#if 0 +#define get_and_buffer_signed_byte(fp) get_signed_byte(fp) +#endif +#define get_and_buffer_unsigned_pair(fp) get_unsigned_pair(fp) +#define get_and_buffer_signed_pair(fp) get_signed_pair(fp) +#define get_and_buffer_unsigned_triple(fp) get_unsigned_triple(fp) +#define get_and_buffer_signed_triple(fp) get_signed_triple(fp) +#define get_and_buffer_signed_quad(fp) get_unsigned_quad(fp) +#define get_and_buffer_unsigned_quad(fp) get_unsigned_quad(fp) +#define get_and_buffer_bytes(fp, ct) seek_relative(fp, ct) + +#define get_buffered_unsigned_byte() get_unsigned_byte(dvi_file) +#define get_buffered_signed_byte() get_signed_byte(dvi_file) +#define get_buffered_unsigned_pair() get_unsigned_pair(dvi_file) +#define get_buffered_signed_pair() get_signed_pair(dvi_file) +#define get_buffered_unsigned_triple() get_unsigned_triple(dvi_file) +#define get_buffered_signed_triple() get_signed_triple(dvi_file) +#define get_buffered_signed_quad() get_signed_quad(dvi_file) +#define get_buffered_unsigned_quad() get_unsigned_quad(dvi_file) +#endif void dvi_set_verbose (void) @@ -717,14 +740,11 @@ get_dvi_fonts (long post_location) ERROR(invalid_signature); } #ifdef XETEX - if (code != XDV_NATIVE_FONT_DEF) { - read_font_record(tex_id); - } else { + if (code == XDV_NATIVE_FONT_DEF) read_native_font_record(tex_id); - } -#else - read_font_record(tex_id); + else #endif + read_font_record(tex_id); } if (verbose > 2) { unsigned i; @@ -1749,9 +1769,12 @@ do_fnt4 (void) static void do_xxx (UNSIGNED_QUAD size) { -#if 0 +#ifdef XETEX + dvi_do_special(dvi_page_buffer + dvi_page_buf_index, size); + dvi_page_buf_index += size; +#else UNSIGNED_QUAD i; - Ubyte *buffer; /* FIXME - no need for new buffer here */ + Ubyte *buffer; buffer = NEW(size+1, Ubyte); for (i = 0; i < size; i++) { @@ -1759,9 +1782,6 @@ do_xxx (UNSIGNED_QUAD size) } dvi_do_special(buffer, size); RELEASE(buffer); -#else - dvi_do_special(dvi_page_buffer + dvi_page_buf_index, size); - dvi_page_buf_index += size; #endif } @@ -2185,13 +2205,16 @@ dvi_do_page (long n, do_pic_file(); break; #endif + case POST: +#ifdef XETEX if (linear && !processing_page) { /* for linear processing, this means there are no more pages */ num_pages = 0; /* force loop to terminate */ return; } /* else fall through to error case */ +#endif case PRE: case POST_POST: ERROR("Unexpected preamble or postamble in dvi file"); break; @@ -2435,7 +2458,7 @@ scan_special (double *wd, double *ht, double *xo, double *yo, char *lm, const char *buf, UNSIGNED_QUAD size) { char *q; - const char *p = buf, *endptr; + const char *p = buf, *endptr; int ns_pdf = 0, error = 0; double tmp; @@ -2707,17 +2730,19 @@ dvi_scan_specials (long page_no, } break; #endif + case PTEXDIR: get_and_buffer_unsigned_byte(fp); break; case POST: +#ifdef XETEX if (linear && dvi_page_buf_index == 1) { /* this is actually an indication that we've reached the end of the input */ return; } /* else fall through to error case */ - +#endif default: /* case PRE: case POST_POST: and others */ ERROR("Unexpected opcode %d at pos=0x%x", opcode, tell_position(fp)); break; diff --git a/Build/source/texk/dvipdfm-x/xsrc/dvi.h b/Build/source/texk/dvipdfm-x/xsrc/dvi.h deleted file mode 100644 index 8f6f7e07e59..00000000000 --- a/Build/source/texk/dvipdfm-x/xsrc/dvi.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - - This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - - Copyright (C) 2002-2012 by Jin-Hwan Cho and Shunsaku Hirata, - the dvipdfmx project team. - - Copyright (C) 1998, 1999 by Mark A. Wicks - - This program 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; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -*/ - -#ifndef _DVI_H_ -#define _DVI_H_ - -#include "error.h" -#include "numbers.h" -/* spt_t */ -#include "pdfdev.h" - -/* instantiated in dvipdfmx.c */ -extern double paper_width, paper_height; -extern char landscape_mode; - -extern double get_origin (int x); - -extern void dvi_set_verbose (void); - -/* returns scale (dvi2pts) */ -extern double dvi_init (char *dvi_filename, double mag); /* may append .dvi or .xdv to filename */ -extern void dvi_close (void); /* Closes data structures created by dvi_open */ - -extern double dvi_tell_mag (void); -#ifdef XETEX -extern double dvi_unit_size (void); -#endif -extern double dvi_dev_xpos (void); -extern double dvi_dev_ypos (void); -extern unsigned dvi_npages (void); -extern const char *dvi_comment (void); - -extern void dvi_vf_init (int dev_font_id); -extern void dvi_vf_finish (void); - -extern void dvi_set_font (int font_id); -extern void dvi_set (SIGNED_QUAD ch); -extern void dvi_rule (SIGNED_QUAD width, SIGNED_QUAD height); - -extern void dvi_right (SIGNED_QUAD x); -extern void dvi_put (SIGNED_QUAD ch); -extern void dvi_push (void); -extern void dvi_pop (void); -extern void dvi_w0 (void); -extern void dvi_w (SIGNED_QUAD ch); -extern void dvi_x0 (void); -extern void dvi_x (SIGNED_QUAD ch); -extern void dvi_down (SIGNED_QUAD y); -extern void dvi_y (SIGNED_QUAD ch); -extern void dvi_y0 (void); -extern void dvi_z (SIGNED_QUAD ch); -extern void dvi_z0 (void); -extern void dvi_dir (UNSIGNED_BYTE dir); - -extern void dvi_do_page (long page_no, - double paper_width, double paper_height, - double x_offset, double y_offset); -extern void dvi_scan_specials (long page_no, - double *width, double *height, - double *x_offset, double *y_offset, - char *landscape, unsigned *minorversion, - int *do_enc, unsigned *key_bits, unsigned *permission, char *owner_pw, char *user_pw); -extern int dvi_locate_font (const char *name, spt_t ptsize); - -/* link or nolink: - * See dvipdfm (not x) user's manual on pdf:link and pdf:nolink. - * This is workaround for preventing inclusion of pagenation artifact such as - * footnote and page number in link annotation. - */ -extern void dvi_link_annot (int flag); -/* The followings are for calculating bounding box of text for annotation. - * DVI uses push/pop to do line-feed-carriage-return. So line breaking is - * handled by inspecting current depth of DVI register stack. - */ -extern void dvi_tag_depth (void); -extern void dvi_untag_depth (void); -extern void dvi_compute_boxes (int flag); - -extern void dvi_do_special (const void *buffer, UNSIGNED_QUAD size); - -/* allow other modules (pdfdev) to ask whether we're collecting box areas */ -int dvi_is_tracking_boxes(void); - -#endif /* _DVI_H_ */ diff --git a/Build/source/texk/dvipdfm-x/xsrc/dvipdfmx.c b/Build/source/texk/dvipdfm-x/xsrc/dvipdfmx.c index b8656256df1..61a81057cc6 100644 --- a/Build/source/texk/dvipdfm-x/xsrc/dvipdfmx.c +++ b/Build/source/texk/dvipdfm-x/xsrc/dvipdfmx.c @@ -60,11 +60,16 @@ #include "pdfximage.h" #include "cid.h" +#include "dvipdfmx.h" #include "xbb.h" +#include "error.h" + +#ifdef XETEX #include "tt_aux.h" +#endif -#include "error.h" +int compat_mode = 0; /* 0 = dvipdfmx, 1 = dvipdfm */ static int verbose = 0; @@ -114,12 +119,6 @@ char *dvi_filename = NULL, *pdf_filename = NULL; static void read_config_file (const char *config); -#ifdef WIN32 -#define STRN_CMP strncasecmp -#else -#define STRN_CMP strncmp -#endif - static void set_default_pdf_filename(void) { @@ -128,17 +127,16 @@ set_default_pdf_filename(void) dvi_base = xbasename(dvi_filename); if (mp_mode && strlen(dvi_base) > 4 && - !STRN_CMP(".mps", dvi_base + strlen(dvi_base) - 4, 4)) { + FILESTRCASEEQ(".mps", dvi_base + strlen(dvi_base) - 4)) { pdf_filename = NEW(strlen(dvi_base)+1, char); strncpy(pdf_filename, dvi_base, strlen(dvi_base) - 4); pdf_filename[strlen(dvi_base)-4] = '\0'; } else if (strlen(dvi_base) > 4 && + (FILESTRCASEEQ(".dvi", dvi_base+strlen(dvi_base)-4) #ifdef XETEX - (!STRN_CMP(".dvi", dvi_base+strlen(dvi_base)-4, 4) || - !STRN_CMP(".xdv", dvi_base+strlen(dvi_base)-4, 4))) { -#else - !STRN_CMP(".dvi", dvi_base+strlen(dvi_base)-4, 4)) { + || FILESTRCASEEQ(".xdv", dvi_base+strlen(dvi_base)-4) #endif + )) { pdf_filename = NEW(strlen(dvi_base)+1, char); strncpy(pdf_filename, dvi_base, strlen(dvi_base)-4); pdf_filename[strlen(dvi_base)-4] = '\0'; @@ -151,9 +149,10 @@ set_default_pdf_filename(void) } static void -usage (int exit_code) +show_version (void) { - fprintf (stdout, "\nThis is %s-%s by Jonathan Kew and Jin-Hwan Cho,\n", PACKAGE, VERSION); + fprintf (stdout, "\nThis is xdvipdfmx-%s by Jonathan Kew and Jin-Hwan Cho,\n", VERSION); + fprintf (stdout, "modified for TeX Live,\n"); fprintf (stdout, "an extended version of DVIPDFMx, which in turn was\n"); fprintf (stdout, "an extended version of dvipdfm-0.13.2c developed by Mark A. Wicks.\n"); fprintf (stdout, "\nCopyright (c) 2006-2013 SIL International and Jin-Hwan Cho.\n"); @@ -161,6 +160,11 @@ usage (int exit_code) fprintf (stdout, "it under the terms of the GNU General Public License as published by\n"); fprintf (stdout, "the Free Software Foundation; either version 2 of the License, or\n"); fprintf (stdout, "(at your option) any later version.\n"); +} + +static void +show_usage (void) +{ fprintf (stdout, "\nUsage: xdvipdfmx [options] xdvfile\n"); fprintf (stdout, "-c \t\tIgnore color specials (for B&W printing)\n"); fprintf (stdout, "-d number\tSet PDF decimal digits (0-5) [2]\n"); @@ -203,7 +207,13 @@ usage (int exit_code) fprintf (stdout, "\nAll dimensions entered on the command line are \"true\" TeX dimensions.\n"); fprintf (stdout, "Argument of \"-s\" lists physical page ranges separated by commas, e.g., \"-s 1-3,5-6\"\n"); fprintf (stdout, "Papersize is specified by paper format (e.g., \"a4\") or by w,h (e.g., \"20cm,30cm\").\n"); +} +static void +usage (int exit_code) +{ + show_version(); + show_usage(); exit(exit_code); } @@ -842,11 +852,14 @@ main (int argc, char *argv[]) { double dvi2pts; - const char *av0 = xbasename(argv[0]); - if (STRN_CMP(av0, "ebb", 3) == 0) - return extractbb(argc, argv, EBB_OUTPUT); - else if (STRN_CMP(av0, "xbb", 3) == 0 || STRN_CMP(av0, "extractbb", 9) == 0) - return extractbb(argc, argv, XBB_OUTPUT); + char *base = kpse_program_basename (argv[0]); + + if (FILESTRCASEEQ (base, "extractbb") || FILESTRCASEEQ (base, "xbb")) + return extractbb (argc, argv, XBB_OUTPUT); + if (FILESTRCASEEQ (base, "ebb")) + return extractbb (argc, argv, EBB_OUTPUT); + + free (base); #ifdef MIKTEX miktex_initialize(); diff --git a/Build/source/texk/dvipdfm-x/xsrc/epdf.c b/Build/source/texk/dvipdfm-x/xsrc/epdf.c index 2984f83df3b..cef72ee0c39 100644 --- a/Build/source/texk/dvipdfm-x/xsrc/epdf.c +++ b/Build/source/texk/dvipdfm-x/xsrc/epdf.c @@ -39,10 +39,7 @@ #include "mem.h" #include "mfileio.h" #include "error.h" - -#ifndef XETEX #include "dvipdfmx.h" -#endif #include "pdfobj.h" #include "pdfdev.h" diff --git a/Build/source/texk/dvipdfm-x/xsrc/mpost.c b/Build/source/texk/dvipdfm-x/xsrc/mpost.c deleted file mode 100644 index ab0f87b91e1..00000000000 --- a/Build/source/texk/dvipdfm-x/xsrc/mpost.c +++ /dev/null @@ -1,1671 +0,0 @@ -/* - - This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - - Copyright (C) 2007-2012 by Jin-Hwan Cho and Shunsaku Hirata, - the dvipdfmx project team. - - Copyright (C) 1998, 1999 by Mark A. Wicks - - This program 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; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -*/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#include "system.h" -#include "mem.h" -#include "error.h" -#include "mfileio.h" -#include "numbers.h" - -#include "tfm.h" - -#include "pdfobj.h" -#include "pdfparse.h" -#include "pdfdev.h" -#include "pdfdoc.h" - -#include "pdfcolor.h" -#include "pdfdraw.h" - -#include "fontmap.h" -#include "subfont.h" - -#include "pdfximage.h" - -#include "mpost.h" - -/* - * In PDF, current path is not a part of graphics state parameter. - * Hence, current path is not saved by the "q" operator and is not - * recovered by the "Q" operator. This means that the following PS - * code - * - * gsave grestore ... - * - * can't be translated to PDF code - * - * q Q ... - * - * . Only clipping path (which is graphics state parameter in PDF - * too) is treated in the same way. So, we write clipping path - * immediately and forget about it but remember current path. - */ - -static int mp_parse_body (const char **start, const char *end, double x_user, double y_user); - -static struct mp_font -{ - char *font_name; - int font_id; - int tfm_id; /* Used for text width calculation */ - int subfont_id; - double pt_size; -} font_stack[PDF_GSAVE_MAX] = { - {NULL, -1, -1, -1, 0} -}; -static int currentfont = -1; - -#define CURRENT_FONT() ((currentfont < 0) ? NULL : &font_stack[currentfont]) - -/* Compatibility */ -#define MP_CMODE_MPOST 0 -#define MP_CMODE_DVIPSK 1 -#define MP_CMODE_PTEXVERT 2 -static int mp_cmode = MP_CMODE_MPOST; - -static int -mp_setfont (const char *font_name, double pt_size) -{ - const char *name = font_name; - struct mp_font *font; - int subfont_id = -1; - fontmap_rec *mrec; - - font = CURRENT_FONT(); - - if (font) { - if (!strcmp(font->font_name, font_name) && - font->pt_size == pt_size) - return 0; - } else { /* No currentfont */ -/* ***TODO*** Here some problem exists! */ - font = &font_stack[0]; - font->font_name = NULL; - currentfont = 0; - } - - mrec = pdf_lookup_fontmap_record(font_name); - if (mrec && mrec->charmap.sfd_name && mrec->charmap.subfont_id) { - subfont_id = sfd_load_record(mrec->charmap.sfd_name, mrec->charmap.subfont_id); - } - - /* See comments in dvi_locate_font() in dvi.c. */ - if (mrec && mrec->map_name) { - name = mrec->map_name; - } else { - name = font_name; - } - - if (font->font_name) - RELEASE(font->font_name); - font->font_name = NEW(strlen(font_name) + 1, char); - strcpy(font->font_name, font_name); - font->subfont_id = subfont_id; - font->pt_size = pt_size; - font->tfm_id = tfm_open(font_name, 0); /* Need not exist in MP mode */ - font->font_id = pdf_dev_locate_font(name, - (spt_t) (pt_size * dev_unit_dviunit())); - - if (font->font_id < 0) { - ERROR("MPOST: No physical font assigned for \"%s\".", font_name); - return 1; - } - - return 0; -} - -static void -save_font (void) -{ - struct mp_font *current, *next; - - if (currentfont < 0) { - font_stack[0].font_name = NEW(strlen("Courier") + 1, char); - strcpy(font_stack[0].font_name, "Courier"); - font_stack[0].pt_size = 1; - font_stack[0].tfm_id = 0; - font_stack[0].subfont_id = 0; - currentfont = 0; - } - - current = &font_stack[currentfont++]; - next = &font_stack[currentfont ]; - next->font_name = NEW(strlen(current->font_name)+1, char); - strcpy(next->font_name, current->font_name); - next->pt_size = current->pt_size; - - next->subfont_id = current->subfont_id; - next->tfm_id = current->tfm_id; -} - -static void -restore_font (void) -{ - struct mp_font *current; - - current = CURRENT_FONT(); - if (current) { - if (current->font_name) - RELEASE(current->font_name); - current->font_name = NULL; - } else { - ERROR("No currentfont..."); - } - - currentfont--; -} - -static void -clear_fonts (void) -{ - while (currentfont >= 0) { - if (font_stack[currentfont].font_name) - RELEASE(font_stack[currentfont].font_name); - currentfont--; - } -} - -static int -is_fontname (const char *token) -{ - fontmap_rec *mrec; - - mrec = pdf_lookup_fontmap_record(token); - if (mrec) - return 1; - - return tfm_exists(token); -} - -int -mps_scan_bbox (const char **pp, const char *endptr, pdf_rect *bbox) -{ - char *number; - double values[4]; - int i; - - /* skip_white() skips lines starting '%'... */ - while (*pp < endptr && isspace(**pp)) - (*pp)++; - - /* Scan for bounding box record */ - while (*pp < endptr && **pp == '%') { - if (*pp + 14 < endptr && - !strncmp(*pp, "%%BoundingBox:", 14)) { - - *pp += 14; - - for (i = 0; i < 4; i++) { - skip_white(pp, endptr); - number = parse_number(pp, endptr); - if (!number) { - break; - } - values[i] = atof(number); - RELEASE(number); - } - if (i < 4) { - return -1; - } else { - bbox->llx = values[0]; - bbox->lly = values[1]; - bbox->urx = values[2]; - bbox->ury = values[3]; - - return 0; - } - } - skip_line (pp, endptr); - while (*pp < endptr && isspace(**pp)) - (*pp)++; - } - - return -1; -} - -static void -skip_prolog (const char **start, const char *end) -{ - int found_prolog = 0; - const char *save; - - save = *start; - while (*start < end) { - if (**start != '%') - skip_white(start, end); - if (*start >= end) - break; - if (!strncmp(*start, "%%EndProlog", 11)) { - found_prolog = 1; - skip_line(start, end); - break; - } else if (!strncmp(*start, "%%Page:", 7)) { - skip_line(start, end); - break; - } - skip_line(start, end); - } - if (!found_prolog) { - *start = save; - } - - return; -} - -/* PostScript Operators */ - -#define ADD 1 -#define SUB 2 -#define MUL 3 -#define DIV 4 -#define NEG 5 -#define TRUNCATE 6 - -#define CLEAR 10 -#define EXCH 11 -#define POP 12 - -#define NEWPATH 31 -#define CLOSEPATH 32 -#define MOVETO 33 -#define RMOVETO 34 -#define CURVETO 35 -#define RCURVETO 36 -#define LINETO 37 -#define RLINETO 38 -#define ARC 39 -#define ARCN 40 - -#define FILL 41 -#define STROKE 42 -#define SHOW 43 - -#define CLIP 44 -#define EOCLIP 45 - -#define SHOWPAGE 49 - -#define GSAVE 50 -#define GRESTORE 51 - -#define CONCAT 52 -#define SCALE 53 -#define TRANSLATE 54 -#define ROTATE 55 - -#define SETLINEWIDTH 60 -#define SETDASH 61 -#define SETLINECAP 62 -#define SETLINEJOIN 63 -#define SETMITERLIMIT 64 - -#define SETGRAY 70 -#define SETRGBCOLOR 71 -#define SETCMYKCOLOR 72 - -#define CURRENTPOINT 80 -#define IDTRANSFORM 81 -#define DTRANSFORM 82 - -#define FINDFONT 201 -#define SCALEFONT 202 -#define SETFONT 203 -#define CURRENTFONT 204 - -#define STRINGWIDTH 210 - -#define DEF 999 - -#define FSHOW 1001 -#define STEXFIG 1002 -#define ETEXFIG 1003 -#define HLW 1004 -#define VLW 1005 -#define RD 1006 -#define B 1007 - -static struct operators -{ - const char *token; - int opcode; -} ps_operators[] = { - {"add", ADD}, - {"mul", MUL}, - {"div", DIV}, - {"neg", NEG}, - {"sub", SUB}, - {"truncate", TRUNCATE}, - - {"clear", CLEAR}, - {"exch", EXCH}, - {"pop", POP}, - - {"clip", CLIP}, - {"eoclip", EOCLIP}, - {"closepath", CLOSEPATH}, - {"concat", CONCAT}, - - {"newpath", NEWPATH}, - {"moveto", MOVETO}, - {"rmoveto", RMOVETO}, - {"lineto", LINETO}, - {"rlineto", RLINETO}, - {"curveto", CURVETO}, - {"rcurveto", RCURVETO}, - {"arc", ARC}, - {"arcn", ARCN}, - - {"stroke", STROKE}, - {"fill", FILL}, - {"show", SHOW}, - {"showpage", SHOWPAGE}, - - {"gsave", GSAVE}, - {"grestore", GRESTORE}, - {"translate", TRANSLATE}, - {"rotate", ROTATE}, - {"scale", SCALE}, - - {"setlinecap", SETLINECAP}, - {"setlinejoin", SETLINEJOIN}, - {"setlinewidth", SETLINEWIDTH}, - {"setmiterlimit", SETMITERLIMIT}, - {"setdash", SETDASH}, - - {"setgray", SETGRAY}, - {"setrgbcolor", SETRGBCOLOR}, - {"setcmykcolor", SETCMYKCOLOR}, - - {"currentpoint", CURRENTPOINT}, /* This is here for rotate support - in graphics package-not MP support */ - {"dtransform", DTRANSFORM}, - {"idtransform", IDTRANSFORM}, - - {"findfont", FINDFONT}, - {"scalefont", SCALEFONT}, - {"setfont", SETFONT}, - {"currentfont", CURRENTFONT}, - - {"stringwidth", STRINGWIDTH}, - - {"def", DEF} /* not implemented yet; just work with mptopdf */ -}; - -static struct operators mps_operators[] = { - {"fshow", FSHOW}, /* exch findfont exch scalefont setfont show */ - {"startTexFig", STEXFIG}, - {"endTexFig", ETEXFIG}, - {"hlw", HLW}, /* 0 dtransform exch truncate exch idtransform pop setlinewidth */ - {"vlw", VLW}, /* 0 exch dtransform truncate idtransform pop setlinewidth pop */ - {"l", LINETO}, - {"r", RLINETO}, - {"c", CURVETO}, - {"m", MOVETO}, - {"p", CLOSEPATH}, - {"n", NEWPATH}, - {"C", SETCMYKCOLOR}, - {"G", SETGRAY}, - {"R", SETRGBCOLOR}, - {"lj", SETLINEJOIN}, - {"ml", SETMITERLIMIT}, - {"lc", SETLINECAP}, - {"S", STROKE}, - {"F", FILL}, - {"q", GSAVE}, - {"Q", GRESTORE}, - {"s", SCALE}, - {"t", CONCAT}, - {"sd", SETDASH}, - {"rd", RD}, /* [] 0 setdash */ - {"P", SHOWPAGE}, - {"B", B}, /* gsave fill grestore */ - {"W", CLIP} -}; - -#define NUM_PS_OPERATORS (sizeof(ps_operators)/sizeof(ps_operators[0])) -#define NUM_MPS_OPERATORS (sizeof(mps_operators)/sizeof(mps_operators[0])) -static int -get_opcode (const char *token) -{ - int i; - - for (i = 0; i < NUM_PS_OPERATORS; i++) { - if (!strcmp(token, ps_operators[i].token)) { - return ps_operators[i].opcode; - } - } - - for (i = 0; i < NUM_MPS_OPERATORS; i++) { - if (!strcmp(token, mps_operators[i].token)) { - return mps_operators[i].opcode; - } - } - - return -1; -} - -#define PS_STACK_SIZE 1024 - -static pdf_obj *stack[PS_STACK_SIZE]; -static unsigned top_stack = 0; - -#define POP_STACK() ((top_stack > 0) ? stack[--top_stack] : NULL) -#define PUSH_STACK(o,e) { \ - if (top_stack < PS_STACK_SIZE) { \ - stack[top_stack++] = (o); \ - } else { \ - WARN("PS stack overflow including MetaPost file or inline PS code"); \ - *(e) = 1; \ - } \ -} - -static int -do_exch (void) -{ - pdf_obj *tmp; - - if (top_stack < 2) - return -1; - - tmp = stack[top_stack-1]; - stack[top_stack-1] = stack[top_stack-2]; - stack[top_stack-2] = tmp; - - return 0; -} - -static int -do_clear (void) -{ - pdf_obj *tmp; - - while (top_stack > 0) { - tmp = POP_STACK(); - if (tmp) - pdf_release_obj(tmp); - } - - return 0; -} - -/* This should be set_bottom and clear (or - * have independent stack) to ensure stack - * depth do not go below real stack bottom. - */ -static void -mps_stack_clear_to (int depth) -{ - pdf_obj *tmp; - - while (top_stack > depth) { - tmp = POP_STACK(); - if (tmp) - pdf_release_obj(tmp); - } - - return; -} - -static int -pop_get_numbers (double *values, int count) -{ - pdf_obj *tmp; - - while (count-- > 0) { - tmp = POP_STACK(); - if (!tmp) { - WARN("mpost: Stack underflow."); - break; - } else if (!PDF_OBJ_NUMBERTYPE(tmp)) { - WARN("mpost: Not a number!"); - pdf_release_obj(tmp); - break; - } - values[count] = pdf_number_value(tmp); - pdf_release_obj(tmp); - } - - return (count + 1); -} - -static int -cvr_array (pdf_obj *array, double *values, int count) -{ - if (!PDF_OBJ_ARRAYTYPE(array)) { - WARN("mpost: Not an array!"); - } else { - pdf_obj *tmp; - - while (count-- > 0) { - tmp = pdf_get_array(array, count); - if (!PDF_OBJ_NUMBERTYPE(tmp)) { - WARN("mpost: Not a number!"); - break; - } - values[count] = pdf_number_value(tmp); - } - } - if (array) - pdf_release_obj(array); - - return (count + 1); -} - -static int -is_fontdict (pdf_obj *dict) -{ - pdf_obj *tmp; - - if (!PDF_OBJ_DICTTYPE(dict)) - return 0; - - tmp = pdf_lookup_dict(dict, "Type"); - if (!tmp || !PDF_OBJ_NAMETYPE(tmp) || - strcmp(pdf_name_value(tmp), "Font")) { - return 0; - } - - tmp = pdf_lookup_dict(dict, "FontName"); - if (!tmp || !PDF_OBJ_NAMETYPE(tmp)) { - return 0; - } - - tmp = pdf_lookup_dict(dict, "FontScale"); - if (!tmp || !PDF_OBJ_NUMBERTYPE(tmp)) { - return 0; - } - - return 1; -} - -static int -do_findfont (void) -{ - int error = 0; - pdf_obj *font_dict, *font_name; - - font_name = POP_STACK(); - if (!font_name) - return 1; - else if (PDF_OBJ_STRINGTYPE(font_name) || - PDF_OBJ_NAMETYPE(font_name)) { - /* Do not check the existence... - * The reason for this is that we cannot locate PK font without - * font scale. - */ - font_dict = pdf_new_dict(); - pdf_add_dict(font_dict, - pdf_new_name("Type"), pdf_new_name("Font")); - if (PDF_OBJ_STRINGTYPE(font_name)) { - pdf_add_dict(font_dict, - pdf_new_name("FontName"), - pdf_new_name(pdf_string_value(font_name))); - pdf_release_obj(font_name); - } else { - pdf_add_dict(font_dict, - pdf_new_name("FontName"), font_name); - } - pdf_add_dict(font_dict, - pdf_new_name("FontScale"), pdf_new_number(1.0)); - - if (top_stack < PS_STACK_SIZE) { - stack[top_stack++] = font_dict; - } else { - WARN("PS stack overflow including MetaPost file or inline PS code"); - pdf_release_obj(font_dict); - error = 1; - } - } else { - error = 1; - } - - return error; -} - -static int -do_scalefont (void) -{ - int error = 0; - pdf_obj *font_dict; - pdf_obj *font_scale; - double scale; - - error = pop_get_numbers(&scale, 1); - if (error) - return error; - - font_dict = POP_STACK(); - if (!font_dict) - error = 1; - else if (is_fontdict(font_dict)) { - font_scale = pdf_lookup_dict(font_dict, "FontScale"); - pdf_set_number(font_scale, pdf_number_value(font_scale)*scale); - if (top_stack < PS_STACK_SIZE) { - stack[top_stack++] = font_dict; - } else { - WARN("PS stack overflow including MetaPost file or inline PS code"); - pdf_release_obj(font_dict); - error = 1; - } - } else { - error = 1; - } - - return error; -} - -static int -do_setfont (void) -{ - int error = 0; - char *font_name; - double font_scale; - pdf_obj *font_dict; - - font_dict = POP_STACK(); - if (!is_fontdict(font_dict)) - error = 1; - else { - /* Subfont support prevent us from managing - * font in a single place... - */ - font_name = pdf_name_value (pdf_lookup_dict(font_dict, "FontName")); - font_scale = pdf_number_value(pdf_lookup_dict(font_dict, "FontScale")); - - error = mp_setfont(font_name, font_scale); - } - pdf_release_obj(font_dict); - - return error; -} - -/* Push dummy font dict onto PS stack */ -static int -do_currentfont (void) -{ - int error = 0; - struct mp_font *font; - pdf_obj *font_dict; - - font = CURRENT_FONT(); - if (!font) { - WARN("Currentfont undefined..."); - return 1; - } else { - font_dict = pdf_new_dict(); - pdf_add_dict(font_dict, - pdf_new_name("Type"), - pdf_new_name("Font")); - pdf_add_dict(font_dict, - pdf_new_name("FontName"), - pdf_new_name(font->font_name)); - pdf_add_dict(font_dict, - pdf_new_name("FontScale"), - pdf_new_number(font->pt_size)); - if (top_stack < PS_STACK_SIZE) { - stack[top_stack++] = font_dict; - } else { - WARN("PS stack overflow..."); - pdf_release_obj(font_dict); - error = 1; - } - } - - return error; -} - -static int -do_show (void) -{ - struct mp_font *font; - pdf_coord cp; - pdf_obj *text_str; - int length; - unsigned char *strptr; - double text_width; - - font = CURRENT_FONT(); - if (!font) { - WARN("Currentfont not set."); /* Should not be error... */ - return 1; - } - - pdf_dev_currentpoint(&cp); - - text_str = POP_STACK(); - if (!PDF_OBJ_STRINGTYPE(text_str)) { - if (text_str) - pdf_release_obj(text_str); - return 1; - } - if (font->font_id < 0) { - WARN("mpost: not set."); /* Should not be error... */ - pdf_release_obj(text_str); - return 1; - } - - strptr = pdf_string_value (text_str); - length = pdf_string_length(text_str); - - if (font->tfm_id < 0) { - WARN("mpost: TFM not found for \"%s\".", font->font_name); - WARN("mpost: Text width not calculated..."); - } - - text_width = 0.0; - if (font->subfont_id >= 0) { - unsigned short uch; - unsigned char *ustr; - int i; - - ustr = NEW(length * 2, unsigned char); - for (i = 0; i < length; i++) { - uch = lookup_sfd_record(font->subfont_id, strptr[i]); - ustr[2*i ] = uch >> 8; - ustr[2*i+1] = uch & 0xff; - if (font->tfm_id >= 0) { - text_width += tfm_get_width(font->tfm_id, strptr[i]); - } - } - text_width *= font->pt_size; - - pdf_dev_set_string((spt_t)(cp.x * dev_unit_dviunit()), - (spt_t)(cp.y * dev_unit_dviunit()), - ustr, length * 2, - (spt_t)(text_width*dev_unit_dviunit()), - font->font_id, 0); - RELEASE(ustr); - } else { -#define FWBASE ((double) (1<<20)) - if (font->tfm_id >= 0) { - text_width = (double) tfm_string_width(font->tfm_id, strptr, length)/FWBASE; - text_width *= font->pt_size; - } - pdf_dev_set_string((spt_t)(cp.x * dev_unit_dviunit()), - (spt_t)(cp.y * dev_unit_dviunit()), - strptr, length, - (spt_t)(text_width*dev_unit_dviunit()), - font->font_id, 0); - } - - if (pdf_dev_get_font_wmode(font->font_id)) { - pdf_dev_rmoveto(0.0, -text_width); - } else { - pdf_dev_rmoveto(text_width, 0.0); - } - - graphics_mode(); - pdf_release_obj(text_str); - - return 0; -} - -static int -do_mpost_bind_def (const char *ps_code, double x_user, double y_user) -{ - int error = 0; - const char *start, *end; - - start = ps_code; - end = start + strlen(start); - - error = mp_parse_body(&start, end, x_user, y_user); - - return error; -} - -static int -do_texfig_operator (int opcode, double x_user, double y_user) -{ - static transform_info fig_p; - static int in_tfig = 0; - static int xobj_id = -1; - static int count = 0; - double values[6]; - int error = 0; - - switch (opcode) { - case STEXFIG: - error = pop_get_numbers(values, 6); - if (!error) { - double dvi2pts; - char resname[256]; - - transform_info_clear(&fig_p); - dvi2pts = 1.0/dev_unit_dviunit(); - - fig_p.width = values[0] * dvi2pts; - fig_p.height = values[1] * dvi2pts; - fig_p.bbox.llx = values[2] * dvi2pts; - fig_p.bbox.lly = -values[3] * dvi2pts; - fig_p.bbox.urx = values[4] * dvi2pts; - fig_p.bbox.ury = -values[5] * dvi2pts; - fig_p.flags |= INFO_HAS_USER_BBOX; - - sprintf(resname, "__tf%d__", count); - xobj_id = pdf_doc_begin_grabbing(resname, - fig_p.bbox.llx, fig_p.bbox.ury, &fig_p.bbox); - - in_tfig = 1; - count++; - } - break; - case ETEXFIG: - if (!in_tfig) - ERROR("endTexFig without valid startTexFig!."); - - pdf_doc_end_grabbing(NULL); - pdf_dev_put_image(xobj_id, &fig_p, x_user, y_user); - in_tfig = 0; - break; - default: - error = 1; - } - - return error; -} - -/* - * buggy... - */ - -/* - * CTM(Current Transformation Matrix) means the transformation of User Space - * to Device Space coordinates. Because DVIPDFMx does not know the resolution - * of Device Space, we assume that the resolution is 1/1000. - */ -#define DEVICE_RESOLUTION 1000 -static int -ps_dev_CTM (pdf_tmatrix *M) -{ - pdf_dev_currentmatrix(M); - M->a *= DEVICE_RESOLUTION; M->b *= DEVICE_RESOLUTION; - M->c *= DEVICE_RESOLUTION; M->d *= DEVICE_RESOLUTION; - M->e *= DEVICE_RESOLUTION; M->f *= DEVICE_RESOLUTION; - - return 0; -} - -/* - * Again, the only piece that needs x_user and y_user is - * that piece dealing with texfig. - */ -static int -do_operator (const char *token, double x_user, double y_user) -{ - int error = 0; - int opcode = 0; - double values[12]; - pdf_obj *tmp = NULL; - pdf_tmatrix matrix; - pdf_coord cp; - pdf_color color; - -#define PUSH(o) { \ - if (top_stack < PS_STACK_SIZE) { \ - stack[top_stack++] = (o); \ - } else { \ - WARN("PS stack overflow including MetaPost file or inline PS code"); \ - error=1; \ - break;\ - } \ -} - - opcode = get_opcode(token); - - switch (opcode) { - - /* - * Arithmetic operators - */ - case ADD: - error = pop_get_numbers(values, 2); - if (!error) - PUSH(pdf_new_number(values[0] + values[1])); - break; - case MUL: - error = pop_get_numbers(values, 2); - if (!error) - PUSH(pdf_new_number(values[0]*values[1])); - break; - case NEG: - error = pop_get_numbers(values, 1); - if (!error) - PUSH(pdf_new_number(-values[0])); - break; - case SUB: - error = pop_get_numbers(values, 2); - if (!error) - PUSH(pdf_new_number(values[0] - values[1])); - break; - case DIV: - error = pop_get_numbers(values, 2); - if (!error) - PUSH(pdf_new_number(values[0]/values[1])); - break; - case TRUNCATE: /* Round toward zero. */ - error = pop_get_numbers(values, 1); - if (!error) - PUSH(pdf_new_number(((values[0] > 0) ? floor(values[0]) : ceil(values[0])))); - break; - - /* Stack operation */ - case CLEAR: - error = do_clear(); - break; - case POP: - tmp = POP_STACK(); - if (tmp) - pdf_release_obj(tmp); - break; - case EXCH: - error = do_exch(); - break; - - /* Path construction */ - case MOVETO: - error = pop_get_numbers(values, 2); - if (!error) - error = pdf_dev_moveto(values[0], values[1]); - break; - case RMOVETO: - error = pop_get_numbers(values, 2); - if (!error) - error = pdf_dev_rmoveto(values[0], values[1]); - break; - case LINETO: - error = pop_get_numbers(values, 2); - if (!error) - error = pdf_dev_lineto(values[0], values[1]); - break; - case RLINETO: - error = pop_get_numbers(values, 2); - if (!error) - error = pdf_dev_rlineto(values[0], values[1]); - break; - case CURVETO: - error = pop_get_numbers(values, 6); - if (!error) - error = pdf_dev_curveto(values[0], values[1], - values[2], values[3], - values[4], values[5]); - break; - case RCURVETO: - error = pop_get_numbers(values, 6); - if (!error) - error = pdf_dev_rcurveto(values[0], values[1], - values[2], values[3], - values[4], values[5]); - break; - case CLOSEPATH: - error = pdf_dev_closepath(); - break; - case ARC: - error = pop_get_numbers(values, 5); - if (!error) - error = pdf_dev_arc(values[0], values[1], - values[2], /* rad */ - values[3], values[4]); - break; - case ARCN: - error = pop_get_numbers(values, 5); - if (!error) - error = pdf_dev_arcn(values[0], values[1], - values[2], /* rad */ - values[3], values[4]); - break; - - case NEWPATH: - pdf_dev_newpath(); - break; - case STROKE: - /* fill rule not supported yet */ - pdf_dev_flushpath('S', PDF_FILL_RULE_NONZERO); - break; - case FILL: - pdf_dev_flushpath('f', PDF_FILL_RULE_NONZERO); - break; - - case CLIP: - error = pdf_dev_clip(); - break; - case EOCLIP: - error = pdf_dev_eoclip(); - break; - - /* Graphics state operators: */ - case GSAVE: - error = pdf_dev_gsave(); - save_font(); - break; - case GRESTORE: - error = pdf_dev_grestore(); - restore_font(); - break; - - case CONCAT: - tmp = POP_STACK(); - error = cvr_array(tmp, values, 6); /* This does pdf_release_obj() */ - tmp = NULL; - if (error) - WARN("Missing array before \"concat\"."); - else { - pdf_setmatrix(&matrix, - values[0], values[1], - values[2], values[3], - values[4], values[5]); - error = pdf_dev_concat(&matrix); - } - break; - case SCALE: - error = pop_get_numbers(values, 2); - if (!error) { - switch (mp_cmode) { -#ifndef WITHOUT_ASCII_PTEX - case MP_CMODE_PTEXVERT: - pdf_setmatrix(&matrix, - values[1], 0.0, - 0.0 , values[0], - 0.0 , 0.0); - break; -#endif /* !WITHOUT_ASCII_PTEX */ - default: - pdf_setmatrix(&matrix, - values[0], 0.0, - 0.0 , values[1], - 0.0 , 0.0); - break; - } - - error = pdf_dev_concat(&matrix); - } - break; - /* Positive angle means clock-wise direction in graphicx-dvips??? */ - case ROTATE: - error = pop_get_numbers(values, 1); - if (!error) { - values[0] = values[0] * M_PI / 180; - - switch (mp_cmode) { - case MP_CMODE_DVIPSK: - case MP_CMODE_MPOST: /* Really? */ -#ifndef WITHOUT_ASCII_PTEX - case MP_CMODE_PTEXVERT: -#endif /* !WITHOUT_ASCII_PTEX */ - pdf_setmatrix(&matrix, - cos(values[0]), -sin(values[0]), - sin(values[0]), cos(values[0]), - 0.0, 0.0); - break; - default: - pdf_setmatrix(&matrix, - cos(values[0]) , sin(values[0]), - -sin(values[0]), cos(values[0]), - 0.0, 0.0); - break; - } - error = pdf_dev_concat(&matrix); - } - break; - case TRANSLATE: - error = pop_get_numbers(values, 2); - if (!error) { - pdf_setmatrix(&matrix, - 1.0, 0.0, - 0.0, 1.0, - values[0], values[1]); - error = pdf_dev_concat(&matrix); - } - break; - - case SETDASH: - error = pop_get_numbers(values, 1); - if (!error) { - pdf_obj *pattern, *dash; - int i, num_dashes; - double dash_values[PDF_DASH_SIZE_MAX]; - double offset; - - offset = values[0]; - pattern = POP_STACK(); - if (!PDF_OBJ_ARRAYTYPE(pattern)) { - if (pattern) - pdf_release_obj(pattern); - error = 1; - break; - } - num_dashes = pdf_array_length(pattern); - if (num_dashes > PDF_DASH_SIZE_MAX) { - WARN("Too many dashes..."); - pdf_release_obj(pattern); - error = 1; - break; - } - for (i = 0; - i < num_dashes && !error ; i++) { - dash = pdf_get_array(pattern, i); - if (!PDF_OBJ_NUMBERTYPE(dash)) - error = 1; - else { - dash_values[i] = pdf_number_value(dash); - } - } - pdf_release_obj(pattern); - if (!error) { - error = pdf_dev_setdash(num_dashes, dash_values, offset); - } - } - break; - case SETLINECAP: - error = pop_get_numbers(values, 1); - if (!error) - error = pdf_dev_setlinecap((int)values[0]); - break; - case SETLINEJOIN: - error = pop_get_numbers(values, 1); - if (!error) - error = pdf_dev_setlinejoin((int)values[0]); - break; - case SETLINEWIDTH: - error = pop_get_numbers(values, 1); - if (!error) - error = pdf_dev_setlinewidth(values[0]); - break; - case SETMITERLIMIT: - error = pop_get_numbers(values, 1); - if (!error) - error = pdf_dev_setmiterlimit(values[0]); - break; - - case SETCMYKCOLOR: - error = pop_get_numbers(values, 4); - /* Not handled properly */ - if (!error) { - pdf_color_cmykcolor(&color, - values[0], values[1], - values[2], values[3]); - pdf_dev_set_color(&color); - } - break; - case SETGRAY: - /* Not handled properly */ - error = pop_get_numbers(values, 1); - if (!error) { - pdf_color_graycolor(&color, values[0]); - pdf_dev_set_color(&color); - } - break; - case SETRGBCOLOR: - error = pop_get_numbers(values, 3); - if (!error) { - pdf_color_rgbcolor(&color, - values[0], values[1], values[2]); - pdf_dev_set_color(&color); - } - break; - - case SHOWPAGE: /* Let's ignore this for now */ - break; - - case CURRENTPOINT: - error = pdf_dev_currentpoint(&cp); - if (!error) { - PUSH(pdf_new_number(cp.x)); - PUSH(pdf_new_number(cp.y)); - } - break; - - case DTRANSFORM: - { - int has_matrix = 0; - - tmp = POP_STACK(); - if (PDF_OBJ_ARRAYTYPE(tmp)) { - error = cvr_array(tmp, values, 6); /* This does pdf_release_obj() */ - tmp = NULL; - if (error) - break; - pdf_setmatrix(&matrix, - values[0], values[1], - values[2], values[3], - values[4], values[5]); - tmp = POP_STACK(); - has_matrix = 1; - } - - if (!PDF_OBJ_NUMBERTYPE(tmp)) { - error = 1; - break; - } - cp.y = pdf_number_value(tmp); - pdf_release_obj(tmp); - - tmp = POP_STACK(); - if (!PDF_OBJ_NUMBERTYPE(tmp)) { - error = 1; - break; - } - cp.x = pdf_number_value(tmp); - pdf_release_obj(tmp); - - if (!has_matrix) { - ps_dev_CTM(&matrix); /* Here, we need real PostScript CTM */ - } - pdf_dev_dtransform(&cp, &matrix); - PUSH(pdf_new_number(cp.x)); - PUSH(pdf_new_number(cp.y)); - } - break; - - case IDTRANSFORM: - { - int has_matrix = 0; - - tmp = POP_STACK(); - if (PDF_OBJ_ARRAYTYPE(tmp)) { - error = cvr_array(tmp, values, 6); /* This does pdf_release_obj() */ - tmp = NULL; - if (error) - break; - pdf_setmatrix(&matrix, - values[0], values[1], - values[2], values[3], - values[4], values[5]); - tmp = POP_STACK(); - has_matrix = 1; - } - - if (!PDF_OBJ_NUMBERTYPE(tmp)) { - error = 1; - break; - } - cp.y = pdf_number_value(tmp); - pdf_release_obj(tmp); - - tmp = POP_STACK(); - if (!PDF_OBJ_NUMBERTYPE(tmp)) { - error = 1; - break; - } - cp.x = pdf_number_value(tmp); - pdf_release_obj(tmp); - - if (!has_matrix) { - ps_dev_CTM(&matrix); /* Here, we need real PostScript CTM */ - } - pdf_dev_idtransform(&cp, &matrix); - PUSH(pdf_new_number(cp.x)); - PUSH(pdf_new_number(cp.y)); - break; - } - - case FINDFONT: - error = do_findfont(); - break; - case SCALEFONT: - error = do_scalefont(); - break; - case SETFONT: - error = do_setfont(); - break; - case CURRENTFONT: - error = do_currentfont(); - break; - - case SHOW: - error = do_show(); - break; - - case STRINGWIDTH: - error = 1; - break; - - /* Extensions */ - case FSHOW: - error = do_mpost_bind_def("exch findfont exch scalefont setfont show", x_user, y_user); - break; - case STEXFIG: - case ETEXFIG: - error = do_texfig_operator(opcode, x_user, y_user); - break; - case HLW: - error = do_mpost_bind_def("0 dtransform exch truncate exch idtransform pop setlinewidth", x_user, y_user); - break; - case VLW: - error = do_mpost_bind_def("0 exch dtransform truncate idtransform setlinewidth pop", x_user, y_user); - break; - case RD: - error = do_mpost_bind_def("[] 0 setdash", x_user, y_user); - break; - case B: - error = do_mpost_bind_def("gsave fill grestore", x_user, y_user); - break; - - case DEF: - tmp = POP_STACK(); - tmp = POP_STACK(); - /* do nothing; not implemented yet */ - break; - - default: - if (is_fontname(token)) { - PUSH(pdf_new_name(token)); - } else { - WARN("Unknown token \"%s\"", token); - error = 1; - } - break; - } - - return error; -} - -/* - * The only sections that need to know x_user and y _user are those - * dealing with texfig. - */ -static int -mp_parse_body (const char **start, const char *end, double x_user, double y_user) -{ - char *token; - pdf_obj *obj; - int error = 0; - - skip_white(start, end); - while (*start < end && !error) { - if (isdigit(**start) || - (*start < end - 1 && - (**start == '+' || **start == '-' || **start == '.' ))) { - double value; - char *next; - - value = strtod(*start, &next); - if (next < end && !strchr("<([{/%", *next) && !isspace(*next)) { - WARN("Unkown PostScript operator."); - dump(*start, next); - error = 1; - } else { - PUSH(pdf_new_number(value)); - *start = next; - } - /* - * PDF parser can't handle PS operator inside arrays. - * This shouldn't use parse_pdf_array(). - */ - } else if (**start == '[' && - (obj = parse_pdf_array(start, end, NULL))) { - PUSH(obj); - /* This cannot handle ASCII85 string. */ - } else if (*start < end - 1 && - (**start == '<' && *(*start+1) == '<') && - (obj = parse_pdf_dict(start, end, NULL))) { - PUSH(obj); - } else if ((**start == '(' || **start == '<') && - (obj = parse_pdf_string (start, end))) { - PUSH(obj); - } else if (**start == '/' && - (obj = parse_pdf_name(start, end))) { - PUSH(obj); - } else { - token = parse_ident(start, end); - if (!token) - error = 1; - else { - error = do_operator(token, x_user, y_user); - RELEASE(token); - } - } - skip_white(start, end); - } - - return error; -} - -void -mps_eop_cleanup (void) -{ - clear_fonts(); - do_clear(); -} - -int -mps_stack_depth (void) -{ - return top_stack; -} - -int -mps_exec_inline (const char **p, const char *endptr, - double x_user, double y_user) -{ - int error; - int dirmode, autorotate; - - /* Compatibility for dvipsk. */ - dirmode = pdf_dev_get_dirmode(); - if (dirmode) { - mp_cmode = MP_CMODE_PTEXVERT; - } else { - mp_cmode = MP_CMODE_DVIPSK; - } - - autorotate = pdf_dev_get_param(PDF_DEV_PARAM_AUTOROTATE); - pdf_dev_set_param(PDF_DEV_PARAM_AUTOROTATE, 0); - //pdf_color_push(); /* ... */ - - /* Comment in dvipdfm: - * Remember that x_user and y_user are off by 0.02 % - */ - pdf_dev_moveto(x_user, y_user); - error = mp_parse_body(p, endptr, x_user, y_user); - - //pdf_color_pop(); /* ... */ - pdf_dev_set_param(PDF_DEV_PARAM_AUTOROTATE, autorotate); - pdf_dev_set_dirmode(dirmode); - - return error; -} - -/* mp inclusion is a bit of a hack. The routine - * starts a form at the lower left corner of - * the page and then calls begin_form_xobj telling - * it to record the image drawn there and bundle it - * up in an xojbect. This allows us to use the coordinates - * in the MP file directly. This appears to be the - * easiest way to be able to use the pdf_dev_set_string() - * command (with its scaled and extended fonts) without - * getting all confused about the coordinate system. - * After the xobject is created, the whole thing can - * be scaled any way the user wants - */ - -/* Should implement save and restore. */ -int -mps_include_page (const char *ident, FILE *fp) -{ - int form_id; - xform_info info; - int st_depth, gs_depth; - char *buffer; - const char *p, *endptr; - long length, nb_read; - int dirmode, autorotate, error; - - rewind(fp); - - length = file_size(fp); - if (length < 1) { - WARN("Can't read any byte in the MPS file."); - return -1; - } - - buffer = NEW(length + 1, char); - buffer[length] = '\0'; - p = buffer; - endptr = p + length; - - while (length > 0) { - nb_read = fread(buffer, sizeof(char), length, fp); - if (nb_read < 0) { - RELEASE(buffer); - WARN("Reading file failed..."); - return -1; - } - length -= nb_read; - } - - error = mps_scan_bbox(&p, endptr, &(info.bbox)); - if (error) { - WARN("Error occured while scanning MetaPost file headers: Could not find BoundingBox."); - RELEASE(buffer); - return -1; - } - skip_prolog(&p, endptr); - - dirmode = pdf_dev_get_dirmode(); - autorotate = pdf_dev_get_param(PDF_DEV_PARAM_AUTOROTATE); - pdf_dev_set_param(PDF_DEV_PARAM_AUTOROTATE, 0); - //pdf_color_push(); - - form_id = pdf_doc_begin_grabbing(ident, 0.0, 0.0, &(info.bbox)); - - mp_cmode = MP_CMODE_MPOST; - gs_depth = pdf_dev_current_depth(); - st_depth = mps_stack_depth(); - /* At this point the gstate must be initialized, since it starts a new - * XObject. Note that it increase gs_depth by 1. */ - pdf_dev_push_gstate(); - - error = mp_parse_body(&p, endptr, 0.0, 0.0); - RELEASE(buffer); - - if (error) { - WARN("Errors occured while interpreting MPS file."); - /* WARN("Leaving garbage in output PDF file."); */ - form_id = -1; - } - - /* It's time to pop the new gstate above. */ - pdf_dev_pop_gstate(); - mps_stack_clear_to (st_depth); - pdf_dev_grestore_to(gs_depth); - - pdf_doc_end_grabbing(NULL); - - //pdf_color_pop(); - pdf_dev_set_param(PDF_DEV_PARAM_AUTOROTATE, autorotate); - pdf_dev_set_dirmode(dirmode); - - return form_id; -} - -int -mps_do_page (FILE *image_file) -{ - int error = 0; - pdf_rect bbox; - char *buffer; - const char *start, *end; - long size; - int dir_mode; - - rewind(image_file); - if ((size = file_size(image_file)) == 0) { - WARN("Can't read any byte in the MPS file."); - return -1; - } - - buffer = NEW(size+1, char); - fread(buffer, sizeof(char), size, image_file); - buffer[size] = 0; - start = buffer; - end = buffer + size; - - error = mps_scan_bbox(&start, end, &bbox); - if (error) { - WARN("Error occured while scanning MetaPost file headers: Could not find BoundingBox."); - RELEASE(buffer); - return -1; - } - - mp_cmode = MP_CMODE_MPOST; - - pdf_doc_begin_page (1.0, 0.0, 0.0); /* scale, xorig, yorig */ - pdf_doc_set_mediabox(pdf_doc_current_page_number(), &bbox); - - dir_mode = pdf_dev_get_dirmode(); - pdf_dev_set_autorotate(0); - - skip_prolog(&start, end); - - error = mp_parse_body(&start, end, 0.0, 0.0); - - if (error) { - WARN("Errors occured while interpreting MetaPost file."); - } - - pdf_dev_set_autorotate(1); - pdf_dev_set_dirmode(dir_mode); - - pdf_doc_end_page(); - - RELEASE(buffer); - - /* - * The reason why we don't return XObject itself is - * PDF inclusion may not be made so. - */ - return (error ? -1 : 0); -} - -int -check_for_mp (FILE *image_file) -{ - int try_count = 10; - - rewind (image_file); - mfgets(work_buffer, WORK_BUFFER_SIZE, image_file); - if (strncmp(work_buffer, "%!PS", 4)) - return 0; - - while (try_count > 0) { - mfgets(work_buffer, WORK_BUFFER_SIZE, image_file); - if (!strncmp(work_buffer, "%%Creator:", 10)) { - if (strlen(work_buffer+10) >= 8 && - strstr(work_buffer+10, "MetaPost")) - break; - } - try_count--; - } - - return ((try_count > 0) ? 1 : 0); -} diff --git a/Build/source/texk/dvipdfm-x/xsrc/pdfdev.h b/Build/source/texk/dvipdfm-x/xsrc/pdfdev.h deleted file mode 100644 index 6df1e91054d..00000000000 --- a/Build/source/texk/dvipdfm-x/xsrc/pdfdev.h +++ /dev/null @@ -1,233 +0,0 @@ -/* - - This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - - Copyright (C) 2002-2012 by Jin-Hwan Cho and Shunsaku Hirata, - the dvipdfmx project team. - - Copyright (C) 1998, 1999 by Mark A. Wicks - - This program 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; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -*/ - -#ifndef _PDFDEV_H_ -#define _PDFDEV_H_ - -#include "numbers.h" -#include "pdfobj.h" -#include "pdfcolor.h" - -typedef signed long spt_t; - -typedef struct pdf_tmatrix -{ - double a, b, c, d, e, f; -} pdf_tmatrix; - -typedef struct pdf_rect -{ - double llx, lly, urx, ury; -} pdf_rect; - -typedef struct pdf_coord -{ - double x, y; -} pdf_coord; - -/* The name transform_info is misleading. - * I'll put this here for a moment... - */ -typedef struct -{ - /* Physical dimensions - * - * If those values are given, images will be scaled - * and/or shifted to fit within a box described by - * those values. - */ - double width; - double height; - double depth; - - pdf_tmatrix matrix; /* transform matrix */ - pdf_rect bbox; /* user_bbox */ - - int flags; -} transform_info; -#define INFO_HAS_USER_BBOX (1 << 0) -#define INFO_HAS_WIDTH (1 << 1) -#define INFO_HAS_HEIGHT (1 << 2) -#define INFO_DO_CLIP (1 << 3) -#define INFO_DO_HIDE (1 << 4) -extern void transform_info_clear (transform_info *info); - - -extern void pdf_dev_set_verbose (void); - -/* Not in spt_t. */ -extern int pdf_sprint_matrix (char *buf, const pdf_tmatrix *p); -extern int pdf_sprint_rect (char *buf, const pdf_rect *p); -extern int pdf_sprint_coord (char *buf, const pdf_coord *p); -extern int pdf_sprint_length (char *buf, double value); -extern int pdf_sprint_number (char *buf, double value); - -/* unit_conv: multiplier for input unit (spt_t) to bp conversion. - * precision: How many fractional digits preserved in output (not real - * accuracy control). - * is_bw: Ignore color related special instructions. - */ -extern void pdf_init_device (double unit_conv, int precision, int is_bw); -extern void pdf_close_device (void); - -/* returns 1.0/unit_conv */ -extern double dev_unit_dviunit (void); - -#if 0 -/* DVI interpreter knows text positioning in relative motion. - * However, pdf_dev_set_string() recieves text string with placement - * in absolute position in user space, and it convert absolute - * positioning back to relative positioning. It is quite wasteful. - * - * TeX using DVI register stack operation to do CR and then use down - * command for LF. DVI interpreter knows hint for current leading - * and others (raised or lowered), but they are mostly lost in - * pdf_dev_set_string(). - */ - -typedef struct -{ - int argc; - - struct { - int is_kern; /* kern or string */ - - spt_t kern; /* negative kern means space */ - - int offset; /* offset to sbuf */ - int length; /* length of string */ - } args[]; - - unsigned char sbuf[PDF_STRING_LEN_MAX]; - -} pdf_text_string; - -/* Something for handling raise, leading, etc. here. */ - -#endif - -/* Draw texts and rules: - * - * xpos, ypos, width, and height are all fixed-point numbers - * converted to big-points by multiplying unit_conv (dvi2pts). - * They must be position in the user space. - * - * ctype: - * 0 - input string is in multi-byte encoding. - * 1 - input string is in 8-bit encoding. - * 2 - input string is in 16-bit encoding. - */ -extern void pdf_dev_set_string (spt_t xpos, spt_t ypos, - const void *instr_ptr, int instr_len, - spt_t text_width, - int font_id, int ctype); -extern void pdf_dev_set_rule (spt_t xpos, spt_t ypos, - spt_t width, spt_t height); - -/* Place XObject */ -extern int pdf_dev_put_image (int xobj_id, - transform_info *p, double ref_x, double ref_y); - -/* The design_size and ptsize required by PK font support... - */ -extern int pdf_dev_locate_font (const char *font_name, spt_t ptsize); - -extern int pdf_dev_setfont (const char *font_name, spt_t ptsize); - -/* The following two routines are NOT WORKING. - * Dvipdfmx doesn't manage gstate well.. - */ -#ifdef XETEX -/* pdf_dev_translate() or pdf_dev_concat() should be used. */ -extern void pdf_dev_set_origin (double orig_x, double orig_y); -#endif -/* Always returns 1.0, please rename this. */ -extern double pdf_dev_scale (void); - -/* Access text state parameters. */ -#if 0 -extern int pdf_dev_currentfont (void); /* returns font_id */ -extern double pdf_dev_get_font_ptsize (int font_id); -#endif -extern int pdf_dev_get_font_wmode (int font_id); /* ps: special support want this (pTeX). */ - -/* Text composition (direction) mode - * This affects only when auto_rotate is enabled. - */ -extern int pdf_dev_get_dirmode (void); -extern void pdf_dev_set_dirmode (int dir_mode); - -/* Set rect to rectangle in device space. - * Unit conversion spt_t to bp and transformation applied within it. - */ -extern void pdf_dev_set_rect (pdf_rect *rect, - spt_t x_pos, spt_t y_pos, - spt_t width, spt_t height, spt_t depth); - -/* Accessor to various device parameters. - */ -#define PDF_DEV_PARAM_AUTOROTATE 1 -#define PDF_DEV_PARAM_COLORMODE 2 - -extern int pdf_dev_get_param (int param_type); -extern void pdf_dev_set_param (int param_type, int value); - -/* Text composition mode is ignored (always same as font's - * writing mode) and glyph rotation is not enabled if - * auto_rotate is unset. - */ -#define pdf_dev_set_autorotate(v) pdf_dev_set_param(PDF_DEV_PARAM_AUTOROTATE, (v)) -#define pdf_dev_set_colormode(v) pdf_dev_set_param(PDF_DEV_PARAM_COLORMODE, (v)) - -/* - * For pdf_doc, pdf_draw and others. - */ - -/* Force reselecting font and color: - * XFrom (content grabbing) and Metapost support want them. - */ -extern void pdf_dev_reset_fonts (void); -extern void pdf_dev_reset_color (void); - -extern void pdf_dev_set_color (pdf_color *color); -extern void pdf_dev_set_strokingcolor (pdf_color *color); -extern void pdf_dev_set_nonstrokingcolor (pdf_color *color); - -/* Initialization of transformation matrix with M and others. - * They are called within pdf_doc_begin_page() and pdf_doc_end_page(). - */ -extern void pdf_dev_bop (const pdf_tmatrix *M); -extern void pdf_dev_eop (void); - -/* Text is normal and line art is not normal in dvipdfmx. So we don't have - * begin_text (BT in PDF) and end_text (ET), but instead we have graphics_mode() - * to terminate text section. pdf_dev_flushpath() and others call this. - */ -extern void graphics_mode (void); - -extern void pdf_dev_get_coord(double *xpos, double *ypos); -extern void pdf_dev_push_coord(double xpos, double ypos); -extern void pdf_dev_pop_coord(void); - -#endif /* _PDFDEV_H_ */ diff --git a/Build/source/texk/dvipdfm-x/xsrc/pdfdoc.h b/Build/source/texk/dvipdfm-x/xsrc/pdfdoc.h deleted file mode 100644 index 5e65da405e3..00000000000 --- a/Build/source/texk/dvipdfm-x/xsrc/pdfdoc.h +++ /dev/null @@ -1,137 +0,0 @@ -/* - - This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - - Copyright (C) 2007-2012 by Jin-Hwan Cho and Shunsaku Hirata, - the dvipdfmx project team. - - Copyright (C) 1998, 1999 by Mark A. Wicks - - This program 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; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -*/ - -#ifndef _PDFDOC_H_ -#define _PDFDOC_H_ - -#include "pdfobj.h" -#include "pdfdev.h" - -#define PDF_DOC_GRABBING_NEST_MAX 4 - -extern void pdf_doc_set_verbose (void); - -extern void pdf_open_document (const char *filename, - int do_encryption, - double media_width, double media_height, - double annot_grow_amount, int bookmark_open_depth); -extern void pdf_close_document (void); - - -/* PDF document metadata */ -extern void pdf_doc_set_creator (const char *creator); - - -/* They just return PDF dictionary object. - * Callers are completely responsible for doing right thing... - */ -extern pdf_obj *pdf_doc_get_dictionary (const char *category); -extern pdf_obj *pdf_doc_get_reference (const char *category); - -#define pdf_doc_page_tree() pdf_doc_get_dictionary("Pages") -#define pdf_doc_catalog() pdf_doc_get_dictionary("Catalog") -#define pdf_doc_docinfo() pdf_doc_get_dictionary("Info") -#define pdf_doc_names() pdf_doc_get_dictionary("Names") -#define pdf_doc_this_page() pdf_doc_get_dictionary("@THISPAGE") - -extern long pdf_doc_current_page_number (void); -extern pdf_obj *pdf_doc_current_page_resources (void); - -extern pdf_obj *pdf_doc_ref_page (unsigned long page_no); -#define pdf_doc_this_page_ref() pdf_doc_get_reference("@THISPAGE") -#define pdf_doc_next_page_ref() pdf_doc_get_reference("@NEXTPAGE") -#define pdf_doc_prev_page_ref() pdf_doc_get_reference("@PREVPAGE") - -/* Not really managing tree... - * There should be something for number tree. - */ -extern int pdf_doc_add_names (const char *category, - const void *key, int keylen, pdf_obj *value); - -extern void pdf_doc_set_bop_content (const char *str, unsigned length); -extern void pdf_doc_set_eop_content (const char *str, unsigned length); - -/* Page */ -extern void pdf_doc_begin_page (double scale, double x_origin, double y_origin); -extern void pdf_doc_end_page (void); - -extern void pdf_doc_set_mediabox (unsigned page_no, const pdf_rect *mediabox); -extern void pdf_doc_get_mediabox (unsigned page_no, pdf_rect *mediabox); - -extern void pdf_doc_add_page_content (const char *buffer, unsigned length); -extern void pdf_doc_add_page_resource (const char *category, - const char *resource_name, pdf_obj *resources); - -/* Article thread */ -extern void pdf_doc_begin_article (const char *article_id, pdf_obj *info); -#if 0 -extern void pdf_doc_end_article (const char *article_id); /* Do nothing... */ -#endif -extern void pdf_doc_make_article (const char *article_id, - const char **bead_order, int num_beads); -extern void pdf_doc_add_bead (const char *article_id, - const char *bead_id, - long page_no, const pdf_rect *rect); - -/* Bookmarks */ -extern int pdf_doc_bookmarks_up (void); -extern int pdf_doc_bookmarks_down (void); -extern void pdf_doc_bookmarks_add (pdf_obj *dict, int is_open); -extern int pdf_doc_bookmarks_depth (void); - - -/* Returns xobj_id of started xform. */ -extern int pdf_doc_begin_grabbing (const char *ident, - double ref_x, double ref_y, - const pdf_rect *cropbox); -extern void pdf_doc_end_grabbing (pdf_obj *attrib); - - -/* Annotation */ -extern void pdf_doc_add_annot (unsigned page_no, - const pdf_rect *rect, pdf_obj *annot_dict); - -/* Annotation with auto- clip and line (or page) break */ -extern void pdf_doc_begin_annot (pdf_obj *dict); -extern void pdf_doc_end_annot (void); - -extern void pdf_doc_break_annot (void); -extern void pdf_doc_expand_box (const pdf_rect *rect); - -/* Manual thumbnail */ -extern void pdf_doc_enable_manual_thumbnails (void); - -#if 0 -/* PageLabels - */ -extern void pdf_doc_set_pagelabel (long page_start, - const char *type, - const void *prefix, int pfrx_len, - long counter_start); -#endif - -/* Similar to bop_content */ -#include "pdfcolor.h" -extern void pdf_doc_set_bgcolor (const pdf_color *color); - -#endif /* _PDFDOC_H_ */ diff --git a/Build/source/texk/dvipdfm-x/xsrc/pdfdraw.h b/Build/source/texk/dvipdfm-x/xsrc/pdfdraw.h deleted file mode 100644 index f24540ef2bf..00000000000 --- a/Build/source/texk/dvipdfm-x/xsrc/pdfdraw.h +++ /dev/null @@ -1,172 +0,0 @@ -/* - - This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - - Copyright (C) 2002-2012 by Jin-Hwan Cho and Shunsaku Hirata, - the dvipdfmx project team. - - Copyright (C) 1998, 1999 by Mark A. Wicks - - This program 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; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -*/ - -#ifndef _PDF_DRAW_H_ -#define _PDF_DRAW_H_ - -#include "pdfcolor.h" -#include "pdfdev.h" - -#define PDF_DASH_SIZE_MAX 16 -#define PDF_GSAVE_MAX 256 - -extern void pdf_dev_init_gstates (void); -extern void pdf_dev_clear_gstates (void); - -#define pdf_copymatrix(m,n) do {\ - (m)->a = (n)->a; (m)->b = (n)->b;\ - (m)->c = (n)->c; (m)->d = (n)->d;\ - (m)->e = (n)->e; (m)->f = (n)->f;\ -} while (0) - -#define pdf_setmatrix(m,p,q,r,s,t,u) do {\ - (m)->a = (p); (m)->b = (q);\ - (m)->c = (r); (m)->d = (s);\ - (m)->e = (t); (m)->f = (u);\ -} while (0) - -/* m -> n x m */ -#define pdf_concatmatrix(m,n) do {\ - double _tmp_a, _tmp_b, _tmp_c, _tmp_d; \ - _tmp_a = (m)->a; _tmp_b = (m)->b; \ - _tmp_c = (m)->c; _tmp_d = (m)->d; \ - (m)->a = ((n)->a) * _tmp_a + ((n)->b) * _tmp_c; \ - (m)->b = ((n)->a) * _tmp_b + ((n)->b) * _tmp_d; \ - (m)->c = ((n)->c) * _tmp_a + ((n)->d) * _tmp_c; \ - (m)->d = ((n)->c) * _tmp_b + ((n)->d) * _tmp_d; \ - (m)->e += ((n)->e) * _tmp_a + ((n)->f) * _tmp_c; \ - (m)->f += ((n)->e) * _tmp_b + ((n)->f) * _tmp_d; \ -} while (0) - -typedef struct pdf_path_ pdf_path; - -extern int pdf_dev_currentmatrix (pdf_tmatrix *M); -extern int pdf_dev_currentpoint (pdf_coord *cp); - -extern int pdf_dev_setlinewidth (double width); -extern int pdf_dev_setmiterlimit (double mlimit); -extern int pdf_dev_setlinecap (int style); -extern int pdf_dev_setlinejoin (int style); -extern int pdf_dev_setdash (int count, - double *pattern, - double offset); -#if 0 -extern int pdf_dev_setflat (int flatness); -#endif /* 0 */ - -/* Path Construction */ -extern int pdf_dev_moveto (double x , double y); -extern int pdf_dev_rmoveto (double x , double y); -extern int pdf_dev_closepath (void); - -extern int pdf_dev_lineto (double x0 , double y0); -extern int pdf_dev_rlineto (double x0 , double y0); -extern int pdf_dev_curveto (double x0 , double y0, - double x1 , double y1, - double x2 , double y2); -extern int pdf_dev_vcurveto (double x0 , double y0, - double x1 , double y1); -extern int pdf_dev_ycurveto (double x0 , double y0, - double x1 , double y1); -extern int pdf_dev_rcurveto (double x0 , double y0, - double x1 , double y1, - double x2 , double y2); -extern int pdf_dev_arc (double c_x, double c_y, double r, - double a_0, double a_1); -extern int pdf_dev_arcn (double c_x, double c_y, double r, - double a_0, double a_1); - -#define PDF_FILL_RULE_NONZERO 0 -#define PDF_FILL_RULE_EVENODD 1 - -extern int pdf_dev_newpath (void); - -/* Path Painting */ -extern int pdf_dev_clip (void); -extern int pdf_dev_eoclip (void); - -#if 0 -extern int pdf_dev_rectstroke (double x, double y, - double w, double h, - const pdf_tmatrix *M /* optional */ - ); -#endif /* 0 */ - -extern int pdf_dev_rectfill (double x, double y, double w, double h); -extern int pdf_dev_rectclip (double x, double y, double w, double h); -extern int pdf_dev_rectadd (double x, double y, double w, double h); - -extern int pdf_dev_flushpath (char p_op, int fill_rule); - -#define pdf_dev_fill() pdf_dev_flushpath('f', PDF_FILL_RULE_NONZERO) -#define pdf_dev_eofill() pdf_dev_flushpath('f', PDF_FILL_RULE_EVENODD) -#define pdf_dev_stroke() pdf_dev_flushpath('S', PDF_FILL_RULE_NONZERO) -#define pdf_dev_fillstroke() pdf_dev_flushpath('B', PDF_FILL_RULE_NONZERO) - -extern int pdf_dev_concat (const pdf_tmatrix *M); -/* NULL pointer of M mean apply current transformation */ -extern void pdf_dev_dtransform (pdf_coord *p, const pdf_tmatrix *M); -extern void pdf_dev_idtransform (pdf_coord *p, const pdf_tmatrix *M); -extern void pdf_dev_transform (pdf_coord *p, const pdf_tmatrix *M); -#if 0 -extern void pdf_dev_itransform (pdf_coord *p, const pdf_tmatrix *M); -#endif /* 0 */ - -extern int pdf_dev_gsave (void); -extern int pdf_dev_grestore (void); - -/* Requires from mpost.c because new MetaPost graphics must initialize - * the current gstate. */ -extern int pdf_dev_push_gstate (void); -extern int pdf_dev_pop_gstate (void); - - -/* extension */ -extern int pdf_dev_arcx (double c_x, double c_y, - double r_x, double r_y, - double a_0, double a_1, - int a_d, /* arc direction */ - double xar /* x-axis-rotation */ - ); -extern int pdf_dev_bspline (double x0, double y0, - double x1, double y1, - double x2, double y2); - - -extern void pdf_invertmatrix (pdf_tmatrix *M); - -/* The depth here is the depth of q/Q nesting. - * We must remember current depth of nesting when starting a page or xform, - * and must recover until that depth at the end of page/xform. - */ -extern int pdf_dev_current_depth (void); -extern void pdf_dev_grestore_to (int depth); -#define pdf_dev_grestoreall() pdf_dev_grestore_to(0); - -extern int pdf_dev_currentcolor (pdf_color *color, int is_fill); -extern int pdf_dev_setcolor (const pdf_color *color, int is_fill); - -extern void pdf_dev_set_fixed_point (double x, double y); -extern void pdf_dev_get_fixed_point (pdf_coord *p); -#endif /* _PDF_DRAW_H_ */ diff --git a/Build/source/texk/dvipdfm-x/xsrc/xbb.c b/Build/source/texk/dvipdfm-x/xsrc/xbb.c index d93840b97ff..6820b3af4c5 100644 --- a/Build/source/texk/dvipdfm-x/xsrc/xbb.c +++ b/Build/source/texk/dvipdfm-x/xsrc/xbb.c @@ -26,11 +26,12 @@ #include #include #include + +#include "numbers.h" #include "system.h" #include "mem.h" #include "error.h" #include "mfileio.h" -#include "numbers.h" #include "pdfobj.h" #include "pdfparse.h" @@ -40,32 +41,43 @@ #include #endif +#include "dvipdfmx.h" #include "xbb.h" #define XBB_PROGRAM "extractbb" -#define XBB_VERSION "Version 0.2" +#define XBB_VERSION VERSION static int xbb_output_mode = XBB_OUTPUT; -static void usage(void) +static void show_version(void) { - fprintf (stderr, "%s, version %s, Copyright (C) 2008 by Jin-Hwan Cho\n", + fprintf (stdout, "%s, version %s, Copyright (C) 2008 by Jin-Hwan Cho\n", XBB_PROGRAM, XBB_VERSION); - fprintf (stderr, "A bounding box extraction utility from PDF, PNG, and JPG.\n"); + fprintf (stdout, "A bounding box extraction utility from PDF, PNG, and JPEG.\n"); fprintf (stdout, "\nThis is free software; you can redistribute it and/or modify\n"); fprintf (stdout, "it under the terms of the GNU General Public License as published by\n"); fprintf (stdout, "the Free Software Foundation; either version 2 of the License, or\n"); fprintf (stdout, "(at your option) any later version.\n"); - fprintf (stderr, "\nUsage: %s [-v] [-b] [-m|-x] [files]\n", XBB_PROGRAM); - fprintf (stderr, "\t-b\tWrite output file in binary mode\n"); +} + +static void show_usage(void) +{ + fprintf (stdout, "\nUsage: %s [-v] [-b] [-m|-x] [files]\n", XBB_PROGRAM); + fprintf (stdout, "\t-v\tBe verbose\n"); + fprintf (stdout, "\t-b\tWrite output file in binary mode\n"); if(xbb_output_mode == EBB_OUTPUT) { - fprintf (stderr, "\t-m\tOutput .bb file used in DVIPDFM (default)\n"); - fprintf (stderr, "\t-x\tOutput .xbb file used in DVIPDFMx\n"); + fprintf (stdout, "\t-m\tOutput .bb file used in DVIPDFM (default)\n"); + fprintf (stdout, "\t-x\tOutput .xbb file used in DVIPDFMx\n"); } else { - fprintf (stderr, "\t-m\tOutput .bb file used in DVIPDFM\n"); - fprintf (stderr, "\t-x\tOutput .xbb file used in DVIPDFMx (default)\n"); + fprintf (stdout, "\t-m\tOutput .bb file used in DVIPDFM\n"); + fprintf (stdout, "\t-x\tOutput .xbb file used in DVIPDFMx (default)\n"); } - fprintf (stderr, "\t-v\tVerbose\n"); +} + +static void usage(void) +{ + show_version(); + show_usage(); exit(1); } @@ -96,11 +108,11 @@ static char *make_xbb_filename(const char *name) break; } if (i == sizeof(extensions) / sizeof(extensions[0])) { - fprintf(stderr, "Warning: %s: Filename does not end in a recognizeable extension.\n", name); - result = NEW(strlen(name)+3, char); + WARN("%s: Filename does not end in a recognizable extension.\n", name); + result = NEW(strlen(name)+5, char); /* 5 = ".xbb" + trailing 0 */ strcpy(result, name); } else { /* Remove extension */ - result = NEW(strlen(name)+3-strlen(extensions[i])+1, char); + result = NEW(strlen(name)-strlen(extensions[i])+5, char); /* 5 = ".xbb" + trailing 0 */ strncpy(result, name, strlen(name)-strlen(extensions[i])); result[strlen(name)-strlen(extensions[i])] = 0; } @@ -122,12 +134,12 @@ static void write_xbb(char *fname, int bbllx, int bblly, int bburx, int bbury) return; } if (verbose) { - fprintf(stderr, "Writing to %s: ", outname); - fprintf(stderr, "Bounding box: %d %d %d %d\n", bbllx, bblly, bburx, bbury); + MESG("Writing to %s: ", outname); + MESG("Bounding box: %d %d %d %d\n", bbllx, bblly, bburx, bbury); } - fprintf(fp,"%%%%Title: %s\n", fname); - fprintf(fp,"%%%%Creator: %s %s\n", XBB_PROGRAM, XBB_VERSION); - fprintf(fp,"%%%%BoundingBox: %d %d %d %d\n", bbllx, bblly, bburx, bbury); + fprintf(fp, "%%%%Title: %s\n", fname); + fprintf(fp, "%%%%Creator: %s %s\n", XBB_PROGRAM, XBB_VERSION); + fprintf(fp, "%%%%BoundingBox: %d %d %d %d\n", bbllx, bblly, bburx, bbury); do_time(fp); RELEASE(outname); MFCLOSE(fp); @@ -480,12 +492,13 @@ int extractbb (int argc, char *argv[], int mode) usage(); } } + for (; argc > 0; argc--, argv++) { FILE *infile = NULL; char *kpse_file_name; if (!(kpse_file_name = kpse_find_pict(argv[0])) || (infile = MFOPEN(kpse_file_name, FOPEN_RBIN_MODE)) == NULL) { - fprintf(stderr, "Can't find file (%s)...skipping\n", argv[0]); + WARN("Can't find file (%s)...skipping\n", argv[0]); goto cont; } if (check_for_jpeg(infile)) { @@ -502,7 +515,7 @@ int extractbb (int argc, char *argv[], int mode) goto cont; } #endif /* HAVE_LIBPNG */ - fprintf(stderr, "Can't handle file type for file named %s\n", argv[0]); + WARN("Can't handle file type for file named %s\n", argv[0]); cont: if (kpse_file_name) RELEASE(kpse_file_name); -- cgit v1.2.3