From 621273b5ef8cc9e83d9aca07bf012f727ba26f15 Mon Sep 17 00:00:00 2001 From: Akira Kakuto Date: Wed, 16 Dec 2015 14:50:11 +0000 Subject: web2c/luatexdir: LuaTeX beta-0.86.0 (Sync with the upstream). git-svn-id: svn://tug.org/texlive/trunk@39116 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/web2c/luatexdir/NEWS | 29 +- Build/source/texk/web2c/luatexdir/am/libluatex.am | 81 +- Build/source/texk/web2c/luatexdir/am/txt2zlib.am | 20 - Build/source/texk/web2c/luatexdir/dvi/dvigen.w | 3 +- Build/source/texk/web2c/luatexdir/font/dofont.w | 2 +- Build/source/texk/web2c/luatexdir/font/luafont.w | 1072 ++++---- Build/source/texk/web2c/luatexdir/font/mapfile.w | 47 +- Build/source/texk/web2c/luatexdir/font/pkin.w | 22 +- Build/source/texk/web2c/luatexdir/font/sfnt.h | 20 +- Build/source/texk/web2c/luatexdir/font/sfnt.w | 8 +- Build/source/texk/web2c/luatexdir/font/subfont.w | 15 +- Build/source/texk/web2c/luatexdir/font/texfont.h | 174 +- Build/source/texk/web2c/luatexdir/font/texfont.w | 109 +- Build/source/texk/web2c/luatexdir/font/tounicode.w | 8 +- Build/source/texk/web2c/luatexdir/font/tt_glyf.w | 44 +- Build/source/texk/web2c/luatexdir/font/tt_table.w | 16 +- Build/source/texk/web2c/luatexdir/font/vfovf.w | 103 +- Build/source/texk/web2c/luatexdir/font/vfpacket.w | 6 +- Build/source/texk/web2c/luatexdir/font/writecff.w | 223 +- Build/source/texk/web2c/luatexdir/font/writefont.w | 33 +- Build/source/texk/web2c/luatexdir/font/writet1.w | 108 +- Build/source/texk/web2c/luatexdir/font/writet3.w | 11 +- Build/source/texk/web2c/luatexdir/font/writettf.w | 119 +- .../source/texk/web2c/luatexdir/font/writetype0.w | 11 +- .../source/texk/web2c/luatexdir/font/writetype2.w | 6 +- Build/source/texk/web2c/luatexdir/image/epdf.h | 3 +- Build/source/texk/web2c/luatexdir/image/image.h | 194 +- .../source/texk/web2c/luatexdir/image/pdftoepdf.h | 4 +- .../source/texk/web2c/luatexdir/image/pdftoepdf.w | 669 +++-- Build/source/texk/web2c/luatexdir/image/writeimg.h | 8 +- Build/source/texk/web2c/luatexdir/image/writeimg.w | 408 +-- .../source/texk/web2c/luatexdir/image/writejbig2.h | 7 +- .../source/texk/web2c/luatexdir/image/writejbig2.w | 265 +- Build/source/texk/web2c/luatexdir/image/writejp2.h | 4 +- Build/source/texk/web2c/luatexdir/image/writejp2.w | 115 +- Build/source/texk/web2c/luatexdir/image/writejpg.h | 6 +- Build/source/texk/web2c/luatexdir/image/writejpg.w | 521 ++-- Build/source/texk/web2c/luatexdir/image/writepng.h | 7 +- Build/source/texk/web2c/luatexdir/image/writepng.w | 319 +-- Build/source/texk/web2c/luatexdir/lang/texlang.h | 3 +- Build/source/texk/web2c/luatexdir/lang/texlang.w | 123 +- .../source/texk/web2c/luatexdir/lua/lcallbacklib.c | 329 +-- Build/source/texk/web2c/luatexdir/lua/lepdflib.cc | 242 +- Build/source/texk/web2c/luatexdir/lua/lfontlib.c | 104 +- Build/source/texk/web2c/luatexdir/lua/limglib.c | 1119 ++++----- Build/source/texk/web2c/luatexdir/lua/liolibext.c | 16 +- Build/source/texk/web2c/luatexdir/lua/lkpselib.c | 24 +- Build/source/texk/web2c/luatexdir/lua/llanglib.c | 81 +- .../source/texk/web2c/luatexdir/lua/lnewtokenlib.c | 333 ++- Build/source/texk/web2c/luatexdir/lua/lnodelib.c | 2008 ++++++++------- Build/source/texk/web2c/luatexdir/lua/loslibext.c | 64 +- Build/source/texk/web2c/luatexdir/lua/lpdflib.c | 113 +- .../texk/web2c/luatexdir/lua/lpdfscannerlib.cc | 78 +- Build/source/texk/web2c/luatexdir/lua/lstatslib.c | 52 +- Build/source/texk/web2c/luatexdir/lua/ltexiolib.c | 11 +- Build/source/texk/web2c/luatexdir/lua/ltexlib.c | 709 +++--- Build/source/texk/web2c/luatexdir/lua/ltokenlib.c | 288 --- Build/source/texk/web2c/luatexdir/lua/luagen.h | 20 - Build/source/texk/web2c/luatexdir/lua/luagen.w | 20 - Build/source/texk/web2c/luatexdir/lua/luainit.w | 234 +- .../source/texk/web2c/luatexdir/lua/luajitstuff.w | 5 +- Build/source/texk/web2c/luatexdir/lua/luanode.w | 32 +- Build/source/texk/web2c/luatexdir/lua/luastuff.w | 5 +- Build/source/texk/web2c/luatexdir/lua/luatex-api.h | 126 +- Build/source/texk/web2c/luatexdir/lua/luatoken.w | 32 +- .../texk/web2c/luatexdir/luafilesystem/src/lfs.c | 3 - .../texk/web2c/luatexdir/luascripts/pdflua.c | 37 - .../texk/web2c/luatexdir/luascripts/pdflua.h | 33 - .../texk/web2c/luatexdir/luascripts/pdflua.lua | 23 - .../texk/web2c/luatexdir/luascripts/txt2zlib.w | 143 -- Build/source/texk/web2c/luatexdir/luatex-common.h | 10 +- Build/source/texk/web2c/luatexdir/luatex.c | 29 +- .../texk/web2c/luatexdir/luatexcallbackids.h | 4 +- Build/source/texk/web2c/luatexdir/pdf/pdfaction.h | 25 +- Build/source/texk/web2c/luatexdir/pdf/pdfaction.w | 100 +- Build/source/texk/web2c/luatexdir/pdf/pdfannot.h | 7 +- Build/source/texk/web2c/luatexdir/pdf/pdfannot.w | 18 +- .../texk/web2c/luatexdir/pdf/pdfcolorstack.h | 7 +- .../texk/web2c/luatexdir/pdf/pdfcolorstack.w | 137 +- Build/source/texk/web2c/luatexdir/pdf/pdfdest.h | 27 +- Build/source/texk/web2c/luatexdir/pdf/pdfdest.w | 146 +- Build/source/texk/web2c/luatexdir/pdf/pdffont.h | 3 +- Build/source/texk/web2c/luatexdir/pdf/pdffont.w | 145 +- Build/source/texk/web2c/luatexdir/pdf/pdfgen.h | 104 +- Build/source/texk/web2c/luatexdir/pdf/pdfgen.w | 892 +++---- Build/source/texk/web2c/luatexdir/pdf/pdfglyph.h | 4 +- Build/source/texk/web2c/luatexdir/pdf/pdfglyph.w | 111 +- Build/source/texk/web2c/luatexdir/pdf/pdfimage.h | 3 +- Build/source/texk/web2c/luatexdir/pdf/pdfimage.w | 6 +- Build/source/texk/web2c/luatexdir/pdf/pdflink.h | 10 +- Build/source/texk/web2c/luatexdir/pdf/pdflink.w | 61 +- Build/source/texk/web2c/luatexdir/pdf/pdflistout.h | 17 +- Build/source/texk/web2c/luatexdir/pdf/pdflistout.w | 1002 ++++---- Build/source/texk/web2c/luatexdir/pdf/pdfliteral.h | 4 +- Build/source/texk/web2c/luatexdir/pdf/pdfliteral.w | 72 +- Build/source/texk/web2c/luatexdir/pdf/pdfluaapi.h | 29 - Build/source/texk/web2c/luatexdir/pdf/pdfluaapi.w | 113 - Build/source/texk/web2c/luatexdir/pdf/pdfobj.h | 26 +- Build/source/texk/web2c/luatexdir/pdf/pdfobj.w | 37 +- Build/source/texk/web2c/luatexdir/pdf/pdfoutline.h | 3 +- Build/source/texk/web2c/luatexdir/pdf/pdfoutline.w | 68 +- Build/source/texk/web2c/luatexdir/pdf/pdfpage.h | 10 +- Build/source/texk/web2c/luatexdir/pdf/pdfpage.w | 172 +- .../source/texk/web2c/luatexdir/pdf/pdfpagetree.h | 6 +- .../source/texk/web2c/luatexdir/pdf/pdfpagetree.w | 96 +- Build/source/texk/web2c/luatexdir/pdf/pdfrule.h | 5 +- Build/source/texk/web2c/luatexdir/pdf/pdfrule.w | 15 +- .../texk/web2c/luatexdir/pdf/pdfsaverestore.h | 12 +- .../texk/web2c/luatexdir/pdf/pdfsaverestore.w | 16 +- .../source/texk/web2c/luatexdir/pdf/pdfsetmatrix.h | 5 +- .../source/texk/web2c/luatexdir/pdf/pdfsetmatrix.w | 44 +- Build/source/texk/web2c/luatexdir/pdf/pdfshipout.h | 7 +- Build/source/texk/web2c/luatexdir/pdf/pdfshipout.w | 284 +-- Build/source/texk/web2c/luatexdir/pdf/pdftables.h | 103 +- Build/source/texk/web2c/luatexdir/pdf/pdftables.w | 221 +- Build/source/texk/web2c/luatexdir/pdf/pdfthread.h | 37 +- Build/source/texk/web2c/luatexdir/pdf/pdfthread.w | 52 +- Build/source/texk/web2c/luatexdir/pdf/pdftypes.h | 113 +- Build/source/texk/web2c/luatexdir/pdf/pdfxform.h | 51 +- Build/source/texk/web2c/luatexdir/pdf/pdfxform.w | 4 +- Build/source/texk/web2c/luatexdir/ptexlib.h | 13 +- Build/source/texk/web2c/luatexdir/tex/align.w | 16 +- Build/source/texk/web2c/luatexdir/tex/buildpage.w | 35 +- Build/source/texk/web2c/luatexdir/tex/commands.h | 34 +- Build/source/texk/web2c/luatexdir/tex/commands.w | 19 +- .../source/texk/web2c/luatexdir/tex/conditional.h | 76 +- .../source/texk/web2c/luatexdir/tex/conditional.w | 556 +++-- Build/source/texk/web2c/luatexdir/tex/directions.h | 74 +- Build/source/texk/web2c/luatexdir/tex/directions.w | 59 +- Build/source/texk/web2c/luatexdir/tex/dumpdata.w | 23 +- .../source/texk/web2c/luatexdir/tex/equivalents.h | 328 +-- .../source/texk/web2c/luatexdir/tex/equivalents.w | 713 +++--- Build/source/texk/web2c/luatexdir/tex/errors.h | 6 +- Build/source/texk/web2c/luatexdir/tex/errors.w | 70 +- Build/source/texk/web2c/luatexdir/tex/expand.h | 5 +- Build/source/texk/web2c/luatexdir/tex/expand.w | 76 +- Build/source/texk/web2c/luatexdir/tex/extensions.h | 8 - Build/source/texk/web2c/luatexdir/tex/extensions.w | 180 +- Build/source/texk/web2c/luatexdir/tex/inputstack.h | 13 +- Build/source/texk/web2c/luatexdir/tex/inputstack.w | 292 ++- Build/source/texk/web2c/luatexdir/tex/linebreak.h | 22 +- Build/source/texk/web2c/luatexdir/tex/linebreak.w | 876 +++---- Build/source/texk/web2c/luatexdir/tex/mainbody.h | 2 - Build/source/texk/web2c/luatexdir/tex/mainbody.w | 32 +- .../source/texk/web2c/luatexdir/tex/maincontrol.w | 1453 ++++++----- Build/source/texk/web2c/luatexdir/tex/mathcodes.h | 28 +- Build/source/texk/web2c/luatexdir/tex/mathcodes.w | 329 +-- Build/source/texk/web2c/luatexdir/tex/mlist.h | 4 +- Build/source/texk/web2c/luatexdir/tex/mlist.w | 56 +- Build/source/texk/web2c/luatexdir/tex/packaging.h | 141 +- Build/source/texk/web2c/luatexdir/tex/packaging.w | 1577 +++++++----- Build/source/texk/web2c/luatexdir/tex/printing.h | 6 +- Build/source/texk/web2c/luatexdir/tex/printing.w | 633 ++--- Build/source/texk/web2c/luatexdir/tex/scanning.h | 32 +- Build/source/texk/web2c/luatexdir/tex/scanning.w | 349 +-- Build/source/texk/web2c/luatexdir/tex/texfileio.w | 4 +- Build/source/texk/web2c/luatexdir/tex/texmath.w | 106 +- Build/source/texk/web2c/luatexdir/tex/texnodes.h | 68 +- Build/source/texk/web2c/luatexdir/tex/texnodes.w | 2422 ++++++++---------- Build/source/texk/web2c/luatexdir/tex/textcodes.h | 29 +- Build/source/texk/web2c/luatexdir/tex/textcodes.w | 445 ++-- Build/source/texk/web2c/luatexdir/tex/textoken.h | 1 + Build/source/texk/web2c/luatexdir/tex/textoken.w | 2640 ++++++++++++-------- .../source/texk/web2c/luatexdir/utils/managed-sa.h | 29 +- .../source/texk/web2c/luatexdir/utils/managed-sa.w | 72 +- .../source/texk/web2c/luatexdir/utils/unistring.w | 19 +- Build/source/texk/web2c/luatexdir/utils/utils.w | 82 +- 167 files changed, 14530 insertions(+), 15226 deletions(-) delete mode 100644 Build/source/texk/web2c/luatexdir/am/txt2zlib.am delete mode 100644 Build/source/texk/web2c/luatexdir/lua/ltokenlib.c delete mode 100644 Build/source/texk/web2c/luatexdir/lua/luagen.h delete mode 100644 Build/source/texk/web2c/luatexdir/lua/luagen.w delete mode 100644 Build/source/texk/web2c/luatexdir/luascripts/pdflua.c delete mode 100644 Build/source/texk/web2c/luatexdir/luascripts/pdflua.h delete mode 100644 Build/source/texk/web2c/luatexdir/luascripts/pdflua.lua delete mode 100644 Build/source/texk/web2c/luatexdir/luascripts/txt2zlib.w delete mode 100644 Build/source/texk/web2c/luatexdir/pdf/pdfluaapi.h delete mode 100644 Build/source/texk/web2c/luatexdir/pdf/pdfluaapi.w (limited to 'Build/source/texk') diff --git a/Build/source/texk/web2c/luatexdir/NEWS b/Build/source/texk/web2c/luatexdir/NEWS index d99f071d993..6d643eac977 100644 --- a/Build/source/texk/web2c/luatexdir/NEWS +++ b/Build/source/texk/web2c/luatexdir/NEWS @@ -1,6 +1,33 @@ This file is in the public domain. + + + +Upcoming LuaTeX Release 0.86 + +(major changes) + +- image data no longer stored in format (was fragile anyway) +- pdf backend data no longer stored in format + +- (incomplete) \mag support removed from pdf backend (kept in dvi mode) + +- all kind of (efficiency) improvements +- some pending issues done (behind the screens) + +- \nospace=1 will not inject glue for spaces (not even zero glue) +- \nospace=2 will inject zero glue for spaces + +- no longer keep track of older math character and delimiter definition states + +- only ^^ ^^^^XXXX ^^^^^^XXXXXX supported +- texio.setescape(0) disables escaping to terminal + +- lc codes saved with language + + + ============================================================== Luatex beta-0.85.0 was released 2015111400 (5550) ============================================================== @@ -2564,7 +2591,7 @@ Other news: we probably introduced new problems as well). * Most (all?) files now have a corrected Copyright header, - and link in $Id: NEWS 5550 2015-11-19 13:23:59Z luigi $ and $URL: https://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/NEWS $ into the object file. + and link in $Id: NEWS 5624 2015-12-15 21:49:14Z luigi $ and $URL: https://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/NEWS $ into the object file. * Some unnecessary files were removed from the distribution. diff --git a/Build/source/texk/web2c/luatexdir/am/libluatex.am b/Build/source/texk/web2c/luatexdir/am/libluatex.am index 6fffb43de4a..b512cffcc11 100644 --- a/Build/source/texk/web2c/luatexdir/am/libluatex.am +++ b/Build/source/texk/web2c/luatexdir/am/libluatex.am @@ -214,8 +214,6 @@ dist_libluatex_sources += \ ## luatex_lua_ctangle = $(ctangle_silent)CWEBINPUTS=$(srcdir)/luatexdir/lua $(ctangle) -luagen.c: ctangle$(EXEEXT) luatexdir/lua/luagen.w - $(luatex_lua_ctangle) luagen.w luainit.c: ctangle$(EXEEXT) luatexdir/lua/luainit.w $(luatex_lua_ctangle) luainit.w luajitstuff.c: ctangle$(EXEEXT) luatexdir/lua/luajitstuff.w @@ -231,11 +229,13 @@ texluac.c: ctangle$(EXEEXT) luatexdir/lua/texluac.w texluajitc.c: ctangle$(EXEEXT) luatexdir/lua/texluajitc.w $(luatex_lua_ctangle) texluajitc.w -libluatex_web += luatexdir/lua/luagen.w luatexdir/lua/luainit.w luatexdir/lua/luajitstuff.w +libluatex_web += luatexdir/lua/luainit.w luatexdir/lua/luajitstuff.w libluatex_web += luatexdir/lua/luanode.w luatexdir/lua/luastuff.w luatexdir/lua/luatoken.w libluatex_web += luatexdir/lua/texluac.w luatexdir/lua/texluajitc.w -nodist_libluatex_sources += luagen.c luainit.c luanode.c luatoken.c +nodist_libluatex_sources += luainit.c luanode.c luatoken.c + + dist_libluatex_sources += \ luatexdir/lua/lcallbacklib.c \ @@ -254,9 +254,7 @@ dist_libluatex_sources += \ luatexdir/lua/lstatslib.c \ luatexdir/lua/ltexiolib.c \ luatexdir/lua/ltexlib.c \ - luatexdir/lua/ltokenlib.c \ luatexdir/lua/lnewtokenlib.c \ - luatexdir/lua/luagen.h \ luatexdir/lua/luatex-api.h ## from luatexdir/pdf @@ -287,8 +285,6 @@ pdflistout.c: ctangle$(EXEEXT) luatexdir/pdf/pdflistout.w $(luatex_pdf_ctangle) pdflistout.w pdfliteral.c: ctangle$(EXEEXT) luatexdir/pdf/pdfliteral.w $(luatex_pdf_ctangle) pdfliteral.w -pdfluaapi.c: ctangle$(EXEEXT) luatexdir/pdf/pdfluaapi.w - $(luatex_pdf_ctangle) pdfluaapi.w pdfobj.c: ctangle$(EXEEXT) luatexdir/pdf/pdfobj.w $(luatex_pdf_ctangle) pdfobj.w pdfoutline.c: ctangle$(EXEEXT) luatexdir/pdf/pdfoutline.w @@ -314,7 +310,7 @@ libluatex_web += luatexdir/pdf/pdfpagetree.w luatexdir/pdf/pdfaction.w luatexdir libluatex_web += luatexdir/pdf/pdfcolorstack.w luatexdir/pdf/pdfdest.w libluatex_web += luatexdir/pdf/pdffont.w luatexdir/pdf/pdfgen.w luatexdir/pdf/pdfglyph.w libluatex_web += luatexdir/pdf/pdfimage.w luatexdir/pdf/pdflink.w luatexdir/pdf/pdflistout.w -libluatex_web += luatexdir/pdf/pdfliteral.w luatexdir/pdf/pdfluaapi.w luatexdir/pdf/pdfobj.w +libluatex_web += luatexdir/pdf/pdfliteral.w luatexdir/pdf/pdfobj.w libluatex_web += luatexdir/pdf/pdfoutline.w luatexdir/pdf/pdfpage.w luatexdir/pdf/pdfrule.w libluatex_web += luatexdir/pdf/pdfsaverestore.w luatexdir/pdf/pdfsetmatrix.w libluatex_web += luatexdir/pdf/pdfshipout.w luatexdir/pdf/pdftables.w @@ -322,7 +318,7 @@ libluatex_web += luatexdir/pdf/pdfthread.w luatexdir/pdf/pdfxform.w nodist_libluatex_sources += pdfpagetree.c pdfaction.c pdfannot.c pdfcolorstack.c pdfdest.c pdffont.c nodist_libluatex_sources += pdfgen.c pdfglyph.c pdfimage.c pdflink.c pdflistout.c pdfliteral.c -nodist_libluatex_sources += pdfluaapi.c pdfobj.c pdfoutline.c pdfpage.c pdfrule.c pdfsaverestore.c +nodist_libluatex_sources += pdfobj.c pdfoutline.c pdfpage.c pdfrule.c pdfsaverestore.c nodist_libluatex_sources += pdfsetmatrix.c pdfshipout.c pdftables.c pdfthread.c pdfxform.c dist_libluatex_sources += \ @@ -338,7 +334,6 @@ dist_libluatex_sources += \ luatexdir/pdf/pdflink.h \ luatexdir/pdf/pdflistout.h \ luatexdir/pdf/pdfliteral.h \ - luatexdir/pdf/pdfluaapi.h \ luatexdir/pdf/pdfobj.h \ luatexdir/pdf/pdfoutline.h \ luatexdir/pdf/pdfpage.h \ @@ -351,36 +346,44 @@ dist_libluatex_sources += \ luatexdir/pdf/pdftypes.h \ luatexdir/pdf/pdfxform.h +################################################################################ +################################################################################ +################################################################################ +## REMOVED +## but still left as example. ## from luatexdir/scripts ## -luatex_luascripts_ctangle = $(ctangle_silent)CWEBINPUTS=$(srcdir)/luatexdir/luascripts $(ctangle) - -txt2zlib.c: ctangle$(EXEEXT) luatexdir/luascripts/txt2zlib.w - $(luatex_luascripts_ctangle) txt2zlib.w - -libluatex_web += \ - luatexdir/luascripts/pdflua.c \ - luatexdir/luascripts/pdflua.lua \ - luatexdir/luascripts/txt2zlib.w - -## We normaly use the auxiliary program txt2zlib to create pdflua.c -## from luatexdir/luascripts/pdflua.lua. When cross compiling we -## use instead the distributed luatexdir/luascripts/pdflua.c. -if cross -pdflua.c: luatexdir/luascripts/pdflua.c - $(AM_V_GEN)rm -f pdflua.c; \ - $(LN_S) $(srcdir)/luatexdir/luascripts/pdflua.c pdflua.c -else !cross -pdflua.c: txt2zlib$(EXEEXT) luatexdir/luascripts/pdflua.lua - $(AM_V_GEN)./txt2zlib $(srcdir)/luatexdir/luascripts/pdflua.lua pdflua.c && \ - cmp -s pdflua.c $(srcdir)/luatexdir/luascripts/pdflua.c || \ - cp -f pdflua.c $(srcdir)/luatexdir/luascripts/pdflua.c -endif !cross - -nodist_libluatex_sources += pdflua.c - -dist_libluatex_sources += \ - luatexdir/luascripts/pdflua.h +# luatex_luascripts_ctangle = $(ctangle_silent)CWEBINPUTS=$(srcdir)/luatexdir/luascripts $(ctangle) + +# txt2zlib.c: ctangle$(EXEEXT) luatexdir/luascripts/txt2zlib.w +# $(luatex_luascripts_ctangle) txt2zlib.w + +# libluatex_web += \ +# luatexdir/luascripts/pdflua.c \ +# luatexdir/luascripts/pdflua.lua \ +# luatexdir/luascripts/txt2zlib.w + +# ## We normaly use the auxiliary program txt2zlib to create pdflua.c +# ## from luatexdir/luascripts/pdflua.lua. When cross compiling we +# ## use instead the distributed luatexdir/luascripts/pdflua.c. +# if cross +# pdflua.c: luatexdir/luascripts/pdflua.c +# $(AM_V_GEN)rm -f pdflua.c; \ +# $(LN_S) $(srcdir)/luatexdir/luascripts/pdflua.c pdflua.c +# else !cross +# pdflua.c: txt2zlib$(EXEEXT) luatexdir/luascripts/pdflua.lua +# $(AM_V_GEN)./txt2zlib $(srcdir)/luatexdir/luascripts/pdflua.lua pdflua.c && \ +# cmp -s pdflua.c $(srcdir)/luatexdir/luascripts/pdflua.c || \ +# cp -f pdflua.c $(srcdir)/luatexdir/luascripts/pdflua.c +# endif !cross + +# nodist_libluatex_sources += pdflua.c + +# dist_libluatex_sources += \ +# luatexdir/luascripts/pdflua.h +################################################################################ +################################################################################ +################################################################################ ## from luatexdir/tex ## diff --git a/Build/source/texk/web2c/luatexdir/am/txt2zlib.am b/Build/source/texk/web2c/luatexdir/am/txt2zlib.am deleted file mode 100644 index 42bc7be964f..00000000000 --- a/Build/source/texk/web2c/luatexdir/am/txt2zlib.am +++ /dev/null @@ -1,20 +0,0 @@ -## texk/web2c/luatexdir/am/txt2zlib.am: Makefile fragment for txt2zlib. -## -## Copyright (C) 2010, 2011 Hartmut Henkel -## You may freely use, modify and/or distribute this file. - -if LUATEX -if !cross -noinst_PROGRAMS += txt2zlib -endif !cross -endif LUATEX -EXTRA_PROGRAMS += txt2zlib - -nodist_txt2zlib_SOURCES = txt2zlib.c - -txt2zlib_CPPFLAGS = $(ZLIB_INCLUDES) -txt2zlib_DEPENDENCIES = $(ZLIB_DEPEND) -txt2zlib_LDADD = $(ZLIB_LIBS) - -DISTCLEANFILES += txt2zlib.c - diff --git a/Build/source/texk/web2c/luatexdir/dvi/dvigen.w b/Build/source/texk/web2c/luatexdir/dvi/dvigen.w index ce38db7c4c2..0a3ca08ea14 100644 --- a/Build/source/texk/web2c/luatexdir/dvi/dvigen.w +++ b/Build/source/texk/web2c/luatexdir/dvi/dvigen.w @@ -43,7 +43,6 @@ #define tracing_output int_par(tracing_output_code) #define tracing_stats int_par(tracing_stats_code) #define tracing_online int_par(tracing_online_code) -#define page_direction int_par(page_direction_code) #define page_width dimen_par(page_width_code) #define page_height dimen_par(page_height_code) #define page_left_offset dimen_par(page_left_offset_code) @@ -1055,7 +1054,7 @@ that a \.{DVI}-reading program will push onto its coordinate stack. void dvi_place_rule(PDF pdf, halfword q, scaledpos size) { synch_dvi_with_pos(pdf->posstruct->pos); - if ((subtype(q) == box_rule) || (subtype(q) == image_rule) || (subtype(q) == empty_rule)) { + if ((subtype(q) >= box_rule) && (subtype(q) <= user_rule)) { /* place nothing, only take space */ if (textdir_is_L(pdf->posstruct->dir)) dvi.h += size.h; diff --git a/Build/source/texk/web2c/luatexdir/font/dofont.w b/Build/source/texk/web2c/luatexdir/font/dofont.w index 28693ac1fc1..db4c2a5ebf0 100644 --- a/Build/source/texk/web2c/luatexdir/font/dofont.w +++ b/Build/source/texk/web2c/luatexdir/font/dofont.w @@ -67,7 +67,7 @@ static int do_define_font(int f, const char *cnom, scaled s, int natural_dir) destroy_saved_callback(callback_id); /* |lua_pop(Luas, 1);| *//* done by |font_from_lua| */ } else if (t == LUA_TNUMBER) { - r=(int)lua_tonumber(Luas, -1); + r = (int) lua_tointeger(Luas, -1); destroy_saved_callback(callback_id); delete_font(f); lua_pop(Luas, 1); diff --git a/Build/source/texk/web2c/luatexdir/font/luafont.w b/Build/source/texk/web2c/luatexdir/font/luafont.w index e72cbc615ed..4c26ca5137d 100644 --- a/Build/source/texk/web2c/luatexdir/font/luafont.w +++ b/Build/source/texk/web2c/luatexdir/font/luafont.w @@ -18,22 +18,27 @@ % with LuaTeX; if not, see . @ @c - - #include "ptexlib.h" #include "lua/luatex-api.h" #define noVERBOSE -const char *font_type_strings[] = { "unknown", "virtual", "real", NULL }; -const char *font_format_strings[] = - { "unknown", "type1", "type3", "truetype", "opentype", NULL }; -const char *font_embedding_strings[] = - { "unknown", "no", "subset", "full", NULL }; +/* todo: also keys */ + +const char *font_type_strings[] = { + "unknown", "virtual", "real", NULL +}; + +const char *font_format_strings[] = { + "unknown", "type1", "type3", "truetype", "opentype", NULL +}; + +const char *font_embedding_strings[] = { + "unknown", "no", "subset", "full", NULL +}; -const char *ligature_type_strings[] = - { "=:", "=:|", "|=:", "|=:|", "", "=:|>", "|=:>", "|=:|>", "", "", "", - "|=:|>>", NULL +const char *ligature_type_strings[] = { + "=:", "=:|", "|=:", "|=:|", "", "=:|>", "|=:>", "|=:|>", "", "", "", "|=:|>>", NULL }; const char *MATH_param_names[] = { @@ -114,34 +119,39 @@ int ff_checkoption (lua_State *L, int narg, const char *def, const char *const l return -1; } -static void dump_intfield(lua_State * L, const char *n, int c) -{ - lua_pushstring(L, n); - lua_pushnumber(L, c); +#define dump_intfield(L,n,c) \ + lua_push_string_by_name(L,n); \ + lua_pushinteger(L, c); \ + lua_rawset(L, -3); \ + +#define dump_stringfield(L,n,c) \ + lua_push_string_by_name(L,n); \ + lua_pushstring(L, c); \ lua_rawset(L, -3); -} +#define dump_booleanfield(L,n,c) \ + lua_push_string_by_name(L,n); \ + lua_pushboolean(L, c); \ + lua_rawset(L, -3); static void dump_math_kerns(lua_State * L, charinfo * co, int l, int id) { int i; for (i = 0; i < l; i++) { lua_newtable(L); - /* *INDENT-OFF* */ - if (id==top_left_kern) { - dump_intfield(L, "height", co->top_left_math_kern_array[(2*i)]); - dump_intfield(L, "kern", co->top_left_math_kern_array[(2*i)+1]); - } else if (id==top_right_kern) { - dump_intfield(L, "height", co->top_right_math_kern_array[(2*i)]); - dump_intfield(L, "kern", co->top_right_math_kern_array[(2*i)+1]); - } else if (id==bottom_right_kern) { - dump_intfield(L, "height", co->bottom_right_math_kern_array[(2*i)]); - dump_intfield(L, "kern", co->bottom_right_math_kern_array[(2*i)+1]); - } else if (id==bottom_left_kern) { - dump_intfield(L, "height", co->bottom_left_math_kern_array[(2*i)]); - dump_intfield(L, "kern", co->bottom_left_math_kern_array[(2*i)+1]); - } - /* INDENT-ON */ + if (id==top_left_kern) { + dump_intfield(L, height, co->top_left_math_kern_array[(2*i)]); + dump_intfield(L, kern, co->top_left_math_kern_array[(2*i)+1]); + } else if (id==top_right_kern) { + dump_intfield(L, height, co->top_right_math_kern_array[(2*i)]); + dump_intfield(L, kern, co->top_right_math_kern_array[(2*i)+1]); + } else if (id==bottom_right_kern) { + dump_intfield(L, height, co->bottom_right_math_kern_array[(2*i)]); + dump_intfield(L, kern, co->bottom_right_math_kern_array[(2*i)+1]); + } else if (id==bottom_left_kern) { + dump_intfield(L, height, co->bottom_left_math_kern_array[(2*i)]); + dump_intfield(L, kern, co->bottom_left_math_kern_array[(2*i)+1]); + } lua_rawseti(L, -2, (i + 1)); } } @@ -153,165 +163,136 @@ static void font_char_to_lua(lua_State * L, internal_font_number f, charinfo * c lua_createtable(L, 0, 10); - lua_pushstring(L, "width"); - lua_pushnumber(L, get_charinfo_width(co)); - lua_rawset(L, -3); - - lua_pushstring(L, "height"); - lua_pushnumber(L, get_charinfo_height(co)); - lua_rawset(L, -3); - - lua_pushstring(L, "depth"); - lua_pushnumber(L, get_charinfo_depth(co)); - lua_rawset(L, -3); - + dump_intfield(L,width,get_charinfo_width(co)); + dump_intfield(L,height,get_charinfo_height(co)); + dump_intfield(L,depth,get_charinfo_depth(co)); if (get_charinfo_italic(co) != 0) { - lua_pushstring(L, "italic"); - lua_pushnumber(L, get_charinfo_italic(co)); - lua_rawset(L, -3); + dump_intfield(L,italic,get_charinfo_italic(co)); } - if (get_charinfo_vert_italic(co) != 0) { - lua_pushstring(L, "vert_italic"); - lua_pushnumber(L, get_charinfo_vert_italic(co)); - lua_rawset(L, -3); + dump_intfield(L,vert_italic,get_charinfo_vert_italic(co)); } - - if (get_charinfo_top_accent(co) !=0) { - lua_pushstring(L, "top_accent"); - lua_pushnumber(L, get_charinfo_top_accent(co)); - lua_rawset(L, -3); + if (get_charinfo_top_accent(co) !=0 && get_charinfo_top_accent(co) != INT_MIN) { + dump_intfield(L,top_accent,get_charinfo_top_accent(co)); } - - if (get_charinfo_bot_accent(co) != 0) { - lua_pushstring(L, "bot_accent") ; - lua_pushnumber(L, get_charinfo_bot_accent(co)); - lua_rawset(L, -3); + if (get_charinfo_bot_accent(co) != 0 && get_charinfo_bot_accent(co) != INT_MIN) { + dump_intfield(L,bot_accent,get_charinfo_bot_accent(co)); } - - if (get_charinfo_ef(co) != 0) { - lua_pushstring(L, "expansion_factor"); - lua_pushnumber(L, get_charinfo_ef(co)); - lua_rawset(L, -3); + if (get_charinfo_ef(co) != 1000) { + dump_intfield(L,expansion_factor,get_charinfo_ef(co)); } - if (get_charinfo_lp(co) != 0) { - lua_pushstring(L, "left_protruding"); - lua_pushnumber(L, get_charinfo_lp(co)); - lua_rawset(L, -3); + dump_intfield(L,left_protruding,get_charinfo_lp(co)); } - if (get_charinfo_rp(co) != 0) { - lua_pushstring(L, "right_protruding"); - lua_pushnumber(L, get_charinfo_rp(co)); - lua_rawset(L, -3); + dump_intfield(L,right_protruding,get_charinfo_rp(co)); } - if (font_encodingbytes(f) == 2) { - lua_pushstring(L, "index"); - lua_pushnumber(L, get_charinfo_index(co)); - lua_rawset(L, -3); + dump_intfield(L,index,get_charinfo_index(co)); } - if (get_charinfo_name(co) != NULL) { - lua_pushstring(L, "name"); - lua_pushstring(L, get_charinfo_name(co)); - lua_rawset(L, -3); + dump_stringfield(L,name,get_charinfo_name(co)); } - if (get_charinfo_tounicode(co) != NULL) { - lua_pushstring(L, "tounicode"); - lua_pushstring(L, get_charinfo_tounicode(co)); - lua_rawset(L, -3); + dump_stringfield(L,tounicode,get_charinfo_tounicode(co)); } - if (get_charinfo_tag(co) == list_tag) { - lua_pushstring(L, "next"); - lua_pushnumber(L, get_charinfo_remainder(co)); - lua_rawset(L, -3); + dump_intfield(L,next,get_charinfo_remainder(co)); + } + if (get_charinfo_used(co)) { + dump_booleanfield(L,used,(get_charinfo_used(co) ? true : false)); } - - lua_pushstring(L, "used"); - lua_pushboolean(L, (get_charinfo_used(co) ? true : false)); - lua_rawset(L, -3); - if (get_charinfo_tag(co) == ext_tag) { extinfo *h; h = get_charinfo_hor_variants(co); if (h != NULL) { int i = 1; + lua_push_string_by_name(L,horiz_variants); lua_newtable(L); while (h != NULL) { lua_createtable(L, 0, 5); - dump_intfield(L, "glyph", h->glyph); - dump_intfield(L, "extender", h->extender); - dump_intfield(L, "start", h->start_overlap); - dump_intfield(L, "end", h->end_overlap); - dump_intfield(L, "advance", h->advance); + dump_intfield(L, glyph, h->glyph); + dump_intfield(L, extender, h->extender); + dump_intfield(L, start, h->start_overlap); + dump_intfield(L, end, h->end_overlap); + dump_intfield(L, advance, h->advance); lua_rawseti(L, -2, i); i++; h = h->next; } - lua_setfield(L, -2, "horiz_variants"); + lua_rawset(L, -3); } h = get_charinfo_vert_variants(co); if (h != NULL) { int i = 1; + lua_push_string_by_name(L,vert_variants); lua_newtable(L); while (h != NULL) { lua_createtable(L, 0, 5); - dump_intfield(L, "glyph", h->glyph); - dump_intfield(L, "extender", h->extender); - dump_intfield(L, "start", h->start_overlap); - dump_intfield(L, "end", h->end_overlap); - dump_intfield(L, "advance", h->advance); + dump_intfield(L, glyph, h->glyph); + dump_intfield(L, extender, h->extender); + dump_intfield(L, start, h->start_overlap); + dump_intfield(L, end, h->end_overlap); + dump_intfield(L, advance, h->advance); lua_rawseti(L, -2, i); i++; h = h->next; } - lua_setfield(L, -2, "vert_variants"); + lua_rawset(L, -3); } } ki = get_charinfo_kerns(co); if (ki != NULL) { int i; - lua_pushstring(L, "kerns"); + lua_push_string_by_name(L,kerns); lua_createtable(L, 10, 1); for (i = 0; !kern_end(ki[i]); i++) { - if (kern_char(ki[i]) == right_boundarychar) { - lua_pushstring(L, "right_boundary"); + if (kern_disabled(ki[i])) { + /* skip like in lookup */ } else { - lua_pushnumber(L, kern_char(ki[i])); + lua_rawgeti(L, -1, kern_char(ki[i])); + if (lua_type(L,-1) == LUA_TNIL) { + lua_pop(L,1); + if (kern_char(ki[i]) == right_boundarychar) { + lua_push_string_by_name(L,right_boundary); + } else { + lua_pushinteger(L, kern_char(ki[i])); + } + lua_pushinteger(L, kern_kern(ki[i])); + lua_rawset(L, -3); + } else { + /* first one wins */ + lua_pop(L,1); + } } - lua_pushnumber(L, kern_kern(ki[i])); - lua_rawset(L, -3); } lua_rawset(L, -3); } l = get_charinfo_ligatures(co); if (l != NULL) { int i; - lua_pushstring(L, "ligatures"); + lua_push_string_by_name(L,ligatures); lua_createtable(L, 10, 1); for (i = 0; !lig_end(l[i]); i++) { if (lig_char(l[i]) == right_boundarychar) { - lua_pushstring(L, "right_boundary"); + lua_push_string_by_name(L,right_boundary); } else { - lua_pushnumber(L, lig_char(l[i])); + lua_pushinteger(L, lig_char(l[i])); } lua_createtable(L, 0, 2); - lua_pushstring(L, "type"); - lua_pushnumber(L, lig_type(l[i])); + lua_push_string_by_name(L,type); + lua_pushinteger(L, lig_type(l[i])); lua_rawset(L, -3); - lua_pushstring(L, "char"); - lua_pushnumber(L, lig_replacement(l[i])); + lua_push_string_by_name(L,char); + lua_pushinteger(L, lig_replacement(l[i])); lua_rawset(L, -3); lua_rawset(L, -3); } lua_rawset(L, -3); } + lua_push_string_by_name(L,mathkern); lua_newtable(L); { int i, j; @@ -319,91 +300,95 @@ static void font_char_to_lua(lua_State * L, internal_font_number f, charinfo * c j = 0; if (i > 0) { j++; + lua_push_string_by_name(L,top_right); lua_newtable(L); dump_math_kerns(L, co, i, top_right_kern); - lua_setfield(L, -2, "top_right"); + lua_rawset(L, -3); } i = get_charinfo_math_kerns(co, top_left_kern); if (i > 0) { j++; + lua_push_string_by_name(L,top_left); lua_newtable(L); dump_math_kerns(L, co, i, top_left_kern); - lua_setfield(L, -2, "top_left"); + lua_rawset(L, -3); } i = get_charinfo_math_kerns(co, bottom_right_kern); if (i > 0) { j++; + lua_push_string_by_name(L,bottom_right); lua_newtable(L); dump_math_kerns(L, co, i, bottom_right_kern); - lua_setfield(L, -2, "bottom_right"); + lua_rawset(L, -3); } i = get_charinfo_math_kerns(co, bottom_left_kern); if (i > 0) { j++; + lua_push_string_by_name(L,bottom_left); lua_newtable(L); dump_math_kerns(L, co, i, bottom_left_kern); - lua_setfield(L, -2, "bottom_left"); + lua_rawset(L, -3); } if (j > 0) - lua_setfield(L, -2, "mathkern"); + lua_rawset(L, -3); else - lua_pop(L, 1); + lua_pop(L, 2); } } static void write_lua_parameters(lua_State * L, int f) { int k; + lua_push_string_by_name(L,parameters); lua_newtable(L); for (k = 1; k <= font_params(f); k++) { - lua_pushnumber(L, font_param(f, k)); switch (k) { - case slant_code: - lua_setfield(L, -2, "slant"); - break; - case space_code: - lua_setfield(L, -2, "space"); - break; - case space_stretch_code: - lua_setfield(L, -2, "space_stretch"); - break; - case space_shrink_code: - lua_setfield(L, -2, "space_shrink"); - break; - case x_height_code: - lua_setfield(L, -2, "x_height"); - break; - case quad_code: - lua_setfield(L, -2, "quad"); - break; - case extra_space_code: - lua_setfield(L, -2, "extra_space"); - break; - default: - lua_rawseti(L, -2, k); + case slant_code: + dump_intfield(L,slant,font_param(f, k)); + break; + case space_code: + dump_intfield(L,space,font_param(f, k)); + break; + case space_stretch_code: + dump_intfield(L,space_stretch,font_param(f, k)); + break; + case space_shrink_code: + dump_intfield(L,space_shrink,font_param(f, k)); + break; + case x_height_code: + dump_intfield(L,x_height,font_param(f, k)); + break; + case quad_code: + dump_intfield(L,quad,font_param(f, k)); + break; + case extra_space_code: + dump_intfield(L,extra_space,font_param(f, k)); + break; + default: + lua_pushinteger(L, font_param(f, k)); + lua_rawseti(L, -2, k); } } - lua_setfield(L, -2, "parameters"); + lua_rawset(L, -3); } @ @c static void write_lua_math_parameters(lua_State * L, int f) { int k; + lua_push_string_by_name(L,MathConstants); lua_newtable(L); for (k = 1; k <= font_math_params(f); k++) { - lua_pushnumber(L, font_math_param(f, k)); + lua_pushinteger(L, font_math_param(f, k)); if (k <= MATH_param_max) { lua_setfield(L, -2, MATH_param_names[k]); } else { lua_rawseti(L, -2, k); } } - lua_setfield(L, -2, "MathConstants"); + lua_rawset(L, -3); } - - int font_to_lua(lua_State * L, int f) { int k; @@ -418,91 +403,58 @@ int font_to_lua(lua_State * L, int f) } lua_newtable(L); + lua_push_string_by_name(L,name); lua_pushstring(L, font_name(f)); - lua_setfield(L, -2, "name"); + lua_rawset(L, -3); if (font_area(f) != NULL) { - lua_pushstring(L, font_area(f)); - lua_setfield(L, -2, "area"); + dump_stringfield(L,area,font_area(f)); } if (font_filename(f) != NULL) { - lua_pushstring(L, font_filename(f)); - lua_setfield(L, -2, "filename"); + dump_stringfield(L,filename,font_filename(f)); } if (font_fullname(f) != NULL) { - lua_pushstring(L, font_fullname(f)); - lua_setfield(L, -2, "fullname"); + dump_stringfield(L,fullname,font_fullname(f)); } if (font_psname(f) != NULL) { - lua_pushstring(L, font_psname(f)); - lua_setfield(L, -2, "psname"); + dump_stringfield(L,psname,font_psname(f)); } if (font_encodingname(f) != NULL) { - lua_pushstring(L, font_encodingname(f)); - lua_setfield(L, -2, "encodingname"); - } - - lua_pushboolean(L, (font_used(f) ? true : false)); - lua_setfield(L, -2, "used"); - - - lua_pushstring(L, font_type_strings[font_type(f)]); - lua_setfield(L, -2, "type"); - lua_pushstring(L, font_format_strings[font_format(f)]); - lua_setfield(L, -2, "format"); - lua_pushstring(L, font_embedding_strings[font_embedding(f)]); - lua_setfield(L, -2, "embedding"); - - lua_pushnumber(L, font_units_per_em(f)); - lua_setfield(L, -2, "units_per_em"); - lua_pushnumber(L, font_size(f)); - lua_setfield(L, -2, "size"); - lua_pushnumber(L, font_dsize(f)); - lua_setfield(L, -2, "designsize"); - lua_pushnumber(L, font_checksum(f)); - lua_setfield(L, -2, "checksum"); - lua_pushnumber(L, font_slant(f)); - lua_setfield(L, -2, "slant"); - lua_pushnumber(L, font_extend(f)); - lua_setfield(L, -2, "extend"); - lua_pushnumber(L, font_natural_dir(f)); - lua_setfield(L, -2, "direction"); - lua_pushnumber(L, font_encodingbytes(f)); - lua_setfield(L, -2, "encodingbytes"); - lua_pushboolean(L, font_oldmath(f)); - lua_setfield(L, -2, "oldmath"); - lua_pushnumber(L, font_tounicode(f)); - lua_setfield(L, -2, "tounicode"); - - /* pdf parameters */ - /* skip the first four for now, that are very much interal */ -#if 0 - if (pdf_font_num(f) != 0) { - lua_pushnumber(L,pdf_font_num(f)); - lua_setfield(L,-2,"pdf_num"); - } -#endif + dump_stringfield(L,encodingname,font_encodingname(f)); + } + + dump_booleanfield(L,used,(font_used(f) ? true : false)); + dump_stringfield(L,type,font_type_strings[font_type(f)]); + dump_stringfield(L,format,font_format_strings[font_format(f)]); + dump_stringfield(L,embedding,font_embedding_strings[font_embedding(f)]); + + dump_intfield(L,units_per_em,font_units_per_em(f)); + dump_intfield(L,size,font_size(f)); + dump_intfield(L,designsize,font_dsize(f)); + dump_intfield(L,checksum,font_checksum(f)); + dump_intfield(L,slant,font_slant(f)); + dump_intfield(L,extend,font_extend(f)); + dump_intfield(L,direction,font_natural_dir(f)); + dump_intfield(L,encodingbytes,font_encodingbytes(f)); + dump_booleanfield(L,oldmath,font_oldmath(f)); + dump_intfield(L,tounicode,font_tounicode(f)); + /* the next one is read only */ if (font_max_shrink(f) != 0) { - lua_pushnumber(L, font_max_shrink(f)); - lua_setfield(L, -2, "max_shrink"); + dump_intfield(L,shrink,font_max_shrink(f)); } if (font_max_stretch(f) != 0) { - lua_pushnumber(L, font_max_stretch(f)); - lua_setfield(L, -2, "max_stretch"); + dump_intfield(L,stretch,font_max_stretch(f)); } if (font_step(f) != 0) { - lua_pushnumber(L, font_step(f)); - lua_setfield(L, -2, "step"); + dump_intfield(L,step,font_step(f)); } if (font_auto_expand(f) != 0) { - lua_pushboolean(L, font_auto_expand(f)); - lua_setfield(L, -2, "auto_expand"); + dump_booleanfield(L,auto_expand,font_auto_expand(f)); } if (pdf_font_attr(f) != 0) { char *s = makecstring(pdf_font_attr(f)); - lua_pushstring(L, s); + dump_stringfield(L,attributes,s); free(s); - lua_setfield(L, -2, "attributes"); } /* params */ @@ -510,28 +462,29 @@ int font_to_lua(lua_State * L, int f) write_lua_math_parameters(L, f); /* chars */ + lua_push_string_by_name(L,characters); lua_createtable(L, font_tables[f]->charinfo_size, 0); /* all characters */ - if (has_left_boundary(f)) { co = get_charinfo(f, left_boundarychar); + lua_push_string_by_name(L,left_boundary); font_char_to_lua(L, f, co); - lua_setfield(L, -2, "left_boundary"); + lua_rawset(L, -3); } if (has_right_boundary(f)) { co = get_charinfo(f, right_boundarychar); + lua_push_string_by_name(L,right_boundary); font_char_to_lua(L, f, co); - lua_setfield(L, -2, "right_boundary"); + lua_rawset(L, -3); } - for (k = font_bc(f); k <= font_ec(f); k++) { if (quick_char_exists(f, k)) { - lua_pushnumber(L, k); + lua_pushinteger(L, k); co = get_charinfo(f, k); font_char_to_lua(L, f, co); lua_rawset(L, -3); } } - lua_setfield(L, -2, "characters"); + lua_rawset(L, -3); if (font_cache_id(f) == 0) { /* renew */ int r; @@ -542,25 +495,22 @@ int font_to_lua(lua_State * L, int f) return 1; } -static int count_hash_items(lua_State * L, int name_index) -{ - int n = -1; - lua_rawgeti(L, LUA_REGISTRYINDEX, name_index); - lua_rawget(L, -2); - if (!lua_isnil(L, -1)) { - if (lua_istable(L, -1)) { - n = 0; - /* now find the number */ - lua_pushnil(L); /* first key */ - while (lua_next(L, -2) != 0) { - n++; - lua_pop(L, 1); - } - } +#define count_hash_items(L,name_index,n) \ + n = 0; \ + lua_rawgeti(L, LUA_REGISTRYINDEX, name_index); \ + lua_rawget(L, -2); \ + if (lua_type(L, -1) == LUA_TTABLE) { \ + lua_pushnil(L); \ + while (lua_next(L, -2) != 0) { \ + n++; \ + lua_pop(L, 1); \ + } \ + } \ + if (n) { \ + /* keep table on stack */ \ + } else{ \ + lua_pop(L, 1); \ } - lua_pop(L, 1); - return n; -} @ @c #define streq(a,b) (strcmp(a,b)==0) @@ -589,8 +539,6 @@ static void append_float(eight_bits ** cpp, float a) *cpp = cp; } -/*#define lua_roundnumber(a,b) (int)floor((double)lua_tonumber(L,-1)+0.5)*/ - static int n_enum_field(lua_State * L, int name_index, int dflt, const char **values) { int k, t; @@ -600,7 +548,7 @@ static int n_enum_field(lua_State * L, int name_index, int dflt, const char **va lua_rawget(L, -2); t = lua_type(L,-1); if (t == LUA_TNUMBER) { - i=(int)lua_tonumber(L, -1); + i = (int) lua_tointeger(L, -1); } else if (t == LUA_TSTRING) { s = lua_tostring(L, -1); k = 0; @@ -651,6 +599,13 @@ static const char *n_string_field(lua_State * L, int name_index) return lua_tostring(L,-1); } +static int n_some_field(lua_State * L, int name_index) +{ + lua_rawgeti(L, LUA_REGISTRYINDEX, name_index); /* fetch the stringptr */ + lua_rawget(L, -2); + return lua_type(L,-1); +} + /*static void init_font_string_pointers(lua_State * L){}*/ static int count_char_packet_bytes(lua_State * L) @@ -737,11 +692,8 @@ static void read_char_packets(lua_State * L, int *l_fonts, charinfo * co, intern int pc = count_char_packet_bytes(L); if (pc <= 0) return; - assert(l_fonts != NULL); - assert(l_fonts[1] != 0); while (l_fonts[(max_f + 1)] != 0) max_f++; - cp = cpackets = xmalloc((unsigned) (pc + 1)); for (i = 1; i <= (int) lua_rawlen(L, -1); i++) { lua_rawgeti(L, -1, i); @@ -799,98 +751,97 @@ static void read_char_packets(lua_State * L, int *l_fonts, charinfo * co, intern } else if (lua_key_eq(s, lua)) { cmd = packet_lua_code; } - switch (cmd) { - case packet_push_code: - case packet_pop_code: - append_packet(cmd); - break; - case packet_font_code: - append_packet(cmd); - lua_rawgeti(L, -2, 2); - n = (int) luaL_checkinteger(L, -1); - if (n == 0) { - ff = n; - } else { - ff = (n > max_f ? l_fonts[1] : l_fonts[n]); - } - do_store_four(ff); - lua_pop(L, 1); - break; - case packet_node_code: - append_packet(cmd); - lua_rawgeti(L, -2, 2); - n = copy_node_list(nodelist_from_lua(L)); - do_store_four(n); - lua_pop(L, 1); - break; - case packet_char_code: - append_packet(cmd); - lua_rawgeti(L, -2, 2); - n = (int) luaL_checkinteger(L, -1); - do_store_four(n); - lua_pop(L, 1); - break; - case packet_right_code: - case packet_down_code: - append_packet(cmd); - lua_rawgeti(L, -2, 2); - n = (int) luaL_checkinteger(L, -1); - do_store_four(sp_to_dvi(n, atsize)); - lua_pop(L, 1); - break; - case packet_rule_code: - append_packet(cmd); - lua_rawgeti(L, -2, 2); - n = (int) luaL_checkinteger(L, -1); - do_store_four(sp_to_dvi(n, atsize)); - lua_rawgeti(L, -3, 3); - n = (int) luaL_checkinteger(L, -1); - do_store_four(sp_to_dvi(n, atsize)); - lua_pop(L, 2); - break; - case packet_special_code: - case packet_lua_code: - append_packet(cmd); - lua_rawgeti(L, -2, 2); - s = luaL_checklstring(L, -1, &l); - if (l > 0) { - do_store_four(l); - m = (int) l; - while (m > 0) { - n = *s++; - m--; - append_packet(n); + case packet_push_code: + case packet_pop_code: + append_packet(cmd); + break; + case packet_font_code: + append_packet(cmd); + lua_rawgeti(L, -2, 2); + n = (int) luaL_checkinteger(L, -1); + if (n == 0) { + ff = n; + } else { + ff = (n > max_f ? l_fonts[1] : l_fonts[n]); } - } - lua_pop(L, 1); - break; - case packet_image_code: - append_packet(cmd); - lua_rawgeti(L, -2, 2); /* img/imgtable? ... */ - if (lua_istable(L, -1)) { /* imgtable ... */ - lua_getglobal(L, "img"); /* imglib imgtable ... */ - lua_pushstring(L, "new"); /* `new' imglib imgtable ... */ - lua_gettable(L, -2); /* f imglib imgtable ... */ - lua_insert(L, -3); /* imglib imgtable f ... */ - lua_pop(L, 1); /* imgtable f ... */ - lua_call(L, 1, 1); - } /* img ... */ - luaL_checkudata(L, -1, TYPE_IMG); /* img ... --- just typecheck */ - n = luaL_ref(L, LUA_REGISTRYINDEX); /* ... */ - do_store_four(n); - break; - case packet_nop_code: - break; - case packet_scale_code: - append_packet(cmd); - lua_rawgeti(L, -2, 2); - append_float(&cp, (float) luaL_checknumber(L, -1)); - lua_pop(L, 1); - break; - default: - normal_error("vf command","invalid packet code"); - /* fprintf(stdout, "Unknown char packet code %s\n", s); */ + do_store_four(ff); + lua_pop(L, 1); + break; + case packet_node_code: + append_packet(cmd); + lua_rawgeti(L, -2, 2); + n = copy_node_list(nodelist_from_lua(L)); + do_store_four(n); + lua_pop(L, 1); + break; + case packet_char_code: + append_packet(cmd); + lua_rawgeti(L, -2, 2); + n = (int) luaL_checkinteger(L, -1); + do_store_four(n); + lua_pop(L, 1); + break; + case packet_right_code: + case packet_down_code: + append_packet(cmd); + lua_rawgeti(L, -2, 2); + n = (int) luaL_checkinteger(L, -1); + do_store_four(sp_to_dvi(n, atsize)); + lua_pop(L, 1); + break; + case packet_rule_code: + append_packet(cmd); + lua_rawgeti(L, -2, 2); + n = (int) luaL_checkinteger(L, -1); + do_store_four(sp_to_dvi(n, atsize)); + lua_rawgeti(L, -3, 3); + n = (int) luaL_checkinteger(L, -1); + do_store_four(sp_to_dvi(n, atsize)); + lua_pop(L, 2); + break; + case packet_special_code: + case packet_lua_code: + append_packet(cmd); + lua_rawgeti(L, -2, 2); + s = luaL_checklstring(L, -1, &l); + if (l > 0) { + do_store_four(l); + m = (int) l; + while (m > 0) { + n = *s++; + m--; + append_packet(n); + } + } + lua_pop(L, 1); + break; + case packet_image_code: + append_packet(cmd); + lua_rawgeti(L, -2, 2); /* img/imgtable? ... */ + if (lua_istable(L, -1)) { /* imgtable ... */ + lua_getglobal(L, "img"); /* imglib imgtable ... */ + lua_pushstring(L, "new"); /* `new' imglib imgtable ... */ + lua_gettable(L, -2); /* f imglib imgtable ... */ + lua_insert(L, -3); /* imglib imgtable f ... */ + lua_pop(L, 1); /* imgtable f ... */ + lua_call(L, 1, 1); + } /* img ... */ + luaL_checkudata(L, -1, TYPE_IMG); /* img ... --- just typecheck */ + n = luaL_ref(L, LUA_REGISTRYINDEX); /* ... */ + do_store_four(n); + break; + case packet_nop_code: + break; + case packet_scale_code: + append_packet(cmd); + lua_rawgeti(L, -2, 2); + append_float(&cp, (float) luaL_checknumber(L, -1)); + lua_pop(L, 1); + break; + default: + normal_error("vf command","invalid packet code"); + /* fprintf(stdout, "Unknown char packet code %s\n", s); */ } } lua_pop(L, 1); /* command code */ @@ -938,8 +889,8 @@ static void read_lua_parameters(lua_State * L, int f) n = 7; lua_pushnil(L); /* first key */ while (lua_next(L, -2) != 0) { - if (lua_isnumber(L, -2)) { - i=(int)lua_tonumber(L, -2); + if (lua_type(L, -2) == LUA_TNUMBER) { + i = (int) lua_tointeger(L, -2); if (i > n) n = i; } @@ -950,8 +901,8 @@ static void read_lua_parameters(lua_State * L, int f) /* sometimes it is handy to have all integer keys */ for (i = 1; i <= 7; i++) { lua_rawgeti(L, -1, i); - if (lua_isnumber(L, -1)) { - n = lua_roundnumber(L, -1); + if (lua_type(L, -1) == LUA_TNUMBER) { + n = lua_roundnumber(L, -1); /* round ? */ set_font_param(f, i, n); } lua_pop(L, 1); @@ -1010,11 +961,11 @@ static void read_lua_math_parameters(lua_State * L, int f) while (lua_next(L, -2) != 0) { t = lua_type(L,-2); if (t == LUA_TNUMBER) { - i=(int)lua_tonumber(L, -2); + i = (int) lua_tointeger(L, -2); } else if (t == LUA_TSTRING) { i = ff_checkoption(L, -2, NULL, MATH_param_names); } - n=(int)lua_tonumber(L, -1); + n = (int) lua_tointeger(L, -1); if (i > 0) { set_font_math_param(f, i, n); } @@ -1030,7 +981,6 @@ static void read_lua_math_parameters(lua_State * L, int f) @ @c #define MIN_INF -0x7FFFFFFF - static void store_math_kerns(lua_State * L, int index, charinfo * co, int id) { int l, k; @@ -1053,11 +1003,9 @@ static void store_math_kerns(lua_State * L, int index, charinfo * co, int id) } @ @c -static void -font_char_from_lua(lua_State * L, internal_font_number f, int i, - int *l_fonts, boolean has_math) +static void font_char_from_lua(lua_State * L, internal_font_number f, int i, int *l_fonts, boolean has_math) { - int k, r, t, lt; + int k, r, t, lt, u, n; charinfo *co; kerninfo *ckerns; liginfo *cligs; @@ -1082,7 +1030,7 @@ font_char_from_lua(lua_State * L, internal_font_number f, int i, set_charinfo_vert_italic(co, j); j = lua_numeric_field_by_index(L, lua_key_index(index), 0); set_charinfo_index(co, j); - j = lua_numeric_field_by_index(L, lua_key_index(expansion_factor), 0); + j = lua_numeric_field_by_index(L, lua_key_index(expansion_factor), 1000); set_charinfo_ef(co, j); j = lua_numeric_field_by_index(L, lua_key_index(left_protruding), 0); set_charinfo_lp(co, j); @@ -1097,13 +1045,76 @@ font_char_from_lua(lua_State * L, internal_font_number f, int i, set_charinfo_name(co, NULL); /* n_string_field leaves a value on stack*/ lua_pop(L,1); - s = n_string_field(L, lua_key_index(tounicode)); - if (s != NULL) + u = n_some_field(L,lua_key_index(tounicode)); + if (u == LUA_TNUMBER) { + u = lua_tointeger(L,-1); + if (u < 0) { + set_charinfo_tounicode(co, NULL); + } else if (u < 0x10000) { + char *s = malloc(5); + sprintf(s,"%04X",(unsigned int) u); + set_charinfo_tounicode(co,s); + } else if (u < 0x1FFFFFFFFF) { + char *s = malloc(9); + sprintf(s,"%04X%04X",(unsigned int) (floor(u/1024)),(unsigned int) (u%1024+0xDC00)); + set_charinfo_tounicode(co,s); + } else { + set_charinfo_tounicode(co, NULL); + } + } else if (u == LUA_TTABLE) { + n = lua_rawlen(L,-1); + u = 0; + for (k = 1; k <= n; k++) { + lua_rawgeti(L, -1, k); + if (lua_type(L,-1) == LUA_TNUMBER) { + u = lua_tointeger(L,-1); + } else { + lua_pop(L, 1); + break; + } + if (u < 0) { + u = -1; + lua_pop(L, 1); + break; + } else if (u < 0x10000) { + u = u + 4; + } else if (u < 0x1FFFFFFFFF) { + u = u + 8; + } else { + u = -1; + lua_pop(L, 1); + break; + } + lua_pop(L, 1); + } + if (u>0) { + char *s = malloc(u+1); + char *t = s ; + for (k = 1; k <= n; k++) { + lua_rawgeti(L, -1, k); + u = lua_tointeger(L,-1); + if (u < 0x10000) { + sprintf(t,"%04X",(unsigned int) u); + t += 4; + } else { + sprintf(t,"%04X%04X",(unsigned int) (floor(u/1024)),(unsigned int) (u%1024+0xDC00)); + t += 8; + } + lua_pop(L, 1); + } + set_charinfo_tounicode(co,s); + } else { + set_charinfo_tounicode(co, NULL); + } + } else if (u == LUA_TSTRING) { + s = lua_tostring(L,-1); set_charinfo_tounicode(co, xstrdup(s)); - else + } else { set_charinfo_tounicode(co, NULL); - /* n_string_field leaves a value on stack*/ + } + /* ... leaves a value on stack*/ lua_pop(L,1); + if (has_math) { j = lua_numeric_field_by_index(L, lua_key_index(top_accent), INT_MIN); set_charinfo_top_accent(co, j); @@ -1127,9 +1138,8 @@ font_char_from_lua(lua_State * L, internal_font_number f, int i, set_charinfo_tag(co, ext_tag); set_charinfo_extensible(co, top, bot, mid, rep); } else { - luatex_warn - ("lua-loaded font %s char [U+%X] has an invalid extensible field!", - font_name(f), (int) i); + formatted_warning("font", "lua-loaded font %s char U+%X has an invalid extensible field", + font_name(f), (int) i); } } lua_pop(L, 1); @@ -1186,15 +1196,18 @@ font_char_from_lua(lua_State * L, internal_font_number f, int i, } lua_pop(L, 1); -/* Here is a complete example: + /* + Here is a complete example: + + |mathkern = {| + | bottom_left = { { height = 420, kern = 80 }, { height = 520, kern = 4 } },| + | bottom_right = { { height = 0, kern = 48 } },| + | top_left = { { height = 620, kern = 0 }, { height = 720, kern = -80 } },| + | top_right = { { height = 676, kern = 115 }, { height = 776, kern = 45 } },| + |}| + + */ - |["mathkern"]={| - |["bottom_left"] ={ { ["height"]=420, ["kern"]=80 }, { ["height"]=520, ["kern"]=4 } },| - |["bottom_right"]={ { ["height"]=0, ["kern"]=48 } },| - |["top_left"] ={ { ["height"]=620, ["kern"]=0 }, { ["height"]=720, ["kern"]=-80 } },| - |["top_right"] ={ { ["height"]=676, ["kern"]=115 }, { ["height"]=776, ["kern"]=45 } },| - |}| - */ lua_rawgeti(L, LUA_REGISTRYINDEX, lua_key_index(mathkern)); lua_rawget(L, -2); if (lua_istable(L, -1)) { @@ -1206,49 +1219,44 @@ font_char_from_lua(lua_State * L, internal_font_number f, int i, lua_pop(L, 1); } /* end of |has_math| */ - nk = count_hash_items(L, lua_key_index(kerns)); + count_hash_items(L, lua_key_index(kerns), nk); if (nk > 0) { + /* kerns table still on stack */ ckerns = xcalloc((unsigned) (nk + 1), sizeof(kerninfo)); - lua_rawgeti(L, LUA_REGISTRYINDEX, lua_key_index(kerns)); - lua_rawget(L, -2); - if (lua_istable(L, -1)) { /* there are kerns */ - ctr = 0; - lua_pushnil(L); - while (lua_next(L, -2) != 0) { - k = non_boundarychar; - lt = lua_type(L,-2); - if (lt == LUA_TNUMBER) { - k=(int)lua_tonumber(L, -2); /* adjacent char */ - if (k < 0) - k = non_boundarychar; - } else if (lt == LUA_TSTRING) { - s = lua_tostring(L, -2); - if (lua_key_eq(s, right_boundary)) { - k = right_boundarychar; - if (!has_right_boundary(f)) - set_right_boundary(f, get_charinfo(f, right_boundarychar)); - } - } - j = lua_roundnumber(L, -1); /* movement */ - if (k != non_boundarychar) { - set_kern_item(ckerns[ctr], k, j); - ctr++; - } else { - luatex_warn - ("lua-loaded font %s char [U+%X] has an invalid kern field!", - font_name(f), (int) i); + ctr = 0; + lua_pushnil(L); /* traverse hash */ + while (lua_next(L, -2) != 0) { + k = non_boundarychar; + lt = lua_type(L,-2); + if (lt == LUA_TNUMBER) { + k = (int) lua_tointeger(L, -2); /* adjacent char */ + if (k < 0) + k = non_boundarychar; + } else if (lt == LUA_TSTRING) { + s = lua_tostring(L, -2); + if (lua_key_eq(s, right_boundary)) { + k = right_boundarychar; + if (!has_right_boundary(f)) + set_right_boundary(f, get_charinfo(f, right_boundarychar)); } - lua_pop(L, 1); } - /* guard against empty tables */ - if (ctr > 0) { - set_kern_item(ckerns[ctr], end_kern, 0); - set_charinfo_kerns(co, ckerns); + j = lua_roundnumber(L, -1); /* movement */ + if (k != non_boundarychar) { + set_kern_item(ckerns[ctr], k, j); + ctr++; } else { - luatex_warn - ("lua-loaded font %s char [U+%X] has an invalid kerns field!", - font_name(f), (int) i); + formatted_warning("font", "lua-loaded font %s char U+%X has an invalid kern field", + font_name(f), (int) i); } + lua_pop(L, 1); + } + /* guard against empty tables */ + if (ctr > 0) { + set_kern_item(ckerns[ctr], end_kern, 0); + set_charinfo_kerns(co, ckerns); + } else { + formatted_warning("font", "lua-loaded font %s char U+%X has an invalid kerns field", + font_name(f), (int) i); } lua_pop(L, 1); } @@ -1266,63 +1274,55 @@ font_char_from_lua(lua_State * L, internal_font_number f, int i, lua_pop(L, 1); /* ligatures */ - nl = count_hash_items(L, lua_key_index(ligatures)); - + count_hash_items(L, lua_key_index(ligatures),nl); if (nl > 0) { + /* ligatures table still on stack */ cligs = xcalloc((unsigned) (nl + 1), sizeof(liginfo)); - lua_rawgeti(L, LUA_REGISTRYINDEX, lua_key_index(ligatures)); - lua_rawget(L, -2); - if (lua_istable(L, -1)) { /* do ligs */ - ctr = 0; - lua_pushnil(L); - while (lua_next(L, -2) != 0) { - k = non_boundarychar; - lt = lua_type(L,-2); - if (lt == LUA_TNUMBER) { - k=(int)lua_tonumber(L, -2); /* adjacent char */ - if (k < 0) { - k = non_boundarychar; - } - } else if (lt == LUA_TSTRING) { - s = lua_tostring(L, -2); - if (lua_key_eq(s, right_boundary)) { - k = right_boundarychar; - if (!has_right_boundary(f)) - set_right_boundary(f, get_charinfo(f, right_boundarychar)); - } - } - r = -1; - if (lua_istable(L, -1)) { - r = lua_numeric_field_by_index(L, lua_key_index(char), -1); /* ligature */ + ctr = 0; + lua_pushnil(L); /* traverse hash */ + while (lua_next(L, -2) != 0) { + k = non_boundarychar; + lt = lua_type(L,-2); + if (lt == LUA_TNUMBER) { + k = (int) lua_tointeger(L, -2); /* adjacent char */ + if (k < 0) { + k = non_boundarychar; } - if (r != -1 && k != non_boundarychar) { - t = n_enum_field(L, lua_key_index(type), 0, ligature_type_strings); - set_ligature_item(cligs[ctr], (char) ((t * 2) + 1), k, r); - ctr++; - } else { - luatex_warn - ("lua-loaded font %s char [U+%X] has an invalid ligature field!", - font_name(f), (int) i); + } else if (lt == LUA_TSTRING) { + s = lua_tostring(L, -2); + if (lua_key_eq(s, right_boundary)) { + k = right_boundarychar; + if (!has_right_boundary(f)) + set_right_boundary(f, get_charinfo(f, right_boundarychar)); } - lua_pop(L, 1); /* iterator value */ } - /* guard against empty tables */ - if (ctr > 0) { - set_ligature_item(cligs[ctr], 0, end_ligature, 0); - set_charinfo_ligatures(co, cligs); + r = -1; + if (lua_istable(L, -1)) { + r = lua_numeric_field_by_index(L, lua_key_index(char), -1); /* ligature */ + } + if (r != -1 && k != non_boundarychar) { + t = n_enum_field(L, lua_key_index(type), 0, ligature_type_strings); + set_ligature_item(cligs[ctr], (char) ((t * 2) + 1), k, r); + ctr++; } else { - luatex_warn - ("lua-loaded font %s char [U+%X] has an invalid ligatures field!", - font_name(f), (int) i); + formatted_warning("font", "lua-loaded font %s char U+%X has an invalid ligature field", + font_name(f), (int) i); } + lua_pop(L, 1); /* iterator value */ + } + /* guard against empty tables */ + if (ctr > 0) { + set_ligature_item(cligs[ctr], 0, end_ligature, 0); + set_charinfo_ligatures(co, cligs); + } else { + formatted_warning("font", "lua-loaded font %s char U+%X has an invalid ligatures field", + font_name(f), (int) i); } lua_pop(L, 1); /* ligatures table */ } } } - - @ The caller has to fix the state of the lua stack when there is an error! @c @@ -1351,9 +1351,6 @@ int font_from_lua(lua_State * L, int f) lua_pop(L,1); /* the table is at stack index -1 */ - /*if (luaS_width_index == 0) - init_font_string_pointers(L); - */ s = n_string_field_copy(L,lua_key_index(area), ""); set_font_area(f, s); @@ -1368,7 +1365,7 @@ int font_from_lua(lua_State * L, int f) set_font_fullname(f, s); if (s == NULL) { - luatex_fail("lua-loaded font [%d] has no name!", f); + formatted_error("font","lua-loaded font '%d' has no name!", f); return false; } s = n_string_field_copy(L, lua_key_index(psname), NULL); @@ -1428,25 +1425,24 @@ int font_from_lua(lua_State * L, int f) } /* now fetch the base fonts, if needed */ - n = count_hash_items(L, lua_key_index(fonts)); + count_hash_items(L, lua_key_index(fonts), n); if (n > 0) { + /* font table still on stack */ l_fonts = xmalloc((unsigned) ((unsigned) (n + 2) * sizeof(int))); memset(l_fonts, 0, (size_t) ((unsigned) (n + 2) * sizeof(int))); - lua_rawgeti(L, LUA_REGISTRYINDEX, lua_key_index(fonts)); - lua_rawget(L, -2); for (i = 1; i <= n; i++) { lua_rawgeti(L, -1, i); if (lua_istable(L, -1)) { lua_key_rawgeti(id); if (lua_isnumber(L, -1)) { - l_fonts[i]=(int)lua_tonumber(L, -1); + l_fonts[i] = (int) lua_tointeger(L, -1); if (l_fonts[i] == 0) { l_fonts[i] = (int) f; } - lua_pop(L, 2); /* pop id and entry */ + lua_pop(L, 2); /* pop id and entry */ continue; } - lua_pop(L, 1); /* pop id */ + lua_pop(L, 1); /* pop id */ }; ss = NULL; if (lua_istable(L, -1)) { @@ -1464,20 +1460,18 @@ int font_from_lua(lua_State * L, int f) l_fonts[i] = find_font_id(ss, t); lua_settop(L, s_top); } else { - luatex_fail("Invalid local font in font %s!\n", font_name(f)); + formatted_error("font","invalid local font in lua-loaded font '%s'", font_name(f)); } - lua_pop(L, 1); /* pop list entry */ + lua_pop(L, 1); /* pop list entry */ } - lua_pop(L, 1); /* pop list entry */ + lua_pop(L, 1); /* pop font table */ + } else if (font_type(f) == virtual_font_type) { + formatted_error("font","invalid local fonts in lua-loaded font '%s'", font_name(f)); } else { - if (font_type(f) == virtual_font_type) { - luatex_fail("Invalid local fonts in font %s!\n", font_name(f)); - } else { - l_fonts = xmalloc(3 * sizeof(int)); - l_fonts[0] = 0; - l_fonts[1] = f; - l_fonts[2] = 0; - } + l_fonts = xmalloc(3 * sizeof(int)); + l_fonts[0] = 0; + l_fonts[1] = f; + l_fonts[2] = 0; } /* parameters */ @@ -1522,9 +1516,6 @@ int font_from_lua(lua_State * L, int f) lua_pop(L, 1); } if (bc != -1) { -#if 0 - fprintf(stdout,"defined a font at %d with %d-%d\n",f,bc,ec); -#endif font_malloc_charinfo(f, num); set_font_bc(f, bc); set_font_ec(f, ec); @@ -1532,7 +1523,7 @@ int font_from_lua(lua_State * L, int f) while (lua_next(L, -2) != 0) { lt = lua_type(L,-2); if (lt == LUA_TNUMBER) { - i=(int)lua_tonumber(L, -2); + i = (int) lua_tointeger(L, -2); if (i >= 0) { font_char_from_lua(L, f, i, l_fonts, !no_math); } @@ -1550,10 +1541,13 @@ int font_from_lua(lua_State * L, int f) } lua_pop(L, 1); - /* handle font expansion last: the |copy_font| routine is called eventually, - and that needs to know |bc| and |ec|. */ + /* + Handle font expansion last: the |copy_font| routine is called eventually, + and that needs to know |bc| and |ec|. + */ + if (font_type(f) != virtual_font_type) { - int fstep = lua_numeric_field_by_index(L, lua_key_index(step), 0); + int fstep = lua_numeric_field_by_index(L, lua_key_index(step), 0); if (fstep < 0) fstep = 0; if (fstep > 100) @@ -1582,7 +1576,7 @@ int font_from_lua(lua_State * L, int f) } else { /* jikes, no characters */ - luatex_warn("lua-loaded font [%d] (%s) has no characters!", f, font_name(f)); + formatted_warning("font","lua-loaded font '%d' with name '%s' has no characters", f, font_name(f)); } if (save_ref > 0) { @@ -1594,9 +1588,8 @@ int font_from_lua(lua_State * L, int f) } } else { /* jikes, no characters */ - luatex_warn("lua-loaded font [%d] (%s) has no character table!", f, font_name(f)); + formatted_warning("font","lua-loaded font '%d' with name '%s' has no character table", f, font_name(f)); } - if (l_fonts != NULL) free(l_fonts); return true; @@ -1605,79 +1598,44 @@ int font_from_lua(lua_State * L, int f) @* Ligaturing. @c -#define assert_disc(a) \ - assert(pre_break(a)!=null); /* expect |head_node| */ \ - assert(type(pre_break(a))==nesting_node); \ - assert((vlink_pre_break(a)==null && tlink_pre_break(a)==null) || \ - tail_of_list(vlink_pre_break(a))==tlink_pre_break(a)); \ - assert(post_break(a)!=null); /* expect |head_node| */ \ - assert(type(post_break(a))==nesting_node); \ - assert((vlink_post_break(a)==null && tlink_post_break(a)==null) || \ - tail_of_list(vlink_post_break(a))==tlink_post_break(a)); \ - assert(no_break(a)!=null); /* expect |head_node| */ \ - assert(type(no_break(a))==nesting_node); \ - assert((vlink_no_break(a)==null && tlink_no_break(a)==null) || \ - tail_of_list(vlink_no_break(a))==tlink_no_break(a)); - static void nesting_append(halfword nest1, halfword newn) { halfword tail = tlink(nest1); - assert(alink(nest1) == null); - assert(vlink(newn) == null); - assert(alink(newn) == null); if (tail == null) { - assert(vlink(nest1) == null); couple_nodes(nest1, newn); } else { - assert(vlink(tail) == null); - assert(tail_of_list(vlink(nest1)) == tail); couple_nodes(tail, newn); } tlink(nest1) = newn; } - static void nesting_prepend(halfword nest1, halfword newn) { halfword head = vlink(nest1); - assert(alink(nest1) == null); - assert(vlink(newn) == null); - assert(alink(newn) == null); couple_nodes(nest1, newn); if (head == null) { - assert(tlink(nest1) == null); tlink(nest1) = newn; } else { - assert(alink(head) == nest1); - assert(tail_of_list(head) == tlink(nest1)); couple_nodes(newn, head); } } - static void nesting_prepend_list(halfword nest1, halfword newn) { halfword head = vlink(nest1); - assert(alink(nest1) == null); - assert(alink(newn) == null); couple_nodes(nest1, newn); if (head == null) { - assert(tlink(nest1) == null); tlink(nest1) = tail_of_list(newn); } else { halfword tail = tail_of_list(newn); - assert(alink(head) == nest1); - assert(tail_of_list(head) == tlink(nest1)); couple_nodes(tail, head); } } - static int test_ligature(liginfo * lig, halfword left, halfword right) { if (type(left) != glyph_node) return 0; - assert(type(right) == glyph_node); if (font(left) != font(right)) return 0; if (is_ghost(left) || is_ghost(right)) @@ -1689,7 +1647,6 @@ static int test_ligature(liginfo * lig, halfword left, halfword right) return 0; } - static int try_ligature(halfword * frst, halfword fwd) { halfword cur = *frst; @@ -1742,7 +1699,6 @@ static int try_ligature(halfword * frst, halfword fwd) halfword prev = alink(cur); uncouple_node(cur); lig_ptr(newgl) = cur; - assert(prev != null); couple_nodes(prev, newgl); cur = newgl; /* as cur has disappeared */ } @@ -1765,7 +1721,6 @@ static int try_ligature(halfword * frst, halfword fwd) couple_nodes(newgl, next); } } - /* check and return */ *frst = cur; return 1; @@ -1773,7 +1728,6 @@ static int try_ligature(halfword * frst, halfword fwd) return 0; } - @ there shouldn't be any ligatures here - we only add them at the end of |xxx_break| in a \.{DISC-1 - DISC-2} situation and we stop processing \.{DISC-1} (we continue with \.{DISC-1}'s |post_| and |no_break|. @@ -1786,16 +1740,15 @@ static halfword handle_lig_nest(halfword root, halfword cur) while (vlink(cur) != null) { halfword fwd = vlink(cur); if (type(cur) == glyph_node && type(fwd) == glyph_node && - font(cur) == font(fwd) && try_ligature(&cur, fwd)) + font(cur) == font(fwd) && try_ligature(&cur, fwd)) { continue; + } cur = vlink(cur); - assert(vlink(alink(cur)) == cur); } tlink(root) = cur; return root; } - static halfword handle_lig_word(halfword cur) { halfword right = null; @@ -1834,7 +1787,6 @@ static halfword handle_lig_word(halfword cur) right = null; continue; } - assert(alink(fwd) == cur); if (type(fwd) == glyph_node) { /* |GLYPH - GLYPH| */ if (font(cur) != font(fwd)) break; @@ -1847,7 +1799,6 @@ static halfword handle_lig_word(halfword cur) halfword nob = vlink_no_break(fwd); halfword next, tail; liginfo lig; - assert_disc(fwd); /* Check on: a{b?}{?}{?} and a+b=>B : {B?}{?}{a?} */ /* Check on: a{?}{?}{b?} and a+b=>B : {a?}{?}{B?} */ if ((pre != null && type(pre) == glyph_node @@ -1856,7 +1807,6 @@ static halfword handle_lig_word(halfword cur) && test_ligature(&lig, cur, nob))) { /* move cur from before disc, to skipped part */ halfword prev = alink(cur); - assert(vlink(prev) == cur); uncouple_node(cur); couple_nodes(prev, fwd); nesting_prepend(no_break(fwd), cur); @@ -1871,8 +1821,6 @@ static halfword handle_lig_word(halfword cur) && test_ligature(&lig, cur, next)) { /* move |cur| from before |disc| to |no_break| part */ halfword prev = alink(cur); - assert(alink(next) == fwd); - assert(vlink(prev) == cur); uncouple_node(cur); couple_nodes(prev, fwd); couple_nodes(no_break(fwd), cur); /* we {\it know\/} it's empty */ @@ -1900,7 +1848,8 @@ static halfword handle_lig_word(halfword cur) /* no need to reset |right|, we're going to leave the loop anyway */ } break; - } else { /* fwd is something unknown */ + } else { + /* fwd is something unknown */ if (right == null) break; couple_nodes(cur, right); @@ -1910,8 +1859,6 @@ static halfword handle_lig_word(halfword cur) } /* A discretionary followed by ... */ } else if (type(cur) == disc_node) { - - assert_disc(cur); /* If \.{{?}{x}{?}} or \.{{?}{?}{y}} then ... */ if (vlink_no_break(cur) != null || vlink_post_break(cur) != null) { halfword prev = 0; @@ -1919,11 +1866,8 @@ static halfword handle_lig_word(halfword cur) liginfo lig; if (subtype(cur) == select_disc) { prev = alink(cur); - assert(type(prev) == disc_node - && subtype(prev) == init_disc); if (vlink_post_break(cur) != null) - handle_lig_nest(post_break(prev), - vlink_post_break(prev)); + handle_lig_nest(post_break(prev), vlink_post_break(prev)); if (vlink_no_break(cur) != null) handle_lig_nest(no_break(prev), vlink_no_break(prev)); } @@ -1976,15 +1920,13 @@ static halfword handle_lig_word(halfword cur) handle_lig_nest(post_break(cur), pst); } if (fwd != null && type(fwd) == disc_node) { - halfword next = vlink(fwd); - if (vlink_no_break(fwd) == null && - vlink_post_break(fwd) == null && - next != null && - type(next) == glyph_node && - ((tlink_post_break(cur) != null && - test_ligature(&lig, tlink_post_break(cur), next)) || - (tlink_no_break(cur) != null && - test_ligature(&lig, tlink_no_break(cur), next)))) { + halfword next = vlink(fwd); + if (vlink_no_break(fwd) == null + && vlink_post_break(fwd) == null + && next != null + && type(next) == glyph_node + && ((tlink_post_break(cur) != null && test_ligature(&lig, tlink_post_break(cur), next)) || + (tlink_no_break (cur) != null && test_ligature(&lig, tlink_no_break (cur), next)))) { /* Building an |init_disc| followed by a |select_disc| \.{{a-}{b}{AB} {-}{}{}} 'c' */ @@ -1996,19 +1938,14 @@ static halfword handle_lig_word(halfword cur) nesting_append(post_break(fwd), copy_node(next)); /* \.{{a-}{b}{AB} {-}{c}{-}} */ if (vlink_no_break(cur) != null) { - nesting_prepend(no_break(fwd), - copy_node(vlink_pre_break(fwd))); + nesting_prepend(no_break(fwd), copy_node(vlink_pre_break(fwd))); } /* \.{{a-}{b}{AB} {b-}{c}{-}} */ if (vlink_post_break(cur) != null) - nesting_prepend_list(pre_break(fwd), - copy_node_list(vlink_post_break - (cur))); + nesting_prepend_list(pre_break(fwd), copy_node_list(vlink_post_break(cur))); /* \.{{a-}{b}{AB} {b-}{c}{AB-}} */ if (vlink_no_break(cur) != null) { - nesting_prepend_list(no_break(fwd), - copy_node_list(vlink_no_break - (cur))); + nesting_prepend_list(no_break(fwd), copy_node_list(vlink_no_break(cur))); } /* \.{{a-}{b}{ABC} {b-}{c}{AB-}} */ tail = tlink_no_break(cur); @@ -2025,18 +1962,13 @@ static halfword handle_lig_word(halfword cur) } } - } else { /* NO GLYPH NOR DISC */ + } else { + /* NO GLYPH NOR DISC */ return cur; } /* step-to-next-node */ - { - halfword prev = cur; - /* \.{--\\par} allows |vlink(cur)| to be null */ - cur = vlink(cur); - if (cur != null) { - assert(alink(cur) == prev); - } - } + /* \.{--\\par} allows |vlink(cur)| to be null */ + cur = vlink(cur); } return cur; @@ -2047,7 +1979,7 @@ static halfword handle_lig_word(halfword cur) @c halfword handle_ligaturing(halfword head, halfword tail) { - halfword save_tail1; /* trick to allow explicit |node==null| tests */ + halfword save_tail1; /* trick to allow explicit |node==null| tests */ halfword cur, prev; if (vlink(head) == null) @@ -2067,7 +1999,6 @@ halfword handle_ligaturing(halfword head, halfword tail) } prev = cur; cur = vlink(cur); - assert(cur == null || alink(cur) == prev); } if (prev == null) prev = tail; @@ -2090,7 +2021,6 @@ static void add_kern_before(halfword left, halfword right) if (k != 0) { halfword kern = new_kern(k); halfword prev = alink(right); - assert(vlink(prev) == right); couple_nodes(prev, kern); couple_nodes(kern, right); /* update the attribute list (inherit from left) */ @@ -2101,7 +2031,6 @@ static void add_kern_before(halfword left, halfword right) } } - static void add_kern_after(halfword left, halfword right, halfword aft) { if ((!is_rightghost(right)) && @@ -2110,7 +2039,6 @@ static void add_kern_after(halfword left, halfword right, halfword aft) if (k != 0) { halfword kern = new_kern(k); halfword next = vlink(aft); - assert(next == null || alink(next) == aft); couple_nodes(aft, kern); try_couple_nodes(kern, next); /* update the attribute list (inherit from left == aft) */ @@ -2121,13 +2049,10 @@ static void add_kern_after(halfword left, halfword right, halfword aft) } } - static void do_handle_kerning(halfword root, halfword init_left, halfword init_right) { halfword cur = vlink(root); halfword left = null; - assert(init_left == null || type(init_left) == glyph_node); - assert(init_right == null || type(init_right) == glyph_node); if (cur == null) { if (init_left != null && init_right != null) { add_kern_after(init_left, init_right, root); @@ -2155,8 +2080,7 @@ static void do_handle_kerning(halfword root, halfword init_left, halfword init_r left = cur; } else { if (type(cur) == disc_node) { - halfword right = - type(vlink(cur)) == glyph_node ? vlink(cur) : null; + halfword right = type(vlink(cur)) == glyph_node ? vlink(cur) : null; do_handle_kerning(pre_break(cur), left, null); do_handle_kerning(post_break(cur), null, right); if (vlink_post_break(cur) != null) @@ -2184,8 +2108,6 @@ static void do_handle_kerning(halfword root, halfword init_left, halfword init_r if (next != null) { couple_nodes(prev, next); tlink(root) = next; - assert(vlink(next) == null); - assert(type(next) == kern_node); } else if (prev != root) { vlink(prev) = null; tlink(root) = prev; @@ -2198,7 +2120,6 @@ static void do_handle_kerning(halfword root, halfword init_left, halfword init_r } } - halfword handle_kerning(halfword head, halfword tail) { halfword save_link; @@ -2231,25 +2152,16 @@ static halfword run_lua_ligkern_callback(halfword head, halfword tail, int callb luatex_error(L, (i == LUA_ERRRUN ? 0 : 1)); return tail; } - /* next two lines disabled to be compatible with the manual */ -#if 0 - tail = nodelist_from_lua(L); - if (fix_node_lists) -#endif - fix_node_list(head); + fix_node_list(head); lua_settop(L, top); return tail; } - halfword new_ligkern(halfword head, halfword tail) { int callback_id = 0; - - assert(head != null); if (vlink(head) == null) return tail; - callback_id = callback_defined(ligaturing_callback); if (callback_id > 0) { tail = run_lua_ligkern_callback(head, tail, callback_id); @@ -2258,12 +2170,12 @@ halfword new_ligkern(halfword head, halfword tail) } else if (callback_id == 0) { tail = handle_ligaturing(head, tail); } - callback_id = callback_defined(kerning_callback); if (callback_id > 0) { tail = run_lua_ligkern_callback(head, tail, callback_id); - if (tail == null) + if (tail == null) { tail = tail_of_list(head); + } } else if (callback_id == 0) { halfword nest1 = new_node(nesting_node, 1); halfword cur = vlink(head); diff --git a/Build/source/texk/web2c/luatexdir/font/mapfile.w b/Build/source/texk/web2c/luatexdir/font/mapfile.w index 70abf22bf0d..939468af4d8 100644 --- a/Build/source/texk/web2c/luatexdir/font/mapfile.w +++ b/Build/source/texk/web2c/luatexdir/font/mapfile.w @@ -164,17 +164,13 @@ int avl_do_entry(fm_entry * fm, int mode) if (p != NULL) { switch (mode) { case FM_DUPIGNORE: - luatex_warn - ("fontmap entry for `%s' already exists, duplicates ignored", - fm->tfm_name); + formatted_warning("map file", "entry for '%s' already exists, duplicates ignored", fm->tfm_name); delete_new = 1; break; case FM_REPLACE: case FM_DELETE: if (is_inuse(p)) { - luatex_warn - ("fontmap entry for `%s' has been used, replace/delete not allowed", - fm->tfm_name); + formatted_warning("map file", "entry for '%s' has been used, replace/delete not allowed", fm->tfm_name); delete_new = 1; } else { a = avl_delete(tfm_tree, p); @@ -220,8 +216,8 @@ static int check_fm_entry(fm_entry * fm, boolean warn) if (is_fontfile(fm) && !is_included(fm)) { if (warn) - luatex_warn - ("ambiguous entry for `%s': font file present but not included, " + formatted_warning("map file", + "ambiguous entry for '%s': font file present but not included, " "will be treated as font file not present", fm->tfm_name); xfree(fm->ff_name); /* do not set variable |a| as this entry will be still accepted */ @@ -230,33 +226,27 @@ static int check_fm_entry(fm_entry * fm, boolean warn) /* if both ps_name and font file are missing, drop this entry */ if (fm->ps_name == NULL && !is_fontfile(fm)) { if (warn) - luatex_warn - ("invalid entry for `%s': both ps_name and font file missing", - fm->tfm_name); + formatted_warning("map file", "invalid entry for '%s': both ps_name and font file missing", fm->tfm_name); a += 1; } /* TrueType fonts cannot be reencoded without subsetting */ if (is_truetype(fm) && is_reencoded(fm) && !is_subsetted(fm)) { if (warn) - luatex_warn - ("invalid entry for `%s': only subsetted TrueType font can be reencoded", - fm->tfm_name); + formatted_warning("map file", "invalid entry for '%s': only subsetted TrueType font can be reencoded", fm->tfm_name); a += 2; } /* the value of SlantFont and ExtendFont must be reasonable */ if (fm->slant < FONT_SLANT_MIN || fm->slant > FONT_SLANT_MAX) { if (warn) - luatex_warn - ("invalid entry for `%s': too big value of SlantFont (%g)", + formatted_warning("map file", "invalid entry for '%s': value '%g' is to large for SlantFont", fm->tfm_name, fm->slant / 1000.0); a += 8; } if (fm->extend < FONT_EXTEND_MIN || fm->extend > FONT_EXTEND_MAX) { if (warn) - luatex_warn - ("invalid entry for `%s': too big value of ExtendFont (%g)", + formatted_warning("map file", "invalid entry for '%s': value '%g' is too large for ExtendFont", fm->tfm_name, fm->extend / 1000.0); a += 16; } @@ -265,8 +255,7 @@ static int check_fm_entry(fm_entry * fm, boolean warn) if (fm->pid != -1 && !(is_truetype(fm) && is_subsetted(fm) && !is_reencoded(fm))) { if (warn) - luatex_warn - ("invalid entry for `%s': PidEid can be used only with subsetted non-reencoded TrueType fonts", + formatted_warning("map file", "invalid entry for '%s': PidEid can be used only with subsetted non-reencoded TrueType fonts", fm->tfm_name); a += 32; } @@ -335,7 +324,7 @@ static void fm_scan_line(void) float d; fm_entry *fm; char fm_line[FM_BUF_SIZE], buf[FM_BUF_SIZE]; - char *p, *q, *s; + char *p, *q, *s; char *r = NULL; switch (mitem->type) { case MAPFILE: @@ -405,9 +394,7 @@ static void fm_scan_line(void) for (r = s; *r != ' ' && *r != '"' && *r != '\0'; r++); /* jump over name */ c = *r; /* remember char for temporary end of string */ *r = '\0'; - luatex_warn - ("invalid entry for `%s': unknown name `%s' ignored", - fm->tfm_name, s); + formatted_warning("map file", "invalid entry for '%s': unknown name '%s' ignored", fm->tfm_name, s); *r = (char) c; } } else @@ -417,9 +404,7 @@ static void fm_scan_line(void) if (*r == '"') /* closing quote */ r++; else { - luatex_warn - ("invalid entry for `%s': closing quote missing", - fm->tfm_name); + formatted_warning("map file", "invalid entry for '%s': closing quote missing", fm->tfm_name); goto bad_line; } break; @@ -525,14 +510,14 @@ static void fm_read_info(void) fm_file = NULL; } } else { - luatex_warn("cannot open font map file (%s)", cur_file_name); + formatted_warning("map file", "cannot open font map file '%s'", cur_file_name); } } else { - luatex_warn("cannot open font map file (%s)", cur_file_name); + formatted_warning("map file", "cannot open font map file '%s'", cur_file_name); } } else { if (!fm_open(cur_file_name)) { - luatex_warn("cannot open font map file (%s)", cur_file_name); + formatted_warning("map file", "cannot open font map file '%s'", cur_file_name); } else { fm_read_file(); report_start_file(filetype_map,cur_file_name); @@ -549,7 +534,7 @@ static void fm_read_info(void) } break; case MAPLINE: - cur_file_name = NULL; /* makes luatex_warn() shorter */ + cur_file_name = NULL; fm_scan_line(); break; default: diff --git a/Build/source/texk/web2c/luatexdir/font/pkin.w b/Build/source/texk/web2c/luatexdir/font/pkin.w index 18c96b20edc..a5d3eb4bccb 100644 --- a/Build/source/texk/web2c/luatexdir/font/pkin.w +++ b/Build/source/texk/web2c/luatexdir/font/pkin.w @@ -56,14 +56,14 @@ typedef short shalfword; @ Now we have some routines to get stuff from the pk file. pkbyte returns the next byte from the pk file. - + @c static shalfword pkbyte(void) { register shalfword i; i = t3_getchar(); if (t3_eof()) - luatex_fail("unexpected eof in pk file"); + normal_error("type 3","unexpected EOF in pk file"); return (i); } @@ -200,7 +200,7 @@ static halfword rest(void) return (i); } } else { - luatex_fail("shouldn't happen"); + normal_error("type 3","pk issue that shouldn't happen"); return 0; /*NOTREACHED*/} } @@ -277,12 +277,6 @@ static void unpack(chardesc * cd) bitweight = 0; while (rowsleft > 0) { count = (*realfunc) (); -#ifdef DEBUG - if (turnon) - printf("(%d) ", (int) count); - else - printf("%d ", (int) count); -#endif while (count != 0) { if ((count < wordweight) && (count < hbit)) { if (turnon) @@ -319,7 +313,7 @@ static void unpack(chardesc * cd) turnon = !turnon; } if ((rowsleft != 0) || ((int) hbit != cd->cwidth)) - luatex_fail("error while unpacking; more bits than required"); + normal_error("type 3","error while unpacking, more bits than required"); } } @@ -341,9 +335,9 @@ int readchar(boolean check_preamble, chardesc * cd) */ if (check_preamble) { if (pkbyte() != 247) - luatex_fail("bad pk file, expected pre"); + normal_error("type 3","bad pk file, expected pre"); if (pkbyte() != 89) - luatex_fail("bad version of pk file"); + normal_error("type 3","bad version of pk file"); for (i = pkbyte(); i > 0; i--) /* creator of pkfile */ (void) pkbyte(); (void) pkquad(); /* design size */ @@ -399,7 +393,7 @@ int readchar(boolean check_preamble, chardesc * cd) cd->yoff = pkquad(); } if (length <= 0) - luatex_fail("packet length (%i) too small", (int) length); + formatted_error("type 3","pk packet length '%i' too small", (int) length); unpack(cd); return 1; } else { @@ -424,7 +418,7 @@ int readchar(boolean check_preamble, chardesc * cd) case 246: break; default: - luatex_fail("unexpected command (%i)", (int) flagbyte); + formatted_error("type 3","unexpected pk command '%i'", (int) flagbyte); } } } diff --git a/Build/source/texk/web2c/luatexdir/font/sfnt.h b/Build/source/texk/web2c/luatexdir/font/sfnt.h index 3fbdb001ea4..dce4248e981 100644 --- a/Build/source/texk/web2c/luatexdir/font/sfnt.h +++ b/Build/source/texk/web2c/luatexdir/font/sfnt.h @@ -1,5 +1,5 @@ /* sfnt.h - + Copyright 2002 by Jin-Hwan Cho and Shunsaku Hirata, the dvipdfmx project team Copyright 2006-2008 Taco Hoekwater @@ -27,18 +27,6 @@ # include # endif /* HAVE_CONFIG_H_ */ -# ifndef pdfTeX -# include "mfileio.h" -# include "numbers.h" -# include "pdfobj.h" -# endif - -# ifdef XETEX -# include "ft2build.h" -# include FT_FREETYPE_H -# include FT_TRUETYPE_TABLES_H -# endif - /* Data Types as described in Apple's TTRefMan */ typedef unsigned char BYTE; typedef signed char ICHAR; @@ -49,8 +37,7 @@ typedef signed long LONG; typedef unsigned long Fixed; /* 16.16-bit signed fixed-point number */ typedef short FWord; typedef unsigned short uFWord; -typedef short F2Dot14; /* 16-bit signed fixed number with the low - 14 bits representing fraction. */ +typedef short F2Dot14; /* 16-bit signed fixed number with the low 14 bits representing fraction. */ struct sfnt_table { /* table header */ @@ -182,9 +169,6 @@ typedef struct { # define RELEASE(a) free(a) # define NEW(a,b) xmalloc((unsigned)((unsigned)(a)*sizeof(b))) # define RENEW(a,b,c) xrealloc(a, (unsigned)((unsigned)(b)*sizeof(c))) -# define TT_ERROR luatex_fail -# define WARN printf - # endif diff --git a/Build/source/texk/web2c/luatexdir/font/sfnt.w b/Build/source/texk/web2c/luatexdir/font/sfnt.w index 939fd0bfe0c..83e38990dd9 100644 --- a/Build/source/texk/web2c/luatexdir/font/sfnt.w +++ b/Build/source/texk/web2c/luatexdir/font/sfnt.w @@ -142,7 +142,7 @@ static void convert_tag(char *tag, unsigned long u_tag) @ Computes the max power of 2 <= n - + @c static unsigned max2floor(unsigned n) { @@ -281,7 +281,7 @@ ULONG sfnt_locate_table(sfnt * sfont, const char *tag) offset = sfnt_find_table_pos(sfont, tag); if (offset == 0) - TT_ERROR("sfnt: table not found..."); + normal_error("ttf","sfnt table not found"); sfnt_seek_set(sfont, (long) offset); @@ -429,7 +429,7 @@ pdf_obj *sfnt_create_FontFile_stream(sfnt * sfont) if (!sfont->buffer) { pdf_release_obj(stream); - TT_ERROR("Font file not opened or already closed..."); + normal_error("ttf","file not opened or already closed"); return NULL; } @@ -439,7 +439,7 @@ pdf_obj *sfnt_create_FontFile_stream(sfnt * sfont) nb_read = sfnt_read(wbuf, (int) MIN(length, 1024), sfont); if (nb_read < 0) { pdf_release_obj(stream); - TT_ERROR("Reading file failed..."); + normal_error("ttf","reading file failed"); return NULL; } else if (nb_read > 0) { pdf_add_stream(stream, wbuf, nb_read); diff --git a/Build/source/texk/web2c/luatexdir/font/subfont.w b/Build/source/texk/web2c/luatexdir/font/subfont.w index ea139c4e48c..0616bdad43c 100644 --- a/Build/source/texk/web2c/luatexdir/font/subfont.w +++ b/Build/source/texk/web2c/luatexdir/font/subfont.w @@ -105,7 +105,7 @@ static void sfd_getline(boolean expect_eof) *sfd_line = 10; return; } else - luatex_fail("unexpected end of file"); + normal_error("sub font","unexpected end of file"); } p = sfd_line; do { @@ -146,16 +146,15 @@ static sfd_entry *read_sfd(char *sfd_name) if (cur_file_name) { callback_id = callback_defined(read_sfd_file_callback); if (callback_id > 0) { - if (!(run_callback(callback_id, "S->bSd", cur_file_name, - &file_opened, &sfd_buffer, &sfd_size) && + if (!(run_callback(callback_id, "S->bSd", cur_file_name, &file_opened, &sfd_buffer, &sfd_size) && file_opened && sfd_size > 0)) { - luatex_warn("cannot open SFD file for reading (%s)", cur_file_name); + formatted_warning("ttf font","cannot open SFD file for reading '%s'", cur_file_name); cur_file_name = NULL; return NULL; } } else { if (!sfd_open(cur_file_name)) { - luatex_warn("cannot open SFD file for reading (%s)", cur_file_name); + formatted_warning("ttf font", "cannot open SFD file for reading '%s'", cur_file_name); cur_file_name = NULL; return NULL; } @@ -187,16 +186,16 @@ static sfd_entry *read_sfd(char *sfd_name) } else if (*p == 0) /* end of subfont */ break; if (sscanf(p, " %li %n", &i, &n) == 0) - luatex_fail("invalid token:\n%s", p); + formatted_error("sub font","invalid token: %s", p); p += n; if (*p == ':') { /* offset */ k = i; p++; } else if (*p == '_') { /* range */ if (sscanf(p + 1, " %li %n", &j, &n) == 0) - luatex_fail("invalid token:\n%s", p); + formatted_error("sub font","invalid token: %s", p); if (i > j || k + (j - i) > 255) - luatex_fail("invalid range:\n%s", p); + formatted_error("sub font","invalid range: %s", p); while (i <= j) sf->charcodes[k++] = i++; p += n + 1; diff --git a/Build/source/texk/web2c/luatexdir/font/texfont.h b/Build/source/texk/web2c/luatexdir/font/texfont.h index 682d1d892ad..3b2773109f2 100644 --- a/Build/source/texk/web2c/luatexdir/font/texfont.h +++ b/Build/source/texk/web2c/luatexdir/font/texfont.h @@ -22,8 +22,9 @@ main pascal program. There is a companion list in luatex.defines to keep web2c happy */ -/* this file is read at the end of ptexlib.h, which is called for at - the end of luatexcoerce.h, as well as from the C sources +/* + This file is read at the end of ptexlib.h, which is called for at + the end of luatexcoerce.h, as well as from the C sources. */ #ifndef TEXFONT_H @@ -32,6 +33,7 @@ # define pointer halfword /* these are dumped en block, so they need endianness tests */ + typedef struct liginfo { # ifdef WORDS_BIGENDIAN int adj; @@ -45,6 +47,7 @@ typedef struct liginfo { } liginfo; /* these are dumped en block, so they need endianness tests */ + typedef struct kerninfo { # ifdef WORDS_BIGENDIAN int adj; @@ -63,7 +66,9 @@ typedef struct extinfo { int advance; int extender; } extinfo; + /* todo: maybe create a 'math info structure' */ + typedef struct charinfo { char *name; /* postscript character name */ liginfo *ligatures; /* ligature items */ @@ -108,8 +113,7 @@ extern void add_charinfo_hor_variant(charinfo * ci, extinfo * ext); extern extinfo *copy_variants(extinfo * o); -extern extinfo *new_variant(int glyph, int startconnect, int endconnect, - int advance, int repeater); +extern extinfo *new_variant(int glyph, int startconnect, int endconnect, int advance, int repeater); extern scaled_whd get_charinfo_whd(internal_font_number f, int c); @@ -198,31 +202,31 @@ extern const char *font_type_strings[]; extern const char *font_format_strings[]; extern const char *font_embedding_strings[]; -# define font_checksum(a) font_tables[a]->_font_checksum -# define set_font_checksum(a,b) font_checksum(a) = b +# define font_checksum(a) font_tables[a]->_font_checksum +# define set_font_checksum(a,b) font_checksum(a) = b -# define font_check_0(a) ((font_tables[a]->_font_checksum&0xFF000000)>>24) -# define font_check_1(a) ((font_tables[a]->_font_checksum&0x00FF0000)>>16) -# define font_check_2(a) ((font_tables[a]->_font_checksum&0x0000FF00)>>8) -# define font_check_3(a) (font_tables[a]->_font_checksum&0x000000FF) +# define font_check_0(a) ((font_tables[a]->_font_checksum&0xFF000000)>>24) +# define font_check_1(a) ((font_tables[a]->_font_checksum&0x00FF0000)>>16) +# define font_check_2(a) ((font_tables[a]->_font_checksum&0x0000FF00)>>8) +# define font_check_3(a) (font_tables[a]->_font_checksum&0x000000FF) -# define font_size(a) font_tables[a]->_font_size -# define set_font_size(a,b) font_size(a) = b -# define font_dsize(a) font_tables[a]->_font_dsize -# define set_font_dsize(a,b) font_dsize(a) = b +# define font_size(a) font_tables[a]->_font_size +# define set_font_size(a,b) font_size(a) = b +# define font_dsize(a) font_tables[a]->_font_dsize +# define set_font_dsize(a,b) font_dsize(a) = b -# define font_units_per_em(a) font_tables[a]->_font_units_per_em -# define set_font_units_per_em(a,b) font_units_per_em(a) = b +# define font_units_per_em(a) font_tables[a]->_font_units_per_em +# define set_font_units_per_em(a,b) font_units_per_em(a) = b -# define font_name(a) font_tables[a]->_font_name -# define get_font_name(a) (unsigned char *)font_name(a) -# define set_font_name(f,b) font_name(f) = b -# define tex_font_name(a) maketexstring(font_name(a)) +# define font_name(a) font_tables[a]->_font_name +# define get_font_name(a) (unsigned char *)font_name(a) +# define set_font_name(f,b) font_name(f) = b +# define tex_font_name(a) maketexstring(font_name(a)) -# define font_area(a) font_tables[a]->_font_area -# define get_font_area(a) (unsigned char *)font_area(a) -# define set_font_area(f,b) font_area(f) = b -# define tex_font_area(a) maketexstring(font_area(a)) +# define font_area(a) font_tables[a]->_font_area +# define get_font_area(a) (unsigned char *)font_area(a) +# define set_font_area(f,b) font_area(f) = b +# define tex_font_area(a) maketexstring(font_area(a)) boolean cmp_font_area(int, str_number); @@ -260,8 +264,7 @@ boolean cmp_font_area(int, str_number); # define set_font_touched(a,b) font_touched(a) = b # define font_type(a) font_tables[a]->_font_type -# define set_font_type(a,b) { /* fprintf(stdout,"set font type of %s to %i: %s\n",font_name(a),b,__FILE__); */ \ - font_type(a) = b; } +# define set_font_type(a,b) font_type(a) = b; # define font_format(a) font_tables[a]->_font_format # define font_format_name(a) font_format_strings[font_tables[a]->_font_format] @@ -338,40 +341,42 @@ boolean cmp_font_area(int, str_number); # define left_boundarychar -1 # define right_boundarychar -2 -# define non_boundarychar -3 +# define non_boundarychar -3 -# define left_boundary(a) font_tables[a]->_left_boundary -# define has_left_boundary(a) (left_boundary(a)!=NULL) -# define set_left_boundary(a,b) font_reassign(left_boundary(a),b) +# define left_boundary(a) font_tables[a]->_left_boundary +# define has_left_boundary(a) (left_boundary(a)!=NULL) +# define set_left_boundary(a,b) font_reassign(left_boundary(a),b) -# define right_boundary(a) font_tables[a]->_right_boundary -# define has_right_boundary(a) (right_boundary(a)!=NULL) -# define set_right_boundary(a,b) font_reassign(right_boundary(a),b) +# define right_boundary(a) font_tables[a]->_right_boundary +# define has_right_boundary(a) (right_boundary(a)!=NULL) +# define set_right_boundary(a,b) font_reassign(right_boundary(a),b) -# define font_bchar(a) (right_boundary(a)!=NULL ? right_boundarychar : non_boundarychar) +# define font_bchar(a) (right_boundary(a)!=NULL ? right_boundarychar : non_boundarychar) /* font parameters */ -# define font_params(a) font_tables[a]->_font_params -# define param_base(a) font_tables[a]->_param_base -# define font_param(a,b) font_tables[a]->_param_base[b] +# define font_params(a) font_tables[a]->_font_params +# define param_base(a) font_tables[a]->_param_base +# define font_param(a,b) font_tables[a]->_param_base[b] extern void set_font_params(internal_font_number f, int b); -# define set_font_param(f,n,b) \ - { if (font_params(f)_font_math_params -# define math_param_base(a) font_tables[a]->_math_param_base -# define font_math_param(a,b) font_tables[a]->_math_param_base[b] +# define set_font_param(f,n,b) { \ + if (font_params(f)_font_math_params +# define math_param_base(a) font_tables[a]->_math_param_base +# define font_math_param(a,b) font_tables[a]->_math_param_base[b] extern void set_font_math_params(internal_font_number f, int b); -# define set_font_math_param(f,n,b) \ - { if (font_math_params(f)characters,c) + +# define quick_char_exists(f,c) (get_sa_item(font_tables[f]->characters,c).int_value) extern void set_charinfo_width(charinfo * ci, scaled val); extern void set_charinfo_height(charinfo * ci, scaled val); @@ -436,14 +443,13 @@ extern void set_charinfo_ef(charinfo * ci, scaled val); extern void set_charinfo_lp(charinfo * ci, scaled val); extern void set_charinfo_rp(charinfo * ci, scaled val); -extern void add_charinfo_math_kern(charinfo * ci, int type, scaled ht, - scaled krn); +extern void add_charinfo_math_kern(charinfo * ci, int type, scaled ht, scaled krn); extern int get_charinfo_math_kerns(charinfo * ci, int id); -# define set_char_used(f,a,b) do { \ - if (char_exists(f,a)) \ - set_charinfo_used(char_info(f,a),b); \ - } while (0) +# define set_char_used(f,a,b) do { \ + if (char_exists(f,a)) \ + set_charinfo_used(char_info(f,a),b); \ +} while (0) extern scaled get_charinfo_width(charinfo * ci); extern scaled get_charinfo_height(charinfo * ci); @@ -471,35 +477,30 @@ extern int ext_bot(internal_font_number f, int c); extern int ext_rep(internal_font_number f, int c); extern int ext_mid(internal_font_number f, int c); -# define set_ligature_item(f,b,c,d) { f.type = b; f.adj = c; f.lig = d; } - -# define set_kern_item(f,b,c) { f.adj = b; f.sc = c; } - +# define set_ligature_item(f,b,c,d) { f.type = b; f.adj = c; f.lig = d; } +# define set_kern_item(f,b,c) { f.adj = b; f.sc = c; } /* character information */ -# define non_char 65536 /* a code that can't match a real character */ -# define non_address 0 /* a spurious |bchar_label| */ - +# define non_char 65536 /* a code that can't match a real character */ +# define non_address 0 /* a spurious |bchar_label| */ /* character kerns and ligatures */ -# define end_kern 0x7FFFFF - /* otherchar value meaning "stop" */ -# define ignored_kern 0x800000 - /* otherchar value meaning "disabled" */ +# define end_kern 0x7FFFFF /* otherchar value meaning "stop" */ +# define ignored_kern 0x800000 /* otherchar value meaning "disabled" */ -# define charinfo_kern(b,c) b->kerns[c] +# define charinfo_kern(b,c) b->kerns[c] -# define kern_char(b) (b).adj -# define kern_kern(b) (b).sc -# define kern_end(b) ((b).adj == end_kern) -# define kern_disabled(b) ((b).adj > end_kern) +# define kern_char(b) (b).adj +# define kern_kern(b) (b).sc +# define kern_end(b) ((b).adj == end_kern) +# define kern_disabled(b) ((b).adj > end_kern) /* character ligatures */ -# define end_ligature 0x7FFFFF /* otherchar value meaning "stop" */ -# define ignored_ligature 0x800000 /* otherchar value meaning "disabled" */ +# define end_ligature 0x7FFFFF /* otherchar value meaning "stop" */ +# define ignored_ligature 0x800000 /* otherchar value meaning "disabled" */ # define charinfo_ligature(b,c) b->ligatures[c] @@ -510,10 +511,10 @@ extern int ext_mid(internal_font_number f, int c); # define lig_end(a) (lig_char(a) == end_ligature) # define lig_disabled(a) (lig_char(a) > end_ligature) -# define no_tag 0 /* vanilla character */ -# define lig_tag 1 /* character has a ligature/kerning program */ -# define list_tag 2 /* character has a successor in a charlist */ -# define ext_tag 3 /* character is extensible */ +# define no_tag 0 /* vanilla character */ +# define lig_tag 1 /* character has a ligature/kerning program */ +# define list_tag 2 /* character has a successor in a charlist */ +# define ext_tag 3 /* character is extensible */ extern scaled char_height(internal_font_number f, int c); extern scaled calc_char_width(internal_font_number f, int c, int ex); @@ -528,9 +529,9 @@ extern liginfo *char_ligatures(internal_font_number f, int c); extern kerninfo *char_kerns(internal_font_number f, int c); extern eight_bits *char_packets(internal_font_number f, int c); -# define has_lig(f,b) (char_exists(f,b) &&( char_ligatures(f,b) != NULL)) -# define has_kern(f,b) (char_exists(f,b) && (char_kerns(f,b) != NULL)) -# define has_packet(f,b) (char_exists(f,b) && (char_packets(f,b) != NULL)) +# define has_lig(f,b) (char_exists(f,b) &&( char_ligatures(f,b) != NULL)) +# define has_kern(f,b) (char_exists(f,b) && (char_kerns(f,b) != NULL)) +# define has_packet(f,b) (char_exists(f,b) && (char_packets(f,b) != NULL)) extern int char_remainder(internal_font_number f, int c); extern char char_tag(internal_font_number f, int c); @@ -578,7 +579,6 @@ extern void set_ef_code(internal_font_number f, int c, int i); int read_tfm_info(internal_font_number f, const char *nom, scaled s); - /* from dofont.c */ extern int read_font_info(pointer u, char *cnom, scaled s, int ndir); @@ -622,9 +622,7 @@ extern int make_vf_table(lua_State * L, const char *name, scaled s); # define get_charheight(f,c) (char_exists(f,c) ? char_height(f,c) : 0) # define get_chardepth(f,c) (char_exists(f,c) ? char_depth(f,c) : 0) -/* moved from pdffont.h */ - -extern int pk_dpi; /* PK pixel density value from \.{texmf.cnf} */ +extern int pk_dpi; /* PK pixel density value from \.{texmf.cnf} */ extern internal_font_number tfm_lookup(char *s, scaled fs); @@ -640,4 +638,4 @@ extern void make_font_copy(small_number a); extern void glyph_to_unicode(void); -#endif /* TEXFONT_H */ +#endif diff --git a/Build/source/texk/web2c/luatexdir/font/texfont.w b/Build/source/texk/web2c/luatexdir/font/texfont.w index 7cfb52215bc..06926a2f5a1 100644 --- a/Build/source/texk/web2c/luatexdir/font/texfont.w +++ b/Build/source/texk/web2c/luatexdir/font/texfont.w @@ -32,7 +32,6 @@ problematic |if 0 != null|. @c - #include "ptexlib.h" #include "lua/luatex-api.h" @@ -96,6 +95,7 @@ int new_font(void) int k; int id; charinfo *ci; + sa_tree_item sa_value = { 0 }; id = new_font_id(); font_bytes += (int) sizeof(texfont); /* most stuff is zero */ @@ -125,8 +125,7 @@ int new_font(void) set_font_param(id, k, 0); } /* character info zero is reserved for notdef */ - font_tables[id]->characters = new_sa_tree(1, 0); /* stack size 1, default item value 0 */ - + font_tables[id]->characters = new_sa_tree(1, 1, sa_value); /* stack size 1, default item value 0 */ ci = xcalloc(1, sizeof(charinfo)); set_charinfo_name(ci, xstrdup(".notdef")); font_tables[id]->charinfo = ci; @@ -148,23 +147,24 @@ void font_malloc_charinfo(internal_font_number f, int num) } @ @c -#define find_charinfo_id(f,c) get_sa_item(font_tables[f]->characters,c) +#define find_charinfo_id(f,c) (get_sa_item(font_tables[f]->characters,c).int_value) charinfo *get_charinfo(internal_font_number f, int c) { - sa_tree_item glyph; + int glyph; charinfo *ci; if (proper_char_index(c)) { - glyph = get_sa_item(font_tables[f]->characters, c); + glyph = get_sa_item(font_tables[f]->characters, c).int_value; if (!glyph) { - + sa_tree_item sa_value = { 0 }; int tglyph = ++font_tables[f]->charinfo_count; if (tglyph >= font_tables[f]->charinfo_size) { font_malloc_charinfo(f, 256); } font_tables[f]->charinfo[tglyph].ef = 1000; /* init */ - set_sa_item(font_tables[f]->characters, c, (sa_tree_item) tglyph, 1); /* 1= global */ - glyph = (sa_tree_item) tglyph; + sa_value.int_value = tglyph; + set_sa_item(font_tables[f]->characters, c, sa_value, 1); /* 1 = global */ + glyph = tglyph; } return &(font_tables[f]->charinfo[glyph]); } else if (c == left_boundarychar) { @@ -188,13 +188,13 @@ charinfo *get_charinfo(internal_font_number f, int c) @ @c static void set_charinfo(internal_font_number f, int c, charinfo * ci) { - sa_tree_item glyph; + int glyph; if (proper_char_index(c)) { - glyph = get_sa_item(font_tables[f]->characters, c); + glyph = get_sa_item(font_tables[f]->characters, c).int_value; if (glyph) { font_tables[f]->charinfo[glyph] = *ci; } else { - luatex_fail("font: %s", "character insertion failed"); + normal_error("font","character insertion failed"); } } else if (c == left_boundarychar) { set_left_boundary(f, ci); @@ -259,13 +259,10 @@ charinfo *copy_charinfo(charinfo * ci) /* horizontal and vertical extenders */ if (get_charinfo_vert_variants(ci) != NULL) { - set_charinfo_vert_variants(co, - copy_variants(get_charinfo_vert_variants - (ci))); + set_charinfo_vert_variants(co, copy_variants(get_charinfo_vert_variants(ci))); } if (get_charinfo_hor_variants(ci) != NULL) { - set_charinfo_hor_variants(co, - copy_variants(get_charinfo_hor_variants(ci))); + set_charinfo_hor_variants(co, copy_variants(get_charinfo_hor_variants(ci))); } x = ci->top_left_math_kerns; co->top_left_math_kerns = x; @@ -273,10 +270,8 @@ charinfo *copy_charinfo(charinfo * ci) co->top_left_math_kern_array = xmalloc((unsigned) (2 * (int) sizeof(scaled) * x)); for (k = 0; k < co->top_left_math_kerns; k++) { - co->top_left_math_kern_array[(2 * k)] = - ci->top_left_math_kern_array[(2 * k)]; - co->top_left_math_kern_array[(2 * k) + 1] = - ci->top_left_math_kern_array[(2 * k) + 1]; + co->top_left_math_kern_array[(2 * k)] = ci->top_left_math_kern_array[(2 * k)]; + co->top_left_math_kern_array[(2 * k) + 1] = ci->top_left_math_kern_array[(2 * k) + 1]; } } x = ci->top_right_math_kerns; @@ -285,10 +280,8 @@ charinfo *copy_charinfo(charinfo * ci) co->top_right_math_kern_array = xmalloc((unsigned) (2 * (int) sizeof(scaled) * x)); for (k = 0; k < co->top_right_math_kerns; k++) { - co->top_right_math_kern_array[(2 * k)] = - ci->top_right_math_kern_array[(2 * k)]; - co->top_right_math_kern_array[(2 * k) + 1] = - ci->top_right_math_kern_array[(2 * k) + 1]; + co->top_right_math_kern_array[(2 * k)] = ci->top_right_math_kern_array[(2 * k)]; + co->top_right_math_kern_array[(2 * k) + 1] = ci->top_right_math_kern_array[(2 * k) + 1]; } } x = ci->bottom_right_math_kerns; @@ -297,10 +290,8 @@ charinfo *copy_charinfo(charinfo * ci) co->bottom_right_math_kern_array = xmalloc((unsigned) (2 * (int) sizeof(scaled) * x)); for (k = 0; k < co->bottom_right_math_kerns; k++) { - co->bottom_right_math_kern_array[(2 * k)] = - ci->bottom_right_math_kern_array[(2 * k)]; - co->bottom_right_math_kern_array[(2 * k) + 1] = - ci->bottom_right_math_kern_array[(2 * k) + 1]; + co->bottom_right_math_kern_array[(2 * k)] = ci->bottom_right_math_kern_array[(2 * k)]; + co->bottom_right_math_kern_array[(2 * k) + 1] = ci->bottom_right_math_kern_array[(2 * k) + 1]; } } x = ci->bottom_left_math_kerns; @@ -309,14 +300,10 @@ charinfo *copy_charinfo(charinfo * ci) co->bottom_left_math_kern_array = xmalloc((unsigned) (2 * (int) sizeof(scaled) * x)); for (k = 0; k < co->bottom_left_math_kerns; k++) { - co->bottom_left_math_kern_array[(2 * k)] = - ci->bottom_left_math_kern_array[(2 * k)]; - co->bottom_left_math_kern_array[(2 * k) + 1] = - ci->bottom_left_math_kern_array[(2 * k) + 1]; + co->bottom_left_math_kern_array[(2 * k)] = ci->bottom_left_math_kern_array[(2 * k)]; + co->bottom_left_math_kern_array[(2 * k) + 1] = ci->bottom_left_math_kern_array[(2 * k) + 1]; } } - - return co; } @@ -375,8 +362,8 @@ static int lua_char_exists_callback(internal_font_number f, int c) lua_pop(L, 2); return 0; } - lua_pushnumber(L, f); - lua_pushnumber(L, c); + lua_pushinteger(L, f); + lua_pushinteger(L, c); if (lua_pcall(L, 2, 1, 0) != 0) { /* two args, 1 result */ fprintf(stdout, "error: %s\n", lua_tostring(L, -1)); lua_pop(L, 2); @@ -498,7 +485,6 @@ extinfo *copy_variants(extinfo * o) return h; } - @ @c static void dump_charinfo_variants(extinfo * o) { @@ -1098,7 +1084,6 @@ void set_font_math_params(internal_font_number f, int b) } } - @ @c int copy_font(int f) { @@ -1358,7 +1343,6 @@ void set_tag_code(internal_font_number f, int c, int i) } } - @ @c void set_lp_code(internal_font_number f, int c, int i) { @@ -1392,10 +1376,8 @@ void set_no_ligatures(internal_font_number f) { int c; charinfo *co; - if (font_tables[f]->ligatures_disabled) return; - co = char_info(f, left_boundarychar); set_charinfo_ligatures(co, NULL); co = char_info(f, right_boundarychar); /* this is weird */ @@ -1410,7 +1392,7 @@ void set_no_ligatures(internal_font_number f) @ @c liginfo get_ligature(internal_font_number f, int lc, int rc) { - int k; + int k = 0; liginfo t, u; charinfo *co; t.lig = 0; @@ -1418,7 +1400,6 @@ liginfo get_ligature(internal_font_number f, int lc, int rc) t.adj = 0; if (lc == non_boundarychar || rc == non_boundarychar || (!has_lig(f, lc))) return t; - k = 0; co = char_info(f, lc); while (1) { u = charinfo_ligature(co, k); @@ -1436,16 +1417,14 @@ liginfo get_ligature(internal_font_number f, int lc, int rc) return t; } - @ @c scaled raw_get_kern(internal_font_number f, int lc, int rc) { - int k; + int k = 0; kerninfo u; charinfo *co; if (lc == non_boundarychar || rc == non_boundarychar) return 0; - k = 0; co = char_info(f, lc); while (1) { u = charinfo_kern(co, k); @@ -1462,7 +1441,6 @@ scaled raw_get_kern(internal_font_number f, int lc, int rc) return 0; } - @ @c scaled get_kern(internal_font_number f, int lc, int rc) { @@ -1715,12 +1693,14 @@ static int undump_charinfo(int f) return i; } -#define undump_font_string(a) undump_int (x); \ - if (x>0) { \ - font_bytes += x; \ - s = xmalloc((unsigned)x); undump_things(*s,x); \ - a(f,s); } - +#define undump_font_string(a) \ + undump_int (x); \ + if (x>0) { \ + font_bytes += x; \ + s = xmalloc((unsigned)x); \ + undump_things(*s,x); \ + a(f,s); \ + } static void undump_font_entry(texfont * f) { @@ -1759,14 +1739,13 @@ static void undump_font_entry(texfont * f) /* *INDENT-ON* */ } - - void undump_font(int f) { int x, i; texfont *tt; charinfo *ci; char *s; + sa_tree_item sa_value = { 0 }; grow_font_table(f); tt = xmalloc(sizeof(texfont)); memset(tt, 0, sizeof(texfont)); @@ -1796,18 +1775,19 @@ void undump_font(int f) undump_things(*math_param_base(f), (font_math_params(f) + 1)); } - font_tables[f]->characters = new_sa_tree(1, 0); /* stack size 1, default item value 0 */ + /* stack size 1, default item value 0 */ + font_tables[f]->characters = new_sa_tree(1, 1, sa_value); ci = xcalloc(1, sizeof(charinfo)); set_charinfo_name(ci, xstrdup(".notdef")); font_tables[f]->charinfo = ci; undump_int(x); if (x) { - i = undump_charinfo(f); - } /* left boundary */ + i = undump_charinfo(f); /* left boundary */ + } undump_int(x); if (x) { - i = undump_charinfo(f); - } /* right boundary */ + i = undump_charinfo(f); /* right boundary */ + } i = font_bc(f); while (i < font_ec(f)) { @@ -1939,7 +1919,7 @@ void read_expand_font(void) normal_error("font expansion","font has been expanded with different auto expansion value"); } else { if (font_used(f)) - normal_warning("font expansion", "font should be expanded before its first use", true, true); + normal_warning("font expansion", "font should be expanded before its first use"); set_expand_params(f, auto_expand, stretch_limit, shrink_limit, font_step); } @@ -1997,14 +1977,13 @@ void make_font_copy(small_number a) void glyph_to_unicode(void) { str_number s1, s2; - scan_pdf_ext_toks(); + scan_toks(false, true); s1 = tokens_to_string(def_ref); delete_token_ref(def_ref); - scan_pdf_ext_toks(); + scan_toks(false, true); s2 = tokens_to_string(def_ref); delete_token_ref(def_ref); def_tounicode(s1, s2); flush_str(s2); flush_str(s1); } - diff --git a/Build/source/texk/web2c/luatexdir/font/tounicode.w b/Build/source/texk/web2c/luatexdir/font/tounicode.w index fe57bbe7e41..c213eee72c5 100644 --- a/Build/source/texk/web2c/luatexdir/font/tounicode.w +++ b/Build/source/texk/web2c/luatexdir/font/tounicode.w @@ -95,9 +95,8 @@ void def_tounicode(str_number glyph, str_number unistr) break; } } - if (l == 0 || valid_unistr == 0 || strlen(buf) == 0 - || strcmp(buf, notdef) == 0) { - luatex_warn("ToUnicode: invalid parameter(s): `%s' => `%s'", buf, p); + if (l == 0 || valid_unistr == 0 || strlen(buf) == 0 || strcmp(buf, notdef) == 0) { + formatted_warning("tounicode", "invalid parameter(s): %s -> %s", buf, p); return; } if (glyph_unicode_tree == NULL) { @@ -308,9 +307,6 @@ int write_tounicode(PDF pdf, char **glyph_names, char *name) int bfchar_count, bfrange_count, subrange_count; assert(strlen(name) + strlen(builtin_suffix) < SMALL_BUF_SIZE); if (glyph_unicode_tree == NULL) { -#ifdef DEBUG - luatex_warn("no GlyphToUnicode entry has been inserted yet!"); -#endif pdf->gen_tounicode = 0; return 0; } diff --git a/Build/source/texk/web2c/luatexdir/font/tt_glyf.w b/Build/source/texk/web2c/luatexdir/font/tt_glyf.w index 0345db62441..167d8df2038 100644 --- a/Build/source/texk/web2c/luatexdir/font/tt_glyf.w +++ b/Build/source/texk/web2c/luatexdir/font/tt_glyf.w @@ -47,7 +47,7 @@ static USHORT find_empty_slot(struct tt_glyphs *g) break; } if (gid == NUM_GLYPH_LIMIT) - TT_ERROR("No empty glyph slot available."); + normal_error("ttf","no empty glyph slot available."); return gid; } @@ -89,10 +89,10 @@ USHORT tt_add_glyph(struct tt_glyphs * g, USHORT gid, USHORT new_gid) ASSERT(g); if (g->used_slot[new_gid / 8] & (1 << (7 - (new_gid % 8)))) { - WARN("Slot %u already used.", new_gid); + formatted_warning("ttf","slot %u already used", new_gid); } else { if (g->num_glyphs + 1 >= NUM_GLYPH_LIMIT) - TT_ERROR("Too many glyphs."); + normal_error("ttf","too many glyphs"); if (g->num_glyphs >= g->max_glyphs) { g->max_glyphs = (USHORT) (g->max_glyphs + GLYPH_ARRAY_ALLOC_SIZE); @@ -193,20 +193,20 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g) ASSERT(g); if (sfont->type != SFNT_TYPE_TRUETYPE && sfont->type != SFNT_TYPE_TTC) - TT_ERROR("Invalid font type"); + normal_error("ttf","invalid font type"); if (g->num_glyphs > NUM_GLYPH_LIMIT) - TT_ERROR("Too many glyphs."); + normal_error("ttf","too many glyphs"); /* Read head, hhea, maxp, loca: - + unitsPerEm --> head numHMetrics --> hhea indexToLocFormat --> head - + numGlyphs --> maxp */ head = tt_read_head_table(sfont); @@ -214,7 +214,7 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g) maxp = tt_read_maxp_table(sfont); if (hhea->metricDataFormat != 0) - TT_ERROR("Unknown metricDataFormat."); + normal_error("ttf","unknown metricDataFormat"); g->emsize = head->unitsPerEm; @@ -252,7 +252,7 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g) for (i = 0; i <= maxp->numGlyphs; i++) location[i] = sfnt_get_ulong(sfont); } else { - TT_ERROR("Unknown IndexToLocFormat."); + normal_error("ttf","unknown IndexToLocFormat"); } w_stat = NEW(g->emsize + 2, USHORT); @@ -280,7 +280,7 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g) gid = g->gd[i].ogid; if (gid >= maxp->numGlyphs) - TT_ERROR("Invalid glyph index (gid %u)", gid); + formatted_error("ttf","invalid glyph index (gid %u)", gid); loc = location[gid]; len = location[gid + 1] - loc; @@ -304,7 +304,7 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g) if (len == 0) { /* Does not contains any data. */ continue; } else if (len < 10) { - TT_ERROR("Invalid TrueType glyph data (gid %u).", gid); + formatted_error("ttf","invalid glyph data (gid %u)", gid); } g->gd[i].data = p = NEW(len, BYTE); @@ -339,8 +339,7 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g) USHORT flags, cgid, new_gid; /* flag, gid of a component */ do { if (p >= endptr) - TT_ERROR("Invalid TrueType glyph data (gid %u): %u bytes", - gid, (unsigned int) len); + formatted_error("ttf","invalid glyph data (gid %u): %u bytes", gid, (unsigned int) len); /* * Flags and gid of component glyph are both USHORT. */ @@ -348,8 +347,7 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g) p += 2; cgid = (USHORT) (((*p) << 8) | *(p + 1)); if (cgid >= maxp->numGlyphs) { - TT_ERROR("Invalid gid (%u > %u) in composite glyph %u.", - cgid, maxp->numGlyphs, gid); + formatted_error("ttf","invalid gid (%u > %u) in composite glyph %u", cgid, maxp->numGlyphs, gid); } new_gid = tt_find_glyph(g, cgid); if (new_gid == 0) { @@ -371,7 +369,7 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g) TrueType instructions comes here: |length_of_instruction| (|ushort|) - + instruction (|byte * length_of_instruction|) */ } @@ -527,14 +525,14 @@ int tt_get_metrics(sfnt * sfont, struct tt_glyphs *g) sfont->stream == NULL #endif ) - TT_ERROR("File not opened."); + normal_error("ttf","file not opened"); if (sfont->type != SFNT_TYPE_TRUETYPE && sfont->type != SFNT_TYPE_TTC) - TT_ERROR("Invalid font type"); + normal_error("ttf","invalid font type"); /* Read head, hhea, maxp, loca: - + unitsPerEm --> head numHMetrics --> hhea @@ -548,7 +546,7 @@ int tt_get_metrics(sfnt * sfont, struct tt_glyphs *g) maxp = tt_read_maxp_table(sfont); if (hhea->metricDataFormat != 0) - TT_ERROR("Unknown metricDataFormat."); + normal_error("ttf","unknown metricDataFormat"); g->emsize = head->unitsPerEm; @@ -580,7 +578,7 @@ int tt_get_metrics(sfnt * sfont, struct tt_glyphs *g) for (i = 0; i <= maxp->numGlyphs; i++) location[i] = sfnt_get_ulong(sfont); } else { - TT_ERROR("Unknown IndexToLocFormat."); + normal_error("ttf","inknown IndexToLocFormat"); } w_stat = NEW(g->emsize + 2, USHORT); @@ -596,7 +594,7 @@ int tt_get_metrics(sfnt * sfont, struct tt_glyphs *g) gid = g->gd[i].ogid; if (gid >= maxp->numGlyphs) - TT_ERROR("Invalid glyph index (gid %u)", gid); + formatted_error("ttf","invalid glyph index (gid %u)", gid); loc = location[gid]; len = location[gid + 1] - loc; @@ -621,7 +619,7 @@ int tt_get_metrics(sfnt * sfont, struct tt_glyphs *g) if (len == 0) { /* Does not contains any data. */ continue; } else if (len < 10) { - TT_ERROR("Invalid TrueType glyph data (gid %u).", gid); + formatted_error("ttf","invalid glyph data (gid %u)", gid); } sfnt_seek_set(sfont, (long) (offset + loc)); diff --git a/Build/source/texk/web2c/luatexdir/font/tt_table.w b/Build/source/texk/web2c/luatexdir/font/tt_table.w index 3ebce2b99ca..8bd2f3b982d 100644 --- a/Build/source/texk/web2c/luatexdir/font/tt_table.w +++ b/Build/source/texk/web2c/luatexdir/font/tt_table.w @@ -45,7 +45,7 @@ char *tt_pack_head_table(struct tt_head_table *table) char *p, *data; if (table == NULL) - TT_ERROR("passed NULL pointer\n"); + normal_error("ttf","passed NULL pointer"); p = data = NEW(TT_HEAD_TABLE_SIZE, char); p += sfnt_put_ulong(p, (LONG) table->version); @@ -205,13 +205,13 @@ struct tt_hhea_table *tt_read_hhea_table(sfnt * sfont) } table->metricDataFormat = sfnt_get_short(sfont); if (table->metricDataFormat != 0) - TT_ERROR("unknown metricDaraFormat"); + normal_error("ttf","unknown metricDaraFormat"); table->numberOfHMetrics = sfnt_get_ushort(sfont); return table; } -@ vhea +@ vhea @c char *tt_pack_vhea_table(struct tt_vhea_table *table) { @@ -279,7 +279,7 @@ struct tt_VORG_table *tt_read_VORG_table(sfnt * sfont) sfnt_locate_table(sfont, "VORG"); if (sfnt_get_ushort(sfont) != 1 || sfnt_get_ushort(sfont) != 0) - TT_ERROR("Unsupported VORG version."); + normal_error("ttf","unsupported VORG version"); vorg->defaultVertOriginY = sfnt_get_short(sfont); vorg->numVertOriginYMetrics = sfnt_get_ushort(sfont); @@ -325,7 +325,7 @@ struct tt_longMetrics *tt_read_longMetrics(sfnt * sfont, USHORT numGlyphs, @ OS/2 table -this table may not exist +this table may not exist @c struct tt_os2__table *tt_read_os2__table(sfnt * sfont) { @@ -398,7 +398,7 @@ tt_get_name(sfnt * sfont, char *dest, USHORT destlen, name_offset = sfnt_locate_table(sfont, "name"); if (sfnt_get_ushort(sfont)) - TT_ERROR("Expecting zero"); + normal_error("ttf","expecting zero"); num_names = sfnt_get_ushort(sfont); string_offset = sfnt_get_ushort(sfont); @@ -443,7 +443,7 @@ USHORT tt_get_ps_fontname(sfnt * sfont, char *dest, USHORT destlen) (namelen = tt_get_name(sfont, dest, destlen, 3, 5, 0x412u, 6)) != 0) return namelen; - fprintf(stderr, "\n** Warning: No valid PostScript name available **\n"); + normal_warning("ttf","no valid PostScript name available"); /* Wrokaround for some bad TTfonts: Language ID value 0xffffu for `accept any language ID' @@ -452,7 +452,7 @@ USHORT tt_get_ps_fontname(sfnt * sfont, char *dest, USHORT destlen) /* Finally falling back to Mac Roman name field. Warning: Some bad Japanese TTfonts using SJIS encoded string in the - Mac Roman name field. + Mac Roman name field. */ namelen = tt_get_name(sfont, dest, destlen, 1, 0, 0, 1); } diff --git a/Build/source/texk/web2c/luatexdir/font/vfovf.w b/Build/source/texk/web2c/luatexdir/font/vfovf.w index d1054a679ab..714ef0f87a9 100644 --- a/Build/source/texk/web2c/luatexdir/font/vfovf.w +++ b/Build/source/texk/web2c/luatexdir/font/vfovf.w @@ -96,19 +96,21 @@ @ go out \.{VF} processing with an error message @c -#define bad_vf(a) { xfree(vf_buffer); print_nlp(); \ - tprint("Error in processing VF font ("); \ - tprint(font_name(f)); \ - tprint(".vf): "); \ - tprint(a); \ - tprint(", virtual font will be ignored"); \ - print_ln(); return; } - -#define lua_bad_vf(a) { xfree(vf_buffer); \ - lua_settop(L,s_top); \ - lua_pushnil(L); \ - lua_pushstring(L,a); \ - return 2; } +#define bad_vf(a) { \ + xfree(vf_buffer); \ + print_nlp(); \ + formatted_warning("virtual font","file '%s', %s, font will be ignored",font_name(f),a); \ + print_ln(); \ + return; \ +} + +#define lua_bad_vf(a) { \ + xfree(vf_buffer); \ + lua_settop(L,s_top); \ + lua_pushnil(L); \ + lua_pushstring(L,a); \ + return 2; \ +} #define tmp_b0 tmp_w.qqqq.b0 #define tmp_b1 tmp_w.qqqq.b1 @@ -129,9 +131,9 @@ typedef struct vf_stack_record { @c #define vf_byte(a) \ { \ - eight_bits vf_tmp_b; \ + eight_bits vf_tmp_b; \ if (vf_cur >= vf_size) { \ - luatex_fail("unexpected eof on virtual font"); \ + normal_error("virtual font","unexpected eof"); \ } \ vf_tmp_b = vf_buffer[vf_cur++]; \ a = vf_tmp_b; \ @@ -185,8 +187,7 @@ void pdf_check_vf(internal_font_number f) } static void -vf_local_font_warning(internal_font_number f, internal_font_number k, - const char *s, int a, int b) +vf_local_font_warning(internal_font_number f, internal_font_number k, const char *s, int a, int b) { print_nlp(); tprint(s); @@ -267,10 +268,10 @@ vf_def_font(internal_font_number f, unsigned char *vf_buffer, int *vf_cr) append_char(junk); } if (level > 5) { - normal_warning("vf","quitting at recurse depth > 5",true,true); + normal_warning("vf","quitting at recurse depth > 5"); k = f ; } else if ((level > 1) && (fs > 65536*1024)) { - normal_warning("vf","quitting when recursing at size > 65536*1024",true,true); + normal_warning("vf","quitting when recursing at size > 65536*1024"); k = f ; } else { level += 1 ; @@ -284,11 +285,9 @@ vf_def_font(internal_font_number f, unsigned char *vf_buffer, int *vf_cr) if (k != null_font) { if (checksum != 0 && font_checksum(k) != 0 && checksum != font_checksum(k)) - vf_local_font_warning(f, k, "checksum mismatch", (int) checksum, - (int) font_checksum(k)); + vf_local_font_warning(f, k, "checksum mismatch", (int) checksum, (int) font_checksum(k)); if (ds != font_dsize(k)) - vf_local_font_warning(f, k, "design size mismatch", ds, - font_dsize(k)); + vf_local_font_warning(f, k, "design size mismatch", ds, font_dsize(k)); } } return k; @@ -1014,31 +1013,31 @@ void do_vf(internal_font_number f) } @ @c -#define make_command0(N,K) { \ - lua_newtable(L); \ - lua_pushstring(L, N); \ - lua_rawseti(L,-2, 1); \ - lua_rawseti(L,-2, K); \ +#define make_command0(N,K) { \ + lua_newtable(L); \ + lua_pushstring(L, N); \ + lua_rawseti(L,-2, 1); \ + lua_rawseti(L,-2, K); \ K++; } -#define make_command1(N,V,K) { \ - lua_newtable(L); \ - lua_pushstring(L, N); \ - lua_rawseti(L,-2, 1); \ - lua_pushnumber(L, V); \ - lua_rawseti(L,-2, 2); \ - lua_rawseti(L,-2, K); \ +#define make_command1(N,V,K) { \ + lua_newtable(L); \ + lua_pushstring(L, N); \ + lua_rawseti(L,-2, 1); \ + lua_pushinteger(L, V); \ + lua_rawseti(L,-2, 2); \ + lua_rawseti(L,-2, K); \ K++; } -#define make_command2(N,V,W,K) { \ - lua_newtable(L); \ - lua_pushstring(L, N); \ - lua_rawseti(L,-2, 1); \ - lua_pushnumber(L, V); \ - lua_rawseti(L,-2, 2); \ - lua_pushnumber(L, W); \ - lua_rawseti(L,-2, 3); \ - lua_rawseti(L,-2, K); \ +#define make_command2(N,V,W,K) { \ + lua_newtable(L); \ + lua_pushstring(L, N); \ + lua_rawseti(L,-2, 1); \ + lua_pushinteger(L, V); \ + lua_rawseti(L,-2, 2); \ + lua_pushinteger(L, W); \ + lua_rawseti(L,-2, 3); \ + lua_rawseti(L,-2, K); \ K++; } #define make_commands(N,S,V,K) { \ @@ -1111,9 +1110,7 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize) vf_byte(cs.b1); vf_byte(cs.b2); vf_byte(cs.b3); - lua_pushnumber(L, - (lua_Number) ((cs.b0 << 24) + (cs.b1 << 16) + - (cs.b2 << 8) + cs.b3)); + lua_pushinteger(L, (lua_Number) ((cs.b0 << 24) + (cs.b1 << 16) + (cs.b2 << 8) + cs.b3)); lua_setfield(L, -2, "checksum"); vf_read(4, k); @@ -1150,7 +1147,7 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize) vf_read(4, k); fs = store_scaled_f(k, atsize); lua_pushstring(L, "size"); - lua_pushnumber(L, fs); + lua_pushinteger(L, fs); lua_rawset(L, -3); vf_read(4, k); @@ -1198,16 +1195,10 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize) vf_read_u(3, utmp); tfm_width = (int) utmp; } - - - lua_newtable(L); /* for this character */ - - lua_pushnumber(L, tfm_width); + lua_pushinteger(L, tfm_width); lua_setfield(L, -2, "width"); - lua_newtable(L); /* for 'commands' */ - k = 1; vf_nf = 0; w = 0; @@ -1217,14 +1208,12 @@ int make_vf_table(lua_State * L, const char *cnom, scaled atsize) while (packet_length > 0) { vf_byte(cmd); decr(packet_length); - if ((cmd >= set_char_0) && (cmd < set1)) { if (vf_nf == 0) { vf_nf = 1; make_command1("font", vf_nf, k); } make_command1("char", cmd, k); - } else if (((fnt_num_0 <= cmd) && (cmd <= fnt_num_0 + 63)) || ((fnt1 <= cmd) && (cmd <= fnt1 + 3))) { if (cmd >= fnt1) { diff --git a/Build/source/texk/web2c/luatexdir/font/vfpacket.w b/Build/source/texk/web2c/luatexdir/font/vfpacket.w index c885d809c96..32b5e634672 100644 --- a/Build/source/texk/web2c/luatexdir/font/vfpacket.w +++ b/Build/source/texk/web2c/luatexdir/font/vfpacket.w @@ -217,8 +217,8 @@ void do_vf_packet(PDF pdf, internal_font_number vf_f, int c, int ex_glyph) packet_scaled(size.v, vp->fs_f); /* height (where is depth?) */ packet_scaled(size.h, vp->fs_f); if (size.h > 0 && size.v > 0) - pdf_place_rule(pdf, 0, size); /* the 0 is unused */ - mat_p->pos.h += size.h; + backend_out[rule_node](pdf, 0, size); /* the 0 is unused */ + mat_p->pos.h += size.h; break; case packet_right_code: packet_scaled(i, vp->fs_f); @@ -255,7 +255,7 @@ void do_vf_packet(PDF pdf, internal_font_number vf_f, int c, int ex_glyph) break; case packet_node_code: packet_number(k); - hlist_out(pdf, (halfword) k); + hlist_out(pdf, (halfword) k, 0); break; case packet_nop_code: break; diff --git a/Build/source/texk/web2c/luatexdir/font/writecff.w b/Build/source/texk/web2c/luatexdir/font/writecff.w index d6e05bca4db..389eed8db76 100644 --- a/Build/source/texk/web2c/luatexdir/font/writecff.w +++ b/Build/source/texk/web2c/luatexdir/font/writecff.w @@ -49,9 +49,6 @@ static unsigned long get_unsigned(cff_font * cff, int n) } @ @c -#define CFF_ERROR luatex_fail -#undef WARN -#define WARN luatex_warn const char *const cff_stdstr[CFF_STDSTR_MAX] = { ".notdef", "space", "exclam", "quotedbl", "numbersign", @@ -163,18 +160,18 @@ cff_index *cff_get_index_header(cff_font * cff) if (count > 0) { idx->offsize = get_card8(cff); if (idx->offsize < 1 || idx->offsize > 4) - CFF_ERROR("invalid offsize data"); + normal_error("cff","invalid offsize data"); idx->offset = xmalloc((unsigned) (((unsigned) count + 1) * sizeof(l_offset))); for (i = 0; i offset)[i] = get_offset(cff, idx->offsize); - if (i == USHRT_MAX) + if (i == USHRT_MAX) break; } if (idx->offset[0] != 1) - CFF_ERROR("cff_get_index(): invalid index data"); + normal_error("cff","invalid index data"); idx->data = NULL; } else { @@ -201,7 +198,7 @@ cff_index *cff_get_index(cff_font * cff) if (count > 0) { idx->offsize = get_card8(cff); if (idx->offsize < 1 || idx->offsize > 4) - CFF_ERROR("invalid offsize data"); + normal_error("cff","invalid offsize data"); idx->offset = xmalloc((unsigned) (((unsigned) count + 1) * sizeof(l_offset))); @@ -210,7 +207,7 @@ cff_index *cff_get_index(cff_font * cff) } if (idx->offset[0] != 1) - CFF_ERROR("Invalid CFF Index offset data"); + normal_error("cff","invalid index offset data"); length = (size_t) (idx->offset[count] - idx->offset[0]); @@ -236,7 +233,7 @@ long cff_pack_index(cff_index * idx, card8 * dest, long destlen) if (idx->count < 1) { if (destlen < 2) - CFF_ERROR("Not enough space available..."); + normal_error("cff","not enough space available"); memset(dest, 0, 2); return 2; } @@ -245,7 +242,7 @@ long cff_pack_index(cff_index * idx, card8 * dest, long destlen) datalen = idx->offset[idx->count] - 1; if (destlen < len) - CFF_ERROR("Not enough space available..."); + normal_error("cff","not enough space available"); *(dest++) = (card8) ((idx->count >> 8) & 0xff); *(dest++) = (card8) (idx->count & 0xff); @@ -368,7 +365,7 @@ void cff_release_encoding(cff_encoding * encoding) xfree(encoding->data.range1); break; default: - CFF_ERROR("Unknown Encoding format."); + normal_error("cff","unknown encoding format"); } if (encoding->format & 0x80) xfree(encoding->supp); @@ -486,7 +483,7 @@ long cff_set_name(cff_font * cff, char *name) cff_index *idx; if (strlen(name) > 127) - CFF_ERROR("FontName string length too large..."); + normal_error("cff","FontName string length too large"); if (cff->name) cff_release_index(cff->name); @@ -506,7 +503,7 @@ long cff_set_name(cff_font * cff, char *name) long cff_put_header(cff_font * cff, card8 * dest, long destlen) { if (destlen < 4) - CFF_ERROR("Not enough space available..."); + normal_error("cff","not enough space available"); *(dest++) = cff->header_major; *(dest++) = cff->header_minor; @@ -863,9 +860,9 @@ cff_dict *cff_dict_unpack(card8 * data, card8 * endptr) } if (status != CFF_PARSE_OK) { - luatex_fail("Parsing CFF DICT failed. (error=%d)", status); + formatted_error("cff","parsing DICT failed (error=%d)", status); } else if (stack_top != 0) { - WARN("Garbage in CFF DICT data."); + normal_warning("cff","garbage in DICT data"); stack_top = 0; } @@ -899,13 +896,13 @@ double cff_dict_get(cff_dict * dict, const char *key, int idx) if ((dict->entries)[i].count > idx) value = (dict->entries)[i].values[idx]; else - luatex_fail("Invalid index number."); + normal_error("cff","invalid index number"); break; } } if (i == dict->count) - luatex_fail("DICT entry \"%s\" not found.", key); + formatted_error("cff","DICT entry '%s' not found", key); return value; } @@ -917,12 +914,12 @@ card8 cff_fdselect_lookup(cff_font * cff, card16 gid) cff_fdselect *fdsel; if (cff->fdselect == NULL) - CFF_ERROR("in cff_fdselect_lookup(): FDSelect not available"); + normal_error("cff","FDSelect not available"); fdsel = cff->fdselect; if (gid >= cff->num_glyphs) - CFF_ERROR("in cff_fdselect_lookup(): Invalid glyph index"); + normal_error("cff","invalid glyph index"); switch (fdsel->format) { case 0: @@ -943,12 +940,12 @@ card8 cff_fdselect_lookup(cff_font * cff, card16 gid) } break; default: - CFF_ERROR("in cff_fdselect_lookup(): Invalid FDSelect format"); + normal_error("cff","invalid FDSelect format"); break; } if (fd >= cff->num_fds) - CFF_ERROR("in cff_fdselect_lookup(): Invalid Font DICT index"); + normal_error("cff","invalid Font DICT index"); return fd; } @@ -1017,7 +1014,7 @@ long cff_read_fdarray(cff_font * cff) card16 i; if (cff->topdict == NULL) - CFF_ERROR("in cff_read_fdarray(): Top DICT not found"); + normal_error("cff","top DICT not found"); if (!(cff->flag & FONTTYPE_CIDFONT)) return 0; @@ -1117,12 +1114,12 @@ cff_font *read_cff(unsigned char *buf, long buflength, int n) cff->header_hdr_size = get_card8(cff); cff->header_offsize = get_card8(cff); if (cff->header_offsize < 1 || cff->header_offsize > 4) { - WARN("invalid offsize data"); + normal_warning("cff","invalid offsize data"); cff_close(cff); return NULL; } if (cff->header_major > 1) { - luatex_warn("CFF major version %u not supported.", cff->header_major); + formatted_warning("cff","major version %u not supported", cff->header_major); cff_close(cff); return NULL; } @@ -1131,7 +1128,7 @@ cff_font *read_cff(unsigned char *buf, long buflength, int n) /* Name INDEX */ idx = cff_get_index(cff); if (n > idx->count - 1) { - luatex_warn("Invalid CFF fontset index number."); + normal_warning("cff","invalid fontset index number"); cff_close(cff); return NULL; } @@ -1143,14 +1140,14 @@ cff_font *read_cff(unsigned char *buf, long buflength, int n) /* Top DICT INDEX */ idx = cff_get_index(cff); if (n > idx->count - 1) { - WARN("CFF Top DICT not exist..."); + normal_warning("cff","top DICT not exist"); cff_close(cff); return NULL; } cff->topdict = cff_dict_unpack(idx->data + idx->offset[n] - 1, idx->data + idx->offset[n + 1] - 1); if (!cff->topdict) { - WARN("Parsing CFF Top DICT data failed..."); + normal_warning("cff","parsing top DICT data failed"); cff_close(cff); return NULL; } @@ -1158,13 +1155,13 @@ cff_font *read_cff(unsigned char *buf, long buflength, int n) if (cff_dict_known(cff->topdict, "CharstringType") && cff_dict_get(cff->topdict, "CharstringType", 0) != 2) { - WARN("Only Type 2 Charstrings supported..."); + normal_warning("cff","only type 2 charstrings supported"); cff_close(cff); return NULL; } if (cff_dict_known(cff->topdict, "SyntheticBase")) { - WARN("CFF Synthetic font not supported."); + normal_warning("cff","synthetic font not supported"); cff_close(cff); return NULL; } @@ -1214,33 +1211,33 @@ static long pack_integer(card8 * dest, long destlen, long value) if (value >= -107 && value <= 107) { if (destlen < 1) - CFF_ERROR("Buffer overflow."); + normal_error("cff","buffer overflow"); dest[0] = (card8) ((value + 139) & 0xff); len = 1; } else if (value >= 108 && value <= 1131) { if (destlen < 2) - CFF_ERROR("Buffer overflow."); + normal_error("cff","buffer overflow"); value = (long) 0xf700u + value - 108; dest[0] = (card8) ((value >> 8) & 0xff); dest[1] = (card8) (value & 0xff); len = 2; } else if (value >= -1131 && value <= -108) { if (destlen < 2) - CFF_ERROR("Buffer overflow."); + normal_error("cff","buffer overflow"); value = (long) 0xfb00u - value - 108; dest[0] = (card8) ((value >> 8) & 0xff); dest[1] = (card8) (value & 0xff); len = 2; } else if (value >= -32768 && value <= 32767) { /* shortint */ if (destlen < 3) - CFF_ERROR("Buffer overflow."); + normal_error("cff","buffer overflow"); dest[0] = 28; dest[1] = (card8) ((value >> 8) & 0xff); dest[2] = (card8) (value & 0xff); len = 3; } else { /* longint */ if (destlen < 5) - CFF_ERROR("Buffer overflow."); + normal_error("cff","buffer overflow"); dest[0] = 29; dest[1] = (card8) ((value >> 24) & 0xff); dest[2] = (card8) ((value >> 16) & 0xff); @@ -1260,7 +1257,7 @@ static long pack_real(card8 * dest, long destlen, double value) #define CFF_REAL_MAX_LEN 17 if (destlen < 2) - CFF_ERROR("Buffer overflow."); + normal_error("cff","buffer overflow"); dest[0] = 30; @@ -1289,7 +1286,7 @@ static long pack_real(card8 * dest, long destlen, double value) } res=sprintf(work_buffer, "%1.14g", value); - if (res<0) CFF_ERROR("Invalid conversion."); + if (res<0) normal_error("cff","invalid conversion"); if (res>CFF_REAL_MAX_LEN) res=CFF_REAL_MAX_LEN; for (i = 0; i < res; i++) { @@ -1297,18 +1294,18 @@ static long pack_real(card8 * dest, long destlen, double value) if (work_buffer[i] == '\0') { /* res should prevent this. */ - /* CFF_ERROR("Cannot happen"); */ + /* normal_error("cff","cannot happen"); */ break; } else if (work_buffer[i] == '.') { ch = 0x0a; } else if (work_buffer[i] >= '0' && work_buffer[i] <= '9') { ch = (unsigned char) (work_buffer[i] - '0'); } else { - CFF_ERROR("Invalid character."); + normal_error("cff","invalid character"); } if (destlen < pos / 2 + 1) - CFF_ERROR("Buffer overflow."); + normal_error("cff","buffer overflow"); if (pos % 2) { dest[pos / 2] = (card8) (dest[pos / 2] + ch); @@ -1323,7 +1320,7 @@ static long pack_real(card8 * dest, long destlen, double value) dest[pos / 2] = (card8) (dest[pos / 2] + 0x0b); } else { if (destlen < pos / 2 + 1) - CFF_ERROR("Buffer overflow."); + normal_error("cff","buffer overflow"); dest[pos / 2] = (card8) (0xb0); } pos++; @@ -1332,7 +1329,7 @@ static long pack_real(card8 * dest, long destlen, double value) dest[pos / 2] = (card8) (dest[pos / 2] + 0x0c); } else { if (destlen < pos / 2 + 1) - CFF_ERROR("Buffer overflow."); + normal_error("cff","buffer overflow"); dest[pos / 2] = (card8) (0xc0); } e *= -1; @@ -1350,11 +1347,11 @@ static long pack_real(card8 * dest, long destlen, double value) } else if (work_buffer[i] >= '0' && work_buffer[i] <= '9') { ch = (unsigned char) (work_buffer[i] - '0'); } else { - CFF_ERROR("Invalid character."); + normal_error("cff","invalid character"); } if (destlen < pos / 2 + 1) - CFF_ERROR("Buffer overflow."); + normal_error("cff","buffer overflow"); if (pos % 2) { dest[pos / 2] = (card8) (dest[pos / 2] + ch); @@ -1370,7 +1367,7 @@ static long pack_real(card8 * dest, long destlen, double value) pos++; } else { if (destlen < pos / 2 + 1) - CFF_ERROR("Buffer overflow."); + normal_error("cff","buffer overflow"); dest[pos / 2] = (card8) (0xff); pos += 2; } @@ -1392,7 +1389,7 @@ static long cff_dict_put_number(double value, lvalue = (long) value; if (destlen < 5) - CFF_ERROR("Buffer overflow."); + normal_error("cff","buffer overflow"); dest[0] = 29; dest[1] = (card8) ((lvalue >> 24) & 0xff); dest[2] = (card8) ((lvalue >> 16) & 0xff); @@ -1428,15 +1425,15 @@ static long put_dict_entry(cff_dict_entry * de, card8 * dest, long destlen) } if (id >= 0 && id < CFF_LAST_DICT_OP1) { if (len + 1 > destlen) - CFF_ERROR("Buffer overflow."); + normal_error("cff","buffer overflow"); dest[len++] = (card8) id; } else if (id >= 0 && id < CFF_LAST_DICT_OP) { if (len + 2 > destlen) - CFF_ERROR("in cff_dict_pack(): Buffer overflow"); + normal_error("cff","buffer overflow"); dest[len++] = 12; dest[len++] = (card8) (id - CFF_LAST_DICT_OP1); } else { - CFF_ERROR("Invalid CFF DICT operator ID."); + normal_error("cff","invalid DICT operator ID"); } } @@ -1477,12 +1474,12 @@ void cff_dict_add(cff_dict * dict, const char *key, int count) } if (id == CFF_LAST_DICT_OP) - CFF_ERROR("Unknown CFF DICT operator."); + normal_error("cff","unknown DICT operator"); for (i = 0; i < dict->count; i++) { if ((dict->entries)[i].id == id) { if ((dict->entries)[i].count != count) - CFF_ERROR("Inconsistent DICT argument number."); + normal_error("cff","inconsistent DICT argument number"); return; } } @@ -1534,13 +1531,13 @@ void cff_dict_set(cff_dict * dict, const char *key, int idx, double value) if ((dict->entries)[i].count > idx) (dict->entries)[i].values[idx] = value; else - CFF_ERROR("Invalid index number."); + normal_error("cff","invalid index number"); break; } } if (i == dict->count) - luatex_fail("DICT entry \"%s\" not found.", key); + formatted_error("cff","DICT entry '%s' not found", key); } @@ -1601,7 +1598,7 @@ long cff_get_sid(cff_font * cff, const char *str) void cff_update_string(cff_font * cff) { if (cff == NULL) - CFF_ERROR("CFF font not opened."); + normal_error("cff","CFF font not opened"); if (cff->string) cff_release_index(cff->string); @@ -1618,7 +1615,7 @@ s_SID cff_add_string(cff_font * cff, const char *str) l_offset offset, size; if (cff == NULL) - CFF_ERROR("CFF font not opened."); + normal_error("cff","CFF font not opened"); if (cff->_string == NULL) cff->_string = cff_new_index(0); @@ -1693,7 +1690,7 @@ long cff_read_charsets(cff_font * cff) card16 count, i; if (cff->topdict == NULL) - CFF_ERROR("Top DICT not available"); + normal_error("cff","top DICT not available"); if (!cff_dict_known(cff->topdict, "charset")) { cff->flag |= CHARSETS_ISOADOBE; @@ -1773,13 +1770,13 @@ long cff_read_charsets(cff_font * cff) break; default: xfree(charset); - CFF_ERROR("Unknown Charset format"); + normal_error("cff","unknown charset format"); break; } if (count > 0) { /* fprintf(stdout, "count=%d\n", count); */ - WARN("Charset data possibly broken (num_glyphs too high)"); + normal_warning("cff","charset data possibly broken (too many glyphs)"); } return length; @@ -1796,7 +1793,7 @@ long cff_pack_charsets(cff_font * cff, card8 * dest, long destlen) return 0; if (destlen < 1) - CFF_ERROR("in cff_pack_charsets(): Buffer overflow"); + normal_error("cff","buffer overflow"); charset = cff->charsets; @@ -1804,7 +1801,7 @@ long cff_pack_charsets(cff_font * cff, card8 * dest, long destlen) switch (charset->format) { case 0: if (destlen < len + (charset->num_entries) * 2) - CFF_ERROR("in cff_pack_charsets(): Buffer overflow"); + normal_error("cff","buffer overflow"); for (i = 0; i < (charset->num_entries); i++) { s_SID sid = (charset->data).glyphs[i]; /* or CID */ dest[len++] = (card8) ((sid >> 8) & 0xff); @@ -1814,7 +1811,7 @@ long cff_pack_charsets(cff_font * cff, card8 * dest, long destlen) case 1: { if (destlen < len + (charset->num_entries) * 3) - CFF_ERROR("in cff_pack_charsets(): Buffer overflow"); + normal_error("cff","buffer overflow"); for (i = 0; i < (charset->num_entries); i++) { dest[len++] = (card8) (((charset->data).range1[i].first >> 8) & 0xff); @@ -1826,7 +1823,7 @@ long cff_pack_charsets(cff_font * cff, card8 * dest, long destlen) case 2: { if (destlen < len + (charset->num_entries) * 4) - CFF_ERROR("in cff_pack_charsets(): Buffer overflow"); + normal_error("cff","buffer overflow"); for (i = 0; i < (charset->num_entries); i++) { dest[len++] = (card8) (((charset->data).range2[i].first >> 8) & 0xff); @@ -1838,7 +1835,7 @@ long cff_pack_charsets(cff_font * cff, card8 * dest, long destlen) } break; default: - CFF_ERROR("Unknown Charset format"); + normal_error("cff","unknown charset format"); break; } @@ -2022,7 +2019,7 @@ static void clear_stack(card8 ** dest, card8 * limit) This number cannot be represented as a single operand. We must use `a b mul ...' or `a c div' to represent large values. */ - CFF_ERROR("Argument value too large. (This is bug)"); + normal_error("cff","argument value too large (this is bug)"); } else if (fabs(value - (double) ivalue) > 3.0e-5) { /* 16.16-bit signed fixed value */ DST_NEED(limit, *dest + 5); @@ -2053,7 +2050,7 @@ static void clear_stack(card8 ** dest, card8 * limit) *(*dest)++ = (card8) ((ivalue >> 8) & 0xff); *(*dest)++ = (card8) ((ivalue) & 0xff); } else { /* Shouldn't come here */ - CFF_ERROR("Unexpected error."); + normal_error("cff","unexpected error"); } } @@ -2144,11 +2141,11 @@ do_operator1(card8 ** dest, card8 * limit, card8 ** data, card8 * endptr) width = cs2_arg_stack[0]; clear_stack(dest, limit); } else if (cs2_stack_top == 4 || cs2_stack_top == 5) { - WARN("\"seac\" character deprecated in Type 2 charstring."); + normal_warning("cff","'seac' character deprecated in type 2 charstring"); status = CS_PARSE_CFF_ERROR; return; } else if (cs2_stack_top > 0) { - WARN("Operand stack not empty."); + normal_warning("cff","operand stack not empty"); } DST_NEED(limit, *dest + 1); *(*dest)++ = op; @@ -2166,7 +2163,7 @@ do_operator1(card8 ** dest, card8 * limit, card8 ** data, card8 * endptr) case cs_vhcurveto: case cs_hvcurveto: if (phase < 2) { - WARN("Broken Type 2 charstring."); + normal_warning("cff","broken type 2 charstring"); status = CS_PARSE_CFF_ERROR; return; } @@ -2179,11 +2176,11 @@ do_operator1(card8 ** dest, card8 * limit, card8 ** data, card8 * endptr) case cs_return: case cs_callgsubr: case cs_callsubr: - CFF_ERROR("Unexpected call(g)subr/return"); + normal_error("cff","unexpected call(g)subr/return"); break; default: /* no-op ? */ - WARN("%s: Unknown charstring operator: 0x%02x", CS_TYPE2_DEBUG_STR, op); + formatted_warning("cff","%s: unknown charstring operator: 0x%02x", CS_TYPE2_DEBUG_STR, op); status = CS_PARSE_CFF_ERROR; break; } @@ -2213,7 +2210,7 @@ do_operator2(card8 ** dest, card8 * limit, card8 ** data, card8 * endptr) switch (op) { case cs_dotsection: /* deprecated */ - WARN("Operator \"dotsection\" deprecated in Type 2 charstring."); + normal_warning("cff","Operator 'dotsection' deprecated in type 2 charstring"); status = CS_PARSE_CFF_ERROR; return; break; @@ -2222,7 +2219,7 @@ do_operator2(card8 ** dest, card8 * limit, card8 ** data, card8 * endptr) case cs_hflex1: case cs_flex1: if (phase < 2) { - WARN("%s: Broken Type 2 charstring.", CS_TYPE2_DEBUG_STR); + formatted_warning("cff","%s: broken type 2 charstring", CS_TYPE2_DEBUG_STR); status = CS_PARSE_CFF_ERROR; return; } @@ -2391,14 +2388,13 @@ do_operator2(card8 ** dest, card8 * limit, card8 ** data, card8 * endptr) } break; case cs_random: - WARN("%s: Charstring operator \"random\" found.", CS_TYPE2_DEBUG_STR); + formatted_warning("cff","%s: Charstring operator 'random' found.", CS_TYPE2_DEBUG_STR); NEED(CS_ARG_STACK_MAX, cs2_stack_top + 1); cs2_arg_stack[cs2_stack_top++] = 1.0; break; default: /* no-op ? */ - WARN("%s: Unknown charstring operator: 0x0c%02x", CS_TYPE2_DEBUG_STR, - op); + formatted_warning("cff","%s: unknown charstring operator: 0x0c%02x", CS_TYPE2_DEBUG_STR, op); status = CS_PARSE_CFF_ERROR; break; } @@ -2487,8 +2483,7 @@ static void get_subr(card8 ** subr, long *len, cff_index * subr_idx, long id) card16 count; if (subr_idx == NULL) - CFF_ERROR("%s: Subroutine called but no subroutine found.", - CS_TYPE2_DEBUG_STR); + formatted_error("cff","%s: subroutine called but no subroutine found",CS_TYPE2_DEBUG_STR); count = subr_idx->count; @@ -2502,8 +2497,7 @@ static void get_subr(card8 ** subr, long *len, cff_index * subr_idx, long id) } if (id > count) - CFF_ERROR("%s: Invalid Subr index: %ld (max=%u)", CS_TYPE2_DEBUG_STR, - id, count); + formatted_error("cff","%s: invalid subroutine index: %ld (max=%u)", CS_TYPE2_DEBUG_STR, id, count); *len = (long) ((subr_idx->offset)[id + 1] - (subr_idx->offset)[id]); *subr = subr_idx->data + (subr_idx->offset)[id] - 1; @@ -2527,7 +2521,7 @@ do_charstring(card8 ** dest, card8 * limit, long len; if (cs2_nest > CS_SUBR_NEST_MAX) - CFF_ERROR("%s: Subroutine nested too deeply.", CS_TYPE2_DEBUG_STR); + formatted_error("cff","%s: subroutine nested too deeply", CS_TYPE2_DEBUG_STR); cs2_nest++; @@ -2545,10 +2539,8 @@ do_charstring(card8 ** dest, card8 * limit, get_subr(&subr, &len, gsubr_idx, (long) cs2_arg_stack[cs2_stack_top]); if (*dest + len > limit) - CFF_ERROR("%s: Possible buffer overflow.", - CS_TYPE2_DEBUG_STR); - do_charstring(dest, limit, &subr, subr + len, gsubr_idx, - subr_idx); + formatted_error("cff","%s: possible buffer overflow", CS_TYPE2_DEBUG_STR); + do_charstring(dest, limit, &subr, subr + len, gsubr_idx, subr_idx); *data += 1; } } else if (b0 == cs_callsubr) { @@ -2559,10 +2551,8 @@ do_charstring(card8 ** dest, card8 * limit, get_subr(&subr, &len, subr_idx, (long) cs2_arg_stack[cs2_stack_top]); if (limit < *dest + len) - CFF_ERROR("%s: Possible buffer overflow.", - CS_TYPE2_DEBUG_STR); - do_charstring(dest, limit, &subr, subr + len, gsubr_idx, - subr_idx); + formatted_error("cff","%s: possible buffer overflow", CS_TYPE2_DEBUG_STR); + do_charstring(dest, limit, &subr, subr + len, gsubr_idx, subr_idx); *data += 1; } } else if (b0 == cs_escape) { @@ -2579,10 +2569,9 @@ do_charstring(card8 ** dest, card8 * limit, if (status == CS_SUBR_RETURN) { status = CS_PARSE_OK; } else if (status == CS_CHAR_END && *data < endptr) { - WARN("%s: Garbage after endchar.", CS_TYPE2_DEBUG_STR); + formatted_warning("cff","%s: garbage after endchar", CS_TYPE2_DEBUG_STR); } else if (status < CS_PARSE_OK) { /* error */ - CFF_ERROR("%s: Parsing charstring failed: (status=%d, stack=%d)", - CS_TYPE2_DEBUG_STR, status, cs2_stack_top); + formatted_error("cff","%s: parsing charstring failed: (status=%d, stack=%d)", CS_TYPE2_DEBUG_STR, status, cs2_stack_top); } cs2_nest--; @@ -2645,7 +2634,7 @@ long cff_read_encoding(cff_font * cff) card8 i; if (cff->topdict == NULL) { - CFF_ERROR("Top DICT data not found"); + normal_error("cff","top DICT data not found"); } if (!cff_dict_known(cff->topdict, "Encoding")) { @@ -2694,7 +2683,7 @@ long cff_read_encoding(cff_font * cff) break; default: xfree(encoding); - CFF_ERROR("Unknown Encoding format"); + normal_error("cff","unknown encoding format"); break; } @@ -2727,7 +2716,7 @@ long cff_pack_encoding(cff_font * cff, card8 * dest, long destlen) return 0; if (destlen < 2) - CFF_ERROR("in cff_pack_encoding(): Buffer overflow"); + normal_error("cff","buffer overflow"); encoding = cff->encoding; @@ -2736,7 +2725,7 @@ long cff_pack_encoding(cff_font * cff, card8 * dest, long destlen) switch (encoding->format & (~0x80)) { case 0: if (destlen < len + encoding->num_entries) - CFF_ERROR("in cff_pack_encoding(): Buffer overflow"); + normal_error("cff","buffer overflow"); for (i = 0; i < (encoding->num_entries); i++) { dest[len++] = (encoding->data).codes[i]; } @@ -2744,7 +2733,7 @@ long cff_pack_encoding(cff_font * cff, card8 * dest, long destlen) case 1: { if (destlen < len + (encoding->num_entries) * 2) - CFF_ERROR("in cff_pack_encoding(): Buffer overflow"); + normal_error("cff","buffer overflow"); for (i = 0; i < (encoding->num_entries); i++) { dest[len++] = (card8) ((encoding->data).range1[i].first & 0xff); dest[len++] = (card8) ((encoding->data).range1[i].n_left); @@ -2752,13 +2741,13 @@ long cff_pack_encoding(cff_font * cff, card8 * dest, long destlen) } break; default: - CFF_ERROR("Unknown Encoding format"); + normal_error("cff","unknown encoding format"); break; } if ((encoding->format) & 0x80) { if (destlen < len + (encoding->num_supps) * 3 + 1) - CFF_ERROR("in cff_pack_encoding(): Buffer overflow"); + normal_error("cff","buffer overflow"); dest[len++] = encoding->num_supps; for (i = 0; i < (encoding->num_supps); i++) { dest[len++] = (card8) ((encoding->supp)[i].code); @@ -2779,7 +2768,7 @@ long cff_read_fdselect(cff_font * cff) card16 i; if (cff->topdict == NULL) - CFF_ERROR("Top DICT not available"); + normal_error("cff","top DICT not available"); if (!(cff->flag & FONTTYPE_CIDFONT)) return 0; @@ -2811,15 +2800,15 @@ long cff_read_fdselect(cff_font * cff) ranges[i].fd = get_card8(cff); } if (ranges[0].first != 0) - CFF_ERROR("Range not starting with 0."); + normal_error("cff","range not starting with 0"); if (cff->num_glyphs != get_card16(cff)) - CFF_ERROR("Sentinel value mismatched with number of glyphs."); + normal_error("cff","sentinel value mismatched with number of glyphs"); length += (fdsel->num_entries) * 3 + 4; } break; default: xfree(fdsel); - CFF_ERROR("Unknown FDSelect format."); + normal_error("cff","unknown FDSelect format"); break; } @@ -2838,7 +2827,7 @@ long cff_pack_fdselect(cff_font * cff, card8 * dest, long destlen) return 0; if (destlen < 1) - CFF_ERROR("in cff_pack_fdselect(): Buffur overflow"); + normal_error("cff","buffer overflow"); fdsel = cff->fdselect; @@ -2846,9 +2835,9 @@ long cff_pack_fdselect(cff_font * cff, card8 * dest, long destlen) switch (fdsel->format) { case 0: if (fdsel->num_entries != cff->num_glyphs) - CFF_ERROR("in cff_pack_fdselect(): Invalid data"); + normal_error("cff","invalid data"); if (destlen < len + fdsel->num_entries) - CFF_ERROR("in cff_pack_fdselect(): Buffer overflow"); + normal_error("cff","buffer overflow"); for (i = 0; i < fdsel->num_entries; i++) { dest[len++] = (fdsel->data).fds[i]; } @@ -2856,18 +2845,18 @@ long cff_pack_fdselect(cff_font * cff, card8 * dest, long destlen) case 3: { if (destlen < len + 2) - CFF_ERROR("in cff_pack_fdselect(): Buffer overflow"); + normal_error("cff","buffer overflow"); len += 2; for (i = 0; i < (fdsel->num_entries); i++) { if (destlen < len + 3) - CFF_ERROR("in cff_pack_fdselect(): Buffer overflow"); + normal_error("cff","buffer overflow"); dest[len++] = (card8) (((fdsel->data).ranges[i].first >> 8) & 0xff); dest[len++] = (card8) ((fdsel->data).ranges[i].first & 0xff); dest[len++] = (card8) ((fdsel->data).ranges[i].fd); } if (destlen < len + 2) - CFF_ERROR("in cff_pack_fdselect(): Buffer overflow"); + normal_error("cff","buffer overflow"); dest[len++] = (card8) ((cff->num_glyphs >> 8) & 0xff); dest[len++] = (card8) (cff->num_glyphs & 0xff); dest[1] = (card8) (((len / 3 - 1) >> 8) & 0xff); @@ -2875,7 +2864,7 @@ long cff_pack_fdselect(cff_font * cff, card8 * dest, long destlen) } break; default: - CFF_ERROR("Unknown FDSelect format."); + normal_error("cff","unknown FDSelect format"); break; } @@ -3012,9 +3001,9 @@ static void write_fontfile(PDF pdf, cff_font * cffont, char *fullname) @c #define DO_COPY_CHARSTRING() \ if ((avl_find(fd->gl_tree,glyph) != NULL)) { \ - size = (long)(cs_idx->offset[code+1] - cs_idx->offset[code]); \ + size = (long)(cs_idx->offset[code+1] - cs_idx->offset[code]); \ if (size > CS_STR_LEN_MAX) { \ - luatex_fail("Charstring too long: gid=%u, %ld bytes", code, size); \ + formatted_error("cff","charstring too long: gid=%u, %ld bytes", code, size); \ } \ if (charstring_len + CS_STR_LEN_MAX >= max_len) { \ max_len = (long)(charstring_len + 2 * CS_STR_LEN_MAX); \ @@ -3154,7 +3143,7 @@ void write_cff(PDF pdf, cff_font * cffont, fd_entry * fd) offset = (long) cffont->offset; cs_count1 = cs_idx->count; if (cs_count1 < 2) { - CFF_ERROR("No valid charstring data found."); + normal_error("cff","no valid charstring data found"); } /* build the new charstrings entry */ @@ -3203,7 +3192,7 @@ void write_cff(PDF pdf, cff_font * cffont, fd_entry * fd) /* this happens if the internal metrics do not agree with the actual disk font */ if (gid < num_glyphs) { - WARN("embedded subset is smaller than expected: %d instead of %d glyphs.", gid, num_glyphs); + formatted_warning("cff","embedded subset is smaller than expected: %d instead of %d glyphs", gid, num_glyphs); num_glyphs = gid; } @@ -3268,7 +3257,7 @@ card16 cff_charsets_lookup(cff_font * cff, card16 cid) 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"); + normal_error("cff","charsets data not available"); } if (cid == 0) { @@ -3312,7 +3301,7 @@ card16 cff_charsets_lookup(cff_font * cff, card16 cid) } break; default: - ERROR("Unknown Charset format"); + normal_error("cff","unknown charset format"); } return 0; /* not found */ @@ -3425,7 +3414,7 @@ void write_cid_cff(PDF pdf, cff_font * cffont, fd_entry * fd) offset = (long) cffont->offset; cs_count1 = cs_idx->count; if (cs_count1 < 2) { - CFF_ERROR("No valid charstring data found."); + normal_error("cff","no valid charstring data found"); } charset = xcalloc(1, sizeof(cff_charsets)); @@ -3458,7 +3447,7 @@ void write_cid_cff(PDF pdf, cff_font * cffont, fd_entry * fd) (CIDToGIDMap[2 * cid + 1])); size = (long) (cs_idx->offset[gid_org + 1] - cs_idx->offset[gid_org]); if (size > CS_STR_LEN_MAX) { - luatex_fail("Charstring too long: gid=%u, %ld bytes", cid, size); + formatted_error("cff","charstring too long: gid=%u, %ld bytes", cid, size); } if (charstring_len + CS_STR_LEN_MAX >= max_len) { max_len = charstring_len + 2 * CS_STR_LEN_MAX; @@ -3492,7 +3481,7 @@ void write_cid_cff(PDF pdf, cff_font * cffont, fd_entry * fd) } if (gid != num_glyphs) - CFF_ERROR("Unexpected error: %i != %i", gid, num_glyphs); + formatted_error("cff","unexpected error: %i != %i", gid, num_glyphs); xfree(data); cff_release_index(cs_idx); diff --git a/Build/source/texk/web2c/luatexdir/font/writefont.w b/Build/source/texk/web2c/luatexdir/font/writefont.w index bbe2524b40b..81a8b0f9b04 100644 --- a/Build/source/texk/web2c/luatexdir/font/writefont.w +++ b/Build/source/texk/web2c/luatexdir/font/writefont.w @@ -41,7 +41,7 @@ const key_entry font_key[FONT_KEYS_NUM] = { , {"FontName", "FontName", 1} }; -@ +@ @c struct avl_table *fo_tree = NULL; /* tree of font dictionaries */ struct avl_table *fd_tree = NULL; /* tree of font descriptor objects */ @@ -62,7 +62,7 @@ static int comp_fd_entry(const void *pa, const void *pb, void *p) return strcmp(p1->fm->ff_name, p2->fm->ff_name); } -@ initialize data structure for /Type /Font +@ initialize data structure for /Type /Font @c static fo_entry *new_fo_entry(void) { @@ -187,7 +187,7 @@ static void write_fontmetrics(PDF pdf, fd_entry * fd) pdf_dict_add_int(pdf, font_key[i].pdfname, fd->font_dim[i].val); } -@ +@ @c static void preset_fontname(fo_entry * fo, internal_font_number f) { @@ -217,7 +217,7 @@ static void pdf_dict_add_fontname(PDF pdf, const char *key, fd_entry * fd) xfree(s); } -@ +@ @c fd_entry *lookup_fd_entry(char *s) { @@ -268,7 +268,7 @@ static void create_fontdescriptor(fo_entry * fo, internal_font_number f) assert(fo->fd->gl_tree != NULL); } -@ +@ For all used characters of \TeX font |f|, get corresponding glyph names from external reencoding (.enc) file and collect these in the glyph tree |gl_tree| of font descriptor |fd| referenced by font dictionary |fo|. @@ -431,7 +431,7 @@ static void write_fontfile(PDF pdf, fd_entry * fd) if (is_opentype(fd->fm)) { writetype0(pdf, fd); } else if (is_truetype(fd->fm)) { - if (!writetype2(pdf, fd)) { + if (!writetype2(pdf, fd)) { writetype0(pdf,fd); fd->fm->type |= F_OTF; fd->fm->type ^= F_TRUETYPE; } @@ -529,9 +529,8 @@ static void write_fontdescriptor(PDF pdf, fd_entry * fd) fd_flags = is_std_t1font(fd->fm) ? std_flags[check_std_t1font(fd->fm->ps_name)] : FD_FLAGS_DEFAULT_NON_EMBED; - luatex_warn - ("No flags specified for non-embedded font `%s' (%s) (I'm using %i): " - "fix your map entry.", + formatted_warning("map file", + "No flags specified for non-embedded font '%s' (%s), I'm using %i, fix your map entry", fd->fm->ps_name != NULL ? fd->fm->ps_name : "No name given", fd->fm->tfm_name, fd_flags); } @@ -720,9 +719,8 @@ static void create_fontdictionary(PDF pdf, internal_font_number f) create_fontdescriptor(fo, f); write_fontdescriptor(pdf, fo->fd); if (!is_std_t1font(fo->fm)) - luatex_warn("font `%s' is not a standard font; " - "I suppose it is available to your PDF viewer then", - fo->fm->ps_name); + formatted_warning("map file", "font '%s' is not a standard font; I suppose it is available to your PDF viewer then", + fo->fm->ps_name); } if (is_type1(fo->fm)) register_fo_entry(fo); @@ -784,9 +782,7 @@ void do_pdf_font(PDF pdf, internal_font_number f) fm->ff_name = s; del_file = 1; } else { - luatex_fail - ("writefont.c: The file (%s) does not contain font `%s'", - fm->ff_name, fm->ps_name); + formatted_error("font","file '%s' does not contain font '%s'",fm->ff_name, fm->ps_name); } } fm->encname = font_encodingname(f); /* for the CIDSystemInfo */ @@ -812,9 +808,8 @@ void do_pdf_font(PDF pdf, internal_font_number f) set_type1(fm); break; default: - luatex_fail - ("writefont.c: The file format (%s) for font `%s' is incompatible with wide characters\n", - font_format_name(f), font_name(f)); + formatted_error("font","file format '%s' for '%s' is incompatible with wide characters", + font_format_name(f), font_name(f)); } /* This makes "unknown" default to subsetted inclusion */ if (font_embedding(f) != no_embedding) { @@ -996,7 +991,7 @@ static void create_cid_fontdictionary(PDF pdf, internal_font_number f) avl_destroy(fo->fd->gl_tree,destroy_glw_cid_entry); } xfree(fo->fd); - } + } xfree(fo); } diff --git a/Build/source/texk/web2c/luatexdir/font/writet1.w b/Build/source/texk/web2c/luatexdir/font/writet1.w index 16dff008e73..f328dbd17fc 100644 --- a/Build/source/texk/web2c/luatexdir/font/writet1.w +++ b/Build/source/texk/web2c/luatexdir/font/writet1.w @@ -254,7 +254,7 @@ static void enc_getline(void) char c; restart: if (enc_eof()) - luatex_fail("unexpected end of file"); + normal_error("type 1","unexpected end of file"); p = enc_line; do { c = (char) enc_getchar(); @@ -280,21 +280,20 @@ char **load_enc_file(char *enc_name) cur_file_name = luatex_find_file(enc_name, find_enc_file_callback); if (cur_file_name == NULL) { - luatex_fail("cannot find encoding file '%s' for reading", enc_name); + formatted_error("type 1","cannot find encoding file '%s' for reading", enc_name); } callback_id = callback_defined(read_enc_file_callback); enc_curbyte = 0; enc_size = 0; if (callback_id > 0) { - if (run_callback(callback_id, "S->bSd", cur_file_name, - &file_opened, &enc_buffer, &enc_size)) { + if (run_callback(callback_id, "S->bSd", cur_file_name, &file_opened, &enc_buffer, &enc_size)) { if ((!file_opened) || enc_size == 0) { - luatex_fail("cannot open encoding file '%s' for reading", cur_file_name); + formatted_error("type 1","cannot open encoding file '%s' for reading", cur_file_name); } } } else { if (!enc_open(cur_file_name)) { - luatex_fail("cannot open encoding file '%s' for reading", cur_file_name); + formatted_error("type 1","cannot open encoding file '%s' for reading", cur_file_name); } enc_read_file(); enc_close(); @@ -306,8 +305,7 @@ char **load_enc_file(char *enc_name) enc_getline(); if (*enc_line != '/' || (r = strchr(enc_line, '[')) == NULL) { remove_eol(r, enc_line); - luatex_fail - ("invalid encoding vector (a name or `[' missing): `%s'", enc_line); + formatted_error("type 1","invalid encoding vector (a name or '[' missing): '%s'", enc_line); } names_count = 0; r++; /* skip '[' */ @@ -319,7 +317,7 @@ char **load_enc_file(char *enc_name) *p = 0; skip(r, ' '); if (names_count >= 256) - luatex_fail("encoding vector contains more than 256 names"); + normal_error("type 1","encoding vector contains more than 256 names"); if (strcmp(buf, notdef) != 0) glyph_names[names_count] = xstrdup(buf); names_count++; @@ -329,9 +327,7 @@ char **load_enc_file(char *enc_name) goto done; else { remove_eol(r, enc_line); - luatex_fail - ("invalid encoding vector: a name or `] def' expected: `%s'", - enc_line); + formatted_error("type 1","invalid encoding vector: a name or '] def' expected: `%s'",enc_line); } } enc_getline(); @@ -371,7 +367,7 @@ static int t1_getbyte(void) return c; if (t1_block_length == 0) { if (c != 128) - luatex_fail("invalid marker"); + normal_error("type 1","invalid marker"); c = t1_getchar(); if (c == 3) { while (!t1_eof()) @@ -451,7 +447,7 @@ static float t1_scan_num(char *p, char **r) skip(p, ' '); if (sscanf(p, "%g", &f) != 1) { remove_eol(p, t1_line_array); - luatex_fail("a number expected: `%s'", t1_line_array); + formatted_error("type 1","a number expected: '%s'", t1_line_array); } if (r != NULL) { for (; isdigit((unsigned char)*p) || *p == '.' || @@ -483,7 +479,7 @@ static void t1_getline(void) static int eexec_len = 17; /* |strlen(eexec_str)| */ restart: if (t1_eof()) - luatex_fail("unexpected end of file"); + normal_error("type 1","unexpected end of file"); t1_line_ptr = t1_line_array; alloc_array(t1_line, 1, T1_BUF_SIZE); t1_cslen = 0; @@ -599,7 +595,7 @@ static void t1_check_block_len(boolean decrypt) c = edecrypt((byte) c); l = (int) t1_block_length; if (!(l == 0 && (c == 10 || c == 13))) { - luatex_fail("%i bytes more than expected were ignored", l + 1); + formatted_error("type 1","%i bytes more than expected were ignored", l + 1); } } @@ -636,7 +632,7 @@ static void t1_stop_eexec(PDF pdf) if (last_hexbyte == 0) t1_puts(pdf, "00"); else - luatex_fail("unexpected data after eexec"); + normal_error("type 1","unexpected data after eexec"); } } t1_cs = false; @@ -674,7 +670,7 @@ static void t1_scan_keys(PDF pdf) if (t1_prefix("/FontType")) { p = t1_line_array + strlen("FontType") + 1; if ((i = (int) t1_scan_num(p, 0)) != 1) - luatex_fail("Type%d fonts unsupported by pdfTeX", i); + formatted_error("type 1","Type%d fonts unsupported by backend", i); return; } for (key = (const key_entry *) font_key; key - font_key < FONT_KEYS_NUM; @@ -690,7 +686,7 @@ static void t1_scan_keys(PDF pdf) if ((k = (int) (key - font_key)) == FONTNAME_CODE) { if (*p != '/') { remove_eol(p, t1_line_array); - luatex_fail("a name expected: `%s'", t1_line_array); + formatted_error("type 1","a name expected: '%s'", t1_line_array); } r = ++p; /* skip the slash */ for (q = t1_buf_array; *p != ' ' && *p != 10; *q++ = *p++); @@ -732,7 +728,7 @@ static void t1_scan_param(PDF pdf) if (t1_prefix(lenIV)) { t1_lenIV = (short) t1_scan_num(t1_line_array + strlen(lenIV), 0); if (t1_lenIV < 0) - luatex_fail("negative value of lenIV is not supported"); + normal_error("type 1","negative value of lenIV is not supported"); return; } t1_scan_keys(pdf); @@ -770,9 +766,7 @@ static char **t1_builtin_enc(void) } return glyph_names; } else - luatex_fail - ("cannot subset font (unknown predefined encoding `%s')", - t1_buf_array); + formatted_error("type 1","cannot subset font (unknown predefined encoding '%s')",t1_buf_array); } /* At this moment \.{/Encoding} is the prefix of |t1_line_array|, and the encoding is not a predefined encoding. @@ -802,7 +796,7 @@ static char **t1_builtin_enc(void) *p = 0; skip(r, ' '); if (counter > 255) - luatex_fail("encoding vector contains more than 256 names"); + normal_error("type 1","encoding vector contains more than 256 names"); if (strcmp(t1_buf_array, notdef) != 0) glyph_names[counter] = xstrdup(t1_buf_array); counter++; @@ -812,9 +806,7 @@ static char **t1_builtin_enc(void) break; else { remove_eol(r, t1_line_array); - luatex_fail - ("a name or `] def' or `] readonly def' expected: `%s'", - t1_line_array); + formatted_error("type 1","a name or '] def' or '] readonly def' expected: '%s'", t1_line_array); } } t1_getline(); @@ -900,23 +892,19 @@ static boolean t1_open_fontfile(int open_name_prefix) t1_size = 0; ff = check_ff_exist(fd_cur->fm->ff_name, is_truetype(fd_cur->fm)); if (ff->ff_path == NULL) { - luatex_fail("cannot open Type 1 font file for reading (%s)", - fd_cur->fm->ff_name); + formatted_error("type 1","cannot open file for reading '%s'",fd_cur->fm->ff_name); return false; } cur_file_name = luatex_find_file(ff->ff_path, find_type1_file_callback); if (cur_file_name == NULL) { - luatex_fail("cannot open Type 1 font file for reading (%s)", - ff->ff_path); + formatted_error("type 1","cannot open file for reading '%s'", ff->ff_path); return false; } callback_id = callback_defined(read_type1_file_callback); if (callback_id > 0) { - if (!run_callback(callback_id, "S->bSd", cur_file_name, - &file_opened, &t1_buffer, &t1_size) + if (!run_callback(callback_id, "S->bSd", cur_file_name, &file_opened, &t1_buffer, &t1_size) && file_opened && t1_size > 0) { - luatex_warn("cannot open Type 1 font file for reading (%s)", - cur_file_name); + formatted_warning("type 1","cannot open file for reading '%s'",cur_file_name); return false; } } else { @@ -966,7 +954,7 @@ static void t1_include(PDF pdf) @c #define check_subr(subr) \ if (subr >= subr_size || subr < 0) \ - luatex_fail("Subrs array: entry index out of range (%i)", subr); + formatted_error("type 1","Subrs array: entry index out of range '%i'", subr); static const char **check_cs_token_pair(void) { @@ -992,8 +980,7 @@ static void cs_store(boolean is_subr) } else { ptr = cs_ptr++; if (cs_ptr - cs_tab > cs_size) - luatex_fail - ("CharStrings dict: more entries than dict size (%i)", cs_size); + formatted_error("type 1","CharStrings dict: more entries than dict size '%i'", cs_size); if (strcmp(t1_buf_array + 1, notdef) == 0) /* skip the slash */ ptr->name = (char *) notdef; else @@ -1018,25 +1005,23 @@ static void cs_store(boolean is_subr) @ @c -#define store_subr() cs_store(true) -#define store_cs() cs_store(false) +#define store_subr() cs_store(true) +#define store_cs() cs_store(false) -#define CC_STACK_SIZE 24 +#define CC_STACK_SIZE 24 static int cc_stack[CC_STACK_SIZE], *stack_ptr = cc_stack; static cc_entry cc_tab[CS_MAX]; static boolean is_cc_init = false; - -#define cc_pop(N) \ - if (stack_ptr - cc_stack < (N)) \ - stack_error(N); \ +#define cc_pop(N) \ + if (stack_ptr - cc_stack < (N)) \ + stack_error(N); \ stack_ptr -= N -#define stack_error(N) { \ - luatex_fail("CharString: invalid access (%i) to stack (%i entries)", \ - (int) N, (int)(stack_ptr - cc_stack)); \ - goto cs_error; \ +#define stack_error(N) { \ + formatted_error("type 1","CharString: invalid access '%i' to stack, '%i' entries", (int) N, (int)(stack_ptr - cc_stack)); \ + goto cs_error; \ } #define cc_get(N) ((N) < 0 ? *(stack_ptr + (N)) : *(cc_stack + (N))) @@ -1095,7 +1080,6 @@ static void cc_init(void) #define mark_subr(n) cs_mark(0, n) #define mark_cs(s) cs_mark(s, 0) -__attribute__ ((noreturn, format(printf, 3, 4))) static void cs_fail(const char *cs_name, int subr, const char *fmt, ...) { char buf[SMALL_BUF_SIZE]; @@ -1104,9 +1088,9 @@ static void cs_fail(const char *cs_name, int subr, const char *fmt, ...) vsprintf(buf, fmt, args); va_end(args); if (cs_name == NULL) - luatex_fail("Subr (%i): %s", (int) subr, buf); + formatted_error("type 1","Subr '%i': %s", (int) subr, buf); else - luatex_fail("CharString (/%s): %s", cs_name, buf); + formatted_error("type 1","CharString (/%s): %s", cs_name, buf); } @ fix a return-less subr by appending |CS_RETURN| @@ -1170,7 +1154,7 @@ static void cs_mark(const char *cs_name, int subr) if (strcmp(ptr->name, cs_name) == 0) break; if (ptr == cs_ptr) { - luatex_warn("glyph `%s' undefined", cs_name); + formatted_warning("type 1","glyph '%s' undefined", cs_name); return; } if (ptr->name == notdef) @@ -1215,8 +1199,7 @@ static void cs_mark(const char *cs_name, int subr) cs_len--; } if (b >= CS_MAX) { - cs_fail(cs_name, subr, "command value out of range: %i", - (int) b); + cs_fail(cs_name, subr, "command value out of range: %i", (int) b); goto cs_error; } cc = cc_tab + b; @@ -1227,11 +1210,11 @@ static void cs_mark(const char *cs_name, int subr) if (cc->bottom) { if (stack_ptr - cc_stack < cc->nargs) cs_fail(cs_name, subr, - "less arguments on stack (%i) than required (%i)", + "less arguments on stack '%i' than required '%i'", (int) (stack_ptr - cc_stack), (int) cc->nargs); else if (stack_ptr - cc_stack > cc->nargs) cs_fail(cs_name, subr, - "more arguments on stack (%i) than required (%i)", + "more arguments on stack '%i' than required '%i'", (int) (stack_ptr - cc_stack), (int) cc->nargs); } last_cmd = b; @@ -1241,7 +1224,7 @@ static void cs_mark(const char *cs_name, int subr) cc_pop(1); mark_subr(a1); if (!subr_tab[a1].valid) { - cs_fail(cs_name, subr, "cannot call subr (%i)", (int) a1); + cs_fail(cs_name, subr, "cannot call subr '%i'", (int) a1); goto cs_error; } break; @@ -1276,9 +1259,9 @@ static void cs_mark(const char *cs_name, int subr) } } if (cs_name == NULL && last_cmd != CS_RETURN) { - luatex_warn("last command in subr `%i' is not a RETURN; " - "I will add it now but please consider fixing the font", - (int) subr); + formatted_warning("type 1", + "last command in subr '%i' is not a RETURN; I will add it now but please consider fixing the font", + (int) subr); append_cs_return(ptr); } return; @@ -1676,8 +1659,7 @@ static void t1_subset_charstrings(PDF pdf) if (cs_token_pair == NULL) - luatex_fail - ("This Type 1 font uses mismatched subroutine begin/end token pairs."); + formatted_error("type 1","mismatched subroutine begin/end token pairs"); t1_subr_flush(); } diff --git a/Build/source/texk/web2c/luatexdir/font/writet3.w b/Build/source/texk/web2c/luatexdir/font/writet3.w index 3dda1770409..1d33330716c 100644 --- a/Build/source/texk/web2c/luatexdir/font/writet3.w +++ b/Build/source/texk/web2c/luatexdir/font/writet3.w @@ -48,7 +48,7 @@ int t3_curbyte = 0; #define t3_check_eof() \ if (t3_eof()) \ - luatex_fail("unexpected end of file"); + normal_error("type 3","unexpected end of file"); @ @c @@ -139,16 +139,13 @@ static boolean writepk(PDF pdf, internal_font_number f) if (name == NULL || !FILESTRCASEEQ(cur_file_name, font_ret.name) || !kpse_bitmap_tolerance((float) font_ret.dpi, (float) dpi)) { - luatex_fail("Font %s at %i not found", cur_file_name, (int) dpi); + formatted_error("type 3","font %s at %i not found", cur_file_name, (int) dpi); } } callback_id = callback_defined(read_pk_file_callback); if (callback_id > 0) { - if (! - (run_callback - (callback_id, "S->bSd", name, &file_opened, &t3_buffer, &t3_size) - && file_opened && t3_size > 0)) { - luatex_warn("Font %s at %i not found", cur_file_name, (int) dpi); + if (!(run_callback(callback_id, "S->bSd", name, &file_opened, &t3_buffer, &t3_size) && file_opened && t3_size > 0)) { + formatted_warning("font %s at %i not found", cur_file_name, (int) dpi); cur_file_name = NULL; return false; } diff --git a/Build/source/texk/web2c/luatexdir/font/writettf.w b/Build/source/texk/web2c/luatexdir/font/writettf.w index 77fef925507..e1edea5e2ab 100644 --- a/Build/source/texk/web2c/luatexdir/font/writettf.w +++ b/Build/source/texk/web2c/luatexdir/font/writettf.w @@ -485,7 +485,7 @@ long ttf_getnum(int s) int c; while (s > 0) { if (ttf_eof()) - luatex_fail("unexpected EOF"); + normal_error("ttf font","unexpected EOF"); c = ttf_getchar(); i = (i << 8) + c; s--; @@ -516,7 +516,7 @@ dirtab_entry *ttf_name_lookup(const char *s, boolean required) } if (tab - dir_tab == ntabs) { if (required) - luatex_fail("can't find table `%s'", s); + formatted_error("ttf font","can't find table '%s'", s); else tab = NULL; } @@ -586,9 +586,7 @@ static void ttf_copy_encoding(void) e = ttfenc_tab + *q; e->code = charcodes[*q]; if (e->code == -1) - luatex_warn - ("character %i in subfont %s is not mapped to any charcode", - *q, fd_cur->fm->tfm_name); + formatted_warning("ttf font", "character %i in subfont %s is not mapped to any charcode", *q, fd_cur->fm->tfm_name); else { assert(e->code < 0x10000); sprintf(buf, "/c%4.4X", (int) e->code); @@ -816,8 +814,7 @@ void ttf_read_post(void) } break; default: - luatex_warn("unsupported format (%.8X) of `post' table, assuming 3.0", - (unsigned int) post_format); + formatted_warning("ttf font", "unsupported format '%.8X' of 'post' table, assuming 3.0", (unsigned int) post_format); case 0x00030000: for (glyph = glyph_tab; glyph - glyph_tab < NMACGLYPHS; glyph++) { glyph->name_index = (TTF_USHORT) (glyph - glyph_tab); @@ -915,14 +912,13 @@ static ttf_cmap_entry *ttf_read_cmap(char *ttf_name, int pid, int eid, goto read_cmap_format_4; else { if (warn) - luatex_warn("cmap format %i unsupported", format); + formatted_warning("ttf font", "cmap format %i unsupported", format); return NULL; } } } if (warn) - luatex_warn("cannot find cmap subtable for (pid,eid) = (%i, %i)", - pid, eid); + formatted_warning("ttf font", "cannot find cmap subtable for (pid,eid) = (%i,%i)", pid, eid); return NULL; read_cmap_format_4: /* initialize the new entry */ @@ -972,13 +968,13 @@ static ttf_cmap_entry *ttf_read_cmap(char *ttf_name, int pid, int eid, index = (index + s->idDelta) & 0xFFFF; } if (index >= glyphs_count) - luatex_fail("cmap: glyph index %li out of range [0..%i)", - index, glyphs_count); + formatted_error("ttf font", + "cmap issue, glyph index %li out of range [0..%i)", + index, glyphs_count); if (p->table[i] != -1) - luatex_warn - ("cmap: multiple glyphs are mapped to unicode %.4lX, " - "only %li will be used (glyph %li being ignored)", i, - p->table[i], index); + formatted_warning("ttf font", + "cmap issue, multiple glyphs are mapped to unicode %.4lX, %li will be used, %li is ignored)", + i, p->table[i], index); else p->table[i] = index; } @@ -991,7 +987,7 @@ static ttf_cmap_entry *ttf_read_cmap(char *ttf_name, int pid, int eid, return p; } -@ +@ @c static void ttf_read_font(void) { @@ -1021,7 +1017,7 @@ static void ttf_reset_chksm(PDF pdf, dirtab_entry * tab) tmp_ulong = 0; tab->offset = (TTF_ULONG) ttf_offset(); if (tab->offset % 4 != 0) - luatex_warn("offset of `%4.4s' is not a multiple of 4", tab->tag); + formatted_warning("ttf font","offset of `%4.4s' is not a multiple of 4", tab->tag); } @@ -1041,7 +1037,7 @@ static void ttf_copytab(PDF pdf, const char *name) ttf_set_chksm(pdf, tab); } -@ +@ @c #define BYTE_ENCODING_LENGTH \ ((256)*TTF_BYTE_SIZE + 3*TTF_USHORT_SIZE) @@ -1057,14 +1053,14 @@ static void ttf_byte_encoding(PDF pdf) put_byte(e->newindex); } else { if (e->name != notdef) - luatex_warn - ("glyph `%s' has been mapped to `%s' in `ttf_byte_encoding' cmap table", - e->name, notdef); + formatted_warning("ttf font", + "glyph '%s' has been mapped to '%s' in 'ttf_byte_encoding' cmap table", + e->name, notdef); put_byte(0); /* notdef */ } } -@ +@ @c #define TRIMMED_TABLE_MAP_LENGTH (TTF_USHORT_SIZE*(5 + (256))) @@ -1080,7 +1076,7 @@ static void ttf_trimmed_table_map(PDF pdf) (void) put_ushort(e->newindex); } -@ +@ @c #define SEG_MAP_DELTA_LENGTH ((16 + (256))*TTF_USHORT_SIZE) @@ -1107,7 +1103,7 @@ static void ttf_seg_map_delta(PDF pdf) (void) put_ushort(e->newindex); } -@ +@ @c #define CMAP_ENTRY_LENGTH (2*TTF_USHORT_SIZE + TTF_ULONG_SIZE) @@ -1146,7 +1142,7 @@ static void ttf_write_cmap(PDF pdf) offset += TRIMMED_TABLE_MAP_LENGTH; break; default: - luatex_fail("invalid format (it should not have happened)"); + normal_error("ttf font","invalid format (it should not have happened)"); } (void) put_ushort(ce->platform_id); (void) put_ushort(ce->encoding_id); @@ -1168,7 +1164,7 @@ static void ttf_write_cmap(PDF pdf) ttf_set_chksm(pdf, tab); } -@ +@ @c static int prepend_subset_tags(int index, char *p) { @@ -1249,7 +1245,7 @@ static void ttf_write_name(PDF pdf) xfree(new_name_buf); } -@ +@ @c static void ttf_write_dirtab(PDF pdf) { @@ -1290,7 +1286,7 @@ static void ttf_write_dirtab(PDF pdf) } } if (i % 4 != 0) { - luatex_warn("font length is not a multiple of 4 (%li)", i); + formatted_warning("ttf font","font length '%li' is not a multiple of 4", i); checksum <<= 8 * (4 - i % 4); } k = 0xB1B0AFBA - checksum; @@ -1299,7 +1295,7 @@ static void ttf_write_dirtab(PDF pdf) ttf_seek_outbuf(save_offset); } -@ +@ @c static void ttf_write_glyf(PDF pdf) { @@ -1323,7 +1319,7 @@ static void ttf_write_glyf(PDF pdf) if (glyph_tab[idx].newindex < 0) { glyph_tab[idx].newindex = (TTF_SHORT) new_glyphs_count; glyph_index[new_glyphs_count++] = idx; - /* + /* N.B.: Here we change |new_glyphs_count|, which appears in the condition of the |for| loop */ @@ -1356,7 +1352,7 @@ static void ttf_write_glyf(PDF pdf) while going through |ttfenc_tab|. After appending a new entry to |glyph_index| we set field |newindex| of corresponding entries in both |glyph_tab| and |ttfenc_tab| to the newly created index. - + @c static void ttf_reindex_glyphs(void) { @@ -1387,8 +1383,8 @@ static void ttf_reindex_glyphs(void) t = cmap->table; assert(t != NULL && e->code < 0x10000); if (t[e->code] < 0) { - luatex_warn - ("subfont %s: wrong mapping: character %li --> 0x%4.4lX --> .notdef", + formatted_warning("ttf font", + "subfont %s has a wrong mapping, character %li -> 0x%4.4lX -> .notdef", fd_cur->fm->tfm_name, (long) (e - ttfenc_tab), e->code); continue; } @@ -1403,8 +1399,7 @@ static void ttf_reindex_glyphs(void) /* scan form `index123' */ if (sscanf(e->name, GLYPH_PREFIX_INDEX "%i", &index) == 1) { if (index >= glyphs_count) { - luatex_warn("`%s' out of valid range [0..%i)", - e->name, glyphs_count); + formatted_warning("ttf font","'%s' out of valid range [0..%i)", e->name, glyphs_count); continue; } glyph = glyph_tab + index; @@ -1418,8 +1413,7 @@ static void ttf_reindex_glyphs(void) if (cmap == NULL) cmap = ttf_read_cmap(fd_cur->fm->ff_name, 0, 3, false); if (cmap == NULL) { - luatex_warn - ("no unicode mapping found, all `uniXXXX' names will be ignored"); + normal_warning("ttf font", "no unicode mapping found, all 'uniXXXX' names will be ignored"); cmap_not_found = true; /* once only */ } } @@ -1429,16 +1423,14 @@ static void ttf_reindex_glyphs(void) assert(t != NULL); if (t[index] != -1) { if (t[index] >= glyphs_count) { - luatex_warn - ("`%s' is mapped to index %li which is out of valid range [0..%i)", + formatted_warning("ttf font", "'%s' is mapped to index %li which is out of valid range [0..%i)", e->name, t[index], glyphs_count); continue; } glyph = glyph_tab + t[index]; goto append_new_glyph; } else { - luatex_warn("`unicode %s%.4X' is not mapped to any glyph", - GLYPH_PREFIX_UNICODE, index); + formatted_warning("ttf font","unicode %s%.4X is not mapped to any glyph", GLYPH_PREFIX_UNICODE, index); continue; } } @@ -1447,7 +1439,7 @@ static void ttf_reindex_glyphs(void) if (glyph->name != notdef && strcmp(glyph->name, e->name) == 0) break; if (!(glyph - glyph_tab < glyphs_count)) { - luatex_warn("glyph `%s' not found", e->name); + formatted_warning("ttf font","glyph '%s' not found", e->name); continue; } append_new_glyph: @@ -1502,7 +1494,7 @@ static void ttf_write_head(PDF pdf) ttf_set_chksm(pdf, tab); } -@ +@ @c static void ttf_write_hhea(PDF pdf) { @@ -1515,7 +1507,7 @@ static void ttf_write_hhea(PDF pdf) ttf_set_chksm(pdf, tab); } -@ +@ @c static void ttf_write_htmx(PDF pdf) { @@ -1529,7 +1521,7 @@ static void ttf_write_htmx(PDF pdf) ttf_set_chksm(pdf, tab); } -@ +@ @c static void ttf_write_loca(PDF pdf) { @@ -1557,7 +1549,7 @@ static void ttf_write_loca(PDF pdf) ttf_set_chksm(pdf, tab); } -@ +@ @c static void ttf_write_mapx(PDF pdf) { @@ -1569,7 +1561,7 @@ static void ttf_write_mapx(PDF pdf) ttf_set_chksm(pdf, tab); } -@ +@ @c static void ttf_write_OS2(PDF pdf) { @@ -1578,7 +1570,7 @@ static void ttf_write_OS2(PDF pdf) ttf_reset_chksm(pdf, tab); version = get_ushort(); if (version > 3) - luatex_fail("unknown version of OS/2 table (%.4X)", version); + formatted_error("ttf font","unknown version '%.4X' of OS/2 table", version); (void) put_ushort(0x0001); /* fix version to 1 */ ttf_ncopy(pdf, 2 * TTF_USHORT_SIZE + 13 * TTF_SHORT_SIZE + 10 * TTF_BYTE_SIZE); @@ -1598,7 +1590,7 @@ static void ttf_write_OS2(PDF pdf) ttf_set_chksm(pdf, tab); } -@ +@ @c static boolean unsafe_name(const char *s) { @@ -1647,7 +1639,7 @@ static void ttf_write_post(PDF pdf) ttf_set_chksm(pdf, tab); } -@ +@ @c static void ttf_init_font(PDF pdf, int n) { @@ -1661,7 +1653,7 @@ static void ttf_init_font(PDF pdf, int n) ttf_seek_outbuf(TABDIR_OFF + n * 4 * TTF_ULONG_SIZE); } -@ +@ @c static void ttf_subset_font(PDF pdf) { @@ -1688,7 +1680,7 @@ static void ttf_subset_font(PDF pdf) ttf_write_dirtab(pdf); } -@ +@ @c static void ttf_copy_font(PDF pdf) { @@ -1703,7 +1695,7 @@ static void ttf_copy_font(PDF pdf) ttf_write_dirtab(pdf); } -@ +@ @c void writettf(PDF pdf, fd_entry * fd) { @@ -1714,9 +1706,8 @@ void writettf(PDF pdf, fd_entry * fd) assert(is_truetype(fd_cur->fm)); assert(is_included(fd_cur->fm)); - if (is_subsetted(fd_cur->fm) && (fd_cur->fe == NULL) - && !is_subfont(fd_cur->fm)) { - luatex_fail("Subset TrueType must be a reencoded or a subfont"); + if (is_subsetted(fd_cur->fm) && (fd_cur->fe == NULL) && !is_subfont(fd_cur->fm)) { + normal_error("ttf font","subset must be a reencoded or a subfont"); } ttf_curbyte = 0; ttf_size = 0; @@ -1724,7 +1715,7 @@ void writettf(PDF pdf, fd_entry * fd) cur_file_name = luatex_find_file(fd_cur->fm->ff_name, find_truetype_file_callback); if (cur_file_name == NULL) { - luatex_fail("cannot find TrueType font file for reading (%s)", fd_cur->fm->ff_name); + formatted_error("ttf font","cannot find font file for reading '%s'", fd_cur->fm->ff_name); } callback_id = callback_defined(read_truetype_file_callback); if (callback_id > 0) { @@ -1732,11 +1723,11 @@ void writettf(PDF pdf, fd_entry * fd) &file_opened, &ttf_buffer, &ttf_size) && file_opened && ttf_size > 0) { } else { - luatex_fail("cannot open TrueType font file for reading (%s)", cur_file_name); + formatted_error("ttf font","cannot open font file for reading '%s'", cur_file_name); } } else { if (!ttf_open(cur_file_name)) { - luatex_fail("cannot open TrueType font file for reading (%s)", cur_file_name); + formatted_error("ttf font","cannot open font file for reading '%s'", cur_file_name); } ttf_read_file(); ttf_close(); @@ -1812,7 +1803,7 @@ static void do_writeotf(PDF pdf, fd_entry * fd) tex_printf(">>"); } -@ +@ @c void writeotf(PDF pdf, fd_entry * fd) { @@ -1829,7 +1820,7 @@ void writeotf(PDF pdf, fd_entry * fd) cur_file_name = luatex_find_file(fd_cur->fm->ff_name, find_opentype_file_callback); if (cur_file_name == NULL) { - luatex_fail("cannot find OpenType font file for reading (%s)", fd_cur->fm->ff_name); + formatted_error("otf font","cannot find font file for reading '%s'", fd_cur->fm->ff_name); } callback_id = callback_defined(read_opentype_file_callback); if (callback_id > 0) { @@ -1837,11 +1828,11 @@ void writeotf(PDF pdf, fd_entry * fd) &file_opened, &ttf_buffer, &ttf_size) && file_opened && ttf_size > 0) { } else { - luatex_fail("cannot open OpenType font file for reading (%s)", cur_file_name); + formatted_error("otf font","cannot open font file for reading '%s'", cur_file_name); } } else { if (!otf_open(cur_file_name)) { - luatex_fail("cannot open OpenType font file for reading (%s)", cur_file_name); + formatted_error("otf font","cannot open font file for reading '%s'", cur_file_name); } ttf_read_file(); ttf_close(); diff --git a/Build/source/texk/web2c/luatexdir/font/writetype0.w b/Build/source/texk/web2c/luatexdir/font/writetype0.w index 3f63b02ae12..3053103c524 100644 --- a/Build/source/texk/web2c/luatexdir/font/writetype0.w +++ b/Build/source/texk/web2c/luatexdir/font/writetype0.w @@ -51,8 +51,7 @@ void writetype0(PDF pdf, fd_entry * fd) cur_file_name = luatex_find_file(fd_cur->fm->ff_name, find_truetype_file_callback); if (cur_file_name == NULL) { - luatex_fail("cannot find OpenType font file for reading (%s)", - fd_cur->fm->ff_name); + formatted_error("type 0","cannot find file '%s'", fd_cur->fm->ff_name); } } callback_id = callback_defined(read_opentype_file_callback); @@ -61,13 +60,11 @@ void writetype0(PDF pdf, fd_entry * fd) &file_opened, &ttf_buffer, &ttf_size) && file_opened && ttf_size > 0) { } else { - luatex_fail("cannot open OpenType font file for reading (%s)", - cur_file_name); + formatted_error("type 0","cannot find file '%s'", cur_file_name); } } else { if (!otf_open(cur_file_name)) { - luatex_fail("cannot open OpenType font file for reading (%s)", - cur_file_name); + formatted_error("type 0","cannot find file '%s'", cur_file_name); } ttf_read_file(); ttf_close(); @@ -78,7 +75,7 @@ void writetype0(PDF pdf, fd_entry * fd) sfont = sfnt_open(ttf_buffer, ttf_size); if (sfont->type == SFNT_TYPE_TTC) i = ff_get_ttc_index(fd->fm->ff_name, fd->fm->ps_name); - + if (is_subsetted(fd_cur->fm)) { report_start_file(filetype_subset, cur_file_name); diff --git a/Build/source/texk/web2c/luatexdir/font/writetype2.w b/Build/source/texk/web2c/luatexdir/font/writetype2.w index 8980344afd7..d5ce1aca40a 100644 --- a/Build/source/texk/web2c/luatexdir/font/writetype2.w +++ b/Build/source/texk/web2c/luatexdir/font/writetype2.w @@ -152,7 +152,7 @@ boolean writetype2(PDF pdf, fd_entry * fd) cur_file_name = luatex_find_file(fd_cur->fm->ff_name, find_opentype_file_callback); if (cur_file_name == NULL) { - luatex_fail("cannot find OpenType font file for reading (%s)", fd_cur->fm->ff_name); + formatted_error("type 2","cannot find file '%s'", fd_cur->fm->ff_name); } callback_id = callback_defined(read_opentype_file_callback); if (callback_id > 0) { @@ -160,11 +160,11 @@ boolean writetype2(PDF pdf, fd_entry * fd) &file_opened, &ttf_buffer, &ttf_size) && file_opened && ttf_size > 0) { } else { - luatex_fail("cannot open OpenType font file for reading (%s)", cur_file_name); + formatted_error("type 2","cannot find file '%s'", cur_file_name); } } else { if (!otf_open(cur_file_name)) { - luatex_fail("cannot open OpenType font file for reading (%s)", cur_file_name); + formatted_error("type 2","cannot find file '%s'", cur_file_name); } ttf_read_file(); ttf_close(); diff --git a/Build/source/texk/web2c/luatexdir/image/epdf.h b/Build/source/texk/web2c/luatexdir/image/epdf.h index 09bc7cc84e4..3d4751c4587 100644 --- a/Build/source/texk/web2c/luatexdir/image/epdf.h +++ b/Build/source/texk/web2c/luatexdir/image/epdf.h @@ -121,7 +121,8 @@ extern "C" { extern int pdf_create_obj(PDF pdf, int t, int i); /* pdftoepdf.cc */ - extern void read_pdf_info(image_dict *, int, int, img_readtype_e); + extern void read_pdf_info(image_dict *); + extern void flush_pdf_info(image_dict *); extern void write_epdf(PDF, image_dict *); extern void unrefPdfDocument(char *); extern void unrefMemStreamPdfDocument(char *); diff --git a/Build/source/texk/web2c/luatexdir/image/image.h b/Build/source/texk/web2c/luatexdir/image/image.h index 5a9adfdc9bb..49996947e26 100644 --- a/Build/source/texk/web2c/luatexdir/image/image.h +++ b/Build/source/texk/web2c/luatexdir/image/image.h @@ -18,7 +18,6 @@ You should have received a copy of the GNU General Public License along with LuaTeX; if not, see . */ - #ifndef IMAGE_H # define IMAGE_H @@ -31,14 +30,13 @@ extern int do_zround(double r); /* from utils.w */ extern scaled one_hundred_bp; /* from pdfgen.w */ + # define bp2sp(p) do_zround(p * (one_hundred_bp / 100.0)) # define sp2bp(i) (i * 100.0 / one_hundred_bp) # define TYPE_IMG "image.meta" # define TYPE_IMG_DICT "image.dict" -/**********************************************************************/ - typedef struct { char *stream; } pdf_stream_struct; @@ -49,41 +47,52 @@ typedef struct { } png_img_struct; typedef struct { - int color_space; /* used color space. See JPG_ constants */ - JPG_UINT32 length; /* length of file/data */ + int color_space; /* used color space. See JPG_ constants */ + JPG_UINT32 length; /* length of file/data */ } jpg_img_struct; typedef struct { - int length; /* length of file/data */ + int length; /* length of file/data */ } jp2_img_struct; # if 0 -typedef struct { /* currently unused */ +typedef struct { /* currently unused */ } jb2_img_struct; # endif -typedef enum { DICT_NEW, /* fresh dictionary */ - DICT_FILESCANNED, /* image file scanned */ - DICT_REFERED, /* pdf_refximage_node in node list --> read-only dict */ - DICT_OUTIMG, /* /Im* appears in pagestream */ - DICT_SCHEDULED, /* image dict scheduled for writing (PONR) */ - DICT_WRITTEN /* image dict written to file */ +typedef enum { + DICT_NEW, /* fresh dictionary */ + DICT_FILESCANNED, /* image file scanned */ + DICT_REFERED, /* pdf_refximage_node in node list --> read-only dict */ + DICT_OUTIMG, /* /Im* appears in pagestream */ + DICT_SCHEDULED, /* image dict scheduled for writing (PONR) */ + DICT_WRITTEN /* image dict written to file */ } dict_state; - -typedef enum { IMG_TYPE_NONE, IMG_TYPE_PDF, IMG_TYPE_PNG, IMG_TYPE_JPG, - IMG_TYPE_JP2, IMG_TYPE_JBIG2, IMG_TYPE_PDFSTREAM, IMG_TYPE_PDFMEMSTREAM, IMG_TYPE_SENTINEL +typedef enum { + IMG_TYPE_NONE, + IMG_TYPE_PDF, + IMG_TYPE_PNG, + IMG_TYPE_JPG, + IMG_TYPE_JP2, + IMG_TYPE_JBIG2, + IMG_TYPE_PDFSTREAM, + IMG_TYPE_PDFMEMSTREAM, + IMG_TYPE_SENTINEL } imgtype_e; typedef enum { IMG_KEEPOPEN, IMG_CLOSEINBETWEEN } img_readtype_e; -typedef enum { PDF_BOX_SPEC_NONE, PDF_BOX_SPEC_MEDIA, PDF_BOX_SPEC_CROP, - PDF_BOX_SPEC_BLEED, PDF_BOX_SPEC_TRIM, PDF_BOX_SPEC_ART, +typedef enum { + PDF_BOX_SPEC_NONE, + PDF_BOX_SPEC_MEDIA, + PDF_BOX_SPEC_CROP, + PDF_BOX_SPEC_BLEED, + PDF_BOX_SPEC_TRIM, + PDF_BOX_SPEC_ART, PDF_BOX_SPEC_SENTINEL } pdfboxspec_e; -/**********************************************************************/ - typedef struct { int objnum; int index; /* /Im1, /Im2, ... */ @@ -113,100 +122,105 @@ typedef struct { int bbox[4]; dict_state state; int flags; + int luaref ; + boolean keepopen; + int errorlevel; + int pdfminorversion; union { pdf_stream_struct *pdfstream; png_img_struct *png; jpg_img_struct *jpg; jp2_img_struct *jp2; - /* jb2_img_struct *jb2; */ + /* jb2_img_struct *jb2; */ } img_struct; } image_dict; -# define img_objnum(N) ((N)->objnum) -# define img_index(N) ((N)->index) -# define img_dimen(N) ((N)->dimen) -# define img_width(N) ((N)->dimen.wd) -# define img_height(N) ((N)->dimen.ht) -# define img_depth(N) ((N)->dimen.dp) -# define img_transform(N) ((N)->transform) -# define img_xsize(N) ((N)->x_size) -# define img_ysize(N) ((N)->y_size) -# define img_xorig(N) ((N)->x_orig) -# define img_yorig(N) ((N)->y_orig) -# define img_xres(N) ((N)->x_res) -# define img_yres(N) ((N)->y_res) -# define img_rotation(N) ((N)->rotation) -# define img_colorspace(N) ((N)->colorspace) -# define img_group_ref(N) ((N)->group_ref) -# define img_totalpages(N) ((N)->total_pages) -# define img_pagenum(N) ((N)->page_num) -# define img_pagename(N) ((N)->pagename) -# define img_filename(N) ((N)->filename) -# define img_visiblefilename(N)((N)->visiblefilename) -# define img_filepath(N) ((N)->filepath) -# define img_attr(N) ((N)->attr) -# define img_file(N) ((N)->file) -# define img_type(N) ((N)->image_type) -# define img_procset(N) ((N)->procset) -# define img_colordepth(N) ((N)->color_depth) -# define img_pagebox(N) ((N)->page_box_spec) -# define img_bbox(N) ((N)->bbox) -# define img_state(N) ((N)->state) -# define img_flags(N) ((N)->flags) - -# define img_pdfstream_ptr(N) ((N)->img_struct.pdfstream) +# define img_objnum(N) ((N)->objnum) +# define img_index(N) ((N)->index) +# define img_dimen(N) ((N)->dimen) +# define img_width(N) ((N)->dimen.wd) +# define img_height(N) ((N)->dimen.ht) +# define img_depth(N) ((N)->dimen.dp) +# define img_transform(N) ((N)->transform) +# define img_xsize(N) ((N)->x_size) +# define img_ysize(N) ((N)->y_size) +# define img_xorig(N) ((N)->x_orig) +# define img_yorig(N) ((N)->y_orig) +# define img_xres(N) ((N)->x_res) +# define img_yres(N) ((N)->y_res) +# define img_rotation(N) ((N)->rotation) +# define img_colorspace(N) ((N)->colorspace) +# define img_group_ref(N) ((N)->group_ref) +# define img_totalpages(N) ((N)->total_pages) +# define img_pagenum(N) ((N)->page_num) +# define img_pagename(N) ((N)->pagename) +# define img_filename(N) ((N)->filename) +# define img_visiblefilename(N) ((N)->visiblefilename) +# define img_filepath(N) ((N)->filepath) +# define img_attr(N) ((N)->attr) +# define img_file(N) ((N)->file) +# define img_type(N) ((N)->image_type) +# define img_procset(N) ((N)->procset) +# define img_colordepth(N) ((N)->color_depth) +# define img_pagebox(N) ((N)->page_box_spec) +# define img_bbox(N) ((N)->bbox) +# define img_state(N) ((N)->state) +# define img_flags(N) ((N)->flags) +# define img_luaref(N) ((N)->luaref) +# define img_keepopen(N) ((N)->keepopen) +# define img_errorlevel(N) ((N)->errorlevel) +# define img_pdfminorversion(N) ((N)->pdfminorversion) + +# define img_pdfstream_ptr(N) ((N)->img_struct.pdfstream) # define img_pdfstream_stream(N) ((N)->img_struct.pdfstream->stream) -# define img_png_ptr(N) ((N)->img_struct.png) -# define img_png_png_ptr(N) ((N)->img_struct.png->png_ptr) -# define img_png_info_ptr(N) ((N)->img_struct.png->info_ptr) - -# define img_jpg_ptr(N) ((N)->img_struct.jpg) -# define img_jpg_color(N) ((N)->img_struct.jpg->color_space) +# define img_png_ptr(N) ((N)->img_struct.png) +# define img_png_png_ptr(N) ((N)->img_struct.png->png_ptr) +# define img_png_info_ptr(N) ((N)->img_struct.png->info_ptr) -# define img_jp2_ptr(N) ((N)->img_struct.jp2) +# define img_jpg_ptr(N) ((N)->img_struct.jpg) +# define img_jpg_color(N) ((N)->img_struct.jpg->color_space) -# define img_jb2_ptr(N) ((N)->img_struct.jb2) +# define img_jp2_ptr(N) ((N)->img_struct.jp2) -# define F_FLAG_BBOX (1 << 0) -# define F_FLAG_GROUP (1 << 1) +# define img_jb2_ptr(N) ((N)->img_struct.jb2) -# define img_set_bbox(N) (img_flags(N) |= F_FLAG_BBOX) -# define img_unset_bbox(N) (img_flags(N) &= ~F_FLAG_BBOX) -# define img_is_bbox(N) ((img_flags(N) & F_FLAG_BBOX) != 0) +# define F_FLAG_BBOX (1 << 0) +# define F_FLAG_GROUP (1 << 1) -# define img_set_group(N) (img_flags(N) |= F_FLAG_GROUP) -# define img_unset_group(N) (img_flags(N) &= ~F_FLAG_GROUP) -# define img_is_group(N) ((img_flags(N) & F_FLAG_GROUP) != 0) +# define img_set_bbox(N) (img_flags(N) |= F_FLAG_BBOX) +# define img_unset_bbox(N) (img_flags(N) &= ~F_FLAG_BBOX) +# define img_is_bbox(N) ((img_flags(N) & F_FLAG_BBOX) != 0) -# define epdf_xsize(a) img_xsize(idict_array[a]) -# define epdf_ysize(a) img_ysize(idict_array[a]) -# define epdf_orig_x(a) img_xorig(idict_array[a]) -# define epdf_orig_y(a) img_yorig(idict_array[a]) +# define img_set_group(N) (img_flags(N) |= F_FLAG_GROUP) +# define img_unset_group(N) (img_flags(N) &= ~F_FLAG_GROUP) +# define img_is_group(N) ((img_flags(N) & F_FLAG_GROUP) != 0) -# define is_pdf_image(a) ((img_type(idict_array[a]) == IMG_TYPE_PDF) || (img_type(idict_array[a]) == IMG_TYPE_PDFMEMSTREAM)) -# define is_png_image(a) (img_type(idict_array[a]) == IMG_TYPE_PNG) +# define epdf_xsize(a) img_xsize(idict_array[a]) +# define epdf_ysize(a) img_ysize(idict_array[a]) +# define epdf_orig_x(a) img_xorig(idict_array[a]) +# define epdf_orig_y(a) img_yorig(idict_array[a]) -# define img_is_refered(N) (img_index(N) != -1) +# define is_pdf_image(a) ((img_type(idict_array[a]) == IMG_TYPE_PDF) || (img_type(idict_array[a]) == IMG_TYPE_PDFMEMSTREAM)) +# define is_png_image(a) (img_type(idict_array[a]) == IMG_TYPE_PNG) -/**********************************************************************/ -/* image structure corresponds to pdfrefximage node */ +# define img_is_refered(N) (img_index(N) != -1) typedef struct { - scaled_whd dimen; /* requested/actual TeX dimensions */ + scaled_whd dimen; /* requested/actual TeX dimensions */ int transform; image_dict *dict; - int dict_ref; /* luaL_ref() reference */ + int dict_ref; /* luaL_ref() reference */ } image; -# define img_dict(N) ((N)->dict) -# define img_dictref(N) ((N)->dict_ref) +# define img_dict(N) ((N)->dict) +# define img_dictref(N) ((N)->dict_ref) -# define set_wd_running(N) (img_width(N) = null_flag) -# define set_ht_running(N) (img_height(N) = null_flag) -# define set_dp_running(N) (img_depth(N) = null_flag) -# define is_wd_running(N) (img_width(N) == null_flag) -# define is_ht_running(N) (img_height(N) == null_flag) -# define is_dp_running(N) (img_depth(N) == null_flag) +# define set_wd_running(N) (img_width(N) = null_flag) +# define set_ht_running(N) (img_height(N) = null_flag) +# define set_dp_running(N) (img_depth(N) = null_flag) +# define is_wd_running(N) (img_width(N) == null_flag) +# define is_ht_running(N) (img_height(N) == null_flag) +# define is_dp_running(N) (img_depth(N) == null_flag) -#endif /* IMAGE_H */ +#endif diff --git a/Build/source/texk/web2c/luatexdir/image/pdftoepdf.h b/Build/source/texk/web2c/luatexdir/image/pdftoepdf.h index 203f85c5c31..12d15121017 100644 --- a/Build/source/texk/web2c/luatexdir/image/pdftoepdf.h +++ b/Build/source/texk/web2c/luatexdir/image/pdftoepdf.h @@ -24,7 +24,9 @@ # include "image.h" -void read_pdf_info(image_dict *, int, int, img_readtype_e); +void read_pdf_info(image_dict *); +void flush_pdf_info(image_dict *); +/* flush_pdfstream_info(image_dict *); */ /* somehow doesn't work due to xfree macro */ void unrefPdfDocument(char *); void unrefMemStreamPdfDocument(char *); void write_epdf(PDF, image_dict *); diff --git a/Build/source/texk/web2c/luatexdir/image/pdftoepdf.w b/Build/source/texk/web2c/luatexdir/image/pdftoepdf.w index 1ece3a2dd48..b9d496ac9f0 100644 --- a/Build/source/texk/web2c/luatexdir/image/pdftoepdf.w +++ b/Build/source/texk/web2c/luatexdir/image/pdftoepdf.w @@ -20,40 +20,40 @@ @ @c - -// define DEBUG #define __STDC_FORMAT_MACROS /* for PRId64 etc. */ #include "image/epdf.h" -// This file is mostly C and not very much C++; it's just used to interface -// the functions of poppler, which happens to be written in C++. +/* + This file is mostly C and not very much C++; it's just used to interface + the functions of poppler, which happens to be written in C++. +*/ extern void md5(Guchar *msg, int msgLen, Guchar *digest); static GBool isInit = gFalse; -//********************************************************************** -// Maintain AVL tree of all PDF files for embedding +/* Maintain AVL tree of all PDF files for embedding */ static avl_table *PdfDocumentTree = NULL; -// AVL sort PdfDocument into PdfDocumentTree by file_path +/* AVL sort PdfDocument into PdfDocumentTree by file_path */ static int CompPdfDocument(const void *pa, const void *pb, void * /*p */ ) { - return strcmp(((const PdfDocument *) pa)->file_path, - ((const PdfDocument *) pb)->file_path); + return strcmp(((const PdfDocument *) pa)->file_path, ((const PdfDocument *) pb)->file_path); } -// Returns pointer to PdfDocument structure for PDF file. +/* Returns pointer to PdfDocument structure for PDF file. */ static PdfDocument *findPdfDocument(char *file_path) { PdfDocument *pdf_doc, tmp; - assert(file_path != NULL); - if (PdfDocumentTree == NULL) + if (file_path == NULL) { + normal_error("pdf backend","empty filename when loading pdf file"); + } else if (PdfDocumentTree == NULL) { return NULL; + } tmp.file_path = file_path; pdf_doc = (PdfDocument *) avl_find(PdfDocumentTree, &tmp); return pdf_doc; @@ -70,22 +70,20 @@ static char *get_file_checksum(const char *a, file_error_mode fe) time_t mtime = finfo.st_mtime; ck = (char *) malloc(PDF_CHECKSUM_SIZE); if (ck == NULL) - luatex_fail("PDF inclusion: out of memory while processing '%s'", - a); - snprintf(ck, PDF_CHECKSUM_SIZE, "%" PRIu64 "_%" PRIu64, (uint64_t) size, - (uint64_t) mtime); + formatted_error("pdf inclusion","out of memory while processing '%s'", a); + snprintf(ck, PDF_CHECKSUM_SIZE, "%" PRIu64 "_%" PRIu64, (uint64_t) size,(uint64_t) mtime); } else { switch (fe) { - case FE_FAIL: - luatex_fail("PDF inclusion: could not stat() file '%s'", a); - break; - case FE_RETURN_NULL: - if (ck != NULL) - free(ck); - ck = NULL; - break; - default: - assert(0); + case FE_FAIL: + formatted_error("pdf inclusion","could not stat() file '%s'", a); + break; + case FE_RETURN_NULL: + if (ck != NULL) + free(ck); + ck = NULL; + break; + default: + assert(0); } } return ck; @@ -93,28 +91,28 @@ static char *get_file_checksum(const char *a, file_error_mode fe) static char *get_stream_checksum (const char *str, unsigned long long str_size){ - /* http://www.cse.yorku.ca/~oz/hash.html */ - /* djb2 */ - unsigned long hash ; - char *ck = NULL; - unsigned int i; - hash = 5381; - ck = (char *) malloc(STRSTREAM_CHECKSUM_SIZE+1); - if (ck == NULL) - luatex_fail("PDF inclusion: out of memory while processing a memstream"); - for(i=0; i<(unsigned int)(str_size); i++) { - hash = ((hash << 5) + hash) + str[i]; /* hash * 33 + str[i] */ - } - snprintf(ck,STRSTREAM_CHECKSUM_SIZE+1,"%lx",hash); - ck[STRSTREAM_CHECKSUM_SIZE]='\0'; - return ck; + /* http://www.cse.yorku.ca/~oz/hash.html */ + /* djb2 */ + unsigned long hash ; + char *ck = NULL; + unsigned int i; + hash = 5381; + ck = (char *) malloc(STRSTREAM_CHECKSUM_SIZE+1); + if (ck == NULL) + normal_error("pdf inclusion","out of memory while processing a memstream"); + for(i=0; i<(unsigned int)(str_size); i++) { + hash = ((hash << 5) + hash) + str[i]; /* hash * 33 + str[i] */ + } + snprintf(ck,STRSTREAM_CHECKSUM_SIZE+1,"%lx",hash); + ck[STRSTREAM_CHECKSUM_SIZE]='\0'; + return ck; } - - -// Returns pointer to PdfDocument structure for PDF file. -// Creates a new PdfDocument structure if it doesn't exist yet. -// When fe = FE_RETURN_NULL, the function returns NULL in error case. +/* + Returns pointer to PdfDocument structure for PDF file. + Creates a new PdfDocument structure if it doesn't exist yet. + When fe = FE_RETURN_NULL, the function returns NULL in error case. +*/ PdfDocument *refPdfDocument(const char *file_path, file_error_mode fe) { @@ -124,15 +122,10 @@ PdfDocument *refPdfDocument(const char *file_path, file_error_mode fe) GooString *docName = NULL; int new_flag = 0; if ((checksum = get_file_checksum(file_path, fe)) == NULL) { - assert(fe == FE_RETURN_NULL); return (PdfDocument *) NULL; } - assert(checksum != NULL); path_copy = xstrdup(file_path); if ((pdf_doc = findPdfDocument(path_copy)) == NULL) { -#ifdef DEBUG - fprintf(stderr, "\nDEBUG: New PdfDocument %s\n", file_path); -#endif new_flag = 1; pdf_doc = new PdfDocument; pdf_doc->file_path = path_copy; @@ -140,38 +133,28 @@ PdfDocument *refPdfDocument(const char *file_path, file_error_mode fe) pdf_doc->doc = NULL; pdf_doc->inObjList = NULL; pdf_doc->ObjMapTree = NULL; - pdf_doc->occurences = 0; // 0 = unreferenced + pdf_doc->occurences = 0; /* 0 = unreferenced */ pdf_doc->pc = 0; } else { -#ifdef DEBUG - fprintf(stderr, "\nDEBUG: Found PdfDocument %s (%d)\n", - pdf_doc->file_path, pdf_doc->occurences); -#endif - assert(pdf_doc->checksum != NULL); if (strncmp(pdf_doc->checksum, checksum, PDF_CHECKSUM_SIZE) != 0) { - luatex_fail("PDF inclusion: file has changed '%s'", file_path); + formatted_error("pdf inclusion","file has changed '%s'", file_path); } free(checksum); free(path_copy); } - assert(pdf_doc != NULL); if (pdf_doc->doc == NULL) { -#ifdef DEBUG - fprintf(stderr, "\nDEBUG: New PDFDoc %s (%d)\n", - pdf_doc->file_path, pdf_doc->occurences); -#endif docName = new GooString(file_path); - doc = new PDFDoc(docName); // takes ownership of docName + doc = new PDFDoc(docName); /* takes ownership of docName */ pdf_doc->pc++; if (!doc->isOk() || !doc->okToPrint()) { switch (fe) { case FE_FAIL: - luatex_fail("PDF inclusion: reading PDF image failed"); + normal_error("pdf inclusion","reading image failed"); break; case FE_RETURN_NULL: delete doc; - // delete docName; + /* delete docName */ if (new_flag == 1) { if (pdf_doc->file_path != NULL) free(pdf_doc->file_path); @@ -187,27 +170,21 @@ PdfDocument *refPdfDocument(const char *file_path, file_error_mode fe) } pdf_doc->doc = doc; } - // PDF file could be opened without problems, checksum ok. + /* PDF file could be opened without problems, checksum ok. */ if (PdfDocumentTree == NULL) PdfDocumentTree = avl_create(CompPdfDocument, NULL, &avl_xallocator); if ((PdfDocument *) avl_find(PdfDocumentTree, pdf_doc) == NULL) { - void **aa = avl_probe(PdfDocumentTree, pdf_doc); - assert(aa != NULL); + avl_probe(PdfDocumentTree, pdf_doc); } pdf_doc->occurences++; -#ifdef DEBUG - fprintf(stderr, "\nDEBUG: Incrementing %s (%d)\n", - pdf_doc->file_path, pdf_doc->occurences); -#endif return pdf_doc; } - - -// Returns pointer to PdfDocument structure for a PDF stream in memory -// of streamsize dimension -// As before, creates a new PdfDocument structure if it doesn't exist yet -// with file_path = file_id +/* + Returns pointer to PdfDocument structure for a PDF stream in memory of streamsize + dimension. As before, creates a new PdfDocument structure if it doesn't exist yet + with file_path = file_id +*/ PdfDocument *refMemStreamPdfDocument(char *docstream, unsigned long long streamsize,const char *file_id) { @@ -219,21 +196,16 @@ PdfDocument *refMemStreamPdfDocument(char *docstream, unsigned long long streams MemStream *docmemstream = NULL; /*int new_flag = 0;*/ size_t cnt = 0; - checksum = get_stream_checksum(docstream, streamsize); - assert(checksum != NULL); cnt = strlen(file_id); - assert(cnt>0 && cnt 0 && cnt file_path = file_path; @@ -241,61 +213,43 @@ PdfDocument *refMemStreamPdfDocument(char *docstream, unsigned long long streams pdf_doc->doc = NULL; pdf_doc->inObjList = NULL; pdf_doc->ObjMapTree = NULL; - pdf_doc->occurences = 0; // 0 = unreferenced + pdf_doc->occurences = 0; /* 0 = unreferenced */ pdf_doc->pc = 0; } else { -#ifdef DEBUG - fprintf(stderr, "\nDEBUG: Found MemStreamPdfDocument %s (%d)\n", - pdf_doc->file_path, pdf_doc->occurences); -#endif - assert(pdf_doc->checksum != NULL); - // As is now, checksum is in file_path, so this check should be useless. + /* As is now, checksum is in file_path, so this check should be useless. */ if (strncmp(pdf_doc->checksum, checksum, STRSTREAM_CHECKSUM_SIZE) != 0) { - luatex_fail("PDF inclusion: stream has changed '%s'", file_path); + formatted_error("pdf inclusion","stream has changed '%s'", file_path); } - free(file_path); + free(file_path); free(checksum); } - assert(pdf_doc != NULL); if (pdf_doc->doc == NULL) { -#ifdef DEBUG - fprintf(stderr, "\nDEBUG: New PDFDoc %s (%d)\n", - pdf_doc->file_path, pdf_doc->occurences); -#endif - docmemstream = new MemStream( docstream,0,streamsize, obj.initNull() ); - doc = new PDFDoc(docmemstream); // takes ownership of docmemstream + docmemstream = new MemStream( docstream,0,streamsize, obj.initNull() ); + doc = new PDFDoc(docmemstream); /* takes ownership of docmemstream */ pdf_doc->pc++; - if (!doc->isOk() || !doc->okToPrint()) { - luatex_fail("poppler: reading PDF Stream failed"); - } + normal_error("pdf inclusion","reading pdf Stream failed"); + } pdf_doc->doc = doc; } - // PDF file could be opened without problems, checksum ok. + /* PDF file could be opened without problems, checksum ok. */ if (PdfDocumentTree == NULL) PdfDocumentTree = avl_create(CompPdfDocument, NULL, &avl_xallocator); if ((PdfDocument *) avl_find(PdfDocumentTree, pdf_doc) == NULL) { - void **aa = avl_probe(PdfDocumentTree, pdf_doc); - assert(aa != NULL); + avl_probe(PdfDocumentTree, pdf_doc); } pdf_doc->occurences++; -#ifdef DEBUG - fprintf(stderr, "\nDEBUG: Incrementing %s (%d)\n", - pdf_doc->file_path, pdf_doc->occurences); -#endif return pdf_doc; } - - -//********************************************************************** -// AVL sort ObjMap into ObjMapTree by object number and generation - -// keep the ObjMap struct small, as these are accumulated until the end +/* + AVL sort ObjMap into ObjMapTree by object number and generation keep the ObjMap + struct small, as these are accumulated until the end +*/ struct ObjMap { - Ref in; // object num/gen in orig. PDF file - int out_num; // object num after embedding (gen == 0) + Ref in; + int out_num; }; static int CompObjMap(const void *pa, const void *pb, void * /*p */ ) @@ -304,11 +258,11 @@ static int CompObjMap(const void *pa, const void *pb, void * /*p */ ) const Ref *b = &(((const ObjMap *) pb)->in); if (a->num > b->num) return 1; - if (a->num < b->num) + else if (a->num < b->num) return -1; - if (a->gen == b->gen) // most likely gen == 0 anyway + else if (a->gen == b->gen) return 0; - if (a->gen < b->gen) + else if (a->gen < b->gen) return -1; return 1; } @@ -316,7 +270,6 @@ static int CompObjMap(const void *pa, const void *pb, void * /*p */ ) static ObjMap *findObjMap(PdfDocument * pdf_doc, Ref in) { ObjMap *obj_map, tmp; - assert(pdf_doc != NULL); if (pdf_doc->ObjMapTree == NULL) return NULL; tmp.in = in; @@ -327,32 +280,31 @@ static ObjMap *findObjMap(PdfDocument * pdf_doc, Ref in) static void addObjMap(PdfDocument * pdf_doc, Ref in, int out_num) { ObjMap *obj_map = NULL; - assert(findObjMap(pdf_doc, in) == NULL); if (pdf_doc->ObjMapTree == NULL) pdf_doc->ObjMapTree = avl_create(CompObjMap, NULL, &avl_xallocator); obj_map = new ObjMap; obj_map->in = in; obj_map->out_num = out_num; - void **aa = avl_probe(pdf_doc->ObjMapTree, obj_map); - assert(aa != NULL); + avl_probe(pdf_doc->ObjMapTree, obj_map); } -// When copying the Resources of the selected page, all objects are -// copied recursively top-down. The findObjMap() function checks if an -// object has already been copied; if so, instead of copying just the -// new object number will be referenced. The ObjMapTree guarantees, -// that during the entire LuaTeX run any object from any embedded PDF -// file will end up max. once in the output PDF file. Indirect objects -// are not fetched during copying, but get a new object number from -// LuaTeX and then will be appended into a linked list. +/* + When copying the Resources of the selected page, all objects are + copied recursively top-down. The findObjMap() function checks if an + object has already been copied; if so, instead of copying just the + new object number will be referenced. The ObjMapTree guarantees, + that during the entire LuaTeX run any object from any embedded PDF + file will end up max. once in the output PDF file. Indirect objects + are not fetched during copying, but get a new object number from + LuaTeX and then will be appended into a linked list. +*/ static int addInObj(PDF pdf, PdfDocument * pdf_doc, Ref ref) { ObjMap *obj_map; InObj *p, *q, *n; if (ref.num == 0) { - luatex_fail("PDF inclusion: reference to invalid object" - " (is the included pdf broken?)"); + normal_error("pdf inclusion","reference to invalid object (broken pdf)"); } if ((obj_map = findObjMap(pdf_doc, ref)) != NULL) return obj_map->out_num; @@ -361,12 +313,14 @@ static int addInObj(PDF pdf, PdfDocument * pdf_doc, Ref ref) n->next = NULL; n->num = pdf_create_obj(pdf, obj_type_others, 0); addObjMap(pdf_doc, ref, n->num); - if (pdf_doc->inObjList == NULL) + if (pdf_doc->inObjList == NULL) { pdf_doc->inObjList = n; - else { - // it is important to add new objects at the end of the list, - // because new objects are being added while the list is being - // written out by writeRefs(). + } else { + /* + It is important to add new objects at the end of the list, + because new objects are being added while the list is being + written out by writeRefs(). + */ for (p = pdf_doc->inObjList; p != NULL; p = p->next) q = p; q->next = n; @@ -374,15 +328,16 @@ static int addInObj(PDF pdf, PdfDocument * pdf_doc, Ref ref) return n->num; } -//********************************************************************** -// Function converts double to pdffloat; very small and very large numbers -// are NOT converted to scientific notation. -// n must be a number or real conforming to the implementation limits -// of PDF as specified in appendix C.1 of the PDF Ref. -// These are: -// maximum value of ints is +2^32 -// maximum value of reals is +2^15 -// smalles values of reals is 1/(2^16) +/* + Function converts double to pdffloat; very small and very large numbers + are NOT converted to scientific notation. Here n must be a number or real + conforming to the implementation limits of PDF as specified in appendix C.1 + of the PDF Ref. These are: + + maximum value of ints is +2^32 + maximum value of reals is +2^15 + smalles values of reals is 1/(2^16) +*/ static pdffloat conv_double_to_pdffloat(double n) { @@ -493,7 +448,6 @@ static void copyStream(PDF pdf, PdfDocument * pdf_doc, Stream * stream) { copyDict(pdf, pdf_doc, stream->getDict()); pdf_begin_stream(pdf); - assert(pdf->zip_write_state == NO_ZIP); copyStreamStream(pdf, stream->getUndecodedStream()); pdf_end_stream(pdf); } @@ -510,9 +464,11 @@ static void copyObject(PDF pdf, PdfDocument * pdf_doc, Object * obj) case objReal: copyReal(pdf, obj->getReal()); break; - // not needed: - // case objNum: - // GBool isNum() { return type == objInt || type == objReal; } + /* + case objNum: + GBool isNum() { return type == objInt || type == objReal; } + break; + */ case objString: copyString(pdf, obj->getString()); break; @@ -538,16 +494,14 @@ static void copyObject(PDF pdf, PdfDocument * pdf_doc, Object * obj) case objError: case objEOF: case objNone: - luatex_fail("PDF inclusion: type <%s> cannot be copied", - obj->getTypeName()); + formatted_error("pdf inclusion","type '%s' cannot be copied", obj->getTypeName()); break; default: - assert(0); // poppler doesn't have any other types + /* poppler doesn't have any other types */ + assert(0); } } -//********************************************************************** - static void writeRefs(PDF pdf, PdfDocument * pdf_doc) { InObj *r, *n; @@ -560,7 +514,7 @@ static void writeRefs(PDF pdf, PdfDocument * pdf_doc) if (obj1.isStream()) pdf_begin_obj(pdf, r->num, OBJSTM_NEVER); else - pdf_begin_obj(pdf, r->num, 2); // \pdfobjcompresslevel = 2 is for this + pdf_begin_obj(pdf, r->num, 2); copyObject(pdf, pdf_doc, &obj1); obj1.free(); pdf_end_obj(pdf); @@ -570,115 +524,120 @@ static void writeRefs(PDF pdf, PdfDocument * pdf_doc) } } -// get the pagebox coordinates according to the pagebox_spec +/* get the pagebox coordinates according to the pagebox_spec */ static PDFRectangle *get_pagebox(Page * page, int pagebox_spec) { switch (pagebox_spec) { - case PDF_BOX_SPEC_MEDIA: - return page->getMediaBox(); - break; - case PDF_BOX_SPEC_CROP: - return page->getCropBox(); - break; - case PDF_BOX_SPEC_BLEED: - return page->getBleedBox(); - break; - case PDF_BOX_SPEC_TRIM: - return page->getTrimBox(); - break; - case PDF_BOX_SPEC_ART: - return page->getArtBox(); - break; - default: - luatex_fail("PDF inclusion: unknown value of pagebox spec (%i)", - (int) pagebox_spec); + case PDF_BOX_SPEC_MEDIA: + return page->getMediaBox(); + break; + case PDF_BOX_SPEC_CROP: + return page->getCropBox(); + break; + case PDF_BOX_SPEC_BLEED: + return page->getBleedBox(); + break; + case PDF_BOX_SPEC_TRIM: + return page->getTrimBox(); + break; + case PDF_BOX_SPEC_ART: + return page->getArtBox(); + break; + default: + return page->getMediaBox(); + break; } - return page->getMediaBox(); // to make the compiler happy } -// Reads various information about the PDF and sets it up for later inclusion. -// This will fail if the PDF version of the PDF is higher than -// minor_pdf_version_wanted or page_name is given and can not be found. -// It makes no sense to give page_name _and_ page_num. -// Returns the page number. +/* + Reads various information about the PDF and sets it up for later inclusion. + This will fail if the PDF version of the PDF is higher than minor_pdf_version_wanted + or page_name is given and can not be found. It makes no sense to give page_name and + page_num. Returns the page number. +*/ -void -read_pdf_info(image_dict * idict, int minor_pdf_version_wanted, - int pdf_inclusion_errorlevel, img_readtype_e readtype) +void flush_pdf_info(image_dict * idict) { - PdfDocument *pdf_doc; - PDFDoc *doc; + if (img_keepopen(idict)) { + unrefPdfDocument(img_filepath(idict)); + } +} + +/* + void flush_pdfstream_info(image_dict * idict) + { + if (img_pdfstream_ptr(idict) != NULL) { + xfree(img_pdfstream_stream(idict)); + xfree(img_pdfstream_ptr(idict)); + img_pdfstream_stream(idict) = NULL; + img_pdfstream_ptr(idict) = NULL; + } + } +*/ + +void read_pdf_info(image_dict * idict) +{ + PdfDocument *pdf_doc = NULL; + PDFDoc *doc = NULL; Catalog *catalog; Page *page; int rotate; PDFRectangle *pagebox; int pdf_major_version_found, pdf_minor_version_found; float xsize, ysize, xorig, yorig; - assert(idict != NULL); - assert((img_type(idict) == IMG_TYPE_PDF) || (img_type(idict) == IMG_TYPE_PDFMEMSTREAM)); - assert(readtype == IMG_CLOSEINBETWEEN); // only this is implemented - // initialize if (isInit == gFalse) { - if (!(globalParams)) // globalParams could be already created - globalParams = new GlobalParams(); - globalParams->setErrQuiet(gFalse); - isInit = gTrue; - } - // open PDF file - if (img_type(idict) == IMG_TYPE_PDF) - pdf_doc = refPdfDocument(img_filepath(idict), FE_FAIL); + if (!(globalParams)) + globalParams = new GlobalParams(); + globalParams->setErrQuiet(gFalse); + isInit = gTrue; + } + if (img_type(idict) == IMG_TYPE_PDF) + pdf_doc = refPdfDocument(img_filepath(idict), FE_FAIL); else if (img_type(idict) == IMG_TYPE_PDFMEMSTREAM) { - pdf_doc = findPdfDocument(img_filepath(idict)) ; - assert(pdf_doc != NULL); - pdf_doc->occurences++; - } else - luatex_fail("PDF inclusion: unknown document (1)"); + pdf_doc = findPdfDocument(img_filepath(idict)) ; + pdf_doc->occurences++; + } else { + normal_error("pdf inclusion","unknown document"); + } doc = pdf_doc->doc; catalog = doc->getCatalog(); - // check PDF version - // this works only for PDF 1.x -- but since any versions of PDF newer - // than 1.x will not be backwards compatible to PDF 1.x, pdfTeX will - // then have to changed drastically anyway. + /* + Check PDF version. This works only for PDF 1.x but since any versions of + PDF newer than 1.x will not be backwards compatible to PDF 1.x, we will + then have to changed drastically anyway. + */ pdf_major_version_found = doc->getPDFMajorVersion(); pdf_minor_version_found = doc->getPDFMinorVersion(); - if ((pdf_major_version_found > 1) - || (pdf_minor_version_found > minor_pdf_version_wanted)) { - const char *msg = - "PDF inclusion: found PDF version <%d.%d>, but at most version <1.%d> allowed"; - if (pdf_inclusion_errorlevel > 0) { - luatex_fail(msg, pdf_major_version_found, pdf_minor_version_found, - minor_pdf_version_wanted); + if ((pdf_major_version_found > 1) || (pdf_minor_version_found > img_pdfminorversion(idict))) { + const char *msg = "PDF inclusion: found PDF version '%d.%d', but at most version '1.%d' allowed"; + if (img_errorlevel(idict) > 0) { + formatted_error("pdf inclusion",msg, pdf_major_version_found, pdf_minor_version_found, img_pdfminorversion(idict)); } else { - luatex_warn(msg, pdf_major_version_found, pdf_minor_version_found, - minor_pdf_version_wanted); + formatted_warning("pdf inclusion",msg, pdf_major_version_found, pdf_minor_version_found, img_pdfminorversion(idict)); } } img_totalpages(idict) = catalog->getNumPages(); if (img_pagename(idict)) { - // get page by name + /* get page by name */ GooString name(img_pagename(idict)); LinkDest *link = doc->findDest(&name); if (link == NULL || !link->isOk()) - luatex_fail("PDF inclusion: invalid destination <%s>", - img_pagename(idict)); + formatted_error("pdf inclusion","invalid destination '%s'",img_pagename(idict)); Ref ref = link->getPageRef(); img_pagenum(idict) = catalog->findPage(ref.num, ref.gen); if (img_pagenum(idict) == 0) - luatex_fail("PDF inclusion: destination is not a page <%s>", - img_pagename(idict)); + formatted_error("pdf inclusion","destination is not a page '%s'",img_pagename(idict)); delete link; } else { - // get page by number + /* get page by number */ if (img_pagenum(idict) <= 0 || img_pagenum(idict) > img_totalpages(idict)) - luatex_fail("PDF inclusion: required page <%i> does not exist", - (int) img_pagenum(idict)); + formatted_error("pdf inclusion","required page '%i' does not exist",(int) img_pagenum(idict)); } - // get the required page + /* get the required page */ page = catalog->getPage(img_pagenum(idict)); - - // get the pagebox coordinates (media, crop,...) to use. + /* get the pagebox coordinates (media, crop,...) to use. */ pagebox = get_pagebox(page, img_pagebox(idict)); if (pagebox->x2 > pagebox->x1) { xorig = pagebox->x1; @@ -694,51 +653,64 @@ read_pdf_info(image_dict * idict, int minor_pdf_version_wanted, yorig = pagebox->y2; ysize = pagebox->y1 - pagebox->y2; } - // The following 4 parameters are raw. Do _not_ modify by /Rotate! + /* The following 4 parameters are raw. Do _not_ modify by /Rotate! */ img_xsize(idict) = bp2sp(xsize); img_ysize(idict) = bp2sp(ysize); img_xorig(idict) = bp2sp(xorig); img_yorig(idict) = bp2sp(yorig); - - // Handle /Rotate parameter. Only multiples of 90 deg. are allowed - // (PDF Ref. v1.3, p. 78). + /* + Handle /Rotate parameter. Only multiples of 90 deg. are allowed (PDF Ref. v1.3, + p. 78). We also accept negative angles. Beware: PDF counts clockwise! */ rotate = page->getRotate(); - switch (((rotate % 360) + 360) % 360) { // handles also neg. angles - case 0: - img_rotation(idict) = 0; - break; - case 90: - img_rotation(idict) = 3; // PDF counts clockwise! - break; - case 180: - img_rotation(idict) = 2; - break; - case 270: - img_rotation(idict) = 1; - break; - default: - luatex_warn - ("PDF inclusion: " - "/Rotate parameter in PDF file not multiple of 90 degrees."); + switch (((rotate % 360) + 360) % 360) { + case 0: + img_rotation(idict) = 0; + break; + case 90: + img_rotation(idict) = 3; + break; + case 180: + img_rotation(idict) = 2; + break; + case 270: + img_rotation(idict) = 1; + break; + default: + formatted_warning("pdf inclusion","/Rotate parameter in PDF file not multiple of 90 degrees"); } - - // currently unused info whether PDF contains a /Group + /* currently unused info whether PDF contains a /Group */ if (page->getGroup() != NULL) img_set_group(idict); + /* + LuaTeX pre 0.85 versions did this: - if (readtype == IMG_CLOSEINBETWEEN) + if (readtype == IMG_CLOSEINBETWEEN) { + unrefPdfDocument(img_filepath(idict)); + } + + and also unref'd in the finalizer zo we got an extra unrefs when garbage was + collected. However it is more efficient to keep the file open so we do that + now. The (slower) alternative is to unref here (which in most cases forcing a + close of the file) but then we must not call flush_pdf_info. + + A close (unref) can be forced by nilling the dict object at the lua end and + forcing a collectgarbage("collect") after that. + + */ + if (! img_keepopen(idict)) { unrefPdfDocument(img_filepath(idict)); + } } -//********************************************************************** -// Writes the current epf_doc. -// Here the included PDF is copied, so most errors that can happen -// during PDF inclusion will arise here. +/* + Write the current epf_doc. Here the included PDF is copied, so most errors + that can happen during PDF inclusion will arise here. +*/ void write_epdf(PDF pdf, image_dict * idict) { - PdfDocument *pdf_doc; - PDFDoc *doc; + PdfDocument *pdf_doc = NULL; + PDFDoc *doc = NULL; Catalog *catalog; Page *page; Ref *pageref; @@ -748,46 +720,39 @@ void write_epdf(PDF pdf, image_dict * idict) int i, l; double bbox[4]; char s[256]; - const char *pagedictkeys[] = - { "Group", "LastModified", "Metadata", "PieceInfo", "Resources", - "SeparationInfo", NULL + const char *pagedictkeys[] = { + "Group", "LastModified", "Metadata", "PieceInfo", "Resources", "SeparationInfo", NULL }; - assert(idict != NULL); - - // open PDF file - if (img_type(idict) == IMG_TYPE_PDF) - pdf_doc = refPdfDocument(img_filepath(idict), FE_FAIL); - else if (img_type(idict) == IMG_TYPE_PDFMEMSTREAM) { - pdf_doc = findPdfDocument(img_filepath(idict)) ; - assert(pdf_doc != NULL); - pdf_doc->occurences++; - } else - luatex_fail("PDF inclusion: unknown document (2)"); + /* open PDF file */ + if (img_type(idict) == IMG_TYPE_PDF) { + pdf_doc = refPdfDocument(img_filepath(idict), FE_FAIL); + } else if (img_type(idict) == IMG_TYPE_PDFMEMSTREAM) { + pdf_doc = findPdfDocument(img_filepath(idict)) ; + pdf_doc->occurences++; + } else { + normal_error("pdf inclusion","unknown document"); + } doc = pdf_doc->doc; catalog = doc->getCatalog(); page = catalog->getPage(img_pagenum(idict)); pageref = catalog->getPageRef(img_pagenum(idict)); - assert(pageref != NULL); // was checked already in read_pdf_info() doc->getXRef()->fetch(pageref->num, pageref->gen, &pageobj); pageDict = pageobj.getDict(); - - // write the Page header + /* write the Page header */ pdf_begin_obj(pdf, img_objnum(idict), OBJSTM_NEVER); pdf_begin_dict(pdf); pdf_dict_add_name(pdf, "Type", "XObject"); pdf_dict_add_name(pdf, "Subtype", "Form"); - if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0) pdf_printf(pdf, "\n%s\n", img_attr(idict)); pdf_dict_add_int(pdf, "FormType", 1); - - // write additional information + /* write additional information */ pdf_dict_add_img_filename(pdf, idict); snprintf(s, 30, "%s.PageNumber", pdfkeyprefix); pdf_dict_add_int(pdf, s, (int) img_pagenum(idict)); doc->getDocInfoNF(&obj1); if (obj1.isRef()) { - // the info dict must be indirect (PDF Ref p. 61) + /* the info dict must be indirect (PDF Ref p. 61) */ snprintf(s, 30, "%s.InfoDict", pdfkeyprefix); pdf_dict_add_ref(pdf, s, addInObj(pdf, pdf_doc, obj1.getRef())); } @@ -798,7 +763,7 @@ void write_epdf(PDF pdf, image_dict * idict) bbox[2] = sp2bp(img_bbox(idict)[2]); bbox[3] = sp2bp(img_bbox(idict)[3]); } else { - // get the pagebox coordinates (media, crop,...) to use. + /* get the pagebox coordinates (media, crop,...) to use. */ pagebox = get_pagebox(page, img_pagebox(idict)); bbox[0] = pagebox->x1; bbox[1] = pagebox->y1; @@ -812,30 +777,30 @@ void write_epdf(PDF pdf, image_dict * idict) copyReal(pdf, bbox[2]); copyReal(pdf, bbox[3]); pdf_end_array(pdf); - // The /Matrix calculation is replaced by transforms in out_img(). - - // Now all relevant parts of the Page dictionary are copied: - - // Metadata validity check (as a stream it must be indirect) + /* + Now all relevant parts of the Page dictionary are copied. Metadata validity + check is needed(as a stream it must be indirect). + */ pageDict->lookupNF("Metadata", &obj1); if (!obj1.isNull() && !obj1.isRef()) - luatex_warn("PDF inclusion: /Metadata must be indirect object"); + formatted_warning("pdf inclusion","/Metadata must be indirect object"); obj1.free(); - - // copy selected items in Page dictionary + /* copy selected items in Page dictionary */ for (i = 0; pagedictkeys[i] != NULL; i++) { pageDict->lookupNF(pagedictkeys[i], &obj1); if (!obj1.isNull()) { pdf_add_name(pdf, pagedictkeys[i]); - copyObject(pdf, pdf_doc, &obj1); // preserves indirection + /* preserves indirection */ + copyObject(pdf, pdf_doc, &obj1); } obj1.free(); } - - // If there are no Resources in the Page dict of the embedded page, - // try to inherit the Resources from the Pages tree of the embedded - // PDF file, climbing up the tree until the Resources are found. - // (This fixes a problem with Scribus 1.3.3.14.) + /* + If there are no Resources in the Page dict of the embedded page, + try to inherit the Resources from the Pages tree of the embedded + PDF file, climbing up the tree until the Resources are found. + (This fixes a problem with Scribus 1.3.3.14.) + */ pageDict->lookupNF("Resources", &obj1); if (obj1.isNull()) { op1 = &pagesobj1; @@ -856,30 +821,28 @@ void write_epdf(PDF pdf, image_dict * idict) op2->free(); }; if (!op1->isDict()) - luatex_warn("PDF inclusion: Page /Resources missing."); + formatted_warning("pdf inclusion","Page /Resources missing"); op1->free(); } obj1.free(); - - // write the Page contents + /* Write the Page contents. */ page->getContents(&contents); if (contents.isStream()) { - // Variant A: get stream and recompress under control - // of \pdfcompresslevel - // - // pdf_begin_stream(); - // copyStreamStream(contents->getStream()); - // pdf_end_stream(); - - // Variant B: copy stream without recompressing - // + /* + Variant A: get stream and recompress under control of \pdfcompresslevel + + pdf_begin_stream(); + copyStreamStream(contents->getStream()); + pdf_end_stream(); + + Variant B: copy stream without recompressing + */ contents.streamGetDict()->lookup("F", &obj1); if (!obj1.isNull()) { - luatex_fail("PDF inclusion: Unsupported external stream"); + normal_error("pdf inclusion","unsupported external stream"); } obj1.free(); contents.streamGetDict()->lookup("Length", &obj1); - assert(!obj1.isNull()); pdf_add_name(pdf, "Length"); copyObject(pdf, pdf_doc, &obj1); obj1.free(); @@ -908,46 +871,45 @@ void write_epdf(PDF pdf, image_dict * idict) copyStreamStream(pdf, (contents.arrayGet(i, &obj1))->getStream()); obj1.free(); if (i < (l - 1)) { - // put a space between streams to be on the safe side (streams - // should have a trailing space here, but one never knows) + /* + Put a space between streams to be on the safe side (streams + should have a trailing space here, but one never knows) + */ pdf_out(pdf, ' '); } } pdf_end_stream(pdf); pdf_end_obj(pdf); - } else { // the contents are optional, but we need to include an empty stream + } else { + /* the contents are optional, but we need to include an empty stream */ pdf_dict_add_streaminfo(pdf); pdf_end_dict(pdf); pdf_begin_stream(pdf); pdf_end_stream(pdf); pdf_end_obj(pdf); } - // write out all indirect objects + /* write out all indirect objects */ writeRefs(pdf, pdf_doc); contents.free(); pageobj.free(); - // unrefPdfDocument() must come after contents.free() and pageobj.free()! - // TH: The next line makes repeated pdf inclusion unacceptably slow -#if 0 - unrefPdfDocument(img_filepath(idict)); -#endif + /* + unrefPdfDocument() must come after contents.free() and pageobj.free()! + TH: The next line makes repeated pdf inclusion unacceptably slow + + unrefPdfDocument(img_filepath(idict)); + */ } -//********************************************************************** -// Deallocate a PdfDocument with all its resources +/* Deallocate a PdfDocument with all its resources. */ static void deletePdfDocumentPdfDoc(PdfDocument * pdf_doc) { InObj *r, *n; - assert(pdf_doc != NULL); - // this may be probably needed for an emergency destroyPdfDocument() + /* this may be probably needed for an emergency destroyPdfDocument() */ for (r = pdf_doc->inObjList; r != NULL; r = n) { n = r->next; delete r; } -#ifdef DEBUG - fprintf(stderr, "\nDEBUG: Deleting PDFDoc %s\n", pdf_doc->file_path); -#endif delete pdf_doc->doc; pdf_doc->doc = NULL; pdf_doc->pc++; @@ -957,47 +919,46 @@ static void destroyPdfDocument(void *pa, void * /*pb */ ) { PdfDocument *pdf_doc = (PdfDocument *) pa; deletePdfDocumentPdfDoc(pdf_doc); - // TODO: delete rest of pdf_doc + /* TODO: delete rest of pdf_doc */ } -// Called when an image has been written and its resources in image_tab are -// freed and it's not referenced anymore. +/* + Called when an image has been written and its resources in image_tab are + freed and it's not referenced anymore. +*/ void unrefPdfDocument(char *file_path) { PdfDocument *pdf_doc = findPdfDocument(file_path); - if (pdf_doc == NULL) /* Does the caller break the contract ? */ -return; - if (pdf_doc->occurences == 0) /* Again, does the caller breaks the contract ? */ -return; - /* for the moment we keep these assert here as remind that the code */ - /* should be revisited */ - //assert(pdf_doc != NULL); - //assert(pdf_doc->occurences != 0); // aim for point landing - pdf_doc->occurences--; -#ifdef DEBUG - fprintf(stderr, "\nDEBUG: Decrementing %s (%d)\n", - pdf_doc->file_path, pdf_doc->occurences); -#endif - if (pdf_doc->occurences == 0) { - assert(pdf_doc->inObjList == NULL); // should be eaten up already - deletePdfDocumentPdfDoc(pdf_doc); + if (pdf_doc->occurences > 0) { + pdf_doc->occurences--; + if (pdf_doc->occurences == 0) { + deletePdfDocumentPdfDoc(pdf_doc); + } + } else { + /* + We either have a mismatch in ref and unref or we're somehow out of sync + which can happen when we mess with the same file in lua and tex. + */ + formatted_warning("pdf inclusion","there can be a mismatch in opening and closing file '%s'",file_path); } } - - -// For completeness, but it isn't currently used -// (unreferencing is done by mean of file_path) +/* + For completeness, but it isn't currently used (unreferencing is done by mean + of file_path. +*/ void unrefMemStreamPdfDocument(char *file_id) { (void) unrefPdfDocument(file_id); - + } -// Called when PDF embedding system is finalized. -// Now deallocate all remaining PdfDocuments. +/* + Called when PDF embedding system is finalized. We now deallocate all remaining + PdfDocuments. +*/ void epdf_free() { diff --git a/Build/source/texk/web2c/luatexdir/image/writeimg.h b/Build/source/texk/web2c/luatexdir/image/writeimg.h index 13f2d3642a5..46c42d2657e 100644 --- a/Build/source/texk/web2c/luatexdir/image/writeimg.h +++ b/Build/source/texk/web2c/luatexdir/image/writeimg.h @@ -18,11 +18,10 @@ You should have received a copy of the GNU General Public License along with LuaTeX; if not, see . */ - #ifndef WRITEIMG_H # define WRITEIMG_H -# include "dvi/dvigen.h" /* for scaled_whd only */ +# include "dvi/dvigen.h" # include "image.h" # include "pdf/pdfpage.h" @@ -31,10 +30,9 @@ idict_entry *idict_array; void new_img_pdfstream_struct(image_dict *); image *new_image(void); -/*void init_image_dict(image_dict *);*/ image_dict *new_image_dict(void); void free_image_dict(image_dict * p); -void read_img(PDF, image_dict *, int, int); +void read_img(image_dict * p); void scan_pdfximage(PDF pdf); void scan_pdfrefximage(PDF pdf); scaled_whd tex_scale(scaled_whd nat, scaled_whd tex); @@ -50,4 +48,4 @@ scaled_whd scan_alt_rule(void); size_t read_file_to_buf(PDF pdf, FILE * f, size_t len); void pdf_dict_add_img_filename(PDF pdf, image_dict * idict); -#endif /* WRITEIMG_H */ +#endif diff --git a/Build/source/texk/web2c/luatexdir/image/writeimg.w b/Build/source/texk/web2c/luatexdir/image/writeimg.w index ff667cfe62e..c002b56dca9 100644 --- a/Build/source/texk/web2c/luatexdir/image/writeimg.w +++ b/Build/source/texk/web2c/luatexdir/image/writeimg.w @@ -21,8 +21,6 @@ @* Image inclusion. @ @c - - #include "ptexlib.h" #include #include @@ -40,78 +38,63 @@ @* Patch ImageTypeDetection 2003/02/08 by Heiko Oberdiek. - Function |readimage| performs some basic initializations. - Then it looks at the file extension to determine the - image type and calls specific code/functions. - - The main disadvantage is that standard file extensions - have to be used, otherwise pdfTeX is not able to detect - the correct image type. +Function |readimage| performs some basic initializations. Then it looks at the +file extension to determine the image type and calls specific code/functions. The +main disadvantage is that standard file extensions have to be used, otherwise +pdfTeX is not able to detect the correct image type. The patch now looks at the +file header first regardless of the file extension. This is implemented in +function |check_type_by_header|. If this check fails, the traditional test of +standard file extension is tried, done in function |check_type_by_extension|. - The patch now looks at the file header first regardless of - the file extension. This is implemented in function - |check_type_by_header|. If this check fails, the traditional - test of standard file extension is tried, done in function - |check_type_by_extension|. +Magic headers: - Magic headers: +* "PNG (Portable Network Graphics) Specification", Version 1.2 + (http://www.libpng.org/pub/png): - * "PNG (Portable Network Graphics) Specification", Version 1.2 - (http://www.libpng.org/pub/png): + 3.1. PNG file signature - 3.1. PNG file signature + The first eight bytes of a PNG file always contain the following + (decimal) values: 137 80 78 71 13 10 26 10 - The first eight bytes of a PNG file always contain the following - (decimal) values: +Translation to C: |"\x89PNG\r\n\x1A\n"| - 137 80 78 71 13 10 26 10 +* "JPEG File Interchange Format", Version 1.02: - Translation to C: |"\x89PNG\r\n\x1A\n"| + * you can identify a JFIF file by looking for the following sequence: + X'FF', SOI X'FF', APP0, <2 bytes to be skipped>, "JFIF", X'00'. - * "JPEG File Interchange Format", Version 1.02: +Function |check_type_by_header| only looks at the first two bytes: |"\xFF\xD8"| - o you can identify a JFIF file by looking for the following - sequence: X'FF', SOI X'FF', APP0, <2 bytes to be skipped>, - "JFIF", X'00'. +* ISO/IEC JTC 1/SC 29/WG 1 + (ITU-T SG8) + Coding of Still Pictures + Title: 14492 FCD + Source: JBIG Committee + Project: JTC 1.29.10 + Status: Final Committee Draft - Function |check_type_by_header| only looks at the first two bytes: - |"\xFF\xD8"| + D.4.1, ID string - * ISO/IEC JTC 1/SC 29/WG 1 - (ITU-T SG8) - Coding of Still Pictures - Title: 14492 FCD - Source: JBIG Committee - Project: JTC 1.29.10 - Status: Final Committee Draft + This is an 8-byte sequence containing 0x97 0x4A 0x42 0x32 0x0D 0x0A 0x1A 0x0A. - D.4.1, ID string +* "PDF Reference", third edition: - This is an 8-byte sequence containing 0x97 0x4A 0x42 0x32 0x0D 0x0A - 0x1A 0x0A. + * The first line should contain \%PDF-1.0 -- \%PDF-1.4 (section 3.4.1 "File Header"). + * The "implementation notes" say: - * "PDF Reference", third edition: + 3.4.1, File Header + 12. Acrobat viewers require only that the header appear somewhere within the + first 1024 bytes of the file. + 13. Acrobat viewers will also accept a header of the form \%!PS-Adobe-N.n PDF-M.m - * The first line should contain "\%PDF-1.0" until "\%PDF-1.4" - (section 3.4.1 "File Header"). - * The "implementation notes" say: +The check in function |check_type_by_header| only implements the first issue. The +implementation notes are not considered. Therefore files with garbage at start of +file must have the standard extension. - 3.4.1, File Header - 12. Acrobat viewers require only that the header appear - somewhere within the first 1024 bytes of the file. - 13. Acrobat viewers will also accept a header of the form - \%!PS-Adobe-N.n PDF-M.m - - The check in function |check_type_by_header| only implements - the first issue. The implementation notes are not considered. - Therefore files with garbage at start of file must have the - standard extension. - - Functions |check_type_by_header| and |check_type_by_extension|: - |img_type(img)| is set to |IMG_TYPE_NONE| by |new_image_dict()|. - Both functions try to detect a type and set |img_type(img)|. - Thus a value other than |IMG_TYPE_NONE| indicates that a - type has been found. +Functions |check_type_by_header| and |check_type_by_extension|: |img_type(img)| +is set to |IMG_TYPE_NONE| by |new_image_dict()|. Both functions try to detect a +type and set |img_type(img)|. Thus a value other than |IMG_TYPE_NONE| indicates +that a type has been found. @c #define HEADER_JPG "\xFF\xD8" @@ -121,8 +104,7 @@ #define HEADER_PDF "%PDF-1." #define MAX_HEADER (sizeof(HEADER_PNG)-1) #define HEADER_PDF_MEMSTREAM "data:application/pdf," /* see epdf.h */ -#define LEN_PDF_MEMSTREAM 21 /* see epdf.h */ - +#define LEN_PDF_MEMSTREAM 21 /* see epdf.h */ static void check_type_by_header(image_dict * idict) { @@ -132,17 +114,13 @@ static void check_type_by_header(image_dict * idict) char prefix[LEN_PDF_MEMSTREAM+1]; assert(idict != NULL); - if (img_type(idict) != IMG_TYPE_NONE) /* nothing to do */ + if (img_type(idict) != IMG_TYPE_NONE) return; - - /* read the header */ - /* Like */ - /* file = xfopen(img_filepath(idict), FOPEN_RBIN_MODE);*/ - /* but we also check for a memstream object */ + /* here we read the and also check for a memstream object */ assert(img_filepath(idict) && FOPEN_RBIN_MODE); file = fopen(img_filepath(idict), FOPEN_RBIN_MODE); if (file == NULL) { - /* check the prefix of img_filepath(idict) */ + /* check the prefix of img_filepath(idict) */ for (i = 0; (unsigned) i < LEN_PDF_MEMSTREAM; i++) { prefix[i] = (char) (img_filepath(idict)[i]); } @@ -158,7 +136,7 @@ static void check_type_by_header(image_dict * idict) for (i = 0; (unsigned) i < MAX_HEADER; i++) { header[i] = (char) xgetc(file); if (feof(file)) - luatex_fail("reading image file failed"); + normal_error("pdf backend","reading image file failed"); } xfclose(file, img_filepath(idict)); /* tests */ @@ -178,8 +156,8 @@ static void check_type_by_header(image_dict * idict) static void check_type_by_extension(image_dict * idict) { char *image_suffix; - - assert(idict != NULL); + if (idict != NULL) + return; if (img_type(idict) != IMG_TYPE_NONE) /* nothing to do */ return; /* tests */ @@ -209,28 +187,22 @@ void new_img_pdfstream_struct(image_dict * p) } @ @c -static void init_image(image * p) +image *new_image(void) { - assert(p != NULL); + image *p = xtalloc(1, image); set_wd_running(p); set_ht_running(p); set_dp_running(p); img_transform(p) = 0; img_dict(p) = NULL; img_dictref(p) = LUA_NOREF; -} - -@ @c -image *new_image(void) -{ - image *p = xtalloc(1, image); - init_image(p); return p; } @ @c -static void init_image_dict(image_dict * p) +image_dict *new_image_dict(void) { + image_dict *p = xtalloc(1, image_dict); assert(p != NULL); memset(p, 0, sizeof(image_dict)); set_wd_running(p); @@ -243,14 +215,11 @@ static void init_image_dict(image_dict * p) img_unset_bbox(p); img_unset_group(p); img_state(p) = DICT_NEW; - img_index(p) = -1; /* -1 = unused, used count from 0 */ -} - -@ @c -image_dict *new_image_dict(void) -{ - image_dict *p = xtalloc(1, image_dict); - init_image_dict(p); + img_index(p) = -1; /* -1 = unused, used count from 0 */ + img_luaref(p) = 0; + img_errorlevel(p) = pdf_inclusion_errorlevel; + fix_pdf_minorversion(static_pdf); + img_pdfminorversion(p) = pdf_minor_version; return p; } @@ -271,31 +240,33 @@ void free_image_dict(image_dict * p) /* called from limglib.c */ assert(img_state(p) < DICT_REFERED); switch (img_type(p)) { - case IMG_TYPE_PDFMEMSTREAM: - case IMG_TYPE_PDF: - unrefPdfDocument(img_filepath(p)); - break; - case IMG_TYPE_PNG: /* assuming |IMG_CLOSEINBETWEEN| */ - assert(img_png_ptr(p) == NULL); - break; - case IMG_TYPE_JPG: /* assuming |IMG_CLOSEINBETWEEN| */ - assert(img_jpg_ptr(p) == NULL); - break; - case IMG_TYPE_JP2: /* */ - assert(img_jp2_ptr(p) == NULL); - break; - case IMG_TYPE_JBIG2: /* todo: writejbig2.w cleanup */ - break; - case IMG_TYPE_PDFSTREAM: - if (img_pdfstream_ptr(p) != NULL) { - xfree(img_pdfstream_stream(p)); - xfree(img_pdfstream_ptr(p)); - } - break; - case IMG_TYPE_NONE: - break; - default: - assert(0); + case IMG_TYPE_PDFMEMSTREAM: + case IMG_TYPE_PDF: + flush_pdf_info(p); + break; + case IMG_TYPE_PNG: + flush_png_info(p); + break; + case IMG_TYPE_JPG: + flush_jpg_info(p); + break; + case IMG_TYPE_JP2: + flush_jp2_info(p); + break; + case IMG_TYPE_JBIG2: + flush_jbig2_info(p); + break; + case IMG_TYPE_PDFSTREAM: + /* flush_pdfstream_info(p); */ + if (img_pdfstream_ptr(p) != NULL) { + xfree(img_pdfstream_stream(p)); + xfree(img_pdfstream_ptr(p)); + } + break; + case IMG_TYPE_NONE: + break; + default: + assert(0); } free_dict_strings(p); assert(img_file(p) == NULL); @@ -303,14 +274,13 @@ void free_image_dict(image_dict * p) } @ @c -void read_img(PDF pdf, - image_dict * idict, int minor_version, int inclusion_errorlevel) +void read_img(image_dict * idict) { char *filepath = NULL; int callback_id; assert(idict != NULL); if (img_filename(idict) == NULL) { - luatex_fail("image file name missing"); + normal_error("pdf backend","image file name missing"); } callback_id = callback_defined(find_image_file_callback); if (img_filepath(idict) == NULL) { @@ -324,7 +294,7 @@ void read_img(PDF pdf, img_filepath(idict) = kpse_find_file(img_filename(idict), kpse_tex_format, true); } if (img_filepath(idict) == NULL) { - luatex_fail("cannot find image file '%s'", img_filename(idict)); + formatted_error("pdf backend","cannot find image file '%s'", img_filename(idict)); } } recorder_record_input(img_filename(idict)); @@ -333,31 +303,24 @@ void read_img(PDF pdf, check_type_by_extension(idict); /* read image */ switch (img_type(idict)) { - case IMG_TYPE_PDFMEMSTREAM: - case IMG_TYPE_PDF: - assert(pdf != NULL); /* TODO! */ - read_pdf_info(idict, minor_version, inclusion_errorlevel, - IMG_CLOSEINBETWEEN); - break; - case IMG_TYPE_PNG: - read_png_info(idict, IMG_CLOSEINBETWEEN); - break; - case IMG_TYPE_JPG: - read_jpg_info(pdf, idict, IMG_CLOSEINBETWEEN); - break; - case IMG_TYPE_JP2: - read_jp2_info(idict, IMG_CLOSEINBETWEEN); - break; - case IMG_TYPE_JBIG2: - if (minor_version < 4) { - luatex_fail - ("JBIG2 images only possible with at least PDF 1.4; you are generating PDF 1.%i", - (int) minor_version); - } - read_jbig2_info(idict); - break; - default: - luatex_fail("internal error: unknown image type (2)"); + case IMG_TYPE_PDFMEMSTREAM: + case IMG_TYPE_PDF: + read_pdf_info(idict); + break; + case IMG_TYPE_PNG: + read_png_info(idict); + break; + case IMG_TYPE_JPG: + read_jpg_info(idict); + break; + case IMG_TYPE_JP2: + read_jp2_info(idict); + break; + case IMG_TYPE_JBIG2: + read_jbig2_info(idict); + break; + default: + normal_error("pdf backend","internal error: unknown image type"); } cur_file_name = NULL; if (img_state(idict) < DICT_FILESCANNED) @@ -365,17 +328,14 @@ void read_img(PDF pdf, } @ @c -static image_dict *read_image(PDF pdf, char *file_name, int page_num, - char *page_name, int colorspace, - int page_box, int minor_version, - int inclusion_errorlevel) +static image_dict *read_image(char *file_name, int page_num, char *page_name, int colorspace, int page_box) { image *a = new_image(); image_dict *idict = img_dict(a) = new_image_dict(); - pdf->ximage_count++; - img_objnum(idict) = pdf_create_obj(pdf, obj_type_ximage, pdf->ximage_count); - img_index(idict) = pdf->ximage_count; - set_obj_data_ptr(pdf, img_objnum(idict), img_index(idict)); + static_pdf->ximage_count++; + img_objnum(idict) = pdf_create_obj(static_pdf, obj_type_ximage, static_pdf->ximage_count); + img_index(idict) = static_pdf->ximage_count; + set_obj_data_ptr(static_pdf, img_objnum(idict), img_index(idict)); idict_to_array(idict); img_colorspace(idict) = colorspace; img_pagenum(idict) = page_num; @@ -384,7 +344,7 @@ static image_dict *read_image(PDF pdf, char *file_name, int page_num, cur_file_name = file_name; img_filename(idict) = file_name; img_pagebox(idict) = page_box; - read_img(pdf, idict, minor_version, inclusion_errorlevel); + read_img(idict); return idict; } @@ -402,11 +362,12 @@ static pdfboxspec_e scan_pdf_box_spec(void) return PDF_BOX_SPEC_TRIM; else if (scan_keyword("artbox")) return PDF_BOX_SPEC_ART; - return PDF_BOX_SPEC_NONE; + else + return PDF_BOX_SPEC_NONE; } @ @c -void scan_pdfximage(PDF pdf) +void scan_pdfximage(PDF pdf) /* static_pdf */ { scaled_whd alt_rule; image_dict *idict; @@ -414,12 +375,12 @@ void scan_pdfximage(PDF pdf) char *named = NULL, *attr = NULL, *file_name = NULL; alt_rule = scan_alt_rule(); /* scans || to |alt_rule| */ if (scan_keyword("attr")) { - scan_pdf_ext_toks(); + scan_toks(false, true); attr = tokenlist_to_cstring(def_ref, true, NULL); delete_token_ref(def_ref); } if (scan_keyword("named")) { - scan_pdf_ext_toks(); + scan_toks(false, true); named = tokenlist_to_cstring(def_ref, true, NULL); delete_token_ref(def_ref); page = 0; @@ -437,13 +398,11 @@ void scan_pdfximage(PDF pdf) if (pagebox == PDF_BOX_SPEC_NONE) pagebox = PDF_BOX_SPEC_CROP; } - scan_pdf_ext_toks(); + scan_toks(false, true); file_name = tokenlist_to_cstring(def_ref, true, NULL); assert(file_name != NULL); delete_token_ref(def_ref); - idict = - read_image(pdf, file_name, page, named, colorspace, pagebox, - pdf_minor_version, pdf_inclusion_errorlevel); + idict = read_image(file_name, page, named, colorspace, pagebox); img_attr(idict) = attr; img_dimen(idict) = alt_rule; img_transform(idict) = transform; @@ -452,7 +411,7 @@ void scan_pdfximage(PDF pdf) } @ @c -#define tail cur_list.tail_field +#define tail cur_list.tail_field void scan_pdfrefximage(PDF pdf) { @@ -559,11 +518,11 @@ scaled_whd scale_img(image_dict * idict, scaled_whd alt_rule, int transform) xr = img_xres(idict); yr = img_yres(idict); if (x <= 0 || y <= 0 || xr < 0 || yr < 0) - luatex_fail("ext1: invalid image dimensions"); + normal_error("pdf backend","invalid image dimensions"); if (xr > 65535 || yr > 65535) { xr = 0; yr = 0; - luatex_warn("ext1: too large image resolution ignored"); + normal_warning("pdf backend","too large image resolution ignored"); } if (((transform - img_rotation(idict)) & 1) == 1) { tmp = x; @@ -622,7 +581,7 @@ void write_img(PDF pdf, image_dict * idict) write_pdfstream(pdf, idict); break; default: - luatex_fail("internal error: unknown image type (1)"); + normal_error("pdf backend","internal error: unknown image type"); } report_stop_file(filetype_image); if (img_type(idict) == IMG_TYPE_PNG) { @@ -645,7 +604,7 @@ void pdf_write_image(PDF pdf, int n) void check_pdfstream_dict(image_dict * idict) { if (!img_is_bbox(idict)) - luatex_fail("image.stream: no bbox given"); + normal_error("pdf backend","image.stream: no bbox given"); if (img_state(idict) < DICT_FILESCANNED) img_state(idict) = DICT_FILESCANNED; } @@ -679,7 +638,6 @@ void write_pdfstream(PDF pdf, image_dict * idict) } @ @c -/* define |idict_ptr|, |idict_array|, and |idict_limit| */ idict_entry *idict_ptr, *idict_array = NULL; size_t idict_limit; @@ -721,6 +679,8 @@ void pdf_dict_add_img_filename(PDF pdf, image_dict * idict) } } +/* hh: why store images in the format ... let's get rid of this */ + @ To allow the use of box resources inside saved boxes in -ini mode, the information in the array has to be (un)dumped with the format. The next two routines take care of that. @@ -731,8 +691,7 @@ the split in two separate runs. There was only one problem remaining: The pdfversion and pdfinclusionerrorlevel can have changed inbetween the call to -|readimage()| and dump time. That is why they are passed as arguments -to undumpimagemeta once more. +|readimage()| and dump time. some of the dumped values are really type int, not integer, but since the macro falls back to |generic_dump| anyway, that @@ -746,121 +705,6 @@ does not matter. by the bytes. The trailing \.{\\0} is dumped as well, because that makes the code simpler. -@c -#define dumpcharptr(a) \ - do { \ - int x; \ - if (a!=NULL) { \ - x = (int)strlen(a)+1; \ - dumpinteger(x); dump_things(*a, x); \ - } else { \ - x = 0; dumpinteger(x); \ - } \ - } while (0) - -#define undumpcharptr(s) \ - do { \ - int x; \ - char *a; \ - undumpinteger (x); \ - if (x>0) { \ - a = xmalloc((unsigned)x); \ - undump_things(*a,x); \ - s = a ; \ - } else { s = NULL; } \ - } while (0) - -@ @c -void dumpimagemeta(void) -{ - int cur_index, i; - image_dict *idict; - - i = (int) idict_limit; - dumpinteger(i); - cur_index = (int) (idict_ptr - idict_array); - dumpinteger(cur_index); - - for (i = 1; i < cur_index; i++) { - idict = idict_array[i]; - assert(idict != NULL); - dumpcharptr(img_filename(idict)); - dumpinteger(img_type(idict)); - dumpinteger(img_procset(idict)); - dumpinteger(img_xsize(idict)); - dumpinteger(img_ysize(idict)); - dumpinteger(img_xres(idict)); - dumpinteger(img_yres(idict)); - dumpinteger(img_totalpages(idict)); - dumpinteger(img_colorspace(idict)); - - /* the |image_struct| is not dumped at all, except for a few - variables that are needed to restore the contents */ - - if ((img_type(idict) == IMG_TYPE_PDF)|| (img_type(idict) == IMG_TYPE_PDFMEMSTREAM)) { - dumpinteger(img_pagebox(idict)); - dumpinteger(img_pagenum(idict)); - } else if (img_type(idict) == IMG_TYPE_JBIG2) { - dumpinteger(img_pagenum(idict)); - } - - } -} - -@ @c -void undumpimagemeta(PDF pdf, int pdfversion, int pdfinclusionerrorlevel) -{ - int cur_index, i; - image_dict *idict; - - assert(pdf != NULL); - undumpinteger(i); - idict_limit = (size_t) i; - - idict_array = xtalloc(idict_limit, idict_entry); - undumpinteger(cur_index); - idict_ptr = idict_array + cur_index; - - for (i = 1; i < cur_index; i++) { - idict = new_image_dict(); - assert(idict != NULL); - assert(img_index(idict) == -1); - idict_to_array(idict); - undumpcharptr(img_filename(idict)); - undumpinteger(img_type(idict)); - undumpinteger(img_procset(idict)); - undumpinteger(img_xsize(idict)); - undumpinteger(img_ysize(idict)); - undumpinteger(img_xres(idict)); - undumpinteger(img_yres(idict)); - undumpinteger(img_totalpages(idict)); - undumpinteger(img_colorspace(idict)); - - switch (img_type(idict)) { - case IMG_TYPE_PDFMEMSTREAM: - case IMG_TYPE_PDF: - undumpinteger(img_pagebox(idict)); - undumpinteger(img_pagenum(idict)); - break; - case IMG_TYPE_PNG: - case IMG_TYPE_JPG: - case IMG_TYPE_JP2: - break; - case IMG_TYPE_JBIG2: - if (pdfversion < 4) { - luatex_fail - ("JBIG2 images only possible with at least PDF 1.4; you are generating PDF 1.%i", - (int) pdfversion); - } - undumpinteger(img_pagenum(idict)); - break; - default: - luatex_fail("unknown type of image"); - } - read_img(pdf, idict, pdfversion, pdfinclusionerrorlevel); - } -} - @ scan rule spec to |alt_rule| @c scaled_whd scan_alt_rule(void) diff --git a/Build/source/texk/web2c/luatexdir/image/writejbig2.h b/Build/source/texk/web2c/luatexdir/image/writejbig2.h index 95019b6c81b..e2c907bf687 100644 --- a/Build/source/texk/web2c/luatexdir/image/writejbig2.h +++ b/Build/source/texk/web2c/luatexdir/image/writejbig2.h @@ -18,7 +18,6 @@ You should have received a copy of the GNU General Public License along with LuaTeX; if not, see . */ - #ifndef WRITEJBIG2_H # define WRITEJBIG2_H @@ -27,8 +26,10 @@ unsigned int read2bytes(FILE * f); unsigned int read4bytes(FILE * f); -void flush_jbig2_page0_objects(PDF); +boolean supported_jbig2(image_dict *); void read_jbig2_info(image_dict *); +void flush_jbig2_info(image_dict *); void write_jbig2(PDF, image_dict *); +void flush_jbig2_page0_objects(PDF); -#endif /* WRITEJBIG"_H */ +#endif diff --git a/Build/source/texk/web2c/luatexdir/image/writejbig2.w b/Build/source/texk/web2c/luatexdir/image/writejbig2.w index 7b676fb6e87..d1ed0a408d4 100644 --- a/Build/source/texk/web2c/luatexdir/image/writejbig2.w +++ b/Build/source/texk/web2c/luatexdir/image/writejbig2.w @@ -20,7 +20,6 @@ % with LuaTeX; if not, see . @ - This is experimental JBIG2 image support to pdfTeX. JBIG2 image decoding is part of Adobe PDF-1.4, and requires Acroread 5.0 or later. @@ -80,8 +79,6 @@ object exists, reference it. Else create fresh one. 09 Dec. 2002: JBIG2 seg. page numbers > 0 are now set to 1, see PDF Ref. @ @c - - #undef DEBUG #include "ptexlib.h" @@ -120,7 +117,7 @@ typedef enum { INITIAL, HAVEINFO, WRITEPDF } PHASE; typedef struct _LITEM { struct _LITEM *prev; struct _LITEM *next; - void *d; /* data */ + void *d; /* data */ } LITEM; typedef struct _LIST { @@ -133,26 +130,26 @@ typedef struct _SEGINFO { unsigned long segnum; boolean isrefered; boolean refers; - unsigned int seghdrflags; /* set by readseghdr() */ - boolean pageassocsizeflag; /* set by readseghdr() */ - unsigned int reftosegcount; /* set by readseghdr() */ - unsigned int countofrefered; /* set by readseghdr() */ - unsigned int fieldlen; /* set by readseghdr() */ - unsigned int segnumwidth; /* set by readseghdr() */ - long segpage; /* set by readseghdr() */ - unsigned long segdatalen; /* set by readseghdr() */ - unsigned long hdrstart; /* set by readseghdr() */ - unsigned long hdrend; /* set by readseghdr() */ + unsigned int seghdrflags; /* set by readseghdr() */ + boolean pageassocsizeflag; /* set by readseghdr() */ + unsigned int reftosegcount; /* set by readseghdr() */ + unsigned int countofrefered; /* set by readseghdr() */ + unsigned int fieldlen; /* set by readseghdr() */ + unsigned int segnumwidth; /* set by readseghdr() */ + long segpage; /* set by readseghdr() */ + unsigned long segdatalen; /* set by readseghdr() */ + unsigned long hdrstart; /* set by readseghdr() */ + unsigned long hdrend; /* set by readseghdr() */ unsigned long datastart; unsigned long dataend; - boolean endofstripeflag; /* set by checkseghdrflags() */ - boolean endofpageflag; /* set by checkseghdrflags() */ - boolean pageinfoflag; /* set by checkseghdrflags() */ - boolean endoffileflag; /* set by checkseghdrflags() */ + boolean endofstripeflag; /* set by checkseghdrflags() */ + boolean endofpageflag; /* set by checkseghdrflags() */ + boolean pageinfoflag; /* set by checkseghdrflags() */ + boolean endoffileflag; /* set by checkseghdrflags() */ } SEGINFO; typedef struct _PAGEINFO { - LIST segments; /* segments associated with page */ + LIST segments; /* segments associated with page */ unsigned long pagenum; unsigned int width; unsigned int height; @@ -167,12 +164,12 @@ typedef struct _FILEINFO { FILE *file; char *filepath; long filesize; - LIST pages; /* not including page0 */ + LIST pages; /* not including page0 */ LIST page0; - unsigned int filehdrflags; /* set by readfilehdr() */ - boolean sequentialaccess; /* set by readfilehdr() */ - unsigned long numofpages; /* set by readfilehdr() */ - unsigned long streamstart; /* set by |get_jbig2_info()| */ + unsigned int filehdrflags; /* set by readfilehdr() */ + boolean sequentialaccess; /* set by readfilehdr() */ + unsigned long numofpages; /* set by readfilehdr() */ + unsigned long streamstart; /* set by |get_jbig2_info()| */ unsigned long pdfpage0objnum; PHASE phase; } FILEINFO; @@ -183,22 +180,19 @@ static struct avl_table *file_tree = NULL; static int comp_file_entry(const void *pa, const void *pb, void *p) { (void) p; - return strcmp(((const FILEINFO *) pa)->filepath, - ((const FILEINFO *) pb)->filepath); + return strcmp(((const FILEINFO *) pa)->filepath,((const FILEINFO *) pb)->filepath); } static int comp_page_entry(const void *pa, const void *pb, void *p) { (void) p; - return (int) (((const PAGEINFO *) pa)->pagenum - - ((const PAGEINFO *) pb)->pagenum); + return (int) (((const PAGEINFO *) pa)->pagenum - ((const PAGEINFO *) pb)->pagenum); } static int comp_segment_entry(const void *pa, const void *pb, void *p) { (void) p; - return (int) (((const SEGINFO *) pa)->segnum - - ((const SEGINFO *) pb)->segnum); + return (int) (((const SEGINFO *) pa)->segnum - ((const SEGINFO *) pb)->segnum); } @ @c @@ -207,9 +201,9 @@ static int ygetc(FILE * stream) int c = getc(stream); if (c < 0) { if (c == EOF) - luatex_fail("getc() failed; premature end of JBIG2 image file"); + normal_error("readjbig2","premature end file"); else - luatex_fail("getc() failed (can't happen)"); + normal_error("readjbig2","can't happen"); } return c; } @@ -382,8 +376,7 @@ static void readfilehdr(FILEINFO * fip) xfseek(fip->file, 0, SEEK_SET, fip->filepath); for (i = 0; i < 8; i++) if (ygetc(fip->file) != jbig2_id[i]) - luatex_fail - ("readfilehdr(): reading JBIG2 image file failed: ID string missing"); + normal_error("readjbig2","ID string missing"); /* Annex D.4.2 File header flags */ fip->filehdrflags = (unsigned int) ygetc(fip->file); fip->sequentialaccess = (fip->filehdrflags & 0x01) ? true : false; @@ -407,41 +400,40 @@ static void checkseghdrflags(SEGINFO * sip) sip->endoffileflag = false; /* 7.3 Segment types */ switch (sip->seghdrflags & 0x3f) { - case M_SymbolDictionary: - case M_IntermediateTextRegion: - case M_ImmediateTextRegion: - case M_ImmediateLosslessTextRegion: - case M_PatternDictionary: - case M_IntermediateHalftoneRegion: - case M_ImmediateHalftoneRegion: - case M_ImmediateLosslessHalftoneRegion: - case M_IntermediateGenericRegion: - case M_ImmediateGenericRegion: - case M_ImmediateLosslessGenericRegion: - case M_IntermediateGenericRefinementRegion: - case M_ImmediateGenericRefinementRegion: - case M_ImmediateLosslessGenericRefinementRegion: - break; - case M_PageInformation: - sip->pageinfoflag = true; - break; - case M_EndOfPage: - sip->endofpageflag = true; - break; - case M_EndOfStripe: - sip->endofstripeflag = true; - break; - case M_EndOfFile: - sip->endoffileflag = true; - break; - case M_Profiles: - case M_Tables: - case M_Extension: - break; - default: - luatex_fail - ("checkseghdrflags(): unknown segment type in JBIG2 image file"); - break; + case M_SymbolDictionary: + case M_IntermediateTextRegion: + case M_ImmediateTextRegion: + case M_ImmediateLosslessTextRegion: + case M_PatternDictionary: + case M_IntermediateHalftoneRegion: + case M_ImmediateHalftoneRegion: + case M_ImmediateLosslessHalftoneRegion: + case M_IntermediateGenericRegion: + case M_ImmediateGenericRegion: + case M_ImmediateLosslessGenericRegion: + case M_IntermediateGenericRefinementRegion: + case M_ImmediateGenericRefinementRegion: + case M_ImmediateLosslessGenericRefinementRegion: + break; + case M_PageInformation: + sip->pageinfoflag = true; + break; + case M_EndOfPage: + sip->endofpageflag = true; + break; + case M_EndOfStripe: + sip->endofstripeflag = true; + break; + case M_EndOfFile: + sip->endoffileflag = true; + break; + case M_Profiles: + case M_Tables: + case M_Extension: + break; + default: + normal_error("readjbig2","unknown segment type file"); + break; } } @@ -454,19 +446,10 @@ static boolean readseghdr(FILEINFO * fip, SEGINFO * sip) sip->hdrstart = xftell(fip->file, fip->filepath); if (fip->sequentialaccess && sip->hdrstart == (unsigned) fip->filesize) return false; /* no endoffileflag is ok for sequentialaccess */ -#ifdef DEBUG - printf("\nhdrstart %d\n", sip->hdrstart); -#endif /* 7.2.2 Segment number */ sip->segnum = read4bytes(fip->file); -#ifdef DEBUG - printf(" segnum %d\n", sip->segnum); -#endif /* 7.2.3 Segment header flags */ sip->seghdrflags = (unsigned int) ygetc(fip->file); -#ifdef DEBUG - printf(" hdrflags %d\n", sip->seghdrflags & 0x3f); -#endif checkseghdrflags(sip); if (fip->sequentialaccess && sip->endoffileflag) /* accept shorter segment, */ return true; /* makes it compliant with Example 3.4 of PDFRef. 5th ed. */ @@ -489,15 +472,15 @@ static boolean readseghdr(FILEINFO * fip, SEGINFO * sip) sip->segnumwidth = 4; for (i = 0; i < sip->countofrefered; i++) { switch (sip->segnumwidth) { - case 1: - (void) ygetc(fip->file); - break; - case 2: - (void) read2bytes(fip->file); - break; - case 4: - (void) read4bytes(fip->file); - break; + case 1: + (void) ygetc(fip->file); + break; + case 2: + (void) read2bytes(fip->file); + break; + case 4: + (void) read4bytes(fip->file); + break; } } /* 7.2.6 Segment page association */ @@ -543,22 +526,22 @@ static void writeseghdr(PDF pdf, FILEINFO * fip, SEGINFO * sip) /* 7.2.5 Referred-to segment numbers */ for (i = 0; i < sip->countofrefered; i++) { switch (sip->segnumwidth) { - case 1: - referedseg = (unsigned long) ygetc(fip->file); - pdf_out(pdf, referedseg); - break; - case 2: - referedseg = read2bytes(fip->file); - pdf_out(pdf, (referedseg >> 8) & 0xff); - pdf_out(pdf, referedseg & 0xff); - break; - case 4: - referedseg = read4bytes(fip->file); - pdf_out(pdf, (referedseg >> 24) & 0xff); - pdf_out(pdf, (referedseg >> 16) & 0xff); - pdf_out(pdf, (referedseg >> 8) & 0xff); - pdf_out(pdf, referedseg & 0xff); - break; + case 1: + referedseg = (unsigned long) ygetc(fip->file); + pdf_out(pdf, referedseg); + break; + case 2: + referedseg = read2bytes(fip->file); + pdf_out(pdf, (referedseg >> 8) & 0xff); + pdf_out(pdf, referedseg & 0xff); + break; + case 4: + referedseg = read4bytes(fip->file); + pdf_out(pdf, (referedseg >> 24) & 0xff); + pdf_out(pdf, (referedseg >> 16) & 0xff); + pdf_out(pdf, (referedseg >> 8) & 0xff); + pdf_out(pdf, referedseg & 0xff); + break; } if (fip->page0.last != NULL && !sip->refers) markpage0seg(fip, referedseg); @@ -592,15 +575,15 @@ static void checkseghdr(FILEINFO * fip, SEGINFO * sip) /* 7.2.5 Referred-to segment numbers */ for (i = 0; i < sip->countofrefered; i++) { switch (sip->segnumwidth) { - case 1: - referedseg = (unsigned long) ygetc(fip->file); - break; - case 2: - referedseg = read2bytes(fip->file); - break; - case 4: - referedseg = read4bytes(fip->file); - break; + case 1: + referedseg = (unsigned long) ygetc(fip->file); + break; + case 2: + referedseg = read2bytes(fip->file); + break; + case 4: + referedseg = read4bytes(fip->file); + break; } if (!sip->refers) markpage0seg(fip, referedseg); @@ -620,8 +603,8 @@ static void checkseghdr(FILEINFO * fip, SEGINFO * sip) static unsigned long findstreamstart(FILEINFO * fip) { SEGINFO tmp; - assert(!fip->sequentialaccess); /* D.2 Random-access organisation */ - do /* find random-access stream start */ + assert(!fip->sequentialaccess); /* D.2 Random-access organisation */ + do /* find random-access stream start */ (void) readseghdr(fip, &tmp); while (!tmp.endoffileflag); fip->streamstart = tmp.hdrend; @@ -632,8 +615,8 @@ static unsigned long findstreamstart(FILEINFO * fip) @ @c static void rd_jbig2_info(FILEINFO * fip) { - unsigned long seekdist = 0; /* for sequential-access only */ - unsigned long streampos = 0; /* for random-access only */ + unsigned long seekdist = 0; /* for sequential-access only */ + unsigned long streampos = 0; /* for random-access only */ unsigned long currentpage = 0; boolean sipavail = false; PAGEINFO *pip; @@ -732,16 +715,14 @@ static void wr_jbig2(PDF pdf, image_dict * idict, FILEINFO * fip, pdf_dict_add_int(pdf, "Height", pip->height); pdf_dict_add_name(pdf, "ColorSpace", "DeviceGray"); pdf_dict_add_int(pdf, "BitsPerComponent", 1); - pdf_dict_add_int(pdf, "Length", - getstreamlen(pip->segments.first, true)); + pdf_dict_add_int(pdf, "Length", getstreamlen(pip->segments.first, true)); pdf_add_name(pdf, "Filter"); pdf_begin_array(pdf); pdf_add_name(pdf, "JBIG2Decode"); pdf_end_array(pdf); if (fip->page0.last != NULL) { if (fip->pdfpage0objnum == 0) { - fip->pdfpage0objnum = - (unsigned long) pdf_create_obj(pdf, obj_type_others, 0); + fip->pdfpage0objnum = (unsigned long) pdf_create_obj(pdf, obj_type_others, 0); } pdf_add_name(pdf, "DecodeParms"); pdf_begin_array(pdf); @@ -757,8 +738,7 @@ static void wr_jbig2(PDF pdf, image_dict * idict, FILEINFO * fip, assert(pip != NULL); pdf_begin_obj(pdf, (int) fip->pdfpage0objnum, OBJSTM_NEVER); pdf_begin_dict(pdf); - pdf_dict_add_int(pdf, "Length", - getstreamlen(pip->segments.first, false)); + pdf_dict_add_int(pdf, "Length", getstreamlen(pip->segments.first, false)); pdf_end_dict(pdf); } pdf_begin_stream(pdf); @@ -779,29 +759,44 @@ static void wr_jbig2(PDF pdf, image_dict * idict, FILEINFO * fip, xfclose(fip->file, fip->filepath); } +@ @c +boolean supported_jbig2(image_dict * idict) +{ + if (img_pdfminorversion(idict) < 4) { + normal_error("readjbig2","you need to generate at least PDF 1.4"); + return false; + } else { + return true; + } +} + +@ @c +void flush_jbig2_info(image_dict * idict) +{ + /* todo */ +} + @ @c void read_jbig2_info(image_dict * idict) { FILEINFO *fip, tmp; PAGEINFO *pip; - void **aa; - assert(idict != NULL); - img_type(idict) = IMG_TYPE_JBIG2; - if (img_pagenum(idict) < 1) - luatex_fail - ("read_jbig2_info(): page %d not in JBIG2 image file; page must be > 0", - (int) img_pagenum(idict)); + img_type(idict) = IMG_TYPE_JBIG2; /* already set probably, see other read_... */ + if (! supported_jbig2(idict)) { + /* already an error done */ + } + if (img_pagenum(idict) < 1) { + normal_error("readjbig2","page must be > 0"); + } if (file_tree == NULL) { file_tree = avl_create(comp_file_entry, NULL, &avl_xallocator); - assert(file_tree != NULL); } tmp.filepath = img_filepath(idict); fip = (FILEINFO *) avl_find(file_tree, &tmp); if (fip == NULL) { fip = new_fileinfo(); fip->filepath = xstrdup(img_filepath(idict)); - aa = avl_probe(file_tree, fip); - assert(aa != NULL); + avl_probe(file_tree, fip); } if (fip->phase == INITIAL) { rd_jbig2_info(fip); @@ -813,9 +808,9 @@ void read_jbig2_info(image_dict * idict) } } pip = find_pageinfo(&(fip->pages), (unsigned long) img_pagenum(idict)); - if (pip == NULL) - luatex_fail("read_jbig2_info(): page %d not found in JBIG2 image file", - (int) img_pagenum(idict)); + if (pip == NULL) { + formatted_error("readjbig2","page %d not found in image file",(int) img_pagenum(idict)); + } img_totalpages(idict) = (int) fip->numofpages; img_xsize(idict) = (int) pip->width; img_ysize(idict) = (int) pip->height; diff --git a/Build/source/texk/web2c/luatexdir/image/writejp2.h b/Build/source/texk/web2c/luatexdir/image/writejp2.h index ed9bbe47c72..aa8248fd25a 100644 --- a/Build/source/texk/web2c/luatexdir/image/writejp2.h +++ b/Build/source/texk/web2c/luatexdir/image/writejp2.h @@ -18,13 +18,13 @@ You should have received a copy of the GNU General Public License along with LuaTeX; if not, see . */ - #ifndef WRITEJP2_H # define WRITEJP2_H # include "image.h" -void read_jp2_info(image_dict *, img_readtype_e); +void read_jp2_info(image_dict *); +void flush_jp2_info(image_dict *); void write_jp2(PDF, image_dict *); #endif /* WRITEJP2_H */ diff --git a/Build/source/texk/web2c/luatexdir/image/writejp2.w b/Build/source/texk/web2c/luatexdir/image/writejp2.w index 8ea537e9f75..cb317e11928 100644 --- a/Build/source/texk/web2c/luatexdir/image/writejp2.w +++ b/Build/source/texk/web2c/luatexdir/image/writejp2.w @@ -20,7 +20,6 @@ @ @c - @ Basic JPEG~2000 image support. Section and Table references below: Information technology --- JPEG~2000 image coding system: Core coding system. ISO/IEC 15444-1, Second edition, 2004-09-15, file |15444-1annexi.pdf|. @@ -66,8 +65,9 @@ static hdr_struct read_boxhdr(image_dict * idict) hdr.tbox = read4bytes(img_file(idict)); if (hdr.lbox == 1) hdr.lbox = read8bytes(img_file(idict)); - if (hdr.lbox == 0 && hdr.tbox != BOX_JP2C) - luatex_fail("reading JP2 image failed (LBox == 0)"); + if (hdr.lbox == 0 && hdr.tbox != BOX_JP2C) { + normal_error("readjp2","LBox == 0"); + } return hdr; } @@ -90,6 +90,7 @@ static void scan_ihdr(image_dict * idict) /* 1.5.3.7.1 Capture Resolution box */ /* 1.5.3.7.2 Default Display Resolution box */ + static void scan_resc_resd(image_dict * idict) { unsigned int vr_n, vr_d, hr_n, hr_d; @@ -108,6 +109,7 @@ static void scan_resc_resd(image_dict * idict) } /* 1.5.3.7 Resolution box (superbox) */ + static void scan_res(image_dict * idict, uint64_t epos_s) { hdr_struct hdr; @@ -118,25 +120,23 @@ static void scan_res(image_dict * idict, uint64_t epos_s) hdr = read_boxhdr(idict); epos = spos + hdr.lbox; switch (hdr.tbox) { - case (BOX_RESC): - /* arbitrarily: let BOX_RESD have precedence */ - if (img_xres(idict) == 0 && img_yres(idict) == 0) { + case (BOX_RESC): + /* arbitrarily: let BOX_RESD have precedence */ + if (img_xres(idict) == 0 && img_yres(idict) == 0) { + scan_resc_resd(idict); + if (xftell(img_file(idict), img_filepath(idict)) != (long)epos) + normal_error("readjp2","resc box size inconsistent"); + } + break; + case (BOX_RESD): scan_resc_resd(idict); if (xftell(img_file(idict), img_filepath(idict)) != (long)epos) - luatex_fail - ("reading JP2 image failed (resc box size inconsistent)"); - } - break; - case (BOX_RESD): - scan_resc_resd(idict); - if (xftell(img_file(idict), img_filepath(idict)) != (long)epos) - luatex_fail - ("reading JP2 image failed (resd box size inconsistent)"); - break; - default:; + normal_error("readjp2","resd box size inconsistent"); + break; + default:; } if (epos > epos_s) - luatex_fail("reading JP2 image failed (res box size inconsistent)"); + normal_error("readjp2","res box size inconsistent"); if (epos == epos_s) break; xfseek(img_file(idict), (long) epos, SEEK_SET, img_filepath(idict)); @@ -144,6 +144,7 @@ static void scan_res(image_dict * idict, uint64_t epos_s) } /* 1.5.3 JP2 Header box (superbox) */ + static boolean scan_jp2h(image_dict * idict, uint64_t epos_s) { boolean ihdr_found = false; @@ -158,8 +159,7 @@ static boolean scan_jp2h(image_dict * idict, uint64_t epos_s) case (BOX_IHDR): scan_ihdr(idict); if (xftell(img_file(idict), img_filepath(idict)) != (long)epos) - luatex_fail - ("reading JP2 image failed (ihdr box size inconsistent)"); + normal_error("readjp2","ihdr box size inconsistent"); ihdr_found = true; break; case (BOX_RES): @@ -168,8 +168,7 @@ static boolean scan_jp2h(image_dict * idict, uint64_t epos_s) default:; } if (epos > epos_s) - luatex_fail - ("reading JP2 image failed (jp2h box size inconsistent)"); + normal_error("readjp2","jp2h box size inconsistent"); if (epos == epos_s) break; xfseek(img_file(idict), (long) epos, SEEK_SET, img_filepath(idict)); @@ -179,50 +178,56 @@ static boolean scan_jp2h(image_dict * idict, uint64_t epos_s) static void close_and_cleanup_jp2(image_dict * idict) { - assert(idict != NULL); - assert(img_file(idict) != NULL); - assert(img_filepath(idict) != NULL); - xfclose(img_file(idict), img_filepath(idict)); - img_file(idict) = NULL; - assert(img_jp2_ptr(idict) != NULL); - xfree(img_jp2_ptr(idict)); + /* if one of then is not NULL we already cleaned up */ + if (img_file(idict) != NULL) { + xfclose(img_file(idict), img_filepath(idict)); + img_file(idict) = NULL; + } + if (img_jp2_ptr(idict) != NULL) { + xfree(img_jp2_ptr(idict)); + } +} + +void flush_jp2_info(image_dict * idict) +{ + close_and_cleanup_jp2(idict); } -void read_jp2_info(image_dict * idict, img_readtype_e readtype) +void read_jp2_info(image_dict * idict) { boolean ihdr_found = false; hdr_struct hdr; uint64_t spos, epos; - assert(img_type(idict) == IMG_TYPE_JP2); + if (img_type(idict) != IMG_TYPE_JP2) { + normal_error("readjp2","conflicting image dictionary"); + } + if (img_file(idict) != NULL) { + normal_error("readjp2","image data already read"); + } img_totalpages(idict) = 1; img_pagenum(idict) = 1; img_xres(idict) = img_yres(idict) = 0; - assert(img_file(idict) == NULL); img_file(idict) = xfopen(img_filepath(idict), FOPEN_RBIN_MODE); - assert(img_jp2_ptr(idict) == NULL); img_jp2_ptr(idict) = xtalloc(1, jp2_img_struct); xfseek(img_file(idict), 0, SEEK_END, img_filepath(idict)); - img_jp2_ptr(idict)->length = - (int) xftell(img_file(idict), img_filepath(idict)); + img_jp2_ptr(idict)->length = (int) xftell(img_file(idict), img_filepath(idict)); xfseek(img_file(idict), 0, SEEK_SET, img_filepath(idict)); - - assert(sizeof(uint64_t) >= 8); + if (sizeof(uint64_t) < 8) { + normal_error("readjp2","size problem"); + } spos = epos = 0; - /* 1.5.1 JPEG 2000 Signature box */ hdr = read_boxhdr(idict); - assert(hdr.tbox == BOX_JP); /* has already been checked */ epos = spos + hdr.lbox; xfseek(img_file(idict), (long) epos, SEEK_SET, img_filepath(idict)); - /* 1.5.2 File Type box */ spos = epos; hdr = read_boxhdr(idict); - if (hdr.tbox != BOX_FTYP) - luatex_fail("reading JP2 image failed (missing ftyp box)"); + if (hdr.tbox != BOX_FTYP) { + normal_error("readjp2","missing ftyp box"); + } epos = spos + hdr.lbox; xfseek(img_file(idict), (long) epos, SEEK_SET, img_filepath(idict)); - while (!ihdr_found) { spos = epos; hdr = read_boxhdr(idict); @@ -233,14 +238,15 @@ void read_jp2_info(image_dict * idict, img_readtype_e readtype) break; case BOX_JP2C: if (!ihdr_found) - luatex_fail("reading JP2 image failed (no ihdr box found)"); + normal_error("readjp2","no ihdr box found"); break; default:; } xfseek(img_file(idict), (long) epos, SEEK_SET, img_filepath(idict)); } - if (readtype == IMG_CLOSEINBETWEEN) + if (! img_keepopen(idict)) { close_and_cleanup_jp2(idict); + } } static void reopen_jp2(image_dict * idict) @@ -250,19 +256,23 @@ static void reopen_jp2(image_dict * idict) height = img_ysize(idict); xres = img_xres(idict); yres = img_yres(idict); - read_jp2_info(idict, IMG_KEEPOPEN); + /* + we need to make sure that the file kept open + */ + img_keepopen(idict) = 1; + read_jp2_info(idict); if (width != img_xsize(idict) || height != img_ysize(idict) - || xres != img_xres(idict) || yres != img_yres(idict)) - luatex_fail("writejp2: image dimensions have changed"); + || xres != img_xres(idict) || yres != img_yres(idict)) { + normal_error("writejp2","image dimensions have changed"); + } } void write_jp2(PDF pdf, image_dict * idict) { long unsigned l; - assert(idict != NULL); - if (img_file(idict) == NULL) + if (img_file(idict) == NULL) { reopen_jp2(idict); - assert(img_jp2_ptr(idict) != NULL); + } pdf_begin_obj(pdf, img_objnum(idict), OBJSTM_NEVER); pdf_begin_dict(pdf); pdf_dict_add_name(pdf, "Type", "XObject"); @@ -279,8 +289,9 @@ void write_jp2(PDF pdf, image_dict * idict) l = (long unsigned int) img_jp2_ptr(idict)->length; xfseek(img_file(idict), 0, SEEK_SET, img_filepath(idict)); if (read_file_to_buf(pdf, img_file(idict), l) != l) - luatex_fail("writejp2: fread failed"); + normal_error("writejp2","fread failed"); pdf_end_stream(pdf); pdf_end_obj(pdf); + /* always */ close_and_cleanup_jp2(idict); } diff --git a/Build/source/texk/web2c/luatexdir/image/writejpg.h b/Build/source/texk/web2c/luatexdir/image/writejpg.h index 8ef290d4746..96bf961246f 100644 --- a/Build/source/texk/web2c/luatexdir/image/writejpg.h +++ b/Build/source/texk/web2c/luatexdir/image/writejpg.h @@ -18,13 +18,13 @@ You should have received a copy of the GNU General Public License along with LuaTeX; if not, see . */ - #ifndef WRITEJPG_H # define WRITEJPG_H # include "image.h" -void read_jpg_info(PDF, image_dict *, img_readtype_e); +void read_jpg_info(image_dict *); +void flush_jpg_info(image_dict *); void write_jpg(PDF, image_dict *); -#endif /* WRITEJPG_H */ +#endif diff --git a/Build/source/texk/web2c/luatexdir/image/writejpg.w b/Build/source/texk/web2c/luatexdir/image/writejpg.w index 7780f312922..07c51f5e1d0 100644 --- a/Build/source/texk/web2c/luatexdir/image/writejpg.w +++ b/Build/source/texk/web2c/luatexdir/image/writejpg.w @@ -20,87 +20,85 @@ @ @c - #include "ptexlib.h" #include #include "image/image.h" #include "image/writejpg.h" @ @c -#define JPG_GRAY 1 /* Gray color space, use /DeviceGray */ -#define JPG_RGB 3 /* RGB color space, use /DeviceRGB */ -#define JPG_CMYK 4 /* CMYK color space, use /DeviceCMYK */ +#define JPG_GRAY 1 /* Gray color space, use /DeviceGray */ +#define JPG_RGB 3 /* RGB color space, use /DeviceRGB */ +#define JPG_CMYK 4 /* CMYK color space, use /DeviceCMYK */ -typedef enum { /* JPEG marker codes */ - M_SOF0 = 0xc0, /* baseline DCT */ - M_SOF1 = 0xc1, /* extended sequential DCT */ - M_SOF2 = 0xc2, /* progressive DCT */ - M_SOF3 = 0xc3, /* lossless (sequential) */ +typedef enum { + M_SOF0 = 0xc0, /* baseline DCT */ + M_SOF1 = 0xc1, /* extended sequential DCT */ + M_SOF2 = 0xc2, /* progressive DCT */ + M_SOF3 = 0xc3, /* lossless (sequential) */ - M_SOF5 = 0xc5, /* differential sequential DCT */ - M_SOF6 = 0xc6, /* differential progressive DCT */ - M_SOF7 = 0xc7, /* differential lossless (sequential) */ + M_SOF5 = 0xc5, /* differential sequential DCT */ + M_SOF6 = 0xc6, /* differential progressive DCT */ + M_SOF7 = 0xc7, /* differential lossless (sequential) */ - M_JPG = 0xc8, /* reserved for JPEG extensions */ - M_SOF9 = 0xc9, /* extended sequential DCT */ - M_SOF10 = 0xca, /* progressive DCT */ - M_SOF11 = 0xcb, /* lossless (sequential) */ + M_JPG = 0xc8, /* reserved for JPEG extensions */ + M_SOF9 = 0xc9, /* extended sequential DCT */ + M_SOF10 = 0xca, /* progressive DCT */ + M_SOF11 = 0xcb, /* lossless (sequential) */ - M_SOF13 = 0xcd, /* differential sequential DCT */ - M_SOF14 = 0xce, /* differential progressive DCT */ - M_SOF15 = 0xcf, /* differential lossless (sequential) */ + M_SOF13 = 0xcd, /* differential sequential DCT */ + M_SOF14 = 0xce, /* differential progressive DCT */ + M_SOF15 = 0xcf, /* differential lossless (sequential) */ - M_DHT = 0xc4, /* define Huffman table(s) */ + M_DHT = 0xc4, /* define Huffman table(s) */ - M_DAC = 0xcc, /* define arithmetic conditioning table */ + M_DAC = 0xcc, /* define arithmetic conditioning table */ - M_RST0 = 0xd0, /* restart */ - M_RST1 = 0xd1, /* restart */ - M_RST2 = 0xd2, /* restart */ - M_RST3 = 0xd3, /* restart */ - M_RST4 = 0xd4, /* restart */ - M_RST5 = 0xd5, /* restart */ - M_RST6 = 0xd6, /* restart */ - M_RST7 = 0xd7, /* restart */ + M_RST0 = 0xd0, /* restart */ + M_RST1 = 0xd1, /* restart */ + M_RST2 = 0xd2, /* restart */ + M_RST3 = 0xd3, /* restart */ + M_RST4 = 0xd4, /* restart */ + M_RST5 = 0xd5, /* restart */ + M_RST6 = 0xd6, /* restart */ + M_RST7 = 0xd7, /* restart */ - M_SOI = 0xd8, /* start of image */ - M_EOI = 0xd9, /* end of image */ - M_SOS = 0xda, /* start of scan */ - M_DQT = 0xdb, /* define quantization tables */ - M_DNL = 0xdc, /* define number of lines */ - M_DRI = 0xdd, /* define restart interval */ - M_DHP = 0xde, /* define hierarchical progression */ - M_EXP = 0xdf, /* expand reference image(s) */ + M_SOI = 0xd8, /* start of image */ + M_EOI = 0xd9, /* end of image */ + M_SOS = 0xda, /* start of scan */ + M_DQT = 0xdb, /* define quantization tables */ + M_DNL = 0xdc, /* define number of lines */ + M_DRI = 0xdd, /* define restart interval */ + M_DHP = 0xde, /* define hierarchical progression */ + M_EXP = 0xdf, /* expand reference image(s) */ - M_APP0 = 0xe0, /* application marker, used for JFIF */ - M_APP1 = 0xe1, /* application marker */ - M_APP2 = 0xe2, /* application marker */ - M_APP3 = 0xe3, /* application marker */ - M_APP4 = 0xe4, /* application marker */ - M_APP5 = 0xe5, /* application marker */ - M_APP6 = 0xe6, /* application marker */ - M_APP7 = 0xe7, /* application marker */ - M_APP8 = 0xe8, /* application marker */ - M_APP9 = 0xe9, /* application marker */ - M_APP10 = 0xea, /* application marker */ - M_APP11 = 0xeb, /* application marker */ - M_APP12 = 0xec, /* application marker */ - M_APP13 = 0xed, /* application marker */ - M_APP14 = 0xee, /* application marker, used by Adobe */ - M_APP15 = 0xef, /* application marker */ + M_APP0 = 0xe0, /* application marker, used for JFIF */ + M_APP1 = 0xe1, /* application marker */ + M_APP2 = 0xe2, /* application marker */ + M_APP3 = 0xe3, /* application marker */ + M_APP4 = 0xe4, /* application marker */ + M_APP5 = 0xe5, /* application marker */ + M_APP6 = 0xe6, /* application marker */ + M_APP7 = 0xe7, /* application marker */ + M_APP8 = 0xe8, /* application marker */ + M_APP9 = 0xe9, /* application marker */ + M_APP10 = 0xea, /* application marker */ + M_APP11 = 0xeb, /* application marker */ + M_APP12 = 0xec, /* application marker */ + M_APP13 = 0xed, /* application marker */ + M_APP14 = 0xee, /* application marker, used by Adobe */ + M_APP15 = 0xef, /* application marker */ - M_JPG0 = 0xf0, /* reserved for JPEG extensions */ - M_JPG13 = 0xfd, /* reserved for JPEG extensions */ - M_COM = 0xfe, /* comment */ + M_JPG0 = 0xf0, /* reserved for JPEG extensions */ + M_JPG13 = 0xfd, /* reserved for JPEG extensions */ + M_COM = 0xfe, /* comment */ - M_TEM = 0x01, /* temporary use */ + M_TEM = 0x01, /* temporary use */ - M_ERROR = 0x100 /* dummy marker, internal use only */ + M_ERROR = 0x100 /* dummy marker, internal use only */ } JPEG_MARKER; @ @c -static unsigned char -myget_unsigned_byte (FILE *file) +static unsigned char myget_unsigned_byte (FILE *file) { int ch; ch = fgetc (file); @@ -108,8 +106,7 @@ myget_unsigned_byte (FILE *file) } @ @c -static unsigned short -myget_unsigned_pair (FILE *file) +static unsigned short myget_unsigned_pair (FILE *file) { unsigned short pair = myget_unsigned_byte(file); pair = (pair << 8) | myget_unsigned_byte(file); @@ -117,31 +114,30 @@ myget_unsigned_pair (FILE *file) } @ @c -static unsigned int -read_exif_bytes(unsigned char **p, int n, int b) +static unsigned int read_exif_bytes(unsigned char **p, int n, int b) { unsigned int rval = 0; unsigned char *pp = *p; if (b) { switch (n) { - case 4: - rval += *pp++; rval <<= 8; - rval += *pp++; rval <<= 8; - case 2: - rval += *pp++; rval <<= 8; - rval += *pp; - break; + case 4: + rval += *pp++; rval <<= 8; + rval += *pp++; rval <<= 8; + case 2: + rval += *pp++; rval <<= 8; + rval += *pp; + break; } } else { pp += n; switch (n) { - case 4: - rval += *--pp; rval <<= 8; - rval += *--pp; rval <<= 8; - case 2: - rval += *--pp; rval <<= 8; - rval += *--pp; - break; + case 4: + rval += *--pp; rval <<= 8; + rval += *--pp; rval <<= 8; + case 2: + rval += *--pp; rval <<= 8; + rval += *--pp; + break; } } *p += n; @@ -149,8 +145,7 @@ read_exif_bytes(unsigned char **p, int n, int b) } @ @c -static void -read_APP1_Exif (FILE *fp, unsigned short length, int *xx, int *yy) +static void read_APP1_Exif (FILE *fp, unsigned short length, int *xx, int *yy) { /* this doesn't save the data, just reads the tags we need */ /* based on info from http://www.exif.org/Exif2-2.PDF */ @@ -160,7 +155,7 @@ read_APP1_Exif (FILE *fp, unsigned short length, int *xx, int *yy) char bigendian; int i; int num_fields, tag, type; - int value = 0, num = 0, den = 0; /* silence uninitialized warnings */ + int value = 0, num = 0, den = 0; /* silence uninitialized warnings */ double xres = 72.0; double yres = 72.0; double res_unit = 1.0; @@ -190,133 +185,156 @@ read_APP1_Exif (FILE *fp, unsigned short length, int *xx, int *yy) type = read_exif_bytes(&p, 2, bigendian); read_exif_bytes(&p, 4, bigendian); switch (type) { - case 1: /* byte */ - value = *p++; - p += 3; - break; - case 3: /* short */ - value = read_exif_bytes(&p, 2, bigendian); - p += 2; - break; - case 4: /* long */ - case 9: /* slong */ - value = read_exif_bytes(&p, 4, bigendian); - break; - case 5: /* rational */ - case 10: /* srational */ - value = read_exif_bytes(&p, 4, bigendian); - rp = tiff_header + value; - num = read_exif_bytes(&rp, 4, bigendian); - den = read_exif_bytes(&rp, 4, bigendian); - break; - case 7: /* undefined */ - value = *p++; - p += 3; - break; - case 2: /* ascii */ - default: - p += 4; - break; - } + case 1: /* byte */ + value = *p++; + p += 3; + break; + case 3: /* short */ + value = read_exif_bytes(&p, 2, bigendian); + p += 2; + break; + case 4: /* long */ + case 9: /* slong */ + value = read_exif_bytes(&p, 4, bigendian); + break; + case 5: /* rational */ + case 10: /* srational */ + value = read_exif_bytes(&p, 4, bigendian); + rp = tiff_header + value; + num = read_exif_bytes(&rp, 4, bigendian); + den = read_exif_bytes(&rp, 4, bigendian); + break; + case 7: /* undefined */ + value = *p++; + p += 3; + break; + case 2: /* ascii */ + default: + p += 4; + break; + } switch (tag) { - case 282: /* x res */ - if (den != 0) - xres = num / den; - break; - case 283: /* y res */ - if (den != 0) - yres = num / den; - break; - case 296: /* res unit */ - switch (value) { - case 2: - res_unit = 1.0; + case 282: /* x res */ + if (den != 0) + xres = num / den; break; - case 3: - res_unit = 2.54; + case 283: /* y res */ + if (den != 0) + yres = num / den; break; - } + case 296: /* res unit */ + switch (value) { + case 2: + res_unit = 1.0; + break; + case 3: + res_unit = 2.54; + break; + } } } *xx = (int)(xres * res_unit); *yy = (int)(yres * res_unit); - err: free(buffer); return; } +/* + + Contrary to pdf where several parallel usage can happen (epdf, tex, lua) with + bitmaps we care less about keeping files open. So, we can keep files open in + the img lib but then they are closed after inclusion anyway. + +*/ + @ @c static void close_and_cleanup_jpg(image_dict * idict) { - assert(idict != NULL); - assert(img_file(idict) != NULL); - assert(img_filepath(idict) != NULL); - xfclose(img_file(idict), img_filepath(idict)); - img_file(idict) = NULL; - assert(img_jpg_ptr(idict) != NULL); - xfree(img_jpg_ptr(idict)); + /* if one of then is not NULL we already cleaned up */ + if (img_file(idict) != NULL) { + xfclose(img_file(idict), img_filepath(idict)); + img_file(idict) = NULL; + } + if (img_jpg_ptr(idict) != NULL) { + xfree(img_jpg_ptr(idict)); + } +} + +@ @c +void flush_jpg_info(image_dict * idict) +{ + close_and_cleanup_jpg(idict); } @ @c -void read_jpg_info(PDF pdf, image_dict * idict, img_readtype_e readtype) +void read_jpg_info(image_dict * idict) { int i, units = 0; unsigned short appmk, length; unsigned char jpg_id[] = "JFIF"; - assert(idict != NULL); - assert(img_type(idict) == IMG_TYPE_JPG); + if (img_type(idict) != IMG_TYPE_JPG) { + normal_error("readjpg","conflicting image dictionary"); + } + if (img_file(idict) != NULL) { + normal_error("readjpg","image data already read"); + } img_totalpages(idict) = 1; img_pagenum(idict) = 1; img_xres(idict) = img_yres(idict) = 0; - assert(img_file(idict) == NULL); img_file(idict) = xfopen(img_filepath(idict), FOPEN_RBIN_MODE); - assert(img_jpg_ptr(idict) == NULL); + if (img_file(idict) == NULL) { + normal_error("readjpg","unable to read image file"); + } img_jpg_ptr(idict) = xtalloc(1, jpg_img_struct); xfseek(img_file(idict), 0, SEEK_END, img_filepath(idict)); img_jpg_ptr(idict)->length = xftell(img_file(idict), img_filepath(idict)); xfseek(img_file(idict), 0, SEEK_SET, img_filepath(idict)); - if ((unsigned int) read2bytes(img_file(idict)) != 0xFFD8) - luatex_fail("reading JPEG image failed (no JPEG header found)"); + if ((unsigned int) read2bytes(img_file(idict)) != 0xFFD8) { + normal_error("readjpg","no header found"); + } /* currently JFIF and Exif files allow extracting |img_xres| and |img_yres| */ appmk = read2bytes(img_file(idict)); - if (appmk == 0xFFE0) { /* check for JFIF */ + if (appmk == 0xFFE0) { + /* check for JFIF */ (void) read2bytes(img_file(idict)); for (i = 0; i < 5; i++) { if (xgetc(img_file(idict)) != jpg_id[i]) break; } - if (i == 5) { /* it's JFIF */ + if (i == 5) { + /* it's JFIF */ (void) read2bytes(img_file(idict)); units = xgetc(img_file(idict)); img_xres(idict) = (int) read2bytes(img_file(idict)); img_yres(idict) = (int) read2bytes(img_file(idict)); switch (units) { case 1: + /* pixels per inch */ if ((img_xres(idict) == 1) || (img_yres(idict) == 1)) { - luatex_warn("The image specifies an unusual resolution of %ddpi by %ddpi. ", - img_xres(idict), img_yres(idict)); + formatted_warning("readjpg","unusual resolution of %ddpi by %ddpi", img_xres(idict), img_yres(idict)); } - break; /* pixels per inch */ + break; case 2: + /* pixels per cm */ img_xres(idict) = (int) ((double) img_xres(idict) * 2.54); img_yres(idict) = (int) ((double) img_yres(idict) * 2.54); - break; /* pixels per cm */ + break; default: img_xres(idict) = img_yres(idict) = 0; break; } } - /* if either xres or yres is 0 but the other isn't, - set it to the value of the other */ + /* if either xres or yres is 0 but the other isn't, set it to the value of the other */ if ((img_xres(idict) == 0) && (img_yres(idict) != 0)) { img_xres(idict) = img_yres(idict); } if ((img_yres(idict) == 0) && (img_xres(idict) != 0)) { img_yres(idict) = img_xres(idict); } - } else if (appmk == 0xFFE1) { /* check for Exif */ + } else if (appmk == 0xFFE1) { + /* check for Exif */ FILE *fp = img_file(idict); int xxres = 0; int yyres = 0; @@ -335,102 +353,111 @@ void read_jpg_info(PDF pdf, image_dict * idict, img_readtype_e readtype) } xfseek(img_file(idict), 0, SEEK_SET, img_filepath(idict)); while (1) { - if (feof(img_file(idict))) - luatex_fail("reading JPEG image failed (premature file end)"); - if (fgetc(img_file(idict)) != 0xFF) - luatex_fail("reading JPEG image failed (no marker found)"); + if (feof(img_file(idict))) { + normal_error("readjpg","premature file end"); + } else if (fgetc(img_file(idict)) != 0xFF) { + normal_error("readjpg","no marker found"); + } i = xgetc(img_file(idict)); switch (i) { - case M_SOF3: /* lossless */ - case M_SOF5: - case M_SOF6: - case M_SOF7: /* lossless */ - case M_SOF9: - case M_SOF10: - case M_SOF11: /* lossless */ - case M_SOF13: - case M_SOF14: - case M_SOF15: /* lossless */ - luatex_fail("unsupported type of compression (SOF_%d)", i - M_SOF0); - break; - case M_SOF2: - if (pdf->minor_version <= 2) - luatex_fail("cannot use progressive DCT with PDF-1.2"); - case M_SOF0: - case M_SOF1: - (void) read2bytes(img_file(idict)); /* read segment length */ - img_colordepth(idict) = xgetc(img_file(idict)); - img_ysize(idict) = (int) read2bytes(img_file(idict)); - img_xsize(idict) = (int) read2bytes(img_file(idict)); - img_jpg_color(idict) = xgetc(img_file(idict)); - xfseek(img_file(idict), 0, SEEK_SET, img_filepath(idict)); - switch (img_jpg_color(idict)) { - case JPG_GRAY: - img_procset(idict) |= PROCSET_IMAGE_B; + case M_SOF3: /* lossless */ + case M_SOF5: + case M_SOF6: + case M_SOF7: /* lossless */ + case M_SOF9: + case M_SOF10: + case M_SOF11: /* lossless */ + case M_SOF13: + case M_SOF14: + case M_SOF15: /* lossless */ + formatted_error("readjpg","unsupported compression SOF_%d", i - M_SOF0); break; - case JPG_RGB: - img_procset(idict) |= PROCSET_IMAGE_C; - break; - case JPG_CMYK: - img_procset(idict) |= PROCSET_IMAGE_C; + case M_SOF2: + if (img_pdfminorversion(idict) <= 2) { + normal_error("readjpg","progressive DCT with PDF-1.2 is not permitted"); + } + case M_SOF0: + case M_SOF1: + (void) read2bytes(img_file(idict)); /* read segment length */ + img_colordepth(idict) = xgetc(img_file(idict)); + img_ysize(idict) = (int) read2bytes(img_file(idict)); + img_xsize(idict) = (int) read2bytes(img_file(idict)); + img_jpg_color(idict) = xgetc(img_file(idict)); + xfseek(img_file(idict), 0, SEEK_SET, img_filepath(idict)); + switch (img_jpg_color(idict)) { + case JPG_GRAY: + img_procset(idict) |= PROCSET_IMAGE_B; + break; + case JPG_RGB: + img_procset(idict) |= PROCSET_IMAGE_C; + break; + case JPG_CMYK: + img_procset(idict) |= PROCSET_IMAGE_C; + break; + default: + formatted_error("readjpg","unsupported color space %i", (int) img_jpg_color(idict)); + } + /* + So we can optionally keep open a file in img. + */ + if (! img_keepopen(idict)) { + close_and_cleanup_jpg(idict); + } + return; + /* ignore markers without parameters */ + case M_SOI: + case M_EOI: + case M_TEM: + case M_RST0: + case M_RST1: + case M_RST2: + case M_RST3: + case M_RST4: + case M_RST5: + case M_RST6: + case M_RST7: break; default: - luatex_fail("Unsupported color space %i", - (int) img_jpg_color(idict)); - } - if (readtype == IMG_CLOSEINBETWEEN) - close_and_cleanup_jpg(idict); - return; - case M_SOI: /* ignore markers without parameters */ - case M_EOI: - case M_TEM: - case M_RST0: - case M_RST1: - case M_RST2: - case M_RST3: - case M_RST4: - case M_RST5: - case M_RST6: - case M_RST7: - break; - default: /* skip variable length markers */ - xfseek(img_file(idict), (int) read2bytes(img_file(idict)) - 2, - SEEK_CUR, img_filepath(idict)); - break; + /* skip variable length markers */ + xfseek(img_file(idict), (int) read2bytes(img_file(idict)) - 2, SEEK_CUR, img_filepath(idict)); + break; } } - assert(0); + normal_error("readjpg","unknown fatal error"); } @ @c -static void reopen_jpg(PDF pdf, image_dict * idict) +static void reopen_jpg(image_dict * idict) { - int width, height, xres, yres; - width = img_xsize(idict); - height = img_ysize(idict); - xres = img_xres(idict); - yres = img_yres(idict); - read_jpg_info(pdf, idict, IMG_KEEPOPEN); - if (width != img_xsize(idict) || height != img_ysize(idict) - || xres != img_xres(idict) || yres != img_yres(idict)) - luatex_fail("writejpg: image dimensions have changed"); + int width = img_xsize(idict); + int height = img_ysize(idict); + int xres = img_xres(idict); + int yres = img_yres(idict); + /* + we need to make sure that the file kept open + */ + img_keepopen(idict) = 1; + read_jpg_info(idict); + if (width != img_xsize(idict) || height != img_ysize(idict) || xres != img_xres(idict) || yres != img_yres(idict)) { + normal_error("writejpg","image dimensions have changed"); + } } @ @c void write_jpg(PDF pdf, image_dict * idict) { size_t l; - assert(idict != NULL); - if (img_file(idict) == NULL) - reopen_jpg(pdf, idict); - assert(img_jpg_ptr(idict) != NULL); + if (img_file(idict) == NULL) { + reopen_jpg(idict); + } pdf_begin_obj(pdf, img_objnum(idict), OBJSTM_NEVER); pdf_begin_dict(pdf); pdf_dict_add_name(pdf, "Type", "XObject"); pdf_dict_add_name(pdf, "Subtype", "Image"); pdf_dict_add_img_filename(pdf, idict); - if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0) + if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0) { pdf_printf(pdf, "\n%s\n", img_attr(idict)); + } pdf_dict_add_int(pdf, "Width", (int) img_xsize(idict)); pdf_dict_add_int(pdf, "Height", (int) img_ysize(idict)); pdf_dict_add_int(pdf, "BitsPerComponent", (int) img_colordepth(idict)); @@ -439,40 +466,40 @@ void write_jpg(PDF pdf, image_dict * idict) pdf_dict_add_ref(pdf, "ColorSpace", (int) img_colorspace(idict)); } else { switch (img_jpg_color(idict)) { - case JPG_GRAY: - pdf_dict_add_name(pdf, "ColorSpace", "DeviceGray"); - break; - case JPG_RGB: - pdf_dict_add_name(pdf, "ColorSpace", "DeviceRGB"); - break; - case JPG_CMYK: - pdf_dict_add_name(pdf, "ColorSpace", "DeviceCMYK"); - pdf_add_name(pdf, "Decode"); - pdf_begin_array(pdf); - pdf_add_int(pdf, 1); - pdf_add_int(pdf, 0); - pdf_add_int(pdf, 1); - pdf_add_int(pdf, 0); - pdf_add_int(pdf, 1); - pdf_add_int(pdf, 0); - pdf_add_int(pdf, 1); - pdf_add_int(pdf, 0); - pdf_end_array(pdf); - break; - default: - luatex_fail("Unsupported color space %i", - (int) img_jpg_color(idict)); + case JPG_GRAY: + pdf_dict_add_name(pdf, "ColorSpace", "DeviceGray"); + break; + case JPG_RGB: + pdf_dict_add_name(pdf, "ColorSpace", "DeviceRGB"); + break; + case JPG_CMYK: + pdf_dict_add_name(pdf, "ColorSpace", "DeviceCMYK"); + pdf_add_name(pdf, "Decode"); + pdf_begin_array(pdf); + pdf_add_int(pdf, 1); + pdf_add_int(pdf, 0); + pdf_add_int(pdf, 1); + pdf_add_int(pdf, 0); + pdf_add_int(pdf, 1); + pdf_add_int(pdf, 0); + pdf_add_int(pdf, 1); + pdf_add_int(pdf, 0); + pdf_end_array(pdf); + break; + default: + formatted_error("writejpg","unsupported JPEG color space %i", (int) img_jpg_color(idict)); } } pdf_dict_add_name(pdf, "Filter", "DCTDecode"); pdf_end_dict(pdf); pdf_begin_stream(pdf); - assert(pdf->zip_write_state == NO_ZIP); l = (size_t) img_jpg_ptr(idict)->length; xfseek(img_file(idict), 0, SEEK_SET, img_filepath(idict)); - if (read_file_to_buf(pdf, img_file(idict), l) != l) - luatex_fail("writejpg: fread failed"); + if (read_file_to_buf(pdf, img_file(idict), l) != l) { + normal_error("writejpg","fread failed"); + } pdf_end_stream(pdf); pdf_end_obj(pdf); + /* always */ close_and_cleanup_jpg(idict); } diff --git a/Build/source/texk/web2c/luatexdir/image/writepng.h b/Build/source/texk/web2c/luatexdir/image/writepng.h index 4dd425c0405..2af2a3fa2fb 100644 --- a/Build/source/texk/web2c/luatexdir/image/writepng.h +++ b/Build/source/texk/web2c/luatexdir/image/writepng.h @@ -18,14 +18,15 @@ You should have received a copy of the GNU General Public License along with LuaTeX; if not, see . */ - #ifndef WRITEPNG_H # define WRITEPNG_H # include "image.h" -void read_png_info(image_dict *, img_readtype_e); +void read_png_info(image_dict *); +void flush_png_info(image_dict *); + void write_additional_png_objects(PDF); void write_png(PDF, image_dict *); -#endif /* WRITEPNG_H */ +#endif diff --git a/Build/source/texk/web2c/luatexdir/image/writepng.w b/Build/source/texk/web2c/luatexdir/image/writepng.w index 40f8e0e2635..412000c427f 100644 --- a/Build/source/texk/web2c/luatexdir/image/writepng.w +++ b/Build/source/texk/web2c/luatexdir/image/writepng.w @@ -20,7 +20,6 @@ @ @c - #include "ptexlib.h" #include #include "image/image.h" @@ -31,45 +30,55 @@ static int transparent_page_group = -1; static void close_and_cleanup_png(image_dict * idict) { - assert(idict != NULL); - assert(img_file(idict) != NULL); - assert(img_filepath(idict) != NULL); - xfclose(img_file(idict), img_filepath(idict)); - img_file(idict) = NULL; - assert(img_png_ptr(idict) != NULL); - png_destroy_read_struct(&(img_png_png_ptr(idict)), - &(img_png_info_ptr(idict)), NULL); - xfree(img_png_ptr(idict)); + /* if one of then is not NULL we already cleaned up */ + if (img_file(idict) != NULL) { + xfclose(img_file(idict), img_filepath(idict)); + img_file(idict) = NULL; + } + if (img_png_ptr(idict) != NULL) { + png_destroy_read_struct(&(img_png_png_ptr(idict)), &(img_png_info_ptr(idict)), NULL); + xfree(img_png_ptr(idict)); + } +} + +@ @c +void flush_png_info(image_dict * idict) +{ + close_and_cleanup_png(idict); } @ @c static void warn(png_structp png_ptr, png_const_charp msg) { - (void)png_ptr; (void)msg; /* Make compiler happy */ + (void)png_ptr; (void)msg; /* Make compiler happy */ } -void read_png_info(image_dict * idict, img_readtype_e readtype) +void read_png_info(image_dict * idict) { png_structp png_p; png_infop info_p; - assert(idict != NULL); - assert(img_type(idict) == IMG_TYPE_PNG); + if (img_type(idict) != IMG_TYPE_PNG) { + normal_error("readpng","conflicting image dictionary"); + } + if (img_file(idict) != NULL) { + normal_error("readpng","image data already read"); + } img_totalpages(idict) = 1; img_pagenum(idict) = 1; img_xres(idict) = img_yres(idict) = 0; - assert(img_file(idict) == NULL); img_file(idict) = xfopen(img_filepath(idict), FOPEN_RBIN_MODE); - assert(img_png_ptr(idict) == NULL); img_png_ptr(idict) = xtalloc(1, png_img_struct); - if ((png_p = png_create_read_struct(PNG_LIBPNG_VER_STRING, - NULL, NULL, warn)) == NULL) - luatex_fail("libpng: png_create_read_struct() failed"); + if ((png_p = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, warn)) == NULL) { + normal_error("readpng","png_create_read_struct() failed"); + } img_png_png_ptr(idict) = png_p; - if ((info_p = png_create_info_struct(png_p)) == NULL) - luatex_fail("libpng: png_create_info_struct() failed"); + if ((info_p = png_create_info_struct(png_p)) == NULL) { + normal_error("readpng","png_create_info_struct() failed"); + } img_png_info_ptr(idict) = info_p; - if (setjmp(png_jmpbuf(png_p))) - luatex_fail("libpng: internal error"); + if (setjmp(png_jmpbuf(png_p))) { + normal_error("readpng","internal error"); + } #if PNG_LIBPNG_VER >= 10603 /* ignore possibly incorrect CMF bytes */ png_set_option(png_p, PNG_MAXIMUM_INFLATE_WINDOW, PNG_OPTION_ON); @@ -80,10 +89,8 @@ void read_png_info(image_dict * idict, img_readtype_e readtype) img_xsize(idict) = (int) png_get_image_width(png_p, info_p); img_ysize(idict) = (int) png_get_image_height(png_p, info_p); if (png_get_valid(png_p, info_p, PNG_INFO_pHYs)) { - img_xres(idict) = - round(0.0254 * (double) png_get_x_pixels_per_meter(png_p, info_p)); - img_yres(idict) = - round(0.0254 * (double) png_get_y_pixels_per_meter(png_p, info_p)); + img_xres(idict) = round(0.0254 * (double) png_get_x_pixels_per_meter(png_p, info_p)); + img_yres(idict) = round(0.0254 * (double) png_get_y_pixels_per_meter(png_p, info_p)); } switch (png_get_color_type(png_p, info_p)) { case PNG_COLOR_TYPE_PALETTE: @@ -98,12 +105,15 @@ void read_png_info(image_dict * idict, img_readtype_e readtype) img_procset(idict) |= PROCSET_IMAGE_C; break; default: - luatex_fail("unsupported type of color_type <%i>", - (int) png_get_color_type(png_p, info_p)); + formatted_error("readpng","unsupported type of color_type '%i'",(int) png_get_color_type(png_p, info_p)); } img_colordepth(idict) = png_get_bit_depth(png_p, info_p); - if (readtype == IMG_CLOSEINBETWEEN) + /* + So we can optionally keep open a file in img. + */ + if (! img_keepopen(idict)) { close_and_cleanup_png(idict); + } } @ @c @@ -164,8 +174,7 @@ void read_png_info(image_dict * idict, img_readtype_e readtype) } @ @c -static void write_palette_streamobj(PDF pdf, int palette_objnum, - png_colorp palette, int num_palette) +static void write_palette_streamobj(PDF pdf, int palette_objnum, png_colorp palette, int num_palette) { int i; if (palette_objnum == 0) @@ -187,8 +196,7 @@ static void write_palette_streamobj(PDF pdf, int palette_objnum, } @ @c -static void write_smask_streamobj(PDF pdf, image_dict * idict, int smask_objnum, - png_bytep smask, int smask_size) +static void write_smask_streamobj(PDF pdf, image_dict * idict, int smask_objnum, png_bytep smask, int smask_size) { int i; png_structp png_p = img_png_png_ptr(idict); @@ -235,13 +243,13 @@ static void write_png_gray(PDF pdf, image_dict * idict) write_noninterlaced(write_simple_pixel(r)); xfree(row); } else { - if (png_get_image_height(png_p, info_p) * - png_get_rowbytes(png_p, info_p) >= 10240000L) - luatex_warn - ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)"); + if (png_get_image_height(png_p, info_p) * png_get_rowbytes(png_p, info_p) >= 10240000L) { + formatted_warning("pngwrite","large interlaced bitmap might cause out of memory"); + } rows = xtalloc(png_get_image_height(png_p, info_p), png_bytep); - for (i = 0; i < (int) png_get_image_height(png_p, info_p); i++) + for (i = 0; i < (int) png_get_image_height(png_p, info_p); i++) { rows[i] = xtalloc(png_get_rowbytes(png_p, info_p), png_byte); + } png_read_image(png_p, rows); write_interlaced(write_simple_pixel(row)); xfree(rows); @@ -264,33 +272,29 @@ static void write_png_gray_alpha(PDF pdf, image_dict * idict) int smask_size = 0; smask_objnum = pdf_create_obj(pdf, obj_type_others, 0); pdf_dict_add_ref(pdf, "SMask", (int) smask_objnum); - smask_size = - (int) ((png_get_rowbytes(png_p, info_p) / 2) * - png_get_image_height(png_p, info_p)); + smask_size = (int) ((png_get_rowbytes(png_p, info_p) / 2) * png_get_image_height(png_p, info_p)); smask = xtalloc((unsigned) smask_size, png_byte); pdf_dict_add_streaminfo(pdf); pdf_end_dict(pdf); pdf_begin_stream(pdf); if (png_get_interlace_type(png_p, info_p) == PNG_INTERLACE_NONE) { row = xtalloc(png_get_rowbytes(png_p, info_p), png_byte); - if ((png_get_bit_depth(png_p, info_p) == 16) - && (pdf->image_hicolor != 0)) { + if ((png_get_bit_depth(png_p, info_p) == 16) && (pdf->image_hicolor != 0)) { write_noninterlaced(write_gray_pixel_16(r)); } else { write_noninterlaced(write_gray_pixel_8(r)); } xfree(row); } else { - if (png_get_image_height(png_p, info_p) * - png_get_rowbytes(png_p, info_p) >= 10240000L) - luatex_warn - ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)"); + if (png_get_image_height(png_p, info_p) * png_get_rowbytes(png_p, info_p) >= 10240000L) { + formatted_warning("pngwrite","large interlaced bitmap might cause out of memory"); + } rows = xtalloc(png_get_image_height(png_p, info_p), png_bytep); - for (i = 0; i < (int) png_get_image_height(png_p, info_p); i++) + for (i = 0; i < (int) png_get_image_height(png_p, info_p); i++) { rows[i] = xtalloc(png_get_rowbytes(png_p, info_p), png_byte); + } png_read_image(png_p, rows); - if ((png_get_bit_depth(png_p, info_p) == 16) - && (pdf->image_hicolor != 0)) { + if ((png_get_bit_depth(png_p, info_p) == 16) && (pdf->image_hicolor != 0)) { write_interlaced(write_gray_pixel_16(row)); } else { write_interlaced(write_gray_pixel_8(row)); @@ -317,33 +321,29 @@ static void write_png_rgb_alpha(PDF pdf, image_dict * idict) int smask_size = 0; smask_objnum = pdf_create_obj(pdf, obj_type_others, 0); pdf_dict_add_ref(pdf, "SMask", (int) smask_objnum); - smask_size = - (int) ((png_get_rowbytes(png_p, info_p) / 4) * - png_get_image_height(png_p, info_p)); + smask_size = (int) ((png_get_rowbytes(png_p, info_p) / 4) * png_get_image_height(png_p, info_p)); smask = xtalloc((unsigned) smask_size, png_byte); pdf_dict_add_streaminfo(pdf); pdf_end_dict(pdf); pdf_begin_stream(pdf); if (png_get_interlace_type(png_p, info_p) == PNG_INTERLACE_NONE) { row = xtalloc(png_get_rowbytes(png_p, info_p), png_byte); - if ((png_get_bit_depth(png_p, info_p) == 16) - && (pdf->image_hicolor != 0)) { + if ((png_get_bit_depth(png_p, info_p) == 16) && (pdf->image_hicolor != 0)) { write_noninterlaced(write_rgb_pixel_16(r)); } else { write_noninterlaced(write_rgb_pixel_8(r)); } xfree(row); } else { - if (png_get_image_height(png_p, info_p) * - png_get_rowbytes(png_p, info_p) >= 10240000L) - luatex_warn - ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)"); + if (png_get_image_height(png_p, info_p) * png_get_rowbytes(png_p, info_p) >= 10240000L) { + formatted_warning("pngwrite","large interlaced bitmap might cause out of memory"); + } rows = xtalloc(png_get_image_height(png_p, info_p), png_bytep); - for (i = 0; i < (int) png_get_image_height(png_p, info_p); i++) + for (i = 0; i < (int) png_get_image_height(png_p, info_p); i++) { rows[i] = xtalloc(png_get_rowbytes(png_p, info_p), png_byte); + } png_read_image(png_p, rows); - if ((png_get_bit_depth(png_p, info_p) == 16) - && (pdf->image_hicolor != 0)) { + if ((png_get_bit_depth(png_p, info_p) == 16) && (pdf->image_hicolor != 0)) { write_interlaced(write_rgb_pixel_16(row)); } else { write_interlaced(write_rgb_pixel_8(row)); @@ -373,8 +373,9 @@ the ``PNG Copy'' function must be skipped; therefore the lengthy tests. static int spng_getint(FILE * f) { unsigned char buf[4]; - if (fread(buf, 1, 4, f) != 4) - luatex_fail("writepng: reading chunk type failed"); + if (fread(buf, 1, 4, f) != 4) { + normal_error("writepng", "reading chunk type failed"); + } return ((((((int) buf[0] << 8) + buf[1]) << 8) + buf[2]) << 8) + buf[3]; } @@ -395,7 +396,7 @@ static void copy_png(PDF pdf, image_dict * idict) f = (FILE *) png_get_io_ptr(png_p); /* 1st pass to find overall stream /Length */ if (fseek(f, 8, SEEK_SET) != 0) - luatex_fail("writepng: fseek in PNG file failed (1)"); + normal_error("writepng", "fseek in file failed"); do { len = spng_getint(f); type = spng_getint(f); @@ -406,49 +407,52 @@ static void copy_png(PDF pdf, image_dict * idict) case SPNG_CHUNK_IDAT: streamlength += len; default: - if (fseek(f, len + 4, SEEK_CUR) != 0) - luatex_fail("writepng: fseek in PNG file failed (2)"); + if (fseek(f, len + 4, SEEK_CUR) != 0) { + normal_error("writepng", "fseek in file failed"); + } } } while (endflag == false); pdf_dict_add_int(pdf, "Length", streamlength); pdf_dict_add_name(pdf, "Filter", "FlateDecode"); pdf_add_name(pdf, "DecodeParms"); pdf_begin_dict(pdf); - pdf_dict_add_int(pdf, "Colors", - png_get_color_type(png_p, - info_p) == PNG_COLOR_TYPE_RGB ? 3 : 1); + pdf_dict_add_int(pdf, "Colors", png_get_color_type(png_p,info_p) == PNG_COLOR_TYPE_RGB ? 3 : 1); pdf_dict_add_int(pdf, "Columns", png_get_image_width(png_p, info_p)); pdf_dict_add_int(pdf, "BitsPerComponent", png_get_bit_depth(png_p, info_p)); pdf_dict_add_int(pdf, "Predictor", 10); pdf_end_dict(pdf); pdf_end_dict(pdf); pdf_begin_stream(pdf); - assert(pdf->zip_write_state == NO_ZIP); /* the PNG stream is already compressed */ + assert(pdf->zip_write_state == NO_ZIP); /* the PNG stream is already compressed */ /* 2nd pass to copy data */ endflag = false; if (fseek(f, 8, SEEK_SET) != 0) - luatex_fail("writepng: fseek in PNG file failed (3)"); + normal_error("writepng", "fseek in file failed"); do { len = spng_getint(f); type = spng_getint(f); switch (type) { - case SPNG_CHUNK_IDAT: /* do copy */ - if (idat == 2) - luatex_fail("writepng: IDAT chunk sequence broken"); + case SPNG_CHUNK_IDAT: + /* do copy */ + if (idat == 2) { + normal_error("writepng", "IDAT chunk sequence broken"); + } idat = 1; - if (read_file_to_buf(pdf, f, len) != len) - luatex_fail("writepng: fread failed"); - if (fseek(f, 4, SEEK_CUR) != 0) - luatex_fail("writepng: fseek in PNG file failed (4)"); + if (read_file_to_buf(pdf, f, len) != len) { + normal_error("writepng", "fread failed"); + } else if (fseek(f, 4, SEEK_CUR) != 0) { + normal_error("writepng", "fseek in file failed"); + } break; - case SPNG_CHUNK_IEND: /* done */ + case SPNG_CHUNK_IEND: + /* done */ endflag = true; break; default: if (idat == 1) idat = 2; if (fseek(f, len + 4, SEEK_CUR) != 0) - luatex_fail("writepng: fseek in PNG file failed (5)"); + normal_error("writepng", "fseek in file failed"); } } while (endflag == false); pdf_end_stream(pdf); @@ -463,10 +467,14 @@ static void reopen_png(image_dict * idict) height = img_ysize(idict); xres = img_xres(idict); yres = img_yres(idict); - read_png_info(idict, IMG_KEEPOPEN); - if (width != img_xsize(idict) || height != img_ysize(idict) - || xres != img_xres(idict) || yres != img_yres(idict)) - luatex_fail("writepng: image dimensions have changed"); + /* + we need to ake sure that the file kept open + */ + img_keepopen(idict) = 1; + read_png_info(idict); + if (width != img_xsize(idict) || height != img_ysize(idict) || xres != img_xres(idict) || yres != img_yres(idict)) { + normal_error("writepng", "image dimensions have changed"); + } } @ @c @@ -526,53 +534,51 @@ void write_png(PDF pdf, image_dict * idict) /* reset structure */ (void) png_set_interlace_handling(png_p); png_read_update_info(png_p, info_p); - pdf_begin_obj(pdf, img_objnum(idict), OBJSTM_NEVER); pdf_begin_dict(pdf); pdf_dict_add_name(pdf, "Type", "XObject"); pdf_dict_add_name(pdf, "Subtype", "Image"); pdf_dict_add_img_filename(pdf, idict); - if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0) + if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0) { pdf_printf(pdf, "\n%s\n", img_attr(idict)); + } pdf_dict_add_int(pdf, "Width", (int) png_get_image_width(png_p, info_p)); pdf_dict_add_int(pdf, "Height", (int) png_get_image_height(png_p, info_p)); - pdf_dict_add_int(pdf, "BitsPerComponent", - (int) png_get_bit_depth(png_p, info_p)); + pdf_dict_add_int(pdf, "BitsPerComponent", (int) png_get_bit_depth(png_p, info_p)); if (img_colorspace(idict) != 0) { pdf_dict_add_ref(pdf, "ColorSpace", (int) img_colorspace(idict)); } else { switch (png_get_color_type(png_p, info_p)) { - case PNG_COLOR_TYPE_PALETTE: - png_get_PLTE(png_p, info_p, &palette, &num_palette); - palette_objnum = pdf_create_obj(pdf, obj_type_others, 0); - pdf_add_name(pdf, "ColorSpace"); - pdf_begin_array(pdf); - pdf_add_name(pdf, "Indexed"); - pdf_add_name(pdf, "DeviceRGB"); /* base; PDFRef. 4.5.5 */ - pdf_add_int(pdf, (int) (num_palette - 1)); /* hival */ - pdf_add_ref(pdf, (int) palette_objnum); /* lookup */ - pdf_end_array(pdf); - break; - case PNG_COLOR_TYPE_GRAY: - case PNG_COLOR_TYPE_GRAY_ALPHA: - pdf_dict_add_name(pdf, "ColorSpace", "DeviceGray"); - break; - case PNG_COLOR_TYPE_RGB: - case PNG_COLOR_TYPE_RGB_ALPHA: - pdf_dict_add_name(pdf, "ColorSpace", "DeviceRGB"); - break; - default: - luatex_fail("unsupported type of color_type <%i>", - png_get_color_type(png_p, info_p)); + case PNG_COLOR_TYPE_PALETTE: + png_get_PLTE(png_p, info_p, &palette, &num_palette); + palette_objnum = pdf_create_obj(pdf, obj_type_others, 0); + pdf_add_name(pdf, "ColorSpace"); + pdf_begin_array(pdf); + pdf_add_name(pdf, "Indexed"); + pdf_add_name(pdf, "DeviceRGB"); /* base; PDFRef. 4.5.5 */ + pdf_add_int(pdf, (int) (num_palette - 1)); /* hival */ + pdf_add_ref(pdf, (int) palette_objnum); /* lookup */ + pdf_end_array(pdf); + break; + case PNG_COLOR_TYPE_GRAY: + case PNG_COLOR_TYPE_GRAY_ALPHA: + pdf_dict_add_name(pdf, "ColorSpace", "DeviceGray"); + break; + case PNG_COLOR_TYPE_RGB: + case PNG_COLOR_TYPE_RGB_ALPHA: + pdf_dict_add_name(pdf, "ColorSpace", "DeviceRGB"); + break; + default: + formatted_error("writepng", "unsupported color_type '%i'", png_get_color_type(png_p, info_p)); } } - if (png_copy && pdf->minor_version > 1 + if (png_copy + && pdf->minor_version > 1 && png_get_interlace_type(png_p, info_p) == PNG_INTERLACE_NONE && (png_get_color_type(png_p, info_p) == PNG_COLOR_TYPE_GRAY - || png_get_color_type(png_p, info_p) == PNG_COLOR_TYPE_RGB) + || png_get_color_type(png_p, info_p) == PNG_COLOR_TYPE_RGB) && !pdf->image_apply_gamma - && (!png_get_valid(png_p, info_p, PNG_INFO_gAMA) - || int_file_gamma == PNG_FP_1) + && (!png_get_valid(png_p, info_p, PNG_INFO_gAMA) || int_file_gamma == PNG_FP_1) && !png_get_valid(png_p, info_p, PNG_INFO_cHRM) && !png_get_valid(png_p, info_p, PNG_INFO_iCCP) && !png_get_valid(png_p, info_p, PNG_INFO_sBIT) @@ -583,64 +589,63 @@ void write_png(PDF pdf, image_dict * idict) && !png_get_valid(png_p, info_p, PNG_INFO_sPLT)) { copy_png(pdf, idict); } else { - if (0) { - tex_printf(" *** PNG copy skipped because: "); + if (img_errorlevel(idict) > 1) { if (!png_copy) - tex_printf("!png_copy "); + normal_warning("pngcopy","failed"); if (!(pdf->minor_version > 1)) - tex_printf("minorversion=%d ", pdf->minor_version); + formatted_warning("pngcopy","skipped because minorversion is '%d'", pdf->minor_version); if (!(png_get_interlace_type(png_p, info_p) == PNG_INTERLACE_NONE)) - tex_printf("interlaced "); + normal_warning("pngcopy","skipped because of interlacing"); if (!((png_get_color_type(png_p, info_p) == PNG_COLOR_TYPE_GRAY) - || (png_get_color_type(png_p, info_p) == PNG_COLOR_TYPE_RGB))) - tex_printf("colortype "); + || (png_get_color_type(png_p, info_p) == PNG_COLOR_TYPE_RGB))) + normal_warning("pngcopy","skipped because of colortype"); if (pdf->image_apply_gamma) - tex_printf("apply gamma "); - if (!(!png_get_valid(png_p, info_p, PNG_INFO_gAMA) - || int_file_gamma == PNG_FP_1)) - tex_printf("gamma "); + normal_warning("pngcopy","skipped because of gamma (1)"); + if (!(!png_get_valid(png_p, info_p, PNG_INFO_gAMA) || int_file_gamma == PNG_FP_1)) + normal_warning("pngcopy","skipped because of gamma (2)"); if (png_get_valid(png_p, info_p, PNG_INFO_cHRM)) - tex_printf("cHRM "); + normal_warning("pngcopy","skipped because of cHRM"); if (png_get_valid(png_p, info_p, PNG_INFO_iCCP)) - tex_printf("iCCP "); + normal_warning("pngcopy","skipped because of iCCP"); if (png_get_valid(png_p, info_p, PNG_INFO_sBIT)) - tex_printf("sBIT "); + normal_warning("pngcopy","skipped because of sBIT"); if (png_get_valid(png_p, info_p, PNG_INFO_sRGB)) - tex_printf("sRGB "); + normal_warning("pngcopy","skipped because of sRGB"); if (png_get_valid(png_p, info_p, PNG_INFO_bKGD)) - tex_printf("bKGD "); + normal_warning("pngcopy","skipped because of bKGD"); if (png_get_valid(png_p, info_p, PNG_INFO_hIST)) - tex_printf("hIST "); + normal_warning("pngcopy","skipped because of hIST"); if (png_get_valid(png_p, info_p, PNG_INFO_tRNS)) - tex_printf("tRNS "); + normal_warning("pngcopy","skipped because of tRNS"); if (png_get_valid(png_p, info_p, PNG_INFO_sPLT)) - tex_printf("sPLT "); + normal_warning("pngcopy","skipped because of sPLT"); } switch (png_get_color_type(png_p, info_p)) { - case PNG_COLOR_TYPE_PALETTE: - case PNG_COLOR_TYPE_GRAY: - case PNG_COLOR_TYPE_RGB: - write_png_gray(pdf, idict); - break; - case PNG_COLOR_TYPE_GRAY_ALPHA: - if (pdf->minor_version >= 4) { - write_png_gray_alpha(pdf, idict); - last_png_needs_page_group = true; - } else + case PNG_COLOR_TYPE_PALETTE: + case PNG_COLOR_TYPE_GRAY: + case PNG_COLOR_TYPE_RGB: write_png_gray(pdf, idict); - break; - case PNG_COLOR_TYPE_RGB_ALPHA: - if (pdf->minor_version >= 4) { - write_png_rgb_alpha(pdf, idict); - last_png_needs_page_group = true; - } else - write_png_gray(pdf, idict); - break; - default: - assert(0); + break; + case PNG_COLOR_TYPE_GRAY_ALPHA: + if (pdf->minor_version >= 4) { + write_png_gray_alpha(pdf, idict); + last_png_needs_page_group = true; + } else + write_png_gray(pdf, idict); + break; + case PNG_COLOR_TYPE_RGB_ALPHA: + if (pdf->minor_version >= 4) { + write_png_rgb_alpha(pdf, idict); + last_png_needs_page_group = true; + } else + write_png_gray(pdf, idict); + break; + default: + assert(0); } } write_palette_streamobj(pdf, palette_objnum, palette, num_palette); + /* always */ close_and_cleanup_png(idict); } @@ -649,13 +654,15 @@ static boolean transparent_page_group_was_written = false; @ Called after the xobject generated by |write_png| has been finished; used to write out additional objects + @c void write_additional_png_objects(PDF pdf) { (void) pdf; (void) transparent_page_group; (void) transparent_page_group_was_written; - return; /* this interferes with current macro-based usage and cannot be configured */ + return; + /* this interferes with current macro-based usage and cannot be configured */ #if 0 if (last_png_needs_page_group) { if (!transparent_page_group_was_written && transparent_page_group > 1) { diff --git a/Build/source/texk/web2c/luatexdir/lang/texlang.h b/Build/source/texk/web2c/luatexdir/lang/texlang.h index 9a8534b3996..0920dc9f740 100644 --- a/Build/source/texk/web2c/luatexdir/lang/texlang.h +++ b/Build/source/texk/web2c/luatexdir/lang/texlang.h @@ -53,7 +53,7 @@ extern int hyphenate_string(struct tex_language *lang, char *w, char **ret); extern void new_hyphenation(halfword h, halfword t); extern void clear_patterns(struct tex_language *lang); extern void clear_hyphenation(struct tex_language *lang); -extern const char *clean_hyphenation(const char *buffer, char **cleaned); +extern const char *clean_hyphenation(int id, const char *buffer, char **cleaned); extern void hnj_hyphenation(halfword head, halfword tail); extern void set_pre_hyphen_char(int lan, int val); @@ -82,6 +82,7 @@ extern void new_post_hyphen_char(void); extern void new_pre_exhyphen_char(void); extern void new_post_exhyphen_char(void); extern void new_hyphenation_min(void); +extern void new_hj_code(void); #endif diff --git a/Build/source/texk/web2c/luatexdir/lang/texlang.w b/Build/source/texk/web2c/luatexdir/lang/texlang.w index 4e9282e5f3f..170770bfeed 100644 --- a/Build/source/texk/web2c/luatexdir/lang/texlang.w +++ b/Build/source/texk/web2c/luatexdir/lang/texlang.w @@ -19,7 +19,6 @@ @ @c - #include "ptexlib.h" #include #include "lua/luatex-api.h" @@ -62,6 +61,9 @@ struct tex_language *new_language(int n) lang->pre_exhyphen_char = 0; lang->post_exhyphen_char = 0; lang->hyphenation_min = -1; + if (int_par(saving_hyph_codes_code)) { + hj_codes_from_lc_codes(l); /* for now, we might just use specific value for whatever task */ + } return lang; } else { return NULL; @@ -96,7 +98,6 @@ void set_post_hyphen_char(int n, int v) l->post_hyphen_char = (int) v; } - void set_pre_exhyphen_char(int n, int v) { struct tex_language *l = get_language((int) n); @@ -111,7 +112,6 @@ void set_post_exhyphen_char(int n, int v) l->post_exhyphen_char = (int) v; } - int get_pre_hyphen_char(int n) { struct tex_language *l = get_language((int) n); @@ -128,7 +128,6 @@ int get_post_hyphen_char(int n) return (int) l->post_hyphen_char; } - int get_pre_exhyphen_char(int n) { struct tex_language *l = get_language((int) n); @@ -145,7 +144,6 @@ int get_post_exhyphen_char(int n) return (int) l->post_exhyphen_char; } - void set_hyphenation_min(int n, int v) { struct tex_language *l = get_language((int) n); @@ -161,7 +159,6 @@ int get_hyphenation_min(int n) return (int) l->hyphenation_min; } -@ @c void load_patterns(struct tex_language *lang, const unsigned char *buff) { if (lang == NULL || buff == NULL || strlen((const char *) buff) == 0) @@ -187,18 +184,23 @@ void load_tex_patterns(int curlang, halfword head) load_patterns(get_language(curlang), (unsigned char *) s); } - @ @c -#define STORE_CHAR(x) do { \ - unsigned xx = get_lc_code(x); \ - if (!xx) xx = x; \ - uindex = uni2string(uindex, xx); \ - } while (0) +#define STORE_CHAR(l,x) do { \ + unsigned xx = get_hj_code(l,x); \ + if (!xx) { \ + xx = x; \ + } \ + uindex = uni2string(uindex, xx); \ +} while (0) -/* Cleans one word which is returned in |cleaned|, - returns the new offset into |buffer| */ +#define hj_char_code(l,c) \ + (l>=0 && get_hj_code(l,c)) -const char *clean_hyphenation(const char *buff, char **cleaned) +@ Cleans one word which is returned in |cleaned|, returns the new offset +into |buffer| + +@c +const char *clean_hyphenation(int id, const char *buff, char **cleaned) { int items = 0; unsigned char word[MAX_WORD_LEN + 1]; /* work buffer for bytes */ @@ -209,8 +211,8 @@ const char *clean_hyphenation(const char *buff, char **cleaned) const char *s = buff; while (*s && !isspace((unsigned char)*s)) { - word[i++] = (unsigned)*s; - s++; + word[i++] = (unsigned)*s; + s++; if ((s-buff)>MAX_WORD_LEN) { /* todo: this is too strict, should count unicode, not bytes */ *cleaned = NULL; @@ -228,7 +230,7 @@ const char *clean_hyphenation(const char *buff, char **cleaned) u = uword[i++]; if (u == '-') { /* skip */ } else if (u == '=') { - STORE_CHAR('-'); + STORE_CHAR(id,'-'); } else if (u == '{') { u = uword[i++]; items = 0; @@ -250,7 +252,7 @@ const char *clean_hyphenation(const char *buff, char **cleaned) u = uword[i++];; } while (u && u != '}') { - STORE_CHAR(u); + STORE_CHAR(id,u); u = uword[i++]; } if (u == '}') { @@ -262,7 +264,7 @@ const char *clean_hyphenation(const char *buff, char **cleaned) return s; } } else { - STORE_CHAR(u); + STORE_CHAR(id,u); } } *uindex = '\0'; @@ -276,6 +278,7 @@ void load_hyphenation(struct tex_language *lang, const unsigned char *buff) const char *s; const char *value; char *cleaned; + int id ; lua_State *L = Luas; if (lang == NULL) return; @@ -285,12 +288,13 @@ void load_hyphenation(struct tex_language *lang, const unsigned char *buff) } lua_rawgeti(L, LUA_REGISTRYINDEX, lang->exceptions); s = (const char *) buff; + id = lang->id; while (*s) { while (isspace((unsigned char)*s)) s++; if (*s) { value = s; - s = clean_hyphenation(s, &cleaned); + s = clean_hyphenation(id, s, &cleaned); if (cleaned != NULL) { if ((s - value) > 0) { lua_pushstring(L, cleaned); @@ -300,8 +304,7 @@ void load_hyphenation(struct tex_language *lang, const unsigned char *buff) free(cleaned); } else { #ifdef VERBOSE - fprintf(stderr, "skipping invalid hyphenation exception: %s\n", - value); + formatted_warning("hyphenation","skipping invalid hyphenation exception: %s", value); #endif } } @@ -442,7 +445,6 @@ halfword compound_word_break(halfword t, int clang) return disc; } - halfword insert_complex_discretionary(halfword t, lang_variables * lan, halfword pre, halfword pos, halfword replace) @@ -451,7 +453,6 @@ halfword insert_complex_discretionary(halfword t, lang_variables * lan, return insert_discretionary(t, pre, pos, replace,int_par(hyphen_penalty_code)); } - halfword insert_character(halfword t, int c) { halfword p; @@ -476,8 +477,6 @@ void set_disc_field(halfword f, halfword t) } } - - @ @c static char *hyphenation_exception(int exceptions, char *w) { @@ -498,7 +497,6 @@ static char *hyphenation_exception(int exceptions, char *w) return ret; } - @ @c char *exception_strings(struct tex_language *lang) { @@ -519,8 +517,7 @@ char *exception_strings(struct tex_language *lang) if (current + 2 + l > size) { ret = xrealloc(ret, - (unsigned) ((size + size / 5) + current + l + - 1024)); + (unsigned) ((size + size / 5) + current + l + 1024)); size = (size + size / 5) + current + l + 1024; } *(ret + current) = ' '; @@ -532,7 +529,6 @@ char *exception_strings(struct tex_language *lang) return ret; } - @ the sequence from |wordstart| to |r| can contain only normal characters it could be faster to modify a halfword pointer and return an integer @@ -570,7 +566,6 @@ static int count_exception_part(unsigned int *j, unsigned int *uword, int len) return ret; } - @ @c static const char *PAT_ERROR[] = { "Exception discretionaries should contain three pairs of braced items.", @@ -706,14 +701,12 @@ Algorithms} was typeset by \TeX, only about 1.2 hyphenations needed to be tried per paragraph, since the line breaking algorithm needed to use two passes on only about 5 per cent of the paragraphs. - When a word been set up to contain a candidate for hyphenation, \TeX\ first looks to see if it is in the user's exception dictionary. If not, hyphens are inserted based on patterns that appear within the given word, using an algorithm due to Frank~M. Liang. @^Liang, Franklin Mark@> - @ This is incompatible with TEX because the first word of a paragraph can be hyphenated, but most european users seem to agree that prohibiting hyphenation there was not the best idea ever. @@ -752,12 +745,14 @@ static halfword find_next_wordstart(halfword r) if (is_simple_character(r)) { chr = character(r) ; if (chr == ex_hyphen_char) { - /* We only accept an explicit hyphen when there is a preceding glyph and */ - /* we skip a sequence of explicit hyphens as that normally indicates a */ - /* -- or --- ligature in which case we can in a worse case usage get bad */ - /* node lists later on due to messed up ligature building as these dashes */ - /* ligatures in base fonts. This is a side effect of the separating the */ - /* hyphenation, ligaturing and kerning steps. A test is cmr with ------. */ + /* + We only accept an explicit hyphen when there is a preceding glyph and + we skip a sequence of explicit hyphens as that normally indicates a + -- or --- ligature in which case we can in a worse case usage get bad + node lists later on due to messed up ligature building as these dashes + are ligatures in base fonts. This is a side effect of the separating the + hyphenation, ligaturing and kerning steps. A test is cmr with ------. + */ t = vlink(r) ; if ((start_ok > 0) && (t!=null) && (type(t) == glyph_node) && (character(t) != ex_hyphen_char)) { t = compound_word_break(r, char_lang(r)); @@ -766,7 +761,7 @@ static halfword find_next_wordstart(halfword r) } else { start_ok = 0; } - } else if (start_ok && (l = get_lc_code(chr)) > 0) { + } else if (start_ok && (l = hj_char_code(char_lang(r),chr)) > 0) { if (char_uchyph(r) || l == chr) { return r; } else { @@ -859,7 +854,7 @@ void hnj_hyphenation(halfword head, halfword tail) langdata.pre_hyphen_char = get_pre_hyphen_char(clang); langdata.post_hyphen_char = get_post_hyphen_char(clang); while (r != null && type(r) == glyph_node && is_simple_character(r) && clang == char_lang(r) && - (((lchar = get_lc_code(character(r))) > 0) || (character(r) == ex_hyphen_char && (lchar = ex_hyphen_char)))) { + (((lchar = hj_char_code(clang,character(r))) > 0) || (character(r) == ex_hyphen_char && (lchar = ex_hyphen_char)))) { if (character(r) == ex_hyphen_char) explicit_hyphen = true; wordlen++; @@ -876,8 +871,7 @@ void hnj_hyphenation(halfword head, halfword tail) (replacement = hyphenation_exception(lang->exceptions, utf8word)) != NULL) { #ifdef VERBOSE - fprintf(stderr, "replacing %s (c=%d) by %s\n", utf8word, clang, - replacement); + formatted_warning("hyphenation","replacing %s (c=%d) by %s", utf8word, clang, replacement); #endif do_exception(wordstart, r, replacement); free(replacement); @@ -887,7 +881,7 @@ void hnj_hyphenation(halfword head, halfword tail) halfword rr = r; halfword t = null; #ifdef VERBOSE - fprintf(stderr, "explicit hyphen(s) found in %s (c=%d)\n", utf8word, clang); + formatted_warning("hyphenation","explicit hyphen(s) found in %s (c=%d)", utf8word, clang); #endif while (rr != wordstart) { if (is_simple_character(rr)) { @@ -919,12 +913,11 @@ void hnj_hyphenation(halfword head, halfword tail) } #ifdef VERBOSE - fprintf(stderr, "hyphenate %s (c=%d,l=%d,r=%d) from %c to %c\n", - utf8word, clang, lhmin, rhmin, character(left), - character(right)); + formatted_warning("hyphenation","hyphenate %s (c=%d,l=%d,r=%d) from %c to %c", + utf8word, clang, lhmin, rhmin, character(left), + character(right)); #endif - (void) hnj_hyphen_hyphenate(lang->patterns, wordstart, end_word, - wordlen, left, right, &langdata); + (void) hnj_hyphen_hyphenate(lang->patterns, wordstart, end_word, wordlen, left, right, &langdata); } } explicit_hyphen = false; @@ -938,7 +931,6 @@ void hnj_hyphenation(halfword head, halfword tail) vlink(tail) = save_tail1; } - @ @c void new_hyphenation(halfword head, halfword tail) { @@ -956,7 +948,7 @@ void new_hyphenation(halfword head, halfword tail) nodelist_to_lua(L, head); nodelist_to_lua(L, tail); if (lua_pcall(L, 2, 0, 0) != 0) { - fprintf(stdout, "error: %s\n", lua_tostring(L, -1)); + formatted_warning("hyphenation","bad specification: %s",lua_tostring(L, -1)); lua_pop(L, 2); lua_error(L); return; @@ -970,15 +962,14 @@ void new_hyphenation(halfword head, halfword tail) @ dumping and undumping languages @c -#define dump_string(a) \ - if (a!=NULL) { \ - x = (int)strlen(a)+1; \ - dump_int(x); dump_things(*a, x); \ - } else { \ - x = 0; dump_int(x); \ +#define dump_string(a) \ + if (a!=NULL) { \ + x = (int)strlen(a)+1; \ + dump_int(x); dump_things(*a, x); \ + } else { \ + x = 0; dump_int(x); \ } - static void dump_one_language(int i) { char *s = NULL; @@ -1022,7 +1013,6 @@ void dump_language_data(void) } } - static void undump_one_language(int i) { char *s = NULL; @@ -1071,7 +1061,6 @@ void undump_language_data(void) } } - @ When \TeX\ has scanned `\.{\\hyphenation}', it calls on a procedure named |new_hyph_exceptions| to do the right thing. @@ -1113,7 +1102,6 @@ void new_post_hyphen_char(void) set_post_hyphen_char(int_par(language_code), cur_val); } - @ `\.{\\preexhyphenchar}', sets the |pre_break| character, and `\.{\\postexhyphenchar}' the |post_break| character. Their defaults are both zero (nul). @@ -1133,10 +1121,19 @@ void new_post_exhyphen_char(void) set_post_exhyphen_char(int_par(language_code), cur_val); } - void new_hyphenation_min(void) { scan_optional_equals(); scan_int(); set_hyphenation_min(int_par(language_code), cur_val); } + +void new_hj_code(void) +{ + int i ; + scan_int(); + i = cur_val; + scan_optional_equals(); + scan_int(); + set_hj_code(int_par(language_code), i, cur_val, -1); +} diff --git a/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c b/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c index dee8057bb7b..3abe333ec60 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c @@ -51,7 +51,6 @@ static const char *const callbacknames[] = { "start_page_number", "stop_page_number", "start_run", "stop_run", "define_font", - "token_filter", "pre_output_filter", "buildpage_filter", "hpack_filter", "vpack_filter", @@ -70,6 +69,7 @@ static const char *const callbacknames[] = { "show_error_message","show_lua_error_hook", "show_warning_message", "hpack_quality", "vpack_quality", + "process_rule", NULL }; @@ -83,18 +83,17 @@ int debug_callback_defined(int i) void get_lua_boolean(const char *table, const char *name, boolean * target) { - int stacktop; - int t; - stacktop = lua_gettop(Luas); + int stacktop = lua_gettop(Luas); luaL_checkstack(Luas, 2, "out of stack space"); lua_getglobal(Luas, table); if (lua_istable(Luas, -1)) { + int t; lua_getfield(Luas, -1, name); t = lua_type(Luas, -1); if (t == LUA_TBOOLEAN) { *target = (boolean) (lua_toboolean(Luas, -1)); } else if (t == LUA_TNUMBER) { - *target = (boolean) (lua_tonumber(Luas, -1) == 0 ? 0 : 1); + *target = (boolean) (lua_tointeger(Luas, -1) == 0 ? 0 : 1); } } lua_settop(Luas, stacktop); @@ -103,18 +102,17 @@ void get_lua_boolean(const char *table, const char *name, boolean * target) void get_saved_lua_boolean(int r, const char *name, boolean * target) { - int stacktop; - int t; - stacktop = lua_gettop(Luas); + int stacktop = lua_gettop(Luas); luaL_checkstack(Luas, 2, "out of stack space"); lua_rawgeti(Luas, LUA_REGISTRYINDEX, r); if (lua_istable(Luas, -1)) { + int t; lua_getfield(Luas, -1, name); t = lua_type(Luas, -1); if (t == LUA_TBOOLEAN) { *target = (boolean) lua_toboolean(Luas, -1); } else if (t == LUA_TNUMBER) { - *target = (boolean) (lua_tonumber(Luas, -1) == 0 ? 0 : 1); + *target = (boolean) (lua_tointeger(Luas, -1) == 0 ? 0 : 1); } } lua_settop(Luas, stacktop); @@ -123,14 +121,13 @@ void get_saved_lua_boolean(int r, const char *name, boolean * target) void get_lua_number(const char *table, const char *name, int *target) { - int stacktop; - stacktop = lua_gettop(Luas); + int stacktop = lua_gettop(Luas); luaL_checkstack(Luas, 2, "out of stack space"); lua_getglobal(Luas, table); if (lua_istable(Luas, -1)) { lua_getfield(Luas, -1, name); if (lua_type(Luas, -1) == LUA_TNUMBER) { - *target = (int)lua_tonumber(Luas, -1); + *target = (int) lua_tointeger(Luas, -1); } } lua_settop(Luas, stacktop); @@ -139,14 +136,13 @@ void get_lua_number(const char *table, const char *name, int *target) void get_saved_lua_number(int r, const char *name, int *target) { - int stacktop; - stacktop = lua_gettop(Luas); + int stacktop = lua_gettop(Luas); luaL_checkstack(Luas, 2, "out of stack space"); lua_rawgeti(Luas, LUA_REGISTRYINDEX, r); if (lua_istable(Luas, -1)) { lua_getfield(Luas, -1, name); if (lua_type(Luas, -1) == LUA_TNUMBER) { - *target=(int)lua_tonumber(Luas, -1); + *target = (int) lua_tointeger(Luas, -1); } } lua_settop(Luas, stacktop); @@ -155,8 +151,7 @@ void get_saved_lua_number(int r, const char *name, int *target) void get_lua_string(const char *table, const char *name, char **target) { - int stacktop; - stacktop = lua_gettop(Luas); + int stacktop = lua_gettop(Luas); luaL_checkstack(Luas, 2, "out of stack space"); lua_getglobal(Luas, table); if (lua_type(Luas, -1) == LUA_TTABLE) { @@ -171,8 +166,7 @@ void get_lua_string(const char *table, const char *name, char **target) void get_saved_lua_string(int r, const char *name, char **target) { - int stacktop; - stacktop = lua_gettop(Luas); + int stacktop = lua_gettop(Luas); luaL_checkstack(Luas, 2, "out of stack space"); lua_rawgeti(Luas, LUA_REGISTRYINDEX, r); if (lua_type(Luas, -1) == LUA_TTABLE) { @@ -190,6 +184,7 @@ void get_saved_lua_string(int r, const char *name, char **target) #define CALLBACK_LINE 'l' #define CALLBACK_STRNUMBER 's' #define CALLBACK_STRING 'S' +#define CALLBACK_RESULT 'R' /* a string but nil is also ok */ #define CALLBACK_CHARNUM 'c' #define CALLBACK_LSTRING 'L' #define CALLBACK_NODE 'N' @@ -279,49 +274,48 @@ int do_run_callback(int special, const char *values, va_list vl) lua_pushvalue(L, -2); } ss = strchr(values, '>'); - assert(ss); luaL_checkstack(L, (int) (ss - values + 1), "out of stack space"); ss = NULL; for (narg = 0; *values; narg++) { switch (*values++) { - case CALLBACK_CHARNUM: /* an ascii char! */ - cs = (char) va_arg(vl, int); - lua_pushlstring(L, &cs, 1); - break; - case CALLBACK_STRING: /* C string */ - s = va_arg(vl, char *); - lua_pushstring(L, s); - break; - case CALLBACK_LSTRING: /* 'lstring' */ - lstr = va_arg(vl, lstring *); - lua_pushlstring(L, (const char *)lstr->s, lstr->l); - break; - case CALLBACK_INTEGER: /* int */ - lua_pushnumber(L, va_arg(vl, int)); - break; - case CALLBACK_STRNUMBER: /* TeX string */ - s = makeclstring(va_arg(vl, int), &len); - lua_pushlstring(L, s, len); - break; - case CALLBACK_BOOLEAN: /* boolean */ - lua_pushboolean(L, va_arg(vl, int)); - break; - case CALLBACK_LINE: /* a buffer section, with implied start */ - lua_pushlstring(L, (char *) (buffer + first), (size_t) va_arg(vl, int)); - break; - case CALLBACK_NODE: - lua_nodelib_push_fast(L,va_arg(vl, int)); - break; - case CALLBACK_DIR: - lua_push_dir_par(L,va_arg(vl, int)); - break; - case '-': - narg--; - break; - case '>': - goto ENDARGS; - default: - ; + case CALLBACK_CHARNUM: /* an ascii char! */ + cs = (char) va_arg(vl, int); + lua_pushlstring(L, &cs, 1); + break; + case CALLBACK_STRING: /* C string */ + s = va_arg(vl, char *); + lua_pushstring(L, s); + break; + case CALLBACK_LSTRING: /* 'lstring' */ + lstr = va_arg(vl, lstring *); + lua_pushlstring(L, (const char *)lstr->s, lstr->l); + break; + case CALLBACK_INTEGER: /* int */ + lua_pushinteger(L, va_arg(vl, int)); + break; + case CALLBACK_STRNUMBER: /* TeX string */ + s = makeclstring(va_arg(vl, int), &len); + lua_pushlstring(L, s, len); + break; + case CALLBACK_BOOLEAN: /* boolean */ + lua_pushboolean(L, va_arg(vl, int)); + break; + case CALLBACK_LINE: /* a buffer section, with implied start */ + lua_pushlstring(L, (char *) (buffer + first), (size_t) va_arg(vl, int)); + break; + case CALLBACK_NODE: + lua_nodelib_push_fast(L,va_arg(vl, int)); + break; + case CALLBACK_DIR: + lua_push_dir_par(L,va_arg(vl, int)); + break; + case '-': + narg--; + break; + case '>': + goto ENDARGS; + default: + ; } } ENDARGS: @@ -343,7 +337,7 @@ int do_run_callback(int special, const char *values, va_list vl) * TeX initialization is complete */ if (!log_opened_global) { - fprintf(stderr, "This went wrong: %s\n", lua_tostring(L, -1)); + fprintf(stderr, "error in callback: %s\n", lua_tostring(L, -1)); error(); } else { lua_gc(L, LUA_GCCOLLECT, 0); @@ -359,102 +353,130 @@ int do_run_callback(int special, const char *values, va_list vl) while (*values) { int b, t; halfword p; + t = lua_type(L, nres); switch (*values++) { - case CALLBACK_BOOLEAN: - if (lua_type(L, nres) != LUA_TBOOLEAN) { - fprintf(stderr, "Expected a boolean, not: %s\n", lua_typename(L, lua_type(L, nres))); - goto EXIT; - } - b = lua_toboolean(L, nres); - *va_arg(vl, boolean *) = (boolean) b; - break; - case CALLBACK_INTEGER: - if (lua_type(L, nres) != LUA_TNUMBER) { - fprintf(stderr, "Expected a number, not: %s\n", lua_typename(L, lua_type(L, nres))); - goto EXIT; - } - b = (int) lua_tonumber(L, nres); - *va_arg(vl, int *) = b; - break; - case CALLBACK_LINE: /* TeX line ... happens frequently when we have a plug-in */ - t = lua_type(L, nres); - if (t == LUA_TNIL) { - bufloc = 0; - goto EXIT; - } else if (t == LUA_TSTRING) { - s = lua_tolstring(L, nres, &len); - if (s == NULL) { /* |len| can be zero */ - bufloc = 0; - } else if (len == 0) { + case CALLBACK_BOOLEAN: + if (t == LUA_TNIL) { + b = 0; + } else if (t != LUA_TBOOLEAN) { + fprintf(stderr, "callback should return a boolean, not: %s\n", lua_typename(L, t)); + goto EXIT; + } else { + b = lua_toboolean(L, nres); + } + *va_arg(vl, boolean *) = (boolean) b; + break; + case CALLBACK_INTEGER: + if (t != LUA_TNUMBER) { + fprintf(stderr, "callback should return a number, not: %s\n", lua_typename(L, t)); + goto EXIT; + } + b = lua_tointeger(L, nres); + *va_arg(vl, int *) = b; + break; + case CALLBACK_LINE: /* TeX line ... happens frequently when we have a plug-in */ + if (t == LUA_TNIL) { bufloc = 0; + goto EXIT; + } else if (t == LUA_TSTRING) { + s = lua_tolstring(L, nres, &len); + if (s == NULL) { /* |len| can be zero */ + bufloc = 0; + } else if (len == 0) { + bufloc = 0; + } else { + bufloc = va_arg(vl, int *); + ret = *bufloc; + check_buffer_overflow(ret + (int) len); + strncpy((char *) (buffer + ret), s, len); + *bufloc += (int) len; + /* while (len--) { buffer[(*bufloc)++] = *s++; } */ + while ((*bufloc) - 1 > ret && buffer[(*bufloc) - 1] == ' ') + (*bufloc)--; + } } else { - bufloc = va_arg(vl, int *); - ret = *bufloc; - check_buffer_overflow(ret + (int) len); - strncpy((char *) (buffer + ret), s, len); - *bufloc += (int) len; - /* while (len--) { buffer[(*bufloc)++] = *s++; } */ - while ((*bufloc) - 1 > ret && buffer[(*bufloc) - 1] == ' ') - (*bufloc)--; + fprintf(stderr, "callback should return a string, not: %s\n", lua_typename(L, t)); + goto EXIT; } - } else { - fprintf(stderr, "Expected a string for (l), not: %s\n", lua_typename(L, lua_type(L, nres))); - goto EXIT; - } - break; - case CALLBACK_STRNUMBER: /* TeX string */ - if (lua_type(L, nres) != LUA_TSTRING) { - fprintf(stderr, "Expected a string for (s), not: %s\n", lua_typename(L, lua_type(L, nres))); - goto EXIT; - } - s = lua_tolstring(L, nres, &len); - if (s == NULL) /* |len| can be zero */ - *va_arg(vl, int *) = 0; - else { - *va_arg(vl, int *) = maketexlstring(s, len); - } - break; - case CALLBACK_STRING: /* C string aka buffer */ - if (lua_type(L, nres) != LUA_TSTRING) { - fprintf(stderr, "Expected a string for (S), not: %s\n", lua_typename(L, lua_type(L, nres))); - goto EXIT; - } - s = lua_tolstring(L, nres, &len); - if (s == NULL) /* |len| can be zero */ - *va_arg(vl, int *) = 0; - else { - ss = xmalloc((unsigned) (len + 1)); - (void) memcpy(ss, s, (len + 1)); - *va_arg(vl, char **) = ss; - } - break; - case CALLBACK_LSTRING: /* lstring */ - if (lua_type(L, nres) != LUA_TSTRING) { - fprintf(stderr, "Expected a string for (S), not: %s\n", lua_typename(L, lua_type(L, nres))); + break; + case CALLBACK_STRNUMBER: /* TeX string */ + if (t != LUA_TSTRING) { + fprintf(stderr, "callback should return a string, not: %s\n", lua_typename(L, t)); + goto EXIT; + } + s = lua_tolstring(L, nres, &len); + if (s == NULL) /* |len| can be zero */ + *va_arg(vl, int *) = 0; + else { + *va_arg(vl, int *) = maketexlstring(s, len); + } + break; + case CALLBACK_STRING: /* C string aka buffer */ + if (t != LUA_TSTRING) { + fprintf(stderr, "callback should return a string, not: %s\n", lua_typename(L, t)); + goto EXIT; + } + s = lua_tolstring(L, nres, &len); + if (s == NULL) /* |len| can be zero */ + *va_arg(vl, int *) = 0; + else { + ss = xmalloc((unsigned) (len + 1)); + (void) memcpy(ss, s, (len + 1)); + *va_arg(vl, char **) = ss; + } + break; + case CALLBACK_RESULT: /* C string aka buffer */ + if (t == LUA_TNIL) { + *va_arg(vl, int *) = 0; + } else if (t == LUA_TBOOLEAN) { + b = lua_toboolean(L, nres); + if (b == 0) { + *va_arg(vl, int *) = 0; + } else { + fprintf(stderr, "callback should return a string, false or nil, not: %s\n", lua_typename(L, t)); + goto EXIT; + } + } else if (t != LUA_TSTRING) { + fprintf(stderr, "callback should return a string, false or nil, not: %s\n", lua_typename(L, t)); + goto EXIT; + } else { + s = lua_tolstring(L, nres, &len); + if (s == NULL) /* |len| can be zero */ + *va_arg(vl, int *) = 0; + else { + ss = xmalloc((unsigned) (len + 1)); + (void) memcpy(ss, s, (len + 1)); + *va_arg(vl, char **) = ss; + } + } + break; + case CALLBACK_LSTRING: /* lstring */ + if (t != LUA_TSTRING) { + fprintf(stderr, "callback should return a string, not: %s\n", lua_typename(L, t)); + goto EXIT; + } + s = lua_tolstring(L, nres, &len); + if (s == NULL) /* |len| can be zero */ + *va_arg(vl, int *) = 0; + else { + lstring *ret = xmalloc(sizeof(lstring)); + ret->s = xmalloc((unsigned) (len + 1)); + (void) memcpy(ret->s, s, (len + 1)); + ret->l = len; + *va_arg(vl, lstring **) = ret; + } + break; + case CALLBACK_NODE: + if (t == LUA_TNIL) { + p = null; + } else { + p = *check_isnode(L,nres); + } + *va_arg(vl, int *) = p; + break; + default: + fprintf(stdout, "callback returned an invalid value type"); goto EXIT; - } - s = lua_tolstring(L, nres, &len); - if (s == NULL) /* |len| can be zero */ - *va_arg(vl, int *) = 0; - else { - lstring *ret = xmalloc(sizeof(lstring)); - ret->s = xmalloc((unsigned) (len + 1)); - (void) memcpy(ret->s, s, (len + 1)); - ret->l = len; - *va_arg(vl, lstring **) = ret; - } - break; - case CALLBACK_NODE: - if (lua_type(L,nres) == LUA_TNIL) { - p = null; - } else { - p = *check_isnode(L,nres); - } - *va_arg(vl, int *) = p; - break; - default: - fprintf(stdout, "invalid return value type"); - goto EXIT; } nres++; } @@ -472,14 +494,13 @@ static int callback_register(lua_State * L) { int cb; const char *s; - int t1, t2; - t1 = lua_type(L,1); + int t1 = lua_type(L,1); + int t2 = lua_type(L,2); if (t1 != LUA_TSTRING) { lua_pushnil(L); lua_pushstring(L, "Invalid arguments to callback.register, first argument must be string."); return 2; } - t2 = lua_type(L,2); if ((t2 != LUA_TFUNCTION) && (t2 != LUA_TNIL) && ((t2 != LUA_TBOOLEAN) && (lua_toboolean(L, 2) == 0))) { lua_pushnil(L); lua_pushstring(L, "Invalid arguments to callback.register."); @@ -507,7 +528,7 @@ static int callback_register(lua_State * L) lua_pushvalue(L, 2); /* the function or nil */ lua_rawseti(L, -2, cb); lua_rawseti(L, LUA_REGISTRYINDEX, callback_callbacks_id); - lua_pushnumber(L, cb); + lua_pushinteger(L, cb); return 1; } diff --git a/Build/source/texk/web2c/luatexdir/lua/lepdflib.cc b/Build/source/texk/web2c/luatexdir/lua/lepdflib.cc index b26f268feb4..00e27863a2c 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lepdflib.cc +++ b/Build/source/texk/web2c/luatexdir/lua/lepdflib.cc @@ -153,17 +153,17 @@ static int l_open_MemStreamPDFDoc(lua_State * L) docstream = luaL_checkstring(L, 1); // stream as Lua string break; case LUA_TLIGHTUSERDATA: - docstream = (const char *) lua_touserdata(L, 1); // stream as sequence of bytes + docstream = (const char *) lua_touserdata(L, 1); // stream as sequence of bytes break; default: - luaL_error(L, "bad argument: string or lightuserdata expected"); + luaL_error(L, "bad argument: string or lightuserdata expected"); } - if (docstream==NULL) - luaL_error(L, "bad document"); + if (docstream==NULL) + luaL_error(L, "bad document"); stream_size = (unsigned long long) luaL_checkint(L, 2);// size of the stream file_id = luaL_checkstring(L, 3); // a symbolic name for this stream, mandatory if (file_id == NULL) - luaL_error(L, "PDFDoc has an invalid id"); + luaL_error(L, "PDFDoc has an invalid id"); if (strlen(file_id) >STREAM_FILE_ID_LEN ) // a limit to the length of the string luaL_error(L, "PDFDoc has a too long id"); docstream_usr = (char *)gmalloc((unsigned) (stream_size + 1)); @@ -183,7 +183,7 @@ static int l_open_MemStreamPDFDoc(lua_State * L) lua_pushnil(L); } else { - if (!(globalParams)) // globalParams could be already created + if (!(globalParams)) // globalParams could be already created globalParams = new GlobalParams(); uout = new_PDFDoc_userdata(L); uout->d = d; @@ -243,20 +243,20 @@ static int l_new_Attribute(lua_State * L) uout->pc = uobj->pc; uout->pd = uobj->pd; } else - lua_pushnil(L); + lua_pushnil(L); return 1; } #define ATTRIBUTE_TYPE_ENTRY(name) \ lua_pushstring(L, #name); \ lua_pushinteger(L, Attribute::name); \ - lua_settable(L,-3) + lua_settable(L,-3) #define STRUCTELEMENT_TYPE_ENTRY(name) \ lua_pushstring(L, #name); \ lua_pushinteger(L, StructElement::name); \ - lua_settable(L,-3) + lua_settable(L,-3) static int l_Attribute_Type(lua_State * L) { @@ -308,74 +308,74 @@ static int l_Attribute_Type(lua_State * L) { static int l_StructElement_Type(lua_State * L) { lua_createtable (L, 0, 50); - STRUCTELEMENT_TYPE_ENTRY(Document); - STRUCTELEMENT_TYPE_ENTRY(Part); - STRUCTELEMENT_TYPE_ENTRY(Art); - STRUCTELEMENT_TYPE_ENTRY(Sect); - STRUCTELEMENT_TYPE_ENTRY(Div); - STRUCTELEMENT_TYPE_ENTRY(BlockQuote); - STRUCTELEMENT_TYPE_ENTRY(Caption); - STRUCTELEMENT_TYPE_ENTRY(NonStruct); - STRUCTELEMENT_TYPE_ENTRY(Index); - STRUCTELEMENT_TYPE_ENTRY(Private); - STRUCTELEMENT_TYPE_ENTRY(Span); - STRUCTELEMENT_TYPE_ENTRY(Quote); - STRUCTELEMENT_TYPE_ENTRY(Note); - STRUCTELEMENT_TYPE_ENTRY(Reference); - STRUCTELEMENT_TYPE_ENTRY(BibEntry); - STRUCTELEMENT_TYPE_ENTRY(Code); - STRUCTELEMENT_TYPE_ENTRY(Link); - STRUCTELEMENT_TYPE_ENTRY(Annot); - STRUCTELEMENT_TYPE_ENTRY(Ruby); - STRUCTELEMENT_TYPE_ENTRY(RB); - STRUCTELEMENT_TYPE_ENTRY(RT); - STRUCTELEMENT_TYPE_ENTRY(RP); - STRUCTELEMENT_TYPE_ENTRY(Warichu); - STRUCTELEMENT_TYPE_ENTRY(WT); - STRUCTELEMENT_TYPE_ENTRY(WP); - STRUCTELEMENT_TYPE_ENTRY(P); - STRUCTELEMENT_TYPE_ENTRY(H); - STRUCTELEMENT_TYPE_ENTRY(H1); - STRUCTELEMENT_TYPE_ENTRY(H2); - STRUCTELEMENT_TYPE_ENTRY(H3); - STRUCTELEMENT_TYPE_ENTRY(H4); - STRUCTELEMENT_TYPE_ENTRY(H5); - STRUCTELEMENT_TYPE_ENTRY(H6); - STRUCTELEMENT_TYPE_ENTRY(L); - STRUCTELEMENT_TYPE_ENTRY(LI); - STRUCTELEMENT_TYPE_ENTRY(Lbl); - STRUCTELEMENT_TYPE_ENTRY(LBody); - STRUCTELEMENT_TYPE_ENTRY(Table); - STRUCTELEMENT_TYPE_ENTRY(TR); - STRUCTELEMENT_TYPE_ENTRY(TH); - STRUCTELEMENT_TYPE_ENTRY(TD); - STRUCTELEMENT_TYPE_ENTRY(THead); - STRUCTELEMENT_TYPE_ENTRY(TFoot); - STRUCTELEMENT_TYPE_ENTRY(TBody); - STRUCTELEMENT_TYPE_ENTRY(Figure); - STRUCTELEMENT_TYPE_ENTRY(Formula); - STRUCTELEMENT_TYPE_ENTRY(Form); - STRUCTELEMENT_TYPE_ENTRY(TOC); - STRUCTELEMENT_TYPE_ENTRY(TOCI); + STRUCTELEMENT_TYPE_ENTRY(Document); + STRUCTELEMENT_TYPE_ENTRY(Part); + STRUCTELEMENT_TYPE_ENTRY(Art); + STRUCTELEMENT_TYPE_ENTRY(Sect); + STRUCTELEMENT_TYPE_ENTRY(Div); + STRUCTELEMENT_TYPE_ENTRY(BlockQuote); + STRUCTELEMENT_TYPE_ENTRY(Caption); + STRUCTELEMENT_TYPE_ENTRY(NonStruct); + STRUCTELEMENT_TYPE_ENTRY(Index); + STRUCTELEMENT_TYPE_ENTRY(Private); + STRUCTELEMENT_TYPE_ENTRY(Span); + STRUCTELEMENT_TYPE_ENTRY(Quote); + STRUCTELEMENT_TYPE_ENTRY(Note); + STRUCTELEMENT_TYPE_ENTRY(Reference); + STRUCTELEMENT_TYPE_ENTRY(BibEntry); + STRUCTELEMENT_TYPE_ENTRY(Code); + STRUCTELEMENT_TYPE_ENTRY(Link); + STRUCTELEMENT_TYPE_ENTRY(Annot); + STRUCTELEMENT_TYPE_ENTRY(Ruby); + STRUCTELEMENT_TYPE_ENTRY(RB); + STRUCTELEMENT_TYPE_ENTRY(RT); + STRUCTELEMENT_TYPE_ENTRY(RP); + STRUCTELEMENT_TYPE_ENTRY(Warichu); + STRUCTELEMENT_TYPE_ENTRY(WT); + STRUCTELEMENT_TYPE_ENTRY(WP); + STRUCTELEMENT_TYPE_ENTRY(P); + STRUCTELEMENT_TYPE_ENTRY(H); + STRUCTELEMENT_TYPE_ENTRY(H1); + STRUCTELEMENT_TYPE_ENTRY(H2); + STRUCTELEMENT_TYPE_ENTRY(H3); + STRUCTELEMENT_TYPE_ENTRY(H4); + STRUCTELEMENT_TYPE_ENTRY(H5); + STRUCTELEMENT_TYPE_ENTRY(H6); + STRUCTELEMENT_TYPE_ENTRY(L); + STRUCTELEMENT_TYPE_ENTRY(LI); + STRUCTELEMENT_TYPE_ENTRY(Lbl); + STRUCTELEMENT_TYPE_ENTRY(LBody); + STRUCTELEMENT_TYPE_ENTRY(Table); + STRUCTELEMENT_TYPE_ENTRY(TR); + STRUCTELEMENT_TYPE_ENTRY(TH); + STRUCTELEMENT_TYPE_ENTRY(TD); + STRUCTELEMENT_TYPE_ENTRY(THead); + STRUCTELEMENT_TYPE_ENTRY(TFoot); + STRUCTELEMENT_TYPE_ENTRY(TBody); + STRUCTELEMENT_TYPE_ENTRY(Figure); + STRUCTELEMENT_TYPE_ENTRY(Formula); + STRUCTELEMENT_TYPE_ENTRY(Form); + STRUCTELEMENT_TYPE_ENTRY(TOC); + STRUCTELEMENT_TYPE_ENTRY(TOCI); lua_pushstring(L, "Unknown"); - lua_pushinteger(L, 0); + lua_pushinteger(L, 0); lua_settable(L,-3); return 1; } static int l_AttributeOwner_Type(lua_State * L) { lua_createtable (L, 0, 12); - lua_pushstring(L, "XML-1.00"); lua_pushinteger(L, Attribute::XML_1_00); lua_settable(L,-3); - lua_pushstring(L, "HTML-3.20"); lua_pushinteger(L, Attribute::HTML_3_20); lua_settable(L,-3); - lua_pushstring(L, "HTML-4.01"); lua_pushinteger(L, Attribute::HTML_4_01); lua_settable(L,-3); - lua_pushstring(L, "OEB-1.00"); lua_pushinteger(L, Attribute::OEB_1_00); lua_settable(L,-3); - lua_pushstring(L, "RTF-1.05"); lua_pushinteger(L, Attribute::RTF_1_05); lua_settable(L,-3); - lua_pushstring(L, "CSS-1.00"); lua_pushinteger(L, Attribute::CSS_1_00); lua_settable(L,-3); - lua_pushstring(L, "CSS-2.00"); lua_pushinteger(L, Attribute::CSS_2_00); lua_settable(L,-3); - lua_pushstring(L, "Layout"); lua_pushinteger(L, Attribute::Layout); lua_settable(L,-3); - lua_pushstring(L, "PrintField"); lua_pushinteger(L, Attribute::PrintField); lua_settable(L,-3); - lua_pushstring(L, "Table"); lua_pushinteger(L, Attribute::Table); lua_settable(L,-3); - lua_pushstring(L, "List"); lua_pushinteger(L, Attribute::List); lua_settable(L,-3); + lua_pushstring(L, "XML-1.00"); lua_pushinteger(L, Attribute::XML_1_00); lua_settable(L,-3); + lua_pushstring(L, "HTML-3.20"); lua_pushinteger(L, Attribute::HTML_3_20); lua_settable(L,-3); + lua_pushstring(L, "HTML-4.01"); lua_pushinteger(L, Attribute::HTML_4_01); lua_settable(L,-3); + lua_pushstring(L, "OEB-1.00"); lua_pushinteger(L, Attribute::OEB_1_00); lua_settable(L,-3); + lua_pushstring(L, "RTF-1.05"); lua_pushinteger(L, Attribute::RTF_1_05); lua_settable(L,-3); + lua_pushstring(L, "CSS-1.00"); lua_pushinteger(L, Attribute::CSS_1_00); lua_settable(L,-3); + lua_pushstring(L, "CSS-2.00"); lua_pushinteger(L, Attribute::CSS_2_00); lua_settable(L,-3); + lua_pushstring(L, "Layout"); lua_pushinteger(L, Attribute::Layout); lua_settable(L,-3); + lua_pushstring(L, "PrintField"); lua_pushinteger(L, Attribute::PrintField); lua_settable(L,-3); + lua_pushstring(L, "Table"); lua_pushinteger(L, Attribute::Table); lua_settable(L,-3); + lua_pushstring(L, "List"); lua_pushinteger(L, Attribute::List); lua_settable(L,-3); lua_pushstring(L, "UserProperties"); lua_pushinteger(L, Attribute::UserProperties);lua_settable(L,-3); return 1; } @@ -496,7 +496,7 @@ static int m_##in##_##function(lua_State * L) \ } #define m_poppler_get_UINT(in, function) \ -m_poppler_get_GUINT(in, function) +m_poppler_get_GUINT(in, function) @@ -509,7 +509,7 @@ static int m_##in##_##function(lua_State * L) \ if (uin->pd != NULL && uin->pd->pc != uin->pc) \ pdfdoc_changed_error(L); \ d = (double) ((in *) uin->d)->function(); \ - lua_pushnumber(L, d); \ + lua_pushnumber(L, d); /* float */ \ return 1; \ } @@ -1619,7 +1619,7 @@ static int m_Object_getInt(lua_State * L) if (uin->pd != NULL && uin->pd->pc != uin->pc) pdfdoc_changed_error(L); if (((Object *) uin->d)->isInt()) - lua_pushnumber(L, ((Object *) uin->d)->getInt()); + lua_pushinteger(L, ((Object *) uin->d)->getInt()); else lua_pushnil(L); return 1; @@ -1632,7 +1632,7 @@ static int m_Object_getReal(lua_State * L) if (uin->pd != NULL && uin->pd->pc != uin->pc) pdfdoc_changed_error(L); if (((Object *) uin->d)->isReal()) - lua_pushnumber(L, ((Object *) uin->d)->getReal()); + lua_pushnumber(L, ((Object *) uin->d)->getReal()); /* float */ else lua_pushnil(L); return 1; @@ -1645,7 +1645,7 @@ static int m_Object_getNum(lua_State * L) if (uin->pd != NULL && uin->pd->pc != uin->pc) pdfdoc_changed_error(L); if (((Object *) uin->d)->isNum()) - lua_pushnumber(L, ((Object *) uin->d)->getNum()); + lua_pushnumber(L, ((Object *) uin->d)->getNum()); /* integer or float */ else lua_pushnil(L); return 1; @@ -1798,7 +1798,7 @@ static int m_Object_arrayGetLength(lua_State * L) pdfdoc_changed_error(L); if (((Object *) uin->d)->isArray()) { len = ((Object *) uin->d)->arrayGetLength(); - lua_pushnumber(L, len); + lua_pushinteger(L, len); } else lua_pushnil(L); return 1; @@ -1877,7 +1877,7 @@ static int m_Object_dictGetLength(lua_State * L) pdfdoc_changed_error(L); if (((Object *) uin->d)->isDict()) { len = ((Object *) uin->d)->dictGetLength(); - lua_pushnumber(L, len); + lua_pushinteger(L, len); } else lua_pushnil(L); return 1; @@ -2385,7 +2385,7 @@ static int m_PDFDoc_##function(lua_State * L) \ pages = ((PdfDocument *) uin->d)->doc->getNumPages(); \ if (i > 0 && i <= pages) { \ d = (double) ((PdfDocument *) uin->d)->doc->function(i); \ - lua_pushnumber(L, d); \ + lua_pushnumber(L, d); /* float */ \ } else \ lua_pushnil(L); \ return 1; \ @@ -2618,16 +2618,16 @@ static int m_PDFRectangle__index(lua_State * L) if (strlen(s) == 2) { if (s[0] == 'x') { if (s[1] == '1') - lua_pushnumber(L, ((PDFRectangle *) uin->d)->x1); + lua_pushnumber(L, ((PDFRectangle *) uin->d)->x1); /* float */ else if (s[1] == '2') - lua_pushnumber(L, ((PDFRectangle *) uin->d)->x2); + lua_pushnumber(L, ((PDFRectangle *) uin->d)->x2); /* float */ else lua_pushnil(L); } else if (s[0] == 'y') { if (s[1] == '1') - lua_pushnumber(L, ((PDFRectangle *) uin->d)->y1); + lua_pushnumber(L, ((PDFRectangle *) uin->d)->y1); /* float */ else if (s[1] == '2') - lua_pushnumber(L, ((PDFRectangle *) uin->d)->y2); + lua_pushnumber(L, ((PDFRectangle *) uin->d)->y2); /* float */ else lua_pushnil(L); } else @@ -2792,7 +2792,7 @@ static const struct luaL_Reg Stream_m[] = { //********************************************************************** // TextSpan -m_poppler_get_GOOSTRING(TextSpan, getText); +m_poppler_get_GOOSTRING(TextSpan, getText); m_poppler__tostring(TextSpan); static const struct luaL_Reg TextSpan_m[] = { @@ -2858,7 +2858,7 @@ static int m_Attribute_getDefaultValue(lua_State * L) pdfdoc_changed_error(L); t = (Attribute::Type) luaL_checkint(L, 2); uout = new_Object_userdata(L); - uout->d = ((Attribute *)uin->d)->getDefaultValue(t) ; + uout->d = ((Attribute *)uin->d)->getDefaultValue(t) ; //uout->atype = ALLOC_LEPDF; uout->pc = uin->pc; uout->pd = uin->pd; @@ -2977,12 +2977,12 @@ m_poppler_get_INT(StructElement, getNumChildren); m_poppler_get_GUINT(StructElement,getRevision); m_poppler_get_UINT(StructElement,getNumAttributes); -m_poppler_get_GOOSTRING(StructElement, getID); -m_poppler_get_GOOSTRING(StructElement, getLanguage); -m_poppler_get_GOOSTRING(StructElement, getTitle); +m_poppler_get_GOOSTRING(StructElement, getID); +m_poppler_get_GOOSTRING(StructElement, getLanguage); +m_poppler_get_GOOSTRING(StructElement, getTitle); m_poppler_get_GOOSTRING(StructElement, getExpandedAbbr); -m_poppler_get_GOOSTRING(StructElement, getAltText); -m_poppler_get_GOOSTRING(StructElement, getActualText); +m_poppler_get_GOOSTRING(StructElement, getAltText); +m_poppler_get_GOOSTRING(StructElement, getActualText); m_poppler_get_poppler(StructElement, StructTreeRoot, getStructTreeRoot); m_poppler__tostring(StructElement); @@ -3021,7 +3021,7 @@ static int m_StructElement_getParentRef(lua_State * L) return 1; } -// Not exactly as the header: +// Not exactly as the header: // Ref = StructElement:getPageRef() // Ref is false if the C++ functione return false static int m_StructElement_getPageRef(lua_State * L) @@ -3073,17 +3073,17 @@ static int m_StructElement_setRevision(lua_State * L) static int m_StructElement_getText(lua_State * L) { GBool i; - GooString *gs; + GooString *gs; udstruct *uin; uin = (udstruct *) luaL_checkudata(L, 1, M_StructElement); if (uin->pd != NULL && uin->pd->pc != uin->pc) pdfdoc_changed_error(L); i = (GBool) lua_toboolean(L, 2); gs = ((StructElement *) uin->d)->getText(i); - if (gs != NULL) - lua_pushlstring(L, gs->getCString(), gs->getLength()); - else - lua_pushnil(L); + if (gs != NULL) + lua_pushlstring(L, gs->getCString(), gs->getLength()); + else + lua_pushnil(L); return 1; } @@ -3098,15 +3098,15 @@ static int m_StructElement_getChild(lua_State * L) pdfdoc_changed_error(L); i = (int) luaL_checkint(L, 2); c = ((StructElement *) uin->d)->getChild(i-1); - if (c != NULL) { + if (c != NULL) { uout = new_StructElement_userdata(L); uout->d = c ; //uout->atype = ALLOC_LEPDF; uout->pc = uin->pc; uout->pd = uin->pd; - } - else - lua_pushnil(L); + } + else + lua_pushnil(L); return 1; } @@ -3135,14 +3135,14 @@ static int m_StructElement_getAttribute(lua_State * L) pdfdoc_changed_error(L); i = (int) luaL_checkint(L, 2); a = ((StructElement *) uin->d)->getAttribute(i-1); - if (a != NULL) { + if (a != NULL) { uout = new_Attribute_userdata(L); uout->d = a ; uout->pc = uin->pc; uout->pd = uin->pd; - } - else - lua_pushnil(L); + } + else + lua_pushnil(L); return 1; } @@ -3177,15 +3177,15 @@ static int m_StructElement_findAttribute(lua_State * L) o = (Attribute::Owner) luaL_checkint(L,2); g = (GBool) lua_toboolean(L, 3); a = ((StructElement *) uin->d)->findAttribute(t,g,o); - + if (a!=NULL){ uout = new_Attribute_userdata(L); uout->d = new Attribute(a->getType(),a->getValue()); uout->atype = ALLOC_LEPDF; uout->pc = uin->pc; uout->pd = uin->pd; - } else - lua_pushnil(L); + } else + lua_pushnil(L); return 1; } @@ -3193,14 +3193,14 @@ static int m_StructElement_findAttribute(lua_State * L) static int m_StructElement_getTextSpans(lua_State * L) { int i ; - udstruct *uin, *uout; + udstruct *uin, *uout; uin = (udstruct *) luaL_checkudata(L, 1, M_StructElement); - if (uin->pd != NULL && uin->pd->pc != uin->pc) - pdfdoc_changed_error(L); - + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if ((((StructElement *) uin->d)->getTextSpans()).size()>0) { - lua_createtable (L, - (int) (((StructElement *) uin->d)->getTextSpans()).size(), + lua_createtable (L, + (int) (((StructElement *) uin->d)->getTextSpans()).size(), 0); for(i=0;i<(int) (((StructElement *) uin->d)->getTextSpans()).size(); i++){ uout = new_TextSpan_userdata(L); @@ -3209,9 +3209,9 @@ static int m_StructElement_getTextSpans(lua_State * L) uout->pc = uin->pc; uout->pd = uin->pd; lua_rawseti(L,-2,i+1); - } - } else - lua_pushnil(L); + } + } else + lua_pushnil(L); return 1; } @@ -3268,8 +3268,8 @@ static int m_StructTreeRoot_getChild(lua_State * L) unsigned int i; udstruct *uin, *uout; StructElement *child ; - StructTreeRoot *root ; - + StructTreeRoot *root ; + uin = (udstruct *) luaL_checkudata(L, 1, M_StructTreeRoot); if (uin->pd != NULL && uin->pd->pc != uin->pc) pdfdoc_changed_error(L); @@ -3291,7 +3291,7 @@ static int m_StructTreeRoot_appendChild(lua_State * L) { udstruct *uin, *uin_child; StructElement *child ; - StructTreeRoot *root ; + StructTreeRoot *root ; uin = (udstruct *) luaL_checkudata(L, 1, M_StructTreeRoot); if (uin->pd != NULL && uin->pd->pc != uin->pc) pdfdoc_changed_error(L); @@ -3310,8 +3310,8 @@ static int m_StructTreeRoot_findParentElement(lua_State * L) unsigned int i; udstruct *uin, *uout; const StructElement *parent ; - StructTreeRoot *root ; - + StructTreeRoot *root ; + uin = (udstruct *) luaL_checkudata(L, 1, M_StructTreeRoot); if (uin->pd != NULL && uin->pd->pc != uin->pc) pdfdoc_changed_error(L); @@ -3324,7 +3324,7 @@ static int m_StructTreeRoot_findParentElement(lua_State * L) uout->atype = ALLOC_LEPDF; uout->pc = uin->pc; uout->pd = uin->pd; - } else + } else lua_pushnil(L); return 1; } diff --git a/Build/source/texk/web2c/luatexdir/lua/lfontlib.c b/Build/source/texk/web2c/luatexdir/lua/lfontlib.c index fa40150370c..2e05f5f3327 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lfontlib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lfontlib.c @@ -37,18 +37,14 @@ static int get_fontid(void) static int font_read_tfm(lua_State * L) { - internal_font_number f; - scaled s; - int k; - const char *cnom; if (lua_type(L, 1) == LUA_TSTRING) { - cnom = lua_tostring(L, 1); + const char *cnom = lua_tostring(L, 1); if (lua_type(L, 2) == LUA_TNUMBER) { - s = (int) lua_tonumber(L, 2); + scaled s = (int) lua_tointeger(L, 2); if (strlen(cnom)) { - f = get_fontid(); + internal_font_number f = get_fontid(); if (read_tfm_info(f, cnom, s)) { - k = font_to_lua(L, f); + int k = font_to_lua(L, f); delete_font(f); return k; } else { @@ -70,13 +66,11 @@ static int font_read_tfm(lua_State * L) static int font_read_vf(lua_State * L) { - int i; - const char *cnom; if (lua_type(L, 1) == LUA_TSTRING) { - cnom = lua_tostring(L, 1); + const char *cnom = lua_tostring(L, 1); if (strlen(cnom)) { if (lua_type(L, 2) == LUA_TNUMBER) { - i = (int) lua_tonumber(L, 2); + int i = lua_tointeger(L, 2); return make_vf_table(L, cnom, (scaled) i); } else { luaL_error(L, "expected an integer size as second argument"); @@ -90,8 +84,7 @@ static int font_read_vf(lua_State * L) static int tex_current_font(lua_State * L) { - int i; - i = (int) luaL_optinteger(L, 1, 0); + int i = luaL_optinteger(L, 1, 0); if (i > 0) { if (is_valid_font(i)) { zset_cur_font(i); @@ -101,23 +94,22 @@ static int tex_current_font(lua_State * L) return 2; /* not reached */ } } else { - lua_pushnumber(L, get_cur_font()); + lua_pushinteger(L, get_cur_font()); return 1; } } static int tex_max_font(lua_State * L) { - lua_pushnumber(L, max_font_id()); + lua_pushinteger(L, max_font_id()); return 1; } static int tex_each_font_next(lua_State * L) { - int i, m; /* id */ - m = (int) lua_tonumber(L, 1); - i = (int) lua_tonumber(L, 2); + int m = lua_tointeger(L, 1); + int i = lua_tointeger(L, 2); i++; while (i <= m && !is_valid_font(i)) i++; @@ -125,7 +117,7 @@ static int tex_each_font_next(lua_State * L) lua_pushnil(L); return 1; } else { - lua_pushnumber(L, i); + lua_pushinteger(L, i); if (!font_to_lua(L, i)) lua_pushnil(L); return 2; @@ -135,15 +127,14 @@ static int tex_each_font_next(lua_State * L) static int tex_each_font(lua_State * L) { lua_pushcclosure(L, tex_each_font_next, 0); - lua_pushnumber(L, max_font_id()); - lua_pushnumber(L, 0); + lua_pushinteger(L, max_font_id()); + lua_pushinteger(L, 0); return 3; } static int frozenfont(lua_State * L) { - int i; - i = (int) luaL_checkinteger(L, 1); + int i = luaL_checkinteger(L, 1); if (i) { if (is_valid_font(i)) { if (font_touched(i) || font_used(i)) { @@ -164,8 +155,7 @@ static int frozenfont(lua_State * L) static int setfont(lua_State * L) { - int i; - i = (int) luaL_checkinteger(L, -2); + int i = luaL_checkinteger(L, -2); if (i) { luaL_checktype(L, -1, LUA_TTABLE); if (is_valid_font(i)) { @@ -185,29 +175,10 @@ static int setfont(lua_State * L) static int deffont(lua_State * L) { - int i; -#if TIMERS - struct timeval tva; - struct timeval tvb; - double tvdiff; -#endif + int i = get_fontid(); luaL_checktype(L, -1, LUA_TTABLE); - i = get_fontid(); -#if TIMERS - gettimeofday(&tva, NULL); -#endif if (font_from_lua(L, i)) { -#if TIMERS - gettimeofday(&tvb, NULL); - tvdiff = tvb.tv_sec * 1000000.0; - tvdiff += (double) tvb.tv_usec; - tvdiff -= (tva.tv_sec * 1000000.0); - tvdiff -= (double) tva.tv_usec; - tvdiff /= 1000000; - fprintf(stdout, "font.define(%s,%i): %f seconds\n", - font_fullname(i), i, tvdiff); -#endif - lua_pushnumber(L, i); + lua_pushinteger(L, i); return 1; } else { lua_pop(L, 1); /* pop the broken table */ @@ -221,7 +192,7 @@ static int deffont(lua_State * L) static int nextfontid(lua_State * L) { int i = get_fontid(); - lua_pushnumber(L, i); + lua_pushinteger(L, i); delete_font(i); return 1; } @@ -229,8 +200,7 @@ static int nextfontid(lua_State * L) static int getfont(lua_State * L) { - int i; - i = (int) luaL_checkinteger(L, -1); + int i = luaL_checkinteger(L, -1); if (i && is_valid_font(i) && font_to_lua(L, i)) return 1; lua_pushnil(L); @@ -240,21 +210,18 @@ static int getfont(lua_State * L) static int getfontid(lua_State * L) { - const char *s; - size_t ff; - int cs; - int f; if (lua_type(L, 1) == LUA_TSTRING) { - s = lua_tolstring(L, 1, &ff); - cs = string_lookup(s, ff); - if (cs == undefined_control_sequence || cs == undefined_cs_cmd - || eq_type(cs) != set_font_cmd) { + size_t ff; + const char *s = lua_tolstring(L, 1, &ff); + int cs = string_lookup(s, ff); + int f; + if (cs == undefined_control_sequence || cs == undefined_cs_cmd || eq_type(cs) != set_font_cmd) { lua_pushstring(L, "not a valid font csname"); f = -1; } else { f = equiv(cs); } - lua_pushnumber(L, f); + lua_pushinteger(L, f); } else { luaL_error(L, "expected font csname string as argument"); } @@ -290,24 +257,23 @@ int luaopen_font(lua_State * L) static int l_vf_char(lua_State * L) { int k, w; - /*int ex = 0;*/ /* Wrong! TODO */ vf_struct *vsp = static_pdf->vfstruct; packet_stack_record *mat_p; internal_font_number lf = vsp->lf; int ex_glyph = vsp->ex_glyph/1000; if (!vsp->vflua) normal_error("vf", "vf.char() outside virtual font"); - k = (int) luaL_checkinteger(L, 1); - if (!char_exists(lf, (int) k)) { - char_warning(lf, (int) k); + k = luaL_checkinteger(L, 1); + if (!char_exists(lf, k)) { + char_warning(lf, k); } else { - if (has_packet(lf, (int) k)) - do_vf_packet(static_pdf, lf, (int) k, ex_glyph); + if (has_packet(lf, k)) + do_vf_packet(static_pdf, lf, k, ex_glyph); else - backend_out[glyph_node] (static_pdf, lf, (int) k, ex_glyph); + backend_out[glyph_node] (static_pdf, lf, k, ex_glyph); } mat_p = &(vsp->packet_stack[vsp->packet_stack_level]); - w = char_width(lf, (int) k); + w = char_width(lf, k); mat_p->pos.h += round_xn_over_d(w, 1000 + ex_glyph, 1000); synch_pos_with_cur(static_pdf->posstruct, vsp->refpos, mat_p->pos); return 0; @@ -355,7 +321,7 @@ static int l_vf_node(lua_State * L) if (!vsp->vflua) normal_error("vf", "vf.node() outside virtual font"); k = (int) luaL_checkinteger(L, 1); - hlist_out(static_pdf, (halfword) k); + hlist_out(static_pdf, (halfword) k, 0); return 0; } @@ -423,7 +389,7 @@ static int l_vf_rule(lua_State * L) size.h = store_scaled_f(size.h, vsp->fs_f); size.v = store_scaled_f(size.v, vsp->fs_f); if (size.h > 0 && size.v > 0) - pdf_place_rule(static_pdf, 0, size); /* the 0 is unused */ + backend_out[rule_node](static_pdf, 0, size); /* the 0 is unused */ mat_p = &(vsp->packet_stack[vsp->packet_stack_level]); mat_p->pos.h += size.h; synch_pos_with_cur(static_pdf->posstruct, vsp->refpos, mat_p->pos); diff --git a/Build/source/texk/web2c/luatexdir/lua/limglib.c b/Build/source/texk/web2c/luatexdir/lua/limglib.c index 5a1943b5245..22dc80e38d6 100644 --- a/Build/source/texk/web2c/luatexdir/lua/limglib.c +++ b/Build/source/texk/web2c/luatexdir/lua/limglib.c @@ -25,78 +25,9 @@ #include "lua.h" #include "lauxlib.h" -#define IMG_ENV "image.env" +#define img_types_max 7 -/**********************************************************************/ - -#ifdef DEBUG -void stackDump(lua_State * L, char *s) -{ - int i, t, top = lua_gettop(L); - printf("\n=== stackDump <%s>: ", s); - for (i = top; i >= 1; i--) { - t = lua_type(L, i); - printf("%d: ", i); - switch (t) { - case LUA_TSTRING: - printf("`%s'", lua_tostring(L, i)); - break; - case LUA_TBOOLEAN: - printf(lua_toboolean(L, i) ? "true" : "false"); - break; - case LUA_TNUMBER: - printf("%g", (double) lua_tonumber(L, i)); - break; - default: - printf("%s", lua_typename(L, t)); - break; - } - /* insert a separator */ - printf(" "); - } - printf("\n"); -} -#endif - -/**********************************************************************/ - -typedef enum { P__ZERO, P_ATTR, P_BBOX, P_COLORDEPTH, P_COLORSPACE, P_DEPTH, - P_FILENAME, P_FILEPATH, P_HEIGHT, P_IMAGETYPE, P_INDEX, P_OBJNUM, - P_PAGEBOX, P_PAGE, P_TOTALPAGES, P_ROTATION, P_STREAM, P_TRANSFORM, - P_VISIBLEFILENAME, P_WIDTH, P_XRES, P_XSIZE, P_YRES, P_YSIZE, P__SENTINEL -} parm_idx; - -static const parm_struct img_parms[] = { - {NULL, P__ZERO}, /* dummy; lua indices run from 1 */ - {"attr", P_ATTR}, - {"bbox", P_BBOX}, - {"colordepth", P_COLORDEPTH}, - {"colorspace", P_COLORSPACE}, - {"depth", P_DEPTH}, - {"filename", P_FILENAME}, - {"filepath", P_FILEPATH}, - {"height", P_HEIGHT}, - {"imagetype", P_IMAGETYPE}, - {"index", P_INDEX}, - {"objnum", P_OBJNUM}, - {"pagebox", P_PAGEBOX}, - {"page", P_PAGE}, - {"pages", P_TOTALPAGES}, - {"rotation", P_ROTATION}, - {"stream", P_STREAM}, - {"transform", P_TRANSFORM}, - {"visiblefilename", P_VISIBLEFILENAME}, - {"width", P_WIDTH}, - {"xres", P_XRES}, - {"xsize", P_XSIZE}, - {"yres", P_YRES}, - {"ysize", P_YSIZE}, - {NULL, P__SENTINEL} -}; - -#define imgtype_max 7 - -const char *imgtype_s[] = { +const char *img_types[] = { "none", "pdf", "png", @@ -108,368 +39,18 @@ const char *imgtype_s[] = { NULL }; -#define pagebox_max 5 - -const char *pdfboxspec_s[] = { - "none", - "media", - "crop", - "bleed", - "trim", - "art", - NULL -}; - -/**********************************************************************/ - -static void image_to_lua(lua_State * L, image * a) -{ /* key user ... */ - int i, j; - image_dict *d = img_dict(a); - assert(d != NULL); - lua_pushstring(L, IMG_ENV); /* s k u ... */ - lua_gettable(L, LUA_REGISTRYINDEX); /* t k u ... */ - lua_pushvalue(L, -2); /* k t k u ... */ - lua_gettable(L, -2); /* i? t k u ... */ - if (lua_type(L, -1) != LUA_TNUMBER) /* !i t k u ... */ - luaL_error(L, "image_to_lua(): %s is not a valid image key", lua_tostring(L, -3)); - i = (int) lua_tointeger(L, -1); /* i t k u ... */ - lua_pop(L, 3); /* u ... */ - switch (i) { - case P_WIDTH: - if (is_wd_running(a)) - lua_pushnil(L); - else - lua_pushinteger(L, img_width(a)); - break; - case P_HEIGHT: - if (is_ht_running(a)) - lua_pushnil(L); - else - lua_pushinteger(L, img_height(a)); - break; - case P_DEPTH: - if (is_dp_running(a)) - lua_pushnil(L); - else - lua_pushinteger(L, img_depth(a)); - break; - case P_TRANSFORM: - lua_pushinteger(L, img_transform(a)); - break; - /* now follow all image_dict entries */ - case P_FILENAME: - if (img_filename(d) == NULL || strlen(img_filename(d)) == 0) - lua_pushnil(L); - else - lua_pushstring(L, img_filename(d)); - break; - case P_VISIBLEFILENAME: - if (img_visiblefilename(d) == NULL - || strlen(img_visiblefilename(d)) == 0) - lua_pushnil(L); - else - lua_pushstring(L, img_visiblefilename(d)); - break; - case P_FILEPATH: - if (img_filepath(d) == NULL || strlen(img_filepath(d)) == 0) - lua_pushnil(L); - else - lua_pushstring(L, img_filepath(d)); - break; - case P_ATTR: - if (img_attr(d) == NULL || strlen(img_attr(d)) == 0) - lua_pushnil(L); - else - lua_pushstring(L, img_attr(d)); - break; - case P_PAGE: - if (img_pagename(d) != NULL && strlen(img_pagename(d)) != 0) - lua_pushstring(L, img_pagename(d)); - else - lua_pushinteger(L, img_pagenum(d)); - break; - case P_TOTALPAGES: - lua_pushinteger(L, img_totalpages(d)); - break; - case P_XSIZE: /* Modify by /Rotate only for output */ - if ((img_rotation(d) & 1) == 0) - lua_pushinteger(L, img_xsize(d)); - else - lua_pushinteger(L, img_ysize(d)); - break; - case P_YSIZE: /* Modify by /Rotate only for output */ - if ((img_rotation(d) & 1) == 0) - lua_pushinteger(L, img_ysize(d)); - else - lua_pushinteger(L, img_xsize(d)); - break; - case P_XRES: - lua_pushinteger(L, img_xres(d)); - break; - case P_YRES: - lua_pushinteger(L, img_yres(d)); - break; - case P_ROTATION: - lua_pushinteger(L, img_rotation(d)); - break; - case P_COLORSPACE: - if (img_colorspace(d) == 0) - lua_pushnil(L); - else - lua_pushinteger(L, img_colorspace(d)); - break; - case P_COLORDEPTH: - if (img_colordepth(d) == 0) - lua_pushnil(L); - else - lua_pushinteger(L, img_colordepth(d)); - break; - case P_IMAGETYPE: - j = img_type(d); - if (j >= 0 && j <= imgtype_max) { - if (j == IMG_TYPE_NONE) - lua_pushnil(L); - else - lua_pushstring(L, imgtype_s[j]); - } else - assert(0); - break; - case P_PAGEBOX: - j = img_pagebox(d); - if (j >= 0 && j <= pagebox_max) { - if (j == PDF_BOX_SPEC_NONE) - lua_pushnil(L); - else - lua_pushstring(L, pdfboxspec_s[j]); - } else - assert(0); - break; - case P_BBOX: - if (!img_is_bbox(d)) { - img_bbox(d)[0] = img_xorig(d); - img_bbox(d)[1] = img_yorig(d); - img_bbox(d)[2] = img_xorig(d) + img_xsize(d); - img_bbox(d)[3] = img_yorig(d) + img_ysize(d); - } - lua_newtable(L); - lua_pushinteger(L, 1); - lua_pushinteger(L, img_bbox(d)[0]); - lua_settable(L, -3); - lua_pushinteger(L, 2); - lua_pushinteger(L, img_bbox(d)[1]); - lua_settable(L, -3); - lua_pushinteger(L, 3); - lua_pushinteger(L, img_bbox(d)[2]); - lua_settable(L, -3); - lua_pushinteger(L, 4); - lua_pushinteger(L, img_bbox(d)[3]); - lua_settable(L, -3); - break; - case P_OBJNUM: - if (img_objnum(d) == 0) - lua_pushnil(L); - else - lua_pushinteger(L, img_objnum(d)); - break; - case P_INDEX: - if (img_index(d) == 0) - lua_pushnil(L); - else - lua_pushinteger(L, img_index(d)); - break; - case P_STREAM: - if (img_type(d) != IMG_TYPE_PDFSTREAM || img_pdfstream_ptr(d) == NULL - || img_pdfstream_stream(d) == NULL - || strlen(img_pdfstream_stream(d)) == 0) - lua_pushnil(L); - else - lua_pushstring(L, img_pdfstream_stream(d)); - break; - default: - assert(0); - } /* v u ... */ -} - -static void lua_to_image(lua_State * L, image * a) -{ /* value key table ... */ - int i; - image_dict *d = img_dict(a); - assert(d != NULL); - lua_pushstring(L, IMG_ENV); /* s v k t ... */ - lua_gettable(L, LUA_REGISTRYINDEX); /* t v k t ... */ - lua_pushvalue(L, -3); /* k t v k t ... */ - lua_gettable(L, -2); /* i? t v k t ... */ - if (lua_type(L, -1) != LUA_TNUMBER) /* !i t v k t ... */ - luaL_error(L, "lua_to_image(): %s is not a valid image key", lua_tostring(L, -4)); - i = (int) lua_tointeger(L, -1); /* i t v k t ... */ - lua_pop(L, 2); /* v k t ... */ - switch (i) { - case P_WIDTH: - if (lua_isnil(L, -1)) - set_wd_running(a); - else if (lua_type(L, -1) == LUA_TNUMBER) - img_width(a) = (int) lua_tointeger(L, -1); - else if (lua_type(L, -1) == LUA_TSTRING) - img_width(a) = dimen_to_number(L, lua_tostring(L, -1)); - else - luaL_error(L, "image.width needs integer or nil value or dimension string"); - break; - case P_HEIGHT: - if (lua_isnil(L, -1)) - set_ht_running(a); - else if (lua_type(L, -1) == LUA_TNUMBER) - img_height(a) = (int) lua_tointeger(L, -1); - else if (lua_type(L, -1) == LUA_TSTRING) - img_height(a) = dimen_to_number(L, lua_tostring(L, -1)); - else - luaL_error(L, "image.height needs integer or nil value or dimension string"); - break; - case P_DEPTH: - if (lua_isnil(L, -1)) - set_dp_running(a); - else if (lua_type(L, -1) == LUA_TNUMBER) - img_depth(a) = (int) lua_tointeger(L, -1); - else if (lua_type(L, -1) == LUA_TSTRING) - img_depth(a) = dimen_to_number(L, lua_tostring(L, -1)); - else - luaL_error(L, "image.depth needs integer or nil value or dimension string"); - break; - case P_TRANSFORM: - if (lua_type(L, -1) == LUA_TNUMBER) - img_transform(a) = (int) lua_tointeger(L, -1); - else - luaL_error(L, "image.transform needs integer value"); - break; - /* now follow all image_dict entries */ - case P_FILENAME: - if (img_state(d) >= DICT_FILESCANNED) - luaL_error(L, "image.filename is now read-only"); - if (img_type(d) == IMG_TYPE_PDFSTREAM) - luaL_error(L, "image.filename can't be used with image.stream"); - if (lua_type(L, -1) == LUA_TSTRING) { - xfree(img_filename(d)); - img_filename(d) = xstrdup(lua_tostring(L, -1)); - } else - luaL_error(L, "image.filename needs string value"); - break; - case P_VISIBLEFILENAME: - if (img_state(d) >= DICT_FILESCANNED) - luaL_error(L, "image.visiblefilename is now read-only"); - if (img_type(d) == IMG_TYPE_PDFSTREAM) - luaL_error(L, "image.visiblefilename can't be used with image.stream"); - if (lua_type(L, -1) == LUA_TSTRING) { - xfree(img_visiblefilename(d)); - img_visiblefilename(d) = xstrdup(lua_tostring(L, -1)); - } else - luaL_error(L, "image.visiblefilename needs string value"); - break; - case P_ATTR: - if (img_state(d) >= DICT_FILESCANNED) - luaL_error(L, "image.attr is now read-only"); - if (lua_type(L, -1) == LUA_TSTRING) { - xfree(img_attr(d)); - img_attr(d) = xstrdup(lua_tostring(L, -1)); - } else if (lua_type(L, -1) == LUA_TNIL) { - xfree(img_attr(d)); - } else - luaL_error(L, "image.attr needs string or nil value"); - break; - case P_PAGE: - if (img_state(d) >= DICT_FILESCANNED) - luaL_error(L, "image.page is now read-only"); - if (lua_type(L, -1) == LUA_TSTRING) { - xfree(img_pagename(d)); - img_pagename(d) = xstrdup(lua_tostring(L, -1)); - img_pagenum(d) = 0; - } else if (lua_type(L, -1) == LUA_TNUMBER) { - img_pagenum(d) = (int) lua_tointeger(L, -1); - xfree(img_pagename(d)); - } else - luaL_error(L, "image.page needs integer or string value"); - break; - case P_COLORSPACE: - if (img_state(d) >= DICT_FILESCANNED) - luaL_error(L, "image.colorspace is now read-only"); - if (lua_isnil(L, -1)) - img_colorspace(d) = 0; - else if (lua_type(L, -1) == LUA_TNUMBER) - img_colorspace(d) = (int) lua_tointeger(L, -1); - else - luaL_error(L, "image.colorspace needs integer or nil value"); - break; - case P_PAGEBOX: - if (img_state(d) >= DICT_FILESCANNED) - luaL_error(L, "image.pagebox is now read-only"); - if (lua_type(L, -1) == LUA_TNIL) - img_pagebox(d) = PDF_BOX_SPEC_NONE; - else if (lua_type(L, -1) == LUA_TSTRING) - img_pagebox(d) = luaL_checkoption(L, -1, "none", pdfboxspec_s); - else - luaL_error(L, "image.pagebox needs string or nil value"); - break; - case P_BBOX: - if (img_state(d) >= DICT_FILESCANNED) - luaL_error(L, "image.bbox is now read-only"); - if (!lua_istable(L, -1)) - luaL_error(L, "image.bbox needs table value"); - if (lua_rawlen(L, -1) != 4) - luaL_error(L, "image.bbox table must have exactly 4 elements"); - for (i = 1; i <= 4; i++) { /* v k t ... */ - lua_pushinteger(L, i); /* idx v k t ... */ - lua_gettable(L, -2); /* int v k t ... */ - if (lua_type(L, -1) == LUA_TNUMBER) - img_bbox(d)[i - 1] = (int) lua_tointeger(L, -1); - else if (lua_type(L, -1) == LUA_TSTRING) - img_bbox(d)[i - 1] = dimen_to_number(L, lua_tostring(L, -1)); - else - luaL_error(L, "image.bbox table needs integer value or dimension string elements"); - lua_pop(L, 1); /* v k t ... */ - } - img_set_bbox(d); - break; - case P_STREAM: - if (img_filename(d) != NULL) - luaL_error(L, "image.stream can't be used with image.filename"); - if (img_state(d) >= DICT_FILESCANNED) - luaL_error(L, "image.stream is now read-only"); - if (img_pdfstream_ptr(d) == NULL) - new_img_pdfstream_struct(d); - xfree(img_pdfstream_stream(d)); - img_pdfstream_stream(d) = xstrdup(lua_tostring(L, -1)); - img_type(d) = IMG_TYPE_PDFSTREAM; - break; - case P_FILEPATH: - case P_TOTALPAGES: - case P_XSIZE: - case P_YSIZE: - case P_XRES: - case P_YRES: - case P_ROTATION: - case P_IMAGETYPE: - case P_OBJNUM: - case P_INDEX: - case P_COLORDEPTH: - luaL_error(L, "image.%s is a read-only variable", img_parms[i].name); - break; - default: - assert(0); - } /* v k t ... */ -} - -/**********************************************************************/ - static void copy_image(lua_State * L, lua_Number scale) { image *a, **aa, *b, **bb; - if (lua_gettop(L) != 1) - luaL_error(L, "img.copy() needs exactly 1 argument"); - aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); /* a */ - lua_pop(L, 1); /* - */ + image_dict *d; + if (lua_gettop(L) == 0) + luaL_error(L, "img.copy needs an image as argument"); + aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); /* a */ + lua_pop(L, 1); /* - */ a = *aa; - bb = (image **) lua_newuserdata(L, sizeof(image *)); /* b */ - luaL_getmetatable(L, TYPE_IMG); /* m b */ - lua_setmetatable(L, -2); /* b */ + bb = (image **) lua_newuserdata(L, sizeof(image *)); /* b */ + luaL_getmetatable(L, TYPE_IMG); /* m b */ + lua_setmetatable(L, -2); /* b */ b = *bb = new_image(); if (!is_wd_running(a)) img_width(b) = do_zround(img_width(a) * scale); @@ -480,101 +61,115 @@ static void copy_image(lua_State * L, lua_Number scale) img_transform(b) = img_transform(a); img_dict(b) = img_dict(a); if (img_dictref(a) != LUA_NOREF) { - lua_rawgeti(L, LUA_REGISTRYINDEX, img_dictref(a)); /* ad b */ - img_dictref(b) = luaL_ref(L, LUA_REGISTRYINDEX); /* b */ + lua_rawgeti(L, LUA_REGISTRYINDEX, img_dictref(a)); /* ad b */ + img_dictref(b) = luaL_ref(L, LUA_REGISTRYINDEX); /* b */ + d = img_dict(*aa); + img_luaref(d) += 1; } else assert(img_state(img_dict(a)) >= DICT_REFERED); } -/**********************************************************************/ +static void lua_to_image(lua_State * L, image * a, image_dict * d); int l_new_image(lua_State * L) { image *a, **aa; image_dict **add; - if (lua_gettop(L) > 1) - luaL_error(L, "img.new() needs maximum 1 argument"); - if (lua_gettop(L) == 1 && !lua_istable(L, -1)) - luaL_error(L, "img.new() needs table as optional argument"); /* (t) */ - aa = (image **) lua_newuserdata(L, sizeof(image *)); /* i (t) */ - luaL_getmetatable(L, TYPE_IMG); /* m i (t) */ - lua_setmetatable(L, -2); /* i (t) */ + if (lua_gettop(L) > 0 && ! lua_istable(L, -1)) + luaL_error(L, "img.new needs table as optional argument"); /* (t) */ + aa = (image **) lua_newuserdata(L, sizeof(image *)); /* i (t) */ + luaL_getmetatable(L, TYPE_IMG); /* m i (t) */ + lua_setmetatable(L, -2); /* i (t) */ a = *aa = new_image(); - add = (image_dict **) lua_newuserdata(L, sizeof(image_dict *)); /* ad i (t) */ - luaL_getmetatable(L, TYPE_IMG_DICT); /* m ad i (t) */ - lua_setmetatable(L, -2); /* ad i (t) */ + add = (image_dict **) lua_newuserdata(L, sizeof(image_dict *)); /* ad i (t) */ + luaL_getmetatable(L, TYPE_IMG_DICT); /* m ad i (t) */ + lua_setmetatable(L, -2); /* ad i (t) */ img_dict(a) = *add = new_image_dict(); - img_dictref(a) = luaL_ref(L, LUA_REGISTRYINDEX); /* i (t) */ - if (lua_gettop(L) == 2) { /* i t, else just i */ - lua_insert(L, -2); /* t i */ - lua_pushnil(L); /* n t i (1st key for iterator) */ - while (lua_next(L, -2) != 0) { /* v k t i */ - lua_to_image(L, a); /* v k t i */ - lua_pop(L, 1); /* k t i */ - } /* t i */ - lua_pop(L, 1); /* i */ - } /* i */ - return 1; /* i */ + img_dictref(a) = luaL_ref(L, LUA_REGISTRYINDEX); /* i (t) */ + img_luaref(*add) += 1; + if (lua_gettop(L) == 2) { /* i t, else just i */ + lua_insert(L, -2); /* t i */ + lua_pushnil(L); /* n t i (1st key for iterator) */ + while (lua_next(L, -2) != 0) { /* v k t i */ + lua_to_image(L, a, *add); /* v k t i */ + lua_pop(L, 1); /* k t i */ + } /* t i */ + lua_pop(L, 1); /* i */ + } /* i */ + return 1; /* i */ } static int l_copy_image(lua_State * L) { - if (lua_gettop(L) != 1) - luaL_error(L, "img.copy() needs exactly 1 argument"); - if (lua_istable(L, 1)) - (void) l_new_image(L); /* image --- if everything worked well */ - else - (void) copy_image(L, 1.0); /* image */ - return 1; /* image */ + if (lua_gettop(L) != 1) { + luaL_error(L, "img.copy needs an image as argument"); + } else if (lua_istable(L, 1)) { + (void) l_new_image(L); + } else { + (void) copy_image(L, 1.0); + } + return 1; } static void read_scale_img(image * a) { image_dict *ad; - assert(a != NULL); - ad = img_dict(a); - assert(ad != NULL); - if (img_state(ad) == DICT_NEW) { - if (img_type(ad) == IMG_TYPE_PDFSTREAM) - check_pdfstream_dict(ad); - else { - fix_pdf_minorversion(static_pdf); - read_img(static_pdf, ad, pdf_minor_version, pdf_inclusion_errorlevel); + if (a == NULL) { + luaL_error(Luas, "the image scaler needs a valid image"); + } else { + ad = img_dict(a); + if (a == NULL) { + luaL_error(Luas, "the image scaler needs a valid dictionary"); + } else { + if (img_state(ad) == DICT_NEW) { + if (img_type(ad) == IMG_TYPE_PDFSTREAM) + check_pdfstream_dict(ad); + else { + read_img(ad); + } + } + if (is_wd_running(a) || is_ht_running(a) || is_dp_running(a)) { + img_dimen(a) = scale_img(ad, img_dimen(a), img_transform(a)); + } } } - if (is_wd_running(a) || is_ht_running(a) || is_dp_running(a)) - img_dimen(a) = scale_img(ad, img_dimen(a), img_transform(a)); } static int l_scan_image(lua_State * L) { image *a, **aa; if (lua_gettop(L) != 1) - luaL_error(L, "img.scan() needs exactly 1 argument"); + luaL_error(L, "img.scan needs exactly 1 argument"); if (lua_istable(L, 1)) - (void) l_new_image(L); /* image --- if everything worked well */ - aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); /* image */ + (void) l_new_image(L); + aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); a = *aa; - check_o_mode(static_pdf, "img.scan()", 1 << OMODE_PDF, false); - /* flush_str(last_tex_string); *//* ?? */ + check_o_mode(static_pdf, "img.scan", 1 << OMODE_PDF, false); read_scale_img(a); - return 1; /* image */ + return 1; } -static halfword img_to_node(image * a) +static halfword img_to_node(lua_State * L, image * a) { image_dict *ad; - halfword n; - assert(a != NULL); - ad = img_dict(a); - assert(ad != NULL); - assert(img_objnum(ad) != 0); - n = new_rule(image_rule); - rule_index(n) = img_index(ad); - width(n) = img_width(a); - height(n) = img_height(a); - depth(n) = img_depth(a); - rule_transform(n) = img_transform(a); + halfword n = null; + if (a == NULL) { + luaL_error(L, "img.tonode needs a valid image"); + } else { + ad = img_dict(a); + if (a == NULL) { + luaL_error(L, "img.tonode image has no dictionary"); + } else if (img_objnum(ad) == 0) { + luaL_error(L, "img.tonode got image without object number"); + } else { + n = new_rule(image_rule); + rule_index(n) = img_index(ad); + width(n) = img_width(a); + height(n) = img_height(a); + depth(n) = img_depth(a); + rule_transform(n) = img_transform(a); + } + } return n; } @@ -586,22 +181,25 @@ typedef enum { } wrtype_e; const char *wrtype_s[] = { - "img.write()", "img.immediatewrite()", "img.node()", "write vf image" + "img.write()", + "img.immediatewrite()", + "img.node()", + "write vf image" }; static void setup_image(PDF pdf, image * a, wrtype_e writetype) { image_dict *ad; - assert(a != NULL); + if (a == NULL) + luaL_error(Luas, "no valid image passed"); /* todo, also check in caller */ ad = img_dict(a); check_o_mode(pdf, wrtype_s[writetype], 1 << OMODE_PDF, false); - /* flush_str(last_tex_string); *//* ?? */ read_scale_img(a); - if (img_objnum(ad) == 0) { /* latest needed just before out_img() */ + if (img_objnum(ad) == 0) { /* latest needed just before out_img() */ pdf->ximage_count++; img_objnum(ad) = pdf_create_obj(pdf, obj_type_ximage, pdf->ximage_count); img_index(ad) = pdf->ximage_count; - idict_to_array(ad); /* now ad is read-only */ + idict_to_array(ad); /* from now on ad is read-only */ obj_data_ptr(pdf, pdf->obj_ptr) = img_index(ad); } } @@ -612,28 +210,28 @@ static void write_image_or_node(lua_State * L, wrtype_e writetype) image_dict *ad; halfword n; if (lua_gettop(L) != 1) - luaL_error(L, "%s needs exactly 1 argument", wrtype_s[writetype]); + luaL_error(L, "%s expects an argument", wrtype_s[writetype]); if (lua_istable(L, 1)) - (void) l_new_image(L); /* image --- if everything worked well */ - aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); /* image */ + (void) l_new_image(L); + aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); a = *aa; ad = img_dict(a); setup_image(static_pdf, a, writetype); switch (writetype) { - case WR_WRITE: - n = img_to_node(a); - tail_append(n); - break; /* image */ - case WR_IMMEDIATEWRITE: - write_img(static_pdf, ad); - break; /* image */ - case WR_NODE: /* image */ - lua_pop(L, 1); /* - */ - n = img_to_node(a); - lua_nodelib_push_fast(L, n); - break; /* node */ - default: - assert(0); + case WR_WRITE: + n = img_to_node(L, a); + tail_append(n); + break; + case WR_IMMEDIATEWRITE: + write_img(static_pdf, ad); + break; + case WR_NODE: + lua_pop(L, 1); /* - */ + n = img_to_node(L, a); + lua_nodelib_push_fast(L, n); + break; + default: + assert(0); } if (img_state(ad) < DICT_REFERED) img_state(ad) = DICT_REFERED; @@ -642,129 +240,429 @@ static void write_image_or_node(lua_State * L, wrtype_e writetype) static int l_write_image(lua_State * L) { write_image_or_node(L, WR_WRITE); - return 1; /* image */ + return 1; } static int l_immediatewrite_image(lua_State * L) { - check_o_mode(static_pdf, "img.immediatewrite()", 1 << OMODE_PDF, true); + check_o_mode(static_pdf, "img.immediatewrite", 1 << OMODE_PDF, true); if (global_shipping_mode != NOT_SHIPPING) { - luaL_error(L, "pdf.immediatewrite() can not be used with \\latelua"); + luaL_error(L, "img.immediatewrite can not be used with \\latelua"); } else { write_image_or_node(L, WR_IMMEDIATEWRITE); } - return 1; /* image */ + return 1; } static int l_image_node(lua_State * L) { write_image_or_node(L, WR_NODE); - return 1; /* node */ + return 1; } static int l_image_keys(lua_State * L) { - const parm_struct *p = img_parms + 1; - if (lua_gettop(L) != 0) - luaL_error(L, "img.keys() goes without argument"); - lua_newtable(L); /* t */ - for (; p->name != NULL; p++) { - lua_pushinteger(L, (int) p->idx); /* k t */ - lua_pushstring(L, p->name); /* v k t */ - lua_settable(L, -3); /* t */ - } - return 1; + return lua_show_valid_keys(L, img_parms, img_parms_max); } static int l_image_types(lua_State * L) { - int i; - const char **p; - if (lua_gettop(L) != 0) - luaL_error(L, "img.types() goes without argument"); - lua_newtable(L); /* t */ - for (i = 1, p = (const char **) (imgtype_s + 1); *p != NULL; p++, i++) { - lua_pushinteger(L, (int) i); /* k t */ - lua_pushstring(L, *p); /* v k t */ - lua_settable(L, -3); /* t */ - } - return 1; + return lua_show_valid_list(L, img_types, img_types_max); } static int l_image_boxes(lua_State * L) { - int i; - const char **p; - if (lua_gettop(L) != 0) - luaL_error(L, "img.boxes() goes without argument"); - lua_newtable(L); /* t */ - for (i = 1, p = (const char **) (pdfboxspec_s + 1); *p != NULL; p++, i++) { - lua_pushinteger(L, (int) i); /* k t */ - lua_pushstring(L, *p); /* v k t */ - lua_settable(L, -3); /* t */ - } - return 1; + return lua_show_valid_keys(L, img_pageboxes, img_pageboxes_max); } static const struct luaL_Reg imglib_f[] = { - {"new", l_new_image}, - {"copy", l_copy_image}, - {"scan", l_scan_image}, - {"write", l_write_image}, - {"immediatewrite", l_immediatewrite_image}, - {"node", l_image_node}, - {"keys", l_image_keys}, - {"types", l_image_types}, - {"boxes", l_image_boxes}, - {NULL, NULL} /* sentinel */ + { "new", l_new_image }, + { "copy", l_copy_image }, + { "scan", l_scan_image }, + { "write", l_write_image }, + { "immediatewrite", l_immediatewrite_image }, + { "node", l_image_node }, + { "keys", l_image_keys }, + { "types", l_image_types }, + { "boxes", l_image_boxes }, + { NULL, NULL } }; -/**********************************************************************/ - void vf_out_image(PDF pdf, unsigned i) { image *a, **aa; image_dict *ad; - lua_State *L = Luas; /* ... */ - lua_rawgeti(L, LUA_REGISTRYINDEX, (int) i); /* image ... */ + lua_State *L = Luas; + lua_rawgeti(L, LUA_REGISTRYINDEX, (int) i); aa = (image **) luaL_checkudata(L, -1, TYPE_IMG); a = *aa; ad = img_dict(a); assert(ad != NULL); - setup_image(pdf, a, WR_VF_IMG); /* image ... */ + setup_image(pdf, a, WR_VF_IMG); place_img(pdf, ad, img_dimen(a), img_transform(a)); - lua_pop(L, 1); /* ... */ + lua_pop(L, 1); } -/**********************************************************************/ -/* Metamethods for image */ +/* metamethods for image */ static int m_img_get(lua_State * L) { - image **aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); /* k u */ - image_to_lua(L, *aa); /* v u */ + int j; + const char *s; + image **a = (image **) luaL_checkudata(L, 1, TYPE_IMG); /* k u */ + image_dict *d = img_dict(*a); + if (d == NULL) { + luaL_error(L, "invalid image dictionary"); + } + s = lua_tostring(L, 2); + if (lua_key_eq(s,width)) { + if (is_wd_running(*a)) { + lua_pushnil(L); + } else { + lua_pushinteger(L, img_width(*a)); + } + } else if (lua_key_eq(s,height)) { + if (is_ht_running(*a)) { + lua_pushnil(L); + } else { + lua_pushinteger(L, img_height(*a)); + } + } else if (lua_key_eq(s,depth)) { + if (is_dp_running(*a)) { + lua_pushnil(L); + } else { + lua_pushinteger(L, img_depth(*a)); + } + } else if (lua_key_eq(s,transform)) { + lua_pushinteger(L, img_transform(*a)); + } else if (lua_key_eq(s,filename)) { + if (img_filename(d) == NULL || strlen(img_filename(d)) == 0) { + lua_pushnil(L); + } else { + lua_pushstring(L, img_filename(d)); + } + } else if (lua_key_eq(s,visiblefilename)) { + if (img_visiblefilename(d) == NULL || strlen(img_visiblefilename(d)) == 0) { + lua_pushnil(L); + } else { + lua_pushstring(L, img_visiblefilename(d)); + } + } else if (lua_key_eq(s,keepopen)) { + lua_pushboolean(L, img_keepopen(d)); + } else if (lua_key_eq(s,filepath)) { + if (img_filepath(d) == NULL || strlen(img_filepath(d)) == 0) { + lua_pushnil(L); + } else { + lua_pushstring(L, img_filepath(d)); + } + } else if (lua_key_eq(s,attr)) { + if (img_attr(d) == NULL || strlen(img_attr(d)) == 0) { + lua_pushnil(L); + } else { + lua_pushstring(L, img_attr(d)); + } + } else if (lua_key_eq(s,page)) { + if (img_pagename(d) != NULL && strlen(img_pagename(d)) != 0) { + lua_pushstring(L, img_pagename(d)); + } else { + lua_pushinteger(L, img_pagenum(d)); + } + } else if (lua_key_eq(s,pages)) { + lua_pushinteger(L, img_totalpages(d)); + } else if (lua_key_eq(s,xsize)) { + if ((img_rotation(d) & 1) == 0) { + lua_pushinteger(L, img_xsize(d)); + } else { + lua_pushinteger(L, img_ysize(d)); + } + } else if (lua_key_eq(s,ysize)) { + if ((img_rotation(d) & 1) == 0) { + lua_pushinteger(L, img_ysize(d)); + } else { + lua_pushinteger(L, img_xsize(d)); + } + } else if (lua_key_eq(s,xres)) { + lua_pushinteger(L, img_xres(d)); + } else if (lua_key_eq(s,yres)) { + lua_pushinteger(L, img_yres(d)); + } else if (lua_key_eq(s,rotation)) { + lua_pushinteger(L, img_rotation(d)); + } else if (lua_key_eq(s,colorspace)) { + if (img_colorspace(d) == 0) { + lua_pushnil(L); + } else { + lua_pushinteger(L, img_colorspace(d)); + } + } else if (lua_key_eq(s,colordepth)) { + if (img_colordepth(d) == 0) { + lua_pushnil(L); + } else { + lua_pushinteger(L, img_colordepth(d)); + } + } else if (lua_key_eq(s,imagetype)) { + j = img_type(d); + if (j >= 0 && j <= img_types_max) { + if (j == IMG_TYPE_NONE) { + lua_pushnil(L); + } else { + lua_pushstring(L, img_types[j]); + } + } else { + lua_pushnil(L); + } + } else if (lua_key_eq(s,pagebox)) { + j = img_pagebox(d); + if (j < 0 || j >= img_pageboxes_max) { + j = 0; + } + lua_push_img_pagebox(L, j); + } else if (lua_key_eq(s,bbox)) { + if (!img_is_bbox(d)) { + img_bbox(d)[0] = img_xorig(d); + img_bbox(d)[1] = img_yorig(d); + img_bbox(d)[2] = img_xorig(d) + img_xsize(d); + img_bbox(d)[3] = img_yorig(d) + img_ysize(d); + } + lua_newtable(L); + lua_pushinteger(L, 1); + lua_pushinteger(L, img_bbox(d)[0]); + lua_settable(L, -3); + lua_pushinteger(L, 2); + lua_pushinteger(L, img_bbox(d)[1]); + lua_settable(L, -3); + lua_pushinteger(L, 3); + lua_pushinteger(L, img_bbox(d)[2]); + lua_settable(L, -3); + lua_pushinteger(L, 4); + lua_pushinteger(L, img_bbox(d)[3]); + lua_settable(L, -3); + } else if (lua_key_eq(s,objnum)) { + if (img_objnum(d) == 0) { + lua_pushnil(L); + } else { + lua_pushinteger(L, img_objnum(d)); + } + } else if (lua_key_eq(s,index)) { + if (img_index(d) == 0) { + lua_pushnil(L); + } else { + lua_pushinteger(L, img_index(d)); + } + } else if (lua_key_eq(s,stream)) { + if (img_type(d) != IMG_TYPE_PDFSTREAM + || img_pdfstream_ptr(d) == NULL + || img_pdfstream_stream(d) == NULL + || strlen(img_pdfstream_stream(d)) == 0) { + lua_pushnil(L); + } else { + lua_pushstring(L, img_pdfstream_stream(d)); + } + } else if (lua_key_eq(s,ref_count)) { + lua_pushinteger(L, img_luaref(d)); + } else { + lua_pushnil(L); + } return 1; } +static void lua_to_image(lua_State * L, image * a, image_dict * d) +{ + int i, t; + const char *s; + s = lua_tostring(L,-2); + t = lua_type(L, -1); + if (lua_key_eq(s,width)) { + if (t == LUA_TNIL) { + set_wd_running(a); + } else if (t == LUA_TNUMBER) { + img_width(a) = (int) lua_tointeger(L, -1); + } else if (t == LUA_TSTRING) { + img_width(a) = dimen_to_number(L, lua_tostring(L, -1)); + } else { + luaL_error(L, "image.width needs integer or nil value or dimension string"); + } + } else if (lua_key_eq(s,height)) { + if (t == LUA_TNIL) { + set_ht_running(a); + } else if (t == LUA_TNUMBER) { + img_height(a) = (int) lua_tointeger(L, -1); + } else if (t == LUA_TSTRING) { + img_height(a) = dimen_to_number(L, lua_tostring(L, -1)); + } else { + luaL_error(L, "image.height needs integer or nil value or dimension string"); + } + } else if (lua_key_eq(s,depth)) { + if (t == LUA_TNIL) { + set_dp_running(a); + } else if (t == LUA_TNUMBER) { + img_depth(a) = (int) lua_tointeger(L, -1); + } else if (t == LUA_TSTRING) { + img_depth(a) = dimen_to_number(L, lua_tostring(L, -1)); + } else { + luaL_error(L, "image.depth needs integer or nil value or dimension string"); + } + } else if (lua_key_eq(s,transform)) { + if (t == LUA_TNUMBER) { + img_transform(a) = (int) lua_tointeger(L, -1); + } else { + luaL_error(L, "image.transform needs integer value"); + } + } else if (lua_key_eq(s,filename)) { + if (img_state(d) >= DICT_FILESCANNED) { + luaL_error(L, "image.filename is now read-only"); + } else if (img_type(d) == IMG_TYPE_PDFSTREAM) { + luaL_error(L, "image.filename can't be used with image.stream"); + } else if (t == LUA_TSTRING) { + xfree(img_filename(d)); + img_filename(d) = xstrdup(lua_tostring(L, -1)); + } else { + luaL_error(L, "image.filename needs string value"); + } + } else if (lua_key_eq(s,visiblefilename)) { + if (img_state(d) >= DICT_FILESCANNED) { + luaL_error(L, "image.visiblefilename is now read-only"); + } else if (img_type(d) == IMG_TYPE_PDFSTREAM) { + luaL_error(L, "image.visiblefilename can't be used with image.stream"); + } else if (t == LUA_TSTRING) { + xfree(img_visiblefilename(d)); + img_visiblefilename(d) = xstrdup(lua_tostring(L, -1)); + } else { + luaL_error(L, "image.visiblefilename needs string value"); + } + } else if (lua_key_eq(s,attr)) { + if (img_state(d) >= DICT_FILESCANNED) { + luaL_error(L, "image.attr is now read-only"); + } else if (t == LUA_TSTRING) { + xfree(img_attr(d)); + img_attr(d) = xstrdup(lua_tostring(L, -1)); + } else if (t == LUA_TNIL) { + xfree(img_attr(d)); + } else { + luaL_error(L, "image.attr needs string or nil value"); + } + } else if (lua_key_eq(s,page)) { + if (img_state(d) >= DICT_FILESCANNED) { + luaL_error(L, "image.page is now read-only"); + } else if (t == LUA_TSTRING) { + xfree(img_pagename(d)); + img_pagename(d) = xstrdup(lua_tostring(L, -1)); + img_pagenum(d) = 0; + } else if (t == LUA_TNUMBER) { + img_pagenum(d) = (int) lua_tointeger(L, -1); + xfree(img_pagename(d)); + } else { + luaL_error(L, "image.page needs integer or string value"); + } + } else if (lua_key_eq(s,colorspace)) { + if (img_state(d) >= DICT_FILESCANNED) { + luaL_error(L, "image.colorspace is now read-only"); + } else if (t == LUA_TNIL) { + img_colorspace(d) = 0; + } else if (t == LUA_TNUMBER) { + img_colorspace(d) = (int) lua_tointeger(L, -1); + } else { + luaL_error(L, "image.colorspace needs integer or nil value"); + } + } else if (lua_key_eq(s,pagebox)) { + if (img_state(d) >= DICT_FILESCANNED) { + luaL_error(L, "image.pagebox is now read-only"); + } else if (t == LUA_TNIL) { + img_pagebox(d) = PDF_BOX_SPEC_MEDIA; + } else if (t == LUA_TNUMBER) { + i = lua_tointeger(L,-1); + if (i < 0 || i >= img_pageboxes_max) { + img_pagebox(d) = PDF_BOX_SPEC_MEDIA; + } else { + img_pagebox(d) = i; + } + } else if (t == LUA_TSTRING) { + img_pagebox(d) = PDF_BOX_SPEC_MEDIA; + for (i = 0; i < img_pageboxes_max; i++) { + lua_rawgeti(L, LUA_REGISTRYINDEX, img_pageboxes[i]); + if (lua_rawequal(L,-1,-2)) { + img_pagebox(d) = i; + lua_pop(L, 1); + break; + } else { + lua_pop(L, 1); + } + } + } else { + luaL_error(L, "image.pagebox needs string, number or nil value"); + } + } else if (lua_key_eq(s,keepopen)) { + if (img_state(d) >= DICT_FILESCANNED) { + luaL_error(L, "image.keepopen is now read-only"); + } else if (t != LUA_TBOOLEAN) { + luaL_error(L, "image.bbox needs boolean value"); + } else { + img_keepopen(d) = lua_toboolean(L, -1); + } + } else if (lua_key_eq(s,bbox)) { + if (img_state(d) >= DICT_FILESCANNED) { + luaL_error(L, "image.bbox is now read-only"); + } else if (t != LUA_TTABLE) { + luaL_error(L, "image.bbox needs table value"); + } else if (lua_rawlen(L, -1) != 4) { + luaL_error(L, "image.bbox table must have exactly 4 elements"); + } else { + for (i = 1; i <= 4; i++) { /* v k t ... */ + lua_pushinteger(L, i); /* idx v k t ... */ + lua_gettable(L, -2); /* int v k t ... */ + t = lua_type(L, -1); + if (t == LUA_TNUMBER) { + img_bbox(d)[i - 1] = (int) lua_tointeger(L, -1); + } else if (t == LUA_TSTRING) { + img_bbox(d)[i - 1] = dimen_to_number(L, lua_tostring(L, -1)); + } else { + luaL_error(L, "image.bbox table needs integer value or dimension string elements"); + } + lua_pop(L, 1); /* v k t ... */ + } + img_set_bbox(d); + } + } else if (lua_key_eq(s,stream)) { + if (img_filename(d) != NULL) { + luaL_error(L, "image.stream can't be used with image.filename"); + } else if (img_state(d) >= DICT_FILESCANNED) { + luaL_error(L, "image.stream is now read-only"); + } else { + if (img_pdfstream_ptr(d) == NULL) { + new_img_pdfstream_struct(d); + } + xfree(img_pdfstream_stream(d)); + img_pdfstream_stream(d) = xstrdup(lua_tostring(L, -1)); + img_type(d) = IMG_TYPE_PDFSTREAM; + } + } else { + luaL_error(L, "image.%s can not be set", s); + } +} + static int m_img_set(lua_State * L) { - image **aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); /* value key user */ - lua_to_image(L, *aa); /* v k u */ + image **a = (image **) luaL_checkudata(L, 1, TYPE_IMG); /* v k u */ + image_dict *d = img_dict(*a); + if (d == NULL) { + luaL_error(L, "invalid image dictionary"); + } else { + lua_to_image(L, *a, d); + } return 0; } static int m_img_mul(lua_State * L) { lua_Number scale; - if (lua_type(L, 1) == LUA_TNUMBER) { /* u? n */ - (void) luaL_checkudata(L, 2, TYPE_IMG); /* u n */ - lua_insert(L, -2); /* n a */ - } else if (lua_type(L, 2) != LUA_TNUMBER) { /* n u? */ - (void) luaL_checkudata(L, 1, TYPE_IMG); /* n a */ - } /* n a */ - scale = lua_tonumber(L, 2); /* n a */ - lua_pop(L, 1); /* a */ - copy_image(L, scale); /* b */ + if (lua_type(L, 1) == LUA_TNUMBER) { /* u? n */ + (void) luaL_checkudata(L, 2, TYPE_IMG); /* u n */ + lua_insert(L, -2); /* n a */ + } else if (lua_type(L, 2) != LUA_TNUMBER) { /* n u? */ + (void) luaL_checkudata(L, 1, TYPE_IMG); /* n a */ + } /* n a */ + scale = lua_tonumber(L, 2); /* float */ /* n a */ + lua_pop(L, 1); /* a */ + copy_image(L, scale); /* b */ return 1; } @@ -774,13 +672,25 @@ static int m_img_print(lua_State * L) image_dict *d; aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); d = img_dict(*aa); - if (img_pagename(d) != NULL && strlen(img_pagename(d)) != 0) - lua_pushfstring(L, "", img_filename(d), img_pagename(d)); - else - lua_pushfstring(L, "", img_filename(d), img_pagenum(d)); + /* formatted a bit like a node */ + if (img_filename(d) == NULL) { + if (img_pagename(d) != NULL && strlen(img_pagename(d)) != 0) { + lua_pushfstring(L, "", img_dictref(*aa)); + } else { + lua_pushfstring(L, "", img_dictref(*aa)); + } + } else { + if (img_pagename(d) != NULL && strlen(img_pagename(d)) != 0) { + lua_pushfstring(L, "", img_filename(d), img_pagename(d), img_dictref(*aa)); + } else { + lua_pushfstring(L, "", img_filename(d), img_pagenum(d), img_dictref(*aa)); + } + } return 1; } +/* this finalizes instance */ + static int m_img_gc(lua_State * L) { image *a, **aa; @@ -788,50 +698,55 @@ static int m_img_gc(lua_State * L) aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); a = *aa; d = img_dict(*aa); -#ifdef DEBUG - printf("\n===== IMG GC ===== a=%d ad=%d\n", a, img_dict(a)); -#endif luaL_unref(L, LUA_REGISTRYINDEX, img_dictref(a)); - if (!img_is_refered(d)) + img_luaref(d) -= 1; + /* we need to check this */ + if (!img_is_refered(d)) { xfree(a); + } + /* till here */ return 0; } +/* the instance */ + static const struct luaL_Reg img_m[] = { {"__index", m_img_get}, {"__newindex", m_img_set}, {"__mul", m_img_mul}, {"__tostring", m_img_print}, - {"__gc", m_img_gc}, /* finalizer */ - {NULL, NULL} /* sentinel */ + {"__gc", m_img_gc}, + {NULL, NULL} }; -/**********************************************************************/ -/* Metamethods for image_dict */ +/* this finalizes the dict */ static int m_img_dict_gc(lua_State * L) { image_dict *ad, **add; add = (image_dict **) luaL_checkudata(L, 1, TYPE_IMG_DICT); ad = *add; -#ifdef DEBUG - printf("\n===== IMG_DICT GC FREE ===== ad=%d\n", ad); -#endif - if (img_state(ad) < DICT_REFERED) - free_image_dict(ad); + if (img_luaref(ad) > 0) { + luaL_error(L, "disposing image dict that has references"); + } else { + /* we need to check this */ + if (img_state(ad) < DICT_REFERED) { + free_image_dict(ad); + } + /* till here */ + } return 0; } +/* the (shared) dict */ + static const struct luaL_Reg img_dict_m[] = { - {"__gc", m_img_dict_gc}, /* finalizer */ - {NULL, NULL} /* sentinel */ + {"__gc", m_img_dict_gc}, + {NULL, NULL} }; -/**********************************************************************/ - int luaopen_img(lua_State * L) { - preset_environment(L, img_parms, IMG_ENV); luaL_newmetatable(L, TYPE_IMG); #ifdef LuajitTeX luaL_register(L, NULL, img_m); @@ -846,5 +761,3 @@ int luaopen_img(lua_State * L) #endif return 1; } - -/**********************************************************************/ diff --git a/Build/source/texk/web2c/luatexdir/lua/liolibext.c b/Build/source/texk/web2c/luatexdir/lua/liolibext.c index edf094d4187..630562228d9 100644 --- a/Build/source/texk/web2c/luatexdir/lua/liolibext.c +++ b/Build/source/texk/web2c/luatexdir/lua/liolibext.c @@ -1,5 +1,5 @@ /* liolibext.c - + Copyright 2014 Taco Hoekwater This file is part of LuaTeX. @@ -81,7 +81,7 @@ #define l_fseek(f,o,w) fseeko64(f,o,w) #define l_ftell(f) ftello64(f) -#define l_seeknum int64_t +#define l_seeknum int64_t #else @@ -196,7 +196,7 @@ static void opencheck (lua_State *L, const char *fname, const char *mode) { #ifdef WIN32 _setmode (fileno (p->f), _O_BINARY); #endif - if (mode[0]=='r') + if (mode[0]=='r') recorder_record_input(fname); else recorder_record_output(fname); @@ -223,7 +223,7 @@ static int io_open (lua_State *L) { #ifdef WIN32 _setmode (fileno (p->f), _O_BINARY); #endif - if (mode[0]=='r') + if (mode[0]=='r') recorder_record_input(filename); else recorder_record_output(filename); @@ -377,7 +377,7 @@ static int io_lines (lua_State *L) { static int read_number (lua_State *L, FILE *f) { lua_Number d; if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) { - lua_pushnumber(L, d); + lua_pushnumber(L, d); /* integer or float */ return 1; } else { @@ -394,7 +394,7 @@ static int test_eof (lua_State *L, FILE *f) { return (c != EOF); } -/* this version does not care wether the file has +/* this version does not care wether the file has line endings using an 'alien' convention */ static int read_line(lua_State * L, FILE * f, int chop) @@ -439,7 +439,7 @@ static void read_all (lua_State *L, FILE *f) { luaL_buffinit(L, &b); /* speed up loading of not too large files: */ old = l_ftell(f); - if ((l_fseek(f, 0, SEEK_END) >= 0) && + if ((l_fseek(f, 0, SEEK_END) >= 0) && ((nrlen = l_ftell(f)) > 0) && nrlen < 1000 * 1000 * 100) { rlen = nrlen; } @@ -603,7 +603,7 @@ static int f_seek (lua_State *L) { if (op) return luaL_fileresult(L, 0, NULL); /* error */ else { - lua_pushnumber(L, (lua_Number)l_ftell(f)); + lua_pushinteger(L, (lua_Number)l_ftell(f)); return 1; } } diff --git a/Build/source/texk/web2c/luatexdir/lua/lkpselib.c b/Build/source/texk/web2c/luatexdir/lua/lkpselib.c index d2fadcbfc26..e45cda0af6f 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lkpselib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lkpselib.c @@ -199,7 +199,7 @@ static int find_file(lua_State * L) if (t == LUA_TBOOLEAN) { mexist = lua_toboolean(L, i); } else if (t == LUA_TNUMBER) { - mexist=(int)lua_tonumber(L, i); + mexist = (int) lua_tointeger(L, i); } else if (t == LUA_TSTRING) { int op = luaL_checkoption(L, i, NULL, filetypenames); ftype = filetypes[op]; @@ -237,7 +237,7 @@ static int lua_kpathsea_find_file(lua_State * L) if (t == LUA_TBOOLEAN) { mexist = (boolean) lua_toboolean(L, i); } else if (t == LUA_TNUMBER) { - mexist=(int)lua_tonumber(L, i); + mexist = (int) lua_tointeger(L, i); } else if (t == LUA_TSTRING) { int op = luaL_checkoption(L, i, NULL, filetypenames); ftype = filetypes[op]; @@ -366,14 +366,16 @@ static unsigned find_dpi(const_string s) return dpi_number; } -/* Return newly-allocated NULL-terminated list of strings from MATCHES - that are prefixed with any of the subdirectories in SUBDIRS. That - is, for a string S in MATCHES, its dirname must end with one of the - elements in SUBDIRS. For instance, if subdir=foo/bar, that will - match a string foo/bar/baz or /some/texmf/foo/bar/baz. +/* + Return newly-allocated NULL-terminated list of strings from MATCHES + that are prefixed with any of the subdirectories in SUBDIRS. That + is, for a string S in MATCHES, its dirname must end with one of the + elements in SUBDIRS. For instance, if subdir=foo/bar, that will + match a string foo/bar/baz or /some/texmf/foo/bar/baz. - We don't reallocate the actual strings, just the list elements. - Perhaps later we will implement wildcards or // or something. */ + We don't reallocate the actual strings, just the list elements. + Perhaps later we will implement wildcards or "//" or something. +*/ static string *subdir_match(str_list_type subdirs, string * matches) { @@ -538,14 +540,14 @@ static int do_lua_kpathsea_lookup(lua_State * L, kpathsea kpse, int idx) lua_pushstring(L, "dpi"); lua_gettable(L, idx + 1); if (lua_type(L, -1) == LUA_TNUMBER) { - dpi=(int)lua_tonumber(L, -1); + dpi = (int) lua_tointeger(L, -1); } lua_pop(L, 1); lua_pushstring(L, "debug"); lua_gettable(L, idx + 1); if (lua_type(L, -1) == LUA_TNUMBER) { int d = 0; - d=(int)lua_tonumber(L, -1); + d = (int) lua_tointeger(L, -1); kpse->debug |= d; } lua_pop(L, 1); diff --git a/Build/source/texk/web2c/luatexdir/lua/llanglib.c b/Build/source/texk/web2c/luatexdir/lua/llanglib.c index 645780ca1c7..3356e734189 100644 --- a/Build/source/texk/web2c/luatexdir/lua/llanglib.c +++ b/Build/source/texk/web2c/luatexdir/lua/llanglib.c @@ -37,11 +37,10 @@ static int lang_new(lua_State * L) } else { int lualang; lang = lua_newuserdata(L, sizeof(struct tex_language *)); - lualang=(int)lua_tonumber(L, 1); + lualang = lua_tointeger(L, 1); *lang = get_language(lualang); if (!*lang) { - return luaL_error(L, "lang.new(%d): undefined language", - lua_tonumber(L, 1)); + return luaL_error(L, "lang.new(%d): undefined language", lualang); } } luaL_getmetatable(L, LANG_METATABLE); @@ -53,7 +52,7 @@ static int lang_id(lua_State * L) { struct tex_language **lang_ptr; lang_ptr = check_islang(L, 1); - lua_pushnumber(L, (*lang_ptr)->id); + lua_pushinteger(L, (*lang_ptr)->id); return 1; } @@ -92,8 +91,7 @@ static int lang_hyphenation(lua_State * L) lang_ptr = check_islang(L, 1); if (lua_gettop(L) != 1) { if (lua_type(L, 2) != LUA_TSTRING) { - return luaL_error(L, - "lang.hyphenation(): argument should be a string"); + return luaL_error(L, "lang.hyphenation(): argument should be a string"); } load_hyphenation(*lang_ptr, (const unsigned char *) lua_tostring(L, 2)); return 0; @@ -115,10 +113,10 @@ static int lang_pre_hyphen_char(lua_State * L) if (lua_type(L, 2) != LUA_TNUMBER) { return luaL_error(L, "lang.prehyphenchar(): argument should be a character number"); } - (*lang_ptr)->pre_hyphen_char=(int)lua_tonumber(L, 2); + (*lang_ptr)->pre_hyphen_char = (int) lua_tointeger(L, 2); return 0; } else { - lua_pushnumber(L, (*lang_ptr)->pre_hyphen_char); + lua_pushinteger(L, (*lang_ptr)->pre_hyphen_char); return 1; } } @@ -131,10 +129,10 @@ static int lang_post_hyphen_char(lua_State * L) if (lua_type(L, 2) != LUA_TNUMBER) { return luaL_error(L, "lang.posthyphenchar(): argument should be a character number"); } - (*lang_ptr)->post_hyphen_char=(int)lua_tonumber(L, 2); + (*lang_ptr)->post_hyphen_char = (int) lua_tointeger(L, 2); return 0; } else { - lua_pushnumber(L, (*lang_ptr)->post_hyphen_char); + lua_pushinteger(L, (*lang_ptr)->post_hyphen_char); return 1; } } @@ -148,14 +146,43 @@ static int lang_pre_exhyphen_char(lua_State * L) if (lua_type(L, 2) != LUA_TNUMBER) { return luaL_error(L, "lang.preexhyphenchar(): argument should be a character number"); } - (*lang_ptr)->pre_exhyphen_char=(int)lua_tonumber(L, 2); + (*lang_ptr)->pre_exhyphen_char = (int) lua_tointeger(L, 2); return 0; } else { - lua_pushnumber(L, (*lang_ptr)->pre_exhyphen_char); + lua_pushinteger(L, (*lang_ptr)->pre_exhyphen_char); return 1; } } +static int lang_sethjcode(lua_State * L) +{ + struct tex_language **lang_ptr; + lang_ptr = check_islang(L, 1); + if (lua_type(L, 2) != LUA_TNUMBER) { + return luaL_error(L, "lang.sethjcode(): argument should be a character number"); + } else { + int i = (int) lua_tointeger(L, 2) ; + if (lua_type(L, 3) == LUA_TNUMBER) { + set_hj_code((*lang_ptr)->id,i,(int) lua_tointeger(L, 3),-1); + } else { + set_hj_code((*lang_ptr)->id,i,i,-1); + } + } + return 0; +} + +static int lang_gethjcode(lua_State * L) +{ + struct tex_language **lang_ptr; + lang_ptr = check_islang(L, 1); + if (lua_type(L, 2) != LUA_TNUMBER) { + return luaL_error(L, "lang.gethjcode(): argument should be a character number"); + } else { + lua_pushinteger(L, get_hj_code((*lang_ptr)->id,lua_tointeger(L, 2))); + } + return 1; +} + static int lang_post_exhyphen_char(lua_State * L) { struct tex_language **lang_ptr; @@ -164,15 +191,14 @@ static int lang_post_exhyphen_char(lua_State * L) if (lua_type(L, 2) != LUA_TNUMBER) { return luaL_error(L, "lang.postexhyphenchar(): argument should be a character number"); } - (*lang_ptr)->post_exhyphen_char=(int)lua_tonumber(L, 2); + (*lang_ptr)->post_exhyphen_char = (int) lua_tointeger(L, 2); return 0; } else { - lua_pushnumber(L, (*lang_ptr)->post_exhyphen_char); + lua_pushinteger(L, (*lang_ptr)->post_exhyphen_char); return 1; } } - static int lang_hyphenation_min(lua_State * L) { struct tex_language **lang_ptr; @@ -181,10 +207,10 @@ static int lang_hyphenation_min(lua_State * L) if (lua_type(L, 2) != LUA_TNUMBER) { return luaL_error(L, "lang.hyphenationmin(): argument should be a number"); } - (*lang_ptr)->hyphenation_min=(int)lua_tonumber(L, 2); + (*lang_ptr)->hyphenation_min = (int) lua_tointeger(L, 2); return 0; } else { - lua_pushnumber(L, (*lang_ptr)->hyphenation_min); + lua_pushinteger(L, (*lang_ptr)->hyphenation_min); return 1; } } @@ -197,14 +223,22 @@ static int lang_clear_hyphenation(lua_State * L) return 0; } - static int do_lang_clean(lua_State * L) { char *cleaned; - if (lua_type(L, 1) != LUA_TSTRING) { - return luaL_error(L, "lang.clean(): argument should be a string"); + if (lua_type(L, 1) == LUA_TSTRING) { + (void) clean_hyphenation(int_par(cur_lang_code), lua_tostring(L, 1), &cleaned); + } else { + struct tex_language **lang_ptr; + lang_ptr = check_islang(L, 1); + if (lang_ptr == NULL) { + return luaL_error(L, "lang.clean(): first argument should be a string or language"); + } else if (lua_type(L, 2) != LUA_TSTRING) { + return luaL_error(L, "lang.clean(): second argument should be a string"); + } else { + (void) clean_hyphenation((*lang_ptr)->id,lua_tostring(L, 2), &cleaned); + } } - (void) clean_hyphenation(lua_tostring(L, 1), &cleaned); lua_pushstring(L, cleaned); return 1; } @@ -227,7 +261,6 @@ static int do_lang_hyphenate(lua_State * L) return 1; } - static const struct luaL_Reg langlib_d[] = { /* *INDENT-OFF* */ {"clear_patterns", lang_clear_patterns}, @@ -239,6 +272,8 @@ static const struct luaL_Reg langlib_d[] = { {"preexhyphenchar", lang_pre_exhyphen_char}, {"postexhyphenchar", lang_post_exhyphen_char}, {"hyphenationmin", lang_hyphenation_min}, + {"sethjcode", lang_sethjcode}, + {"gethjcode", lang_gethjcode}, {"id", lang_id}, /* *INDENT-ON* */ {NULL, NULL} /* sentinel */ @@ -256,6 +291,8 @@ static const struct luaL_Reg langlib[] = { {"preexhyphenchar", lang_pre_exhyphen_char}, {"postexhyphenchar", lang_post_exhyphen_char}, {"hyphenationmin", lang_hyphenation_min}, + {"sethjcode", lang_sethjcode}, + {"gethjcode", lang_gethjcode}, {"id", lang_id}, {"clean", do_lang_clean}, {"hyphenate", do_lang_hyphenate}, diff --git a/Build/source/texk/web2c/luatexdir/lua/lnewtokenlib.c b/Build/source/texk/web2c/luatexdir/lua/lnewtokenlib.c index f51e1e47bff..08ca9e9a1ba 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lnewtokenlib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lnewtokenlib.c @@ -74,6 +74,17 @@ static lua_token *check_istoken(lua_State * L, int ud); #define is_active_string(s) (strlen((char *)s)>3 && *s==0xEF && *(s+1)==0xBF && *(s+2)==0xBF) +void make_token_table(lua_State * L, int cmd, int chr, int cs) +{ + lua_createtable(L, 3, 0); + lua_pushinteger(L, cmd); + lua_rawseti(L, -2, 1); + lua_pushinteger(L, chr); + lua_rawseti(L, -2, 2); + lua_pushinteger(L, cs); + lua_rawseti(L, -2, 3); +} + static unsigned char *get_cs_text(int cs) { if (cs == null_cs) @@ -108,7 +119,7 @@ lua_token *check_istoken(lua_State * L, int ud) lua_token *p = maybe_istoken(L, ud); if (p != NULL) return p; - luatex_fail("There should have been a lua here, not an object with type %s!", luaL_typename(L, ud)); + formatted_error("token lib","lua expected, not an object with type %s", luaL_typename(L, ud)); return NULL; } @@ -139,7 +150,7 @@ static void push_token(lua_State * L, int tok) /* static int run_get_cs_offset(lua_State * L) */ /* { */ -/* lua_pushnumber(L, cs_token_flag); */ +/* lua_pushinteger(L, cs_token_flag); */ /* return 1; */ /* } */ @@ -149,7 +160,7 @@ static void push_token(lua_State * L, int tok) /* if (lua_type(L, -1) == LUA_TSTRING) { */ /* cs = get_command_id(lua_tostring(L, -1)); */ /* } */ -/* lua_pushnumber(L, cs); */ +/* lua_pushinteger(L, cs); */ /* return 1; */ /* } */ @@ -161,7 +172,7 @@ static void push_token(lua_State * L, int tok) /* s = lua_tolstring(L, -1, &k); */ /* cs = (size_t) string_lookup(s, k); */ /* } */ -/* lua_pushnumber(L, (lua_Number) cs); */ +/* lua_pushinteger(L, (lua_Number) cs); */ /* return 1; */ /* } */ @@ -219,7 +230,7 @@ static int run_scan_int(lua_State * L) scan_int(); v = cur_val; unsave_tex_scanner(texstate); - lua_pushnumber(L,(lua_Number)v); + lua_pushinteger(L,(int)v); return 1; } @@ -238,9 +249,9 @@ static int run_scan_dimen(lua_State * L) v = cur_val; o = cur_order; unsave_tex_scanner(texstate); - lua_pushnumber(L,(lua_Number)v); + lua_pushinteger(L,v); if (inf) { - lua_pushnumber(L,(lua_Number)o); + lua_pushinteger(L,(lua_Number)o); return 2; } else { return 1; @@ -379,7 +390,7 @@ static int run_scan_code(lua_State * L) /* HH */ } } if (cc & (1<<(cur_cmd))) { - lua_pushnumber(L,(lua_Number)cur_chr); + lua_pushinteger(L,(int)cur_chr); } else { lua_pushnil(L); back_input(); @@ -426,11 +437,10 @@ static int run_lookup(lua_State * L) static int run_build(lua_State * L) { - int cmd, chr, cs; if (lua_type(L, 1) == LUA_TNUMBER) { - cs = 0; - chr = (int) lua_tointeger(L, 1); - cmd = (int) luaL_optinteger(L, 2, get_cat_code(int_par(cat_code_table_code),chr)); + int cs = 0; + int chr = (int) lua_tointeger(L, 1); + int cmd = (int) luaL_optinteger(L, 2, get_cat_code(int_par(cat_code_table_code),chr)); if (cmd == 0 || cmd == 9 || cmd == 14 || cmd == 15) { fprintf(stdout, "\n\nluatex error: not a good token.\nCatcode %i can not be returned, so I replaced it by 12 (other)", @@ -461,105 +471,188 @@ static int lua_tokenlib_free(lua_State * L) return 1; } -static int lua_tokenlib_getfield(lua_State * L) +/* fast accessors */ + +inline static int lua_tokenlib_get_command(lua_State * L) { - lua_token *n; - const char *s; - halfword t, e ; - n = check_istoken(L, 1); - s = lua_tostring(L, 2); - t = token_info(n->token); - if (lua_key_eq(s, command)) { - if (t >= cs_token_flag) { - lua_pushnumber(L, eq_type((t - cs_token_flag))); + lua_token *n = check_istoken(L, 1); + halfword t = token_info(n->token); + if (t >= cs_token_flag) { + lua_pushinteger(L,(int) eq_type((t - cs_token_flag))); + } else { + lua_pushinteger(L, token_cmd(t)); + } + return 1; +} + +inline static int lua_tokenlib_get_index(lua_State * L) +{ + lua_token *n = check_istoken(L, 1); + halfword t = token_info(n->token); + int cmd = (t >= cs_token_flag ? eq_type(t - cs_token_flag) : token_cmd(t)); + halfword e = equiv(t - cs_token_flag); + switch (cmd) { + case assign_int_cmd: + e -= count_base; + break; + case assign_attr_cmd: + e -= attribute_base; + break; + case assign_dimen_cmd: + e -= dimen_base; + break; + case assign_glue_cmd: + e -= skip_base; + break; + case assign_mu_glue_cmd: + e -= mu_skip_base; + break; + case assign_toks_cmd: + e -= toks_base; + break; + default: + e = -1; + break; + } + if ((e >= 0) && (e <= 65535)) { + lua_pushinteger(L, e); + } else { + lua_pushnil(L); + } + return 1; +} + +inline static int lua_tokenlib_get_mode(lua_State * L) +{ + lua_token *n = check_istoken(L, 1); + halfword t = token_info(n->token); + if (t >= cs_token_flag) { + lua_pushinteger(L, equiv(t - cs_token_flag)); + } else { + lua_pushinteger(L, token_chr(t)); + } + return 1; +} + +inline static int lua_tokenlib_get_cmdname(lua_State * L) +{ + lua_token *n = check_istoken(L, 1); + halfword t = token_info(n->token); + int cmd = (t >= cs_token_flag ? eq_type(t - cs_token_flag) : token_cmd(t)); + lua_pushstring(L, command_names[cmd].cmd_name); /* can be sped up */ + return 1; +} + +inline static int lua_tokenlib_get_csname(lua_State * L) +{ + lua_token *n = check_istoken(L, 1); + halfword t = token_info(n->token); + unsigned char *s; + if (t >= cs_token_flag && ((s = get_cs_text(t - cs_token_flag)) != (unsigned char *) NULL)) { + if (is_active_string(s)) + lua_pushstring(L, (char *) (s + 3)); + else + lua_pushstring(L, (char *) s); + } else { + lua_pushnil(L); + } + return 1; +} + +inline static int lua_tokenlib_get_id(lua_State * L) +{ + lua_token *n = check_istoken(L, 1); + lua_pushinteger(L, n->token); + return 1; +} + +inline static int lua_tokenlib_get_tok(lua_State * L) +{ + lua_token *n = check_istoken(L, 1); + halfword t = token_info(n->token); + lua_pushinteger(L, t); + return 1; +} + +inline static int lua_tokenlib_get_active(lua_State * L) +{ + lua_token *n = check_istoken(L, 1); + halfword t = token_info(n->token); + unsigned char *s; + if (t >= cs_token_flag && ((s = get_cs_text(t - cs_token_flag)) != (unsigned char *) NULL)) { + if (is_active_string(s)) + lua_pushboolean(L,1); + else + lua_pushboolean(L,0); + free(s); + } else { + lua_pushboolean(L,0); + } + return 1; +} + +inline static int lua_tokenlib_get_expandable(lua_State * L) +{ + lua_token *n = check_istoken(L, 1); + halfword t = token_info(n->token); + int cmd = (t >= cs_token_flag ? eq_type(t - cs_token_flag) : token_cmd(t)); + if (cmd > max_command_cmd) { + lua_pushboolean(L, 1); + } else { + lua_pushboolean(L, 0); + } + return 1; +} + +inline static int lua_tokenlib_get_protected(lua_State * L) +{ + lua_token *n = check_istoken(L, 1); + halfword t = token_info(n->token); + int cmd = (t >= cs_token_flag ? eq_type(t - cs_token_flag) : token_cmd(t)); + if (cmd > max_command_cmd && (cmd >= call_cmd) && (cmd < end_template_cmd)) { + int chr = (t >= cs_token_flag ? equiv(t - cs_token_flag) : token_chr(t)); + if (token_info(token_link(chr)) == protected_token) { + lua_pushboolean(L, 1); } else { - lua_pushnumber(L, token_cmd(t)); + lua_pushboolean(L, 0); } + } else { + lua_pushboolean(L, 0); + } + return 1; +} + +static int lua_tokenlib_getfield(lua_State * L) +{ + const char *s = lua_tostring(L, 2); + if (lua_key_eq(s, command)) { + return lua_tokenlib_get_command(L); } else if (lua_key_eq(s, index)) { - int cmd = (t >= cs_token_flag ? eq_type(t - cs_token_flag) : token_cmd(t)); - e = equiv(t - cs_token_flag); - switch (cmd) { - case assign_int_cmd: - e -= count_base; - break; - case assign_attr_cmd: - e -= attribute_base; - break; - case assign_dimen_cmd: - e -= dimen_base; - break; - case assign_glue_cmd: - e -= skip_base; - break; - case assign_mu_glue_cmd: - e -= mu_skip_base; - break; - case assign_toks_cmd: - e -= toks_base; - break; - default: - e = -1; - break; - } - if ((e >= 0) && (e <= 65535)) { - lua_pushnumber(L, e); - } else { - lua_pushnil(L); - } + return lua_tokenlib_get_index(L); } else if (lua_key_eq(s, mode)) { - if (t >= cs_token_flag) { - lua_pushnumber(L, equiv(t - cs_token_flag)); - } else { - lua_pushnumber(L, token_chr(t)); - } + return lua_tokenlib_get_mode(L); } else if (lua_key_eq(s, cmdname)) { - int cmd = (t >= cs_token_flag ? eq_type(t - cs_token_flag) : token_cmd(t)); - lua_pushstring(L, command_names[cmd].cmd_name); /* can be sped up */ + return lua_tokenlib_get_cmdname(L); } else if (lua_key_eq(s, csname)) { - unsigned char *s; - if (t >= cs_token_flag && ((s = get_cs_text(t - cs_token_flag)) != (unsigned char *) NULL)) { - if (is_active_string(s)) - lua_pushstring(L, (char *) (s + 3)); - else - lua_pushstring(L, (char *) s); - } else { - lua_pushnil(L); - } + return lua_tokenlib_get_csname(L); } else if (lua_key_eq(s, id)) { - lua_pushnumber(L, n->token); + return lua_tokenlib_get_id(L); } else if (lua_key_eq(s, tok)) { - lua_pushnumber(L, t); + return lua_tokenlib_get_tok(L); } else if (lua_key_eq(s, active)) { - unsigned char *s; - if (t >= cs_token_flag && ((s = get_cs_text(t - cs_token_flag)) != (unsigned char *) NULL)) { - if (is_active_string(s)) - lua_pushboolean(L,1); - else - lua_pushboolean(L,0); - free(s); - } else { - lua_pushboolean(L,0); - } + return lua_tokenlib_get_active(L); } else if (lua_key_eq(s, expandable)) { - int cmd = (t >= cs_token_flag ? eq_type(t - cs_token_flag) : token_cmd(t)); - if (cmd > max_command_cmd) { - lua_pushboolean(L, 1); - } else { - lua_pushboolean(L, 0); - } + return lua_tokenlib_get_expandable(L); } else if (lua_key_eq(s, protected)) { - int cmd = (t >= cs_token_flag ? eq_type(t - cs_token_flag) : token_cmd(t)); - int chr = (t >= cs_token_flag ? equiv(t - cs_token_flag) : token_chr(t)); - if (cmd > max_command_cmd && ((cmd >= call_cmd) && (cmd < end_template_cmd)) && - token_info(token_link(chr)) == protected_token) { - lua_pushboolean(L, 1); - } else { - lua_pushboolean(L, 0); - } + return lua_tokenlib_get_protected(L); + } else { + lua_pushnil(L); } return 1; } +/* end */ + static int lua_tokenlib_equal(lua_State * L) { lua_token *n, *m; @@ -733,26 +826,44 @@ static int set_macro(lua_State * L) } static const struct luaL_Reg tokenlib[] = { - {"is_token", lua_tokenlib_is_token}, - {"get_next", run_get_next}, - {"scan_keyword", run_scan_keyword}, - {"scan_int", run_scan_int}, - {"scan_dimen", run_scan_dimen}, - {"scan_glue", run_scan_glue}, - {"scan_toks", run_scan_toks}, - {"scan_code", run_scan_code}, - {"scan_string", run_scan_string}, - {"scan_word", run_scan_word}, - {"scan_csname", run_scan_csname}, - {"type", lua_tokenlib_type}, - {"create", run_build}, - {"scan_token", run_scan_token}, /* expands next token if needed */ - {"set_macro", set_macro}, + { "type", lua_tokenlib_type }, + { "create", run_build }, + { "is_token", lua_tokenlib_is_token }, + /* scanners */ + { "get_next", run_get_next }, + { "scan_keyword", run_scan_keyword }, + { "scan_int", run_scan_int }, + { "scan_dimen", run_scan_dimen }, + { "scan_glue", run_scan_glue }, + { "scan_toks", run_scan_toks }, + { "scan_code", run_scan_code }, + { "scan_string", run_scan_string }, + { "scan_word", run_scan_word }, + { "scan_csname", run_scan_csname }, + { "scan_token", run_scan_token }, /* expands next token if needed */ + /* push into input stream */ + /* + { "write",luatwrite }, + */ + /* getters */ + { "get_command", lua_tokenlib_get_command }, + { "get_index", lua_tokenlib_get_index }, + { "get_mode", lua_tokenlib_get_mode }, + { "get_cmdname", lua_tokenlib_get_cmdname }, + { "get_csname", lua_tokenlib_get_csname }, + { "get_id", lua_tokenlib_get_id }, + { "get_tok", lua_tokenlib_get_tok }, + { "get_active", lua_tokenlib_get_active }, + { "get_expandable", lua_tokenlib_get_expandable }, + { "get_protected", lua_tokenlib_get_protected }, + /* maybe more setters */ + { "set_macro", set_macro }, + /* probably never */ /* {"expand", run_expand}, */ /* does not work yet! */ /* {"csname_id", run_get_csname_id}, */ /* yes or no */ /* {"command_id", run_get_command_id}, */ /* yes or no */ /* {"cs_offset", run_get_cs_offset}, */ /* not that useful */ - {NULL, NULL} /* sentinel */ + {NULL, NULL} }; static const struct luaL_Reg tokenlib_m[] = { diff --git a/Build/source/texk/web2c/luatexdir/lua/lnodelib.c b/Build/source/texk/web2c/luatexdir/lua/lnodelib.c index fed975719c8..fcd5d994baa 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lnodelib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lnodelib.c @@ -98,7 +98,6 @@ */ - #include "ptexlib.h" #include "lua/luatex-api.h" #ifdef LuajitTeX @@ -114,7 +113,6 @@ */ - /* When the first argument to an accessor is a node, we can use it's metatable @@ -172,14 +170,14 @@ */ -#define nodelib_pushdirect(n) lua_pushnumber(L,n) +#define nodelib_pushdirect(n) lua_pushinteger(L,n) #define nodelib_popdirect(n) lua_tointeger(L,n) #define nodelib_pushdirect_or_nil(n) do { \ if (n==null) { \ lua_pushnil(L); \ } else { \ - lua_pushnumber(L,n); \ + lua_pushinteger(L,n); \ } \ } while (0) @@ -188,43 +186,29 @@ lua_pushnil(L); \ } else { \ alink(n) = null; \ - lua_pushnumber(L,n); \ + lua_pushinteger(L,n); \ } \ } while (0) -#define nodelib_check_glue_spec(n) do { \ - n = glue_ptr(n); \ - if ((!n) || (!valid_node(n))) { \ - n = new_node(glue_spec_node,0); \ - glue_ptr(n) = n; \ +#define nodelib_check_glue_spec(n,g,field) do { \ + g = glue_ptr(n); \ + v = (halfword) lua_tointeger(L, 3); \ + if ((!g) || (!valid_node(g))) { \ + g = new_node(glue_spec_node,0); \ + glue_ptr(n) = g; \ + field(g) = v; \ + } else if (field(g) != v) { \ + if (glue_ref_count(g) > 1) { \ + c = new_spec(g); \ + delete_glue_ref(g); \ + g = c; \ + add_glue_ref(g); \ + glue_ptr(n) = g; \ + } \ + field(g) = v; \ } \ } while (0) -/* handy sometimes: */ - -/* static void stackDump (lua_State * L) { */ -/* int i; */ -/* int top = lua_gettop(L); */ -/* for (i = top; i >= 1; i--) { */ -/* int t = lua_type(L, i); */ -/* switch (t) { */ -/* case LUA_TSTRING: */ -/* printf("[%d] '%s'\n", i, lua_tostring(L, i)); */ -/* break; */ -/* case LUA_TBOOLEAN: */ -/* printf("[%d] %s\n",i, lua_toboolean(L, i) ? "true" : "false"); */ -/* break; */ -/* case LUA_TNUMBER: */ -/* printf("[%d] %g\n", i, lua_tonumber(L, i)); */ -/* break; */ -/* default: */ -/* printf("[%d][%d] %s &d=0x%x *d=%d\n",i-top-1, i, lua_typename(L, t), lua_touserdata(L,i), *((int *)lua_touserdata(L,i))); */ -/* break; */ -/* } */ -/* } */ -/* } */ - - #define nodelib_setattr(L, s, n) reassign_attribute(n,nodelib_getlist(L,s)) #define nodelib_gettoks(L,a) tokenlist_from_lua(L) @@ -234,10 +218,10 @@ /* fetching a field from a node .. we can often use the reuse bot-of-stack metatable */ -#define nodelib_pushlist(L,n) { lua_pushnumber(L,n); lua_nodelib_push(L); } /* can be: fast_metatable_or_nil(n) */ -#define nodelib_pushattr(L,n) { lua_pushnumber(L,n); lua_nodelib_push(L); } /* can be: fast_metatable_or_nil(n) */ -#define nodelib_pushspec(L,n) { lua_pushnumber(L,n); lua_nodelib_push_spec(L); } /* can be: fast_metatable_or_nil(n) - different criterium? */ -#define nodelib_pushaction(L,n) { lua_pushnumber(L,n); lua_nodelib_push(L); } /* can be: fast_metatable_or_nil(n) */ +#define nodelib_pushlist(L,n) { lua_pushinteger(L,n); lua_nodelib_push(L); } /* can be: fast_metatable_or_nil(n) */ +#define nodelib_pushattr(L,n) { lua_pushinteger(L,n); lua_nodelib_push(L); } /* can be: fast_metatable_or_nil(n) */ +#define nodelib_pushspec(L,n) { lua_pushinteger(L,n); lua_nodelib_push_spec(L); } /* can be: fast_metatable_or_nil(n) - different criterium? */ +#define nodelib_pushaction(L,n) { lua_pushinteger(L,n); lua_nodelib_push(L); } /* can be: fast_metatable_or_nil(n) */ #define nodelib_pushstring(L,n) { char *ss=makecstring(n); lua_pushstring(L,ss); free(ss); } /* find prev, and fix backlinks .. can be a macro instead (only used a few times) */ @@ -250,9 +234,6 @@ while (vlink(t)!=current && t != null) { \ t = vlink(t); \ } -#define get_node_type_id(L,n) do_get_node_type_id(L,n,node_data) -#define get_node_subtype_id(L,n) do_get_node_type_id(L,n,whatsit_node_data) - #define box(A) eqtb[box_base+(A)].hh.rh #define direct_check_index_range(j,s) \ if (j<0 || j > 65535) { \ @@ -288,7 +269,7 @@ halfword *check_isnode(lua_State * L, int i) halfword *p = maybe_isnode(L, i); if (p != NULL) return p; - luatex_fail("There should have been a lua here, not an object with type %s!", luaL_typename(L, i)); + formatted_error("node lib","lua expected, not an object with type %s", luaL_typename(L, i)); return NULL; } @@ -297,56 +278,15 @@ halfword *check_isnode(lua_State * L, int i) This routine finds the numerical value of a string (or number) at lua stack index |n|. If it is not a valid node type, returns -1 - Todo: create a lua table instead at initialization time and then - use that hash, so that we don't need to loop for each lookup. - - HH: can crash on noad 9 - */ -static int do_get_node_type_id(lua_State * L, int n, node_info * data) +static int get_node_type_id_from_name(lua_State * L, int n, node_info * data) { int j; - /* switch (lua_type(L, n)) { */ - /* case LUA_TNIL: */ - /* printf("LUA_TNIL\n"); */ - /* break; */ - /* case LUA_TNUMBER: */ - /* printf("LUA_TNUMBER\n"); */ - /* break; */ - /* case LUA_TBOOLEAN: */ - /* printf("LUA_TBOOLEAN\n"); */ - /* break; */ - /* case LUA_TSTRING: */ - /* printf("LUA_TSTRING\n"); */ - /* break; */ - /* case LUA_TTABLE: */ - /* printf("LUA_TTABLE\n"); */ - /* break; */ - /* case LUA_TFUNCTION: */ - /* printf("LUA_TFUNCTION\n"); */ - /* break; */ - /* case LUA_TUSERDATA: */ - /* printf("LUA_TUSERDATA\n"); */ - /* break; */ - /* case LUA_TTHREAD: */ - /* printf("LUA_TTHREAD\n"); */ - /* break; */ - /* case LUA_TLIGHTUSERDATA: */ - /* printf("LUA_TLIGHTUSERDATA\n"); */ - /* break; */ - /* } */ - if (lua_type(L, n) == LUA_TSTRING) { - const char *s = lua_tostring(L, n); - for (j = 0; data[j].id != -1; j++) { - if (strcmp(s, data[j].name) == 0) - return j; - } - } else if (lua_type(L, n) == LUA_TNUMBER) { - int i = (int) lua_tointeger(L, n); - for (j = 0; data[j].id != -1; j++) { - if (data[j].id == i) - return j; + const char *s = lua_tostring(L, n); + for (j = 0; data[j].id != -1; j++) { + if (strcmp(s, data[j].name) == 0) { + return j; } } return -1; @@ -354,26 +294,40 @@ static int do_get_node_type_id(lua_State * L, int n, node_info * data) static int get_valid_node_type_id(lua_State * L, int n) { - int i = get_node_type_id(L, n); - if (i == -1) { - if (lua_type(L, n) == LUA_TSTRING) { - luaL_error(L, "Invalid node type id: %s", lua_tostring(L, n)); - } else { - luaL_error(L, "Invalid node type id: %d", lua_tonumber(L, n)); + int i = -1; + int t = lua_type(L, n); + if (t == LUA_TSTRING) { + i = get_node_type_id_from_name(L,n,node_data); + if (i<0) { + luaL_error(L, "invalid node type id: %s", lua_tostring(L, n)); + } + } else if (t == LUA_TNUMBER) { + i = lua_tointeger(L,n); + if (! known_node_type(i)) { + luaL_error(L, "invalid node type id: %d", i); } + } else { + luaL_error(L, "invalid node type id"); } return i; } static int get_valid_node_subtype_id(lua_State * L, int n) { - int i = get_node_subtype_id(L, n); - if (i == -1) { - if (lua_type(L, n) == LUA_TSTRING) { - luaL_error(L, "Invalid whatsit node id: %s", lua_tostring(L, n)); - } else { - luaL_error(L, "Invalid whatsit node id: %d", lua_tonumber(L, n)); + int i = -1; + int t = lua_type(L, n); + if (t == LUA_TSTRING) { + i = get_node_type_id_from_name(L,n,whatsit_node_data); + if (i<0) { + luaL_error(L, "invalid whatsit type id: %s", lua_tostring(L, n)); } + } else if (t == LUA_TNUMBER) { + i = lua_tointeger(L,n); + if (! known_whatsit_type(i)) { + luaL_error(L, "invalid whatsit type id: %d", i); + } + } else { + luaL_error(L, "invalid whatsit type id"); } return i; } @@ -486,9 +440,13 @@ void lua_nodelib_push_fast(lua_State * L, halfword n) static int lua_nodelib_id(lua_State * L) { - int i = get_node_type_id(L, 1); - if (i >= 0) { - lua_pushnumber(L, i); + if (lua_type(L,1) == LUA_TSTRING) { + int i = get_node_type_id_from_name(L, 1, node_data); + if (i >= 0) { + lua_pushinteger(L, i); + } else { + lua_pushnil(L); + } } else { lua_pushnil(L); } @@ -512,7 +470,7 @@ static int lua_nodelib_getid(lua_State * L) if (!lua_rawequal(L, -1, -2)) { lua_pushnil(L); } else { - lua_pushnumber(L, type(*p)); + lua_pushinteger(L, type(*p)); } return 1; } @@ -523,7 +481,7 @@ static int lua_nodelib_getid(lua_State * L) { halfword *n; n = (halfword *) lua_touserdata(L, 1); - lua_pushnumber(L, type(*n)); + lua_pushinteger(L, type(*n)); return 1; } @@ -533,12 +491,11 @@ static int lua_nodelib_getid(lua_State * L) static int lua_nodelib_direct_getid(lua_State * L) { - halfword n; - n = (halfword) lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if (n == null) { lua_pushnil(L); } else { - lua_pushnumber(L, type(n)); + lua_pushinteger(L, type(n)); } return 1; } @@ -555,7 +512,7 @@ static int lua_nodelib_getsubtype(lua_State * L) if ( (!lua_rawequal(L, -1, -2)) || (! nodetype_has_subtype(*p))) { lua_pushnil(L); } else { - lua_pushnumber(L, subtype(*p)); + lua_pushinteger(L, subtype(*p)); } } return 1; @@ -567,7 +524,7 @@ static int lua_nodelib_getsubtype(lua_State * L) { halfword *n; n = (halfword *) lua_touserdata(L, 1); - lua_pushnumber(L, subtype(*n)); + lua_pushinteger(L, subtype(*n)); return 1; } @@ -577,12 +534,11 @@ static int lua_nodelib_getsubtype(lua_State * L) static int lua_nodelib_direct_getsubtype(lua_State * L) { - halfword n; - n = (halfword) lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if (n == null) { /* no check, we assume sane use */ lua_pushnil(L); } else { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } return 1; } @@ -599,7 +555,7 @@ static int lua_nodelib_getfont(lua_State * L) if ( (!lua_rawequal(L, -1, -2)) || (type(*p) != glyph_node) ) { lua_pushnil(L); } else { - lua_pushnumber(L, font(*p)); + lua_pushinteger(L, font(*p)); } } return 1; @@ -614,7 +570,7 @@ static int lua_nodelib_getfont(lua_State * L) if (type(*n) != glyph_node) { lua_pushnil(L); } else { - lua_pushnumber(L, font(*n)); + lua_pushinteger(L, font(*n)); } return 1; } @@ -628,11 +584,11 @@ static int lua_nodelib_getfont(lua_State * L) static int lua_nodelib_direct_getfont(lua_State * L) { halfword n; - n = (halfword) lua_tonumber(L, 1); + n = (halfword) lua_tointeger(L, 1); if ((n == null) || (type(n) != glyph_node)) { lua_pushnil(L); } else { - lua_pushnumber(L, font(n)); + lua_pushinteger(L, font(n)); } return 1; } @@ -641,14 +597,13 @@ static int lua_nodelib_direct_getfont(lua_State * L) static int lua_nodelib_direct_getfont(lua_State * L) /* family_font is not yet in manual, what does arg 2 do */ { - halfword n, t; - n = (halfword) lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if (n != null) { - t = type(n); + halfword t = type(n); if (t == glyph_node) { - lua_pushnumber(L, font(n)); + lua_pushinteger(L, font(n)); } else if ((t == math_char_node) || (t == math_text_char_node)) { - lua_pushnumber(L, fam_fnt(math_fam(n), 0)); + lua_pushinteger(L, fam_fnt(math_fam(n), 0)); } else { lua_pushnil(L); } @@ -666,9 +621,9 @@ static int lua_nodelib_getcharacter(lua_State * L) if ( (n == NULL) || (! lua_getmetatable(L,1)) ) { lua_pushnil(L); } else if (type(*n) == glyph_node) { - lua_pushnumber(L, character(*n)); + lua_pushinteger(L, character(*n)); } else if ((type(*n) == math_char_node) || (type(*n) == math_text_char_node)) { - lua_pushnumber(L, math_character(*n)); + lua_pushinteger(L, math_character(*n)); } return 1; } @@ -680,9 +635,9 @@ static int lua_nodelib_getcharacter(lua_State * L) halfword *n; n = (halfword *) lua_touserdata(L, 1); if (type(*n) == glyph_node) { - lua_pushnumber(L, character(*n)); + lua_pushinteger(L, character(*n)); } else if ((type(*n) == math_char_node) || (type(*n) == math_text_char_node)) { - lua_pushnumber(L, math_character(*n)); + lua_pushinteger(L, math_character(*n)); } else { lua_pushnil(L); } @@ -695,14 +650,13 @@ static int lua_nodelib_getcharacter(lua_State * L) static int lua_nodelib_direct_getcharacter(lua_State * L) { - halfword n; - n = (halfword) lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if (n == null) { lua_pushnil(L); } else if (type(n) == glyph_node) { - lua_pushnumber(L, character(n)); + lua_pushinteger(L, character(n)); } else if ((type(n) == math_char_node) || (type(n) == math_text_char_node)) { - lua_pushnumber(L, math_character(n)); + lua_pushinteger(L, math_character(n)); } else { lua_pushnil(L); } @@ -714,8 +668,7 @@ static int lua_nodelib_direct_getcharacter(lua_State * L) static int lua_nodelib_direct_getdiscretionary(lua_State * L) { - halfword n; - n = (halfword) lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if (n != null) { if (type(n) == disc_node) { nodelib_pushdirect_or_nil(vlink(pre_break(n))); @@ -756,9 +709,8 @@ static int lua_nodelib_getlist(lua_State * L) static int lua_nodelib_direct_getlist(lua_State * L) { - halfword n; - n = (halfword) lua_tonumber(L, 1); - if ( n == null) { + halfword n = lua_tointeger(L, 1); + if (n == null) { lua_pushnil(L); } else if ((type(n) == hlist_node) || (type(n) == vlist_node)) { nodelib_pushdirect_or_nil_alink(list_ptr(n)); @@ -788,9 +740,8 @@ static int lua_nodelib_getleader(lua_State * L) static int lua_nodelib_direct_getleader(lua_State * L) { - halfword n; - n = (halfword) lua_tonumber(L, 1); - if ( n == null) { + halfword n = lua_tointeger(L, 1); + if (n == null) { lua_pushnil(L); } else if (type(n) == glue_node) { nodelib_pushdirect_or_nil(leader_ptr(n)); @@ -828,22 +779,16 @@ static int lua_nodelib_getnext(lua_State * L) static int lua_nodelib_fast_getnext(lua_State * L) { halfword *a; - // [given-node] [...] halfword *p = lua_touserdata(L, 1); if ((p == NULL) || (!vlink(*p))){ lua_pushnil(L); } else { lua_settop(L,1); - // [given-node] lua_getmetatable(L,1); - // [given-node] [mt-node] a = lua_newuserdata(L, sizeof(halfword)); - // [given-node] [mt-node] [next-node] *a = vlink(*p); lua_replace(L,1); - // [next-node] [mt-node] lua_setmetatable(L,1); - // [next-node-with-mt] } return 1; } @@ -854,8 +799,7 @@ static int lua_nodelib_getnext(lua_State * L) static int lua_nodelib_direct_getnext(lua_State * L) { - halfword p; - p = (halfword) lua_tonumber(L, 1); + halfword p = lua_tointeger(L, 1); if (p == null) { lua_pushnil(L); } else { @@ -910,22 +854,16 @@ static int lua_nodelib_getboth(lua_State * L) static int lua_nodelib_fast_getprev(lua_State * L) { halfword *a; - // [given-node] [...] halfword *p = lua_touserdata(L, 1); if ((p == NULL) || (!alink(*p))) { lua_pushnil(L); } else { lua_settop(L,1); - // [given-node] lua_getmetatable(L,1); - // [given-node] [mt-node] a = lua_newuserdata(L, sizeof(halfword)); - // [given-node] [mt-node] [next-node] *a = alink(*p); lua_replace(L,1); - // [next-node] [mt-node] lua_setmetatable(L,1); - // [next-node-with-mt] } return 1; } @@ -936,8 +874,7 @@ static int lua_nodelib_getboth(lua_State * L) static int lua_nodelib_direct_getprev(lua_State * L) { - halfword p; - p = (halfword) lua_tonumber(L, 1); + halfword p = lua_tointeger(L, 1); if (p == null) { lua_pushnil(L); } else { @@ -950,8 +887,7 @@ static int lua_nodelib_direct_getprev(lua_State * L) static int lua_nodelib_direct_getboth(lua_State * L) { - halfword p; - p = (halfword) lua_tonumber(L, 1); + halfword p = lua_tointeger(L, 1); if (p == null) { lua_pushnil(L); lua_pushnil(L); @@ -962,13 +898,13 @@ static int lua_nodelib_direct_getboth(lua_State * L) return 2; } -/* node.subtype */ +/* node.subtype (maybe also return them for other node types now) */ static int lua_nodelib_subtype(lua_State * L) { - int i = get_node_subtype_id(L, 1); + int i = get_node_type_id_from_name(L,1,whatsit_node_data); if (i >= 0) { - lua_pushnumber(L, i); + lua_pushinteger(L, i); } else { lua_pushnil(L); /* return 0; */ } @@ -980,8 +916,8 @@ static int lua_nodelib_subtype(lua_State * L) static int lua_nodelib_type(lua_State * L) { if (lua_type(L,1) == LUA_TNUMBER) { - int i = get_node_type_id(L, 1); - if (i >= 0) { + int i = lua_tointeger(L, 1); + if (known_node_type(i)) { lua_pushstring(L, node_data[i].name); return 1; } @@ -999,17 +935,39 @@ static int lua_nodelib_new(lua_State * L) { int i, j; halfword n = null; - i = get_valid_node_type_id(L, 1); + int t = lua_type(L, 1); + if (t == LUA_TNUMBER) { + i = lua_tointeger(L,1); + if (! known_node_type(i)) { + i = -1; + } + } else if (t == LUA_TSTRING) { + i = get_node_type_id_from_name(L,1,node_data); + } else { + i = -1; + } + if (i < 0) { + luaL_error(L, "invalid node id for creating new node"); + } + t = lua_type(L, 2); if (i == whatsit_node) { - j = -1; - if (lua_gettop(L) > 1) - j = get_valid_node_subtype_id(L, 2); - if (j < 0) - luaL_error(L, "Creating a whatsit requires the subtype number as a second argument"); + if (t == LUA_TNUMBER) { + j = lua_tointeger(L,2); + if (! known_whatsit_type(j)) { + j = -1; + } + } else if (t == LUA_TSTRING) { + j = get_node_type_id_from_name(L,2,whatsit_node_data); + } else { + j = -1; + } + if (j < 0) { + luaL_error(L, "creating a whatsit requires the subtype number as a second argument"); + } + } else if (t == LUA_TNUMBER) { + j = (int) lua_tointeger(L, 2); } else { j = 0; - if (lua_gettop(L) > 1) - j = (int) lua_tointeger(L, 2); } n = new_node(i, j); lua_nodelib_push_fast(L, n); @@ -1020,9 +978,9 @@ static int lua_nodelib_new(lua_State * L) static int lua_nodelib_direct_new(lua_State * L) { - int i, j; + int j; halfword n ; - i = get_valid_node_type_id(L, 1); + int i = get_valid_node_type_id(L, 1); if (i == whatsit_node) { j = -1; if (lua_gettop(L) > 1) @@ -1035,7 +993,7 @@ static int lua_nodelib_direct_new(lua_State * L) j = (int) lua_tointeger(L, 2); } n = new_node(i, j); - lua_pushnumber(L,n); + lua_pushinteger(L,n); return 1; } @@ -1043,7 +1001,7 @@ static int lua_nodelib_direct_new(lua_State * L) static int lua_nodelib_free(lua_State * L) { - halfword *n; + halfword n; halfword p; if (lua_gettop(L) < 1) { lua_pushnil(L); @@ -1051,11 +1009,11 @@ static int lua_nodelib_free(lua_State * L) } else if (lua_isnil(L, 1)) { return 1; /* the nil itself */ } - n = check_isnode(L, 1); - p = vlink(*n); - flush_node(*n); + n = *(check_isnode(L, 1)); + p = vlink(n); + flush_node(n); /* can be: lua_nodelib_push_fast(L, p); */ - lua_pushnumber(L, p); + lua_pushinteger(L, p); lua_nodelib_push(L); return 1; } @@ -1064,18 +1022,16 @@ static int lua_nodelib_free(lua_State * L) static int lua_nodelib_direct_free(lua_State * L) { - halfword n; - halfword p; - n = (halfword) lua_tonumber(L,1); + halfword n = lua_tointeger(L,1); if (n == null) { lua_pushnil(L); } else { - p = vlink(n); + halfword p = vlink(n); flush_node(n); if (p == 0) { lua_pushnil(L); } else { - lua_pushnumber(L,p); + lua_pushinteger(L,p); } } return 1; @@ -1085,21 +1041,20 @@ static int lua_nodelib_direct_free(lua_State * L) static int lua_nodelib_flush_node(lua_State * L) { - halfword *n; - if ((lua_gettop(L) < 1) || lua_isnil(L, 1)) + if ((lua_gettop(L) < 1) || lua_isnil(L, 1)) { return 0; - n = check_isnode(L, 1); - // no check if n? - flush_node(*n); - return 0; + } else { + halfword n = *(check_isnode(L, 1)); + flush_node(n); + return 0; + } } /* node.direct.flush_node */ static int lua_nodelib_direct_flush_node(lua_State * L) { - halfword n; - n = (halfword) lua_tonumber(L,1); + halfword n = lua_tointeger(L,1); if (n == null) return 0; flush_node(n); @@ -1110,20 +1065,20 @@ static int lua_nodelib_direct_flush_node(lua_State * L) static int lua_nodelib_flush_list(lua_State * L) { - halfword *n_ptr; - if ((lua_gettop(L) < 1) || lua_isnil(L, 1)) + if ((lua_gettop(L) < 1) || lua_isnil(L, 1)) { return 0; - n_ptr = check_isnode(L, 1); - flush_node_list(*n_ptr); - return 0; + } else { + halfword n_ptr = *check_isnode(L, 1); + flush_node_list(n_ptr); + return 0; + } } /* node.direct.flush_list */ static int lua_nodelib_direct_flush_list(lua_State * L) { - halfword n; - n = (halfword) lua_tonumber(L,1); + halfword n = lua_tointeger(L,1); if (n == null) return 0; flush_node_list(n); @@ -1153,23 +1108,20 @@ static int lua_nodelib_remove(lua_State * L) if (lua_gettop(L) < 2) luaL_error(L, "Not enough arguments for node.remove()"); head = *(check_isnode(L, 1)); -#if DEBUG - show_node_links(head, "before"); -#endif if (lua_isnil(L, 2)) return 2; /* the arguments, as they are */ current = *(check_isnode(L, 2)); if (head == current) { if (alink(current)){ - vlink(alink(current)) = vlink(current); // vlink(prev) = next + vlink(alink(current)) = vlink(current); } if (vlink(current)){ - alink( vlink(current)) = alink(current); // alink(next) = prev + alink( vlink(current)) = alink(current); } - head = vlink(current); //head = next - current = vlink(current); //current = next - } else { /* head != current */ + head = vlink(current); + current = vlink(current); + } else { t = alink(current); if (t == null || vlink(t) != current) { set_t_to_prev(head, current); @@ -1186,10 +1138,10 @@ static int lua_nodelib_remove(lua_State * L) show_node_links(head, "after"); #endif /* can be: lua_nodelib_push_fast(L, head); */ - lua_pushnumber(L, head); + lua_pushinteger(L, head); lua_nodelib_push(L); /* can be: lua_nodelib_push_fast(L, current); */ - lua_pushnumber(L, current); + lua_pushinteger(L, current); lua_nodelib_push(L); return 2; } @@ -1198,28 +1150,28 @@ static int lua_nodelib_remove(lua_State * L) static int lua_nodelib_direct_remove(lua_State * L) { - halfword head, current , t; - head = (halfword) lua_tonumber(L,1); + halfword current, t; + halfword head = lua_tointeger(L,1); if (head == null) { lua_pushnil(L); lua_pushnil(L); return 2 ; } - current = (halfword) lua_tonumber(L,2); + current = (halfword) lua_tointeger(L,2); if (current == null) { - lua_pushnumber(L, head); + lua_pushinteger(L, head); lua_pushnil(L); return 2 ; } if (head == current) { if (alink(current)){ - vlink( alink(current) ) = vlink(current); // vlink(prev) = next + vlink( alink(current) ) = vlink(current); } if (vlink(current)){ - alink( vlink(current) ) = alink(current); // alink(next) = prev + alink( vlink(current) ) = alink(current); } - head = vlink(current); //head = next - current = vlink(current); //current = next + head = vlink(current); + current = vlink(current); } else { t = alink(current); if (t == null || vlink(t) != current) { @@ -1236,12 +1188,12 @@ static int lua_nodelib_direct_remove(lua_State * L) if (head == null) { lua_pushnil(L); } else { - lua_pushnumber(L, head); + lua_pushinteger(L, head); } if (current == null) { lua_pushnil(L); } else { - lua_pushnumber(L, current); + lua_pushinteger(L, current); } return 2; } @@ -1298,20 +1250,20 @@ static int lua_nodelib_insert_before(lua_State * L) static int lua_nodelib_direct_insert_before(lua_State * L) { - halfword head, current, n, t; - n = (halfword) lua_tonumber(L,3); + halfword head, current; + halfword n = lua_tointeger(L,3); if (n == null){ /* no node */ lua_pop(L, 1); return 2 ; } - head = (halfword) lua_tonumber(L,1); - current = (halfword) lua_tonumber(L,2); + head = (halfword) lua_tointeger(L,1); + current = (halfword) lua_tointeger(L,2); /* no head, ignore current */ if (head == null) { vlink(n) = null; alink(n) = null; - lua_pushnumber(L, n); + lua_pushinteger(L, n); lua_pushvalue(L, -1); /* n, n */ return 2; @@ -1320,18 +1272,18 @@ static int lua_nodelib_direct_insert_before(lua_State * L) if (current == null) current = tail_of_list(head); if (head != current) { - t = alink(current); + halfword t = alink(current); if (t == null || vlink(t) != current) set_t_to_prev(head, current); couple_nodes(t, n); } couple_nodes(n, current); if (head == current) { - lua_pushnumber(L, n); + lua_pushinteger(L, n); } else { - lua_pushnumber(L, head); + lua_pushinteger(L, head); } - lua_pushnumber(L, n); + lua_pushinteger(L, n); return 2; } @@ -1377,20 +1329,20 @@ static int lua_nodelib_insert_after(lua_State * L) static int lua_nodelib_direct_insert_after(lua_State * L) { - halfword head, current, n; + halfword head, current; /*[head][current][new]*/ - n = (halfword) lua_tonumber(L,3); + halfword n = lua_tointeger(L,3); if (n == null) { /* no node */ return 2 ; } - head = (halfword) lua_tonumber(L,1); - current = (halfword) lua_tonumber(L,2); + head = (halfword) lua_tointeger(L,1); + current = (halfword) lua_tointeger(L,2); if (head == null) { /* no head, ignore current */ vlink(n) = null; alink(n) = null; - lua_pushnumber(L,n); + lua_pushinteger(L,n); lua_pushvalue(L, -1); /* n, n */ return 2; @@ -1404,14 +1356,18 @@ static int lua_nodelib_direct_insert_after(lua_State * L) try_couple_nodes(n, vlink(current)); couple_nodes(current, n); lua_pop(L, 2); - lua_pushnumber(L, n); + lua_pushinteger(L, n); return 2; } /* node.copy_list */ -/* hh-ls: we need to use an intermediate variable as otherwise target is used in the loop -and subfields get overwritten (or something like that) which results in crashes and -unexpected side effects */ + +/* + we need to use an intermediate variable as otherwise target is used in the loop + and subfields get overwritten (or something like that) which results in crashes + and unexpected side effects +*/ + static int lua_nodelib_copy_list(lua_State * L) { halfword n, s = null; @@ -1427,23 +1383,22 @@ static int lua_nodelib_copy_list(lua_State * L) } - /* node.direct.copy_list */ static int lua_nodelib_direct_copy_list(lua_State * L) { - halfword n, s, m; - n = (halfword) lua_tonumber(L,1); + halfword n = lua_tointeger(L,1); if (n == null) { lua_pushnil(L); } else { - s = (halfword) lua_tonumber(L,2); + halfword s = lua_tointeger(L,2); + halfword m; if (s == null) { m = do_copy_node_list(n,null); } else { m = do_copy_node_list(n,s); } - lua_pushnumber(L,m); + lua_pushinteger(L,m); } return 1; } @@ -1452,13 +1407,12 @@ static int lua_nodelib_direct_copy_list(lua_State * L) static int lua_nodelib_copy(lua_State * L) { - halfword *n; - halfword m; + halfword n; if (lua_isnil(L, 1)) return 1; /* the nil itself */ - n = check_isnode(L, 1); - m = copy_node(*n); - lua_nodelib_push_fast(L, m); + n = *check_isnode(L, 1); + n = copy_node(n); + lua_nodelib_push_fast(L, n); return 1; } @@ -1466,15 +1420,15 @@ static int lua_nodelib_copy(lua_State * L) static int lua_nodelib_direct_copy(lua_State * L) { - halfword n; - halfword m; - if (lua_isnil(L, 1)) + if (lua_isnil(L, 1)) { return 1; /* the nil itself */ - /* beware, a glue node can have number 0 (zeropt) so we cannot test for null) */ - n = (halfword) lua_tonumber(L, 1); - m = copy_node(n); - lua_pushnumber(L, m); - return 1; + } else { + /* beware, a glue node can have number 0 (zeropt) so we cannot test for null) */ + halfword n = lua_tointeger(L, 1); + n = copy_node(n); + lua_pushinteger(L, n); + return 1; + } } @@ -1482,17 +1436,15 @@ static int lua_nodelib_direct_copy(lua_State * L) static int lua_nodelib_append(lua_State * L) { - halfword *n; - halfword m; - int i, j; - j = lua_gettop(L); + halfword n; + int i; + int j = lua_gettop(L); for (i = 1; i <= j; i++) { - n = check_isnode(L, i); - m = *n; - tail_append(m); - while (vlink(m) != null) { - m = vlink(m); - tail_append(m); + n = *check_isnode(L, i); + tail_append(n); + while (vlink(n) != null) { + n = vlink(n); + tail_append(n); } } return 0; @@ -1502,12 +1454,11 @@ static int lua_nodelib_append(lua_State * L) static int lua_nodelib_direct_append(lua_State * L) { - halfword n; halfword m; - int i, j; - j = lua_gettop(L); + int i; + int j = lua_gettop(L); for (i = 1; i <= j; i++) { - n = (halfword) lua_tonumber(L,i); /*lua_getnumber(L, i);*/ + halfword n = lua_tointeger(L,i); /*lua_getnumber(L, i);*/ if (n != null) { m = n ; tail_append(m); @@ -1524,10 +1475,9 @@ static int lua_nodelib_direct_append(lua_State * L) static int lua_nodelib_last_node(lua_State * L) { - halfword m; - m = pop_tail(); + halfword m = pop_tail(); /* can be: lua_nodelib_push_fast(L, m); */ - lua_pushnumber(L, m); + lua_pushinteger(L, m); lua_nodelib_push(L); return 1; } @@ -1536,9 +1486,8 @@ static int lua_nodelib_last_node(lua_State * L) static int lua_nodelib_direct_last_node(lua_State * L) { - halfword m; - m = pop_tail(); - lua_pushnumber(L, m); + halfword m = pop_tail(); + lua_pushinteger(L, m); return 1; } @@ -1546,12 +1495,12 @@ static int lua_nodelib_direct_last_node(lua_State * L) static int lua_nodelib_hpack(lua_State * L) { - halfword n, p; + halfword p; const char *s; int w = 0; int m = 1; int d = -1; - n = *(check_isnode(L, 1)); + halfword n = *(check_isnode(L, 1)); if (lua_gettop(L) > 1) { w = (int) lua_tointeger(L, 2); if (lua_gettop(L) > 2) { @@ -1569,7 +1518,7 @@ static int lua_nodelib_hpack(lua_State * L) luaL_error(L, "3rd argument should be either additional or exactly"); } } else if (lua_type(L, 3) == LUA_TNUMBER) { - m=(int)lua_tonumber(L, 3); + m = (int) lua_tointeger(L, 3); } else { lua_pushstring(L, "incorrect 3rd argument"); } @@ -1584,7 +1533,7 @@ static int lua_nodelib_hpack(lua_State * L) } p = hpack(n, w, m, d); lua_nodelib_push_fast(L, p); - lua_pushnumber(L, last_badness); + lua_pushinteger(L, last_badness); return 2; } @@ -1592,12 +1541,12 @@ static int lua_nodelib_hpack(lua_State * L) static int lua_nodelib_direct_hpack(lua_State * L) { - halfword n, p; + halfword p; const char *s; int w = 0; int m = 1; int d = -1; - n = (halfword) lua_tonumber(L,1); + halfword n = lua_tointeger(L,1); /* could be macro */ if (lua_gettop(L) > 1) { w = (int) lua_tointeger(L, 2); @@ -1616,7 +1565,7 @@ static int lua_nodelib_direct_hpack(lua_State * L) luaL_error(L, "3rd argument should be either additional or exactly"); } } else if (lua_type(L, 3) == LUA_TNUMBER) { - m=(int)lua_tonumber(L, 3); + m = (int) lua_tointeger(L, 3); } else { lua_pushstring(L, "incorrect 3rd argument"); } @@ -1631,8 +1580,8 @@ static int lua_nodelib_direct_hpack(lua_State * L) } /* till here */ p = hpack(n, w, m, d); - lua_pushnumber(L, p); - lua_pushnumber(L, last_badness); + lua_pushinteger(L, p); + lua_pushinteger(L, last_badness); return 2; } @@ -1640,12 +1589,12 @@ static int lua_nodelib_direct_hpack(lua_State * L) static int lua_nodelib_vpack(lua_State * L) { - halfword n, p; + halfword p; const char *s; int w = 0; int m = 1; int d = -1; - n = *(check_isnode(L, 1)); + halfword n = *(check_isnode(L, 1)); if (lua_gettop(L) > 1) { w = (int) lua_tointeger(L, 2); if (lua_gettop(L) > 2) { @@ -1669,7 +1618,7 @@ static int lua_nodelib_vpack(lua_State * L) } else if (lua_type(L, 3) == LUA_TNUMBER) { - m=(int)lua_tonumber(L, 3); + m= (int) lua_tointeger(L, 3); } else { lua_pushstring(L, "incorrect 3rd argument"); } @@ -1677,7 +1626,7 @@ static int lua_nodelib_vpack(lua_State * L) } p = vpackage(n, w, m, max_dimen, d); lua_nodelib_push_fast(L, p); - lua_pushnumber(L, last_badness); + lua_pushinteger(L, last_badness); return 2; } @@ -1685,12 +1634,12 @@ static int lua_nodelib_vpack(lua_State * L) static int lua_nodelib_direct_vpack(lua_State * L) { - halfword n, p; + halfword p; const char *s; int w = 0; int m = 1; int d = -1; - n = (halfword) lua_tonumber(L,1); + halfword n = (halfword) lua_tointeger(L,1); if (lua_gettop(L) > 1) { w = (int) lua_tointeger(L, 2); if (lua_gettop(L) > 2) { @@ -1714,15 +1663,15 @@ static int lua_nodelib_direct_vpack(lua_State * L) } else if (lua_type(L, 3) == LUA_TNUMBER) { - m=(int)lua_tonumber(L, 3); + m= (int) lua_tointeger(L, 3); } else { lua_pushstring(L, "incorrect 3rd argument"); } } } p = vpackage(n, w, m, max_dimen, d); - lua_pushnumber(L, p); - lua_pushnumber(L, last_badness); + lua_pushinteger(L, p); + lua_pushinteger(L, last_badness); return 2; } @@ -1730,8 +1679,7 @@ static int lua_nodelib_direct_vpack(lua_State * L) static int lua_nodelib_dimensions(lua_State * L) { - int top; - top = lua_gettop(L); + int top = lua_gettop(L); if (top > 0) { scaled_whd siz; glue_ratio g_mult = 1.0; @@ -1746,9 +1694,9 @@ static int lua_nodelib_dimensions(lua_State * L) return 1; } i += 3; - g_mult = (glue_ratio) lua_tonumber(L, 1); - g_sign=(int)lua_tonumber(L, 2); - g_order=(int)lua_tonumber(L, 3); + g_mult = (glue_ratio) lua_tonumber(L, 1); /* integer or float */ + g_sign = (int) lua_tointeger(L, 2); + g_order = (int) lua_tointeger(L, 3); } n = *(check_isnode(L, i)); if (lua_gettop(L) > i && !lua_isnil(L, (i + 1))) { @@ -1762,9 +1710,9 @@ static int lua_nodelib_dimensions(lua_State * L) d = nodelib_getdir(L, (i + 2), 1); } siz = natural_sizes(n, p, g_mult, g_sign, g_order, d); - lua_pushnumber(L, siz.wd); - lua_pushnumber(L, siz.ht); - lua_pushnumber(L, siz.dp); + lua_pushinteger(L, siz.wd); + lua_pushinteger(L, siz.ht); + lua_pushinteger(L, siz.dp); return 3; } else { luaL_error(L, "missing argument to 'dimensions' (node expected)"); @@ -1776,8 +1724,7 @@ static int lua_nodelib_dimensions(lua_State * L) static int lua_nodelib_direct_dimensions(lua_State * L) { - int top; - top = lua_gettop(L); + int top = lua_gettop(L); if (top > 0) { scaled_whd siz; glue_ratio g_mult = 1.0; @@ -1788,24 +1735,24 @@ static int lua_nodelib_direct_dimensions(lua_State * L) halfword n = null, p = null; if (top > 3) { i += 3; - g_mult = (glue_ratio) lua_tonumber(L, 1); - g_sign=(int)lua_tonumber(L, 2); - g_order=(int)lua_tonumber(L, 3); + g_mult = (glue_ratio) lua_tonumber(L, 1); /* integer or float */ + g_sign = (int) lua_tointeger(L, 2); + g_order = (int) lua_tointeger(L, 3); } - n = (halfword) lua_tonumber(L,i); + n = (halfword) lua_tointeger(L,i); if (lua_gettop(L) > i && !lua_isnil(L, (i + 1))) { if (lua_type(L, (i + 1)) == LUA_TSTRING) { d = nodelib_getdir(L, (i + 1), 1); } else { - p = (halfword) lua_tonumber(L,i+1); + p = (halfword) lua_tointeger(L,i+1); } } if (lua_gettop(L) > (i + 1) && lua_type(L, (i + 2)) == LUA_TSTRING) d = nodelib_getdir(L, (i + 2), 1); siz = natural_sizes(n, p, g_mult, g_sign, g_order, d); - lua_pushnumber(L, siz.wd); - lua_pushnumber(L, siz.ht); - lua_pushnumber(L, siz.dp); + lua_pushinteger(L, siz.wd); + lua_pushinteger(L, siz.ht); + lua_pushinteger(L, siz.dp); return 3; } else { luaL_error(L, "missing argument to 'dimensions' (node expected)"); @@ -1817,15 +1764,13 @@ static int lua_nodelib_direct_dimensions(lua_State * L) static int lua_nodelib_mlist_to_hlist(lua_State * L) { - halfword n; int w; boolean m; - n = *(check_isnode(L, 1)); - //w = luaL_checkoption(L, 2, "text", math_style_names); + halfword n = *(check_isnode(L, 1)); assign_math_style(L,2,w); luaL_checkany(L, 3); m = lua_toboolean(L, 3); - mlist_to_hlist_args(n, w, m); + mlist_to_hlist(n, m, w); alink(vlink(temp_head)) = null; /*hh-ls */ lua_nodelib_push_fast(L, vlink(temp_head)); return 1; @@ -1835,13 +1780,13 @@ static int lua_nodelib_mlist_to_hlist(lua_State * L) static int lua_nodelib_mfont(lua_State * L) { - int f, s; - f = (int) luaL_checkinteger(L, 1); + int s; + int f = luaL_checkinteger(L, 1); if (lua_gettop(L) == 2) - s = (int) lua_tointeger(L, 2); /* this should be a multiple of 256 ! */ + s = lua_tointeger(L, 2); /* this should be a multiple of 256 ! */ else s = 0; - lua_pushnumber(L, fam_fnt(f, s)); + lua_pushinteger(L, fam_fnt(f,s)); return 1; } @@ -1911,13 +1856,34 @@ static int lua_nodelib_has_field(lua_State * L) return 1; } +/* node.is_char (node[,font]) */ + +static int lua_nodelib_is_char(lua_State * L) +{ + halfword f; + halfword n = *(check_isnode(L, 1)); + if ((type(n) == glyph_node) && (subtype(n) < 256)) { /* <= 256 */ + if (lua_type(L,2) == LUA_TNUMBER) { + f = (halfword) lua_tointeger(L, 2); + if (f && f == font(n)) { + lua_pushinteger(L,character(n)); + return 1; + } + } else { + lua_pushinteger(L,character(n)); + return 1; + } + } + lua_pushboolean(L,0); + return 1; +} + /* node.direct.has_field */ static int lua_nodelib_direct_has_field(lua_State * L) { int i = -2; - halfword n; - n = (halfword) lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if (n != null) i = get_node_field_id(L, 2, n); lua_pushboolean(L, (i != -2)); @@ -1993,10 +1959,9 @@ static int lua_nodelib_subtypes(lua_State * L) { int i = -1; int l = 0; - int t; const char **subtypes = NULL; const char *s ; - t = lua_type(L,1); + int t = lua_type(L,1); if (t == LUA_TSTRING) { /* official accessors */ s = lua_tostring(L,1); @@ -2020,7 +1985,7 @@ static int lua_nodelib_subtypes(lua_State * L) else if (lua_key_eq(s,pdf_literal)) subtypes = node_subtypes_pdf_literal; } else if (t == LUA_TNUMBER) { /* maybe */ - t = lua_tonumber(L,1); + t = lua_tointeger(L,1); if (t == glyph_node) subtypes = node_subtypes_glyph; else if (t == glue_node) { subtypes = node_subtypes_glue; l = 1; } else if (t == penalty_node) subtypes = node_subtypes_penalty; @@ -2066,20 +2031,18 @@ static int lua_nodelib_subtypes(lua_State * L) static int lua_nodelib_slide(lua_State * L) { - halfword *n; - halfword t; + halfword n; if (lua_isnil(L, 1)) return 1; /* the nil itself */ - n = check_isnode(L, 1); - t = *n; - if (t == null) + n = *check_isnode(L, 1); + if (n == null) return 1; /* the old userdata */ /* alink(t) = null; */ /* don't do this, |t|'s |alink| may be a valid pointer */ - while (vlink(t) != null) { - alink(vlink(t)) = t; - t = vlink(t); + while (vlink(n) != null) { + alink(vlink(n)) = n; + n = vlink(n); } - lua_nodelib_push_fast(L, t); + lua_nodelib_push_fast(L, n); return 1; } @@ -2087,8 +2050,7 @@ static int lua_nodelib_slide(lua_State * L) static int lua_nodelib_direct_slide(lua_State * L) { - halfword n; - n = (halfword) lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if (n == null) { lua_pushnil(L); } else { @@ -2096,7 +2058,7 @@ static int lua_nodelib_direct_slide(lua_State * L) alink(vlink(n)) = n; n = vlink(n); } - lua_pushnumber(L, n); + lua_pushinteger(L, n); } return 1; } @@ -2105,17 +2067,15 @@ static int lua_nodelib_direct_slide(lua_State * L) static int lua_nodelib_tail(lua_State * L) { - halfword *n; - halfword t; + halfword n; if (lua_isnil(L, 1)) return 1; /* the nil itself */ - n = check_isnode(L, 1); - t = *n; - if (t == null) + n = *check_isnode(L, 1); + if (n == null) return 1; /* the old userdata */ - while (vlink(t) != null) - t = vlink(t); - lua_nodelib_push_fast(L, t); + while (vlink(n) != null) + n = vlink(n); + lua_nodelib_push_fast(L, n); return 1; } @@ -2123,14 +2083,13 @@ static int lua_nodelib_tail(lua_State * L) static int lua_nodelib_direct_tail(lua_State * L) { - halfword n; - n = (halfword) lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if (n == null) { lua_pushnil(L); } else { while (vlink(n) != null) n = vlink(n); - lua_pushnumber(L, n); + lua_pushinteger(L, n); } return 1; } @@ -2139,22 +2098,20 @@ static int lua_nodelib_direct_tail(lua_State * L) static int lua_nodelib_end_of_math(lua_State * L) { - halfword *n; - halfword t; + halfword n; if (lua_isnil(L, 1)) return 0; - n = check_isnode(L, 1); - t = *n; - if (t == null) + n = *check_isnode(L, 1); + if (n == null) return 0; - if (type(t)==math_node && (subtype(t)==1)) { - lua_nodelib_push_fast(L, t); + if (type(n) == math_node && (subtype(n) == 1)) { + lua_nodelib_push_fast(L, n); return 1; } - while (vlink(t) != null) { - t = vlink(t); - if (t && (type(t)==math_node) && (subtype(t)==1)) { - lua_nodelib_push_fast(L, t); + while (vlink(n) != null) { + n = vlink(n); + if (n && (type(n) == math_node) && (subtype(n) == 1)) { + lua_nodelib_push_fast(L, n); return 1; } } @@ -2165,18 +2122,17 @@ static int lua_nodelib_end_of_math(lua_State * L) static int lua_nodelib_direct_end_of_math(lua_State * L) { - halfword n; - n = (halfword) lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if (n == null) return 0; if ((type(n)==math_node && (subtype(n)==1))) { - lua_pushnumber(L, n); + lua_pushinteger(L, n); return 1; } while (vlink(n) != null) { n = vlink(n); if (n && (type(n)==math_node) && (subtype(n)==1)) { - lua_pushnumber(L, n); + lua_pushinteger(L, n); return 1; } } @@ -2188,14 +2144,13 @@ static int lua_nodelib_direct_end_of_math(lua_State * L) static int lua_nodelib_has_attribute(lua_State * L) { - halfword *n; int i, val; - n = check_isnode(L, 1); - if (n != NULL) { - i = (int) lua_tointeger(L, 2); - val = (int) luaL_optinteger(L, 3, UNUSED_ATTRIBUTE); - if ((val = has_attribute(*n, i, val)) > UNUSED_ATTRIBUTE) { - lua_pushnumber(L, val); + halfword n = *check_isnode(L, 1); + if (n != null) { + i = lua_tointeger(L, 2); + val = luaL_optinteger(L, 3, UNUSED_ATTRIBUTE); + if ((val = has_attribute(n, i, val)) > UNUSED_ATTRIBUTE) { + lua_pushinteger(L, val); return 1; } } @@ -2207,14 +2162,13 @@ static int lua_nodelib_has_attribute(lua_State * L) static int lua_nodelib_direct_has_attribute(lua_State * L) { - halfword n; int i, val; - n = (halfword) lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if (n != null) { - i = (int) lua_tointeger(L, 2); - val = (int) luaL_optinteger(L, 3, UNUSED_ATTRIBUTE); + i = lua_tointeger(L, 2); + val = luaL_optinteger(L, 3, UNUSED_ATTRIBUTE); if ((val = has_attribute(n, i, val)) > UNUSED_ATTRIBUTE) { - lua_pushnumber(L, val); + lua_pushinteger(L, val); return 1; } } @@ -2222,20 +2176,83 @@ static int lua_nodelib_direct_has_attribute(lua_State * L) return 1; } +/* node.get_attribute */ + +static int lua_nodelib_get_attribute(lua_State * L) +{ + halfword p; + p = *check_isnode(L, 1); + if (nodetype_has_attributes(type(p))) { + p = node_attr(p); + if (p != null) { + p = vlink(p); + if (p != null) { + int i = lua_tointeger(L, 2); + while (p != null) { + if (attribute_id(p) == i) { + int ret = attribute_value(p); + if (ret == UNUSED_ATTRIBUTE) { + break; + } else { + lua_pushinteger(L,ret); + return 1; + } + } else if (attribute_id(p) > i) { + break; + } + p = vlink(p); + } + } + } + } + lua_pushnil(L); + return 1; +} + +/* node.direct.get_attribute */ + +static int lua_nodelib_direct_get_attribute(lua_State * L) +{ + register halfword p = lua_tointeger(L, 1); + if (nodetype_has_attributes(type(p))) { + p = node_attr(p); + if (p != null) { + p = vlink(p); + if (p != null) { + int i = lua_tointeger(L, 2); + while (p != null) { + if (attribute_id(p) == i) { + int ret = attribute_value(p); + if (ret == UNUSED_ATTRIBUTE) { + break; + } else { + lua_pushinteger(L,ret); + return 1; + } + } else if (attribute_id(p) > i) { + break; + } + p = vlink(p); + } + } + } + } + lua_pushnil(L); + return 1; +} + /* node.set_attribute */ static int lua_nodelib_set_attribute(lua_State * L) { - halfword *n; - int i, val; if (lua_gettop(L) == 3) { - i = (int) lua_tointeger(L, 2); - val = (int) lua_tointeger(L, 3); - n = check_isnode(L, 1); + int i = lua_tointeger(L, 2); + int val = lua_tointeger(L, 3); + halfword n = *check_isnode(L, 1); if (val == UNUSED_ATTRIBUTE) { - (void) unset_attribute(*n, i, val); + (void) unset_attribute(n, i, val); } else { - set_attribute(*n, i, val); + set_attribute(n, i, val); } } else { luaL_error(L, "incorrect number of arguments"); @@ -2247,9 +2264,8 @@ static int lua_nodelib_set_attribute(lua_State * L) static int lua_nodelib_direct_set_attribute(lua_State * L) { - halfword n; int i, val; - n = (halfword) lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if (n == null) return 0; if (lua_gettop(L) == 3) { @@ -2270,15 +2286,13 @@ static int lua_nodelib_direct_set_attribute(lua_State * L) static int lua_nodelib_unset_attribute(lua_State * L) { - halfword *n; - int i, val, ret; if (lua_gettop(L) <= 3) { - i=(int)luaL_checknumber(L, 2); - val=(int)luaL_optnumber(L, 3, UNUSED_ATTRIBUTE); - n = check_isnode(L, 1); - ret = unset_attribute(*n, i, val); + int i = luaL_checknumber(L, 2); + int val = luaL_optnumber(L, 3, UNUSED_ATTRIBUTE); + halfword n = *check_isnode(L, 1); + int ret = unset_attribute(n, i, val); if (ret > UNUSED_ATTRIBUTE) { - lua_pushnumber(L, ret); + lua_pushinteger(L, ret); } else { lua_pushnil(L); } @@ -2292,9 +2306,8 @@ static int lua_nodelib_unset_attribute(lua_State * L) static int lua_nodelib_direct_unset_attribute(lua_State * L) { - halfword n; int i, val, ret; - n = (halfword) lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if (n == null) { lua_pushnil(L); } else if (lua_gettop(L) <= 3) { /* a useless test, we never test for that elsewhere */ @@ -2302,7 +2315,7 @@ static int lua_nodelib_direct_unset_attribute(lua_State * L) val=(int)luaL_optnumber(L, 3, UNUSED_ATTRIBUTE); ret = unset_attribute(n, i, val); if (ret > UNUSED_ATTRIBUTE) { - lua_pushnumber(L, ret); + lua_pushinteger(L, ret); } else { lua_pushnil(L); } @@ -2353,7 +2366,7 @@ static int lua_nodelib_traverse_filtered(lua_State * L) lua_pushcclosure(L, nodelib_aux_nil, 0); return 1; } - n = *(check_isnode(L, 2)); + n = *check_isnode(L, 2); lua_pop(L, 1); /* the node, integer remains */ lua_pushcclosure(L, nodelib_aux_next_filtered, 1); lua_nodelib_push_fast(L, n); @@ -2368,21 +2381,24 @@ static int nodelib_direct_aux_next_filtered(lua_State * L) halfword t; /* traverser */ int i = (int) lua_tointeger(L, lua_upvalueindex(1)); if (lua_isnil(L, 2)) { /* first call */ - t = lua_tonumber(L,1) ; + t = lua_tointeger(L,1) ; lua_settop(L,1); } else { - t = lua_tonumber(L,2) ; + t = lua_tointeger(L,2) ; t = vlink(t); lua_settop(L,2); } - while (t != null && type(t) != i) { - t = vlink(t); - } - if (t == null) { - lua_pushnil(L); - } else { - lua_pushnumber(L,t); + while (1) { + if (t == null) { + break; + } else if (type(t) == i) { + lua_pushinteger(L,t); + return 1; + } else { + t = vlink(t); + } } + lua_pushnil(L); return 1; } @@ -2393,13 +2409,61 @@ static int lua_nodelib_direct_traverse_filtered(lua_State * L) lua_pushcclosure(L, nodelib_aux_nil, 0); return 1; } - n = (halfword) lua_tonumber(L, 2); + n = (halfword) lua_tointeger(L, 2); if (n == null) return 0; - n = (halfword) lua_tonumber(L, 2); + /* funny duplicate check + n = (halfword) lua_tointeger(L, 2); + */ lua_pop(L, 1); lua_pushcclosure(L, nodelib_direct_aux_next_filtered, 1); - lua_pushnumber(L,n); + lua_pushinteger(L,n); + lua_pushnil(L); + return 3; +} + +/* node.direct.traverse_char */ + +static int nodelib_direct_aux_next_char(lua_State * L) +{ + halfword t; /* traverser */ + /*int i = (int) lua_tointeger(L, lua_upvalueindex(1));*/ + if (lua_isnil(L, 2)) { /* first call */ + t = lua_tointeger(L,1) ; + lua_settop(L,1); + } else { + t = lua_tointeger(L,2) ; + t = vlink(t); + lua_settop(L,2); + } + while (1) { + if (t == null) { + break; + } else if ((type(t) == glyph_node) && (subtype(t) < 256)){ + lua_pushinteger(L,t); + return 1; + } else { + t = vlink(t); + } + } + lua_pushnil(L); + return 1; +} + +static int lua_nodelib_direct_traverse_char(lua_State * L) +{ + halfword n; + if (lua_isnil(L, 1)) { + lua_pushcclosure(L, nodelib_aux_nil, 0); + return 1; + } + n = (halfword) lua_tointeger(L, 1); + if (n == null) { + lua_pushcclosure(L, nodelib_aux_nil, 0); + return 1; + } + lua_pushcclosure(L, nodelib_direct_aux_next_char, 0); + lua_pushinteger(L,n); lua_pushnil(L); return 3; } @@ -2433,13 +2497,54 @@ static int lua_nodelib_traverse(lua_State * L) lua_pushcclosure(L, nodelib_aux_nil, 0); return 1; } - n = *(check_isnode(L, 1)); + n = *check_isnode(L, 1); lua_pushcclosure(L, nodelib_aux_next, 0); lua_nodelib_push_fast(L, n); lua_pushnil(L); return 3; } +/* node.traverse_char */ + +static int nodelib_aux_next_char(lua_State * L) +{ + halfword t; /* traverser */ + halfword *a; + if (lua_isnil(L, 2)) { /* first call */ + t = *check_isnode(L, 1); + lua_settop(L,1); + } else { + t = *check_isnode(L, 2); + t = vlink(t); + lua_settop(L,2); + } + while (1) { + if (t == null) { + break; + } else if ((type(t) == glyph_node) && (subtype(t) < 256)){ + fast_metatable_top(t); + return 1; + } else { + t = vlink(t); + } + } + return 1; +} + +static int lua_nodelib_traverse_char(lua_State * L) +{ + halfword n; + if (lua_isnil(L, 1)) { + lua_pushcclosure(L, nodelib_aux_nil, 0); + return 1; + } + n = *check_isnode(L, 1); + lua_pushcclosure(L, nodelib_aux_next_char, 0); + lua_nodelib_push_fast(L, n); + lua_pushnil(L); + return 3; +} + /* node.direct.traverse */ static int nodelib_direct_aux_next(lua_State * L) @@ -2447,17 +2552,17 @@ static int nodelib_direct_aux_next(lua_State * L) halfword t; /* traverser */ /*int i = (int) lua_tointeger(L, lua_upvalueindex(1));*/ if (lua_isnil(L, 2)) { /* first call */ - t = lua_tonumber(L,1) ; + t = lua_tointeger(L,1) ; lua_settop(L,1); } else { - t = lua_tonumber(L,2) ; + t = lua_tointeger(L,2) ; t = vlink(t); lua_settop(L,2); } if (t == null) { lua_pushnil(L); } else { - lua_pushnumber(L,t); + lua_pushinteger(L,t); } return 1; } @@ -2469,18 +2574,17 @@ static int lua_nodelib_direct_traverse(lua_State * L) lua_pushcclosure(L, nodelib_aux_nil, 0); return 1; } - n = (halfword) lua_tonumber(L, 1); + n = (halfword) lua_tointeger(L, 1); if (n == null) { lua_pushcclosure(L, nodelib_aux_nil, 0); return 1; } lua_pushcclosure(L, nodelib_direct_aux_next, 0); - lua_pushnumber(L,n); + lua_pushinteger(L,n); lua_pushnil(L); return 3; } - /* counting */ static int do_lua_nodelib_count(lua_State * L, halfword match, int i, halfword first1) @@ -2492,7 +2596,7 @@ static int do_lua_nodelib_count(lua_State * L, halfword match, int i, halfword f count++; t = vlink(t); } - lua_pushnumber(L, count); + lua_pushinteger(L, count); return 1; } @@ -2503,12 +2607,12 @@ static int lua_nodelib_length(lua_State * L) halfword n; halfword m = null; if (lua_isnil(L, 1)) { - lua_pushnumber(L, 0); + lua_pushinteger(L, 0); return 1; } - n = *(check_isnode(L, 1)); + n = *check_isnode(L, 1); if (lua_gettop(L) == 2) - m = *(check_isnode(L, 2)); + m = *check_isnode(L, 2); return do_lua_nodelib_count(L, m, -1, n); } @@ -2516,13 +2620,13 @@ static int lua_nodelib_length(lua_State * L) static int lua_nodelib_direct_length(lua_State * L) { - halfword n, m; - n = (halfword) lua_tonumber(L, 1); + halfword m; + halfword n = lua_tointeger(L, 1); if (n == 0) { - lua_pushnumber(L, 0); + lua_pushinteger(L, 0); return 1; } - m = (halfword) lua_tonumber(L, 2); + m = (halfword) lua_tointeger(L, 2); return do_lua_nodelib_count(L, m, -1, n); } @@ -2532,15 +2636,14 @@ static int lua_nodelib_count(lua_State * L) { halfword n; halfword m = null; - int i = -1; - i = (int) lua_tointeger(L, 1); + int i = lua_tointeger(L, 1); if (lua_isnil(L, 2)) { - lua_pushnumber(L, 0); + lua_pushinteger(L, 0); return 1; } - n = *(check_isnode(L, 2)); + n = *check_isnode(L, 2); if (lua_gettop(L) == 3) - m = *(check_isnode(L, 3)); + m = *check_isnode(L, 3); return do_lua_nodelib_count(L, m, i, n); } @@ -2549,9 +2652,9 @@ static int lua_nodelib_count(lua_State * L) static int lua_nodelib_direct_count(lua_State * L) { return do_lua_nodelib_count(L, - (halfword) lua_tonumber(L, 3), /* m */ + (halfword) lua_tointeger(L, 3), /* m */ (int) lua_tointeger(L, 1), /* i */ - (halfword) lua_tonumber(L, 2) /* n */ + (halfword) lua_tointeger(L, 2) /* n */ ); } @@ -2559,10 +2662,9 @@ static int lua_nodelib_direct_count(lua_State * L) int nodelib_getlist(lua_State * L, int n) { - halfword *m; if (lua_isuserdata(L, n)) { - m = check_isnode(L, n); - return *m; + halfword m = *check_isnode(L, n); + return m; } else { return null; } @@ -2606,21 +2708,19 @@ static int nodelib_nonwritable(lua_State * L, int n, const char *s) static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) { - int t ; - t = subtype(n); - + int t = subtype(n); if (t == user_defined_node) { if (lua_key_eq(s, user_id)) { - lua_pushnumber(L, user_node_id(n)); + lua_pushinteger(L, user_node_id(n)); } else if (lua_key_eq(s, type)) { - lua_pushnumber(L, user_node_type(n)); + lua_pushinteger(L, user_node_type(n)); } else if (lua_key_eq(s, value)) { switch (user_node_type(n)) { case 'a': nodelib_pushlist(L, user_node_value(n)); break; case 'd': - lua_pushnumber(L, user_node_value(n)); + lua_pushinteger(L, user_node_value(n)); break; case 'l': if (user_node_value(n) != 0) { @@ -2639,7 +2739,7 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) tokenlist_to_lua(L, user_node_value(n)); break; default: - lua_pushnumber(L, user_node_value(n)); + lua_pushinteger(L, user_node_value(n)); break; } } else { @@ -2647,7 +2747,7 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) } } else if (t == pdf_literal_node) { if (lua_key_eq(s, mode)) { - lua_pushnumber(L, pdf_literal_mode(n)); + lua_pushinteger(L, pdf_literal_mode(n)); } else if (lua_key_eq(s, data)) { if (pdf_literal_type(n) == lua_refid_literal) { lua_rawgeti(L, LUA_REGISTRYINDEX, pdf_literal_data(n)); @@ -2671,13 +2771,13 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) } } else if (t == pdf_annot_node) { if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); + lua_pushinteger(L, depth(n)); } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); + lua_pushinteger(L, height(n)); } else if (lua_key_eq(s, objnum)) { - lua_pushnumber(L, pdf_annot_objnum(n)); + lua_pushinteger(L, pdf_annot_objnum(n)); } else if (lua_key_eq(s, data)) { tokenlist_to_luastring(L, pdf_annot_data(n)); } else { @@ -2685,24 +2785,24 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) } } else if (t == pdf_dest_node) { if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); + lua_pushinteger(L, depth(n)); } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); + lua_pushinteger(L, height(n)); } else if (lua_key_eq(s, named_id)) { - lua_pushnumber(L, pdf_dest_named_id(n)); + lua_pushinteger(L, pdf_dest_named_id(n)); } else if (lua_key_eq(s, dest_id)) { if (pdf_dest_named_id(n) == 1) tokenlist_to_luastring(L, pdf_dest_id(n)); else - lua_pushnumber(L, pdf_dest_id(n)); + lua_pushinteger(L, pdf_dest_id(n)); } else if (lua_key_eq(s, dest_type)) { - lua_pushnumber(L, pdf_dest_type(n)); + lua_pushinteger(L, pdf_dest_type(n)); } else if (lua_key_eq(s, xyz_zoom)) { - lua_pushnumber(L, pdf_dest_xyz_zoom(n)); + lua_pushinteger(L, pdf_dest_xyz_zoom(n)); } else if (lua_key_eq(s, objnum)) { - lua_pushnumber(L, pdf_dest_objnum(n)); + lua_pushinteger(L, pdf_dest_objnum(n)); } else { lua_pushnil(L); } @@ -2714,9 +2814,9 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) } } else if (t == pdf_colorstack_node) { if (lua_key_eq(s, stack)) { - lua_pushnumber(L, pdf_colorstack_stack(n)); + lua_pushinteger(L, pdf_colorstack_stack(n)); } else if (lua_key_eq(s, command)) { - lua_pushnumber(L, pdf_colorstack_cmd(n)); + lua_pushinteger(L, pdf_colorstack_cmd(n)); } else if (lua_key_eq(s, data)) { tokenlist_to_luastring(L, pdf_colorstack_data(n)); } else { @@ -2724,13 +2824,13 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) } } else if (t == pdf_refobj_node) { if (lua_key_eq(s, objnum)) { - lua_pushnumber(L, pdf_obj_objnum(n)); + lua_pushinteger(L, pdf_obj_objnum(n)); } else { lua_pushnil(L); } } else if (t == write_node) { if (lua_key_eq(s, stream)) { - lua_pushnumber(L, write_stream(n)); + lua_pushinteger(L, write_stream(n)); } else if (lua_key_eq(s, data)) { tokenlist_to_lua(L, write_tokens(n)); } else { @@ -2744,13 +2844,13 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) } } else if (t == pdf_start_link_node) { if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); + lua_pushinteger(L, depth(n)); } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); + lua_pushinteger(L, height(n)); } else if (lua_key_eq(s, objnum)) { - lua_pushnumber(L, pdf_link_objnum(n)); + lua_pushinteger(L, pdf_link_objnum(n)); } else if (lua_key_eq(s, link_attr)) { tokenlist_to_luastring(L, pdf_link_attr(n)); } else if (lua_key_eq(s, action)) { @@ -2760,40 +2860,40 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) } } else if (t == pdf_action_node) { if (lua_key_eq(s, action_type)) { - lua_pushnumber(L, pdf_action_type(n)); + lua_pushinteger(L, pdf_action_type(n)); } else if (lua_key_eq(s, named_id)) { - lua_pushnumber(L, pdf_action_named_id(n)); + lua_pushinteger(L, pdf_action_named_id(n)); } else if (lua_key_eq(s, action_id)) { if (pdf_action_named_id(n) == 1) { tokenlist_to_luastring(L, pdf_action_id(n)); } else { - lua_pushnumber(L, pdf_action_id(n)); + lua_pushinteger(L, pdf_action_id(n)); } } else if (lua_key_eq(s, file)) { tokenlist_to_luastring(L, pdf_action_file(n)); } else if (lua_key_eq(s, new_window)) { - lua_pushnumber(L, pdf_action_new_window(n)); + lua_pushinteger(L, pdf_action_new_window(n)); } else if (lua_key_eq(s, data)) { tokenlist_to_luastring(L, pdf_action_tokens(n)); } else if (lua_key_eq(s, ref_count)) { - lua_pushnumber(L, pdf_action_refcount(n)); + lua_pushinteger(L, pdf_action_refcount(n)); } else { lua_pushnil(L); } } else if ((t == pdf_thread_node) || (t == pdf_start_thread_node)) { if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); + lua_pushinteger(L, depth(n)); } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); + lua_pushinteger(L, height(n)); } else if (lua_key_eq(s, named_id)) { - lua_pushnumber(L, pdf_thread_named_id(n)); + lua_pushinteger(L, pdf_thread_named_id(n)); } else if (lua_key_eq(s, thread_id)) { if (pdf_thread_named_id(n) == 1) { tokenlist_to_luastring(L, pdf_thread_id(n)); } else { - lua_pushnumber(L, pdf_thread_id(n)); + lua_pushinteger(L, pdf_thread_id(n)); } } else if (lua_key_eq(s, thread_attr)) { tokenlist_to_luastring(L, pdf_thread_attr(n)); @@ -2802,7 +2902,7 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) } } else if (t == open_node) { if (lua_key_eq(s, stream)) { - lua_pushnumber(L, write_stream(n)); + lua_pushinteger(L, write_stream(n)); } else if (lua_key_eq(s, name)) { nodelib_pushstring(L, open_name(n)); } else if (lua_key_eq(s, area)) { @@ -2814,7 +2914,7 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) } } else if (t == close_node) { if (lua_key_eq(s, stream)) { - lua_pushnumber(L, write_stream(n)); + lua_pushinteger(L, write_stream(n)); } else { lua_pushnil(L); } @@ -2830,13 +2930,11 @@ static int lua_nodelib_fast_getfield(lua_State * L) importance of fields */ - halfword n; halfword *a; const char *s; - int t ; - n = *((halfword *) lua_touserdata(L, 1)); - t = type(n); + halfword n = *((halfword *) lua_touserdata(L, 1)); + int t = type(n); /* @@ -2867,7 +2965,7 @@ static int lua_nodelib_fast_getfield(lua_State * L) while (p != null) { if (attribute_id(p) == i) { if ((int) attribute_value(p) > UNUSED_ATTRIBUTE) { - lua_pushnumber(L, (int) attribute_value(p)); + lua_pushinteger(L, (int) attribute_value(p)); } else { lua_pushnil(L); } @@ -2885,7 +2983,7 @@ static int lua_nodelib_fast_getfield(lua_State * L) s = lua_tostring(L, 2); if (lua_key_eq(s, id)) { - lua_pushnumber(L, t); + lua_pushinteger(L, t); } else if (lua_key_eq(s, next)) { fast_metatable_or_nil(vlink(n)); } else if (lua_key_eq(s, prev)) { @@ -2899,64 +2997,64 @@ static int lua_nodelib_fast_getfield(lua_State * L) } else if (t == glyph_node) { /* candidates: fontchar (font,char) whd (width,height,depth) */ if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, font)) { - lua_pushnumber(L, font(n)); + lua_pushinteger(L, font(n)); } else if (lua_key_eq(s, char)) { - lua_pushnumber(L, character(n)); + lua_pushinteger(L, character(n)); } else if (lua_key_eq(s, xoffset)) { - lua_pushnumber(L, x_displace(n)); + lua_pushinteger(L, x_displace(n)); } else if (lua_key_eq(s, yoffset)) { - lua_pushnumber(L, y_displace(n)); + lua_pushinteger(L, y_displace(n)); } else if (lua_key_eq(s, width)) { - lua_pushnumber(L, char_width(font(n),character(n))); + lua_pushinteger(L, char_width(font(n),character(n))); } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, char_height(font(n),character(n))); + lua_pushinteger(L, char_height(font(n),character(n))); } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, char_depth(font(n),character(n))); + lua_pushinteger(L, char_depth(font(n),character(n))); } else if (lua_key_eq(s, expansion_factor)) { - lua_pushnumber(L, ex_glyph(n)); + lua_pushinteger(L, ex_glyph(n)); } else if (lua_key_eq(s, components)) { fast_metatable_or_nil(lig_ptr(n)); } else if (lua_key_eq(s, lang)) { - lua_pushnumber(L, char_lang(n)); + lua_pushinteger(L, char_lang(n)); } else if (lua_key_eq(s, left)) { - lua_pushnumber(L, char_lhmin(n)); + lua_pushinteger(L, char_lhmin(n)); } else if (lua_key_eq(s, right)) { - lua_pushnumber(L, char_rhmin(n)); + lua_pushinteger(L, char_rhmin(n)); } else if (lua_key_eq(s, uchyph)) { - lua_pushnumber(L, char_uchyph(n)); + lua_pushinteger(L, char_uchyph(n)); } else { lua_pushnil(L); } } else if ((t == hlist_node) || (t == vlist_node)) { /* candidates: whd (width,height,depth) */ if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, list) || lua_key_eq(s, head)) { fast_metatable_or_nil_alink(list_ptr(n)); } else if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); + lua_pushinteger(L, height(n)); } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); + lua_pushinteger(L, depth(n)); } else if (lua_key_eq(s, dir)) { lua_push_dir_par(L, box_dir(n)); } else if (lua_key_eq(s, shift)) { - lua_pushnumber(L, shift_amount(n)); + lua_pushinteger(L, shift_amount(n)); } else if (lua_key_eq(s, glue_order)) { - lua_pushnumber(L, glue_order(n)); + lua_pushinteger(L, glue_order(n)); } else if (lua_key_eq(s, glue_sign)) { - lua_pushnumber(L, glue_sign(n)); + lua_pushinteger(L, glue_sign(n)); } else if (lua_key_eq(s, glue_set)) { - lua_pushnumber(L, (double) glue_set(n)); + lua_pushnumber(L, (double) glue_set(n)); /* float */ } else { lua_pushnil(L); } } else if (t == disc_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, pre)) { fast_metatable_or_nil(vlink(pre_break(n))); } else if (lua_key_eq(s, post)) { @@ -2968,7 +3066,7 @@ static int lua_nodelib_fast_getfield(lua_State * L) } } else if (t == glue_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, spec)) { nodelib_pushspec(L, glue_ptr(n)); } else if (lua_key_eq(s, leader)) { @@ -2976,36 +3074,36 @@ static int lua_nodelib_fast_getfield(lua_State * L) } else { n = glue_ptr(n); if (!n) { - lua_pushnil(L); + lua_pushinteger(L, 0); /* zero skip constant */ } else if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, stretch)) { - lua_pushnumber(L, stretch(n)); + lua_pushinteger(L, stretch(n)); } else if (lua_key_eq(s, shrink)) { - lua_pushnumber(L, shrink(n)); + lua_pushinteger(L, shrink(n)); } else if (lua_key_eq(s, stretch_order)) { - lua_pushnumber(L, stretch_order(n)); + lua_pushinteger(L, stretch_order(n)); } else if (lua_key_eq(s, shrink_order)) { - lua_pushnumber(L, shrink_order(n)); + lua_pushinteger(L, shrink_order(n)); } else { lua_pushnil(L); } } } else if (t == glue_spec_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, 0); /* dummy, the only one that prevents move up */ + lua_pushinteger(L, 0); /* dummy, the only one that prevents move up */ } else if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, stretch)) { - lua_pushnumber(L, stretch(n)); + lua_pushinteger(L, stretch(n)); } else if (lua_key_eq(s, shrink)) { - lua_pushnumber(L, shrink(n)); + lua_pushinteger(L, shrink(n)); } else if (lua_key_eq(s, stretch_order)) { - lua_pushnumber(L, stretch_order(n)); + lua_pushinteger(L, stretch_order(n)); } else if (lua_key_eq(s, shrink_order)) { - lua_pushnumber(L, shrink_order(n)); + lua_pushinteger(L, shrink_order(n)); } else if (lua_key_eq(s, ref_count)) { - lua_pushnumber(L, glue_ref_count(n)); + lua_pushinteger(L, glue_ref_count(n)); } else if (lua_key_eq(s, writable)) { lua_pushboolean(L, valid_node(n)); } else { @@ -3013,83 +3111,82 @@ static int lua_nodelib_fast_getfield(lua_State * L) } } else if (t == kern_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, kern)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, expansion_factor)) { - lua_pushnumber(L, ex_kern(n)); + lua_pushinteger(L, ex_kern(n)); } else { lua_pushnil(L); } } else if (t == penalty_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, penalty)) { - lua_pushnumber(L, penalty(n)); + lua_pushinteger(L, penalty(n)); } else { lua_pushnil(L); } } else if (t == rule_node) { /* candidates: whd (width,height,depth) */ if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); + lua_pushinteger(L, height(n)); } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); + lua_pushinteger(L, depth(n)); } else if (lua_key_eq(s, dir)) { lua_push_dir_par(L, rule_dir(n)); } else if (lua_key_eq(s, index)) { - lua_pushnumber(L, rule_index(n)); + lua_pushinteger(L, rule_index(n)); } else if (lua_key_eq(s, transform)) { - lua_pushnumber(L,rule_transform(n)); + lua_pushinteger(L,rule_transform(n)); } else { lua_pushnil(L); } } else if (t == dir_node) { if (lua_key_eq(s, dir)) { - // nodelib_pushdir(L, dir_dir(n), true); lua_push_dir_text(L, dir_dir(n)); } else if (lua_key_eq(s, level)) { - lua_pushnumber(L, dir_level(n)); + lua_pushinteger(L, dir_level(n)); } else if (lua_key_eq(s, dvi_ptr)) { - lua_pushnumber(L, dir_dvi_ptr(n)); + lua_pushinteger(L, dir_dvi_ptr(n)); } else if (lua_key_eq(s, dir_h)) { - lua_pushnumber(L, dir_dvi_h(n)); + lua_pushinteger(L, dir_dvi_h(n)); } else { lua_pushnil(L); } } else if (t == local_par_node) { if (lua_key_eq(s, pen_inter)) { - lua_pushnumber(L, local_pen_inter(n)); + lua_pushinteger(L, local_pen_inter(n)); } else if (lua_key_eq(s, pen_broken)) { - lua_pushnumber(L, local_pen_broken(n)); + lua_pushinteger(L, local_pen_broken(n)); } else if (lua_key_eq(s, dir)) { lua_push_dir_par(L, local_par_dir(n)); } else if (lua_key_eq(s, box_left)) { /* can be: fast_metatable_or_nil(local_box_left(n)) */ nodelib_pushlist(L, local_box_left(n)); } else if (lua_key_eq(s, box_left_width)) { - lua_pushnumber(L, local_box_left_width(n)); + lua_pushinteger(L, local_box_left_width(n)); } else if (lua_key_eq(s, box_right)) { /* can be: fast_metatable_or_nil(local_box_right(n)) */ nodelib_pushlist(L, local_box_right(n)); } else if (lua_key_eq(s, box_right_width)) { - lua_pushnumber(L, local_box_right_width(n)); + lua_pushinteger(L, local_box_right_width(n)); } else { lua_pushnil(L); } } else if (t == whatsit_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else { lua_nodelib_getfield_whatsit(L, n, s); } } else if (t == simple_noad) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, nucleus)) { fast_metatable_or_nil(nucleus(n)); } else if (lua_key_eq(s, sub)) { @@ -3102,19 +3199,19 @@ static int lua_nodelib_fast_getfield(lua_State * L) } else if ((t == math_char_node) || (t == math_text_char_node)) { /* candidates: famchar (fam,char) */ if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, fam)) { - lua_pushnumber(L, math_fam(n)); + lua_pushinteger(L, math_fam(n)); } else if (lua_key_eq(s, char)) { - lua_pushnumber(L, math_character(n)); + lua_pushinteger(L, math_character(n)); } else { lua_pushnil(L); } } else if (t == mark_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, class)) { - lua_pushnumber(L, mark_class(n)); + lua_pushinteger(L, mark_class(n)); } else if (lua_key_eq(s, mark)) { tokenlist_to_lua(L, mark_ptr(n)); } else { @@ -3122,13 +3219,13 @@ static int lua_nodelib_fast_getfield(lua_State * L) } } else if (t == ins_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, cost)) { - lua_pushnumber(L, float_cost(n)); + lua_pushinteger(L, float_cost(n)); } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); + lua_pushinteger(L, depth(n)); } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); + lua_pushinteger(L, height(n)); } else if (lua_key_eq(s, spec)) { nodelib_pushspec(L, split_top_ptr(n)); } else if ((lua_key_eq(s, list)) || (lua_key_eq(s, head))) { @@ -3138,17 +3235,17 @@ static int lua_nodelib_fast_getfield(lua_State * L) } } else if (t == math_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, surround)) { - lua_pushnumber(L, surround(n)); + lua_pushinteger(L, surround(n)); } else { lua_pushnil(L); } } else if (t == fraction_noad) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, width)) { - lua_pushnumber(L, thickness(n)); + lua_pushinteger(L, thickness(n)); } else if (lua_key_eq(s, num)) { fast_metatable_or_nil(numerator(n)); } else if (lua_key_eq(s, denom)) { @@ -3162,7 +3259,7 @@ static int lua_nodelib_fast_getfield(lua_State * L) } } else if (t == style_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, style)) { lua_push_math_style_name(L,subtype(n)); } else { @@ -3170,7 +3267,7 @@ static int lua_nodelib_fast_getfield(lua_State * L) } } else if (t == accent_noad) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, nucleus)) { fast_metatable_or_nil(nucleus(n)); } else if (lua_key_eq(s, sub)) { @@ -3188,7 +3285,7 @@ static int lua_nodelib_fast_getfield(lua_State * L) } } else if (t == fence_noad) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, delim)) { fast_metatable_or_nil(delimiter(n)); } else { @@ -3196,21 +3293,21 @@ static int lua_nodelib_fast_getfield(lua_State * L) } } else if (t == delim_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, small_fam)) { - lua_pushnumber(L, small_fam(n)); + lua_pushinteger(L, small_fam(n)); } else if (lua_key_eq(s, small_char)) { - lua_pushnumber(L, small_char(n)); + lua_pushinteger(L, small_char(n)); } else if (lua_key_eq(s, large_fam)) { - lua_pushnumber(L, large_fam(n)); + lua_pushinteger(L, large_fam(n)); } else if (lua_key_eq(s, large_char)) { - lua_pushnumber(L, large_char(n)); + lua_pushinteger(L, large_char(n)); } else { lua_pushnil(L); } } else if ((t == sub_box_node) || (t == sub_mlist_node)) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if ((lua_key_eq(s, list)) || (lua_key_eq(s, head))){ fast_metatable_or_nil_alink(math_list(n)); } else { @@ -3218,7 +3315,7 @@ static int lua_nodelib_fast_getfield(lua_State * L) } } else if (t == radical_noad) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, nucleus)) { fast_metatable_or_nil(nucleus(n)); } else if (lua_key_eq(s, sub)) { @@ -3234,9 +3331,9 @@ static int lua_nodelib_fast_getfield(lua_State * L) } } else if (t == margin_kern_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, glyph)) { fast_metatable_or_nil(margin_char(n)); } else { @@ -3244,7 +3341,7 @@ static int lua_nodelib_fast_getfield(lua_State * L) } } else if (t == split_up_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, last_ins_ptr)) { fast_metatable_or_nil(last_ins_ptr(n)); } else if (lua_key_eq(s, best_ins_ptr)) { @@ -3258,7 +3355,7 @@ static int lua_nodelib_fast_getfield(lua_State * L) } } else if (t == choice_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, display)) { fast_metatable_or_nil(display_mlist(n)); } else if (lua_key_eq(s, text)) { @@ -3272,7 +3369,7 @@ static int lua_nodelib_fast_getfield(lua_State * L) } } else if (t == inserting_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, last_ins_ptr)) { fast_metatable_or_nil(last_ins_ptr(n)); } else if (lua_key_eq(s, best_ins_ptr)) { @@ -3282,17 +3379,17 @@ static int lua_nodelib_fast_getfield(lua_State * L) } } else if (t == attribute_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, number)) { - lua_pushnumber(L, attribute_id(n)); + lua_pushinteger(L, attribute_id(n)); } else if (lua_key_eq(s, value)) { - lua_pushnumber(L, attribute_value(n)); + lua_pushinteger(L, attribute_value(n)); } else { lua_pushnil(L); } } else if (t == adjust_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if ((lua_key_eq(s, list)) || (lua_key_eq(s, head))) { fast_metatable_or_nil_alink(adjust_ptr(n)); } else { @@ -3300,25 +3397,25 @@ static int lua_nodelib_fast_getfield(lua_State * L) } } else if (t == unset_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); + lua_pushinteger(L, height(n)); } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); + lua_pushinteger(L, depth(n)); } else if (lua_key_eq(s, dir)) { lua_push_dir_par(L, box_dir(n)); } else if (lua_key_eq(s, shrink)) { - lua_pushnumber(L, glue_shrink(n)); + lua_pushinteger(L, glue_shrink(n)); } else if (lua_key_eq(s, glue_order)) { - lua_pushnumber(L, glue_order(n)); + lua_pushinteger(L, glue_order(n)); } else if (lua_key_eq(s, glue_sign)) { - lua_pushnumber(L, glue_sign(n)); + lua_pushinteger(L, glue_sign(n)); } else if (lua_key_eq(s, stretch)) { - lua_pushnumber(L, glue_stretch(n)); + lua_pushinteger(L, glue_stretch(n)); } else if (lua_key_eq(s, count)) { - lua_pushnumber(L, span_count(n)); + lua_pushinteger(L, span_count(n)); } else if ((lua_key_eq(s, list)) || (lua_key_eq(s, head))){ fast_metatable_or_nil_alink(list_ptr(n)); } else { @@ -3326,15 +3423,15 @@ static int lua_nodelib_fast_getfield(lua_State * L) } } else if (t == attribute_list_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else { lua_pushnil(L); } } else if (t == boundary_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, value)) { - lua_pushnumber(L, boundary_value(n)); + lua_pushinteger(L, boundary_value(n)); } else { lua_pushnil(L); } @@ -3369,21 +3466,19 @@ static int lua_nodelib_getfield(lua_State * L) static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char *s) { - int t ; - t = subtype(n); - + int t = subtype(n); if (t == user_defined_node) { if (lua_key_eq(s, user_id)) { - lua_pushnumber(L, user_node_id(n)); + lua_pushinteger(L, user_node_id(n)); } else if (lua_key_eq(s, type)) { - lua_pushnumber(L, user_node_type(n)); + lua_pushinteger(L, user_node_type(n)); } else if (lua_key_eq(s, value)) { switch (user_node_type(n)) { case 'a': nodelib_pushdirect(user_node_value(n)); break; case 'd': - lua_pushnumber(L, user_node_value(n)); + lua_pushinteger(L, user_node_value(n)); break; case 'l': if (user_node_value(n) != 0) { @@ -3402,7 +3497,7 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char tokenlist_to_lua(L, user_node_value(n)); break; default: - lua_pushnumber(L, user_node_value(n)); + lua_pushinteger(L, user_node_value(n)); break; } } else { @@ -3410,7 +3505,7 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char } } else if (t == pdf_literal_node) { if (lua_key_eq(s, mode)) { - lua_pushnumber(L, pdf_literal_mode(n)); + lua_pushinteger(L, pdf_literal_mode(n)); } else if (lua_key_eq(s, data)) { if (pdf_literal_type(n) == lua_refid_literal) { lua_rawgeti(L, LUA_REGISTRYINDEX, pdf_literal_data(n)); @@ -3434,13 +3529,13 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char } } else if (t == pdf_annot_node) { if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); + lua_pushinteger(L, depth(n)); } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); + lua_pushinteger(L, height(n)); } else if (lua_key_eq(s, objnum)) { - lua_pushnumber(L, pdf_annot_objnum(n)); + lua_pushinteger(L, pdf_annot_objnum(n)); } else if (lua_key_eq(s, data)) { tokenlist_to_luastring(L, pdf_annot_data(n)); } else { @@ -3448,24 +3543,24 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char } } else if (t == pdf_dest_node) { if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); + lua_pushinteger(L, depth(n)); } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); + lua_pushinteger(L, height(n)); } else if (lua_key_eq(s, named_id)) { - lua_pushnumber(L, pdf_dest_named_id(n)); + lua_pushinteger(L, pdf_dest_named_id(n)); } else if (lua_key_eq(s, dest_id)) { if (pdf_dest_named_id(n) == 1) tokenlist_to_luastring(L, pdf_dest_id(n)); else - lua_pushnumber(L, pdf_dest_id(n)); + lua_pushinteger(L, pdf_dest_id(n)); } else if (lua_key_eq(s, dest_type)) { - lua_pushnumber(L, pdf_dest_type(n)); + lua_pushinteger(L, pdf_dest_type(n)); } else if (lua_key_eq(s, xyz_zoom)) { - lua_pushnumber(L, pdf_dest_xyz_zoom(n)); + lua_pushinteger(L, pdf_dest_xyz_zoom(n)); } else if (lua_key_eq(s, objnum)) { - lua_pushnumber(L, pdf_dest_objnum(n)); + lua_pushinteger(L, pdf_dest_objnum(n)); } else { lua_pushnil(L); } @@ -3477,9 +3572,9 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char } } else if (t == pdf_colorstack_node) { if (lua_key_eq(s, stack)) { - lua_pushnumber(L, pdf_colorstack_stack(n)); + lua_pushinteger(L, pdf_colorstack_stack(n)); } else if (lua_key_eq(s, command)) { - lua_pushnumber(L, pdf_colorstack_cmd(n)); + lua_pushinteger(L, pdf_colorstack_cmd(n)); } else if (lua_key_eq(s, data)) { tokenlist_to_luastring(L, pdf_colorstack_data(n)); } else { @@ -3487,13 +3582,13 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char } } else if (t == pdf_refobj_node) { if (lua_key_eq(s, objnum)) { - lua_pushnumber(L, pdf_obj_objnum(n)); + lua_pushinteger(L, pdf_obj_objnum(n)); } else { lua_pushnil(L); } } else if (t == write_node) { if (lua_key_eq(s, stream)) { - lua_pushnumber(L, write_stream(n)); + lua_pushinteger(L, write_stream(n)); } else if (lua_key_eq(s, data)) { tokenlist_to_lua(L, write_tokens(n)); } else { @@ -3507,13 +3602,13 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char } } else if (t == pdf_start_link_node) { if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); + lua_pushinteger(L, depth(n)); } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); + lua_pushinteger(L, height(n)); } else if (lua_key_eq(s, objnum)) { - lua_pushnumber(L, pdf_link_objnum(n)); + lua_pushinteger(L, pdf_link_objnum(n)); } else if (lua_key_eq(s, link_attr)) { tokenlist_to_luastring(L, pdf_link_attr(n)); } else if (lua_key_eq(s, action)) { @@ -3523,40 +3618,40 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char } } else if (t == pdf_action_node) { if (lua_key_eq(s, action_type)) { - lua_pushnumber(L, pdf_action_type(n)); + lua_pushinteger(L, pdf_action_type(n)); } else if (lua_key_eq(s, named_id)) { - lua_pushnumber(L, pdf_action_named_id(n)); + lua_pushinteger(L, pdf_action_named_id(n)); } else if (lua_key_eq(s, action_id)) { if (pdf_action_named_id(n) == 1) { tokenlist_to_luastring(L, pdf_action_id(n)); } else { - lua_pushnumber(L, pdf_action_id(n)); + lua_pushinteger(L, pdf_action_id(n)); } } else if (lua_key_eq(s, file)) { tokenlist_to_luastring(L, pdf_action_file(n)); } else if (lua_key_eq(s, new_window)) { - lua_pushnumber(L, pdf_action_new_window(n)); + lua_pushinteger(L, pdf_action_new_window(n)); } else if (lua_key_eq(s, data)) { tokenlist_to_luastring(L, pdf_action_tokens(n)); } else if (lua_key_eq(s, ref_count)) { - lua_pushnumber(L, pdf_action_refcount(n)); + lua_pushinteger(L, pdf_action_refcount(n)); } else { lua_pushnil(L); } } else if ((t == pdf_thread_node) || (t == pdf_start_thread_node)) { if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); + lua_pushinteger(L, depth(n)); } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); + lua_pushinteger(L, height(n)); } else if (lua_key_eq(s, named_id)) { - lua_pushnumber(L, pdf_thread_named_id(n)); + lua_pushinteger(L, pdf_thread_named_id(n)); } else if (lua_key_eq(s, thread_id)) { if (pdf_thread_named_id(n) == 1) { tokenlist_to_luastring(L, pdf_thread_id(n)); } else { - lua_pushnumber(L, pdf_thread_id(n)); + lua_pushinteger(L, pdf_thread_id(n)); } } else if (lua_key_eq(s, thread_attr)) { tokenlist_to_luastring(L, pdf_thread_attr(n)); @@ -3565,7 +3660,7 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char } } else if (t == open_node) { if (lua_key_eq(s, stream)) { - lua_pushnumber(L, write_stream(n)); + lua_pushinteger(L, write_stream(n)); } else if (lua_key_eq(s, name)) { nodelib_pushstring(L, open_name(n)); } else if (lua_key_eq(s, area)) { @@ -3577,7 +3672,7 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char } } else if (t == close_node) { if (lua_key_eq(s, stream)) { - lua_pushnumber(L, write_stream(n)); + lua_pushinteger(L, write_stream(n)); } else { lua_pushnil(L); } @@ -3589,24 +3684,16 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char static int lua_nodelib_direct_getfield(lua_State * L) { - halfword n; const char *s; - int t ; - - n = (halfword) lua_tonumber(L, 1); - - t = type(n); - + halfword n = lua_tointeger(L, 1); + int t = type(n); if (lua_type(L, 2) == LUA_TNUMBER) { - halfword p; int i; - if (! nodetype_has_attributes(t)) { lua_pushnil(L) ; return 1; } - p = node_attr(n); if (p == null || vlink(p) == null) { lua_pushnil(L) ; @@ -3617,7 +3704,7 @@ static int lua_nodelib_direct_getfield(lua_State * L) while (p != null) { if (attribute_id(p) == i) { if ((int) attribute_value(p) > UNUSED_ATTRIBUTE) { - lua_pushnumber(L, (int) attribute_value(p)); + lua_pushinteger(L, (int) attribute_value(p)); } else { lua_pushnil(L); } @@ -3635,50 +3722,50 @@ static int lua_nodelib_direct_getfield(lua_State * L) s = lua_tostring(L, 2); if (lua_key_eq(s, id)) { - lua_pushnumber(L, t); + lua_pushinteger(L, t); } else if (lua_key_eq(s, next)) { nodelib_pushdirect_or_nil(vlink(n)); } else if (lua_key_eq(s, prev)) { nodelib_pushdirect_or_nil(alink(n)); + } else if (lua_key_eq(s, subtype)) { + if (t == glue_spec_node) { + lua_pushinteger(L, 0); /* dummy, the only one */ + } else { + lua_pushinteger(L, subtype(n)); + } } else if (lua_key_eq(s, attr)) { if (! nodetype_has_attributes(t)) { lua_pushnil(L); } else { nodelib_pushattr(L, node_attr(n)); } - } else if (lua_key_eq(s, subtype)) { - if (t == glue_spec_node) { - lua_pushnumber(L, 0); /* dummy, the only one */ - } else { - lua_pushnumber(L, subtype(n)); - } } else if (t == glyph_node) { if (lua_key_eq(s, font)) { - lua_pushnumber(L, font(n)); + lua_pushinteger(L, font(n)); } else if (lua_key_eq(s, char)) { - lua_pushnumber(L, character(n)); + lua_pushinteger(L, character(n)); } else if (lua_key_eq(s, xoffset)) { - lua_pushnumber(L, x_displace(n)); + lua_pushinteger(L, x_displace(n)); } else if (lua_key_eq(s, yoffset)) { - lua_pushnumber(L, y_displace(n)); + lua_pushinteger(L, y_displace(n)); } else if (lua_key_eq(s, width)) { - lua_pushnumber(L, char_width(font(n),character(n))); + lua_pushinteger(L, char_width(font(n),character(n))); } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, char_height(font(n),character(n))); + lua_pushinteger(L, char_height(font(n),character(n))); } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, char_depth(font(n),character(n))); + lua_pushinteger(L, char_depth(font(n),character(n))); } else if (lua_key_eq(s, expansion_factor)) { - lua_pushnumber(L, ex_glyph(n)); + lua_pushinteger(L, ex_glyph(n)); } else if (lua_key_eq(s, components)) { nodelib_pushdirect_or_nil(lig_ptr(n)); } else if (lua_key_eq(s, lang)) { - lua_pushnumber(L, char_lang(n)); + lua_pushinteger(L, char_lang(n)); } else if (lua_key_eq(s, left)) { - lua_pushnumber(L, char_lhmin(n)); + lua_pushinteger(L, char_lhmin(n)); } else if (lua_key_eq(s, right)) { - lua_pushnumber(L, char_rhmin(n)); + lua_pushinteger(L, char_rhmin(n)); } else if (lua_key_eq(s, uchyph)) { - lua_pushnumber(L, char_uchyph(n)); + lua_pushinteger(L, char_uchyph(n)); } else { lua_pushnil(L); } @@ -3687,21 +3774,21 @@ static int lua_nodelib_direct_getfield(lua_State * L) if (lua_key_eq(s, list) || lua_key_eq(s, head)) { nodelib_pushdirect_or_nil_alink(list_ptr(n)); } else if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); + lua_pushinteger(L, height(n)); } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); + lua_pushinteger(L, depth(n)); } else if (lua_key_eq(s, dir)) { lua_push_dir_par(L, box_dir(n)); } else if (lua_key_eq(s, shift)) { - lua_pushnumber(L, shift_amount(n)); + lua_pushinteger(L, shift_amount(n)); } else if (lua_key_eq(s, glue_order)) { - lua_pushnumber(L, glue_order(n)); + lua_pushinteger(L, glue_order(n)); } else if (lua_key_eq(s, glue_sign)) { - lua_pushnumber(L, glue_sign(n)); + lua_pushinteger(L, glue_sign(n)); } else if (lua_key_eq(s, glue_set)) { - lua_pushnumber(L, (double) glue_set(n)); + lua_pushnumber(L, (double) glue_set(n)); /* float */ } else { lua_pushnil(L); } @@ -3723,34 +3810,34 @@ static int lua_nodelib_direct_getfield(lua_State * L) } else { n = glue_ptr(n); if (!n) { - lua_pushnil(L); + lua_pushinteger(L, 0); /* zero skip constant */ } else if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, stretch)) { - lua_pushnumber(L, stretch(n)); + lua_pushinteger(L, stretch(n)); } else if (lua_key_eq(s, shrink)) { - lua_pushnumber(L, shrink(n)); + lua_pushinteger(L, shrink(n)); } else if (lua_key_eq(s, stretch_order)) { - lua_pushnumber(L, stretch_order(n)); + lua_pushinteger(L, stretch_order(n)); } else if (lua_key_eq(s, shrink_order)) { - lua_pushnumber(L, shrink_order(n)); + lua_pushinteger(L, shrink_order(n)); } else { lua_pushnil(L); } } } else if (t == glue_spec_node) { if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, stretch)) { - lua_pushnumber(L, stretch(n)); + lua_pushinteger(L, stretch(n)); } else if (lua_key_eq(s, shrink)) { - lua_pushnumber(L, shrink(n)); + lua_pushinteger(L, shrink(n)); } else if (lua_key_eq(s, stretch_order)) { - lua_pushnumber(L, stretch_order(n)); + lua_pushinteger(L, stretch_order(n)); } else if (lua_key_eq(s, shrink_order)) { - lua_pushnumber(L, shrink_order(n)); + lua_pushinteger(L, shrink_order(n)); } else if (lua_key_eq(s, ref_count)) { - lua_pushnumber(L, glue_ref_count(n)); + lua_pushinteger(L, glue_ref_count(n)); } else if (lua_key_eq(s, writable)) { lua_pushboolean(L, valid_node(n)); } else { @@ -3758,63 +3845,62 @@ static int lua_nodelib_direct_getfield(lua_State * L) } } else if (t == kern_node) { if (lua_key_eq(s, kern)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, expansion_factor)) { - lua_pushnumber(L, ex_kern(n)); + lua_pushinteger(L, ex_kern(n)); } else { lua_pushnil(L); } } else if (t == penalty_node) { if (lua_key_eq(s, penalty)) { - lua_pushnumber(L, penalty(n)); + lua_pushinteger(L, penalty(n)); } else { lua_pushnil(L); } } else if (t == rule_node) { /* candidates: whd (width,height,depth) */ if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); + lua_pushinteger(L, height(n)); } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); + lua_pushinteger(L, depth(n)); } else if (lua_key_eq(s, dir)) { lua_push_dir_par(L, rule_dir(n)); } else if (lua_key_eq(s, index)) { - lua_pushnumber(L, rule_index(n)); + lua_pushinteger(L, rule_index(n)); } else if (lua_key_eq(s, transform)) { - lua_pushnumber(L,rule_transform(n)); + lua_pushinteger(L,rule_transform(n)); } else { lua_pushnil(L); } } else if (t == dir_node) { if (lua_key_eq(s, dir)) { - // nodelib_pushdir(L, dir_dir(n), true); lua_push_dir_text(L, dir_dir(n)); } else if (lua_key_eq(s, level)) { - lua_pushnumber(L, dir_level(n)); + lua_pushinteger(L, dir_level(n)); } else if (lua_key_eq(s, dvi_ptr)) { - lua_pushnumber(L, dir_dvi_ptr(n)); + lua_pushinteger(L, dir_dvi_ptr(n)); } else if (lua_key_eq(s, dir_h)) { - lua_pushnumber(L, dir_dvi_h(n)); + lua_pushinteger(L, dir_dvi_h(n)); } else { lua_pushnil(L); } } else if (t == local_par_node) { if (lua_key_eq(s, pen_inter)) { - lua_pushnumber(L, local_pen_inter(n)); + lua_pushinteger(L, local_pen_inter(n)); } else if (lua_key_eq(s, pen_broken)) { - lua_pushnumber(L, local_pen_broken(n)); + lua_pushinteger(L, local_pen_broken(n)); } else if (lua_key_eq(s, dir)) { lua_push_dir_par(L, local_par_dir(n)); } else if (lua_key_eq(s, box_left)) { nodelib_pushdirect_or_nil(local_box_left(n)); } else if (lua_key_eq(s, box_left_width)) { - lua_pushnumber(L, local_box_left_width(n)); + lua_pushinteger(L, local_box_left_width(n)); } else if (lua_key_eq(s, box_right)) { nodelib_pushdirect_or_nil(local_box_right(n)); } else if (lua_key_eq(s, box_right_width)) { - lua_pushnumber(L, local_box_right_width(n)); + lua_pushinteger(L, local_box_right_width(n)); } else { lua_pushnil(L); } @@ -3832,15 +3918,15 @@ static int lua_nodelib_direct_getfield(lua_State * L) } } else if ((t == math_char_node) || (t == math_text_char_node)) { if (lua_key_eq(s, fam)) { - lua_pushnumber(L, math_fam(n)); + lua_pushinteger(L, math_fam(n)); } else if (lua_key_eq(s, char)) { - lua_pushnumber(L, math_character(n)); + lua_pushinteger(L, math_character(n)); } else { lua_pushnil(L); } } else if (t == mark_node) { if (lua_key_eq(s, class)) { - lua_pushnumber(L, mark_class(n)); + lua_pushinteger(L, mark_class(n)); } else if (lua_key_eq(s, mark)) { tokenlist_to_lua(L, mark_ptr(n)); } else { @@ -3848,11 +3934,11 @@ static int lua_nodelib_direct_getfield(lua_State * L) } } else if (t == ins_node) { if (lua_key_eq(s, cost)) { - lua_pushnumber(L, float_cost(n)); + lua_pushinteger(L, float_cost(n)); } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); + lua_pushinteger(L, depth(n)); } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); + lua_pushinteger(L, height(n)); } else if (lua_key_eq(s, spec)) { nodelib_pushdirect_or_nil(split_top_ptr(n)); } else if ((lua_key_eq(s, list)) || (lua_key_eq(s, head))) { @@ -3862,13 +3948,13 @@ static int lua_nodelib_direct_getfield(lua_State * L) } } else if (t == math_node) { if (lua_key_eq(s, surround)) { - lua_pushnumber(L, surround(n)); + lua_pushinteger(L, surround(n)); } else { lua_pushnil(L); } } else if (t == fraction_noad) { if (lua_key_eq(s, width)) { - lua_pushnumber(L, thickness(n)); + lua_pushinteger(L, thickness(n)); } else if (lua_key_eq(s, num)) { nodelib_pushdirect_or_nil(numerator(n)); } else if (lua_key_eq(s, denom)) { @@ -3910,13 +3996,13 @@ static int lua_nodelib_direct_getfield(lua_State * L) } } else if (t == delim_node) { if (lua_key_eq(s, small_fam)) { - lua_pushnumber(L, small_fam(n)); + lua_pushinteger(L, small_fam(n)); } else if (lua_key_eq(s, small_char)) { - lua_pushnumber(L, small_char(n)); + lua_pushinteger(L, small_char(n)); } else if (lua_key_eq(s, large_fam)) { - lua_pushnumber(L, large_fam(n)); + lua_pushinteger(L, large_fam(n)); } else if (lua_key_eq(s, large_char)) { - lua_pushnumber(L, large_char(n)); + lua_pushinteger(L, large_char(n)); } else { lua_pushnil(L); } @@ -3942,7 +4028,7 @@ static int lua_nodelib_direct_getfield(lua_State * L) } } else if (t == margin_kern_node) { if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, glyph)) { nodelib_pushdirect_or_nil(margin_char(n)); } else { @@ -3982,9 +4068,9 @@ static int lua_nodelib_direct_getfield(lua_State * L) } } else if (t == attribute_node) { if (lua_key_eq(s, number)) { - lua_pushnumber(L, attribute_id(n)); + lua_pushinteger(L, attribute_id(n)); } else if (lua_key_eq(s, value)) { - lua_pushnumber(L, attribute_value(n)); + lua_pushinteger(L, attribute_value(n)); } else { lua_pushnil(L); } @@ -3996,23 +4082,23 @@ static int lua_nodelib_direct_getfield(lua_State * L) } } else if (t == unset_node) { if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); + lua_pushinteger(L, width(n)); } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); + lua_pushinteger(L, height(n)); } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); + lua_pushinteger(L, depth(n)); } else if (lua_key_eq(s, dir)) { lua_push_dir_par(L, box_dir(n)); } else if (lua_key_eq(s, shrink)) { - lua_pushnumber(L, glue_shrink(n)); + lua_pushinteger(L, glue_shrink(n)); } else if (lua_key_eq(s, glue_order)) { - lua_pushnumber(L, glue_order(n)); + lua_pushinteger(L, glue_order(n)); } else if (lua_key_eq(s, glue_sign)) { - lua_pushnumber(L, glue_sign(n)); + lua_pushinteger(L, glue_sign(n)); } else if (lua_key_eq(s, stretch)) { - lua_pushnumber(L, glue_stretch(n)); + lua_pushinteger(L, glue_stretch(n)); } else if (lua_key_eq(s, count)) { - lua_pushnumber(L, span_count(n)); + lua_pushinteger(L, span_count(n)); } else if ((lua_key_eq(s, list)) || (lua_key_eq(s, head))){ nodelib_pushdirect_or_nil_alink(list_ptr(n)); } else { @@ -4022,9 +4108,9 @@ static int lua_nodelib_direct_getfield(lua_State * L) /* lua_pushnil(L); */ } else if (t == boundary_node) { if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n)); + lua_pushinteger(L, subtype(n)); } else if (lua_key_eq(s, value)) { - lua_pushnumber(L, boundary_value(n)); + lua_pushinteger(L, boundary_value(n)); } else { lua_pushnil(L); } @@ -4042,7 +4128,6 @@ static void lua_nodelib_do_tostring(lua_State * L, halfword n, const char *tag) char a[7] = { ' ', ' ', ' ', 'n', 'i', 'l', 0 }; char v[7] = { ' ', ' ', ' ', 'n', 'i', 'l', 0 }; msg = xmalloc(256); - if ((alink(n) != null) && (type(n) != attribute_node)) snprintf(a, 7, "%6d", (int) alink(n)); if (vlink(n) != null) @@ -4057,9 +4142,8 @@ static void lua_nodelib_do_tostring(lua_State * L, halfword n, const char *tag) static int lua_nodelib_tostring(lua_State * L) { - halfword *n; - n = check_isnode(L, 1); - lua_nodelib_do_tostring(L, *n, "node"); + halfword n = *check_isnode(L, 1); + lua_nodelib_do_tostring(L, n, "node"); return 1; } @@ -4067,7 +4151,7 @@ static int lua_nodelib_tostring(lua_State * L) static int lua_nodelib_direct_tostring(lua_State * L) { - halfword n = (halfword) lua_tonumber(L,1); + halfword n = lua_tointeger(L,1); if (n==0) { lua_pushnil(L); } else { @@ -4080,9 +4164,8 @@ static int lua_nodelib_direct_tostring(lua_State * L) static int lua_nodelib_equal(lua_State * L) { - halfword n, m; - n = *((halfword *) lua_touserdata(L, 1)); - m = *((halfword *) lua_touserdata(L, 2)); + halfword n = *((halfword *) lua_touserdata(L, 1)); + halfword m = *((halfword *) lua_touserdata(L, 2)); lua_pushboolean(L, (n == m)); return 1; } @@ -4094,39 +4177,74 @@ static int font_tex_ligaturing(lua_State * L) /* on the stack are two nodes and a direction */ /* hh-ls: we need to deal with prev nodes when a range starts with a ligature */ halfword tmp_head; - halfword *h; + halfword h; halfword t = null; - halfword p ; /* hh-ls */ + halfword p ; if (lua_gettop(L) < 1) { lua_pushnil(L); lua_pushboolean(L, 0); return 2; } - h = check_isnode(L, 1); + h = *check_isnode(L, 1); if (lua_gettop(L) > 1) { - t = *(check_isnode(L, 2)); + t = *check_isnode(L, 2); } tmp_head = new_node(nesting_node, 1); - p = alink(*h); /* hh-ls */ - couple_nodes(tmp_head, *h); + p = alink(h); + couple_nodes(tmp_head, h); tlink(tmp_head) = t; t = handle_ligaturing(tmp_head, t); if (p != null) { - vlink(p) = vlink(tmp_head) ; /* hh-ls */ + vlink(p) = vlink(tmp_head) ; } - alink(vlink(tmp_head)) = p ; /* hh-ls */ - lua_pushnumber(L, vlink(tmp_head)); - /* can be: lua_nodelib_push_fast(L, head); */ - flush_node(tmp_head); + alink(vlink(tmp_head)) = p ; + /* + lua_pushinteger(L, vlink(tmp_head)); lua_nodelib_push(L); - /* can be: lua_nodelib_push_fast(L, t); */ - lua_pushnumber(L, t); + */ + lua_nodelib_push_fast(L, vlink(tmp_head)); + /* + lua_pushinteger(L, t); lua_nodelib_push(L); + */ + lua_nodelib_push_fast(L, t); lua_pushboolean(L, 1); + flush_node(tmp_head); return 3; } - +static int font_tex_direct_ligaturing(lua_State * L) +{ + /* on the stack are two nodes and a direction */ + /* hh-ls: we need to deal with prev nodes when a range starts with a ligature */ + halfword tmp_head; + halfword h; + halfword t = null; + halfword p ; + if (lua_gettop(L) < 1) { + lua_pushnil(L); + lua_pushboolean(L, 0); + return 2; + } + h = lua_tointeger(L, 1); + if (lua_gettop(L) > 1) { + t = lua_tointeger(L, 2); + } + tmp_head = new_node(nesting_node, 1); + p = alink(h); + couple_nodes(tmp_head, h); + tlink(tmp_head) = t; + t = handle_ligaturing(tmp_head, t); + if (p != null) { + vlink(p) = vlink(tmp_head) ; + } + alink(vlink(tmp_head)) = p ; + lua_pushinteger(L, vlink(tmp_head)); + lua_pushinteger(L, t); + lua_pushboolean(L, 1); + flush_node(tmp_head); + return 3; +} /* node.kerning */ @@ -4135,35 +4253,72 @@ static int font_tex_kerning(lua_State * L) /* on the stack are two nodes and a direction */ halfword tmp_head; - halfword *h; + halfword h; halfword t = null; - halfword p ; /* hh-ls */ + halfword p ; if (lua_gettop(L) < 1) { lua_pushnil(L); lua_pushboolean(L, 0); return 2; } - h = check_isnode(L, 1); + h = *check_isnode(L, 1); if (lua_gettop(L) > 1) { - t = *(check_isnode(L, 2)); + t = *check_isnode(L, 2); } tmp_head = new_node(nesting_node, 1); - p = alink(*h); /* hh-ls */ - couple_nodes(tmp_head, *h); + p = alink(h); + couple_nodes(tmp_head, h); tlink(tmp_head) = t; t = handle_kerning(tmp_head, t); if (p != null) { - vlink(p) = vlink(tmp_head) ; /* hh-ls */ + vlink(p) = vlink(tmp_head) ; } - alink(vlink(tmp_head)) = p ; /* hh-ls */ - lua_pushnumber(L, vlink(tmp_head)); - /* can be: lua_nodelib_push_fast(L, head); */ - flush_node(tmp_head); + alink(vlink(tmp_head)) = p ; + /* + lua_pushinteger(L, vlink(tmp_head)); lua_nodelib_push(L); - /* can be: lua_nodelib_push_fast(L, t); */ - lua_pushnumber(L, t); + */ + lua_nodelib_push_fast(L, vlink(tmp_head)); + /* + lua_pushinteger(L, t); lua_nodelib_push(L); + */ + lua_nodelib_push_fast(L, t); lua_pushboolean(L, 1); + flush_node(tmp_head); + return 3; +} + +static int font_tex_direct_kerning(lua_State * L) +{ + /* on the stack are two nodes and a direction */ + + halfword tmp_head; + halfword h; + halfword t = null; + halfword p ; + if (lua_gettop(L) < 1) { + lua_pushnil(L); + lua_pushboolean(L, 0); + return 2; + } + h = lua_tointeger(L, 1); + if (lua_gettop(L) > 1) { + t = lua_tointeger(L, 2); + } + tmp_head = new_node(nesting_node, 1); + p = alink(h); + couple_nodes(tmp_head, h); + tlink(tmp_head) = t; + t = handle_kerning(tmp_head, t); + if (p != null) { + vlink(p) = vlink(tmp_head) ; + } + alink(vlink(tmp_head)) = p ; + lua_pushinteger(L, vlink(tmp_head)); + lua_pushinteger(L, t); + lua_pushboolean(L, 1); + flush_node(tmp_head); return 3; } @@ -4172,7 +4327,7 @@ static int font_tex_kerning(lua_State * L) static int lua_nodelib_protect_glyphs(lua_State * L) { int t = 0; - halfword head = *(check_isnode(L, 1)); + halfword head = *check_isnode(L, 1); while (head != null) { if (type(head) == glyph_node) { int s = subtype(head); @@ -4188,12 +4343,24 @@ static int lua_nodelib_protect_glyphs(lua_State * L) return 2; } +static int lua_nodelib_protect_glyph(lua_State * L) +{ + halfword n = *check_isnode(L, 1); + if (type(n) == glyph_node) { + int s = subtype(n); + if (s <= 256) { + subtype(n) = (quarterword) (s == 1 ? 256 : 256 + s); + } + } + return 0; +} + /* node.direct.protect_glyphs */ static int lua_nodelib_direct_protect_glyphs(lua_State * L) { int t = 0; - halfword head = (halfword) lua_tonumber(L,1); + halfword head = (halfword) lua_tointeger(L,1); while (head != null) { if (type(head) == glyph_node) { int s = subtype(head); @@ -4209,6 +4376,18 @@ static int lua_nodelib_direct_protect_glyphs(lua_State * L) return 2; } +static int lua_nodelib_direct_protect_glyph(lua_State * L) +{ + halfword n = (halfword) lua_tointeger(L,1); + if ((n != null) && (type(n) == glyph_node)) { + int s = subtype(n); + if (s <= 256) { + subtype(n) = (quarterword) (s == 1 ? 256 : 256 + s); + } + } + return 0; +} + /* node.unprotect_glyphs (returns also boolean because that signals callback) */ static int lua_nodelib_unprotect_glyphs(lua_State * L) @@ -4235,7 +4414,7 @@ static int lua_nodelib_unprotect_glyphs(lua_State * L) static int lua_nodelib_direct_unprotect_glyphs(lua_State * L) { int t = 0; - halfword head = (halfword) lua_tonumber(L,1); + halfword head = (halfword) lua_tointeger(L,1); while (head != null) { if (type(head) == glyph_node) { int s = subtype(head); @@ -4274,7 +4453,7 @@ static int lua_nodelib_first_glyph(lua_State * L) if (savetail != null) { vlink(t) = savetail; } - lua_pushnumber(L, h); + lua_pushinteger(L, h); lua_nodelib_push(L); lua_pushboolean(L, (h == null ? 0 : 1)); return 2; @@ -4287,12 +4466,12 @@ static int lua_nodelib_direct_first_glyph(lua_State * L) halfword h,savetail,t; savetail = null; t = null; - h = (halfword) lua_tonumber(L,1); + h = (halfword) lua_tointeger(L,1); if (h == null) { lua_pushnil(L); return 1; } - t = (halfword) lua_tonumber(L,2); + t = (halfword) lua_tointeger(L,2); if (t != null) { savetail = vlink(t); vlink(t) = null; @@ -4301,7 +4480,7 @@ static int lua_nodelib_direct_first_glyph(lua_State * L) h = vlink(h); if (savetail != null) vlink(t) = savetail; - lua_pushnumber(L, h); + lua_pushinteger(L, h); return 1; /* no need to also push a boolean if we have nil */ } @@ -4340,7 +4519,7 @@ static int lua_nodelib_has_glyph(lua_State * L) static int lua_nodelib_direct_has_glyph(lua_State * L) { - halfword h = (halfword) lua_tonumber(L,1) ; + halfword h = (halfword) lua_tointeger(L,1) ; while (h != null) { if ((type(h) == glyph_node) || (type(h) == disc_node)) { nodelib_pushdirect(h); @@ -4353,15 +4532,6 @@ static int lua_nodelib_direct_has_glyph(lua_State * L) return 1; } - -/* depricated */ - -static int lua_nodelib_first_character(lua_State * L) -{ - luatex_warn("node.first_character() is deprecated, please update to node.first_glyph()"); - return lua_nodelib_first_glyph(L); -} - /* this is too simplistic, but it helps Hans to get going */ static halfword do_ligature_n(halfword prev, halfword stop, halfword lig) @@ -4377,19 +4547,19 @@ static halfword do_ligature_n(halfword prev, halfword stop, halfword lig) static int lua_nodelib_do_ligature_n(lua_State * L) { - halfword n, m, o, p, tmp_head; - n = *(check_isnode(L, 1)); - m = *(check_isnode(L, 2)); - o = *(check_isnode(L, 3)); + halfword p; + halfword n = *check_isnode(L, 1); + halfword m = *check_isnode(L, 2); + halfword o = *check_isnode(L, 3); if (alink(n) == null || vlink(alink(n)) != n) { - tmp_head = new_node(temp_node, 0); + halfword tmp_head = new_node(temp_node, 0); couple_nodes(tmp_head, n); p = do_ligature_n(tmp_head, m, o); flush_node(tmp_head); } else { p = do_ligature_n(alink(n), m, o); } - lua_pushnumber(L, p); + lua_pushinteger(L, p); lua_nodelib_push(L); return 1; } @@ -4398,22 +4568,22 @@ static int lua_nodelib_do_ligature_n(lua_State * L) static int lua_nodelib_direct_do_ligature_n(lua_State * L) { - halfword n, m, o, p, tmp_head; - n = (halfword) lua_tonumber(L, 1); - m = (halfword) lua_tonumber(L, 2); - o = (halfword) lua_tonumber(L, 3); + halfword p; + halfword n = (halfword) lua_tointeger(L, 1); + halfword m = (halfword) lua_tointeger(L, 2); + halfword o = (halfword) lua_tointeger(L, 3); if ((n == null) || (m == null) || (o == null)) { lua_pushnil(L); } else { if (alink(n) == null || vlink(alink(n)) != n) { - tmp_head = new_node(temp_node, 0); + halfword tmp_head = new_node(temp_node, 0); couple_nodes(tmp_head, n); p = do_ligature_n(tmp_head, m, o); flush_node(tmp_head); } else { p = do_ligature_n(alink(n), m, o); } - lua_pushnumber(L, p); + lua_pushinteger(L, p); } return 1; } @@ -4422,7 +4592,7 @@ static int lua_nodelib_direct_do_ligature_n(lua_State * L) static int lua_nodelib_usedlist(lua_State * L) { - lua_pushnumber(L, list_node_mem_usage()); + lua_pushinteger(L, list_node_mem_usage()); lua_nodelib_push(L); return 1; } @@ -4431,7 +4601,7 @@ static int lua_nodelib_usedlist(lua_State * L) static int lua_nodelib_direct_usedlist(lua_State * L) { - lua_pushnumber(L, list_node_mem_usage()); + lua_pushinteger(L, list_node_mem_usage()); return 1; } @@ -4439,8 +4609,7 @@ static int lua_nodelib_direct_usedlist(lua_State * L) static int lua_nodelib_cp_skipable(lua_State * L) { - halfword n; - n = *(check_isnode(L, 1)); + halfword n = *check_isnode(L, 1); lua_pushboolean(L, cp_skipable(n)); return 1; } @@ -4449,8 +4618,7 @@ static int lua_nodelib_cp_skipable(lua_State * L) static int lua_nodelib_direct_cp_skipable(lua_State * L) { - halfword n; - n = (halfword) lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if (n == null) { lua_pushnil(L); } else { @@ -4472,7 +4640,7 @@ static int lua_nodelib_currentattr(lua_State * L) /* or null (attr_list_cache can also be null) */ n = current_attribute_list(); if (n) { - lua_pushnumber(L, n); + lua_pushinteger(L, n); lua_nodelib_push(L); } else @@ -4480,7 +4648,7 @@ static int lua_nodelib_currentattr(lua_State * L) return 1; } else { /* assign */ - luatex_warn("Assignment via node.current_attr() is not supported (yet)"); + normal_warning("node lib","assignment via node.current_attr() is not supported (yet)"); return 0; } } @@ -4490,12 +4658,11 @@ static int lua_nodelib_currentattr(lua_State * L) static int lua_nodelib_direct_currentattr(lua_State * L) { - halfword n ; /* current_attribute_list() return attr_list_cache */ /* or null (attr_list_cache can also be null) */ - n = current_attribute_list(); + halfword n = current_attribute_list(); if (n) - lua_pushnumber(L, n); + lua_pushinteger(L, n); else lua_pushnil(L); return 1; @@ -4513,7 +4680,7 @@ static int lua_nodelib_direct_todirect(lua_State * L) if (n == null) { lua_pushnil(L); } else { - lua_pushnumber(L, *((halfword *)n) ); + lua_pushinteger(L, *((halfword *)n) ); } } /* else assume direct and returns argument */ return 1; @@ -4525,8 +4692,7 @@ static int lua_nodelib_direct_todirect(lua_State * L) static int lua_nodelib_direct_tonode(lua_State * L) { halfword *a; - halfword n; - n = (halfword) lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if (n != null) { a = (halfword *) lua_newuserdata(L, sizeof(halfword)); *a=n; @@ -4558,8 +4724,7 @@ static int lua_nodelib_direct_tonode(lua_State * L) static int lua_nodelib_setfield_whatsit(lua_State * L, int n, const char *s) { - int t ; - t = subtype(n); + int t = subtype(n); if (t == pdf_literal_node) { if (lua_key_eq(s, mode)) { @@ -4794,20 +4959,15 @@ static int lua_nodelib_setfield_whatsit(lua_State * L, int n, const char *s) static int lua_nodelib_fast_setfield(lua_State * L) { - halfword n; + halfword g, c, v; const char *s; - int t ; - - n = *((halfword *) lua_touserdata(L, 1)); - t = type(n); + halfword n = *((halfword *) lua_touserdata(L, 1)); + int t = type(n); if (lua_type(L, 2) == LUA_TNUMBER) { - - int i, val; - if (lua_gettop(L) == 3) { - i = (int) lua_tointeger(L, 2); - val = (int) lua_tointeger(L, 3); + int i = lua_tointeger(L, 2); + int val = lua_tointeger(L, 3); if (val == UNUSED_ATTRIBUTE) { (void) unset_attribute(n, i, val); } else { @@ -4892,7 +5052,7 @@ static int lua_nodelib_fast_setfield(lua_State * L) } else if (lua_key_eq(s, glue_sign)) { glue_sign(n) = (quarterword) lua_tointeger(L, 3); } else if (lua_key_eq(s, glue_set)) { - glue_set(n) = (glue_ratio) lua_tonumber(L, 3); + glue_set(n) = (glue_ratio) lua_tonumber(L, 3); /* integer or float */ } else { return nodelib_cantset(L, n, s); } @@ -4916,20 +5076,15 @@ static int lua_nodelib_fast_setfield(lua_State * L) } else if (lua_key_eq(s, leader)) { leader_ptr(n) = nodelib_getlist(L, 3); } else if (lua_key_eq(s, width)) { - nodelib_check_glue_spec(n); - width(n) = (halfword) lua_tointeger(L, 3); + nodelib_check_glue_spec(n, g, width); } else if (lua_key_eq(s, stretch)) { - nodelib_check_glue_spec(n); - stretch(n) = (halfword) lua_tointeger(L, 3); + nodelib_check_glue_spec(n, g, stretch); } else if (lua_key_eq(s, shrink)) { - nodelib_check_glue_spec(n); - shrink(n) = (halfword) lua_tointeger(L, 3); + nodelib_check_glue_spec(n, g, shrink); } else if (lua_key_eq(s, stretch_order)) { - nodelib_check_glue_spec(n); - stretch_order(n) = (quarterword) lua_tointeger(L, 3); + nodelib_check_glue_spec(n, g, stretch_order); } else if (lua_key_eq(s, shrink_order)) { - nodelib_check_glue_spec(n); - shrink_order(n) = (quarterword) lua_tointeger(L, 3); + nodelib_check_glue_spec(n, g, shrink_order); } else { return nodelib_cantset(L, n, s); } @@ -5100,7 +5255,6 @@ static int lua_nodelib_fast_setfield(lua_State * L) /* dummy subtype */ } else if (lua_key_eq(s, style)) { assign_math_style(L,3,subtype(n)); - //subtype(n) = (quarterword) luaL_checkoption(L, 3, "text", math_style_names); /* not 2? */ } else { /* return nodelib_cantset(L, n, s); */ } @@ -5303,9 +5457,7 @@ static int lua_nodelib_setfield(lua_State * L) static int lua_nodelib_direct_setfield_whatsit(lua_State * L, int n, const char *s) { - int t ; - t = subtype(n); - + int t = subtype(n); if (t == pdf_literal_node) { if (lua_key_eq(s, mode)) { pdf_literal_mode(n) = (quarterword) lua_tointeger(L, 3); @@ -5538,8 +5690,7 @@ static int lua_nodelib_direct_setfield_whatsit(lua_State * L, int n, const char static int lua_nodelib_direct_setcharacter(lua_State * L) { - halfword n; - n = (halfword ) lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if ((n) && (lua_type(L, 2) == LUA_TNUMBER)) { if (type(n) == glyph_node) { character(n) = (halfword) lua_tointeger(L, 2); @@ -5552,8 +5703,7 @@ static int lua_nodelib_direct_setcharacter(lua_State * L) static int lua_nodelib_direct_setnext(lua_State * L) { - halfword n; - n = (halfword ) lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if (n) { if (lua_type(L, 2) == LUA_TNUMBER) { vlink(n) = (halfword) lua_tointeger(L, 2); @@ -5566,8 +5716,7 @@ static int lua_nodelib_direct_setnext(lua_State * L) static int lua_nodelib_direct_setprev(lua_State * L) { - halfword n; - n = (halfword ) lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if (n) { if (lua_type(L, 2) == LUA_TNUMBER) { alink(n) = (halfword) lua_tointeger(L, 2); @@ -5580,8 +5729,7 @@ static int lua_nodelib_direct_setprev(lua_State * L) static int lua_nodelib_direct_setboth(lua_State * L) { - halfword n; - n = (halfword ) lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if (n) { if (lua_type(L, 2) == LUA_TNUMBER) { alink(n) = (halfword) lua_tointeger(L, 2); @@ -5599,18 +5747,17 @@ static int lua_nodelib_direct_setboth(lua_State * L) static int lua_nodelib_direct_setlink(lua_State * L) { - halfword a, b; if (lua_type(L, 1) == LUA_TNUMBER) { - a = (halfword ) lua_tonumber(L, 1); + halfword a = lua_tointeger(L, 1); if (lua_type(L, 2) == LUA_TNUMBER) { - b = (halfword ) lua_tonumber(L, 2); + halfword b = lua_tointeger(L, 2); vlink(a) = b; alink(b) = a; } else { vlink(a) = null; } } else if (lua_type(L, 2) == LUA_TNUMBER) { - b = (halfword ) lua_tonumber(L, 2); + halfword b = lua_tointeger(L, 2); alink(b) = null; } return 0; @@ -5618,13 +5765,16 @@ static int lua_nodelib_direct_setlink(lua_State * L) static int lua_nodelib_direct_is_char(lua_State * L) { - halfword n; - halfword f; - n = (halfword ) lua_tointeger(L, 1); - if ((type(n) == glyph_node) && (subtype(n) < 256)) { - f = (halfword ) lua_tointeger(L, 2); - if (f && f == font(n)) { - lua_pushboolean(L,1); + halfword n = lua_tointeger(L, 1); + if ((type(n) == glyph_node) && (subtype(n) < 256)) { /* <= 256 */ + if (lua_type(L,2) == LUA_TNUMBER) { + halfword f = lua_tointeger(L, 2); + if (f && f == font(n)) { + lua_pushinteger(L,character(n)); + return 1; + } + } else { + lua_pushinteger(L,character(n)); return 1; } } @@ -5634,11 +5784,9 @@ static int lua_nodelib_direct_is_char(lua_State * L) static int lua_nodelib_direct_setdiscretionary(lua_State * L) { - int t ; - halfword n; - n = (halfword ) lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if (type(n) == disc_node) { - t = lua_gettop(L) ; + int t = lua_gettop(L) ; if (t > 1) { set_disc_field(pre_break(n), lua_tointeger(L,2)); if (t > 2) { @@ -5670,20 +5818,16 @@ static int lua_nodelib_direct_setdiscretionary(lua_State * L) static int lua_nodelib_direct_setfield(lua_State * L) { - halfword n; + halfword g, c, v; const char *s; - int t ; - n = (halfword ) lua_tonumber(L, 1); - t = type(n); + halfword n = lua_tointeger(L, 1); + int t = type(n); if (lua_type(L, 2) == LUA_TNUMBER) { - - int i, val; - if (lua_gettop(L) == 3) { - i = (int) lua_tointeger(L, 2); - val = (int) lua_tointeger(L, 3); + int i = lua_tointeger(L, 2); + int val = lua_tointeger(L, 3); if (val == UNUSED_ATTRIBUTE) { (void) unset_attribute(n, i, val); } else { @@ -5768,7 +5912,7 @@ static int lua_nodelib_direct_setfield(lua_State * L) } else if (lua_key_eq(s, glue_sign)) { glue_sign(n) = (quarterword) lua_tointeger(L, 3); } else if (lua_key_eq(s, glue_set)) { - glue_set(n) = (glue_ratio) lua_tonumber(L, 3); + glue_set(n) = (glue_ratio) lua_tonumber(L, 3); /* integer or float */ } else { return nodelib_cantset(L, n, s); } @@ -5792,20 +5936,15 @@ static int lua_nodelib_direct_setfield(lua_State * L) } else if (lua_key_eq(s, leader)) { leader_ptr(n) = nodelib_popdirect(3); } else if (lua_key_eq(s, width)) { - nodelib_check_glue_spec(n); - width(n) = (halfword) lua_tointeger(L, 3); + nodelib_check_glue_spec(n, g, width); } else if (lua_key_eq(s, stretch)) { - nodelib_check_glue_spec(n); - stretch(n) = (halfword) lua_tointeger(L, 3); + nodelib_check_glue_spec(n, g, stretch); } else if (lua_key_eq(s, shrink)) { - nodelib_check_glue_spec(n); - shrink(n) = (halfword) lua_tointeger(L, 3); + nodelib_check_glue_spec(n, g, shrink); } else if (lua_key_eq(s, stretch_order)) { - nodelib_check_glue_spec(n); - stretch_order(n) = (quarterword) lua_tointeger(L, 3); + nodelib_check_glue_spec(n, g, stretch_order); } else if (lua_key_eq(s, shrink_order)) { - nodelib_check_glue_spec(n); - shrink_order(n) = (quarterword) lua_tointeger(L, 3); + nodelib_check_glue_spec(n, g, shrink_order); } else { return nodelib_cantset(L, n, s); } @@ -5976,7 +6115,6 @@ static int lua_nodelib_direct_setfield(lua_State * L) /* dummy subtype */ } else if (lua_key_eq(s, style)) { assign_math_style(L,2,subtype(n)); - //subtype(n) = (quarterword) luaL_checkoption(L, 2, "text", math_style_names); /* was 3 */ } else { /* return nodelib_cantset(L, n, s); */ } @@ -6165,21 +6303,21 @@ static int direct_get_box_id(lua_State * L, int i) size_t k = 0; int j = -1; switch (lua_type(L, i)) { - case LUA_TSTRING: - s = lua_tolstring(L, i, &k); - cur_cs1 = string_lookup(s, k); - cur_cmd1 = eq_type(cur_cs1); - if (cur_cmd1 == char_given_cmd || - cur_cmd1 == math_given_cmd) { - j = equiv(cur_cs1); - } - break; - case LUA_TNUMBER: - j=(int)lua_tonumber(L, (i)); - break; - default: - luaL_error(L, "argument must be a string or a number"); - j = -1; /* not a valid box id */ + case LUA_TSTRING: + s = lua_tolstring(L, i, &k); + cur_cs1 = string_lookup(s, k); + cur_cmd1 = eq_type(cur_cs1); + if (cur_cmd1 == char_given_cmd || + cur_cmd1 == math_given_cmd) { + j = equiv(cur_cs1); + } + break; + case LUA_TNUMBER: + j = lua_tointeger(L, (i)); + break; + default: + luaL_error(L, "argument must be a string or a number"); + j = -1; /* not a valid box id */ } return j; } @@ -6190,11 +6328,11 @@ static int direct_get_box_id(lua_State * L, int i) static int lua_nodelib_direct_getbox(lua_State * L) { - int k, t; - k = direct_get_box_id(L, -1); + int t; + int k = direct_get_box_id(L, -1); direct_check_index_range(k, "getbox"); t = get_tex_box_register(k); - lua_pushnumber(L, t); + lua_pushinteger(L, t); return 1; } @@ -6313,12 +6451,11 @@ static int lua_nodelib_direct_is_node(lua_State * L) /* if really needed we can provide this: -static int lua_nodelib_attributes_to_table(lua_State * L) // hh -{ // - halfword n; +static int lua_nodelib_attributes_to_table(lua_State * L) +{ halfword n; register halfword attribute; if (lua_type(L,1) == LUA_TNUMBER) { - n = lua_tonumber(L,1); + n = lua_tointeger(L,1); } else { n = *((halfword *) lua_touserdata(L, 1)); } @@ -6333,8 +6470,8 @@ static int lua_nodelib_attributes_to_table(lua_State * L) // hh lua_newtable(L); } while (attribute != null) { - lua_pushnumber(L,(int)attribute_id(attribute)); - lua_pushnumber(L,(int)attribute_value(attribute)); + lua_pushinteger(L,(int)attribute_id(attribute)); + lua_pushinteger(L,(int)attribute_value(attribute)); lua_rawset(L,-3); attribute = vlink(attribute) ; } @@ -6348,11 +6485,10 @@ static int lua_nodelib_attributes_to_table(lua_State * L) // hh /* There is no gain here but let's keep it around: static int lua_nodelib_attributes_to_properties(lua_State * L) -{ // - halfword n; +{ halfword n; register halfword attribute; if (lua_type(L,1) == LUA_TNUMBER) { - n = lua_tonumber(L,1); + n = lua_tointeger(L,1); } else { n = *((halfword *) lua_touserdata(L, 1)); } @@ -6373,8 +6509,8 @@ static int lua_nodelib_attributes_to_properties(lua_State * L) lua_pushnil(L); } else { while (attribute != null) { - lua_pushnumber(L,(int)attribute_id(attribute)); - lua_pushnumber(L,(int)attribute_value(attribute)); + lua_pushinteger(L,(int)attribute_id(attribute)); + lua_pushinteger(L,(int)attribute_value(attribute)); lua_rawset(L,-3); attribute = vlink(attribute) ; } @@ -6423,8 +6559,7 @@ static int lua_nodelib_properties_flush_table(lua_State * L) /* hh */ static int lua_nodelib_get_property(lua_State * L) /* hh */ { /* */ - halfword n; - n = *((halfword *) lua_touserdata(L, 1)); + halfword n = *((halfword *) lua_touserdata(L, 1)); if (n == null) { lua_pushnil(L); } else { @@ -6437,7 +6572,7 @@ static int lua_nodelib_get_property(lua_State * L) /* hh */ static int lua_nodelib_direct_get_property(lua_State * L) /* hh */ { /* */ - halfword n = lua_tonumber(L, 1); + halfword n = lua_tointeger(L, 1); if (n == null) { lua_pushnil(L); } else { @@ -6451,8 +6586,7 @@ static int lua_nodelib_direct_get_property(lua_State * L) /* hh */ static int lua_nodelib_set_property(lua_State * L) /* hh */ { /* */ - halfword n; - n = *((halfword *) lua_touserdata(L, 1)); + halfword n = *((halfword *) lua_touserdata(L, 1)); if (n != null) { lua_settop(L,2); lua_rawgeti(L, LUA_REGISTRYINDEX, lua_key_index(node_properties)); @@ -6468,8 +6602,8 @@ static int lua_nodelib_set_property(lua_State * L) /* hh */ static int lua_nodelib_direct_set_property(lua_State * L) /* hh */ { /* */ - halfword n = lua_tonumber(L, 1); - if (n != null) { // we could store in node instead */ + halfword n = lua_tointeger(L, 1); + if (n != null) { lua_settop(L,2); lua_rawgeti(L, LUA_REGISTRYINDEX, lua_key_index(node_properties)); lua_gettable(L, LUA_REGISTRYINDEX); @@ -6481,9 +6615,6 @@ static int lua_nodelib_direct_set_property(lua_State * L) /* hh */ return 0; } - - - static int lua_nodelib_direct_properties_get_table(lua_State * L) /* hh */ { /* */ lua_rawgeti(L, LUA_REGISTRYINDEX, lua_key_index(node_properties)); @@ -6502,8 +6633,7 @@ static int lua_nodelib_properties_get_table(lua_State * L) /* hh */ static int lua_nodelib_get_property_t(lua_State * L) /* hh */ { /* */ - halfword n; - n = *((halfword *) lua_touserdata(L, 2)); + halfword n = *((halfword *) lua_touserdata(L, 2)); if (n == null) { lua_pushnil(L); } else { @@ -6515,8 +6645,7 @@ static int lua_nodelib_get_property_t(lua_State * L) /* hh */ static int lua_nodelib_set_property_t(lua_State * L) /* hh */ { /*
*/ - halfword n; - n = *((halfword *) lua_touserdata(L, 2)); + halfword n = *((halfword *) lua_touserdata(L, 2)); if (n != null) { lua_settop(L,3); lua_rawseti(L,1,n); @@ -6530,14 +6659,12 @@ static int lua_nodelib_effective_glue(lua_State * L) { halfword *glue; halfword *parent; - halfword s; - int w; glue = lua_touserdata(L, 1); if ((glue == NULL) || (type(*glue) != glue_node)) { lua_pushnil(L) ; } else { - s = glue_ptr(*glue); - w = width(s) ; + halfword s = glue_ptr(*glue); + int w = width(s) ; parent = lua_touserdata(L, 2); if ((parent != NULL) && ((type(*parent) == hlist_node) || (type(*parent) == vlist_node))) { if ((int)glue_sign(*parent) == 1) { @@ -6550,7 +6677,7 @@ static int lua_nodelib_effective_glue(lua_State * L) } } } - lua_pushnumber(L,w); + lua_pushinteger(L,w); } return 1; } @@ -6558,17 +6685,13 @@ static int lua_nodelib_effective_glue(lua_State * L) static int lua_nodelib_direct_effective_glue(lua_State * L) { - halfword glue; - halfword parent; - halfword s; - int w; - glue = (halfword)lua_tonumber(L, 1); + halfword glue = lua_tointeger(L, 1); if ((glue == null) || (type(glue) != glue_node)) { lua_pushnil(L) ; } else { - s = glue_ptr(glue); - w = width(s) ; - parent = (halfword)lua_tonumber(L, 2); + halfword s = glue_ptr(glue); + int w = width(s) ; + halfword parent = lua_tointeger(L, 2); if ((parent != null) && ((type(parent) == hlist_node) || (type(parent) == vlist_node))) { if ((int)glue_sign(parent) == 1) { if (stretch_order(s) == glue_order(parent)) { @@ -6580,7 +6703,7 @@ static int lua_nodelib_direct_effective_glue(lua_State * L) } } } - lua_pushnumber(L,w); + lua_pushinteger(L,w); } return 1; } @@ -6592,7 +6715,7 @@ static const struct luaL_Reg nodelib_p[] = { {NULL, NULL} /* sentinel */ }; -static void lua_new_properties_table(lua_State * L) /* hh */ +static void lua_new_properties_table(lua_State * L) { lua_pushstring(L,"node.properties"); lua_newtable(L); @@ -6606,8 +6729,6 @@ static void lua_new_properties_table(lua_State * L) /* hh */ lua_settable(L,LUA_REGISTRYINDEX); } -/* end of properties experiment */ - /* node.direct.* */ static const struct luaL_Reg direct_nodelib_f[] = { @@ -6618,9 +6739,8 @@ static const struct luaL_Reg direct_nodelib_f[] = { {"dimensions", lua_nodelib_direct_dimensions}, {"do_ligature_n", lua_nodelib_direct_do_ligature_n}, {"end_of_math", lua_nodelib_direct_end_of_math}, - /* {"family_font", lua_nodelib_mfont}, */ /* no node argument */ - /* {"fields", lua_nodelib_fields}, */ /* no node argument */ - /* {"first_character", lua_nodelib_first_character}, */ /* obsolete */ + /* {"family_font", lua_nodelib_mfont}, */ /* no node argument */ + /* {"fields", lua_nodelib_fields}, */ /* no node argument */ {"first_glyph", lua_nodelib_direct_first_glyph}, {"flush_list", lua_nodelib_direct_flush_list}, {"flush_node", lua_nodelib_direct_flush_node}, @@ -6639,24 +6759,24 @@ static const struct luaL_Reg direct_nodelib_f[] = { {"getsubtype", lua_nodelib_direct_getsubtype}, {"has_glyph", lua_nodelib_direct_has_glyph}, {"has_attribute", lua_nodelib_direct_has_attribute}, + {"get_attribute", lua_nodelib_direct_get_attribute}, {"has_field", lua_nodelib_direct_has_field}, {"is_char", lua_nodelib_direct_is_char}, {"hpack", lua_nodelib_direct_hpack}, - /* {"id", lua_nodelib_id}, */ /* no node argument */ + /* {"id", lua_nodelib_id}, */ /* no node argument */ {"insert_after", lua_nodelib_direct_insert_after}, {"insert_before", lua_nodelib_direct_insert_before}, {"is_direct", lua_nodelib_direct_is_direct}, {"is_node", lua_nodelib_direct_is_node}, - /* {"kerning", font_tex_kerning}, */ /* maybe direct too (rather basic callback exposure) */ + {"kerning", font_tex_direct_kerning}, {"last_node", lua_nodelib_direct_last_node}, {"length", lua_nodelib_direct_length}, - /* {"ligaturing", font_tex_ligaturing}, */ /* maybe direct too (rather basic callback exposure) */ - /* {"mlist_to_hlist", lua_nodelib_mlist_to_hset_properties_modelist}, */ /* maybe direct too (rather basic callback exposure) */ + {"ligaturing", font_tex_direct_ligaturing}, + /* {"mlist_to_hlist", lua_nodelib_mlist_to_hset_properties_modelist}, */ {"new", lua_nodelib_direct_new}, - /* {"next", lua_nodelib_next}, */ /* replaced by getnext */ - /* {"prev", lua_nodelib_prev}, */ /* replaced by getprev */ {"tostring", lua_nodelib_direct_tostring}, {"protect_glyphs", lua_nodelib_direct_protect_glyphs}, + {"protect_glyph", lua_nodelib_direct_protect_glyph}, {"protrusion_skippable", lua_nodelib_direct_cp_skipable}, {"remove", lua_nodelib_direct_remove}, {"set_attribute", lua_nodelib_direct_set_attribute}, @@ -6669,28 +6789,26 @@ static const struct luaL_Reg direct_nodelib_f[] = { {"setboth", lua_nodelib_direct_setboth}, {"setlink", lua_nodelib_direct_setlink}, {"slide", lua_nodelib_direct_slide}, - /* {"subtype", lua_nodelib_subtype}, */ /* no node argument */ + /* {"subtype", lua_nodelib_subtype}, */ /* no node argument */ {"tail", lua_nodelib_direct_tail}, - {"todirect", lua_nodelib_direct_todirect}, /* not in node.* */ - {"tonode", lua_nodelib_direct_tonode}, /* similar to node.* */ + {"todirect", lua_nodelib_direct_todirect}, + {"tonode", lua_nodelib_direct_tonode}, {"traverse", lua_nodelib_direct_traverse}, {"traverse_id", lua_nodelib_direct_traverse_filtered}, - /* {"type", lua_nodelib_type}, */ /* no node argument */ - /* {"types", lua_nodelib_types}, */ /* no node argument */ + {"traverse_char", lua_nodelib_direct_traverse_char}, + /* {"type", lua_nodelib_type}, */ /* no node argument */ + /* {"types", lua_nodelib_types}, */ /* no node argument */ {"unprotect_glyphs", lua_nodelib_direct_unprotect_glyphs}, {"unset_attribute", lua_nodelib_direct_unset_attribute}, {"usedlist", lua_nodelib_direct_usedlist}, {"vpack", lua_nodelib_direct_vpack}, - /* {"whatsits", lua_nodelib_whatsits}, */ /* no node argument */ + /* {"whatsits", lua_nodelib_whatsits}, */ /* no node argument */ {"write", lua_nodelib_direct_append}, - /* an experiment */ - /* {"attributes_to_table",lua_nodelib_attributes_to_table}, */ /* hh experiment */ - /* an experiment */ - {"set_properties_mode",lua_nodelib_properties_set_mode}, /* hh experiment */ + {"set_properties_mode",lua_nodelib_properties_set_mode}, {"flush_properties_table",lua_nodelib_properties_flush_table}, /* hh experiment */ {"get_properties_table",lua_nodelib_direct_properties_get_table}, /* hh experiment */ - {"getproperty", lua_nodelib_direct_get_property}, /* bonus */ /* hh experiment */ - {"setproperty", lua_nodelib_direct_set_property}, /* bonus */ /* hh experiment */ + {"getproperty", lua_nodelib_direct_get_property}, + {"setproperty", lua_nodelib_direct_set_property}, {"effective_glue", lua_nodelib_direct_effective_glue}, /* done */ {NULL, NULL} /* sentinel */ @@ -6709,7 +6827,6 @@ static const struct luaL_Reg nodelib_f[] = { {"family_font", lua_nodelib_mfont}, {"fields", lua_nodelib_fields}, {"subtypes", lua_nodelib_subtypes}, - {"first_character", lua_nodelib_first_character}, {"first_glyph", lua_nodelib_first_glyph}, {"flush_list", lua_nodelib_flush_list}, {"flush_node", lua_nodelib_flush_node}, @@ -6728,7 +6845,9 @@ static const struct luaL_Reg nodelib_f[] = { {"getchar", lua_nodelib_getcharacter}, {"has_glyph", lua_nodelib_has_glyph}, {"has_attribute", lua_nodelib_has_attribute}, + {"get_attribute", lua_nodelib_get_attribute}, {"has_field", lua_nodelib_has_field}, + {"is_char", lua_nodelib_is_char}, {"hpack", lua_nodelib_hpack}, {"id", lua_nodelib_id}, {"insert_after", lua_nodelib_insert_after}, @@ -6744,6 +6863,7 @@ static const struct luaL_Reg nodelib_f[] = { {"prev", lua_nodelib_prev}, /* getprev is somewhat more efficient, and get* fits better in direct compatibility */ {"tostring", lua_nodelib_tostring}, {"protect_glyphs", lua_nodelib_protect_glyphs}, + {"protect_glyph", lua_nodelib_protect_glyph}, {"protrusion_skippable", lua_nodelib_cp_skipable}, {"remove", lua_nodelib_remove}, /* {"setbox", lua_nodelib_setbox}, */ /* tex.setbox */ @@ -6753,6 +6873,7 @@ static const struct luaL_Reg nodelib_f[] = { {"tail", lua_nodelib_tail}, {"traverse", lua_nodelib_traverse}, {"traverse_id", lua_nodelib_traverse_filtered}, + {"traverse_char", lua_nodelib_traverse_char}, {"type", lua_nodelib_type}, {"types", lua_nodelib_types}, {"unprotect_glyphs", lua_nodelib_unprotect_glyphs}, @@ -6810,15 +6931,16 @@ int luaopen_node(lua_State * L) void nodelist_to_lua(lua_State * L, int n) { - lua_pushnumber(L, n); + lua_pushinteger(L, n); lua_nodelib_push(L); } int nodelist_from_lua(lua_State * L) { - halfword *n; - if (lua_isnil(L, -1)) + if (lua_isnil(L, -1)) { return null; - n = check_isnode(L, -1); - return (n ? *n : null); + } else { + halfword n= *check_isnode(L, -1); + return (n ? n : null); + } } diff --git a/Build/source/texk/web2c/luatexdir/lua/loslibext.c b/Build/source/texk/web2c/luatexdir/lua/loslibext.c index 5a20a63e440..76dd527c0bf 100644 --- a/Build/source/texk/web2c/luatexdir/lua/loslibext.c +++ b/Build/source/texk/web2c/luatexdir/lua/loslibext.c @@ -1,5 +1,5 @@ /* loslibext.c - + Copyright 2006-2012 Taco Hoekwater This file is part of LuaTeX. @@ -33,8 +33,8 @@ /* An attempt to figure out the basic platform, does not care about niceties like version numbers yet, - and ignores platforms where luatex is unlikely to - successfully compile without major prorting effort + and ignores platforms where luatex is unlikely to + successfully compile without major prorting effort (amiga|mac|os2|vms) */ #if defined(_WIN32) || defined(__NT__) @@ -111,14 +111,14 @@ /* Note: under WIN32, |environ| is nothing but a copy of the actual environment as it was during program startup. That variable - can then be changed (which is a little odd), but such changes + can then be changed (which is a little odd), but such changes do not survive in the actual environment *unless* they are passed on down in e.g. |_execvpe|, when they would be inherited - by the child process. + by the child process. - This gives trouble because some parts of the texk code actually - change the contents of the |environ| variable as a side-effect - of other processing, and that explains why the current code does + This gives trouble because some parts of the texk code actually + change the contents of the |environ| variable as a side-effect + of other processing, and that explains why the current code does not use |environ| at all for the moment. The API is kept in place for now, just in case. Thanks to Tomek @@ -205,21 +205,21 @@ static int exec_command(const char *file, char *const *av, char *const *envp) return -1; } -/* +/* It is not possible to mimic |spawnve()| completely. The main problem is - that the |fork|--|waitpid| combination cannot really do identical error + that the |fork|--|waitpid| combination cannot really do identical error reporting to the parent process, because it has to pass all the possible - error conditions as well as the actual process return status through a + error conditions as well as the actual process return status through a single 8-bit value. The current implementation tries to give back meaningful results for |execve()| errors in the child, for the cases that could also be returned by |spawnve()|, and for |ETXTBSY|, because that can be triggered by our path searching routine. - This implementation does not differentiate abnormal status conditions reported + This implementation does not differentiate abnormal status conditions reported by |waitpid()|, but will simply return a single error indication value. - For all this, hyjacking a bunch of numbers in the range 1...255 is needed. + For all this, hyjacking a bunch of numbers in the range 1...255 is needed. The chance of collisions is hopefully diminished by using a rather random range in the 8-bit section. */ @@ -284,7 +284,7 @@ static int spawn_command(const char *file, char *const *av, char *const *envp) #ifdef _WIN32 static char *get_command_name(char *maincmd) { - /* retrieve argv[0] part from the command string, + /* retrieve argv[0] part from the command string, it will be truncated to MAX_PATH if it's too long */ char *cmdname = (char *) malloc(sizeof(char) * MAX_PATH); int i, k, quoted; @@ -307,10 +307,10 @@ static char **do_split_command(const char *maincmd, char **runcmd) { char **cmdline = NULL; #ifdef _WIN32 - /* On WIN32 don't split anything, because - _spawnvpe can't put it back together properly - if there are quoted arguments with spaces. - Instead, dump everything into one argument + /* On WIN32 don't split anything, because + _spawnvpe can't put it back together properly + if there are quoted arguments with spaces. + Instead, dump everything into one argument and it will be passed through as is */ cmdline = malloc(sizeof(char *) * 2); cmdline[0] = xstrdup(maincmd); @@ -325,7 +325,7 @@ static char **do_split_command(const char *maincmd, char **runcmd) int quoted = 0; if (strlen(maincmd) == 0) return NULL; - /* allocate the array of options first. it will probably be + /* allocate the array of options first. it will probably be be a little bit too big, but better too much than to little */ j = 2; for (i = 0; i < strlen(maincmd); i++) { @@ -434,7 +434,7 @@ static int os_exec(lua_State * L) char *safecmd = NULL, *cmdname = NULL; char **cmdline = NULL; char **envblock = NULL; - + if (lua_gettop(L) != 1) { lua_pushnil(L); lua_pushliteral(L, "invalid arguments passed"); @@ -480,7 +480,7 @@ static int os_exec(lua_State * L) if (r == -1) { lua_pushnil(L); lua_pushfstring(L, "%s: %s", runcmd, strerror(errno)); - lua_pushnumber(L, errno); + lua_pushinteger(L, errno); return 3; } } @@ -503,7 +503,7 @@ static int os_exec(lua_State * L) #define do_error_return(A,B) do { \ lua_pushnil(L); \ lua_pushfstring(L,"%s: %s",runcmd,(A)); \ - lua_pushnumber(L, B); \ + lua_pushinteger(L, B); \ return 3; \ } while (0) @@ -555,7 +555,7 @@ static int os_spawn(lua_State * L) if (cmdname) free(cmdname); if (i == 0) { - lua_pushnumber(L, i); + lua_pushinteger(L, i); return 1; } else if (i == -1) { /* this branch covers WIN32 as well as fork() and waitpid() errors */ @@ -577,7 +577,7 @@ static int os_spawn(lua_State * L) do_error_return("execution interrupted", i); #endif } else { - lua_pushnumber(L, i); + lua_pushinteger(L, i); return 1; } } @@ -723,7 +723,7 @@ static int uname(struct utsname *uts) strcpy(uts->sysname, "Windows Vista"); /* Vista */ /* else - strcpy (uts->sysname, "Windows Server 2008"); + strcpy (uts->sysname, "Windows Server 2008"); */ } os = WinNT; @@ -775,9 +775,9 @@ static int uname(struct utsname *uts) strcpy(uts->machine, "mips"); break; case PROCESSOR_ARCHITECTURE_INTEL: - /* + /* * dwProcessorType is only valid in Win95 and Win98 and WinME - * wProcessorLevel is only valid in WinNT + * wProcessorLevel is only valid in WinNT */ switch (os) { case Win95: @@ -841,19 +841,19 @@ static int os_times(lua_State * L) struct tms r; (void) times(&r); lua_newtable(L); - lua_pushnumber(L, + lua_pushnumber(L, /* float */ ((lua_Number) (r.tms_utime)) / (lua_Number) sysconf(_SC_CLK_TCK)); lua_setfield(L, -2, "utime"); - lua_pushnumber(L, + lua_pushnumber(L, /* float */ ((lua_Number) (r.tms_stime)) / (lua_Number) sysconf(_SC_CLK_TCK)); lua_setfield(L, -2, "stime"); - lua_pushnumber(L, + lua_pushnumber(L, /* float */ ((lua_Number) (r.tms_cutime)) / (lua_Number) sysconf(_SC_CLK_TCK)); lua_setfield(L, -2, "cutime"); - lua_pushnumber(L, + lua_pushnumber(L, /* float */ ((lua_Number) (r.tms_cstime)) / (lua_Number) sysconf(_SC_CLK_TCK)); lua_setfield(L, -2, "cstime"); @@ -889,7 +889,7 @@ static int os_gettimeofday(lua_State * L) tmpres -= DELTA_EPOCH_IN_MICROSECS; /*converting file time to unix epoch */ v = (double) tmpres / 1000000.0; # endif - lua_pushnumber(L, v); + lua_pushnumber(L, v); /* float */ return 1; } #endif diff --git a/Build/source/texk/web2c/luatexdir/lua/lpdflib.c b/Build/source/texk/web2c/luatexdir/lua/lpdflib.c index b1dca1b5c1e..3a1c58f2ed4 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lpdflib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lpdflib.c @@ -100,7 +100,7 @@ static int l_immediateobj(lua_State * L) n = lua_gettop(L); if ((n > 0) && (lua_type(L, 1) == LUA_TNUMBER)) { first_arg++; - k=(int)lua_tonumber(L, 1); + k = (int) lua_tointeger(L, 1); check_obj_type(static_pdf, obj_type_obj, k); if (is_obj_scheduled(static_pdf, k) || obj_data_ptr(static_pdf, k) != 0) luaL_error(L, "pdf.immediateobj() object in use"); @@ -379,7 +379,7 @@ static int orig_obj(lua_State * L) n = lua_gettop(L); if ((n > 0) && (lua_type(L, 1) == LUA_TNUMBER)) { first_arg++; - k=(int)lua_tonumber(L, 1); + k = (int) lua_tointeger(L, 1); check_obj_type(static_pdf, obj_type_obj, k); if (is_obj_scheduled(static_pdf, k) || obj_data_ptr(static_pdf, k) != 0) luaL_error(L, "pdf.obj() object in use"); @@ -565,10 +565,10 @@ static int getpdf(lua_State * L) if (lua_type(L,-1) == LUA_TSTRING) { s = lua_tostring(L, -1); if (lua_key_eq(s,h)) { - lua_pushnumber(L, static_pdf->posstruct->pos.h); + lua_pushinteger(L, static_pdf->posstruct->pos.h); return 1; } else if (lua_key_eq(s,v)) { - lua_pushnumber(L, static_pdf->posstruct->pos.v); + lua_pushinteger(L, static_pdf->posstruct->pos.v); return 1; } else if (valid_pdf_key) { lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_index(pdf_data)); @@ -703,26 +703,26 @@ static int l_pageref(lua_State * L) if (n <= 0) luaL_error(L, "pdf.pageref() needs page number > 0"); n = pdf_get_obj(static_pdf, obj_type_page, n, false); - lua_pushnumber(L, n); + lua_pushinteger(L, n); return 1; } static int l_getpos(lua_State * L) { - lua_pushnumber(L, static_pdf->posstruct->pos.h); - lua_pushnumber(L, static_pdf->posstruct->pos.v); + lua_pushinteger(L, static_pdf->posstruct->pos.h); + lua_pushinteger(L, static_pdf->posstruct->pos.v); return 2; } static int l_gethpos(lua_State * L) { - lua_pushnumber(L, static_pdf->posstruct->pos.h); + lua_pushinteger(L, static_pdf->posstruct->pos.h); return 1; } static int l_getvpos(lua_State * L) { - lua_pushnumber(L, static_pdf->posstruct->pos.v); + lua_pushinteger(L, static_pdf->posstruct->pos.v); return 1; } @@ -730,19 +730,19 @@ static int l_getmatrix(lua_State * L) { if (matrix_stack_used > 0) { matrix_entry *m = &matrix_stack[matrix_stack_used - 1]; - lua_pushnumber(L, m->a); - lua_pushnumber(L, m->b); - lua_pushnumber(L, m->c); - lua_pushnumber(L, m->d); - lua_pushnumber(L, m->e); - lua_pushnumber(L, m->f); + lua_pushinteger(L, m->a); + lua_pushinteger(L, m->b); + lua_pushinteger(L, m->c); + lua_pushinteger(L, m->d); + lua_pushinteger(L, m->e); + lua_pushinteger(L, m->f); } else { - lua_pushnumber(L, 1); - lua_pushnumber(L, 0); - lua_pushnumber(L, 0); - lua_pushnumber(L, 1); - lua_pushnumber(L, 0); - lua_pushnumber(L, 0); + lua_pushinteger(L, 1); + lua_pushinteger(L, 0); + lua_pushinteger(L, 0); + lua_pushinteger(L, 1); + lua_pushinteger(L, 0); + lua_pushinteger(L, 0); } return 6 ; } @@ -755,25 +755,25 @@ static int l_hasmatrix(lua_State * L) static int l_get_lastlink(lua_State * L) { - lua_pushnumber(L, (pdf_last_link)); + lua_pushinteger(L, (pdf_last_link)); return 1 ; } static int l_get_retval(lua_State * L) { - lua_pushnumber(L, (pdf_retval)); + lua_pushinteger(L, (pdf_retval)); return 1 ; } static int l_get_lastobj(lua_State * L) { - lua_pushnumber(L, (pdf_last_obj)); + lua_pushinteger(L, (pdf_last_obj)); return 1 ; } static int l_get_lastannot(lua_State * L) { - lua_pushnumber(L, (pdf_last_annot)); + lua_pushinteger(L, (pdf_last_annot)); return 1 ; } @@ -788,13 +788,13 @@ static int l_get_lastannot(lua_State * L) static int l_get_compresslevel(lua_State * L) { - lua_pushnumber(L, (pdf_compress_level)); + lua_pushinteger(L, (pdf_compress_level)); return 1 ; } static int l_get_objcompresslevel(lua_State * L) { - lua_pushnumber(L, (pdf_objcompresslevel)); + lua_pushinteger(L, (pdf_objcompresslevel)); return 1 ; } @@ -826,6 +826,27 @@ static int l_set_objcompresslevel(lua_State * L) return 0 ; } +/* accuracy */ + +static int l_get_decimal_digits(lua_State * L) +{ + lua_pushinteger(L, (pdf_decimal_digits)); + return 1 ; +} + + +static int l_set_decimal_digits(lua_State * L) +{ + int c ; + if (lua_type(L, 1) == LUA_TNUMBER) { + c = (int) lua_tointeger(L, 1); + if (c<0) + c = 0 ; + set_pdf_decimal_digits(c); + } + return 0 ; +} + /* pdf stuff */ static int getpdffontname(lua_State * L) @@ -837,7 +858,7 @@ static int getpdffontname(lua_State * L) if (!font_used(c)) pdf_init_font(static_pdf,c); set_ff(c); - lua_pushnumber(L, (obj_info(static_pdf, pdf_font_num(ff)))); + lua_pushinteger(L, (obj_info(static_pdf, pdf_font_num(ff)))); } else { lua_pushnil(L); } @@ -853,7 +874,7 @@ static int getpdffontobjnum(lua_State * L) if (!font_used(c)) pdf_init_font(static_pdf,c); set_ff(c); - lua_pushnumber(L, (pdf_font_num(ff))); + lua_pushinteger(L, (pdf_font_num(ff))); } else { lua_pushnil(L); } @@ -865,7 +886,7 @@ static int getpdffontsize(lua_State * L) int c; if (lua_type(L, 1) == LUA_TNUMBER) { c = (int) lua_tointeger(L, 1); - lua_pushnumber(L, (font_size(c))); + lua_pushinteger(L, (font_size(c))); } else { lua_pushnil(L); } @@ -877,7 +898,7 @@ static int getpdfpageref(lua_State * L) int c ; if (lua_type(L, 1) == LUA_TNUMBER) { c = (int) lua_tointeger(L, 1); - lua_pushnumber(L, (pdf_get_obj(static_pdf, obj_type_page, c, false))); + lua_pushinteger(L, (pdf_get_obj(static_pdf, obj_type_page, c, false))); } else { lua_pushnil(L); } @@ -890,7 +911,7 @@ static int getpdfxformname(lua_State * L) if (lua_type(L, 1) == LUA_TNUMBER) { c = (int) lua_tointeger(L, 1); check_obj_type(static_pdf, obj_type_xform, c); - lua_pushnumber(L, (obj_info(static_pdf, c))); + lua_pushinteger(L, (obj_info(static_pdf, c))); } else { lua_pushnil(L); } @@ -899,14 +920,14 @@ static int getpdfxformname(lua_State * L) static int getpdfversion(lua_State * L) { - lua_pushnumber(L,1); + lua_pushinteger(L,1); return 1 ; } static int getpdfminorversion(lua_State * L) { - /* lua_pushnumber(L,static_pdf->minor_version); */ - lua_pushnumber(L,pdf_minor_version); + /* lua_pushinteger(L,static_pdf->minor_version); */ + lua_pushinteger(L,pdf_minor_version); return 1 ; } @@ -923,6 +944,23 @@ static int setpdfminorversion(lua_State * L) return 0 ; } +static int setpdforigin(lua_State * L) +{ + int h = 0 ; + int v = 0 ; + if (lua_type(L, 1) == LUA_TNUMBER) { + h = (int) lua_tointeger(L, 1); + if (lua_type(L, 2) == LUA_TNUMBER) { + v = (int) lua_tointeger(L, 1); + } else { + v = h; + } + } + set_tex_extension_dimen_register(d_pdf_h_origin,h); + set_tex_extension_dimen_register(d_pdf_v_origin,v); + return 0 ; +} + static int newpdfcolorstack(lua_State * L) { const char *s = NULL; @@ -950,7 +988,7 @@ static int newpdfcolorstack(lua_State * L) page_start = lua_toboolean(L, 3); } id = newcolorstack(s, literal_mode, page_start); - lua_pushnumber(L, id); + lua_pushinteger(L, id); return 1 ; } @@ -997,6 +1035,8 @@ static const struct luaL_Reg pdflib[] = { { "getobjcompresslevel", l_get_objcompresslevel }, { "setcompresslevel", l_set_compresslevel }, { "setobjcompresslevel", l_set_objcompresslevel }, + { "getdecimaldigits", l_get_decimal_digits }, + { "setdecimaldigits", l_set_decimal_digits }, /* moved from tex table */ { "fontname", getpdffontname}, { "fontobjnum", getpdffontobjnum}, @@ -1007,6 +1047,7 @@ static const struct luaL_Reg pdflib[] = { { "getminorversion", getpdfminorversion}, { "setminorversion", setpdfminorversion}, { "newcolorstack", newpdfcolorstack}, + { "setorigin",setpdforigin}, /* sentinel */ {NULL, NULL} }; diff --git a/Build/source/texk/web2c/luatexdir/lua/lpdfscannerlib.cc b/Build/source/texk/web2c/luatexdir/lua/lpdfscannerlib.cc index 7fa6c4438c7..cc311daebee 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lpdfscannerlib.cc +++ b/Build/source/texk/web2c/luatexdir/lua/lpdfscannerlib.cc @@ -1,5 +1,5 @@ /* lpdfscannerlib.c - + Copyright 2013 Taco Hoekwater This file is part of LuaTeX. @@ -162,7 +162,7 @@ static scannerdata *scanner_check (lua_State *L, int index) return bar; } -static void free_token (Token *token) +static void free_token (Token *token) { if (token->string) { free(token->string); @@ -419,10 +419,10 @@ static Token *_parseInlineImage (scannerdata *self, int c) /* remove end-of-line before EI */ if (found[foundindex-1] == '\n') { found[--foundindex] = '\0'; - } + } if (found[foundindex-1] == '\r') { found[--foundindex] = '\0'; - } + } break; } else { c = streamGetChar(self); @@ -433,7 +433,7 @@ static Token *_parseInlineImage (scannerdata *self, int c) c = streamGetChar(self); check_overflow(found, foundindex); found[foundindex++] = c; - } + } } else { c = streamGetChar(self); check_overflow(found, foundindex); @@ -454,7 +454,7 @@ static Token *_parseOperator (scannerdata *self, int c) found[foundindex++] = c; c = streamLookChar(self); if ((c<0) || (c == ' ' || c == '\n' || c == '\r' || c == '\t' || - c == '/' || c == '[' || c == '(' || c == '<')) + c == '/' || c == '[' || c == '(' || c == '<')) break ; c = streamGetChar(self); } @@ -480,7 +480,7 @@ static Token *_parseOperator (scannerdata *self, int c) } -static Token * _parseComment (scannerdata *self, int c) +static Token * _parseComment (scannerdata *self, int c) { do { c = streamGetChar(self); @@ -488,7 +488,7 @@ static Token * _parseComment (scannerdata *self, int c) return _parseToken(self,streamGetChar(self)); } -static Token *_parseLt (scannerdata *self, int c) +static Token *_parseLt (scannerdata *self, int c) { c = streamGetChar(self); if (c == '<') { @@ -496,9 +496,9 @@ static Token *_parseLt (scannerdata *self, int c) } else { return _parseHexstring(self,c); } -} +} -static Token * _parseGt (scannerdata *self, int c) +static Token * _parseGt (scannerdata *self, int c) { c = streamGetChar(self); if (c== '>') { @@ -510,24 +510,24 @@ static Token * _parseGt (scannerdata *self, int c) } -static Token *_parseError (int c) +static Token *_parseError (int c) { fprintf(stderr, "stray %c [%d] in stream", c, c); return NULL; } -static Token *_parseStartarray () +static Token *_parseStartarray () { return new_operand (pdf_startarray); } -static Token *_parseStoparray () +static Token *_parseStoparray () { return new_operand (pdf_stoparray); } -static Token *_parseToken (scannerdata *self, int c) +static Token *_parseToken (scannerdata *self, int c) { if (self->_ininlineimage==1) { self->_ininlineimage = 2; @@ -548,23 +548,23 @@ static Token *_parseToken (scannerdata *self, int c) case '<': return _parseLt(self,c); break; case '>': return _parseGt(self,c); break; case '%': return _parseComment(self,c); break; - case ' ': - case '\r': - case '\n': - case '\t': + case ' ': + case '\r': + case '\n': + case '\t': return _parseSpace(self); break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '-': - case '.': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '-': + case '.': return _parseNumber(self,c); break; default: if (c<=127) { @@ -662,7 +662,7 @@ static int scanner_scan(lua_State * L) while (token) { if (token->type == pdf_operator) { lua_pushstring(L, token->string); - free_token(token); + free_token(token); lua_rawget(L,2); // operator table if (lua_isfunction(L,-1)) { lua_pushvalue(L,4); @@ -671,7 +671,7 @@ static int scanner_scan(lua_State * L) } else { lua_pop(L,1); // nil } - clear_operand_stack(self,0); + clear_operand_stack(self,0); } else { push_operand(self, token); } @@ -775,12 +775,12 @@ static void push_dict (lua_State *L, scannerdata *self) } } -const char *typenames[pdf_stopdict+1] = - { "unknown", "integer", "real", "boolean", "name", "operator", +const char *typenames[pdf_stopdict+1] = + { "unknown", "integer", "real", "boolean", "name", "operator", "string", "array", "array", "dict", "dict" }; static void push_token (lua_State *L, scannerdata *self) -{ +{ Token *token = self->_operandstack[self->_nextoperand-1]; lua_createtable(L,2,0); lua_pushstring (L, typenames[token->type]); @@ -788,7 +788,7 @@ static void push_token (lua_State *L, scannerdata *self) if (token->type == pdf_string || token->type == pdf_name) { lua_pushlstring(L, token->string, token->value); } else if (token->type == pdf_real || token->type == pdf_integer) { - lua_pushnumber(L, token->value); + lua_pushnumber(L, token->value); /* integer or float */ } else if (token->type == pdf_boolean) { lua_pushboolean(L, (int)token->value); } else if (token->type == pdf_startarray) { @@ -820,7 +820,7 @@ static int scanner_popsingular (lua_State * L, int token_type) { push_token(L, self); lua_rawgeti(L,-1,2); } else if (token_type == pdf_real || token_type == pdf_integer) { - lua_pushnumber(L, token->value); + lua_pushnumber(L, token->value); /* integer or float */ } else if (token_type == pdf_boolean) { lua_pushboolean(L,(int)token->value); } else if (token_type == pdf_name || token_type == pdf_string) { @@ -860,7 +860,7 @@ static int scanner_popanything (lua_State * L) { static int scanner_popnumber(lua_State * L) { - if(scanner_popsingular(L,pdf_real)) + if(scanner_popsingular(L,pdf_real)) return 1; if (scanner_popsingular(L,pdf_integer)) return 1; @@ -870,7 +870,7 @@ static int scanner_popnumber(lua_State * L) static int scanner_popboolean(lua_State * L) { - if(scanner_popsingular(L,pdf_boolean)) + if(scanner_popsingular(L,pdf_boolean)) return 1; lua_pushnil(L); return 1; diff --git a/Build/source/texk/web2c/luatexdir/lua/lstatslib.c b/Build/source/texk/web2c/luatexdir/lua/lstatslib.c index 74781cbd6af..7c6e1bda2b8 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lstatslib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lstatslib.c @@ -48,17 +48,43 @@ static const char *get_output_file_name(void) return NULL; } +/* static const char *getfilename(void) { int t = 0; int level = in_open; while ((level > 0)) { t = input_stack[level--].name_field; - if (t >= STRING_OFFSET) + if (t >= STRING_OFFSET) { return (const char *) str_string(t); + } } return ""; } +*/ + +static const char *getfilename(void) +{ + const char * s; + int level, t; + level = in_open; + while ((level > 0)) { + s = full_source_filename_stack[level--]; + if (s != NULL) { + return s; + } + } + /* old method */ + level = in_open; + while ((level > 0)) { + t = input_stack[level--].name_field; + if (t >= STRING_OFFSET) { + return (const char *) str_string(t); + } + } + return ""; +} + static const char *getlasterror(void) { @@ -147,7 +173,6 @@ static lua_Number get_pdf_mem_ptr(void) return (lua_Number) 0; } - static lua_Number get_obj_ptr(void) { if (static_pdf != NULL) @@ -181,6 +206,17 @@ static int get_hash_size(void) return hash_size; /* is a #define */ } +static lua_Number shell_escape_state(void) +{ + if (shellenabledp <= 0) { + return (lua_Number) 0; + } else if (restrictedshell == 0) { + return (lua_Number) 1; + } else { + return (lua_Number) 2; + } +} + static int luastate_max = 1; /* fixed value */ /* temp, for backward compat */ @@ -213,13 +249,14 @@ static struct statistic stats[] = { {"output_file_name", 'S', (void *) &get_output_file_name}, {"log_name", 'S', (void *) &getlogname}, {"banner", 'S', (void *) &getbanner}, - {"luatex_svn", 'G', &get_luatexsvn}, {"luatex_version", 'G', &get_luatexversion}, {"luatex_revision", 'S', (void *) &luatexrevision}, {"luatex_hashtype", 'S', (void *) &get_luatexhashtype}, {"luatex_hashchars", 'N', &get_luatexhashchars}, {"ini_version", 'b', &ini_version}, + + {"shell_escape", 'N', &shell_escape_state}, /* be easy on old time usage */ /* * mem stat */ @@ -254,7 +291,6 @@ static struct statistic stats[] = { {"buf_size", 'g', &buf_size}, {"save_size", 'g', &save_size}, {"input_ptr", 'g', &input_ptr}, - /* pdf stats */ {"obj_ptr", 'N', &get_obj_ptr}, {"obj_tab_size", 'N', &get_obj_tab_size}, {"pdf_os_cntr", 'N', &get_pdf_os_cntr}, @@ -263,9 +299,7 @@ static struct statistic stats[] = { {"dest_names_size", 'N', &get_dest_names_size}, {"pdf_mem_ptr", 'N', &get_pdf_mem_ptr}, {"pdf_mem_size", 'N', &get_pdf_mem_size}, - {"largest_used_mark", 'g', &biggest_used_mark}, - {"luabytecodes", 'g', &luabytecode_max}, {"luabytecode_bytes", 'g', &luabytecode_bytes}, {"luastates", 'g', &luastate_max}, @@ -313,14 +347,14 @@ static int do_getstat(lua_State * L, int i) break; case 'N': n = stats[i].value; - lua_pushnumber(L, n()); + lua_pushinteger(L, n()); break; case 'G': g = stats[i].value; - lua_pushnumber(L, g()); + lua_pushinteger(L, g()); break; case 'g': - lua_pushnumber(L, *(int *) (stats[i].value)); + lua_pushinteger(L, *(int *) (stats[i].value)); break; case 'B': g = stats[i].value; diff --git a/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c b/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c index 2ae5812af22..37c8fc79336 100644 --- a/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c +++ b/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c @@ -44,7 +44,7 @@ static boolean get_selector_value(lua_State * L, int i, int *l) r = true; } } else if (t == LUA_TNUMBER) { - int n = lua_tonumber(L,i); + int n = lua_tointeger(L,i); if (file_can_be_written(n)) { *l = n; r = true; @@ -71,7 +71,7 @@ static int do_texio_print(lua_State * L, texio_printer printfunction) if (get_selector_value(L, i, &selector)) i++; } - if (selector != log_only && selector != term_only && selector != term_and_log) { + if (selector != term_and_log && selector != log_only && selector != term_only) { if (! valid_write_file(selector)) { normalize_selector(); /* sets selector */ } @@ -145,9 +145,16 @@ void flush_loggable_info(void) } } +static int texio_setescape(lua_State * L) +{ + escape_controls = lua_tointeger(L,-1); + return 0 ; +} + static const struct luaL_Reg texiolib[] = { {"write", texio_print}, {"write_nl", texio_printnl}, + {"setescape", texio_setescape}, {NULL, NULL} }; diff --git a/Build/source/texk/web2c/luatexdir/lua/ltexlib.c b/Build/source/texk/web2c/luatexdir/lua/ltexlib.c index 2c292afa40a..2f4aa10230b 100644 --- a/Build/source/texk/web2c/luatexdir/lua/ltexlib.c +++ b/Build/source/texk/web2c/luatexdir/lua/ltexlib.c @@ -43,6 +43,7 @@ typedef struct { void *next; boolean partial; int cattable; + /* halfword tok; */ } rope; typedef struct { @@ -63,8 +64,8 @@ static int spindle_index = 0; static void luac_store(lua_State * L, int i, int partial, int cattable) { - char *st; const char *sttemp; + char *st; size_t tsize; rope *rn = NULL; sttemp = lua_tolstring(L, i, &tsize); @@ -78,6 +79,7 @@ static void luac_store(lua_State * L, int i, int partial, int cattable) rn->partial = partial; rn->cattable = cattable; rn->next = NULL; + /* rn->tok = 0; */ if (write_spindle.head == NULL) { assert(write_spindle.tail == NULL); write_spindle.head = rn; @@ -91,13 +93,12 @@ static void luac_store(lua_State * L, int i, int partial, int cattable) static int do_luacprint(lua_State * L, int partial, int deftable) { - int i, n; int cattable = deftable; int startstrings = 1; - n = lua_gettop(L); + int n = lua_gettop(L); if (cattable != NO_CAT_TABLE) { if (lua_type(L, 1) == LUA_TNUMBER && n > 1) { - cattable=(int)lua_tonumber(L, 1); + cattable = lua_tointeger(L, 1); startstrings = 2; if (cattable != -1 && cattable != -2 && !valid_catcode_table(cattable)) { cattable = DEFAULT_CAT_TABLE; @@ -105,6 +106,7 @@ static int do_luacprint(lua_State * L, int partial, int deftable) } } if (lua_type(L, startstrings) == LUA_TTABLE) { + int i; for (i = 1;; i++) { lua_rawgeti(L, startstrings, i); if (lua_isstring(L,-1)) { /* or number */ @@ -115,6 +117,7 @@ static int do_luacprint(lua_State * L, int partial, int deftable) } } } else { + int i; for (i = startstrings; i <= n; i++) { if (!lua_isstring(L,1)) { /* or number */ luaL_error(L, "no string to print"); @@ -136,6 +139,54 @@ static int do_luacprint(lua_State * L, int partial, int deftable) return 0; } +/* + +// some first experiments .. somewhat tricky at the other end + +int luatwrite(lua_State * L) +{ + int top = lua_gettop(L); + if (top>0) { + rope *rn = xmalloc(sizeof(rope)); // overkill + int i = 1 ; + luacstrings++; // should be luactokens + rn->text = NULL; + rn->tsize = 0; + rn->partial = 0; + rn->cattable = DEFAULT_CAT_TABLE; + rn->next = NULL; + rn->tok = 0; + if (write_spindle.head == NULL) { + write_spindle.head = rn; + } else { + write_spindle.tail->next = rn; + } + write_spindle.tail = rn; + write_spindle.complete = 0; + while (1) { + rn->tok = lua_tointeger(L,i); + if (itext = NULL; + r->tsize = 0; + r->partial = 0; + r->cattable = DEFAULT_CAT_TABLE; + r->next = NULL; + r->tok = 0; + rn->next = r; + rn = r; + write_spindle.tail = rn; + i++; + } else { + break; + } + } + } + return 0; +} + +*/ + static int luacwrite(lua_State * L) { return do_luacprint(L, FULL_LINE, NO_CAT_TABLE); @@ -153,9 +204,9 @@ static int luacsprint(lua_State * L) static int luactprint(lua_State * L) { - int i, j, n; + int i, j; int cattable, startstrings; - n = lua_gettop(L); + int n = lua_gettop(L); for (i = 1; i <= n; i++) { cattable = DEFAULT_CAT_TABLE; startstrings = 1; @@ -163,19 +214,18 @@ static int luactprint(lua_State * L) luaL_error(L, "no string to print"); } lua_pushvalue(L, i); /* push the table */ - lua_pushnumber(L, 1); + lua_pushinteger(L, 1); lua_gettable(L, -2); if (lua_type(L, -1) == LUA_TNUMBER) { - cattable=(int)lua_tonumber(L, -1); + cattable = lua_tointeger(L, -1); startstrings = 2; if (cattable != -1 && cattable != -2 && !valid_catcode_table(cattable)) { cattable = DEFAULT_CAT_TABLE; } } lua_pop(L, 1); - for (j = startstrings;; j++) { - lua_pushnumber(L, j); + lua_pushinteger(L, j); lua_gettable(L, -2); if (lua_isstring(L, -1)) { /* or number */ luac_store(L, -1, PARTIAL_LINE, cattable); @@ -190,7 +240,6 @@ static int luactprint(lua_State * L) return 0; } - int luacstring_cattable(void) { return (int) read_spindle.tail->cattable; @@ -208,9 +257,8 @@ int luacstring_final_line(void) int luacstring_input(void) { - char *st; - int ret; rope *t = read_spindle.head; + int ret = 1 ; if (!read_spindle.complete) { read_spindle.complete = 1; read_spindle.tail = NULL; @@ -222,12 +270,11 @@ int luacstring_input(void) return 0; } if (t->text != NULL) { - st = t->text; /* put that thing in the buffer */ + char *st = t->text; + int ret = first; last = first; - ret = last; check_buffer_overflow(last + (int) t->tsize); - while (t->tsize-- > 0) buffer[last++] = (packed_ASCII_code) * st++; if (!t->partial) { @@ -236,13 +283,17 @@ int luacstring_input(void) } free(t->text); t->text = NULL; + /* + } else if (t->tok > 0) { + ret = - t->tok; + */ } if (read_spindle.tail != NULL) { /* not a one-liner */ free(read_spindle.tail); } read_spindle.tail = t; read_spindle.head = t->next; - return 1; + return ret; } /* open for reading, and make a new one for writing */ @@ -272,8 +323,8 @@ void luacstring_close(int n) t = next; next = next->next; if (t==read_spindle.tail) { - read_spindle.tail = NULL; // prevent double-free - } + read_spindle.tail = NULL; + } free(t); } read_spindle.head = NULL; @@ -293,7 +344,7 @@ void luacstring_close(int n) #define check_register(base) do { \ int k = get_item_index(L, lua_gettop(L), base); \ if ((k>=0) && (k <= 65535)) { \ - lua_pushnumber(L,k); \ + lua_pushinteger(L,k); \ } else { \ lua_pushboolean(L,false); \ } \ @@ -303,14 +354,14 @@ void luacstring_close(int n) static const char *scan_integer_part(lua_State * L, const char *ss, int *ret, int *radix_ret) { boolean negative = false; /* should the answer be negated? */ - int m; /* |$2^{31}$ / radix|, the threshold of danger */ + int m = 214748364; /* |$2^{31}$ / radix|, the threshold of danger */ int d; /* the digit just scanned */ - boolean vacuous; /* have no digits appeared? */ - boolean OK_so_far; /* has an error message been issued? */ - int radix1 = 0; /* the radix of the integer */ + boolean vacuous = true; /* have no digits appeared? */ + boolean OK_so_far = true; /* has an error message been issued? */ + int radix1 = 10; /* the radix of the integer */ int c = 0; /* the current character */ const char *s; /* where we stopped in the string |ss| */ - integer val = 0; /* return value */ + integer val = 0; /* return value */ s = ss; do { do { @@ -321,10 +372,6 @@ static const char *scan_integer_part(lua_State * L, const char *ss, int *ret, in c = '+'; } } while (c == '+'); - - - radix1 = 10; - m = 214748364; if (c == '\'') { radix1 = 8; m = 02000000000; @@ -334,10 +381,6 @@ static const char *scan_integer_part(lua_State * L, const char *ss, int *ret, in m = 01000000000; c = *s++; } - vacuous = true; - val = 0; - OK_so_far = true; - /* Accumulate the constant until |cur_tok| is not a suitable digit */ while (1) { if ((c < '0' + radix1) && (c >= '0') && (c <= '0' + 9)) { @@ -411,7 +454,6 @@ static const char *scan_dimen_part(lua_State * L, const char *ss, int *ret) c = '+'; } } while (c == '+'); - if (c == ',') { c = '.'; } @@ -449,7 +491,6 @@ static const char *scan_dimen_part(lua_State * L, const char *ss, int *ret) negative = !negative; cur_val = -cur_val; } - /* Scan for (u)units that are internal dimensions; |goto attach_sign| with |cur_val| set if found */ save_cur_val = cur_val; @@ -478,7 +519,6 @@ static const char *scan_dimen_part(lua_State * L, const char *ss, int *ret) cur_val = nx_plus_y(save_cur_val, v, xn_over_d(v, f, 0200000)); goto ATTACH_SIGN; NOT_FOUND: - /* Scan for (m)\.{mu} units and |goto attach_fraction| */ if (strncmp(s, "mu", 2) == 0) { s += 2; @@ -487,12 +527,14 @@ static const char *scan_dimen_part(lua_State * L, const char *ss, int *ret) if (strncmp(s, "true", 4) == 0) { /* Adjust (f)for the magnification ratio */ s += 4; - prepare_mag(); - if (int_par(mag_code) != 1000) { - cur_val = xn_over_d(cur_val, 1000, int_par(mag_code)); - f = (1000 * f + 0200000 * tex_remainder) / int_par(mag_code); - cur_val = cur_val + (f / 0200000); - f = f % 0200000; + if (output_mode_used == OMODE_DVI) { + prepare_mag(); + if (int_par(mag_code) != 1000) { + cur_val = xn_over_d(cur_val, 1000, int_par(mag_code)); + f = (1000 * f + 0200000 * tex_remainder) / int_par(mag_code); + cur_val = cur_val + (f / 0200000); + f = f % 0200000; + } } do { c = *s++; @@ -505,37 +547,36 @@ static const char *scan_dimen_part(lua_State * L, const char *ss, int *ret) } /* Scan for (a)all other units and adjust |cur_val| and |f| accordingly; |goto done| in the case of scaled points */ - - if (strncmp(s, "in", 2) == 0) { + if (strncmp(s, "mm", 2) == 0) { s += 2; - set_conversion(7227, 100); - } else if (strncmp(s, "pc", 2) == 0) { - s += 2; - set_conversion(12, 1); + set_conversion(7227, 2540); } else if (strncmp(s, "cm", 2) == 0) { s += 2; set_conversion(7227, 254); - } else if (strncmp(s, "mm", 2) == 0) { + } else if (strncmp(s, "sp", 2) == 0) { s += 2; - set_conversion(7227, 2540); + goto DONE; } else if (strncmp(s, "bp", 2) == 0) { s += 2; set_conversion(7227, 7200); + } else if (strncmp(s, "in", 2) == 0) { + s += 2; + set_conversion(7227, 100); } else if (strncmp(s, "dd", 2) == 0) { s += 2; set_conversion(1238, 1157); } else if (strncmp(s, "cc", 2) == 0) { s += 2; set_conversion(14856, 1157); + } else if (strncmp(s, "pc", 2) == 0) { + s += 2; + set_conversion(12, 1); } else if (strncmp(s, "nd", 2) == 0) { s += 2; set_conversion(685, 642); } else if (strncmp(s, "nc", 2) == 0) { s += 2; set_conversion(1370, 107); - } else if (strncmp(s, "sp", 2) == 0) { - s += 2; - goto DONE; } else { /* Complain about unknown unit and |goto done2| */ luaL_error(L, "Illegal unit of measure (pt inserted)"); @@ -587,25 +628,25 @@ static int tex_scaledimen(lua_State * L) int sp; int t = lua_type(L, 1); if (t == LUA_TNUMBER) { - sp = (int) lua_tonumber(L, 1); + sp = lua_tointeger(L, 1); } else if (t == LUA_TSTRING) { sp = dimen_to_number(L, lua_tostring(L, 1)); } else { luaL_error(L, "argument must be a string or a number"); return 0; } - lua_pushnumber(L, sp); + lua_pushinteger(L, sp); return 1; } static int texerror (lua_State * L) { - int i, n, l; const char **errhlp = NULL; const char *error = luaL_checkstring(L,1); - n = lua_gettop(L); + int n = lua_gettop(L); if (n==2 && lua_type(L, n) == LUA_TTABLE) { - l = 1; /* |errhlp| is terminated by a NULL entry */ + int i; + int l = 1; /* |errhlp| is terminated by a NULL entry */ for (i = 1;; i++) { lua_rawgeti(L, n, i); if (lua_type(L,-1) == LUA_TSTRING) { @@ -654,7 +695,7 @@ static int get_item_index(lua_State * L, int i, int base) k = (equiv(cur_cs1) - base); break; case LUA_TNUMBER: - k = (int) luaL_checkinteger(L, i); + k = luaL_checkinteger(L, i); break; default: luaL_error(L, "argument must be a string or a number"); @@ -705,7 +746,7 @@ static int get_item_index(lua_State * L, int i, int base) } \ break; \ case LUA_TNUMBER: \ - key = (int) luaL_checkinteger(L, where); \ + key = luaL_checkinteger(L, where); \ if (key>=0 && key <= 65535) { \ err = set_register(key, value); \ if (err) { \ @@ -745,7 +786,7 @@ static int gettex(lua_State * L); } \ break; \ case LUA_TNUMBER: \ - key = (int) luaL_checkinteger(L, where); \ + key = luaL_checkinteger(L, where); \ if (key>=0 && key <= 65535) { \ value = get_register(key); \ } else { \ @@ -770,7 +811,7 @@ static int setdimen(lua_State * L) int t = lua_type(L, top); check_item_global(L,top,isglobal); if (t == LUA_TNUMBER) { - value = (int) lua_tonumber(L, top); + value = lua_tointeger(L, top); } else if (t == LUA_TSTRING) { value = dimen_to_number(L, lua_tostring(L, top)); } else { @@ -784,7 +825,7 @@ static int getdimen(lua_State * L) { int value = 0; get_item_index_plus(L, lua_gettop(L), scaled_base, "dimen", value, is_dim_assign, get_tex_dimen_register, false); - lua_pushnumber(L, value); + lua_pushinteger(L, value); return 1; } @@ -853,8 +894,8 @@ static int setcount(lua_State * L) int top = lua_gettop(L); check_item_global(L,top,isglobal); t = lua_type(L,top); - if (t == LUA_TNUMBER || t == LUA_TSTRING) { - value = (int) lua_tonumber(L, top); + if (t == LUA_TNUMBER) { + value = lua_tointeger(L, top); } else { luaL_error(L, "unsupported %s value type","count"); } @@ -866,7 +907,7 @@ static int getcount(lua_State * L) { int value = 0; get_item_index_plus(L, lua_gettop(L), count_base, "count", value, is_int_assign, get_tex_count_register, false); - lua_pushnumber(L, value); + lua_pushinteger(L, value); return 1; } @@ -885,8 +926,8 @@ static int setattribute(lua_State * L) int top = lua_gettop(L); check_item_global(L,top,isglobal); t = lua_type(L,top); - if (t == LUA_TNUMBER || t == LUA_TSTRING) { - value = (int) lua_tonumber(L, top); + if (t == LUA_TNUMBER) { + value = lua_tointeger(L, top); } else { luaL_error(L, "unsupported %s value type","attribute"); } @@ -898,7 +939,7 @@ static int getattribute(lua_State * L) { int value = 0; get_item_index_plus(L, lua_gettop(L), attribute_base, "attribute", value, is_attr_assign, get_tex_attribute_register, false); - lua_pushnumber(L, value); + lua_pushinteger(L, value); return 1; } @@ -972,7 +1013,7 @@ static int scantoks(lua_State * L) memcpy (s, ss, str.l+1); str.s = (unsigned char *)s; k = get_item_index(L, (i - 2), toks_base); - c = (int) luaL_checkinteger(L, i - 1); + c = luaL_checkinteger(L, i - 1); check_index_range(k, "settoks"); err = scan_tex_toks_register(k, c, str); xfree(str.s); @@ -985,10 +1026,9 @@ static int scantoks(lua_State * L) static int gettoks(lua_State * L) { - int k; - str_number t; char *ss; - k = get_item_index(L, lua_gettop(L), toks_base); + str_number t; + int k = get_item_index(L, lua_gettop(L), toks_base); check_index_range(k, "gettoks"); t = get_tex_toks_register(k); ss = makecstring(t); @@ -1005,31 +1045,31 @@ static int get_box_id(lua_State * L, int i, boolean report) size_t k = 0; int j = -1; switch (lua_type(L, i)) { - case LUA_TSTRING: - s = lua_tolstring(L, i, &k); - cur_cs1 = string_lookup(s, k); - cur_cmd1 = eq_type(cur_cs1); - if (cur_cmd1 == char_given_cmd || - cur_cmd1 == math_given_cmd) { - j = equiv(cur_cs1); - } - break; - case LUA_TNUMBER: - j=(int)lua_tonumber(L, (i)); - break; - default: - if (report) { - luaL_error(L, "argument must be a string or a number"); - } - j = -1; /* not a valid box id */ + case LUA_TSTRING: + s = lua_tolstring(L, i, &k); + cur_cs1 = string_lookup(s, k); + cur_cmd1 = eq_type(cur_cs1); + if (cur_cmd1 == char_given_cmd || + cur_cmd1 == math_given_cmd) { + j = equiv(cur_cs1); + } + break; + case LUA_TNUMBER: + j = lua_tointeger(L, (i)); + break; + default: + if (report) { + luaL_error(L, "argument must be a string or a number"); + } + j = -1; /* not a valid box id */ } return j; } static int getbox(lua_State * L) { - int k, t; - k = get_box_id(L, -1, true); + int t; + int k = get_box_id(L, -1, true); check_index_range(k, "getbox"); t = get_tex_box_register(k); nodelist_to_lua(L, t); @@ -1085,14 +1125,13 @@ static int setbox(lua_State * L) return vsetbox(L, isglobal); } -#define check_char_range(j,s,lim) \ - if (j<0 || j >= lim) { \ - luaL_error(L, "incorrect character value %d for tex.%s()", (int)j, s); \ +#define check_char_range(j,s,lim) \ + if (j<0 || j >= lim) { \ + luaL_error(L, "incorrect character value %d for tex.%s()", (int) j, s); \ } - static int setcode (lua_State *L, void (*setone)(int,halfword,quarterword), - void (*settwo)(int,halfword,quarterword), const char *name, int lim) + void (*settwo)(int,halfword,quarterword), const char *name, int lim) { int ch; halfword val, ucval; @@ -1100,7 +1139,7 @@ static int setcode (lua_State *L, void (*setone)(int,halfword,quarterword), int n = lua_gettop(L); int f = 1; if (n>1 && lua_type(L,1) == LUA_TTABLE) - f++; + f++; if (n>2 && (lua_type(L,f) == LUA_TSTRING)) { const char *s = lua_tostring(L, f); if (lua_key_eq(s,global)) { @@ -1108,13 +1147,13 @@ static int setcode (lua_State *L, void (*setone)(int,halfword,quarterword), f++; } } - ch = (int) luaL_checkinteger(L, f); + ch = luaL_checkinteger(L, f); check_char_range(ch, name, 65536*17); val = (halfword) luaL_checkinteger(L, f+1); check_char_range(val, name, lim); (setone)(ch, val, level); if (settwo != NULL && n-f == 2) { - ucval = (halfword) luaL_checkinteger(L, f+2); + ucval = (halfword) luaL_checkinteger(L, f+2); check_char_range(ucval, name, lim); (settwo)(ch, ucval, level); } @@ -1128,9 +1167,9 @@ static int setlccode(lua_State * L) static int getlccode(lua_State * L) { - int ch = (int) luaL_checkinteger(L, -1); + int ch = luaL_checkinteger(L, -1); check_char_range(ch, "getlccode", 65536*17); - lua_pushnumber(L, get_lc_code(ch)); + lua_pushinteger(L, get_lc_code(ch)); return 1; } @@ -1141,9 +1180,9 @@ static int setuccode(lua_State * L) static int getuccode(lua_State * L) { - int ch = (int) luaL_checkinteger(L, -1); + int ch = luaL_checkinteger(L, -1); check_char_range(ch, "getuccode", 65536*17); - lua_pushnumber(L, get_uc_code(ch)); + lua_pushinteger(L, get_uc_code(ch)); return 1; } @@ -1154,9 +1193,9 @@ static int setsfcode(lua_State * L) static int getsfcode(lua_State * L) { - int ch = (int) luaL_checkinteger(L, -1); + int ch = luaL_checkinteger(L, -1); check_char_range(ch, "getsfcode", 65536*17); - lua_pushnumber(L, get_sf_code(ch)); + lua_pushinteger(L, get_sf_code(ch)); return 1; } @@ -1178,9 +1217,9 @@ static int setcatcode(lua_State * L) } } if (n-f == 2) { - cattable = (int) luaL_checkinteger(L, -3); + cattable = luaL_checkinteger(L, -3); } - ch = (int) luaL_checkinteger(L, -2); + ch = luaL_checkinteger(L, -2); check_char_range(ch, "setcatcode", 65536*17); val = (halfword) luaL_checkinteger(L, -1); check_char_range(val, "setcatcode", 16); @@ -1191,12 +1230,12 @@ static int setcatcode(lua_State * L) static int getcatcode(lua_State * L) { int cattable = int_par(cat_code_table_code); - int ch = (int) luaL_checkinteger(L, -1); + int ch = luaL_checkinteger(L, -1); if (lua_gettop(L)>=2 && lua_type(L,-2)==LUA_TNUMBER) { cattable = luaL_checkinteger(L, -2); } check_char_range(ch, "getcatcode", 65536*17); - lua_pushnumber(L, get_cat_code(cattable, ch)); + lua_pushinteger(L, get_cat_code(cattable, ch)); return 1; } @@ -1220,7 +1259,7 @@ static int setmathcode(lua_State * L) if (n-f!=1 || lua_type(L,f+1) != LUA_TTABLE) { luaL_error(L, "Bad arguments for tex.setmathcode()"); } - ch = (int) luaL_checkinteger(L, -2); + ch = luaL_checkinteger(L, -2); check_char_range(ch, "setmathcode", 65536*17); lua_rawgeti(L, -1, 1); @@ -1234,35 +1273,35 @@ static int setmathcode(lua_State * L) check_char_range(cval, "setmathcode", 8); check_char_range(fval, "setmathcode", 256); check_char_range(chval, "setmathcode", 65536*17); - set_math_code(ch, umath_mathcode, cval,fval, chval, (quarterword) (level)); + set_math_code(ch, cval,fval, chval, (quarterword) (level)); return 0; } static int getmathcode(lua_State * L) { - mathcodeval mval = { 0, 0, 0, 0 }; - int ch = (int) luaL_checkinteger(L, -1); + mathcodeval mval = { 0, 0, 0 }; + int ch = luaL_checkinteger(L, -1); check_char_range(ch, "getmathcode", 65536*17); mval = get_math_code(ch); lua_newtable(L); - lua_pushnumber(L,mval.class_value); + lua_pushinteger(L,mval.class_value); lua_rawseti(L, -2, 1); - lua_pushnumber(L,mval.family_value); + lua_pushinteger(L,mval.family_value); lua_rawseti(L, -2, 2); - lua_pushnumber(L,mval.character_value); + lua_pushinteger(L,mval.character_value); lua_rawseti(L, -2, 3); return 1; } static int getmathcodes(lua_State * L) { - mathcodeval mval = { 0, 0, 0, 0 }; - int ch = (int) luaL_checkinteger(L, -1); + mathcodeval mval = { 0, 0, 0 }; + int ch = luaL_checkinteger(L, -1); check_char_range(ch, "getmathcodes", 65536*17); mval = get_math_code(ch); - lua_pushnumber(L,mval.class_value); - lua_pushnumber(L,mval.family_value); - lua_pushnumber(L,mval.character_value); + lua_pushinteger(L,mval.class_value); + lua_pushinteger(L,mval.family_value); + lua_pushinteger(L,mval.character_value); return 3; } @@ -1285,7 +1324,7 @@ static int setdelcode(lua_State * L) if (n-f!=1 || lua_type(L,f+1) != LUA_TTABLE) { luaL_error(L, "Bad arguments for tex.setdelcode()"); } - ch = (int) luaL_checkinteger(L, -2); + ch = luaL_checkinteger(L, -2); check_char_range(ch, "setdelcode", 65536*17); lua_rawgeti(L, -1, 1); sfval = (halfword) luaL_checkinteger(L, -1); @@ -1301,59 +1340,56 @@ static int setdelcode(lua_State * L) check_char_range(scval, "setdelcode", 65536*17); check_char_range(lfval, "setdelcode", 256); check_char_range(lcval, "setdelcode", 65536*17); - set_del_code(ch, umath_mathcode, sfval, scval, lfval, lcval, (quarterword) (level)); + set_del_code(ch, sfval, scval, lfval, lcval, (quarterword) (level)); return 0; } static int getdelcode(lua_State * L) { - delcodeval mval = { 0, 0, 0, 0, 0, 0 }; - int ch = (int) luaL_checkinteger(L, -1); + delcodeval mval = { 0, 0, 0, 0, 0 }; + int ch = luaL_checkinteger(L, -1); check_char_range(ch, "getdelcode", 65536*17); mval = get_del_code(ch); - /* lua_pushnumber(L, mval.class_value); */ - /* lua_pushnumber(L, mval.origin_value); */ lua_newtable(L); - lua_pushnumber(L,mval.small_family_value); + lua_pushinteger(L,mval.small_family_value); lua_rawseti(L, -2, 1); - lua_pushnumber(L,mval.small_character_value); + lua_pushinteger(L,mval.small_character_value); lua_rawseti(L, -2, 2); - lua_pushnumber(L,mval.large_family_value); + lua_pushinteger(L,mval.large_family_value); lua_rawseti(L, -2, 3); - lua_pushnumber(L,mval.large_character_value); + lua_pushinteger(L,mval.large_character_value); lua_rawseti(L, -2, 4); return 1; } static int getdelcodes(lua_State * L) { - delcodeval mval = { 0, 0, 0, 0, 0, 0 }; - int ch = (int) luaL_checkinteger(L, -1); + delcodeval mval = { 0, 0, 0, 0, 0 }; + int ch = luaL_checkinteger(L, -1); check_char_range(ch, "getdelcodes", 65536*17); mval = get_del_code(ch); - lua_pushnumber(L,mval.small_family_value); - lua_pushnumber(L,mval.small_character_value); - lua_pushnumber(L,mval.large_family_value); - lua_pushnumber(L,mval.large_character_value); + lua_pushinteger(L,mval.small_family_value); + lua_pushinteger(L,mval.small_character_value); + lua_pushinteger(L,mval.large_family_value); + lua_pushinteger(L,mval.large_character_value); return 4; } static int settex(lua_State * L) { const char *st; - int i, j, texstr; + int texstr; size_t k; int cur_cs1, cur_cmd1; int isglobal = 0; - j = 0; - i = lua_gettop(L); + int j = 0; + int i = lua_gettop(L); if (lua_type(L,i-1) == LUA_TSTRING) { st = lua_tolstring(L, (i - 1), &k); - if (lua_key_eq(st,prevdepth)) { if (lua_type(L, i) == LUA_TNUMBER) { - cur_list.prev_depth_field = lua_tonumber(L, i); + cur_list.prev_depth_field = lua_tointeger(L, i); } else if (lua_type(L, i) == LUA_TSTRING) { cur_list.prev_depth_field = dimen_to_number(L, lua_tostring(L, i)); } else { @@ -1361,22 +1397,20 @@ static int settex(lua_State * L) } return 0; } else if (lua_key_eq(st,prevgraf)) { - if (lua_type(L, i) != LUA_TNUMBER) { - cur_list.pg_field = lua_tonumber(L, i); + if (lua_type(L, i) == LUA_TNUMBER) { + cur_list.pg_field = lua_tointeger(L, i); } else { luaL_error(L, "unsupported value type"); } return 0; } else if (lua_key_eq(st,spacefactor)) { - if (lua_type(L, i) != LUA_TNUMBER) { - cur_list.space_factor_field = lua_tonumber(L, i); + if (lua_type(L, i) == LUA_TNUMBER) { + cur_list.space_factor_field = lua_tointeger(L, i); } else { luaL_error(L, "unsupported value type"); } return 0; } - - texstr = maketexlstring(st, k); if (is_primitive(texstr)) { if (i == 3 && (lua_type(L,1) == LUA_TSTRING)) { @@ -1389,16 +1423,14 @@ static int settex(lua_State * L) cur_cmd1 = eq_type(cur_cs1); if (is_int_assign(cur_cmd1)) { if (lua_type(L, i) == LUA_TNUMBER) { - int luai; - luai=(int)lua_tonumber(L, i); - assign_internal_value((isglobal ? 4 : 0), - equiv(cur_cs1), luai); + int luai = lua_tointeger(L, i); + assign_internal_value((isglobal ? 4 : 0), equiv(cur_cs1), luai); } else { luaL_error(L, "unsupported value type"); } } else if (is_dim_assign(cur_cmd1)) { if (lua_type(L, i) == LUA_TNUMBER) { - j=(int)lua_tonumber(L, i); + j = lua_tointeger(L, i); } else if (lua_type(L, i) == LUA_TSTRING) { j = dimen_to_number(L, lua_tostring(L, i)); } else { @@ -1452,6 +1484,7 @@ static int do_convert(lua_State * L, int cur_code) case left_margin_kern_code: /* arg box */ case right_margin_kern_code: /* arg box */ case string_code: /* arg token */ + case cs_string_code: /* arg token */ case meaning_code: /* arg token */ break; @@ -1466,7 +1499,7 @@ static int do_convert(lua_State * L, int cur_code) if (lua_gettop(L) < 1) { /* error */ } - i=(int)lua_tonumber(L, 1); + i = lua_tointeger(L, 1); /* these fall through! */ @@ -1502,7 +1535,7 @@ static int do_scan_internal(lua_State * L, int cur_cmd1, int cur_code) case int_val_level: case dimen_val_level: case attr_val_level: - lua_pushnumber(L, cur_val); + lua_pushinteger(L, cur_val); break; case glue_val_level: case mu_val_level: @@ -1596,11 +1629,9 @@ static int tex_setmathparm(lua_State * L) { int i, j; int k; - int n; int l = cur_level; void *p; - n = lua_gettop(L); - + int n = lua_gettop(L); if ((n == 3) || (n == 4)) { if (n == 4 && (lua_type(L,1) == LUA_TSTRING)) { const char *s = lua_tostring(L, 1); @@ -1615,11 +1646,11 @@ static int tex_setmathparm(lua_State * L) p = lua_touserdata(L, n); k = *((halfword *)p); def_math_param(i, j, (scaled) k, l); - } else { - if (lua_type(L, n) == LUA_TNUMBER) - luaL_error(L, "argument must be a number"); - k=(int)lua_tonumber(L, n); + } else if (lua_type(L, n) == LUA_TNUMBER) { + k = lua_tointeger(L, n); def_math_param(i, j, (scaled) k, l); + } else { + luaL_error(L, "argument must be a number"); } } return 0; @@ -1627,12 +1658,10 @@ static int tex_setmathparm(lua_State * L) static int tex_getmathparm(lua_State * L) { - int i, j; - scaled k; if ((lua_gettop(L) == 2)) { - i = luaL_checkoption(L, 1, NULL, math_param_names); - j = luaL_checkoption(L, 2, NULL, math_style_names); - k = get_math_param(i, j); + int i = luaL_checkoption(L, 1, NULL, math_param_names); + int j = luaL_checkoption(L, 2, NULL, math_style_names); + scaled k = get_math_param(i, j); if (i<0 && i>=math_param_last) { lua_pushnil(L); } else if (i>=math_param_first_mu_glue) { @@ -1641,7 +1670,7 @@ static int tex_getmathparm(lua_State * L) } lua_nodelib_push_fast(L, k); } else { - lua_pushnumber(L, k); + lua_pushinteger(L, k); } } return 1; @@ -1674,17 +1703,16 @@ static int getromannumeral(lua_State * L) static int get_parshape(lua_State * L) { - int n; halfword par_shape_ptr = equiv(par_shape_loc); if (par_shape_ptr != 0) { int m = 1; - n = vinfo(par_shape_ptr + 1); + int n = vinfo(par_shape_ptr + 1); lua_createtable(L, n, 0); while (m <= n) { lua_createtable(L, 2, 0); - lua_pushnumber(L, vlink((par_shape_ptr) + (2 * (m - 1)) + 2)); + lua_pushinteger(L, vlink((par_shape_ptr) + (2 * (m - 1)) + 2)); lua_rawseti(L, -2, 1); - lua_pushnumber(L, vlink((par_shape_ptr) + (2 * (m - 1)) + 3)); + lua_pushinteger(L, vlink((par_shape_ptr) + (2 * (m - 1)) + 3)); lua_rawseti(L, -2, 2); lua_rawseti(L, -2, m); m++; @@ -1704,54 +1732,51 @@ static int gettex(lua_State * L) int texstr; size_t k; const char *st = lua_tolstring(L, t, &k); - if (lua_key_eq(st,prevdepth)) { - lua_pushnumber(L, cur_list.prev_depth_field); + lua_pushinteger(L, cur_list.prev_depth_field); return 1; } else if (lua_key_eq(st,prevgraf)) { - lua_pushnumber(L, cur_list.pg_field); + lua_pushinteger(L, cur_list.pg_field); return 1; } else if (lua_key_eq(st,spacefactor)) { - lua_pushnumber(L, cur_list.space_factor_field); + lua_pushinteger(L, cur_list.space_factor_field); return 1; } - texstr = maketexlstring(st, k); cur_cs1 = prim_lookup(texstr); /* not found == relax == 0 */ flush_str(texstr); } if (cur_cs1 > 0) { - int cur_cmd1, cur_code; - cur_cmd1 = get_prim_eq_type(cur_cs1); - cur_code = get_prim_equiv(cur_cs1); + int cur_cmd1 = get_prim_eq_type(cur_cs1); + int cur_code = get_prim_equiv(cur_cs1); switch (cur_cmd1) { - case last_item_cmd: - retval = do_lastitem(L, cur_code); - break; - case convert_cmd: - retval = do_convert(L, cur_code); - break; - case assign_toks_cmd: - case assign_int_cmd: - case assign_attr_cmd: - case assign_dir_cmd: - case assign_dimen_cmd: - case assign_glue_cmd: - case assign_mu_glue_cmd: - case set_aux_cmd: - case set_prev_graf_cmd: - case set_page_int_cmd: - case set_page_dimen_cmd: - case char_given_cmd: - case math_given_cmd: - retval = do_scan_internal(L, cur_cmd1, cur_code); - break; - case set_tex_shape_cmd: - retval = get_parshape(L); - break; - default: - lua_pushnil(L); - break; + case last_item_cmd: + retval = do_lastitem(L, cur_code); + break; + case convert_cmd: + retval = do_convert(L, cur_code); + break; + case assign_toks_cmd: + case assign_int_cmd: + case assign_attr_cmd: + case assign_dir_cmd: + case assign_dimen_cmd: + case assign_glue_cmd: + case assign_mu_glue_cmd: + case set_aux_cmd: + case set_prev_graf_cmd: + case set_page_int_cmd: + case set_page_dimen_cmd: + case char_given_cmd: + case math_given_cmd: + retval = do_scan_internal(L, cur_cmd1, cur_code); + break; + case set_tex_shape_cmd: + retval = get_parshape(L); + break; + default: + lua_pushnil(L); + break; } } else if (t == 2) { lua_rawget(L, 1); @@ -1766,44 +1791,44 @@ static int getlist(lua_State * L) str = lua_tostring(L, 2); if (lua_key_eq(str,page_ins_head)) { if (vlink(page_ins_head) == page_ins_head) - lua_pushnumber(L, null); + lua_pushinteger(L, null); else - lua_pushnumber(L, vlink(page_ins_head)); + lua_pushinteger(L, vlink(page_ins_head)); lua_nodelib_push(L); } else if (lua_key_eq(str,contrib_head)) { alink(vlink(contrib_head)) = null ; - lua_pushnumber(L, vlink(contrib_head)); + lua_pushinteger(L, vlink(contrib_head)); lua_nodelib_push(L); } else if (lua_key_eq(str,page_head)) { alink(vlink(page_head)) = null ;/*hh-ls */ - lua_pushnumber(L, vlink(page_head)); + lua_pushinteger(L, vlink(page_head)); lua_nodelib_push(L); } else if (lua_key_eq(str,temp_head)) { alink(vlink(temp_head)) = null ;/*hh-ls */ - lua_pushnumber(L, vlink(temp_head)); + lua_pushinteger(L, vlink(temp_head)); lua_nodelib_push(L); } else if (lua_key_eq(str,hold_head)) { alink(vlink(hold_head)) = null ;/*hh-ls */ - lua_pushnumber(L, vlink(hold_head)); + lua_pushinteger(L, vlink(hold_head)); lua_nodelib_push(L); } else if (lua_key_eq(str,adjust_head)) { alink(vlink(adjust_head)) = null ;/*hh-ls */ - lua_pushnumber(L, vlink(adjust_head)); + lua_pushinteger(L, vlink(adjust_head)); lua_nodelib_push(L); } else if (lua_key_eq(str,best_page_break)) { - lua_pushnumber(L, best_page_break); + lua_pushinteger(L, best_page_break); lua_nodelib_push(L); } else if (lua_key_eq(str,least_page_cost)) { - lua_pushnumber(L, least_page_cost); + lua_pushinteger(L, least_page_cost); } else if (lua_key_eq(str,best_size)) { - lua_pushnumber(L, best_size); + lua_pushinteger(L, best_size); } else if (lua_key_eq(str,pre_adjust_head)) { alink(vlink(pre_adjust_head)) = null ;/*hh-ls */ - lua_pushnumber(L, vlink(pre_adjust_head)); + lua_pushinteger(L, vlink(pre_adjust_head)); lua_nodelib_push(L); } else if (lua_key_eq(str,align_head)) { alink(vlink(align_head)) = null ;/*hh-ls */ - lua_pushnumber(L, vlink(align_head)); + lua_pushinteger(L, vlink(align_head)); lua_nodelib_push(L); } else { lua_pushnil(L); @@ -1816,16 +1841,15 @@ static int getlist(lua_State * L) static int setlist(lua_State * L) { - halfword *n_ptr; - const char *str; - halfword n = 0; if (lua_type(L,2) == LUA_TSTRING) { - str = lua_tostring(L, 2); + const char *str = lua_tostring(L, 2); if (lua_key_eq(str,best_size)) { best_size = (int) lua_tointeger(L, 3); } else if (lua_key_eq(str,least_page_cost)) { least_page_cost = (int) lua_tointeger(L, 3); } else { + halfword *n_ptr; + halfword n = 0; if (!lua_isnil(L, 3)) { n_ptr = check_isnode(L, 3); n = *n_ptr; @@ -1875,32 +1899,32 @@ static int lua_nest_getfield(lua_State * L) const char *field = lua_tostring(L, -1); r = *rv; if (lua_key_eq(field,mode)) { - lua_pushnumber(L, r->mode_field); + lua_pushinteger(L, r->mode_field); } else if (lua_key_eq(field,head)) { lua_nodelib_push_fast(L, r->head_field); } else if (lua_key_eq(field,tail)) { lua_nodelib_push_fast(L, r->tail_field); } else if (lua_key_eq(field,delimptr)) { - lua_pushnumber(L, r->eTeX_aux_field); + lua_pushinteger(L, r->eTeX_aux_field); lua_nodelib_push(L); } else if (lua_key_eq(field,prevgraf)) { - lua_pushnumber(L, r->pg_field); + lua_pushinteger(L, r->pg_field); } else if (lua_key_eq(field,modeline)) { - lua_pushnumber(L, r->ml_field); + lua_pushinteger(L, r->ml_field); } else if (lua_key_eq(field,prevdepth)) { - lua_pushnumber(L, r->prev_depth_field); + lua_pushinteger(L, r->prev_depth_field); } else if (lua_key_eq(field,spacefactor)) { - lua_pushnumber(L, r->space_factor_field); + lua_pushinteger(L, r->space_factor_field); } else if (lua_key_eq(field,noad)) { - lua_pushnumber(L, r->incompleat_noad_field); + lua_pushinteger(L, r->incompleat_noad_field); lua_nodelib_push(L); } else if (lua_key_eq(field,dirs)) { - lua_pushnumber(L, r->dirs_field); + lua_pushinteger(L, r->dirs_field); lua_nodelib_push(L); } else if (lua_key_eq(field,mathdir)) { lua_pushboolean(L, r->math_field); } else if (lua_key_eq(field,mathstyle)) { - lua_pushnumber(L, r->math_style_field); + lua_pushinteger(L, r->math_style_field); } else { lua_pushnil(L); } @@ -1915,7 +1939,7 @@ static int lua_nest_setfield(lua_State * L) const char *field = lua_tostring(L, -2); r = *rv; if (lua_key_eq(field,mode)) { - i=(int)lua_tonumber(L, -1); + i = lua_tointeger(L, -1); r->mode_field = i; } else if (lua_key_eq(field,head)) { n = check_isnode(L, -1); @@ -1927,16 +1951,16 @@ static int lua_nest_setfield(lua_State * L) n = check_isnode(L, -1); r->eTeX_aux_field = *n; } else if (lua_key_eq(field,prevgraf)) { - i=(int)lua_tonumber(L, -1); + i = lua_tointeger(L, -1); r->pg_field = i; } else if (lua_key_eq(field,modeline)) { - i=(int)lua_tonumber(L, -1); + i = lua_tointeger(L, -1); r->ml_field = i; } else if (lua_key_eq(field,prevdepth)) { - i=(int)lua_tonumber(L, -1); + i = lua_tointeger(L, -1); r->prev_depth_field = i; } else if (lua_key_eq(field,spacefactor)) { - i=(int)lua_tonumber(L, -1); + i = lua_tointeger(L, -1); r->space_factor_field = i; } else if (lua_key_eq(field,noad)) { n = check_isnode(L, -1); @@ -1947,7 +1971,7 @@ static int lua_nest_setfield(lua_State * L) } else if (lua_key_eq(field,mathdir)) { r->math_field = lua_toboolean(L, -1); } else if (lua_key_eq(field,mathstyle)) { - i=(int)lua_tonumber(L, -1); + i = lua_tointeger(L, -1); r->math_style_field = i; } return 0; @@ -1968,11 +1992,10 @@ static void init_nest_lib(lua_State * L) static int getnest(lua_State * L) { - int ptr; list_state_record **nestitem; int t = lua_type(L, 2); if (t == LUA_TNUMBER) { - ptr=(int)lua_tonumber(L, 2); + int ptr = lua_tointeger(L, 2); if (ptr >= 0 && ptr <= nest_ptr) { nestitem = lua_newuserdata(L, sizeof(list_state_record *)); *nestitem = &nest[ptr]; @@ -1984,7 +2007,7 @@ static int getnest(lua_State * L) } else if (t == LUA_TSTRING) { const char *s = lua_tostring(L, 2); if (lua_key_eq(s,ptr)) { - lua_pushnumber(L, nest_ptr); + lua_pushinteger(L, nest_ptr); } else { lua_pushnil(L); } @@ -2013,11 +2036,11 @@ static int do_integer_error(double m) static int tex_roundnumber(lua_State * L) { - double m = (double) lua_tonumber(L, 1) + 0.5; + double m = (double) lua_tonumber(L, 1) + 0.5; /* integer or float */ if (abs(m) > (double) infinity) - lua_pushnumber(L, do_integer_error(m)); + lua_pushinteger(L, do_integer_error(m)); else - lua_pushnumber(L, floor(m)); + lua_pushinteger(L, floor(m)); return 1; } @@ -2031,21 +2054,21 @@ static int tex_scaletable(lua_State * L) lua_pushvalue(L, -2); lua_insert(L, -2); if (lua_type(L,-2) == LUA_TNUMBER) { - double m = (double) lua_tonumber(L, -1) * delta + 0.5; + double m = (double) lua_tonumber(L, -1) * delta + 0.5; /* integer or float */ lua_pop(L, 1); if (abs(m) > (double) infinity) - lua_pushnumber(L, do_integer_error(m)); + lua_pushinteger(L, do_integer_error(m)); else - lua_pushnumber(L, floor(m)); + lua_pushinteger(L, floor(m)); } lua_rawset(L, 3); } } else if (lua_type(L,1) == LUA_TNUMBER) { - double m = (double) lua_tonumber(L, 1) * delta + 0.5; + double m = (double) lua_tonumber(L, 1) * delta + 0.5; /* integer or float */ if (abs(m) > (double) infinity) - lua_pushnumber(L, do_integer_error(m)); + lua_pushinteger(L, do_integer_error(m)); else - lua_pushnumber(L, floor(m)); + lua_pushinteger(L, floor(m)); } else { lua_pushnil(L); } @@ -2071,7 +2094,7 @@ static int tex_definefont(lua_State * L) i = 2; } csname = luaL_checklstring(L, i, &l); - f = (int) luaL_checkinteger(L, (i + 1)); + f = luaL_checkinteger(L, (i + 1)); t = maketexlstring(csname, l); no_new_control_sequence = 0; u = string_lookup(csname, l); @@ -2136,10 +2159,7 @@ static int tex_extraprimitives(lua_State * L) int cs = 0; n = lua_gettop(L); if (n == 0) { - mask = etex_command - + pdftex_command /* obsolete */ - + umath_command /* obsolete */ - + luatex_command; + mask = etex_command + luatex_command; } else { for (i = 1; i <= n; i++) { if (lua_type(L,i) == LUA_TSTRING) { @@ -2150,13 +2170,8 @@ static int tex_extraprimitives(lua_State * L) mask |= tex_command; } else if (lua_key_eq(s,core)) { mask |= core_command; - } else if (lua_key_eq(s,pdftex)) { /* obsolete */ - mask |= pdftex_command; } else if (lua_key_eq(s,luatex)) { - mask |= luatex_command - | umath_command; /* obsolete */ - } else if (lua_key_eq(s,umath)) { /* obsolete */ - mask |= umath_command; + mask |= luatex_command; } } } @@ -2238,57 +2253,55 @@ static int tex_enableprimitives(lua_State * L) return 0; } -#define get_int_par(A,B,C) do { \ - lua_pushstring(L,(A)); \ - lua_gettable(L,-2); \ - if (lua_type(L, -1) == LUA_TNUMBER) { \ - B=(int)lua_tonumber(L, -1); \ - } else { \ - B = (C); \ - } \ - lua_pop(L,1); \ - } while (0) - - -#define get_intx_par(A,B,C,D,E) do { \ - lua_pushstring(L,(A)); \ - lua_gettable(L,-2); \ - if (lua_type(L, -1) == LUA_TNUMBER) { \ - B=(int)lua_tonumber(L, -1); \ - D = null; \ - } else if (lua_type(L, -1) == LUA_TTABLE){ \ - B = 0; \ - D = nodelib_topenalties(L, lua_gettop(L)); \ - } else { \ - B = (C); \ - D = (E); \ - } \ - lua_pop(L,1); \ - } while (0) - -#define get_dimen_par(A,B,C) do { \ +#define get_int_par(A,B,C) do { \ lua_pushstring(L,(A)); \ - lua_gettable(L,-2); \ - if (lua_type(L, -1) == LUA_TNUMBER) { \ - B=(int)lua_tonumber(L, -1); \ - } else { \ - B = (C); \ - } \ - lua_pop(L,1); \ - } while (0) - + lua_gettable(L,-2); \ + if (lua_type(L, -1) == LUA_TNUMBER) { \ + B = (int) lua_tointeger(L, -1); \ + } else { \ + B = (C); \ + } \ + lua_pop(L,1); \ +} while (0) + + +#define get_intx_par(A,B,C,D,E) do { \ + lua_pushstring(L,(A)); \ + lua_gettable(L,-2); \ + if (lua_type(L, -1) == LUA_TNUMBER) { \ + B = (int) lua_tointeger(L, -1); \ + D = null; \ + } else if (lua_type(L, -1) == LUA_TTABLE){ \ + B = 0; \ + D = nodelib_topenalties(L, lua_gettop(L)); \ + } else { \ + B = (C); \ + D = (E); \ + } \ + lua_pop(L,1); \ +} while (0) + +#define get_dimen_par(A,B,C) do { \ + lua_pushstring(L,(A)); \ + lua_gettable(L,-2); \ + if (lua_type(L, -1) == LUA_TNUMBER) { \ + B = (int) lua_tointeger(L, -1); \ + } else { \ + B = (C); \ + } \ + lua_pop(L,1); \ +} while (0) #define get_glue_par(A,B,C) do { \ - lua_pushstring(L,(A)); \ - lua_gettable(L,-2); \ - if (lua_type(L, -1) != LUA_TNIL) { \ - B = *check_isnode(L, -1); \ - } else { \ - B = (C); \ - } \ - lua_pop(L,1); \ - } while (0) - + lua_pushstring(L,(A)); \ + lua_gettable(L,-2); \ + if (lua_type(L, -1) != LUA_TNIL) { \ + B = *check_isnode(L, -1); \ + } else { \ + B = (C); \ + } \ + lua_pop(L,1); \ +} while (0) static halfword nodelib_toparshape(lua_State * L, int i) { @@ -2314,11 +2327,11 @@ static halfword nodelib_toparshape(lua_State * L, int i) if (lua_type(L, i) == LUA_TTABLE) { lua_rawgeti(L, -1, 1); /* indent */ if (lua_type(L, -1) == LUA_TNUMBER) { - indent=(int)lua_tonumber(L, -1); + indent = lua_tointeger(L, -1); lua_pop(L, 1); lua_rawgeti(L, -1, 2); /* width */ if (lua_type(L, -1) == LUA_TNUMBER) { - width=(int)lua_tonumber(L, -1); + width = lua_tointeger(L, -1); lua_pop(L, 1); varmem[p + 2 * j].cint = indent; varmem[p + 2 * j + 1].cint = width; @@ -2351,16 +2364,15 @@ static halfword nodelib_topenalties(lua_State * L, int i) lua_pushnil(L); j = 2; while (lua_next(L, i) != 0) { - j++; - if (lua_type(L, -1) == LUA_TNUMBER) { - int pen = 0; - pen=(int)lua_tonumber(L, -1); - varmem[p+j].cint = pen; - } - lua_pop(L, 1); + j++; + if (lua_type(L, -1) == LUA_TNUMBER) { + int pen = lua_tointeger(L, -1); + varmem[p+j].cint = pen; + } + lua_pop(L, 1); } if (!odd(n)) - varmem[p+j+1].cint = 0; + varmem[p+j+1].cint = 0; return p; } @@ -2481,16 +2493,16 @@ static int tex_run_linebreak(lua_State * L) lua_nodelib_push_fast(L, vlink(cur_list.head_field)); lua_newtable(L); lua_pushstring(L, "demerits"); - lua_pushnumber(L, fewest_demerits); + lua_pushinteger(L, fewest_demerits); lua_settable(L, -3); lua_pushstring(L, "looseness"); - lua_pushnumber(L, actual_looseness); + lua_pushinteger(L, actual_looseness); lua_settable(L, -3); lua_pushstring(L, "prevdepth"); - lua_pushnumber(L, cur_list.prev_depth_field); + lua_pushinteger(L, cur_list.prev_depth_field); lua_settable(L, -3); lua_pushstring(L, "prevgraf"); - lua_pushnumber(L, cur_list.pg_field); + lua_pushinteger(L, cur_list.pg_field); lua_settable(L, -3); /* restore nest stack */ @@ -2511,10 +2523,9 @@ static int tex_shipout(lua_State * L) static int tex_badness(lua_State * L) { - scaled t,s; - t=(int)lua_tonumber(L,1); - s=(int)lua_tonumber(L,2); - lua_pushnumber(L, badness(t,s)); + scaled t = lua_tointeger(L,1); + scaled s = lua_tointeger(L,2); + lua_pushinteger(L, badness(t,s)); return 1; } @@ -2574,7 +2585,7 @@ static int tex_init_rand(lua_State * L) luaL_error(L, "argument must be a number"); return 0; } - sp=(int)lua_tonumber(L, 1); + sp = lua_tointeger(L, 1); init_randoms(sp); return 0; } @@ -2586,14 +2597,14 @@ static int tex_unif_rand(lua_State * L) luaL_error(L, "argument must be a number"); return 0; } - sp=(int)lua_tonumber(L, 1); - lua_pushnumber(L, unif_rand(sp)); + sp = lua_tointeger(L, 1); + lua_pushinteger(L, unif_rand(sp)); return 1; } static int tex_norm_rand(lua_State * L) { - lua_pushnumber(L, norm_rand()); + lua_pushinteger(L, norm_rand()); return 1; } @@ -2607,20 +2618,20 @@ static int tex_norm_rand(lua_State * L) r = r / rand_max; switch (lua_gettop(L)) { /* check number of arguments */ case 0: { /* no arguments */ - lua_pushnumber(L, r); /* Number between 0 and 1 */ + lua_pushnumber(L, r); /* float: [0, 1] */ break; } case 1: { /* only upper limit */ lua_Number u = luaL_checknumber(L, 1); luaL_argcheck(L, (lua_Number)1.0 <= u, 1, "interval is empty"); - lua_pushnumber(L, floor(r*u) + (lua_Number)(1.0)); /* [1, u] */ + lua_pushnumber(L, floor(r*u) + (lua_Number)(1.0)); /* float: [1, u] */ break; } case 2: { /* lower and upper limits */ lua_Number l = luaL_checknumber(L, 1); lua_Number u = luaL_checknumber(L, 2); luaL_argcheck(L, l <= u, 2, "interval is empty"); - lua_pushnumber(L, floor(r*(u-l+1)) + l); /* [l, u] */ + lua_pushnumber(L, floor(r*(u-l+1)) + l); /* float: [l, u] */ break; } default: @@ -2654,10 +2665,10 @@ static int tex_show_context(lua_State * L) static int tex_save_box_resource(lua_State * L) { - halfword boxnumber, boxdata; + halfword boxdata; int index, attributes, resources; /* box attributes resources */ - boxnumber = (halfword) lua_tonumber(L,1); + halfword boxnumber = lua_tointeger(L,1); if (lua_type(L,2) == LUA_TSTRING) { lua_pushvalue(L, 2); attributes = luaL_ref(L, LUA_REGISTRYINDEX); @@ -2687,7 +2698,7 @@ static int tex_save_box_resource(lua_State * L) set_obj_xform_depth(static_pdf, index, depth(boxdata)); box(boxnumber) = null; last_saved_box_index = index; - lua_pushnumber(L, index); + lua_pushinteger(L, index); return 1; } @@ -2702,18 +2713,18 @@ static int tex_use_box_resource(lua_State * L) lua_pushnil(L); lua_pushnil(L); } else { - index = lua_tonumber(L,1); + index = lua_tointeger(L,1); alt.wd = null_flag; alt.ht = null_flag; alt.dp = null_flag; if (lua_type(L,2) == LUA_TNUMBER) { - alt.wd = (scaled) lua_tonumber(L,2); + alt.wd = (scaled) lua_tointeger(L,2); } if (lua_type(L,3) == LUA_TNUMBER) { - alt.ht = (scaled) lua_tonumber(L,3); + alt.ht = (scaled) lua_tointeger(L,3); } if (lua_type(L,4) == LUA_TNUMBER) { - alt.dp = (scaled) lua_tonumber(L,4); + alt.dp = (scaled) lua_tointeger(L,4); } /* sort of the same as backend */ check_obj_type(static_pdf, obj_type_xform, index); @@ -2731,9 +2742,9 @@ static int tex_use_box_resource(lua_State * L) height(rule) = dim.ht; depth(rule) = dim.dp; nodelist_to_lua(L, rule); - lua_pushnumber(L, (int) dim.wd); - lua_pushnumber(L, (int) dim.ht); - lua_pushnumber(L, (int) dim.dp); + lua_pushinteger(L, (int) dim.wd); + lua_pushinteger(L, (int) dim.ht); + lua_pushinteger(L, (int) dim.dp); } return 4; } @@ -2746,11 +2757,11 @@ static int tex_get_box_resource_dimensions(lua_State * L) lua_pushnil(L); lua_pushnil(L); } else { - index = lua_tonumber(L,1); + index = lua_tointeger(L,1); check_obj_type(static_pdf, obj_type_xform, index); - lua_pushnumber(L, (int) obj_xform_width(static_pdf, index)); - lua_pushnumber(L, (int) obj_xform_height(static_pdf, index)); - lua_pushnumber(L, (int) obj_xform_depth(static_pdf, index)); + lua_pushinteger(L, (int) obj_xform_width(static_pdf, index)); + lua_pushinteger(L, (int) obj_xform_height(static_pdf, index)); + lua_pushinteger(L, (int) obj_xform_depth(static_pdf, index)); } return 3; } diff --git a/Build/source/texk/web2c/luatexdir/lua/ltokenlib.c b/Build/source/texk/web2c/luatexdir/lua/ltokenlib.c deleted file mode 100644 index 21686c6c3ec..00000000000 --- a/Build/source/texk/web2c/luatexdir/lua/ltokenlib.c +++ /dev/null @@ -1,288 +0,0 @@ -/* ltokenlib.c - - Copyright 2006-2012 Taco Hoekwater - - This file is part of LuaTeX. - - LuaTeX 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. - - LuaTeX 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 Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ - -#include "ptexlib.h" -#include "lua/luatex-api.h" - - -#define is_valid_token(L,i) (lua_istable(L,i) && lua_rawlen(L,i)==3) -#define get_token_cmd(L,i) lua_rawgeti(L,i,1) -#define get_token_chr(L,i) lua_rawgeti(L,i,2) -#define get_token_cs(L,i) lua_rawgeti(L,i,3) -#define is_active_string(s) (strlen((char *)s)>3 && *s==0xEF && *(s+1)==0xBF && *(s+2)==0xBF) - - -static unsigned char *get_cs_text(int cs) -{ - if (cs == null_cs) - return (unsigned char *) xstrdup("\\csname\\endcsname"); - else if ((cs_text(cs) < 0) || (cs_text(cs) >= str_ptr)) - return (unsigned char *) xstrdup(""); - else - return (unsigned char *) makecstring(cs_text(cs)); -} - - -static int test_expandable(lua_State * L) -{ - int cmd = -1; - int t; - if (is_valid_token(L, -1)) { - get_token_cmd(L, -1); - t = lua_type(L, -1); - if (t == LUA_TNUMBER) { - cmd = (int) lua_tointeger(L, -1); - } else if (t == LUA_TSTRING) { - cmd = get_command_id(lua_tostring(L, -1)); - } - if (cmd > max_command_cmd) { - lua_pushboolean(L, 1); - } else { - lua_pushboolean(L, 0); - } - } else { - lua_pushnil(L); - } - return 1; -} - - -static int test_protected(lua_State * L) -{ - int chr = -1; - int t; - if (is_valid_token(L, -1)) { - get_token_chr(L, -1); - t = lua_type(L, -1); - if (t == LUA_TNUMBER) { - chr = (int) lua_tointeger(L, -1); - } else if (t == LUA_TSTRING) { - chr = get_command_id(lua_tostring(L, -1)); - } - if (token_info(token_link(chr)) == protected_token) { - lua_pushboolean(L, 1); - } else { - lua_pushboolean(L, 0); - } - } else { - lua_pushnil(L); - } - return 1; -} - -static int test_activechar(lua_State * L) -{ - if (is_valid_token(L, -1)) { - unsigned char *s; - int cs = 0; - get_token_cs(L, -1); - if (lua_type(L, -1) == LUA_TNUMBER) { - cs = (int) lua_tointeger(L, -1); - } - lua_pop(L, 1); - if (cs != 0 && ((s = get_cs_text(cs)) != (unsigned char *) NULL)) { - if (is_active_string(s)) { - free(s); - lua_pushboolean(L, 1); - return 1; - } - free(s); - } - } - lua_pushboolean(L, 0); - return 1; -} - - -static int run_get_command_name(lua_State * L) -{ - int cs; - if (is_valid_token(L, -1)) { - get_token_cmd(L, -1); - if (lua_type(L, -1) == LUA_TNUMBER) { - cs = (int) lua_tointeger(L, -1); - lua_pushstring(L, command_names[cs].cmd_name); - } else { - lua_pushstring(L, ""); - } - } else { - lua_pushnil(L); - } - return 1; -} - - -static int run_get_csname_name(lua_State * L) -{ - int cs /*, cmd*/; - unsigned char *s; - if (is_valid_token(L, -1)) { - get_token_cmd(L, -1); - /* - if (lua_type(L, -1) == LUA_TNUMBER) { - cmd = (int) lua_tointeger(L, -1); - } - */ - lua_pop(L, 1); - cs = 0; - get_token_cs(L, -1); - if (lua_type(L, -1) == LUA_TNUMBER) { - cs = (int) lua_tointeger(L, -1); - } - lua_pop(L, 1); - - if (cs != 0 && ((s = get_cs_text(cs)) != (unsigned char *) NULL)) { - if (is_active_string(s)) - lua_pushstring(L, (char *) (s + 3)); - else - lua_pushstring(L, (char *) s); - } else { - lua_pushstring(L, ""); - } - } else { - lua_pushnil(L); - } - return 1; -} - -static int run_get_command_id(lua_State * L) -{ - int cs = -1; - if (lua_type(L, -1) == LUA_TSTRING) { - cs = get_command_id(lua_tostring(L, -1)); - } - lua_pushnumber(L, cs); - return 1; -} - - -static int run_get_csname_id(lua_State * L) -{ - const char *s; - size_t k, cs = 0; - if (lua_type(L, -1) == LUA_TSTRING) { - s = lua_tolstring(L, -1, &k); - cs = (size_t) string_lookup(s, k); - } - lua_pushnumber(L, (lua_Number) cs); - return 1; -} - - -void make_token_table(lua_State * L, int cmd, int chr, int cs) -{ - lua_createtable(L, 3, 0); - lua_pushnumber(L, cmd); - lua_rawseti(L, -2, 1); - lua_pushnumber(L, chr); - lua_rawseti(L, -2, 2); - lua_pushnumber(L, cs); - lua_rawseti(L, -2, 3); -} - -static int run_get_next(lua_State * L) -{ - int save_nncs; - save_nncs = no_new_control_sequence; - no_new_control_sequence = 0; - get_next(); - no_new_control_sequence = save_nncs; - make_token_table(L, cur_cmd, cur_chr, cur_cs); - return 1; -} - -static int run_expand(lua_State * L) -{ - (void) L; - expand(); - return 0; -} - - -static int run_lookup(lua_State * L) -{ - const char *s; - size_t l; - int cs, cmd, chr; - int save_nncs; - if (lua_type(L, -1) == LUA_TSTRING) { - s = lua_tolstring(L, -1, &l); - if (l > 0) { - save_nncs = no_new_control_sequence; - no_new_control_sequence = true; - cs = id_lookup((last + 1), (int) l); /* cleans up the lookup buffer */ - cs = string_lookup(s, l); - cmd = eq_type(cs); - chr = equiv(cs); - make_token_table(L, cmd, chr, cs); - no_new_control_sequence = save_nncs; - return 1; - } - } - lua_newtable(L); - return 1; -} - -static int run_build(lua_State * L) -{ - int cmd, chr, cs; - if (lua_type(L, 1) == LUA_TNUMBER) { - cs = 0; - chr = (int) lua_tointeger(L, 1); - cmd = (int) luaL_optinteger(L, 2, get_char_cat_code(chr)); - if (cmd == 0 || cmd == 9 || cmd == 14 || cmd == 15) { - fprintf(stdout, - "\n\nluatex error: not a good token.\nCatcode %i can not be returned, so I replaced it by 12 (other)", - (int) cmd); - error(); - cmd = 12; - } - if (cmd == 13) { - cs = active_to_cs(chr, false); - cmd = eq_type(cs); - chr = equiv(cs); - } - make_token_table(L, cmd, chr, cs); - return 1; - } else { - return run_lookup(L); - } -} - - -static const struct luaL_Reg tokenlib[] = { - {"get_next", run_get_next}, - {"expand", run_expand}, - {"lookup", run_lookup}, - {"create", run_build}, - {"is_expandable", test_expandable}, - {"is_activechar", test_activechar}, - {"is_protected", test_protected}, - {"csname_id", run_get_csname_id}, - {"csname_name", run_get_csname_name}, - {"command_name", run_get_command_name}, - {"command_id", run_get_command_id}, - {NULL, NULL} /* sentinel */ -}; - -int luaopen_oldtoken(lua_State * L) -{ - luaL_register(L, "oldtoken", tokenlib); - return 1; -} diff --git a/Build/source/texk/web2c/luatexdir/lua/luagen.h b/Build/source/texk/web2c/luatexdir/lua/luagen.h deleted file mode 100644 index d49f60f02b8..00000000000 --- a/Build/source/texk/web2c/luatexdir/lua/luagen.h +++ /dev/null @@ -1,20 +0,0 @@ -/* luagen.h - - Copyright 2009-2013 Taco Hoekwater - - This file is part of LuaTeX. - - LuaTeX 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. - - LuaTeX 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 Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ - -/* obsolete, one can intercept nodelist and flush as lua if needed */ diff --git a/Build/source/texk/web2c/luatexdir/lua/luagen.w b/Build/source/texk/web2c/luatexdir/lua/luagen.w deleted file mode 100644 index f5b01df8505..00000000000 --- a/Build/source/texk/web2c/luatexdir/lua/luagen.w +++ /dev/null @@ -1,20 +0,0 @@ -% luagen.w -% -% Copyright 2009-2013 Taco Hoekwater -% -% This file is part of LuaTeX. -% -% LuaTeX 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. -% -% LuaTeX 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 Lesser General Public -% License for more details. -% -% You should have received a copy of the GNU General Public License along -% with LuaTeX; if not, see . - -/* obsolete */ diff --git a/Build/source/texk/web2c/luatexdir/lua/luainit.w b/Build/source/texk/web2c/luatexdir/lua/luainit.w index c95c29d5aaf..fb9d2c72909 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luainit.w +++ b/Build/source/texk/web2c/luatexdir/lua/luainit.w @@ -19,7 +19,6 @@ @ @c - #include "ptexlib.h" #include @@ -29,10 +28,7 @@ /* internalized strings: see luatex-api.h */ set_make_keys; - @ -TH: TODO - This file is getting a bit messy, but it is not simple to fix unilaterally. Better to wait until Karl has some time (after texlive 2008) so we can @@ -150,12 +146,8 @@ static char *ex_selfdir(char *argv0) #endif } - - - @ @c -static void -prepare_cmdline(lua_State * L, char **av, int ac, int zero_offset) +static void prepare_cmdline(lua_State * L, char **av, int ac, int zero_offset) { int i; char *s; @@ -289,8 +281,6 @@ unsigned int lua_unsigned_numeric_field_by_index(lua_State * L, int name_index, return i; } - - @ @c static void parse_options(int ac, char **av) { @@ -338,52 +328,41 @@ static void parse_options(int ac, char **av) } else if (ARGUMENT_IS("jiton")) { luajiton = 1; } else if (ARGUMENT_IS("jithash")) { - size_t len = strlen(optarg); - if (len<16) - jithash_hashname = optarg; - else{ - WARNING2("hash name truncated to 15 characters from %d. (%s)", - (int) len, optarg); - jithash_hashname = (string) xmalloc(16); - strncpy(jithash_hashname, optarg, 15); - jithash_hashname[15] = 0; - } + size_t len = strlen(optarg); + if (len<16) { + jithash_hashname = optarg; + } else { + WARNING2("hash name truncated to 15 characters from %d. (%s)", (int) len, optarg); + jithash_hashname = (string) xmalloc(16); + strncpy(jithash_hashname, optarg, 15); + jithash_hashname[15] = 0; + } #endif - } else if (ARGUMENT_IS("luahashchars")) { show_luahashchars = 1; - } else if (ARGUMENT_IS("kpathsea-debug")) { kpathsea_debug |= atoi(optarg); - } else if (ARGUMENT_IS("progname")) { user_progname = optarg; - } else if (ARGUMENT_IS("jobname")) { c_job_name = optarg; - } else if (ARGUMENT_IS("fmt")) { dump_name = optarg; - } else if (ARGUMENT_IS("output-directory")) { output_directory = optarg; - } else if (ARGUMENT_IS("output-comment")) { size_t len = strlen(optarg); if (len < 256) { output_comment = optarg; } else { - WARNING2("Comment truncated to 255 characters from %d. (%s)", - (int) len, optarg); + WARNING2("Comment truncated to 255 characters from %d. (%s)", (int) len, optarg); output_comment = (string) xmalloc(256); strncpy(output_comment, optarg, 255); output_comment[255] = 0; } - } else if (ARGUMENT_IS("shell-restricted")) { shellenabledp = 1; restrictedshell = 1; - } else if (ARGUMENT_IS("output-format")) { output_mode_option = 1; if (strcmp(optarg, "dvi") == 0) { @@ -394,17 +373,13 @@ static void parse_options(int ac, char **av) WARNING1("Ignoring unknown value `%s' for --output-format",optarg); output_mode_option = 0; } - } else if (ARGUMENT_IS("draftmode")) { draft_mode_option = 1; draft_mode_value = 1; - } else if (ARGUMENT_IS("mktex")) { kpse_maketex_option(optarg, true); - } else if (ARGUMENT_IS("no-mktex")) { kpse_maketex_option(optarg, false); - } else if (ARGUMENT_IS("interaction")) { /* These numbers match CPP defines */ if (STREQ(optarg, "batchmode")) { @@ -416,17 +391,13 @@ static void parse_options(int ac, char **av) } else if (STREQ(optarg, "errorstopmode")) { interactionoption = 3; } else { - WARNING1("Ignoring unknown argument `%s' to --interaction", - optarg); + WARNING1("Ignoring unknown argument `%s' to --interaction", optarg); } - } else if (ARGUMENT_IS("synctex")) { /* Synchronize TeXnology: catching the command line option as a long */ synctexoption = (int) strtol(optarg, NULL, 0); - } else if (ARGUMENT_IS("help")) { usagehelp(LUATEX_IHELP, BUG_ADDRESS); - } else if (ARGUMENT_IS("version")) { print_version_banner(); /* *INDENT-OFF* */ @@ -463,9 +434,9 @@ static void parse_options(int ac, char **av) } /* attempt to find |input_name| / |dump_name| */ if (lua_only) { - if (argv[optind]) { - startup_filename = xstrdup(argv[optind]); - lua_offset = optind; + if (argv[optind]) { + startup_filename = xstrdup(argv[optind]); + lua_offset = optind; } } else if (argv[optind] && argv[optind][0] == '&') { dump_name = xstrdup(argv[optind] + 1); @@ -482,11 +453,11 @@ static void parse_options(int ac, char **av) firstfile + strlen(firstfile) - 4) || (strstr(firstfile, ".LUC") == firstfile + strlen(firstfile) - 4)) { - if (startup_filename == NULL) { - startup_filename = firstfile; - lua_offset = optind; - lua_only = 1; - luainit = 1; + if (startup_filename == NULL) { + startup_filename = firstfile; + lua_offset = optind; + lua_only = 1; + luainit = 1; } } else { input_name = firstfile; @@ -521,7 +492,6 @@ static void parse_options(int ac, char **av) } if (safer_option) /* --safer implies --nosocket */ nosocket_option = 1; - /* Finalize the input filename. */ if (input_name != NULL) { argv[optind] = normalize_quotes(input_name, "argument"); @@ -561,11 +531,9 @@ static char *find_filename(char *name, const char *envkey) return NULL; } - @ @c static void init_kpse(void) { - if (!user_progname) { user_progname = dump_name; } else if (!dump_name) { @@ -637,8 +605,7 @@ static const char *luatex_kpse_find_aux(lua_State *L, const char *name, filename = kpse_find_file(name, format, false); } if (filename == NULL) { - lua_pushfstring(L, "\n\t[kpse %s searcher] file not found: " LUA_QS, - errname, name); + lua_pushfstring(L, "\n\t[kpse %s searcher] file not found: " LUA_QS, errname, name); } return filename; } @@ -662,9 +629,9 @@ static int luatex_kpse_lua_find(lua_State * L) name = luaL_checkstring(L, 1); if (program_name_set == 0) { lua_rawgeti(L, LUA_REGISTRYINDEX, lua_loader_function); - lua_pushvalue(L, -2); - lua_call(L, 1, 1); - return 1; + lua_pushvalue(L, -2); + lua_call(L, 1, 1); + return 1; } filename = luatex_kpse_find_aux(L, name, kpse_lua_format, "lua"); if (filename == NULL) @@ -691,9 +658,9 @@ static int luatex_kpse_clua_find(lua_State * L) name = luaL_checkstring(L, 1); if (program_name_set == 0) { lua_rawgeti(L, LUA_REGISTRYINDEX, clua_loader_function); - lua_pushvalue(L, -2); - lua_call(L, 1, 1); - return 1; + lua_pushvalue(L, -2); + lua_call(L, 1, 1); + return 1; } else { const char *path_saved; char *prefix, *postfix, *p, *total; @@ -701,11 +668,12 @@ static int luatex_kpse_clua_find(lua_State * L) char *temp_name; int j; filename = luatex_kpse_find_aux(L, name, kpse_clua_format, "C"); - if (filename == NULL) + if (filename == NULL) return 1; /* library not found in this path */ - extensionless = strdup(filename); - if (!extensionless) return 1; /* allocation failure */ - /* Fix Issue 850: replace '.' with LUA_DIRSEP */ + extensionless = strdup(filename); + if (!extensionless) + return 1; /* allocation failure */ + /* Fix Issue 850: replace '.' with LUA_DIRSEP */ temp_name = strdup(name); for(j=0; ; j++){ if ((unsigned char)temp_name[j]=='\0') { @@ -715,36 +683,36 @@ static int luatex_kpse_clua_find(lua_State * L) temp_name[j]=LUA_DIRSEP[0]; } } - p = strstr(extensionless, temp_name); - if (!p) return 1; /* this would be exceedingly weird */ - *p = '\0'; - prefix = strdup(extensionless); - if (!prefix) return 1; /* allocation failure */ - postfix = strdup(p+strlen(name)); - if (!postfix) return 1; /* allocation failure */ - total = malloc(strlen(prefix)+strlen(postfix)+2); - if (!total) return 1; /* allocation failure */ - snprintf(total,strlen(prefix)+strlen(postfix)+2, "%s?%s", prefix, postfix); - /* save package.path */ - lua_getglobal(L,"package"); + p = strstr(extensionless, temp_name); + if (!p) return 1; /* this would be exceedingly weird */ + *p = '\0'; + prefix = strdup(extensionless); + if (!prefix) return 1; /* allocation failure */ + postfix = strdup(p+strlen(name)); + if (!postfix) return 1; /* allocation failure */ + total = malloc(strlen(prefix)+strlen(postfix)+2); + if (!total) return 1; /* allocation failure */ + snprintf(total,strlen(prefix)+strlen(postfix)+2, "%s?%s", prefix, postfix); + /* save package.path */ + lua_getglobal(L,"package"); lua_getfield(L,-1,"cpath"); - path_saved = lua_tostring(L,-1); - lua_pop(L,1); + path_saved = lua_tostring(L,-1); + lua_pop(L,1); /* set package.path = "?" */ - lua_pushstring(L,total); - lua_setfield(L,-2,"cpath"); - lua_pop(L,1); /* pop "package" */ + lua_pushstring(L,total); + lua_setfield(L,-2,"cpath"); + lua_pop(L,1); /* pop "package" */ /* run function */ lua_rawgeti(L, LUA_REGISTRYINDEX, clua_loader_function); - lua_pushstring(L, name); - lua_call(L, 1, 1); + lua_pushstring(L, name); + lua_call(L, 1, 1); /* restore package.path */ - lua_getglobal(L,"package"); - lua_pushstring(L,path_saved); - lua_setfield(L,-2,"cpath"); - lua_pop(L,1); /* pop "package" */ - free(extensionless); - free(total); + lua_getglobal(L,"package"); + lua_pushstring(L,path_saved); + lua_setfield(L,-2,"cpath"); + lua_pop(L,1); /* pop "package" */ + free(extensionless); + free(total); free(temp_name); return 1; } @@ -793,6 +761,33 @@ int l_math_style_name_index [MATH_STYLE_NAME_SIZE]; int l_dir_par_index [DIR_PAR_SIZE]; int l_dir_text_index [DIR_TEXT_SIZE]; +int img_parms [img_parms_max]; +int img_pageboxes [img_pageboxes_max]; + +int lua_show_valid_list(lua_State *L, const char **list, int max) +{ + int i; + lua_newtable(L); + for (i = 0; i < max; i++) { + lua_pushinteger(L,i+1); + lua_pushstring(L, list[i]); + lua_settable(L, -3); + } + return 1; +} + +int lua_show_valid_keys(lua_State *L, int *list, int max) +{ + int i; + lua_newtable(L); + for (i = 0; i < max; i++) { + lua_pushinteger(L,i+1); + lua_rawgeti(L, LUA_REGISTRYINDEX, list[i]); + lua_settable(L, -3); + } + return 1; +} + #if defined(WIN32) || defined(__MINGW32__) || defined(__CYGWIN__) char **suffixlist; @@ -846,37 +841,24 @@ static void mk_suffixlist(void) } #endif - @ @c void lua_initialize(int ac, char **av) { - char *given_file = NULL; char *banner; int kpse_init; + size_t len; static char LC_CTYPE_C[] = "LC_CTYPE=C"; static char LC_COLLATE_C[] = "LC_COLLATE=C"; static char LC_NUMERIC_C[] = "LC_NUMERIC=C"; static char engine_luatex[] = "engine=" my_name; /* Save to pass along to topenin. */ + const char *fmt = "This is " MyName ", Version %s" WEB2CVERSION; argc = ac; argv = av; - - - if (luatex_svn < 0) { - const char *fmt = "This is " MyName ", Version %s" WEB2CVERSION; - size_t len; - len = strlen(fmt) + strlen(luatex_version_string) ; - - banner = xmalloc(len); - sprintf(banner, fmt, luatex_version_string); - } else { - const char *fmt = "This is " MyName ", Version %s" WEB2CVERSION " (rev %d)"; - size_t len; - len = strlen(fmt) + strlen(luatex_version_string) + 6; - banner = xmalloc(len); - sprintf(banner, fmt, luatex_version_string, luatex_svn); - } + len = strlen(fmt) + strlen(luatex_version_string) ; + banner = xmalloc(len); + sprintf(banner, fmt, luatex_version_string); luatex_banner = banner; kpse_invocation_name = kpse_program_basename(argv[0]); @@ -946,6 +928,9 @@ void lua_initialize(int ac, char **av) set_l_dir_par_index; set_l_dir_text_index; + set_l_img_keys_index; + set_l_img_pageboxes_index; + prepare_cmdline(Luas, argv, argc, lua_offset); /* collect arguments */ setup_lua_path(Luas); @@ -974,7 +959,7 @@ void lua_initialize(int ac, char **av) init_tex_table(Luas); if (lua_pcall(Luas, 0, 0, 0)) { fprintf(stdout, "%s\n", lua_tostring(Luas, -1)); - lua_traceback(Luas); + lua_traceback(Luas); exit(1); } /* no filename? quit now! */ @@ -1028,7 +1013,7 @@ void lua_initialize(int ac, char **av) shellenabledp = 1; restrictedshell = 1; } - free(v1); + free(v1); } /* If shell escapes are restricted, get allowed cmds from cnf. */ if (shellenabledp && restrictedshell == 1) { @@ -1036,21 +1021,18 @@ void lua_initialize(int ac, char **av) get_lua_string("texconfig", "shell_escape_commands", &v1); if (v1) { mk_shellcmdlist(v1); - free(v1); + free(v1); } } fix_dumpname(); - } else { if (luainit) { if (given_file) { - fprintf(stdout, "%s file %s not found\n", - (lua_only ? "Script" : "Configuration"), given_file); + fprintf(stdout, "%s file %s not found\n", (lua_only ? "Script" : "Configuration"), given_file); free(given_file); } else { - fprintf(stdout, "No %s file given\n", - (lua_only ? "script" : "configuration")); + fprintf(stdout, "No %s file given\n", (lua_only ? "script" : "configuration")); } exit(1); } else { @@ -1072,30 +1054,10 @@ void check_texconfig_init(void) int i = lua_pcall(Luas, 0, 0, 0); if (i != 0) { /* Can't be more precise here, called before TeX initialization */ - fprintf(stderr, "This went wrong: %s\n", - lua_tostring(Luas, -1)); + fprintf(stderr, "This went wrong: %s\n", lua_tostring(Luas, -1)); error(); } } } } } - -@ @c -void write_svnversion(char *v) -{ - char *a_head, *n; - char *a = xstrdup(v); - size_t l = strlen("$Id: luatex.web "); - if (a != NULL) { - a_head = a; - if (strlen(a) > l) - a += l; - n = a; - while (*n != '\0' && *n != ' ') - n++; - *n = '\0'; - fprintf(stdout, " luatex.web >= v%s", a); - free(a_head); - } -} diff --git a/Build/source/texk/web2c/luatexdir/lua/luajitstuff.w b/Build/source/texk/web2c/luatexdir/lua/luajitstuff.w index 8e0953fa0ab..e19338027b0 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luajitstuff.w +++ b/Build/source/texk/web2c/luatexdir/lua/luajitstuff.w @@ -100,7 +100,7 @@ void luafunctioncall(int slot) lua_rawgeti(Luas, -1,slot); if (lua_isfunction(Luas,-1)) { int base = lua_gettop(Luas); /* function index */ - lua_pushnumber(Luas, slot); + lua_pushinteger(Luas, slot); lua_pushcfunction(Luas, lua_traceback); /* push traceback function */ lua_insert(Luas, base); /* put it under chunk */ i = lua_pcall(Luas, 1, 0, base); @@ -302,7 +302,6 @@ void luainterpreter(void) luaopen_ff(L); luaopen_tex(L); luaopen_token(L); - luaopen_oldtoken(L); luaopen_node(L); luaopen_texio(L); luaopen_kpse(L); @@ -587,7 +586,7 @@ lua_State *luatex_error(lua_State * L, int is_fatal) lua_close(L); return (lua_State *) NULL; } else { - normal_warning("lua",err,true,true); + normal_warning("lua",err); return L; } } diff --git a/Build/source/texk/web2c/luatexdir/lua/luanode.w b/Build/source/texk/web2c/luatexdir/lua/luanode.w index c1da8f2d1ca..bd328b8c2f2 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luanode.w +++ b/Build/source/texk/web2c/luatexdir/lua/luanode.w @@ -152,7 +152,7 @@ int lua_appendtovlist_callback(halfword box, int location, halfword prev_depth, } nodelist_to_lua(L, box); lua_push_string_by_index(L,location); - lua_pushnumber(L, (int) prev_depth); + lua_pushinteger(L, (int) prev_depth); lua_pushboolean(L, is_mirrored); if (lua_pcall(L, 4, 2, 0) != 0) { fprintf(stdout, "error: %s\n", lua_tostring(L, -1)); @@ -161,7 +161,7 @@ int lua_appendtovlist_callback(halfword box, int location, halfword prev_depth, return 0; } if (lua_type(L,-1) == LUA_TNUMBER) { - *next_depth = lua_tonumber(L,-1); + *next_depth = lua_tointeger(L,-1); *prev_set = true; if (lua_type(L, -2) != LUA_TNIL) { p = check_isnode(L, -2); @@ -193,7 +193,7 @@ halfword lua_hpack_filter(halfword head_node, scaled size, int pack_type, int ex alink(head_node) = null ; /* hh-ls */ nodelist_to_lua(L, head_node); lua_push_group_code(L,extrainfo); - lua_pushnumber(L, size); + lua_pushinteger(L, size); lua_push_pack_type(L,pack_type); if (pack_direction >= 0) lua_push_dir_par(L, pack_direction); @@ -251,9 +251,9 @@ halfword lua_vpack_filter(halfword head_node, scaled size, int pack_type, scaled alink(head_node) = null ; /* hh-ls */ nodelist_to_lua(L, head_node); lua_push_group_code(L,extrainfo); - lua_pushnumber(L, size); + lua_pushinteger(L, size); lua_push_pack_type(L,pack_type); - lua_pushnumber(L, maxd); + lua_pushinteger(L, maxd); if (pack_direction >= 0) lua_push_dir_par(L, pack_direction); else @@ -383,17 +383,17 @@ void show_pdf_literal(pointer p) { tprint_esc("pdfliteral"); switch (pdf_literal_mode(p)) { - case set_origin: - break; - case direct_page: - tprint(" page"); - break; - case direct_always: - tprint(" direct"); - break; - default: - confusion("literal2"); - break; + case set_origin: + break; + case direct_page: + tprint(" page"); + break; + case direct_always: + tprint(" direct"); + break; + default: + confusion("literal2"); + break; } if (pdf_literal_type(p) == normal) { print_mark(pdf_literal_data(p)); diff --git a/Build/source/texk/web2c/luatexdir/lua/luastuff.w b/Build/source/texk/web2c/luatexdir/lua/luastuff.w index 4214675cd19..6fac3afbf32 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luastuff.w +++ b/Build/source/texk/web2c/luatexdir/lua/luastuff.w @@ -96,7 +96,7 @@ void luafunctioncall(int slot) lua_rawgeti(Luas, -1,slot); if (lua_isfunction(Luas,-1)) { int base = lua_gettop(Luas); /* function index */ - lua_pushnumber(Luas, slot); + lua_pushinteger(Luas, slot); lua_pushcfunction(Luas, lua_traceback); /* push traceback function */ lua_insert(Luas, base); /* put it under chunk */ i = lua_pcall(Luas, 1, 0, base); @@ -255,7 +255,6 @@ void luainterpreter(void) /* our own libraries */ luaopen_ff(L); luaopen_tex(L); - luaopen_oldtoken(L); luaopen_token(L); luaopen_node(L); luaopen_texio(L); @@ -535,7 +534,7 @@ lua_State *luatex_error(lua_State * L, int is_fatal) lua_close(L); return (lua_State *) NULL; } else { - normal_warning("lua",err,true,true); + normal_warning("lua",err); return L; } } diff --git a/Build/source/texk/web2c/luatexdir/lua/luatex-api.h b/Build/source/texk/web2c/luatexdir/lua/luatex-api.h index 8c99cf72519..c67522c06fc 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luatex-api.h +++ b/Build/source/texk/web2c/luatexdir/lua/luatex-api.h @@ -156,7 +156,6 @@ extern int luajiton; extern char *jithash_hashname ; #endif - #if !defined(LUAI_HASHLIMIT) #define LUAI_HASHLIMIT 5 #endif @@ -245,6 +244,8 @@ extern char **environ; } #endif +extern int luatwrite(lua_State * L); + /* Same as in lnodelib.c, but with prefix G_ for now. These macros create and access pointers (indices) to keys which is faster. The @@ -318,14 +319,14 @@ extern int l_math_style_name_index [MATH_STYLE_NAME_SIZE]; extern int l_dir_par_index [DIR_PAR_SIZE]; extern int l_dir_text_index [DIR_TEXT_SIZE]; -#define lua_push_pack_type(L,pack_type) lua_rawgeti(L, LUA_REGISTRYINDEX, l_pack_type_index[pack_type] ); -#define lua_push_group_code(L,group_code) lua_rawgeti(L, LUA_REGISTRYINDEX, l_group_code_index[group_code]); +#define lua_push_pack_type(L,pack_type) lua_rawgeti(L, LUA_REGISTRYINDEX, l_pack_type_index[pack_type] ); +#define lua_push_group_code(L,group_code) lua_rawgeti(L, LUA_REGISTRYINDEX, l_group_code_index[group_code]); #define lua_push_math_style_name(L,style_name) lua_rawgeti(L, LUA_REGISTRYINDEX, l_math_style_name_index[style_name]); -#define lua_push_dir_par(L,dir) lua_rawgeti(L, LUA_REGISTRYINDEX, l_dir_par_index[dir+dir_swap]) -#define lua_push_dir_text(L,dir) lua_rawgeti(L, LUA_REGISTRYINDEX, l_dir_text_index[dir+dir_swap]) +#define lua_push_dir_par(L,dir) lua_rawgeti(L, LUA_REGISTRYINDEX, l_dir_par_index[dir+dir_swap]) +#define lua_push_dir_text(L,dir) lua_rawgeti(L, LUA_REGISTRYINDEX, l_dir_text_index[dir+dir_swap]) -#define lua_push_string_by_index(L,index) lua_rawgeti(L, LUA_REGISTRYINDEX, index) -#define lua_push_string_by_name(L,index) lua_rawgeti(L, LUA_REGISTRYINDEX, lua_key_index(index)) +#define lua_push_string_by_index(L,index) lua_rawgeti(L, LUA_REGISTRYINDEX, index) +#define lua_push_string_by_name(L,index) lua_rawgeti(L, LUA_REGISTRYINDEX, lua_key_index(index)) #define set_l_pack_type_index \ l_pack_type_index[0] = lua_key_index(exactly); \ @@ -388,6 +389,53 @@ l_dir_text_index[5] = lua_key_index(pTRT);\ l_dir_text_index[6] = lua_key_index(pLTL);\ l_dir_text_index[7] = lua_key_index(pRTT);\ +#define img_parms_max 25 +#define img_pageboxes_max 6 + +extern int img_parms [img_parms_max]; +extern int img_pageboxes [img_pageboxes_max]; + +# define set_l_img_keys_index \ +img_parms[ 0] = lua_key_index(attr); \ +img_parms[ 1] = lua_key_index(bbox); \ +img_parms[ 2] = lua_key_index(colordepth); \ +img_parms[ 3] = lua_key_index(colorspace); \ +img_parms[ 4] = lua_key_index(depth); \ +img_parms[ 5] = lua_key_index(filename); \ +img_parms[ 6] = lua_key_index(filepath); \ +img_parms[ 7] = lua_key_index(height); \ +img_parms[ 8] = lua_key_index(imagetype); \ +img_parms[ 9] = lua_key_index(index); \ +img_parms[10] = lua_key_index(keepopen); \ +img_parms[11] = lua_key_index(objnum); \ +img_parms[12] = lua_key_index(pagebox); \ +img_parms[13] = lua_key_index(page); \ +img_parms[14] = lua_key_index(pages); \ +img_parms[15] = lua_key_index(ref_count); \ +img_parms[16] = lua_key_index(rotation); \ +img_parms[17] = lua_key_index(stream); \ +img_parms[18] = lua_key_index(transform); \ +img_parms[19] = lua_key_index(visiblefilename); \ +img_parms[20] = lua_key_index(width); \ +img_parms[21] = lua_key_index(xres); \ +img_parms[22] = lua_key_index(xsize); \ +img_parms[23] = lua_key_index(yres); \ +img_parms[24] = lua_key_index(ysize); \ + +# define set_l_img_pageboxes_index \ +img_pageboxes[0] = lua_key_index(none); \ +img_pageboxes[1] = lua_key_index(media); \ +img_pageboxes[2] = lua_key_index(crop); \ +img_pageboxes[3] = lua_key_index(bleed); \ +img_pageboxes[4] = lua_key_index(trim); \ +img_pageboxes[5] = lua_key_index(art); \ + +#define lua_push_img_key(L,key) lua_rawgeti(L, LUA_REGISTRYINDEX, img_parms[key] ); +#define lua_push_img_pagebox(L,box) lua_rawgeti(L, LUA_REGISTRYINDEX, img_pageboxes[box]); + +extern int lua_show_valid_list(lua_State *L, const char **list, int max); +extern int lua_show_valid_keys(lua_State *L, int *list, int max); + #define set_make_keys \ make_lua_key(cmdname);make_lua_key(expandable);make_lua_key(protected);\ make_lua_key(LTL);\ @@ -413,13 +461,16 @@ make_lua_key(align_set);\ make_lua_key(alignment);\ make_lua_key(annot);\ make_lua_key(area);\ +make_lua_key(art);\ make_lua_key(attr);\ make_lua_key(attributes);\ make_lua_key(auto_expand);\ +make_lua_key(bbox);\ make_lua_key(before_display);\ make_lua_key(best_ins_ptr);\ make_lua_key(best_page_break);\ make_lua_key(best_size);\ +make_lua_key(bleed);\ make_lua_key(bot);\ make_lua_key(bot_accent);\ make_lua_key(bottom_left);\ @@ -439,6 +490,8 @@ make_lua_key(characters);\ make_lua_key(checksum);\ make_lua_key(cidinfo);\ make_lua_key(class);\ +make_lua_key(colordepth);\ +make_lua_key(colorspace);\ make_lua_key(command);\ make_lua_key(commands);\ make_lua_key(comment);\ @@ -452,6 +505,7 @@ make_lua_key(crampeddisplay);\ make_lua_key(crampedscript);\ make_lua_key(crampedscriptscript);\ make_lua_key(crampedtext);\ +make_lua_key(crop);\ make_lua_key(csname);\ make_lua_key(data);\ make_lua_key(degree);\ @@ -491,6 +545,7 @@ make_lua_key(fast);\ make_lua_key(fence);\ make_lua_key(file);\ make_lua_key(filename);\ +make_lua_key(filepath);\ make_lua_key(fill);\ make_lua_key(fin_row);\ make_lua_key(font);\ @@ -513,11 +568,13 @@ make_lua_key(horiz_variants);\ make_lua_key(hyphenchar);\ make_lua_key(id);\ make_lua_key(image);\ +make_lua_key(imagetype);\ make_lua_key(immediate);\ make_lua_key(index);\ make_lua_key(info);\ make_lua_key(insert);\ make_lua_key(italic);\ +make_lua_key(keepopen);\ make_lua_key(kern);\ make_lua_key(kerns);\ make_lua_key(lang);\ @@ -554,6 +611,7 @@ make_lua_key(math_shift);\ make_lua_key(mathdir);\ make_lua_key(mathkern);\ make_lua_key(mathstyle);\ +make_lua_key(media);\ make_lua_key(mid);\ make_lua_key(mode);\ make_lua_key(modeline);\ @@ -570,6 +628,7 @@ make_lua_key(node);\ make_lua_key(node_properties);\ make_lua_key(node_properties_indirect);\ make_lua_key(nomath);\ +make_lua_key(none);\ make_lua_key(nop);\ make_lua_key(nucleus);\ make_lua_key(num);\ @@ -586,9 +645,11 @@ make_lua_key(pRTT);\ make_lua_key(pTLT);\ make_lua_key(pTRT);\ make_lua_key(page);\ +make_lua_key(pages);\ make_lua_key(page_head);\ make_lua_key(page_ins_head);\ make_lua_key(pageattributes);\ +make_lua_key(pagebox);\ make_lua_key(pageresources);\ make_lua_key(pagesattributes);\ make_lua_key(parameters);\ @@ -627,6 +688,7 @@ make_lua_key(resources);\ make_lua_key(right);\ make_lua_key(right_boundary);\ make_lua_key(right_protruding);\ +make_lua_key(rotation);\ make_lua_key(rule);\ make_lua_key(scale);\ make_lua_key(script);\ @@ -682,6 +744,7 @@ make_lua_key(top_right);\ make_lua_key(tounicode);\ make_lua_key(trailer);\ make_lua_key(transform);\ +make_lua_key(trim);\ make_lua_key(type);\ make_lua_key(uchyph);\ make_lua_key(umath);\ @@ -696,6 +759,7 @@ make_lua_key(version);\ make_lua_key(vert_italic);\ make_lua_key(vert_variants);\ make_lua_key(vmode_par);\ +make_lua_key(visiblefilename);\ make_lua_key(vtop);\ make_lua_key(width);\ make_lua_key(writable);\ @@ -703,8 +767,12 @@ make_lua_key(x_height);\ make_lua_key(xformresources);\ make_lua_key(xformattributes);\ make_lua_key(xoffset);\ +make_lua_key(xres);\ +make_lua_key(xsize);\ make_lua_key(xyz_zoom);\ -make_lua_key(yoffset) +make_lua_key(yoffset); \ +make_lua_key(yres); \ +make_lua_key(ysize) #define set_init_keys \ init_lua_key(cmdname);init_lua_key(expandable);init_lua_key(protected);\ @@ -731,13 +799,16 @@ init_lua_key(align_set);\ init_lua_key(alignment);\ init_lua_key(annot);\ init_lua_key(area);\ +init_lua_key(art);\ init_lua_key(attr);\ init_lua_key(attributes);\ init_lua_key(auto_expand);\ +init_lua_key(bbox);\ init_lua_key(before_display);\ init_lua_key(best_ins_ptr);\ init_lua_key(best_page_break);\ init_lua_key(best_size);\ +init_lua_key(bleed);\ init_lua_key(bot);\ init_lua_key(bot_accent);\ init_lua_key(bottom_left);\ @@ -757,6 +828,8 @@ init_lua_key(characters);\ init_lua_key(checksum);\ init_lua_key(cidinfo);\ init_lua_key(class);\ +init_lua_key(colordepth);\ +init_lua_key(colorspace);\ init_lua_key(command);\ init_lua_key(commands);\ init_lua_key(comment);\ @@ -770,6 +843,7 @@ init_lua_key(crampeddisplay);\ init_lua_key(crampedscript);\ init_lua_key(crampedscriptscript);\ init_lua_key(crampedtext);\ +init_lua_key(crop);\ init_lua_key(csname);\ init_lua_key(data);\ init_lua_key(degree);\ @@ -808,6 +882,7 @@ init_lua_key(fast);\ init_lua_key(fence);\ init_lua_key(file);\ init_lua_key(filename);\ +init_lua_key(filepath);\ init_lua_key(fill);\ init_lua_key(fin_row);\ init_lua_key(font);\ @@ -830,11 +905,13 @@ init_lua_key(horiz_variants);\ init_lua_key(hyphenchar);\ init_lua_key(id);\ init_lua_key(image);\ +init_lua_key(imagetype);\ init_lua_key(immediate);\ init_lua_key(index);\ init_lua_key(info);\ init_lua_key(insert);\ init_lua_key(italic);\ +init_lua_key(keepopen);\ init_lua_key(kern);\ init_lua_key(kerns);\ init_lua_key(lang);\ @@ -867,6 +944,7 @@ init_lua_key(math_shift);\ init_lua_key(mathdir);\ init_lua_key(mathkern);\ init_lua_key(mathstyle);\ +init_lua_key(media);\ init_lua_key(mid);\ init_lua_key(mode);\ init_lua_key(modeline);\ @@ -881,6 +959,7 @@ init_lua_key(no_align);\ init_lua_key(noad);\ init_lua_key(node);\ init_lua_key(nomath);\ +init_lua_key(none);\ init_lua_key(nop);\ init_lua_key(nucleus);\ init_lua_key(num);\ @@ -893,9 +972,11 @@ init_lua_key(ordering);\ init_lua_key(output);\ init_lua_key(overlay_accent);\ init_lua_key(page);\ +init_lua_key(pages);\ init_lua_key(page_head);\ init_lua_key(page_ins_head);\ init_lua_key(pageattributes);\ +init_lua_key(pagebox);\ init_lua_key(pageresources);\ init_lua_key(pagesattributes);\ init_lua_key(parameters);\ @@ -933,6 +1014,7 @@ init_lua_key(resources);\ init_lua_key(right);\ init_lua_key(right_boundary);\ init_lua_key(right_protruding);\ +init_lua_key(rotation);\ init_lua_key(rule);\ init_lua_key(scale);\ init_lua_key(script);\ @@ -987,6 +1069,7 @@ init_lua_key(top_right);\ init_lua_key(tounicode);\ init_lua_key(trailer);\ init_lua_key(transform);\ +init_lua_key(trim);\ init_lua_key(type);\ init_lua_key(uchyph);\ init_lua_key(umath);\ @@ -1001,6 +1084,7 @@ init_lua_key(version);\ init_lua_key(vert_italic);\ init_lua_key(vert_variants);\ init_lua_key(vmode_par);\ +init_lua_key(visiblefilename);\ init_lua_key(vtop);\ init_lua_key(width);\ init_lua_key(writable);\ @@ -1008,8 +1092,12 @@ init_lua_key(x_height);\ init_lua_key(xformresources);\ init_lua_key(xformattributes);\ init_lua_key(xoffset);\ +init_lua_key(xres);\ +init_lua_key(xsize);\ init_lua_key(xyz_zoom);\ init_lua_key(yoffset);\ +init_lua_key(yres);\ +init_lua_key(ysize);\ init_lua_key_alias(empty_string,"");\ init_lua_key_alias(lua_functions,"lua.functions");\ init_lua_key_alias(luatex_node, "luatex.node");\ @@ -1029,7 +1117,7 @@ init_lua_key_alias(term_and_log,"term and log") #define assign_math_style(L,n,target) do { \ if (lua_type(L,n) == LUA_TNUMBER) { \ /* new, often same as subtype anyway */ \ - target = lua_tonumber(L,n); \ + target = lua_tointeger(L,n); \ } else if (lua_type(L,n) == LUA_TSTRING) { \ const char *s = lua_tostring(L, n); \ if (lua_key_eq(s,display)) { \ @@ -1092,13 +1180,16 @@ use_lua_key(align_set); use_lua_key(alignment); use_lua_key(annot); use_lua_key(area); +use_lua_key(art); use_lua_key(attr); use_lua_key(attributes); use_lua_key(auto_expand); +use_lua_key(bbox); use_lua_key(before_display); use_lua_key(best_ins_ptr); use_lua_key(best_page_break); use_lua_key(best_size); +use_lua_key(bleed); use_lua_key(bot); use_lua_key(bot_accent); use_lua_key(bottom_left); @@ -1118,6 +1209,8 @@ use_lua_key(characters); use_lua_key(checksum); use_lua_key(cidinfo); use_lua_key(class); +use_lua_key(colordepth); +use_lua_key(colorspace); use_lua_key(command); use_lua_key(commands); use_lua_key(comment); @@ -1131,6 +1224,7 @@ use_lua_key(crampeddisplay); use_lua_key(crampedscript); use_lua_key(crampedscriptscript); use_lua_key(crampedtext); +use_lua_key(crop); use_lua_key(csname); use_lua_key(data); use_lua_key(degree); @@ -1170,6 +1264,7 @@ use_lua_key(fast); use_lua_key(fence); use_lua_key(file); use_lua_key(filename); +use_lua_key(filepath); use_lua_key(fill); use_lua_key(fin_row); use_lua_key(font); @@ -1192,11 +1287,13 @@ use_lua_key(horiz_variants); use_lua_key(hyphenchar); use_lua_key(id); use_lua_key(image); +use_lua_key(imagetype); use_lua_key(immediate); use_lua_key(index); use_lua_key(info); use_lua_key(insert); use_lua_key(italic); +use_lua_key(keepopen); use_lua_key(kern); use_lua_key(kerns); use_lua_key(lang); @@ -1233,6 +1330,7 @@ use_lua_key(math_shift); use_lua_key(mathdir); use_lua_key(mathkern); use_lua_key(mathstyle); +use_lua_key(media); use_lua_key(mid); use_lua_key(mode); use_lua_key(modeline); @@ -1249,6 +1347,7 @@ use_lua_key(node); use_lua_key(node_properties); use_lua_key(node_properties_indirect); use_lua_key(nomath); +use_lua_key(none); use_lua_key(nop); use_lua_key(nucleus); use_lua_key(num); @@ -1265,8 +1364,10 @@ use_lua_key(pRTT); use_lua_key(pTLT); use_lua_key(pTRT); use_lua_key(page); +use_lua_key(pages); use_lua_key(page_head); use_lua_key(page_ins_head); +use_lua_key(pagebox); use_lua_key(pageattributes); use_lua_key(pageresources); use_lua_key(pagesattributes); @@ -1306,6 +1407,7 @@ use_lua_key(resources); use_lua_key(right); use_lua_key(right_boundary); use_lua_key(right_protruding); +use_lua_key(rotation); use_lua_key(rule); use_lua_key(scale); use_lua_key(script); @@ -1361,6 +1463,7 @@ use_lua_key(top_right); use_lua_key(tounicode); use_lua_key(trailer); use_lua_key(transform); +use_lua_key(trim); use_lua_key(type); use_lua_key(uchyph); use_lua_key(umath); @@ -1375,6 +1478,7 @@ use_lua_key(version); use_lua_key(vert_italic); use_lua_key(vert_variants); use_lua_key(vmode_par); +use_lua_key(visiblefilename); use_lua_key(vtop); use_lua_key(width); use_lua_key(writable); @@ -1382,5 +1486,9 @@ use_lua_key(x_height); use_lua_key(xformresources); use_lua_key(xformattributes); use_lua_key(xoffset); +use_lua_key(xres); +use_lua_key(xsize); use_lua_key(xyz_zoom); use_lua_key(yoffset); +use_lua_key(yres); +use_lua_key(ysize); diff --git a/Build/source/texk/web2c/luatexdir/lua/luatoken.w b/Build/source/texk/web2c/luatexdir/lua/luatoken.w index d8ac7eebca8..9001026ca45 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luatoken.w +++ b/Build/source/texk/web2c/luatexdir/lua/luatoken.w @@ -158,6 +158,7 @@ command_item command_names[] = { {"variable", variable_cmd, NULL}, {"feedback", feedback_cmd, NULL}, {"the", the_cmd, NULL}, + {"combinetoks", combine_toks_cmd, NULL}, {"top_bot_mark", top_bot_mark_cmd, NULL}, {"call", call_cmd, NULL}, {"long_call", long_call_cmd, NULL}, @@ -188,7 +189,7 @@ int get_command_id(const char *s) return cmd; } -@ @c +/* static int get_cur_cmd(lua_State * L) { int r = 0; @@ -212,7 +213,7 @@ static int get_cur_cmd(lua_State * L) } return r; } - +*/ @ @c static int token_from_lua(lua_State * L) @@ -239,7 +240,7 @@ static int token_from_lua(lua_State * L) return -1; } -@ @c +/* static int get_cur_cs(lua_State * L) { const char *s; @@ -272,6 +273,7 @@ static int get_cur_cs(lua_State * L) lua_pop(L, 1); return ret; } +*/ @ @c void tokenlist_to_lua(lua_State * L, int p) @@ -357,28 +359,28 @@ int tokenlist_from_lua(lua_State * L) } } -@ @c -void do_get_token_lua(int callback_id) +/* + +static void do_get_token_lua(int callback_id) { lua_State *L = Luas; while (1) { if (!get_callback(L, callback_id)) { get_next(); - lua_pop(L, 2); /* the not-a-function callback and the container */ + lua_pop(L, 2); break; } - if (lua_pcall(L, 0, 1, 0) != 0) { /* no arg, 1 result */ + if (lua_pcall(L, 0, 1, 0) != 0) { tex_error(lua_tostring(L, -1), NULL); - lua_pop(L, 2); /* container and result */ + lua_pop(L, 2); break; } if (lua_istable(L, -1)) { lua_rawgeti(L, -1, 1); - if (lua_istable(L, -1)) { /* container, result, result[1] */ + if (lua_istable(L, -1)) { int p, q, r; size_t i, j; - lua_pop(L, 1); /* container, result */ - /* build a token list */ + lua_pop(L, 1); r = get_avail(); p = r; j = lua_rawlen(L, -1); @@ -403,8 +405,8 @@ void do_get_token_lua(int callback_id) } lua_pop(L, 2); break; - } else { /* container, result, whatever */ - lua_pop(L, 1); /* container, result */ + } else { + lua_pop(L, 1); if (get_cur_cmd(L) || get_cur_cs(L)) { lua_pop(L, 2); break; @@ -414,8 +416,10 @@ void do_get_token_lua(int callback_id) } } } else { - lua_pop(L, 2); /* container, result */ + lua_pop(L, 2); } } return; } + +*/ diff --git a/Build/source/texk/web2c/luatexdir/luafilesystem/src/lfs.c b/Build/source/texk/web2c/luatexdir/luafilesystem/src/lfs.c index a0b967df193..2b1b06cf1db 100644 --- a/Build/source/texk/web2c/luatexdir/luafilesystem/src/lfs.c +++ b/Build/source/texk/web2c/luatexdir/luafilesystem/src/lfs.c @@ -374,10 +374,8 @@ static int make_dir (lua_State *L) { const char *path = luaL_checkstring (L, 1); int fail; #ifdef _WIN32 - int oldmask = umask (0); fail = _mkdir (path); #else - mode_t oldmask = umask( (mode_t)0 ); fail = mkdir (path, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH ); #endif @@ -386,7 +384,6 @@ static int make_dir (lua_State *L) { lua_pushfstring (L, "%s", strerror(errno)); return 2; } - umask (oldmask); lua_pushboolean (L, 1); return 1; } diff --git a/Build/source/texk/web2c/luatexdir/luascripts/pdflua.c b/Build/source/texk/web2c/luatexdir/luascripts/pdflua.c deleted file mode 100644 index 05fe351cb7e..00000000000 --- a/Build/source/texk/web2c/luatexdir/luascripts/pdflua.c +++ /dev/null @@ -1,37 +0,0 @@ -/* pdflua.c - - Copyright 2010 Taco Hoekwater - Copyright 2010 Hartmut Henkel - - This file is part of LuaTeX. - - LuaTeX 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. - - LuaTeX 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 Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ - -#include "ptexlib.h" - -static const Byte compr[139] = { - 0x78, 0x9c, 0xad, 0x4e, 0x5b, 0x0a, 0xc3, 0x30, 0x0c, 0xfb, 0xd7, 0x29, 0xfc, 0xb9, 0x41, 0x93, - 0x1b, 0xec, 0x30, 0x59, 0xeb, 0x76, 0x61, 0xc1, 0x09, 0x4e, 0xc2, 0x18, 0x63, 0x77, 0x5f, 0x0a, - 0x61, 0x4f, 0xf6, 0x57, 0x23, 0x8c, 0x90, 0x04, 0x12, 0x8c, 0xa1, 0x72, 0xf2, 0x99, 0x1a, 0xd8, - 0x69, 0xb8, 0xd2, 0x25, 0xea, 0x99, 0xbc, 0x50, 0xd2, 0xb8, 0x28, 0xe7, 0x6c, 0xad, 0x05, 0xcc, - 0x46, 0x07, 0x1c, 0x79, 0xf1, 0x92, 0xdc, 0xc2, 0x74, 0xa0, 0xb9, 0xca, 0x58, 0x7c, 0x94, 0x9d, - 0xdb, 0x83, 0x65, 0xc2, 0xfa, 0xfe, 0x59, 0xb1, 0x96, 0xd4, 0xd0, 0xdc, 0x5c, 0x94, 0x3f, 0x22, - 0x3d, 0xb1, 0xdd, 0xc6, 0x10, 0x47, 0x17, 0x28, 0x4d, 0x73, 0xa8, 0xae, 0x15, 0xdd, 0x40, 0xf4, - 0x3e, 0xfb, 0xc9, 0x87, 0x66, 0xbc, 0x26, 0x77, 0xb6, 0x8a, 0xbf, 0x63, 0xbf, 0x94, 0x01, 0x77, - 0x40, 0xb9, 0x54, 0x95, 0xde, 0x83, 0x07, 0x1c, 0xdd, 0x6c, 0x66 -}; - -static const zlib_struct compr_struct = { 394, 139, compr }; - -const zlib_struct *pdflua_zlib_struct_ptr = &compr_struct; diff --git a/Build/source/texk/web2c/luatexdir/luascripts/pdflua.h b/Build/source/texk/web2c/luatexdir/luascripts/pdflua.h deleted file mode 100644 index d80f55006ef..00000000000 --- a/Build/source/texk/web2c/luatexdir/luascripts/pdflua.h +++ /dev/null @@ -1,33 +0,0 @@ -/* pdflua.h - - Copyright 2010 Taco Hoekwater - Copyright 2010 Hartmut Henkel - - This file is part of LuaTeX. - - LuaTeX 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. - - LuaTeX 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 Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ - - -#ifndef PDFLUA_H -# define PDFLUA_H - -typedef struct _zlib_struct { - uLong uncomprLen; - uLong comprLen; - const Byte *compr; -} zlib_struct; - -extern const zlib_struct *pdflua_zlib_struct_ptr; - -#endif /* PDFLUA_H */ diff --git a/Build/source/texk/web2c/luatexdir/luascripts/pdflua.lua b/Build/source/texk/web2c/luatexdir/luascripts/pdflua.lua deleted file mode 100644 index c8164367d75..00000000000 --- a/Build/source/texk/web2c/luatexdir/luascripts/pdflua.lua +++ /dev/null @@ -1,23 +0,0 @@ - --- this is early work in progress... - ------------------------------------------------------------------------- - -beginpage = function(a) -end - -endpage = function(a) -end - -outputpagestree = function() -end - ------------------------------------------------------------------------- - -local pdflua = { - beginpage = beginpage, - endpage = endpage, - outputpagestree = outputpagestree, -} - -return pdflua diff --git a/Build/source/texk/web2c/luatexdir/luascripts/txt2zlib.w b/Build/source/texk/web2c/luatexdir/luascripts/txt2zlib.w deleted file mode 100644 index 669125b7f26..00000000000 --- a/Build/source/texk/web2c/luatexdir/luascripts/txt2zlib.w +++ /dev/null @@ -1,143 +0,0 @@ -% txt2zlib.w -% -% Copyright 2010 Taco Hoekwater -% Copyright 2010 Hartmut Henkel -% -% This file is part of LuaTeX. -% -% LuaTeX 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. -% -% LuaTeX 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 Lesser General Public -% License for more details. -% -% You should have received a copy of the GNU General Public License along -% with LuaTeX; if not, see . - - -@ -@c - -#include -#include -#include -#include - -#define INBUFINITLEN 10 -#define LINELEN 16 - -char header[] = - " Copyright 2010 Taco Hoekwater \n" - " Copyright 2010 Hartmut Henkel \n" - "\n" - " This file is part of LuaTeX.\n" - "\n" - " LuaTeX is free software; you can redistribute it and/or modify it under\n" - " the terms of the GNU General Public License as published by the Free\n" - " Software Foundation; either version 2 of the License, or (at your\n" - " option) any later version.\n" - "\n" - " LuaTeX is distributed in the hope that it will be useful, but WITHOUT\n" - " ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\n" - " FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public\n" - " License for more details.\n" - "\n" - " You should have received a copy of the GNU General Public License along\n" - " with LuaTeX; if not, see ."; - -#define NAMELEN 100 - -int main(int argc, char *argv[]) -{ - int i, j, c, err; - Byte *inbuf = NULL, *outbuf; - FILE *fin, *fout; - char ptrname[NAMELEN]; - uLong inbuflen, uncomprLen = 0, outbuflen, comprLen; - - if (argc != 3) { - fprintf(stderr, - "%s: need exactly two arguments (input file name, output file name).\n", - argv[0]); - exit(EXIT_FAILURE); - } - fin = fopen(argv[1], "r"); - if (fin == NULL) { - fprintf(stderr, "%s: can't open %s for reading.\n", argv[0], argv[1]); - exit(EXIT_FAILURE); - } - fout = fopen(argv[2], "wb"); - if (fout == NULL) { - fprintf(stderr, "%s: can't open %s for writing.\n", argv[0], argv[2]); - exit(EXIT_FAILURE); - } - if ((inbuf = malloc(INBUFINITLEN * sizeof(Byte))) == NULL) - exit(EXIT_FAILURE); - inbuflen = INBUFINITLEN; - while ((c = fgetc(fin)) != EOF) { - if (uncomprLen == inbuflen - 1) { - inbuflen = (uLong) ((double) inbuflen * 1.5 + 1); - if ((inbuf = realloc(inbuf, inbuflen)) == NULL) - exit(EXIT_FAILURE); - } - inbuf[uncomprLen] = (Byte) c; - uncomprLen++; - } - - outbuflen = comprLen = (uLong) ((double) uncomprLen * 1.1 + 50); - if ((outbuf = malloc(outbuflen * sizeof(Byte))) == NULL) - exit(EXIT_FAILURE); - - err = compress(outbuf, &comprLen, inbuf, uncomprLen); - - if (err != Z_OK) { - fprintf(stderr, "compress error: %d\n", err); - exit(EXIT_FAILURE); - } - - fprintf(fout, "/* %s\n\n", argv[2]); - fprintf(fout, "%s */\n\n", header); - fprintf(fout, "#include \"ptexlib.h\"\n\n"); - - fprintf(fout, "static const Byte compr[%ld] = {\n", comprLen); - for (i = 0, j = 0; (uLong) i < comprLen; i++) { - if (j == 0) - fprintf(fout, " "); - fprintf(fout, "0x%02x", outbuf[i]); - if ((uLong) i < comprLen - 1) { - fprintf(fout, ","); - if (j == LINELEN - 1) { - fprintf(fout, "\n"); - j = 0; - } else { - fprintf(fout, " "); - j++; - } - } - } - fprintf(fout, "\n};\n\n"); - - strncpy(ptrname, argv[2], NAMELEN - 20); - for (i = (int) strlen(ptrname) - 1; i > 0; i--) { - if (ptrname[i] == '.') { - ptrname[i] = '\0'; - break; - } - } - - strcat(ptrname, "_zlib_struct_ptr"); - - fprintf(fout, - "static const zlib_struct compr_struct = { %ld, %ld, compr };\n\n", - uncomprLen, comprLen); - - fprintf(fout, "const zlib_struct *%s = &compr_struct;\n", ptrname); - - fclose(fin); - fclose(fout); - return EXIT_SUCCESS; -} diff --git a/Build/source/texk/web2c/luatexdir/luatex-common.h b/Build/source/texk/web2c/luatexdir/luatex-common.h index 379c7b2f43c..073d6ad1c5b 100644 --- a/Build/source/texk/web2c/luatexdir/luatex-common.h +++ b/Build/source/texk/web2c/luatexdir/luatex-common.h @@ -25,9 +25,11 @@ # define LUATEX_COMMON_H /* utils.c */ -__attribute__ ((format(printf, 1, 2))) -extern void luatex_warn(const char *fmt, ...); -__attribute__ ((noreturn, format(printf, 1, 2))) -extern void luatex_fail(const char *fmt, ...); + +extern void tex_error(const char *msg, const char **hlp); +extern void normal_error(const char *t, const char *p); +extern void normal_warning(const char *t, const char *p); +extern void formatted_error(const char *t, const char *fmt, ...); +extern void formatted_warning(const char *t, const char *fmt, ...); #endif /* LUATEX_COMMON_H */ diff --git a/Build/source/texk/web2c/luatexdir/luatex.c b/Build/source/texk/web2c/luatexdir/luatex.c index 64393bad697..279d46faa50 100644 --- a/Build/source/texk/web2c/luatexdir/luatex.c +++ b/Build/source/texk/web2c/luatexdir/luatex.c @@ -2,7 +2,7 @@ written by Tim Morgan, drawing from other Unix ports of TeX. This is a collection of miscellany, everything that's easier (or only possible) to do in C. - + This file is public domain. */ /* This file is used to create texextra.c etc., with this line @@ -21,16 +21,17 @@ #include "ptexlib.h" #include "luatex.h" #include "lua/luatex-api.h" +/* #include "luatex_svnversion.h" +*/ #define TeX -int luatex_svn = luatex_svn_revision; -int luatex_version = 85; /* \.{\\luatexversion} */ +int luatex_version = 86; /* \.{\\luatexversion} */ int luatex_revision = '0'; /* \.{\\luatexrevision} */ -int luatex_date_info = 2015111900; /* the compile date is now hardwired */ -const char *luatex_version_string = "beta-0.85.0"; +int luatex_date_info = 2015120800; /* the compile date is now hardwired */ +const char *luatex_version_string = "beta-0.86.0"; const char *engine_name = my_name; /* the name of this engine */ #include @@ -204,7 +205,7 @@ static int Isspace(char c) -1 : invalid quotation of an argument 0 : command is not allowed 2 : restricted shell escape, CMD is allowed. - + We set *SAFECMD to a safely-quoted version of *CMD; this is what should get executed. And we set CMDNAME to its first word; this is what is checked against the shell_escape_commands list. */ @@ -379,7 +380,7 @@ int shell_cmd_is_allowed(const char *cmd, char **safecmd, char **cmdname) strcat (q, (p + 2)); free (*safecmd); *safecmd = q; - } else if (!IS_DIR_SEP (p[0]) && !(p[1] == ':' && IS_DIR_SEP (p[2]))) { + } else if (!IS_DIR_SEP (p[0]) && !(p[1] == ':' && IS_DIR_SEP (p[2]))) { p = kpse_var_value ("SELFAUTOLOC"); if (p) { r = *safecmd; @@ -432,15 +433,15 @@ int runsystem(const char *cmd) allow = 1; else allow = shell_cmd_is_allowed(cmd, &safecmd, &cmdname); - + if (allow == 1) status = system(cmd); else if (allow == 2) status = system(safecmd); /* Not really meaningful, but we have to manage the return value of system. */ if (status==-1) - fprintf(stderr,"system returned with code -1\n"); - + fprintf(stderr,"system returned with code -1\n"); + if (safecmd) free(safecmd); if (cmdname) @@ -480,7 +481,7 @@ static void myInvalidParameterHandler(const wchar_t * expression, /* I return silently to avoid an exit with the error 0xc0000417 (invalid parameter) when we use non-embedded fonts in luatex-ja, - which works without any problem on Unix systems. + which works without any problem on Unix systems. I hope it is not dangerous. */ return; @@ -628,7 +629,7 @@ struct msg int namelength; /* length of auxiliary data */ int eof; /* new eof for dvi file */ #if 0 /* see usage of struct msg below */ - char more_data[0]; /* where the rest of the stuff goes */ + char more_data[0]; /* where the rest of the stuff goes */ #endif }; @@ -799,7 +800,7 @@ ipcpage (int is_eof) if (!begun) { string name; /* Just the filename. */ string cwd = xgetcwd (); - + ipc_open_out (); /* Have to pass whole filename to the other end, since it may have @@ -824,7 +825,7 @@ ipcpage (int is_eof) begun = true; } ipc_snd (len, is_eof, p); - + if (p) free (p); } diff --git a/Build/source/texk/web2c/luatexdir/luatexcallbackids.h b/Build/source/texk/web2c/luatexdir/luatexcallbackids.h index 368a0234014..e2010282075 100644 --- a/Build/source/texk/web2c/luatexdir/luatexcallbackids.h +++ b/Build/source/texk/web2c/luatexdir/luatexcallbackids.h @@ -44,7 +44,6 @@ typedef enum { start_page_number_callback, stop_page_number_callback, start_run_callback, stop_run_callback, define_font_callback, - token_filter_callback, pre_output_filter_callback, buildpage_filter_callback, hpack_filter_callback, vpack_filter_callback, @@ -64,6 +63,7 @@ typedef enum { show_error_message_callback, show_lua_error_hook_callback, show_warning_message_callback, hpack_quality_callback, vpack_quality_callback, + process_rule_callback, total_callbacks } callback_callback_types; @@ -91,6 +91,8 @@ extern void get_lua_boolean(const char *table, const char *name, boolean * targe extern void get_lua_number(const char *table, const char *name, int *target); extern void get_lua_string(const char *table, const char *name, char **target); +extern int lua_reader_callback(int callback_id, pointer *buffloc); + extern char *get_lua_name(int i); /* texfileio.c */ diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfaction.h b/Build/source/texk/web2c/luatexdir/pdf/pdfaction.h index ed9ba48a2ce..3d7751351df 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfaction.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfaction.h @@ -15,25 +15,30 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ + with LuaTeX; if not, see . +*/ #ifndef PDFACTION_H # define PDFACTION_H -/* increase count of references to this action. this is used to speed up - copy_node() */ +/* + Increase count of references to this action. this is used to speed up + copy_node(). +*/ # define add_action_ref(a) pdf_action_refcount((a))++ -/* decrease count of references to this action; free it if there is no reference - to this action */ +/* + Decrease count of references to this action; free it if there is no reference + to this action. +*/ -# define delete_action_ref(a) { \ +# define delete_action_ref(a) { \ if (pdf_action_refcount(a) == null) { \ - flush_node(a); \ - } else { \ - pdf_action_refcount(a)--; \ - } \ + flush_node(a); \ + } else { \ + pdf_action_refcount(a)--; \ + } \ } # define set_pdf_action_type(A,B) pdf_action_type(A)=B diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfaction.w b/Build/source/texk/web2c/luatexdir/pdf/pdfaction.w index 65c1afcc352..bb0d6e06d50 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfaction.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfaction.w @@ -19,16 +19,14 @@ @ @c - #include "ptexlib.h" @ read an action specification -@c -halfword scan_action(PDF pdf) + +@c halfword scan_action(PDF pdf) { - int p; + int p = new_node(whatsit_node, pdf_action_node); (void) pdf; - p = new_node(whatsit_node, pdf_action_node); if (scan_keyword("user")) set_pdf_action_type(p, pdf_action_user); else if (scan_keyword("goto")) @@ -38,12 +36,12 @@ halfword scan_action(PDF pdf) else normal_error("pdf backend", "action type missing"); if (pdf_action_type(p) == pdf_action_user) { - scan_pdf_ext_toks(); + scan_toks(false, true); set_pdf_action_tokens(p, def_ref); return p; } if (scan_keyword("file")) { - scan_pdf_ext_toks(); + scan_toks(false, true); set_pdf_action_file(p, def_ref); } if (scan_keyword("page")) { @@ -55,10 +53,10 @@ halfword scan_action(PDF pdf) normal_error("pdf backend", "page number must be positive"); set_pdf_action_id(p, cur_val); set_pdf_action_named_id(p, 0); - scan_pdf_ext_toks(); + scan_toks(false, true); set_pdf_action_tokens(p, def_ref); } else if (scan_keyword("name")) { - scan_pdf_ext_toks(); + scan_toks(false, true); set_pdf_action_named_id(p, 1); set_pdf_action_id(p, def_ref); } else if (scan_keyword("num")) { @@ -97,8 +95,8 @@ halfword scan_action(PDF pdf) } @ write an action specification -@c -void write_action(PDF pdf, halfword p) + +@c void write_action(PDF pdf, halfword p) { char *s; int d = 0; @@ -124,44 +122,30 @@ void write_action(PDF pdf, halfword p) } } switch (pdf_action_type(p)) { - case pdf_action_page: - pdf_dict_add_name(pdf, "S", "GoTo"); - if (pdf_action_file(p) == null) { - pdf_add_name(pdf, "D"); - pdf_begin_array(pdf); - pdf_add_ref(pdf, pdf_get_obj(pdf, obj_type_page, pdf_action_id(p), false)); - } else { - pdf_add_name(pdf, "D"); - pdf_begin_array(pdf); - pdf_print_int(pdf, pdf_action_id(p) - 1); - } - { - char *tokstr = tokenlist_to_cstring(pdf_action_tokens(p), true, NULL); - pdf_printf(pdf, " %s", tokstr); - pdf_end_array(pdf); - xfree(tokstr); - } - break; - case pdf_action_goto: - if (pdf_action_file(p) == null) { + case pdf_action_page: pdf_dict_add_name(pdf, "S", "GoTo"); - d = pdf_get_obj(pdf, obj_type_dest, pdf_action_id(p), pdf_action_named_id(p)); - } else - pdf_dict_add_name(pdf, "S", "GoToR"); - if (pdf_action_named_id(p) > 0) { - char *tokstr = tokenlist_to_cstring(pdf_action_id(p), true, NULL); - pdf_dict_add_string(pdf, "D", tokstr); - xfree(tokstr); - } else if (pdf_action_file(p) == null) { - pdf_dict_add_ref(pdf, "D", d); - } else { - normal_error("pdf backend","'goto' option cannot be used with both 'file' and 'num'"); - } - break; - case pdf_action_thread: - pdf_dict_add_name(pdf, "S", "Thread"); - if (pdf_action_file(p) == null) { - d = pdf_get_obj(pdf, obj_type_thread, pdf_action_id(p), pdf_action_named_id(p)); + if (pdf_action_file(p) == null) { + pdf_add_name(pdf, "D"); + pdf_begin_array(pdf); + pdf_add_ref(pdf, pdf_get_obj(pdf, obj_type_page, pdf_action_id(p), false)); + } else { + pdf_add_name(pdf, "D"); + pdf_begin_array(pdf); + pdf_print_int(pdf, pdf_action_id(p) - 1); + } + { + char *tokstr = tokenlist_to_cstring(pdf_action_tokens(p), true, NULL); + pdf_printf(pdf, " %s", tokstr); + pdf_end_array(pdf); + xfree(tokstr); + } + break; + case pdf_action_goto: + if (pdf_action_file(p) == null) { + pdf_dict_add_name(pdf, "S", "GoTo"); + d = pdf_get_obj(pdf, obj_type_dest, pdf_action_id(p), pdf_action_named_id(p)); + } else + pdf_dict_add_name(pdf, "S", "GoToR"); if (pdf_action_named_id(p) > 0) { char *tokstr = tokenlist_to_cstring(pdf_action_id(p), true, NULL); pdf_dict_add_string(pdf, "D", tokstr); @@ -169,10 +153,24 @@ void write_action(PDF pdf, halfword p) } else if (pdf_action_file(p) == null) { pdf_dict_add_ref(pdf, "D", d); } else { - pdf_dict_add_int(pdf, "D", pdf_action_id(p)); + normal_error("pdf backend","'goto' option cannot be used with both 'file' and 'num'"); } - } - break; + break; + case pdf_action_thread: + pdf_dict_add_name(pdf, "S", "Thread"); + if (pdf_action_file(p) == null) { + d = pdf_get_obj(pdf, obj_type_thread, pdf_action_id(p), pdf_action_named_id(p)); + if (pdf_action_named_id(p) > 0) { + char *tokstr = tokenlist_to_cstring(pdf_action_id(p), true, NULL); + pdf_dict_add_string(pdf, "D", tokstr); + xfree(tokstr); + } else if (pdf_action_file(p) == null) { + pdf_dict_add_ref(pdf, "D", d); + } else { + pdf_dict_add_int(pdf, "D", pdf_action_id(p)); + } + } + break; } pdf_end_dict(pdf); } diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfannot.h b/Build/source/texk/web2c/luatexdir/pdf/pdfannot.h index 0b9ce5b9c12..2c862975db0 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfannot.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfannot.h @@ -15,7 +15,8 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ + with LuaTeX; if not, see . +*/ #ifndef PDFANNOT_H @@ -23,10 +24,10 @@ /* data structure of annotations; words 1..4 represent the coordinates of the annotation */ -# define obj_annot_ptr obj_aux /* pointer to corresponding whatsit node */ +# define obj_annot_ptr obj_aux /* pointer to corresponding whatsit node */ # define set_pdf_annot_objnum(A,B) pdf_annot_objnum(A)=B -# define set_pdf_annot_data(A,B) pdf_annot_data(A)=B +# define set_pdf_annot_data(A,B) pdf_annot_data(A)=B extern void do_annot(PDF pdf, halfword p, halfword parent_box, scaledpos cur); extern void new_annot_whatsit(small_number w); diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfannot.w b/Build/source/texk/web2c/luatexdir/pdf/pdfannot.w index 67bcc69a40c..6bbfec226e7 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfannot.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfannot.w @@ -19,18 +19,17 @@ @ @c - #include "ptexlib.h" @ @c -#define tail cur_list.tail_field +#define tail cur_list.tail_field void do_annot(PDF pdf, halfword p, halfword parent_box, scaledpos cur) { scaled_whd alt_rule; int k; if (global_shipping_mode == SHIPPING_FORM) - normal_error("pdf backend", "annotations cannot be inside an XForm"); + normal_error("pdf backend", "annotations cannot be inside an xform"); if (doing_leaders) return; if (is_obj_scheduled(pdf, pdf_annot_objnum(p))) { @@ -47,8 +46,8 @@ void do_annot(PDF pdf, halfword p, halfword parent_box, scaledpos cur) } @ create a new whatsit node for annotation -@c -void new_annot_whatsit(small_number w) + +@c void new_annot_whatsit(small_number w) { scaled_whd alt_rule; new_whatsit(w); @@ -58,7 +57,7 @@ void new_annot_whatsit(small_number w) set_depth(tail, alt_rule.dp); if ((w == pdf_thread_node) || (w == pdf_start_thread_node)) { if (scan_keyword("attr")) { - scan_pdf_ext_toks(); + scan_toks(false, true); set_pdf_thread_attr(tail, def_ref); } else { set_pdf_thread_attr(tail, null); @@ -66,8 +65,9 @@ void new_annot_whatsit(small_number w) } } -@ @c -void scan_annot(PDF pdf) +@ scanning at the \TeX\ end + +@c void scan_annot(PDF pdf) { int k; if (scan_keyword("reserveobjnum")) { @@ -89,7 +89,7 @@ void scan_annot(PDF pdf) new_annot_whatsit(pdf_annot_node); obj_annot_ptr(pdf, k) = tail; set_pdf_annot_objnum(tail, k); - scan_pdf_ext_toks(); + scan_toks(false, true); set_pdf_annot_data(tail, def_ref); } pdf_last_annot = k; diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfcolorstack.h b/Build/source/texk/web2c/luatexdir/pdf/pdfcolorstack.h index cab0a4cb0ae..dfd955c5e2c 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfcolorstack.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfcolorstack.h @@ -15,15 +15,16 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ + with LuaTeX; if not, see . +*/ #ifndef PDFCOLORSTACK_H # define PDFCOLORSTACK_H # define set_pdf_colorstack_stack(A,B) pdf_colorstack_stack(A)=B -# define set_pdf_colorstack_cmd(A,B) pdf_colorstack_cmd(A)=B -# define set_pdf_colorstack_data(A,B) pdf_colorstack_data(A)=B +# define set_pdf_colorstack_cmd(A,B) pdf_colorstack_cmd(A)=B +# define set_pdf_colorstack_data(A,B) pdf_colorstack_data(A)=B # define STACK_INCREMENT 8 diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfcolorstack.w b/Build/source/texk/web2c/luatexdir/pdf/pdfcolorstack.w index eb48ab89ca6..bcc7145c6ce 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfcolorstack.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfcolorstack.w @@ -19,36 +19,36 @@ @ @c - #include "ptexlib.h" @* Color Stack and Matrix Transformation Support. - @ In the following array and especially stack data structures are used. They have the following properties: - \item{-} They automatically grow dynamically. - \item{-} The size never decreases. - \item{-} The variable with name ending in "size" contains the number how many - entries the data structure can hold. - \item{-} The variable with name ending in "used" contains the number of - actually used entries. - \item{-} Memory of strings in stack entries must be allocated and - freed if the stack is cleared. - +\item{-} They automatically grow dynamically. +\item{-} The size never decreases. +\item{-} The variable with name ending in "size" contains the number how many + entries the data structure can hold. +\item{-} The variable with name ending in "used" contains the number of + actually used entries. +\item{-} Memory of strings in stack entries must be allocated and + freed if the stack is cleared. @ Color Stack @c + #define MAX_COLORSTACKS 32768 -/* The colorstack number is stored in two bytes (info field of the node) */ -/* Condition (newcolorstack): |MAX_COLORSTACKS mod STACK_INCREMENT = 0| */ + +/* + The colorstack number is stored in two bytes (info field of the node); + condition (newcolorstack): |MAX_COLORSTACKS mod STACK_INCREMENT = 0| +*/ #define COLOR_DEFAULT "0 g 0 G" -/* |literal_mode|s, see pdftex.web */ -#define SET_ORIGIN 0 -#define DIRECT_PAGE 1 +#define SET_ORIGIN 0 +#define DIRECT_PAGE 1 #define DIRECT_ALWAYS 2 typedef struct { @@ -69,9 +69,9 @@ static colstack_type *colstacks = NULL; static int colstacks_size = 0; static int colstacks_used = 0; -@ Initialization is done, if the color stacks are used, - |init_colorstacks()| is defined as macro to avoid unnecessary - procedure calls. +@ Initialization is done, if the color stacks are used, |init_colorstacks()| is defined +as macro to avoid unnecessary procedure calls. + @c #define init_colorstacks() if (colstacks_size == 0) colstacks_first_init(); @@ -100,27 +100,26 @@ int colorstackused(void) return colstacks_used; } -@ |newcolorstack()| - A new color stack is setup with the given parameters. - The stack number is returned or -1 in case of error (no room). +@ A new color stack is setup with the given parameters. The stack number is returned +or -1 in case of error (no room). + @c int newcolorstack(const char *str, int literal_mode, boolean page_start) { colstack_type *colstack; int colstack_num; - init_colorstacks(); - /* make room */ if (colstacks_used == MAX_COLORSTACKS) { return -1; } if (colstacks_used == colstacks_size) { colstacks_size += STACK_INCREMENT; - /* If |(MAX_COLORSTACKS mod STACK_INCREMENT = 0)| then we don't - need to check the case that size overruns |MAX_COLORSTACKS|. */ - colstacks = - xreallocarray(colstacks, colstack_type, (unsigned) colstacks_size); + /* + If |(MAX_COLORSTACKS mod STACK_INCREMENT = 0)| then we don't + need to check the case that size overruns |MAX_COLORSTACKS|. + */ + colstacks = xreallocarray(colstacks, colstack_type, (unsigned) colstacks_size); } /* claim new color stack */ colstack_num = colstacks_used++; @@ -149,8 +148,8 @@ int newcolorstack(const char *str, int literal_mode, boolean page_start) #define get_colstack(n) (&colstacks[n]) @ Puts a string on top of the string pool and updates |pool_ptr|. -@c -static void put_cstring_on_str_pool(char *str) + +@c static void put_cstring_on_str_pool(char *str) { int save_selector = selector; selector = new_string; @@ -197,8 +196,7 @@ static int colorstackpush(int colstack_no, str_number s) if (global_shipping_mode == SHIPPING_PAGE) { if (colstack->page_used == colstack->page_size) { colstack->page_size += STACK_INCREMENT; - xretalloc(colstack->page_stack, (unsigned) colstack->page_size, - char *); + xretalloc(colstack->page_stack, (unsigned) colstack->page_size, char *); } colstack->page_stack[colstack->page_used++] = colstack->page_current; str = makecstring(s); @@ -211,8 +209,7 @@ static int colorstackpush(int colstack_no, str_number s) } else { if (colstack->form_used == colstack->form_size) { colstack->form_size += STACK_INCREMENT; - xretalloc(colstack->form_stack, (unsigned) colstack->form_size, - char *); + xretalloc(colstack->form_stack, (unsigned) colstack->form_size, char *); } colstack->form_stack[colstack->form_used++] = colstack->form_current; str = makecstring(s); @@ -230,11 +227,9 @@ static int colorstackpush(int colstack_no, str_number s) int colorstackpop(int colstack_no) { colstack_type *colstack = get_colstack(colstack_no); - if (global_shipping_mode == SHIPPING_PAGE) { if (colstack->page_used == 0) { - luatex_warn("pop empty color page stack %u", - (unsigned int) colstack_no); + formatted_warning("pdf backend","pop empty color page stack %u",(unsigned int) colstack_no); return colstack->literal_mode; } xfree(colstack->page_current); @@ -242,8 +237,7 @@ int colorstackpop(int colstack_no) put_cstring_on_str_pool(colstack->page_current); } else { if (colstack->form_used == 0) { - luatex_warn("pop empty color form stack %u", - (unsigned int) colstack_no); + formatted_warning("pdf backend","pop empty color form stack %u",(unsigned int) colstack_no); return colstack->literal_mode; } xfree(colstack->form_current); @@ -258,7 +252,6 @@ void colorstackpagestart(void) { int i, j; colstack_type *colstack; - if (global_shipping_mode == SHIPPING_PAGE) { /* see procedure |pdf_out_colorstack_startpage| */ return; @@ -283,7 +276,6 @@ void colorstackpagestart(void) int colorstackskippagestart(int colstack_no) { colstack_type *colstack = get_colstack(colstack_no); - if (!colstack->page_start) { return 1; } @@ -302,12 +294,9 @@ void pdf_out_colorstack(PDF pdf, halfword p) { int old_setting; str_number s; - int cmd; - int stack_no; - int literal_mode; - cmd = pdf_colorstack_cmd(p); - stack_no = pdf_colorstack_stack(p); - literal_mode = 0; + int cmd = pdf_colorstack_cmd(p); + int stack_no = pdf_colorstack_stack(p); + int literal_mode = 0; if (stack_no >= colorstackused()) { tprint_nl(""); tprint("Color stack "); @@ -317,30 +306,30 @@ void pdf_out_colorstack(PDF pdf, halfword p) return; } switch (cmd) { - case colorstack_set: - case colorstack_push: - old_setting = selector; - selector = new_string; - show_token_list(token_link(pdf_colorstack_data(p)), null, -1); - selector = old_setting; - s = make_string(); - if (cmd == colorstack_set) - literal_mode = colorstackset(stack_no, s); - else - literal_mode = colorstackpush(stack_no, s); - if (str_length(s) > 0) - pdf_literal(pdf, s, literal_mode, false); - flush_str(s); - return; - break; - case colorstack_pop: - literal_mode = colorstackpop(stack_no); - break; - case colorstack_current: - literal_mode = colorstackcurrent(stack_no); - break; - default: - break; + case colorstack_set: + case colorstack_push: + old_setting = selector; + selector = new_string; + show_token_list(token_link(pdf_colorstack_data(p)), null, -1); + selector = old_setting; + s = make_string(); + if (cmd == colorstack_set) + literal_mode = colorstackset(stack_no, s); + else + literal_mode = colorstackpush(stack_no, s); + if (str_length(s) > 0) + pdf_literal(pdf, s, literal_mode, false); + flush_str(s); + return; + break; + case colorstack_pop: + literal_mode = colorstackpop(stack_no); + break; + case colorstack_current: + literal_mode = colorstackcurrent(stack_no); + break; + default: + break; } if (cur_length > 0) { s = make_string(); @@ -352,13 +341,11 @@ void pdf_out_colorstack(PDF pdf, halfword p) @ @c void pdf_out_colorstack_startpage(PDF pdf) { - int i; - int max; int start_status; int literal_mode; str_number s; - i = 0; - max = colorstackused(); + int i = 0; + int max = colorstackused(); while (i < max) { start_status = colorstackskippagestart(i); if (start_status == 0) { diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfdest.h b/Build/source/texk/web2c/luatexdir/pdf/pdfdest.h index 4c2f1911931..576baea0434 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfdest.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfdest.h @@ -15,7 +15,8 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ + with LuaTeX; if not, see . +*/ #ifndef PDFDEST_H @@ -24,17 +25,18 @@ /* types of destinations */ typedef enum { - pdf_dest_xyz = 0, - pdf_dest_fit = 1, - pdf_dest_fith = 2, - pdf_dest_fitv = 3, - pdf_dest_fitb = 4, + pdf_dest_xyz = 0, + pdf_dest_fit = 1, + pdf_dest_fith = 2, + pdf_dest_fitv = 3, + pdf_dest_fitb = 4, pdf_dest_fitbh = 5, pdf_dest_fitbv = 6, - pdf_dest_fitr = 7 + pdf_dest_fitr = 7 } pdf_destination_types; /* max number of kids for balanced trees */ + # define name_tree_kids_max 32 /* max number of kids of node of name tree for name destinations */ /* data structure of destinations */ @@ -42,18 +44,16 @@ typedef enum { # define obj_dest_ptr obj_aux /* pointer to |pdf_dest_node| */ # define set_obj_dest_ptr(pdf,A,B) obj_dest_ptr(pdf,A)=B -# define set_pdf_dest_id(A,B) pdf_dest_id(A)=B +# define set_pdf_dest_id(A,B) pdf_dest_id(A)=B # define set_pdf_dest_named_id(A,B) pdf_dest_named_id(A)=B -# define set_pdf_dest_type(A,B) pdf_dest_type(A)=B +# define set_pdf_dest_type(A,B) pdf_dest_type(A)=B # define set_pdf_dest_xyz_zoom(A,B) pdf_dest_xyz_zoom(A)=B -# define inf_dest_names_size 1000 /* min size of the destination names table for PDF output */ -# define sup_dest_names_size 131072 /* max size of the destination names table for PDF output */ +# define inf_dest_names_size 1000 /* min size of the destination names table for PDF output */ +# define sup_dest_names_size 131072 /* max size of the destination names table for PDF output */ extern void append_dest_name(PDF, char *, int); extern void do_dest(PDF pdf, halfword p, halfword parent_box, scaledpos cur); -extern void warn_dest_dup(int id, small_number byname, const char *s1, - const char *s2); extern void write_out_pdf_mark_destinations(PDF); extern void scan_pdfdest(PDF); @@ -61,5 +61,4 @@ extern void init_dest_names(PDF); extern void sort_dest_names(PDF); extern int output_name_tree(PDF); - #endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfdest.w b/Build/source/texk/web2c/luatexdir/pdf/pdfdest.w index 7aefc45288f..74e8e4b1f13 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfdest.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfdest.w @@ -19,18 +19,16 @@ @ @c - #include "ptexlib.h" -@ Here we implement subroutines for work with objects and related things. -Some of them are used in former parts too, so we need to declare them -forward. +@ Here we implement subroutines for work with objects and related things. Some of +them are used in former parts too, so we need to declare them forward. @c void init_dest_names(PDF pdf) { pdf->dest_names_size = inf_dest_names_size; - pdf->dest_names = xmallocarray(dest_name_entry, inf_dest_names_size); /* will grow dynamically */ + pdf->dest_names = xmallocarray(dest_name_entry, inf_dest_names_size); /* will grow dynamically */ } @ @c @@ -38,45 +36,35 @@ void append_dest_name(PDF pdf, char *s, int n) { int a; if (pdf->dest_names_ptr == sup_dest_names_size) - overflow("number of destination names (dest_names_size)", - (unsigned) pdf->dest_names_size); + overflow("number of destination names (dest_names_size)",(unsigned) pdf->dest_names_size); if (pdf->dest_names_ptr == pdf->dest_names_size) { a = pdf->dest_names_size / 5; if (pdf->dest_names_size < sup_dest_names_size - a) pdf->dest_names_size = pdf->dest_names_size + a; else pdf->dest_names_size = sup_dest_names_size; - pdf->dest_names = - xreallocarray(pdf->dest_names, dest_name_entry, - (unsigned) pdf->dest_names_size); + pdf->dest_names = xreallocarray(pdf->dest_names, dest_name_entry, (unsigned) pdf->dest_names_size); } pdf->dest_names[pdf->dest_names_ptr].objname = xstrdup(s); pdf->dest_names[pdf->dest_names_ptr].objnum = n; pdf->dest_names_ptr++; } - @ When a destination is created we need to check whether another destination with the same identifier already exists and give a warning if needed. @c -void warn_dest_dup(int id, small_number byname, const char *s1, const char *s2) +static void warn_dest_dup(int id, small_number byname) { - normal_warning(s1, "destination with the same identifier (", false, false); if (byname > 0) { - tprint("name"); - print_mark(id); + char *ss = tokenlist_to_cstring(id, true, NULL); + formatted_warning("pdf backend", "ignoring duplicate destination with the name '%s'",ss); } else { - tprint("num"); - print_int(id); + formatted_warning("pdf backend", "ignoring duplicate destination with the num '%d'",id); } - tprint(") "); - tprint(s2); - print_ln(); - show_context(); + /* no longer the annoying context */ } - @ @c void do_dest(PDF pdf, halfword p, halfword parent_box, scaledpos cur) { @@ -84,13 +72,12 @@ void do_dest(PDF pdf, halfword p, halfword parent_box, scaledpos cur) scaled_whd alt_rule; int k; if (global_shipping_mode == SHIPPING_FORM) - normal_error("pdf backend", "destinations cannot be inside an XForm"); + normal_error("pdf backend", "destinations cannot be inside an xform"); if (doing_leaders) return; k = pdf_get_obj(pdf, obj_type_dest, pdf_dest_id(p), pdf_dest_named_id(p)); if (obj_dest_ptr(pdf, k) != null) { - warn_dest_dup(pdf_dest_id(p), (small_number) pdf_dest_named_id(p), - "pdf backend", "has been already used, duplicate ignored"); + warn_dest_dup(pdf_dest_id(p), (small_number) pdf_dest_named_id(p)); return; } obj_dest_ptr(pdf, k) = p; @@ -149,50 +136,50 @@ void write_out_pdf_mark_destinations(PDF pdf) pdf_begin_array(pdf); pdf_add_ref(pdf, pdf->last_page); switch (pdf_dest_type(i)) { - case pdf_dest_xyz: - pdf_add_name(pdf, "XYZ"); - pdf_add_mag_bp(pdf, pdf_ann_left(i)); - pdf_add_mag_bp(pdf, pdf_ann_top(i)); - if (pdf_dest_xyz_zoom(i) == null) { - pdf_add_null(pdf); - } else { - if (pdf->cave == 1) - pdf_out(pdf, ' '); - pdf_print_int(pdf, pdf_dest_xyz_zoom(i) / 1000); - pdf_out(pdf, '.'); - pdf_print_int(pdf, (pdf_dest_xyz_zoom(i) % 1000)); - pdf->cave = 1; - } - break; - case pdf_dest_fit: - pdf_add_name(pdf, "Fit"); - break; - case pdf_dest_fith: - pdf_add_name(pdf, "FitH"); - pdf_add_mag_bp(pdf, pdf_ann_top(i)); - break; - case pdf_dest_fitv: - pdf_add_name(pdf, "FitV"); - pdf_add_mag_bp(pdf, pdf_ann_left(i)); - break; - case pdf_dest_fitb: - pdf_add_name(pdf, "FitB"); - break; - case pdf_dest_fitbh: - pdf_add_name(pdf, "FitBH"); - pdf_add_mag_bp(pdf, pdf_ann_top(i)); - break; - case pdf_dest_fitbv: - pdf_add_name(pdf, "FitBV"); - pdf_add_mag_bp(pdf, pdf_ann_left(i)); - break; - case pdf_dest_fitr: - pdf_add_name(pdf, "FitR"); - pdf_add_rect_spec(pdf, i); - break; - default: - normal_error("pdf backend", "unknown dest type"); - break; + case pdf_dest_xyz: + pdf_add_name(pdf, "XYZ"); + pdf_add_bp(pdf, pdf_ann_left(i)); + pdf_add_bp(pdf, pdf_ann_top(i)); + if (pdf_dest_xyz_zoom(i) == null) { + pdf_add_null(pdf); + } else { + if (pdf->cave == 1) + pdf_out(pdf, ' '); + pdf_print_int(pdf, pdf_dest_xyz_zoom(i) / 1000); + pdf_out(pdf, '.'); + pdf_print_int(pdf, (pdf_dest_xyz_zoom(i) % 1000)); + pdf->cave = 1; + } + break; + case pdf_dest_fit: + pdf_add_name(pdf, "Fit"); + break; + case pdf_dest_fith: + pdf_add_name(pdf, "FitH"); + pdf_add_bp(pdf, pdf_ann_top(i)); + break; + case pdf_dest_fitv: + pdf_add_name(pdf, "FitV"); + pdf_add_bp(pdf, pdf_ann_left(i)); + break; + case pdf_dest_fitb: + pdf_add_name(pdf, "FitB"); + break; + case pdf_dest_fitbh: + pdf_add_name(pdf, "FitBH"); + pdf_add_bp(pdf, pdf_ann_top(i)); + break; + case pdf_dest_fitbv: + pdf_add_name(pdf, "FitBV"); + pdf_add_bp(pdf, pdf_ann_left(i)); + break; + case pdf_dest_fitr: + pdf_add_name(pdf, "FitR"); + pdf_add_rect_spec(pdf, i); + break; + default: + normal_error("pdf backend", "unknown dest type"); + break; } pdf_end_array(pdf); if (pdf_dest_named_id(i) > 0) @@ -222,7 +209,7 @@ void scan_pdfdest(PDF pdf) set_pdf_dest_id(cur_list.tail_field, cur_val); set_pdf_dest_named_id(cur_list.tail_field, 0); } else if (scan_keyword("name")) { - scan_pdf_ext_toks(); + scan_toks(false, true); set_pdf_dest_id(cur_list.tail_field, def_ref); set_pdf_dest_named_id(cur_list.tail_field, 1); } else { @@ -271,13 +258,10 @@ void scan_pdfdest(PDF pdf) k = find_obj(pdf, obj_type_dest, i, true); flush_str(i); } else { - k = find_obj(pdf, obj_type_dest, pdf_dest_id(cur_list.tail_field), - false); + k = find_obj(pdf, obj_type_dest, pdf_dest_id(cur_list.tail_field), false); } if ((k != 0) && (obj_dest_ptr(pdf, k) != null)) { - warn_dest_dup(pdf_dest_id(cur_list.tail_field), - (small_number) pdf_dest_named_id(cur_list.tail_field), - "pdf backend", "has been already used, duplicate ignored"); + warn_dest_dup(pdf_dest_id(cur_list.tail_field),(small_number) pdf_dest_named_id(cur_list.tail_field)); flush_node_list(cur_list.tail_field); cur_list.tail_field = q; vlink(q) = null; @@ -296,8 +280,7 @@ static int dest_cmp(const void *a, const void *b) @ @c void sort_dest_names(PDF pdf) { - qsort(pdf->dest_names, (size_t) pdf->dest_names_ptr, - sizeof(dest_name_entry), dest_cmp); + qsort(pdf->dest_names, (size_t) pdf->dest_names_ptr, sizeof(dest_name_entry), dest_cmp); } @ Output the name tree. The tree nature of the destination list forces the @@ -309,18 +292,18 @@ pointers. int output_name_tree(PDF pdf) { boolean is_names = true; /* flag for name tree output: is it Names or Kids? */ - int b = 0, j, l; int k = 0; /* index of current child of |l|; if |k < pdf_dest_names_ptr| then this is pointer to |dest_names| array; otherwise it is the pointer to |obj_tab| (object number) */ - int m; + int b = 0; + int m, j, l; int dests = 0; - int names_head = 0, names_tail = 0; + int names_head = 0; + int names_tail = 0; if (pdf->dest_names_ptr == 0) { goto DONE; } sort_dest_names(pdf); - while (true) { do { l = pdf_create_obj(pdf, obj_type_others, 0); /* create a new node */ @@ -385,7 +368,6 @@ int output_name_tree(PDF pdf) goto DONE; } } - DONE: if ((dests != 0) || (pdf_names_toks != null)) { m = pdf_create_obj(pdf, obj_type_others, 0); diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdffont.h b/Build/source/texk/web2c/luatexdir/pdf/pdffont.h index 78726a0aa9e..47f987dd685 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdffont.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdffont.h @@ -15,7 +15,8 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ + with LuaTeX; if not, see . +*/ #ifndef PDFFONT_H diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdffont.w b/Build/source/texk/web2c/luatexdir/pdf/pdffont.w index 4a7319db8a3..b3f1605154c 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdffont.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdffont.w @@ -21,7 +21,6 @@ @ @c - #include "ptexlib.h" @ As \pdfTeX{} should also act as a back-end driver, it needs to support virtual @@ -37,38 +36,38 @@ The |has_packet()| C macro checks for this condition. @c scaled_whd output_one_char(PDF pdf, halfword p) { - scaled_whd ci; /* the real width, height and depth of the character */ internal_font_number f = font(p); int c = character(p); int ex_glyph = ex_glyph(p)/1000; - ci = get_charinfo_whd(f, c); + scaled_whd ci = get_charinfo_whd(f, c); /* the real width, height and depth of the character */ if (!(char_exists(f,c))) { char_warning(f,c); return ci; } - //ci.wd = round_xn_over_d(ci.wd, 1000 + ex_glyph, 1000); ci.wd = ext_xn_over_d(ci.wd, 1000000 + ex_glyph(p), 1000000); switch (pdf->posstruct->dir) { - case dir_TLT: - break; - case dir_TRT: - pos_left(ci.wd); - break; - case dir_LTL: - pos_down(ci.ht); - pos_left(ci.wd); - break; - case dir_RTT: - pos_down(ci.ht); - pos_left(ci.wd / 2); - break; - default: - assert(0); + case dir_TLT: + break; + case dir_TRT: + pos_left(ci.wd); + break; + case dir_LTL: + pos_down(ci.ht); + pos_left(ci.wd); + break; + case dir_RTT: + pos_down(ci.ht); + pos_left(ci.wd / 2); + break; + default: + formatted_warning("pdf backend","ignoring bad dir %i when outputting a character",pdf->posstruct->dir); } if (has_packet(f, c)) { do_vf_packet(pdf, f, c, ex_glyph); - } else - backend_out[glyph_node] (pdf, f, c, ex_glyph); /* |pdf_place_glyph(pdf, f, c, ex_glyph);| */ + } else { + /* |pdf_place_glyph(pdf, f, c, ex_glyph);| */ + backend_out[glyph_node] (pdf, f, c, ex_glyph); + } return ci; } @@ -77,72 +76,59 @@ scaled_whd output_one_char(PDF pdf, halfword p) static void pdf_use_font(internal_font_number f, int fontnum) { set_font_used(f, true); - assert((fontnum > 0) || ((fontnum < 0) && (pdf_font_num(-fontnum) > 0))); - set_pdf_font_num(f, fontnum); + if ((fontnum > 0) || ((fontnum < 0) && (pdf_font_num(-fontnum) > 0))) { + set_pdf_font_num(f, fontnum); + } else { + normal_error("pdf backend","bad font id"); + } } -@ To set PDF font we need to find out fonts with the same name, because \TeX\ -can load the same font several times for various sizes. For such fonts we -define only one font resource. The array |pdf_font_num| holds the object -number of font resource. A negative value of an entry of |pdf_font_num| -indicates that the corresponding font shares the font resource with the font +@ To set PDF font we need to find out fonts with the same name, because \TeX\ can +load the same font several times for various sizes. For such fonts we define only +one font resource. The array |pdf_font_num| holds the object number of font +resource. A negative value of an entry of |pdf_font_num| indicates that the +corresponding font shares the font resource with the font @c #define same(n,f,k) (n(f) != NULL && n(k) != NULL && strcmp(n(f), n(k)) == 0) +/* + For some lua-loaded (for instance AFM) fonts, it is normal to have + a zero cidregistry, and such fonts do not have a fontmap entry yet + at this point, so the test should use the other branch +*/ + static boolean font_shareable(internal_font_number f, internal_font_number k) { - int ret = 0; - /* For some lua-loaded (for instance AFM) fonts, it is normal to have - a zero cidregistry, and such fonts do not have a fontmap entry yet - at this point, so the test should use the other branch */ - if (font_cidregistry(f) == NULL && font_cidregistry(k) == NULL && - font_encodingbytes(f) != 2 && font_encodingbytes(k) != 2) { - if (font_map(k) != NULL && - font_map(f) != NULL && (same(font_name, k, f))) { - ret = 1; + if (font_cidregistry(f) == NULL && font_cidregistry(k) == NULL && font_encodingbytes(f) != 2 && font_encodingbytes(k) != 2) { + if (font_map(k) != NULL && font_map(f) != NULL && (same(font_name, k, f))) { + return 1; } - } else { - if ((same(font_filename, k, f) && same(font_fullname, k, f))) { - ret = 1; - } -#ifdef DEBUG - printf("\nfont_shareable(%d:%s:%s,%d:%s:%s): => %d\n", - f, font_filename(f), font_fullname(f), - k, font_filename(k), font_fullname(k), ret); -#endif + } else if ((same(font_filename, k, f) && same(font_fullname, k, f))) { + return 1; } - return ret; + return 0; } @ create a font object @c void pdf_init_font(PDF pdf, internal_font_number f) { - internal_font_number k/*, b*/; + internal_font_number k; fm_entry *fm; int i, l; - assert(!font_used(f)); - - ///* if |f| is auto expanded then ensure the base font is initialized */ - // - // if (font_auto_expand(f) && ((b = pdf_font_blink(f)) != null_font)) { - // if (!font_used(b)) - // pdf_init_font(pdf, b); - // set_font_map(f, font_map(b)); - // /* propagate slant and extend from unexpanded base font */ - // set_font_slant(f, font_slant(b)); - // set_font_extend(f, font_extend(b)); - //} - /* check whether |f| can share the font object with some |k|: we have 2 cases - here: 1) |f| and |k| have the same tfm name (so they have been loaded at - different sizes, eg 'cmr10' and 'cmr10 at 11pt'); 2) |f| has been auto - expanded from |k| - */ - - /* take over slant and extend from map entry, if not already set; - this should also be the only place where getfontmap() may be called. */ - + if (font_used(f)) { + formatted_error("pdf backend","font %i gets initialized twice",(int) f); + } + /* + check whether |f| can share the font object with some |k|: we have 2 cases + here: 1) |f| and |k| have the same tfm name (so they have been loaded at + different sizes, eg 'cmr10' and 'cmr10 at 11pt'); 2) |f| has been auto + expanded from |k| + + take over slant and extend from map entry, if not already set; + this should also be the only place where getfontmap() may be called. + */ fm = getfontmap(font_name(f)); if (font_map(f) == NULL && fm != NULL) { font_map(f) = fm; @@ -155,7 +141,6 @@ void pdf_init_font(PDF pdf, internal_font_number f) while (i != 0) { k = obj_info(pdf, i); if (font_shareable(f, k)) { - assert(pdf_font_num(k) != 0); if (pdf_font_num(k) < 0) pdf_use_font(f, pdf_font_num(k)); else @@ -169,20 +154,18 @@ void pdf_init_font(PDF pdf, internal_font_number f) pdf_use_font(f, l); } -@ set the actual font on PDF page +@ set the actual font on PDF page; sets |ff| to the tfm number of the base font +sharing the font object with |f|; |ff| is either |f| itself (then it is its own +base font), or some font with the same tfm name at different size and/or +expansion. + @c internal_font_number pdf_set_font(PDF pdf, internal_font_number f) { - int ff; /* for use with |set_ff| */ + int ff; /* for use with |set_ff| */ if (!font_used(f)) pdf_init_font(pdf, f); - /* - set |ff| to the tfm number of the base font sharing the font object with |f|; - |ff| is either |f| itself (then it is its own base font), - or some font with the same tfm name at different size and/or expansion. - */ - ff = pdf_font_num(f) < 0 ? -pdf_font_num(f) : f; /* aka |set_ff(f)| */ - assert(pdf_font_num(ff) > 0); /* base font object number */ + ff = pdf_font_num(f) < 0 ? -pdf_font_num(f) : f; /* aka |set_ff(f)| */ addto_page_resources(pdf, obj_type_font, pdf_font_num(ff)); return ff; } @@ -191,7 +174,7 @@ internal_font_number pdf_set_font(PDF pdf, internal_font_number f) void pdf_include_chars(PDF pdf) { str_number s; - unsigned char *k, *j; /* running index */ + unsigned char *k, *j; /* running index */ internal_font_number f; scan_font_ident(); f = cur_val; @@ -200,7 +183,7 @@ void pdf_include_chars(PDF pdf) pdf_check_vf(cur_val); if (!font_used(f)) pdf_init_font(pdf, f); - scan_pdf_ext_toks(); + scan_toks(false, true); s = tokens_to_string(def_ref); delete_token_ref(def_ref); j = str_string(s) + str_length(s); diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfgen.h b/Build/source/texk/web2c/luatexdir/pdf/pdfgen.h index d0677c1748f..0a8e099b177 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfgen.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfgen.h @@ -15,8 +15,8 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ - + with LuaTeX; if not, see . +*/ #ifndef PDFGEN_H # define PDFGEN_H @@ -27,46 +27,49 @@ # define PROCSET_IMAGE_C (1 << 3) # define PROCSET_IMAGE_I (1 << 4) -# define inf_pdf_mem_size 10000/* min size of the |mem| array */ -# define sup_pdf_mem_size 10000000 /* max size of the |mem| array */ +# define inf_pdf_mem_size 10000 /* min size of the |mem| array */ +# define sup_pdf_mem_size 10000000 /* max size of the |mem| array */ extern PDF static_pdf; extern int pdf_get_mem(PDF pdf, int s); /* -We use the similiar subroutines to handle the output buffer for -PDF output. When compress is used, the state of writing to buffer -is held in |zip_write_state|. We must write the header of PDF -output file in initialization to ensure that it will be the first -written bytes. + +We use the similiar subroutines to handle the output buffer for PDF output. When +compress is used, the state of writing to buffer is held in |zip_write_state|. We +must write the header of PDF output file in initialization to ensure that it will +be the first written bytes. + */ -# define inf_pdfout_buf_size 16384 /* initial value of |pdf->buf| size */ -# define sup_pdfout_buf_size 16384 /* arbitrary upper hard limit of |pdf->buf| size */ -# define inf_objstm_buf_size 1 /* initial value of |os->buf[OBJSTM_BUF]| size */ -# define sup_objstm_buf_size 5000000 /* arbitrary upper hard limit of |os->buf[OBJSTM_BUF]| size */ +# define inf_pdfout_buf_size 16384 /* initial value of |pdf->buf| size */ +# define sup_pdfout_buf_size 16384 /* arbitrary upper hard limit of |pdf->buf| size */ +# define inf_objstm_buf_size 1 /* initial value of |os->buf[OBJSTM_BUF]| size */ +# define sup_objstm_buf_size 5000000 /* arbitrary upper hard limit of |os->buf[OBJSTM_BUF]| size */ -# define PDF_OS_MAX_OBJS 100 /* maximum number of objects in object stream */ +# define PDF_OS_MAX_OBJS 100 /* maximum number of objects in object stream */ -# define inf_obj_tab_size 1000 /* min size of the cross-reference table for PDF output */ -# define sup_obj_tab_size 8388607 /* max size of the cross-reference table for PDF output */ +# define inf_obj_tab_size 1000 /* min size of the cross-reference table for PDF output */ +# define sup_obj_tab_size 8388607 /* max size of the cross-reference table for PDF output */ /* The following macros are similar as for \.{DVI} buffer handling */ # define pdf_offset(pdf) (pdf->gone + (off_t)(pdf->buf->p - pdf->buf->data)) - /* the file offset of last byte in PDF - buffer that |pdf_ptr| points to */ # define pdf_save_offset(pdf) pdf->save_offset = (pdf->gone + (off_t)(pdf->buf->p - pdf->buf->data)) -# define set_ff(A) do { \ - if (pdf_font_num(A) < 0) \ - ff = -pdf_font_num(A); \ - else \ - ff = A; \ - } while (0) +# define set_ff(A) do { \ + if (pdf_font_num(A) < 0) \ + ff = -pdf_font_num(A); \ + else \ + ff = A; \ +} while (0) -typedef enum { NOT_SHIPPING, SHIPPING_PAGE, SHIPPING_FORM } shipping_mode_e; /* needs pdf_prefix */ +typedef enum { /* needs pdf_prefix */ + NOT_SHIPPING, + SHIPPING_PAGE, + SHIPPING_FORM +} shipping_mode_e; extern scaled one_hundred_inch; extern scaled one_inch; @@ -80,29 +83,36 @@ extern void pdf_room(PDF, int); extern void fix_pdf_minorversion(PDF); - /* output a byte to PDF buffer without checking of overflow */ +/* output a byte to PDF buffer without checking of overflow */ + # define pdf_quick_out(pdf,A) * (pdf->buf->p++) = (unsigned char) (A) /* do the same as |pdf_quick_out| and flush the PDF buffer if necessary */ -# define pdf_out(pdf,A) do { pdf_room(pdf, 1); pdf_quick_out(pdf, A); } while (0) + +# define pdf_out(pdf,A) do { \ + pdf_room(pdf, 1); \ + pdf_quick_out(pdf, A); \ +} while (0) /* + Basic printing procedures for PDF output are very similiar to \TeX\ basic -printing ones but the output is going to PDF buffer. Subroutines with -suffix |_ln| append a new-line character to the PDF output. +printing ones but the output is going to PDF buffer. Subroutines with suffix +|_ln| append a new-line character to the PDF output. + */ -/* print out a string to PDF buffer followed by a new-line character */ -# define pdf_print_ln(pdf,A) do { \ - pdf_print(pdf,A); \ - pdf_out(pdf, '\n'); \ - } while (0) +# define pdf_print_ln(pdf,A) do { \ + pdf_print(pdf,A); \ + pdf_out(pdf, '\n'); \ +} while (0) /* print out an integer to PDF buffer followed by a new-line character */ -# define pdf_print_int_ln(pdf,A) do { \ - pdf_print_int(pdf,A); \ - pdf_out(pdf, '\n'); \ - } while (0) + +# define pdf_print_int_ln(pdf,A) do { \ + pdf_print_int(pdf,A); \ + pdf_out(pdf, '\n'); \ +} while (0) extern __attribute__ ((format(printf, 2, 3))) void pdf_printf(PDF, const char *, ...); @@ -131,7 +141,6 @@ extern void pdf_begin_stream(PDF); extern void pdf_end_stream(PDF); extern void pdf_add_bp(PDF, scaled); -extern void pdf_add_mag_bp(PDF, scaled); extern strbuf_s *new_strbuf(size_t size, size_t limit); extern void strbuf_seek(strbuf_s * b, off_t offset); @@ -149,10 +158,10 @@ extern void pdf_out_block(PDF pdf, const char *s, size_t n); # define pdf_puts(pdf, s) pdf_out_block((pdf), (s), strlen(s)) -# define pdf_print_resname_prefix(pdf) do { \ - if (pdf->resname_prefix != NULL) \ - pdf_puts(pdf, pdf->resname_prefix); \ - } while (0) +# define pdf_print_resname_prefix(pdf) do { \ + if (pdf->resname_prefix != NULL) \ + pdf_puts(pdf, pdf->resname_prefix); \ +} while (0) extern void pdf_print_str_ln(PDF, const char *); @@ -195,15 +204,14 @@ extern int get_pdf_table_bool(PDF, const char *, int); extern void ensure_output_state(PDF pdf, output_state s); extern PDF init_pdf_struct(PDF pdf); -extern halfword pdf_info_toks; /* additional keys of Info dictionary */ +extern halfword pdf_info_toks; /* additional keys of Info dictionary */ extern halfword pdf_catalog_toks; /* additional keys of Catalog dictionary */ extern halfword pdf_catalog_openaction; -extern halfword pdf_names_toks; /* additional keys of Names dictionary */ +extern halfword pdf_names_toks; /* additional keys of Names dictionary */ extern halfword pdf_trailer_toks; /* additional keys of Trailer dictionary */ extern void scan_pdfcatalog(PDF pdf); -extern void finish_pdf_file(PDF pdf, int luatex_version, - str_number luatex_revision); +extern void finish_pdf_file(PDF pdf, int luatex_version, str_number luatex_revision); extern shipping_mode_e global_shipping_mode; -#endif /* PDFGEN_H */ +#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfgen.w b/Build/source/texk/web2c/luatexdir/pdf/pdfgen.w index f9a96aac808..94bfbaddcbf 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfgen.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfgen.w @@ -30,11 +30,12 @@ #define check_nprintf(size_get, size_want) \ if ((unsigned)(size_get) >= (unsigned)(size_want)) \ - luatex_fail ("snprintf failed: file %s, line %d", __FILE__, __LINE__); + formatted_error("pdf backend","snprintf() failed in file %s at line %d", __FILE__, __LINE__); PDF static_pdf = NULL; @ commandline interface + @c int output_mode_used; int output_mode_option; @@ -42,12 +43,12 @@ int output_mode_value; int draft_mode_option; int draft_mode_value; -halfword pdf_info_toks; /* additional keys of Info dictionary */ -halfword pdf_catalog_toks; /* additional keys of Catalog dictionary */ +halfword pdf_info_toks; /* additional keys of Info dictionary */ +halfword pdf_catalog_toks; /* additional keys of Catalog dictionary */ halfword pdf_catalog_openaction; -halfword pdf_names_toks; /* additional keys of Names dictionary */ -halfword pdf_trailer_toks; /* additional keys of Trailer dictionary */ -shipping_mode_e global_shipping_mode = NOT_SHIPPING; /* set to |shipping_mode| when |ship_out| starts */ +halfword pdf_names_toks; /* additional keys of Names dictionary */ +halfword pdf_trailer_toks; /* additional keys of Trailer dictionary */ +shipping_mode_e global_shipping_mode = NOT_SHIPPING; /* set to |shipping_mode| when |ship_out| starts */ @ Create a new buffer |strbuf_s| of size |size| and maximum allowed size |limit|. Initialize it and set |p| to begin of data. @@ -56,14 +57,13 @@ Initialize it and set |p| to begin of data. strbuf_s *new_strbuf(size_t size, size_t limit) { strbuf_s *b; - assert(limit >= size); b = xtalloc(1, strbuf_s); b->size = size; b->limit = limit; if (size > 0) b->p = b->data = xtalloc(b->size, unsigned char); else - b->p = b->data = NULL; /* for other alloc */ + b->p = b->data = NULL; /* for other alloc */ return b; } @@ -94,7 +94,6 @@ static void strbuf_room(strbuf_s * b, size_t n) @c void strbuf_seek(strbuf_s * b, off_t offset) { - assert(offset >= 0 && offset < (off_t) b->size); b->p = b->data + offset; } @@ -140,12 +139,11 @@ void strbuf_free(strbuf_s * b) PDF init_pdf_struct(PDF pdf) { os_struct *os; - assert(pdf == NULL); pdf = xtalloc(1, pdf_output_file); memset(pdf, 0, sizeof(pdf_output_file)); pdf->job_name = makecstring(job_name); - output_mode_used = OMODE_NONE; /* will be set by |fix_o_mode()| */ + output_mode_used = OMODE_NONE; /* will be set by |fix_o_mode()| */ pdf->o_mode = output_mode_used; /* used by synctex, we need to use output_mode_used there */ pdf->o_state = ST_INITIAL; @@ -159,20 +157,27 @@ PDF init_pdf_struct(PDF pdf) os->curbuf = PDFOUT_BUF; pdf->buf = os->buf[os->curbuf]; - - /* Later ttf_seek_outbuf(TABDIR_OFF + n * 4 * TTF_ULONG_SIZE) */ - /* in ttf_init_font will need 236 bytes, so we start with 256 bytes as in pdftex. */ + /* + Later ttf_seek_outbuf(TABDIR_OFF + n * 4 * TTF_ULONG_SIZE); in ttf_init_font + we need 236 bytes, so we start with 256 bytes as in pdftex. + */ pdf->fb = new_strbuf(256, 100000000); pdf->stream_deflate = false; pdf->stream_writing = false; - /* Sometimes it is neccesary to allocate memory for PDF output that cannot - be deallocated then, so we use |mem| for this purpose. */ - pdf->mem_size = inf_pdf_mem_size; /* allocated size of |mem| array */ + /* + Sometimes it is neccesary to allocate memory for PDF output that cannot be + deallocated then, so we use |mem| for this purpose. + */ + pdf->mem_size = inf_pdf_mem_size; pdf->mem = xtalloc(pdf->mem_size, int); - pdf->mem_ptr = 1; /* the first word is not used so we can use zero as a value for testing - whether a pointer to |mem| is valid */ + /* + The first word is not used so we can use zero as a value for testing + whether a pointer to |mem| is valid. + */ + pdf->mem_ptr = 1; + pdf->pstruct = NULL; pdf->posstruct = xtalloc(1, posstructure); @@ -180,11 +185,12 @@ PDF init_pdf_struct(PDF pdf) pdf->posstruct->pos.v = 0; pdf->posstruct->dir = dir_TLT; - pdf->obj_tab_size = (unsigned) inf_obj_tab_size; /* allocated size of |obj_tab| array */ + /* allocated size of |obj_tab| array */ + pdf->obj_tab_size = (unsigned) inf_obj_tab_size; pdf->obj_tab = xtalloc(pdf->obj_tab_size + 1, obj_entry); memset(pdf->obj_tab, 0, sizeof(obj_entry)); - pdf->minor_version = -1; /* unset */ + pdf->minor_version = -1; pdf->decimal_digits = 4; pdf->gamma = 65536; pdf->image_gamma = 65536; @@ -194,7 +200,6 @@ PDF init_pdf_struct(PDF pdf) pdf->compress_level = 0; pdf->draftmode = 0; pdf->inclusion_copy_font = 1; - pdf->replace_font = 0; pdf->pk_resolution = 0; pdf->pk_scale_factor = 0; @@ -202,7 +207,6 @@ PDF init_pdf_struct(PDF pdf) pdf->page_resources = NULL; init_pdf_pagecalculations(pdf); - pdf->pdflua_ref = new_pdflua(); pdf->vfstruct = new_vfstruct(); @@ -213,11 +217,11 @@ PDF init_pdf_struct(PDF pdf) @c int pdf_get_mem(PDF pdf, int s) -{ /* allocate |s| words in |mem| */ +{ int a; int ret; if (s > sup_pdf_mem_size - pdf->mem_ptr) - overflow("PDF memory size (pdf_mem_size)", (unsigned) pdf->mem_size); + overflow("pdf memory size (pdf_mem_size)", (unsigned) pdf->mem_size); if (pdf->mem_ptr + s > pdf->mem_size) { a = pdf->mem_size >> 2; if (pdf->mem_ptr + s > pdf->mem_size + a) { @@ -258,10 +262,10 @@ void fix_o_mode(void) } } -@ This ensures that |pdfminorversion| is set only before any bytes have -been written to the generated \.{PDF} file. Here also all variables for -\.{PDF} output are initialized, the \.{PDF} file is opened by |ensure_pdf_open|, -and the \.{PDF} header is written. +@ This ensures that |pdfminorversion| is set only before any bytes have been +written to the generated \.{PDF} file. Here also all variables for \.{PDF} output +are initialized, the \.{PDF} file is opened by |ensure_pdf_open|, and the \.{PDF} +header is written. @c void fix_pdf_minorversion(PDF pdf) @@ -292,9 +296,9 @@ void fix_pdf_minorversion(PDF pdf) @ @c #define ZIP_BUF_SIZE 32768 -#define check_err(f, fn) \ - if (f != Z_OK) \ - luatex_fail("zlib: %s() failed (error code %d)", fn, f) +#define check_err(f, fn) \ + if (f != Z_OK) \ + formatted_error("pdf backend","zlib %s() failed (error code %d)", fn, f) @ @c static void write_zip(PDF pdf) @@ -304,15 +308,6 @@ static void write_zip(PDF pdf) strbuf_s *buf = pdf->buf; z_stream *s = pdf->c_stream; boolean finish = pdf->zip_write_state == ZIP_FINISH; - assert(pdf->compress_level > 0); - /* This was just to suppress the filename report in |luatex_fail| - but zlib errors are rare enough (especially now that the - compress level is fixed) that I don't care about the slightly - ugly error message that could result. - */ -#if 0 - cur_file_name = NULL; -#endif if (pdf->stream_length == 0) { if (s == NULL) { s = pdf->c_stream = xtalloc(1, z_stream); @@ -320,15 +315,12 @@ static void write_zip(PDF pdf) s->zfree = (free_func) 0; s->opaque = (voidpf) 0; check_err(deflateInit(s, pdf->compress_level), "deflateInit"); - assert(pdf->zipbuf == NULL); pdf->zipbuf = xtalloc(ZIP_BUF_SIZE, char); } else check_err(deflateReset(s), "deflateReset"); s->next_out = (Bytef *) pdf->zipbuf; s->avail_out = ZIP_BUF_SIZE; } - assert(s != NULL); - assert(pdf->zipbuf != NULL); s->next_in = buf->data; s->avail_in = (uInt) (buf->p - buf->data); while (true) { @@ -341,8 +333,6 @@ static void write_zip(PDF pdf) } if (finish) { if (err == Z_STREAM_END) { - assert(s->avail_in == 0); - assert(s->avail_out == ZIP_BUF_SIZE); xfflush(pdf->file); pdf->zip_write_state = NO_ZIP; break; @@ -355,7 +345,7 @@ static void write_zip(PDF pdf) } err = deflate(s, flush); if (err != Z_OK && err != Z_STREAM_END) - luatex_fail("zlib: deflate() failed (error code %d)", err); + formatted_error("pdf backend","zlib deflate() failed (error code %d)", err); } pdf->stream_length = (off_t) s->total_out; } @@ -378,8 +368,7 @@ static void write_nozip(PDF pdf) if (l == 0) return; pdf->stream_length = pdf_offset(pdf) - pdf->save_offset; - pdf->gone += - (off_t) xfwrite((char *) buf->data, sizeof(char), l, pdf->file); + pdf->gone += (off_t) xfwrite((char *) buf->data, sizeof(char), l, pdf->file); pdf->last_byte = *(buf->p - 1); } @@ -390,34 +379,33 @@ to finish it. The stream contents will be compressed if compression is turn on. @c void pdf_flush(PDF pdf) -{ /* flush out the |pdf->buf| */ +{ os_struct *os = pdf->os; off_t saved_pdf_gone = pdf->gone; - assert(pdf->buf == os->buf[os->curbuf]); switch (os->curbuf) { - case PDFOUT_BUF: - if (pdf->draftmode == 0) { - switch (pdf->zip_write_state) { - case NO_ZIP: - write_nozip(pdf); - break; - case ZIP_WRITING: - case ZIP_FINISH: - write_zip(pdf); - break; - default: - assert(0); - } - } else - pdf->zip_write_state = NO_ZIP; - strbuf_seek(pdf->buf, 0); - if (saved_pdf_gone > pdf->gone) - normal_error("pdf backend", "file size exceeds architectural limits (pdf_gone wraps around)"); - break; - case OBJSTM_BUF: - break; - default: - assert(0); + case PDFOUT_BUF: + if (pdf->draftmode == 0) { + switch (pdf->zip_write_state) { + case NO_ZIP: + write_nozip(pdf); + break; + case ZIP_WRITING: + case ZIP_FINISH: + write_zip(pdf); + break; + default: + normal_error("pdf backend", "bad zip state"); + } + } else + pdf->zip_write_state = NO_ZIP; + strbuf_seek(pdf->buf, 0); + if (saved_pdf_gone > pdf->gone) + normal_error("pdf backend", "file size exceeds architectural limits (pdf_gone wraps around)"); + break; + case OBJSTM_BUF: + break; + default: + normal_error("pdf backend", "bad buffer state"); } } @@ -426,9 +414,9 @@ static void pdf_buffer_select(PDF pdf, buffer_e buf) { os_struct *os = pdf->os; if (pdf->os_enable && buf == OBJSTM_BUF) - os->curbuf = OBJSTM_BUF; /* switch to object stream */ + os->curbuf = OBJSTM_BUF; /* switch to object stream */ else - os->curbuf = PDFOUT_BUF; /* switch to PDF stream */ + os->curbuf = PDFOUT_BUF; /* switch to PDF stream */ pdf->buf = os->buf[pdf->os->curbuf]; } @@ -439,64 +427,53 @@ static void pdf_prepare_obj(PDF pdf, int k, int pdf_os_threshold) { os_struct *os = pdf->os; strbuf_s *obuf = os->buf[OBJSTM_BUF]; - assert(pdf_os_threshold >= OBJSTM_ALWAYS); if (pdf->objcompresslevel >= pdf_os_threshold) pdf_buffer_select(pdf, OBJSTM_BUF); else pdf_buffer_select(pdf, PDFOUT_BUF); - assert(pdf->buf == os->buf[os->curbuf]); switch (os->curbuf) { - case PDFOUT_BUF: - obj_offset(pdf, k) = pdf_offset(pdf); - obj_os_idx(pdf, k) = PDF_OS_MAX_OBJS; /* mark it as not included in any ObjStm */ - break; - case OBJSTM_BUF: - if (os->cur_objstm == 0) { - os->cur_objstm = - (unsigned int) pdf_create_obj(pdf, obj_type_objstm, 0); - os->idx = 0; - obuf->p = obuf->data; /* start fresh object stream */ - os->ostm_ctr++; /* only for statistics */ - } - assert(os->idx < PDF_OS_MAX_OBJS); /* for marking below */ - obj_os_idx(pdf, k) = (int) os->idx; - obj_os_objnum(pdf, k) = (int) os->cur_objstm; - os->obj[os->idx].num = k; - os->obj[os->idx].off = obuf->p - obuf->data; - break; - default: - assert(0); + case PDFOUT_BUF: + obj_offset(pdf, k) = pdf_offset(pdf); + obj_os_idx(pdf, k) = PDF_OS_MAX_OBJS; /* mark it as not included in any ObjStm */ + break; + case OBJSTM_BUF: + if (os->cur_objstm == 0) { + os->cur_objstm = + (unsigned int) pdf_create_obj(pdf, obj_type_objstm, 0); + os->idx = 0; + obuf->p = obuf->data; /* start fresh object stream */ + os->ostm_ctr++; /* only for statistics */ + } + obj_os_idx(pdf, k) = (int) os->idx; + obj_os_objnum(pdf, k) = (int) os->cur_objstm; + os->obj[os->idx].num = k; + os->obj[os->idx].off = obuf->p - obuf->data; + break; + default: + normal_error("pdf backend", "bad object state"); } } @* Low-level buffer checkers. -@ Set the active buffer pointer. -Make sure that there are at least |n| bytes free in that buffer, -flush if needed. +@ Set the active buffer pointer. Make sure that there are at least |n| bytes free +in that buffer, flush if needed. @c -void pdf_room(PDF pdf, int n) +inline void pdf_room(PDF pdf, int n) { - os_struct *os = pdf->os; strbuf_s *buf = pdf->buf; if ((size_t) (n + buf->p - buf->data) <= buf->size) return; - assert(buf == os->buf[os->curbuf]); - switch (os->curbuf) { - case PDFOUT_BUF: + if (pdf->os->curbuf == PDFOUT_BUF) { if ((size_t) n > buf->size) overflow("PDF output buffer", (unsigned) buf->size); if ((size_t) (n + buf->p - buf->data) < buf->limit) - strbuf_room(buf, (size_t) n); /* grow it if possible */ + strbuf_room(buf, (size_t) n); else pdf_flush(pdf); - break; - case OBJSTM_BUF: - strbuf_room(buf, (size_t) n); /* just grow it */ - break; - default: - assert(0); + } else { + strbuf_room(buf, (size_t) n); } } @@ -543,7 +520,6 @@ void pdf_print(PDF pdf, str_number s) l = str_length(s); pdf_out_block(pdf, ss, l); } else { - assert(s < 256); pdf_out(pdf, s); } } @@ -564,7 +540,7 @@ void pdf_print_int(PDF pdf, longinteger n) void print_pdffloat(PDF pdf, pdffloat f) { char a[24]; - int e = f.e, i, j, l; + int e = f.e, i, l; int64_t m = f.m; if (m < 0) { pdf_out(pdf, '-'); @@ -575,8 +551,7 @@ void print_pdffloat(PDF pdf, pdffloat f) l = m % ten_pow[e]; if (l != 0) { pdf_out(pdf, '.'); - j = snprintf(a, 23, "%d", l + ten_pow[e]); - assert(j < 23); + snprintf(a, 23, "%d", l + ten_pow[e]); for (i = e; i > 0; i--) { if (a[i] != '0') break; @@ -592,7 +567,7 @@ void print_pdffloat(PDF pdf, pdffloat f) void pdf_print_str(PDF pdf, const char *s) { const char *orig = s; - int l = (int) strlen(s) - 1; /* last string index */ + int l = (int) strlen(s) - 1; /* last string index */ if (l < 0) { pdf_puts(pdf, "()"); return; @@ -617,7 +592,7 @@ void pdf_print_str(PDF pdf, const char *s) pdf_out(pdf, ')'); return; } - pdf_puts(pdf, orig); /* it was a hex string after all */ + pdf_puts(pdf, orig); /* it was a hex string after all */ } @ begin a stream (needs to have a stream dictionary also) @@ -625,15 +600,10 @@ void pdf_print_str(PDF pdf, const char *s) @c void pdf_begin_stream(PDF pdf) { - os_struct *os = pdf->os; - assert(os->curbuf == PDFOUT_BUF); - assert(pdf->buf == os->buf[os->curbuf]); - assert(pdf->zip_write_state == NO_ZIP); pdf_puts(pdf, "\nstream\n"); pdf_save_offset(pdf); pdf_flush(pdf); if (pdf->stream_deflate) { - assert(pdf->compress_level > 0); pdf->zip_write_state = ZIP_WRITING; } pdf->stream_writing = true; @@ -647,30 +617,25 @@ void pdf_begin_stream(PDF pdf) void pdf_end_stream(PDF pdf) { os_struct *os = pdf->os; - assert(pdf->buf == os->buf[os->curbuf]); switch (os->curbuf) { - case PDFOUT_BUF: - if (pdf->zip_write_state == ZIP_WRITING) - pdf->zip_write_state = ZIP_FINISH; - pdf_flush(pdf); /* sets pdf->last_byte */ - break; - case OBJSTM_BUF: - assert(0); - break; - default: - assert(0); - } - assert(pdf->zip_write_state == NO_ZIP); - assert(os->curbuf == PDFOUT_BUF); - assert(pdf->buf == os->buf[os->curbuf]); + case PDFOUT_BUF: + if (pdf->zip_write_state == ZIP_WRITING) + pdf->zip_write_state = ZIP_FINISH; + pdf_flush(pdf); /* sets pdf->last_byte */ + break; + case OBJSTM_BUF: + normal_error("pdf backend", "bad buffer in end stream, case 1"); + break; + default: + normal_error("pdf backend", "bad buffer in end stream, case 2"); + } pdf->stream_deflate = false; pdf->stream_writing = false; pdf_out(pdf, '\n'); /* doesn't really belong to the stream */ pdf_puts(pdf, "endstream"); /* write stream /Length */ if (pdf->seek_write_length && pdf->draftmode == 0) { - xfseeko(pdf->file, (off_t)pdf->stream_length_offset, SEEK_SET, - pdf->job_name); + xfseeko(pdf->file, (off_t)pdf->stream_length_offset, SEEK_SET, pdf->job_name); fprintf(pdf->file, "%" LONGINTEGER_PRI "i", (LONGINTEGER_TYPE) pdf->stream_length); xfseeko(pdf->file, 0, SEEK_END, pdf->job_name); } @@ -705,8 +670,8 @@ for optimizations that are not possible in pascal. @c scaled round_xn_over_d(scaled x, int n, unsigned int d) { - boolean positive = true; /* was |x>=0|, |n>=0| ? */ - unsigned t, u, v; /* intermediate quantities */ + boolean positive = true; + unsigned t, u, v; if (x < 0) { positive = !positive; x = -(x); @@ -733,10 +698,9 @@ scaled round_xn_over_d(scaled x, int n, unsigned int d) @ @c void pdf_add_bp(PDF pdf, scaled s) -{ /* print scaled as |bp| */ +{ pdffloat a; pdfstructure *p = pdf->pstruct; - assert(p != NULL); a.m = i64round(s * p->k1); a.e = pdf->decimal_digits; if (pdf->cave > 0) @@ -745,22 +709,6 @@ void pdf_add_bp(PDF pdf, scaled s) pdf->cave = 1; } -void pdf_add_mag_bp(PDF pdf, scaled s) -{ /* take |mag| into account */ - pdffloat a; - pdfstructure *p = pdf->pstruct; - prepare_mag(); - if (int_par(mag_code) != 1000) - a.m = i64round(s * (double) int_par(mag_code) / 1000.0 * p->k1); - else - a.m = i64round(s * p->k1); - a.e = pdf->decimal_digits; - if (pdf->cave > 0) - pdf_out(pdf, ' '); - print_pdffloat(pdf, a); - pdf->cave = 1; -} - @* handling page resources. @c @@ -772,10 +720,9 @@ typedef struct { @ @c static int comp_page_resources(const void *pa, const void *pb, void *p) { - int a, b; + int a = ((const pr_entry *) pa)->obj_type; + int b = ((const pr_entry *) pb)->obj_type; (void) p; - a = ((const pr_entry *) pa)->obj_type; - b = ((const pr_entry *) pb)->obj_type; if (a > b) return 1; if (a < b) @@ -790,16 +737,11 @@ void addto_page_resources(PDF pdf, pdf_obj_type t, int k) pr_entry *pr, tmp; void **pp; pdf_object_list *p, *item = NULL; - assert(pdf != NULL); re = pdf->page_resources; - assert(re != NULL); - assert(t <= PDF_OBJ_TYPE_MAX); if (re->resources_tree == NULL) { - re->resources_tree = - avl_create(comp_page_resources, NULL, &avl_xallocator); + re->resources_tree = avl_create(comp_page_resources, NULL, &avl_xallocator); if (re->resources_tree == NULL) - luatex_fail - ("addto_page_resources(): avl_create() page_resource_tree failed"); + formatted_error("pdf backend","addto_page_resources(): avl_create() page_resource_tree failed"); } tmp.obj_type = t; pr = (pr_entry *) avl_find(re->resources_tree, &tmp); @@ -809,8 +751,7 @@ void addto_page_resources(PDF pdf, pdf_obj_type t, int k) pr->list = NULL; pp = avl_probe(re->resources_tree, pr); if (pp == NULL) - luatex_fail - ("addto_page_resources(): avl_probe() out of memory in insertion"); + formatted_error("pdf backend","addto_page_resources(): avl_probe() out of memory in insertion"); } if (pr->list == NULL) { item = xtalloc(1, pdf_object_list); @@ -949,10 +890,10 @@ void pdf_print_toks(PDF pdf, halfword p) @c void pdf_add_rect_spec(PDF pdf, halfword r) { - pdf_add_mag_bp(pdf, pdf_ann_left(r)); - pdf_add_mag_bp(pdf, pdf_ann_bottom(r)); - pdf_add_mag_bp(pdf, pdf_ann_right(r)); - pdf_add_mag_bp(pdf, pdf_ann_top(r)); + pdf_add_bp(pdf, pdf_ann_left(r)); + pdf_add_bp(pdf, pdf_ann_bottom(r)); + pdf_add_bp(pdf, pdf_ann_right(r)); + pdf_add_bp(pdf, pdf_ann_top(r)); } @ output a rectangle specification to PDF file @@ -960,7 +901,6 @@ void pdf_add_rect_spec(PDF pdf, halfword r) @c void pdf_rectangle(PDF pdf, halfword r) { - prepare_mag(); pdf_add_name(pdf, "Rect"); pdf_begin_array(pdf); pdf_add_rect_spec(pdf, r); @@ -971,7 +911,6 @@ void pdf_rectangle(PDF pdf, halfword r) static void init_pdf_outputparameters(PDF pdf) { int pk_mode; - assert(output_mode_used == OMODE_PDF); pdf->draftmode = fix_int(int_par(draft_mode_code), 0, 1); pdf->compress_level = fix_int(pdf_compress_level, 0, 9); pdf->decimal_digits = fix_int(pdf_decimal_digits, 0, 4); @@ -981,21 +920,19 @@ static void init_pdf_outputparameters(PDF pdf) pdf->image_apply_gamma = fix_int(pdf_image_apply_gamma, 0, 1); pdf->objcompresslevel = fix_int(pdf_objcompresslevel, 0, MAX_OBJ_COMPRESS_LEVEL); pdf->inclusion_copy_font = fix_int(pdf_inclusion_copy_font, 0, 1); - pdf->replace_font = fix_int(pdf_replace_font, 0, 1); pdf->pk_resolution = fix_int(pdf_pk_resolution, 72, 8000); if ((pdf->minor_version >= 5) && (pdf->objcompresslevel > 0)) { pdf->os_enable = true; } else { if (pdf->objcompresslevel > 0) { - normal_warning("pdf backend","objcompresslevel > 0 requires minorversion > 4", true, true); + normal_warning("pdf backend","objcompresslevel > 0 requires minorversion > 4"); pdf->objcompresslevel = 0; } pdf->os_enable = false; } if (pdf->pk_resolution == 0) /* if not set from format file or by user */ pdf->pk_resolution = pk_dpi; /* take it from \.{texmf.cnf} */ - pdf->pk_scale_factor = - divide_scaled(72, pdf->pk_resolution, 5 + pdf->decimal_digits); + pdf->pk_scale_factor = divide_scaled(72, pdf->pk_resolution, 5 + pdf->decimal_digits); if (!callback_defined(read_pk_file_callback)) { pk_mode = pdf_pk_mode; /* lookup once */ if (pk_mode != null) { @@ -1008,8 +945,7 @@ static void init_pdf_outputparameters(PDF pdf) if (!kpse_var_value("MKTEXPK")) kpse_set_program_enabled(kpse_pk_format, 1, kpse_src_cmdline); } - set_job_id(pdf, int_par(year_code), - int_par(month_code), int_par(day_code), int_par(time_code)); + set_job_id(pdf, int_par(year_code), int_par(month_code), int_par(day_code), int_par(time_code)); if ((pdf_unique_resname > 0) && (pdf->resname_prefix == NULL)) pdf->resname_prefix = get_resname_prefix(pdf); } @@ -1035,8 +971,6 @@ static void ensure_output_file_open(PDF pdf, const char *ext) @ @c static void ensure_pdf_header_written(PDF pdf) { - assert(pdf->o_state == ST_FILE_OPEN); - assert(output_mode_used == OMODE_PDF); /* Initialize variables for \.{PDF} output */ fix_pdf_minorversion(pdf); init_pdf_outputparameters(pdf); @@ -1057,39 +991,39 @@ void ensure_output_state(PDF pdf, output_state s) if (s > ST_INITIAL) ensure_output_state(pdf, s - 1); switch (s - 1) { - case ST_INITIAL: - fix_o_mode(); - break; - case ST_OMODE_FIX: - switch (output_mode_used) { - case OMODE_DVI: - ensure_output_file_open(pdf, ".dvi"); + case ST_INITIAL: + fix_o_mode(); break; - case OMODE_PDF: - ensure_output_file_open(pdf, ".pdf"); + case ST_OMODE_FIX: + switch (output_mode_used) { + case OMODE_DVI: + ensure_output_file_open(pdf, ".dvi"); + break; + case OMODE_PDF: + ensure_output_file_open(pdf, ".pdf"); + break; + default: + normal_error("pdf backend","weird output state"); + } break; - default: - assert(0); - } - break; - case ST_FILE_OPEN: - switch (output_mode_used) { - case OMODE_DVI: - ensure_dvi_header_written(pdf); + case ST_FILE_OPEN: + switch (output_mode_used) { + case OMODE_DVI: + ensure_dvi_header_written(pdf); + break; + case OMODE_PDF: + ensure_pdf_header_written(pdf); + break; + default: + normal_error("pdf backend","weird output state"); + } break; - case OMODE_PDF: - ensure_pdf_header_written(pdf); + case ST_HEADER_WRITTEN: + break; + case ST_FILE_CLOSED: break; default: - assert(0); - } - break; - case ST_HEADER_WRITTEN: - break; - case ST_FILE_CLOSED: - break; - default: - assert(0); + normal_error("pdf backend","weird output state"); } pdf->o_state++; } @@ -1097,12 +1031,11 @@ void ensure_output_state(PDF pdf, output_state s) @ Write out an accumulated object stream. -First the object number and byte offset pairs are generated -and appended to the ready buffered object stream. -By this the value of \.{/First} can be calculated. -Then a new \.{/ObjStm} object is generated, and everything is -copied to the PDF output buffer, where also compression is done. -When calling this procedure, |pdf_os_mode| must be |true|. +First the object number and byte offset pairs are generated and appended to the +ready buffered object stream. By this the value of \.{/First} can be calculated. +Then a new \.{/ObjStm} object is generated, and everything is copied to the PDF +output buffer, where also compression is done. When calling this procedure, +|pdf_os_mode| must be |true|. @c static void pdf_os_write_objstream(PDF pdf) @@ -1112,8 +1045,6 @@ static void pdf_os_write_objstream(PDF pdf) strbuf_s *obuf = os->buf[OBJSTM_BUF]; if (os->cur_objstm == 0) /* no object stream started */ return; - assert(pdf->buf == obuf); /* yes, pdf_out() still goes into ObjStm */ - assert(os->idx > 0); /* yes, there are objects for the ObjStm */ n1 = (unsigned int) strbuf_offset(obuf); /* remember end of collected object stream contents */ /* this is needed here to calculate /First for the ObjStm dict */ for (i = 0, j = 0; i < os->idx; i++) { /* add object-number/byte-offset list to buffer */ @@ -1282,11 +1213,10 @@ remember file position for seek @c void pdf_dict_add_streaminfo(PDF pdf) { - assert(pdf->buf == pdf->os->buf[PDFOUT_BUF]); pdf_add_name(pdf, "Length"); pdf->stream_length_offset = pdf_offset(pdf) + 1; - pdf->seek_write_length = true; /* fill in length at |pdf_end_stream| call */ - pdf_puts(pdf, " x "); /* space for 10 decimal digits */ + pdf->seek_write_length = true; /* fill in length at |pdf_end_stream| call */ + pdf_puts(pdf, " x "); /* space for 10 decimal digits */ pdf->cave = 1; if (pdf->compress_level > 0) { pdf_dict_add_name(pdf, "Filter", "FlateDecode"); @@ -1320,17 +1250,16 @@ void pdf_begin_obj(PDF pdf, int i, int pdf_os_threshold) os_struct *os = pdf->os; ensure_output_state(pdf, ST_HEADER_WRITTEN); pdf_prepare_obj(pdf, i, pdf_os_threshold); - assert(pdf->buf == os->buf[os->curbuf]); switch (os->curbuf) { - case PDFOUT_BUF: - pdf_printf(pdf, "%d 0 obj\n", (int) i); - break; - case OBJSTM_BUF: - if (pdf->compress_level == 0) - pdf_printf(pdf, "%% %d 0 obj\n", (int) i); /* debugging help */ - break; - default: - assert(0); + case PDFOUT_BUF: + pdf_printf(pdf, "%d 0 obj\n", (int) i); + break; + case OBJSTM_BUF: + if (pdf->compress_level == 0) + pdf_printf(pdf, "%% %d 0 obj\n", (int) i); /* debugging help */ + break; + default: + normal_error("pdf backend","weird begin object"); } pdf->cave = 0; } @@ -1341,21 +1270,20 @@ void pdf_begin_obj(PDF pdf, int i, int pdf_os_threshold) void pdf_end_obj(PDF pdf) { os_struct *os = pdf->os; - assert(pdf->buf == os->buf[os->curbuf]); switch (os->curbuf) { - case PDFOUT_BUF: - pdf_puts(pdf, "\nendobj\n"); /* end a PDF object */ - break; - case OBJSTM_BUF: - os->idx++; /* = number of objects collected so far in ObjStm */ - os->o_ctr++; /* only for statistics */ - if (os->idx == PDF_OS_MAX_OBJS) - pdf_os_write_objstream(pdf); - else - pdf_out(pdf, '\n'); /* Adobe Reader seems to need this */ - break; - default: - assert(0); + case PDFOUT_BUF: + pdf_puts(pdf, "\nendobj\n"); /* end a PDF object */ + break; + case OBJSTM_BUF: + os->idx++; /* = number of objects collected so far in ObjStm */ + os->o_ctr++; /* only for statistics */ + if (os->idx == PDF_OS_MAX_OBJS) + pdf_os_write_objstream(pdf); + else + pdf_out(pdf, '\n'); /* Adobe Reader seems to need this */ + break; + default: + normal_error("pdf backend","weird end object"); } } @@ -1400,16 +1328,15 @@ char *convertStringToPDFString(const char *in, int len) return pstrbuf; } -@ Converts any string given in in in an allowed PDF string which is - hexadecimal encoded; - |sizeof(out)| should be at least $|lin|*2+1$. +@ Converts any string given in in in an allowed PDF string which is hexadecimal +encoded; |sizeof(out)| should be at least $|lin|*2+1$. @c static void convertStringToHexString(const char *in, char *out, int lin) { - int i, j, k; + int i, k; char buf[3]; - j = 0; + int j = 0; for (i = 0; i < lin; i++) { k = snprintf(buf, sizeof(buf), "%02X", (unsigned int) (unsigned char) in[i]); check_nprintf(k, sizeof(buf)); @@ -1420,37 +1347,32 @@ static void convertStringToHexString(const char *in, char *out, int lin) } @ Compute the ID string as per PDF1.4 9.3: -\medskip -{\obeylines\obeyspaces - File identifers are defined by the optional ID entry in a PDF file's - trailer dictionary (see Section 3.4.4, "File Trailer"; see also - implementation note 105 in Appendix H). The value of this entry is an - array of two strings. The first string is a permanent identifier based - on the contents of the file at the time it was originally created, and - does not change when the file is incrementally updated. The second - string is a changing identifier based on the file's contents at the - time it was last updated. When a file is first written, both - identifiers are set to the same value. If both identifiers match when a - file reference is resolved, it is very likely that the correct file has - been found; if only the first identifier matches, then a different - version of the correct file has been found. - To help ensure the uniqueness of file identifiers, it is recommend - that they be computed using a message digest algorithm such as MD5 - (described in Internet RFC 1321, The MD5 Message-Digest Algorithm; see - the Bibliography), using the following information (see implementation - note 106 in Appendix H): - - The current time - - A string representation of the file's location, usually a pathname - - The size of the file in bytes - - The values of all entries in the file's document information - dictionary (see Section 9.2.1, Document Information Dictionary ) -} -\medskip - This stipulates only that the two IDs must be identical when the file is - created and that they should be reasonably unique. Since it's difficult - to get the file size at this point in the execution of pdfTeX and - scanning the info dict is also difficult, we start with a simpler - implementation using just the first two items. + +File identifers are defined by the optional ID entry in a PDF file's trailer +dictionary (see Section 3.4.4, "File Trailer"; see also implementation note 105 +in Appendix H). The value of this entry is an array of two strings. The first +string is a permanent identifier based on the contents of the file at the time it +was originally created, and does not change when the file is incrementally +updated. The second string is a changing identifier based on the file's contents +at the time it was last updated. When a file is first written, both identifiers +are set to the same value. If both identifiers match when a file reference is +resolved, it is very likely that the correct file has been found; if only the +first identifier matches, then a different version of the correct file has been +found. To help ensure the uniqueness of file identifiers, it is recommend that +they be computed using a message digest algorithm such as MD5 (described in +Internet RFC 1321, The MD5 Message-Digest Algorithm; see the Bibliography), using +the following information (see implementation note 106 in Appendix H): - The +current time + +- A string representation of the file's location, usually a pathname +- The size of the file in bytes +- The values of all entries in the file's document information + dictionary (see Section 9.2.1, Document Information Dictionary ) + +This stipulates only that the two IDs must be identical when the file is created +and that they should be reasonably unique. Since it's difficult to get the file +size at this point in the execution of pdfTeX and scanning the info dict is also +difficult, we start with a simpler implementation using just the first two items. @c static void print_ID(PDF pdf) @@ -1470,7 +1392,7 @@ static void print_ID(PDF pdf) md5_append(&state, (const md5_byte_t *) time_str, (int) size); /* get the file name */ if (getcwd(pwd, sizeof(pwd)) == NULL) - luatex_fail("getcwd() failed (%s), (path too long?)", strerror(errno)); + formatted_error("pdf backend","getcwd() failed (%s), (path too long?)", strerror(errno)); #ifdef WIN32 { char *p; @@ -1498,56 +1420,50 @@ static void print_ID(PDF pdf) @ Print the /CreationDate entry. - PDF Reference, third edition says about the expected date format: -\medskip -{\obeylines\obeyspaces - 3.8.2 Dates - - PDF defines a standard date format, which closely follows that of - the international standard ASN.1 (Abstract Syntax Notation One), - defined in ISO/IEC 8824 (see the Bibliography). A date is a string - of the form - - (D:YYYYMMDDHHmmSSOHH'mm') - - where - - YYYY is the year - MM is the month - DD is the day (01-31) - HH is the hour (00-23) - mm is the minute (00-59) - SS is the second (00-59) - O is the relationship of local time to Universal Time (UT), - denoted by one of the characters +, -, or Z (see below) - HH followed by ' is the absolute value of the offset from UT - in hours (00-23) - mm followed by ' is the absolute value of the offset from UT - in minutes (00-59) - - The apostrophe character (') after HH and mm is part of the syntax. - All fields after the year are optional. (The prefix D:, although also - optional, is strongly recommended.) The default values for MM and DD - are both 01; all other numerical fields default to zero values. A plus - sign (+) as the value of the O field signifies that local time is - later than UT, a minus sign (-) that local time is earlier than UT, - and the letter Z that local time is equal to UT. If no UT information - is specified, the relationship of the specified time to UT is - considered to be unknown. Whether or not the time zone is known, the - rest of the date should be specified in local time. - - For example, December 23, 1998, at 7:52 PM, U.S. Pacific Standard - Time, is represented by the string - - D:199812231952-08'00' -} - - The main difficulty is get the time zone offset. |strftime()| does this in ISO - C99 (e.g. newer glibc) with \%z, but we have to work with other systems (e.g. - Solaris 2.5). +PDF Reference, third edition says about the expected date format: + +3.8.2 Dates + +PDF defines a standard date format, which closely follows that of the +international standard ASN.1 (Abstract Syntax Notation One), defined in ISO/IEC +8824 (see the Bibliography). A date is a string of the form + +(D:YYYYMMDDHHmmSSOHH'mm') + +where + +YYYY is the year +MM is the month +DD is the day (01-31) +HH is the hour (00-23) +mm is the minute (00-59) +SS is the second (00-59) +O is the relationship of local time to Universal Time (UT), denoted by one + of the characters +, -, or Z (see below) +HH followed by ' is the absolute value of the offset from UT in hours (00-23) +mm followed by ' is the absolute value of the offset from UT in minutes (00-59) + +The apostrophe character (') after HH and mm is part of the syntax. All fields +after the year are optional. (The prefix D:, although also optional, is strongly +recommended.) The default values for MM and DD are both 01; all other numerical +fields default to zero values. A plus sign (+) as the value of the O field +signifies that local time is later than UT, a minus sign (-) that local time is +earlier than UT, and the letter Z that local time is equal to UT. If no UT +information is specified, the relationship of the specified time to UT is +considered to be unknown. Whether or not the time zone is known, the rest of the +date should be specified in local time. + +For example, December 23, 1998, at 7:52 PM, U.S. Pacific Standard Time, is +represented by the string + +D:199812231952-08'00' + +The main difficulty is get the time zone offset. |strftime()| does this in ISO +C99 (e.g. newer glibc) with \%z, but we have to work with other systems (e.g. +Solaris 2.5). @c -#define TIME_STR_SIZE 30 /* minimum size for |time_str| is 24: |"D:YYYYmmddHHMMSS+HH'MM'"| */ +#define TIME_STR_SIZE 30 /* minimum size for |time_str| is 24: |"D:YYYYmmddHHMMSS+HH'MM'"| */ static void makepdftime(PDF pdf) { @@ -1556,7 +1472,6 @@ static void makepdftime(PDF pdf) int i, off, off_hours, off_mins; time_t t = pdf->start_time; char *time_str = pdf->start_time_str; - /* get the time */ lt = *localtime(&t); size = strftime(time_str, TIME_STR_SIZE, "D:%Y%m%d%H%M%S", <); @@ -1566,19 +1481,18 @@ static void makepdftime(PDF pdf) time_str[0] = '\0'; return; } - - /* correction for seconds: \%S can be in range 00..61, - the PDF reference expects 00..59, - therefore we map "60" and "61" to "59" */ + /* + correction for seconds: \%S can be in range 00..61, the PDF reference + expects 00..59, therefore we map "60" and "61" to "59" + */ if (time_str[14] == '6') { time_str[14] = '5'; time_str[15] = '9'; - time_str[16] = '\0'; /* for safety */ + /* for safety */ + time_str[16] = '\0'; } - /* get the time zone offset */ gmt = *gmtime(&t); - /* this calculation method was found in exim's tod.c */ off = 60 * (lt.tm_hour - gmt.tm_hour) + lt.tm_min - gmt.tm_min; if (lt.tm_year != gmt.tm_year) { @@ -1586,7 +1500,6 @@ static void makepdftime(PDF pdf) } else if (lt.tm_yday != gmt.tm_yday) { off += (lt.tm_yday > gmt.tm_yday) ? 1440 : -1440; } - if (off == 0) { time_str[size++] = 'Z'; time_str[size] = 0; @@ -1602,7 +1515,6 @@ static void makepdftime(PDF pdf) @ @c void init_start_time(PDF pdf) { - assert(pdf); if (pdf->start_time == 0) { pdf->start_time = time((time_t *) NULL); pdf->start_time_str = xtalloc(TIME_STR_SIZE, char); @@ -1613,7 +1525,6 @@ void init_start_time(PDF pdf) @ @c char *getcreationdate(PDF pdf) { - assert(pdf); init_start_time(pdf); return pdf->start_time_str; } @@ -1635,20 +1546,16 @@ void remove_pdffile(PDF pdf) void check_o_mode(PDF pdf, const char *s, int o_mode_bitpattern, boolean strict) /* s ignored now */ { - char warn_string[100]; output_mode o_mode; const char *m = NULL; - if (lua_only) { normal_error("lua only","no backend present, needed for what you asked for"); return ; } - - /* in warn mode (strict == false): - only check, don't do |fix_o_mode()| here! |output_mode_used| is left - in possibly wrong state until real output, ok. - */ - + /* + in warn mode (strict == false): only check, don't do |fix_o_mode()| here! |output_mode_used| + is left in possibly wrong state until real output, ok. + */ if (output_mode_used == OMODE_NONE) o_mode = get_o_mode(); else @@ -1656,21 +1563,19 @@ void check_o_mode(PDF pdf, const char *s, int o_mode_bitpattern, boolean strict) pdf->o_mode = output_mode_used; /* used by synctex, we need to use output_mode_used there */ if (!((1 << o_mode) & o_mode_bitpattern)) { /* warning or error */ switch (o_mode) { - case OMODE_DVI: - m = "DVI"; - break; - case OMODE_PDF: - m = "PDF"; - break; - default: - assert(0); - } - snprintf(warn_string, 99, "%s not allowed in %s mode (outputmode = %d)", - s, m, (int) int_par(output_mode_code)); + case OMODE_DVI: + m = "DVI"; + break; + case OMODE_PDF: + m = "PDF"; + break; + default: + normal_error("pdf backend","weird output state"); + } if (strict) - normal_error("pdf backend", warn_string); + formatted_error("pdf backend", "%s not allowed in %s mode (outputmode = %d)",s, m, (int) int_par(output_mode_code)); else - normal_warning("pdf backend", warn_string, true, true); + formatted_warning("pdf backend", "%s not allowed in %s mode (outputmode = %d)",s, m, (int) int_par(output_mode_code)); } else if (strict) ensure_output_state(pdf, ST_HEADER_WRITTEN); } @@ -1681,20 +1586,14 @@ void set_job_id(PDF pdf, int year, int month, int day, int time) char *name_string, *format_string, *s; size_t slen; int i; - if (pdf->job_id_string != NULL) return; - name_string = makecstring(job_name); format_string = makecstring(format_ident); - slen = SMALL_BUF_SIZE + - strlen(name_string) + strlen(format_string) + strlen(luatex_banner); + slen = SMALL_BUF_SIZE + strlen(name_string) + strlen(format_string) + strlen(luatex_banner); s = xtalloc(slen, char); /* The Web2c version string starts with a space. */ - i = snprintf(s, slen, - "%.4d/%.2d/%.2d %.2d:%.2d %s %s %s", - year, month, day, time / 60, time % 60, - name_string, format_string, luatex_banner); + i = snprintf(s, slen, "%.4d/%.2d/%.2d %.2d:%.2d %s %s %s", year, month, day, time / 60, time % 60, name_string, format_string, luatex_banner); check_nprintf(i, slen); pdf->job_id_string = xstrdup(s); xfree(s); @@ -1705,16 +1604,12 @@ void set_job_id(PDF pdf, int year, int month, int day, int time) @ @c char *get_resname_prefix(PDF pdf) { - static char name_str[] = - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - static char prefix[7]; /* make a tag of 6 chars long */ - unsigned long crc; + static char name_str[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + static char prefix[7]; /* make a tag of 6 chars long */ short i; size_t base = strlen(name_str); - crc = crc32(0L, Z_NULL, 0); - crc = - crc32(crc, (Bytef *) pdf->job_id_string, - (uInt) strlen(pdf->job_id_string)); + unsigned long crc = crc32(0L, Z_NULL, 0); + crc = crc32(crc, (Bytef *) pdf->job_id_string, (uInt) strlen(pdf->job_id_string)); for (i = 0; i < 6; i++) { prefix[i] = name_str[crc % base]; crc /= base; @@ -1730,15 +1625,14 @@ void pdf_begin_page(PDF pdf) { pdffloat f; int xform_attributes; - scaled form_margin = 0; /* was one_bp until SVN4066 */ + scaled form_margin = 0; /* was one_bp until SVN4066 */ ensure_output_state(pdf, ST_HEADER_WRITTEN); init_pdf_pagecalculations(pdf); if (pdf->page_resources == NULL) { pdf->page_resources = xtalloc(1, pdf_resource_struct); pdf->page_resources->resources_tree = NULL; } - pdf->page_resources->last_resources = - pdf_create_obj(pdf, obj_type_others, 0); + pdf->page_resources->last_resources = pdf_create_obj(pdf, obj_type_others, 0); reset_page_resources(pdf); if (global_shipping_mode == SHIPPING_PAGE) { @@ -1748,12 +1642,9 @@ void pdf_begin_page(PDF pdf) pdf_begin_obj(pdf, pdf->last_stream, OBJSTM_NEVER); pdf->last_thread = null; pdf_begin_dict(pdf); - pdflua_begin_page(pdf); } else { - assert(global_shipping_mode == SHIPPING_FORM); pdf_begin_obj(pdf, pdf_cur_form, OBJSTM_NEVER); pdf->last_stream = pdf_cur_form; - /* Write out Form stream header */ pdf_begin_dict(pdf); pdf_dict_add_name(pdf, "Type", "XObject"); @@ -1804,8 +1695,7 @@ void pdf_begin_page(PDF pdf) pdf_puts(pdf, " 0 0 cm\n"); } } - pos_stack_used = 0; /* start with empty stack */ - + pos_stack_used = 0; /* start with empty stack */ if (global_shipping_mode == SHIPPING_PAGE) { colorstackpagestart(); } @@ -1820,9 +1710,9 @@ void print_pdf_table_string(PDF pdf, const char *s) const char *ls; lua_rawgeti(Luas, LUA_REGISTRYINDEX, lua_key_index(pdf_data)); lua_rawget(Luas, LUA_REGISTRYINDEX); - lua_pushstring(Luas, s); /* s t ... */ - lua_rawget(Luas, -2); /* s? t ... */ - if (lua_type(Luas, -1) == LUA_TSTRING) { /* s t ... */ + lua_pushstring(Luas, s); /* s t ... */ + lua_rawget(Luas, -2); /* s? t ... */ + if (lua_type(Luas, -1) == LUA_TSTRING) { /* s t ... */ ls = lua_tolstring(Luas, -1, &len); if (len > 0) { if (pdf->cave == 1) @@ -1831,7 +1721,7 @@ void print_pdf_table_string(PDF pdf, const char *s) pdf->cave = 1; } } - lua_pop(Luas, 2); /* ... */ + lua_pop(Luas, 2); } @ @c @@ -1840,25 +1730,22 @@ const char *get_pdf_table_string(const char *s) const_lstring ls; lua_rawgeti(Luas, LUA_REGISTRYINDEX, lua_key_index(pdf_data)); lua_rawget(Luas, LUA_REGISTRYINDEX); - lua_pushstring(Luas, s); /* s t ... */ - lua_rawget(Luas, -2); /* s? t ... */ - if (lua_type(Luas, -1) == LUA_TSTRING) { /* s t ... */ + lua_pushstring(Luas, s); /* s t ... */ + lua_rawget(Luas, -2); /* s? t ... */ + if (lua_type(Luas, -1) == LUA_TSTRING) { /* s t ... */ ls.s = lua_tolstring(Luas, -1, &ls.l); /* s is supposed to be anchored (e.g in the registry) so it's not garbage collected */ - lua_pop(Luas, 2); /* ... */ + lua_pop(Luas, 2); return ls.s; } - lua_pop(Luas, 2); /* ... */ + lua_pop(Luas, 2); return NULL ; } @ @c -// #define pdf_page_attr equiv(pdf_page_attr_loc) -// #define pdf_page_resources equiv(pdf_page_resources_loc) - void pdf_end_page(PDF pdf) { char s[64], *p; @@ -1866,29 +1753,24 @@ void pdf_end_page(PDF pdf) pdf_resource_struct *res_p = pdf->page_resources; pdf_resource_struct local_page_resources; pdf_object_list *annot_list, *bead_list, *link_list, *ol, *ol1; - scaledpos save_cur_page_size; /* to save |pdf->page_size| during flushing pending forms */ + scaledpos save_cur_page_size; /* to save |pdf->page_size| during flushing pending forms */ shipping_mode_e save_shipping_mode; int xform_resources; int page_resources, page_attributes; int procset = PROCSET_PDF; - /* Finish stream of page/form contents */ pdf_goto_pagemode(pdf); if (pos_stack_used > 0) { - luatex_fail("%u unmatched 'save' after %s shipout", (unsigned int) pos_stack_used, + formatted_error("pdf backend","%u unmatched 'save' after %s shipout", (unsigned int) pos_stack_used, ((global_shipping_mode == SHIPPING_PAGE) ? "page" : "form")); } pdf_end_stream(pdf); pdf_end_obj(pdf); - /* hh-ls : new call back finish_pdfpage_callback */ callback_id = callback_defined(finish_pdfpage_callback); if (callback_id > 0) run_callback(callback_id, "b->",(global_shipping_mode == SHIPPING_PAGE)); - if (global_shipping_mode == SHIPPING_PAGE) { - pdf->last_pages = pdf_do_page_divert(pdf, pdf->last_page, 0); - /* Write out /Page object */ pdf_begin_obj(pdf, pdf->last_page, OBJSTM_ALWAYS); pdf_begin_dict(pdf); @@ -1899,8 +1781,8 @@ void pdf_end_page(PDF pdf) pdf_begin_array(pdf); pdf_add_int(pdf, 0); pdf_add_int(pdf, 0); - pdf_add_mag_bp(pdf, pdf->page_size.h); - pdf_add_mag_bp(pdf, pdf->page_size.v); + pdf_add_bp(pdf, pdf->page_size.h); + pdf_add_bp(pdf, pdf->page_size.v); pdf_end_array(pdf); page_attributes = pdf_page_attr ; /* lookup once */ if (page_attributes != null) @@ -1908,7 +1790,6 @@ void pdf_end_page(PDF pdf) print_pdf_table_string(pdf, "pageattributes"); pdf_dict_add_ref(pdf, "Parent", pdf->last_pages); if (pdf->img_page_group_val != 0) { - assert(pdf->img_page_group_val > 0); pdf_dict_add_ref(pdf, "Group", pdf->img_page_group_val); } annot_list = get_page_resources_list(pdf, obj_type_annot); @@ -1924,16 +1805,12 @@ void pdf_end_page(PDF pdf) } pdf_end_dict(pdf); pdf_end_obj(pdf); - pdflua_end_page(pdf, annots, beads); - pdf->img_page_group_val = 0; - /* Generate array of annotations or beads in page */ if (annot_list != NULL || link_list != NULL) { pdf_begin_obj(pdf, annots, OBJSTM_ALWAYS); pdf_begin_array(pdf); while (annot_list != NULL) { - assert(annot_list->info > 0); pdf_add_ref(pdf, annot_list->info); annot_list = annot_list->link; } @@ -1955,9 +1832,7 @@ void pdf_end_page(PDF pdf) pdf_end_obj(pdf); } } - - /* Write out resource lists */ - /* Write out pending raw objects */ + /* Write out resource lists and pending raw objects */ ol = get_page_resources_list(pdf, obj_type_obj); while (ol != NULL) { if (!is_obj_written(pdf, ol->info)) @@ -1965,11 +1840,11 @@ void pdf_end_page(PDF pdf) ol = ol->link; } - /* Write out pending forms */ - /* When flushing pending forms we need to save and restore resource lists - which are also used by page shipping. - Saving and restoring |pdf->page_size| is needed for proper - writing out pending PDF marks. */ + /* + When flushing pending forms we need to save and restore resource lists + which are also used by page shipping. Saving and restoring + |pdf->page_size| is needed for proper writing out pending PDF marks. + */ ol = get_page_resources_list(pdf, obj_type_xform); while (ol != NULL) { if (!is_obj_written(pdf, ol->info)) { @@ -1987,7 +1862,6 @@ void pdf_end_page(PDF pdf) } ol = ol->link; } - /* Write out pending images */ ol = get_page_resources_list(pdf, obj_type_ximage); while (ol != NULL) { @@ -1995,14 +1869,12 @@ void pdf_end_page(PDF pdf) pdf_write_image(pdf, ol->info); ol = ol->link; } - if (global_shipping_mode == SHIPPING_PAGE) { - /* Write out pending PDF marks */ - /* Write out PDF annotations */ + /* Write out pending PDF marks and annotations */ ol = get_page_resources_list(pdf, obj_type_annot); while (ol != NULL) { if (ol->info > 0 && obj_type(pdf, ol->info) == obj_type_annot) { - j = obj_annot_ptr(pdf, ol->info); /* |j| points to |pdf_annot_node| */ + j = obj_annot_ptr(pdf, ol->info); /* |j| points to |pdf_annot_node| */ pdf_begin_obj(pdf, ol->info, OBJSTM_ALWAYS); pdf_begin_dict(pdf); pdf_dict_add_name(pdf, "Type", "Annot"); @@ -2013,7 +1885,6 @@ void pdf_end_page(PDF pdf) } ol = ol->link; } - /* Write out PDF link annotations */ if ((ol = get_page_resources_list(pdf, obj_type_link)) != NULL) { while (ol != NULL) { @@ -2037,19 +1908,19 @@ void pdf_end_page(PDF pdf) ol = get_page_resources_list(pdf, obj_type_link); while (ol != NULL) { j = obj_annot_ptr(pdf, ol->info); - /* nodes with |subtype = pdf_link_data_node| were created by |append_link| and - must be flushed here, as they are not linked in any list */ + /* + nodes with |subtype = pdf_link_data_node| were created by |append_link| and + must be flushed here, as they are not linked in any list + */ if (subtype(j) == pdf_link_data_node) flush_node(j); ol = ol->link; } } - /* Write out PDF mark destinations */ write_out_pdf_mark_destinations(pdf); /* Write out PDF bead rectangle specifications */ print_bead_rectangles(pdf); - } /* Write out resources dictionary */ pdf_begin_obj(pdf, res_p->last_resources, OBJSTM_ALWAYS); @@ -2075,13 +1946,11 @@ void pdf_end_page(PDF pdf) set_obj_xform_resources_str(pdf, pdf_cur_form, null); } } - /* Generate font resources */ if ((ol = get_page_resources_list(pdf, obj_type_font)) != NULL) { pdf_add_name(pdf, "Font"); pdf_begin_dict(pdf); while (ol != NULL) { - assert(ol->info > 0); /* always base font: an object number */ p = s; p += snprintf(p, 20, "F%i", obj_info(pdf, ol->info)); if (pdf->resname_prefix != NULL) @@ -2092,7 +1961,6 @@ void pdf_end_page(PDF pdf) pdf_end_dict(pdf); procset |= PROCSET_TEXT; } - /* Generate XObject resources */ ol = get_page_resources_list(pdf, obj_type_xform); ol1 = get_page_resources_list(pdf, obj_type_ximage); @@ -2118,7 +1986,6 @@ void pdf_end_page(PDF pdf) } pdf_end_dict(pdf); } - /* Generate ProcSet */ pdf_add_name(pdf, "ProcSet"); pdf_begin_array(pdf); @@ -2140,8 +2007,8 @@ void pdf_end_page(PDF pdf) @* Finishing the PDF output file. @ Destinations that have been referenced but don't exists have -|obj_dest_ptr=null|. Leaving them undefined might cause troubles for -PDF browsers, so we need to fix them; they point to the last page. +|obj_dest_ptr=null|. Leaving them undefined might cause troubles for PDF +browsers, so we need to fix them; they point to the last page. @c static void check_nonexisting_destinations(PDF pdf) @@ -2149,19 +2016,12 @@ static void check_nonexisting_destinations(PDF pdf) int k; for (k = pdf->head_tab[obj_type_dest]; k != 0; k = obj_link(pdf, k)) { if (obj_dest_ptr(pdf, k) == null) { - normal_warning("pdf backend", "dest ", false, false); if (obj_info(pdf, k) < 0) { - tprint("name{"); - print(-obj_info(pdf, k)); - tprint("}"); + char *ss = makecstring(-obj_info(pdf, k)); + formatted_warning("pdf backend", "unreferenced destination with name '%s'",ss); } else { - tprint("num"); - print_int(obj_info(pdf, k)); + formatted_warning("pdf backend", "unreferenced destination with num '%d'",obj_info(pdf,k)); } - tprint - (" has been referenced but does not exist, replaced by a fixed one"); - print_ln(); - print_ln(); pdf_begin_obj(pdf, k, OBJSTM_ALWAYS); pdf_begin_array(pdf); @@ -2181,20 +2041,15 @@ static void check_nonexisting_pages(PDF pdf) struct avl_table *page_tree = pdf->obj_tree[obj_type_page]; avl_t_init(&t, page_tree); /* search from the end backward until the last real page is found */ - for (p = avl_t_last(&t, page_tree); - p != NULL && obj_aux(pdf, p->objptr) == 0; p = avl_t_prev(&t)) { - normal_warning("pdf backend", "Page ", false, false); - print_int(obj_info(pdf, p->objptr)); - tprint(" has been referenced but does not exist!"); - print_ln(); - print_ln(); + for (p = avl_t_last(&t, page_tree); p != NULL && obj_aux(pdf, p->objptr) == 0; p = avl_t_prev(&t)) { + formatted_warning("pdf backend", "page %s has been referenced but does not exist",obj_info(pdf, p->objptr)); } } @ If the same keys in a dictionary are given several times, then it is not -defined which value is choosen by an application. Therefore the keys -|/Producer| and |/Creator| are only set if the token list -|pdf_info_toks| converted to a string does not contain these key strings. +defined which value is choosen by an application. Therefore the keys |/Producer| +and |/Creator| are only set if the token list |pdf_info_toks| converted to a +string does not contain these key strings. @c static boolean substr_of_str(const char *s, const char *t) @@ -2207,18 +2062,16 @@ static boolean substr_of_str(const char *s, const char *t) static int pdf_print_info(PDF pdf, int luatexversion, str_number luatexrevision) { /* print info object */ - boolean creator_given, producer_given, creationdate_given, moddate_given, - trapped_given; + boolean creator_given = false; + boolean producer_given = false; + boolean creationdate_given = false; + boolean moddate_given = false; + boolean trapped_given = false; char *s = NULL; const char *p = NULL; int k, len = 0; k = pdf_create_obj(pdf, obj_type_info, 0); pdf_begin_obj(pdf, k, 3); /* keep Info readable unless explicitely forced */ - creator_given = false; - producer_given = false; - creationdate_given = false; - moddate_given = false; - trapped_given = false; pdf_begin_dict(pdf); if (pdf_info_toks != 0) { s = tokenlist_to_cstring(pdf_info_toks, true, &len); @@ -2283,8 +2136,8 @@ static int pdf_print_info(PDF pdf, int luatexversion, static void build_free_object_list(PDF pdf) { - int k, l; - l = 0; + int k; + int l = 0; set_obj_fresh(pdf, l); /* null object at begin of list of free objects */ for (k = 1; k <= pdf->obj_ptr; k++) { if (!is_obj_written(pdf, k)) { @@ -2306,53 +2159,35 @@ void finish_pdf_file(PDF pdf, int luatexversion, str_number luatexrevision) size_t xref_offset_width; int callback_id = callback_defined(stop_run_callback); int callback_id1 = callback_defined(finish_pdffile_callback); - if (total_pages == 0) { if (callback_id == 0) { - tprint_nl("No pages of output."); - print_ln(); + normal_warning("pdf backend","no pages of output."); } else if (callback_id > 0) { run_callback(callback_id, "->"); } if (pdf->gone > 0) - garbage_warning(); + normal_error("pdf backend","dangling objects discarded, no output file produced."); } else { if (pdf->draftmode == 0) { - pdf_flush(pdf); /* to make sure that the output file name has been already created */ - flush_jbig2_page0_objects(pdf); /* flush page 0 objects from JBIG2 images, if any */ + pdf_flush(pdf); /* to make sure that the output file name has been already created */ + flush_jbig2_page0_objects(pdf); /* flush page 0 objects from JBIG2 images, if any */ if (callback_id1 > 0) run_callback(callback_id1, "->"); - check_nonexisting_pages(pdf); check_nonexisting_destinations(pdf); - /* Output fonts definition */ for (k = 1; k <= max_font_id(); k++) { if (font_used(k) && (pdf_font_num(k) < 0)) { i = -pdf_font_num(k); - assert(pdf_font_num(i) > 0); for (j = font_bc(k); j <= font_ec(k); j++) if (quick_char_exists(k, j) && pdf_char_marked(k, j)) pdf_mark_char(i, j); if ((pdf_font_attr(i) == 0) && (pdf_font_attr(k) != 0)) { set_pdf_font_attr(i, pdf_font_attr(k)); - } else if ((pdf_font_attr(k) == 0) - && (pdf_font_attr(i) != 0)) { + } else if ((pdf_font_attr(k) == 0) && (pdf_font_attr(i) != 0)) { set_pdf_font_attr(k, pdf_font_attr(i)); - } else if ((pdf_font_attr(i) != 0) - && (pdf_font_attr(k) != 0) - && - (!str_eq_str - (pdf_font_attr(i), pdf_font_attr(k)))) { - normal_warning("pdf backend","fontattr in ", false, false); - print_font_identifier(i); - tprint(" and "); - print_font_identifier(k); - tprint(" have conflicting attributes; the attributes assigned to "); - print_font_identifier(i); - tprint(" are ignored"); - print_ln(); - print_ln(); + } else if ((pdf_font_attr(i) != 0) && (pdf_font_attr(k) != 0) && (!str_eq_str(pdf_font_attr(i), pdf_font_attr(k)))) { + formatted_warning("pdf backend","fontattr of font %d and %d are conflicting, %k is used",i,k,i); } } } @@ -2360,25 +2195,22 @@ void finish_pdf_file(PDF pdf, int luatexversion, str_number luatexrevision) k = pdf->head_tab[obj_type_font]; while (k != 0) { int f = obj_info(pdf, k); - assert(pdf_font_num(f) > 0); - assert(pdf_font_num(f) == k); do_pdf_font(pdf, f); k = obj_link(pdf, k); } write_fontstuff(pdf); - pdf->last_pages = output_pages_tree(pdf); - pdflua_output_pages_tree(pdf); /* Output outlines */ outlines = print_outlines(pdf); - - /* Output name tree */ - /* The name tree is very similiar to Pages tree so its construction should be - certain from Pages tree construction. For intermediate node |obj_info| will be - the first name and |obj_link| will be the last name in \.{\\Limits} array. - Note that |pdf_dest_names_ptr| will be less than |obj_ptr|, so we test if - |k < pdf_dest_names_ptr| then |k| is index of leaf in |dest_names|; else - |k| will be index in |obj_tab| of some intermediate node. + /* + Output name tree. The name tree is very similiar to Pages tree so + its construction should be certain from Pages tree construction. + For intermediate node |obj_info| will be the first name and + |obj_link| will be the last name in \.{\\Limits} array. Note that + |pdf_dest_names_ptr| will be less than |obj_ptr|, so we test if + |k < pdf_dest_names_ptr| then |k| is index of leaf in + |dest_names|; else |k| will be index in |obj_tab| of some + intermediate node. */ names_tree = output_name_tree(pdf); @@ -2402,7 +2234,6 @@ void finish_pdf_file(PDF pdf, int luatexversion, str_number luatexrevision) } else { threads = 0; } - /* Output the /Catalog object */ root = pdf_create_obj(pdf, obj_type_catalog, 0); pdf_begin_obj(pdf, root, OBJSTM_ALWAYS); @@ -2425,10 +2256,9 @@ void finish_pdf_file(PDF pdf, int luatexversion, str_number luatexrevision) pdf_dict_add_ref(pdf, "OpenAction", pdf_catalog_openaction); pdf_end_dict(pdf); pdf_end_obj(pdf); - /* last candidate for object stream */ - info = pdf_print_info(pdf, luatexversion, luatexrevision); /* final object for pdf->os_enable == false */ - + info = pdf_print_info(pdf, luatexversion, luatexrevision); + /* final object for pdf->os_enable == false */ if (pdf->os_enable) { pdf_buffer_select(pdf, OBJSTM_BUF); pdf_os_write_objstream(pdf); @@ -2492,14 +2322,10 @@ void finish_pdf_file(PDF pdf, int luatexversion, str_number luatexrevision) } pdf_end_stream(pdf); pdf_end_obj(pdf); - /* TODO: generate a debug version of the crossref */ - pdf_flush(pdf); } else { - /* Output the |obj_tab| */ - /* Build a linked list of free objects */ + /* Output the |obj_tab| and build a linked list of free objects */ build_free_object_list(pdf); - pdf_save_offset(pdf); pdf_puts(pdf, "xref\n"); pdf_puts(pdf, "0 "); @@ -2515,9 +2341,7 @@ void finish_pdf_file(PDF pdf, int luatexversion, str_number luatexrevision) pdf_puts(pdf, " 00000 n \n"); } } - } - /* Output the trailer */ if (!pdf->os_enable) { pdf_puts(pdf, "trailer\n"); @@ -2541,9 +2365,7 @@ void finish_pdf_file(PDF pdf, int luatexversion, str_number luatexrevision) else pdf_add_longint(pdf, (longinteger) pdf->save_offset); pdf_puts(pdf, "\n%%EOF\n"); - pdf_flush(pdf); - if (callback_id == 0) { tprint_nl("Output written on "); tprint(pdf->file_name); @@ -2564,28 +2386,24 @@ void finish_pdf_file(PDF pdf, int luatexversion, str_number luatexrevision) if (pdf->draftmode == 0) close_file(pdf->file); else - normal_warning("pdf backend","draftmode enabled, not changing output pdf",true, true); + normal_warning("pdf backend","draftmode enabled, not changing output pdf"); } - if (callback_id == 0) { if (log_opened_global) { - fprintf(log_file, - "\nPDF statistics: %d PDF objects out of %d (max. %d)\n", - (int) pdf->obj_ptr, (int) pdf->obj_tab_size, - (int) sup_obj_tab_size); + fprintf(log_file, "\nPDF statistics: %d PDF objects out of %d (max. %d)\n", + (int) pdf->obj_ptr, (int) pdf->obj_tab_size, + (int) sup_obj_tab_size); if (pdf->os->ostm_ctr > 0) { - fprintf(log_file, - " %d compressed objects within %d object stream%s\n", - (int) pdf->os->o_ctr, (int) pdf->os->ostm_ctr, - (pdf->os->ostm_ctr > 1 ? "s" : "")); + fprintf(log_file, " %d compressed objects within %d object stream%s\n", + (int) pdf->os->o_ctr, (int) pdf->os->ostm_ctr, + (pdf->os->ostm_ctr > 1 ? "s" : "")); } fprintf(log_file, " %d named destinations out of %d (max. %d)\n", - (int) pdf->dest_names_ptr, (int) pdf->dest_names_size, - (int) sup_dest_names_size); - fprintf(log_file, - " %d words of extra memory for PDF output out of %d (max. %d)\n", - (int) pdf->mem_ptr, (int) pdf->mem_size, - (int) sup_pdf_mem_size); + (int) pdf->dest_names_ptr, (int) pdf->dest_names_size, + (int) sup_dest_names_size); + fprintf(log_file, " %d words of extra memory for PDF output out of %d (max. %d)\n", + (int) pdf->mem_ptr, (int) pdf->mem_size, + (int) sup_pdf_mem_size); } } } @@ -2594,7 +2412,7 @@ void finish_pdf_file(PDF pdf, int luatexversion, str_number luatexrevision) void scan_pdfcatalog(PDF pdf) { halfword p; - scan_pdf_ext_toks(); + scan_toks(false, true); pdf_catalog_toks = concat_tokens(pdf_catalog_toks, def_ref); if (scan_keyword("openaction")) { if (pdf_catalog_openaction != 0) { diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.h b/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.h index 37766d26c8f..2d04e944c6e 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.h @@ -15,8 +15,8 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ - + with LuaTeX; if not, see . +*/ #ifndef PDFGLYPH_H # define PDFGLYPH_H diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.w b/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.w index 1f8319484e2..93096d025e5 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.w @@ -19,24 +19,22 @@ @ @c - #include "ptexlib.h" #include "pdf/pdfpage.h" #define pdf2double(a) ((double) (a).m / ten_pow[(a).e]) @ eternal constants + @c -#define one_bp ((double) 65536 * (double) 72.27 / 72) /* number of sp per 1bp */ -#define e_tj 3 /* must be 3; movements in []TJ are in fontsize/$10^3$ units */ +#define one_bp ((double) 65536 * (double) 72.27 / 72) /* number of sp per 1bp */ +#define e_tj 3 /* must be 3; movements in []TJ are in fontsize/$10^3$ units */ @ @c static int64_t pdf_char_width(pdfstructure * p, internal_font_number f, int i) { /* use exactly this formula also for calculating the /Width array values */ - return - i64round((double) char_width(f, i) / font_size(f) * - ten_pow[e_tj + p->cw.e]); + return i64round((double) char_width(f, i) / font_size(f) * ten_pow[e_tj + p->cw.e]); } @ @c @@ -56,9 +54,7 @@ static void setup_fontparameters(PDF pdf, internal_font_number f, int ex_glyph) float u = 1.0; pdfstructure *p = pdf->pstruct; /* fix mantis bug \# 0000200 (acroread "feature") */ - if ((font_format(f) == opentype_format || - (font_format(f) == type1_format && font_encodingbytes(f) == 2)) - && font_units_per_em(f) > 0) + if ((font_format(f) == opentype_format || (font_format(f) == type1_format && font_encodingbytes(f) == 2)) && font_units_per_em(f) > 0) u = font_units_per_em(f) / 1000.0; pdf->f_cur = f; p->f_pdf = pdf_set_font(pdf, f); @@ -68,19 +64,14 @@ static void setup_fontparameters(PDF pdf, internal_font_number f, int ex_glyph) expand = 1.0 + (ex_glyph/1) / 1000.0; p->tj_delta.e = p->cw.e - 1; /* "- 1" makes less corrections inside []TJ */ /* no need to be more precise than TeX (1sp) */ - while (p->tj_delta.e > 0 - && (double) font_size(f) / ten_pow[p->tj_delta.e + e_tj] < 0.5) + while (p->tj_delta.e > 0 && (double) font_size(f) / ten_pow[p->tj_delta.e + e_tj] < 0.5) p->tj_delta.e--; /* happens for very tiny fonts */ - assert(p->cw.e >= p->tj_delta.e); /* else we would need, e. g., |ten_pow[-1]| */ p->tm[0].m = i64round(scale * expand * extend * ten_pow[p->tm[0].e]); p->tm[2].m = i64round(slant * ten_pow[p->tm[2].e]); p->tm[3].m = i64round(scale * ten_pow[p->tm[3].e]); - p->k2 = - ten_pow[e_tj + - p->cw.e] * scale / (ten_pow[p->pdf.h.e] * pdf2double(p->fs) * - pdf2double(p->tm[0])); + p->k2 = ten_pow[e_tj + p->cw.e] * scale / (ten_pow[p->pdf.h.e] * pdf2double(p->fs) * pdf2double(p->tm[0])); p->cur_ex = ex_glyph ; /* we keep track of the state of ex */ -} +} @ @c @@ -95,7 +86,7 @@ static void set_font(PDF pdf) p->f_pdf_cur = p->f_pdf; p->fs_cur.m = p->fs.m; p->need_tf = false; - p->need_tm = true; /* always follow Tf by Tm */ + p->need_tm = true; /* always follow Tf by Tm */ } @ @c @@ -103,12 +94,13 @@ static void set_textmatrix(PDF pdf, scaledpos pos) { boolean move; pdfstructure *p = pdf->pstruct; - assert(is_textmode(p)); + if (!is_textmode(p)) + normal_error("pdf backend","text mode expected in set_textmatrix"); move = calc_pdfpos(p, pos); if (p->need_tm || move) { print_pdf_matrix(pdf, p->tm); pdf_puts(pdf, " Tm "); - p->pdf.h.m = p->pdf_bt_pos.h.m + p->tm[4].m; /* Tm replaces */ + p->pdf.h.m = p->pdf_bt_pos.h.m + p->tm[4].m; /* Tm replaces */ p->pdf.v.m = p->pdf_bt_pos.v.m + p->tm[5].m; p->need_tm = false; } @@ -118,6 +110,7 @@ static void set_textmatrix(PDF pdf, scaledpos pos) @ Print out a character to PDF buffer; the character will be printed in octal form in the following cases: chars <= 32, backslash (92), left parenthesis (40), and right parenthesis (41). + @c static void pdf_print_char(PDF pdf, int c) { @@ -144,7 +137,8 @@ static void pdf_print_wide_char(PDF pdf, int c) @ @c static void begin_charmode(PDF pdf, internal_font_number f, pdfstructure * p) { - assert(is_chararraymode(p)); + if (!is_chararraymode(p)) + normal_error("pdf backend","char array mode expected in begin_char_mode"); if (font_encodingbytes(f) == 2) { p->ishex = 1; pdf_out(pdf, '<'); @@ -159,7 +153,8 @@ static void begin_charmode(PDF pdf, internal_font_number f, pdfstructure * p) void end_charmode(PDF pdf) { pdfstructure *p = pdf->pstruct; - assert(is_charmode(p)); + if (!is_charmode(p)) + normal_error("pdf backend","char mode expected in end_char_mode"); if (p->ishex == 1) { p->ishex = 0; pdf_out(pdf, '>'); @@ -173,7 +168,8 @@ void end_charmode(PDF pdf) static void begin_chararray(PDF pdf) { pdfstructure *p = pdf->pstruct; - assert(is_textmode(p)); + if (!is_textmode(p)) + normal_error("pdf backend","text mode expected in begin_char_array"); p->pdf_tj_pos = p->pdf; p->cw.m = 0; pdf_out(pdf, '['); @@ -184,58 +180,28 @@ static void begin_chararray(PDF pdf) void end_chararray(PDF pdf) { pdfstructure *p = pdf->pstruct; - assert(is_chararraymode(p)); + if (!is_chararraymode(p)) + normal_error("pdf backend","char array mode expected in end_char_array"); pdf_puts(pdf, "]TJ\n"); p->pdf = p->pdf_tj_pos; p->mode = PMODE_TEXT; } -@ @c +@ We need to adapt the tm when a font changes. A change can be a change in id +(frontend) or pdf reference (backend, as we share font resources). At such a +change we also need to adapt to the slant and extend. Initially we also need to +take the exfactor of a glyph into account. When the font is unchanged, we still +need to check each glyph for a change in exfactor. We store the current one on +the state record so that we can minimize testing. + +@c void pdf_place_glyph(PDF pdf, internal_font_number f, int c, int ex) { boolean move; pdfstructure *p = pdf->pstruct; scaledpos pos = pdf->posstruct->pos; - if (!char_exists(f, c)) return; - -/* - p->need_tf : okay, set somewhere else - f != pdf->f_cur : font change - p->f_pdf != p->f_pdf_cur : font change - p->fs.m ~= p->fs_cur.m : move - is_pagemode(p) -> stream change - p->tm0_cur.m -> p->tm[0].m : also move -*/ - - /* fix issue 857 */ - /* /\* ensure to be within BT...ET *\/ */ - /* if (is_pagemode(p)) { */ - /* pdf_goto_textmode(pdf); */ - /* p->need_tf = true; */ - /* } */ - /* /\* all font setup *\/ */ - /* if (true || f != pdf->f_cur || p->need_tf) { */ - /* setup_fontparameters(pdf, f, ex); */ - /* if (p->need_tf || p->f_pdf != p->f_pdf_cur || p->fs.m != p->fs_cur.m) { */ - /* pdf_goto_textmode(pdf); */ - /* set_font(pdf); */ - /* } else if (p->tm0_cur.m != p->tm[0].m) { */ - /* /\* catch in-line HZ expand change due to efcode *\/ */ - /* p->need_tm = true; */ - /* } */ - /* } */ - - - /* LS/HH: We need to adapt the tm when a font changes. A change can be a change in - id (frontend) or pdf reference (backend, as we share font resources). At - such a change we also need to adapt to the slant and extend. Initially - we also need to take the exfactor of a glyph into account. When the font is - unchanged, we still need to check each glyph for a change in exfactor. We - store the current one on the state record so that we can minimize testing. */ - - /* is the p->need_tf test really needed ? */ if (p->need_tf || f != pdf->f_cur || p->f_pdf != p->f_pdf_cur || p->fs.m != p->fs_cur.m || is_pagemode(p)) { pdf_goto_textmode(pdf); setup_fontparameters(pdf, f, ex); @@ -243,37 +209,30 @@ void pdf_place_glyph(PDF pdf, internal_font_number f, int c, int ex) } else if (p->tm0_cur.m != p->tm[0].m || p->cur_ex != ex) { setup_fontparameters(pdf, f, ex); p->need_tm = true; - } - + } /* all movements */ move = calc_pdfpos(p, pos); /* within text or chararray or char mode */ if (move || p->need_tm) { - if (p->need_tm || (p->wmode == WMODE_H - && (p->pdf_bt_pos.v.m + p->tm[5].m) != p->pdf.v.m) - || (p->wmode == WMODE_V - && (p->pdf_bt_pos.h.m + p->tm[4].m) != p->pdf.h.m) - || abs(p->tj_delta.m) >= 1000000) { + if (p->need_tm || (p->wmode == WMODE_H && (p->pdf_bt_pos.v.m + p->tm[5].m) != p->pdf.v.m) + || (p->wmode == WMODE_V && (p->pdf_bt_pos.h.m + p->tm[4].m) != p->pdf.h.m) + || abs(p->tj_delta.m) >= 1000000) { pdf_goto_textmode(pdf); set_textmatrix(pdf, pos); begin_chararray(pdf); move = calc_pdfpos(p, pos); /* for fine adjustment */ } if (move) { - assert((p->wmode == WMODE_H - && (p->pdf_bt_pos.v.m + p->tm[5].m) == p->pdf.v.m) - || (p->wmode == WMODE_V - && (p->pdf_bt_pos.h.m + p->tm[4].m) == p->pdf.h.m)); if (is_charmode(p)) end_charmode(pdf); - assert(p->tj_delta.m != 0); print_pdffloat(pdf, p->tj_delta); p->cw.m -= p->tj_delta.m * ten_pow[p->cw.e - p->tj_delta.e]; } } /* glyph output */ - assert(is_chararraymode(p) || is_charmode(p)); if (is_chararraymode(p)) begin_charmode(pdf, f, p); + else if (!is_charmode(p)) + normal_error("pdf backend","char (array) mode expected in place_glyph"); pdf_mark_char(f, c); if (font_encodingbytes(f) == 2) pdf_print_wide_char(pdf, char_index(f, c)); diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfimage.h b/Build/source/texk/web2c/luatexdir/pdf/pdfimage.h index c4f5f53aecb..b5b8718393e 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfimage.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfimage.h @@ -15,8 +15,9 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ + with LuaTeX; if not, see . +*/ #ifndef PDFIMAGE_H # define PDFIMAGE_H diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfimage.w b/Build/source/texk/web2c/luatexdir/pdf/pdfimage.w index 29795990eab..fd364243804 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfimage.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfimage.w @@ -19,7 +19,6 @@ @ @c - #include "ptexlib.h" @ @c @@ -34,8 +33,6 @@ void place_img(PDF pdf, image_dict * idict, scaled_whd dim, int transform) scaledpos tmppos; pdffloat cm[6]; int groupref; /* added from web for 1.40.8 */ - assert(idict != 0); - assert(p != NULL); a[0] = a[3] = 1.0e6; a[1] = a[2] = 0; if (img_type(idict) == IMG_TYPE_PDF || img_type(idict) == IMG_TYPE_PDFMEMSTREAM @@ -58,7 +55,7 @@ void place_img(PDF pdf, image_dict * idict, scaled_whd dim, int transform) xoff = yoff = 0; r = 4; } - if ((transform & 7) > 3) { // mirror cases + if ((transform & 7) > 3) { /* mirror cases */ a[0] *= -1; xoff *= -1; } @@ -146,7 +143,6 @@ void pdf_place_image(PDF pdf, halfword p) { scaled_whd dim; image_dict *idict = idict_array[rule_index(p)]; - assert(idict != NULL); dim.wd = width(p); dim.ht = height(p); dim.dp = depth(p); diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdflink.h b/Build/source/texk/web2c/luatexdir/pdf/pdflink.h index b7103aec56e..5b3d2042a80 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdflink.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdflink.h @@ -15,13 +15,13 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ - + with LuaTeX; if not, see . +*/ #ifndef PDFLINK_H # define PDFLINK_H -# define set_pdf_link_attr(A,B) pdf_link_attr(A)=B +# define set_pdf_link_attr(A,B) pdf_link_attr(A)=B # define set_pdf_link_action(A,B) pdf_link_action(A)=B # define set_pdf_link_objnum(A,B) pdf_link_objnum(A)=B @@ -29,9 +29,7 @@ extern void push_link_level(PDF pdf, halfword p); extern void pop_link_level(PDF pdf); extern void do_link(PDF pdf, halfword p, halfword parent_box, scaledpos cur); extern void end_link(PDF pdf, halfword p); -extern void append_link(PDF pdf, halfword parent_box, scaledpos cur, - small_number i); - +extern void append_link(PDF pdf, halfword parent_box, scaledpos cur, small_number i); extern void scan_startlink(PDF pdf); diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdflink.w b/Build/source/texk/web2c/luatexdir/pdf/pdflink.w index 89fb1057567..b21d0774ecd 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdflink.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdflink.w @@ -19,7 +19,6 @@ @ @c - #include "ptexlib.h" @ To implement nested link annotations, we need a stack to hold copy of @@ -31,7 +30,6 @@ void push_link_level(PDF pdf, halfword p) { if (pdf->link_stack_ptr >= pdf_max_link_level) overflow("pdf link stack size", pdf_max_link_level); - assert(((type(p) == whatsit_node) && (subtype(p) == pdf_start_link_node))); pdf->link_stack_ptr++; pdf->link_stack[pdf->link_stack_ptr].nesting_level = cur_s; pdf->link_stack[pdf->link_stack_ptr].link_node = copy_node_list(p); @@ -41,7 +39,6 @@ void push_link_level(PDF pdf, halfword p) @ @c void pop_link_level(PDF pdf) { - assert(pdf->link_stack_ptr > 0); flush_node_list(pdf->link_stack[pdf->link_stack_ptr].link_node); pdf->link_stack_ptr--; } @@ -54,8 +51,7 @@ void do_link(PDF pdf, halfword p, halfword parent_box, scaledpos cur) if (type(p) == vlist_node) normal_error("pdf backend", "'startlink' ended up in vlist"); if (global_shipping_mode == SHIPPING_FORM) - normal_error("pdf backend", "link annotations cannot be inside an XForm"); - assert(type(parent_box) == hlist_node); + normal_error("pdf backend", "link annotations cannot be inside an xform"); if (is_obj_scheduled(pdf, pdf_link_objnum(p))) pdf_link_objnum(p) = pdf_create_obj(pdf, obj_type_others, 0); push_link_level(pdf, p); @@ -80,32 +76,34 @@ void end_link(PDF pdf, halfword p) normal_error("pdf backend","pdf link_stack empty, 'endlink' used without 'startlink'"); if (pdf->link_stack[pdf->link_stack_ptr].nesting_level != cur_s) normal_error("pdf backend","'endlink' ended up in different nesting level than 'startlink'"); - - /* N.B.: test for running link must be done on |link_node| and not |ref_link_node|, - as |ref_link_node| can be set by |do_link| or |append_link| already */ - + /* + NOTA BENE: test for running link must be done on |link_node| and not + |ref_link_node|, as |ref_link_node| can be set by |do_link| or + |append_link| already + */ if (is_running(width(pdf->link_stack[pdf->link_stack_ptr].link_node))) { q = pdf->link_stack[pdf->link_stack_ptr].ref_link_node; if (global_shipping_mode == SHIPPING_PAGE && matrixused()) { - matrixrecalculate(pos.h + pdf_link_margin); + matrixrecalculate(pos.h + pdf_link_margin); pdf_ann_left(q) = getllx() - pdf_link_margin; pdf_ann_top(q) = getlly() - pdf_link_margin; pdf_ann_right(q) = geturx() + pdf_link_margin; pdf_ann_bottom(q) = getury() + pdf_link_margin; } else { switch (pdf->posstruct->dir) { - case dir_TLT: - pdf_ann_right(q) = pos.h + pdf_link_margin; - break; - case dir_TRT: - pdf_ann_left(q) = pos.h - pdf_link_margin; - break; - case dir_LTL: - case dir_RTT: - pdf_ann_bottom(q) = pos.v - pdf_link_margin; - break; - default: - assert(0); + case dir_TLT: + pdf_ann_right(q) = pos.h + pdf_link_margin; + break; + case dir_TRT: + pdf_ann_left(q) = pos.h - pdf_link_margin; + break; + case dir_LTL: + case dir_RTT: + pdf_ann_bottom(q) = pos.v - pdf_link_margin; + break; + default: + pdf_ann_right(q) = pos.h + pdf_link_margin; + formatted_warning("pdf backend","forcing bad dir %i to TLT in link",pdf->posstruct->dir); } } } @@ -114,10 +112,9 @@ void end_link(PDF pdf, halfword p) @ For ``running'' annotations we must append a new node when the end of annotation is in other box than its start. The new created node is identical to -corresponding whatsit node representing the start of annotation, but its -|info| field is |max_halfword|. We set |info| field just before destroying the -node, in order to use |flush_node_list| to do the job. - +corresponding whatsit node representing the start of annotation, but its |info| +field is |max_halfword|. We set |info| field just before destroying the node, in +order to use |flush_node_list| to do the job. @ Append a new pdf annot to |pdf_link_list|. @@ -127,7 +124,6 @@ void append_link(PDF pdf, halfword parent_box, scaledpos cur, small_number i) halfword p; int k; scaled_whd alt_rule; - assert(type(parent_box) == hlist_node); p = copy_node(pdf->link_stack[(int) i].link_node); pdf->link_stack[(int) i].ref_link_node = p; subtype(p) = pdf_link_data_node; /* this node is not a normal link node */ @@ -152,14 +148,17 @@ void scan_startlink(PDF pdf) new_annot_whatsit(pdf_start_link_node); set_pdf_link_attr(cur_list.tail_field, null); if (scan_keyword("attr")) { - scan_pdf_ext_toks(); + scan_toks(false, true); set_pdf_link_attr(cur_list.tail_field, def_ref); } r = scan_action(pdf); set_pdf_link_action(cur_list.tail_field, r); set_pdf_link_objnum(cur_list.tail_field, k); pdf_last_link = k; - /* N.B.: although it is possible to set |obj_annot_ptr(k) := tail| here, it - is not safe if nodes are later copied/destroyed/moved; a better place - to do this is inside |do_link|, when the whatsit node is written out */ + /* + NOTA BENE: although it is possible to set |obj_annot_ptr(k) := tail| + here, it is not safe if nodes are later copied/destroyed/moved; a better + place to do this is inside |do_link|, when the whatsit node is written + out + */ } diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdflistout.h b/Build/source/texk/web2c/luatexdir/pdf/pdflistout.h index 646a26b855a..76c1d552f1a 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdflistout.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdflistout.h @@ -15,24 +15,23 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ - + with LuaTeX; if not, see . +*/ #ifndef PDFLISTOUT_H # define PDFLISTOUT_H -/* a few small helpers */ # define pos_right(A) pdf->posstruct->pos.h = pdf->posstruct->pos.h + (A) # define pos_left(A) pdf->posstruct->pos.h = pdf->posstruct->pos.h - (A) # define pos_up(A) pdf->posstruct->pos.v = pdf->posstruct->pos.v + (A) # define pos_down(A) pdf->posstruct->pos.v = pdf->posstruct->pos.v - (A) -typedef void (*backend_function) (); /* variadic arguments */ +typedef void (*backend_function) (); /* variadic arguments */ typedef struct { - char *name; /* name of the backend */ - backend_function *node_fu; /* array of node output functions */ - backend_function *whatsit_fu; /* array of whatsit output functions */ + char *name; /* name of the backend */ + backend_function *node_fu; /* array of node output functions */ + backend_function *whatsit_fu; /* array of whatsit output functions */ } backend_struct; extern pos_info_structure pos_info; @@ -42,8 +41,8 @@ extern backend_function *backend_out_whatsit; extern void init_backend_functionpointers(output_mode o_mode); -extern void hlist_out(PDF pdf, halfword this_box); -extern void vlist_out(PDF pdf, halfword this_box); +extern void hlist_out(PDF pdf, halfword this_box, int rule_callback_id); +extern void vlist_out(PDF pdf, halfword this_box, int rule_callback_id); extern void out_what(PDF pdf, halfword p); #endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdflistout.w b/Build/source/texk/web2c/luatexdir/pdf/pdflistout.w index bf32cb8c629..2bd15f3cedf 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdflistout.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdflistout.w @@ -31,21 +31,11 @@ backend_function *backend_out, *backend_out_whatsit; @ @c static void missing_backend_function(PDF pdf, halfword p) { - char *b; - const char *s; - const char *n; - char backend_string[15]; - char err_string[60]; - assert(backend != NULL); + const char *n = get_node_name(type(p), subtype(p)); if (type(p) == whatsit_node) - s = "whatsit"; + formatted_error("pdf backend","no output function for whatsit %s",n); else - s = "node"; - n = get_node_name(type(p), subtype(p)); - b = backend[output_mode_used].name; - snprintf(backend_string, strlen(b) + 10, "%s back-end", b); - snprintf(err_string, 59, "no output function for \"%s\" %s", n, s); - normal_error(backend_string, err_string); + formatted_error("pdf backend","no output function for node %s",n); } @ @c @@ -89,7 +79,6 @@ static void init_dvi_backend_functions(void) p->whatsit_fu[late_lua_node] = &late_lua; } - @ @c void init_backend_functionpointers(output_mode o_mode) { @@ -126,22 +115,22 @@ static scaled simple_advance_width(halfword p) while ((q != null) && (vlink(q) != null)) { q = vlink(q); switch (type(q)) { - case glyph_node: - w += glyph_width(q); - break; - case hlist_node: - case vlist_node: - case rule_node: - case margin_kern_node: - case kern_node: - w += width(q); - break; - case disc_node: - /* hh: the frontend should append already */ - if (vlink(no_break(q)) != null) - w += simple_advance_width(no_break(q)); - default: - break; + case glyph_node: + w += glyph_width(q); + break; + case hlist_node: + case vlist_node: + case rule_node: + case margin_kern_node: + case kern_node: + w += width(q); + break; + case disc_node: + /* hh: the frontend should append already */ + if (vlink(no_break(q)) != null) + w += simple_advance_width(no_break(q)); + default: + break; } } return w; @@ -163,60 +152,60 @@ static halfword calculate_width_to_enddir(halfword p, real cur_glue, scaled cur_ w += pack_width(box_dir(this_box), dir_TRT, q, true); else { switch (type(q)) { - case hlist_node: - case vlist_node: - w += pack_width(box_dir(this_box), box_dir(q), q, false); - break; - case rule_node: - case margin_kern_node: - case kern_node: - w += width(q); - break; - case math_node: - /* begin mathskip code */ - if (glue_ptr(q) == zero_glue) { - w += surround(q); + case hlist_node: + case vlist_node: + w += pack_width(box_dir(this_box), box_dir(q), q, false); break; - } else { - /* fall through: mathskip */ - } - /* end mathskip code */ - case glue_node: - g = glue_ptr(q); - w += width(g) - cur_g; - if (g_sign != normal) { - if (g_sign == stretching) { - if (stretch_order(g) == g_order) { - cur_glue = cur_glue + stretch(g); + case rule_node: + case margin_kern_node: + case kern_node: + w += width(q); + break; + case math_node: + /* begin mathskip code */ + if (glue_ptr(q) == zero_glue) { + w += surround(q); + break; + } else { + /* fall through: mathskip */ + } + /* end mathskip code */ + case glue_node: + g = glue_ptr(q); + w += width(g) - cur_g; + if (g_sign != normal) { + if (g_sign == stretching) { + if (stretch_order(g) == g_order) { + cur_glue = cur_glue + stretch(g); + vet_glue(float_cast(glue_set(this_box)) * cur_glue); + cur_g = float_round(glue_temp); + } + } else if (shrink_order(g) == g_order) { + cur_glue = cur_glue - shrink(g); vet_glue(float_cast(glue_set(this_box)) * cur_glue); cur_g = float_round(glue_temp); } - } else if (shrink_order(g) == g_order) { - cur_glue = cur_glue - shrink(g); - vet_glue(float_cast(glue_set(this_box)) * cur_glue); - cur_g = float_round(glue_temp); } - } - w += cur_g; - break; - case disc_node: - /* hh: the frontend should append already */ - if (vlink(no_break(q)) != null) - w += simple_advance_width(no_break(q)); - break; - case dir_node: - if (dir_dir(q) >= 0) - dir_nest++; - else - dir_nest--; - if (dir_nest == 0) { - enddir_ptr = q; - dir_cur_h(enddir_ptr) = w; - q = null; - } - break; - default: - break; + w += cur_g; + break; + case disc_node: + /* hh: the frontend should append already */ + if (vlink(no_break(q)) != null) + w += simple_advance_width(no_break(q)); + break; + case dir_node: + if (dir_dir(q) >= 0) + dir_nest++; + else + dir_nest--; + if (dir_nest == 0) { + enddir_ptr = q; + dir_cur_h(enddir_ptr) = w; + q = null; + } + break; + default: + break; } } } @@ -237,56 +226,55 @@ implementations, due to machine-dependent rounding in the glue calculations.) @c void out_what(PDF pdf, halfword p) { - switch (subtype(p)) { /* function(pdf, p) */ - case special_node: /* |pdf_special(pdf, p)|; */ - case late_lua_node: /* |late_lua(pdf, p)|; */ - case pdf_save_node: /* |pdf_out_save(pdf, p)|; */ - case pdf_restore_node: /* |pdf_out_restore(pdf, p)|; */ - case pdf_end_link_node: /* |end_link(pdf, p)|; */ - case pdf_end_thread_node: /* |end_thread(pdf, p)|; */ - case pdf_literal_node: /* |pdf_out_literal(pdf, p)|; */ - case pdf_colorstack_node: /* |pdf_out_colorstack(pdf, p)|; */ - case pdf_setmatrix_node: /* |pdf_out_setmatrix(pdf, p)|; */ - case pdf_refobj_node: /* |pdf_ref_obj(pdf, p)| */ - backend_out_whatsit[subtype(p)] (pdf, p); - break; - case open_node: - case write_node: - case close_node: - /* do some work that has been queued up for \.{\\write} */ - if (!doing_leaders) { - int j = write_stream(p); - if (subtype(p) == write_node) { - write_out(p); - } else if (subtype(p) == close_node) { - close_write_file(j); - } else if (valid_write_file(j)) { - char *fn; - close_write_file(j); - cur_name = open_name(p); - cur_area = open_area(p); - cur_ext = open_ext(p); - if (cur_ext == get_nullstr()) - cur_ext = maketexstring(".tex"); - fn = pack_file_name(cur_name, cur_area, cur_ext); - while (! open_write_file(j,fn)) { - fn = prompt_file_name("output file name", ".tex"); + switch (subtype(p)) { + case special_node: /* |pdf_special(pdf, p)|; */ + case late_lua_node: /* |late_lua(pdf, p)|; */ + case pdf_save_node: /* |pdf_out_save(pdf, p)|; */ + case pdf_restore_node: /* |pdf_out_restore(pdf, p)|; */ + case pdf_end_link_node: /* |end_link(pdf, p)|; */ + case pdf_end_thread_node: /* |end_thread(pdf, p)|; */ + case pdf_literal_node: /* |pdf_out_literal(pdf, p)|; */ + case pdf_colorstack_node: /* |pdf_out_colorstack(pdf, p)|; */ + case pdf_setmatrix_node: /* |pdf_out_setmatrix(pdf, p)|; */ + case pdf_refobj_node: /* |pdf_ref_obj(pdf, p)| */ + backend_out_whatsit[subtype(p)] (pdf, p); + break; + case open_node: + case write_node: + case close_node: + /* do some work that has been queued up for \.{\\write} */ + if (!doing_leaders) { + int j = write_stream(p); + if (subtype(p) == write_node) { + write_out(p); + } else if (subtype(p) == close_node) { + close_write_file(j); + } else if (valid_write_file(j)) { + char *fn; + close_write_file(j); + cur_name = open_name(p); + cur_area = open_area(p); + cur_ext = open_ext(p); + if (cur_ext == get_nullstr()) + cur_ext = maketexstring(".tex"); + fn = pack_file_name(cur_name, cur_area, cur_ext); + while (! open_write_file(j,fn)) { + fn = prompt_file_name("output file name", ".tex"); + } } } - } - break; - case user_defined_node: - break; - default: - /* this should give an error about missing whatsit backend function */ - backend_out_whatsit[subtype(p)] (pdf, p); + break; + case user_defined_node: + break; + default: + /* this should give an error about missing whatsit backend function */ + backend_out_whatsit[subtype(p)] (pdf, p); } } @ @c -void hlist_out(PDF pdf, halfword this_box) +void hlist_out(PDF pdf, halfword this_box, int rule_callback_id) { - posstructure localpos; /* the position structure local within this function */ posstructure *refpos; /* the list origin pos. on the page, provided by the caller */ scaledpos cur = { 0, 0 }, tmpcur, basepoint; @@ -333,7 +321,6 @@ void hlist_out(PDF pdf, halfword this_box) } for (i = 1; i <= pdf->link_stack_ptr; i++) { - assert(is_running(width(pdf->link_stack[i].link_node))); if (pdf->link_stack[i].nesting_level == cur_s) append_link(pdf, this_box, cur, (small_number) i); } @@ -362,302 +349,305 @@ void hlist_out(PDF pdf, halfword this_box) } else { /* output the non-|char_node| |p| for |hlist_out| and move to the next node */ switch (type(p)) { - case hlist_node: - case vlist_node: - if (textdir_parallel(box_dir(p), localpos.dir)) { - effective_horizontal = width(p); - basepoint.v = 0; - if (textdir_opposite(box_dir(p), localpos.dir)) - basepoint.h = width(p); - else - basepoint.h = 0; - } else { - effective_horizontal = height(p) + depth(p); - if (!is_mirrored(box_dir(p))) { - if (partextdir_eq(box_dir(p), localpos.dir)) - basepoint.h = height(p); + case hlist_node: + case vlist_node: + if (textdir_parallel(box_dir(p), localpos.dir)) { + effective_horizontal = width(p); + basepoint.v = 0; + if (textdir_opposite(box_dir(p), localpos.dir)) + basepoint.h = width(p); else - basepoint.h = depth(p); + basepoint.h = 0; } else { - if (partextdir_eq(box_dir(p), localpos.dir)) - basepoint.h = depth(p); - else - basepoint.h = height(p); + effective_horizontal = height(p) + depth(p); + if (!is_mirrored(box_dir(p))) { + if (partextdir_eq(box_dir(p), localpos.dir)) + basepoint.h = height(p); + else + basepoint.h = depth(p); + } else { + if (partextdir_eq(box_dir(p), localpos.dir)) + basepoint.h = depth(p); + else + basepoint.h = height(p); + } + if (is_rotated(localpos.dir)) { + if (partextdir_eq(localpos.dir, box_dir(p))) + basepoint.v = -width(p) / 2; /* up */ + else + basepoint.v = width(p) / 2; /* down */ + } else if (is_mirrored(localpos.dir)) { + if (partextdir_eq(localpos.dir, box_dir(p))) + basepoint.v = 0; + else + basepoint.v = width(p); /* down */ + } else { + if (partextdir_eq(localpos.dir, box_dir(p))) + basepoint.v = -width(p); /* up */ + else + basepoint.v = 0; + } } - if (is_rotated(localpos.dir)) { - if (partextdir_eq(localpos.dir, box_dir(p))) - basepoint.v = -width(p) / 2; /* up */ - else - basepoint.v = width(p) / 2; /* down */ - } else if (is_mirrored(localpos.dir)) { - if (partextdir_eq(localpos.dir, box_dir(p))) - basepoint.v = 0; - else - basepoint.v = width(p); /* down */ + if (!is_mirrored(localpos.dir)) + basepoint.v = basepoint.v + shift_amount(p); /* shift the box down */ + else + basepoint.v = basepoint.v - shift_amount(p); /* shift the box up */ + if (list_ptr(p) == null) { + if (synctex) { + if (type(p) == vlist_node) + synctexvoidvlist(p, this_box); + else + synctexvoidhlist(p, this_box); + } } else { - if (partextdir_eq(localpos.dir, box_dir(p))) - basepoint.v = -width(p); /* up */ - else - basepoint.v = 0; - } - } - if (!is_mirrored(localpos.dir)) - basepoint.v = basepoint.v + shift_amount(p); /* shift the box down */ - else - basepoint.v = basepoint.v - shift_amount(p); /* shift the box up */ - if (list_ptr(p) == null) { - if (synctex) { + tmpcur.h = cur.h + basepoint.h; + tmpcur.v = basepoint.v; + synch_pos_with_cur(pdf->posstruct, refpos, tmpcur); if (type(p) == vlist_node) - synctexvoidvlist(p, this_box); + vlist_out(pdf, p, rule_callback_id); else - synctexvoidhlist(p, this_box); + hlist_out(pdf, p, rule_callback_id); } - } else { - assert(cur.v == 0); - tmpcur.h = cur.h + basepoint.h; - tmpcur.v = basepoint.v; - synch_pos_with_cur(pdf->posstruct, refpos, tmpcur); - if (type(p) == vlist_node) - vlist_out(pdf, p); - else - hlist_out(pdf, p); - } - cur.h += effective_horizontal; - break; - case disc_node: - /* hh: the frontend should append already */ - if (vlink(no_break(p)) != null) { - if (subtype(p) != select_disc) { - q = tail_of_list(vlink(no_break(p))); /* this could be a tlink */ - vlink(q) = vlink(p); - q = vlink(no_break(p)); - vlink(no_break(p)) = null; - vlink(p) = q; - } - } - break; - case rule_node: - if (rule_dir(p) < 0) - rule_dir(p) = localpos.dir; - if (pardir_parallel(rule_dir(p), localpos.dir)) { - rule.ht = height(p); - rule.dp = depth(p); - rule.wd = width(p); - } else { - rule.ht = width(p) / 2; - rule.dp = width(p) / 2; - rule.wd = height(p) + depth(p); - } - goto FIN_RULE; - break; - case dir_node: - /* output a reflection instruction if the direction has changed */ - if (dir_dir(p) >= 0) { - /* - Calculate the needed width to the matching |enddir|, return the - |enddir| node, with width info - */ - enddir_ptr = calculate_width_to_enddir(p, cur_glue, cur_g, this_box); - if (textdir_parallel(dir_dir(p), localpos.dir)) { - dir_cur_h(enddir_ptr) += cur.h; - if (textdir_opposite(dir_dir(p), localpos.dir)) - cur.h = dir_cur_h(enddir_ptr); - } else - dir_cur_h(enddir_ptr) = cur.h; - if (enddir_ptr != p) { - /* only if it is an enddir */ - dir_cur_v(enddir_ptr) = cur.v; - dir_refpos_h(enddir_ptr) = refpos->pos.h; - dir_refpos_v(enddir_ptr) = refpos->pos.v; - /* negative: mark it as |enddir| */ - dir_dir(enddir_ptr) = localpos.dir - dir_swap; - } - /* fake a nested |hlist_out| */ - synch_pos_with_cur(pdf->posstruct, refpos, cur); - refpos->pos = pdf->posstruct->pos; - localpos.dir = dir_dir(p); - cur.h = 0; - cur.v = 0; - } else { - refpos->pos.h = dir_refpos_h(p); - refpos->pos.v = dir_refpos_v(p); - localpos.dir = dir_dir(p) + dir_swap; - cur.h = dir_cur_h(p); - cur.v = dir_cur_v(p); - } - break; - case whatsit_node: - /* output the whatsit node |p| in |hlist_out| */ - switch (subtype(p)) { - case save_pos_node: - last_position = pdf->posstruct->pos; - pos_info.curpos = pdf->posstruct->pos; - pos_info.boxpos.pos = refpos->pos; - pos_info.boxpos.dir = localpos.dir; - pos_info.boxdim.wd = width(this_box); - pos_info.boxdim.ht = height(this_box); - pos_info.boxdim.dp = depth(this_box); - break; - case pdf_annot_node: - case pdf_start_link_node: - case pdf_dest_node: - case pdf_start_thread_node: - case pdf_thread_node: - backend_out_whatsit[subtype(p)] (pdf, p, this_box, cur); + cur.h += effective_horizontal; break; - default: - out_what(pdf, p); - } - break; - case math_node: - if (synctex) { - synctexmath(p, this_box); - } - /* begin mathskip code */ - if (glue_ptr(p) == zero_glue) { - cur.h += surround(p); + case disc_node: + /* hh: the frontend should append already */ + if (vlink(no_break(p)) != null) { + if (subtype(p) != select_disc) { + q = tail_of_list(vlink(no_break(p))); /* this could be a tlink */ + vlink(q) = vlink(p); + q = vlink(no_break(p)); + vlink(no_break(p)) = null; + vlink(p) = q; + } + } break; - } else { - /* fall through: mathskip */ - } - /* end mathskip code */ - case glue_node: - { - /* move right or output leaders, we use real multiplication */ - halfword g = glue_ptr(p); - rule.wd = width(g) - cur_g; - if (g_sign != normal) { - if (g_sign == stretching) { - if (stretch_order(g) == g_order) { - cur_glue = cur_glue + stretch(g); + case glue_node: + { + /* move right or output leaders, we use real multiplication */ + halfword g = glue_ptr(p); + rule.wd = width(g) - cur_g; + if (g_sign != normal) { + if (g_sign == stretching) { + if (stretch_order(g) == g_order) { + cur_glue = cur_glue + stretch(g); + vet_glue(float_cast(glue_set(this_box)) * cur_glue); + cur_g = float_round(glue_temp); + } + } else if (shrink_order(g) == g_order) { + cur_glue = cur_glue - shrink(g); vet_glue(float_cast(glue_set(this_box)) * cur_glue); cur_g = float_round(glue_temp); } - } else if (shrink_order(g) == g_order) { - cur_glue = cur_glue - shrink(g); - vet_glue(float_cast(glue_set(this_box)) * cur_glue); - cur_g = float_round(glue_temp); - } - } - rule.wd = rule.wd + cur_g; - if (subtype(p) >= a_leaders) { - /* output leaders in an hlist, |goto fin_rule| if a rule or to |next_p| if done */ - leader_box = leader_ptr(p); - if (type(leader_box) == rule_node) { - rule.ht = height(leader_box); - rule.dp = depth(leader_box); - goto FIN_RULE; } - if (textdir_parallel(box_dir(leader_box), localpos.dir)) - leader_wd = width(leader_box); - else - leader_wd = height(leader_box) + depth(leader_box); - if ((leader_wd > 0) && (rule.wd > 0)) { - rule.wd = rule.wd + 10; /* compensate for floating-point rounding */ - edge = cur.h + rule.wd; - lx = 0; - /* - let |cur.h| be the position of the first box, and set |leader_wd+lx| - to the spacing between corresponding parts of boxes - */ - if (subtype(p) == g_leaders) { - save_h = cur.h; - switch (localpos.dir) { - case dir_TLT: - cur.h += refpos->pos.h - shipbox_refpos.h; - cur.h = leader_wd * (cur.h / leader_wd); - cur.h -= refpos->pos.h - shipbox_refpos.h; - break; - case dir_TRT: - cur.h = refpos->pos.h - shipbox_refpos.h - cur.h; - cur.h = leader_wd * (cur.h / leader_wd); - cur.h = refpos->pos.h - shipbox_refpos.h - cur.h; - break; - case dir_LTL: - case dir_RTT: - cur.h = refpos->pos.v - shipbox_refpos.v - cur.h; + rule.wd = rule.wd + cur_g; + if (subtype(p) >= a_leaders) { + /* output leaders in an hlist, |goto fin_rule| if a rule or to |next_p| if done */ + leader_box = leader_ptr(p); + if (type(leader_box) == rule_node) { + rule.ht = height(leader_box); + rule.dp = depth(leader_box); + goto FIN_RULE; + } + if (textdir_parallel(box_dir(leader_box), localpos.dir)) + leader_wd = width(leader_box); + else + leader_wd = height(leader_box) + depth(leader_box); + if ((leader_wd > 0) && (rule.wd > 0)) { + rule.wd = rule.wd + 10; /* compensate for floating-point rounding */ + edge = cur.h + rule.wd; + lx = 0; + /* + let |cur.h| be the position of the first box, and set |leader_wd+lx| + to the spacing between corresponding parts of boxes + */ + if (subtype(p) == g_leaders) { + save_h = cur.h; + switch (localpos.dir) { + case dir_TLT: + cur.h += refpos->pos.h - shipbox_refpos.h; + cur.h = leader_wd * (cur.h / leader_wd); + cur.h -= refpos->pos.h - shipbox_refpos.h; + break; + case dir_TRT: + cur.h = refpos->pos.h - shipbox_refpos.h - cur.h; + cur.h = leader_wd * (cur.h / leader_wd); + cur.h = refpos->pos.h - shipbox_refpos.h - cur.h; + break; + case dir_LTL: + case dir_RTT: + cur.h = refpos->pos.v - shipbox_refpos.v - cur.h; + cur.h = leader_wd * (cur.h / leader_wd); + cur.h = refpos->pos.v - shipbox_refpos.v - cur.h; + break; + default: + formatted_warning("pdf backend","forcing bad dir %i to TLT in hlist case 1",localpos.dir); + localpos.dir = dir_TLT; + cur.h += refpos->pos.h - shipbox_refpos.h; + cur.h = leader_wd * (cur.h / leader_wd); + cur.h -= refpos->pos.h - shipbox_refpos.h; + break; + } + if (cur.h < save_h) + cur.h += leader_wd; + } else if (subtype(p) == a_leaders) { + save_h = cur.h; cur.h = leader_wd * (cur.h / leader_wd); - cur.h = refpos->pos.v - shipbox_refpos.v - cur.h; - break; - default: - assert(0); - } - if (cur.h < save_h) - cur.h += leader_wd; - } else if (subtype(p) == a_leaders) { - save_h = cur.h; - cur.h = leader_wd * (cur.h / leader_wd); - if (cur.h < save_h) - cur.h += leader_wd; - } else { - lq = rule.wd / leader_wd; /* the number of box copies */ - lr = rule.wd % leader_wd; /* the remaining space */ - if (subtype(p) == c_leaders) { - cur.h += lr / 2; + if (cur.h < save_h) + cur.h += leader_wd; } else { - lx = lr / (lq + 1); - cur.h += (lr - (lq - 1) * lx) / 2; + lq = rule.wd / leader_wd; /* the number of box copies */ + lr = rule.wd % leader_wd; /* the remaining space */ + if (subtype(p) == c_leaders) { + cur.h += lr / 2; + } else { + lx = lr / (lq + 1); + cur.h += (lr - (lq - 1) * lx) / 2; + } } - } - while (cur.h + leader_wd <= edge) { - /* output a leader box at |cur.h|, then advance |cur.h| by |leader_wd+lx| */ - if (pardir_parallel(box_dir(leader_box), localpos.dir)) { - basepoint.v = 0; - if (textdir_opposite(box_dir(leader_box), localpos.dir)) - basepoint.h = width(leader_box); - else - basepoint.h = 0; - } else { - if (!is_mirrored(box_dir(leader_box))) { - if (partextdir_eq(box_dir(leader_box), localpos.dir)) - basepoint.h = height(leader_box); + while (cur.h + leader_wd <= edge) { + /* output a leader box at |cur.h|, then advance |cur.h| by |leader_wd+lx| */ + if (pardir_parallel(box_dir(leader_box), localpos.dir)) { + basepoint.v = 0; + if (textdir_opposite(box_dir(leader_box), localpos.dir)) + basepoint.h = width(leader_box); else - basepoint.h = depth(leader_box); + basepoint.h = 0; } else { - if (partextdir_eq(box_dir(leader_box), localpos.dir)) - basepoint.h = depth(leader_box); + if (!is_mirrored(box_dir(leader_box))) { + if (partextdir_eq(box_dir(leader_box), localpos.dir)) + basepoint.h = height(leader_box); + else + basepoint.h = depth(leader_box); + } else { + if (partextdir_eq(box_dir(leader_box), localpos.dir)) + basepoint.h = depth(leader_box); + else + basepoint.h = height(leader_box); + } + if (partextdir_eq(localpos.dir, box_dir(leader_box))) + basepoint.v = -(width(leader_box) / 2); else - basepoint.h = height(leader_box); + basepoint.v = (width(leader_box) / 2); } - if (partextdir_eq(localpos.dir, box_dir(leader_box))) - basepoint.v = -(width(leader_box) / 2); + if (!is_mirrored(localpos.dir)) + basepoint.v = basepoint.v + shift_amount(leader_box); /* shift the box down */ + else + basepoint.v = basepoint.v - shift_amount(leader_box); /* shift the box up */ + tmpcur.h = cur.h + basepoint.h; + tmpcur.v = basepoint.v; + synch_pos_with_cur(pdf->posstruct, refpos, tmpcur); + outer_doing_leaders = doing_leaders; + doing_leaders = true; + if (type(leader_box) == vlist_node) + vlist_out(pdf, leader_box, rule_callback_id); else - basepoint.v = (width(leader_box) / 2); + hlist_out(pdf, leader_box, rule_callback_id); + doing_leaders = outer_doing_leaders; + cur.h += leader_wd + lx; } - if (!is_mirrored(localpos.dir)) - basepoint.v = basepoint.v + shift_amount(leader_box); /* shift the box down */ - else - basepoint.v = basepoint.v - shift_amount(leader_box); /* shift the box up */ - assert(cur.v == 0); - tmpcur.h = cur.h + basepoint.h; - tmpcur.v = basepoint.v; - synch_pos_with_cur(pdf->posstruct, refpos, tmpcur); - outer_doing_leaders = doing_leaders; - doing_leaders = true; - if (type(leader_box) == vlist_node) - vlist_out(pdf, leader_box); - else - hlist_out(pdf, leader_box); - doing_leaders = outer_doing_leaders; - cur.h += leader_wd + lx; + cur.h = edge - 10; + goto NEXTP; } - cur.h = edge - 10; - goto NEXTP; } - } - } - goto MOVE_PAST; - break; - case margin_kern_node: - cur.h += width(p); - break; - case kern_node: - if (synctex) - synctexkern(p, this_box); - cur.h += width(p); - break; - default: - break; + } + goto MOVE_PAST; + break; + case kern_node: + if (synctex) + synctexkern(p, this_box); + cur.h += width(p); + break; + case rule_node: + if (rule_dir(p) < 0) + rule_dir(p) = localpos.dir; + if (pardir_parallel(rule_dir(p), localpos.dir)) { + rule.ht = height(p); + rule.dp = depth(p); + rule.wd = width(p); + } else { + rule.ht = width(p) / 2; + rule.dp = width(p) / 2; + rule.wd = height(p) + depth(p); + } + goto FIN_RULE; + break; + case dir_node: + /* output a reflection instruction if the direction has changed */ + if (dir_dir(p) >= 0) { + /* + Calculate the needed width to the matching |enddir|, return the + |enddir| node, with width info + */ + enddir_ptr = calculate_width_to_enddir(p, cur_glue, cur_g, this_box); + if (textdir_parallel(dir_dir(p), localpos.dir)) { + dir_cur_h(enddir_ptr) += cur.h; + if (textdir_opposite(dir_dir(p), localpos.dir)) + cur.h = dir_cur_h(enddir_ptr); + } else + dir_cur_h(enddir_ptr) = cur.h; + if (enddir_ptr != p) { + /* only if it is an enddir */ + dir_cur_v(enddir_ptr) = cur.v; + dir_refpos_h(enddir_ptr) = refpos->pos.h; + dir_refpos_v(enddir_ptr) = refpos->pos.v; + /* negative: mark it as |enddir| */ + dir_dir(enddir_ptr) = localpos.dir - dir_swap; + } + /* fake a nested |hlist_out| */ + synch_pos_with_cur(pdf->posstruct, refpos, cur); + refpos->pos = pdf->posstruct->pos; + localpos.dir = dir_dir(p); + cur.h = 0; + cur.v = 0; + } else { + refpos->pos.h = dir_refpos_h(p); + refpos->pos.v = dir_refpos_v(p); + localpos.dir = dir_dir(p) + dir_swap; + cur.h = dir_cur_h(p); + cur.v = dir_cur_v(p); + } + break; + case whatsit_node: + /* output the whatsit node |p| in |hlist_out| */ + switch (subtype(p)) { + case save_pos_node: + last_position = pdf->posstruct->pos; + pos_info.curpos = pdf->posstruct->pos; + pos_info.boxpos.pos = refpos->pos; + pos_info.boxpos.dir = localpos.dir; + pos_info.boxdim.wd = width(this_box); + pos_info.boxdim.ht = height(this_box); + pos_info.boxdim.dp = depth(this_box); + break; + case pdf_annot_node: + case pdf_start_link_node: + case pdf_dest_node: + case pdf_start_thread_node: + case pdf_thread_node: + backend_out_whatsit[subtype(p)] (pdf, p, this_box, cur); + break; + default: + out_what(pdf, p); + } + break; + case math_node: + if (synctex) { + synctexmath(p, this_box); + } + /* begin mathskip code */ + if (glue_ptr(p) == zero_glue) { + cur.h += surround(p); + break; + } else { + /* fall through: mathskip */ + } + /* end mathskip code */ + case margin_kern_node: + cur.h += width(p); + break; + default: + break; } goto NEXTP; FIN_RULE: @@ -669,39 +659,44 @@ void hlist_out(PDF pdf, halfword this_box) /* we don't output empty rules */ if ((rule.ht + rule.dp) > 0 && rule.wd > 0) { switch (localpos.dir) { - case dir_TLT: - size.h = rule.wd; - size.v = rule.ht + rule.dp; - pos_down(rule.dp); - break; - case dir_TRT: - size.h = rule.wd; - size.v = rule.ht + rule.dp; - pos_left(size.h); - pos_down(rule.dp); - break; - case dir_LTL: - size.h = rule.ht + rule.dp; - size.v = rule.wd; - pos_left(rule.ht); - pos_down(size.v); - break; - case dir_RTT: - size.h = rule.ht + rule.dp; - size.v = rule.wd; - pos_left(rule.dp); - pos_down(size.v); - break; - default: - assert(0); + case dir_TLT: + size.h = rule.wd; + size.v = rule.ht + rule.dp; + pos_down(rule.dp); + break; + case dir_TRT: + size.h = rule.wd; + size.v = rule.ht + rule.dp; + pos_left(size.h); + pos_down(rule.dp); + break; + case dir_LTL: + size.h = rule.ht + rule.dp; + size.v = rule.wd; + pos_left(rule.ht); + pos_down(size.v); + break; + case dir_RTT: + size.h = rule.ht + rule.dp; + size.v = rule.wd; + pos_left(rule.dp); + pos_down(size.v); + break; + default: + formatted_warning("pdf backend","forcing bad dir %i to TLT in hlist case 2",localpos.dir); + localpos.dir = dir_TLT; + size.h = rule.wd; + size.v = rule.ht + rule.dp; + pos_down(rule.dp); + break; } if (type(p) == glue_node) { q = leader_ptr(p); if ((q) && (type(q) == rule_node)) { - backend_out[rule_node] (pdf, q, size); + backend_out[rule_node] (pdf, q, size, rule_callback_id); } } else { - backend_out[rule_node] (pdf, p, size); + backend_out[rule_node] (pdf, p, size, rule_callback_id); } } MOVE_PAST: @@ -715,10 +710,8 @@ void hlist_out(PDF pdf, halfword this_box) synch_pos_with_cur(pdf->posstruct, refpos, cur); } } - if (synctex) synctextsilh(this_box); - if (output_mode_used == OMODE_DVI) { prune_movements(save_loc); if (cur_s > 0) { @@ -731,7 +724,7 @@ void hlist_out(PDF pdf, halfword this_box) } @ @c -void vlist_out(PDF pdf, halfword this_box) +void vlist_out(PDF pdf, halfword this_box, int rule_callback_id) { posstructure localpos; /* the position structure local within this function */ posstructure *refpos; /* the list origin pos. on the page, provided by the caller */ @@ -790,11 +783,7 @@ void vlist_out(PDF pdf, halfword this_box) check_running_thread(pdf, this_box, cur); while (p != null) { - if (is_char_node(p)) { - confusion("vlistout"); /* this can't happen */ - } else { - /* output the non-|char_node| |p| for |vlist_out| */ - switch (type(p)) { + switch (type(p)) { case hlist_node: case vlist_node: /* @@ -846,14 +835,13 @@ void vlist_out(PDF pdf, halfword this_box) synctexvoidhlist(p, this_box); } } else { - assert(cur.h == 0); tmpcur.h = basepoint.h; tmpcur.v = cur.v + basepoint.v; synch_pos_with_cur(pdf->posstruct, refpos, tmpcur); if (type(p) == vlist_node) - vlist_out(pdf, p); + vlist_out(pdf, p, rule_callback_id); else - hlist_out(pdf, p); + hlist_out(pdf, p, rule_callback_id); cur.v += effective_vertical; } break; @@ -871,29 +859,6 @@ void vlist_out(PDF pdf, halfword this_box) } goto FIN_RULE; break; - case whatsit_node: - /* output the whatsit node |p| in |vlist_out| */ - switch (subtype(p)) { - case save_pos_node: - last_position = pdf->posstruct->pos; - pos_info.curpos = pdf->posstruct->pos; - pos_info.boxpos.pos = refpos->pos; - pos_info.boxpos.dir = localpos.dir; - pos_info.boxdim.wd = width(this_box); - pos_info.boxdim.ht = height(this_box); - pos_info.boxdim.dp = depth(this_box); - break; - case pdf_annot_node: - case pdf_start_link_node: - case pdf_dest_node: - case pdf_start_thread_node: - case pdf_thread_node: - backend_out_whatsit[subtype(p)] (pdf, p, this_box, cur); - break; - default: - out_what(pdf, p); - } - break; case glue_node: { /* move down or output leaders, we use real multiplication */ @@ -933,24 +898,29 @@ void vlist_out(PDF pdf, halfword this_box) if (subtype(p) == g_leaders) { save_v = cur.v; switch (localpos.dir) { - case dir_LTL: - cur.v += refpos->pos.h - shipbox_refpos.h; - cur.v = leader_ht * (cur.v / leader_ht); - cur.v -= refpos->pos.h - shipbox_refpos.h; - break; - case dir_RTT: - cur.v = refpos->pos.h - shipbox_refpos.h - cur.v; - cur.v = leader_ht * (cur.v / leader_ht); - cur.v = refpos->pos.h - shipbox_refpos.h - cur.v; - break; - case dir_TLT: - case dir_TRT: - cur.v = refpos->pos.v - shipbox_refpos.v - cur.v; - cur.v = leader_ht * (cur.v / leader_ht); - cur.v = refpos->pos.v - shipbox_refpos.v - cur.v; - break; - default: - assert(0); + case dir_LTL: + cur.v += refpos->pos.h - shipbox_refpos.h; + cur.v = leader_ht * (cur.v / leader_ht); + cur.v -= refpos->pos.h - shipbox_refpos.h; + break; + case dir_RTT: + cur.v = refpos->pos.h - shipbox_refpos.h - cur.v; + cur.v = leader_ht * (cur.v / leader_ht); + cur.v = refpos->pos.h - shipbox_refpos.h - cur.v; + break; + case dir_TLT: + case dir_TRT: + cur.v = refpos->pos.v - shipbox_refpos.v - cur.v; + cur.v = leader_ht * (cur.v / leader_ht); + cur.v = refpos->pos.v - shipbox_refpos.v - cur.v; + break; + default: + formatted_warning("pdf backend","forcing bad dir %i to TLT in vlist case 1",localpos.dir); + localpos.dir = dir_TLT; + cur.v += refpos->pos.h - shipbox_refpos.h; + cur.v = leader_ht * (cur.v / leader_ht); + cur.v -= refpos->pos.h - shipbox_refpos.h; + break; } if (cur.v < save_v) cur.v += leader_ht; @@ -972,16 +942,15 @@ void vlist_out(PDF pdf, halfword this_box) while (cur.v + leader_ht <= edge) { /* output a leader box at |cur.v|, then advance |cur.v| by |leader_ht+lx| */ - assert(cur.h == 0); tmpcur.h = shift_amount(leader_box); tmpcur.v = cur.v + height(leader_box); synch_pos_with_cur(pdf->posstruct, refpos, tmpcur); outer_doing_leaders = doing_leaders; doing_leaders = true; if (type(leader_box) == vlist_node) - vlist_out(pdf, leader_box); + vlist_out(pdf, leader_box, rule_callback_id); else - hlist_out(pdf, leader_box); + hlist_out(pdf, leader_box, rule_callback_id); doing_leaders = outer_doing_leaders; cur.v += leader_ht + lx; } @@ -995,17 +964,44 @@ void vlist_out(PDF pdf, halfword this_box) case kern_node: cur.v += width(p); break; + case whatsit_node: + /* output the whatsit node |p| in |vlist_out| */ + switch (subtype(p)) { + case save_pos_node: + last_position = pdf->posstruct->pos; + pos_info.curpos = pdf->posstruct->pos; + pos_info.boxpos.pos = refpos->pos; + pos_info.boxpos.dir = localpos.dir; + pos_info.boxdim.wd = width(this_box); + pos_info.boxdim.ht = height(this_box); + pos_info.boxdim.dp = depth(this_box); + break; + case pdf_annot_node: + case pdf_start_link_node: + case pdf_dest_node: + case pdf_start_thread_node: + case pdf_thread_node: + backend_out_whatsit[subtype(p)] (pdf, p, this_box, cur); + break; + default: + out_what(pdf, p); + } + break; + case glyph_node: + case disc_node: + confusion("vlistout"); /* this can't happen */ + break; default: break; - } - goto NEXTP; - FIN_RULE: - /* output a rule in a vlist, |goto next_p| */ - if (is_running(rule.wd)) - rule.wd = width(this_box); - /* we don't output empty rules */ - if ((rule.ht + rule.dp) > 0 && rule.wd > 0) { - switch (localpos.dir) { + } + goto NEXTP; + FIN_RULE: + /* output a rule in a vlist, |goto next_p| */ + if (is_running(rule.wd)) + rule.wd = width(this_box); + /* we don't output empty rules */ + if ((rule.ht + rule.dp) > 0 && rule.wd > 0) { + switch (localpos.dir) { case dir_TLT: size.h = rule.wd; size.v = rule.ht + rule.dp; @@ -1029,24 +1025,28 @@ void vlist_out(PDF pdf, halfword this_box) pos_down(size.v); break; default: - assert(0); - } - if (type(p) == glue_node) { - q = leader_ptr(p); - if ((q) && (type(q) == rule_node)) { - backend_out[rule_node] (pdf, q, size); - } - } else { - backend_out[rule_node] (pdf, p, size); + formatted_warning("pdf backend","forcing bad dir %i to TLT in vlist case 2",localpos.dir); + localpos.dir = dir_TLT; + size.h = rule.wd; + size.v = rule.ht + rule.dp; + pos_down(size.v); + break; + } + if (type(p) == glue_node) { + q = leader_ptr(p); + if ((q) && (type(q) == rule_node)) { + backend_out[rule_node] (pdf, q, size, rule_callback_id); } + } else { + backend_out[rule_node] (pdf, p, size, rule_callback_id); } - cur.v += rule.ht + rule.dp; - goto NEXTP; - MOVE_PAST: - cur.v += rule.ht; - NEXTP: - p = vlink(p); } + cur.v += rule.ht + rule.dp; + goto NEXTP; + MOVE_PAST: + cur.v += rule.ht; + NEXTP: + p = vlink(p); synch_pos_with_cur(pdf->posstruct, refpos, cur); } if (synctex) diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfliteral.h b/Build/source/texk/web2c/luatexdir/pdf/pdfliteral.h index 134bca44a24..14c197d0f72 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfliteral.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfliteral.h @@ -15,13 +15,13 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ + with LuaTeX; if not, see . +*/ #ifndef PDFLITERAL_H # define PDFLITERAL_H - # define set_pdf_literal_mode(A,B) pdf_literal_mode(A)=B # define set_pdf_literal_type(A,B) pdf_literal_type(A)=B # define set_pdf_literal_data(A,B) pdf_literal_data(A)=B diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfliteral.w b/Build/source/texk/web2c/luatexdir/pdf/pdfliteral.w index dae67234a51..3c6b6f6efbf 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfliteral.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfliteral.w @@ -19,15 +19,13 @@ @ @c - #include "ptexlib.h" @ @c void pdf_special(PDF pdf, halfword p) { - int old_setting; /* holds print |selector| */ + int old_setting = selector; str_number s; - old_setting = selector; selector = new_string; show_token_list(token_link(write_tokens(p)), null, -1); selector = old_setting; @@ -36,11 +34,10 @@ void pdf_special(PDF pdf, halfword p) flush_str(s); } - @ To ship out a \TeX\ box to PDF page description we need to implement -|hlist_out|, |vlist_out| and |ship_out|, which are equivalent to -the \TeX' original |hlist_out|, |vlist_out| and |ship_out| resp. But first we -need to declare some procedures needed in |hlist_out| and |vlist_out|. +|hlist_out|, |vlist_out| and |ship_out|, which are equivalent to the \TeX' +original |hlist_out|, |vlist_out| and |ship_out| resp. But first we need to +declare some procedures needed in |hlist_out| and |vlist_out|. @c void pdf_out_literal(PDF pdf, halfword p) @@ -57,22 +54,21 @@ void pdf_out_literal(PDF pdf, halfword p) pdf_literal(pdf, s, pdf_literal_mode(p), false); flush_str(s); } else { - assert(pdf_literal_mode(p) != scan_special); switch (pdf_literal_mode(p)) { - case set_origin: - pdf_goto_pagemode(pdf); - pdf_set_pos(pdf, pdf->posstruct->pos); - break; - case direct_page: - pdf_goto_pagemode(pdf); - break; - case direct_always: - pdf_end_string_nl(pdf); - ps->need_tm = true; - break; - default: - confusion("literal1"); - break; + case set_origin: + pdf_goto_pagemode(pdf); + pdf_set_pos(pdf, pdf->posstruct->pos); + break; + case direct_page: + pdf_goto_pagemode(pdf); + break; + case direct_always: + pdf_end_string_nl(pdf); + ps->need_tm = true; + break; + default: + normal_error("pdf backend","bad literal mode"); + break; } lua_pdf_literal(pdf, pdf_literal_data(p)); } @@ -101,7 +97,8 @@ void pdf_literal(PDF pdf, str_number s, int literal_mode, boolean warn) size_t l; pool_pointer j = 0; /* current character code position, initialized to make the compiler happy */ pdfstructure *p = pdf->pstruct; - if (s >= STRING_OFFSET) { /* needed for |out_save| */ + if (s >= STRING_OFFSET) { + /* needed for |out_save| */ j = 0; /* the next is obsolete, in fact, specials are obsolete in pdf mode */ if (literal_mode == scan_special) { @@ -123,27 +120,26 @@ void pdf_literal(PDF pdf, str_number s, int literal_mode, boolean warn) } } switch (literal_mode) { - case set_origin: - pdf_goto_pagemode(pdf); - pdf_set_pos(pdf, pdf->posstruct->pos); - break; - case direct_page: - pdf_goto_pagemode(pdf); - break; - case direct_always: - pdf_end_string_nl(pdf); - p->need_tm = true; - break; - default: - confusion("literal1"); - break; + case set_origin: + pdf_goto_pagemode(pdf); + pdf_set_pos(pdf, pdf->posstruct->pos); + break; + case direct_page: + pdf_goto_pagemode(pdf); + break; + case direct_always: + pdf_end_string_nl(pdf); + p->need_tm = true; + break; + default: + normal_error("pdf backend","bad literal mode"); + break; } if (s >= STRING_OFFSET) { ss = str_string(s); l = str_length(s) - (size_t) j; pdf_out_block(pdf, (const char *) (ss + j), l); } else { - assert(s < 256); pdf_out(pdf, s); } pdf_out(pdf, '\n'); diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfluaapi.h b/Build/source/texk/web2c/luatexdir/pdf/pdfluaapi.h deleted file mode 100644 index 3d8652ecc67..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfluaapi.h +++ /dev/null @@ -1,29 +0,0 @@ -/* pdfluaapi.h - - Copyright 2009 Taco Hoekwater - - This file is part of LuaTeX. - - LuaTeX 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. - - LuaTeX 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 Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ - - -#ifndef PDFLUAAPI_H -# define PDFLUAAPI_H - -extern int new_pdflua(void); -extern void pdflua_begin_page(PDF pdf); -extern void pdflua_end_page(PDF pdf, int annots, int beads); -extern void pdflua_output_pages_tree(PDF pdf); - -#endif /* PDFLUAAPI_H */ diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfluaapi.w b/Build/source/texk/web2c/luatexdir/pdf/pdfluaapi.w deleted file mode 100644 index ebd20d6e20d..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfluaapi.w +++ /dev/null @@ -1,113 +0,0 @@ -% pdfluaapi.w -% -% Copyright 2010 Taco Hoekwater -% -% This file is part of LuaTeX. -% -% LuaTeX 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. -% -% LuaTeX 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 Lesser General Public -% License for more details. -% -% You should have received a copy of the GNU General Public License along -% with LuaTeX; if not, see . - -@ @c - - -#include "ptexlib.h" - -@ @c -int new_pdflua(void) -{ - int i, err; - Byte *uncompr; - const zlib_struct *zp = pdflua_zlib_struct_ptr; - uLong uncomprLen = zp->uncomprLen; - if ((uncompr = xtalloc(zp->uncomprLen, Byte)) == NULL) - luatex_fail("new_pdflua(): xtalloc()"); - err = uncompress(uncompr, &uncomprLen, zp->compr, zp->comprLen); - if (err != Z_OK) - luatex_fail("new_pdflua(): uncompress()"); - assert(uncomprLen == zp->uncomprLen); - if (luaL_loadbuffer(Luas, (const char *) uncompr, uncomprLen, "pdflua") - || lua_pcall(Luas, 0, 1, 0)) - luatex_fail("new_pdflua(): lua_pcall()"); - luaL_checktype(Luas, -1, LUA_TTABLE); /* t */ - i = luaL_ref(Luas, LUA_REGISTRYINDEX); /* - */ - xfree(uncompr); - return i; -} - -@ @c -void pdflua_begin_page(PDF pdf) -{ - int err; /* ... */ - lua_rawgeti(Luas, LUA_REGISTRYINDEX, pdf->pdflua_ref); /* t ... */ - lua_pushstring(Luas, "beginpage"); /* s t ... */ - lua_gettable(Luas, -2); /* f t ... */ - lua_newtable(Luas); /* t f t ... */ - lua_pushnumber(Luas, total_pages + 1); /* i t f t ... */ - lua_setfield(Luas, -2, "pagenum"); /* t f t ... */ - lua_pushnumber(Luas, pdf->last_page); /* i t f t ... */ - lua_setfield(Luas, -2, "page_objnum"); /* t f t ... */ - lua_pushnumber(Luas, pdf->last_stream); /* i t f t ... */ - lua_setfield(Luas, -2, "stream_objnum"); /* t f t ... */ - lua_pushnumber(Luas, pdf->page_resources->last_resources); /* i t f t ... */ - lua_setfield(Luas, -2, "resources_objnum"); /* t f t ... */ - err = lua_pcall(Luas, 1, 0, 0); /* (e) t ... */ - if (err != 0) - luatex_fail("pdflua.lua: beginpage()"); - /* t ... */ - lua_pop(Luas, 1); /* ... */ -} - -@ @c -void pdflua_end_page(PDF pdf, int annots, int beads) -{ - int err; /* ... */ - lua_rawgeti(Luas, LUA_REGISTRYINDEX, pdf->pdflua_ref); /* t ... */ - lua_pushstring(Luas, "endpage"); /* s t ... */ - lua_gettable(Luas, -2); /* f t ... */ - lua_newtable(Luas); /* t f t ... */ - lua_pushnumber(Luas, total_pages); /* i t f t ... */ - lua_setfield(Luas, -2, "pagenum"); /* t f t ... */ - lua_pushnumber(Luas, pdf->page_size.h); /* i t f t ... */ - lua_setfield(Luas, -2, "hsize"); /* t f t ... */ - lua_pushnumber(Luas, pdf->page_size.v); /* i t f t ... */ - lua_setfield(Luas, -2, "vsize"); /* t f t ... */ - if (annots != 0) { - lua_pushnumber(Luas, annots); /* i t f t ... */ - lua_setfield(Luas, -2, "annots"); /* t f t ... */ - } - if (beads != 0) { - lua_pushnumber(Luas, beads); /* i t f t ... */ - lua_setfield(Luas, -2, "beads"); /* t f t ... */ - } - if (pdf->img_page_group_val != 0) { - lua_pushnumber(Luas, pdf->img_page_group_val); /* i t f t ... */ - lua_setfield(Luas, -2, "imggroup"); /* t f t ... */ - } - err = lua_pcall(Luas, 1, 0, 0); /* (e) t ... */ - if (err != 0) - luatex_fail("pdflua.lua: endpage()"); - /* t ... */ - lua_pop(Luas, 1); /* ... */ -} - -@ @c -void pdflua_output_pages_tree(PDF pdf) -{ - int err; - lua_rawgeti(Luas, LUA_REGISTRYINDEX, pdf->pdflua_ref); /* t */ - lua_pushstring(Luas, "outputpagestree"); /* s t */ - lua_gettable(Luas, -2); /* f */ - err = lua_pcall(Luas, 0, 0, 0); /* - */ - if (err != 0) - luatex_fail("pdflua.lua: outputpagestree()"); -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfobj.h b/Build/source/texk/web2c/luatexdir/pdf/pdfobj.h index ad392338509..f8fac35eea7 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfobj.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfobj.h @@ -15,8 +15,8 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ - + with LuaTeX; if not, see . +*/ #ifndef PDFOBJ_H # define PDFOBJ_H @@ -25,21 +25,13 @@ # define set_pdf_obj_objnum(A, B) pdf_obj_objnum(A) = (B) -# define pdfmem_obj_size 5 /* size of memory in |mem| which |obj_data_ptr| holds */ - -# define obj_obj_data(pdf, A) pdf->mem[obj_data_ptr((pdf), (A)) + 0] /* object data */ -# define obj_obj_stream_attr(pdf, A) pdf->mem[obj_data_ptr((pdf), (A)) + 1] /* additional attributes into stream dict */ -# define obj_obj_flags(pdf, A) pdf->mem[obj_data_ptr((pdf), (A)) + 2] /* stream/file flags */ -# define obj_obj_pdfcompresslevel(pdf, A) pdf->mem[obj_data_ptr((pdf), (A)) + 3] /* overrides \pdfcompresslevel */ -# define obj_obj_objstm_threshold(pdf, A) pdf->mem[obj_data_ptr((pdf), (A)) + 4] /* for object stream compression */ +# define pdfmem_obj_size 5 /* size of memory in |mem| which |obj_data_ptr| holds */ -/* define set_obj_obj_data(pdf, A, B) obj_obj_data((pdf), (A)) = (B) */ -/* define set_obj_obj_flags(pdf, A, B) obj_obj_flags((pdf), (A)) = (B) */ -/* define set_obj_obj_stream_attr(pdf, A, B) obj_obj_stream_attr((pdf), (A)) = (B) */ -/* define set_obj_obj_pdfcompresslevel(pdf, A, B) obj_obj_pdfcompresslevel((pdf), (A)) = (B) */ -/* define set_obj_obj_objstm_threshold(pdf, A, B) obj_obj_objstm_threshold((pdf), (A)) = (B) */ - -/**********************************************************************/ +# define obj_obj_data(pdf, A) pdf->mem[obj_data_ptr((pdf), (A)) + 0] /* object data */ +# define obj_obj_stream_attr(pdf, A) pdf->mem[obj_data_ptr((pdf), (A)) + 1] /* additional attributes into stream dict */ +# define obj_obj_flags(pdf, A) pdf->mem[obj_data_ptr((pdf), (A)) + 2] /* stream/file flags */ +# define obj_obj_pdfcompresslevel(pdf, A) pdf->mem[obj_data_ptr((pdf), (A)) + 3] /* overrides \pdfcompresslevel */ +# define obj_obj_objstm_threshold(pdf, A) pdf->mem[obj_data_ptr((pdf), (A)) + 4] /* for object stream compression */ # define OBJ_FLAG_ISSTREAM (1 << 0) # define OBJ_FLAG_ISFILE (1 << 1) @@ -52,8 +44,6 @@ # define set_obj_obj_is_file(pdf,A) ((obj_obj_flags((pdf), (A)) |= OBJ_FLAG_ISFILE)) # define unset_obj_obj_is_file(pdf,A) ((obj_obj_flags((pdf), (A)) &= ~OBJ_FLAG_ISFILE)) -/**********************************************************************/ - extern void init_obj_obj(PDF pdf, int k); extern void pdf_write_obj(PDF pdf, int n); extern void scan_obj(PDF pdf); diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfobj.w b/Build/source/texk/web2c/luatexdir/pdf/pdfobj.w index a3aa09f3860..7dd51061595 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfobj.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfobj.w @@ -67,8 +67,8 @@ void pdf_write_obj(PDF pdf, int k) st.l = li; lua_pop(Luas, 1); if (obj_obj_is_file(pdf, k)) { - boolean res = false; /* callback status value */ - const char *fnam = NULL; /* callback found filename */ + boolean res = false; /* callback status value */ + const char *fnam = NULL; /* callback found filename */ int callback_id; /* st.s is also |\0|-terminated, even as lstring */ fnam = luatex_find_file(st.s, find_data_file_callback); @@ -96,18 +96,10 @@ void pdf_write_obj(PDF pdf, int k) tprint("<<"); tprint(st.s); pdf_out_block(pdf, (const char *) data.s, data.l); - /* already happens in pdf_end_obj: - if (!obj_obj_is_stream(pdf, k) && data.s[data.l - 1] != '\n') - pdf_out(pdf, '\n'); - */ xfree(data.s); tprint(">>"); } else { pdf_out_block(pdf, st.s, st.l); - /* already happens in pdf_end_obj: - if (!obj_obj_is_stream(pdf, k) && st.s[st.l - 1] != '\n') - pdf_out(pdf, '\n'); - */ } if (obj_obj_is_stream(pdf, k)) { pdf_end_stream(pdf); @@ -126,16 +118,16 @@ void init_obj_obj(PDF pdf, int k) obj_obj_data(pdf, k) = LUA_NOREF; unset_obj_obj_is_stream(pdf, k); unset_obj_obj_is_file(pdf, k); - obj_obj_pdfcompresslevel(pdf, k) = -1; /* unset */ - obj_obj_objstm_threshold(pdf, k) = OBJSTM_UNSET; /* unset */ + obj_obj_pdfcompresslevel(pdf, k) = -1; /* unset */ + obj_obj_objstm_threshold(pdf, k) = OBJSTM_UNSET; /* unset */ } -@ The \.{\\pdfextension obj} primitive is used to create a ``raw'' object in the PDF - output file. The object contents will be hold in memory and will be written - out only when the object is referenced by \.{\\pdfextension refobj}. When - \.{\\pdfextension obj} is used with \.{\\immediate}, the object contents will be - written out immediately. Objects referenced in the current page are appended into - |pdf_obj_list|. +@ The \.{\\pdfextension obj} primitive is used to create a ``raw'' object in the +PDF output file. The object contents will be hold in memory and will be written +out only when the object is referenced by \.{\\pdfextension refobj}. When +\.{\\pdfextension obj} is used with \.{\\immediate}, the object contents will be +written out immediately. Objects referenced in the current page are appended into +|pdf_obj_list|. @c void scan_obj(PDF pdf) @@ -143,7 +135,6 @@ void scan_obj(PDF pdf) int k; lstring *st = NULL; if (scan_keyword("reserveobjnum")) { - /* Scan an optional space */ get_x_token(); if (cur_cmd != spacer_cmd) back_input(); @@ -163,13 +154,13 @@ void scan_obj(PDF pdf) obj_data_ptr(pdf, k) = pdf_get_mem(pdf, pdfmem_obj_size); init_obj_obj(pdf, k); if (scan_keyword("uncompressed")) { - obj_obj_pdfcompresslevel(pdf, k) = 0; /* \pdfcompresslevel = 0 */ + obj_obj_pdfcompresslevel(pdf, k) = 0; obj_obj_objstm_threshold(pdf, k) = OBJSTM_NEVER; } if (scan_keyword("stream")) { set_obj_obj_is_stream(pdf, k); if (scan_keyword("attr")) { - scan_pdf_ext_toks(); + scan_toks(false, true); st = tokenlist_to_lstring(def_ref, true); flush_list(def_ref); lua_pushlstring(Luas, (char *) st->s, st->l); @@ -180,7 +171,7 @@ void scan_obj(PDF pdf) } if (scan_keyword("file")) set_obj_obj_is_file(pdf, k); - scan_pdf_ext_toks(); + scan_toks(false, true); st = tokenlist_to_lstring(def_ref, true); flush_list(def_ref); lua_pushlstring(Luas, (char *) st->s, st->l); @@ -192,7 +183,7 @@ void scan_obj(PDF pdf) } @ @c -#define tail cur_list.tail_field +#define tail cur_list.tail_field void scan_refobj(PDF pdf) { diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfoutline.h b/Build/source/texk/web2c/luatexdir/pdf/pdfoutline.h index 79002329953..a1c42df936e 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfoutline.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfoutline.h @@ -15,7 +15,8 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ + with LuaTeX; if not, see . +*/ #ifndef PDFOUTLINE_H diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfoutline.w b/Build/source/texk/web2c/luatexdir/pdf/pdfoutline.w index 922428da951..6c0a30a88d9 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfoutline.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfoutline.w @@ -19,46 +19,44 @@ @ @c - #include "ptexlib.h" -@ Data structure of outlines; it's not able to write out outline entries -before all outline entries are defined, so memory allocated for outline -entries can't not be deallocated and will stay in memory. For this reason we -will store data of outline entries in |pdf->mem| instead of |mem| +@ Data structure of outlines; it's not able to write out outline entries before +all outline entries are defined, so memory allocated for outline entries can't +not be deallocated and will stay in memory. For this reason we will store data of +outline entries in |pdf->mem| instead of |mem| @c -#define pdfmem_outline_size 8 /* size of memory in |pdf->mem| which |obj_outline_ptr| points to */ - -#define obj_outline_count obj_info /* count of all opened children */ -#define set_obj_outline_count(pdf,A,B) obj_outline_count(pdf,A)=B -#define obj_outline_ptr obj_aux /* pointer to |pdf->mem| */ -#define set_obj_outline_ptr(pdf,A,B) obj_outline_ptr(pdf,A)=B - -#define obj_outline_title(pdf,A) pdf->mem[obj_outline_ptr(pdf,A)] -#define obj_outline_parent(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 1] -#define obj_outline_prev(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 2] -#define obj_outline_next(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 3] -#define obj_outline_first(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 4] -#define obj_outline_last(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 5] -#define obj_outline_action_objnum(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 6] /* object number of action */ -#define obj_outline_attr(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 7] - +#define pdfmem_outline_size 8 /* size of memory in |pdf->mem| which |obj_outline_ptr| points to */ + +#define obj_outline_count obj_info /* count of all opened children */ +#define obj_outline_ptr obj_aux /* pointer to |pdf->mem| */ + +#define obj_outline_title(pdf,A) pdf->mem[obj_outline_ptr(pdf,A)] +#define obj_outline_parent(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 1] +#define obj_outline_prev(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 2] +#define obj_outline_next(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 3] +#define obj_outline_first(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 4] +#define obj_outline_last(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 5] +#define obj_outline_action_objnum(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 6] /* object number of action */ +#define obj_outline_attr(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 7] + +#define set_obj_outline_count(pdf,A,B) obj_outline_count(pdf,A)=B +#define set_obj_outline_ptr(pdf,A,B) obj_outline_ptr(pdf,A)=B #define set_obj_outline_action_objnum(pdf,A,B) obj_outline_action_objnum(pdf,A)=B -#define set_obj_outline_title(pdf,A,B) obj_outline_title(pdf,A)=B -#define set_obj_outline_prev(pdf,A,B) obj_outline_prev(pdf,A)=B -#define set_obj_outline_next(pdf,A,B) obj_outline_next(pdf,A)=B -#define set_obj_outline_first(pdf,A,B) obj_outline_first(pdf,A)=B -#define set_obj_outline_last(pdf,A,B) obj_outline_last(pdf,A)=B -#define set_obj_outline_parent(pdf,A,B) obj_outline_parent(pdf,A)=B -#define set_obj_outline_attr(pdf,A,B) obj_outline_attr(pdf,A)=B +#define set_obj_outline_title(pdf,A,B) obj_outline_title(pdf,A)=B +#define set_obj_outline_prev(pdf,A,B) obj_outline_prev(pdf,A)=B +#define set_obj_outline_next(pdf,A,B) obj_outline_next(pdf,A)=B +#define set_obj_outline_first(pdf,A,B) obj_outline_first(pdf,A)=B +#define set_obj_outline_last(pdf,A,B) obj_outline_last(pdf,A)=B +#define set_obj_outline_parent(pdf,A,B) obj_outline_parent(pdf,A)=B +#define set_obj_outline_attr(pdf,A,B) obj_outline_attr(pdf,A)=B @ @c static int open_subentries(PDF pdf, halfword p) { - int k, c; - int l, r; - k = 0; + int c, l, r; + int k = 0; if (obj_outline_first(pdf, p) != 0) { l = obj_outline_first(pdf, p); do { @@ -101,7 +99,7 @@ void scan_pdfoutline(PDF pdf) int j = 0; halfword p = null; if (scan_keyword("attr")) { - scan_pdf_ext_toks(); + scan_toks(false, true); r = def_ref; } else { r = 0; @@ -118,7 +116,7 @@ void scan_pdfoutline(PDF pdf) } else { i = 0; } - scan_pdf_ext_toks(); + scan_toks(false, true); q = def_ref; if (j == 0) { j = pdf_create_obj(pdf, obj_type_others, 0); @@ -180,8 +178,8 @@ void scan_pdfoutline(PDF pdf) } } -@ In the end we must flush PDF objects that cannot be written out -immediately after shipping out pages. +@ In the end we must flush PDF objects that cannot be written out immediately +after shipping out pages. @c int print_outlines(PDF pdf) diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfpage.h b/Build/source/texk/web2c/luatexdir/pdf/pdfpage.h index 6d9fcc0e0b1..175fbcc6c7e 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfpage.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfpage.h @@ -15,8 +15,8 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ - + with LuaTeX; if not, see . +*/ #ifndef PDFPAGE_H # define PDFPAGE_H @@ -33,11 +33,7 @@ # undef hz # endif -/**********************************************************************/ - -void synch_pos_with_cur(posstructure * pos, posstructure * refpos, - scaledpos cur); - +void synch_pos_with_cur(posstructure * pos, posstructure * refpos, scaledpos cur); boolean calc_pdfpos(pdfstructure * p, scaledpos pos); void pdf_end_string_nl(PDF pdf); void pdf_goto_pagemode(PDF pdf); diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfpage.w b/Build/source/texk/web2c/luatexdir/pdf/pdfpage.w index 3fc698a9ec7..73c83c64234 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfpage.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfpage.w @@ -19,7 +19,6 @@ @ @c - #include "ptexlib.h" #include @@ -27,16 +26,16 @@ #include #include -@ eternal constants +@ eternal constant: number of sp per 1bp + @c -#define one_bp ((double) 65536 * (double) 72.27 / 72) /* number of sp per 1bp */ +#define one_bp ((double) 65536 * (double) 72.27 / 72) @ @c void init_pdf_pagecalculations(PDF pdf) { pdfstructure *p; int decimal_digits = pdf->decimal_digits; - assert(pdf != NULL); if (pdf->pstruct == NULL) pdf->pstruct = xmalloc(sizeof(pdfstructure)); p = pdf->pstruct; @@ -52,10 +51,10 @@ void init_pdf_pagecalculations(PDF pdf) setpdffloat(p->cm[4], 0, decimal_digits); /* horizontal movement on page */ setpdffloat(p->cm[5], 0, decimal_digits); /* vertical movement on page */ /* for placement inside BT...ET */ - setpdffloat(p->tm0_cur, 0, 6); /* mantissa holds HZ expand * ExtendFont */ + setpdffloat(p->tm0_cur, 0, 6); /* mantissa holds HZ expand * ExtendFont */ setpdffloat(p->tm[0], ten_pow[6], 6); /* mantissa holds HZ expand * ExtendFont */ setpdffloat(p->tm[1], 0, 0); - setpdffloat(p->tm[2], 0, 3); /* mantissa holds SlantFont, 0 = default */ + setpdffloat(p->tm[2], 0, 3); /* mantissa holds SlantFont, 0 = default */ setpdffloat(p->tm[3], ten_pow[6], 6); setpdffloat(p->tm[4], 0, decimal_digits); /* mantissa holds delta from |pdf_bt_pos.h| */ setpdffloat(p->tm[5], 0, decimal_digits); /* mantissa holds delta from |pdf_bt_pos.v| */ @@ -71,28 +70,31 @@ void init_pdf_pagecalculations(PDF pdf) } @ @c -void synch_pos_with_cur(posstructure * pos, posstructure * refpos, - scaledpos cur) +void synch_pos_with_cur(posstructure * pos, posstructure * refpos, scaledpos cur) { switch (pos->dir) { - case dir_TLT: - pos->pos.h = refpos->pos.h + cur.h; - pos->pos.v = refpos->pos.v - cur.v; - break; - case dir_TRT: - pos->pos.h = refpos->pos.h - cur.h; - pos->pos.v = refpos->pos.v - cur.v; - break; - case dir_LTL: - pos->pos.h = refpos->pos.h + cur.v; - pos->pos.v = refpos->pos.v - cur.h; - break; - case dir_RTT: - pos->pos.h = refpos->pos.h - cur.v; - pos->pos.v = refpos->pos.v - cur.h; - break; - default: - assert(0); + case dir_TLT: + pos->pos.h = refpos->pos.h + cur.h; + pos->pos.v = refpos->pos.v - cur.v; + break; + case dir_TRT: + pos->pos.h = refpos->pos.h - cur.h; + pos->pos.v = refpos->pos.v - cur.v; + break; + case dir_LTL: + pos->pos.h = refpos->pos.h + cur.v; + pos->pos.v = refpos->pos.v - cur.h; + break; + case dir_RTT: + pos->pos.h = refpos->pos.h - cur.v; + pos->pos.v = refpos->pos.v - cur.h; + break; + default: + formatted_warning("pdf backend","forcing bad dir %i to TLT in synch_pos_with_cur",pos->dir); + pos->dir = dir_TLT; + pos->pos.h = refpos->pos.h + cur.h; + pos->pos.v = refpos->pos.v - cur.v; + break; } } @@ -102,55 +104,48 @@ boolean calc_pdfpos(pdfstructure * p, scaledpos pos) scaledpos new; boolean move_pdfpos = false; switch (p->mode) { - case PMODE_PAGE: - new.h = i32round(pos.h * p->k1); - new.v = i32round(pos.v * p->k1); - p->cm[4].m = new.h - p->pdf.h.m; /* cm is concatenated */ - p->cm[5].m = new.v - p->pdf.v.m; - if (new.h != p->pdf.h.m || new.v != p->pdf.v.m) - move_pdfpos = true; - break; - case PMODE_TEXT: - new.h = i32round(pos.h * p->k1); - new.v = i32round(pos.v * p->k1); - p->tm[4].m = new.h - p->pdf_bt_pos.h.m; /* Tm replaces */ - p->tm[5].m = new.v - p->pdf_bt_pos.v.m; - if (new.h != p->pdf.h.m || new.v != p->pdf.v.m) - move_pdfpos = true; - break; - case PMODE_CHAR: - case PMODE_CHARARRAY: - switch (p->wmode) { - case WMODE_H: - new.h = - i32round((pos.h * p->k1 - (double) p->pdf_tj_pos.h.m) * p->k2); + case PMODE_PAGE: + new.h = i32round(pos.h * p->k1); new.v = i32round(pos.v * p->k1); - p->tj_delta.m = -i64round((double) - ((new.h - p->cw.m) / ten_pow[p->cw.e - - p->tj_delta. - e])); - p->tm[5].m = new.v - p->pdf_bt_pos.v.m; /* p->tm[4] is meaningless */ - if (p->tj_delta.m != 0 || new.v != p->pdf.v.m) + p->cm[4].m = new.h - p->pdf.h.m; /* cm is concatenated */ + p->cm[5].m = new.v - p->pdf.v.m; + if (new.h != p->pdf.h.m || new.v != p->pdf.v.m) move_pdfpos = true; break; - case WMODE_V: + case PMODE_TEXT: new.h = i32round(pos.h * p->k1); - new.v = - i32round(((double) p->pdf_tj_pos.v.m - pos.v * p->k1) * p->k2); - p->tm[4].m = new.h - p->pdf_bt_pos.h.m; /* p->tm[5] is meaningless */ - p->tj_delta.m = -i64round((double) - ((new.v - p->cw.m) / ten_pow[p->cw.e - - p->tj_delta. - e])); - if (p->tj_delta.m != 0 || new.h != p->pdf.h.m) + new.v = i32round(pos.v * p->k1); + p->tm[4].m = new.h - p->pdf_bt_pos.h.m; /* Tm replaces */ + p->tm[5].m = new.v - p->pdf_bt_pos.v.m; + if (new.h != p->pdf.h.m || new.v != p->pdf.v.m) move_pdfpos = true; break; + case PMODE_CHAR: + case PMODE_CHARARRAY: + switch (p->wmode) { + case WMODE_H: + new.h = i32round((pos.h * p->k1 - (double) p->pdf_tj_pos.h.m) * p->k2); + new.v = i32round(pos.v * p->k1); + p->tj_delta.m = -i64round((double) ((new.h - p->cw.m) / ten_pow[p->cw.e - p->tj_delta.e])); + p->tm[5].m = new.v - p->pdf_bt_pos.v.m; /* p->tm[4] is meaningless */ + if (p->tj_delta.m != 0 || new.v != p->pdf.v.m) + move_pdfpos = true; + break; + case WMODE_V: + new.h = i32round(pos.h * p->k1); + new.v = i32round(((double) p->pdf_tj_pos.v.m - pos.v * p->k1) * p->k2); + p->tm[4].m = new.h - p->pdf_bt_pos.h.m; /* p->tm[5] is meaningless */ + p->tj_delta.m = -i64round((double) ((new.v - p->cw.m) / ten_pow[p->cw.e - p->tj_delta.e])); + if (p->tj_delta.m != 0 || new.h != p->pdf.h.m) + move_pdfpos = true; + break; + default: + normal_error("pdf backend","unknown mode in char array in calc_pos"); + break; + } + break; default: - assert(0); - } - break; - default: - assert(0); + normal_error("pdf backend","unknown mode in calc_pos"); } return move_pdfpos; } @@ -178,7 +173,8 @@ void pdf_set_pos(PDF pdf, scaledpos pos) { boolean move; pdfstructure *p = pdf->pstruct; - assert(is_pagemode(p)); + if (!is_pagemode(p)) + normal_error("pdf backend","page mode expected in set_pos"); move = calc_pdfpos(p, pos); if (move) { pdf_print_cm(pdf, p->cm); @@ -192,17 +188,20 @@ void pdf_set_pos_temp(PDF pdf, scaledpos pos) { boolean move; pdfstructure *p = pdf->pstruct; - assert(is_pagemode(p)); + if (!is_pagemode(p)) + normal_error("pdf backend","page mode expected in set_pos_temp"); move = calc_pdfpos(p, pos); - if (move) + if (move) { pdf_print_cm(pdf, p->cm); + } } @ @c static void begin_text(PDF pdf) { pdfstructure *p = pdf->pstruct; - assert(is_pagemode(p)); + if (!is_pagemode(p)) + normal_error("pdf backend","page mode expected in begin_text"); p->pdf_bt_pos = p->pdf; pdf_puts(pdf, "BT\n"); p->mode = PMODE_TEXT; @@ -212,7 +211,8 @@ static void begin_text(PDF pdf) static void end_text(PDF pdf) { pdfstructure *p = pdf->pstruct; - assert(is_textmode(p)); + if (!is_textmode(p)) + normal_error("pdf backend","text mode expected in end_text"); pdf_puts(pdf, "ET\n"); p->pdf = p->pdf_bt_pos; p->mode = PMODE_PAGE; @@ -231,7 +231,6 @@ void pdf_end_string_nl(PDF pdf) void pdf_goto_pagemode(PDF pdf) { pdfstructure *p = pdf->pstruct; - assert(p != NULL); if (!is_pagemode(p)) { if (is_charmode(p)) end_charmode(pdf); @@ -239,8 +238,9 @@ void pdf_goto_pagemode(PDF pdf) end_chararray(pdf); if (is_textmode(p)) end_text(pdf); + if (!is_pagemode(p)) + normal_error("pdf backend","page mode expected in goto_page_mode"); } - assert(is_pagemode(p)); } void pdf_goto_textmode(PDF pdf) @@ -249,16 +249,16 @@ void pdf_goto_textmode(PDF pdf) const scaledpos origin = { 0, 0 }; - if (!is_textmode(p)) { - if (is_pagemode(p)) { - pdf_set_pos(pdf, origin); /* reset to page origin */ - begin_text(pdf); - } else { - if (is_charmode(p)) - end_charmode(pdf); - if (is_chararraymode(p)) - end_chararray(pdf); - } + if (is_pagemode(p)) { + /* reset to page origin */ + pdf_set_pos(pdf, origin); + begin_text(pdf); + } else if (!is_textmode(p)) { + if (is_charmode(p)) + end_charmode(pdf); + if (is_chararraymode(p)) + end_chararray(pdf); + if (!is_textmode(p)) + normal_error("pdf backend","text mode expected in goto_text_mode"); } - assert(is_textmode(p)); } diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfpagetree.h b/Build/source/texk/web2c/luatexdir/pdf/pdfpagetree.h index b00fc0476a1..9fdb0ac83d3 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfpagetree.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfpagetree.h @@ -15,8 +15,8 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ - + with LuaTeX; if not, see . +*/ #ifndef PAGETREE_H # define PAGETREE_H @@ -25,4 +25,4 @@ int output_pages_tree(PDF); int pdf_do_page_divert(PDF, int, int); void pdf_do_page_undivert(int, int); -#endif /* PAGETREE_H */ +#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfpagetree.w b/Build/source/texk/web2c/luatexdir/pdf/pdfpagetree.w index 4470e53cbfb..76d008c4359 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfpagetree.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfpagetree.w @@ -19,25 +19,20 @@ @ @c - #include "ptexlib.h" @* Page diversions. @ @c -#ifdef DEBUG -# define PAGES_TREE_KIDSMAX 3 -#else -# define PAGES_TREE_KIDSMAX 10 -#endif +# define PAGES_TREE_KIDSMAX 10 static struct avl_table *divert_list_tree = NULL; typedef struct pages_entry_ { - int objnum; /* object number of this /Pages object */ - int number_of_pages; /* total number of all pages below */ - int number_of_kids; /* number of direct kid objects */ - int kids[PAGES_TREE_KIDSMAX]; /* array of kid object numbers */ + int objnum; /* object number of this /Pages object */ + int number_of_pages; /* total number of all pages below */ + int number_of_kids; /* number of direct kid objects */ + int kids[PAGES_TREE_KIDSMAX]; /* array of kid object numbers */ struct pages_entry_ *next; } pages_entry; @@ -50,11 +45,9 @@ typedef struct divert_list_entry_ { static int comp_divert_list_entry(const void *pa, const void *pb, void *p) { (void) p; - if (((const divert_list_entry *) pa)->divnum > - ((const divert_list_entry *) pb)->divnum) + if (((const divert_list_entry *) pa)->divnum > ((const divert_list_entry *) pb)->divnum) return 1; - if (((const divert_list_entry *) pa)->divnum < - ((const divert_list_entry *) pb)->divnum) + if (((const divert_list_entry *) pa)->divnum < ((const divert_list_entry *) pb)->divnum) return -1; return 0; } @@ -62,9 +55,8 @@ static int comp_divert_list_entry(const void *pa, const void *pb, void *p) @ @c static pages_entry *new_pages_entry(PDF pdf) { - pages_entry *p; int i; - p = xtalloc(1, pages_entry); + pages_entry *p = xtalloc(1, pages_entry); p->number_of_pages = p->number_of_kids = 0; for (i = 0; i < PAGES_TREE_KIDSMAX; i++) p->kids[i] = 0; @@ -86,9 +78,7 @@ static divert_list_entry *new_divert_list_entry(void) static void ensure_list_tree(void) { if (divert_list_tree == NULL) { - divert_list_tree = - avl_create(comp_divert_list_entry, NULL, &avl_xallocator); - assert(divert_list_tree != NULL); + divert_list_tree = avl_create(comp_divert_list_entry, NULL, &avl_xallocator); } } @@ -102,8 +92,11 @@ static divert_list_entry *get_divert_list(int divnum) if (d == NULL) { d = new_divert_list_entry(); d->divnum = divnum; + /* the next bit of code can actually be removed */ aa = avl_probe(divert_list_tree, d); - assert(aa != NULL); + if (aa==NULL) { + normal_error("pdf backend","page list lookup error"); + } } return d; } @@ -114,11 +107,6 @@ int pdf_do_page_divert(PDF pdf, int objnum, int divnum) { divert_list_entry *d; pages_entry *p; -#ifdef DEBUG - pages_entry *q; - struct avl_traverser t; - int i; -#endif /* initialize the tree */ ensure_list_tree(); /* make sure we have a list for this diversion */ @@ -135,34 +123,21 @@ int pdf_do_page_divert(PDF pdf, int objnum, int divnum) p = d->last; p->kids[p->number_of_kids++] = objnum; p->number_of_pages++; -#ifdef DEBUG - printf("\n"); - avl_t_init(&t, divert_list_tree); - for (d = avl_t_first(&t, divert_list_tree); d != NULL; d = avl_t_next(&t)) { - printf("===== D-LIST %d: ", d->divnum); - for (q = d->first; q != NULL; q = q->next) { - printf("P=%d NK=%d (", q->objnum, q->number_of_kids); - for (i = 0; i < q->number_of_kids; i++) - printf("%d ", q->kids[i]); - printf(") "); - } - printf("\n"); - } - printf("\n"); -#endif return p->objnum; } @ @c static void movelist(divert_list_entry * d, divert_list_entry * dto) { - if (d != NULL && d->first != NULL && d->divnum != dto->divnum) { /* no undivert of empty list or into self */ + if (d != NULL && d->first != NULL && d->divnum != dto->divnum) { + /* no undivert of empty list or into self */ if (dto->first == NULL) dto->first = d->first; else dto->last->next = d->first; dto->last = d->last; - d->first = d->last = NULL; /* one could as well remove this |divert_list_entry| */ + /* one could as well remove this |divert_list_entry| */ + d->first = d->last = NULL; } } @@ -172,15 +147,12 @@ void pdf_do_page_undivert(int divnum, int curdivnum) { divert_list_entry *d, *dto, tmp; struct avl_traverser t; -#ifdef DEBUG - pages_entry *p; - int i; -#endif /* initialize the tree */ ensure_list_tree(); /* find the diversion |curdivnum| list where diversion |divnum| should go */ dto = get_divert_list(curdivnum); - if (divnum == 0) { /* 0 = special case: undivert {\it all\/} lists */ + if (divnum == 0) { + /* 0 = special case: undivert {\it all\/} lists */ avl_t_init(&t, divert_list_tree); for (d = avl_t_first(&t, divert_list_tree); d != NULL; d = avl_t_next(&t)) @@ -190,21 +162,6 @@ void pdf_do_page_undivert(int divnum, int curdivnum) d = (divert_list_entry *) avl_find(divert_list_tree, &tmp); movelist(d, dto); } -#ifdef DEBUG - printf("\n"); - avl_t_init(&t, divert_list_tree); - for (d = avl_t_first(&t, divert_list_tree); d != NULL; d = avl_t_next(&t)) { - printf("===== U-LIST %d: ", d->divnum); - for (p = d->first; p != NULL; p = p->next) { - printf("P=%d NK=%d (", p->objnum, p->number_of_kids); - for (i = 0; i < p->number_of_kids; i++) - printf("%d ", p->kids[i]); - printf(") "); - } - printf("\n"); - } - printf("\n"); -#endif } @ write a /Pages object @@ -214,11 +171,11 @@ static void write_pages(PDF pdf, pages_entry * p, int parent) { int i; int pages_attributes ; - assert(p != NULL); pdf_begin_obj(pdf, p->objnum, OBJSTM_ALWAYS); pdf_begin_dict(pdf); pdf_dict_add_name(pdf, "Type", "Pages"); - if (parent == 0) { /* it's root */ + if (parent == 0) { + /* it's root */ pages_attributes = pdf_pages_attr; /* lookup once */ if (pages_attributes != null) { pdf_print_toks(pdf, pages_attributes); @@ -240,16 +197,17 @@ static void write_pages(PDF pdf, pages_entry * p, int parent) @ loop over all /Pages objects, output them, create their parents, recursing bottom up, return the /Pages root object number + @c static int output_pages_list(PDF pdf, pages_entry * pe) { pages_entry *p, *q, *r; - assert(pe != NULL); - if (pe->next == NULL) { /* everything fits into one |pages_entry| */ - write_pages(pdf, pe, 0); /* --> /Pages root found */ + if (pe->next == NULL) { + /* everything fits into one |pages_entry| */ + write_pages(pdf, pe, 0); /* /Pages root found */ return pe->objnum; } - q = r = new_pages_entry(pdf); /* one level higher needed */ + q = r = new_pages_entry(pdf); /* one level higher needed */ for (p = pe; p != NULL; p = p->next) { if (q->number_of_kids == PAGES_TREE_KIDSMAX) { q->next = new_pages_entry(pdf); @@ -259,7 +217,7 @@ static int output_pages_list(PDF pdf, pages_entry * pe) q->number_of_pages += p->number_of_pages; write_pages(pdf, p, q->objnum); } - return output_pages_list(pdf, r); /* recurse through next higher level */ + return output_pages_list(pdf, r); /* recurse through next higher level */ } @ @c diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfrule.h b/Build/source/texk/web2c/luatexdir/pdf/pdfrule.h index 3770b2cbbe5..c0d68fd44b0 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfrule.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfrule.h @@ -15,12 +15,13 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ + with LuaTeX; if not, see . +*/ #ifndef PDFRULE_H # define PDFRULE_H -void pdf_place_rule(PDF pdf, halfword p, scaledpos size); +void pdf_place_rule(PDF pdf, halfword p, scaledpos size, int callback_id); #endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfrule.w b/Build/source/texk/web2c/luatexdir/pdf/pdfrule.w index a9d670c1154..e4897dfb04b 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfrule.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfrule.w @@ -18,13 +18,14 @@ % with LuaTeX; if not, see . @ @c - - #include "ptexlib.h" #include "pdf/pdfpage.h" @ @c -void pdf_place_rule(PDF pdf, halfword q, scaledpos size) + +/* maybe we should have an extra callback on normal rules or on any rule in 2.0+ */ + +void pdf_place_rule(PDF pdf, halfword q, scaledpos size, int callback_id) { pdfpos dim; pdfstructure *p = pdf->pstruct; @@ -36,6 +37,14 @@ void pdf_place_rule(PDF pdf, halfword q, scaledpos size) pdf_place_image(pdf,q); } else if (subtype(q) == empty_rule) { /* place nothing, only take space */ + } else if (subtype(q) == user_rule) { + if (callback_id != 0) { + pdf_goto_pagemode(pdf); + pdf_puts(pdf, "q\n"); + pdf_set_pos_temp(pdf, pos); + run_callback(callback_id, "Ndd->",q,size.h,size.v); + pdf_puts(pdf, "\nQ\n"); + } } else { /* normal_rule or >= 100 being a leader rule */ pdf_goto_pagemode(pdf); diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfsaverestore.h b/Build/source/texk/web2c/luatexdir/pdf/pdfsaverestore.h index e45902328c8..3e1e1ef061e 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfsaverestore.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfsaverestore.h @@ -15,20 +15,22 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ - + with LuaTeX; if not, see . +*/ #ifndef PDFSAVERESTORE_H # define PDFSAVERESTORE_H /* stack for positions of \pdfsave */ + typedef struct { scaledpos pos; int matrix_stack; } pos_entry; -extern pos_entry *pos_stack; /* the stack */ -extern int pos_stack_size; /* initially empty */ -extern int pos_stack_used; /* used entries */ + +extern pos_entry *pos_stack; /* the stack */ +extern int pos_stack_size; /* initially empty */ +extern int pos_stack_used; /* used entries */ extern void pdf_out_save(PDF pdf, halfword p); extern void pdf_out_restore(PDF pdf, halfword p); diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfsaverestore.w b/Build/source/texk/web2c/luatexdir/pdf/pdfsaverestore.w index 4c88dec6182..0d91de54496 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfsaverestore.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfsaverestore.w @@ -19,24 +19,21 @@ @ @c - #include "ptexlib.h" @ @c -pos_entry *pos_stack = 0; /* the stack */ -int pos_stack_size = 0; /* initially empty */ -int pos_stack_used = 0; /* used entries */ +pos_entry *pos_stack = 0; /* the stack */ +int pos_stack_size = 0; /* initially empty */ +int pos_stack_used = 0; /* used entries */ @ @c static void checkpdfsave(scaledpos pos) { pos_entry *new_stack; - if (pos_stack_used >= pos_stack_size) { pos_stack_size += STACK_INCREMENT; new_stack = xtalloc((unsigned) pos_stack_size, pos_entry); - memcpy((void *) new_stack, (void *) pos_stack, - (unsigned) pos_stack_used * sizeof(pos_entry)); + memcpy((void *) new_stack, (void *) pos_stack, (unsigned) pos_stack_used * sizeof(pos_entry)); xfree(pos_stack); pos_stack = new_stack; } @@ -53,21 +50,20 @@ static void checkpdfrestore(scaledpos pos) { scaledpos diff; if (pos_stack_used == 0) { - luatex_warn("%s", "'restore' is missing a 'save'"); + normal_warning("pdf backend", "'restore' is missing a 'save'"); return; } pos_stack_used--; diff.h = pos.h - pos_stack[pos_stack_used].pos.h; diff.v = pos.v - pos_stack[pos_stack_used].pos.v; if (diff.h != 0 || diff.v != 0) { - luatex_warn("misplaced 'restore' by (%dsp, %dsp)", (int) diff.h, (int) diff.v); + formatted_warning("pdf backend","misplaced 'restore' by (%dsp, %dsp)", (int) diff.h, (int) diff.v); } if (global_shipping_mode == SHIPPING_PAGE) { matrix_stack_used = pos_stack[pos_stack_used].matrix_stack; } } - @ @c void pdf_out_save(PDF pdf, halfword p) { diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfsetmatrix.h b/Build/source/texk/web2c/luatexdir/pdf/pdfsetmatrix.h index c65e0ea8b8a..59fd1f69cdc 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfsetmatrix.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfsetmatrix.h @@ -15,8 +15,8 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ - + with LuaTeX; if not, see . +*/ #ifndef PDFSETMATRIX_H # define PDFSETMATRIX_H @@ -36,7 +36,6 @@ extern matrix_entry *matrix_stack; extern int matrix_stack_size; extern int matrix_stack_used; - scaled getllx(void); scaled getlly(void); scaled geturx(void); diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfsetmatrix.w b/Build/source/texk/web2c/luatexdir/pdf/pdfsetmatrix.w index ba9317e776d..b107033b984 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfsetmatrix.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfsetmatrix.w @@ -19,7 +19,6 @@ @ @c - #include "ptexlib.h" @ stack for \.{\\pdfextension setmatrix} @@ -38,34 +37,28 @@ boolean matrixused(void) static void matrix_stack_room(void) { matrix_entry *new_stack; - if (matrix_stack_used >= matrix_stack_size) { matrix_stack_size += STACK_INCREMENT; new_stack = xtalloc((unsigned) matrix_stack_size, matrix_entry); - memcpy((void *) new_stack, (void *) matrix_stack, - (unsigned) matrix_stack_used * sizeof(matrix_entry)); + memcpy((void *) new_stack, (void *) matrix_stack, (unsigned) matrix_stack_used * sizeof(matrix_entry)); xfree(matrix_stack); matrix_stack = new_stack; } } -@ \.{\\pdfextension setmatrix{a b c d}} +@ \.{\\pdfextension setmatrix{a b c d}} - |e| := pos.h +|e| := pos.h - |f| := pos.v +|f| := pos.v - |M_top|: current active matrix at the top of - the matrix stack +|M_top|: current active matrix at the top of the matrix stack - The origin of \.{\\pdfextension setmatrix} is the current point. - The annotation coordinate system is the original - page coordinate system. When pdfTeX calculates - annotation rectangles it does not take into - account this transformations, it uses the original - coordinate system. To get the corrected values, - first we go back to the origin, perform the - transformation and go back: +The origin of \.{\\pdfextension setmatrix} is the current point. The annotation +coordinate system is the original page coordinate system. When pdfTeX calculates +annotation rectangles it does not take into account this transformations, it uses +the original coordinate system. To get the corrected values, first we go back to +the origin, perform the transformation and go back: {\obeylines\obeyspaces\tt ( 1 0 0 ) ( a b 0 ) ( 1 0 0 ) @@ -84,15 +77,14 @@ static void matrix_stack_room(void) @c static void pdfsetmatrix(const char *in, scaledpos pos) { - /* Argument of \.{\\pdfextension setmatrix} starts with |str_pool[in]| and ends - before |str_pool[pool_ptr]|. */ - + /* + Argument of \.{\\pdfextension setmatrix} starts with |str_pool[in]| and ends + before |str_pool[pool_ptr]|. + */ matrix_entry x, *y, *z; - if (global_shipping_mode == SHIPPING_PAGE) { - if (sscanf((const char *) in, " %lf %lf %lf %lf ", - &x.a, &x.b, &x.c, &x.d) != 4) { - luatex_warn("unrecognized format of setmatrix: {%s}", in); + if (sscanf((const char *) in, " %lf %lf %lf %lf ", &x.a, &x.b, &x.c, &x.d) != 4) { + formatted_warning("pdf backend","unrecognized format of setmatrix: %s", in); return; } /* calculate this transformation matrix */ @@ -130,8 +122,9 @@ static void pdfsetmatrix(const char *in, scaledpos pos) If \.{\\pdfextension setmatrix} wasn't used, then return the value unchanged. +@ Return values for matrix tranform functions: + @c -/* Return values for matrix tranform functions */ static scaled ret_llx; static scaled ret_lly; static scaled ret_urx; @@ -181,7 +174,6 @@ static void do_matrixtransform(scaled x, scaled y, scaled * retx, scaled * rety) void matrixtransformrect(scaled llx, scaled lly, scaled urx, scaled ury) { scaled x1, x2, x3, x4, y1, y2, y3, y4; - if (global_shipping_mode == SHIPPING_PAGE && matrix_stack_used > 0) { last_llx = llx; last_lly = lly; diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfshipout.h b/Build/source/texk/web2c/luatexdir/pdf/pdfshipout.h index b341f818099..8fb073da4c2 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfshipout.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfshipout.h @@ -15,14 +15,15 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ + with LuaTeX; if not, see . +*/ #ifndef PDFSHIPOUT_H # define PDFSHIPOUT_H -extern shipping_mode_e global_shipping_mode; /* set to |shipping_mode| when |ship_out| starts */ -extern scaledpos shipbox_refpos; /* for \gleaders */ +extern shipping_mode_e global_shipping_mode; /* set to |shipping_mode| when |ship_out| starts */ +extern scaledpos shipbox_refpos; /* for \gleaders */ extern void ship_out(PDF pdf, halfword p, shipping_mode_e shipping_mode); diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfshipout.w b/Build/source/texk/web2c/luatexdir/pdf/pdfshipout.w index b75cb339c13..d60b4a0dc75 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfshipout.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfshipout.w @@ -23,48 +23,46 @@ @ @c #define count(A) eqtb[count_base+(A)].cint -#define h_offset dimen_par(h_offset_code) -#define mag int_par(mag_code) + +#define mag int_par(mag_code) +#define h_offset dimen_par(h_offset_code) #define page_bottom_offset dimen_par(page_bottom_offset_code) -#define page_direction int_par(page_direction_code) -#define page_height dimen_par(page_height_code) -#define page_left_offset dimen_par(page_left_offset_code) -#define page_right_offset dimen_par(page_right_offset_code) -#define page_top_offset dimen_par(page_top_offset_code) -#define page_width dimen_par(page_width_code) -#define tracing_output int_par(tracing_output_code) -#define tracing_stats int_par(tracing_stats_code) -#define v_offset dimen_par(v_offset_code) +#define page_height dimen_par(page_height_code) +#define page_left_offset dimen_par(page_left_offset_code) +#define page_right_offset dimen_par(page_right_offset_code) +#define page_top_offset dimen_par(page_top_offset_code) +#define page_width dimen_par(page_width_code) +#define tracing_output int_par(tracing_output_code) +#define tracing_stats int_par(tracing_stats_code) +#define v_offset dimen_par(v_offset_code) scaledpos shipbox_refpos; -@ |ship_out| is used to shipout a box to PDF or DVI mode. -If |shipping_mode| is set to |SHIPPING_FORM| then the output will be a Form object -(only PDF), and if it is set to |SHIPPING_PAGE| it will be a Page object. +@ |ship_out| is used to shipout a box to PDF or DVI mode. If |shipping_mode| is +set to |SHIPPING_FORM| then the output will be a Form object (only PDF), and if +it is set to |SHIPPING_PAGE| it will be a Page object. @c void ship_out(PDF pdf, halfword p, shipping_mode_e shipping_mode) { - /* output the box |p| */ - int j, k; /* indices to first ten count registers */ + int j, k; /* indices to first ten count registers */ int post_callback_id; int pre_callback_id; - posstructure refpoint; /* the origin pos. on the page */ + posstructure refpoint; /* the origin pos. on the page */ + int rule_callback_id = 0; scaledpos cur = { 0, 0 }; refpoint.pos.h = 0; refpoint.pos.v = 0; - ensure_output_state(pdf, ST_HEADER_WRITTEN); - fix_o_mode(); /* this is only for complaining if \.{\\outputmode} has changed */ + fix_o_mode(); /* this is only for complaining if \.{\\outputmode} has changed */ init_backend_functionpointers(output_mode_used); - pdf->f_cur = null_font; - - /* Start sheet {\sl Sync\TeX} information record */ - /* {\sl Sync\TeX}: we assume that |pdf_output| is properly set up */ + /* + Start sheet {\sl Sync\TeX} information record; we assume that |pdf_output| is + properly set up. + */ if (int_par(synctex_code)) synctexsheet(mag); - pre_callback_id = callback_defined(start_page_number_callback); post_callback_id = callback_defined(stop_page_number_callback); if ((tracing_output > 0) && (pre_callback_id == 0)) { @@ -99,20 +97,18 @@ void ship_out(PDF pdf, halfword p, shipping_mode_e shipping_mode) show_box(p); end_diagnostic(true); } - /* Ship box |p| out */ if (shipping_mode == SHIPPING_PAGE && box_dir(p) != page_direction) - normal_warning("backend","pagedir differs from bodydir, the output may be placed wrongly on the page", true, true); - /* Update the values of |max_h| and |max_v|; but if the page is too large, |goto done| */ - /* Sometimes the user will generate a huge page because other error messages - are being ignored. Such pages are not output to the \.{dvi} file, since they - may confuse the printing software. */ - - if ((height(p) > max_dimen) || (depth(p) > max_dimen) - || (height(p) + depth(p) + v_offset > max_dimen) - || (width(p) + h_offset > max_dimen)) { - const char *hlp[] = - { "The page just created is more than 18 feet tall or", + normal_warning("backend","pagedir differs from bodydir, the output may be placed wrongly on the page"); + /* + Update the values of |max_h| and |max_v|; but if the page is too large, + |goto done|. Sometimes the user will generate a huge page because other + error messages are being ignored. Such pages are not output to the + \.{dvi} file, since they may confuse the printing software. + */ + if ((height(p) > max_dimen) || (depth(p) > max_dimen) || (height(p) + depth(p) + v_offset > max_dimen) || (width(p) + h_offset > max_dimen)) { + const char *hlp[] = { + "The page just created is more than 18 feet tall or", "more than 18 feet wide, so I suspect something went wrong.", NULL }; @@ -129,136 +125,139 @@ void ship_out(PDF pdf, halfword p, shipping_mode_e shipping_mode) max_v = height(p) + depth(p) + v_offset; if (width(p) + h_offset > max_h) max_h = width(p) + h_offset; - /* Calculate page dimensions and margins */ if (global_shipping_mode == SHIPPING_PAGE) { if (page_width > 0) pdf->page_size.h = page_width; else { switch (page_direction) { - case dir_TLT: - pdf->page_size.h = width(p) + 2 * page_left_offset; - break; - case dir_TRT: - pdf->page_size.h = width(p) + 2 * page_right_offset; - break; - case dir_LTL: - pdf->page_size.h = height(p) + depth(p) + 2 * page_left_offset; - break; - case dir_RTT: - pdf->page_size.h = height(p) + depth(p) + 2 * page_right_offset; - break; - default: - assert(0); + case dir_TLT: + pdf->page_size.h = width(p) + 2 * page_left_offset; + break; + case dir_TRT: + pdf->page_size.h = width(p) + 2 * page_right_offset; + break; + case dir_LTL: + pdf->page_size.h = height(p) + depth(p) + 2 * page_left_offset; + break; + case dir_RTT: + pdf->page_size.h = height(p) + depth(p) + 2 * page_right_offset; + break; + default: + pdf->page_size.h = width(p) + 2 * page_left_offset; + normal_warning("pdf backend","bad page direction, assuming TLT, case 1"); } } if (page_height > 0) pdf->page_size.v = page_height; else { switch (page_direction) { - case dir_TLT: - case dir_TRT: - pdf->page_size.v = height(p) + depth(p) + 2 * page_top_offset; + case dir_TLT: + case dir_TRT: + pdf->page_size.v = height(p) + depth(p) + 2 * page_top_offset; + break; + case dir_LTL: + case dir_RTT: + pdf->page_size.v = width(p) + 2 * page_top_offset; + break; + default: + pdf->page_size.v = height(p) + depth(p) + 2 * page_top_offset; + normal_warning("pdf backend","bad page direction, assuming TLT, case 2"); + } + } + /* + Think in upright page/paper coordinates (page origin = lower left edge). + First preset |refpoint.pos| to the DVI origin (near upper left page edge). + */ + switch (output_mode_used) { + case OMODE_DVI: + /* hh: how can we end up here? */ + refpoint.pos.h = one_true_inch; + refpoint.pos.v = pdf->page_size.v - one_true_inch; + dvi = refpoint.pos; break; - case dir_LTL: - case dir_RTT: - pdf->page_size.v = width(p) + 2 * page_top_offset; + case OMODE_PDF: + refpoint.pos.h = pdf_h_origin; + refpoint.pos.v = pdf->page_size.v - pdf_v_origin; break; default: - assert(0); - } - } - - /* Think in upright page/paper coordinates (page origin = lower left edge). - First preset |refpoint.pos| to the DVI origin (near upper left page edge). */ - - switch (output_mode_used) { - case OMODE_DVI: - /* hh: how can we end up here? */ - refpoint.pos.h = one_true_inch; - refpoint.pos.v = pdf->page_size.v - one_true_inch; - dvi = refpoint.pos; - break; - case OMODE_PDF: - refpoint.pos.h = pdf_h_origin; - refpoint.pos.v = pdf->page_size.v - pdf_v_origin; - break; - default: - assert(0); + normal_error("pdf backend", "unknown output mode"); } - /* Then shift |refpoint.pos| of the DVI origin depending on the - |page_direction| within the upright (TLT) page coordinate system */ - + /* + Then shift |refpoint.pos| of the DVI origin depending on the + |page_direction| within the upright (TLT) page coordinate system + */ switch (page_direction) { - case dir_TLT: - case dir_LTL: - refpoint.pos.h += h_offset; - refpoint.pos.v -= v_offset; - break; - case dir_TRT: - case dir_RTT: - refpoint.pos.h += - pdf->page_size.h - page_right_offset - one_true_inch; - refpoint.pos.v -= v_offset; - break; - default: - assert(0); + case dir_TLT: + case dir_LTL: + refpoint.pos.h += h_offset; + refpoint.pos.v -= v_offset; + break; + case dir_TRT: + case dir_RTT: + refpoint.pos.h += pdf->page_size.h - page_right_offset - one_true_inch; + refpoint.pos.v -= v_offset; + break; + default: + refpoint.pos.h += h_offset; + refpoint.pos.v -= v_offset; + normal_warning("pdf backend","bad page direction, assuming TLT, case 3"); } - - /* Then switch to page box coordinate system; do |height(p)| movement, - to get the location of the box origin. */ - + /* + Then switch to page box coordinate system; do |height(p)| movement, + to get the location of the box origin. + */ pdf->posstruct->dir = page_direction; cur.h = 0; cur.v = height(p); synch_pos_with_cur(pdf->posstruct, &refpoint, cur); - } else { /* shipping a /Form */ - assert(output_mode_used == OMODE_PDF); + } else { + /* shipping a /Form */ pdf->posstruct->dir = box_dir(p); switch (pdf->posstruct->dir) { - case dir_TLT: - case dir_TRT: - pdf->page_size.h = width(p); - pdf->page_size.v = height(p) + depth(p); - break; - case dir_LTL: - case dir_RTT: - pdf->page_size.h = height(p) + depth(p); - pdf->page_size.v = width(p); - break; - default: - assert(0); - } + case dir_TLT: + case dir_TRT: + pdf->page_size.h = width(p); + pdf->page_size.v = height(p) + depth(p); + break; + case dir_LTL: + case dir_RTT: + pdf->page_size.h = height(p) + depth(p); + pdf->page_size.v = width(p); + break; + default: + pdf->page_size.h = width(p); + pdf->page_size.v = height(p) + depth(p); + normal_warning("pdf backend","bad page direction, assuming TLT, case 4"); + } switch (pdf->posstruct->dir) { - case dir_TLT: - pdf->posstruct->pos.h = 0; - pdf->posstruct->pos.v = depth(p); - break; - case dir_TRT: - pdf->posstruct->pos.h = width(p); - pdf->posstruct->pos.v = depth(p); - break; - case dir_LTL: - pdf->posstruct->pos.h = height(p); - pdf->posstruct->pos.v = width(p); - break; - case dir_RTT: - pdf->posstruct->pos.h = depth(p); - pdf->posstruct->pos.v = width(p); - break; - default: - assert(0); + case dir_TLT: + pdf->posstruct->pos.h = 0; + pdf->posstruct->pos.v = depth(p); + break; + case dir_TRT: + pdf->posstruct->pos.h = width(p); + pdf->posstruct->pos.v = depth(p); + break; + case dir_LTL: + pdf->posstruct->pos.h = height(p); + pdf->posstruct->pos.v = width(p); + break; + case dir_RTT: + pdf->posstruct->pos.h = depth(p); + pdf->posstruct->pos.v = width(p); + break; + default: + pdf->posstruct->pos.h = 0; + pdf->posstruct->pos.v = depth(p); + normal_warning("pdf backend","bad page direction, assuming TLT, case 5"); } } - /* Now we are at the point on the page where the origin of the page box should go. */ - - shipbox_refpos = pdf->posstruct->pos; /* for \.{\\gleaders} */ - + shipbox_refpos = pdf->posstruct->pos; /* for \.{\\gleaders} */ switch (output_mode_used) { case OMODE_DVI: - assert(shipping_mode == SHIPPING_PAGE); dvi_begin_page(pdf); break; case OMODE_PDF: @@ -267,24 +266,21 @@ void ship_out(PDF pdf, halfword p, shipping_mode_e shipping_mode) default: normal_error("pdf backend", "unknown output mode"); } - + rule_callback_id = callback_defined(process_rule_callback); switch (type(p)) { case vlist_node: - vlist_out(pdf, p); + vlist_out(pdf, p, rule_callback_id); break; case hlist_node: - hlist_out(pdf, p); + hlist_out(pdf, p, rule_callback_id); break; default: normal_error("pdf backend", "no vlist or hlist in (xform) shipout"); } - if (shipping_mode == SHIPPING_PAGE) total_pages++; cur_s = -1; - /* Finish shipping */ - switch (output_mode_used) { case OMODE_DVI: dvi_end_page(pdf); @@ -295,10 +291,8 @@ void ship_out(PDF pdf, halfword p, shipping_mode_e shipping_mode) default: normal_error("pdf backend", "unknown output mode"); } - DONE: - if ((tracing_output <= 0) && (post_callback_id == 0) - && shipping_mode == SHIPPING_PAGE) { + if ((tracing_output <= 0) && (post_callback_id == 0) && shipping_mode == SHIPPING_PAGE) { print_char(']'); update_terminal(); } @@ -321,10 +315,8 @@ void ship_out(PDF pdf, halfword p, shipping_mode_e shipping_mode) } if (shipping_mode == SHIPPING_PAGE && (post_callback_id > 0)) (void) run_callback(post_callback_id, "->"); - /* Finish sheet {\sl Sync\TeX} information record */ if (int_par(synctex_code)) synctexteehs(); - global_shipping_mode = NOT_SHIPPING; } diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdftables.h b/Build/source/texk/web2c/luatexdir/pdf/pdftables.h index adcff69964c..f08195b4e04 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdftables.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdftables.h @@ -15,8 +15,8 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ - + with LuaTeX; if not, see . +*/ #ifndef PDFTABLES_H # define PDFTABLES_H @@ -33,52 +33,49 @@ typedef struct { int int0; char *str0; } u; - union_type u_type; /* integer or char * in union above */ + union_type u_type; /* integer or char * in union above */ int objptr; } oentry; /* -The cross-reference table |obj_tab| is an array of |obj_tab_size| of -|obj_entry|. Each entry contains five integer fields and represents an object -in PDF file whose object number is the index of this entry in |obj_tab|. -Objects in |obj_tab| maybe linked into list; objects in such a linked list have -the same type. -*/ -/* -The first field contains information representing identifier of this object. -It is usally a number for most of object types, but it may be a string number -for named destination or named thread. +The cross-reference table |obj_tab| is an array of |obj_tab_size| of |obj_entry|. +Each entry contains five integer fields and represents an object in PDF file +whose object number is the index of this entry in |obj_tab|. Objects in |obj_tab| +maybe linked into list; objects in such a linked list have the same type. -The second field of |obj_entry| contains link to the next -object in |obj_tab| if this object is linked in a list. +The first field contains information representing identifier of this object. It +is usally a number for most of object types, but it may be a string number for +named destination or named thread. -The third field holds the byte offset of the object in the output PDF file, -or its byte offset within an object stream. As long as the object is not -written, this field is used for flags about the write status of the object; -then it has a negative value. +The second field of |obj_entry| contains link to the next object in |obj_tab| if +this object is linked in a list. -The fourth field holds the object number of the object stream, into which -the object is included. +The third field holds the byte offset of the object in the output PDF file, or +its byte offset within an object stream. As long as the object is not written, +this field is used for flags about the write status of the object; then it has a +negative value. + +The fourth field holds the object number of the object stream, into which the +object is included. + +The last field usually represents the pointer to some auxiliary data structure +depending on the object type; however it may be used as a counter as well. -The last field usually represents the pointer to some auxiliary data -structure depending on the object type; however it may be used as a counter as -well. */ -# define obj_info(pdf,A) pdf->obj_tab[(A)].u.int0 /* information representing identifier of this object */ -# define obj_start(pdf,A) pdf->obj_tab[(A)].u.str0 -# define obj_link(pdf,A) pdf->obj_tab[(A)].int1 /* link to the next entry in linked list */ +# define obj_info(pdf,A) pdf->obj_tab[(A)].u.int0 /* information representing identifier of this object */ +# define obj_start(pdf,A) pdf->obj_tab[(A)].u.str0 +# define obj_link(pdf,A) pdf->obj_tab[(A)].int1 /* link to the next entry in linked list */ -# define obj_offset(pdf,A) pdf->obj_tab[(A)].int2 /* negative (flags), or byte offset for this object in PDF - output file, or ... */ -# define obj_os_objnum(pdf,A) pdf->obj_tab[(A)].int2 /* ... object stream number for this object */ -# define obj_os_idx(pdf,A) pdf->obj_tab[(A)].int3 /* index of this object in object stream */ -# define obj_aux(pdf,A) pdf->obj_tab[(A)].v.int4 /* auxiliary pointer */ -# define obj_stop(pdf,A) pdf->obj_tab[(A)].v.str4 -# define obj_type(pdf,A) pdf->obj_tab[(A)].objtype +# define obj_offset(pdf,A) pdf->obj_tab[(A)].int2 /* negative (flags), or byte offset for this object in PDF output file, or ... */ +# define obj_os_objnum(pdf,A) pdf->obj_tab[(A)].int2 /* ... object stream number for this object */ +# define obj_os_idx(pdf,A) pdf->obj_tab[(A)].int3 /* index of this object in object stream */ +# define obj_aux(pdf,A) pdf->obj_tab[(A)].v.int4 /* auxiliary pointer */ +# define obj_stop(pdf,A) pdf->obj_tab[(A)].v.str4 +# define obj_type(pdf,A) pdf->obj_tab[(A)].objtype -# define obj_data_ptr obj_aux /* pointer to |pdf->mem| */ +# define obj_data_ptr obj_aux /* pointer to |pdf->mem| */ # define set_obj_link(pdf,A,B) obj_link(pdf,A)=(B) # define set_obj_start(pdf,A,B) obj_start(pdf,A)=(B) @@ -94,30 +91,25 @@ well. # define is_obj_scheduled(pdf,A) ((obj_offset(pdf,A))>(off_t)-2) # define is_obj_written(pdf,A) ((obj_offset(pdf,A))>(off_t)-1) -/* NOTE: The data structure definitions for the nodes on the typesetting side are - inside |nodes.h| */ +/* + NOTE: The data structure definitions for the nodes on the typesetting side are + inside |nodes.h| +*/ -/* Some constants */ -# define inf_pk_dpi 72 /* min PK pixel density value from \.{texmf.cnf} */ -# define sup_pk_dpi 8000 /* max PK pixel density value from \.{texmf.cnf} */ +# define inf_pk_dpi 72 /* min PK pixel density value from \.{texmf.cnf} */ +# define sup_pk_dpi 8000 /* max PK pixel density value from \.{texmf.cnf} */ extern int find_obj(PDF pdf, int t, int i, boolean byname); extern void check_obj_exists(PDF pdf, int objnum); extern void check_obj_type(PDF pdf, int t, int objnum); extern int pdf_get_obj(PDF pdf, int t, int i, boolean byname); extern int pdf_create_obj(PDF pdf, int t, int i); - -extern void set_rect_dimens(PDF pdf, halfword p, halfword parent_box, - scaledpos cur, scaled_whd alt_rule, scaled margin); - +extern void set_rect_dimens(PDF pdf, halfword p, halfword parent_box, scaledpos cur, scaled_whd alt_rule, scaled margin); extern void libpdffinish(PDF); -extern void dump_pdftex_data(PDF pdf); -extern void undump_pdftex_data(PDF pdf); - -# define set_width(A, B) width(A) = (B) -# define set_height(A, B) height(A) = (B) -# define set_depth(A, B) depth(A) = (B) +# define set_width(A,B) width(A)=(B) +# define set_height(A,B) height(A)=(B) +# define set_depth(A,B) depth(A)=(B) /* pdf backend definitions */ @@ -138,7 +130,6 @@ typedef enum { c_pdf_objcompresslevel, c_pdf_inclusion_copy_font, c_pdf_gen_tounicode, - c_pdf_replace_font, } pdf_backend_counters ; typedef enum { @@ -158,6 +149,11 @@ typedef enum { t_pdf_pk_mode, } pdf_backend_tokenlists ; +extern int pdf_last_annot; +extern int pdf_last_link; +extern int pdf_last_obj; +extern int pdf_retval; + # define pdf_compress_level get_tex_extension_count_register(c_pdf_compress_level) # define pdf_decimal_digits get_tex_extension_count_register(c_pdf_decimal_digits) # define pdf_image_resolution get_tex_extension_count_register(c_pdf_image_resolution) @@ -174,7 +170,6 @@ typedef enum { # define pdf_objcompresslevel get_tex_extension_count_register(c_pdf_objcompresslevel) # define pdf_inclusion_copy_font get_tex_extension_count_register(c_pdf_inclusion_copy_font) # define pdf_gen_tounicode get_tex_extension_count_register(c_pdf_gen_tounicode) -# define pdf_replace_font get_tex_extension_count_register(c_pdf_replace_font) # define pdf_h_origin get_tex_extension_dimen_register(d_pdf_h_origin) # define pdf_v_origin get_tex_extension_dimen_register(d_pdf_v_origin) @@ -193,4 +188,6 @@ typedef enum { # define set_pdf_compress_level(i) set_tex_extension_count_register(c_pdf_compress_level,i) # define set_pdf_objcompresslevel(i) set_tex_extension_count_register(c_pdf_objcompresslevel,i) -#endif /* PDFTABLES_H */ +# define set_pdf_decimal_digits(i) set_tex_extension_count_register(c_pdf_decimal_digits,i) + +#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdftables.w b/Build/source/texk/web2c/luatexdir/pdf/pdftables.w index 72f0474e922..d8b5cf10321 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdftables.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdftables.w @@ -19,54 +19,55 @@ @ @c - #include "ptexlib.h" @ @c -const char *pdf_obj_typenames[PDF_OBJ_TYPE_MAX + 1] = - { "font", "outline", "dest", "obj", "xform", "ximage", "thread", +const char *pdf_obj_typenames[PDF_OBJ_TYPE_MAX + 1] = { + "font", "outline", "dest", "obj", "xform", "ximage", "thread", "pagestream", "page", "pages", "catalog", "info", "link", "annot", "annots", "bead", "beads", "objstm", "others" }; +int pdf_last_annot; +int pdf_last_link; +int pdf_last_obj; +int pdf_retval; /* global multi-purpose return value */ + @ AVL sort entry into |avl_table[]| @c static int compare_info(const void *pa, const void *pb, void *param) { - const oentry *a, *b; + const oentry *a = (const oentry *) pa; + const oentry *b = (const oentry *) pb; (void) param; - a = (const oentry *) pa; - b = (const oentry *) pb; if (a->u_type == b->u_type) { if (a->u_type == union_type_int) - return ((a->u.int0 < - b->u.int0 ? -1 : (a->u.int0 > b->u.int0 ? 1 : 0))); - else /* string type */ + return ((a->u.int0 < b->u.int0 ? -1 : (a->u.int0 > b->u.int0 ? 1 : 0))); + else /* string type */ return strcmp(a->u.str0, b->u.str0); - } else if (a->u_type == union_type_int) + } else if (a->u_type == union_type_int) { return -1; - else + } else { return 1; + } } static void avl_put_obj(PDF pdf, int t, oentry * oe) { void **pp; - assert(t >= 0 && t <= PDF_OBJ_TYPE_MAX); if (pdf->obj_tree[t] == NULL) { pdf->obj_tree[t] = avl_create(compare_info, NULL, &avl_xallocator); if (pdf->obj_tree[t] == NULL) - luatex_fail("avlstuff.c: avl_create() pdf->obj_tree failed"); + formatted_error("pdf backend","avl_create() pdf->obj_tree failed"); } pp = avl_probe(pdf->obj_tree[t], oe); if (pp == NULL) - luatex_fail("avlstuff.c: avl_probe() out of memory in insertion"); + formatted_error("pdf backend","avl_probe() out of memory in insertion"); } static void avl_put_int_obj(PDF pdf, int int0, int objptr, int t) { - oentry *oe; - oe = xtalloc(1, oentry); + oentry *oe = xtalloc(1, oentry); oe->u.int0 = int0; oe->u_type = union_type_int; oe->objptr = objptr; @@ -75,8 +76,7 @@ static void avl_put_int_obj(PDF pdf, int int0, int objptr, int t) static void avl_put_str_obj(PDF pdf, char *str0, int objptr, int t) { - oentry *oe; - oe = xtalloc(1, oentry); + oentry *oe = xtalloc(1, oentry); oe->u.str0 = str0; /* no xstrdup() here */ oe->u_type = union_type_cstring; oe->objptr = objptr; @@ -87,7 +87,6 @@ static int avl_find_int_obj(PDF pdf, int t, int i) { oentry *p; oentry tmp; - assert(t >= 0 && t <= PDF_OBJ_TYPE_MAX); tmp.u.int0 = i; tmp.u_type = union_type_int; if (pdf->obj_tree[t] == NULL) @@ -102,7 +101,6 @@ static int avl_find_str_obj(PDF pdf, int t, char *s) { oentry *p; oentry tmp; - assert(t >= 0 && t <= PDF_OBJ_TYPE_MAX); tmp.u.str0 = s; tmp.u_type = union_type_cstring; if (pdf->obj_tree[t] == NULL) @@ -128,9 +126,7 @@ int pdf_create_obj(PDF pdf, int t, int i) pdf->obj_tab_size = pdf->obj_tab_size + a; else pdf->obj_tab_size = sup_obj_tab_size; - pdf->obj_tab = - xreallocarray(pdf->obj_tab, obj_entry, - (unsigned) pdf->obj_tab_size); + pdf->obj_tab = xreallocarray(pdf->obj_tab, obj_entry, (unsigned) pdf->obj_tab_size); } pdf->obj_ptr++; obj_info(pdf, pdf->obj_ptr) = i; @@ -146,8 +142,7 @@ int pdf_create_obj(PDF pdf, int t, int i) obj_link(pdf, pdf->obj_ptr) = pdf->head_tab[t]; pdf->head_tab[t] = pdf->obj_ptr; if ((t == obj_type_dest) && (i < 0)) - append_dest_name(pdf, makecstring(-obj_info(pdf, pdf->obj_ptr)), - pdf->obj_ptr); + append_dest_name(pdf, makecstring(-obj_info(pdf, pdf->obj_ptr)), pdf->obj_ptr); /* why not just -i */ } return pdf->obj_ptr; } @@ -157,7 +152,6 @@ int find_obj(PDF pdf, int t, int i, boolean byname) { char *ss = NULL; int ret; - assert(i >= 0); /* no tricks */ if (byname) { ss = makecstring(i); ret = avl_find_str_obj(pdf, t, ss); @@ -169,19 +163,17 @@ int find_obj(PDF pdf, int t, int i, boolean byname) } @ The following function finds an object with identifier |i| and type |t|. - Identifier |i| is either an integer or a token list index. If no - such object exists then it will be created. This function is used mainly to - find destination for link annotations and outlines; however it is also used - in |ship_out| (to check whether a Page object already exists) so we need - to declare it together with subroutines needed in |hlist_out| and - |vlist_out|. +Identifier |i| is either an integer or a token list index. If no such object +exists then it will be created. This function is used mainly to find destination +for link annotations and outlines; however it is also used in |ship_out| (to +check whether a Page object already exists) so we need to declare it together +with subroutines needed in |hlist_out| and |vlist_out|. @c int pdf_get_obj(PDF pdf, int t, int i, boolean byname) { int r; str_number s; - assert(i >= 0); if (byname > 0) { s = tokens_to_string(i); r = find_obj(pdf, t, s, true); @@ -215,28 +207,22 @@ void check_obj_exists(PDF pdf, int objnum) void check_obj_type(PDF pdf, int t, int objnum) { int u; - char *s; check_obj_exists(pdf, objnum); u = obj_type(pdf, objnum); if (t != u) { - assert(t >= 0 && t <= PDF_OBJ_TYPE_MAX); - assert(u >= 0 && u <= PDF_OBJ_TYPE_MAX); - s = (char *) xtalloc(128, char); - snprintf(s, 127, "referenced object has wrong type %s; should be %s", - pdf_obj_typenames[u], pdf_obj_typenames[t]); - normal_error("pdf backend", s); + formatted_error("pdf backend", "referenced object has wrong type %s; should be %s", + pdf_obj_typenames[u], pdf_obj_typenames[t]); } } @ @c -void set_rect_dimens(PDF pdf, halfword p, halfword parent_box, scaledpos cur, - scaled_whd alt_rule, scaled margin) +void set_rect_dimens(PDF pdf, halfword p, halfword parent_box, scaledpos cur, scaled_whd alt_rule, scaled margin) { - scaledpos ll, ur; /* positions relative to cur */ + scaledpos ll, ur; /* positions relative to cur */ scaledpos pos_ll, pos_ur, tmp; posstructure localpos; localpos.dir = pdf->posstruct->dir; - ll.h = 0; /* pdf contains current point on page */ + ll.h = 0; /* pdf contains current point on page */ if (is_running(alt_rule.dp)) ll.v = depth(parent_box) - cur.v; else @@ -249,12 +235,10 @@ void set_rect_dimens(PDF pdf, halfword p, halfword parent_box, scaledpos cur, ur.v = -height(parent_box) - cur.v; else ur.v = -alt_rule.ht; - synch_pos_with_cur(&localpos, pdf->posstruct, ll); pos_ll = localpos.pos; synch_pos_with_cur(&localpos, pdf->posstruct, ur); pos_ur = localpos.pos; - if (pos_ll.h > pos_ur.h) { tmp.h = pos_ll.h; pos_ll.h = pos_ur.h; @@ -292,148 +276,3 @@ void libpdffinish(PDF pdf) glyph_unicode_free(); zip_free(pdf); } - -@ Store some of the pdftex data structures in the format. The idea here is -to ensure that any data structures referenced from pdftex-specific whatsit -nodes are retained. For the sake of simplicity and speed, all the filled parts -of |pdf->mem| and |obj_tab| are retained, in the present implementation. We also -retain three of the linked lists that start from |head_tab|, so that it is -possible to, say, load an image in the \.{INITEX} run and then reference it in a -\.{VIRTEX} run that uses the dumped format. - -@c -void dump_pdftex_data(PDF pdf) -{ - int k, x; - pdf_object_list *l; - dumpimagemeta(); /* the image information array */ - dump_int(pdf->mem_size); - dump_int(pdf->mem_ptr); - for (k = 1; k <= pdf->mem_ptr - 1; k++) { - x = pdf->mem[k]; - dump_int(x); - } - print_ln(); - print_int(pdf->mem_ptr - 1); - tprint(" words of pdf memory"); - x = pdf->obj_tab_size; - dump_int(x); - x = pdf->obj_ptr; - dump_int(x); - for (k = 1; k <= pdf->obj_ptr; k++) { - x = obj_info(pdf, k); - dump_int(x); - x = obj_link(pdf, k); - dump_int(x); - x = obj_os_idx(pdf, k); - dump_int(x); - x = obj_aux(pdf, k); - dump_int(x); - x = obj_type(pdf, k); - dump_int(x); - } - print_ln(); - print_int(pdf->obj_ptr); - tprint(" indirect objects"); - dump_int(pdf->obj_count); - dump_int(pdf->xform_count); - dump_int(pdf->ximage_count); - if ((l = get_page_resources_list(pdf, obj_type_obj)) != NULL) { - while (l != NULL) { - dump_int(l->info); - l = l->link; - } - } - dump_int(0); /* signal end of |obj_list| */ - if ((l = get_page_resources_list(pdf, obj_type_xform)) != NULL) { - while (l != NULL) { - dump_int(l->info); - l = l->link; - } - } - dump_int(0); /* signal end of |xform_list| */ - if ((l = get_page_resources_list(pdf, obj_type_ximage)) != NULL) { - while (l != NULL) { - dump_int(l->info); - l = l->link; - } - } - dump_int(0); /* signal end of |ximage_list| */ - x = pdf->head_tab[obj_type_obj]; - dump_int(x); - x = pdf->head_tab[obj_type_xform]; - dump_int(x); - x = pdf->head_tab[obj_type_ximage]; - dump_int(x); - dump_int(pdf_last_obj); - dump_int(last_saved_box_index); - dump_int(last_saved_image_index); -} - -@ And restoring the pdftex data structures from the format. The -two function arguments to |undumpimagemeta| have been restored -already in an earlier module. - -@c -void undump_pdftex_data(PDF pdf) -{ - int k, x; - undumpimagemeta(pdf, pdf_minor_version, pdf_inclusion_errorlevel); /* the image information array */ - undump_int(pdf->mem_size); - pdf->mem = xreallocarray(pdf->mem, int, (unsigned) pdf->mem_size); - undump_int(pdf->mem_ptr); - for (k = 1; k <= pdf->mem_ptr - 1; k++) { - undump_int(x); - pdf->mem[k] = (int) x; - } - undump_int(x); - pdf->obj_tab_size = x; - undump_int(x); - pdf->obj_ptr = x; - for (k = 1; k <= pdf->obj_ptr; k++) { - undump_int(x); - obj_info(pdf, k) = x; - undump_int(x); - obj_link(pdf, k) = x; - set_obj_offset(pdf, k, -1); - undump_int(x); - obj_os_idx(pdf, k) = x; - undump_int(x); - obj_aux(pdf, k) = x; - undump_int(x); - obj_type(pdf, k) = x; - } - - undump_int(x); - pdf->obj_count = x; - undump_int(x); - pdf->xform_count = x; - undump_int(x); - pdf->ximage_count = x; - /* todo : the next 3 loops can be done much more efficiently */ - undump_int(x); - while (x != 0) { - addto_page_resources(pdf, obj_type_obj, x); - undump_int(x); - } - undump_int(x); - while (x != 0) { - addto_page_resources(pdf, obj_type_xform, x); - undump_int(x); - } - undump_int(x); - while (x != 0) { - addto_page_resources(pdf, obj_type_ximage, x); - undump_int(x); - } - - undump_int(x); - pdf->head_tab[obj_type_obj] = x; - undump_int(x); - pdf->head_tab[obj_type_xform] = x; - undump_int(x); - pdf->head_tab[obj_type_ximage] = x; - undump_int(pdf_last_obj); - undump_int(last_saved_box_index); - undump_int(last_saved_image_index); -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfthread.h b/Build/source/texk/web2c/luatexdir/pdf/pdfthread.h index 5719803b86f..dd9078444fc 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfthread.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfthread.h @@ -15,7 +15,8 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ + with LuaTeX; if not, see . +*/ #ifndef PDFTHREAD_H @@ -23,34 +24,36 @@ /* data structure of threads; words 1..4 represent the coordinates of the corners */ -# define obj_thread_first obj_aux /* pointer to the first bead */ +# define obj_thread_first obj_aux /* pointer to the first bead */ /* data structure of beads */ -# define pdfmem_bead_size 5 /* size of memory in |pdf->mem| which |obj_bead_ptr| points to */ +# define pdfmem_bead_size 5 /* size of memory in |pdf->mem| which |obj_bead_ptr| points to */ -# define set_pdf_thread_attr(A,B) pdf_thread_attr(A)=B -# define set_pdf_thread_id(A,B) pdf_thread_id(A)=B -# define set_pdf_thread_named_id(A,B) pdf_thread_named_id(A)=B +# define set_pdf_thread_attr(A,B) pdf_thread_attr(A)=B +# define set_pdf_thread_id(A,B) pdf_thread_id(A)=B +# define set_pdf_thread_named_id(A,B) pdf_thread_named_id(A)=B -# define obj_bead_ptr obj_aux /* pointer to |pdf->mem| */ +# define obj_bead_ptr obj_aux /* pointer to |pdf->mem| */ # define obj_bead_rect(pdf,A) pdf->mem[obj_bead_ptr(pdf,A)] # define obj_bead_page(pdf,A) pdf->mem[obj_bead_ptr(pdf,A) + 1] # define obj_bead_next(pdf,A) pdf->mem[obj_bead_ptr(pdf,A) + 2] # define obj_bead_prev(pdf,A) pdf->mem[obj_bead_ptr(pdf,A) + 3] # define obj_bead_attr(pdf,A) pdf->mem[obj_bead_ptr(pdf,A) + 4] +# define obj_bead_data obj_bead_rect +# define set_obj_bead_data set_obj_bead_rect -# define set_obj_bead_rect(pdf,A,B) obj_bead_rect(pdf,A)=B -# define set_obj_bead_page(pdf,A,B) obj_bead_page(pdf,A)=B -# define set_obj_bead_next(pdf,A,B) obj_bead_next(pdf,A)=B -# define set_obj_bead_prev(pdf,A,B) obj_bead_prev(pdf,A)=B -# define set_obj_bead_attr(pdf,A,B) obj_bead_attr(pdf,A)=B +# define set_obj_bead_rect(pdf,A,B) obj_bead_rect(pdf,A)=B +# define set_obj_bead_page(pdf,A,B) obj_bead_page(pdf,A)=B +# define set_obj_bead_next(pdf,A,B) obj_bead_next(pdf,A)=B +# define set_obj_bead_prev(pdf,A,B) obj_bead_prev(pdf,A)=B +# define set_obj_bead_attr(pdf,A,B) obj_bead_attr(pdf,A)=B -/* pointer to the corresponding whatsit node; |obj_bead_rect| is needed only when the bead - rectangle has been written out and after that |obj_bead_data| is not needed any more - so we can use this field for both */ -# define obj_bead_data obj_bead_rect -# define set_obj_bead_data set_obj_bead_rect +/* + pointer to the corresponding whatsit node; |obj_bead_rect| is needed only when the bead + rectangle has been written out and after that |obj_bead_data| is not needed any more + so we can use this field for both +*/ extern void append_bead(PDF pdf, halfword p); extern void do_thread(PDF pdf, halfword parent_box, halfword p, scaledpos cur); diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfthread.w b/Build/source/texk/web2c/luatexdir/pdf/pdfthread.w index 85f7007aa67..b11e48c5fc0 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfthread.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfthread.w @@ -19,7 +19,6 @@ @ @c - #include "ptexlib.h" @ @c @@ -32,9 +31,8 @@ void append_bead(PDF pdf, halfword p) { int a, b, c, t; if (global_shipping_mode == SHIPPING_FORM) - normal_error("pdf backend", "threads cannot be inside an XForm"); - t = pdf_get_obj(pdf, obj_type_thread, pdf_thread_id(p), - pdf_thread_named_id(p)); + normal_error("pdf backend", "threads cannot be inside an xform"); + t = pdf_get_obj(pdf, obj_type_thread, pdf_thread_id(p), pdf_thread_named_id(p)); b = pdf_create_obj(pdf, obj_type_others, 0); obj_bead_ptr(pdf, b) = pdf_get_mem(pdf, pdfmem_bead_size); set_obj_bead_page(pdf, b, pdf->last_page); @@ -87,9 +85,8 @@ void do_thread(PDF pdf, halfword p, halfword parent_box, scaledpos cur) @ @c void append_thread(PDF pdf, halfword parent_box, scaledpos cur) { - halfword p; scaled_whd alt_rule; - p = new_node(whatsit_node, pdf_thread_data_node); + halfword p = new_node(whatsit_node, pdf_thread_data_node); width(p) = pdf->thread.wd; height(p) = pdf->thread.ht; depth(p) = pdf->thread.dp; @@ -119,18 +116,18 @@ void end_thread(PDF pdf, halfword p) normal_error("pdf backend", "'endthread' ended up in different nesting level than 'startthread'"); if (is_running(pdf->thread.dp) && (pdf->last_thread != null)) { switch (pdf->posstruct->dir) { - case dir_TLT: - case dir_TRT: - pdf_ann_bottom(pdf->last_thread) = pos.v - pdf_thread_margin; - break; - case dir_LTL: - pdf_ann_right(pdf->last_thread) = pos.h + pdf_thread_margin; - break; - case dir_RTT: - pdf_ann_left(pdf->last_thread) = pos.h - pdf_thread_margin; - break; - default: - assert(0); + case dir_TLT: + case dir_TRT: + pdf_ann_bottom(pdf->last_thread) = pos.v - pdf_thread_margin; + break; + case dir_LTL: + pdf_ann_right(pdf->last_thread) = pos.h + pdf_thread_margin; + break; + case dir_RTT: + pdf_ann_left(pdf->last_thread) = pos.h - pdf_thread_margin; + break; + default: + formatted_warning("pdf backend","forcing bad dir %i to TLT in end tread",pdf->posstruct->dir); } } if (pdf->last_thread_named_id) @@ -154,18 +151,12 @@ void thread_title(PDF pdf, int t) void pdf_fix_thread(PDF pdf, int t) { halfword a; - normal_warning("pdf backend", "thread destination", false, false); if (obj_info(pdf, t) < 0) { - tprint("name{"); - print(-obj_info(pdf, t)); - tprint("}"); + char *ss = makecstring(-obj_info(pdf, t)); + formatted_warning("pdf backend", "unknown thread destination name '%s'",ss); } else { - tprint("num"); - print_int(obj_info(pdf, t)); + formatted_warning("pdf backend", "unknown thread destination num '%d'",obj_info(pdf, t)); } - tprint(" has been referenced but does not exist, replaced by a fixed one"); - print_ln(); - print_ln(); a = pdf_create_obj(pdf, obj_type_others, 0); pdf_begin_obj(pdf, a, OBJSTM_ALWAYS); pdf_begin_dict(pdf); @@ -182,7 +173,6 @@ void pdf_fix_thread(PDF pdf, int t) pdf_end_array(pdf); pdf_end_dict(pdf); pdf_end_obj(pdf); - pdf_begin_obj(pdf, t, OBJSTM_ALWAYS); pdf_begin_dict(pdf); pdf_add_name(pdf, "I"); @@ -250,7 +240,7 @@ void scan_thread_id(void) set_pdf_thread_id(cur_list.tail_field, cur_val); set_pdf_thread_named_id(cur_list.tail_field, 0); } else if (scan_keyword("name")) { - scan_pdf_ext_toks(); + scan_toks(false, true); set_pdf_thread_id(cur_list.tail_field, def_ref); set_pdf_thread_named_id(cur_list.tail_field, 1); } else { @@ -276,9 +266,9 @@ void print_bead_rectangles(PDF pdf) l = pdf_create_obj(pdf, obj_type_others, 0); pdf_begin_obj(pdf, l, OBJSTM_ALWAYS); pdf_begin_array(pdf); - i = obj_bead_data(pdf, k->info); /* pointer to a whatsit or whatsit-like node */ + i = obj_bead_data(pdf, k->info); /* pointer to a whatsit or whatsit-like node */ pdf_add_rect_spec(pdf, i); - if (subtype(i) == pdf_thread_data_node) /* thanh says it mis be destroyed here */ + if (subtype(i) == pdf_thread_data_node) flush_node(i); pdf_end_array(pdf); pdf_end_obj(pdf); diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdftypes.h b/Build/source/texk/web2c/luatexdir/pdf/pdftypes.h index b25d74d1cc9..f3dafb0ce35 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdftypes.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdftypes.h @@ -15,7 +15,9 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ + with LuaTeX; if not, see . + +*/ #ifndef PDFTYPES_H # define PDFTYPES_H @@ -26,26 +28,27 @@ # include # include "lua/luatex-api.h" -/* The prefix "PTEX" for the PDF keys is special to pdfTeX; - this has been registered with Adobe by Hans Hagen. */ +/* + The prefix "PTEX" for the PDF keys is special to pdfTeX and has been registered with + Adobe by Hans Hagen. +*/ # define pdfkeyprefix "PTEX" # define i32round(a) (int) floor((a) + 0.5) # define i64round(a) (int64_t) floor((a) + 0.5) -# define MAX_OBJ_COMPRESS_LEVEL 3 /* maximum/clipping value for \pdfobjcompresslevel */ -# define OBJSTM_UNSET -1 /* initial value */ -# define OBJSTM_ALWAYS 1 /* \pdfobjcompresslevel >= OBJSTM_ALWAYS: put object into object stream */ -# define OBJSTM_NEVER (MAX_OBJ_COMPRESS_LEVEL + 1) - /* above maximum/clipping value for \pdfobjcompresslevel */ +# define MAX_OBJ_COMPRESS_LEVEL 3 /* maximum/clipping value for \pdfobjcompresslevel */ +# define OBJSTM_UNSET -1 /* initial value */ +# define OBJSTM_ALWAYS 1 /* \pdfobjcompresslevel >= OBJSTM_ALWAYS: put object into object stream */ +# define OBJSTM_NEVER (MAX_OBJ_COMPRESS_LEVEL + 1) /* above maximum/clipping value for \pdfobjcompresslevel */ -typedef int internal_font_number; /* |font| in a |char_node| */ +typedef int internal_font_number; /* |font| in a |char_node| */ typedef enum { - NO_ZIP, /* no \.{ZIP} compression */ - ZIP_WRITING, /* \.{ZIP} compression being used */ - ZIP_FINISH /* finish \.{ZIP} compression */ + NO_ZIP, /* no \.{ZIP} compression */ + ZIP_WRITING, /* \.{ZIP} compression being used */ + ZIP_FINISH /* finish \.{ZIP} compression */ } zip_write_state_e; typedef enum { @@ -53,19 +56,21 @@ typedef enum { OBJSTM_BUF, } buffer_e; -/* This stucture holds everything that is needed for the actual pdf generation. +/* + This stucture holds everything that is needed for the actual pdf generation. + + Because this structure interfaces with C++, it is not wise to use |boolean| + here (C++ has a boolean type built-in that is not compatible). Also, I have + plans to convert the backend code into a C library for use with e.g. standalone + lua. Together, this means that it is best only to use the standard C types and + the types explicitly defined in this header, and stay away from types like + |integer| and |eight_bits| that are used elsewhere in the \LUATEX\ sources. -Because this structure interfaces with C++, it is not wise to use |boolean| -here (C++ has a boolean type built-in that is not compatible). Also, I have -plans to convert the backend code into a C library for use with e.g. standalone -lua. Together, this means that it is best only to use the standard C types and -the types explicitly defined in this header, and stay away from types like -|integer| and |eight_bits| that are used elsewhere in the \LUATEX\ sources. */ typedef struct { - int64_t m; /* mantissa (significand) */ - int e; /* exponent * -1 */ + int64_t m; /* mantissa (significand) */ + int e; /* exponent * -1 */ } pdffloat; typedef struct { @@ -81,26 +86,35 @@ typedef struct scaledpos_ { } scaledpos; typedef struct scaled_whd_ { - scaled wd; /* TeX width */ - scaled ht; /* TeX height */ - scaled dp; /* TeX depth */ + scaled wd; /* TeX width */ + scaled ht; /* TeX height */ + scaled dp; /* TeX depth */ } scaled_whd; typedef struct posstructure_ { - scaledpos pos; /* position on the page */ - int dir; /* direction of stuff to be put onto the page */ + scaledpos pos; /* position on the page */ + int dir; /* direction of stuff to be put onto the page */ } posstructure; typedef struct { - scaledpos curpos; /* \pdflastpos position */ - posstructure boxpos; /* box dir and position of the box origin on the page */ - scaled_whd boxdim; /* box dimensions (in hlist/vlist coordinate system) */ + scaledpos curpos; /* \pdflastpos position */ + posstructure boxpos; /* box dir and position of the box origin on the page */ + scaled_whd boxdim; /* box dimensions (in hlist/vlist coordinate system) */ } pos_info_structure; -typedef enum { PMODE_NONE, PMODE_PAGE, PMODE_TEXT, PMODE_CHARARRAY, PMODE_CHAR +typedef enum { + PMODE_NONE, + PMODE_PAGE, + PMODE_TEXT, + PMODE_CHARARRAY, + PMODE_CHAR } pos_mode; -typedef enum { ST_INITIAL, ST_OMODE_FIX, ST_FILE_OPEN, ST_HEADER_WRITTEN, +typedef enum { + ST_INITIAL, + ST_OMODE_FIX, + ST_FILE_OPEN, + ST_HEADER_WRITTEN, ST_FILE_CLOSED } output_state; @@ -109,14 +123,16 @@ typedef struct pdf_object_list_ { struct pdf_object_list_ *link; } pdf_object_list; -typedef enum { WMODE_H, WMODE_V } writing_mode; /* []TJ runs horizontal or vertical */ +typedef enum { /* []TJ runs horizontal or vertical */ + WMODE_H, + WMODE_V +} writing_mode; typedef struct { pdfpos pdf; /* pos. on page (PDF page raster) */ pdfpos pdf_bt_pos; /* pos. at begin of BT-ET group (PDF page raster) */ pdfpos pdf_tj_pos; /* pos. at begin of TJ array (PDF page raster) */ - pdffloat cw; /* pos. within [(..)..]TJ array (glyph raster); - cw.e = fractional digits in /Widths array */ + pdffloat cw; /* pos. within [(..)..]TJ array (glyph raster); cw.e = fractional digits in /Widths array */ pdffloat tj_delta; /* rel. movement in [(..)..]TJ array (glyph raster) */ pdffloat fs; /* font size in PDF units */ pdffloat fs_cur; /* to check if fs.m has changed and Tf needed */ @@ -155,7 +171,7 @@ typedef struct dest_name_entry_ { int objnum; /* destination object number */ } dest_name_entry; -# define pdf_max_link_level 10/* maximum depth of link nesting */ +# define pdf_max_link_level 10 /* maximum depth of link nesting */ typedef struct pdf_link_stack_record { int nesting_level; @@ -166,6 +182,12 @@ typedef struct pdf_link_stack_record { } pdf_link_stack_record; /* types of objects */ + +/* + NB: |obj_type_thread| is the highest entry in |head_tab|, but there are a few + more linked lists that are handy. +*/ + typedef enum { obj_type_font = 0, /* index of linked list of Fonts objects */ obj_type_outline = 1, /* index of linked list of outline objects */ @@ -174,8 +196,6 @@ typedef enum { obj_type_xform = 4, /* index of linked list of XObject forms */ obj_type_ximage = 5, /* index of linked list of XObject images */ obj_type_thread = 6, /* index of linked list of num article threads */ - /* |obj_type_thread| is the highest entry in |head_tab|, but there are a few - more linked lists that are handy: */ obj_type_pagestream = 7, /* Page stream objects */ obj_type_page = 8, /* /Page objects */ obj_type_pages = 9, /* /Pages objects */ @@ -198,7 +218,6 @@ typedef struct pdf_resource_struct_ { int last_resources; /* halfword to most recently generated Resources object. */ } pdf_resource_struct; -/**********************************************************************/ typedef struct os_obj_data_ { int num; @@ -222,10 +241,9 @@ typedef struct os_struct_ { unsigned int o_ctr; /* statistics: counter for objects within object streams */ } os_struct; -/**********************************************************************/ -# define packet_max_recursion 100 /* see |packet_cur_s| */ -# define packet_stack_size 100 +# define packet_max_recursion 100 /* see |packet_cur_s| */ +# define packet_stack_size 100 typedef struct packet_stack_record_ { float c0; @@ -247,8 +265,6 @@ typedef struct vf_struct_ { int vflua; /* flag, whether vf.*() functions are allowed */ } vf_struct; -/**********************************************************************/ - typedef struct pdf_output_file_ { FILE *file; /* the PDF output file handle */ char *file_name; /* the PDF output file name */ @@ -265,7 +281,6 @@ typedef struct pdf_output_file_ { int decimal_digits; int gen_tounicode; int inclusion_copy_font; - int replace_font; int minor_version; /* fixed minor part of the PDF version */ int compress_level; /* level for zlib object stream compression */ int objcompresslevel; /* fixed level for activating PDF object streams */ @@ -292,8 +307,7 @@ typedef struct pdf_output_file_ { int stream_deflate; /* true, if stream dict has /Filter/FlateDecode */ int stream_writing; /* true while writing stream */ - int pk_scale_factor; /* this is just a preprocessed value that depends on - |pk_resolution| and |decimal_digits| */ + int pk_scale_factor; /* this is just a preprocessed value that depends on |pk_resolution| and |decimal_digits| */ int img_page_group_val; /* page group information pointer from included pdf or png images */ char *resname_prefix; /* global prefix of resources name */ @@ -320,10 +334,6 @@ typedef struct pdf_output_file_ { int seek_write_length; /* flag whether to seek back and write \.{/Length} */ int last_byte; /* byte most recently written to PDF file; for \.{endstream} in new line */ - /* integer last_resources; halfword to most recently generated Resources object. - TH: this used to be a local in pdf_shipout, but I would like to - be able to split that function into a pre- and post part */ - int obj_count; int xform_count; int ximage_count; @@ -351,7 +361,6 @@ typedef struct pdf_output_file_ { int thread_level; /* depth of nesting of box containing the last thread */ int f_cur; /* TeX font number */ - int pdflua_ref; int cave; /* stay away from previous PDF object */ vf_struct *vfstruct; @@ -359,4 +368,4 @@ typedef struct pdf_output_file_ { typedef pdf_output_file *PDF; -#endif /* PDFTYPES_H */ +#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfxform.h b/Build/source/texk/web2c/luatexdir/pdf/pdfxform.h index 9c62f71c0a2..f7f6e54d68f 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfxform.h +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfxform.h @@ -15,44 +15,37 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ + with LuaTeX; if not, see . +*/ #ifndef PDFXFORM_H # define PDFXFORM_H -/* data structure for box resources */ - -# define pdfmem_xform_size 8 /* size of memory in |pdf->mem| which |obj_data_ptr| holds */ - -# define set_pdf_xform_objnum(A,B) pdf_xform_objnum(A)=B - -# define obj_xform_width(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 0] -# define obj_xform_height(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 1] -# define obj_xform_depth(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 2] -# define obj_xform_box(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 3] /* this field holds - pointer to the corresponding box */ -# define obj_xform_attr(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 4] /* additional xform - attributes */ -# define obj_xform_resources(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 5] /* additional xform - Resources */ -# define obj_xform_attr_str(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 6] -# define obj_xform_resources_str(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 7] - - -# define set_obj_xform_width(pdf,A,B) obj_xform_width(pdf,A)=B -# define set_obj_xform_height(pdf,A,B) obj_xform_height(pdf,A)=B -# define set_obj_xform_depth(pdf,A,B) obj_xform_depth(pdf,A)=B -# define set_obj_xform_box(pdf,A,B) obj_xform_box(pdf,A)=B -# define set_obj_xform_attr(pdf,A,B) obj_xform_attr(pdf,A)=B -# define set_obj_xform_resources(pdf,A,B) obj_xform_resources(pdf,A)=B -# define set_obj_xform_attr_str(pdf,A,B) obj_xform_attr_str(pdf,A)=B +# define pdfmem_xform_size 8 /* size of memory in |pdf->mem| which |obj_data_ptr| holds */ + +# define obj_xform_width(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 0] +# define obj_xform_height(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 1] +# define obj_xform_depth(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 2] +# define obj_xform_box(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 3] /* this field holds pointer to the corresponding box */ +# define obj_xform_attr(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 4] /* additional xform attributes */ +# define obj_xform_resources(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 5] /* additional xform Resources */ +# define obj_xform_attr_str(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 6] +# define obj_xform_resources_str(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 7] + +# define set_pdf_xform_objnum(A,B) pdf_xform_objnum(A)=B +# define set_obj_xform_width(pdf,A,B) obj_xform_width(pdf,A)=B +# define set_obj_xform_height(pdf,A,B) obj_xform_height(pdf,A)=B +# define set_obj_xform_depth(pdf,A,B) obj_xform_depth(pdf,A)=B +# define set_obj_xform_box(pdf,A,B) obj_xform_box(pdf,A)=B +# define set_obj_xform_attr(pdf,A,B) obj_xform_attr(pdf,A)=B +# define set_obj_xform_resources(pdf,A,B) obj_xform_resources(pdf,A)=B +# define set_obj_xform_attr_str(pdf,A,B) obj_xform_attr_str(pdf,A)=B # define set_obj_xform_resources_str(pdf,A,B) obj_xform_resources_str(pdf,A)=B -extern int pdf_cur_form; /* the form being output */ +extern int pdf_cur_form; /* the form being output */ void pdf_place_form(PDF pdf, halfword p); - void scan_pdfxform(PDF pdf); void scan_pdfrefxform(PDF pdf); diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfxform.w b/Build/source/texk/web2c/luatexdir/pdf/pdfxform.w index 46a0910f6f7..962acb0f031 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfxform.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfxform.w @@ -73,14 +73,14 @@ void scan_pdfxform(PDF pdf) k = pdf_create_obj(pdf, obj_type_xform, pdf->xform_count); set_obj_data_ptr(pdf, k, pdf_get_mem(pdf, pdfmem_xform_size)); if (scan_keyword("attr")) { - scan_pdf_ext_toks(); + scan_toks(false, true); set_obj_xform_attr(pdf, k, def_ref); } else { set_obj_xform_attr(pdf, k, null); } set_obj_xform_attr_str(pdf, k, null); if (scan_keyword("resources")) { - scan_pdf_ext_toks(); + scan_toks(false, true); set_obj_xform_resources(pdf, k, def_ref); } else { set_obj_xform_resources(pdf, k, null); diff --git a/Build/source/texk/web2c/luatexdir/ptexlib.h b/Build/source/texk/web2c/luatexdir/ptexlib.h index 3d05b8661c5..e282e1774cc 100644 --- a/Build/source/texk/web2c/luatexdir/ptexlib.h +++ b/Build/source/texk/web2c/luatexdir/ptexlib.h @@ -80,7 +80,7 @@ extern char **suffixlist; /* in luainit.w */ # define check_buf(size, buf_size) \ if ((unsigned)(size) > (unsigned)(buf_size)) \ - luatex_fail("buffer overflow: %d > %d at file %s, line %d", \ + formatted_error("internal","buffer overflow: %d > %d at file %s, line %d", \ (int)(size), (int)(buf_size), __FILE__, __LINE__ ) # define append_char_to_buf(c, p, buf, buf_size) do { \ @@ -178,7 +178,6 @@ size_t T##_limit # include "pdf/pdflink.h" # include "pdf/pdflistout.h" # include "pdf/pdfliteral.h" -# include "pdf/pdfluaapi.h" # include "pdf/pdfobj.h" # include "pdf/pdfoutline.h" # include "pdf/pdfrule.h" @@ -188,9 +187,6 @@ size_t T##_limit # include "pdf/pdfthread.h" # include "pdf/pdfxform.h" -# include "lua/luagen.h" - -# include "luascripts/pdflua.h" # include "font/luatexfont.h" # include "font/mapfile.h" @@ -237,9 +233,6 @@ size_t T##_limit # include "tex/filename.h" -/* lua/luainit.c */ -extern void write_svnversion(char *a); - /**********************************************************************/ extern halfword new_ligkern(halfword head, halfword tail); @@ -288,9 +281,6 @@ int luacstring_input(void); int luacstring_partial(void); int luacstring_final_line(void); -/* lua/luatoken.c */ -void do_get_token_lua(int callback_id); - /* lua/luanode.c */ int visible_last_node_type(int n); void print_node_mem_stats(void); @@ -326,7 +316,6 @@ extern boolean get_callback(lua_State * L, int i); /* test whether a char in font is marked */ # define pdf_char_marked char_used -# define pdfassert assert # define voidcast(a) (void *)(a) # define fixmemcast(a) (smemory_word *)(a) diff --git a/Build/source/texk/web2c/luatexdir/tex/align.w b/Build/source/texk/web2c/luatexdir/tex/align.w index 75c3f932252..f1984a88c50 100644 --- a/Build/source/texk/web2c/luatexdir/tex/align.w +++ b/Build/source/texk/web2c/luatexdir/tex/align.w @@ -671,15 +671,15 @@ boolean fin_col(void) adjust_tail = cur_tail; pre_adjust_tail = cur_pre_tail; u = filtered_hpack(cur_list.head_field, cur_list.tail_field, 0, - additional, align_set_group, -1); + additional, align_set_group, -1, 0); w = width(u); cur_tail = adjust_tail; adjust_tail = null; cur_pre_tail = pre_adjust_tail; pre_adjust_tail = null; } else { - u = filtered_vpackage(vlink(cur_list.head_field), 0, additional, 0, - align_set_group, -1); + u = filtered_vpackage(vlink(cur_list.head_field), + 0, additional, 0, align_set_group, -1, 0); w = height(u); } n = min_quarterword; /* this represents a span count of 1 */ @@ -772,7 +772,7 @@ void fin_row(void) pointer p; /* the new unset box */ if (cur_list.mode_field == -hmode) { p = filtered_hpack(cur_list.head_field, cur_list.tail_field, 0, - additional, fin_row_group, -1); + additional, fin_row_group, -1, 0); pop_nest(); if (cur_pre_head != cur_pre_tail) append_list(cur_pre_head, cur_pre_tail); @@ -780,8 +780,8 @@ void fin_row(void) if (cur_head != cur_tail) append_list(cur_head, cur_tail); } else { - p = filtered_vpackage(vlink(cur_list.head_field), 0, additional, - max_depth, fin_row_group, -1); + p = filtered_vpackage(vlink(cur_list.head_field), + 0, additional, max_depth, fin_row_group, -1, 0); pop_nest(); vlink(cur_list.tail_field) = p; cur_list.tail_field = p; @@ -932,8 +932,8 @@ value is changed to zero and so is the next tabskip. width(q) = 0; q = vlink(vlink(q)); } while (q != null); - p = filtered_vpackage(preamble, saved_value(0), saved_level(0), - max_depth, preamble_group, -1); + p = filtered_vpackage(preamble, + saved_value(0), saved_level(0), max_depth, preamble_group, -1, 0); q = vlink(preamble); do { width(q) = height(q); diff --git a/Build/source/texk/web2c/luatexdir/tex/buildpage.w b/Build/source/texk/web2c/luatexdir/tex/buildpage.w index a1807b91993..409a10c33ba 100644 --- a/Build/source/texk/web2c/luatexdir/tex/buildpage.w +++ b/Build/source/texk/web2c/luatexdir/tex/buildpage.w @@ -19,7 +19,6 @@ @ @c - #include "ptexlib.h" @ @c @@ -32,7 +31,6 @@ #define vbadness int_par(vbadness_code) #define max_dead_cycles int_par(max_dead_cycles_code) #define output_box int_par(output_box_code) -#define body_direction int_par(body_direction_code) #define holding_inserts int_par(holding_inserts_code) #define vsize dimen_par(vsize_code) @@ -95,7 +93,6 @@ halfword best_page_break; /* break here to get the best page known so far int least_page_cost; /* the score for this currently best page */ scaled best_size; /* its |page_goal| */ - @ The page builder has another data structure to keep track of insertions. This is a list of four-word nodes, starting and ending at |page_ins_head|. That is, the first element of the list is node |r@t$_1$@>=vlink(page_ins_head)|; @@ -128,8 +125,6 @@ minimum badness among all page breaks considered so far. We have |best_ins_ptr(r)=null| if and only if no insertion for this box should be made to produce this optimum page. - - @ Pages are built by appending nodes to the current list in \TeX's vertical mode, which is at the outermost level of the semantic nest. This vlist is split into two parts; the ``current page'' that we have been @@ -195,13 +190,13 @@ scaled last_kern; /* used to implement \.{\\lastkern} */ int last_node_type; /* used to implement \.{\\lastnodetype} */ int insert_penalties; /* sum of the penalties for held-over insertions */ -#define print_plus(A,B) do { \ - if (page_so_far[(A)]!=0) { \ - tprint(" plus "); \ - print_scaled(page_so_far[(A)]); \ - tprint((B)); \ - } \ - } while (0) +#define print_plus(A,B) do { \ + if (page_so_far[(A)]!=0) { \ + tprint(" plus "); \ + print_scaled(page_so_far[(A)]); \ + tprint((B)); \ + } \ +} while (0) void print_totals(void) { @@ -216,7 +211,6 @@ void print_totals(void) } } - @ Here is a procedure that is called when the |page_contents| is changing from |empty| to |inserts_only| or |box_there|. @@ -242,14 +236,12 @@ void freeze_page_specs(int s) } } - @ The global variable |output_active| is true during the time the user's output routine is driving \TeX. @c boolean output_active; /* are we in the midst of an output routine? */ - @ The page builder is ready to start a fresh page if we initialize the following state variables. (However, the page insertion list is initialized elsewhere.) @@ -268,7 +260,6 @@ void start_new_page(void) page_max_depth = 0; } - @ At certain times box \.{\\outputbox} is supposed to be void (i.e., |null|), or an insertion box is supposed to be ready to accept a vertical list. If not, an error message is printed, and the following subroutine @@ -286,7 +277,6 @@ static void box_error(int n) box(n) = null; } - @ The following procedure guarantees that a given box register does not contain an \.{\\hbox}. @@ -304,7 +294,6 @@ static void ensure_vbox(int n) } } - @ \TeX\ is not always in vertical mode at the time |build_page| is called; the current mode reflects what \TeX\ should return to, after the contribution list has been emptied. A call on |build_page| should @@ -317,10 +306,9 @@ void build_page(void) halfword p; /* the node being appended */ halfword q, r; /* nodes being examined */ int b, c; /* badness and cost of current page */ - int pi; /* penalty to be added to the badness */ + int pi = 0; /* penalty to be added to the badness */ int n; /* insertion box number */ scaled delta, h, w; /* sizes used for insertion calculations */ - pi = 0; if ((vlink(contrib_head) == null) || output_active) return; do { @@ -917,9 +905,8 @@ void fire_up(halfword c) vbadness = inf_bad; save_vfuzz = vfuzz; vfuzz = max_dimen; /* inhibit error messages */ - box(output_box) = - filtered_vpackage(vlink(page_head), best_size, exactly, page_max_depth, - output_group, body_direction); + box(output_box) = filtered_vpackage(vlink(page_head), + best_size, exactly, page_max_depth, output_group, body_direction, 0); vbadness = save_vbadness; vfuzz = save_vfuzz; if (last_glue != max_halfword) @@ -993,7 +980,6 @@ void fire_up(halfword c) box(output_box) = null; } - @ When the user's output routine finishes, it has constructed a vlist in internal vertical mode, and \TeX\ will do the following: @@ -1045,5 +1031,4 @@ void resume_after_output(void) pop_nest(); lua_node_filter_s(buildpage_filter_callback,lua_key_index(after_output)); build_page(); - } diff --git a/Build/source/texk/web2c/luatexdir/tex/commands.h b/Build/source/texk/web2c/luatexdir/tex/commands.h index ef0e5d796df..d2a7779a0e1 100644 --- a/Build/source/texk/web2c/luatexdir/tex/commands.h +++ b/Build/source/texk/web2c/luatexdir/tex/commands.h @@ -207,6 +207,7 @@ typedef enum { variable_cmd, feedback_cmd, the_cmd, /* expand an internal quantity ( \.{\\the} or \.{\\unexpanded}, \.{\\detokenize} ) */ + combine_toks_cmd, top_bot_mark_cmd, /* inserted mark ( \.{\\topmark}, etc.~) */ call_cmd, /* non-long, non-outer control sequence */ long_call_cmd, /* long, non-outer control sequence */ @@ -234,33 +235,34 @@ typedef enum { typedef enum { number_code = 0, /* command code for \.{\\number} */ - roman_numeral_code, /* command code for \.{\\romannumeral} */ + lua_function_code, /* command code for \.{\\luafunction} */ + lua_code, /* command code for \.{\\directlua} */ + expanded_code, /* command code for \.{\\expanded} */ + math_style_code, /* command code for \.{\\mathstyle} */ string_code, /* command code for \.{\\string} */ + cs_string_code, /* command code for \.{\\csstring} */ + roman_numeral_code, /* command code for \.{\\romannumeral} */ meaning_code, /* command code for \.{\\meaning} */ + uchar_code, /* command code for \.{\\Uchar} */ + lua_escape_string_code, /* command code for \.{\\luaescapestring} */ + font_id_code, /* command code for \.{\\fontid} */ font_name_code, /* command code for \.{\\fontname} */ - etex_code, /* command code for \.{\\eTeXVersion} */ - format_name_code, /* command code for \.{\\AlephVersion} */ - luatex_banner_code, /* command code for \.{\\luatexbanner}: */ left_margin_kern_code, /* command code for \.{\\leftmarginkern} */ right_margin_kern_code, /* command code for \.{\\rightmarginkern} */ uniform_deviate_code, /* command code for \.{\\uniformdeviate} */ normal_deviate_code, /* command code for \.{\\normaldeviate} */ - lua_code, /* command code for \.{\\directlua} */ - lua_escape_string_code, /* command code for \.{\\luaescapestring} */ + math_char_class_code, + math_char_fam_code, + math_char_slot_code, + insert_ht_code, /* command code for \.{\\insertht} */ + job_name_code, /* command code for \.{\\jobname} */ + format_name_code, /* command code for \.{\\AlephVersion} */ + luatex_banner_code, /* command code for \.{\\luatexbanner}: */ luatex_revision_code, /* command code for \.{\\luatexrevision} */ luatex_date_code, /* command code for \.{\\luatexdate} */ - math_style_code, /* command code for \.{\\mathstyle} */ - expanded_code, /* command code for \.{\\expanded} */ - job_name_code, /* command code for \.{\\jobname} */ + etex_code, /* command code for \.{\\eTeXVersion} */ eTeX_revision_code, /* command code for \.{\\eTeXrevision} */ font_identifier_code, /* command code for \.{tex.fontidentifier} (virtual) */ - font_id_code, /* command code for \.{\\fontid} */ - uchar_code, /* command code for \.{\\Uchar} */ - lua_function_code, /* command code for \.{\\luafunction} */ - insert_ht_code, /* command code for \.{\\insertht} */ - math_char_class_code, - math_char_fam_code, - math_char_slot_code, /* backend */ dvi_feedback_code, pdf_feedback_code, diff --git a/Build/source/texk/web2c/luatexdir/tex/commands.w b/Build/source/texk/web2c/luatexdir/tex/commands.w index 8cd6128b54d..02c2e4a74ae 100644 --- a/Build/source/texk/web2c/luatexdir/tex/commands.w +++ b/Build/source/texk/web2c/luatexdir/tex/commands.w @@ -1,4 +1,4 @@ - % commands.w +% commands.w % % Copyright 2009-2010 Taco Hoekwater % @@ -123,6 +123,7 @@ void initialize_commands(void) primitive_luatex("luastartup", assign_int_cmd, int_base + luastartup_id_code, int_base); primitive_luatex("nokerns", assign_int_cmd, int_base + disable_kern_code, int_base); primitive_luatex("noligs", assign_int_cmd, int_base + disable_lig_code, int_base); + primitive_luatex("nospaces", assign_int_cmd, int_base + disable_space_code, int_base); primitive_luatex("catcodetable", assign_int_cmd, int_base + cat_code_table_code, int_base); primitive_luatex("outputbox", assign_int_cmd, int_base + output_box_code, int_base); primitive_luatex("outputmode", assign_int_cmd, int_base + output_mode_code, int_base); @@ -168,6 +169,8 @@ void initialize_commands(void) primitive_tex("begingroup", begin_group_cmd, 0, 0); primitive_tex("char", char_num_cmd, 0, 0); primitive_tex("csname", cs_name_cmd, 0, 0); + primitive_luatex("lastnamedcs", cs_name_cmd, 1, 0); + primitive_luatex("begincsname", cs_name_cmd, 2, 0); primitive_tex("delimiter", delim_num_cmd, 0, 0); primitive_luatex("Udelimiter", delim_num_cmd, 1, 0); primitive_tex("divide", divide_cmd, 0, 0); @@ -184,6 +187,7 @@ void initialize_commands(void) primitive_tex("fontdimen", assign_font_dimen_cmd, 0, 0); primitive_tex("halign", halign_cmd, 0, 0); primitive_tex("hrule", hrule_cmd, 0, 0); + primitive_luatex("nohrule", no_vrule_cmd, 0, 0); primitive_tex("ignorespaces", ignore_spaces_cmd, 0, 0); primitive_tex("insert", insert_cmd, 0, 0); primitive_luatex("leftghost", char_ghost_cmd, 0, 0); @@ -197,8 +201,6 @@ void initialize_commands(void) primitive_luatex("Ustack", math_choice_cmd, 1, 0); primitive_tex("multiply", multiply_cmd, 0, 0); primitive_tex("noalign", no_align_cmd, 0, 0); - primitive_luatex("nohrule", no_vrule_cmd, 0, 0); - primitive_luatex("novrule", no_hrule_cmd, 0, 0); primitive_tex("boundary", boundary_cmd, 0, 0); primitive_tex("noboundary", no_boundary_cmd, 0, 0); primitive_tex("noexpand", no_expand_cmd, 0, 0); @@ -223,11 +225,16 @@ void initialize_commands(void) primitive_luatex("rightghost", char_ghost_cmd, 1, 0); primitive_tex("setbox", set_box_cmd, 0, 0); primitive_tex("the", the_cmd, 0, 0); + primitive_luatex("toksapp", combine_toks_cmd, 0, 0); + primitive_luatex("tokspre", combine_toks_cmd, 1, 0); + primitive_luatex("etoksapp", combine_toks_cmd, 2, 0); + primitive_luatex("etokspre", combine_toks_cmd, 3, 0); primitive_tex("toks", toks_register_cmd, 0, 0); primitive_tex("vadjust", vadjust_cmd, 0, 0); primitive_tex("valign", valign_cmd, 0, 0); primitive_tex("vcenter", vcenter_cmd, 0, 0); primitive_tex("vrule", vrule_cmd, 0, 0); + primitive_luatex("novrule", no_hrule_cmd, 0, 0); primitive_tex("par", par_end_cmd, too_big_char, too_big_char); /* cf.\ |scan_file_name| */ par_loc = cur_val; par_token = cs_token_flag + par_loc; @@ -297,6 +304,7 @@ void initialize_commands(void) primitive_tex("number", convert_cmd, number_code, 0); primitive_tex("romannumeral", convert_cmd, roman_numeral_code, 0); primitive_tex("string", convert_cmd, string_code, 0); + primitive_tex("csstring", convert_cmd, cs_string_code, 0); primitive_tex("meaning", convert_cmd, meaning_code, 0); primitive_etex("eTeXVersion", convert_cmd, etex_code, 0); primitive_tex("fontname", convert_cmd, font_name_code, 0); @@ -408,6 +416,9 @@ void initialize_commands(void) primitive_tex("copy", make_box_cmd, copy_code, 0); primitive_tex("lastbox", make_box_cmd, last_box_code, 0); primitive_tex("vsplit", make_box_cmd, vsplit_code, 0); + primitive_tex("tpack", make_box_cmd, tpack_code, 0); + primitive_tex("vpack", make_box_cmd, vpack_code, 0); + primitive_tex("hpack", make_box_cmd, hpack_code, 0); primitive_tex("vtop", make_box_cmd, vtop_code, 0); primitive_tex("vbox", make_box_cmd, vtop_code + vmode, 0); primitive_tex("hbox", make_box_cmd, vtop_code + hmode, 0); @@ -488,6 +499,7 @@ void initialize_commands(void) primitive_tex("xdef", def_cmd, 3, 0); primitive_tex("let", let_cmd, normal, 0); primitive_tex("futurelet", let_cmd, normal + 1, 0); + primitive_luatex("letcharcode", let_cmd, normal + 2, 0); primitive_tex("chardef", shorthand_def_cmd, char_def_code, 0); primitive_tex("mathchardef", shorthand_def_cmd, math_char_def_code, 0); primitive_luatex("Umathchardef", shorthand_def_cmd, xmath_char_def_code, 0); @@ -637,6 +649,7 @@ void initialize_commands(void) primitive_luatex("preexhyphenchar", hyph_data_cmd, 4, 0); primitive_luatex("postexhyphenchar", hyph_data_cmd, 5, 0); primitive_luatex("hyphenationmin", hyph_data_cmd, 6, 0); + primitive_luatex("hjcode", hyph_data_cmd, 7, 0); primitive_tex("hyphenchar", assign_font_int_cmd, 0, 0); primitive_tex("skewchar", assign_font_int_cmd, 1, 0); primitive_luatex("lpcode", assign_font_int_cmd, lp_code_base, 0); diff --git a/Build/source/texk/web2c/luatexdir/tex/conditional.h b/Build/source/texk/web2c/luatexdir/tex/conditional.h index 13e822a1bf9..b6abe7578d3 100644 --- a/Build/source/texk/web2c/luatexdir/tex/conditional.h +++ b/Build/source/texk/web2c/luatexdir/tex/conditional.h @@ -1,5 +1,5 @@ /* conditional.h - + Copyright 2009 Taco Hoekwater This file is part of LuaTeX. @@ -15,61 +15,57 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ - + with LuaTeX; if not, see . +*/ #ifndef CONDITIONAL_H # define CONDITIONAL_H - # define unless_code 32 /* amount added for `\.{\\unless}' prefix */ typedef enum { - if_char_code = 0, /* `\.{\\if}' */ - if_cat_code = 1, /* `\.{\\ifcat}' */ - if_int_code = 2, /* `\.{\\ifnum}' */ - if_dim_code = 3, /* `\.{\\ifdim}' */ - if_odd_code = 4, /* `\.{\\ifodd}' */ - if_vmode_code = 5, /* `\.{\\ifvmode}' */ - if_hmode_code = 6, /* `\.{\\ifhmode}' */ - if_mmode_code = 7, /* `\.{\\ifmmode}' */ - if_inner_code = 8, /* `\.{\\ifinner}' */ - if_void_code = 9, /* `\.{\\ifvoid}' */ - if_hbox_code = 10, /* `\.{\\ifhbox}' */ - if_vbox_code = 11, /* `\.{\\ifvbox}' */ - ifx_code = 12, /* `\.{\\ifx}' */ - if_eof_code = 13, /* `\.{\\ifeof}' */ - if_true_code = 14, /* `\.{\\iftrue}' */ - if_false_code = 15, /* `\.{\\iffalse}' */ - if_case_code = 16, /* `\.{\\ifcase}' */ - if_def_code = 17, /* `\.{\\ifdefined}' */ - if_cs_code = 18, /* `\.{\\ifcsname}' */ - if_font_char_code = 19, /* `\.{\\iffontchar}' */ - if_in_csname_code = 20, /* `\.{\\ifincsname}' */ - if_primitive_code = 21, /* `\.{\\ifprimitive}' */ - if_abs_num_code = 22, /* `\.{\\ifabsnum}' */ - if_abs_dim_code = 23, /* `\.{\\ifabsdim}' */ + if_char_code = 0, /* \.{\\if} */ + if_cat_code = 1, /* \.{\\ifcat} */ + if_int_code = 2, /* \.{\\ifnum} */ + if_dim_code = 3, /* \.{\\ifdim} */ + if_odd_code = 4, /* \.{\\ifodd} */ + if_vmode_code = 5, /* \.{\\ifvmode} */ + if_hmode_code = 6, /* \.{\\ifhmode} */ + if_mmode_code = 7, /* \.{\\ifmmode} */ + if_inner_code = 8, /* \.{\\ifinner} */ + if_void_code = 9, /* \.{\\ifvoid} */ + if_hbox_code = 10, /* \.{\\ifhbox} */ + if_vbox_code = 11, /* \.{\\ifvbox} */ + ifx_code = 12, /* \.{\\ifx} */ + if_eof_code = 13, /* \.{\\ifeof} */ + if_true_code = 14, /* \.{\\iftrue} */ + if_false_code = 15, /* \.{\\iffalse} */ + if_case_code = 16, /* \.{\\ifcase} */ + if_def_code = 17, /* \.{\\ifdefined} */ + if_cs_code = 18, /* \.{\\ifcsname} */ + if_font_char_code = 19, /* \.{\\iffontchar} */ + if_in_csname_code = 20, /* \.{\\ifincsname} */ + if_primitive_code = 21, /* \.{\\ifprimitive} */ + if_abs_num_code = 22, /* \.{\\ifabsnum} */ + if_abs_dim_code = 23, /* \.{\\ifabsdim} */ } if_type_codes; - - - # define if_limit_subtype(A) subtype((A)+1) # define if_limit_type(A) type((A)+1) # define if_line_field(A) vlink((A)+1) typedef enum { - if_code = 1, /* code for \.{\\if...} being evaluated */ - fi_code = 2, /* code for \.{\\fi} */ - else_code = 3, /* code for \.{\\else} */ - or_code = 4, /* code for \.{\\or} */ + if_code = 1, /* \.{\\if...} */ + fi_code = 2, /* \.{\\fi} */ + else_code = 3, /* \.{\\else} */ + or_code = 4, /* \.{\\or} */ } else_type_codes; -extern halfword cond_ptr; /* top of the condition stack */ -extern int if_limit; /* upper bound on |fi_or_else| codes */ -extern int cur_if; /* type of conditional being worked on */ -extern int if_line; /* line where that conditional began */ -extern int skip_line; /* skipping began here */ +extern halfword cond_ptr; /* top of the condition stack */ +extern int if_limit; /* upper bound on |fi_or_else| codes */ +extern int cur_if; /* type of conditional being worked on */ +extern int if_line; /* line where that conditional began */ +extern int skip_line; /* skipping began here */ extern void pass_text(void); extern void push_condition_stack(void); diff --git a/Build/source/texk/web2c/luatexdir/tex/conditional.w b/Build/source/texk/web2c/luatexdir/tex/conditional.w index 53967087102..fa4e73b49cb 100644 --- a/Build/source/texk/web2c/luatexdir/tex/conditional.w +++ b/Build/source/texk/web2c/luatexdir/tex/conditional.w @@ -19,7 +19,6 @@ @ @c - #include "ptexlib.h" @ @c @@ -49,14 +48,12 @@ int if_limit; /* upper bound on |fi_or_else| codes */ int cur_if; /* type of conditional being worked on */ int if_line; /* line where that conditional began */ - @ When we skip conditional text, we keep track of the line number where skipping began, for use in error messages. @c int skip_line; /* skipping began here */ - @ Here is a procedure that ignores text until coming to an \.{\\or}, \.{\\else}, or \.{\\fi} at level zero of $\.{\\if}\ldots\.{\\fi}$ nesting. After it has acted, |cur_chr| will indicate the token that @@ -66,14 +63,12 @@ procedure run faster). @c void pass_text(void) { - int l; /* level of $\.{\\if}\ldots\.{\\fi}$ nesting */ - int save_scanner_status; /* |scanner_status| upon entry */ - save_scanner_status = scanner_status; + int l = 0; /* level of $\.{\\if}\ldots\.{\\fi}$ nesting */ + int save_scanner_status = scanner_status; /* |scanner_status| upon entry */ scanner_status = skipping; - l = 0; skip_line = line; while (1) { - get_next(); /* get_token_lua(); */ + get_next(); if (cur_cmd == fi_or_else_cmd) { if (l == 0) break; @@ -88,7 +83,6 @@ void pass_text(void) show_cur_cmd_chr(); } - @ When we begin to process a new \.{\\if}, we set |if_limit:=if_code|; then if\/ \.{\\or} or \.{\\else} or \.{\\fi} occurs before the current \.{\\if} condition has been evaluated, \.{\\relax} will be inserted. @@ -123,18 +117,17 @@ void pop_condition_stack(void) flush_node(p); } - @ Here's a procedure that changes the |if_limit| code corresponding to a given value of |cond_ptr|. @c void change_if_limit(int l, halfword p) { - halfword q; if (p == cond_ptr) { - if_limit = l; /* that's the easy case */ + /* that's the easy case */ + if_limit = l; } else { - q = cond_ptr; + halfword q = cond_ptr; while (1) { if (q == null) confusion("if"); @@ -147,21 +140,21 @@ void change_if_limit(int l, halfword p) } } - @ The conditional \.{\\ifcsname} is equivalent to \.{\\expandafter} \.{\\expandafter} \.{\\ifdefined} \.{\\csname}, except that no new control sequence will be entered into the hash table (once all tokens preceding the mandatory \.{\\endcsname} have been expanded). @c +static halfword last_tested_cs ; + static boolean test_for_cs(void) { - boolean b; /*is the condition true? */ + boolean b = false; /*is the condition true? */ int m, s; /*to be tested against the second operand */ - halfword n, p, q; /*for traversing token lists in \.{\\ifx} tests */ - n = get_avail(); - p = n; /*head of the list of characters */ - b = false; + halfword q; /*for traversing token lists in \.{\\ifx} tests */ + halfword n = get_avail(); + halfword p = n; /*head of the list of characters */ while (1) { get_x_token(); if (cur_cs != 0) @@ -169,6 +162,7 @@ static boolean test_for_cs(void) store_new_token(cur_tok); } if (cur_cmd != end_cs_name_cmd) { + last_tested_cs = null_cs; if (int_par(suppress_ifcsname_error_code)) { do { get_x_token(); @@ -201,41 +195,35 @@ static boolean test_for_cs(void) } else { buffer[m++] = (packed_ASCII_code) (0xF0 + s / 0x40000); buffer[m++] = (packed_ASCII_code) (0x80 + (s % 0x40000) / 0x1000); - buffer[m++] = - (packed_ASCII_code) (0x80 + ((s % 0x40000) % 0x1000) / 0x40); - buffer[m++] = - (packed_ASCII_code) (0x80 + ((s % 0x40000) % 0x1000) % 0x40); + buffer[m++] = (packed_ASCII_code) (0x80 + ((s % 0x40000) % 0x1000) / 0x40); + buffer[m++] = (packed_ASCII_code) (0x80 + ((s % 0x40000) % 0x1000) % 0x40); } p = token_link(p); } if (m > first) { - cur_cs = id_lookup(first, m - first); /*|no_new_control_sequence| is |true| */ + cur_cs = id_lookup(first, m - first); /* |no_new_control_sequence| is |true| */ } else if (m == first) { - cur_cs = null_cs; /*the list is empty */ + cur_cs = null_cs; /* the list is empty */ } b = (eq_type(cur_cs) != undefined_cs_cmd); flush_list(n); + last_cs_name = cur_cs; return b; } - @ An active character will be treated as category 13 following \.{\\if\\noexpand} or following \.{\\ifcat\\noexpand}. @c -#define get_x_token_or_active_char() do { \ - get_x_token(); \ - if (cur_cmd==relax_cmd && cur_chr==no_expand_flag) { \ - if (is_active_cs(cs_text(cur_cs))) { \ - cur_cmd=active_char_cmd; \ - cur_chr=active_cs_value(cs_text(cur_tok-cs_token_flag)); \ - } \ - } \ - } while (0) - - - - +#define get_x_token_or_active_char() do { \ + get_x_token(); \ + if (cur_cmd==relax_cmd && cur_chr==no_expand_flag) { \ + if (is_active_cs(cs_text(cur_cs))) { \ + cur_cmd=active_char_cmd; \ + cur_chr=active_cs_value(cs_text(cur_tok-cs_token_flag)); \ + } \ + } \ +} while (0) @ A condition is started when the |expand| procedure encounters an |if_test| command; in that case |expand| reduces to |conditional|, @@ -245,7 +233,7 @@ which is a recursive procedure. @c void conditional(void) { - boolean b; /*is the condition true? */ + boolean b = false; /*is the condition true? */ int r; /*relation to be evaluated */ int m, n; /*to be tested against the second operand */ halfword p, q; /*for traversing token lists in \.{\\ifx} tests */ @@ -253,245 +241,271 @@ void conditional(void) halfword save_cond_ptr; /*|cond_ptr| corresponding to this conditional */ int this_if; /*type of this conditional */ boolean is_unless; /*was this if preceded by `\.{\\unless}' ? */ - b = false; /*default is false, just in case */ - if (int_par(tracing_ifs_code) > 0) - if (int_par(tracing_commands_code) <= 1) - show_cur_cmd_chr(); + if ((int_par(tracing_ifs_code) > 0) && (int_par(tracing_commands_code) <= 1)) + show_cur_cmd_chr(); push_condition_stack(); save_cond_ptr = cond_ptr; is_unless = (cur_chr >= unless_code); this_if = cur_chr % unless_code; /* Either process \.{\\ifcase} or set |b| to the value of a boolean condition */ switch (this_if) { - case if_char_code: - case if_cat_code: - /* Test if two characters match */ - get_x_token_or_active_char(); - if ((cur_cmd > active_char_cmd) || (cur_chr > biggest_char)) { /*not a character */ - m = relax_cmd; - n = too_big_char; - } else { - m = cur_cmd; - n = cur_chr; - } - get_x_token_or_active_char(); - if ((cur_cmd > active_char_cmd) || (cur_chr > biggest_char)) { - cur_cmd = relax_cmd; - cur_chr = too_big_char; - } - if (this_if == if_char_code) - b = (n == cur_chr); - else - b = (m == cur_cmd); - break; - case if_int_code: - case if_dim_code: - case if_abs_dim_code: - case if_abs_num_code: - /* Test relation between integers or dimensions */ - /* Here we use the fact that |"<"|, |"="|, and |">"| are consecutive ASCII - codes. */ - if (this_if == if_int_code || this_if == if_abs_num_code) - scan_int(); - else - scan_normal_dimen(); - n = cur_val; - if (n < 0) - if (this_if == if_abs_dim_code || this_if == if_abs_num_code) + case if_char_code: + case if_cat_code: + /* Test if two characters match */ + get_x_token_or_active_char(); + if ((cur_cmd > active_char_cmd) || (cur_chr > biggest_char)) { + /*not a character */ + m = relax_cmd; + n = too_big_char; + } else { + m = cur_cmd; + n = cur_chr; + } + get_x_token_or_active_char(); + if ((cur_cmd > active_char_cmd) || (cur_chr > biggest_char)) { + cur_cmd = relax_cmd; + cur_chr = too_big_char; + } + if (this_if == if_char_code) + b = (n == cur_chr); + else + b = (m == cur_cmd); + break; + case if_int_code: + case if_dim_code: + case if_abs_dim_code: + case if_abs_num_code: + /* Test relation between integers or dimensions */ + /* Here we use the fact that |"<"|, |"="|, and |">"| are consecutive ASCII codes. */ + if (this_if == if_int_code || this_if == if_abs_num_code) + scan_int(); + else + scan_normal_dimen(); + n = cur_val; + if ((n < 0) && (this_if == if_abs_dim_code || this_if == if_abs_num_code)) negate(n); - - /* Get the next non-blank non-call... */ - do { - get_x_token(); - } while (cur_cmd == spacer_cmd); - - if ((cur_tok >= other_token + '<') && (cur_tok <= other_token + '>')) { + /* Get the next non-blank non-call... */ + do { + get_x_token(); + } while (cur_cmd == spacer_cmd); + /* + if ((cur_tok >= other_token + '<') && (cur_tok <= other_token + '>')) { + r = cur_tok - other_token; + } else { + */ r = cur_tok - other_token; - } else { - print_err("Missing = inserted for "); - print_cmd_chr(if_test_cmd, this_if); - help1("I was expecting to see `<', `=', or `>'. Didn't."); - back_error(); - r = '='; - } - if (this_if == if_int_code || this_if == if_abs_num_code) - scan_int(); - else - scan_normal_dimen(); - - if (cur_val < 0) - if (this_if == if_abs_dim_code || this_if == if_abs_num_code) + if ((r < '<') || (r > '>')) { + print_err("Missing = inserted for "); + print_cmd_chr(if_test_cmd, this_if); + help1("I was expecting to see `<', `=', or `>'. Didn't."); + back_error(); + r = '='; + } + if (this_if == if_int_code || this_if == if_abs_num_code) + scan_int(); + else + scan_normal_dimen(); + if ((cur_val < 0) && (this_if == if_abs_dim_code || this_if == if_abs_num_code)) negate(cur_val); - - switch (r) { - case '<': - b = (n < cur_val); + switch (r) { + case '<': + b = (n < cur_val); + break; + case '=': + b = (n == cur_val); + break; + case '>': + b = (n > cur_val); + break; + default: + /* can't happen */ + b = false; + break; + } + break; + case if_odd_code: + /* Test if an integer is odd */ + scan_int(); + b = odd(cur_val); break; - case '=': - b = (n == cur_val); + case if_vmode_code: + b = (abs(cur_list.mode_field) == vmode); break; - case '>': - b = (n > cur_val); + case if_hmode_code: + b = (abs(cur_list.mode_field) == hmode); break; - default: - b = false; - break; /*can't happen */ - } - break; - case if_odd_code: - /* Test if an integer is odd */ - scan_int(); - b = odd(cur_val); - break; - case if_vmode_code: - b = (abs(cur_list.mode_field) == vmode); - break; - case if_hmode_code: - b = (abs(cur_list.mode_field) == hmode); - break; - case if_mmode_code: - b = (abs(cur_list.mode_field) == mmode); - break; - case if_inner_code: - b = (cur_list.mode_field < 0); - break; - case if_void_code: - case if_hbox_code: - case if_vbox_code: - /* Test box register status */ - scan_register_num(); - p = box(cur_val); - if (this_if == if_void_code) + case if_mmode_code: + b = (abs(cur_list.mode_field) == mmode); + break; + case if_inner_code: + b = (cur_list.mode_field < 0); + break; + /* + case if_void_code: + case if_hbox_code: + case if_vbox_code: + scan_register_num(); + p = box(cur_val); + if (this_if == if_void_code) + b = (p == null); + else if (p == null) + b = false; + else if (this_if == if_hbox_code) + b = (type(p) == hlist_node); + else + b = (type(p) == vlist_node); + break; + */ + case if_void_code: + scan_register_num(); + p = box(cur_val); b = (p == null); - else if (p == null) - b = false; - else if (this_if == if_hbox_code) - b = (type(p) == hlist_node); - else - b = (type(p) == vlist_node); - break; - case ifx_code: - /* Test if two tokens match */ - /* Note that `\.{\\ifx}' will declare two macros different if one is \\{long} - or \\{outer} and the other isn't, even though the texts of the macros are - the same. - - We need to reset |scanner_status|, since \.{\\outer} control sequences - are allowed, but we might be scanning a macro definition or preamble. - */ - save_scanner_status = scanner_status; - scanner_status = normal; - get_next(); /* get_token_lua(); */ - n = cur_cs; - p = cur_cmd; - q = cur_chr; - get_next(); /* get_token_lua(); */ - if (cur_cmd != p) { - b = false; - } else if (cur_cmd < call_cmd) { - b = (cur_chr == q); - } else { - /* Test if two macro texts match */ - /* Note also that `\.{\\ifx}' decides that macros \.{\\a} and \.{\\b} are - different in examples like this: - $$\vbox{\halign{\.{#}\hfil&\qquad\.{#}\hfil\cr - {}\\def\\a\{\\c\}& - {}\\def\\c\{\}\cr - {}\\def\\b\{\\d\}& - {}\\def\\d\{\}\cr}}$$ */ - p = token_link(cur_chr); - q = token_link(equiv(n)); /*omit reference counts */ - if (p == q) { - b = true; + break; + case if_hbox_code: + scan_register_num(); + p = box(cur_val); + b = (p != null) && (type(p) == hlist_node); + break; + case if_vbox_code: + scan_register_num(); + p = box(cur_val); + b = (p != null) && (type(p) == vlist_node); + break; + case ifx_code: + /* + Test if two tokens match + + Note that `\.{\\ifx}' will declare two macros different if one is \\{long} + or \\{outer} and the other isn't, even though the texts of the macros are + the same. + + We need to reset |scanner_status|, since \.{\\outer} control sequences + are allowed, but we might be scanning a macro definition or preamble. + */ + save_scanner_status = scanner_status; + scanner_status = normal; + get_next(); + n = cur_cs; + p = cur_cmd; + q = cur_chr; + get_next(); + if (cur_cmd != p) { + b = false; + } else if (cur_cmd < call_cmd) { + b = (cur_chr == q); } else { - while ((p != null) && (q != null)) { - if (token_info(p) != token_info(q)) { - p = null; - } else { - p = token_link(p); - q = token_link(q); + /* + Test if two macro texts match + + Note also that `\.{\\ifx}' decides that macros \.{\\a} and \.{\\b} are + different in examples like this: + + $$\vbox{\halign{\.{#}\hfil&\qquad\.{#}\hfil\cr + {}\\def\\a\{\\c\}& + {}\\def\\c\{\}\cr + {}\\def\\b\{\\d\}& + {}\\def\\d\{\}\cr}}$$ + */ + p = token_link(cur_chr); + /*omit reference counts */ + q = token_link(equiv(n)); + if (p == q) { + b = true; + } else { + while ((p != null) && (q != null)) { + if (token_info(p) != token_info(q)) { + p = null; + break; + } else { + p = token_link(p); + q = token_link(q); + } } + b = ((p == null) && (q == null)); } - b = ((p == null) && (q == null)); } - } - scanner_status = save_scanner_status; - break; - case if_eof_code: - scan_four_bit_int(); - b = (read_open[cur_val] == closed); - break; - case if_true_code: - b = true; - break; - case if_false_code: - b = false; - break; - case if_case_code: - /* Select the appropriate case - and |return| or |goto common_ending| */ - scan_int(); - n = cur_val; /*|n| is the number of cases to pass */ - if (int_par(tracing_commands_code) > 1) { - begin_diagnostic(); - tprint("{case "); - print_int(n); - print_char('}'); - end_diagnostic(false); - } - while (n != 0) { - pass_text(); - if (cond_ptr == save_cond_ptr) { - if (cur_chr == or_code) - decr(n); - else - goto COMMON_ENDING; - } else if (cur_chr == fi_code) { - pop_condition_stack(); + scanner_status = save_scanner_status; + break; + case if_eof_code: + scan_four_bit_int(); + b = (read_open[cur_val] == closed); + break; + case if_true_code: + b = true; + break; + case if_false_code: + b = false; + break; + case if_case_code: + /* Select the appropriate case and |return| or |goto common_ending| */ + scan_int(); + /* |n| is the number of cases to pass */ + n = cur_val; + if (int_par(tracing_commands_code) > 1) { + begin_diagnostic(); + tprint("{case "); + print_int(n); + print_char('}'); + end_diagnostic(false); } - } - change_if_limit(or_code, save_cond_ptr); - return; /*wait for \.{\\or}, \.{\\else}, or \.{\\fi} */ - break; - case if_primitive_code: - save_scanner_status = scanner_status; - scanner_status = normal; - get_next(); /* get_token_lua(); */ - scanner_status = save_scanner_status; - m = prim_lookup(cs_text(cur_cs)); - b = ((cur_cmd != undefined_cs_cmd) && - (m != undefined_primitive) && - (cur_cmd == get_prim_eq_type(m)) && - (cur_chr == get_prim_equiv(m))); - break; - case if_def_code: - /* The conditional \.{\\ifdefined} tests if a control sequence is defined. */ - /* We need to reset |scanner_status|, since \.{\\outer} control sequences - are allowed, but we might be scanning a macro definition or preamble. */ - save_scanner_status = scanner_status; - scanner_status = normal; - get_next(); /* get_token_lua(); */ - b = (cur_cmd != undefined_cs_cmd); - scanner_status = save_scanner_status; - break; - case if_cs_code: - b = test_for_cs(); - break; - case if_in_csname_code: - b = is_in_csname; - break; - case if_font_char_code: - /* The conditional \.{\\iffontchar} tests the existence of a character in - a font. */ - scan_font_ident(); - n = cur_val; - scan_char_num(); - b = char_exists(n, cur_val); - break; - default: /* there are no other cases, but for -Wall: */ - b = false; + while (n != 0) { + pass_text(); + if (cond_ptr == save_cond_ptr) { + if (cur_chr == or_code) + decr(n); + else + goto COMMON_ENDING; + } else if (cur_chr == fi_code) { + pop_condition_stack(); + } + } + change_if_limit(or_code, save_cond_ptr); + /*wait for \.{\\or}, \.{\\else}, or \.{\\fi} */ + return; + break; + case if_primitive_code: + save_scanner_status = scanner_status; + scanner_status = normal; + get_next(); + scanner_status = save_scanner_status; + m = prim_lookup(cs_text(cur_cs)); + b = ((cur_cmd != undefined_cs_cmd) && + (m != undefined_primitive) && + (cur_cmd == get_prim_eq_type(m)) && + (cur_chr == get_prim_equiv(m))); + break; + case if_def_code: + /* + The conditional \.{\\ifdefined} tests if a control sequence is defined. + We need to reset |scanner_status|, since \.{\\outer} control sequences + are allowed, but we might be scanning a macro definition or preamble. + */ + save_scanner_status = scanner_status; + scanner_status = normal; + get_next(); + b = (cur_cmd != undefined_cs_cmd); + scanner_status = save_scanner_status; + break; + case if_cs_code: + b = test_for_cs(); + break; + case if_in_csname_code: + b = is_in_csname; + break; + case if_font_char_code: + /* + The conditional \.{\\iffontchar} tests the existence of a character in + a font. + */ + scan_font_ident(); + n = cur_val; + scan_char_num(); + b = char_exists(n, cur_val); + break; + default: + /* there are no other cases, but for -Wall: */ + b = false; } - if (is_unless) b = !b; if (int_par(tracing_commands_code) > 1) { @@ -505,14 +519,16 @@ void conditional(void) } if (b) { change_if_limit(else_code, save_cond_ptr); - return; /*wait for \.{\\else} or \.{\\fi} */ + /*wait for \.{\\else} or \.{\\fi} */ + return; } - /* Skip to \.{\\else} or \.{\\fi}, then |goto common_ending| */ /* - In a construction like `\.{\\if\\iftrue abc\\else d\\fi}', the first - \.{\\else} that we come to after learning that the \.{\\if} is false is - not the \.{\\else} we're looking for. Hence the following curious - logic is needed. + Skip to \.{\\else} or \.{\\fi}, then |goto common_ending| + + In a construction like `\.{\\if\\iftrue abc\\else d\\fi}', the first + \.{\\else} that we come to after learning that the \.{\\if} is false is + not the \.{\\else} we're looking for. Hence the following curious + logic is needed. */ while (1) { pass_text(); @@ -527,8 +543,10 @@ void conditional(void) } } COMMON_ENDING: - if (cur_chr == fi_code) + if (cur_chr == fi_code) { pop_condition_stack(); - else - if_limit = fi_code; /*wait for \.{\\fi} */ + } else { + /*wait for \.{\\fi} */ + if_limit = fi_code; + } } diff --git a/Build/source/texk/web2c/luatexdir/tex/directions.h b/Build/source/texk/web2c/luatexdir/tex/directions.h index 34a89cc29a2..e4cea9014dd 100644 --- a/Build/source/texk/web2c/luatexdir/tex/directions.h +++ b/Build/source/texk/web2c/luatexdir/tex/directions.h @@ -31,7 +31,7 @@ */ # define dir_TLT 0 /* maybe use this one as unset value */ -# define dir_TRT 1 /* or swhould we avoid that one because it's a signal too */ +# define dir_TRT 1 /* or should we avoid that one because it's a signal too */ # define dir_LTL 2 # define dir_RTT 3 @@ -56,14 +56,52 @@ extern int dir_swap; # define is_rotated(a) (a == dir_RTT) +/* + + # define textdir_parallel(a,b) ( \ + ((a == dir_TLT || a == dir_TRT) && (b == dir_TLT || b == dir_TRT)) || \ + ((a == dir_LTL || a == dir_RTT) && (b == dir_LTL || b == dir_RTT)) \ + ) + + # define pardir_parallel(a,b) ( \ + ((a == dir_TLT || a == dir_TRT) && (b == dir_TLT || b == dir_TRT)) || \ + ((a == dir_LTL || a == dir_RTT) && (b == dir_LTL || b == dir_RTT)) \ + ) + + # define pardir_eq(a,b) ( \ + ((a == dir_TLT || a == dir_TRT) && (b == dir_TLT || b == dir_TRT)) || \ + (a == dir_LTL && b == dir_LTL) || \ + (a == dir_RTT && b == dir_RTT) \ + ) + + # define textdir_eq(a,b) ( \ + (a == dir_TLT && b == dir_TLT) || \ + (a == dir_TRT && b == dir_TRT) || \ + (a == dir_LTL && (b == dir_LTL || b == dir_RTT)) || \ + (a == dir_RTT && (b == dir_LTL || b == dir_RTT)) + + # define partextdir_eq(a,b) ( \ + ((a == dir_TLT || a == dir_TRT) && (b == dir_LTL || b == dir_RTT)) || \ + (a == dir_LTL && b == dir_TLT) || \ + (a == dir_RTT && b == dir_TRT) \ + ) + +*/ + +/* # define dir_TLT_or_TRT(a) (a == dir_TLT || a == dir_TRT) */ +/* # define dir_LTL_or_RTT(a) (a == dir_LTL || a == dir_RTT) */ + +# define dir_TLT_or_TRT(a) (a < 2) +# define dir_LTL_or_RTT(a) (a > 1) + # define textdir_parallel(a,b) ( \ - ((a == dir_TLT || a == dir_TRT) && (b == dir_TLT || b == dir_TRT)) || \ - ((a == dir_LTL || a == dir_RTT) && (b == dir_LTL || b == dir_RTT)) \ + (dir_TLT_or_TRT(a) && dir_TLT_or_TRT(b)) || \ + (dir_LTL_or_RTT(a) && dir_LTL_or_RTT(b)) \ ) # define pardir_parallel(a,b) ( \ - ((a == dir_TLT || a == dir_TRT) && (b == dir_TLT || b == dir_TRT)) || \ - ((a == dir_LTL || a == dir_RTT) && (b == dir_LTL || b == dir_RTT)) \ + (dir_TLT_or_TRT(a) && dir_TLT_or_TRT(b)) || \ + (dir_LTL_or_RTT(a) && dir_LTL_or_RTT(b)) \ ) # define pardir_opposite(a,b) ( \ @@ -79,7 +117,7 @@ extern int dir_swap; # define glyphdir_opposite(a,b) 0 # define pardir_eq(a,b) ( \ - ((a == dir_TLT || a == dir_TRT) && (b == dir_TLT || b == dir_TRT)) || \ + (dir_TLT_or_TRT(a) && dir_TLT_or_TRT(b)) || \ (a == dir_LTL && b == dir_LTL) || \ (a == dir_RTT && b == dir_RTT) \ ) @@ -87,8 +125,8 @@ extern int dir_swap; # define textdir_eq(a,b) ( \ (a == dir_TLT && b == dir_TLT) || \ (a == dir_TRT && b == dir_TRT) || \ - (a == dir_LTL && (b == dir_LTL || b == dir_RTT)) || \ - (a == dir_RTT && (b == dir_LTL || b == dir_RTT) \ + (a == dir_LTL && dir_LTL_or_RTT(b)) || \ + (a == dir_RTT && dir_LTL_or_RTT(b)) \ ) # define glyphdir_eq(a,b) ( \ @@ -97,7 +135,7 @@ extern int dir_swap; ) # define partextdir_eq(a,b) ( \ - ((a == dir_TLT || a == dir_TRT)&&(b == dir_LTL || b == dir_RTT)) || \ + (dir_TLT_or_TRT(a) && dir_LTL_or_RTT(b)) || \ (a == dir_LTL && b == dir_TLT) || \ (a == dir_RTT && b == dir_TRT) \ ) @@ -106,21 +144,21 @@ extern int dir_swap; # define textdir_is_L(a) (a == dir_TLT) -# define push_dir(a,b) { \ +# define push_dir(p,a) { \ halfword dir_tmp=new_dir((a)); \ - vlink(dir_tmp)=b; \ - b=dir_tmp; \ + vlink(dir_tmp)=p; \ + p=dir_tmp; \ } -# define push_dir_node(a,b) { \ +# define push_dir_node(p,a) { \ halfword dir_tmp=copy_node((a)); \ - vlink(dir_tmp)=b; \ - b=dir_tmp; \ + vlink(dir_tmp)=p; \ + p=dir_tmp; \ } -# define pop_dir_node(b) { \ - halfword dir_tmp=b; \ - b=vlink(dir_tmp); \ +# define pop_dir_node(p) { \ + halfword dir_tmp=p; \ + p=vlink(dir_tmp); \ flush_node(dir_tmp); \ } diff --git a/Build/source/texk/web2c/luatexdir/tex/directions.w b/Build/source/texk/web2c/luatexdir/tex/directions.w index addde937df7..b010eb4a9cc 100644 --- a/Build/source/texk/web2c/luatexdir/tex/directions.w +++ b/Build/source/texk/web2c/luatexdir/tex/directions.w @@ -19,7 +19,6 @@ @ @c - #include "ptexlib.h" @ @c @@ -59,8 +58,7 @@ void scan_direction(void) @c halfword do_push_dir_node(halfword p, halfword a) { - halfword n; - n = copy_node(a); + halfword n = copy_node(a); vlink(n) = p; return n; } @@ -86,8 +84,7 @@ void initialize_directions(void) @ @c halfword new_dir(int s) { - halfword p; /* the new node */ - p = new_node(dir_node, 0); + halfword p = new_node(dir_node, 0); dir_dir(p) = s; dir_dvi_ptr(p) = -1; dir_level(p) = cur_level; @@ -150,10 +147,10 @@ scaled pack_width(int curdir, int pdir, halfword p, boolean isglyph) if (textdir_parallel(curdir, pdir) == textglyphdir_orthogonal(pdir)) { wd = glyph_width(p); if (ex_glyph(p) != 0) { - //wd = round_xn_over_d(wd, 1000 + ex_glyph(p)/1000, 1000); - wd = ext_xn_over_d(wd, 1000000+ex_glyph(p), 1000000); + /* wd = round_xn_over_d(wd, 1000 + ex_glyph(p)/1000, 1000); */ + wd = ext_xn_over_d(wd, 1000000+ex_glyph(p), 1000000); - } + } } else { wd = glyph_depth(p) + glyph_height(p); } @@ -178,22 +175,20 @@ scaled_whd pack_width_height_depth(int curdir, int pdir, halfword p, whd.ht = whd.dp = (glyph_height(p) + glyph_depth(p)) / 2; else whd.ht = whd.dp = glyph_width(p) / 2; + } else if (is_rotated(pdir)) { + if (textdir_parallel(curdir, pdir)) + whd.ht = whd.dp = (glyph_height(p) + glyph_depth(p)) / 2; + else + whd.ht = glyph_width(p); } else { - if (is_rotated(pdir)) { - if (textdir_parallel(curdir, pdir)) - whd.ht = whd.dp = (glyph_height(p) + glyph_depth(p)) / 2; - else - whd.ht = glyph_width(p); - } else { - if (glyphdir_eq(curdir, pdir)) { - whd.ht = glyph_height(p); - whd.dp = glyph_depth(p); - } else if (glyphdir_opposite(curdir, pdir)) { - whd.ht = glyph_depth(p); - whd.dp = glyph_height(p); - } else - whd.ht = glyph_width(p); - } + if (glyphdir_eq(curdir, pdir)) { + whd.ht = glyph_height(p); + whd.dp = glyph_depth(p); + } else if (glyphdir_opposite(curdir, pdir)) { + whd.ht = glyph_depth(p); + whd.dp = glyph_height(p); + } else + whd.ht = glyph_width(p); } } else { if (is_rotated(curdir)) { @@ -201,16 +196,14 @@ scaled_whd pack_width_height_depth(int curdir, int pdir, halfword p, whd.ht = whd.dp = (height(p) + depth(p)) / 2; else whd.ht = whd.dp = width(p) / 2; - } else { - if (pardir_eq(curdir, pdir)) { - whd.ht = height(p); - whd.dp = depth(p); - } else if (pardir_opposite(curdir, pdir)) { - whd.ht = depth(p); - whd.dp = height(p); - } else - whd.ht = width(p); - } + } else if (pardir_eq(curdir, pdir)) { + whd.ht = height(p); + whd.dp = depth(p); + } else if (pardir_opposite(curdir, pdir)) { + whd.ht = depth(p); + whd.dp = height(p); + } else + whd.ht = width(p); } return whd; } diff --git a/Build/source/texk/web2c/luatexdir/tex/dumpdata.w b/Build/source/texk/web2c/luatexdir/tex/dumpdata.w index 727951b9f32..ea882a74040 100644 --- a/Build/source/texk/web2c/luatexdir/tex/dumpdata.w +++ b/Build/source/texk/web2c/luatexdir/tex/dumpdata.w @@ -26,8 +26,9 @@ #define prev_depth cur_list.prev_depth_field /* 907 = sum of the values of the bytes of "don knuth" */ -/* The next FORMAT_ID will be 907+7 */ -#define FORMAT_ID (907+6) +/* The next FORMAT_ID will be 907+10 */ + +#define FORMAT_ID (907+10) #if ((FORMAT_ID>=0) && (FORMAT_ID<=256)) #error Wrong value for FORMAT_ID. #endif @@ -47,8 +48,8 @@ after the |banner| line when \TeX\ is ready to start. For \.{INITEX} this string says simply `\.{(INITEX)}'; for other versions of \TeX\ it says, for example, `\.{(preloaded format=plain 1982.11.19)}', showing the year, month, and day that the format file was created. We have |format_ident=0| -before \TeX's tables are loaded. |FORMAT_ID| is a new field of type int -suitable for the identification of a format: values between 0 and 256 +before \TeX's tables are loaded. |FORMAT_ID| is a new field of type int +suitable for the identification of a format: values between 0 and 256 (included) can not be used because in the previous format they are used for the length of the name of the engine. @c @@ -81,7 +82,7 @@ void store_fmt_file(void) succumb(); } - /* Create the |format_ident|, open the format file, and inform the user + /* Create the |format_ident|, open the format file, and inform the user that dumping has begun */ callback_id = callback_defined(pre_dump_callback); if (callback_id > 0) { @@ -121,7 +122,7 @@ void store_fmt_file(void) dump/undump macros. */ dump_int(0x57325458); /* Web2C \TeX's magic constant: "W2TX" */ - dump_int(FORMAT_ID); + dump_int(FORMAT_ID); /* Align engine to 4 bytes with one or more trailing NUL */ x = (int) strlen(engine_name); @@ -150,7 +151,7 @@ void store_fmt_file(void) /* Dump the dynamic memory */ /* By sorting the list of available spaces in the variable-size portion of |mem|, we are usually able to get by without having to dump very much - of the dynamic memory. + of the dynamic memory. We recompute |var_used| and |dyn_used|, so that \.{INITEX} dumps valid information even when it has not been gathering statistics. @@ -301,9 +302,6 @@ void store_fmt_file(void) /* Dump the hyphenation tables */ dump_language_data(); - /* Dump pdftex data */ - dump_pdftex_data(static_pdf); - /* Dump a couple more things and the closing check word */ dump_int(interaction); dump_int(format_ident); @@ -387,7 +385,7 @@ boolean load_fmt_file(const char *fmtname) format_debug("engine name size", x); if ((x < 0) || (x > 256)) goto BAD_FMT; /* corrupted format file */ - + format_engine = xmalloc((unsigned) x); undump_things(format_engine[0], x); format_engine[x - 1] = 0; /* force string termination, just in case */ @@ -510,9 +508,6 @@ boolean load_fmt_file(const char *fmtname) /* Undump the hyphenation tables */ undump_language_data(); - /* Undump pdftex data */ - undump_pdftex_data(static_pdf); - /* Undump a couple more things and the closing check word */ undump(batch_mode, error_stop_mode, interaction); if (interactionoption != unspecified_mode) diff --git a/Build/source/texk/web2c/luatexdir/tex/equivalents.h b/Build/source/texk/web2c/luatexdir/tex/equivalents.h index 8a7debe8345..9f604ab8be6 100644 --- a/Build/source/texk/web2c/luatexdir/tex/equivalents.h +++ b/Build/source/texk/web2c/luatexdir/tex/equivalents.h @@ -15,104 +15,97 @@ License for more details. You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see . */ - + with LuaTeX; if not, see . +*/ #ifndef EQUIVALENTS_H # define EQUIVALENTS_H /* -Like the preceding parameters, the following quantities can be changed -at compile time to extend or reduce \TeX's capacity. But if they are changed, -it is necessary to rerun the initialization program \.{INITEX} -@.INITEX@> -to generate new tables for the production \TeX\ program. -One can't simply make helter-skelter changes to the following constants, -since certain rather complex initialization -numbers are computed from them. They are defined here using -\.{WEB} macros, instead of being put into \PASCAL's |const| list, in order to -emphasize this distinction. + +Like the preceding parameters, the following quantities can be changed at compile +time to extend or reduce \TeX's capacity. But if they are changed, it is +necessary to rerun the initialization program \.{INITEX} @.INITEX@> to generate +new tables for the production \TeX\ program. One can't simply make helter-skelter +changes to the following constants, since certain rather complex initialization +numbers are computed from them. They are defined here using \.{WEB} macros, +instead of being put into \PASCAL's |const| list, in order to emphasize this +distinction. + */ -# define font_base 0 /* smallest internal font number; must not be less than |min_quarterword| */ -# define biggest_reg 65535 /* the largest allowed register number; must be |< max_quarterword| */ -# define number_regs 65536 /* |biggest_reg+1| */ -# define number_attrs 65536 /* total numbeer of attributes */ -# define biggest_char 1114111 /* the largest allowed character number; must be |< max_halfword| */ -# define too_big_char 1114112 /* |biggest_char+1| */ -# define special_char 1114113 /* |biggest_char+2| */ -# define number_chars 1114112 /* |biggest_char+1| */ +# define font_base 0 /* smallest internal font number; must not be less than |min_quarterword| */ +# define biggest_reg 65535 /* the largest allowed register number; must be |< max_quarterword| */ +# define number_regs 65536 /* |biggest_reg+1| */ +# define number_attrs 65536 /* total numbeer of attributes */ +# define biggest_char 1114111 /* the largest allowed character number; must be |< max_halfword| */ +# define too_big_char 1114112 /* |biggest_char+1| */ +# define special_char 1114113 /* |biggest_char+2| */ +# define number_chars 1114112 /* |biggest_char+1| */ # define number_fonts (5535-font_base+1) -# define biggest_lang 32767 -# define too_big_lang 32768 -# define text_size 0 /* size code for the largest size in a family */ -# define script_size 1 /* size code for the medium size in a family */ -# define script_script_size 2 /* size code for the smallest size in a family */ +# define biggest_lang 32767 +# define too_big_lang 32768 +# define text_size 0 /* size code for the largest size in a family */ +# define script_size 1 /* size code for the medium size in a family */ +# define script_script_size 2 /* size code for the smallest size in a family */ /* + Each entry in |eqtb| is a |memory_word|. Most of these words are of type |two_halves|, and subdivided into three fields: -\yskip\hangg 1) The |eq_level| (a quarterword) is the level of grouping at -which this equivalent was defined. If the level is |level_zero|, the -equivalent has never been defined; |level_one| refers to the outer level -(outside of all groups), and this level is also used for global -definitions that never go away. Higher levels are for equivalents that -will disappear at the end of their group. @^global definitions@> - -\yskip\hangg 2) The |eq_type| (another quarterword) specifies what kind of -entry this is. There are many types, since each \TeX\ primitive like -\.{\\hbox}, \.{\\def}, etc., has its own special code. The list of -command codes above includes all possible settings of the |eq_type| field. - -\yskip\hangg 3) The |equiv| (a halfword) is the current equivalent value. -This may be a font number, a pointer into |mem|, or a variety of other -things. -*/ +\yskip\hangg 1) The |eq_level| (a quarterword) is the level of grouping at which +this equivalent was defined. If the level is |level_zero|, the equivalent has +never been defined; |level_one| refers to the outer level (outside of all +groups), and this level is also used for global definitions that never go away. +Higher levels are for equivalents that will disappear at the end of their group. +@^global definitions@> + +\yskip\hangg 2) The |eq_type| (another quarterword) specifies what kind of entry +this is. There are many types, since each \TeX\ primitive like \.{\\hbox}, +\.{\\def}, etc., has its own special code. The list of command codes above +includes all possible settings of the |eq_type| field. + +\yskip\hangg 3) The |equiv| (a halfword) is the current equivalent value. This +may be a font number, a pointer into |mem|, or a variety of other things. + +Many locations in |eqtb| have symbolic names. The purpose of the next paragraphs +is to define these names, and to set up the initial values of the equivalents. + +In the first region we have a single entry for the `null csname' of length zero. +In luatex, the active characters and and single-letter control sequence names are +part of the next region. + +Then comes region~2, which corresponds to the hash table that we will define +later. The maximum address in this region is used for a dummy control sequence +that is perpetually undefined. There also are several locations for control +sequences that are perpetually defined (since they are used in error recovery). + +@ Region 3 of |eqtb| contains the |number_regs| \.{\\skip} registers, as well as +the glue parameters defined here. It is important that the ``muskip'' parameters +have larger numbers than the others. + +@ Region 4 of |eqtb| contains the local quantities defined here. The bulk of this +region is taken up by five tables that are indexed by eight-bit characters; these +tables are important to both the syntactic and semantic portions of \TeX. There +are also a bunch of special things like font and token parameters, as well as the +tables of \.{\\toks} and \.{\\box} registers. + +@ Region 5 of |eqtb| contains the integer parameters and registers defined here, +as well as the |del_code| table. The latter table differs from the +|cat_code..math_code| tables that precede it, since delimiter codes are fullword +integers while the other kinds of codes occupy at most a halfword. This is what +makes region~5 different from region~4. We will store the |eq_level| information +in an auxiliary array of quarterwords that will be defined later. + +@ The integer parameters should really be initialized by a macro package; the +following initialization does the minimum to keep \TeX\ from complete failure. -/* -Many locations in |eqtb| have symbolic names. The purpose of the next -paragraphs is to define these names, and to set up the initial values of the -equivalents. - -In the first region we have a single entry for the `null csname' of -length zero. In luatex, the active characters and and single-letter -control sequence names are part of the next region. - -Then comes region~2, which corresponds to the hash table that we will -define later. The maximum address in this region is used for a dummy -control sequence that is perpetually undefined. There also are several -locations for control sequences that are perpetually defined -(since they are used in error recovery). -*/ - -/* -@ Region 3 of |eqtb| contains the |number_regs| \.{\\skip} registers, as well as the -glue parameters defined here. It is important that the ``muskip'' -parameters have larger numbers than the others. - -@ Region 4 of |eqtb| contains the local quantities defined here. The -bulk of this region is taken up by five tables that are indexed by eight-bit -characters; these tables are important to both the syntactic and semantic -portions of \TeX. There are also a bunch of special things like font and -token parameters, as well as the tables of \.{\\toks} and \.{\\box} -registers. - -@ Region 5 of |eqtb| contains the integer parameters and registers defined -here, as well as the |del_code| table. The latter table differs from the -|cat_code..math_code| tables that precede it, since delimiter codes are -fullword integers while the other kinds of codes occupy at most a -halfword. This is what makes region~5 different from region~4. We will -store the |eq_level| information in an auxiliary array of quarterwords -that will be defined later. - -@ The integer parameters should really be initialized by a macro package; -the following initialization does the minimum to keep \TeX\ from -complete failure. @^null delimiter@> -@ The final region of |eqtb| contains the dimension parameters defined -here, and the |number_regs| \.{\\dimen} registers. +@ The final region of |eqtb| contains the dimension parameters defined here, and +the |number_regs| \.{\\dimen} registers. + */ # define null_cs 1 /* equivalent of \.{\\csname\\endcsname} */ @@ -258,45 +251,46 @@ here, and the |number_regs| \.{\\dimen} registers. # define luastartup_id_code 60 # define disable_lig_code 61 # define disable_kern_code 62 -# define cat_code_table_code 63 -# define output_box_code 64 -# define cur_lang_code 65 /* current language id */ -# define ex_hyphen_char_code 66 -# define hyphenation_min_code 67 /* minimum word length */ -# define adjust_spacing_code 68 /* level of spacing adjusting */ -# define protrude_chars_code 69 /* protrude chars at left/right edge of paragraphs */ -# define output_mode_code 70 /* switch on PDF output if positive */ -# define draft_mode_code 71 -# define tracing_fonts_code 72 -# define tracing_assigns_code 73 /* show assignments */ -# define tracing_groups_code 74 /* show save/restore groups */ -# define tracing_ifs_code 75 /* show conditionals */ -# define tracing_scan_tokens_code 76 /* show pseudo file open and close */ -# define tracing_nesting_code 77 /* show incomplete groups and ifs within files */ -# define pre_display_direction_code 78 /* text direction preceding a display */ -# define last_line_fit_code 79 /* adjustment for last line of paragraph */ -# define saving_vdiscards_code 80 /* save items discarded from vlists */ -# define saving_hyph_codes_code 81 /* save hyphenation codes for languages */ -# define suppress_fontnotfound_error_code 82 /* suppress errors for missing fonts */ -# define suppress_long_error_code 83 /* suppress errors for missing fonts */ -# define suppress_ifcsname_error_code 84 /* suppress errors for failed \.{\\ifcsname} */ -# define suppress_outer_error_code 85 /* suppress errors for \.{\\outer} */ -# define suppress_mathpar_error_code 86 /* suppress errors for \.{\\par}} in math */ -# define math_eqno_gap_step_code 87 /* factor/1000 used for distance between eq and eqno */ -# define math_display_skip_mode_code 88 -# define math_scripts_mode_code 89 -# define synctex_code 90 /* is synctex file generation enabled ? */ - -# define math_no_italic_compensation_code 91 /* just for tracing, can change */ -# define math_no_char_italic_code 92 /* just for tracing, can change */ -# define math_use_old_fraction_scaling_code 93 /* just for tracing, can change */ -# define math_old_code 94 /* this one is stable */ -# define math_option_code 95 - -# define backend_int_base (int_base+96) -# define backend_int_last (int_base+115) - -# define tex_int_pars (116) /* total number of integer parameters */ +# define disable_space_code 63 +# define cat_code_table_code 64 +# define output_box_code 65 +# define cur_lang_code 66 /* current language id */ +# define ex_hyphen_char_code 67 +# define hyphenation_min_code 68 /* minimum word length */ +# define adjust_spacing_code 69 /* level of spacing adjusting */ +# define protrude_chars_code 70 /* protrude chars at left/right edge of paragraphs */ +# define output_mode_code 71 /* switch on PDF output if positive */ +# define draft_mode_code 72 +# define tracing_fonts_code 73 +# define tracing_assigns_code 74 /* show assignments */ +# define tracing_groups_code 75 /* show save/restore groups */ +# define tracing_ifs_code 76 /* show conditionals */ +# define tracing_scan_tokens_code 77 /* show pseudo file open and close */ +# define tracing_nesting_code 78 /* show incomplete groups and ifs within files */ +# define pre_display_direction_code 79 /* text direction preceding a display */ +# define last_line_fit_code 80 /* adjustment for last line of paragraph */ +# define saving_vdiscards_code 81 /* save items discarded from vlists */ +# define saving_hyph_codes_code 82 /* save hyphenation codes for languages */ +# define suppress_fontnotfound_error_code 83 /* suppress errors for missing fonts */ +# define suppress_long_error_code 84 /* suppress errors for missing fonts */ +# define suppress_ifcsname_error_code 85 /* suppress errors for failed \.{\\ifcsname} */ +# define suppress_outer_error_code 86 /* suppress errors for \.{\\outer} */ +# define suppress_mathpar_error_code 87 /* suppress errors for \.{\\par}} in math */ +# define math_eqno_gap_step_code 88 /* factor/1000 used for distance between eq and eqno */ +# define math_display_skip_mode_code 89 +# define math_scripts_mode_code 90 +# define synctex_code 91 /* is synctex file generation enabled ? */ + +# define math_no_italic_compensation_code 92 /* just for tracing, can change */ +# define math_no_char_italic_code 93 /* just for tracing, can change */ +# define math_use_old_fraction_scaling_code 94 /* just for tracing, can change */ +# define math_old_code 95 /* this one is stable */ +# define math_option_code 96 + +# define backend_int_base (int_base+97) +# define backend_int_last (int_base+116) + +# define tex_int_pars (117) /* total number of integer parameters */ # define page_direction_code (tex_int_pars) # define body_direction_code (tex_int_pars+1) @@ -339,7 +333,7 @@ here, and the |number_regs| \.{\\dimen} registers. # define page_bottom_offset_code 24 # define px_dimen_code 25 # define page_width_code 26 /* page width of the output */ -# define page_height_code 27 /* page height of the output */ /* total number of dimension parameters */ +# define page_height_code 27 /* page height of the output */ # define backend_dimen_base (dimen_base+28) # define backend_dimen_last (dimen_base+37) @@ -387,8 +381,10 @@ extern int cur_boundary; /* where # define save_word(A) save_stack[(A)].word_ /* |eqtb| entry */ /* -We use the notation |saved(k)| to stand for an item that -appears in location |save_ptr+k| of the save stack. + +We use the notation |saved(k)| to stand for an item that appears in location +|save_ptr+k| of the save stack. + */ # define saved_type(A) save_stack[save_ptr+(A)].type_ @@ -418,58 +414,59 @@ appears in location |save_ptr+k| of the save stack. # define saved_boxspec 14 # define saved_boxdir 15 # define saved_boxattr 16 -# define saved_eqtb 17 +# define saved_boxpack 18 +# define saved_eqtb 19 extern void print_save_stack(void); -# define assign_trace(A,B) if (int_par(tracing_assigns_code)>0) restore_trace((A),(B)) - # define int_par(A) eqtb[int_base+(A)].cint # define dimen_par(A) eqtb[dimen_base+(A)].cint # define loc_par(A) equiv(local_base+(A)) # define glue_par(A) equiv(glue_base+(A)) -extern int mag_set; /* if nonzero, this magnification should be used henceforth */ +/* if nonzero, this magnification should be used henceforth */ + +extern int mag_set; extern void prepare_mag(void); /* -@ Here are the group codes that are used to discriminate between different -kinds of groups. They allow \TeX\ to decide what special actions, if any, -should be performed when a group ends. -\def\grp{\.{\char'173...\char'175}} -Some groups are not supposed to be ended by right braces. For example, -the `\.\$' that begins a math formula causes a |math_shift_group| to -be started, and this should be terminated by a matching `\.\$'. Similarly, -a group that starts with \.{\\left} should end with \.{\\right}, and -one that starts with \.{\\begingroup} should end with \.{\\endgroup}. +@ Here are the group codes that are used to discriminate between different kinds +of groups. They allow \TeX\ to decide what special actions, if any, should be +performed when a group ends. \def\grp{\.{\char'173...\char'175}} + +Some groups are not supposed to be ended by right braces. For example, the `\.\$' +that begins a math formula causes a |math_shift_group| to be started, and this +should be terminated by a matching `\.\$'. Similarly, a group that starts with +\.{\\left} should end with \.{\\right}, and one that starts with \.{\\begingroup} +should end with \.{\\endgroup}. */ typedef enum { - bottom_level = 0, /* group code for the outside world */ - simple_group, /* group code for local structure only */ - hbox_group, /* code for `\.{\\hbox}\grp' */ - adjusted_hbox_group, /* code for `\.{\\hbox}\grp' in vertical mode */ - vbox_group, /* code for `\.{\\vbox}\grp' */ - vtop_group, /* code for `\.{\\vtop}\grp' */ - align_group, /* code for `\.{\\halign}\grp', `\.{\\valign}\grp' */ - no_align_group, /* code for `\.{\\noalign}\grp' */ - output_group, /* code for output routine */ - math_group, /* code for, e.g., `\.{\char'136}\grp' */ - disc_group, /* code for `\.{\\discretionary}\grp\grp\grp' */ - insert_group, /* code for `\.{\\insert}\grp', `\.{\\vadjust}\grp' */ - vcenter_group, /* code for `\.{\\vcenter}\grp' */ - math_choice_group, /* code for `\.{\\mathchoice}\grp\grp\grp\grp' */ - semi_simple_group, /* code for `\.{\\begingroup...\\endgroup}' */ - math_shift_group, /* code for `\.{\$...\$}' */ - math_left_group, /* code for `\.{\\left...\\right}' */ - local_box_group, /* code for `\.{\\localleftbox...\\localrightbox}' */ - split_off_group, /* box code for the top part of a \.{\\vsplit} */ - split_keep_group, /* box code for the bottom part of a \.{\\vsplit} */ - preamble_group, /* box code for the preamble processing in an alignment */ - align_set_group, /* box code for the final item pass in an alignment */ - fin_row_group /* box code for a provisory line in an alignment */ + bottom_level = 0, /* group code for the outside world */ + simple_group, /* group code for local structure only */ + hbox_group, /* code for `\.{\\hbox}\grp' */ + adjusted_hbox_group, /* code for `\.{\\hbox}\grp' in vertical mode */ + vbox_group, /* code for `\.{\\vbox}\grp' */ + vtop_group, /* code for `\.{\\vtop}\grp' */ + align_group, /* code for `\.{\\halign}\grp', `\.{\\valign}\grp' */ + no_align_group, /* code for `\.{\\noalign}\grp' */ + output_group, /* code for output routine */ + math_group, /* code for, e.g., `\.{\char'136}\grp' */ + disc_group, /* code for `\.{\\discretionary}\grp\grp\grp' */ + insert_group, /* code for `\.{\\insert}\grp', `\.{\\vadjust}\grp' */ + vcenter_group, /* code for `\.{\\vcenter}\grp' */ + math_choice_group, /* code for `\.{\\mathchoice}\grp\grp\grp\grp' */ + semi_simple_group, /* code for `\.{\\begingroup...\\endgroup}' */ + math_shift_group, /* code for `\.{\$...\$}' */ + math_left_group, /* code for `\.{\\left...\\right}' */ + local_box_group, /* code for `\.{\\localleftbox...\\localrightbox}' */ + split_off_group, /* box code for the top part of a \.{\\vsplit} */ + split_keep_group, /* box code for the bottom part of a \.{\\vsplit} */ + preamble_group, /* box code for the preamble processing in an alignment */ + align_set_group, /* box code for the final item pass in an alignment */ + fin_row_group /* box code for a provisory line in an alignment */ } tex_group_codes; # define max_group_code local_box_group /* which is wrong, but is what the web says */ @@ -490,7 +487,6 @@ extern void geq_define(halfword p, quarterword t, halfword e); /* global |eq_de extern void geq_word_define(halfword p, int w); /* global |eq_word_define| */ extern void save_for_after(halfword t); extern void unsave(void); /* pops the top level off the save stack */ -extern void restore_trace(halfword p, const char *s); /* |eqtb[p]| has just been restored or retained */ extern void show_save_groups(void); # define level_zero 0 /* level for undefined quantities */ @@ -498,10 +494,20 @@ extern void show_save_groups(void); extern void show_eqtb(halfword n); +/* \csname \ifcsname */ + +extern halfword last_cs_name; + /* more will move here */ #define space_skip glue_par(space_skip_code) #define xspace_skip glue_par(xspace_skip_code) #define math_skip glue_par(math_skip_code) +#define body_direction int_par(body_direction_code) +#define page_direction int_par(page_direction_code) +#define par_direction int_par(par_direction_code) +#define text_direction int_par(text_direction_code) +#define math_direction int_par(math_direction_code) + #endif diff --git a/Build/source/texk/web2c/luatexdir/tex/equivalents.w b/Build/source/texk/web2c/luatexdir/tex/equivalents.w index 5fe8b4ec500..d88b7322a76 100644 --- a/Build/source/texk/web2c/luatexdir/tex/equivalents.w +++ b/Build/source/texk/web2c/luatexdir/tex/equivalents.w @@ -19,9 +19,23 @@ @ @c - #include "ptexlib.h" +halfword last_cs_name = null_cs; + +/* |eqtb[p]| has just been restored or retained */ + +static void diagnostic_trace(halfword p, const char *s) +{ + begin_diagnostic(); + print_char('{'); + tprint(s); + print_char(' '); + show_eqtb(p); + print_char('}'); + end_diagnostic(false); +} + @ @c #define par_shape_ptr equiv(par_shape_loc) @@ -85,7 +99,6 @@ void initialize_equivalents(void) xeq_level[k] = level_one; } - @ The nested structure provided by `$\.{\char'173}\ldots\.{\char'175}$' groups in \TeX\ means that |eqtb| entries valid in outer groups should be saved and restored later if they are overridden inside the braces. When a new |eqtb| @@ -105,9 +118,9 @@ interpreted in one of four ways: |save_value(p)| is a location in |eqtb| whose current value should be destroyed at the end of the current group and replaced by |save_word(p-1)| (|save_type(p-1)==saved_eqtb|). -Furthermore if |save_value(p)>=int_base|, then |save_level(p)| should +Furthermore if |save_value(p)>=int_base|, then |save_level(p)| should replace the corresponding entry in |xeq_level| (if |save_value(p)max_save_stack) { \ - max_save_stack=save_ptr; \ - if (max_save_stack>save_size-8) \ - overflow("save size",(unsigned)save_size); \ - } \ - } while (0) - +#define check_full_save_stack() do { \ + if (save_ptr>max_save_stack) { \ + max_save_stack=save_ptr; \ + if (max_save_stack>save_size-8) \ + overflow("save size",(unsigned)save_size); \ + } \ +} while (0) @ Procedure |new_save_level| is called when a group begins. The argument is a group identification code like `|hbox_group|'. After @@ -193,7 +204,7 @@ called. @c void new_save_level(group_code c) -{ /* begin a new level of grouping */ +{ /* begin a new level of grouping */ check_full_save_stack(); set_saved_record(0, saved_line, 0, line); incr(save_ptr); @@ -216,27 +227,26 @@ static const char *save_stack_type(int v) { const char *s = ""; switch (save_type(v)) { -/* *INDENT-OFF* */ - case restore_old_value: s = "restore_old_value"; break; - case restore_zero: s = "restore_zero"; break; - case insert_token: s = "insert_token"; break; - case level_boundary: s = "level_boundary"; break; - case saved_line: s = "saved_line"; break; - case saved_adjust: s = "saved_adjust"; break; - case saved_insert: s = "saved_insert"; break; - case saved_disc: s = "saved_disc"; break; - case saved_boxtype: s = "saved_boxtype"; break; - case saved_textdir: s = "saved_textdir"; break; - case saved_eqno: s = "saved_eqno"; break; - case saved_choices: s = "saved_choices"; break; - case saved_math: s = "saved_math"; break; - case saved_boxcontext: s = "saved_boxcontext"; break; - case saved_boxspec: s = "saved_boxspec"; break; - case saved_boxdir: s = "saved_boxdir"; break; - case saved_boxattr: s = "saved_boxattr"; break; - case saved_eqtb: s = "saved_eqtb"; break; - default: break; -/* *INDENT-ON* */ + case restore_old_value: s = "restore_old_value"; break; + case restore_zero: s = "restore_zero"; break; + case insert_token: s = "insert_token"; break; + case level_boundary: s = "level_boundary"; break; + case saved_line: s = "saved_line"; break; + case saved_adjust: s = "saved_adjust"; break; + case saved_insert: s = "saved_insert"; break; + case saved_disc: s = "saved_disc"; break; + case saved_boxtype: s = "saved_boxtype"; break; + case saved_textdir: s = "saved_textdir"; break; + case saved_eqno: s = "saved_eqno"; break; + case saved_choices: s = "saved_choices"; break; + case saved_math: s = "saved_math"; break; + case saved_boxcontext: s = "saved_boxcontext"; break; + case saved_boxspec: s = "saved_boxspec"; break; + case saved_boxdir: s = "saved_boxdir"; break; + case saved_boxattr: s = "saved_boxattr"; break; + case saved_boxpack: s = "saved_boxpack"; break; + case saved_eqtb: s = "saved_eqtb"; break; + default: break; } return s; } @@ -258,106 +268,105 @@ void print_save_stack(void) tprint("]: "); tprint(save_stack_type(i)); switch (save_type(i)) { - case restore_old_value: - tprint(", "); - show_eqtb_meaning(save_value(i)); - tprint("="); - if (save_value(i) >= int_base) { - print_int(save_word(i - 1).cint); - } else { - print_int(eq_type_field(save_word(i - 1))); - print_char(','); /* |print_int(eq_level_field(save_word(i-1)));| */ - print_int(equiv_field(save_word(i - 1))); - } - i--; - break; - case restore_zero: - tprint(", "); - show_eqtb_meaning(save_value(i)); - break; - case insert_token: - tprint(", "); - { - halfword p = get_avail(); - set_token_info(p, save_value(i)); - show_token_list(p, null, 1); - free_avail(p); - } - break; - case level_boundary: - tprint(", old group="); - print_int(save_level(i)); - tprint(", boundary = "); - print_int(save_value(i)); - tprint(", line = "); - print_int(save_value(i - 1)); - i--; - break; - case saved_adjust: - tprint(", "); - print_int(save_level(i)); /* vadjust vs vadjust pre */ - break; - case saved_insert: - tprint(", "); - print_int(save_value(i)); /* insert number */ - break; - case saved_boxtype: /* \.{\\localleftbox} vs \.{\\localrightbox} */ - tprint(", "); - print_int(save_value(i)); - break; - case saved_eqno: /* \.{\\eqno} vs \.{\\leqno} */ - tprint(", "); - print_int(save_value(i)); - break; - case saved_disc: - case saved_choices: - tprint(", "); - print_int(save_value(i)); - break; - case saved_math: - tprint(", listptr="); - print_int(save_value(i)); - break; - case saved_boxcontext: - tprint(", "); - print_int(save_value(i)); - break; - case saved_boxspec: - tprint(", spec="); - print_int(save_level(i)); - tprint(", dimen="); - print_int(save_value(i)); - break; - case saved_textdir: - case saved_boxdir: - tprint(", "); - print_dir(dir_dir(save_value(i))); - break; - case saved_boxattr: - tprint(", "); - print_int(save_value(i)); - break; - case saved_line: - case saved_eqtb: - break; - default: - break; + case restore_old_value: + tprint(", "); + show_eqtb_meaning(save_value(i)); + tprint("="); + if (save_value(i) >= int_base) { + print_int(save_word(i - 1).cint); + } else { + print_int(eq_type_field(save_word(i - 1))); + print_char(','); /* |print_int(eq_level_field(save_word(i-1)));| */ + print_int(equiv_field(save_word(i - 1))); + } + i--; + break; + case restore_zero: + tprint(", "); + show_eqtb_meaning(save_value(i)); + break; + case insert_token: + tprint(", "); + { + halfword p = get_avail(); + set_token_info(p, save_value(i)); + show_token_list(p, null, 1); + free_avail(p); + } + break; + case level_boundary: + tprint(", old group="); + print_int(save_level(i)); + tprint(", boundary = "); + print_int(save_value(i)); + tprint(", line = "); + print_int(save_value(i - 1)); + i--; + break; + case saved_adjust: + tprint(", "); + print_int(save_level(i)); /* vadjust vs vadjust pre */ + break; + case saved_insert: + tprint(", "); + print_int(save_value(i)); /* insert number */ + break; + case saved_boxtype: /* \.{\\localleftbox} vs \.{\\localrightbox} */ + tprint(", "); + print_int(save_value(i)); + break; + case saved_eqno: /* \.{\\eqno} vs \.{\\leqno} */ + tprint(", "); + print_int(save_value(i)); + break; + case saved_disc: + case saved_choices: + tprint(", "); + print_int(save_value(i)); + break; + case saved_math: + tprint(", listptr="); + print_int(save_value(i)); + break; + case saved_boxcontext: + tprint(", "); + print_int(save_value(i)); + break; + case saved_boxspec: + tprint(", spec="); + print_int(save_level(i)); + tprint(", dimen="); + print_int(save_value(i)); + break; + case saved_textdir: + case saved_boxdir: + tprint(", "); + print_dir(dir_dir(save_value(i))); + break; + case saved_boxattr: + case saved_boxpack: + tprint(", "); + print_int(save_value(i)); + break; + case saved_line: + case saved_eqtb: + break; + default: + break; } print_ln(); } end_diagnostic(true); } - @ The \.{\\showgroups} command displays all currently active grouping levels. - @ The modifications of \TeX\ required for the display produced by the |show_save_groups| procedure were first discussed by Donald~E. Knuth in {\sl TUGboat\/} {\bf 11}, 165--170 and 499--511, 1990. @^Knuth, Donald Ervin@> - + In order to understand a group type we also have to know its mode. Since unrestricted horizontal modes are not associated with grouping, they are skipped when traversing the semantic nest. @@ -365,26 +374,17 @@ void print_save_stack(void) @c void show_save_groups(void) { - int p; /* index into |nest| */ + int p = nest_ptr; /* index into |nest| */ int m; /* mode */ - save_pointer v; /* saved value of |save_ptr| */ - quarterword l; /* saved value of |cur_level| */ - group_code c; /* saved value of |cur_group| */ - int a; /* to keep track of alignments */ + save_pointer v = save_ptr; /* saved value of |save_ptr| */ + quarterword l = cur_level; /* saved value of |cur_level| */ + group_code c = cur_group; /* saved value of |cur_group| */ + int a = 1; /* to keep track of alignments */ int i; quarterword j; - const char *s; -#ifdef DEBUG - print_save_stack(); -#endif - p = nest_ptr; - v = save_ptr; - l = cur_level; - c = cur_group; + const char *s = NULL; save_ptr = cur_boundary; decr(cur_level); - a = 1; - s = NULL; tprint_nl(""); print_ln(); while (1) { @@ -401,106 +401,106 @@ void show_save_groups(void) } while (m == hmode); tprint(" ("); switch (cur_group) { - case simple_group: - incr(p); - goto FOUND2; - break; - case hbox_group: - case adjusted_hbox_group: - s = "hbox"; - break; - case vbox_group: - s = "vbox"; - break; - case vtop_group: - s = "vtop"; - break; - case align_group: - if (a == 0) { - if (m == -vmode) - s = "halign"; - else - s = "valign"; - a = 1; + case simple_group: + incr(p); + goto FOUND2; + break; + case hbox_group: + case adjusted_hbox_group: + s = "hbox"; + break; + case vbox_group: + s = "vbox"; + break; + case vtop_group: + s = "vtop"; + break; + case align_group: + if (a == 0) { + if (m == -vmode) + s = "halign"; + else + s = "valign"; + a = 1; + goto FOUND1; + } else { + if (a == 1) + tprint("align entry"); + else + tprint_esc("cr"); + if (p >= a) + p = p - a; + a = 0; + goto FOUND; + } + break; + case no_align_group: + incr(p); + a = -1; + tprint_esc("noalign"); + goto FOUND2; + break; + case output_group: + tprint_esc("output"); + goto FOUND; + break; + case math_group: + goto FOUND2; + break; + case disc_group: + tprint_esc("discretionary"); + for (i = 1; i < 3; i++) + if (i <= saved_value(-2)) + tprint("{}"); + goto FOUND2; + break; + case math_choice_group: + tprint_esc("mathchoice"); + for (i = 1; i < 4; i++) + if (i <= saved_value(-3)) /* different offset because |-2==saved_textdir| */ + tprint("{}"); + goto FOUND2; + break; + case insert_group: + if (saved_type(-1) == saved_adjust) { + tprint_esc("vadjust"); + if (saved_level(-1) != 0) + tprint(" pre"); + } else { + tprint_esc("insert"); + print_int(saved_value(-1)); + } + goto FOUND2; + break; + case vcenter_group: + s = "vcenter"; goto FOUND1; - } else { - if (a == 1) - tprint("align entry"); - else - tprint_esc("cr"); - if (p >= a) - p = p - a; - a = 0; + break; + case semi_simple_group: + incr(p); + tprint_esc("begingroup"); goto FOUND; - } - break; - case no_align_group: - incr(p); - a = -1; - tprint_esc("noalign"); - goto FOUND2; - break; - case output_group: - tprint_esc("output"); - goto FOUND; - break; - case math_group: - goto FOUND2; - break; - case disc_group: - tprint_esc("discretionary"); - for (i = 1; i < 3; i++) - if (i <= saved_value(-2)) - tprint("{}"); - goto FOUND2; - break; - case math_choice_group: - tprint_esc("mathchoice"); - for (i = 1; i < 4; i++) - if (i <= saved_value(-3)) /* different offset because |-2==saved_textdir| */ - tprint("{}"); - goto FOUND2; - break; - case insert_group: - if (saved_type(-1) == saved_adjust) { - tprint_esc("vadjust"); - if (saved_level(-1) != 0) - tprint(" pre"); - } else { - tprint_esc("insert"); - print_int(saved_value(-1)); - } - goto FOUND2; - break; - case vcenter_group: - s = "vcenter"; - goto FOUND1; - break; - case semi_simple_group: - incr(p); - tprint_esc("begingroup"); - goto FOUND; - break; - case math_shift_group: - if (m == mmode) { + break; + case math_shift_group: + if (m == mmode) { + print_char('$'); + } else if (nest[p].mode_field == mmode) { + print_cmd_chr(eq_no_cmd, saved_value(-2)); + goto FOUND; + } print_char('$'); - } else if (nest[p].mode_field == mmode) { - print_cmd_chr(eq_no_cmd, saved_value(-2)); goto FOUND; - } - print_char('$'); - goto FOUND; - break; - case math_left_group: - if (subtype(nest[p + 1].eTeX_aux_field) == left_noad_side) - tprint_esc("left"); - else - tprint_esc("middle"); - goto FOUND; - break; - default: - confusion("showgroups"); - break; + break; + case math_left_group: + if (subtype(nest[p + 1].eTeX_aux_field) == left_noad_side) + tprint_esc("left"); + else + tprint_esc("middle"); + goto FOUND; + break; + default: + confusion("showgroups"); + break; } /* Show the box context */ i = saved_value(-5); @@ -560,8 +560,6 @@ void show_save_groups(void) cur_group = c; } - - @ Just before an entry of |eqtb| is changed, the following procedure should be called to update the other data structures properly. It is important to keep in mind that reference counts in |mem| include references from @@ -573,29 +571,28 @@ void eq_destroy(memory_word w) { /* gets ready to forget |w| */ halfword q; /* |equiv| field of |w| */ switch (eq_type_field(w)) { - case call_cmd: - case long_call_cmd: - case outer_call_cmd: - case long_outer_call_cmd: - delete_token_ref(equiv_field(w)); - break; - case glue_ref_cmd: - delete_glue_ref(equiv_field(w)); - break; - case shape_ref_cmd: - q = equiv_field(w); /* we need to free a \.{\\parshape} block */ - if (q != null) - flush_node(q); - break; /* such a block is |2n+1| words long, where |n=vinfo(q)| */ - case box_ref_cmd: - flush_node_list(equiv_field(w)); - break; - default: - break; + case call_cmd: + case long_call_cmd: + case outer_call_cmd: + case long_outer_call_cmd: + delete_token_ref(equiv_field(w)); + break; + case glue_ref_cmd: + delete_glue_ref(equiv_field(w)); + break; + case shape_ref_cmd: + q = equiv_field(w); /* we need to free a \.{\\parshape} block */ + if (q != null) + flush_node(q); + break; /* such a block is |2n+1| words long, where |n=vinfo(q)| */ + case box_ref_cmd: + flush_node_list(equiv_field(w)); + break; + default: + break; } } - @ To save a value of |eqtb[p]| that was established at level |l|, we can use the following subroutine. @@ -616,7 +613,6 @@ void eq_save(halfword p, quarterword l) incr(save_ptr); } - @ The procedure |eq_define| defines an |eqtb| entry having specified |eq_type| and |equiv| fields, and saves the former value if appropriate. This procedure is used only for entries in the first four regions of |eqtb|, @@ -625,15 +621,19 @@ After calling this routine, it is safe to put four more entries on |save_stack|, provided that there was room for four more entries before the call, since |eq_save| makes the necessary test. +@ new data for |eqtb| @c void eq_define(halfword p, quarterword t, halfword e) -{ /* new data for |eqtb| */ +{ + boolean trace = int_par(tracing_assigns_code) > 0; if ((eq_type(p) == t) && (equiv(p) == e)) { - assign_trace(p, "reassigning"); + if (trace) + diagnostic_trace(p, "reassigning"); eq_destroy(eqtb[p]); return; } - assign_trace(p, "changing"); + if (trace) + diagnostic_trace(p, "changing"); if (eq_level(p) == cur_level) eq_destroy(eqtb[p]); else if (cur_level > level_one) @@ -641,10 +641,10 @@ void eq_define(halfword p, quarterword t, halfword e) set_eq_level(p, cur_level); set_eq_type(p, t); set_equiv(p, e); - assign_trace(p, "into"); + if (trace) + diagnostic_trace(p, "into"); } - @ The counterpart of |eq_define| for the remaining (fullword) positions in |eqtb| is called |eq_word_define|. Since |xeq_level[p]>=level_one| for all |p|, a `|restore_zero|' will never be used in this case. @@ -652,17 +652,21 @@ void eq_define(halfword p, quarterword t, halfword e) @c void eq_word_define(halfword p, int w) { + boolean trace = int_par(tracing_assigns_code) > 0; if (eqtb[p].cint == w) { - assign_trace(p, "reassigning"); + if (trace) + diagnostic_trace(p, "reassigning"); return; } - assign_trace(p, "changing"); + if (trace) + diagnostic_trace(p, "changing"); if (xeq_level[p] != cur_level) { eq_save(p, xeq_level[p]); xeq_level[p] = cur_level; } eqtb[p].cint = w; - assign_trace(p, "into"); + if (trace) + diagnostic_trace(p, "into"); } @@ -674,24 +678,29 @@ to save old values, and the new value is associated with |level_one|. @c void geq_define(halfword p, quarterword t, halfword e) { /* global |eq_define| */ - assign_trace(p, "globally changing"); + boolean trace = int_par(tracing_assigns_code) > 0; + if (trace) + diagnostic_trace(p, "globally changing"); eq_destroy(eqtb[p]); set_eq_level(p, level_one); set_eq_type(p, t); set_equiv(p, e); - assign_trace(p, "into"); + if (trace) + diagnostic_trace(p, "into"); } void geq_word_define(halfword p, int w) { /* global |eq_word_define| */ - assign_trace(p, "globally changing"); + boolean trace = int_par(tracing_assigns_code) > 0; + if (trace) + diagnostic_trace(p, "globally changing"); eqtb[p].cint = w; xeq_level[p] = level_one; - assign_trace(p, "into"); + if (trace) + diagnostic_trace(p, "into"); } - -@ Subroutine |save_for_after| puts a token on the stack for save-keeping. +@ Subroutine |save_for_after| puts a token on the stack for save-keeping. @c void save_for_after(halfword t) @@ -705,7 +714,6 @@ void save_for_after(halfword t) } } - @ The |unsave| routine goes the other way, taking items off of |save_stack|. This routine takes care of restoration when a level ends; everything belonging to the topmost group is cleared off of the save stack. @@ -714,15 +722,14 @@ belonging to the topmost group is cleared off of the save stack. void unsave(void) { /* pops the top level off the save stack */ halfword p; /* position to be restored */ - quarterword l; /* saved level, if in fullword regions of |eqtb| */ - boolean a; /* have we already processed an \.{\\aftergroup} ? */ - a = false; - l = level_one; /* just in case */ + quarterword l = level_one; /* saved level, if in fullword regions of |eqtb| */ + boolean a = false; /* have we already processed an \.{\\aftergroup} ? */ unsave_math_codes(cur_level); unsave_cat_codes(int_par(cat_code_table_code), cur_level); unsave_text_codes(cur_level); unsave_math_data(cur_level); if (cur_level > level_one) { + boolean trace = int_par(tracing_restores_code) > 0; decr(cur_level); /* Clear off top level from |save_stack| */ while (true) { @@ -731,7 +738,8 @@ void unsave(void) break; p = save_value(save_ptr); if (save_type(save_ptr) == insert_token) { - a = reinsert_token(a, p); + reinsert_token(a, p); + a = true; /* always ... always etex now */ } else { if (save_type(save_ptr) == restore_old_value) { l = save_level(save_ptr); @@ -749,24 +757,23 @@ void unsave(void) if (p < int_base || p > eqtb_size) { if (eq_level(p) == level_one) { eq_destroy(save_word(save_ptr)); /* destroy the saved value */ - if (int_par(tracing_restores_code) > 0) - restore_trace(p, "retaining"); + if (trace) + diagnostic_trace(p, "retaining"); } else { eq_destroy(eqtb[p]); /* destroy the current value */ eqtb[p] = save_word(save_ptr); /* restore the saved value */ - if (int_par(tracing_restores_code) > 0) - restore_trace(p, "restoring"); + if (trace) + diagnostic_trace(p, "restoring"); } } else if (xeq_level[p] != level_one) { eqtb[p] = save_word(save_ptr); xeq_level[p] = l; - if (int_par(tracing_restores_code) > 0) - restore_trace(p, "restoring"); + if (trace) + diagnostic_trace(p, "restoring"); } else { - if (int_par(tracing_restores_code) > 0) - restore_trace(p, "retaining"); + if (trace) + diagnostic_trace(p, "retaining"); } - } } if (int_par(tracing_groups_code) > 0) @@ -776,26 +783,12 @@ void unsave(void) cur_group = save_level(save_ptr); cur_boundary = save_value(save_ptr); decr(save_ptr); - } else { confusion("curlevel"); /* |unsave| is not used when |cur_group=bottom_level| */ } attr_list_cache = cache_disabled; } -@ @c -void restore_trace(halfword p, const char *s) -{ /* |eqtb[p]| has just been restored or retained */ - begin_diagnostic(); - print_char('{'); - tprint(s); - print_char(' '); - show_eqtb(p); - print_char('}'); - end_diagnostic(false); -} - - @ Most of the parameters kept in |eqtb| can be changed freely, but there's an exception: The magnification should not be used with two different values during any \TeX\ job, since a single magnification is applied to an @@ -803,8 +796,7 @@ entire run. The global variable |mag_set| is set to the current magnification whenever it becomes necessary to ``freeze'' it at a particular value. @c -int mag_set; /* if nonzero, this magnification should be used henceforth */ - +int mag_set; /* if nonzero, this magnification should be used henceforth */ @ The |prepare_mag| subroutine is called whenever \TeX\ wants to use |mag| for magnification. @@ -839,7 +831,6 @@ void prepare_mag(void) mag_set = mag; } - @ Let's pause a moment now and try to look at the Big Picture. The \TeX\ program consists of three main parts: syntactic routines, semantic routines, and output routines. The chief purpose of the @@ -892,7 +883,7 @@ halfword cur_chr; /* operand of current command */ halfword cur_cs; /* control sequence found here, zero if none found */ halfword cur_tok; /* packed representative of |cur_cmd| and |cur_chr| */ -@ Here is a procedure that displays the current command. +@ Here is a procedure that displays the current command. @c #define mode cur_list.mode_field @@ -939,20 +930,22 @@ void show_cur_cmd_chr(void) end_diagnostic(false); } - -@ Here is a procedure that displays the contents of |eqtb[n]| - symbolically. +@ Here is a procedure that displays the contents of |eqtb[n]| symbolically. @c void show_eqtb(halfword n) { if (n < null_cs) { - print_char('?'); /* this can't happen */ + /* this can't happen */ + print_char('?'); } else if ((n < glue_base) || ((n > eqtb_size) && (n <= eqtb_top))) { - /* Show equivalent |n|, in region 1 or 2 */ - /* Here is a routine that displays the current meaning of an |eqtb| entry - in region 1 or~2. (Similar routines for the other regions will appear - below.) */ + /* + Show equivalent |n|, in region 1 or 2 + + Here is a routine that displays the current meaning of an |eqtb| entry + in region 1 or~2. (Similar routines for the other regions will appear + below.) + */ sprint_cs(n); print_char('='); @@ -962,8 +955,11 @@ void show_eqtb(halfword n) show_token_list(token_link(equiv(n)), null, 32); } } else if (n < local_base) { - /* Show equivalent |n|, in region 3 */ - /* All glue parameters and registers are initially `\.{0pt plus0pt minus0pt}'. */ + /* + Show equivalent |n|, in region 3 + + All glue parameters and registers are initially `\.{0pt plus0pt minus0pt}'. + */ if (n < skip_base) { if (n < glue_base + thin_mu_skip_code) print_cmd_chr(assign_glue_cmd, n); @@ -987,16 +983,19 @@ void show_eqtb(halfword n) } } else if (n < int_base) { - /* Show equivalent |n|, in region 4 */ - /* We initialize most things to null or undefined values. An undefined font - is represented by the internal code |font_base|. - - However, the character code tables are given initial values based on the - conventional interpretation of ASCII code. These initial values should - not be changed when \TeX\ is adapted for use with non-English languages; - all changes to the initialization conventions should be made in format - packages, not in \TeX\ itself, so that global interchange of formats is - possible. */ + /* + Show equivalent |n|, in region 4 + + We initialize most things to null or undefined values. An undefined font + is represented by the internal code |font_base|. + + However, the character code tables are given initial values based on the + conventional interpretation of ASCII code. These initial values should + not be changed when \TeX\ is adapted for use with non-English languages; + all changes to the initialization conventions should be made in format + packages, not in \TeX\ itself, so that global interchange of formats is + possible. + */ if ((n == par_shape_loc) || ((n >= etex_pen_base) && (n < etex_pens))) { if (n == par_shape_loc) print_cmd_chr(set_tex_shape_cmd, n); @@ -1042,7 +1041,6 @@ void show_eqtb(halfword n) print_char('='); print_esc(hash[font_id_base + equiv(n)].rh); /* that's |font_id_text(equiv(n))| */ } - } else if (n < dimen_base) { /* Show equivalent |n|, in region 5 */ if (n < dir_base) { @@ -1064,7 +1062,6 @@ void show_eqtb(halfword n) print_char('='); print_int(eqtb[n].cint); } - } else if (n <= eqtb_size) { /* Show equivalent |n|, in region 6 */ if (n < scaled_base) { @@ -1076,9 +1073,9 @@ void show_eqtb(halfword n) print_char('='); print_scaled(eqtb[n].cint); tprint("pt"); - } else { - print_char('?'); /* this can't happen either */ + /* this can't happen either */ + print_char('?'); } } @@ -1086,17 +1083,23 @@ void show_eqtb(halfword n) void show_eqtb_meaning(halfword n) { if (n < null_cs) { - print_char('?'); /* this can't happen */ + /* this can't happen */ + print_char('?'); } else if ((n < glue_base) || ((n > eqtb_size) && (n <= eqtb_top))) { - /* Show equivalent |n|, in region 1 or 2 */ - /* Here is a routine that displays the current meaning of an |eqtb| entry - in region 1 or~2. (Similar routines for the other regions will appear - below.) */ + /* + Show equivalent |n|, in region 1 or 2 + Here is a routine that displays the current meaning of an |eqtb| entry + in region 1 or~2. (Similar routines for the other regions will appear + below.) + */ sprint_cs(n); } else if (n < local_base) { - /* Show equivalent |n|, in region 3 */ - /* All glue parameters and registers are initially `\.{0pt plus0pt minus0pt}'. */ + /* + Show equivalent |n|, in region 3 + + All glue parameters and registers are initially `\.{0pt plus0pt minus0pt}'. + */ if (n < skip_base) { if (n < glue_base + thin_mu_skip_code) print_cmd_chr(assign_glue_cmd, n); @@ -1111,16 +1114,19 @@ void show_eqtb_meaning(halfword n) } } else if (n < int_base) { - /* Show equivalent |n|, in region 4 */ - /* We initialize most things to null or undefined values. An undefined font - is represented by the internal code |font_base|. - - However, the character code tables are given initial values based on the - conventional interpretation of ASCII code. These initial values should - not be changed when \TeX\ is adapted for use with non-English languages; - all changes to the initialization conventions should be made in format - packages, not in \TeX\ itself, so that global interchange of formats is - possible. */ + /* + Show equivalent |n|, in region 4 + + We initialize most things to null or undefined values. An undefined font + is represented by the internal code |font_base|. + + However, the character code tables are given initial values based on the + conventional interpretation of ASCII code. These initial values should + not be changed when \TeX\ is adapted for use with non-English languages; + all changes to the initialization conventions should be made in format + packages, not in \TeX\ itself, so that global interchange of formats is + possible. + */ if ((n == par_shape_loc) || ((n >= etex_pen_base) && (n < etex_pens))) { if (n == par_shape_loc) print_cmd_chr(set_tex_shape_cmd, n); @@ -1138,7 +1144,6 @@ void show_eqtb_meaning(halfword n) /* Show the font identifier in |eqtb[n]| */ tprint("current font"); } - } else if (n < dimen_base) { /* Show equivalent |n|, in region 5 */ if (n < dir_base) { @@ -1152,7 +1157,6 @@ void show_eqtb_meaning(halfword n) tprint_esc("attribute"); print_int(n - attribute_base); } - } else if (n <= eqtb_size) { /* Show equivalent |n|, in region 6 */ if (n < scaled_base) { @@ -1162,6 +1166,7 @@ void show_eqtb_meaning(halfword n) print_int(n - scaled_base); } } else { - print_char('?'); /* this can't happen either */ + /* this can't happen either */ + print_char('?'); } } diff --git a/Build/source/texk/web2c/luatexdir/tex/errors.h b/Build/source/texk/web2c/luatexdir/tex/errors.h index 101e78adb71..3eae1c8a927 100644 --- a/Build/source/texk/web2c/luatexdir/tex/errors.h +++ b/Build/source/texk/web2c/luatexdir/tex/errors.h @@ -99,7 +99,9 @@ extern void pause_for_instructions(void); extern void tex_error(const char *msg, const char **hlp); extern void normal_error(const char *t, const char *p); -extern void normal_warning(const char *t, const char *p, boolean pr, boolean ap); +extern void normal_warning(const char *t, const char *p); +extern void formatted_error(const char *t, const char *fmt, ...); +extern void formatted_warning(const char *t, const char *fmt, ...); extern void back_error(void); extern void ins_error(void); @@ -107,4 +109,6 @@ extern void flush_err(void); extern void char_warning(internal_font_number f, int c); +extern void wrapup_backend(void); + #endif diff --git a/Build/source/texk/web2c/luatexdir/tex/errors.w b/Build/source/texk/web2c/luatexdir/tex/errors.w index e11fcd908fe..227095d3f09 100644 --- a/Build/source/texk/web2c/luatexdir/tex/errors.w +++ b/Build/source/texk/web2c/luatexdir/tex/errors.w @@ -659,10 +659,41 @@ void char_warning(internal_font_number f, int c) } @ @c + +void wrapup_backend(void) { + ensure_output_state(static_pdf, ST_OMODE_FIX); + switch (output_mode_used) { + case OMODE_NONE: + print_err(" ==> Fatal error occurred, no FMT file produced!"); + break; + case OMODE_PDF: + if (history == fatal_error_stop) { + remove_pdffile(static_pdf); /* will become remove_output_file */ + print_err(" ==> Fatal error occurred, no output PDF file produced!"); + } else { + finish_pdf_file(static_pdf, luatex_version, get_luatexrevision()); + } + break; + case OMODE_DVI: + if (history == fatal_error_stop) { + print_err(" ==> Fatal error occurred, bad output DVI file produced!"); + finish_dvi_file(static_pdf, luatex_version, get_luatexrevision()); + } else { + finish_dvi_file(static_pdf, luatex_version, get_luatexrevision()); + } + break; + } +} + void normal_error(const char *t, const char *p) { normalize_selector(); print_err("error "); + if (cur_file_name) { + tprint(" (file "); + tprint(cur_file_name); + tprint(")"); + } if (t != NULL) { tprint(" ("); tprint(t); @@ -671,11 +702,14 @@ void normal_error(const char *t, const char *p) tprint(": "); if (p != NULL) tprint(p); - succumb(); + /* quit */ + history = fatal_error_stop; + wrapup_backend(); + exit(EXIT_FAILURE); } @ @c -void normal_warning(const char *t, const char *p, boolean prepend_nl, boolean append_nl) +void normal_warning(const char *t, const char *p) { int report_id ; if (strcmp(t,"lua") == 0) { @@ -704,9 +738,13 @@ void normal_warning(const char *t, const char *p, boolean prepend_nl, boolean ap strcpy(last_warning_tag,t); run_callback(report_id, "->"); } else { - if (prepend_nl) - print_ln(); + print_ln(); tprint("warning "); + if (cur_file_name) { + tprint(" (file "); + tprint(cur_file_name); + tprint(")"); + } if (t != NULL) { tprint(" ("); tprint(t); @@ -715,10 +753,30 @@ void normal_warning(const char *t, const char *p, boolean prepend_nl, boolean ap tprint(": "); if (p != NULL) tprint(p); - if (append_nl) - print_ln(); + print_ln(); } if (history == spotless) history = warning_issued; } } + +@ @c +static char print_buf[PRINTF_BUF_SIZE]; + +void formatted_error(const char *t, const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vsnprintf(print_buf, PRINTF_BUF_SIZE, fmt, args); + normal_error(t,print_buf); + va_end(args); +} + +void formatted_warning(const char *t, const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vsnprintf(print_buf, PRINTF_BUF_SIZE, fmt, args); + normal_warning(t,print_buf); + va_end(args); +} diff --git a/Build/source/texk/web2c/luatexdir/tex/expand.h b/Build/source/texk/web2c/luatexdir/tex/expand.h index 713901986a3..18c0514e317 100644 --- a/Build/source/texk/web2c/luatexdir/tex/expand.h +++ b/Build/source/texk/web2c/luatexdir/tex/expand.h @@ -1,5 +1,5 @@ /* expand.h - + Copyright 2009 Taco Hoekwater This file is part of LuaTeX. @@ -24,7 +24,8 @@ extern boolean is_in_csname; extern void expand(void); extern void complain_missing_csname(void); -extern void manufacture_csname(void); +extern void manufacture_csname(boolean use); +extern void inject_last_tested_cs(void); extern void insert_relax(void); extern void get_x_token(void); extern void x_token(void); diff --git a/Build/source/texk/web2c/luatexdir/tex/expand.w b/Build/source/texk/web2c/luatexdir/tex/expand.w index 098b6808373..46c8622b491 100644 --- a/Build/source/texk/web2c/luatexdir/tex/expand.w +++ b/Build/source/texk/web2c/luatexdir/tex/expand.w @@ -221,7 +221,13 @@ void expand(void) break; case cs_name_cmd: /* Manufacture a control sequence name; */ - manufacture_csname(); + if (cur_chr == 0) { + manufacture_csname(0); + } else if (cur_chr == 1) { + inject_last_tested_cs(); + } else { + manufacture_csname(1); + } break; case convert_cmd: conv_toks(); /* this procedure is discussed in Part 27 below */ @@ -229,6 +235,9 @@ void expand(void) case the_cmd: ins_the_toks(); /* this procedure is discussed in Part 27 below */ break; + case combine_toks_cmd: + combine_the_toks(cur_chr); + break; case if_test_cmd: conditional(); /* this procedure is discussed in Part 28 below */ break; @@ -320,7 +329,7 @@ void complain_missing_csname(void) } @ @c -void manufacture_csname(void) +void manufacture_csname(boolean use) { halfword p, q, r; lstring *ss; @@ -339,22 +348,50 @@ void manufacture_csname(void) /* Look up the characters of list |r| in the hash table, and set |cur_cs| */ ss = tokenlist_to_lstring(r, true); is_in_csname -= 1; - if (ss->l > 0) { - no_new_control_sequence = false; - cur_cs = string_lookup((char *) ss->s, ss->l); - no_new_control_sequence = true; + if (use) { + if (ss->l > 0) { + cur_cs = string_lookup((char *) ss->s, ss->l); + } else { + cur_cs = null_cs; + } + last_cs_name = cur_cs ; + free_lstring(ss); + flush_list(r); + if (cur_cs == null_cs) { + /* skip */ + } else if (eq_type(cur_cs) == undefined_cs_cmd) { + /* skip */ + } else { + cur_tok = cur_cs + cs_token_flag; + back_input(); + } } else { - cur_cs = null_cs; /* the list is empty */ + if (ss->l > 0) { + no_new_control_sequence = false; + cur_cs = string_lookup((char *) ss->s, ss->l); + no_new_control_sequence = true; + } else { + cur_cs = null_cs; /* the list is empty */ + } + last_cs_name = cur_cs ; + free_lstring(ss); + flush_list(r); + if (eq_type(cur_cs) == undefined_cs_cmd) { + eq_define(cur_cs, relax_cmd, too_big_char); /* N.B.: The |save_stack| might change */ + }; /* the control sequence will now match `\.{\\relax}' */ + cur_tok = cur_cs + cs_token_flag; + back_input(); } - free_lstring(ss); - flush_list(r); - if (eq_type(cur_cs) == undefined_cs_cmd) { - eq_define(cur_cs, relax_cmd, too_big_char); /* N.B.: The |save_stack| might change */ - }; /* the control sequence will now match `\.{\\relax}' */ - cur_tok = cur_cs + cs_token_flag; - back_input(); } +void inject_last_tested_cs(void) +{ + if (last_cs_name != null_cs) { + cur_cs = last_cs_name; + cur_tok = last_cs_name + cs_token_flag; + back_input(); + } +} @ Sometimes the expansion looks too far ahead, so we want to insert a harmless \.{\\relax} into the user's input. @@ -378,7 +415,7 @@ common cases. void get_x_token(void) { /* sets |cur_cmd|, |cur_chr|, |cur_tok|, and expands macros */ RESTART: - get_next(); /* get_token_lua(); */ + get_next(); if (cur_cmd <= max_command_cmd) goto DONE; if (cur_cmd >= call_cmd) { @@ -409,7 +446,7 @@ void x_token(void) { /* |get_x_token| without the initial |get_next| */ while (cur_cmd > max_command_cmd) { expand(); - get_next(); /* get_token_lua(); */ + get_next(); } if (cur_cs == 0) cur_tok = token_val(cur_cmd, cur_chr); @@ -750,9 +787,10 @@ void macro_call(void) /* Before we put a new token list on the input stack, it is wise to clean off all token lists that have recently been depleted. Then a user macro that ends with a call to itself will not require unbounded stack space. */ - while ((istate == token_list) && (iloc == null) - && (token_type != v_template)) - end_token_list(); /* conserve stack space */ + while ((istate == token_list) && (iloc == null) && (token_type != v_template)) { + /* conserve stack space */ + end_token_list(); + } begin_token_list(ref_count, macro); iname = warning_index; iloc = token_link(r); diff --git a/Build/source/texk/web2c/luatexdir/tex/extensions.h b/Build/source/texk/web2c/luatexdir/tex/extensions.h index 4909b9b95f6..01a75b7e387 100644 --- a/Build/source/texk/web2c/luatexdir/tex/extensions.h +++ b/Build/source/texk/web2c/luatexdir/tex/extensions.h @@ -44,13 +44,6 @@ extern halfword write_loc; extern void do_extension(int immediate); -extern int pdf_last_annot; -extern int pdf_last_link; -extern int pdf_last_obj; -extern int pdf_retval; - -/* Three extra node types carry information from |main_control|. */ - /* User defined whatsits can be inserted into node lists to pass data along from one lua call to another without interference from the @@ -59,7 +52,6 @@ type of the value depends on the |user_node_type| field. */ extern void new_whatsit(int s); -extern void scan_pdf_ext_toks(void); extern halfword concat_tokens(halfword q, halfword r); diff --git a/Build/source/texk/web2c/luatexdir/tex/extensions.w b/Build/source/texk/web2c/luatexdir/tex/extensions.w index 37736cc5a1a..0e178f01516 100644 --- a/Build/source/texk/web2c/luatexdir/tex/extensions.w +++ b/Build/source/texk/web2c/luatexdir/tex/extensions.w @@ -152,7 +152,7 @@ static void do_extension_pdf(int immediate) set_pdf_literal_mode(tail, direct_page); else set_pdf_literal_mode(tail, set_origin); - scan_pdf_ext_toks(); + scan_toks(false, true); set_pdf_literal_type(tail, normal); set_pdf_literal_data(tail, def_ref); } else if (scan_keyword("dest")) { @@ -165,7 +165,7 @@ static void do_extension_pdf(int immediate) new_whatsit(pdf_restore_node); } else if (scan_keyword("setmatrix")) { new_whatsit(pdf_setmatrix_node); - scan_pdf_ext_toks(); + scan_toks(false, true); set_pdf_setmatrix_data(tail, def_ref); } else if (scan_keyword("obj")) { scan_obj(static_pdf); @@ -211,7 +211,7 @@ static void do_extension_pdf(int immediate) set_pdf_colorstack_cmd(tail, i); set_pdf_colorstack_data(tail, null); if (i <= colorstack_data) { - scan_pdf_ext_toks(); + scan_toks(false, true); set_pdf_colorstack_data(tail, def_ref); } } else { @@ -251,30 +251,30 @@ static void do_extension_pdf(int immediate) i = cur_val; if (i == null_font) normal_error("pdf backend", "invalid font identifier"); - scan_pdf_ext_toks(); + scan_toks(false, true); set_pdf_font_attr(i, tokens_to_string(def_ref)); if (str_length(pdf_font_attr(i)) == 0) { flush_str((str_ptr - 1)); /* from |tokens_to_string| */ set_pdf_font_attr(i, 0); } } else if (scan_keyword("mapfile")) { - scan_pdf_ext_toks(); + scan_toks(false, true); pdfmapfile(def_ref); delete_token_ref(def_ref); } else if (scan_keyword("mapline")) { - scan_pdf_ext_toks(); + scan_toks(false, true); pdfmapline(def_ref); delete_token_ref(def_ref); } else if (scan_keyword("includechars")) { pdf_include_chars(static_pdf); } else if (scan_keyword("info")) { - scan_pdf_ext_toks(); + scan_toks(false, true); pdf_info_toks = concat_tokens(pdf_info_toks, def_ref); } else if (scan_keyword("names")) { - scan_pdf_ext_toks(); + scan_toks(false, true); pdf_names_toks = concat_tokens(pdf_names_toks, def_ref); } else if (scan_keyword("trailer")) { - scan_pdf_ext_toks(); + scan_toks(false, true); pdf_trailer_toks = concat_tokens(pdf_trailer_toks, def_ref); } else { tex_error("unexpected use of \\pdfextension",null); @@ -463,8 +463,7 @@ and appends it to the current list. @c void new_whatsit(int s) { - halfword p; /* the new node */ - p = new_node(whatsit_node, s); + halfword p = new_node(whatsit_node, s); couple_nodes(tail, p); tail = p; } @@ -482,11 +481,10 @@ single page, the stack would overflow. void expand_macros_in_tokenlist(halfword p) { - int old_mode; /* saved |mode| */ - pointer q, r; /* temporary variables for list manipulation */ - q = get_avail(); + int old_mode; + pointer q = get_avail(); + pointer r = get_avail(); token_info(q) = right_brace_token + '}'; - r = get_avail(); token_link(q) = r; token_info(r) = end_write_token; begin_token_list(q, inserted); @@ -588,22 +586,6 @@ boolean open_write_file(int id, char *fn) { } } -@ We have to check whether \.{\\outputmode} is set for using \pdfTeX{} - extensions. - -@c -void scan_pdf_ext_toks(void) -{ - (void) scan_toks(false, true); /* like \.{\\special} */ -} - -@ the pdflast* need extra global variables - -@c -int pdf_last_annot; -int pdf_last_link; -int pdf_last_obj; -int pdf_retval; /* global multi-purpose return value */ @ To implement primitives as \.{\\pdfextension info}, \.{\\pdfextension catalog} or \.{\\pdfextension names} we need to concatenate tokens lists. @@ -644,58 +626,58 @@ the name corresponding to |cur_group|. void print_group(boolean e) { switch (cur_group) { - case bottom_level: - tprint("bottom level"); - return; - break; - case simple_group: - case semi_simple_group: - if (cur_group == semi_simple_group) - tprint("semi "); - tprint("simple"); - break;; - case hbox_group: - case adjusted_hbox_group: - if (cur_group == adjusted_hbox_group) - tprint("adjusted "); - tprint("hbox"); - break; - case vbox_group: - tprint("vbox"); - break; - case vtop_group: - tprint("vtop"); - break; - case align_group: - case no_align_group: - if (cur_group == no_align_group) - tprint("no "); - tprint("align"); - break; - case output_group: - tprint("output"); - break; - case disc_group: - tprint("disc"); - break; - case insert_group: - tprint("insert"); - break; - case vcenter_group: - tprint("vcenter"); - break; - case math_group: - case math_choice_group: - case math_shift_group: - case math_left_group: - tprint("math"); - if (cur_group == math_choice_group) - tprint(" choice"); - else if (cur_group == math_shift_group) - tprint(" shift"); - else if (cur_group == math_left_group) - tprint(" left"); - break; + case bottom_level: + tprint("bottom level"); + return; + break; + case simple_group: + case semi_simple_group: + if (cur_group == semi_simple_group) + tprint("semi "); + tprint("simple"); + break;; + case hbox_group: + case adjusted_hbox_group: + if (cur_group == adjusted_hbox_group) + tprint("adjusted "); + tprint("hbox"); + break; + case vbox_group: + tprint("vbox"); + break; + case vtop_group: + tprint("vtop"); + break; + case align_group: + case no_align_group: + if (cur_group == no_align_group) + tprint("no "); + tprint("align"); + break; + case output_group: + tprint("output"); + break; + case disc_group: + tprint("disc"); + break; + case insert_group: + tprint("insert"); + break; + case vcenter_group: + tprint("vcenter"); + break; + case math_group: + case math_choice_group: + case math_shift_group: + case math_left_group: + tprint("math"); + if (cur_group == math_choice_group) + tprint(" choice"); + else if (cur_group == math_shift_group) + tprint(" shift"); + else if (cur_group == math_left_group) + tprint(" left"); + break; } /* there are no other cases */ tprint(" group (level "); print_int(cur_level); @@ -751,12 +733,10 @@ synchronized with the |in_open| variable indexing |grp_stack|. @c void group_warning(void) { - int i; /* index into |grp_stack| */ - boolean w; /* do we need a warning? */ + boolean w = false; /* do we need a warning? */ + int i = in_open; /* index into |grp_stack| */ base_ptr = input_ptr; input_stack[base_ptr] = cur_input; /* store current state */ - i = in_open; - w = false; while ((grp_stack[i] == cur_boundary) && (i > 0)) { /* Set variable |w| to indicate if this case should be reported */ /* This code scans the input stack in order to determine the type of the @@ -792,12 +772,10 @@ give a warning message (with the same complications as above). @c void if_warning(void) { - int i; /* index into |if_stack| */ - boolean w; /* do we need a warning? */ + boolean w = false; /* do we need a warning? */ + int i = in_open; base_ptr = input_ptr; input_stack[base_ptr] = cur_input; /* store current state */ - i = in_open; - w = false; while (if_stack[i] == cond_ptr) { /* Set variable |w| to... */ if (tracing_nesting > 0) { @@ -832,13 +810,10 @@ file are still incomplete. @c void file_warning(void) { - halfword p; /* saved value of |save_ptr| or |cond_ptr| */ - int l; /* saved value of |cur_level| or |if_limit| */ - int c; /* saved value of |cur_group| or |cur_if| */ - int i; /* saved value of |if_line| */ - p = save_ptr; - l = cur_level; - c = cur_group; + halfword p = save_ptr; /* saved value of |save_ptr| or |cond_ptr| */ + int l = cur_level; /* saved value of |cur_level| or |if_limit| */ + int c = cur_group; /* saved value of |cur_group| or |cur_if| */ + int i; /* saved value of |if_line| */ save_ptr = cur_boundary; while (grp_stack[in_open] != save_ptr) { decr(cur_level); @@ -999,8 +974,7 @@ int set_tex_attribute_register(int j, scaled v) int get_tex_toks_register(int j) { - str_number s; - s = get_nullstr(); + str_number s = get_nullstr(); if (toks(j) != null) { s = tokens_to_string(toks(j)); } @@ -1009,9 +983,8 @@ int get_tex_toks_register(int j) int set_tex_toks_register(int j, lstring s) { - halfword ref; int a; - ref = get_avail(); + halfword ref = get_avail(); (void) str_toks(s); set_token_ref_count(ref, 0); set_token_link(ref, token_link(temp_token_head)); @@ -1025,9 +998,8 @@ int set_tex_toks_register(int j, lstring s) int scan_tex_toks_register(int j, int c, lstring s) { - halfword ref; int a; - ref = get_avail(); + halfword ref = get_avail(); (void) str_scan_toks(c,s); set_token_ref_count(ref, 0); set_token_link(ref, token_link(temp_token_head)); diff --git a/Build/source/texk/web2c/luatexdir/tex/inputstack.h b/Build/source/texk/web2c/luatexdir/tex/inputstack.h index 390fb169198..378fabe24b8 100644 --- a/Build/source/texk/web2c/luatexdir/tex/inputstack.h +++ b/Build/source/texk/web2c/luatexdir/tex/inputstack.h @@ -1,5 +1,5 @@ /* inputstack.h - + Copyright 2009 Taco Hoekwater This file is part of LuaTeX. @@ -24,7 +24,7 @@ /* The state of \TeX's input mechanism appears in the input stack, whose entries are records with six fields, called |state|, |index|, |start|, |loc|, - |limit|, and |name|. + |limit|, and |name|. */ typedef struct in_state_record { @@ -273,7 +273,7 @@ the text expansion of a \.{\\count} or similar variable; \yskip\noindent The codes for |output_text|, |every_par_text|, etc., are equal to a constant plus the corresponding codes for token list parameters |output_routine_loc|, -|every_par_loc|, etc. +|every_par_loc|, etc. The token list begins with a reference count if and only if |token_type>=macro|. @@ -319,18 +319,13 @@ extern int base_ptr; extern void show_context(void); extern void set_trick_count(void); -/* leave an input level, re-enter the old */ -# define pop_input() cur_input=input_stack[--input_ptr] - -extern void push_input(void); - # define back_list(A) begin_token_list(A,backed_up) /* backs up a simple token list */ # define ins_list(A) begin_token_list(A,inserted) /* inserts a simple token list */ extern void begin_token_list(halfword p, quarterword t); extern void end_token_list(void); extern void back_input(void); -extern int reinsert_token(boolean a, halfword pp); +extern void reinsert_token(boolean a, halfword pp); extern void begin_file_reading(void); extern void end_file_reading(void); extern void clear_for_error_prompt(void); diff --git a/Build/source/texk/web2c/luatexdir/tex/inputstack.w b/Build/source/texk/web2c/luatexdir/tex/inputstack.w index aaeec71e65f..273863d2042 100644 --- a/Build/source/texk/web2c/luatexdir/tex/inputstack.w +++ b/Build/source/texk/web2c/luatexdir/tex/inputstack.w @@ -19,14 +19,12 @@ @ @c - #include "ptexlib.h" @ @c #define end_line_char int_par(end_line_char_code) #define error_context_lines int_par(error_context_lines_code) - in_state_record *input_stack = NULL; int input_ptr = 0; /* first unused location of |input_stack| */ int max_in_stack = 0; /* largest value of |input_ptr| when pushing */ @@ -46,15 +44,13 @@ int scanner_status = 0; /* can a subfile end now? */ pointer warning_index = null; /* identifier relevant to non-|normal| scanner status */ pointer def_ref = null; /* reference count of token list being defined */ - - @ Here is a procedure that uses |scanner_status| to print a warning message when a subfile has ended, and at certain other crucial times: @c void runaway(void) { - pointer p = null; /* head of runaway list */ + pointer p = null; /* head of runaway list */ if (scanner_status > skipping) { switch (scanner_status) { case defining: @@ -73,7 +69,8 @@ void runaway(void) tprint_nl("Runaway text"); p = def_ref; break; - default: /* there are no other cases */ + default: + /* there are no other cases */ break; } print_char('?'); @@ -82,7 +79,6 @@ void runaway(void) } } - @ The |param_stack| is an auxiliary array used to hold pointers to the token lists for parameters at the current level and subsidiary levels of input. This stack is maintained with convention (2), and it grows at a different @@ -106,7 +102,6 @@ $v_j$ template begins when a tab mark or \.{\\cr} occurs at a time that @c int align_state = 0; /* group level with respect to current alignment */ - @ Thus, the ``current input state'' can be very complicated indeed; there can be many levels and each level can arise in a variety of ways. The |show_context| procedure, which is used by \TeX's error-reporting routine to @@ -118,7 +113,6 @@ displayed by this procedure. @c int base_ptr = 0; /* shallowest level shown by |show_context| */ - @ The status at each level is indicated by printing two lines, where the first line indicates what was read so far and the second line shows what remains to be read. The context is cropped, if necessary, so that the first line @@ -130,66 +124,66 @@ at most |error_line|. Non-current input levels whose |token_type| is static void print_token_list_type(int t) { switch (t) { - case parameter: - tprint_nl(" "); - break; - case u_template: - case v_template: - tprint_nl("