diff options
author | Karl Berry <karl@freefriends.org> | 2013-04-13 23:04:44 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2013-04-13 23:04:44 +0000 |
commit | 7b85ff3b395eead1f1311abc4b4cac881d0fd50b (patch) | |
tree | 64792be49db994614043ec99f37f38d8d8adc971 /Master/texmf-dist/tex/context | |
parent | 215ff8c0d4b35463f2a094477c2308a8986d424c (diff) |
context-cyrillicnumbers (12apr13)
git-svn-id: svn://tug.org/texlive/trunk@29905 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context')
4 files changed, 903 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/context/interface/third/t-cyrillicnumbers.xml b/Master/texmf-dist/tex/context/interface/third/t-cyrillicnumbers.xml new file mode 100644 index 00000000000..e3586b2d82d --- /dev/null +++ b/Master/texmf-dist/tex/context/interface/third/t-cyrillicnumbers.xml @@ -0,0 +1,104 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> + +<!-- versions: + + comment : user interface definitions of the Cyrillic Numbers module + + authors : Philipp Gesang + + versions : 2013-03-27 23:57:55+0100 (mercurial tip) + +--> + +<cd:interface xmlns:cd="http://www.pragma-ade.com/commands" + name="context" + language="en" + version="2013-03-27 23:57:58+0100"> + + <cd:command name="setupcyrnum" file="t-cyrillicnumbers.mkvi"> + <cd:sequence> + <cd:string value="setupcyrnum"/> + </cd:sequence> + <cd:arguments> + <cd:keywords n="1" optional="yes"> + <cd:constant type="cd:name"/> + </cd:keywords> + <cd:assignments n="2" list="yes" optional="no"> + <cd:parameter name="command"> + <cd:constant type="cd:oneargument"/> + </cd:parameter> + <cd:parameter name="dots"> + <cd:constant type="no"/> + <cd:constant type="yes" default="yes"/> + </cd:parameter> + <cd:parameter name="dotsymbol"> + <cd:constant type="cd:text" default="·"/> + </cd:parameter> + <cd:parameter name="penwidth"> + <cd:constant type="cd:dimension" default=".66pt"/> + </cd:parameter> + <cd:parameter name="preferhundredk"> + <cd:constant type="no" default="yes"/> + <cd:constant type="yes"/> + </cd:parameter> + <cd:parameter name="titlo"> + <cd:constant type="mp" default="yes"/> + <cd:constant type="font"/> + </cd:parameter> + <cd:parameter name="titlocolor"> + <cd:constant type="cd:name" default="black"/> + </cd:parameter> + <cd:parameter name="titlolocation"> + <cd:constant type="middle" default="yes"/> + <cd:constant type="final"/> + <cd:constant type="first"/> + </cd:parameter> + <cd:parameter name="titlomode"> + <cd:constant type="cd:number" default="5"/> + </cd:parameter> + <cd:parameter name="titlospan"> + <cd:constant type="cd:number" default="3"/> + </cd:parameter> + </cd:assignments> + </cd:arguments> + </cd:command> + + <cd:command name="definecyrnum" file="t-cyrillicnumbers.mkvi"> + <cd:sequence> + <cd:string value="definecyrnum"/> + </cd:sequence> + <cd:arguments> + <cd:keywords n="1" optional="no"> + <cd:constant type="cd:name"/> + </cd:keywords> + <cd:assignments n="2" list="yes" optional="yes"> + <cd:inherit name="setupcyrnum" n="2"/> + </cd:assignments> + </cd:arguments> + </cd:command> + + <cd:command name="cyrnum" generated="yes" file="t-cyrillicnumbers.mkvi"> + <cd:sequence> + <cd:variable value="cyrnum"/> + </cd:sequence> + <cd:arguments> + <cd:assignments n="1" list="yes" optional="yes"> + <cd:inherit name="setupcyrnum"/> + </cd:assignments> + <cd:content n="2" optional="no"/> + </cd:arguments> + </cd:command> + + <cd:command name="cyrnumdrawtitlo" generated="yes" file="t-cyrillicnumbers.mkvi"> + <cd:sequence> + <cd:variable value="cyrnumdrawtitlo"/> + </cd:sequence> + <cd:arguments> + <cd:content n="1" optional="no"/> + </cd:arguments> + </cd:command> + +</cd:interface> + +<!-- vim:sw=2:ts=2 +--> diff --git a/Master/texmf-dist/tex/context/third/cyrillicnumbers/cyrillicnumbers.lua b/Master/texmf-dist/tex/context/third/cyrillicnumbers/cyrillicnumbers.lua new file mode 100644 index 00000000000..f33395c73d0 --- /dev/null +++ b/Master/texmf-dist/tex/context/third/cyrillicnumbers/cyrillicnumbers.lua @@ -0,0 +1,325 @@ +#!/usr/bin/env texlua +-------------------------------------------------------------------------------- +-- FILE: cyrillicnumbers.lua +-- USAGE: called by t-cyrillicnumbers.mkvi +-- DESCRIPTION: part of the Cyrillic Numbers module for ConTeXt +-- REQUIREMENTS: recent ConTeXt MkIV and LuaTeX +-- AUTHOR: Philipp Gesang (phg), <phg42 dot 2a at gmail dot com> +-- VERSION: hg tip +-- CHANGED: 2013-03-28 00:10:47+0100 +-------------------------------------------------------------------------------- +-- + +--[[ldx-- +<p>read this first:</p> + +<p>Жолобов, О. Ф.: <key>Числительные</key>. In: <key>Историческая + грамматика древнерусского языка</key>, vol. 4, Moskva + 2006, pp. 58--63</p> + +<p>Trunte, Nikolaos H.: <key>Altkirchenslavisch</key>. In: + <key>Словѣньскъи ѩꙁъікъ. Ein praktisches Lehrbuch + des Kirchenslavischen in 30 Lektionen. Zugleich eine + Einführung in die slavische Philologie</key>, vol. + 1, München ⁵2005, pp. 161ff.</p> + +<p>or have a glance at these:</p> + +<typing> +http://www.pravpiter.ru/zads/n018/ta013.htm +http://www.uni-giessen.de/partosch/eurotex99/berdnikov2.pdf +http://ru.wikipedia.org/wiki/Кириллическая_система_счисления +</typing> +--ldx]]-- + +local iowrite = io.write +local mathceil = math.ceil +local mathfloor = math.floor +local stringformat = string.format +local tableconcat = table.concat +local tableinsert = table.insert +local tostring = tostring +local type = type +local utf8char = unicode.utf8.char +local utf8len = unicode.utf8.len + + +local cyrnum = { + placetitlo = "font", + prefer100k = false, + titlolocation = "final", -- above final digit + titlospan = 3, -- only with mp + drawdots = true, + debug = false, +} + +thirddata = thirddata or { } +thirddata.cyrnum = cyrnum + +local dbgpfx = "[cyrnum]" +local dbg = function (...) + if cyrnum.debug then + local args = {...} + if type(args[1]) == "table" then args = args[1] end + iowrite(dbgpfx) + for i=1, #args do + local this = args[i] + local tthis = type(this) + iowrite" " + if tthis == "number" or tthis == "string" then + iowrite(this) + else + iowrite(tostring(this)) + end + end + iowrite"\n" + end +end + +local cyrillic_numerals = { + { "а", "в", "г", "д", "е", "ѕ", "з", "и", "ѳ", }, + { "і", "к", "л", "м", "н", "ѯ", "о", "п", "ч", }, + { "р", "с", "т", "у", "ф", "х", "ѱ", "ѡ", "ц", }, +} +local cyrillic_1k = "҂" +local cyrillic_100k = utf8char(0x488) -- combining hundred thousands sign +local cyrillic_1m = utf8char(0x489) -- combining million sign +local cyrillic_titlo = utf8char(0x483) -- combining titlo + +--[[ldx-- +<p>Some string synonyms for user convenience.</p> +--ldx]]-- +cyrnum.yes_synonyms = { + yes = true, + yeah = true, + ["true"] = true, +} + +cyrnum.no_synonyms = { + no = true, + nope = true, + ["false"] = true, +} + +--[[ldx-- +<p><type>m</type> for rounded down middle position, <type>l</type> for final +position. Will default to initial position otherwise.</p> +--ldx]]-- +cyrnum.position_synonyms = { + final = "l", + last = "l", + right = "l", + rightmost = "l", + ["false"] = "l", + middle = "m", + center = "m", + ["true"] = "m", +} + +--[[ldx-- +<p>Digits above the thirds require special markers, some of which need to be +placed before, others after the determined character.</p> +--ldx]]-- +local handle_plus1k = function (digit) + local before, after + if digit == 7 then + after = cyrillic_1m + elseif cyrnum.prefer100k and digit == 6 then + after = cyrillic_100k + elseif digit > 3 then -- insert thousand sign + before = cyrillic_1k + end + return before, after +end + +-- digit list = { +-- [1] = character to be printed +-- [2] = real digit of character +-- [3] = print this before character (e.g. thousand signs) +-- [4] = print this after character (e.g. million signs) +-- } + +--[[ldx-- +<p>The base list of digits denotes empty (zero) digits with "false" values +instead of characters. The function <type>digits_only</type> will extract only +the nonempty digit values, returning a list.</p> +--ldx]]-- +local digits_only = function (list) + local result = { } + for i=1, #list do + local elm = list[i] + if type(elm) == "string" then + local before, after + if i > 3 then + before, after = handle_plus1k(i) + end + result[#result+1] = { elm, i, before, after } -- i contains the real digit + end + end + return result +end + +--[[ldx-- +<p>The different ways for drawing the <italic>titlo</italic> are stored inside +a table. Basically, the options are to use the titlos symbol that is provided +by the font or to draw the titlo in <l n="metapost"/>.</p> +--ldx]]-- +local lreverse = function(list)local r={}for i=#list,1,-1 do r[#r+1]=list[i]end return r end + +local start_titlo, stop_titlo = [[\cyrnumdrawtitlo{]], "}" + +local titlofuncs = { + font = function (list) + local result, titlopos = { }, #list + if cyrnum.titlolocation == "l" then + titlopos = 1 + elseif cyrnum.titlolocation == "m" then + titlopos = mathceil(#list/2) + end + for i=#list, 1, -1 do + local char, digit, before, after = list[i][1], list[i][2], list[i][3], list[i][4] + if before then + result[#result+1] = before + end + result[#result+1] = char + if after then + result[#result+1] = after + end + if i == titlopos then + result[#result+1] = cyrillic_titlo + end + end + return result + end, + mp = function (list) + local result = { } + local titlospan = cyrnum.titlospan + local titlotype = cyrnum.titlotype + local titlostart = #list -- default to “all” + if titlotype == true then -- number + titlostart = (#list >= titlospan) and titlospan or #list + end + for i=#list, 1, -1 do + local char, digit, before, after = list[i][1], list[i][2], list[i][3], list[i][4] + --local char, digit, before, after = unpack(list[i]) + if i == titlostart then + result[#result+1] = start_titlo + end + if before then + result[#result+1] = before + end + result[#result+1] = char + if after then + result[#result+1] = after + end + end + result[#result+1] = stop_titlo + return result + end, + no = function (list) + local result = { } + for i=#list, 1, -1 do + local char, digit, before, after = list[i][1], list[i][2], list[i][3], list[i][4] + if before then + result[#result+1] = before + end + result[#result+1] = char + if after then + result[#result+1] = after + end + end + return result + end, +} + +--[[ldx-- +<p>Concatenation of the digit list has to take into account different conditions: whether the user requests the dot markers to be added, whether a titlo is requested etc.</p> +--ldx]]-- +local concat_cyrillic_nums = function (list) + local result = "" + local digits = digits_only(list) -- strip placeholders + local nlist, ndigits = #list, #digits + dbg(list) + --dbg(digits) + local titlo = titlofuncs[cyrnum.placetitlo] + if titlo then + result = tableconcat(titlo(digits)) + if cyrnum.drawdots then + local sym = cyrnum.dotsymbol + result = sym .. result .. sym + end + end + dbg(result) + return result +end + +local do_tocyrillic do_tocyrillic = function (n, result) + if n < 1000 then + local mod100 = n % 100 + if #result == 0 and mod100 > 10 and mod100 < 20 then + result[#result+1] = "і" + result[#result+1] = cyrillic_numerals[1][mod100%10] or false + else + result[#result+1] = cyrillic_numerals[1][mathfloor(n%10)] or false + result[#result+1] = cyrillic_numerals[2][mathfloor((n%100)/10)] or false + end + result[#result+1] = cyrillic_numerals[3][mathfloor((n%1000)/100)] or false + else + result = do_tocyrillic(n%1000, result) + result = do_tocyrillic(mathfloor(n/1000), result) + end + return result +end + +local tocyrillic = function (n) + local chars = do_tocyrillic(n, { }) + return concat_cyrillic_nums(chars) +end + +local Tocyrillic = function (n) + local chars = do_tocyrillic(n, { }) + return concat_cyrillic_nums(chars, true) +end + +converters.tocyrillic = tocyrillic +converters.cyrillicnumerals = tocyrillic +converters.Cyrillicnumerals = Tocyrillic + +function commands.cyrillicnumerals (n) context(tocyrillic(n)) end +function commands.Cyrillicnumerals (n) context(Tocyrillic(n)) end + +--- Fun --------------------------------------------------------- + +local f_peano = [[suc(%s)]] +local do_topeano = function (n) + n = tonumber(n) or 0 + if n == 0 then return "0" end + local result = stringformat(f_peano, 0) + if n == 1 then return result end + for i=2, n do + result = stringformat(f_peano, result) + end + return result +end + +local s_churchp = [[λf.λx.\;]] +local s_church0 = [[x]] +local s_church1 = [[f\,x]] +local f_church = [[f(%s)]] +local do_tochurch = function (n) + if n == 0 then return s_churchp .. s_church0 + elseif n == 1 then return s_churchp .. s_church1 end + local result = stringformat(f_church, s_church1) + for i=2, n do + result = stringformat(f_church, result) + end + return s_churchp .. result +end + +converters.topeano = do_topeano +converters.tochurch = do_tochurch + +commands.peanonumerals = function (n) context(do_topeano(n)) end +commands.churchnumerals = function (n) context.mathematics(do_tochurch(n)) end + +-- vim:ft=lua:ts=2:sw=2:expandtab:fo=croql diff --git a/Master/texmf-dist/tex/context/third/cyrillicnumbers/t-cyrillicnumbers.mkii b/Master/texmf-dist/tex/context/third/cyrillicnumbers/t-cyrillicnumbers.mkii new file mode 100644 index 00000000000..c3b955bc91d --- /dev/null +++ b/Master/texmf-dist/tex/context/third/cyrillicnumbers/t-cyrillicnumbers.mkii @@ -0,0 +1,3 @@ +\writestatus{loading}{Cyrillic Number Support for ConTeXt} +\writestatus{ERROR} {The module “Cyrillic Numbers” does not support ConTeXt MkII.} +\bye \endinput diff --git a/Master/texmf-dist/tex/context/third/cyrillicnumbers/t-cyrillicnumbers.mkvi b/Master/texmf-dist/tex/context/third/cyrillicnumbers/t-cyrillicnumbers.mkvi new file mode 100644 index 00000000000..c86934cce40 --- /dev/null +++ b/Master/texmf-dist/tex/context/third/cyrillicnumbers/t-cyrillicnumbers.mkvi @@ -0,0 +1,471 @@ +%D \module +%D [ file=t-cyrillicnumbers.mkvi, +%D version=2013-03-28 00:11:33+0100, +%D title=\CONTEXT\ User Module, +%D subtitle=Cyrillic Numbers, +%D author=Philipp Gesang, +%D date=\currentdate, +%D copyright=Philipp Gesang, +%D license=2-clause BSD, +%D email={phg42 dot 2a at gmail dot com}] +%D This module is licensed under the conditions of the BSD license with +%D two clauses. There is a copy in a file named "COPYING" in the +%D t-cyrillicnumbers source tree. + +%M \definehead[docsection] [chapter] +%M \setuphead [docsection] [page=no,style=\tf\bold\WORD,color=darkmagenta,alternative=inmargin,before={\blank[3*line]}] +%M \definehead[doctitle] [coupling=docsection,default=docsection,incrementnumber=no,page=no] +%M \setuplist [docsection] [alternative=b,textstyle=\tf] +%M \setupinteraction[focus=standard,color=darkmagenta] + +%D \doctitle{Overview}\placelist[docsection][criterium=all]\page[yes] +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%D \docsection{Global strings and namespace initialization} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\writestatus{loading}{Cyrillic Number Support for ConTeXt} + +\unprotect + +\startinterface all + \setinterfacevariable {cyrillicnumerals} {cyrillicnumerals} + \setinterfacevariable {Cyrillicnumerals} {Cyrillicnumerals} + \setinterfacevariable {cyrnum} {cyrnum} + \setinterfacevariable {dots} {dots} + \setinterfacevariable {dotsymbol} {dotsymbol} + \setinterfacevariable {penwidth} {penwidth} + \setinterfacevariable {preferhundredk} {preferhundredk} + \setinterfacevariable {titlolocation} {titlolocation} + \setinterfacevariable {titlocolor} {titlocolor} + \setinterfacevariable {titlomode} {titlomode} + \setinterfacevariable {titlospan} {titlospan} + \setinterfacevariable {titlo} {titlo} +\stopinterface + +\definenamespace [cyrnum] [ + \v!command=\v!yes, + comment=cyrillic numbers, + \s!name=\v!cyrnum, + \s!parent=\v!cyrnum, + setup=\v!list, + style=\v!no, + type=module, + version=hg-tip, +] + +%D Loading the \LUA\ conversion routines. + +\registerctxluafile{cyrillicnumbers} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%D \docsection{Setup command} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%D The\reference[setupdef]{} autogenerated setup command needs to +%D be extended to pass values on to the \LUA\ end. + +\def\cyrnumsetvariables{% + \startluacode + local tc = thirddata.cyrnum + tc.placetitlo = "\cyrnumparameter{\v!titlo}" + tc.titlolocation = tc.position_synonyms["\cyrnumparameter{\v!titlolocation}"] or "f" + tc.prefer100k = tc. yes_synonyms["\cyrnumparameter{\v!preferhundredk}"] or false + tc.drawdots = tc. yes_synonyms["\cyrnumparameter{\v!dots}"] or false + tc.dotsymbol = "\luaescapestring{\cyrnumparameter{\v!dotsymbol}}" + + local span = "\cyrnumparameter{\v!titlospan}" + local num = tonumber(span) + if num then + tc.titlotype = true + tc.titlospan = num + elseif span == "all" then + tc.titlotype = false + end + \stopluacode% +} + +\appendtoks \setuevalue{\currentcyrnum}{\cyrnum_cmd[\currentcyrnum]} \to \everydefinecyrnum +\appendtoks \cyrnumsetvariables \to \everysetupcyrnum + +%D This allows the module to be loaded with a second set of +%D key-value arguments. If initialized as follows, additional debug +%D information will be output on the terminal. +%D +%D \starttyping +%D \usemodule[cyrillicnumbers][test=yes] +%D \stoptyping + +\startmoduletestsection + \ctxlua{thirddata.cyrnum.debug = true} +\stopmoduletestsection + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%D \docsection{Titlo variants} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%D The {\em Cyrillic Numbers} module allows the titlo, if requested, +%D to be drawn in two different ways. If the setup parameter +%D \type{titlo} has the value {\em mp}, then the variant employing +%D \METAPOST\ is selected. As there are a couple of different +%D styles, it will be necessary that the user determine one by +%D setting the parameter \type{titlomode} to an integer. +%D Additionally it is possible to manipulate the pen width that +%D \METAPOST\ uses when executing the titlo code. {\em NB} as the +%D drawing routines differ, the \type{penwidth} parameter lead to +%D different results with different modes as well, ymmv. +%D +%D \starttyping +%D \setupcyrnum[ +%D titlo=mp, +%D titlomode=4, +%D penwidth=4, +%D ] +%D \stoptyping + +\startuniqueMPgraphic{cyrnum-titlo1} + path titlo ; + save High, Low ; + save Vfactor ; Vfactor = .15 ; + save Hfactor ; Hfactor = .90 ; + titlo := ( 0.00, -Vfactor) .. + ( 0.05, .4*Vfactor) .. + ( 0.95, -.4*Vfactor) .. + ( 1.00, Vfactor) ; + pickup pensquare yscaled \cyrnumparameter{penwidth} xscaled 1 rotated -30 ; + draw titlo + xysized (Hfactor*OverlayWidth,Vfactor*OverlayHeight) + shifted (.5*(OverlayWidth-Hfactor*OverlayWidth),OverlayHeight-Vfactor*OverlayHeight) + withcolor \MPcolor{\cyrnumparameter{titlocolor}}; + setbounds currentpicture to boundingbox OverlayBox ; +\stopuniqueMPgraphic + +\startuniqueMPgraphic{cyrnum-titlo2} + path titlo ; + save penwidth ; penwidth = \cyrnumparameter{penwidth} ; + save High, Low ; + save Vfactor ; Vfactor = .15 ; + save Hfactor ; Hfactor = .80 ; + titlo := ( 0.05, -Vfactor) -- + ( 0.07, .7*Vfactor) .. + ( 0.09, .8*Vfactor) .. + ( 0.91, -.8*Vfactor) .. + ( 0.93, -.7*Vfactor) -- + ( 0.95, Vfactor) ; + pickup pensquare yscaled penwidth xscaled 1 rotated 70 ; + draw titlo + xysized (Hfactor*OverlayWidth,Vfactor*OverlayHeight) + shifted (.5*(OverlayWidth-Hfactor*OverlayWidth)-.5*penwidth,OverlayHeight-Vfactor*OverlayHeight) + withcolor \MPcolor{\cyrnumparameter{titlocolor}}; + setbounds currentpicture to boundingbox OverlayBox ; +\stopuniqueMPgraphic + +\startuniqueMPgraphic{cyrnum-titlo3} + path titlo ; + save penwidth ; penwidth = \cyrnumparameter{penwidth} ; + save High, Low ; + save Vfactor ; Vfactor = .15 ; + save Hfactor ; Hfactor = .80 ; + titlo := ( 0.05, -Vfactor) -- + ( 0.07, 0.70*Vfactor) .. + ( 0.09, 0.90*Vfactor) .. { dir 00 } + ( 0.49, -0.00*Vfactor) -- + ( 0.49, -0.90*Vfactor) -- + ( 0.51, 0.90*Vfactor) -- + ( 0.51, 0.00*Vfactor) { dir 00 } .. + ( 0.91, -0.90*Vfactor) .. + ( 0.93, -0.70*Vfactor) -- + ( 0.95, Vfactor) ; + pickup pensquare yscaled penwidth xscaled 1 rotated 70 ; + draw titlo + xysized (Hfactor*OverlayWidth,Vfactor*OverlayHeight) + shifted (.5*(OverlayWidth-Hfactor*OverlayWidth)-.5*penwidth,OverlayHeight-Vfactor*OverlayHeight) + withcolor \MPcolor{\cyrnumparameter{titlocolor}}; + setbounds currentpicture to boundingbox OverlayBox ; +\stopuniqueMPgraphic + +%%% Same as 2 with inner vertical stroke +\startuniqueMPgraphic{cyrnum-titlo4} + path titlo, stroke ; + save penwidth ; penwidth = \cyrnumparameter{penwidth} ; + save High, Low ; + save Vfactor ; Vfactor = .15 ; + save Hfactor ; Hfactor = .80 ; + titlo = ( 0.05, -1.00*Vfactor) -- + ( 0.07, 0.70*Vfactor) .. + ( 0.09, 0.90*Vfactor) { dir 00 } .. { dir 00 } + ( 0.91, -0.90*Vfactor) .. + ( 0.93, -0.70*Vfactor) -- + ( 0.95, 1.00*Vfactor) ; + stroke = ( 0.49*Hfactor*OverlayWidth+.5*penwidth, -0.30*Vfactor*OverlayHeight ) -- %% this is a mess + ( 0.51*Hfactor*OverlayWidth+.5*penwidth, 0.50*Vfactor*OverlayHeight ) ; + pickup pensquare yscaled penwidth xscaled 1 rotated 80 ; + draw titlo + xysized (Hfactor*OverlayWidth,Vfactor*OverlayHeight) + shifted (.5*(OverlayWidth-Hfactor*OverlayWidth)-.5*penwidth,OverlayHeight-Vfactor*OverlayHeight) + withcolor \MPcolor{\cyrnumparameter{titlocolor}}; + draw stroke + % xysized (Hfactor*OverlayWidth,Vfactor*OverlayHeight) %% doesn’t work as expected somehow + shifted (.5*(OverlayWidth-Hfactor*OverlayWidth)-.5*penwidth,OverlayHeight-Vfactor*OverlayHeight) + withcolor \MPcolor{\cyrnumparameter{titlocolor}} ; + setbounds currentpicture to boundingbox OverlayBox ; +\stopuniqueMPgraphic + +\startuniqueMPgraphic{cyrnum-titlo5} + path titlo ; + save penwidth ; penwidth = \cyrnumparameter{penwidth} ; + save High, Low ; + save Vfactor ; Vfactor = .20 ; + save Hfactor ; Hfactor = .75 ; + titlo := ( 0.00, -0.8*Vfactor) {dir 90} .. {dir 90} + ( 1.00, 1.2*Vfactor) ; + pickup pensquare yscaled penwidth xscaled 2 rotated 85 ; + draw titlo + xysized (Hfactor*OverlayWidth-penwidth,Vfactor*OverlayHeight) + shifted (.5*(OverlayWidth-Hfactor*OverlayWidth),OverlayHeight-Vfactor*OverlayHeight) + withcolor \MPcolor{\cyrnumparameter{titlocolor}} ; + setbounds currentpicture to boundingbox OverlayBox ; +\stopuniqueMPgraphic + +\startuniqueMPgraphic{cyrnum-titlo6} + path titlo ; + save penwidth ; penwidth = \cyrnumparameter{penwidth} ; + save High, Low ; + save Vfactor ; Vfactor = .20 ; + save Hfactor ; Hfactor = .85 ; + titlo := ( 0.03, -0.80*Vfactor) -- + ( 0.03, 0.15*Vfactor) -- + ( 0.00, 0.20*Vfactor) {right} .. {right} + ( 1.00, -0.20*Vfactor) -- + ( 0.97, -0.15*Vfactor) -- + ( 0.97, 0.80*Vfactor) ; + pickup pensquare yscaled penwidth xscaled sqrt(2) rotated 90 ; + draw titlo + xysized (Hfactor*OverlayWidth-.5*penwidth,Vfactor*OverlayHeight) + shifted (.5*(OverlayWidth-Hfactor*OverlayWidth),OverlayHeight-(0.5*Vfactor*OverlayHeight)) + withcolor \MPcolor{\cyrnumparameter{titlocolor}} ; + setbounds currentpicture to boundingbox OverlayBox ; +\stopuniqueMPgraphic + +\startuniqueMPgraphic{cyrnum-titlo7} + path titlo ; + save penwidth ; penwidth = \cyrnumparameter{penwidth} ; + save High, Low ; + save Vfactor ; Vfactor = .20 ; + save Hfactor ; Hfactor = .85 ; + titlo := ( 0.05, -0.80*Vfactor) -- + ( 0.05, -0.30*Vfactor) {up} .. {right} + ( 0.07, -0.00*Vfactor) -- + ( 0.93, 0.00*Vfactor) {right} .. {up} + ( 0.95, 0.30*Vfactor) -- + ( 0.95, 0.80*Vfactor) ; + pickup pensquare yscaled (0.66*penwidth) xscaled penwidth ; + draw titlo + xysized (Hfactor*OverlayWidth-2*penwidth,Vfactor*OverlayHeight) + shifted ((.5*penwidth+.5*(OverlayWidth-Hfactor*OverlayWidth)), + (OverlayHeight-(0.7*Vfactor*OverlayHeight))) + withcolor \MPcolor{\cyrnumparameter{titlocolor}} ; + setbounds currentpicture to boundingbox OverlayBox ; +\stopuniqueMPgraphic + +\startuniqueMPgraphic{cyrnum-titlo8} + path titlo, stroke ; + save penwidth ; penwidth = \cyrnumparameter{penwidth} ; + save High, Low ; + save Vfactor ; Vfactor = .20 ; + save Hfactor ; Hfactor = .85 ; + titlo := ( 0.15, -0.10*Vfactor) {dir 25} ..% tension 8 .. + controls (0.40, 0.50) and (0.00, 0.35) .. + ( 0.00, -0.00*Vfactor) {down} .. + controls (0.00, -0.30) and (0.10, -0.25) .. + % ( 0.10, -0.20*Vfactor) {right} .. tension 4 .. {dir -120} + ( 0.30, -0.90*Vfactor) .. + controls + ( 0.70, 0.20*Vfactor) and + ( 0.97, 0.08*Vfactor) .. + ( 0.97, -0.30*Vfactor) .. tension 6 .. {dir -140} + ( 0.95, -0.90*Vfactor) ; + stroke := ((0.45*Hfactor*OverlayWidth),-0.20*Vfactor*OverlayHeight) .. + ((0.54*Hfactor*OverlayWidth), 0.35*Vfactor*OverlayHeight) --- + ((0.65*Hfactor*OverlayWidth), 0.90*Vfactor*OverlayHeight) {dir -120} .. {dir 30} + % ((0.54*Hfactor*OverlayWidth), 0.35*Vfactor*OverlayHeight) .. + ((0.45*Hfactor*OverlayWidth), 0.90*Vfactor*OverlayHeight) + ; + pickup pensquare yscaled 2 xscaled (0.5*penwidth) rotated 10; + % pickup pensquare yscaled 1 xscaled 2 ; + draw titlo + xysized (Hfactor*OverlayWidth,Vfactor*OverlayHeight) + shifted ((.5*(OverlayWidth-Hfactor*OverlayWidth)), + (OverlayHeight-(0.7*Vfactor*OverlayHeight))) + withcolor \MPcolor{\cyrnumparameter{titlocolor}} ; + pickup pensquare yscaled 2 xscaled (0.5*penwidth) rotated 70; + draw stroke + % xysized (Hfactor*OverlayWidth,Vfactor*OverlayHeight) + shifted ((.6*(OverlayWidth-Hfactor*OverlayWidth)), + (OverlayHeight-Vfactor*OverlayHeight)) + withcolor \MPcolor{\cyrnumparameter{titlocolor}} ; + ; + setbounds currentpicture to boundingbox OverlayBox ; +\stopuniqueMPgraphic + +\startuniqueMPgraphic{cyrnum-titlo9} + path titlo ; + save penwidth ; penwidth = \cyrnumparameter{penwidth} ; + save High, Low ; + save Vfactor ; Vfactor = .10 ; + save Hfactor ; Hfactor = .85 ; + titlo := ( 0.05, -0.40*Vfactor) -- + ( 0.05, 0.00*Vfactor) -- + ( 0.95, 0.00*Vfactor) -- + ( 0.95, -0.40*Vfactor) ; + pickup pensquare yscaled (2*penwidth/3) xscaled penwidth ; + draw titlo + xysized (Hfactor*OverlayWidth-2*penwidth,Vfactor*OverlayHeight) + shifted ((.5*penwidth+.5*(OverlayWidth-Hfactor*OverlayWidth)), + (OverlayHeight-(0.7*Vfactor*OverlayHeight))) + withcolor \MPcolor{\cyrnumparameter{titlocolor}} ; + setbounds currentpicture to boundingbox OverlayBox ; +\stopuniqueMPgraphic + +%D The \METAPOST\ titlo is drawn as an overlay which in turn +%D serves as the background for a dedicated \type{\framed} macro. +%D This titlo command is accessible in protected mode as +%D \type{\cyrnumdrawtitlo}, which is also called by the +%D \LUA\ functions. + +\defineoverlay[cyrnum-titlo-overlay1][\uniqueMPgraphic{cyrnum-titlo1}] +\defineoverlay[cyrnum-titlo-overlay2][\uniqueMPgraphic{cyrnum-titlo2}] +\defineoverlay[cyrnum-titlo-overlay3][\uniqueMPgraphic{cyrnum-titlo3}] +\defineoverlay[cyrnum-titlo-overlay4][\uniqueMPgraphic{cyrnum-titlo4}] +\defineoverlay[cyrnum-titlo-overlay5][\uniqueMPgraphic{cyrnum-titlo5}] +\defineoverlay[cyrnum-titlo-overlay6][\uniqueMPgraphic{cyrnum-titlo6}] +\defineoverlay[cyrnum-titlo-overlay7][\uniqueMPgraphic{cyrnum-titlo7}] +\defineoverlay[cyrnum-titlo-overlay8][\uniqueMPgraphic{cyrnum-titlo8}] +\defineoverlay[cyrnum-titlo-overlay9][\uniqueMPgraphic{cyrnum-titlo9}] + +\defineframed[cyrnum_titloframe][ + location=low, + frame=off, + background=cyrnum-titlo-overlay\cyrnumparameter{titlomode}, +] + +%D \macros +%D {cyrnumdrawtitlo} +%D +%D The macro \type{\cyrnumdrawtitlo} allows for arbitrary titlo +%D placement which might be useful for other text elements besides +%D plain numbers, e.~g. abbreviations {\italic\letterampersand}c. + +\let\cyrnumdrawtitlo\cyrnum_titloframe + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%D \docsection{User level interface} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%D \macros +%D {definecyrnum} +%D +%D User interface to the main conversion routines. The definition +%D macro autogenerates the primary user-level macro, which in turn +%D relies \type{\setupcyrnum} for argument processing (see above on +%D \at{page}[setupdef]). +%D +%D Example usage: +%D +%D \starttyping +%D \definecyrnum[titlofree] +%D \setupcyrnum [titlofree][titlo=no] +%D \starttext +%D \titlofree{42} +%D \stoptext +%D \stoptyping + +\unexpanded\def\cyrnum_cmd[#id]{% + \edef\currentcyrnum{#id}% + \dosingleempty\cyrnum_cmd_parms% +} + +\def\cyrnum_cmd_parms[#parms]{% + \begingroup + \setupcyrnum[\currentcyrnum][#parms]% + \cyrnumparameter{command}\begingroup + \cyrnum_cmd_content% +} + +\def\cyrnum_cmd_content#num{% + \ctxcommand{cyrillicnumerals(\number#num)}% + \endgroup + \endgroup% +} + +%D \macros +%D {setupcyrnum} +%D +%D The \type{\setupcyrnum} and \type{\definecyrnum} macros are +%D autogenerated via the namespace. + +\setupcyrnum[ + \v!dots=\v!yes, % yes|no + \v!dotsymbol=·, + \v!penwidth=.66pt, + \v!preferhundredk=no, + \v!command=, + \v!titlocolor=black, + \v!titlolocation=\v!middle, % final|middle -- only effective if using the font’s titlo + \v!titlomode=5, + \v!titlospan=3, % n|all + \v!titlo=\v!mp, % font|mp|no +] + +%D \macros +%D {cyrnum} +%D +%D The default user macro is defined as \type{\cyrnum}. + +\definecyrnum[\v!cyrnum] + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%D \docsection{Conversion routines} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%D \macros +%D {cyrillicnumerals,Cyrillicnumerals} +%D +%D Conforming to the standard \CONTEXT\ naming scheme as employed +%D with number conversion macros, we define two macros for use with +%D conversions. As there is no definition for uppercase conversion, +%D the macro \type{\Cyrillicnumerals} exists only for compatibility +%D reasons. +%D +%D Also, we setup two corresponding conversions \type{cyr} and +%D \type{Cyr} for use with e.g. enumerations, headings, counters +%D {\italic\letterampersand}c. Instead of these predefined ones +%D the user may consider defining a dedicated conversion routine +%D for each purpose: + +%D \starttyping +%D \definecyrnum [mycyrnum] [titlo=mp,titlomode=7,titlospan=all,penwidth=2] +%D \defineconversion[myconversion][\mycyrnum] +%D +%D \setuphead[section][conversion=myconversion] +%D \stoptyping + +\definecyrnum[\v!cyrillicnumerals] +\definecyrnum[\v!Cyrillicnumerals] + +\defineconversion[cyrillicnumerals][\cyrillicnumerals] +\defineconversion[Cyrillicnumerals][\Cyrillicnumerals] +\defineconversion[cyr] [\cyrillicnumerals] +\defineconversion[Cyr] [\Cyrillicnumerals] + +% \protect \endinput + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Fun %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\def\peano#num{\ctxcommand{peanonumerals(\number#num)}} +\defineconversion[peano][\peano] + +\def\church#num{\ctxcommand{churchnumerals(\number#num)}} +\defineconversion[church][\church] + +\protect \endinput + +% vi:ft=context:fo=co:ts=2:expandtab:sw=2 |