summaryrefslogtreecommitdiff
path: root/Build/source/texk/tex4htk/java/HtSpk.java
blob: 1f0e9c0a0bda70da3468552e9bbd1d34862b4dfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package tex4ht;
import org.w3c.dom.*;
public class HtSpk {
  public static void fracLevel(Node dom) {
   setFracLevel(dom.getFirstChild(), 0);
}
private static int setFracLevel(Node node, int cont) {
  int level = 0;
  String clName = null;
  if (node.hasChildNodes()) {
    if (node.hasAttributes()) {
      Node cl = node.getAttributes().getNamedItem("class");
      if (cl != null) { clName = cl.getNodeValue(); }
    }
    NodeList children = node.getChildNodes();
int max = 0;
for (int i = 0; i < children.getLength(); i++) {
   Node child = children.item(i);
   if (child.getNodeType() == Node.ELEMENT_NODE) {
      int d = setFracLevel(child,
           (clName != null) &&
            clName.equals("continuous-mfrac")?
            2 :
            ((clName != null) &&
              clName.equals("continuous-mfrac")?
                (cont-1) : cont)
        );
      if (d > max) { max = d; }
}  }
level += max;

    if( clName != null ){
      if( clName.equals("msub") || clName.equals("msup") ||
    clName.equals("msubsup")
) {
   return 0;
}

      if( clName.equals("continuous-mfrac") ) {
   if( cont > 0 ){
     Node child = node.getLastChild();
if (child.getNodeType() == Node.ELEMENT_NODE) {
   Node cls = child.getAttributes() .getNamedItem("class");
   if (cls != null) {
      String clsName = cls.getNodeValue();
      if ( clsName.equals("begin-end")) {
         node.removeChild( child  );
}  }  }

   } else { for (int i = 0; i < children.getLength(); i++) {
  Node child = children.item(i);
  if (child.getNodeType() == Node.ELEMENT_NODE) {
    Node cls = child.getAttributes()
                   .getNamedItem("class");
    if (cls != null) {
       String clsName = cls.getNodeValue();
       if ( clsName.equals("begin-end")) {
          child = child.getFirstChild();
          String s = child.getNodeValue();
          s = s.replaceFirst("begin", "begin continued");
          s = s.replaceFirst("end", "end continued");
          ((org.w3c.dom.Text) child).setData(s);
} } } }
 } 
   return 0;
}

      if (clName.equals("mfrac")) {
        if( cont > 0 ){
          Node child = node.getLastChild();
if (child.getNodeType() == Node.ELEMENT_NODE) {
   Node cls = child.getAttributes() .getNamedItem("class");
   if (cls != null) {
      String clsName = cls.getNodeValue();
      if ( clsName.equals("begin-end")) {
         node.removeChild( child  );
}  }  }

        } else if( level > 0 ){
          for (int i = 0; i < children.getLength(); i++) {
  Node child = children.item(i);
  if (child.getNodeType() == Node.ELEMENT_NODE) {
    Node cls = child.getAttributes()
                    .getNamedItem("class");
    if (cls != null) {
      String clsName = cls.getNodeValue();
      if (clsName.equals("begin-end")) {
         child = child.getFirstChild();
         String s = child.getNodeValue();
         String bg = "", ov = "", en = "";
         for(int j=0; j<level; j++){
            bg += " begin "; ov += " over "; en += " end ";
         }
         s = s.replaceFirst("begin", bg + "begin");
         s = s.replaceFirst("over", ov + "over");
         s = s.replaceFirst("end", en + "end");
         ((org.w3c.dom.Text) child).setData(s);
} } } }

        }
        level++;
  } } }
  return level;
}

  public static void scriptLevel(Node dom) {
   setScriptLevel(dom.getFirstChild(), "");
}
private static void setScriptLevel(Node node, String prefix) {
  String clName = null;
  if (node.hasChildNodes()) {
    if (node.hasAttributes()) {
      Node cl = node.getAttributes().getNamedItem("class");
      if (cl != null) {
        clName = cl.getNodeValue();
        if( clName.equals("mrow-sub")
            ||
            clName.equals("mrow-super")
        ){
          if( !prefix.equals("") ){
  Node child = node.getFirstChild();
if( (child.getNodeType() == Node.ELEMENT_NODE)
    &&
    child.hasAttributes()
){
   Node cls = child.getAttributes().getNamedItem("class");
   if (cls != null) {
      String clsName = cls.getNodeValue();
      if ( clsName.equals("begin-script")
           ||
           clsName.equals("mid-script")
      ) {
         child = child.getFirstChild();
         String s = child.getNodeValue();
         ((org.w3c.dom.Text) child).setData( prefix + s );
}  }  }

}
if( clName.equals( "mrow-sub" ) ){ prefix += " sub "; }
else
if( clName.equals( "mrow-super" ) ){ prefix += " super "; }

        } else if(
           clName.equals("msqrt")
        ){  prefix = ""; }
    } }
    NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
   Node child = children.item(i);
   if (child.getNodeType() == Node.ELEMENT_NODE) {
      setScriptLevel(child, prefix);
}  }

} }

  public static void rootLevel(Node dom) {
   setRootLevel(dom.getFirstChild());
}
private static int setRootLevel( Node node ){
  int level = 0;
  String clName = null;
  if (node.hasChildNodes()) {
    if (node.hasAttributes()) {
      Node cl = node.getAttributes().getNamedItem("class");
      if (cl != null) { clName = cl.getNodeValue(); }
    }
    NodeList children = node.getChildNodes();
int max = 0;
for (int i = 0; i < children.getLength(); i++) {
  Node child = children.item(i);
  if (child.getNodeType() == Node.ELEMENT_NODE) {
    int d = setRootLevel(child);
    if( d > max ){ max = d; }
} }
level += max;

    if( clName != null ){
      if( clName.equals("msub") || clName.equals("msup") ||
    clName.equals("msubsup")
) {
   return 0;
}

      if( clName.equals("msqrt") || clName.equals("root") ){
        for (int i = 0; i < children.getLength(); i++) {
  Node child = children.item(i);
  if (child.getNodeType() == Node.ELEMENT_NODE) {
    Node cls = child.getAttributes()
                    .getNamedItem("class");
    if (cls != null) {
      String clsName = cls.getNodeValue();
      if( clsName.equals("begin-root")
          || clsName.equals("mid-root")
          || clsName.equals("end-root")
      ){
         child = child.getFirstChild();
         String s = child.getNodeValue();
         String nested = "";
         for(int j=0; j<level; j++){
            nested += " nested ";
         }
         ((org.w3c.dom.Text) child).setData( nested + s);
} } } }

        level++;
  } } }
  return level;
}

}