@@ -2,6 +2,8 @@ local nodefactory = require("types.node")
22local hb = require (" justenoughharfbuzz" )
33local ot = require (" core.opentype-parser" )
44local syms = require (" packages.math.unicode-symbols" )
5+ local mathvariants = require (" packages.math.unicode-mathvariants" )
6+ local convertMathVariantScript = mathvariants .convertMathVariantScript
57
68local atomType = syms .atomType
79local symbolDefaults = syms .symbolDefaults
@@ -19,32 +21,6 @@ local mathMode = {
1921 scriptScriptCramped = 7 ,
2022}
2123
22- local scriptType = {
23- upright = 1 ,
24- bold = 2 , -- also have Greek and digits
25- italic = 3 , -- also have Greek
26- boldItalic = 4 , -- also have Greek
27- script = 5 ,
28- boldScript = 6 ,
29- fraktur = 7 ,
30- boldFraktur = 8 ,
31- doubleStruck = 9 , -- also have digits
32- sansSerif = 10 , -- also have digits
33- sansSerifBold = 11 , -- also have Greek and digits
34- sansSerifItalic = 12 ,
35- sansSerifBoldItalic = 13 , -- also have Greek
36- monospace = 14 , -- also have digits
37- }
38-
39- local mathVariantToScriptType = function (attr )
40- return attr == " normal" and scriptType .upright
41- or attr == " bold" and scriptType .bold
42- or attr == " italic" and scriptType .italic
43- or attr == " bold-italic" and scriptType .boldItalic
44- or attr == " double-struck" and scriptType .doubleStruck
45- or SU .error (' Invalid value "' .. attr .. ' " for option mathvariant' )
46- end
47-
4824local function isDisplayMode (mode )
4925 return mode <= 1
5026end
@@ -61,50 +37,6 @@ local function isScriptScriptMode (mode)
6137 return mode == mathMode .scriptScript or mode == mathMode .scriptScriptCramped
6238end
6339
64- local mathScriptConversionTable = {
65- capital = {
66- [scriptType .upright ] = function (codepoint )
67- return codepoint
68- end ,
69- [scriptType .bold ] = function (codepoint )
70- return codepoint + 0x1D400 - 0x41
71- end ,
72- [scriptType .italic ] = function (codepoint )
73- return codepoint + 0x1D434 - 0x41
74- end ,
75- [scriptType .boldItalic ] = function (codepoint )
76- return codepoint + 0x1D468 - 0x41
77- end ,
78- [scriptType .doubleStruck ] = function (codepoint )
79- return codepoint == 0x43 and 0x2102
80- or codepoint == 0x48 and 0x210D
81- or codepoint == 0x4E and 0x2115
82- or codepoint == 0x50 and 0x2119
83- or codepoint == 0x51 and 0x211A
84- or codepoint == 0x52 and 0x211D
85- or codepoint == 0x5A and 0x2124
86- or codepoint + 0x1D538 - 0x41
87- end ,
88- },
89- small = {
90- [scriptType .upright ] = function (codepoint )
91- return codepoint
92- end ,
93- [scriptType .bold ] = function (codepoint )
94- return codepoint + 0x1D41A - 0x61
95- end ,
96- [scriptType .italic ] = function (codepoint )
97- return codepoint == 0x68 and 0x210E or codepoint + 0x1D44E - 0x61
98- end ,
99- [scriptType .boldItalic ] = function (codepoint )
100- return codepoint + 0x1D482 - 0x61
101- end ,
102- [scriptType .doubleStruck ] = function (codepoint )
103- return codepoint + 0x1D552 - 0x61
104- end ,
105- },
106- }
107-
10840local mathCache = {}
10941
11042local function retrieveMathTable (font )
@@ -952,16 +884,7 @@ function elements.text:_init (kind, attributes, script, text)
952884 self .script = script
953885 self .text = text
954886 if self .script ~= " upright" then
955- local converted = " "
956- for _ , uchr in luautf8 .codes (self .text ) do
957- local dst_char = luautf8 .char (uchr )
958- if uchr >= 0x41 and uchr <= 0x5A then -- Latin capital letter
959- dst_char = luautf8 .char (mathScriptConversionTable .capital [self .script ](uchr ))
960- elseif uchr >= 0x61 and uchr <= 0x7A then -- Latin non-capital letter
961- dst_char = luautf8 .char (mathScriptConversionTable .small [self .script ](uchr ))
962- end
963- converted = converted .. dst_char
964- end
887+ local converted = convertMathVariantScript (self .text , self .script )
965888 self .originalText = self .text
966889 self .text = converted
967890 end
@@ -1521,8 +1444,6 @@ end
15211444
15221445elements .mathMode = mathMode
15231446elements .atomType = atomType
1524- elements .scriptType = scriptType
1525- elements .mathVariantToScriptType = mathVariantToScriptType
15261447elements .symbolDefaults = symbolDefaults
15271448elements .newSubscript = newSubscript
15281449elements .newUnderOver = newUnderOver
0 commit comments