diff options
85 files changed, 1065 insertions, 1130 deletions
diff --git a/doc/context/documents/general/manuals/luatex.pdf b/doc/context/documents/general/manuals/luatex.pdf Binary files differindex 909511695..64579ea5d 100644 --- a/doc/context/documents/general/manuals/luatex.pdf +++ b/doc/context/documents/general/manuals/luatex.pdf diff --git a/doc/context/documents/general/qrcs/setup-cs.pdf b/doc/context/documents/general/qrcs/setup-cs.pdf Binary files differindex a4419cbac..07c29bcd9 100644 --- a/doc/context/documents/general/qrcs/setup-cs.pdf +++ b/doc/context/documents/general/qrcs/setup-cs.pdf diff --git a/doc/context/documents/general/qrcs/setup-de.pdf b/doc/context/documents/general/qrcs/setup-de.pdf Binary files differindex 1307192cc..641dda76c 100644 --- a/doc/context/documents/general/qrcs/setup-de.pdf +++ b/doc/context/documents/general/qrcs/setup-de.pdf diff --git a/doc/context/documents/general/qrcs/setup-en.pdf b/doc/context/documents/general/qrcs/setup-en.pdf Binary files differindex 870816228..e5740aa2c 100644 --- a/doc/context/documents/general/qrcs/setup-en.pdf +++ b/doc/context/documents/general/qrcs/setup-en.pdf diff --git a/doc/context/documents/general/qrcs/setup-fr.pdf b/doc/context/documents/general/qrcs/setup-fr.pdf Binary files differindex a33afa9db..7d6ae81eb 100644 --- a/doc/context/documents/general/qrcs/setup-fr.pdf +++ b/doc/context/documents/general/qrcs/setup-fr.pdf diff --git a/doc/context/documents/general/qrcs/setup-it.pdf b/doc/context/documents/general/qrcs/setup-it.pdf Binary files differindex b043eabf5..68d84e42d 100644 --- a/doc/context/documents/general/qrcs/setup-it.pdf +++ b/doc/context/documents/general/qrcs/setup-it.pdf diff --git a/doc/context/documents/general/qrcs/setup-mapping-cs.pdf b/doc/context/documents/general/qrcs/setup-mapping-cs.pdf Binary files differindex 93b4b50a0..ce8e808db 100644 --- a/doc/context/documents/general/qrcs/setup-mapping-cs.pdf +++ b/doc/context/documents/general/qrcs/setup-mapping-cs.pdf diff --git a/doc/context/documents/general/qrcs/setup-mapping-de.pdf b/doc/context/documents/general/qrcs/setup-mapping-de.pdf Binary files differindex 731c4f84e..45c469809 100644 --- a/doc/context/documents/general/qrcs/setup-mapping-de.pdf +++ b/doc/context/documents/general/qrcs/setup-mapping-de.pdf diff --git a/doc/context/documents/general/qrcs/setup-mapping-en.pdf b/doc/context/documents/general/qrcs/setup-mapping-en.pdf Binary files differindex 524fff8a5..67bf50992 100644 --- a/doc/context/documents/general/qrcs/setup-mapping-en.pdf +++ b/doc/context/documents/general/qrcs/setup-mapping-en.pdf diff --git a/doc/context/documents/general/qrcs/setup-mapping-fr.pdf b/doc/context/documents/general/qrcs/setup-mapping-fr.pdf Binary files differindex 3ca020d87..7316debcf 100644 --- a/doc/context/documents/general/qrcs/setup-mapping-fr.pdf +++ b/doc/context/documents/general/qrcs/setup-mapping-fr.pdf diff --git a/doc/context/documents/general/qrcs/setup-mapping-it.pdf b/doc/context/documents/general/qrcs/setup-mapping-it.pdf Binary files differindex 8e77b7749..f6d5d6a23 100644 --- a/doc/context/documents/general/qrcs/setup-mapping-it.pdf +++ b/doc/context/documents/general/qrcs/setup-mapping-it.pdf diff --git a/doc/context/documents/general/qrcs/setup-mapping-nl.pdf b/doc/context/documents/general/qrcs/setup-mapping-nl.pdf Binary files differindex 700c20639..0b3d8c46f 100644 --- a/doc/context/documents/general/qrcs/setup-mapping-nl.pdf +++ b/doc/context/documents/general/qrcs/setup-mapping-nl.pdf diff --git a/doc/context/documents/general/qrcs/setup-mapping-ro.pdf b/doc/context/documents/general/qrcs/setup-mapping-ro.pdf Binary files differindex 4a1cb0bf2..e804d25da 100644 --- a/doc/context/documents/general/qrcs/setup-mapping-ro.pdf +++ b/doc/context/documents/general/qrcs/setup-mapping-ro.pdf diff --git a/doc/context/documents/general/qrcs/setup-nl.pdf b/doc/context/documents/general/qrcs/setup-nl.pdf Binary files differindex dd2098318..7a2d5a079 100644 --- a/doc/context/documents/general/qrcs/setup-nl.pdf +++ b/doc/context/documents/general/qrcs/setup-nl.pdf diff --git a/doc/context/documents/general/qrcs/setup-ro.pdf b/doc/context/documents/general/qrcs/setup-ro.pdf Binary files differindex 597703202..967dc6ad8 100644 --- a/doc/context/documents/general/qrcs/setup-ro.pdf +++ b/doc/context/documents/general/qrcs/setup-ro.pdf diff --git a/doc/context/sources/general/manuals/luatex/luatex-introduction.tex b/doc/context/sources/general/manuals/luatex/luatex-introduction.tex index 1f997e250..5ed80f4c1 100644 --- a/doc/context/sources/general/manuals/luatex/luatex-introduction.tex +++ b/doc/context/sources/general/manuals/luatex/luatex-introduction.tex @@ -125,10 +125,15 @@ but there is no support for any of its experimental features. Intermediate releases (from trunk) are normally available via the \CONTEXT\ distribution channels (the garden and so called minimals). -Future versions will probably become a bit leaner and meaner. Some libraries -might become external as we don't want to bloat the binary and also don't want to -add more hard coded solutions. After all, with \LUA\ you can extend the core -functionality. The less dependencies, the better. +Version 1.10 is more or less an endpoint in development: this is what you get. +Because not only \CONTEXT, that we can adapt rather easily, uses \LUATEX, we +cannot change fundamentals without unforeseen consequences. By now it has been +proven that \LUA\ can be used to extend the core functionality so there is no +need to add more, and definitely no hard coded solutions for (not so) common +problems. Of course there will be bug fixes, maybe some optimization, and there +might even be some additions or non|-|intrusive improvements, but only after +testing outside the stable release. After all, the binary is already more than +large enough and there is not that much to gain. You might find \LUA\ helpers that are not yet documented. These are considered experimental, although when you encounter them in a \CONTEXT\ version that has diff --git a/doc/context/sources/general/manuals/luatex/luatex-lua.tex b/doc/context/sources/general/manuals/luatex/luatex-lua.tex index 27146d99b..f9107fa1f 100644 --- a/doc/context/sources/general/manuals/luatex/luatex-lua.tex +++ b/doc/context/sources/general/manuals/luatex/luatex-lua.tex @@ -347,29 +347,22 @@ returns the name. \startsubsection[title={Multibyte \type {string} functions}] -\libidx{string}{utfvalues} -\libidx{string}{utfcharacters} -\libidx{string}{characters} -\libidx{string}{characterpairs} -\libidx{string}{bytes} -\libidx{string}{bytepairs} -\libidx{string}{utfvalue} -\libidx{string}{utfcharacter} -\libidx{string}{utflength} - -The \type {string} library has a few extra functions like \type -{string.explode(s[,m])}. This function returns an array containing the string -argument \type {s} split into sub-strings based on the value of the string -argument \type {m}. The second argument is a string that is either empty (this -splits the string into characters), a single character (this splits on each -occurrence of that character, possibly introducing empty strings), or a single -character followed by the plus sign \type {+} (this special version does not -create empty sub-strings). The default value for \type {m} is \quote {\type { +}} -(multiple spaces). Note: \type {m} is not hidden by surrounding braces as it -would be if this function was written in \TEX\ macros. +The \type {string} library has a few extra functions, for example \libidx +{string} {explode}. This function takes upto two arguments: \type +{string.explode(s[,m])} and returns an array containing the string argument \type +{s} split into sub-strings based on the value of the string argument \type {m}. +The second argument is a string that is either empty (this splits the string into +characters), a single character (this splits on each occurrence of that +character, possibly introducing empty strings), or a single character followed by +the plus sign \type {+} (this special version does not create empty sub-strings). +The default value for \type {m} is \quote {\type { +}} (multiple spaces). Note: +\type {m} is not hidden by surrounding braces as it would be if this function was +written in \TEX\ macros. The \type {string} library also has six extra iterators that return strings -piecemeal: +piecemeal: \libidx {string} {utfvalues}, \libidx {string} {utfcharacters}, +\libidx {string} {characters}, \libidx {string} {characterpairs}, \libidx +{string} {bytes} and \libidx {string} {bytepairs}. \startitemize \startitem @@ -415,7 +408,8 @@ interpretation of character classes in \type {unicode.utf8} functions refer to the library sources at \hyphenatedurl {http://luaforge.net/projects/sln}. Version 5.3 of \LUA\ provides some native \UTF8 support but we have added a few -similar helpers too: +similar helpers too: \libidx {string} {utfvalue}, \libidx {string} {utfcharacter} +and \libidx {string} {utflength}. \startitemize \startitem @@ -431,27 +425,18 @@ similar helpers too: \stopitem \stopitemize -These three functions are relative fast and don't do much checking. They can be used -as building blocks for other helpers. So, eventually we can decide to drop the -\type {sln} library, just that you know. +These three functions are relative fast and don't do much checking. They can be +used as building blocks for other helpers. \stopsubsection \startsubsection[title={Extra \type {os} library functions}] -\libidx{os}{selfdir} -\libidx{os}{exec} -\libidx{os}{spawn} -\libidx{os}{setenv} -\libidx{os}{env} -\libidx{os}{gettimeofday} -\libidx{os}{times} -\libidx{os}{tmpdir} -\libidx{os}{type} -\libidx{os}{name} -\libidx{os}{uname} - -The \type {os} library has a few extra functions and variables: +The \type {os} library has a few extra functions and variables: \libidx {os} +{selfdir}, \libidx {os} {exec}, \libidx {os} {spawn}, \libidx {os} {setenv}, +\libidx {os} {env}, \libidx {os} {gettimeofday}, \libidx {os} {times}, \libidx +{os} {tmpdir}, \libidx {os} {type}, \libidx {os} {name} and \libidx {os} {uname}, +that we will discuss here. \startitemize @@ -585,24 +570,16 @@ The \type {os} library has a few extra functions and variables: \startsubsection[title={Binary input from files with \type {fio}}] -\libidx{fio}{readcardinal1} -\libidx{fio}{readcardinal2} -\libidx{fio}{readcardinal3} -\libidx{fio}{readcardinal4} -\libidx{fio}{readcardinaltable} -\libidx{fio}{readinteger1} -\libidx{fio}{readinteger2} -\libidx{fio}{readinteger3} -\libidx{fio}{readinteger4} -\libidx{fio}{readintegertable} -\libidx{fio}{readfixed2} -\libidx{fio}{readfixed4} -\libidx{fio}{read2dot14} -\libidx{fio}{setposition} -\libidx{fio}{getposition} -\libidx{fio}{skipposition} -\libidx{fio}{readbytes} -\libidx{fio}{readbytetable} +There is a whole set of helpers for reading numbers and strings from a file: +\libidx {fio} {readcardinal1}, \libidx {fio} {readcardinal2}, \libidx {fio} +{readcardinal3}, \libidx {fio} {readcardinal4}, \libidx {fio} +{readcardinaltable}, \libidx {fio} {readinteger1}, \libidx {fio} {readinteger2}, +\libidx {fio} {readinteger3}, \libidx {fio} {readinteger4}, \libidx {fio} +{readintegertable}, \libidx {fio} {readfixed2}, \libidx {fio} {readfixed4}, +\libidx {fio} {read2dot14}, \libidx {fio} {setposition}, \libidx {fio} +{getposition}, \libidx {fio} {skipposition}, \libidx {fio} {readbytes}, \libidx +{fio} {readbytetable}. They work on normal \LUA\ file handles. + %libidx{fio}{readline} %libidx{fio}{recordfilename} %libidx{fio}{checkpermission} @@ -635,39 +612,25 @@ in addition to the regular \type {io} library functions. \startsubsection[title={Binary input from strings with \type {sio}}] -\libidx{sio}{readcardinal1} -\libidx{sio}{readcardinal2} -\libidx{sio}{readcardinal3} -\libidx{sio}{readcardinal4} -\libidx{sio}{readcardinaltable} -\libidx{sio}{readinteger1} -\libidx{sio}{readinteger2} -\libidx{sio}{readinteger3} -\libidx{sio}{readinteger4} -\libidx{sio}{readintegertable} -\libidx{sio}{readfixed2} -\libidx{sio}{readfixed4} -\libidx{sio}{read2dot14} -\libidx{sio}{setposition} -\libidx{sio}{getposition} -\libidx{sio}{skipposition} -\libidx{sio}{readbytes} -\libidx{sio}{readbytetable} - A similar set of function as in the \type {fio} library is available in the \type -{sio} library. Here the first argument is a string. +{sio} library: \libidx {sio} {readcardinal1}, \libidx {sio} {readcardinal2}, +\libidx {sio} {readcardinal3}, \libidx {sio} {readcardinal4}, \libidx {sio} +{readcardinaltable}, \libidx {sio} {readinteger1}, \libidx {sio} {readinteger2}, +\libidx {sio} {readinteger3}, \libidx {sio} {readinteger4}, \libidx {sio} +{readintegertable}, \libidx {sio} {readfixed2}, \libidx {sio} {readfixed4}, +\libidx {sio} {read2dot14}, \libidx {sio} {setposition}, \libidx {sio} +{getposition}, \libidx {sio} {skipposition}, \libidx {sio} {readbytes} and +\libidx {sio} {readbytetable}. Here the first argument is a string instead of a +file handle. More details can be found in the previous section. \stopsubsection \startsubsection[title={Hashes conform \type {sha2}}] -\libidx{sha2}{digest256} -\libidx{sha2}{digest384} -\libidx{sha2}{digest512} - This library is a side effect of the \type {pdfe} library that needs such -helpers. The \type {digest256}, \type {digest384} and \type {digest512} functions -accept a string and return a string with the hash. +helpers. The \libidx{sha2}{digest256}, \libidx{sha2}{digest384} and +\libidx{sha2}{digest512} functions accept a string and return a string with the +hash. \stopsubsection diff --git a/doc/context/sources/general/manuals/luatex/luatex-preamble.tex b/doc/context/sources/general/manuals/luatex/luatex-preamble.tex index 1daef3c4d..829317977 100644 --- a/doc/context/sources/general/manuals/luatex/luatex-preamble.tex +++ b/doc/context/sources/general/manuals/luatex/luatex-preamble.tex @@ -87,19 +87,19 @@ When you read about nodes in the following chapters it's good to keep in mind th commands that relate to then. Here are a few: \starttabulate[|l|l|p|] -\DB command \BC node \BC explanation \NC \NR +\DB command \BC node \BC explanation \NC \NR \TB -\NC \prm {hbox} \NC \nod {hlist} \NC horizontal box \NC \NR -\NC \prm {vbox} \NC \nod {vlist} \NC vertical box with the baseline at the bottom \NC \NR -\NC \prm {vtop} \NC \nod {vlist} \NC vertical box with the baseline at the top \NC \NR -\NC \prm {hskip} \NC \nod {glue} \NC horizontal skip with optional stretch and shrink \NC \NR -\NC \prm {vskip} \NC \nod {glue} \NC vertical skip with optional stretch and shrink \NC \NR -\NC \prm {kern} \NC \nod {kern} \NC horizontal or vertical fixed skip \NC \NR -\NC \prm {discretionary} \NC \nod {disc} \NC hyphenation point (pre, post, replace) \NC \NR -\NC \prm {char} \NC \nod {glyph} \NC a character \NC \NR -\NC \prm {hrule} \NC \nod {rule} \NC a horizontal rule \NC \NR -\NC \prm {vrule} \NC \nod {rule} \NC a vertical rule \NC \NR -\NC \prm {textdir} \NC \nod {dir} \NC a change in text direction \NC \NR +\NC \prm {hbox} \NC \nod {hlist} \NC horizontal box \NC \NR +\NC \prm {vbox} \NC \nod {vlist} \NC vertical box with the baseline at the bottom \NC \NR +\NC \prm {vtop} \NC \nod {vlist} \NC vertical box with the baseline at the top \NC \NR +\NC \prm {hskip} \NC \nod {glue} \NC horizontal skip with optional stretch and shrink \NC \NR +\NC \prm {vskip} \NC \nod {glue} \NC vertical skip with optional stretch and shrink \NC \NR +\NC \prm {kern} \NC \nod {kern} \NC horizontal or vertical fixed skip \NC \NR +\NC \prm {discretionary} \NC \nod {disc} \NC hyphenation point (pre, post, replace) \NC \NR +\NC \prm {char} \NC \nod {glyph} \NC a character \NC \NR +\NC \prm {hrule} \NC \nod {rule} \NC a horizontal rule \NC \NR +\NC \prm {vrule} \NC \nod {rule} \NC a vertical rule \NC \NR +\NC \prm {textdir(ection)} \NC \nod {dir} \NC a change in text direction \NC \NR \LL \stoptabulate diff --git a/metapost/context/base/mpiv/mp-base.mpiv b/metapost/context/base/mpiv/mp-base.mpiv index 20d747a25..617855473 100644 --- a/metapost/context/base/mpiv/mp-base.mpiv +++ b/metapost/context/base/mpiv/mp-base.mpiv @@ -330,53 +330,18 @@ primarydef w dotprod z = (xpart w * xpart z + ypart w * ypart z) enddef ; -primarydef x**y = - if y = 2 : - x*x - else : - takepower y of x - fi -enddef ; - -def takepower expr y of x = - if x>0 : - mexp(y*mlog x) - elseif (x=0) and (y>0) : - 0 - else : - 1 - if y = floor y : - if y >= 0 : - for n=1 upto y : - *x - endfor - else : - for n=-1 downto y : - /x - endfor - fi - else : - hide(errmessage "Undefined power: " & decimal x & "**" & decimal y) - fi - fi -enddef ; - -% for big number systems: -% % primarydef x**y = -% if y = 1 : -% x -% elseif y = 2 : +% if y = 2 : % x*x -% elseif y = 3 : -% x*x*x % else : % takepower y of x % fi % enddef ; -% -% vardef takepower expr y of x = -% if (x=0) and (y>0) : +% +% def takepower expr y of x = +% if x>0 : +% mexp(y*mlog x) +% elseif (x=0) and (y>0) : % 0 % else : % 1 @@ -396,6 +361,51 @@ enddef ; % fi % enddef ; +% for big number systems: + +primarydef x**y = + if y = 0 : + 1 + elseif x = 0 : + 0 + elseif y < 0 : + 1/(x**-y) + elseif y = 1 : + x + elseif y = 2 : + x*x + elseif y = 3 : + x*x*x + else : + takepower y of x + fi +enddef ; + +def takepower expr y of x = + if y=0 : % isn't x**0 = 1 even if x=0 ? + 1 + elseif x=0 : + 0 + else : + if y = floor y : + 1 + if y >= 0 : + for n=1 upto y : + *x + endfor + else : + for n=-1 downto y : + /x + endfor + fi + elseif x>0 : + mexp(y*mlog x) + else : + -mexp(y*mlog -x) + fi + fi +enddef ; + vardef direction expr t of p = postcontrol t of p - precontrol t of p enddef ; diff --git a/metapost/context/base/mpiv/mp-mlib.mpiv b/metapost/context/base/mpiv/mp-mlib.mpiv index 41ec64cf2..f9f5e3877 100644 --- a/metapost/context/base/mpiv/mp-mlib.mpiv +++ b/metapost/context/base/mpiv/mp-mlib.mpiv @@ -407,15 +407,15 @@ vardef installlabel@# (expr type, x, y, offset) = enddef ; vardef mfun_labshift@#(expr p) = - (labxf@#*lrcorner p + - labyf@#*ulcorner p + - (1-labxf@#-labyf@#)*llcorner p) + (mfun_labxf@#*lrcorner p + + mfun_labyf@#*ulcorner p + + (1-mfun_labxf@#-mfun_labyf@#)*llcorner p) enddef ; vardef mfun_picshift@#(expr p) = - (labxf@#*ulcorner p + - labyf@#*lrcorner p + - (1-labxf@#-labyf@#)*urcorner p) + (mfun_labxf@#*ulcorner p + + mfun_labyf@#*lrcorner p + + (1-mfun_labxf@#-mfun_labyf@#)*urcorner p) enddef ; % we save the plain variant @@ -468,7 +468,7 @@ plain_compatibility_data := plain_compatibility_data & "save label, thelabel ;" % fi % enddef ; -newinternal anchortextexts ; anchortextexts := 1 ; % so we can disable it +newinternal anchortextexts ; anchortextexts := 0 ; % disabled by default vardef thetextext@#(expr p,z) = % interim labeloffset := textextoffset ; @@ -479,7 +479,7 @@ vardef thetextext@#(expr p,z) = elseif pair p : thetextext@#(rawtextext(ddecimal p),z) else : - if anchortextexts = 1 : + if anchortextexts > 0 : image(draw p withprescript "tx_anchor=" & ddecimal z) else : p @@ -502,6 +502,8 @@ enddef ; % formatted text +pair mfun_tt_z ; + if mfun_use_one_pass : vardef rawfmttext(text t) = @@ -526,8 +528,6 @@ if mfun_use_one_pass : else : - pair mfun_tt_z ; - vardef rawfmttext(text t) = % todo: avoid currentpicture mfun_tt_n := mfun_tt_n + 1 ; mfun_tt_c := nullpicture ; @@ -575,9 +575,13 @@ else : fi ; vardef thefmttext@#(text t) = - mfun_tt_z := origin ; + mfun_tt_z := origin ; % initialization save p ; picture p ; p := rawfmttext(t) ; - p + if anchortextexts > 0 : + image(draw p withprescript "tx_anchor=" & ddecimal mfun_tt_z) + else : + p + fi if (mfun_labtype@# >= 10) : shifted (0,ypart center p) fi @@ -633,10 +637,10 @@ vardef theoffset@#(expr z) = enddef; vardef thelabel@#(expr p,z) = - if numeric p : - thelabel@#(decimal p,z) - elseif string p : + if string p : thelabel@#(rawtextext("\definedfont[" & defaultfont & "]" & p) scaled defaultscale,z) + elseif numeric p : + thelabel@#(decimal p,z) elseif pair p : thelabel@#("(" & decimal(xpart p) & "," & decimal(ypart p) & ")",z) else : diff --git a/tex/context/base/mkii/cont-new.mkii b/tex/context/base/mkii/cont-new.mkii index 603be7c3b..e68577746 100644 --- a/tex/context/base/mkii/cont-new.mkii +++ b/tex/context/base/mkii/cont-new.mkii @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2019.01.03 19:27} +\newcontextversion{2019.01.07 10:07} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/mkii/context.mkii b/tex/context/base/mkii/context.mkii index 228265904..6e45eb33b 100644 --- a/tex/context/base/mkii/context.mkii +++ b/tex/context/base/mkii/context.mkii @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2019.01.03 19:27} +\edef\contextversion{2019.01.07 10:07} %D For those who want to use this: diff --git a/tex/context/base/mkiv/anch-pgr.lua b/tex/context/base/mkiv/anch-pgr.lua index 5237eb11e..32b7c2960 100644 --- a/tex/context/base/mkiv/anch-pgr.lua +++ b/tex/context/base/mkiv/anch-pgr.lua @@ -154,7 +154,7 @@ local function flush(head,f,l,a,parent,depth) ln = new_hlist(setlink(new_rule(65536,65536*4,0),new_kern(-65536),ln)) rn = new_hlist(setlink(new_rule(65536,0,65536*4),new_kern(-65536),rn)) end - if getid(f) == localpar_code then -- we need to clean this mess + if getid(f) == localpar_code and getsubtype(f) == 0 then -- we need to clean this mess insert_after(head,f,ln) else head, f = insert_before(head,f,ln) diff --git a/tex/context/base/mkiv/anch-pos.lua b/tex/context/base/mkiv/anch-pos.lua index 3cce01b31..9438fa2a7 100644 --- a/tex/context/base/mkiv/anch-pos.lua +++ b/tex/context/base/mkiv/anch-pos.lua @@ -606,7 +606,7 @@ end local nofparagraphs = 0 -scanners.parpos = function() -- todo: relate to localpar (so this is an intermediate variant) +scanners.parpos = function() nofparagraphs = nofparagraphs + 1 texsetcount("global","c_anch_positions_paragraph",nofparagraphs) local box = getbox("strutbox") diff --git a/tex/context/base/mkiv/back-exp.lua b/tex/context/base/mkiv/back-exp.lua index 24b7b11df..c57c2e69b 100644 --- a/tex/context/base/mkiv/back-exp.lua +++ b/tex/context/base/mkiv/back-exp.lua @@ -3281,7 +3281,7 @@ local collectresults do -- too many locals otherwise last = nil currentparagraph = nil end - elseif id == localpar_code then + elseif not localparagraph and id == localpar_code and subtype == 0 then localparagraph = getattr(n,a_taggedpar) end p = n diff --git a/tex/context/base/mkiv/back-ini.lua b/tex/context/base/mkiv/back-ini.lua index 27d1fa165..3d12fe946 100644 --- a/tex/context/base/mkiv/back-ini.lua +++ b/tex/context/base/mkiv/back-ini.lua @@ -26,6 +26,8 @@ local allocate = utilities.storage.allocate local setmetatableindex = table.setmetatableindex local setaction = nodes.tasks.setaction +local texset = tex.set + local function nothing() return nil end backends.nothing = nothing @@ -60,6 +62,17 @@ backends.tables = { } setmetatableindex(backends.tables, tables backends.current = "unknown" +local lmtx_mode = nil + +local function lmtxmode() + if lmtx_mode == nil then + lmtx_mode = environment.lmtxmode and drivers and drivers.lmtxversion + end + return lmtx_mode +end + +codeinjections.lmtxmode = lmtxmode + function backends.install(what) if type(what) == "string" then local backend = backends[what] @@ -87,7 +100,7 @@ end statistics.register("used backend", function() local bc = backends.current if bc ~= "unknown" then - local lmtx = environment.lmtxmode and drivers and drivers.lmtxversion + local lmtx = lmtxmode() local cmnt = backends[bc].comment or "no comment" if lmtx then return format("lmtx version %0.2f, %s (%s)",lmtx,bc,cmnt) @@ -138,3 +151,33 @@ backends.included = included function backends.timestamp() return os.date("%Y-%m-%dT%X") .. os.timezone(true) end + +-- Also here: + +local paper_width = 0 +local paper_height = 0 + +function codeinjections.setpagedimensions(paperwidth,paperheight) + if paperwidth then + paper_width = paperwidth + end + if paperheight then + paper_height = paperheight + end + if not lmtxmode() then + texset("global","pageheight",paper_height) + texset("global","pagewidth", paper_width) + end + return paper_width, paper_height +end + +function codeinjections.getpagedimensions() + return paper_width, paper_height +end + +interfaces.implement { + name = "shipoutoffset", + actions = function() + context(lmtxmode() and "0pt" or "-1in") -- the old tex offset + end +} diff --git a/tex/context/base/mkiv/back-ini.mkiv b/tex/context/base/mkiv/back-ini.mkiv index c7a62f078..42af1165a 100644 --- a/tex/context/base/mkiv/back-ini.mkiv +++ b/tex/context/base/mkiv/back-ini.mkiv @@ -16,11 +16,21 @@ \writestatus{loading}{ConTeXt Backend Macros / Initialization} +%D The exact page model depends on the backend so we just define some +%D variables that are used. A helper at the \LUA\ end will synchronize +%D with the internal variables. We store these in the format. + +% \newdimen\backendpageheight +% \newdimen\backendpagewidth +% \newdimen\backendinchoffset \backendinchoffset=1in + +%D Now we load the \LUA\ code: + \registerctxluafile{back-ini}{} \registerctxluafile{back-res}{} -%D We currently have a curious mix between tex and lua backend -%D handling but eventually most will move to lua. +%D We currently have a curious mix between tex and lua backend handling but +%D eventually most will move to \LUA. \unprotect @@ -28,23 +38,21 @@ \ifdefined\everylastbackendshipout \else \newtoks\everylastbackendshipout \fi \ifdefined\everybackendlastinshipout \else \newtoks\everybackendlastinshipout \fi % e.g. finalize via latelua -%D Right from the start \CONTEXT\ had a backend system based on -%D runtime pluggable code. As most backend issues involved specials -%D and since postprocessors had not that much in common, we ended up -%D with a system where we could switch backend as well as output code -%D for multiple backends at the same time. +%D Right from the start \CONTEXT\ had a backend system based on runtime pluggable +%D code. As most backend issues involved specials and since postprocessors had not +%D that much in common, we ended up with a system where we could switch backend as +%D well as output code for multiple backends at the same time. %D -%D Because \LUATEX\ has the backend built in, and since some backend -%D issues have been moved to the frontend I decided to provide new -%D backend code for \MKIV, starting with what was actually used. +%D Because \LUATEX\ has the backend built in, and since some backend issues have +%D been moved to the frontend I decided to provide new backend code for \MKIV, +%D starting with what was actually used. %D -%D At this moment \DVI\ is no longer used for advanced document -%D output and we therefore dropped support for this format. Future -%D versions might support more backends again, but this has a low -%D priority. +%D At this moment \DVI\ is no longer used for advanced document output and we +%D therefore dropped support for this format. Future versions might support more +%D backends again, but this has a low priority. %D -%D Not everything here makes sense and the content of this file will -%D definitely change (or even go away). +%D Not everything here makes sense and the content of this file will definitely +%D change (or even go away). \let \dostartrotation \gobbleoneargument \let \dostoprotation \donothing @@ -57,25 +65,23 @@ %D \macros %D {back_ovalbox} %D -%D When we look at the implementation, this is a complicated -%D one. There are seven arguments. +%D When we look at the implementation, this is a complicated one. There are seven +%D arguments. %D %D \starttyping %D \back_ovalbox {w} {h} {d} {linewidth} {radius} {stroke} {fill} {variant} %D \stoptyping %D -%D This command has to return a \type{\vbox} which can be used -%D to lay over another one (with text). The radius is in -%D degrees, the stroke and fill are~\type{1} (true) of~\type{0} -%D (false). +%D This command has to return a \type {\vbox} which can be used to lay over another +%D one (with text). The radius is in degrees, the stroke and fill are~\type {1} +%D (true) of~\type {0} (false). \let\back_ovalbox \gobbleeightarguments %D \macros %D {dostartclipping,dostopclipping} %D -%D Clipping is implemented in such a way that an arbitrary code -%D can be fed. +%D Clipping is implemented in such a way that an arbitrary code can be fed. %D %D \starttyping %D \dostartclipping {pathname} {width} {height} @@ -88,9 +94,8 @@ %D \macros %D {jobsuffix} %D -%D By default, \TEX\ produces \DVI\ files which can be -%D converted to other filetypes. Sometimes it is handy to -%D know what the target file will be. In other driver +%D By default, \TEX\ produces \DVI\ files which can be converted to other filetypes. +%D Sometimes it is handy to know what the target file will be. In other driver %D modules we wil set \type {\jobsuffix} to \type {pdf}. %D Backend configuration: diff --git a/tex/context/base/mkiv/back-pdf.mkiv b/tex/context/base/mkiv/back-pdf.mkiv index a9a74cae4..c523d30b7 100644 --- a/tex/context/base/mkiv/back-pdf.mkiv +++ b/tex/context/base/mkiv/back-pdf.mkiv @@ -66,7 +66,13 @@ %D %D Here we initialize some internal quantities. We also protect them. -\outputmode\plusone \let\outputmode\relax \newcount\outputmode \outputmode\plusone +\ifdefined\outputmode + \outputmode\plusone + \let\outputmode\relax + \newcount\outputmode + \outputmode\plusone + \let\normaloutputmode\outputmode +\fi %D Because we do a lot in \LUA\ and don't want interferences, we nil most of the %D \PDFTEX\ primitives. Of course one can always use the \type {\pdfvariable}, diff --git a/tex/context/base/mkiv/cont-new.mkiv b/tex/context/base/mkiv/cont-new.mkiv index cf4113e3d..5b487174a 100644 --- a/tex/context/base/mkiv/cont-new.mkiv +++ b/tex/context/base/mkiv/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2019.01.03 19:27} +\newcontextversion{2019.01.07 10:07} %D This file is loaded at runtime, thereby providing an excellent place for %D hacks, patches, extensions and new features. diff --git a/tex/context/base/mkiv/context.mkiv b/tex/context/base/mkiv/context.mkiv index 4ec1d9d56..a72b78c15 100644 --- a/tex/context/base/mkiv/context.mkiv +++ b/tex/context/base/mkiv/context.mkiv @@ -42,7 +42,7 @@ %D has to match \type {YYYY.MM.DD HH:MM} format. \edef\contextformat {\jobname} -\edef\contextversion{2019.01.03 19:27} +\edef\contextversion{2019.01.07 10:07} \edef\contextkind {beta} %D For those who want to use this: diff --git a/tex/context/base/mkiv/core-sys.lua b/tex/context/base/mkiv/core-sys.lua index 26229235b..4078ab8a8 100644 --- a/tex/context/base/mkiv/core-sys.lua +++ b/tex/context/base/mkiv/core-sys.lua @@ -73,13 +73,13 @@ implement { name = "outputfilename", actions = function() context(environme statistics.register("result saved in file", function() -- suffix will be fetched from backend local outputfilename = environment.outputfilename or environment.jobname or tex.jobname or "<unset>" - if (tex.pdfoutput or tex.outputmode) > 0 then + -- if (tex.pdfoutput or tex.outputmode) > 0 then return format("%s.%s, compresslevel %s, objectcompresslevel %s",outputfilename,"pdf", lpdf.getcompression() ) - else - return format("%s.%s",outputfilename,"dvi") -- hard to imagine - end + -- else + -- return format("%s.%s",outputfilename,"dvi") -- hard to imagine + -- end end) implement { diff --git a/tex/context/base/mkiv/font-chk.lua b/tex/context/base/mkiv/font-chk.lua index 0e4adf87e..ab145ce4d 100644 --- a/tex/context/base/mkiv/font-chk.lua +++ b/tex/context/base/mkiv/font-chk.lua @@ -67,12 +67,9 @@ local hpack_node = node.hpack local nuts = nodes.nuts local tonut = nuts.tonut -local getfont = nuts.getfont -local getchar = nuts.getchar - +local isglyph = nuts.isglyph local setchar = nuts.setchar ------ traverse_id = nuts.traverse_id local nextglyph = nuts.traversers.glyph local remove_node = nuts.remove @@ -296,7 +293,7 @@ checkers.placeholder = placeholder function checkers.missing(head) local lastfont, characters, found = nil, nil, nil - for n, font, char in nextglyph, head do -- faster than while loop so we delay removal + for n, char, font in nextglyph, head do -- faster than while loop so we delay removal if font ~= lastfont then characters = fontcharacters[font] lastfont = font @@ -325,7 +322,8 @@ function checkers.missing(head) elseif action == "replace" then for i=1,#found do local node = found[i] - local kind, char = placeholder(getfont(node),getchar(node)) + local char, font = isglyph(node) + local kind, char = placeholder(font,char) if kind == "node" then insert_node_after(head,node,tonut(char)) head = remove_node(head,node,true) diff --git a/tex/context/base/mkiv/font-col.lua b/tex/context/base/mkiv/font-col.lua index ae6399525..d197c7c85 100644 --- a/tex/context/base/mkiv/font-col.lua +++ b/tex/context/base/mkiv/font-col.lua @@ -20,9 +20,6 @@ local formatters = string.formatters local nuts = nodes.nuts -local getfont = nuts.getfont -local getchar = nuts.getchar - local setfont = nuts.setfont ----- traverse_char = nuts.traverse_char diff --git a/tex/context/base/mkiv/font-ctx.lua b/tex/context/base/mkiv/font-ctx.lua index 87741bfad..7b8cf0d7c 100644 --- a/tex/context/base/mkiv/font-ctx.lua +++ b/tex/context/base/mkiv/font-ctx.lua @@ -79,14 +79,12 @@ local aglunicodes = nil -- delayed loading local nuts = nodes.nuts local tonut = nuts.tonut ------ traverse_char = nuts.traverse_char local nextchar = nuts.traversers.char local getattr = nuts.getattr local setattr = nuts.setattr local getprop = nuts.getprop local setprop = nuts.setprop -local getfont = nuts.getfont local setsubtype = nuts.setsubtype local texgetattribute = tex.getattribute @@ -2752,8 +2750,8 @@ do function methods.nocolor(head,font,attr) - for n in nextchar, head do - if not font or getfont(n) == font then + for n, c, f in nextchar, head do + if not font or f == font then setattr(n,a_color,unsetvalue) end end diff --git a/tex/context/base/mkiv/font-mps.lua b/tex/context/base/mkiv/font-mps.lua index 36f1e4164..6d4da9059 100644 --- a/tex/context/base/mkiv/font-mps.lua +++ b/tex/context/base/mkiv/font-mps.lua @@ -269,8 +269,6 @@ local nuts = nodes.nuts local getnext = nuts.getnext local getid = nuts.getid local getlist = nuts.getlist -local getchar = nuts.getchar -local getfont = nuts.getfont local getsubtype = nuts.getsubtype local getfield = nuts.getfield local getbox = nuts.getbox @@ -281,6 +279,7 @@ local getwidth = nuts.getwidth local getheight = nuts.getheight local getdepth = nuts.getdepth local getexpansion = nuts.getexpansion +local isglyph = nuts.isglyph local effective_glue = nuts.effective_glue @@ -358,9 +357,9 @@ function fonts.metapost.boxtomp(n,kind) horizontal = function(parent,current,xoffset,yoffset) local dx = 0 while current do - local id = getid(current) - if id == glyph_code then - local code, width = metapost.output(kind,getfont(current),getchar(current),xoffset+dx,yoffset,getexpansion(current)) + local char, id = isglyph(current) + if char then + local code, width = metapost.output(kind,id,char,xoffset+dx,yoffset,getexpansion(current)) result[#result+1] = code dx = dx + width elseif id == disc_code then diff --git a/tex/context/base/mkiv/font-nod.lua b/tex/context/base/mkiv/font-nod.lua index 561714601..f878f1e50 100644 --- a/tex/context/base/mkiv/font-nod.lua +++ b/tex/context/base/mkiv/font-nod.lua @@ -62,7 +62,6 @@ local getprev = nuts.getprev local getid = nuts.getid local getfont = nuts.getfont local getsubtype = nuts.getsubtype -local getchar = nuts.getchar local getlist = nuts.getlist local getdisc = nuts.getdisc local isglyph = nuts.isglyph @@ -80,7 +79,7 @@ local flush_node_list = nuts.flush_list local protect_glyphs = nuts.protect_glyphs local nextnode = nuts.traversers.node ------ nextglyph = nuts.traversers.glyph +local nextglyph = nuts.traversers.glyph local nodepool = nuts.pool local new_glyph = nodepool.glyph @@ -118,11 +117,11 @@ function char_tracers.collect(head,list,tag,n) n = n or 0 local ok, fn = false, nil while head do - local c, id = isglyph(head) - if c then - local f = getfont(head) - if f ~= fn then - ok, fn = false, f + local char, id = isglyph(head) + if char then + local font = id + if font ~= fn then + ok, fn = false, font end if not ok then ok = true @@ -131,8 +130,8 @@ function char_tracers.collect(head,list,tag,n) list[n][tag] = { } end local l = list[n][tag] - -- l[#l+1] = { c, f, i } - l[#l+1] = { c, f } + -- l[#l+1] = { char, font, i } + l[#l+1] = { char, font } elseif id == disc_code then -- skip -- local pre, post, replace = getdisc(head) @@ -296,47 +295,44 @@ end function step_tracers.features() -- we cannot use first_glyph here as it only finds characters with subtype < 256 local f = collection[1] - while f do - if getid(f) == glyph_code then - local tfmdata = fontidentifiers[getfont(f)] - local features = tfmdata.resources.features - local result_1 = { } - local result_2 = { } - local gpos = features and features.gpos or { } - local gsub = features and features.gsub or { } - for feature, value in table.sortedhash(tfmdata.shared.features) do - if feature == "number" or feature == "features" then - value = false - elseif type(value) == "boolean" then - if value then - value = "yes" - else - value = false - end - else - -- use value - end + for n, char, font in nextglyph, f do + local tfmdata = fontidentifiers[font] + local features = tfmdata.resources.features + local result_1 = { } + local result_2 = { } + local gpos = features and features.gpos or { } + local gsub = features and features.gsub or { } + for feature, value in table.sortedhash(tfmdata.shared.features) do + if feature == "number" or feature == "features" then + value = false + elseif type(value) == "boolean" then if value then - if gpos[feature] or gsub[feature] or feature == "language" or feature == "script" then - result_1[#result_1+1] = formatters["%s=%s"](feature,value) - else - result_2[#result_2+1] = formatters["%s=%s"](feature,value) - end + value = "yes" + else + value = false end - end - if #result_1 > 0 then - context("{\\bf[basic:} %, t{\\bf]} ",result_1) else - context("{\\bf[}no basic features{\\bf]} ") + -- use value end - if #result_2 > 0 then - context("{\\bf[extra:} %, t{\\bf]}",result_2) - else - context("{\\bf[}no extra features{\\bf]}") + if value then + if gpos[feature] or gsub[feature] or feature == "language" or feature == "script" then + result_1[#result_1+1] = formatters["%s=%s"](feature,value) + else + result_2[#result_2+1] = formatters["%s=%s"](feature,value) + end end - return end - f = getnext(f) + if #result_1 > 0 then + context("{\\bf[basic:} %, t{\\bf]} ",result_1) + else + context("{\\bf[}no basic features{\\bf]} ") + end + if #result_2 > 0 then + context("{\\bf[extra:} %, t{\\bf]}",result_2) + else + context("{\\bf[}no extra features{\\bf]}") + end + return end end @@ -348,21 +344,15 @@ end function step_tracers.font(command) local c = collection[1] - while c do - local id = getid(c) - if id == glyph_code then - local font = getfont(c) - local name = file.basename(fontproperties[font].filename or "unknown") - local size = fontparameters[font].size or 0 - if command then - context[command](font,name,size) -- size in sp - else - context("[%s: %s @ %p]",font,name,size) - end - return + for n, char, font in nextglyph, c do + local name = file.basename(fontproperties[font].filename or "unknown") + local size = fontparameters[font].size or 0 + if command then + context[command](font,name,size) -- size in sp else - c = getnext(c) + context("[%s: %s @ %p]",font,name,size) end + return end end @@ -375,9 +365,7 @@ local colors = { function step_tracers.codes(i,command,space) local c = collection[i] - local function showchar(c) - local f = getfont(c) - local c = getchar(c) + local function showchar(c,f) if command then local d = fontdescriptions[f] local d = d and d[c] @@ -393,7 +381,8 @@ function step_tracers.codes(i,command,space) context("%s:",what) for c, id in nextnode, w do if id == glyph_code then - showchar(c) + local c, f = isglyph(c) + showchar(c,f) else context("[%s]",nodecodes[id]) end @@ -404,10 +393,10 @@ function step_tracers.codes(i,command,space) end while c do - local id = getid(c) - if id == glyph_code then - showchar(c) - elseif id == dir_code or id == localpar_code then + local char, id = isglyph(c) + if char then + showchar(char,id) + elseif id == dir_code or (id == localpar_code and getsubtype(c) == 0) then context("[%s]",getdirection(c) or "?") elseif id == disc_code then local pre, post, replace = getdisc(c) @@ -499,9 +488,9 @@ local function toutf(list,result,nofresult,stopcriterium,nostrip) if list then for n, id in nextnode, tonut(list) do if id == glyph_code then - local c = getchar(n) + local c, f = isglyph(n) if c > 0 then - local fc = fontcharacters[getfont(n)] + local fc = fontcharacters[f] if fc then local fcc = fc[c] if fcc then diff --git a/tex/context/base/mkiv/font-ota.lua b/tex/context/base/mkiv/font-ota.lua index 48ec6b976..a0bf616e7 100644 --- a/tex/context/base/mkiv/font-ota.lua +++ b/tex/context/base/mkiv/font-ota.lua @@ -37,7 +37,6 @@ local getprev = nuts.getprev local getprev = nuts.getprev local getprop = nuts.getprop local setprop = nuts.setprop -local getfont = nuts.getfont local getsubtype = nuts.getsubtype local getchar = nuts.getchar local ischar = nuts.is_char diff --git a/tex/context/base/mkiv/font-ots.lua b/tex/context/base/mkiv/font-ots.lua index ae54c390e..ea126a755 100644 --- a/tex/context/base/mkiv/font-ots.lua +++ b/tex/context/base/mkiv/font-ots.lua @@ -189,7 +189,6 @@ local getattr = nuts.getattr local setattr = nuts.setattr local getprop = nuts.getprop local setprop = nuts.setprop -local getfont = nuts.getfont local getsubtype = nuts.getsubtype local setsubtype = nuts.setsubtype local getchar = nuts.getchar @@ -199,7 +198,6 @@ local setdisc = nuts.setdisc local setlink = nuts.setlink local getcomponents = nuts.getcomponents -- the original one, not yet node-aux local setcomponents = nuts.setcomponents -- the original one, not yet node-aux -local getdir = nuts.getdir local getwidth = nuts.getwidth local ischar = nuts.is_char @@ -3641,58 +3639,58 @@ local function k_run_multiple(sub,injection,last,font,attr,steps,nofsteps,datase end end -local txtdirstate, pardirstate do +local txtdirstate, pardirstate do -- this might change (no need for nxt in pardirstate) local getdirection = nuts.getdirection local lefttoright = 0 local righttoleft = 1 txtdirstate = function(start,stack,top,rlparmode) - local nxt = getnext(start) local dir, pop = getdirection(start) if pop then if top == 1 then - return nxt, 0, rlparmode + return 0, rlparmode else top = top - 1 if stack[top] == righttoleft then - return nxt, top, -1 + return top, -1 else - return nxt, top, 1 + return top, 1 end end elseif dir == lefttoright then top = top + 1 stack[top] = lefttoright - return nxt, top, 1 + return top, 1 elseif dir == righttoleft then top = top + 1 stack[top] = righttoleft - return nxt, top, -1 + return top, -1 else - return nxt, top, rlparmode + return top, rlparmode end end pardirstate = function(start) - local nxt = getnext(start) local dir = getdirection(start) if dir == lefttoright then - return nxt, 1, 1 + return 1, 1 elseif dir == righttoleft then - return nxt, -1, -1 + return -1, -1 -- for old times sake we we handle strings too elseif dir == "TLT" then - return nxt, 1, 1 + return 1, 1 elseif dir == "TRT" then - return nxt, -1, -1 + return -1, -1 else - return nxt, 0, 0 + return 0, 0 end end end +-- These are non public helpers that can change without notice! + otf.helpers = otf.helpers or { } otf.helpers.txtdirstate = txtdirstate otf.helpers.pardirstate = pardirstate @@ -3799,7 +3797,13 @@ do checkstep(head) end - local initialrl = (direction == 1 or direction == "TRT") and -1 or 0 + local initialrl = 0 + + if getid(head) == localpar_code and getsubtype(head) == 0 then + initialrl = pardirstate(start) + elseif direction == 1 or direction == "TRT" then + initialrl = -1 + end -- local done = false local datasets = otfdataset(tfmdata,font,attr) @@ -3947,9 +3951,11 @@ do elseif id == math_code then start = getnext(end_of_math(start)) elseif id == dir_code then - start, topstack, rlmode = txtdirstate(start,dirstack,topstack,rlparmode) - elseif id == localpar_code then - start, rlparmode, rlmode = pardirstate(start) + topstack, rlmode = txtdirstate(start,dirstack,topstack,rlparmode) + start = getnext(start) + -- elseif id == localpar_code then + -- rlparmode, rlmode = pardirstate(start) + -- start = getnext(start) else start = getnext(start) end @@ -4029,9 +4035,11 @@ do elseif id == math_code then start = getnext(end_of_math(start)) elseif id == dir_code then - start, topstack, rlmode = txtdirstate(start,dirstack,topstack,rlparmode) - elseif id == localpar_code then - start, rlparmode, rlmode = pardirstate(start) + topstack, rlmode = txtdirstate(start,dirstack,topstack,rlparmode) + start = getnext(start) + -- elseif id == localpar_code then + -- rlparmode, rlmode = pardirstate(start) + -- start = getnext(start) else start = getnext(start) end @@ -4138,9 +4146,11 @@ do elseif id == math_code then start = getnext(end_of_math(start)) elseif id == dir_code then - start, topstack, rlmode = txtdirstate(start,dirstack,topstack,rlparmode) - elseif id == localpar_code then - start, rlparmode, rlmode = pardirstate(start) + topstack, rlmode = txtdirstate(start,dirstack,topstack,rlparmode) + start = getnext(start) + -- elseif id == localpar_code then + -- rlparmode, rlmode = pardirstate(start) + -- start = getnext(start) else start = getnext(start) end diff --git a/tex/context/base/mkiv/font-sol.lua b/tex/context/base/mkiv/font-sol.lua index b755a7ade..20472746c 100644 --- a/tex/context/base/mkiv/font-sol.lua +++ b/tex/context/base/mkiv/font-sol.lua @@ -426,7 +426,7 @@ function splitters.split(head) -- best also pass the direction end local direction, pop = getdirection(current) r2l = not pop and direction == righttoleft - elseif id == localpar_code then + elseif id == localpar_code and getsubtype(current) == 0 then if start then flush() -- very unlikely as this starts a paragraph end diff --git a/tex/context/base/mkiv/good-ctx.lua b/tex/context/base/mkiv/good-ctx.lua index 0ab10fdfc..82ef25e29 100644 --- a/tex/context/base/mkiv/good-ctx.lua +++ b/tex/context/base/mkiv/good-ctx.lua @@ -31,10 +31,7 @@ local fontgoodies = fonts.goodies or { } local nuts = nodes.nuts local tonut = nuts.tonut -local getfont = nuts.getfont -local getchar = nuts.getchar local getattr = nuts.getattr - local nextglyph = nuts.traversers.glyph -- colorschemes @@ -147,7 +144,7 @@ function colorschemes.coloring(head) local lastattr = nil local lastcache = nil local lastscheme = nil - for n, f, char in nextglyph, head do + for n, char, f in nextglyph, head do local a = getattr(n,a_colorscheme) if a then if f ~= lastfont then diff --git a/tex/context/base/mkiv/lang-dis.lua b/tex/context/base/mkiv/lang-dis.lua index 5baaecb87..5603d1193 100644 --- a/tex/context/base/mkiv/lang-dis.lua +++ b/tex/context/base/mkiv/lang-dis.lua @@ -21,7 +21,6 @@ local setfield = nuts.setfield local getnext = nuts.getnext local getprev = nuts.getprev local getid = nuts.getid -local getfont = nuts.getfont local getattr = nuts.getattr local getsubtype = nuts.getsubtype local setsubtype = nuts.setsubtype diff --git a/tex/context/base/mkiv/lpdf-mis.lua b/tex/context/base/mkiv/lpdf-mis.lua index 4fbbbb1d0..c8071e5d7 100644 --- a/tex/context/base/mkiv/lpdf-mis.lua +++ b/tex/context/base/mkiv/lpdf-mis.lua @@ -18,7 +18,6 @@ if not modules then modules = { } end modules ['lpdf-mis'] = { local next, tostring, type = next, tostring, type local format, gsub, formatters = string.format, string.gsub, string.formatters local flattened = table.flattened -local texset, texget = tex.set, tex.get local backends, lpdf, nodes = backends, lpdf, nodes @@ -54,6 +53,8 @@ local addtonames = lpdf.addtonames local pdfgetmetadata = lpdf.getmetadata +local texset = tex.set + local variables = interfaces.variables local v_stop = variables.stop @@ -237,10 +238,12 @@ local function setupidentity() addtoinfo("ID", pdfstring(id), id) -- needed for pdf/x -- addtoinfo("ConTeXt.Version",version) - local lmtx = environment.lmtxmode and drivers and drivers.lmtxversion + -- + local lmtx = codeinjections.lmtxmode() if lmtx then addtoinfo("ConTeXt.LMTX",formatters["%0.2f"](lmtx)) end + -- addtoinfo("ConTeXt.Time",os.date("%Y-%m-%d %H:%M")) addtoinfo("ConTeXt.Jobname",jobname) addtoinfo("ConTeXt.Url","www.pragma-ade.com") @@ -395,21 +398,23 @@ local cropoffset, bleedoffset, trimoffset, artoffset = 0, 0, 0, 0 local marked = false local copies = false +local getpagedimensions getpagedimensions = function() + getpagedimensions = backends.codeinjections.getpagedimensions + return getpagedimensions() +end + function codeinjections.setupcanvas(specification) local paperheight = specification.paperheight local paperwidth = specification.paperwidth local paperdouble = specification.doublesided - if paperheight then - texset('global','pageheight',paperheight) - end - if paperwidth then - texset('global','pagewidth',paperwidth) - end + -- + paperwidth, paperheight = codeinjections.setpagedimensions(paperwidth,paperheight) + -- pagespec = specification.mode or pagespec topoffset = specification.topoffset or 0 leftoffset = specification.leftoffset or 0 - height = specification.height or texget("pageheight") - width = specification.width or texget("pagewidth") + height = specification.height or paperheight + width = specification.width or paperwidth marked = specification.print -- copies = specification.copies @@ -514,11 +519,11 @@ local function boxvalue(n) -- we could share them end local function pagespecification() - local pht = texget("pageheight") + local paperwidth, paperheight = codeinjections.getpagedimensions() local llx = leftoffset - local lly = pht + topoffset - height + local lly = paperheight + topoffset - height local urx = width - leftoffset - local ury = pht - topoffset + local ury = paperheight - topoffset -- boxes can be cached local function extrabox(WhatBox,offset,always) if offset ~= 0 or always then diff --git a/tex/context/base/mkiv/math-tag.lua b/tex/context/base/mkiv/math-tag.lua index 07998eb08..03f9e70bb 100644 --- a/tex/context/base/mkiv/math-tag.lua +++ b/tex/context/base/mkiv/math-tag.lua @@ -34,8 +34,6 @@ local setattr = nuts.setattr local getcomponents = nuts.getcomponents -- not really needed local getwidth = nuts.getwidth -local isglyph = nuts.isglyph - local getnucleus = nuts.getnucleus local getsub = nuts.getsub local getsup = nuts.getsup @@ -167,7 +165,8 @@ local fencesstack = { } -- end local function getunicode(n) -- instead of getchar - local char, font = isglyph(n) + -- local char, font = isglyph(n) -- no, we have a mathchar + local char, font = getchar(n), getfont(n) local data = fontcharacters[font][char] return data.unicode or char -- can be a table but unlikely for math characters end diff --git a/tex/context/base/mkiv/node-aux.lua b/tex/context/base/mkiv/node-aux.lua index cb969bc1d..d6a9950fe 100644 --- a/tex/context/base/mkiv/node-aux.lua +++ b/tex/context/base/mkiv/node-aux.lua @@ -32,8 +32,6 @@ local getnext = nuts.getnext local getid = nuts.getid local getsubtype = nuts.getsubtype local getlist = nuts.getlist -local getfont = nuts.getfont -local getchar = nuts.getchar local getattr = nuts.getattr local getboth = nuts.getboth local getcomponents = nuts.getcomponents @@ -196,93 +194,6 @@ nuts.setattributes = set_attributes nodes.setattributes nuts.setunsetattributes = set_unset_attributes nodes.setunsetattributes = vianuts(set_unset_attributes) nuts.unsetattributes = unset_attributes nodes.unsetattributes = vianuts(unset_attributes) --- history: --- --- local function glyph_width(a) --- local ch = chardata[getfont(a)][getchar(a)] --- return (ch and ch.width) or 0 --- end --- --- local function glyph_total(a) --- local ch = chardata[getfont(a)][getchar(a)] --- return (ch and (ch.height+ch.depth)) or 0 --- end --- --- local function non_discardable(a) -- inline --- return getid(id) < math_node -- brrrr --- end --- --- local function calculate_badness(t,s) --- if t == 0 then --- return 0 --- elseif s <= 0 then --- return INF_BAD --- else --- local r --- if t <= 7230584 then --- r = t * 297 / s --- elseif s >= 1663497 then --- r = t / floor(s / 297) --- else --- r = t --- end --- r = floor(r) --- if r > 1290 then --- return INF_BAD --- else --- return floor((r * r * r + 0x20000) / 0x40000) -- 0400000 / 01000000 --- end --- end --- end --- --- left-overs --- --- local function round_xn_over_d(x, n, d) --- local positive -- was x >= 0 --- if x >= 0 then --- positive = true --- else --- x = -x --- positive = false --- end --- local t = floor(x % 0x8000) * n -- 0100000 --- local f = floor(t / 0x8000) -- 0100000 --- local u = floor(x / 0x8000) * n + f -- 0100000 --- local v = floor(u % d) * 0x8000 + f -- 0100000 --- if floor(u / d) >= 0x8000 then -- 0100000 --- report_parbuilders('arith_error') --- else --- u = 0x8000 * floor(u / d) + floor(v / d) -- 0100000 --- end --- v = floor(v % d) --- if 2*v >= d then --- u = u + 1 --- end --- if positive then --- return u --- else --- return -u --- end --- end --- --- local function firstline(n) --- while n do --- local id = getid(n) --- if id == hlist_code then --- if getsubtype(n) == line_code then --- return n --- else --- return firstline(getlist(n)) --- end --- elseif id == vlist_code then --- return firstline(getlist(n)) --- end --- n = getnext(n) --- end --- end --- --- nodes.firstline = firstline - function nuts.firstcharacter(n,untagged) -- tagged == subtype > 255 if untagged then return first_glyph(n) @@ -296,8 +207,8 @@ end local function firstcharinbox(n) local l = getlist(getbox(n)) if l then - for g in nextglyph, l do - return getchar(g) + for g, c in nextglyph, l do + return c end end return 0 diff --git a/tex/context/base/mkiv/node-dir.lua b/tex/context/base/mkiv/node-dir.lua index 0494fd036..3f0cba67e 100644 --- a/tex/context/base/mkiv/node-dir.lua +++ b/tex/context/base/mkiv/node-dir.lua @@ -6,328 +6,61 @@ if not modules then modules = { } end modules ['node-dir'] = { license = "see context related readme files" } ---[[ -<p>In the process of cleaning up the lua variant of the parbuilder -we ran into a couple of functions (translated c macros) that were -somewhat inefficient. More convenient is to use hashes although at -the c-end still macros are used. In the process directions.h was -adapted and now has the mappings as comments. This lua file is -based on that file. -]]-- - -local allocate = utilities.storage.allocate - -local nodes = nodes - -nodes.is_mirrored = allocate { - -- TLT = false, - -- TRT = false, - -- LTL = false, - -- RTT = false, -} - -nodes.is_rotated = allocate { -- used - -- TLT = false, - -- TRT = false, - -- LTL = false, - RTT = true, ["+RTT"] = true, -} - -do - - local tlt = { - TLT = true, ["+TLT"] = true, - TRT = true, ["+TRT"] = true, - -- LTL = false, - -- RTT = false, - } - - local trt = { - TLT = true, ["+TLT"] = true, - TRT = true, ["+TRT"] = true, - -- LTL = false, - -- RTT = false, - } - - local ltl = { - -- TLT = false, - -- TRT = false, - LTL = true, ["+LTL"] = true, - RTT = true, ["+RTT"] = true, - } - - local rtt = { - -- TLT = false, - -- TRT = false, - LTL = true, ["+LTL"] = true, - RTT = true, ["+RTT"] = true, - } - - nodes.textdir_is_parallel = allocate { -- used - TLT = tlt, ["+TLT"] = tlt, -- ["-TLT"] = tlt, - TRT = trt, ["+TRT"] = trt, -- ["-TRT"] = trt, - LTL = ltl, ["+LTL"] = ltl, -- ["-LTL"] = ltl, - RTT = rtt, ["+RTT"] = rtt, -- ["-RTT"] = rtt, - } - +-- This is experimental code, so when I change it I need to check other modules +-- too. +-- +-- Local par nodes are somewhat special. They start a paragraph and then register +-- the par direction. But they can also show op mid paragraph in which case they +-- register boxes and penalties. In that case the direction should not be affected. +-- +-- We can assume that when hpack and prelinebreak filters are called, a local par +-- still sits at the head, but after a linebreak pass this node can be after the +-- leftskip (when present). + +local nodes = nodes +local nuts = nodes.nuts + +local nodecodes = nodes.nodecodes +local localpar_code = nodecodes.localpar + +local getid = nuts.getid +local getsubtype = nuts.getsubtype +local getdirection = nuts.getdirection + +local dirvalues = nodes.dirvalues +local lefttoright = dirvalues.lefttoright +local righttoleft = dirvalues.righttoleft + +local localparnewgraf_code = 0 + +local function newstack(head,direction) + local stack = { } + local top = 0 + if head and getid(head) == localpar_code and getsubtype(head) == localparnewgraf_code then + direction = getdirection(head) + end + if not direction then + direction = lefttoright + elseif direction == "TLT" then + direction = lefttoright + elseif direction == "TRT" then + direction = righttoleft + end + local function update(node) + local dir, pop = getdirection(node) + if not pop then + top = top + 1 + stack[top] = dir + return dir + elseif top == 0 then + return direction + elseif top == 1 then + top = 0 + return direction + else + top = top - 1 + return stack[top] + end + end + return direction, update end - -do - - local tlt = { - TLT = true, ["+TLT"] = true, - TRT = true, ["+TRT"] = true, - -- LTL = false, - -- RTT = false, - } - - local trt = { - TLT = true, ["+TLT"] = true, - TRT = true, ["+TRT"] = true, - -- LTL = false, - -- RTT = false, - } - - local ltl = { - -- TLT = false, - -- TRT = false, - LTL = true, ["+LTL"] = true, - RTT = true, ["+RTT"] = true, - } - - local rtt = { - -- TLT = false, - -- TRT = false, - LTL = true, ["+LTL"] = true, - RTT = true, ["+RTT"] = true, - } - - nodes.pardir_is_parallel = allocate { - TLT = tlt, ["+TLT"] = tlt, -- ["-TLT"] = tlt, - TRT = trt, ["+TRT"] = trt, -- ["-TRT"] = trt, - LTL = ltl, ["+LTL"] = ltl, -- ["-LTL"] = ltl, - RTT = rtt, ["+RTT"] = rtt, -- ["-RTT"] = rtt, - } - -end - -nodes.pardir_is_opposite = allocate { - TLT = { - -- TLT = false, - -- TRT = false, - -- LTL = false, - -- RTT = false, - }, - TRT = { - -- TLT = false, - -- TRT = false, - -- LTL = false, - -- RTT = false, - }, - LTL = { - -- TLT = false, - -- TRT = false, - -- LTL = false, - RTT = true, ["+RTT"] = true, - }, - RTT = { - -- TLT = false, - -- TRT = false, - LTL = true, ["+LTL"] = true, - -- RTT = false, - }, -} - -nodes.textdir_is_opposite = allocate { -- used - TLT = { - -- TLT = false, - TRT = true, ["+TRT"] = true, - -- LTL = false, - -- RTT = false, - }, - TRT= { - TLT = true, ["+TLT"] = true, - -- TRT = false, - -- LTL = false, - -- RTT = false, - }, - LTL = { - -- TLT = false, - -- TRT = false, - -- LTL = false, - -- RTT = false, - }, - RTT = { - -- TLT = false, - -- TRT = false, - -- LTL = false, - -- RTT = false, - }, -} - -nodes.glyphdir_is_opposite = allocate { - TLT = { - -- TLT = false, - -- TRT = false, - -- LTL = false, - -- RTT = false, - }, - TRT= { - -- TLT = false, - -- TRT = false, - -- LTL = false, - -- RTT = false, - }, - LTL = { - -- TLT = false, - -- TRT = false, - -- LTL = false, - -- RTT = false, - }, - RTT = { - -- TLT = false, - -- TRT = false, - -- LTL = false, - -- RTT = false, - }, -} - -nodes.pardir_is_equal = allocate { -- used - TLT = { - TLT = true, ["+TLT"] = true, - TRT = true, ["+TRT"] = true, - -- LTL = false, - -- RTT = false, - }, - TRT= { - TLT = true, ["+TLT"] = true, - TRT = true, ["+TRT"] = true, - -- LTL = false, - -- RTT = false, - }, - LTL= { - -- TLT = false, - -- TRT = false, - LTL = true, ["+LTL"] = true, - -- RTT = false, - }, - RTT= { - -- TLT = false, - -- TRT = false, - -- LTL = false, - RTT = true, ["+RTT"] = true, - }, -} - -nodes.textdir_is_equal = allocate { -- used - TLT = { - TLT = true, ["+TLT"] = true, - -- TRT = false, - -- LTL = false, - -- RTT = false, - }, - TRT= { - -- TLT = false, - TRT = true, ["+TRT"] = true, - -- LTL = false, - -- RTT = false, - }, - LTL = { - -- TLT = false, - -- TRT = false, - LTL = true, ["+LTL"] = true, - RTT = true, ["+RTT"] = true, - }, - RTT = { - -- TLT = false, - -- TRT = false, - LTL = true, ["+LTL"] = true, - RTT = true, ["+RTT"] = true, - }, -} - -nodes.glyphdir_is_equal = allocate { -- used - TLT = { - TLT = true, ["+TLT"] = true, - TRT = true, ["+TRT"] = true, - -- LTL = false, - RTT = true, ["+RTT"] = true, - }, - TRT= { - TLT = true, ["+TLT"] = true, - TRT = true, ["+TRT"] = true, - -- LTL = false, - RTT = true, ["+RTT"] = true, - }, - LTL = { - -- TLT = false, - -- TRT = false, - LTL = true, ["+LTL"] = true, - -- RTT = false, - }, - RTT = { - TLT = true, ["+TLT"] = true, - TRT = true, ["+TRT"] = true, - -- LTL = false, - RTT = true, ["+RTT"] = true, - }, -} - -nodes.partextdir_is_equal = allocate { - TLT = { - -- TLT = false, - -- TRT = false, - LTL = true, ["+LTL"] = true, - RTT = true, ["+RTT"] = true, - }, - TRT= { - -- TLT = false, - -- TRT = false, - LTL = true, ["+LTL"] = true, - RTT = true, ["+RTT"] = true, - }, - LTL = { - TLT = true, ["+TLT"] = true, - -- TRT = false, - -- LTL = false, - -- RTT = false, - }, - RTT = { - -- TLT = false, - TRT = true, ["+TRT"] = true, - -- LTL = false, - -- RTT = false, - }, -} - -nodes.textdir_is_is = allocate { - TLT = true, ["+TLT"] = true, - -- TRT = false, - -- LTL = false, - -- RTT = false, -} - -nodes.glyphdir_is_orthogonal = allocate { - TLT = true, ["+TLT"] = true, - TRT = true, ["+TRT"] = true, - LTL = true, ["+LTL"] = true, - -- RTT = false -} - -nodes.dir_is_pop = allocate { -- used - ["-TRT"] = true, - ["-TLT"] = true, - ["-LTL"] = true, - ["-RTT"] = true, -} - -nodes.dir_negation = allocate { -- used - ["-TRT"] = "+TRT", - ["-TLT"] = "+TLT", - ["-LTL"] = "+LTL", - ["-RTT"] = "+RTT", - ["+TRT"] = "-TRT", - ["+TLT"] = "-TLT", - ["+LTL"] = "-LTL", - ["+RTT"] = "-RTT", -} diff --git a/tex/context/base/mkiv/node-fin.lua b/tex/context/base/mkiv/node-fin.lua index f75c948c5..dc681d165 100644 --- a/tex/context/base/mkiv/node-fin.lua +++ b/tex/context/base/mkiv/node-fin.lua @@ -55,7 +55,6 @@ local glue_code = nodecodes.glue local rule_code = nodecodes.rule local hlist_code = nodecodes.hlist local vlist_code = nodecodes.vlist -local localpar_code = nodecodes.localpar local states = attributes.states local numbers = attributes.numbers diff --git a/tex/context/base/mkiv/node-fnt.lua b/tex/context/base/mkiv/node-fnt.lua index 5748312de..154853121 100644 --- a/tex/context/base/mkiv/node-fnt.lua +++ b/tex/context/base/mkiv/node-fnt.lua @@ -45,9 +45,7 @@ local nuts = nodes.nuts local getattr = nuts.getattr local getid = nuts.getid -local getfont = nuts.getfont local getsubtype = nuts.getsubtype -local getchar = nuts.getchar local getdisc = nuts.getdisc local getnext = nuts.getnext local getprev = nuts.getprev @@ -180,7 +178,7 @@ local function start_trace(head) while n do local char, id = isglyph(n) if char then - local font = getfont(n) + local font = id local attr = getattr(n,0) or 0 report_fonts("font %03i, dynamic %03i, glyph %C",font,attr,char) elseif id == disc_code then diff --git a/tex/context/base/mkiv/node-ltp.lua b/tex/context/base/mkiv/node-ltp.lua index 6279fac82..0d501890b 100644 --- a/tex/context/base/mkiv/node-ltp.lua +++ b/tex/context/base/mkiv/node-ltp.lua @@ -246,8 +246,6 @@ local getnext = nuts.getnext local getprev = nuts.getprev local getboth = nuts.getboth local getlist = nuts.getlist -local getfont = nuts.getfont -local getchar = nuts.getchar local getdisc = nuts.getdisc local getattr = nuts.getattr local getdisc = nuts.getdisc @@ -547,9 +545,9 @@ end) local function kern_stretch_shrink(p,d) local left = getprev(p) if left then - local char = isglyph(left) + local char, font = isglyph(left) if char then - local data = expansions[getfont(left)][char] + local data = expansions[font][char] if data then local stretch = data.stretch local shrink = data.shrink @@ -751,8 +749,8 @@ local function find_protchar_right(l,r) end local function left_pw(p) - local font = getfont(p) - local prot = chardata[font][getchar(p)].left_protruding + local char, font = isglyph(p) + local prot = chardata[font][char].left_protruding if not prot or prot == 0 then return 0 end @@ -760,8 +758,8 @@ local function left_pw(p) end local function right_pw(p) - local font = getfont(p) - local prot = chardata[font][getchar(p)].right_protruding + local char, font = isglyph(p) + local prot = chardata[font][char].right_protruding if not prot or prot == 0 then return 0 end @@ -794,7 +792,7 @@ local function add_to_width(line_break_dir,checked_expansion,s) -- split into tw size = size + wd end if checked_expansion then - local data = checked_expansion[getfont(s)] + local data = checked_expansion[id] -- id == font if data then data = data[char] if data then @@ -2023,13 +2021,15 @@ do local margin_kern_shrink = 0 if protrude_chars > 1 then if lp then - local data = expansions[getfont(lp)][getchar(lp)] + local char, font = isglyph(lp) + local data = expansions[font][char] if data then margin_kern_stretch, margin_kern_shrink = data.glyphstretch, data.glyphshrink end end if rp then - local data = expansions[getfont(lp)][getchar(lp)] + local char, font = isglyph(rp) + local data = expansions[font][char] if data then margin_kern_stretch = margin_kern_stretch + data.glyphstretch margin_kern_shrink = margin_kern_shrink + data.glyphshrink @@ -2295,11 +2295,11 @@ do active_width.size = active_width.size + wd end if checked_expansion then - local currentfont = getfont(current) - local data = checked_expansion[currentfont] + local font = id -- == font + local data = checked_expansion[font] if data then - if currentfont ~= lastfont then - fontexps = checked_expansion[currentfont] -- a bit redundant for the par line packer + if font ~= lastfont then + fontexps = checked_expansion[font] -- a bit redundant for the par line packer lastfont = currentfont end if fontexps then @@ -2572,6 +2572,7 @@ do while a do local char, id = isglyph(a) if char then + -- id == font if id ~= font_in_short_display then write(target,tex.fontidentifier(id) .. ' ') font_in_short_display = id @@ -2936,10 +2937,10 @@ do local char, id = isglyph(current) if char then if cal_expand_ratio then - local currentfont = getfont(current) - if currentfont ~= lastfont then - fontexps = checked_expansion[currentfont] -- a bit redundant for the par line packer - lastfont = currentfont + local font = id -- == font + if font ~= lastfont then + fontexps = checked_expansion[font] -- a bit redundant for the par line packer + lastfont = font end if fontexps then local expansion = fontexps[char] @@ -3108,14 +3109,13 @@ do local fontexps, lastfont for i=1,expansion_index do - local g = expansion_stack[i] - local e = 0 - local char = isglyph(g) + local g = expansion_stack[i] + local e = 0 + local char, font = isglyph(g) if char then - local currentfont = getfont(g) - if currentfont ~= lastfont then - fontexps = expansions[currentfont] - lastfont = currentfont + if font ~= lastfont then + fontexps = expansions[font] + lastfont = font end local data = fontexps[char] if trace_expansion then @@ -3165,14 +3165,13 @@ do local fontexps, lastfont for i=1,expansion_index do - local g = expansion_stack[i] - local e = 0 - local char = isglyph(g) + local g = expansion_stack[i] + local e = 0 + local char, font = isglyph(g) if char then - local currentfont = getfont(g) - if currentfont ~= lastfont then - fontexps = expansions[currentfont] - lastfont = currentfont + if font ~= lastfont then + fontexps = expansions[font] + lastfont = font end local data = fontexps[char] if trace_expansion then diff --git a/tex/context/base/mkiv/node-ref.lua b/tex/context/base/mkiv/node-ref.lua index 3a6e66779..107cadc46 100644 --- a/tex/context/base/mkiv/node-ref.lua +++ b/tex/context/base/mkiv/node-ref.lua @@ -418,8 +418,10 @@ local function inject_areas(head,attribute,make,stack,done,skip,parent,pardir,tx elseif id == dir_code then local direction, pop = getdirection(current) txtdir = not pop and direction -- we might need a stack - elseif id == localpar_code then -- only test at begin - pardir = getdirection(current) + elseif id == localpar_code then + if getsubtype(current) == 0 then + pardir = getdirection(current) + end else local r = getattr(current,attribute) if not r then diff --git a/tex/context/base/mkiv/node-rul.lua b/tex/context/base/mkiv/node-rul.lua index 54500a493..ea0e5c7a0 100644 --- a/tex/context/base/mkiv/node-rul.lua +++ b/tex/context/base/mkiv/node-rul.lua @@ -50,6 +50,8 @@ local getwidth = nuts.getwidth local setwidth = nuts.setwidth local setfield = nuts.setfield +local isglyph = nuts.isglyph + local flushlist = nuts.flush_list local effective_glue = nuts.effective_glue local insert_node_after = nuts.insert_after @@ -240,9 +242,9 @@ end local function flush_ruled(head,f,l,d,level,parent,strip) -- not that fast but acceptable for this purpose local font = nil - local id = getid(f) - if id == glyph_code then - font = getfont(f) + local char, id = isglyph(f) + if char then + font = id elseif id == hlist_code then font = getattr(f,a_runningtext) end diff --git a/tex/context/base/mkiv/node-syn.lua b/tex/context/base/mkiv/node-syn.lua index c9a7f6608..a00dc65ec 100644 --- a/tex/context/base/mkiv/node-syn.lua +++ b/tex/context/base/mkiv/node-syn.lua @@ -374,9 +374,15 @@ local function flushpostamble() enabled = false end +local getpagedimensions getpagedimensions = function() + getpagedimensions = backends.codeinjections.getpagedimensions + return getpagedimensions() +end + -- local function doaction(action,t,l,w,h,d) +-- local pagewidth, pageheight = getpagedimensions() -- local x, y = getpos() --- filehandle:write(action(t,l,x,tex.pageheight-y,w,h,d)) +-- filehandle:write(action(t,l,x,pageheight-y,w,h,d)) -- nofobjects = nofobjects + 1 -- end -- @@ -412,24 +418,27 @@ end -- generic -- -- local function doaction(t,l,w,h,d) +-- local pagewidth, pageheight = getpagedimensions() -- local x, y = getpos() --- filehandle:write(f_hlist_1(t,l,x,tex.pageheight-y,w,h,d)) +-- filehandle:write(f_hlist_1(t,l,x,pageheight-y,w,h,d)) -- nofobjects = nofobjects + 1 -- end local x_hlist do local function doaction_1(t,l,w,h,d) + local pagewidth, pageheight = getpagedimensions() local x, y = getpos() - filehandle:write(f_hlist_1(t,l,x,tex.pageheight-y,w,h,d)) + filehandle:write(f_hlist_1(t,l,x,pageheight-y,w,h,d)) nofobjects = nofobjects + 1 end -- local lastx, lasty, lastw, lasth, lastd -- -- local function doaction_2(t,l,w,h,d) + -- local pagewidth, pageheight = getpagedimensions() -- local x, y = getpos() - -- y = tex.pageheight-y + -- y = pageheight-y -- filehandle:write(f_hlist_2(t,l, -- x == lastx and "=" or x, -- y == lasty and "=" or y, @@ -446,8 +455,9 @@ local x_hlist do local lasty = false local function doaction_2(t,l,w,h,d) + local pagewidth, pageheight = getpagedimensions() local x, y = getpos() - y = tex.pageheight - y + y = pageheight - y filehandle:write(f_hlist_2(t,l,x,y == lasty and "=" or y,w,h,d)) lasty = y nofobjects = nofobjects + 1 @@ -673,10 +683,9 @@ function synctex.start() writeanchor() filehandle:write("{",nofsheets,eol) -- this seems to work: - local h = tex.pageheight - local w = tex.pagewidth + local pagewidth, pageheight = getpagedimensions() filehandle:write(z_hlist) - filehandle:write(f_vlist_1(0,0,0,h,w,h,0)) + filehandle:write(f_vlist_1(0,0,0,pageheight,pagewidth,pageheight,0)) end end end diff --git a/tex/context/base/mkiv/node-tra.lua b/tex/context/base/mkiv/node-tra.lua index 01616c2e4..e1b6927fb 100644 --- a/tex/context/base/mkiv/node-tra.lua +++ b/tex/context/base/mkiv/node-tra.lua @@ -42,7 +42,6 @@ local tonode = nuts.tonode local getnext = nuts.getnext local getprev = nuts.getprev local getid = nuts.getid -local getchar = nuts.getchar local getsubtype = nuts.getsubtype local getlist = nuts.getlist local getdisc = nuts.getdisc @@ -100,7 +99,7 @@ function nodes.handlers.checkglyphs(head,message) local t = { } local n = 0 local f = formatters["%U:%s"] - for g, font, char in nextglyph, h do + for g, char, font in nextglyph, h do n = n + 1 t[n] = f(char,getsubtype(g)) end @@ -166,7 +165,7 @@ local function tosequence(start,stop,compact) elseif id == dir_code then local d, p = getdirection(start) n = n + 1 ; t[n] = "[<" .. (p and "-" or "+") .. d .. ">]" -- todo l2r etc - elseif id == localpar_code then + elseif id == localpar_code and getsubtype(start) == 0 then n = n + 1 ; t[n] = "[<" .. getdirection(start) .. ">]" -- todo l2r etc elseif compact then n = n + 1 ; t[n] = "[]" diff --git a/tex/context/base/mkiv/page-imp.mkiv b/tex/context/base/mkiv/page-imp.mkiv index 7791d2b9a..9b3b8f4f6 100644 --- a/tex/context/base/mkiv/page-imp.mkiv +++ b/tex/context/base/mkiv/page-imp.mkiv @@ -162,8 +162,6 @@ \box\scratchbox \endgroup} -\newdimen\d_page_shipouts_offset \d_page_shipouts_offset=-1in - \def\page_shipout_box#1{\normalshipout\box#1\relax} % takes a number \def\page_shipouts_normal#1% @@ -189,9 +187,12 @@ \finalizeshipoutbox\shipoutscratchbox \fi \setbox\shipoutscratchbox\vpack - {\offinterlineskip - \vkern\d_page_shipouts_offset - \hkern\d_page_shipouts_offset + {\scratchdimen\clf_shipoutoffset\relax + \ifdim\scratchdimen=\zeropoint + \offinterlineskip + \vkern\scratchdimen + \hkern\scratchdimen + \fi \hpack {\page_otr_flush_every_stuff \page_otr_flush_special_content diff --git a/tex/context/base/mkiv/page-lay.mkiv b/tex/context/base/mkiv/page-lay.mkiv index 005910a79..02cc5aa17 100644 --- a/tex/context/base/mkiv/page-lay.mkiv +++ b/tex/context/base/mkiv/page-lay.mkiv @@ -13,19 +13,16 @@ \writestatus{loading}{ConTeXt Page Macros / Layout Specification} -%D Before you start wondering why some of the page related -%D modules skip upward or left in order to place elements, you -%D must realize that the reference point is the top left -%D corner of the main typesetting area. One reason for this -%D choice is that it suited some viewers that displayed page -%D areas. Another reason is that margins, edges and top and -%D bottom areas are kind of virtual, while the header, text -%D and footer areas normally determine the text flow. +%D Before you start wondering why some of the page related modules skip upward or +%D left in order to place elements, you must realize that the reference point is the +%D top left corner of the main typesetting area. One reason for this choice is that +%D it suited some viewers that displayed page areas. Another reason is that margins, +%D edges and top and bottom areas are kind of virtual, while the header, text and +%D footer areas normally determine the text flow. \unprotect -%D The dimensions related to layout areas are represented by -%D real dimensions. +%D The dimensions related to layout areas are represented by real dimensions. \newdimen\paperheight \paperheight = 297mm \newdimen\paperwidth \paperwidth = 210mm @@ -69,17 +66,15 @@ \newdimen\totaltextwidth -%D The next series of dimensions are complemented by left -%D and rights ones. +%D The next series of dimensions are complemented by left and rights ones. \newdimen\margindistance \newdimen\edgedistance \newdimen\marginwidth \newdimen\edgewidth -%D Because a distance does not really makes sense when there -%D is no area, we use a zero distance in case there is no -%D area. +%D Because a distance does not really makes sense when there is no area, we use a +%D zero distance in case there is no area. %D The horizontal distances are: @@ -244,16 +239,15 @@ \swapmacros\innersidetotal \outersidetotal \to \everyswapmargins -%D The papersize macros have a long history and we don't want -%D to change the commands so they keep looking a bit complex. +%D The papersize macros have a long history and we don't want to change the commands +%D so they keep looking a bit complex. %D \macros %D {definepapersize} %D -%D Before we start calculating layout dimensions, we will -%D first take care of paper sizes. The first argument can be -%D either an assignment (for defaults) or an identifier, in -%D which case the second argument is an assignment. +%D Before we start calculating layout dimensions, we will first take care of paper +%D sizes. The first argument can be either an assignment (for defaults) or an +%D identifier, in which case the second argument is an assignment. %D %D \showsetup{definepapersize} %D @@ -281,8 +275,8 @@ %D \macros %D {setuppaper,setuppapersize} %D -%D When setting up the papersize on which to typeset and -%D print, we can also determine some more characteristics. +%D When setting up the papersize on which to typeset and print, we can also +%D determine some more characteristics. %D %D \showsetup{setuppapersize} %D @@ -335,9 +329,8 @@ \def\v_page_target_xy {\numexpr\v_page_target_nx*\v_page_target_ny\relax} -% Normally we will not use this command directly but for now it -% works out okay. In the future we might use more of the related -% commands. +%D Normally we will not use this command directly but for now it works out okay. In +%D the future we might use more of the related commands. \setuplayouttarget [% these are rather special @@ -1175,12 +1168,9 @@ {\freezetextwidth \page_otr_command_set_hsize} -% The next few are better off in page-ini.mkiv - -%D When we start at an even page, we need to swap the layout -%D differently. We cannot adapt the real page number, since -%D it is used in cross referencing. The next switch is set -%D when we start at an even page. +%D When we start at an even page, we need to swap the layout differently. We cannot +%D adapt the real page number, since it is used in cross referencing. The next +%D switch is set when we start at an even page. % #single #left #right @@ -1325,12 +1315,9 @@ %D \macros %D {startlocallayout} %D -%D These macros should be used with care. They permit local -%D layouts (as used in fitting pages, see \type {page-app.tex}). - -%D This is kind of obsolete now that we have \type -%D {\definelayout}, so this hack will disappear in future -%D versions. +%D These macros should be used with care. They permit local layouts (as used in +%D fitting pages, see \type {page-app.tex}). This is kind of obsolete now that we +%D have \type {\definelayout}, so this hack will disappear in future versions. \unexpanded\def\startlocallayout {\globalpushmacro\page_paper_restore @@ -1365,19 +1352,16 @@ \glet\page_grids_add_to_one\gobbleoneargument \glet\page_grids_add_to_mix\gobbleoneargument -%D The default dimensions are quite old and will not change. -%D The funny fractions were introduced when we went from fixed -%D dimensions to relative ones. Since \CONTEXT\ is a dutch -%D package, the dimensions are based on the metric system. The -%D asymmetrical layout is kind of handy for short -%D quick||and||dirty stapled documents. +%D The default dimensions are quite old and will not change. The funny fractions +%D were introduced when we went from fixed dimensions to relative ones. Since +%D \CONTEXT\ is a dutch package, the dimensions are based on the metric system. The +%D asymmetrical layout is kind of handy for short quick||and||dirty stapled +%D documents. %D -%D Although valid, it is not a real good idea to use -%D dimensions based on the \type {em} unit. First of all, -%D since there are no fonts loaded yet, this dimension makes -%D no sense, and second, you would loose track of values, -%D since they could change while going to a new page, -%D depending on the current font setting. +%D Although valid, it is not a real good idea to use dimensions based on the \type +%D {em} unit. First of all, since there are no fonts loaded yet, this dimension +%D makes no sense, and second, you would loose track of values, since they could +%D change while going to a new page, depending on the current font setting. \setuplayout [ \c!topspace=.08417508418\paperheight, % 2.5cm @@ -1433,8 +1417,8 @@ \c!columns=\plusone, \c!columndistance=\zeropoint] -%D First we define a whole range of (DIN) papersizes, -%D of which the A-series makes most sense. We enable checking. +%D First we define a whole range of (DIN) papersizes, of which the A-series makes +%D most sense. We enable checking. \definepapersize [A0] [\c!width=841mm,\c!height=1189mm] \definepapersize [A1] [\c!width=594mm,\c!height=841mm] @@ -1475,18 +1459,17 @@ \definepapersize [C9] [\c!width=40mm,\c!height=57mm] \definepapersize [C10] [\c!width=28mm,\c!height=40mm] -%D Per August 2004 the rounding of some (seldom used) sizes -%D were corrected top the latest DIN specifications. Peter -%D Rolf came up with these and a few more missing sizes. -%D Watch out: spaces and slashes! +%D Per August 2004 the rounding of some (seldom used) sizes were corrected top the +%D latest DIN specifications. Peter Rolf came up with these and a few more missing +%D sizes. Watch out: spaces and slashes! \definepapersize [4 A0] [\c!width=1682mm,\c!height=2378mm] \definepapersize [2 A0] [\c!width=1189mm,\c!height=1682mm] \definepapersize [C6/C5] [\c!width=114mm,\c!height=229mm] -%D Because there are no standardized screen sizes, we define -%D a bunch of sizes with $4:3$ ratios. The \type {S6} size is -%D nearly as wide as a sheet of \type {A4} paper. +%D Because there are no standardized screen sizes, we define a bunch of sizes with +%D $4:3$ ratios. The \type {S6} size is nearly as wide as a sheet of \type {A4} +%D paper. \definepapersize [S3] [\c!width=300pt,\c!height=225pt] \definepapersize [S4] [\c!width=400pt,\c!height=300pt] @@ -1507,15 +1490,13 @@ \definepapersize [S55] [\c!width=500pt,\c!height=500pt] \definepapersize [S66] [\c!width=600pt,\c!height=600pt] -%D One may wonder if \TEX\ should be used for typesetting -%D \CDROM\ covers, but it does not hurt to have the paper size -%D ready. +%D One may wonder if \TEX\ should be used for typesetting \CDROM\ covers, but it +%D does not hurt to have the paper size ready. \definepapersize [CD] [\c!width=120mm,\c!height=120mm] -%D The next series is for our English speaking friends who -%D decided to stick to non metric values. Thanks to Nelson -%D Beebe for completing the inch based list. +%D The next series is for our English speaking friends who decided to stick to non +%D metric values. Thanks to Nelson Beebe for completing the inch based list. \definepapersize [letter] [\c!width=8.5in,\c!height=11in] \definepapersize [ledger] [\c!width=11in,\c!height=17in] @@ -1571,9 +1552,9 @@ \definepapersize [business] [\c!width=85mm,\c!height=55mm] \definepapersize [businessUS] [\c!width=3.5in,\c!height=2in] -%D We can now default to a reasonable size. We match the print -%D paper size with the typeset paper size. This setting should -%D come after the first layout specification (already done). +%D We can now default to a reasonable size. We match the print paper size with the +%D typeset paper size. This setting should come after the first layout specification +%D (already done). % \definepapersize % [\v!default] diff --git a/tex/context/base/mkiv/page-sid.mkiv b/tex/context/base/mkiv/page-sid.mkiv index afaf18231..803381244 100644 --- a/tex/context/base/mkiv/page-sid.mkiv +++ b/tex/context/base/mkiv/page-sid.mkiv @@ -561,11 +561,19 @@ \page_sides_inject_dummy_line_normal \fi \par + % on an empty page we have topskip, say 12pt \ignoreparskip + % this can be 18.5pt \kern-\dimexpr\lineheight+\strutdp\relax + % so we can actually have a -2.5pt skip on top \ignoreparskip \blank[\v!samepage] - \blank[\v!disable]} + \blank[\v!disable] + % now say we are negative now + \ifdim\pagetotal<\zeropoint + % then we're at the top of the page ... quite messy .. i really need to + % make the page builder a bit more flexible .. should we do something now? + \fi} %D Checkers: @@ -706,12 +714,9 @@ \def\page_sides_analyse_space {\global\settrue\c_page_sides_flag -\ifdim\pagegoal=\maxdimen - \pagegoal\textheight -\fi -\ifdim\pagetotal<\zeropoint - \pagetotal\textheight -\fi +% \ifdim\pagegoal=\maxdimen +% \pagegoal\textheight % maybe +% \fi \global\d_page_sides_page_total \pagetotal % global \ifnum\c_page_sides_float_type<\plusfour \global\d_page_sides_width \zeropoint diff --git a/tex/context/base/mkiv/scrp-cjk.lua b/tex/context/base/mkiv/scrp-cjk.lua index ad63c1452..83eecf6a3 100644 --- a/tex/context/base/mkiv/scrp-cjk.lua +++ b/tex/context/base/mkiv/scrp-cjk.lua @@ -6,13 +6,16 @@ if not modules then modules = { } end modules ['scrp-cjk'] = { license = "see context related readme files" } --- We can speed this up by preallocating nodes and copying them but the --- gain is not that large. - --- The input line endings: there is no way to distinguish between --- inline spaces and endofline turned into spaces (would not make --- sense either because otherwise a wanted space at the end of a --- line would have to be a hard coded ones. +-- We can speed this up by preallocating nodes and copying them but the gain is not +-- that large. +-- +-- If needed we can speed this up (traversers and prev next and such) but cjk +-- documents don't have that many glyphs and certainly not much font processing so +-- there not much gain in it. +-- +-- The input line endings: there is no way to distinguish between inline spaces and +-- endofline turned into spaces (would not make sense either because otherwise a +-- wanted space at the end of a line would have to be a hard coded ones. local nuts = nodes.nuts @@ -439,13 +442,16 @@ local injectors = { -- [previous] [current] local function process(head,first,last) if first ~= last then - local lastfont, previous, last = nil, "start", nil + local lastfont = nil + local previous = "start" + local last = nil while true do - local upcoming, id = getnext(first), getid(first) + local upcoming = getnext(first) + local id = getid(first) if id == glyph_code then - local a = getattr(first,a_scriptstatus) + local a = getattr(first,a_scriptstatus) local current = numbertocategory[a] - local action = injectors[previous] + local action = injectors[previous] if action then action = action[current] if action then @@ -459,12 +465,16 @@ local function process(head,first,last) end previous = current else -- glue - local p, n = getprev(first), upcoming + local p = getprev(first) + local n = upcoming if p and n then - local pid, nid = getid(p), getid(n) + local pid = getid(p) + local nid = getid(n) if pid == glyph_code and nid == glyph_code then - local pa, na = getattr(p,a_scriptstatus), getattr(n,a_scriptstatus) - local pcjk, ncjk = pa and numbertocategory[pa], na and numbertocategory[na] + local pa = getattr(p,a_scriptstatus) + local na = getattr(n,a_scriptstatus) + local pcjk = pa and numbertocategory[pa] + local ncjk = na and numbertocategory[na] if not pcjk or not ncjk or pcjk == "korean" or ncjk == "korean" or pcjk == "other" or ncjk == "other" @@ -510,8 +520,8 @@ scripts.installmethod { function scripts.decomposehangul(head) local done = false - for current in nextglyph, head do - local lead_consonant, medial_vowel, tail_consonant = decomposed(getchar(current)) + for current, char in nextglyph, head do + local lead_consonant, medial_vowel, tail_consonant = decomposed(char) if lead_consonant then setchar(current,lead_consonant) local m = copy_node(current) @@ -694,13 +704,16 @@ local injectors = { -- [previous] [current] local function process(head,first,last) if first ~= last then - local lastfont, previous, last = nil, "start", nil + local lastfont = nil + local previous = "start" + local last = nil while true do - local upcoming, id = getnext(first), getid(first) + local upcoming = getnext(first) + local id = getid(first) if id == glyph_code then - local a = getattr(first,a_scriptstatus) + local a = getattr(first,a_scriptstatus) local current = numbertocategory[a] - local action = injectors[previous] + local action = injectors[previous] if action then action = action[current] if action then @@ -714,12 +727,16 @@ local function process(head,first,last) end previous = current else -- glue - local p, n = getprev(first), upcoming + local p = getprev(first) + local n = upcoming if p and n then - local pid, nid = getid(p), getid(n) + local pid = getid(p) + local nid = getid(n) if pid == glyph_code and nid == glyph_code then - local pa, na = getattr(p,a_scriptstatus), getattr(n,a_scriptstatus) - local pcjk, ncjk = pa and numbertocategory[pa], na and numbertocategory[na] + local pa = getattr(p,a_scriptstatus) + local na = getattr(n,a_scriptstatus) + local pcjk = pa and numbertocategory[pa] + local ncjk = na and numbertocategory[na] if not pcjk or not ncjk or pcjk == "korean" or ncjk == "korean" or pcjk == "other" or ncjk == "other" @@ -916,13 +933,16 @@ local injectors = { -- [previous] [current] local function process(head,first,last) if first ~= last then - local lastfont, previous, last = nil, "start", nil + local lastfont = nil + local previous = "start" + local last = nil while true do - local upcoming, id = getnext(first), getid(first) + local upcoming = getnext(first) + local id = getid(first) if id == glyph_code then - local a = getattr(first,a_scriptstatus) + local a = getattr(first,a_scriptstatus) local current = numbertocategory[a] - local action = injectors[previous] + local action = injectors[previous] if action then action = action[current] if action then @@ -939,12 +959,16 @@ local function process(head,first,last) -- upcoming = getnext(end_of_math(current)) -- previous = "start" else -- glue - local p, n = getprev(first), upcoming -- we should remember prev + local p = getprev(first) + local n = upcoming if p and n then - local pid, nid = getid(p), getid(n) + local pid = getid(p) + local nid = getid(n) if pid == glyph_code and nid == glyph_code then - local pa, na = getattr(p,a_scriptstatus), getattr(n,a_scriptstatus) - local pcjk, ncjk = pa and numbertocategory[pa], na and numbertocategory[na] + local pa = getattr(p,a_scriptstatus) + local na = getattr(n,a_scriptstatus) + local pcjk = pa and numbertocategory[pa] + local ncjk = na and numbertocategory[na] if not pcjk or not ncjk or pcjk == "korean" or ncjk == "korean" or pcjk == "other" or ncjk == "other" diff --git a/tex/context/base/mkiv/scrp-ini.lua b/tex/context/base/mkiv/scrp-ini.lua index 8c493650b..c9479cccb 100644 --- a/tex/context/base/mkiv/scrp-ini.lua +++ b/tex/context/base/mkiv/scrp-ini.lua @@ -495,16 +495,15 @@ function scripts.injectors.handler(head) normal_process = handler.injector end if normal_process then - -- wrong: originals are indices ! - local font = getfont(start) - if font ~= lastfont then - originals = fontdata[font].resources + -- id == font + if id ~= lastfont then + originals = fontdata[id].resources if resources then originals = resources.originals else originals = nil -- can't happen end - lastfont = font + lastfont = id end if originals and type(originals) == "number" then char = originals[char] or char @@ -889,7 +888,7 @@ setmetatableindex(cache_nop,function(t,k) local v = { } t[k] = v return v end) -- playing nice function autofontfeature.handler(head) - for n, font, char in nextchar, head do + for n, char, font in nextchar, head do -- if getattr(n,a_scriptinjection) then -- -- already tagged by script feature, maybe some day adapt -- else diff --git a/tex/context/base/mkiv/spac-chr.lua b/tex/context/base/mkiv/spac-chr.lua index 70f03c187..23cf9741b 100644 --- a/tex/context/base/mkiv/spac-chr.lua +++ b/tex/context/base/mkiv/spac-chr.lua @@ -35,7 +35,6 @@ local getlang = nuts.getlang local setchar = nuts.setchar local setattrlist = nuts.setattrlist local getfont = nuts.getfont -local getchar = nuts.getchar local setsubtype = nuts.setsubtype local setdisc = nuts.setdisc local isglyph = nuts.isglyph @@ -149,7 +148,7 @@ end function characters.replacenbspaces(head) local wipe = false - for current, font, char in nextglyph, head do -- can be anytime so no traverse_char + for current, char, font in nextglyph, head do -- can be anytime so no traverse_char if char == 0x00A0 then if wipe then head = remove_node(h,current,true) @@ -188,11 +187,11 @@ local methods = { [0x001F] = function(head,current) -- kind of special local next = getnext(current) if next then - local char = isglyph(next) + local char, font = isglyph(next) if char then head, current = remove_node(head,current,true) if not is_punctuation[char] then - local p = fontparameters[getfont(next)] + local p = fontparameters[font] head, current = insert_node_before(head,current,new_glue(p.space,p.space_stretch,p.space_shrink)) end end diff --git a/tex/context/base/mkiv/spac-ver.lua b/tex/context/base/mkiv/spac-ver.lua index 91d69a1e1..07a58ae47 100644 --- a/tex/context/base/mkiv/spac-ver.lua +++ b/tex/context/base/mkiv/spac-ver.lua @@ -290,7 +290,7 @@ end local function validvbox(parentid,list) if parentid == hlist_code then local id = getid(list) - if id == localpar_code then -- check for initial par subtype + if id == localpar_code and getsubtype(list) == 0 then list = getnext(list) if not next then return nil @@ -326,7 +326,7 @@ local function already_done(parentid,list,a_snapmethod) -- todo: done when only -- problem: any snapped vbox ends up in a line if list and parentid == hlist_code then local id = getid(list) - if id == localpar_code then -- check for initial par subtype + if id == localpar_code and getsubtype(list) == 0 then list = getnext(list) if not list then return false diff --git a/tex/context/base/mkiv/status-files.pdf b/tex/context/base/mkiv/status-files.pdf Binary files differindex 45dffcfaa..b9333c951 100644 --- a/tex/context/base/mkiv/status-files.pdf +++ b/tex/context/base/mkiv/status-files.pdf diff --git a/tex/context/base/mkiv/status-lua.pdf b/tex/context/base/mkiv/status-lua.pdf Binary files differindex de9be122c..30c70d1bb 100644 --- a/tex/context/base/mkiv/status-lua.pdf +++ b/tex/context/base/mkiv/status-lua.pdf diff --git a/tex/context/base/mkiv/syst-ini.mkiv b/tex/context/base/mkiv/syst-ini.mkiv index 4e767b3ad..92591d501 100644 --- a/tex/context/base/mkiv/syst-ini.mkiv +++ b/tex/context/base/mkiv/syst-ini.mkiv @@ -1163,7 +1163,9 @@ \normalpdfcompression -\outputmode \zerocount % we generate the format in this mode +\ifdefined\outputmode + \outputmode \zerocount % we generate the format in this mode +\fi %D Basic status stuff. @@ -1198,7 +1200,7 @@ \savingvdiscards\plusone %D We only can set this one via directives (system.synctex) and we only support -%D the context variant. +%D the context variant. This will go away completely. \let\synctex\undefined \newcount\synctex \let\normalsynctex\synctex @@ -1207,10 +1209,12 @@ \voffset\zeropoint \let\voffset\relax \newdimen\voffset \let\normalvoffset\voffset \hoffset\zeropoint \let\hoffset\relax \newdimen\hoffset \let\normalhoffset\hoffset -\let\pageleftoffset \hoffset \let\normalpageleftoffset \hoffset -\let\pagerightoffset \hoffset \let\normalpagerightoffset \hoffset -\let\pagetopoffset \voffset \let\normalpagetopoffset \voffset -\let\pagebottomoffset\voffset \let\normalpagebottomoffset\voffset +\ifdefined\pageleftoffset + \let\pageleftoffset \hoffset \let\normalpageleftoffset \hoffset + \let\pagerightoffset \hoffset \let\normalpagerightoffset \hoffset + \let\pagetopoffset \voffset \let\normalpagetopoffset \voffset + \let\pagebottomoffset\voffset \let\normalpagebottomoffset\voffset +\fi %D Handy. diff --git a/tex/context/base/mkiv/trac-par.lua b/tex/context/base/mkiv/trac-par.lua index 78548afbb..d888fafeb 100644 --- a/tex/context/base/mkiv/trac-par.lua +++ b/tex/context/base/mkiv/trac-par.lua @@ -19,11 +19,11 @@ local getfield = nuts.getfield local getid = nuts.getid local getnext = nuts.getnext local getlist = nuts.getlist -local getfont = nuts.getfont -local getchar = nuts.getchar local getwidth = nuts.getwidth local getexpansion = nuts.getexpansion +local isglyph = nuts.isglyph + local nodecodes = nodes.nodecodes local hlist_code = nodecodes.hlist local vlist_code = nodecodes.vlist @@ -64,23 +64,23 @@ local function colorize(n) -- tricky: the built-in method creates dummy fonts and the last line normally has the -- original font and that one then has ex.auto set while n do - local id = getid(n) - if id == glyph_code then + local char, id = isglyph(n) + if char then local ne = getexpansion(n) if ne == 0 then if length > 0 then flush() end setnodecolor(n,"hz:zero") else - local f = getfont(n) - if f ~= font then + -- id == font + if id ~= font then if length > 0 then flush() end - local pf = parameters[f] + local pf = parameters[id] local ex = pf.expansion if ex and ex.auto then size = pf.size - font = f -- save lookups + font = id -- save lookups else size = false end @@ -101,7 +101,7 @@ local function colorize(n) end if trace_verbose then length = length + 1 - list[length] = utfchar(getchar(n)) + list[length] = utfchar(char) width = width + getwidth(n) -- no kerning yet end end @@ -110,7 +110,10 @@ local function colorize(n) if length > 0 then flush() end - colorize(getlist(n),flush) + local list = getlist(n) + if list then + colorize(list,flush) + end else -- nothing to show on kerns if length > 0 then flush() diff --git a/tex/context/base/mkiv/trac-vis.lua b/tex/context/base/mkiv/trac-vis.lua index d690bfb4e..8c7d6fef1 100644 --- a/tex/context/base/mkiv/trac-vis.lua +++ b/tex/context/base/mkiv/trac-vis.lua @@ -50,7 +50,6 @@ local getid = nuts.getid local getfont = nuts.getfont local getattr = nuts.getattr local getsubtype = nuts.getsubtype -local getchar = nuts.getchar local getbox = nuts.getbox local getlist = nuts.getlist local getleader = nuts.getleader @@ -66,6 +65,8 @@ local getdepth = nuts.getdepth local getshift = nuts.getshift local getexpansion = nuts.getexpansion +local isglyph = nuts.isglyph + local hpack_nodes = nuts.hpack local vpack_nodes = nuts.vpack local copy_list = nuts.copy_list @@ -818,7 +819,6 @@ local ruledglyph do ruledglyph = function(head,current,previous) -- wrong for vertical glyphs local wd = getwidth(current) - -- local wd = chardata[getfont(current)][getchar(current)].width if wd ~= 0 then local wd, ht, dp = getwhd(current) local next = getnext(current) @@ -838,7 +838,8 @@ local ruledglyph do new_kern(-wd) ) -- - local char = chardata[getfont(current)][getchar(current)] + local c, f = isglyph(current) + local char = chardata[f][c] if char and type(char.unicode) == "table" then -- hackery test setlistcolor(info,c_ligature) setlisttransparency(info,c_ligature_d) diff --git a/tex/context/base/mkiv/typo-bld.lua b/tex/context/base/mkiv/typo-bld.lua index 4c2f7f2a5..55d74281f 100644 --- a/tex/context/base/mkiv/typo-bld.lua +++ b/tex/context/base/mkiv/typo-bld.lua @@ -275,11 +275,21 @@ implement { name = "disableparbuilder", actions = constructors.disable } -- Here are some tracers: -local new_kern = nodes.pool.kern -local new_rule = nodes.pool.rule -local hpack = nodes.hpack +local nuts = nodes.nuts +local tonut = nodes.tonut local setcolor = nodes.tracers.colors.set local listtoutf = nodes.listtoutf +local new_kern = nuts.pool.kern +local new_rule = nuts.pool.rule +local hpack = nuts.hpack +local getheight = nuts.getheight +local getdepth = nuts.getdepth +local getdirection = nuts.getdirection +local getlist = nuts.getlist +local setwidth = nuts.setwidth +local setdirection = nuts.setdirection +local setlink = nuts.setlink +local tonode = nuts.tonode local report_hpack = logs.reporter("hpack routine") local report_vpack = logs.reporter("vpack routine") @@ -303,8 +313,9 @@ end) local report, show = false, false local function hpack_quality(how,detail,n,first,last) + n = tonut(n) if report then - local str = listtoutf(n.head,"",true,nil,true) + local str = listtoutf(getlist(n),"",true,nil,true) if last <= 0 then report_hpack("%s hbox: %s",how,str) elseif first > 0 and first < last then @@ -314,10 +325,10 @@ local function hpack_quality(how,detail,n,first,last) end end if show then - local width = 2*65536 - local height = n.height - local depth = n.depth - local dir = n.dir + local width = 2*65536 + local height = getheight(n) + local depth = getdepth(n) + local direction = getdirection(n) if height < 4*65526 then height = 4*65526 end @@ -325,12 +336,11 @@ local function hpack_quality(how,detail,n,first,last) depth = 2*65526 end local rule = new_rule(width,height,depth) - rule.dir = dir + setdirection(rule,direction) if how == "overfull" then setcolor(rule,"red") local kern = new_kern(-detail) - kern.next = rule - rule.prev = kern + setlink(kern,rule) rule = kern elseif how == "underfull" then setcolor(rule,"blue") @@ -340,9 +350,9 @@ local function hpack_quality(how,detail,n,first,last) setcolor(rule,"cyan") end rule = hpack(rule) - rule.width = 0 - rule.dir = dir - return rule + setwidth(rule,0) + setdirection(rule,direction) + return tonode(rule) -- can be a nut end end diff --git a/tex/context/base/mkiv/typo-cap.lua b/tex/context/base/mkiv/typo-cap.lua index cb92933ef..7e8003c62 100644 --- a/tex/context/base/mkiv/typo-cap.lua +++ b/tex/context/base/mkiv/typo-cap.lua @@ -27,6 +27,7 @@ local takeattr = nuts.takeattr local getfont = nuts.getfont local getsubtype = nuts.getsubtype local getchar = nuts.getchar +local isglyph = nuts.isglyph local getdisc = nuts.getdisc local setattr = nuts.setattr @@ -113,10 +114,9 @@ local categories = characters.categories -- true false true == mixed local function replacer(start,codes) - local char = getchar(start) - local dc = codes[char] + local char, fnt = isglyph(start) + local dc = codes[char] if dc then - local fnt = getfont(start) local ifc = fontchar[fnt] if type(dc) == "table" then for i=1,#dc do diff --git a/tex/context/base/mkiv/typo-chr.lua b/tex/context/base/mkiv/typo-chr.lua index c364df33c..15d14c860 100644 --- a/tex/context/base/mkiv/typo-chr.lua +++ b/tex/context/base/mkiv/typo-chr.lua @@ -175,8 +175,7 @@ local function pickup(head,tail,str) while true do local prev = first.prev if prev and prev[a_marked] == attr then - local id = prev.id - if id == localpar_code then + if prev.id == localpar_code then -- and prev.subtype == 0 break else first = prev diff --git a/tex/context/base/mkiv/typo-cln.lua b/tex/context/base/mkiv/typo-cln.lua index e5dd2271f..b9b0e7d6c 100644 --- a/tex/context/base/mkiv/typo-cln.lua +++ b/tex/context/base/mkiv/typo-cln.lua @@ -32,7 +32,6 @@ local texsetattribute = tex.setattribute local nuts = nodes.nuts -local getchar = nuts.getchar local getattr = nuts.getattr local setattr = nuts.setattr @@ -58,7 +57,7 @@ local resetter = { -- this will become an entry in char-def function cleaners.handler(head) local inline = false - for n, font, char in nextglyph, head do + for n, char, font in nextglyph, head do if resetter[char] then inline = false elseif not inline then diff --git a/tex/context/base/mkiv/typo-dha.lua b/tex/context/base/mkiv/typo-dha.lua index 8dffc79a4..c7c34d379 100644 --- a/tex/context/base/mkiv/typo-dha.lua +++ b/tex/context/base/mkiv/typo-dha.lua @@ -55,7 +55,7 @@ local getsubtype = nuts.getsubtype local getlist = nuts.getlist local getattr = nuts.getattr local getprop = nuts.getprop -local getdirection = nuts.getdir +local getdirection = nuts.getdirection local isglyph = nuts.isglyph -- or ischar local setprop = nuts.setprop @@ -331,7 +331,7 @@ local function process(start) end textdir = autodir setprop(current,"direction",true) - elseif id == localpar_code then + elseif id == localpar_code and getsubtype(current) == 0 then local direction = getdirection(current) if direction == righttoleft_code then autodir = -1 diff --git a/tex/context/base/mkiv/typo-dig.lua b/tex/context/base/mkiv/typo-dig.lua index 51ed247fe..175fc0cc7 100644 --- a/tex/context/base/mkiv/typo-dig.lua +++ b/tex/context/base/mkiv/typo-dig.lua @@ -23,10 +23,9 @@ local nuts = nodes.nuts local getnext = nuts.getnext local getprev = nuts.getprev -local getfont = nuts.getfont -local getchar = nuts.getchar local getid = nuts.getid local getwidth = nuts.getwidth +local isglyph = nuts.isglyph local takeattr = nuts.takeattr local setlink = nuts.setlink @@ -97,8 +96,7 @@ function nodes.aligned(head,start,stop,width,how) end actions[1] = function(head,start,attr) - local font = getfont(start) - local char = getchar(start) + local char, font = isglyph(start) local unic = chardata[font][char].unicode or char if charbase[unic].category == "nd" then -- ignore unic tables local oldwidth = getwidth(start) diff --git a/tex/context/base/mkiv/typo-drp.lua b/tex/context/base/mkiv/typo-drp.lua index 33c5fbdc9..9a59891e1 100644 --- a/tex/context/base/mkiv/typo-drp.lua +++ b/tex/context/base/mkiv/typo-drp.lua @@ -138,7 +138,7 @@ interfaces.implement { actions[v_default] = function(head,setting) local id = getid(head) - if id == localpar_code then + if id == localpar_code then -- and getsubtype(head) == 0 -- begin of par local first = getnext(head) local indent = false @@ -222,8 +222,7 @@ actions[v_default] = function(head,setting) -- maybe also: get all A. B. etc local next = getnext(first) if next then - for current in nextglyph, next do - local char = getchar(current) + for current, char in nextglyph, next do local kind = category(char) if kind == "po" then if method[v_last] then diff --git a/tex/context/base/mkiv/typo-dua.lua b/tex/context/base/mkiv/typo-dua.lua index f31cd9d54..c4b359745 100644 --- a/tex/context/base/mkiv/typo-dua.lua +++ b/tex/context/base/mkiv/typo-dua.lua @@ -334,7 +334,7 @@ end local function get_baselevel(head,list,size) -- todo: skip if first is object (or pass head and test for localpar) local id = getid(head) - if id == localpar_code then + if id == localpar_code and getsubtype(head) == 0 then local direction = getdirection(head) if direction == righttoleft_code or direction == "TRT" then -- for old times sake we we handle strings too return 1, righttoleft_code, true @@ -710,8 +710,8 @@ local function insert_dir_points(list,size) begindir = righttoleft_code enddir = righttoleft_code else - begindir = righttoleft_code - enddir = righttoleft_code + begindir = lefttoright_code + enddir = lefttoright_code end for i=1,size do local entry = list[i] @@ -771,7 +771,7 @@ local function apply_to_list(list,size,head,pardir) enddir = false end elseif begindir then - if id == localpar_code then + if id == localpar_code and getsubtype(current) == 0 then -- localpar should always be the 1st node local d = new_direction(begindir) setprop(d,"directions",true) diff --git a/tex/context/base/mkiv/typo-dub.lua b/tex/context/base/mkiv/typo-dub.lua index e08d96e88..1a9a91ae6 100644 --- a/tex/context/base/mkiv/typo-dub.lua +++ b/tex/context/base/mkiv/typo-dub.lua @@ -63,7 +63,7 @@ local getlist = nuts.getlist local getchar = nuts.getchar local getattr = nuts.getattr local getprop = nuts.getprop -local getdir ection = nuts.getdirection +local getdirection = nuts.getdirection local setprop = nuts.setprop local setchar = nuts.setchar @@ -405,7 +405,7 @@ end local function get_baselevel(head,list,size) -- todo: skip if first is object (or pass head and test for localpar) local id = getid(head) - if id == localpar_code then + if id == localpar_code and getsubtype(head) == 0 then local direction = getdirection(head) if direction == righttoleft_code or direction == "TRT" then -- for old times sake we we handle strings too return 1, righttoleft_code, true @@ -887,8 +887,8 @@ local function insert_dir_points(list,size) local enddir -- = nil local prev -- = nil if toggle then - begindir = righttoleft_code - enddir = righttoleft_code + begindir = lefttoright_code + enddir = lefttoright_code toggle = false else begindir = righttoleft_code @@ -932,7 +932,7 @@ local function insert_dir_points(list,size) if trace_list and n > 1 then report_directions("unbalanced list") end - last.enddir = s[n] == righttoleft_code or lefttoright_code + last.enddir = s[n] == righttoleft_code and righttoleft_code or lefttoright_code end end end @@ -984,7 +984,7 @@ local function apply_to_list(list,size,head,pardir) enddir = false end elseif begindir then - if id == localpar_code then + if id == localpar_code and getsubtype(current) == 0 then -- localpar should always be the 1st node local d = new_direction(begindir) setprop(d,"directions",true) diff --git a/tex/context/base/mkiv/typo-duc.lua b/tex/context/base/mkiv/typo-duc.lua index 29d90cd4a..597042b37 100644 --- a/tex/context/base/mkiv/typo-duc.lua +++ b/tex/context/base/mkiv/typo-duc.lua @@ -409,7 +409,7 @@ end local function get_baselevel(head,list,size,direction) if direction == lefttoright_code or direction == righttoleft_code then return direction, true - elseif getid(head) == localpar_code then + elseif getid(head) == localpar_code and getsubtype(head) == 0 then direction = getdirection(head) if direction == righttoleft_code or direction == lefttoright_code then return direction, true @@ -946,7 +946,7 @@ local function apply_to_list(list,size,head,pardir) enddir = false end elseif begindir then - if id == localpar_code then + if id == localpar_code and getsubtype(current) == 0 then -- localpar should always be the 1st node local d = new_direction(begindir) local p = properties[d] if p then p.directions = true else properties[d] = { directions = true } end diff --git a/tex/context/base/mkiv/typo-fkr.lua b/tex/context/base/mkiv/typo-fkr.lua index 7fe848ade..1fd08526c 100644 --- a/tex/context/base/mkiv/typo-fkr.lua +++ b/tex/context/base/mkiv/typo-fkr.lua @@ -9,9 +9,8 @@ if not modules then modules = { } end modules ['typo-fkr'] = { local nuts = nodes.nuts local getid = nuts.getid local getnext = nuts.getnext -local getchar = nuts.getchar -local getfont = nuts.getfont local getattr = nuts.getattr +local isglyph = nuts.isglyph local nodecodes = nodes.nodecodes local glyph_code = nodecodes.glyph @@ -36,12 +35,10 @@ function typesetters.fontkerns.handler(head) local lastchar = nil local lastdata = nil while current do - local id = getid(current) - if id == glyph_code then + local char, font = isglyph(current) + if char then local a = getattr(current,a_extrakern) if a then - local char = getchar(current) - local font = getfont(current) if font ~= lastfont then if a > 0 and lastchar then if not lastdata then diff --git a/tex/context/base/mkiv/typo-itc.lua b/tex/context/base/mkiv/typo-itc.lua index b85a2847e..6cd3caf88 100644 --- a/tex/context/base/mkiv/typo-itc.lua +++ b/tex/context/base/mkiv/typo-itc.lua @@ -32,7 +32,6 @@ local nodepool = nuts.pool local getprev = nuts.getprev local getnext = nuts.getnext local getid = nuts.getid -local getfont = nuts.getfont local getchar = nuts.getchar local getdisc = nuts.getdisc local getattr = nuts.getattr @@ -197,8 +196,7 @@ local function domath(head,current) a = a + 100 end local i = getkern(kern) - local f = getfont(glyph) - local c = getchar(glyph) + local c, f = isglyph(glyph) if getheight(next) < 1.25*exheights[f] then if i == 0 then if trace_italics then @@ -298,7 +296,7 @@ local function texthandler(head) while current do local char, id = isglyph(current) if char then - local font = getfont(current) + local font = id local data = italicsdata[font] if font ~= lastfont then if previtalic ~= 0 then @@ -383,7 +381,7 @@ local function texthandler(head) while current do local char, id = isglyph(current) if char then - local font = getfont(current) + local font = id local data = italicsdata[font] if data then local attr = forcedvariant or getattr(current,a_italics) @@ -419,7 +417,7 @@ local function texthandler(head) while current do local char, id = isglyph(current) if char then - local font = getfont(current) + local font = id local data = italicsdata[font] if data then local attr = forcedvariant or getattr(current,a_italics) diff --git a/tex/context/base/mkiv/typo-krn.lua b/tex/context/base/mkiv/typo-krn.lua index 87d89572f..c26004a49 100644 --- a/tex/context/base/mkiv/typo-krn.lua +++ b/tex/context/base/mkiv/typo-krn.lua @@ -29,6 +29,7 @@ local insert_node_before = nuts.insert_before local insert_node_after = nuts.insert_after local end_of_math = nuts.end_of_math local use_components = nuts.use_components +local copy_node = nuts.copy local getnext = nuts.getnext local getprev = nuts.getprev @@ -40,10 +41,12 @@ local getdisc = nuts.getdisc local getglue = nuts.getglue local getkern = nuts.getkern local isglyph = nuts.isglyph +local setchar = nuts.setchar local setfield = nuts.setfield local getattr = nuts.getattr local takeattr = nuts.takeattr +local setattr = nuts.setattr local setlink = nuts.setlink local setdisc = nuts.setdisc local setglue = nuts.setglue @@ -252,7 +255,7 @@ end local function inject_end(boundary,next,keeptogether,krn,ok) local tail = find_node_tail(boundary) - local char, id = getid(tail) + local char, id = isglyph(tail) if id == kern_code then if getsubtype(tail) == fontkern_code then local inject = true @@ -296,7 +299,7 @@ local function process_list(head,keeptogether,krn,font,okay) local char, id = isglyph(start) if char then if not font then - font = getfont(start) + font = id -- getfont(start) mark = markdata[font] kern = quaddata[font]*krn end @@ -349,15 +352,221 @@ local function closest_bound(b,get) while b do if not getattr(b,a_kerns) then break - elseif getid(b) == glyph_code then - return b, getfont(b) else - b = get(b) + local c, f = isglyph(b) + if c then + return b, f + else + b = get(b) + end end end end end +-- function kerns.handler(head) +-- local start = head +-- local lastfont = nil +-- local keepligature = kerns.keepligature +-- local keeptogether = kerns.keeptogether +-- local fillup = false +-- local bound = false +-- local prev = nil +-- local previd = nil +-- local prevchar = nil +-- local prevfont = nil +-- local prevmark = nil +-- while start do +-- -- fontkerns don't get the attribute but they always sit between glyphs so +-- -- are always valid bound .. disc nodes also somtimes don't get them +-- local id = getid(start) +-- local attr = takeattr(start,a_kerns) +-- if attr and attr > 0 then +-- local krn = mapping[attr] +-- if krn == v_max then +-- krn = .25 +-- fillup = true +-- else +-- fillup = false +-- end +-- if not krn or krn == 0 then +-- bound = false +-- elseif id == glyph_code then +-- if keepligature and keepligature(start) then +-- -- keep 'm +-- else +-- -- we could use the subtype ligature but that's also a call +-- -- todo: check tounicode and use that information to split +-- head, start = use_components(head,start) +-- end +-- local char, font = isglyph(start) +-- local mark = markdata[font] +-- if not bound then +-- -- yet +-- elseif mark[char] then +-- -- skip +-- elseif previd == kern_code then +-- if getsubtype(prev) == fontkern_code then +-- local inject = true +-- if keeptogether then +-- if previd == glyph_code and keeptogether(prev,start) then +-- inject = false +-- end +-- end +-- if inject then +-- -- not yet ok, as injected kerns can be overlays (from node-inj.lua) +-- setkern(prev,getkern(prev) + quaddata[font]*krn,userkern_code) +-- end +-- end +-- elseif previd == glyph_code then +-- if prevfont == font then +-- if keeptogether and keeptogether(prev,start) then +-- -- keep 'm +-- else +-- local data = chardata[font][prevchar] +-- local kerns = data and data.kerns +-- local kern = (kerns and kerns[char] or 0) + quaddata[font]*krn +-- insert_node_before(head,start,kern_injector(fillup,kern)) +-- end +-- else +-- insert_node_before(head,start,kern_injector(fillup,quaddata[font]*krn)) +-- end +-- end +-- prev = start +-- prevchar = char +-- prevfont = font +-- prevmark = mark +-- previd = id +-- bound = true +-- elseif id == disc_code then +-- local prev, next, pglyph, nglyph -- delayed till needed +-- local subtype = getsubtype(start) +-- -- if subtype == automaticdisc_code then +-- -- -- this is kind of special, as we have already injected the +-- -- -- previous kern +-- -- local prev = getprev(start) +-- -- local pglyph = prev and getid(prev) == glyph_code +-- -- languages.expand(start,pglyph and prev) +-- -- -- we can have a different start now +-- -- elseif subtype ~= discretionarydisc_code then +-- -- prev = getprev(start) +-- -- pglyph = prev and getid(prev) == glyph_code +-- -- languages.expand(start,pglyph and prev) +-- -- end +-- local pre, post, replace = getdisc(start) +-- local indeed = false +-- if pre then +-- local okay = false +-- if not prev then +-- prev = getprev(start) +-- pglyph = prev and getid(prev) == glyph_code +-- end +-- if pglyph then +-- pre, okay = inject_begin(pre,prev,keeptogether,krn,okay) +-- end +-- pre, okay = process_list(pre,keeptogether,krn,false,okay) +-- if okay then +-- indeed = true +-- end +-- end +-- if post then +-- local okay = false +-- if not next then +-- next = getnext(start) +-- nglyph = next and getid(next) == glyph_code +-- end +-- if nglyph then +-- post, okay = inject_end(post,next,keeptogether,krn,okay) +-- end +-- post, okay = process_list(post,keeptogether,krn,false,okay) +-- if okay then +-- indeed = true +-- end +-- end +-- if replace then +-- local okay = false +-- if not prev then +-- prev = getprev(start) +-- pglyph = prev and getid(prev) == glyph_code +-- end +-- if pglyph then +-- replace, okay = inject_begin(replace,prev,keeptogether,krn,okay) +-- end +-- if not next then +-- next = getnext(start) +-- nglyph = next and getid(next) == glyph_code +-- end +-- if nglyph then +-- replace, okay = inject_end(replace,next,keeptogether,krn,okay) +-- end +-- replace, okay = process_list(replace,keeptogether,krn,false,okay) +-- if okay then +-- indeed = true +-- end +-- elseif prevfont then +-- replace = new_kern(quaddata[prevfont]*krn) +-- indeed = true +-- end +-- if indeed then +-- setdisc(start,pre,post,replace) +-- end +-- bound = false +-- elseif id == kern_code then +-- bound = getsubtype(start) == fontkern_code +-- prev = start +-- previd = id +-- elseif id == glue_code then +-- local subtype = getsubtype(start) +-- if subtype == userskip_code or subtype == xspaceskip_code or subtype == spaceskip_code then +-- local width, stretch, shrink, stretch_order, shrink_order = getglue(start) +-- if width > 0 then +-- local w = width + gluefactor * width * krn +-- stretch = stretch * w / width +-- shrink = shrink * w / width +-- if fillup then +-- stretch = 2 * stretch +-- shrink = 2 * shrink +-- stretch_order = 1 +-- -- shrink_order = 1 ? +-- end +-- setglue(start,w,stretch,shrink,stretch_order,shrink_order) +-- end +-- end +-- bound = false +-- elseif id == hlist_code or id == vlist_code then +-- local subtype = getsubtype(start) +-- if subtype == unknownlist_code or subtype == boxlist_code then +-- -- special case +-- local b, f = closest_bound(start,getprev) +-- if b then +-- insert_node_before(head,start,kern_injector(fillup,quaddata[f]*krn)) +-- end +-- local b, f = closest_bound(start,getnext) +-- if b then +-- insert_node_after(head,start,kern_injector(fillup,quaddata[f]*krn)) +-- end +-- end +-- bound = false +-- elseif id == math_code then +-- start = end_of_math(start) +-- bound = false +-- end +-- if start then +-- start = getnext(start) +-- end +-- elseif id == kern_code then +-- bound = getsubtype(start) == fontkern_code +-- prev = start +-- previd = id +-- start = getnext(start) +-- else +-- bound = false +-- start = getnext(start) +-- end +-- end +-- return head +-- end + function kerns.handler(head) local start = head local lastfont = nil @@ -372,10 +581,10 @@ function kerns.handler(head) local prevmark = nil while start do -- fontkerns don't get the attribute but they always sit between glyphs so - -- are always valid bound .. disc nodes also somtimes don't get them - local id = getid(start) + -- are always valid bound .. disc nodes also sometimes don't get them local attr = takeattr(start,a_kerns) if attr and attr > 0 then + local char, id = isglyph(start) local krn = mapping[attr] if krn == v_max then krn = .25 @@ -385,17 +594,34 @@ function kerns.handler(head) end if not krn or krn == 0 then bound = false - elseif id == glyph_code then + elseif char then -- id == glyph_code + local font = id -- more readable + local mark = markdata[font] if keepligature and keepligature(start) then -- keep 'm else - -- we could use the subtype ligature but that's also a call - -- todo: check tounicode and use that information to split - head, start = use_components(head,start) + -- head, start = use_components(head,start) + -- beware, these are not kerned so we mighty need a kern only pass + -- maybe some day .. anyway, one should disable ligaturing + local data = chardata[font][char] + if data then + local unicode = data.unicode -- can be cached + if type(unicode) == "table" then + char = unicode[1] + local s = start + setchar(s,char) + for i=2,#unicode do + local n = copy_node(s) + if i == 2 then + setattr(n,a_kerns,attr) -- we took away the attr + end + setchar(n,unicode[i]) + insert_node_after(head,s,n) + s = n + end + end + end end - local char = getchar(start) - local font = getfont(start) - local mark = markdata[font] if not bound then -- yet elseif mark[char] then @@ -418,6 +644,7 @@ function kerns.handler(head) if keeptogether and keeptogether(prev,start) then -- keep 'm else + -- hm, only basemode ... will go away ... local data = chardata[font][prevchar] local kerns = data and data.kerns local kern = (kerns and kerns[char] or 0) + quaddata[font]*krn @@ -431,7 +658,7 @@ function kerns.handler(head) prevchar = char prevfont = font prevmark = mark - previd = id + previd = glyph_code -- id bound = true elseif id == disc_code then local prev, next, pglyph, nglyph -- delayed till needed @@ -549,14 +776,17 @@ function kerns.handler(head) if start then start = getnext(start) end - elseif id == kern_code then - bound = getsubtype(start) == fontkern_code - prev = start - previd = id - start = getnext(start) else - bound = false - start = getnext(start) + local id = getid(start) + if id == kern_code then + bound = getsubtype(start) == fontkern_code + prev = start + previd = id + start = getnext(start) + else + bound = false + start = getnext(start) + end end end return head diff --git a/tex/context/base/mkiv/typo-pnc.lua b/tex/context/base/mkiv/typo-pnc.lua index 786fd7d3f..732970884 100644 --- a/tex/context/base/mkiv/typo-pnc.lua +++ b/tex/context/base/mkiv/typo-pnc.lua @@ -68,7 +68,7 @@ local mapping = periodkerns.mapping local factors = periodkerns.factors function periodkerns.handler(head) - for current, font, char in nextglyph, head do + for current, char, font in nextglyph, head do if char == period then local a = getattr(current,a_periodkern) if a then @@ -77,10 +77,10 @@ function periodkerns.handler(head) local prev, next = getboth(current) if prev and next and getid(prev) == glyph_code and getid(next) == glyph_code then local pchar = getchar(prev) - local pcode = categories[getchar(prev)] + local pcode = categories[pchar] if pcode == "lu" or pcode == "ll" then local nchar = getchar(next) - local ncode = categories[getchar(next)] + local ncode = categories[nchar] if ncode == "lu" or ncode == "ll" then local next2 = getnext(next) if next2 and getid(next2) == glyph_code and getchar(next2) == period then diff --git a/tex/context/base/mkiv/typo-rub.lua b/tex/context/base/mkiv/typo-rub.lua index f096d3bb4..9b3bdb9d8 100644 --- a/tex/context/base/mkiv/typo-rub.lua +++ b/tex/context/base/mkiv/typo-rub.lua @@ -63,8 +63,8 @@ local glue_code = nodecodes.glue local penalty_code = nodecodes.penalty local hlist_code = nodecodes.hlist local vlist_code = nodecodes.vlist -local whatsit_code = nodecodes.whatsit local localpar_code = nodecodes.localpar +local dir_code = nodecodes.dir local kerncodes = nodes.kerncodes local fontkern_code = kerncodes.font @@ -305,11 +305,11 @@ local function whatever(current) local c = getprev(current) while c do local id = getid(c) - if id == glue_code or id == penalty_code or id == kern_code or (id == whatsit_code and getsubtype(current,localpar_code)) then + if id == glue_code or id == penalty_code or id == kern_code then -- go on elseif id == hlist_code and getwidth(c) == 0 then -- go on - elseif id == whatsit_code or id == localpar_code then + elseif id == whatsit_code or id == localpar_code or id == dir_code then -- go on else l = false diff --git a/tex/context/base/mkiv/typo-spa.lua b/tex/context/base/mkiv/typo-spa.lua index c49897f87..78fc22964 100644 --- a/tex/context/base/mkiv/typo-spa.lua +++ b/tex/context/base/mkiv/typo-spa.lua @@ -26,7 +26,6 @@ local nuts = nodes.nuts local getnext = nuts.getnext local getprev = nuts.getprev -local getfont = nuts.getfont local takeattr = nuts.takeattr local isglyph = nuts.isglyph @@ -83,10 +82,11 @@ function spacings.handler(head) if data then local map = data.characters[char] if map then + local font = id local left = map.left local right = map.right local alternative = map.alternative - local quad = quaddata[getfont(start)] + local quad = quaddata[font] local prev = getprev(start) if left and left ~= 0 and prev then local ok = false diff --git a/tex/context/base/mkiv/typo-tal.lua b/tex/context/base/mkiv/typo-tal.lua index d9c2a51ac..8cf298329 100644 --- a/tex/context/base/mkiv/typo-tal.lua +++ b/tex/context/base/mkiv/typo-tal.lua @@ -208,7 +208,7 @@ function characteralign.handler(head,where) while current do local char, id = isglyph(current) if char then - local font = getfont(current) + local font = id --- nicer local data = fontcharacters[font][char] local unicode = data and data.unicode or char -- ignore tables if not unicode then -- type(unicode) ~= "number" @@ -232,8 +232,9 @@ function characteralign.handler(head,where) if not b_start then if sign then b_start = sign - local new = validsigns[getchar(sign)] - if char == new or not fontcharacters[getfont(sign)][new] then + local c, f = isglyph(sign) + local new = validsigns[c] + if char == new or not fontcharacters[f][new] then if trace_split then setcolor(sign,"darkyellow") end @@ -283,7 +284,7 @@ function characteralign.handler(head,where) while current do local char, id = isglyph(current) if char then - local font = getfont(current) + local font = id -- nicer -- local unicode = unicodes[font][char] local unicode = fontcharacters[font][char].unicode or char -- ignore tables if not unicode then diff --git a/tex/context/interface/mkiv/i-context.pdf b/tex/context/interface/mkiv/i-context.pdf Binary files differindex 870816228..e5740aa2c 100644 --- a/tex/context/interface/mkiv/i-context.pdf +++ b/tex/context/interface/mkiv/i-context.pdf diff --git a/tex/context/interface/mkiv/i-readme.pdf b/tex/context/interface/mkiv/i-readme.pdf Binary files differindex 5ac21feab..550aa8964 100644 --- a/tex/context/interface/mkiv/i-readme.pdf +++ b/tex/context/interface/mkiv/i-readme.pdf diff --git a/tex/generic/context/luatex/luatex-basics-nod.lua b/tex/generic/context/luatex/luatex-basics-nod.lua index 53414a009..4c9a13f9a 100644 --- a/tex/generic/context/luatex/luatex-basics-nod.lua +++ b/tex/generic/context/luatex/luatex-basics-nod.lua @@ -144,8 +144,6 @@ nodes.unset_attribute = node.unset_attribute nodes.protect_glyphs = node.protect_glyphs nodes.unprotect_glyphs = node.unprotect_glyphs ------.kerning = node.kerning ------.ligaturing = node.ligaturing nodes.mlist_to_hlist = node.mlist_to_hlist -- in generic code, at least for some time, we stay nodes, while in context @@ -167,64 +165,74 @@ nodes.tonut = tonut nuts.tonode = tonode nuts.tonut = tonut -local getfield = direct.getfield -local setfield = direct.setfield - -nuts.getfield = getfield -nuts.setfield = setfield -nuts.getnext = direct.getnext -nuts.setnext = direct.setnext -nuts.getprev = direct.getprev -nuts.setprev = direct.setprev -nuts.getboth = direct.getboth -nuts.setboth = direct.setboth -nuts.getid = direct.getid nuts.getattr = direct.get_attribute -nuts.setattr = setfield +nuts.getboth = direct.getboth +nuts.getchar = direct.getchar +nuts.getcomponents = direct.getcomponents +----.getdepth = direct.getdepth +----.getdir = direct.getdir +nuts.getdirection = direct.getdirection +nuts.getdisc = direct.getdisc +nuts.getfield = direct.getfield nuts.getfont = direct.getfont -nuts.setfont = direct.setfont +----.getheight = direct.getheight +nuts.getid = direct.getid +nuts.getkern = direct.getkern +----.getleader = direct.getleader +nuts.getlist = direct.getlist +nuts.getnext = direct.getnext +nuts.getoffsets = direct.getoffsets +nuts.getprev = direct.getprev nuts.getsubtype = direct.getsubtype -nuts.setsubtype = direct.setsubtype -nuts.getchar = direct.getchar +nuts.getwidth = direct.getwidth +nuts.setattr = direct.setfield +nuts.setboth = direct.setboth nuts.setchar = direct.setchar -nuts.getdisc = direct.getdisc +nuts.setcomponents = direct.setcomponents +----.setdepth = direct.setdepth +nuts.setdir = direct.setdir +nuts.setdirection = direct.setdirection nuts.setdisc = direct.setdisc +nuts.setfield = setfield +----.setfont = direct.setfont +----.setheight = direct.setheight +nuts.setkern = direct.setkern +----.setleader = direct.setleader nuts.setlink = direct.setlink -nuts.setsplit = direct.setsplit -nuts.getlist = direct.getlist nuts.setlist = direct.setlist -nuts.getoffsets = direct.getoffsets +nuts.setnext = direct.setnext nuts.setoffsets = direct.setoffsets +nuts.setprev = direct.setprev +nuts.setsplit = direct.setsplit +nuts.setsubtype = direct.setsubtype +nuts.setwidth = direct.setwidth -nuts.ischar = direct.is_char nuts.is_char = direct.is_char -nuts.isglyph = direct.is_glyph nuts.is_glyph = direct.is_glyph +nuts.ischar = direct.is_char +nuts.isglyph = direct.is_glyph -nuts.insert_before = direct.insert_before -nuts.insert_after = direct.insert_after -nuts.delete = direct.delete nuts.copy = direct.copy -nuts.copy_node = direct.copy nuts.copy_list = direct.copy_list -nuts.tail = direct.tail +nuts.copy_node = direct.copy +nuts.delete = direct.delete +nuts.end_of_math = direct.end_of_math +nuts.flush = direct.flush nuts.flush_list = direct.flush_list nuts.flush_node = direct.flush_node -nuts.flush = direct.flush nuts.free = direct.free -nuts.remove = direct.remove +nuts.insert_after = direct.insert_after +nuts.insert_before = direct.insert_before nuts.is_node = direct.is_node -nuts.end_of_math = direct.end_of_math +nuts.kerning = direct.kerning +nuts.ligaturing = direct.ligaturing +nuts.new = direct.new +nuts.remove = direct.remove +nuts.tail = direct.tail nuts.traverse = direct.traverse -nuts.traverse_id = direct.traverse_id nuts.traverse_char = direct.traverse_char nuts.traverse_glyph = direct.traverse_glyph -nuts.ligaturing = direct.ligaturing -nuts.kerning = direct.kerning -nuts.new = direct.new - -nuts.getprop = nuts.getattr -nuts.setprop = nuts.setattr +nuts.traverse_id = direct.traverse_id -- properties as used in the (new) injector: diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index accb0810d..e2e8dc750 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : c:/data/develop/context/sources/luatex-fonts-merged.lua -- parent file : c:/data/develop/context/sources/luatex-fonts.lua --- merge date : 01/03/19 19:27:26 +-- merge date : 01/07/19 10:07:58 do -- begin closure to overcome local limits and interference @@ -4824,60 +4824,64 @@ nodes.tonode=tonode nodes.tonut=tonut nuts.tonode=tonode nuts.tonut=tonut -local getfield=direct.getfield -local setfield=direct.setfield -nuts.getfield=getfield -nuts.setfield=setfield -nuts.getnext=direct.getnext -nuts.setnext=direct.setnext -nuts.getprev=direct.getprev -nuts.setprev=direct.setprev -nuts.getboth=direct.getboth -nuts.setboth=direct.setboth -nuts.getid=direct.getid nuts.getattr=direct.get_attribute -nuts.setattr=setfield +nuts.getboth=direct.getboth +nuts.getchar=direct.getchar +nuts.getcomponents=direct.getcomponents +nuts.getdirection=direct.getdirection +nuts.getdisc=direct.getdisc +nuts.getfield=direct.getfield nuts.getfont=direct.getfont -nuts.setfont=direct.setfont +nuts.getid=direct.getid +nuts.getkern=direct.getkern +nuts.getlist=direct.getlist +nuts.getnext=direct.getnext +nuts.getoffsets=direct.getoffsets +nuts.getprev=direct.getprev nuts.getsubtype=direct.getsubtype -nuts.setsubtype=direct.setsubtype -nuts.getchar=direct.getchar +nuts.getwidth=direct.getwidth +nuts.setattr=direct.setfield +nuts.setboth=direct.setboth nuts.setchar=direct.setchar -nuts.getdisc=direct.getdisc +nuts.setcomponents=direct.setcomponents +nuts.setdir=direct.setdir +nuts.setdirection=direct.setdirection nuts.setdisc=direct.setdisc +nuts.setfield=setfield +nuts.setkern=direct.setkern nuts.setlink=direct.setlink -nuts.setsplit=direct.setsplit -nuts.getlist=direct.getlist nuts.setlist=direct.setlist -nuts.getoffsets=direct.getoffsets +nuts.setnext=direct.setnext nuts.setoffsets=direct.setoffsets -nuts.ischar=direct.is_char +nuts.setprev=direct.setprev +nuts.setsplit=direct.setsplit +nuts.setsubtype=direct.setsubtype +nuts.setwidth=direct.setwidth nuts.is_char=direct.is_char -nuts.isglyph=direct.is_glyph nuts.is_glyph=direct.is_glyph -nuts.insert_before=direct.insert_before -nuts.insert_after=direct.insert_after -nuts.delete=direct.delete +nuts.ischar=direct.is_char +nuts.isglyph=direct.is_glyph nuts.copy=direct.copy -nuts.copy_node=direct.copy nuts.copy_list=direct.copy_list -nuts.tail=direct.tail +nuts.copy_node=direct.copy +nuts.delete=direct.delete +nuts.end_of_math=direct.end_of_math +nuts.flush=direct.flush nuts.flush_list=direct.flush_list nuts.flush_node=direct.flush_node -nuts.flush=direct.flush nuts.free=direct.free -nuts.remove=direct.remove +nuts.insert_after=direct.insert_after +nuts.insert_before=direct.insert_before nuts.is_node=direct.is_node -nuts.end_of_math=direct.end_of_math +nuts.kerning=direct.kerning +nuts.ligaturing=direct.ligaturing +nuts.new=direct.new +nuts.remove=direct.remove +nuts.tail=direct.tail nuts.traverse=direct.traverse -nuts.traverse_id=direct.traverse_id nuts.traverse_char=direct.traverse_char nuts.traverse_glyph=direct.traverse_glyph -nuts.ligaturing=direct.ligaturing -nuts.kerning=direct.kerning -nuts.new=direct.new -nuts.getprop=nuts.getattr -nuts.setprop=nuts.setattr +nuts.traverse_id=direct.traverse_id local propertydata=direct.get_properties_table() nodes.properties={ data=propertydata } direct.set_properties_mode(true,true) @@ -25082,7 +25086,6 @@ local getprev=nuts.getprev local getprev=nuts.getprev local getprop=nuts.getprop local setprop=nuts.setprop -local getfont=nuts.getfont local getsubtype=nuts.getsubtype local getchar=nuts.getchar local ischar=nuts.is_char @@ -25506,7 +25509,6 @@ local getattr=nuts.getattr local setattr=nuts.setattr local getprop=nuts.getprop local setprop=nuts.setprop -local getfont=nuts.getfont local getsubtype=nuts.getsubtype local setsubtype=nuts.setsubtype local getchar=nuts.getchar @@ -25516,7 +25518,6 @@ local setdisc=nuts.setdisc local setlink=nuts.setlink local getcomponents=nuts.getcomponents local setcomponents=nuts.setcomponents -local getdir=nuts.getdir local getwidth=nuts.getwidth local ischar=nuts.is_char local isglyph=nuts.isglyph @@ -28407,49 +28408,47 @@ local function k_run_multiple(sub,injection,last,font,attr,steps,nofsteps,datase end end end -local txtdirstate,pardirstate do +local txtdirstate,pardirstate do local getdirection=nuts.getdirection local lefttoright=0 local righttoleft=1 txtdirstate=function(start,stack,top,rlparmode) - local nxt=getnext(start) local dir,pop=getdirection(start) if pop then if top==1 then - return nxt,0,rlparmode + return 0,rlparmode else top=top-1 if stack[top]==righttoleft then - return nxt,top,-1 + return top,-1 else - return nxt,top,1 + return top,1 end end elseif dir==lefttoright then top=top+1 stack[top]=lefttoright - return nxt,top,1 + return top,1 elseif dir==righttoleft then top=top+1 stack[top]=righttoleft - return nxt,top,-1 + return top,-1 else - return nxt,top,rlparmode + return top,rlparmode end end pardirstate=function(start) - local nxt=getnext(start) local dir=getdirection(start) if dir==lefttoright then - return nxt,1,1 + return 1,1 elseif dir==righttoleft then - return nxt,-1,-1 + return -1,-1 elseif dir=="TLT" then - return nxt,1,1 + return 1,1 elseif dir=="TRT" then - return nxt,-1,-1 + return -1,-1 else - return nxt,0,0 + return 0,0 end end end @@ -28498,7 +28497,12 @@ do if trace_steps then checkstep(head) end - local initialrl=(direction==1 or direction=="TRT") and -1 or 0 + local initialrl=0 + if getid(head)==localpar_code and getsubtype(head)==0 then + initialrl=pardirstate(start) + elseif direction==1 or direction=="TRT" then + initialrl=-1 + end local datasets=otfdataset(tfmdata,font,attr) local dirstack={ nil } sweephead={} @@ -28613,9 +28617,8 @@ do elseif id==math_code then start=getnext(end_of_math(start)) elseif id==dir_code then - start,topstack,rlmode=txtdirstate(start,dirstack,topstack,rlparmode) - elseif id==localpar_code then - start,rlparmode,rlmode=pardirstate(start) + topstack,rlmode=txtdirstate(start,dirstack,topstack,rlparmode) + start=getnext(start) else start=getnext(start) end @@ -28684,9 +28687,8 @@ do elseif id==math_code then start=getnext(end_of_math(start)) elseif id==dir_code then - start,topstack,rlmode=txtdirstate(start,dirstack,topstack,rlparmode) - elseif id==localpar_code then - start,rlparmode,rlmode=pardirstate(start) + topstack,rlmode=txtdirstate(start,dirstack,topstack,rlparmode) + start=getnext(start) else start=getnext(start) end @@ -28763,9 +28765,8 @@ do elseif id==math_code then start=getnext(end_of_math(start)) elseif id==dir_code then - start,topstack,rlmode=txtdirstate(start,dirstack,topstack,rlparmode) - elseif id==localpar_code then - start,rlparmode,rlmode=pardirstate(start) + topstack,rlmode=txtdirstate(start,dirstack,topstack,rlparmode) + start=getnext(start) else start=getnext(start) end |