diff options
Diffstat (limited to 'Master/texmf-dist/tex/luatex/chickenize')
3 files changed, 274 insertions, 59 deletions
diff --git a/Master/texmf-dist/tex/luatex/chickenize/chickenize.lua b/Master/texmf-dist/tex/luatex/chickenize/chickenize.lua index 6a2b3f648db..8043148a62d 100644 --- a/Master/texmf-dist/tex/luatex/chickenize/chickenize.lua +++ b/Master/texmf-dist/tex/luatex/chickenize/chickenize.lua @@ -8,7 +8,7 @@ -- -- EXPERIMENTAL CODE -- --- This package is copyright © 2013 Arno L. Trautmann. It may be distributed and/or +-- This package is copyright © 2015 Arno L. Trautmann. It may be distributed and/or -- modified under the conditions of the LaTeX Project Public License, either version 1.3c -- of this license or (at your option) any later version. This work has the LPPL mainten- -- ance status ‘maintained’. @@ -24,10 +24,11 @@ local nodetraverseid = node.traverse_id local nodeslide = node.slide Hhead = nodeid("hhead") -RULE = nodeid("rule") -GLUE = nodeid("glue") -WHAT = nodeid("whatsit") -COL = node.subtype("pdf_colorstack") +RULE = nodeid("rule") +GLUE = nodeid("glue") +WHAT = nodeid("whatsit") +COL = node.subtype("pdf_colorstack") +PDF_LITERAL = node.subtype("pdf_literal") GLYPH = nodeid("glyph") color_push = nodenew(WHAT,COL) color_pop = nodenew(WHAT,COL) @@ -47,7 +48,7 @@ chicken_substitutions = 0 -- value to count the substituted chickens. Makes sens local match = unicode.utf8.match chickenize_ignore_word = false chickenize_real_stuff = function(i,head) - while ((i.next.id == 37) or (i.next.id == 11) or (i.next.id == 7) or (i.next.id == 0)) do --find end of a word + while ((i.next.id == GLYPH) or (i.next.id == 11) or (i.next.id == 7) or (i.next.id == 0)) do --find end of a word i.next = i.next.next end @@ -57,9 +58,9 @@ chickenize_real_stuff = function(i,head) -- But it could be done only once each paragraph as in-paragraph changes are not possible! chickenstring_tmp = chickenstring[math.random(1,#chickenstring)] - chicken[0] = nodenew(37,1) -- only a dummy for the loop + chicken[0] = nodenew(GLYPH,1) -- only a dummy for the loop for i = 1,string.len(chickenstring_tmp) do - chicken[i] = nodenew(37,1) + chicken[i] = nodenew(GLYPH,1) chicken[i].font = font.current() chicken[i-1].next = chicken[i] end @@ -96,23 +97,23 @@ chickenize_real_stuff = function(i,head) end chickenize = function(head) - for i in nodetraverseid(37,head) do --find start of a word + for i in nodetraverseid(GLYPH,head) do --find start of a word + -- Random determination of the chickenization of the next word: + if math.random() > chickenizefraction then + chickenize_ignore_word = true + elseif chickencount then + chicken_substitutions = chicken_substitutions + 1 + end + if (chickenize_ignore_word == false) then -- normal case: at the beginning of a word, we jump into chickenization if (i.char > 64 and i.char < 91) then chickenize_capital = true else chickenize_capital = false end head = chickenize_real_stuff(i,head) end -- At the end of the word, the ignoring is reset. New chance for everyone. - if not((i.next.id == 37) or (i.next.id == 7) or (i.next.id == 22) or (i.next.id == 11)) then + if not((i.next.id == GLYPH) or (i.next.id == 7) or (i.next.id == 22) or (i.next.id == 11)) then chickenize_ignore_word = false end - --- And the random determination of the chickenization of the next word: - if math.random() > chickenizefraction then - chickenize_ignore_word = true - elseif chickencount then - chicken_substitutions = chicken_substitutions + 1 - end end return head end @@ -134,8 +135,8 @@ nicetext = function() end end boustrophedon = function(head) - rot = node.new(8,8) - rot2 = node.new(8,8) + rot = node.new(8,PDF_LITERAL) + rot2 = node.new(8,PDF_LITERAL) odd = true for line in node.traverse_id(0,head) do if odd == false then @@ -153,12 +154,12 @@ boustrophedon = function(head) end boustrophedon_glyphs = function(head) odd = false - rot = nodenew(8,8) - rot2 = nodenew(8,8) + rot = nodenew(8,PDF_LITERAL) + rot2 = nodenew(8,PDF_LITERAL) for line in nodetraverseid(0,head) do if odd==true then line.dir = "TRT" - for g in nodetraverseid(37,line.head) do + for g in nodetraverseid(GLYPH,line.head) do w = -g.width/65536*0.99625 rot.data = "-1 0 0 1 " .. w .." 0 cm" rot2.data = "-1 0 0 1 " .. -w .." 0 cm" @@ -174,8 +175,8 @@ boustrophedon_glyphs = function(head) return head end boustrophedon_inverse = function(head) - rot = node.new(8,8) - rot2 = node.new(8,8) + rot = node.new(8,PDF_LITERAL) + rot2 = node.new(8,PDF_LITERAL) odd = true for line in node.traverse_id(0,head) do if odd == false then @@ -193,24 +194,41 @@ texio.write_nl(line.height) end return head end +function bubblesort(head) + for line in nodetraverseid(0,head) do + for glyph in nodetraverseid(GLYPH,line.head) do + + end + end + return head +end +-- Take care: This will slow down the compilation extremely, by about a factor of 2! Only use for playing around or counting a final version of your document! countglyphs = function(head) for line in nodetraverseid(0,head) do - for glyph in nodetraverseid(37,line.head) do + for glyph in nodetraverseid(GLYPH,line.head) do glyphnumber = glyphnumber + 1 - if (glyph.next.id == 10) and (glyph.next.next.id ==37) then - spacenumber = spacenumber + 1 + if (glyph.next.next) then + if (glyph.next.id == 10) and (glyph.next.next.id == GLYPH) then + spacenumber = spacenumber + 1 + end + counted_glyphs_by_code[glyph.char] = counted_glyphs_by_code[glyph.char] + 1 end end end return head end printglyphnumber = function() - texiowrite_nl("\nNumber of glyphs in this document: "..glyphnumber) + texiowrite_nl("\nNumber of glyphs by character code (only up to 127):") + for i = 1,127 do --%% FIXME: should allow for more characters, but cannot be printed to console output – print into document? + texiowrite_nl(string.char(i)..": "..counted_glyphs_by_code[i]) + end + + texiowrite_nl("\nTotal number of glyphs in this document: "..glyphnumber) texiowrite_nl("Number of spaces in this document: "..spacenumber) texiowrite_nl("Glyphs plus spaces: "..glyphnumber+spacenumber.."\n") end countwords = function(head) - for glyph in nodetraverseid(37,head) do + for glyph in nodetraverseid(GLYPH,head) do if (glyph.next.id == 10) then wordnumber = wordnumber + 1 end @@ -228,7 +246,7 @@ function detectdoublewords(head) newlastword = {} newfirstword = {} for line in nodetraverseid(0,head) do - for g in nodetraverseid(37,line.head) do + for g in nodetraverseid(GLYPH,line.head) do texio.write_nl("next glyph",#newfirstword+1) newfirstword[#newfirstword+1] = g.char if (g.next.id == 10) then break end @@ -359,6 +377,20 @@ leet = function(head) end return head end +leftsideright = function(head) + local factor = 65536/0.99626 + for n in nodetraverseid(GLYPH,head) do + if (leftsiderightarray[n.char]) then + shift = nodenew(8,PDF_LITERAL) + shift2 = nodenew(8,PDF_LITERAL) + shift.data = "q -1 0 0 1 " .. n.width/factor .." 0 cm" + shift2.data = "Q 1 0 0 1 " .. n.width/factor .." 0 cm" + nodeinsertbefore(head,n,shift) + nodeinsertafter(head,n,shift2) + end + end + return head +end local letterspace_glue = nodenew(nodeid"glue") local letterspace_spec = nodenew(nodeid"glue_spec") local letterspace_pen = nodenew(nodeid"penalty") @@ -411,6 +443,47 @@ matrixize = function(head) end return head end +medievalumlaut = function(head) + local factor = 65536/0.99626 + local org_e_node = nodenew(GLYPH) + org_e_node.char = 101 + for line in nodetraverseid(0,head) do + for n in nodetraverseid(GLYPH,line.head) do + if (n.char == 228 or n.char == 246 or n.char == 252) then + e_node = nodecopy(org_e_node) + e_node.font = n.font + shift = nodenew(8,PDF_LITERAL) + shift2 = nodenew(8,PDF_LITERAL) + shift2.data = "Q 1 0 0 1 " .. e_node.width/factor .." 0 cm" + nodeinsertafter(head,n,e_node) + + nodeinsertbefore(head,e_node,shift) + nodeinsertafter(head,e_node,shift2) + + x_node = nodenew(11) + x_node.kern = -e_node.width + nodeinsertafter(head,shift2,x_node) + end + + if (n.char == 228) then -- ä + shift.data = "q 0.5 0 0 0.5 " .. + -n.width/factor*0.85 .." ".. n.height/factor*0.75 .. " cm" + n.char = 97 + end + if (n.char == 246) then -- ö + shift.data = "q 0.5 0 0 0.5 " .. + -n.width/factor*0.75 .." ".. n.height/factor*0.75 .. " cm" + n.char = 111 + end + if (n.char == 252) then -- ü + shift.data = "q 0.5 0 0 0.5 " .. + -n.width/factor*0.75 .." ".. n.height/factor*0.75 .. " cm" + n.char = 117 + end + end + end + return head +end local separator = string.rep("=", 28) local texiowrite_nl = texio.write_nl pancaketext = function() @@ -446,7 +519,7 @@ randomfonts = function(head) end uclcratio = 0.5 -- ratio between uppercase and lower case randomuclc = function(head) - for i in nodetraverseid(37,head) do + for i in nodetraverseid(GLYPH,head) do if not(randomuclc_onlytext) or node.has_attribute(i,luatexbase.attributes.randuclcattr) then if math.random() < uclcratio then i.char = tex.uccode[i.char] @@ -514,7 +587,7 @@ randomcolorstring = function() end randomcolor = function(head) for line in nodetraverseid(0,head) do - for i in nodetraverseid(37,line.head) do + for i in nodetraverseid(GLYPH,line.head) do if not(randomcolor_onlytext) or (node.has_attribute(i,luatexbase.attributes.randcolorattr)) then @@ -540,6 +613,18 @@ substitutewords = function(head) end return head end +suppressonecharbreakpenaltynode = node.new(12) +suppressonecharbreakpenaltynode.penalty = 10000 +function suppressonecharbreak(head) + for i in node.traverse_id(10,head) do + if ((i.next) and (i.next.next.id == 10)) then + pen = node.copy(suppressonecharbreakpenaltynode) + node.insert_after(head,i.next,pen) + end + end + + return head +end tabularasa_onlytext = false tabularasa = function(head) @@ -555,6 +640,44 @@ tabularasa = function(head) end return head end +tanjanize = function(head) + local s = nodenew(nodeid"kern") + local m = nodenew(GLYPH,1) + local use_letter_i = true + scale = nodenew(8,PDF_LITERAL) + scale2 = nodenew(8,PDF_LITERAL) + scale.data = "0.5 0 0 0.5 0 0 cm" + scale2.data = "2 0 0 2 0 0 cm" + + for line in nodetraverseid(nodeid"hlist",head) do + for n in nodetraverseid(nodeid"glyph",line.head) do + mimicount = 0 + tmpwidth = 0 + while ((n.next.id == GLYPH) or (n.next.id == 11) or (n.next.id == 7) or (n.next.id == 0)) do --find end of a word + n.next = n.next.next + mimicount = mimicount + 1 + tmpwidth = tmpwidth + n.width + end + + mimi = {} -- constructing the node list. + mimi[0] = nodenew(GLYPH,1) -- only a dummy for the loop + for i = 1,string.len(mimicount) do + mimi[i] = nodenew(GLYPH,1) + mimi[i].font = font.current() + if(use_letter_i) then mimi[i].char = 109 else mimi[i].char = 105 end + use_letter_i = not(use_letter_i) + mimi[i-1].next = mimi[i] + end +--]] + +line.head = nodeinsertbefore(line.head,n,nodecopy(scale)) +nodeinsertafter(line.head,n,nodecopy(scale2)) + s.kern = (tmpwidth*2-n.width) + nodeinsertafter(line.head,n,nodecopy(s)) + end + end + return head +end uppercasecolor_onlytext = false uppercasecolor = function (head) @@ -572,6 +695,22 @@ uppercasecolor = function (head) end return head end +upsidedown = function(head) + local factor = 65536/0.99626 + for line in nodetraverseid(Hhead,head) do + for n in nodetraverseid(GLYPH,line.head) do + if (upsidedownarray[n.char]) then + shift = nodenew(8,PDF_LITERAL) + shift2 = nodenew(8,PDF_LITERAL) + shift.data = "q 1 0 0 -1 0 " .. n.height/factor .." cm" + shift2.data = "Q 1 0 0 1 " .. n.width/factor .." 0 cm" + nodeinsertbefore(head,n,shift) + nodeinsertafter(head,n,shift2) + end + end + end + return head +end keeptext = true colorexpansion = true @@ -590,8 +729,8 @@ colorstretch = function (head) if colorexpansion then -- if also the font expansion should be shown local g = line.head - while not(g.id == 37) and (g.next) do g = g.next end -- find first glyph on line. If line is empty, no glyph: - if (g.id == 37) then -- read width only if g is a glyph! + while not(g.id == GLYPH) and (g.next) do g = g.next end -- find first glyph on line. If line is empty, no glyph: + if (g.id == GLYPH) then -- read width only if g is a glyph! exp_factor = g.width / f[g.char].width exp_color = colorstretch_coloroffset + (1-exp_factor)*10 .. " g" rule_bad.width = 0.5*line.width -- we need two rules on each line! @@ -643,7 +782,7 @@ colorstretch = function (head) glue_ratio_output = {} for s in string.utfvalues(math.abs(glue_ratio)) do -- using math.abs here gets us rid of the minus sign local char = unicode.utf8.char(s) - glue_ratio_output[j] = nodenew(37,1) + glue_ratio_output[j] = nodenew(GLYPH,1) glue_ratio_output[j].font = font.current() glue_ratio_output[j].char = s j = j+1 diff --git a/Master/texmf-dist/tex/luatex/chickenize/chickenize.sty b/Master/texmf-dist/tex/luatex/chickenize/chickenize.sty index fc58953a20d..0e9a58626ce 100644 --- a/Master/texmf-dist/tex/luatex/chickenize/chickenize.sty +++ b/Master/texmf-dist/tex/luatex/chickenize/chickenize.sty @@ -8,13 +8,14 @@ %% %% EXPERIMENTAL CODE %% -%% This package is copyright © 2013 Arno L. Trautmann. It may be distributed and/or +%% This package is copyright © 2015 Arno L. Trautmann. It may be distributed and/or %% modified under the conditions of the LaTeX Project Public License, either version 1.3c %% of this license or (at your option) any later version. This work has the LPPL mainten- %% ance status ‘maintained’. \ProvidesPackage{chickenize}% - [2013/08/22 v0.2.1a chickenize package] + [2015/12/26 v0.2.2 chickenize package] \input{chickenize} + \iffalse \DeclareDocumentCommand\includegraphics{O{}m}{ \fbox{Chicken} %% actually, I'd love to draw an MP graph showing a chicken … diff --git a/Master/texmf-dist/tex/luatex/chickenize/chickenize.tex b/Master/texmf-dist/tex/luatex/chickenize/chickenize.tex index 955102e8a41..185c8e6326e 100644 --- a/Master/texmf-dist/tex/luatex/chickenize/chickenize.tex +++ b/Master/texmf-dist/tex/luatex/chickenize/chickenize.tex @@ -8,25 +8,46 @@ %% %% EXPERIMENTAL CODE %% -%% This package is copyright © 2013 Arno L. Trautmann. It may be distributed and/or +%% This package is copyright © 2015 Arno L. Trautmann. It may be distributed and/or %% modified under the conditions of the LaTeX Project Public License, either version 1.3c %% of this license or (at your option) any later version. This work has the LPPL mainten- %% ance status ‘maintained’. -\input{luatexbase.sty} \directlua{dofile(kpse.find_file("chickenize.lua"))} +\def\ALT{% + \bgroup% + \fontspec{Latin Modern Sans}% + A% + \kern-.37em \raisebox{.7ex}{\scalebox{0.25}{L}}% + \kern-.0em \raisebox{-0.98ex}{T}% + \egroup% +} + +\def\allownumberincommands{ + \catcode`\0=11 + \catcode`\1=11 + \catcode`\2=11 + \catcode`\3=11 + \catcode`\4=11 + \catcode`\5=11 + \catcode`\6=11 + \catcode`\7=11 + \catcode`\8=11 + \catcode`\9=11 +} + \def\BEClerize{ \chickenize \directlua{ - chickenstring[1] = "noise noise" - chickenstring[2] = "atom noise" - chickenstring[3] = "shot noise" - chickenstring[4] = "photon noise" - chickenstring[5] = "camera noise" - chickenstring[6] = "noising noise" - chickenstring[7] = "thermal noise" - chickenstring[8] = "electronic noise" - chickenstring[9] = "spin noise" + chickenstring[1] = "noise noise" + chickenstring[2] = "atom noise" + chickenstring[3] = "shot noise" + chickenstring[4] = "photon noise" + chickenstring[5] = "camera noise" + chickenstring[6] = "noising noise" + chickenstring[7] = "thermal noise" + chickenstring[8] = "electronic noise" + chickenstring[9] = "spin noise" chickenstring[10] = "electron noise" chickenstring[11] = "Bogoliubov noise" chickenstring[12] = "white noise" @@ -53,6 +74,11 @@ \def\unboustrophedoninverse{ \directlua{luatexbase.remove_from_callback("post_linebreak_filter","boustrophedon_inverse")}} +\def\bubblesort{ + \directlua{luatexbase.add_to_callback("post_linebreak_filter",bubblesort,"bubblesort")}} +\def\unbubblesort{ + \directlua{luatexbase.remove_from_callback("bubblesort","bubblesort")}} + \def\chickenize{ \directlua{luatexbase.add_to_callback("pre_linebreak_filter",chickenize,"chickenize") luatexbase.add_to_callback("start_page_number", @@ -78,7 +104,12 @@ \directlua{luatexbase.remove_from_callback("post_linebreak_filter","stretch_expansion")}} \def\countglyphs{ - \directlua{glyphnumber = 0 spacenumber = 0 + \directlua{ + counted_glyphs_by_code = {} + for i = 1,10000 do + counted_glyphs_by_code[i] = 0 + end + glyphnumber = 0 spacenumber = 0 luatexbase.add_to_callback("post_linebreak_filter",countglyphs,"countglyphs") luatexbase.add_to_callback("stop_run",printglyphnumber,"printglyphnumber") } @@ -168,6 +199,19 @@ \def\unleetspeak{ \directlua{luatexbase.remove_from_callback("post_linebreak_filter","1337")}} +\def\leftsideright#1{ + \directlua{luatexbase.add_to_callback("pre_linebreak_filter",leftsideright,"leftsideright")} + \directlua{ + leftsiderightindex = {#1} + leftsiderightarray = {} + for _,i in pairs(leftsiderightindex) do + leftsiderightarray[i] = true + end + } +} +\def\unleftsideright{ + \directlua{luatexbase.remove_from_callback("pre_linebreak_filter","leftsideright")}} + \def\letterspaceadjust{ \directlua{luatexbase.add_to_callback("pre_linebreak_filter",letterspaceadjust,"letterspaceadjust")}} \def\unletterspaceadjust{ @@ -187,13 +231,18 @@ \def\matrixize{ \directlua{luatexbase.add_to_callback("pre_linebreak_filter",matrixize,"matrixize")}} \def\unmatrixize{ - \directlua{luatexbase.remove_from_callback("pre_linebreak_filter",matrixize)}} + \directlua{luatexbase.remove_from_callback("pre_linebreak_filter","matrixize")}} \def\milkcow{ %% FIXME %% to be implemented \directlua{}} \def\unmilkcow{ \directlua{}} +\def\medievalumlaut{ + \directlua{luatexbase.add_to_callback("post_linebreak_filter",medievalumlaut,"medievalumlaut")}} +\def\unmedievalumlaut{ + \directlua{luatexbase.remove_from_callback("post_linebreak_filter","medievalumlaut")}} + \def\pancakenize{ \directlua{luatexbase.add_to_callback("stop_run",pancaketext,"pancaketext")}} @@ -203,8 +252,8 @@ \def\unrainbowcolor{ \directlua{luatexbase.remove_from_callback("post_linebreak_filter","rainbowcolor") rainbowcolor = false}} - \let\nyanize\rainbowcolor - \let\unnyanize\unrainbowcolor +\let\nyanize\rainbowcolor +\let\unnyanize\unrainbowcolor \def\randomcolor{ \directlua{luatexbase.add_to_callback("post_linebreak_filter",randomcolor,"randomcolor")}} @@ -248,16 +297,42 @@ \directlua{addtosubstitutions("#1","#2")} } +\def\suppressonecharbreak{ + \directlua{luatexbase.add_to_callback("pre_linebreak_filter",suppressonecharbreak,"suppressonecharbreak")}} +\def\unsuppressonecharbreak{ + \directlua{luatexbase.remove_from_callback("pre_linebreak_filter","suppressonecharbreak")}} + \def\tabularasa{ \directlua{luatexbase.add_to_callback("post_linebreak_filter",tabularasa,"tabularasa")}} \def\untabularasa{ \directlua{luatexbase.remove_from_callback("post_linebreak_filter","tabularasa")}} +\def\tanjanize{ + \directlua{luatexbase.add_to_callback("post_linebreak_filter",tanjanize,"tanjanize")}} +\def\untanjanize{ + \directlua{luatexbase.remove_from_callback("post_linebreak_filter","tanjanize")}} + \def\uppercasecolor{ \directlua{luatexbase.add_to_callback("post_linebreak_filter",uppercasecolor,"uppercasecolor")}} \def\unuppercasecolor{ \directlua{luatexbase.remove_from_callback("post_linebreak_filter","uppercasecolor")}} +\def\upsidedown#1{ + \directlua{luatexbase.add_to_callback("post_linebreak_filter",upsidedown,"upsidedown")} + \directlua{ + upsidedownindex = {#1} + upsidedownarray = {} + for _,i in pairs(upsidedownindex) do + upsidedownarray[i] = true + end + } +} +\def\unupsidedown{ + \directlua{luatexbase.remove_from_callback("post_linebreak_filter","upsidedown")}} + +\def\unuppercasecolor{ + \directlua{luatexbase.remove_from_callback("post_linebreak_filter","upsidedow")}} + \def\variantjustification{ \directlua{luatexbase.add_to_callback("post_linebreak_filter",variantjustification,"variantjustification")}} \def\unvariantjustification{ @@ -267,13 +342,13 @@ \directlua{luatexbase.add_to_callback("post_linebreak_filter",zebranize,"zebranize")}} \def\unzebranize{ \directlua{luatexbase.remove_from_callback("post_linebreak_filter","zebranize")}} -\newluatexattribute\leetattr -\newluatexattribute\letterspaceadjustattr -\newluatexattribute\randcolorattr -\newluatexattribute\randfontsattr -\newluatexattribute\randuclcattr -\newluatexattribute\tabularasaattr -\newluatexattribute\uppercasecolorattr +\newattribute\leetattr +\newattribute\letterspaceadjustattr +\newattribute\randcolorattr +\newattribute\randfontsattr +\newattribute\randuclcattr +\newattribute\tabularasaattr +\newattribute\uppercasecolorattr \long\def\textleetspeak#1% {\setluatexattribute\leetattr{42}#1\unsetluatexattribute\leetattr} |