Annotation of Amaya/amaya/MathMLbuilder.c, revision 1.190
1.1 cvs 1: /*
2: *
1.180 vatton 3: * (c) COPYRIGHT INRIA and W3C, 1996-2003
1.1 cvs 4: * Please first read the full copyright statement in file COPYRIGHT.
5: *
6: */
1.159 quint 7:
1.1 cvs 8: /*
9: * MathMLbuilder
10: *
11: * Author: V. Quint
12: */
13:
14: #define THOT_EXPORT extern
1.4 cvs 15: #include "amaya.h"
1.25 cvs 16: #include "css.h"
1.59 cvs 17: #include "html2thot_f.h"
1.25 cvs 18: #include "MathML.h"
1.169 quint 19: #include "HTML.h"
1.25 cvs 20: #include "parser.h"
1.59 cvs 21: #include "styleparser_f.h"
22: #include "style.h"
23: #include "undo.h"
1.133 cvs 24: #include "Xml2thot_f.h"
1.109 cvs 25:
1.106 cvs 26: /* Define a pointer to let parser functions access the Math entity table */
27: extern XmlEntity *pMathEntityTable;
1.1 cvs 28:
29: #define MaxMsgLength 200
30:
1.12 cvs 31: #include "HTMLtable_f.h"
1.29 cvs 32: #include "Mathedit_f.h"
33: #include "styleparser_f.h"
34: #include "fetchXMLname_f.h"
1.1 cvs 35:
36: /*----------------------------------------------------------------------
1.170 quint 37: IsLargeOp
38: Return TRUE if character is listed as a largeop in the MathML 2.0
39: Operator dictionary (appendix F.5)
40: ----------------------------------------------------------------------*/
1.171 carcone 41: static ThotBool IsLargeOp (CHAR_T character, char script)
1.170 quint 42: {
43: #ifdef _I18N_
1.177 quint 44: if (character == 0x22C1 || /* Vee */
45: character == 0x2296 || /* CircleMinus */
46: character == 0x2295 || /* CirclePlus */
47: character == 0x2211 || /* Sum */
48: character == 0x22C3 || /* Union */
49: character == 0x228E || /* UnionPlus */
50: character == 0x2232 || /* ClockwiseContourIntegral */
51: character == 0x222E || /* ContourIntegral */
52: character == 0x2233 || /* CounterClockwiseContourIntegral */
53: character == 0x222F || /* DoubleContourIntegral */
54: character == 0x222B || /* Integral */
55: character == 0x22C0 || /* Wedge */
56: character == 0x2297 || /* CircleTimes */
57: character == 0x2210 || /* Coproduct */
58: character == 0x220F || /* Product */
59: character == 0x22C2 ) /* Intersection */
1.170 quint 60: #else
61: if ((script == 'G') &&
62: (character == 229 || character == 213)) /* large Sigma or Pi */
63: #endif
1.177 quint 64: /* it's a large operator */
1.170 quint 65: return TRUE;
66: else
67: return FALSE;
68: }
69:
70: /*----------------------------------------------------------------------
1.177 quint 71: IsStretchyFence
72: Return TRUE if character is listed as a stretchy fence in the MathML 2.0
1.170 quint 73: Operator dictionary (appendix F.5)
74: ----------------------------------------------------------------------*/
1.177 quint 75: static ThotBool IsStretchyFence (CHAR_T character, char script)
1.170 quint 76: {
77: if ((
78: #ifndef _I18N_
79: (script == 'L') &&
80: #endif
81: (character == '(' || character == ')' ||
82: character == '[' || character == ']' ||
83: character == '{' || character == '}' ||
1.177 quint 84: character == '|')) || /* strangely enough, appendix F.5 does not
85: consider this character as a fence */
1.170 quint 86: (
87: #ifdef _I18N_
1.177 quint 88: (character == 0x2329 || /* LeftAngleBracket */
89: /* LeftBracketingBar ??? */
90: character == 0x2308 || /* LeftCeiling */
91: character == 0x301A || /* LeftDoubleBracket */
92: /* LeftDoubleBracketingBar ??? */
93: character == 0x230A || /* LeftFloor */
94: character == 0x232A || /* RightAngleBracket */
95: /* RightBracketingBar ??? */
96: character == 0x2309 || /* RightCeiling */
97: character == 0x301B || /* RightDoubleBracket */
98: /* RightDoubleBracketingBar ??? */
99: character == 0x230B ) /* RightFloor */
1.170 quint 100: #else
101: (script == 'G') &&
1.177 quint 102: (character == 225 || character == 241) /* left and right angle bracket*/
1.170 quint 103: #endif
104: ))
105: return TRUE;
106: else
107: return FALSE;
108: }
109:
110: /*----------------------------------------------------------------------
1.1 cvs 111: MapMathMLAttribute
112: Search in the Attribute Mapping Table the entry for the
113: attribute of name Attr and returns the corresponding Thot attribute type.
114: ----------------------------------------------------------------------*/
1.120 cvs 115: void MapMathMLAttribute (char *attrName, AttributeType *attrType,
116: char *elementName, ThotBool *level, Document doc)
1.1 cvs 117: {
1.68 cvs 118: attrType->AttrSSchema = GetMathMLSSchema (doc);
1.170 quint 119: MapXMLAttribute (MATH_TYPE, attrName, elementName, level, doc,
120: &(attrType->AttrTypeNum));
1.1 cvs 121: }
122:
123: /*----------------------------------------------------------------------
124: MapMathMLAttributeValue
125: Search in the Attribute Value Mapping Table the entry for the attribute
126: ThotAtt and its value AttrVal. Returns the corresponding Thot value.
127: ----------------------------------------------------------------------*/
1.150 vatton 128: void MapMathMLAttributeValue (char *attVal, AttributeType attrType, int *value)
1.1 cvs 129: {
1.150 vatton 130: MapXMLAttributeValue (MATH_TYPE, attVal, attrType, value);
1.1 cvs 131: }
132:
133: /*----------------------------------------------------------------------
1.130 carcone 134: MathMLEntityCreated
135: ----------------------------------------------------------------------*/
136: void MathMLEntityCreated (unsigned char *entityValue, Language lang,
137: char *entityName, Document doc)
138: {
139: }
140:
141: /*----------------------------------------------------------------------
1.1 cvs 142: ElementNeedsPlaceholder
143: returns TRUE if element el needs a sibling placeholder.
144: ----------------------------------------------------------------------*/
1.18 cvs 145: ThotBool ElementNeedsPlaceholder (Element el)
1.1 cvs 146: {
147: ElementType elType;
1.138 cvs 148: Element child, parent, sibling;
1.18 cvs 149: ThotBool ret;
1.139 quint 150:
1.1 cvs 151: ret = FALSE;
152: elType = TtaGetElementType (el);
1.43 cvs 153: if (elType.ElTypeNum == MathML_EL_MS ||
1.39 cvs 154: elType.ElTypeNum == MathML_EL_MFRAC ||
1.54 cvs 155: elType.ElTypeNum == MathML_EL_BevelledMFRAC ||
1.39 cvs 156: elType.ElTypeNum == MathML_EL_MSQRT ||
157: elType.ElTypeNum == MathML_EL_MROOT ||
158: elType.ElTypeNum == MathML_EL_MSTYLE ||
159: elType.ElTypeNum == MathML_EL_MERROR ||
160: elType.ElTypeNum == MathML_EL_MPADDED ||
161: elType.ElTypeNum == MathML_EL_MPHANTOM ||
162: elType.ElTypeNum == MathML_EL_MFENCED ||
1.1 cvs 163: elType.ElTypeNum == MathML_EL_MF ||
164: elType.ElTypeNum == MathML_EL_MSUB ||
165: elType.ElTypeNum == MathML_EL_MSUP ||
1.39 cvs 166: elType.ElTypeNum == MathML_EL_MSUBSUP ||
1.1 cvs 167: elType.ElTypeNum == MathML_EL_MUNDER ||
168: elType.ElTypeNum == MathML_EL_MOVER ||
169: elType.ElTypeNum == MathML_EL_MUNDEROVER ||
1.28 cvs 170: elType.ElTypeNum == MathML_EL_MMULTISCRIPTS ||
1.39 cvs 171: elType.ElTypeNum == MathML_EL_MTABLE ||
172: elType.ElTypeNum == MathML_EL_MACTION)
1.1 cvs 173: ret = TRUE;
1.138 cvs 174: else if (elType.ElTypeNum == MathML_EL_MROW)
1.183 quint 175: /* a mrow needs a place holder only if it's not the only child of
1.138 cvs 176: an element such as Numerator, Denominator, RootBase, Index, etc. */
177: {
178: ret = TRUE;
179: sibling = el; TtaNextSibling (&sibling);
180: if (!sibling)
181: {
1.139 quint 182: sibling = el; TtaPreviousSibling (&sibling);
1.138 cvs 183: if (!sibling)
1.183 quint 184: /* the MROW element has no sibling */
1.138 cvs 185: {
186: parent = TtaGetParent (el);
187: if (parent)
188: {
189: elType = TtaGetElementType (parent);
190: if (elType.ElTypeNum == MathML_EL_Numerator ||
191: elType.ElTypeNum == MathML_EL_Denominator ||
192: elType.ElTypeNum == MathML_EL_RootBase ||
193: elType.ElTypeNum == MathML_EL_Index ||
194: elType.ElTypeNum == MathML_EL_FencedExpression ||
195: elType.ElTypeNum == MathML_EL_Base ||
196: elType.ElTypeNum == MathML_EL_Subscript ||
197: elType.ElTypeNum == MathML_EL_Superscript ||
198: elType.ElTypeNum == MathML_EL_UnderOverBase ||
199: elType.ElTypeNum == MathML_EL_Underscript ||
200: elType.ElTypeNum == MathML_EL_Overscript ||
201: elType.ElTypeNum == MathML_EL_MultiscriptBase ||
202: elType.ElTypeNum == MathML_EL_MSubscript ||
203: elType.ElTypeNum == MathML_EL_MSuperscript)
1.183 quint 204: {
205: /* no place holder required, except if the MROW element
206: actually represent a prenthesized block */
207: ret = FALSE;
208: child = TtaGetFirstChild (el);
209: if (child != NULL)
210: {
211: elType = TtaGetElementType (child);
212: if (elType.ElTypeNum == MathML_EL_MF)
213: /* the first child of the MROW element is a MF */
214: /* The MROW element needs a placeholder */
215: ret = TRUE;
216: }
217: }
1.138 cvs 218: }
219: }
220: }
221: }
1.158 quint 222: else if (elType.ElTypeNum == MathML_EL_MO ||
223: elType.ElTypeNum == MathML_EL_OpeningFence ||
224: elType.ElTypeNum == MathML_EL_ClosingFence ||
225: elType.ElTypeNum == MathML_EL_FencedSeparator)
1.138 cvs 226: /* an operator that contains a single Symbol needs a placeholder,
227: except when it is in a Base or UnderOverBase */
228: {
229: child = TtaGetFirstChild (el);
230: if (child != NULL)
1.1 cvs 231: {
1.138 cvs 232: elType = TtaGetElementType (child);
233: if (elType.ElTypeNum == MathML_EL_SYMBOL_UNIT)
234: {
1.1 cvs 235: ret = TRUE;
236: parent = TtaGetParent (el);
237: if (parent != NULL)
238: {
1.138 cvs 239: elType = TtaGetElementType (parent);
240: if (elType.ElTypeNum == MathML_EL_Base ||
241: elType.ElTypeNum == MathML_EL_UnderOverBase)
1.139 quint 242: ret = FALSE;
243: }
244: }
245: }
246: }
247: else if (elType.ElTypeNum == MathML_EL_MSPACE)
248: {
249: /* in principle mspace needs a placeholder sibling */
250: ret = TRUE;
251: /* but if it's the only child of a mstyle element, the placeholders
252: would change the height and width of the mstyle. Consider for
253: instance:
254: <mstyle background="#000099">
255: <mspace depth="2mm" width=".2in"/>
256: </mstyle> */
257: sibling = el; TtaNextSibling (&sibling);
258: if (!sibling)
259: {
260: sibling = el; TtaPreviousSibling (&sibling);
261: if (!sibling)
262: {
263: parent = TtaGetParent (el);
264: if (parent)
265: {
266: elType = TtaGetElementType (parent);
267: if (elType.ElTypeNum == MathML_EL_MSTYLE)
1.138 cvs 268: ret = FALSE;
1.1 cvs 269: }
1.138 cvs 270: }
1.1 cvs 271: }
1.138 cvs 272: }
1.1 cvs 273: return ret;
274: }
1.132 cvs 275:
1.1 cvs 276: /*----------------------------------------------------------------------
277: CreatePlaceholders
278: ----------------------------------------------------------------------*/
279: static void CreatePlaceholders (Element el, Document doc)
280: {
1.132 cvs 281: Element sibling, prev, constr, child;
282: Attribute attr;
283: ElementType elType;
284: AttributeType attrType;
285: ThotBool create, stretchableSubsup;
1.1 cvs 286:
1.55 cvs 287: if (!el)
288: return;
1.2 cvs 289: elType.ElSSchema = GetMathMLSSchema (doc);
1.1 cvs 290: prev = NULL;
291: create = TRUE;
292: sibling = el;
293: while (sibling != NULL)
294: {
295: if (!ElementNeedsPlaceholder (sibling))
296: create = FALSE;
297: else
298: {
299: if (sibling == el)
300: /* first element */
301: {
302: elType = TtaGetElementType (sibling);
303: if (elType.ElTypeNum == MathML_EL_MF)
304: /* the first element is a MF. Don't create a placeholder
305: before */
306: create = FALSE;
307: else if (elType.ElTypeNum == MathML_EL_MROW)
308: /* the first element is a MROW */
309: {
310: child = TtaGetFirstChild (sibling);
311: if (child != NULL)
312: {
313: elType = TtaGetElementType (child);
314: if (elType.ElTypeNum != MathML_EL_MF)
315: /* the first child of the MROW element is not a MF */
316: /* Don't create a placeholder before */
317: create = FALSE;
318: }
319: }
320: }
321: if (create)
322: {
323: elType.ElTypeNum = MathML_EL_Construct;
324: constr = TtaNewElement (doc, elType);
325: TtaInsertSibling (constr, sibling, TRUE, doc);
326: attrType.AttrSSchema = elType.ElSSchema;
1.22 cvs 327: attrType.AttrTypeNum = MathML_ATTR_IntPlaceholder;
1.1 cvs 328: attr = TtaNewAttribute (attrType);
329: TtaAttachAttribute (constr, attr, doc);
1.55 cvs 330: TtaSetAttributeValue (attr, MathML_ATTR_IntPlaceholder_VAL_yes_,
331: constr, doc);
1.1 cvs 332: }
333: create = TRUE;
334: }
335: prev = sibling;
336: TtaNextSibling (&sibling);
337: }
338: if (prev != NULL && create)
339: {
1.132 cvs 340: stretchableSubsup = FALSE;
1.1 cvs 341: elType = TtaGetElementType (prev);
1.95 cvs 342: /* don't insert a placeholder after the last element if it's a MF */
343: if (elType.ElTypeNum == MathML_EL_MF)
1.1 cvs 344: create = FALSE;
345: else if (elType.ElTypeNum == MathML_EL_MROW)
346: /* the last element is a MROW */
347: {
348: child = TtaGetLastChild (prev);
349: if (child != NULL)
350: {
351: elType = TtaGetElementType (child);
352: if (elType.ElTypeNum != MathML_EL_MF)
353: /* the last child of the MROW element is not a MF */
354: /* Don't create a placeholder before */
355: create = FALSE;
356: }
357: }
1.132 cvs 358: else if (elType.ElTypeNum == MathML_EL_MSUBSUP ||
359: elType.ElTypeNum == MathML_EL_MSUB ||
360: elType.ElTypeNum == MathML_EL_MSUP ||
361: elType.ElTypeNum == MathML_EL_MUNDEROVER ||
362: elType.ElTypeNum == MathML_EL_MUNDER ||
363: elType.ElTypeNum == MathML_EL_MUNDEROVER)
364: {
365: attrType.AttrSSchema = elType.ElSSchema;
366: attrType.AttrTypeNum = MathML_ATTR_IntVertStretch;
367: if (TtaGetAttribute (prev, attrType))
368: stretchableSubsup = TRUE;
369: }
370:
1.1 cvs 371: if (create)
372: {
1.132 cvs 373: if (stretchableSubsup)
374: elType.ElTypeNum = MathML_EL_Construct1;
375: else
376: elType.ElTypeNum = MathML_EL_Construct;
1.1 cvs 377: constr = TtaNewElement (doc, elType);
378: TtaInsertSibling (constr, prev, FALSE, doc);
379: attrType.AttrSSchema = elType.ElSSchema;
1.22 cvs 380: attrType.AttrTypeNum = MathML_ATTR_IntPlaceholder;
1.1 cvs 381: attr = TtaNewAttribute (attrType);
382: TtaAttachAttribute (constr, attr, doc);
1.55 cvs 383: TtaSetAttributeValue (attr, MathML_ATTR_IntPlaceholder_VAL_yes_,
384: constr, doc);
1.132 cvs 385: }
1.1 cvs 386: }
387: }
388:
389: /*----------------------------------------------------------------------
1.95 cvs 390: NextNotComment
391: Return the next sibling of element el that is not an XMLcomment element.
392: Return el itself if it's not a comment.
1.1 cvs 393: ----------------------------------------------------------------------*/
1.95 cvs 394: static void NextNotComment (Element* el, Element* prev)
1.1 cvs 395: {
396: ElementType elType;
397:
398: if (*el == NULL)
399: return;
400: elType = TtaGetElementType (*el);
1.95 cvs 401: while (*el != NULL && elType.ElTypeNum == MathML_EL_XMLcomment)
1.1 cvs 402: {
403: *prev = *el;
404: TtaNextSibling (el);
405: if (*el != NULL)
406: elType = TtaGetElementType (*el);
407: }
408: }
409:
410: /*----------------------------------------------------------------------
1.189 quint 411: SetIntMovelimitsAttr
412: Put a IntMovelimits attribute on element el (which is a munder, mover
413: or munderover) if the current value of IntDisplaystyle is false and
414: if el contains a MO element that allows limits to be moved.
415: -----------------------------------------------------------------------*/
416: void SetIntMovelimitsAttr (Element el, Document doc)
417: {
418: Element ancestor, child, base, operator, textEl;
419: int value, len;
420: ElementType elType;
421: AttributeType attrType;
422: Attribute attr;
423: Language lang;
424: CHAR_T text[10];
425: char buffer[20];
426: ThotBool movable;
427: #ifndef _I18N_
428: char script;
429: #endif
430:
431: if (el == NULL || doc == 0)
432: return;
433: movable = FALSE;
434:
435: /* first look for an IntDisplaystyle attribute on an ancestor */
436: elType = TtaGetElementType (el);
437: attrType.AttrSSchema = elType.ElSSchema;
438: attrType.AttrTypeNum = MathML_ATTR_IntDisplaystyle;
439: ancestor = el;
440: do
441: {
442: attr = TtaGetAttribute (ancestor, attrType);
443: if (!attr)
444: ancestor = TtaGetParent(ancestor);
445: }
446: while (!attr && ancestor);
447: if (attr)
448: /* there is an ancestor with an attribute IntDisplaystyle */
449: {
450: value = TtaGetAttributeValue (attr);
451: if (value == MathML_ATTR_IntDisplaystyle_VAL_false)
452: /* an ancestor has an attribute IntDisplaystyle = false */
453: {
454: /* Check the operator within the base */
455: child = TtaGetFirstChild (el);
456: base = NULL;
457: do
458: {
459: elType = TtaGetElementType (child);
460: if (elType.ElTypeNum == MathML_EL_UnderOverBase)
461: base = child;
462: else
463: TtaNextSibling (&child);
464: }
465: while (child && !base);
466: if (base)
467: {
468: child = TtaGetFirstChild (base);
469: operator = NULL;
470: do
471: {
472: elType = TtaGetElementType (child);
473: if (elType.ElTypeNum == MathML_EL_MO)
474: operator = child;
475: else
476: TtaNextSibling (&child);
477: }
478: while (child && !operator);
479: if (operator)
480: {
481: attrType.AttrTypeNum = MathML_ATTR_movablelimits;
482: attr = TtaGetAttribute (operator, attrType);
483: if (attr)
484: /* the operator has an attribute movablelimits */
485: {
486: value = TtaGetAttributeValue (attr);
487: if (value == MathML_ATTR_movablelimits_VAL_true)
488: movable = TRUE;
489: }
490: else
491: /* no attribute movablelimits. Look at the content of the
492: operator element */
493: {
494: textEl = TtaGetFirstChild (operator);
495: if (textEl)
496: {
497: elType = TtaGetElementType (textEl);
498: if (elType.ElTypeNum == MathML_EL_TEXT_UNIT)
499: {
500: len = TtaGetElementVolume (textEl);
501: if (len == 3)
502: {
503: TtaGiveTextContent (textEl, buffer, &len, &lang);
504: #ifndef _I18N_
505: script = TtaGetScript (lang);
506: if (script == 'L')
507: #endif
508: {
509: if (!strcmp (buffer, "lim") ||
510: !strcmp (buffer, "max") ||
511: !strcmp (buffer, "min"))
512: movable = TRUE;
513: }
514: }
515: else if (len == 1)
516: {
517: TtaGiveBufferContent (textEl, text, len+1, &lang);
518: #ifdef _I18N_
519: if (text[0] == 0x22C1 /* Vee */ ||
520: text[0] == 0x2296 /* CircleMinus */ ||
521: text[0] == 0x2295 /* CirclePlus */ ||
522: text[0] == 0x2211 /* Sum */ ||
523: text[0] == 0x22C3 /* Union */ ||
524: text[0] == 0x228E /* UnionPlus */ ||
525: text[0] == 0x22C0 /* Wedge */ ||
526: text[0] == 0x2297 /* CircleTimes */ ||
527: text[0] == 0x2210 /* Coproduct */ ||
528: text[0] == 0x220F /* Product */ ||
529: text[0] == 0x22C2 /* Intersection */ ||
530: text[0] == 0x2299 /* CircleDot */ )
531: movable = TRUE;
532: #else
533: script = TtaGetScript (lang);
534: if (script == 'G')
535: /* Adobe Symbol character set */
536: if (text[0] == 197 || text[0] == 229 ||
537: text[0] == 200 || text[0] == 196 ||
538: text[0] == 213 || text[0] == 199)
539: movable = TRUE;
540: #endif
541: }
542: }
543: }
544: }
545: }
546: }
547: }
548: }
549:
550: attrType.AttrTypeNum = MathML_ATTR_IntMovelimits;
551: attr = TtaGetAttribute (el, attrType);
552: if (movable)
553: {
554: if (!attr)
555: {
556: attr = TtaNewAttribute (attrType);
557: TtaAttachAttribute (el, attr, doc);
558: }
559: TtaSetAttributeValue (attr, MathML_ATTR_IntMovelimits_VAL_yes_, el, doc);
560: }
561: else if (attr)
562: TtaRemoveAttribute (el, attr, doc);
563: }
564:
565: /*----------------------------------------------------------------------
566: CheckLargeOp
567: If el is a MO element,
568: if it's a large operator (∑ for instance), put a presentation
569: rule to enlarge the character.
570: ----------------------------------------------------------------------*/
571: void CheckLargeOp (Element el, Document doc)
572: {
573: ElementType elType, contType;
574: Element content, ancestor;
575: AttributeType attrType;
576: Attribute attrLargeop, attr;
577: Language lang;
578: PresentationValue pval;
579: PresentationContext ctxt;
580: CHAR_T text[2];
581: char script;
582: int len, val;
583: ThotBool largeop;
584:
585: elType = TtaGetElementType (el);
586: if (elType.ElTypeNum == MathML_EL_MO)
587: /* the element is a MO */
588: {
589: content = TtaGetFirstChild (el);
590: if (content != NULL)
591: {
592: contType = TtaGetElementType (content);
593: if (contType.ElTypeNum == MathML_EL_TEXT_UNIT)
594: {
595: len = TtaGetElementVolume (content);
596: if (len == 1)
597: /* the MO element contains a single character */
598: {
599: TtaGiveBufferContent (content, text, len+1, &lang);
600: script = TtaGetScript (lang);
601: largeop = FALSE;
602: /* is there an attribute largeop on this MO element? */
603: attrType.AttrSSchema = elType.ElSSchema;
604: attrType.AttrTypeNum = MathML_ATTR_largeop;
605: attrLargeop = TtaGetAttribute (el, attrType);
606: if (attrLargeop)
607: /* there is an attribute largeop. Just take its value */
608: largeop = (TtaGetAttributeValue (attrLargeop) == MathML_ATTR_largeop_VAL_true);
609: else
610: /* no attribute largeop */
611: {
612: /* first look for an IntDisplaystyle attribute on an ancestor */
613: attrType.AttrSSchema = elType.ElSSchema;
614: attrType.AttrTypeNum = MathML_ATTR_IntDisplaystyle;
615: ancestor = el;
616: do
617: {
618: attr = TtaGetAttribute (ancestor, attrType);
619: if (!attr)
620: ancestor = TtaGetParent(ancestor);
621: }
622: while (!attr && ancestor);
623: if (attr)
624: /* there is an ancestor with an attribute IntDisplaystyle */
625: {
626: val = TtaGetAttributeValue (attr);
627: if (val == MathML_ATTR_IntDisplaystyle_VAL_true)
628: /* an ancestor has an attribute IntDisplaystyle = true */
629: /* Look at the symbol */
630: largeop = IsLargeOp (text[0], script);
631: }
632: }
633: ctxt = TtaGetSpecificStyleContext (doc);
634: if (largeop)
635: /* it's a large operator. Make it larger */
636: {
637: ctxt->destroy = FALSE;
638: /* the specific presentation to be created is not a CSS rule */
639: ctxt->cssSpecificity = 0;
640: pval.typed_data.unit = UNIT_PERCENT;
641: pval.typed_data.real = FALSE;
642: pval.typed_data.value = 180;
643: }
644: else
645: /* it's not a large operator, remove the Size presentation rule
646: if it's present */
647: {
648: ctxt->destroy = TRUE;
649: pval.typed_data.value = 0;
650: }
651: TtaSetStylePresentation (PRSize, content, NULL, ctxt, pval);
652: }
653: }
654: }
655: }
656: }
657:
658: /*----------------------------------------------------------------------
659: ApplyDisplaystyle
660: An IntDisplaystyle attribute has been associated with (or removed from)
661: element el.
662: Handle all large operators in the sub tree.
663: Update attribute IntMovelimits for all munder, mover or munderover
664: elements in the subtree
665: ----------------------------------------------------------------------*/
666: static void ApplyDisplaystyle (Element el, Document doc)
667: {
668: ElementType elType;
669: Element child;
670:
671: if (el)
672: {
673: elType = TtaGetElementType (el);
674: if (!strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
675: {
676: if (elType.ElTypeNum == MathML_EL_MO)
677: CheckLargeOp (el, doc);
678: else if (elType.ElTypeNum == MathML_EL_MUNDER ||
679: elType.ElTypeNum == MathML_EL_MOVER ||
680: elType.ElTypeNum == MathML_EL_MUNDEROVER)
681: SetIntMovelimitsAttr (el, doc);
682: }
683: child = TtaGetFirstChild (el);
684: while (child)
685: {
686: ApplyDisplaystyle (child, doc);
687: TtaNextSibling (&child);
688: }
689: }
690: }
691:
692: /*----------------------------------------------------------------------
693: CheckIntDisplaystyle
694: Internal element el has just been created by function
695: CheckMathSubExpressions. If this new element has an implicit (see MathML.S)
696: attribute IntDisplaystyle=false, set the size of large operators and
697: update attribute IntMovelimit in the whole subtree.
698: ----------------------------------------------------------------------*/
699: static void CheckIntDisplaystyle (Element el, Document doc)
700: {
701: ElementType elType;
702:
703: elType = TtaGetElementType (el);
704: if (elType.ElTypeNum == MathML_EL_Index ||
705: elType.ElTypeNum == MathML_EL_Subscript ||
706: elType.ElTypeNum == MathML_EL_Superscript ||
707: elType.ElTypeNum == MathML_EL_Underscript ||
708: elType.ElTypeNum == MathML_EL_Overscript ||
709: elType.ElTypeNum == MathML_EL_PostscriptPairs ||
710: elType.ElTypeNum == MathML_EL_PrescriptPairs)
711: {
712: ApplyDisplaystyle (el, doc);
713: }
714: }
715:
716: /*----------------------------------------------------------------------
1.1 cvs 717: CheckMathSubExpressions
718: Children of element el should be of type type1, type2, and type3.
1.56 cvs 719: If they are not, wrap them in elements of these types.
1.124 cvs 720: If element el has too many or not enough children, return FALSE.
1.1 cvs 721: ----------------------------------------------------------------------*/
1.56 cvs 722: static ThotBool CheckMathSubExpressions (Element el, int type1, int type2, int type3, Document doc)
1.1 cvs 723: {
724: Element child, new, prev;
725: ElementType elType, childType;
1.124 cvs 726: char msgBuffer[200];
1.56 cvs 727: ThotBool result;
1.1 cvs 728:
1.56 cvs 729: result = TRUE;
1.2 cvs 730: elType.ElSSchema = GetMathMLSSchema (doc);
1.1 cvs 731: child = TtaGetFirstChild (el);
732: prev = NULL;
1.95 cvs 733: NextNotComment (&child, &prev);
1.56 cvs 734: if (type1 == 0)
1.1 cvs 735: {
1.56 cvs 736: if (child)
737: /* no child expected and there is one, error */
1.124 cvs 738: {
739: sprintf (msgBuffer, "No subexpression allowed in %s",
740: TtaGetElementTypeName (TtaGetElementType (el)));
741: XmlParseError (errorParsing, msgBuffer, 0);
742: result = FALSE;
743: }
1.56 cvs 744: }
745: else
746: if (!child)
747: /* a first child is expected and it's missing */
1.124 cvs 748: {
749: sprintf (msgBuffer, "Missing subexpression in %s",
750: TtaGetElementTypeName (TtaGetElementType (el)));
751: XmlParseError (errorParsing, msgBuffer, 0);
752: result = FALSE;
753: }
1.56 cvs 754: else
755: {
1.1 cvs 756: elType.ElTypeNum = type1;
757: childType = TtaGetElementType (child);
758: if (TtaSameTypes (childType, elType) == 0)
759: {
760: TtaRemoveTree (child, doc);
761: new = TtaNewElement (doc, elType);
762: if (prev == NULL)
763: TtaInsertFirstChild (&new, el, doc);
764: else
765: TtaInsertSibling (new, prev, FALSE, doc);
766: TtaInsertFirstChild (&child, new, doc);
767: CreatePlaceholders (child, doc);
768: child = new;
1.189 quint 769: CheckIntDisplaystyle (new, doc);
1.1 cvs 770: }
1.56 cvs 771: prev = child;
772: TtaNextSibling (&child);
1.95 cvs 773: NextNotComment (&child, &prev);
1.56 cvs 774: if (type2 == 0)
775: {
776: if (child)
777: /* this second child is not expected, error */
1.124 cvs 778: {
779: sprintf (msgBuffer, "Only 1 subexpression allowed in %s",
780: TtaGetElementTypeName (TtaGetElementType (el)));
781: XmlParseError (errorParsing, msgBuffer, 0);
782: result = FALSE;
783: }
1.56 cvs 784: }
785: else
1.1 cvs 786: {
1.56 cvs 787: if (!child)
788: /* a second child is expected and it's missing */
1.124 cvs 789: {
790: sprintf (msgBuffer, "2 subexpressions required in %s",
791: TtaGetElementTypeName (TtaGetElementType (el)));
792: XmlParseError (errorParsing, msgBuffer, 0);
793: result = FALSE;
794: }
1.56 cvs 795: else
1.1 cvs 796: {
797: elType.ElTypeNum = type2;
798: childType = TtaGetElementType (child);
799: if (TtaSameTypes (childType, elType) == 0)
800: {
801: TtaRemoveTree (child, doc);
802: new = TtaNewElement (doc, elType);
803: TtaInsertSibling (new, prev, FALSE, doc);
804: TtaInsertFirstChild (&child, new, doc);
805: CreatePlaceholders (child, doc);
806: child = new;
1.189 quint 807: CheckIntDisplaystyle (new, doc);
1.1 cvs 808: }
1.56 cvs 809: prev = child;
810: TtaNextSibling (&child);
1.95 cvs 811: NextNotComment (&child, &prev);
1.56 cvs 812: if (type3 == 0)
1.1 cvs 813: {
1.56 cvs 814: if (child)
815: /* this third child is not expected, error */
1.124 cvs 816: {
817: sprintf (msgBuffer, "Only 2 subexpressions allowed in %s",
818: TtaGetElementTypeName (TtaGetElementType (el)));
819: XmlParseError (errorParsing, msgBuffer, 0);
820: result = FALSE;
821: }
1.56 cvs 822: }
823: else
824: {
825: if (!child)
826: /* a third child is expected and it's missing */
1.124 cvs 827: {
828: sprintf (msgBuffer, "3 subexpressions required in %s",
829: TtaGetElementTypeName (TtaGetElementType (el)));
830: XmlParseError (errorParsing, msgBuffer, 0);
831: result = FALSE;
832: }
1.56 cvs 833: else
1.1 cvs 834: {
835: elType.ElTypeNum = type3;
836: childType = TtaGetElementType (child);
837: if (TtaSameTypes (childType, elType) == 0)
838: {
839: TtaRemoveTree (child, doc);
840: new = TtaNewElement (doc, elType);
841: TtaInsertSibling (new, prev, FALSE, doc);
842: TtaInsertFirstChild (&child, new, doc);
843: CreatePlaceholders (child, doc);
1.56 cvs 844: child = new;
1.189 quint 845: CheckIntDisplaystyle (new, doc);
1.1 cvs 846: }
847: }
1.56 cvs 848: prev = child;
849: TtaNextSibling (&child);
1.95 cvs 850: NextNotComment (&child, &prev);
1.56 cvs 851: if (child)
852: /* this fourth child is unexpected */
1.124 cvs 853: {
854: sprintf (msgBuffer,"Only 3 subexpressions allowed in %s",
855: TtaGetElementTypeName (TtaGetElementType (el)));
856: XmlParseError (errorParsing, msgBuffer, 0);
857: result = FALSE;
858: }
1.1 cvs 859: }
860: }
861: }
1.56 cvs 862: }
863: return result;
1.1 cvs 864: }
865:
866: /*----------------------------------------------------------------------
1.22 cvs 867: SetSingleIntHorizStretchAttr
1.1 cvs 868:
1.22 cvs 869: Put a IntHorizStretch attribute on element el if it contains only
1.1 cvs 870: a MO element that is a stretchable symbol.
871: -----------------------------------------------------------------------*/
1.22 cvs 872: void SetSingleIntHorizStretchAttr (Element el, Document doc, Element* selEl)
1.1 cvs 873: {
874: Element child, sibling, textEl, symbolEl;
1.152 quint 875: ElementType elType, childType, siblingType;
1.1 cvs 876: Attribute attr;
877: AttributeType attrType;
1.55 cvs 878: Language lang;
1.128 vatton 879: CHAR_T text[2];
1.143 vatton 880: char script;
1.49 cvs 881: unsigned char c;
1.128 vatton 882: int len;
1.152 quint 883: ThotBool doit;
1.1 cvs 884:
885: if (el == NULL)
886: return;
887: child = TtaGetFirstChild (el);
1.154 vatton 888: textEl = NULL;
1.55 cvs 889: if (child)
1.1 cvs 890: {
891: elType = TtaGetElementType (child);
1.162 quint 892: /* skip empty Constructs (placeholders) and comments */
893: while (child &&
894: (elType.ElTypeNum == MathML_EL_Construct ||
895: elType.ElTypeNum == MathML_EL_XMLcomment) &&
896: !strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
1.152 quint 897: {
898: TtaNextSibling (&child);
899: if (child)
900: elType = TtaGetElementType (child);
901: }
1.162 quint 902: while (child && elType.ElTypeNum == MathML_EL_MROW &&
903: strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
904: /* the first significant child is a mrow. Check whether it has a
905: single child */
1.98 cvs 906: {
907: child = TtaGetFirstChild (child);
908: if (child)
909: {
1.152 quint 910: elType = TtaGetElementType (child);
1.162 quint 911: /* skip empty Constructs (placeholders) and comments */
912: while (child &&
913: (elType.ElTypeNum == MathML_EL_Construct ||
914: elType.ElTypeNum == MathML_EL_XMLcomment) &&
915: !strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
1.152 quint 916: {
1.162 quint 917: TtaNextSibling (&child);
918: if (child)
919: elType = TtaGetElementType (child);
1.152 quint 920: }
1.98 cvs 921: sibling = child;
922: TtaNextSibling (&sibling);
1.152 quint 923: if (sibling)
924: /* there are other children */
925: {
926: siblingType = TtaGetElementType (sibling);
1.162 quint 927: while (sibling &&
928: (siblingType.ElTypeNum == MathML_EL_Construct ||
929: siblingType.ElTypeNum == MathML_EL_XMLcomment) &&
930: !strcmp (TtaGetSSchemaName (siblingType.ElSSchema), "MathML"))
931: /* its an empty construct (placeholder) or a comment, skip it*/
932: {
933: TtaNextSibling (&sibling);
934: if (sibling)
935: siblingType = TtaGetElementType (sibling);
936: }
1.152 quint 937: if (sibling)
1.162 quint 938: /* there are significant siblings */
1.152 quint 939: child = NULL;
940: }
1.98 cvs 941: }
942: }
1.152 quint 943: if (child && (elType.ElTypeNum == MathML_EL_MO ||
944: elType.ElTypeNum == MathML_EL_MOVER ||
945: elType.ElTypeNum == MathML_EL_MUNDER))
946: /* the first child is a MO, a MUNDER or a MOVER */
1.1 cvs 947: {
948: sibling = child;
949: TtaNextSibling (&sibling);
1.152 quint 950: if (sibling)
1.162 quint 951: siblingType = TtaGetElementType (sibling);
952: /* skip empty Constructs (placeholders) and comments */
953: while (sibling &&
954: (siblingType.ElTypeNum == MathML_EL_Construct ||
955: siblingType.ElTypeNum == MathML_EL_XMLcomment) &&
956: !strcmp (TtaGetSSchemaName (siblingType.ElSSchema), "MathML"))
1.152 quint 957: {
1.162 quint 958: TtaNextSibling (&sibling);
959: if (sibling)
960: siblingType = TtaGetElementType (sibling);
1.152 quint 961: }
1.1 cvs 962: if (sibling == NULL)
1.162 quint 963: /* there is no other significant child */
1.1 cvs 964: {
1.152 quint 965: c = EOS;
966: doit = FALSE;
967: attrType.AttrSSchema = elType.ElSSchema;
968: attrType.AttrTypeNum = MathML_ATTR_IntHorizStretch;
969:
970: if (elType.ElTypeNum == MathML_EL_MOVER ||
971: elType.ElTypeNum == MathML_EL_MUNDER)
972: /* check if the UnderOverBase has a IntHorizStretch attribute */
973: {
974: childType.ElTypeNum = MathML_EL_UnderOverBase;
1.172 cheyroul 975: childType.ElSSchema = elType.ElSSchema;
1.152 quint 976: textEl = TtaSearchTypedElement (childType, SearchInTree, child);
977: if (textEl)
978: {
979: if (TtaGetAttribute (textEl, attrType))
980: doit = TRUE;
981: }
982: }
983: else if (elType.ElTypeNum == MathML_EL_MO)
984: {
985: textEl = TtaGetFirstChild (child);
986: childType = TtaGetElementType (textEl);
987: if (childType.ElTypeNum == MathML_EL_TEXT_UNIT)
988: /* the MO child contains a TEXT element */
989: {
990: len = TtaGetElementVolume (textEl);
991: if (len == 1)
1.123 cvs 992: /* the TEXT element contains a single character */
993: {
1.152 quint 994: /* get that character */
995: len = 2;
996: TtaGiveBufferContent (textEl, text, len, &lang);
997: script = TtaGetScript (lang);
998: if (
1.146 quint 999: #ifndef _I18N_
1.152 quint 1000: (script == 'L') &&
1.146 quint 1001: #endif
1.152 quint 1002: (text[0] == '-' || text[0] == '_' ||
1003: text[0] == 175))
1.146 quint 1004: /* a horizontal line in the middle of the box */
1005: c = 'h';
1.152 quint 1006: else
1007: #ifdef _I18N_
1008: if (text[0] == 0x2190)
1009: c = 'L'; /* arrow left */
1010: else if (text[0] == 0x2192)
1011: c = 'R'; /* arrow right */
1.153 quint 1012: else if (text[0] == 45) /* - (minus) */
1013: /* a horizontal line in the middle of the box */
1014: c = 'h';
1015: else if (text[0] == 0x2212) /* - (minus) */
1.152 quint 1016: /* a horizontal line in the middle of the box */
1017: c = 'h';
1018: else if (text[0] == 0x0332) /* UnderBar */
1019: /* a horizontal line */
1020: c = 'h';
1021: else if (text[0] == 65079)
1022: c = 'o'; /* Over brace */
1023: else if (text[0] == 65080)
1024: c = 'u'; /* Under brace */
1.146 quint 1025: #else
1026: if (script == 'G')
1027: /* a single Symbol character */
1028: {
1029: if (text[0] == 172)
1030: c = 'L'; /* arrow left */
1031: else if (text[0] == 174)
1032: c = 'R'; /* arrow right */
1033: else if (text[0] == 45) /* - (minus) */
1034: /* a horizontal line in the middle of the box */
1035: c = 'h';
1036: else if (text[0] == 132)
1037: c = 'o'; /* Over brace */
1038: else if (text[0] == 133)
1039: c = 'u'; /* Under brace */
1040: }
1041: #endif
1.152 quint 1042: if (c != EOS)
1043: doit = TRUE;
1.123 cvs 1044: }
1.152 quint 1045: }
1046: }
1047: if (doit)
1048: {
1049: /* attach a IntHorizStretch attribute to the element
1050: (UnderOverBase, Underscript, or Overscript) */
1051: attr = TtaNewAttribute (attrType);
1052: TtaAttachAttribute (el, attr, doc);
1053: TtaSetAttributeValue (attr, MathML_ATTR_IntHorizStretch_VAL_yes_, el, doc);
1054: attr = TtaNewAttribute (attrType);
1055: TtaAttachAttribute (child, attr, doc);
1056: TtaSetAttributeValue (attr, MathML_ATTR_IntHorizStretch_VAL_yes_, child, doc);
1057: }
1058: if (c != EOS)
1059: {
1060: /* replace the TEXT element by a Thot SYMBOL element */
1061: childType.ElTypeNum = MathML_EL_SYMBOL_UNIT;
1062: symbolEl = TtaNewElement (doc, childType);
1063: TtaInsertSibling (symbolEl, textEl, FALSE, doc);
1064: if (selEl != NULL)
1065: if (*selEl == textEl)
1066: *selEl = symbolEl;
1067: TtaDeleteTree (textEl, doc);
1068: if (c != EOS)
1069: TtaSetGraphicsShape (symbolEl, c, doc);
1070: }
1.1 cvs 1071: }
1072: }
1073: }
1074: }
1.162 quint 1075:
1.1 cvs 1076: /*----------------------------------------------------------------------
1.22 cvs 1077: SetIntHorizStretchAttr
1.1 cvs 1078:
1.152 quint 1079: Put a IntHorizStretch attribute on all children of element el that
1.1 cvs 1080: contain only a MO element that is a stretchable symbol.
1081: -----------------------------------------------------------------------*/
1.22 cvs 1082: static void SetIntHorizStretchAttr (Element el, Document doc)
1.1 cvs 1083: {
1084: Element child;
1085:
1086: if (el == NULL)
1087: return;
1088: child = TtaGetFirstChild (el);
1089: while (child != NULL)
1090: {
1.22 cvs 1091: SetSingleIntHorizStretchAttr (child, doc, NULL);
1.1 cvs 1092: TtaNextSibling (&child);
1093: }
1094: }
1095:
1096: /*----------------------------------------------------------------------
1.22 cvs 1097: SetIntVertStretchAttr
1.1 cvs 1098:
1.22 cvs 1099: Put a IntVertStretch attribute on element el if its base element
1.1 cvs 1100: (Base for a MSUBSUP, MSUP or MSUB; UnderOverBase for a MUNDEROVER,
1101: a MUNDER of a MOVER) contains only a MO element that is a vertically
1.162 quint 1102: stretchable symbol (integral, vertical arrow, etc).
1.1 cvs 1103: -----------------------------------------------------------------------*/
1.22 cvs 1104: void SetIntVertStretchAttr (Element el, Document doc, int base, Element* selEl)
1.1 cvs 1105: {
1.132 cvs 1106: Element child, sibling, textEl, symbolEl, parent, operator, next;
1.1 cvs 1107: ElementType elType;
1108: Attribute attr;
1109: AttributeType attrType;
1.131 cvs 1110: SSchema MathMLSSchema;
1.128 vatton 1111: Language lang;
1.143 vatton 1112: char script;
1.131 cvs 1113: #define buflen 50
1114: CHAR_T text[buflen];
1.49 cvs 1115: unsigned char c;
1.131 cvs 1116: int len, i;
1.162 quint 1117: ThotBool inbase, stretchable;
1.1 cvs 1118:
1119: if (el == NULL)
1.131 cvs 1120: return;
1.1 cvs 1121: operator = NULL;
1.131 cvs 1122: inbase = FALSE;
1123: MathMLSSchema = TtaGetElementType(el).ElSSchema;
1.154 vatton 1124: symbolEl = parent = NULL;
1.1 cvs 1125: if (base == 0)
1.131 cvs 1126: /* it's a MO */
1127: {
1128: parent = TtaGetParent (el);
1129: if (parent != NULL)
1.1 cvs 1130: {
1.131 cvs 1131: /* don't process the mo if it is within a base. It will be processed
1132: when the enclosing construct is processed (see below) */
1133: elType = TtaGetElementType (parent);
1134: if (elType.ElSSchema != MathMLSSchema ||
1135: (elType.ElTypeNum != MathML_EL_Base &&
1136: elType.ElTypeNum != MathML_EL_UnderOverBase &&
1137: elType.ElTypeNum != MathML_EL_MSUBSUP &&
1138: elType.ElTypeNum != MathML_EL_MSUB &&
1139: elType.ElTypeNum != MathML_EL_MSUP &&
1140: elType.ElTypeNum != MathML_EL_MUNDEROVER &&
1141: elType.ElTypeNum != MathML_EL_MUNDER &&
1.162 quint 1142: elType.ElTypeNum != MathML_EL_MUNDEROVER &&
1143: elType.ElTypeNum != MathML_EL_MTD))
1.131 cvs 1144: operator = el;
1.1 cvs 1145: }
1.131 cvs 1146: }
1.1 cvs 1147: else
1.131 cvs 1148: /* it's not a MO */
1149: {
1150: /* search the Base or UnderOverBase child */
1151: child = TtaGetFirstChild (el);
1152: if (child != NULL)
1.1 cvs 1153: {
1.131 cvs 1154: elType = TtaGetElementType (child);
1.162 quint 1155: /* skip empty Constructs (placeholders) and comments */
1156: while (child &&
1157: (elType.ElTypeNum == MathML_EL_Construct ||
1158: elType.ElTypeNum == MathML_EL_XMLcomment) &&
1159: elType.ElSSchema == MathMLSSchema)
1160: {
1161: TtaNextSibling (&child);
1162: if (child)
1163: elType = TtaGetElementType (child);
1164: }
1165:
1.131 cvs 1166: if (elType.ElTypeNum == base && elType.ElSSchema == MathMLSSchema)
1167: /* the first child is a Base or UnderOverBase */
1168: {
1169: child = TtaGetFirstChild (child);
1170: if (child != NULL)
1171: {
1172: elType = TtaGetElementType (child);
1.162 quint 1173: /* skip empty Constructs (placeholders) and comments */
1174: while (child &&
1175: (elType.ElTypeNum == MathML_EL_Construct ||
1176: elType.ElTypeNum == MathML_EL_XMLcomment) &&
1177: elType.ElSSchema == MathMLSSchema)
1178: {
1179: TtaNextSibling (&child);
1180: if (child)
1181: elType = TtaGetElementType (child);
1182: }
1183:
1.131 cvs 1184: if (elType.ElTypeNum == MathML_EL_MO &&
1185: elType.ElSSchema == MathMLSSchema)
1.162 quint 1186: /* its first significant child is a MO */
1.131 cvs 1187: {
1188: sibling = child;
1189: TtaNextSibling (&sibling);
1.162 quint 1190: /* skip empty Constructs (placeholders) and comments */
1191: while (sibling &&
1192: (elType.ElTypeNum == MathML_EL_Construct ||
1193: elType.ElTypeNum == MathML_EL_XMLcomment) &&
1194: elType.ElSSchema == MathMLSSchema)
1195: {
1196: TtaNextSibling (&sibling);
1197: if (sibling)
1198: elType = TtaGetElementType (sibling);
1199: }
1200:
1.131 cvs 1201: if (sibling == NULL)
1.162 quint 1202: /* there is no other significant child */
1.131 cvs 1203: {
1204: operator = child;
1205: if (base == MathML_EL_Base ||
1206: base == MathML_EL_UnderOverBase)
1207: {
1208: parent = el;
1209: inbase = TRUE;
1210: }
1211: }
1212: }
1213: }
1214: }
1.1 cvs 1215: }
1.131 cvs 1216: }
1217: if (operator)
1218: {
1219: textEl = TtaGetFirstChild (operator);
1220: if (textEl != NULL)
1.84 cvs 1221: {
1.131 cvs 1222: elType = TtaGetElementType (textEl);
1223: if (elType.ElTypeNum == MathML_EL_TEXT_UNIT)
1224: {
1.146 quint 1225: len = TtaGetElementVolume (textEl);
1.131 cvs 1226: if (len >= 1)
1227: {
1228: if (len >= buflen)
1229: len = buflen-1;
1.146 quint 1230: TtaGiveBufferContent (textEl, text, len+1, &lang);
1.143 vatton 1231: script = TtaGetScript (lang);
1.146 quint 1232: #ifdef _I18N_
1.162 quint 1233: stretchable = TRUE;
1.146 quint 1234: for (i = 0; i < len; i++)
1.162 quint 1235: if ((text[i] < 0x222B || text[i] > 0x2233) &&
1236: text[i] != 0x2191 && text[i] != 0x2193 &&
1237: text[i] != 0x2195 &&
1238: text[i] != 0x21D1 && text[i] != 0x21D3 &&
1239: text[i] != 0x21D5)
1.146 quint 1240: /* accept only symbols like simple integral, double or
1.162 quint 1241: triple integral, contour integral, etc. or vertical
1242: arrows (add more arrows *****) */
1243: stretchable = FALSE;
1.146 quint 1244: #else
1.162 quint 1245: stretchable = FALSE;
1.143 vatton 1246: if (script == 'G')
1.131 cvs 1247: /* Adobe Symbol character set */
1.55 cvs 1248: {
1.162 quint 1249: stretchable = TRUE;
1.131 cvs 1250: /* check all characters in this TEXT element */
1251: for (i = 0; i < len; i++)
1.162 quint 1252: if (text[i] != 242 && /* integral */
1253: text[i] != 173 && text[i] != 175 && /* arrows */
1254: text[i] != 221 && text[i] != 223) /* double arrows */
1.131 cvs 1255: /**** accept also other symbols like double or triple
1256: integral, contour integral, etc. ****/
1.162 quint 1257: stretchable = FALSE;
1.146 quint 1258: }
1259: #endif
1.162 quint 1260: if (stretchable)
1261: /* the operator contains only stretchable symbols */
1.146 quint 1262: {
1263: /* attach a IntVertStretch attribute */
1264: attrType.AttrSSchema = MathMLSSchema;
1265: attrType.AttrTypeNum = MathML_ATTR_IntVertStretch;
1266: attr = TtaNewAttribute (attrType);
1267: TtaAttachAttribute (el, attr, doc);
1268: TtaSetAttributeValue (attr,
1.131 cvs 1269: MathML_ATTR_IntVertStretch_VAL_yes_,
1270: el, doc);
1.146 quint 1271: TtaRegisterAttributeCreate (attr, el, doc);
1272:
1.162 quint 1273: /* replace the stretchable characters by a Thot SYMBOL
1.146 quint 1274: element. If there are several such characters in
1.162 quint 1275: the mo (multiple integral for instance), replace
1276: them too. */
1.146 quint 1277: do
1278: {
1279: /* replace the TEXT element by a Thot SYMBOL */
1.162 quint 1280: elType.ElSSchema = MathMLSSchema;
1.146 quint 1281: elType.ElTypeNum = MathML_EL_SYMBOL_UNIT;
1282: for (i = 0; i < len; i++)
1.162 quint 1283: {
1.176 cvs 1284: c = (unsigned char) text[i];
1.146 quint 1285: #ifdef _I18N_
1.162 quint 1286: if (text[i] == 0x222B)
1287: c = 'i';
1288: else if (text[i] == 0x222C)
1289: c = 'd';
1290: else if (text[i] == 0x222D)
1291: c = 't';
1292: else if (text[i] == 0x222E)
1293: c = 'c';
1294: else if (text[i] == 0x2191)
1295: c = '^';
1296: else if (text[i] == 0x2193)
1297: c = 'V';
1.173 vatton 1298: #else /*_I18N_ */
1.162 quint 1299: if (text[i] == 242)
1300: c = 'i';
1301: else if (text[i] == 173)
1302: c = '<';
1303: else if (text[i] == 175)
1304: c = '>';
1.173 vatton 1305: #endif /*_I18N_ */
1.162 quint 1306: symbolEl = TtaNewElement (doc, elType);
1307: TtaInsertSibling (symbolEl, textEl, TRUE,doc);
1308: TtaSetGraphicsShape (symbolEl, c, doc);
1309: TtaRegisterElementCreate (symbolEl, doc);
1.179 quint 1310: if (selEl != NULL)
1311: if (*selEl == textEl)
1312: *selEl = symbolEl;
1.162 quint 1313: }
1.146 quint 1314: TtaRegisterElementDelete (textEl, doc);
1315: TtaDeleteTree (textEl, doc);
1316: /* is there an other text element after the
1.162 quint 1317: stretchable symbol? */
1.146 quint 1318: textEl = symbolEl; TtaNextSibling (&textEl);
1319: if (textEl)
1320: {
1.189 quint 1321: elType = TtaGetElementType (textEl);
1322: if (elType.ElTypeNum != MathML_EL_TEXT_UNIT)
1323: textEl = NULL;
1324: else
1325: /* there is another text element.
1326: Is it a single stretchable symbol? */
1.169 quint 1327: {
1.189 quint 1328: len = TtaGetElementVolume (textEl);
1329: if (len < 1)
1330: /* not a single character */
1331: textEl = NULL;
1332: else
1.169 quint 1333: {
1.189 quint 1334: if (len >= buflen)
1335: len = buflen-1;
1336: TtaGiveBufferContent (textEl, text,
1337: len+1, &lang);
1338: script = TtaGetScript (lang);
1339: #ifdef _I18N_
1340: if (text[0] != 0x222B &&
1341: text[0] != 0x222C &&
1342: text[0] != 0x222D &&
1343: text[0] != 0x222E &&
1344: text[0] != 0x2191 &&
1345: text[0] != 0x2193)
1346: #else /*_I18N_ */
1347: if (script != 'G' ||
1348: (text[0] != 242 && text[0] != 173 &&
1349: text[0] != 175))
1350: #endif /*_I18N_ */
1351: /* not a stretchable symbol */
1352: textEl = NULL;
1.169 quint 1353: }
1354: }
1.189 quint 1355: }
1356: }
1357: while (textEl);
1358:
1359: if (inbase)
1360: /* it's within a Base or UnderOverBase element */
1361: {
1362: sibling = parent;
1363: TtaNextSibling (&sibling);
1364: if (sibling)
1365: /* the msubsup of munderover element has a next
1366: sibling */
1367: {
1368: elType = TtaGetElementType (sibling);
1369: if (elType.ElTypeNum == MathML_EL_Construct &&
1370: elType.ElSSchema == MathMLSSchema)
1371: /* the next sibling is a Construct */
1.169 quint 1372: {
1.189 quint 1373: next = sibling;
1374: TtaNextSibling (&next);
1375: if (!next)
1376: /* there is no other sibling after the
1377: Construct. Change it into Construct1*/
1378: {
1379: TtaRegisterElementDelete (sibling, doc);
1380: TtaRemoveTree (sibling, doc);
1.190 ! vatton 1381: TtaChangeElementType (sibling,
1.189 quint 1382: MathML_EL_Construct1);
1383: TtaInsertSibling (sibling, parent,
1384: FALSE, doc);
1385: TtaRegisterElementCreate (sibling, doc);
1386: /* force the msubsup element to be
1387: reformatted and to take into account
1388: its new next sibling */
1389: TtaRemoveTree (parent, doc);
1390: TtaInsertSibling (parent, sibling, TRUE,
1391: doc);
1392: }
1.169 quint 1393: }
1394: }
1.189 quint 1395: }
1.169 quint 1396: }
1397: }
1398: }
1399: }
1400: }
1401: }
1402:
1403: /*----------------------------------------------------------------------
1.22 cvs 1404: SetIntPlaceholderAttr
1.1 cvs 1405:
1.22 cvs 1406: Put a IntPlaceholder attribute on all Construct elements in the
1.1 cvs 1407: subtree of root el.
1408: -----------------------------------------------------------------------*/
1.22 cvs 1409: static void SetIntPlaceholderAttr (Element el, Document doc)
1.1 cvs 1410: {
1411: Element child;
1412: ElementType elType;
1413: Attribute attr;
1414: AttributeType attrType;
1415:
1416: if (el == NULL)
1417: return;
1418: elType = TtaGetElementType (el);
1419: if (elType.ElTypeNum == MathML_EL_Construct &&
1.2 cvs 1420: elType.ElSSchema == GetMathMLSSchema (doc))
1.1 cvs 1421: {
1422: attrType.AttrSSchema = elType.ElSSchema;
1.22 cvs 1423: attrType.AttrTypeNum = MathML_ATTR_IntPlaceholder;
1.1 cvs 1424: attr = TtaNewAttribute (attrType);
1425: TtaAttachAttribute (el, attr, doc);
1.22 cvs 1426: TtaSetAttributeValue (attr, MathML_ATTR_IntPlaceholder_VAL_yes_, el, doc);
1.1 cvs 1427: }
1428: else
1429: {
1430: child = TtaGetFirstChild (el);
1431: while (child != NULL)
1432: {
1.22 cvs 1433: SetIntPlaceholderAttr (child, doc);
1.1 cvs 1434: TtaNextSibling (&child);
1435: }
1436: }
1437: }
1438:
1439: /*----------------------------------------------------------------------
1440: BuildMultiscript
1441:
1442: The content of a MMULTISCRIPT element has been created following
1443: the original MathML structure. Create all Thot elements defined
1444: in the MathML S schema.
1445: -----------------------------------------------------------------------*/
1446: static void BuildMultiscript (Element elMMULTISCRIPT, Document doc)
1447: {
1448: Element elem, base, next, group, pair, script, prevPair, prevScript;
1449: ElementType elType, elTypeGroup, elTypePair, elTypeScript;
1.2 cvs 1450: SSchema MathMLSSchema;
1.1 cvs 1451: base = NULL;
1452: group = NULL;
1453: prevPair = NULL;
1454: prevScript = NULL;
1455:
1.2 cvs 1456: MathMLSSchema = GetMathMLSSchema (doc);
1.1 cvs 1457: elTypeGroup.ElSSchema = MathMLSSchema;
1458: elTypePair.ElSSchema = MathMLSSchema;
1459: elTypeScript.ElSSchema = MathMLSSchema;
1460:
1461: /* process all children of the MMULTISCRIPT element */
1462: elem = TtaGetFirstChild (elMMULTISCRIPT);
1463: while (elem != NULL)
1464: {
1465: /* remember the element to be processed after the current one */
1466: next = elem;
1467: TtaNextSibling (&next);
1468:
1469: /* remove the current element from the tree */
1470: TtaRemoveTree (elem, doc);
1471:
1472: if (base == NULL)
1473: /* the current element is the first child of the MMULTISCRIPT
1474: element */
1475: {
1476: /* Create a MultiscriptBase element as the first child of
1477: MMULTISCRIPT and move the current element as the first child
1478: of the MultiscriptBase element */
1479: elTypeGroup.ElTypeNum = MathML_EL_MultiscriptBase;
1480: base = TtaNewElement (doc, elTypeGroup);
1481: TtaInsertFirstChild (&base, elMMULTISCRIPT, doc);
1482: TtaInsertFirstChild (&elem, base, doc);
1483: }
1484: else
1485: /* the current element is a subscript or a superscript */
1486: {
1487: if (group == NULL)
1488: /* there is no PostscriptPairs element. Create one */
1489: {
1490: elTypeGroup.ElTypeNum = MathML_EL_PostscriptPairs;
1491: group = TtaNewElement (doc, elTypeGroup);
1492: TtaInsertSibling (group, base, FALSE, doc);
1493: elTypePair.ElTypeNum = MathML_EL_PostscriptPair;
1494: /* create a first and a last PostscriptPair as placeholders */
1.47 cvs 1495: pair = TtaNewTree (doc, elTypePair, "");
1.1 cvs 1496: TtaInsertFirstChild (&pair, group, doc);
1.22 cvs 1497: SetIntPlaceholderAttr (pair, doc);
1.1 cvs 1498: prevPair = pair;
1.47 cvs 1499: pair = TtaNewTree (doc, elTypePair, "");
1.1 cvs 1500: TtaInsertSibling (pair, prevPair, FALSE, doc);
1.22 cvs 1501: SetIntPlaceholderAttr (pair, doc);
1.1 cvs 1502: prevScript = NULL;
1503: }
1504: if (prevScript == NULL)
1505: /* the current element is the first subscript or superscript
1506: in a pair */
1507: {
1508: /* create a PostscriptPair or PrescriptPair element */
1509: pair = TtaNewElement (doc, elTypePair);
1510: if (prevPair == NULL)
1511: TtaInsertFirstChild (&pair, group, doc);
1512: else
1513: TtaInsertSibling (pair, prevPair, FALSE, doc);
1514: prevPair = pair;
1515: /* create a MSubscript element */
1516: elTypeScript.ElTypeNum = MathML_EL_MSubscript;
1517: script = TtaNewElement (doc, elTypeScript);
1518: TtaInsertFirstChild (&script, pair, doc);
1519: prevScript = script;
1520: }
1521: else
1522: /* the current element is a superscript in a pair */
1523: {
1524: /* create a MSuperscript element */
1525: elTypeScript.ElTypeNum = MathML_EL_MSuperscript;
1526: script = TtaNewElement (doc, elTypeScript);
1527: /* insert it as a sibling of the previous MSubscript element */
1528: TtaInsertSibling (script, prevScript, FALSE, doc);
1529: prevScript = NULL;
1530: }
1531: /* insert the current element as a child of the new MSuperscript or
1532: MSubscript element */
1533: TtaInsertFirstChild (&elem, script, doc);
1.22 cvs 1534: SetIntPlaceholderAttr (elem, doc);
1.1 cvs 1535: }
1536:
1537: CreatePlaceholders (elem, doc);
1538:
1539: /* get next child of the MMULTISCRIPT element */
1540: elem = next;
1541: if (elem != NULL)
1542: {
1543: elType = TtaGetElementType (elem);
1544: if (elType.ElSSchema == MathMLSSchema &&
1545: elType.ElTypeNum == MathML_EL_PrescriptPairs)
1546: /* the next element is a PrescriptPairs */
1547: {
1548: /* if there there is no PostscriptPairs element, create one as a
1549: placeholder */
1550: if (elTypeGroup.ElTypeNum != MathML_EL_PostscriptPairs)
1551: {
1552: elTypeGroup.ElTypeNum = MathML_EL_PostscriptPairs;
1.47 cvs 1553: group = TtaNewTree (doc, elTypeGroup, "");
1.1 cvs 1554: TtaInsertSibling (group, elem, TRUE, doc);
1.22 cvs 1555: SetIntPlaceholderAttr (group, doc);
1.1 cvs 1556: }
1557: /* the following elements will be interpreted as sub- superscripts
1558: in PrescriptPair elements, wich will be children of this
1559: PrescriptPairs element */
1560: elTypeGroup.ElTypeNum = MathML_EL_PrescriptPairs;
1561: elTypePair.ElTypeNum = MathML_EL_PrescriptPair;
1562: group = elem;
1563: /* create a first and a last PostscriptPair as placeholders */
1.47 cvs 1564: pair = TtaNewTree (doc, elTypePair, "");
1.1 cvs 1565: TtaInsertFirstChild (&pair, group, doc);
1.22 cvs 1566: SetIntPlaceholderAttr (pair, doc);
1.1 cvs 1567: prevPair = pair;
1.47 cvs 1568: pair = TtaNewTree (doc, elTypePair, "");
1.1 cvs 1569: TtaInsertSibling (pair, prevPair, FALSE, doc);
1.22 cvs 1570: SetIntPlaceholderAttr (pair, doc);
1.1 cvs 1571: prevScript = NULL;
1572: TtaNextSibling (&elem);
1573: }
1574: }
1575: }
1576: /* all children of element MMULTISCRIPTS have been processed */
1577: /* if the last group processed is not a PrescriptPairs element,
1578: create one as a placeholder */
1579: if (elTypeGroup.ElTypeNum != MathML_EL_PrescriptPairs && base != NULL)
1580: {
1581: elTypeGroup.ElTypeNum = MathML_EL_PrescriptPairs;
1.47 cvs 1582: elem = TtaNewTree (doc, elTypeGroup, "");
1.1 cvs 1583: if (group == NULL)
1584: group = base;
1585: TtaInsertSibling (elem, group, TRUE, doc);
1.22 cvs 1586: SetIntPlaceholderAttr (elem, doc);
1.1 cvs 1587: }
1588: }
1589:
1.39 cvs 1590: /*----------------------------------------------------------------------
1591: CreateWrapper
1592:
1593: Create an element of type wrapperType as a child of element el and
1594: move all chidren of element el within the new element.
1595: -----------------------------------------------------------------------*/
1596: static void CreateWrapper (Element el, int wrapperType, Document doc)
1597: {
1598: Element wrapper, child, prevChild, nextChild;
1599: ElementType elType;
1600:
1601: child = TtaGetFirstChild (el);
1602: elType.ElSSchema = GetMathMLSSchema (doc);
1603: elType.ElTypeNum = wrapperType;
1604: wrapper = TtaNewElement (doc, elType);
1605: TtaInsertFirstChild (&wrapper, el, doc);
1606: prevChild = NULL;
1607: while (child)
1608: {
1609: nextChild = child;
1610: TtaNextSibling (&nextChild);
1611: TtaRemoveTree (child, doc);
1612: if (prevChild == NULL)
1613: TtaInsertFirstChild (&child, wrapper, doc);
1614: else
1615: TtaInsertSibling (child, prevChild, FALSE, doc);
1616: prevChild = child;
1617: child = nextChild;
1618: }
1619: }
1.5 cvs 1620:
1621: /*----------------------------------------------------------------------
1622: CheckMTable
1623:
1624: The content of a MTABLE element has been created following
1625: the original MathML structure. Create all Thot elements defined
1626: in the MathML S schema.
1.64 cvs 1627: If placeholder, associate an attribute IntPlaceholder with all
1.103 cvs 1628: cells generated in the MathML table.
1.5 cvs 1629: -----------------------------------------------------------------------*/
1.64 cvs 1630: void CheckMTable (Element elMTABLE, Document doc, ThotBool placeholder)
1.5 cvs 1631: {
1632: ElementType elType;
1633: Element MTableHead, MTableBody, row, nextRow, el, prevRow, cell,
1.103 cvs 1634: nextCell, newMTD, firstColHead, label;
1.5 cvs 1635: SSchema MathMLSSchema;
1636:
1637: MathMLSSchema = GetMathMLSSchema (doc);
1638: row = TtaGetFirstChild (elMTABLE);
1639:
1640: /* create a MTable_head as the first child of element MTABLE */
1641: elType.ElSSchema = MathMLSSchema;
1642: elType.ElTypeNum = MathML_EL_MTable_head;
1643: MTableHead = TtaNewElement (doc, elType);
1644: TtaInsertFirstChild (&MTableHead, elMTABLE, doc);
1645: elType.ElTypeNum = MathML_EL_MColumn_head;
1.47 cvs 1646: firstColHead = TtaNewTree (doc, elType, "");
1.5 cvs 1647: TtaInsertFirstChild (&firstColHead, MTableHead, doc);
1648:
1649: /* create a MTable_body */
1650: elType.ElTypeNum = MathML_EL_MTable_body;
1651: MTableBody = TtaNewElement (doc, elType);
1652: TtaInsertSibling (MTableBody, MTableHead, FALSE, doc);
1653:
1654: /* move all children of element MTABLE into the new MTable_body element
1.103 cvs 1655: and wrap each non-MTR element in a MTR, except comments */
1.5 cvs 1656: prevRow = NULL;
1657: while (row)
1658: {
1659: nextRow = row;
1660: TtaNextSibling (&nextRow);
1661: elType = TtaGetElementType (row);
1662: TtaRemoveTree (row, doc);
1663: if (TtaSameSSchemas (elType.ElSSchema, MathMLSSchema) &&
1664: (elType.ElTypeNum == MathML_EL_XMLcomment ||
1.101 cvs 1665: elType.ElTypeNum == MathML_EL_MTR ||
1666: elType.ElTypeNum == MathML_EL_MLABELEDTR))
1.5 cvs 1667: {
1668: if (prevRow == NULL)
1669: TtaInsertFirstChild (&row, MTableBody, doc);
1670: else
1671: TtaInsertSibling (row, prevRow, FALSE, doc);
1672: prevRow = row;
1.101 cvs 1673: if (elType.ElTypeNum == MathML_EL_MTR ||
1674: elType.ElTypeNum == MathML_EL_MLABELEDTR)
1.103 cvs 1675: {
1.5 cvs 1676: cell = TtaGetFirstChild (row);
1.103 cvs 1677: if (elType.ElTypeNum == MathML_EL_MLABELEDTR)
1678: /* skip the first significant child of the mlabeledtr element */
1679: {
1680: /* skip comments first */
1681: do
1682: {
1683: elType = TtaGetElementType (cell);
1684: if (TtaSameSSchemas (elType.ElSSchema, MathMLSSchema) &&
1685: elType.ElTypeNum == MathML_EL_XMLcomment)
1686: TtaNextSibling (&cell);
1687: }
1688: while (cell && elType.ElTypeNum == MathML_EL_XMLcomment);
1689: /* skip the first element after the comments: it's a label */
1690: if (cell)
1691: {
1.105 cvs 1692: /* if it's a MTD change its type into LabelCell */
1693: if (elType.ElTypeNum == MathML_EL_MTD &&
1694: elType.ElSSchema == MathMLSSchema)
1.190 ! vatton 1695: TtaChangeElementType (cell, MathML_EL_LabelCell);
1.103 cvs 1696: /* wrap this element in a RowLabel element */
1.105 cvs 1697: /* This will allow the P schema to specify the horizontal
1698: position of the label */
1.103 cvs 1699: elType.ElSSchema = MathMLSSchema;
1700: elType.ElTypeNum = MathML_EL_RowLabel;
1701: label = TtaNewElement (doc, elType);
1702: TtaInsertSibling (label, cell, TRUE, doc);
1703: TtaRemoveTree (cell, doc);
1704: TtaInsertFirstChild (&cell, label, doc);
1705: cell = label;
1706: TtaNextSibling (&cell);
1707: }
1708: }
1709: }
1.5 cvs 1710: else
1711: cell = NULL;
1712: }
1713: else
1.103 cvs 1714: /* this child is not a MTR, MLABELEDTR, or a comment.
1715: In MathML 2.0, this in an error, but we try to recover by
1716: creating a MTR element */
1.5 cvs 1717: {
1718: elType.ElSSchema = MathMLSSchema;
1719: elType.ElTypeNum = MathML_EL_MTR;
1720: el = TtaNewElement (doc, elType);
1721: if (prevRow == NULL)
1722: TtaInsertFirstChild (&el, MTableBody, doc);
1723: else
1724: TtaInsertSibling (el, prevRow, FALSE, doc);
1725: TtaInsertFirstChild (&row, el, doc);
1726: cell = row;
1727: prevRow = el;
1728: }
1729: while (cell)
1730: /* check all children of the current MTR element */
1731: {
1732: nextCell = cell;
1733: TtaNextSibling (&nextCell);
1734: elType = TtaGetElementType (cell);
1735: if (!TtaSameSSchemas (elType.ElSSchema, MathMLSSchema) ||
1736: (elType.ElTypeNum != MathML_EL_XMLcomment &&
1737: elType.ElTypeNum != MathML_EL_MTD))
1738: /* this is not a MTD nor a comment, create a wrapping MTD */
1739: {
1740: elType.ElSSchema = MathMLSSchema;
1741: elType.ElTypeNum = MathML_EL_MTD;
1742: newMTD = TtaNewElement (doc, elType);
1743: TtaInsertSibling (newMTD, cell, TRUE, doc);
1744: TtaRemoveTree (cell, doc);
1745: TtaInsertFirstChild (&cell, newMTD, doc);
1746: cell = newMTD;
1747: }
1748: if (elType.ElTypeNum == MathML_EL_MTD)
1749: /* This is a MTD element. Wrap its contents with a CellWrapper */
1.162 quint 1750: {
1751: CreateWrapper (cell, MathML_EL_CellWrapper, doc);
1752: SetIntHorizStretchAttr (cell, doc);
1753: SetIntVertStretchAttr (cell, doc, MathML_EL_CellWrapper, NULL);
1754: }
1.5 cvs 1755: cell = nextCell;
1756: }
1757: row = nextRow;
1758: }
1.107 cvs 1759: CheckAllRows (elMTABLE, doc, placeholder, FALSE);
1.5 cvs 1760: }
1.12 cvs 1761:
1.46 cvs 1762: /*----------------------------------------------------------------------
1.1 cvs 1763: SetFontstyleAttr
1764: The content of a MI element has been created or modified.
1765: Create or change attribute IntFontstyle for that element accordingly.
1766: -----------------------------------------------------------------------*/
1767: void SetFontstyleAttr (Element el, Document doc)
1768: {
1769: ElementType elType;
1.157 quint 1770: AttributeType attrType, attrType1;
1.1 cvs 1771: Attribute attr, IntAttr;
1.157 quint 1772: Element ancestor, textEl;
1.1 cvs 1773: int len;
1.163 quint 1774: Language lang;
1775: #ifndef _I18N_
1776: char script;
1.166 quint 1777: char *value;
1.163 quint 1778: #endif
1.166 quint 1779: CHAR_T text[2];
1.54 cvs 1780: ThotBool italic;
1.1 cvs 1781:
1782: if (el != NULL)
1.142 quint 1783: {
1.157 quint 1784: /* search the (deprecated) fontstyle attribute or the mathvariant
1785: attribute on the element and its ancestors */
1.142 quint 1786: elType = TtaGetElementType (el);
1787: attrType.AttrSSchema = elType.ElSSchema;
1788: attrType.AttrTypeNum = MathML_ATTR_fontstyle;
1.157 quint 1789: attrType1.AttrSSchema = elType.ElSSchema;
1790: attrType1.AttrTypeNum = MathML_ATTR_mathvariant;
1791: ancestor = el;
1792: attr = NULL;
1793: do
1794: {
1795: attr = TtaGetAttribute (ancestor, attrType);
1796: if (!attr)
1797: attr = TtaGetAttribute (ancestor, attrType1);
1798: if (!attr)
1799: {
1800: ancestor = TtaGetParent (ancestor);
1801: if (ancestor)
1802: {
1803: elType = TtaGetElementType (ancestor);
1804: if (elType.ElSSchema != attrType.AttrSSchema)
1805: /* this ancestor is not in the MathML namespace */
1806: ancestor = NULL;
1807: }
1808: }
1809: }
1810: while (ancestor && !attr);
1811:
1.142 quint 1812: attrType.AttrTypeNum = MathML_ATTR_IntFontstyle;
1813: IntAttr = TtaGetAttribute (el, attrType);
1814: if (attr != NULL)
1.157 quint 1815: /* there is a fontstyle or mathvariant attribute. Remove the
1816: IntFontstyle internal attribute that is not needed */
1.1 cvs 1817: {
1.142 quint 1818: if (IntAttr != NULL)
1819: TtaRemoveAttribute (el, IntAttr, doc);
1.1 cvs 1820: }
1.142 quint 1821: else
1.157 quint 1822: /* there is no fontstyle or mathvariant attribute. Create an internal
1823: IntFontstyle attribute with a value that depends on the content of
1824: the MI element */
1.1 cvs 1825: {
1.142 quint 1826: /* get content length */
1827: len = TtaGetElementVolume (el);
1828: if (len > 1)
1829: /* put an attribute IntFontstyle = IntNormal */
1830: {
1831: if (IntAttr == NULL)
1832: {
1833: IntAttr = TtaNewAttribute (attrType);
1834: TtaAttachAttribute (el, IntAttr, doc);
1835: }
1836: TtaSetAttributeValue (IntAttr,
1837: MathML_ATTR_IntFontstyle_VAL_IntNormal,
1838: el, doc);
1839: }
1840: else
1841: /* MI contains a single character. Remove attribute IntFontstyle
1842: if it exists, except if it's ImaginaryI, ExponentialE or
1843: DifferentialD */
1844: {
1845: italic = TRUE;
1846: textEl = TtaGetFirstChild (el);
1847: if (textEl != NULL)
1848: {
1849: elType = TtaGetElementType (textEl);
1850: if (elType.ElTypeNum == MathML_EL_MGLYPH)
1851: /* the content of the MI element is a MGLYPH element */
1852: /* check the length if it's alt attribute */
1853: {
1854: /* by default, use normal style */
1855: italic = FALSE;
1856: attrType.AttrTypeNum = MathML_ATTR_alt;
1857: attr = TtaGetAttribute (textEl, attrType);
1858: if (attr)
1859: /* the MGLYPH element has an alt attribute */
1860: {
1861: len = TtaGetTextAttributeLength (attr);
1862: if (len == 1)
1863: italic = TRUE;
1864: }
1865: }
1.163 quint 1866: else if (elType.ElTypeNum == MathML_EL_TEXT_UNIT)
1.142 quint 1867: {
1.166 quint 1868: len = TtaGetElementVolume (textEl);
1.163 quint 1869: if (len == 1)
1.166 quint 1870: /* the TEXT element contains a single character */
1.163 quint 1871: {
1.166 quint 1872: /* get that character */
1873: len = 2;
1874: TtaGiveBufferContent (textEl, text, len, &lang);
1.163 quint 1875: #ifndef _I18N_
1876: script = TtaGetScript (lang);
1877: #endif
1878: if (
1879: #ifndef _I18N_
1880: script == 'L' &&
1881: #endif
1882: text[0] >= '0' && text[0] <= '9')
1.166 quint 1883: /* that's a single digit */
1.163 quint 1884: italic = FALSE;
1.166 quint 1885: else
1886: #ifdef _I18N_
1887: /* is this the Unicode character for DifferentialD,
1888: ExponentialE or ImaginaryI? */
1889: if (text[0] == 0x2146 || text[0] == 0x2147 ||
1890: text[0] == 0x2148)
1891: italic = FALSE;
1892: #else
1.142 quint 1893: {
1.166 quint 1894: /* is there an attribute EntityName on that
1895: character? */
1896: attrType.AttrTypeNum = MathML_ATTR_EntityName;
1897: attr = TtaGetAttribute (textEl, attrType);
1898: if (attr)
1899: {
1900: len = TtaGetTextAttributeLength (attr);
1901: if (len > 0)
1902: {
1903: value = TtaGetMemory (len+1);
1904: TtaGiveTextAttributeValue (attr, value, &len);
1905: if (strcmp (&value[1], "ImaginaryI;") == 0 ||
1906: strcmp (&value[1], "ExponentialE;") == 0 ||
1907: strcmp (&value[1], "DifferentialD;") == 0)
1908: italic = FALSE;
1909: TtaFreeMemory (value);
1910: }
1911: }
1.142 quint 1912: }
1.166 quint 1913: #endif
1.142 quint 1914: }
1915: }
1916: if (italic)
1917: {
1918: if (IntAttr != NULL)
1919: TtaRemoveAttribute (el, IntAttr, doc);
1920: }
1921: else
1922: {
1923: /* put an attribute IntFontstyle = IntNormal */
1924: if (IntAttr == NULL)
1925: {
1926: attrType.AttrTypeNum = MathML_ATTR_IntFontstyle;
1927: IntAttr = TtaNewAttribute (attrType);
1928: TtaAttachAttribute (el, IntAttr, doc);
1929: }
1930: TtaSetAttributeValue (IntAttr,
1931: MathML_ATTR_IntFontstyle_VAL_IntNormal,
1932: el, doc);
1933: }
1934: }
1935: }
1.1 cvs 1936: }
1.142 quint 1937: }
1.1 cvs 1938: }
1939:
1940: /*----------------------------------------------------------------------
1.22 cvs 1941: SetIntAddSpaceAttr
1.1 cvs 1942: The content of a MO element has been created or modified.
1.22 cvs 1943: Create or change attribute IntAddSpace for that element accordingly.
1.1 cvs 1944: -----------------------------------------------------------------------*/
1.22 cvs 1945: void SetIntAddSpaceAttr (Element el, Document doc)
1.1 cvs 1946: {
1947: Element textEl, previous;
1948: ElementType elType;
1949: AttributeType attrType;
1.60 cvs 1950: Attribute attr, formAttr;
1.155 quint 1951: SSchema MathMLSSchema;
1.60 cvs 1952: int len, val, form;
1.146 quint 1953: CHAR_T text[2];
1.1 cvs 1954: Language lang;
1.143 vatton 1955: char script;
1.155 quint 1956: ThotBool comment;
1.1 cvs 1957:
1.155 quint 1958: MathMLSSchema = TtaGetElementType(el).ElSSchema;
1.60 cvs 1959: /* get the content of the mo element */
1.1 cvs 1960: textEl = TtaGetFirstChild (el);
1.155 quint 1961:
1962: /* skip comments if any */
1963: if (textEl)
1964: do
1965: {
1966: elType = TtaGetElementType (textEl);
1967: if (TtaSameSSchemas (elType.ElSSchema, MathMLSSchema) &&
1968: elType.ElTypeNum == MathML_EL_XMLcomment)
1969: /* it's a comment, skip it */
1970: TtaNextSibling (&textEl);
1971: }
1972: while (textEl && elType.ElTypeNum == MathML_EL_XMLcomment);
1973:
1974: if (textEl && elType.ElTypeNum == MathML_EL_TEXT_UNIT)
1975: /* the mo element is not empty */
1976: {
1977: /* does the mo element have an IntAddSpace attribute? */
1978: attrType.AttrSSchema = MathMLSSchema;
1979: attrType.AttrTypeNum = MathML_ATTR_IntAddSpace;
1980: attr = TtaGetAttribute (el, attrType);
1981: if (attr == NULL)
1.60 cvs 1982: /* no IntAddSpace Attr, create one */
1.1 cvs 1983: {
1.155 quint 1984: attr = TtaNewAttribute (attrType);
1985: TtaAttachAttribute (el, attr, doc);
1986: }
1987: /* space on both sides by default */
1.185 vatton 1988: val = MathML_ATTR_IntAddSpace_VAL_both_;
1.155 quint 1989: /* does the mo element have a form attribute? */
1990: attrType.AttrTypeNum = MathML_ATTR_form;
1991: formAttr = TtaGetAttribute (el, attrType);
1992: if (formAttr)
1993: /* there is a form attribute */
1994: {
1995: form = TtaGetAttributeValue (formAttr);
1996: switch (form)
1997: {
1998: case MathML_ATTR_form_VAL_prefix:
1999: val = MathML_ATTR_IntAddSpace_VAL_nospace;
2000: break;
2001: case MathML_ATTR_form_VAL_infix:
1.185 vatton 2002: val = MathML_ATTR_IntAddSpace_VAL_both_;
1.155 quint 2003: break;
2004: case MathML_ATTR_form_VAL_postfix:
2005: val = MathML_ATTR_IntAddSpace_VAL_spaceafter;
2006: break;
2007: default:
1.185 vatton 2008: val = MathML_ATTR_IntAddSpace_VAL_both_;
1.155 quint 2009: break;
2010: }
1.1 cvs 2011: }
1.155 quint 2012: else
2013: /* no form attribute. Analyze the content */
2014: {
2015: len = TtaGetElementVolume (textEl);
2016: if (len == 1)
2017: {
2018: TtaGiveBufferContent (textEl, text, len+1, &lang);
2019: script = TtaGetScript (lang);
2020: /* the mo element contains a single character */
1.146 quint 2021: #ifndef _I18N_
1.155 quint 2022: if (script == 'L')
2023: /* ISO-Latin 1 character */
2024: {
1.146 quint 2025: #endif
1.155 quint 2026: if (text[0] == '-'
1.153 quint 2027: #ifdef _I18N_
1.155 quint 2028: || text[0] == 0x2212 /* minus */
1.153 quint 2029: #endif
1.155 quint 2030: )
2031: /* prefix or infix operator? */
2032: {
2033: /* skip preceding comments if any */
2034: previous = el;
2035: do
2036: {
2037: comment = FALSE;
2038: TtaPreviousSibling (&previous);
2039: if (previous)
2040: {
2041: elType = TtaGetElementType (previous);
2042: comment = (TtaSameSSchemas (elType.ElSSchema, MathMLSSchema) &&
2043: elType.ElTypeNum == MathML_EL_XMLcomment);
2044: }
2045: }
2046: while (previous && comment);
2047:
2048: if (previous == NULL)
2049: /* no previous sibling => prefix operator */
2050: val = MathML_ATTR_IntAddSpace_VAL_nospace;
2051: else
2052: {
2053: elType = TtaGetElementType (previous);
1.158 quint 2054: if (elType.ElTypeNum == MathML_EL_MO ||
2055: elType.ElTypeNum == MathML_EL_OpeningFence ||
2056: elType.ElTypeNum == MathML_EL_ClosingFence ||
2057: elType.ElTypeNum == MathML_EL_FencedSeparator)
1.155 quint 2058: /* after an operator => prefix operator */
2059: val = MathML_ATTR_IntAddSpace_VAL_nospace;
2060: else
2061: /* infix operator */
1.185 vatton 2062: val = MathML_ATTR_IntAddSpace_VAL_both_;
1.155 quint 2063: }
2064: }
2065: else if (text[0] == '&' ||
2066: text[0] == '*' ||
2067: text[0] == '+' ||
2068: text[0] == '/' ||
2069: text[0] == '<' ||
2070: text[0] == '=' ||
2071: text[0] == '>' ||
2072: text[0] == '^' ||
2073: (int)text[0] == 177 || /* plus or minus */
2074: (int)text[0] == 215 || /* times */
2075: (int)text[0] == 247) /* divide */
2076: /* infix operator */
1.185 vatton 2077: val = MathML_ATTR_IntAddSpace_VAL_both_;
1.155 quint 2078: else if (text[0] == ',' ||
2079: text[0] == '!' ||
2080: text[0] == '&' ||
2081: text[0] == ':' ||
2082: text[0] == ';')
2083: /* separator */
2084: val = MathML_ATTR_IntAddSpace_VAL_spaceafter;
2085: else if (text[0] == '(' ||
2086: text[0] == ')' ||
2087: text[0] == '[' ||
2088: text[0] == ']' ||
2089: text[0] == '{' ||
2090: text[0] == '}' ||
2091: text[0] == '.' ||
2092: text[0] == '@' ||
1.165 quint 2093: #ifndef _I18N_
2094: text[0] == 'd' || /* probably DifferentialD */
2095: #endif
1.155 quint 2096: (int)text[0] == 129 || /* thin space */
2097: (int)text[0] == 130 || /* en space */
2098: (int)text[0] == 160) /* em space */
2099: val = MathML_ATTR_IntAddSpace_VAL_nospace;
1.146 quint 2100: #ifndef _I18N_
1.155 quint 2101: }
2102: else if (script == 'G')
2103: {
2104: /* Symbol character set */
2105: if ((int)text[0] == 163 || /* less or equal */
2106: (int)text[0] == 177 || /* plus or minus */
2107: (int)text[0] == 179 || /* greater or equal */
2108: (int)text[0] == 180 || /* times */
2109: (int)text[0] == 184 || /* divide */
2110: (int)text[0] == 185 || /* not equal */
2111: (int)text[0] == 186 || /* identical */
2112: (int)text[0] == 187 || /* equivalent */
2113: (int)text[0] == 196 || /* circle times */
2114: (int)text[0] == 197 || /* circle plus */
2115: ((int)text[0] >= 199 && (int)text[0] <= 209) || /* */
2116: (int)text[0] == 217 || /* and */
2117: (int)text[0] == 218) /* or */
1.146 quint 2118: #else
1.155 quint 2119: else
2120: if ((int)text[0] == 0x2264 || /* less or equal */
2121: (int)text[0] == 0x00B1 || /* plus or minus */
2122: (int)text[0] == 0x2265 || /* greater or equal */
2123: (int)text[0] == 0x00D7 || /* times */
2124: (int)text[0] == 0x00F7 || /* divide */
2125: (int)text[0] == 0x2260 || /* not equal */
2126: (int)text[0] == 0x2261 || /* identical */
2127: (int)text[0] == 0x2248 || /* equivalent */
2128: (int)text[0] == 0x2297 || /* circle times */
2129: (int)text[0] == 0x2295 || /* circle plus */
2130: (int)text[0] == 0x2229 || /* Intersection */
2131: (int)text[0] == 0x222A || /* Union */
2132: (int)text[0] == 0x2283 || /* Superset of */
2133: (int)text[0] == 0x2287 || /* Superset of or equal to */
2134: (int)text[0] == 0x2284 || /* Not a subset of */
2135: (int)text[0] == 0x2282 || /* Subset of */
2136: (int)text[0] == 0x2286 || /* Subset of or equal to */
2137: (int)text[0] == 0x2208 || /* Element of */
2138: (int)text[0] == 0x2209 || /* Not an element of */
2139: (int)text[0] == 0x2220 || /* Angle */
2140: (int)text[0] == 0x2207 || /* Nabla */
2141: (int)text[0] == 0x2227 || /* and */
2142: (int)text[0] == 0x2228 || /* or */
2143: (int)text[0] == 0x2190 || /* left arrow */
2144: (int)text[0] == 0x2192 || /* right arrow */
2145: (int)text[0] == 0x2194) /* left right arrow */
1.146 quint 2146: #endif
1.155 quint 2147: /* infix operator */
1.185 vatton 2148: val = MathML_ATTR_IntAddSpace_VAL_both_;
1.155 quint 2149: else
2150: val = MathML_ATTR_IntAddSpace_VAL_nospace;
1.146 quint 2151: #ifndef _I18N_
1.155 quint 2152: }
1.146 quint 2153: #endif
1.155 quint 2154: }
2155: }
2156: TtaSetAttributeValue (attr, val, el, doc);
2157: }
1.1 cvs 2158: }
2159:
2160: /*----------------------------------------------------------------------
1.58 cvs 2161: ChildOfMRowOrInferred
2162: Return TRUE if element el is a child of a MROW element or an
2163: inferred MROW element
2164: ----------------------------------------------------------------------*/
2165: ThotBool ChildOfMRowOrInferred (Element el)
2166: {
2167: ElementType elType;
2168: Element parent;
2169: ThotBool result;
2170:
2171: result = FALSE;
2172: parent = TtaGetParent (el);
2173: if (parent)
2174: {
2175: elType = TtaGetElementType (parent);
2176: result = (elType.ElTypeNum == MathML_EL_MROW ||
2177: elType.ElTypeNum == MathML_EL_SqrtBase ||
2178: elType.ElTypeNum == MathML_EL_MSTYLE ||
2179: elType.ElTypeNum == MathML_EL_MERROR ||
1.92 cvs 2180: elType.ElTypeNum == MathML_EL_MENCLOSE ||
1.58 cvs 2181: elType.ElTypeNum == MathML_EL_MPADDED ||
2182: elType.ElTypeNum == MathML_EL_MPHANTOM ||
1.158 quint 2183: elType.ElTypeNum == MathML_EL_MFENCED ||
1.58 cvs 2184: elType.ElTypeNum == MathML_EL_CellWrapper ||
1.92 cvs 2185: elType.ElTypeNum == MathML_EL_MathML ||
1.58 cvs 2186: elType.ElTypeNum == MathML_EL_FencedExpression);
2187: }
2188: return result;
2189: }
2190:
2191: /*----------------------------------------------------------------------
1.175 quint 2192: CheckFence
2193: If el is a MO element of a fence,
2194: if it's a child of a MROW (or equivalent) element and if it contains
2195: a single fence character, transform the MO into a MF and the fence
2196: character into a Thot stretchable symbol.
2197: ----------------------------------------------------------------------*/
2198: void CheckFence (Element el, Document doc)
2199: {
2200: ElementType elType, contType;
2201: Element content;
2202: AttributeType attrType;
2203: Attribute attr, attrStretchy;
2204: Language lang;
2205: CHAR_T text[2];
2206: char script;
2207: unsigned char c;
2208: int len, val, oldStructureChecking;
1.170 quint 2209:
1.175 quint 2210: elType = TtaGetElementType (el);
2211: if (elType.ElTypeNum == MathML_EL_MO ||
2212: elType.ElTypeNum == MathML_EL_OpeningFence ||
2213: elType.ElTypeNum == MathML_EL_ClosingFence ||
2214: elType.ElTypeNum == MathML_EL_FencedSeparator)
2215: /* the element is a MO or equivalent */
2216: {
2217: content = TtaGetFirstChild (el);
2218: if (content != NULL)
2219: {
2220: contType = TtaGetElementType (content);
2221: if (contType.ElTypeNum == MathML_EL_TEXT_UNIT)
2222: {
2223: len = TtaGetElementVolume (content);
2224: if (len == 1)
2225: /* the MO or fence element contains a single character */
2226: {
2227: TtaGiveBufferContent (content, text, len+1, &lang);
2228: script = TtaGetScript (lang);
2229: if (ChildOfMRowOrInferred (el))
2230: /* the MO or fence element is a child of a MROW element */
1.170 quint 2231: /* Is it a stretchable symbol? */
1.1 cvs 2232: {
1.177 quint 2233: if (IsStretchyFence (text[0], script))
1.84 cvs 2234: /* it's a stretchable parenthesis or equivalent */
2235: {
2236: /* remove the content of the MO element */
2237: TtaDeleteTree (content, doc);
2238: /* change the MO element into a MF element */
1.158 quint 2239: if (elType.ElTypeNum == MathML_EL_MO)
2240: ChangeTypeOfElement (el, doc, MathML_EL_MF);
1.84 cvs 2241: /* is there an attribute stretchy on this mo element? */
2242: attrType.AttrSSchema = elType.ElSSchema;
2243: attrType.AttrTypeNum = MathML_ATTR_stretchy;
2244: attrStretchy = TtaGetAttribute (el, attrType);
2245: if (attrStretchy)
2246: val = TtaGetAttributeValue (attrStretchy);
2247: else
2248: val = MathML_ATTR_stretchy_VAL_true;
2249: if (val == MathML_ATTR_stretchy_VAL_true)
2250: {
1.158 quint 2251: /* attach a IntVertStretch attribute to the MF element */
1.84 cvs 2252: attrType.AttrTypeNum = MathML_ATTR_IntVertStretch;
1.158 quint 2253: attr = TtaGetAttribute (el, attrType);
2254: if (!attr)
2255: {
2256: attr = TtaNewAttribute (attrType);
2257: TtaAttachAttribute (el, attr, doc);
2258: }
1.84 cvs 2259: TtaSetAttributeValue (attr,
2260: MathML_ATTR_IntVertStretch_VAL_yes_,
2261: el, doc);
2262: }
2263: /* create a new content for the MF element */
1.87 cvs 2264: elType.ElTypeNum = MathML_EL_SYMBOL_UNIT;
1.146 quint 2265: #ifdef _I18N_
2266: if (text[0] == 9002)
2267: #else
1.143 vatton 2268: if (script == 'G' && text[0] == 241)
1.146 quint 2269: #endif
1.102 cvs 2270: c = '>'; /* RightAngleBracket */
2271: else
1.146 quint 2272: #ifdef _I18N_
2273: if (text[0] == 9001)
2274: #else
2275: if (script == 'G' && text[0] == 225)
2276: #endif
2277: c = '<'; /* LeftAngleBracket */
2278: else
2279: c = (char) text[0];
1.84 cvs 2280: content = TtaNewElement (doc, elType);
1.158 quint 2281: /* do not check the Thot abstract tree against the structure
2282: schema while inserting this child element */
2283: oldStructureChecking = TtaGetStructureChecking (doc);
2284: TtaSetStructureChecking (0, doc);
1.84 cvs 2285: TtaInsertFirstChild (&content, el, doc);
2286: TtaSetGraphicsShape (content, c, doc);
1.158 quint 2287: /* resume structure checking */
2288: TtaSetStructureChecking ((ThotBool)oldStructureChecking, doc);
1.84 cvs 2289: }
1.1 cvs 2290: }
1.84 cvs 2291: }
2292: }
1.58 cvs 2293: }
2294: }
1.1 cvs 2295: }
2296:
2297: /*----------------------------------------------------------------------
2298: CreateFencedSeparators
2299: Create FencedSeparator elements within the fencedExpression
2300: according to attribute separators of the MFENCED element.
2301: ----------------------------------------------------------------------*/
1.110 cvs 2302: void CreateFencedSeparators (Element fencedExpression, Document doc, ThotBool record)
1.1 cvs 2303: {
2304: ElementType elType;
2305: Element child, separator, leaf, next, prev, mfenced;
2306: AttributeType attrType;
2307: Attribute attr;
2308: int length, sep, i;
2309: Language lang;
1.116 cvs 2310: char text[32], sepValue[4];
1.1 cvs 2311:
2312: /* get the separators attribute */
2313: mfenced = TtaGetParent (fencedExpression);
2314: elType = TtaGetElementType (fencedExpression);
2315: attrType.AttrSSchema = elType.ElSSchema;
2316: attrType.AttrTypeNum = MathML_ATTR_separators;
2317: text[0] = ','; /* default value is sparators="," */
2318: text[1] = EOS;
2319: length = 1;
2320: attr = TtaGetAttribute (mfenced, attrType);
2321: if (attr != NULL)
2322: {
2323: length = 31;
2324: TtaGiveTextAttributeValue (attr, text, &length);
2325: }
2326:
2327: /* create FencedSeparator elements in the FencedExpression */
2328: prev = NULL;
2329: sep = 0;
2330: /* skip leading spaces in attribute separators */
2331: while (text[sep] <= SPACE && text[sep] != EOS)
2332: sep++;
2333: /* if attribute separators is empty or contains only spaces, do not
2334: insert any separator element */
2335: if (text[sep] != EOS)
2336: {
2337: child = TtaGetFirstChild (fencedExpression);
2338: while (child != NULL)
2339: {
2340: next = child;
2341: TtaNextSibling (&next);
2342: elType = TtaGetElementType (child);
2343: if (elType.ElTypeNum != MathML_EL_Construct)
2344: {
2345: if (prev != NULL)
2346: {
2347: elType.ElTypeNum = MathML_EL_FencedSeparator;
2348: separator = TtaNewElement (doc, elType);
2349: TtaInsertSibling (separator, prev, FALSE, doc);
2350: elType.ElTypeNum = MathML_EL_TEXT_UNIT;
2351: leaf = TtaNewElement (doc, elType);
2352: TtaInsertFirstChild (&leaf, separator, doc);
2353: sepValue[0] = text[sep];
1.158 quint 2354: sepValue[1] = EOS;
1.143 vatton 2355: lang = TtaGetLanguageIdFromScript('L');
1.1 cvs 2356: TtaSetTextContent (leaf, sepValue, lang, doc);
1.158 quint 2357: SetIntAddSpaceAttr (separator, doc);
2358: SetIntVertStretchAttr (separator, doc, 0, NULL);
1.175 quint 2359: CheckFence (separator, doc);
1.158 quint 2360:
1.1 cvs 2361: /* is there a following non-space character in separators? */
2362: i = sep + 1;
2363: while (text[i] <= SPACE && text[i] != EOS)
2364: i++;
2365: if (text[i] > SPACE && text[i] != EOS)
2366: sep = i;
1.17 cvs 2367: if (record)
2368: TtaRegisterElementCreate (separator, doc);
1.1 cvs 2369: }
2370: prev = child;
2371: }
2372: child = next;
2373: }
2374: }
2375: }
2376:
1.124 cvs 2377: /*----------------------------------------------------------------------
2378: CreateOpeningOrClosingFence
2379: Create the OpeningFence or ClosingFence element (depending on parameter
2380: open) for the MFENCED element el which contain the fencedExpression
2381: element.
2382: ----------------------------------------------------------------------*/
2383: static void CreateOpeningOrClosingFence (Element fencedExpression,
2384: Element el, Document doc,
2385: ThotBool open)
2386: {
2387: ElementType elType;
2388: Element leaf, fence;
2389: AttributeType attrType;
2390: Attribute attr;
2391: int length;
2392: char text[32];
2393:
2394: elType = TtaGetElementType (el);
2395: attrType.AttrSSchema = elType.ElSSchema;
2396: if (open)
2397: {
1.158 quint 2398: text[0] = '('; /* default value of attribute 'open' */
1.124 cvs 2399: attrType.AttrTypeNum = MathML_ATTR_open;
2400: elType.ElTypeNum = MathML_EL_OpeningFence;
2401: }
2402: else
2403: {
1.158 quint 2404: text[0] = ')'; /* default value of attribute 'close' */
1.124 cvs 2405: attrType.AttrTypeNum = MathML_ATTR_close;
2406: elType.ElTypeNum = MathML_EL_ClosingFence;
2407: }
2408: attr = TtaGetAttribute (el, attrType);
2409: if (attr != NULL)
2410: {
2411: length = 31;
2412: TtaGiveTextAttributeValue (attr, text, &length);
2413: if (length != 1)
2414: /* content of attribute open or close should be a single character */
1.158 quint 2415: text[0] = '?';
1.124 cvs 2416: }
1.158 quint 2417: text[1] = EOS;
1.124 cvs 2418: fence = TtaNewElement (doc, elType);
2419: TtaInsertSibling (fence, fencedExpression, open, doc);
1.158 quint 2420: elType.ElTypeNum = MathML_EL_TEXT_UNIT;
1.124 cvs 2421: leaf = TtaNewElement (doc, elType);
2422: TtaInsertFirstChild (&leaf, fence, doc);
1.158 quint 2423: TtaSetTextContent (leaf, text, TtaGetLanguageIdFromScript('L'), doc);
2424: SetIntAddSpaceAttr (fence, doc);
2425: SetIntVertStretchAttr (fence, doc, 0, NULL);
1.175 quint 2426: CheckFence (fence, doc);
1.124 cvs 2427: }
1.1 cvs 2428:
2429: /*----------------------------------------------------------------------
2430: TransformMFENCED
2431: Transform the content of a MFENCED element: create elements
2432: OpeningFence, FencedExpression, ClosingFence and FencedSeparator.
2433: ----------------------------------------------------------------------*/
1.46 cvs 2434: static void TransformMFENCED (Element el, Document doc)
1.1 cvs 2435: {
2436: ElementType elType;
1.124 cvs 2437: Element child, fencedExpression, next, prev, firstChild;
1.1 cvs 2438:
2439: child = TtaGetFirstChild (el);
2440: if (child != NULL)
2441: elType = TtaGetElementType (child);
2442: if (child != NULL && elType.ElTypeNum == MathML_EL_OpeningFence)
2443: /* The first child of this MFENCED element is an OpeningFence.
2444: This MFENCED expression has already been transformed, possibly
2445: by the Transform command */
2446: {
2447: TtaNextSibling (&child);
2448: fencedExpression = child;
2449: if (fencedExpression != NULL)
2450: elType = TtaGetElementType (fencedExpression);
2451: if (elType.ElTypeNum == MathML_EL_FencedExpression)
2452: /* the second child is a FencedExpression. OK.
2453: Remove all existing FencedSeparator elements */
2454: {
2455: child = TtaGetFirstChild (fencedExpression);
2456: prev = NULL;
2457: while (child != NULL)
2458: {
2459: elType = TtaGetElementType (child);
2460: next = child;
2461: TtaNextSibling (&next);
2462: if (elType.ElTypeNum == MathML_EL_FencedSeparator)
2463: /* Remove this separator */
2464: TtaDeleteTree (child, doc);
2465: child = next;
2466: }
2467: /* create FencedSeparator elements in the FencedExpression */
1.17 cvs 2468: CreateFencedSeparators (fencedExpression, doc, FALSE);
1.1 cvs 2469: }
2470: }
2471: else
2472: /* this MFENCED element must be transformed */
2473: {
2474: /* create a FencedExpression element as a child of the MFENCED elem. */
2475: elType = TtaGetElementType (el);
2476: elType.ElTypeNum = MathML_EL_FencedExpression;
2477: fencedExpression = TtaNewElement (doc, elType);
2478: TtaInsertFirstChild (&fencedExpression, el, doc);
2479: if (child == NULL)
2480: /* empty MFENCED element */
2481: {
2482: elType.ElTypeNum = MathML_EL_Construct;
2483: child = TtaNewElement (doc, elType);
2484: TtaInsertFirstChild (&child, fencedExpression, doc);
1.22 cvs 2485: SetIntPlaceholderAttr (child, doc);
1.1 cvs 2486: }
2487: else
2488: {
2489: /* move the content of the MFENCED element within the new
2490: FencedExpression element */
2491: prev = NULL;
2492: firstChild = NULL;
2493: while (child != NULL)
2494: {
2495: next = child;
2496: TtaNextSibling (&next);
2497: TtaRemoveTree (child, doc);
2498: if (prev == NULL)
2499: {
2500: TtaInsertFirstChild (&child, fencedExpression, doc);
2501: firstChild = child;
2502: }
2503: else
2504: TtaInsertSibling (child, prev, FALSE, doc);
2505: prev = child;
2506: child = next;
2507: }
2508:
2509: /* create FencedSeparator elements in the FencedExpression */
1.17 cvs 2510: CreateFencedSeparators (fencedExpression, doc, FALSE);
1.1 cvs 2511:
2512: /* Create placeholders within the FencedExpression element */
2513: CreatePlaceholders (firstChild, doc);
2514: }
2515:
2516: /* create the OpeningFence element according to the open attribute */
1.124 cvs 2517: CreateOpeningOrClosingFence (fencedExpression, el, doc, TRUE);
1.1 cvs 2518:
2519: /* create the ClosingFence element according to close attribute */
1.124 cvs 2520: CreateOpeningOrClosingFence (fencedExpression, el, doc, FALSE);
1.1 cvs 2521: }
2522: }
2523:
2524: /*----------------------------------------------------------------------
1.59 cvs 2525: MathMLScriptShift
2526: The MathML attribute attr (superscriptshift or subscriptshift) is associated
2527: with element el (a msub, msup or msubsup).
2528: If value is not NULL, generate the corresponding Thot VertPos rule for the
2529: Subscript or Superscript child of el.
2530: If value is NULL, remove the Thot VertPos rule.
2531: -----------------------------------------------------------------------*/
1.120 cvs 2532: void MathMLScriptShift (Document doc, Element el, char *value, int attr)
1.59 cvs 2533: {
2534: ElementType elType;
2535: Element script, child;
2536: int scrType;
2537: PresentationValue pval;
2538: PresentationContext ctxt;
2539:
2540: /* get the Superscript or Subscript child of el */
2541: if (attr == MathML_ATTR_superscriptshift)
2542: scrType = MathML_EL_Superscript;
2543: else if (attr == MathML_ATTR_subscriptshift)
2544: scrType = MathML_EL_Subscript;
2545: else
2546: return;
2547: script = NULL;
2548: child = TtaGetFirstChild (el);
2549: while (!script && child)
2550: {
2551: elType = TtaGetElementType (child);
2552: if (elType.ElTypeNum == scrType)
2553: script = child;
2554: else
2555: TtaNextSibling (&child);
2556: }
2557: if (script)
2558: /* Superscript or Subscript element found */
2559: {
2560: ctxt = TtaGetSpecificStyleContext (doc);
2561: if (!value)
2562: /* remove the presentation rule */
2563: {
2564: ctxt->destroy = TRUE;
1.75 cvs 2565: pval.typed_data.value = 0;
1.59 cvs 2566: TtaSetStylePresentation (PRVertPos, script, NULL, ctxt, pval);
2567: }
2568: else
2569: {
2570: ctxt->destroy = FALSE;
2571: /* parse the attribute value (a number followed by a unit) */
1.119 cvs 2572: value = TtaSkipBlanks (value);
1.59 cvs 2573: value = ParseCSSUnit (value, &pval);
1.184 vatton 2574: if (pval.typed_data.unit != UNIT_INVALID)
1.59 cvs 2575: {
1.184 vatton 2576: if (pval.typed_data.unit == UNIT_BOX)
2577: pval.typed_data.unit = UNIT_EM;
1.181 vatton 2578: /* the specific presentation to be created is not a CSS rule */
2579: ctxt->cssSpecificity = 0;
2580: if (attr == MathML_ATTR_superscriptshift)
2581: pval.typed_data.value = - pval.typed_data.value;
2582: TtaSetStylePresentation (PRVertPos, script, NULL, ctxt, pval);
1.59 cvs 2583: }
2584: }
2585: TtaFreeMemory (ctxt);
2586: }
2587: }
2588:
2589: /*----------------------------------------------------------------------
2590: SetScriptShift
2591: If element el (which is a msup, msub or msubsup) has an attribute
2592: att (which is subscriptshift or superscriptshift), generate the
2593: corresponding Thot presentation rule.
2594: ----------------------------------------------------------------------*/
1.120 cvs 2595: static void SetScriptShift (Element el, Document doc, int att)
1.59 cvs 2596: {
2597: AttributeType attrType;
2598: ElementType elType;
2599: Attribute attr;
1.120 cvs 2600: char *value;
1.59 cvs 2601: int length;
2602:
2603: elType = TtaGetElementType (el);
2604: attrType.AttrSSchema = elType.ElSSchema;
2605: attrType.AttrTypeNum = att;
2606: attr = TtaGetAttribute (el, attrType);
2607: if (attr)
2608: {
2609: length = TtaGetTextAttributeLength (attr);
2610: if (length > 0)
2611: {
1.116 cvs 2612: value = TtaGetMemory (length+1);
1.59 cvs 2613: value[0] = EOS;
2614: TtaGiveTextAttributeValue (attr, value, &length);
2615: MathMLScriptShift (doc, el, value, att);
2616: TtaFreeMemory (value);
2617: }
2618: }
2619: }
2620:
2621: /*----------------------------------------------------------------------
1.159 quint 2622: DeleteIntRowAlign
2623: Remove attribute IntRowAlign from element row if there is no rowalign_mtr
2624: attribut on this element.
2625: -----------------------------------------------------------------------*/
2626: static void DeleteIntRowAlign (Element row, Document doc)
2627: {
2628: ElementType elType;
2629: AttributeType attrType;
2630: Attribute attr;
2631:
2632: elType = TtaGetElementType (row);
2633: attrType.AttrSSchema = elType.ElSSchema;
2634: attrType.AttrTypeNum = MathML_ATTR_rowalign_mtr;
2635: attr = TtaGetAttribute (row, attrType);
2636: if (!attr)
2637: {
2638: attrType.AttrTypeNum = MathML_ATTR_IntRowAlign;
2639: attr = TtaGetAttribute (row, attrType);
2640: if (attr)
2641: TtaRemoveAttribute (row, attr, doc);
2642: }
2643: }
2644:
2645: /*----------------------------------------------------------------------
2646: SetIntRowAlign
2647: Set attribute IntRowAlign for element row unless this element already has
2648: a rowalign_mtr attribute
2649: -----------------------------------------------------------------------*/
2650: static void SetIntRowAlign (Element row, int val, Document doc)
2651: {
2652: ElementType elType;
2653: AttributeType attrType;
2654: Attribute attr;
2655:
2656: elType = TtaGetElementType (row);
2657: attrType.AttrSSchema = elType.ElSSchema;
2658: attrType.AttrTypeNum = MathML_ATTR_rowalign_mtr;
2659: attr = TtaGetAttribute (row, attrType);
2660: if (!attr)
2661: {
2662: attrType.AttrTypeNum = MathML_ATTR_IntRowAlign;
2663: attr = TtaGetAttribute (row, attrType);
2664: if (!attr)
2665: {
2666: attr = TtaNewAttribute (attrType);
2667: TtaAttachAttribute (row, attr, doc);
2668: }
2669: TtaSetAttributeValue (attr, val, row, doc);
2670: }
2671: }
2672:
2673: /*----------------------------------------------------------------------
2674: HandleRowalignAttribute
2675: An attribute rowalign has been created, updated (if !delete) or deleted
2676: (if delete) for element el in document doc. Update the IntRowAlign
2677: attributes of all enclosed mrow elements accordingly.
2678: ----------------------------------------------------------------------*/
2679: void HandleRowalignAttribute (Attribute attr, Element el, Document doc,
2680: ThotBool delete)
2681: {
2682: char *value;
2683: char *ptr;
2684: int length, val;
2685: ElementType elType;
2686: Element row;
2687:
2688: elType = TtaGetElementType (el);
2689: if (elType.ElTypeNum != MathML_EL_MTABLE ||
2690: strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
2691: /* ignore rowalign attribute on mstyle elements */
2692: /* process it only on mtable elements */
2693: return;
2694:
2695: value = NULL;
2696: if (!delete)
2697: {
2698: length = TtaGetTextAttributeLength (attr);
2699: if (length > 0)
2700: {
2701: value = TtaGetMemory (length+1);
2702: value[0] = EOS;
2703: TtaGiveTextAttributeValue (attr, value, &length);
2704: }
2705: }
2706: /* if attribute rowalign is created or updated but has no value, don't
2707: do anything */
2708: if (!delete && !value)
2709: return;
2710:
2711: ptr = value;
2712: val = 0;
2713: elType.ElTypeNum = MathML_EL_TableRow;
2714: row = TtaSearchTypedElement (elType, SearchInTree, el);
2715: while (row)
2716: {
2717: elType = TtaGetElementType (row);
2718: /* skip comments and other non row elements */
2719: if ((elType.ElTypeNum == MathML_EL_MTR ||
2720: elType.ElTypeNum == MathML_EL_MLABELEDTR) &&
2721: strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
2722: {
2723: if (delete)
2724: DeleteIntRowAlign (row, doc);
2725: else
2726: {
2727: if (*ptr != EOS)
2728: {
2729: /* get next word in the attribute value */
2730: ptr = TtaSkipBlanks (ptr);
2731: /* process that word */
2732: if (*ptr != EOS && *ptr != ' ')
2733: {
2734: if (!strncasecmp (ptr, "top", 3))
2735: val = MathML_ATTR_IntRowAlign_VAL_IntTop;
2736: else if (!strncasecmp (ptr, "bottom", 6))
2737: val = MathML_ATTR_IntRowAlign_VAL_IntBottom;
2738: else if (!strncasecmp (ptr, "center", 6))
2739: val = MathML_ATTR_IntRowAlign_VAL_IntCenter;
2740: else if (!strncasecmp (ptr, "baseline", 8))
2741: val = MathML_ATTR_IntRowAlign_VAL_IntBaseline;
2742: else if (!strncasecmp (ptr, "axis", 4))
2743: val = MathML_ATTR_IntRowAlign_VAL_IntAxis;
2744: else
2745: val = 0;
2746: /* skip the word that has been processed */
2747: while (*ptr != EOS && *ptr != ' ')
2748: ptr++;
2749: }
2750: }
2751: if (val > 0)
2752: SetIntRowAlign (row, val, doc);
2753: }
2754: }
2755: TtaNextSibling (&row);
2756: }
2757: if (value)
2758: TtaFreeMemory (value);
2759: }
2760:
2761: /*----------------------------------------------------------------------
2762: DeleteIntColAlign
2763: Remove attribute IntColAlign from element cell if there is no columnalign_mtd
2764: attribut on this element.
2765: -----------------------------------------------------------------------*/
2766: static void DeleteIntColAlign (Element cell, Document doc)
2767: {
2768: ElementType elType;
2769: AttributeType attrType;
2770: Attribute attr;
2771:
2772: elType = TtaGetElementType (cell);
2773: attrType.AttrSSchema = elType.ElSSchema;
2774: attrType.AttrTypeNum = MathML_ATTR_columnalign_mtd;
2775: attr = TtaGetAttribute (cell, attrType);
2776: if (!attr)
2777: {
2778: attrType.AttrTypeNum = MathML_ATTR_IntColAlign;
2779: attr = TtaGetAttribute (cell, attrType);
2780: if (attr)
2781: TtaRemoveAttribute (cell, attr, doc);
2782: }
2783: }
2784:
2785: /*----------------------------------------------------------------------
2786: SetIntColAlign
2787: Set attribute IntColAlign for element cell unless this element already has
2788: a columnalign_mtd attribute
2789: -----------------------------------------------------------------------*/
2790: static void SetIntColAlign (Element cell, int val, Document doc)
2791: {
2792: ElementType elType;
2793: AttributeType attrType;
2794: Attribute attr;
2795:
2796: elType = TtaGetElementType (cell);
2797: attrType.AttrSSchema = elType.ElSSchema;
2798: attrType.AttrTypeNum = MathML_ATTR_columnalign_mtd;
2799: attr = TtaGetAttribute (cell, attrType);
2800: if (!attr)
2801: {
2802: attrType.AttrTypeNum = MathML_ATTR_IntColAlign;
2803: attr = TtaGetAttribute (cell, attrType);
2804: if (!attr)
2805: {
2806: attr = TtaNewAttribute (attrType);
2807: TtaAttachAttribute (cell, attr, doc);
2808: }
2809: TtaSetAttributeValue (attr, val, cell, doc);
2810: }
2811: }
2812:
2813: /*----------------------------------------------------------------------
2814: RowWithoutColalignAttr
2815: if skip: if element row has a columnalign attribute, get the next sibling row
2816: element without a columnalign attribute and return its first cell
2817: if not skip: always return the first cell in the row, and the columnalign
2818: attribute of that row if there is one.
2819: -----------------------------------------------------------------------*/
2820: static void RowWithoutColalignAttr (Element *row, Element *cell,
2821: Attribute *attr, ThotBool skip)
2822: {
2823: ElementType elType;
2824: AttributeType attrType;
2825:
2826: elType = TtaGetElementType (*row);
2827: attrType.AttrSSchema = elType.ElSSchema;
2828: attrType.AttrTypeNum = MathML_ATTR_columnalign;
2829: *cell = NULL;
2830: *attr = NULL;
2831: while (*row != NULL && *cell == NULL)
2832: {
2833: elType = TtaGetElementType (*row);
2834: if ((elType.ElTypeNum != MathML_EL_MTR &&
2835: elType.ElTypeNum != MathML_EL_MLABELEDTR) ||
2836: strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
2837: /* not a row. Skip it */
2838: TtaNextSibling (row);
2839: else
2840: {
2841: /* skip that row if it has a columnalign attribute */
2842: *attr = TtaGetAttribute (*row, attrType);
2843: if (skip && *attr != NULL)
2844: {
2845: TtaNextSibling (row);
2846: *attr = NULL;
2847: }
2848: else
2849: /* it's a row without a columnalign attribute */
2850: *cell = TtaGetFirstChild (*row);
2851: }
2852: }
2853: }
2854:
2855: /*----------------------------------------------------------------------
2856: HandleColalignAttribute
2857: An attribute columnalign has been created, updated (if !delete) or deleted
2858: (if delete) for element el in document doc. Update the IntColAlign
2859: attributes of all concerned cells accordingly.
2860: If allRows is TRUE, process also rows that have their own columnalign
2861: attribute, according to that attribute, otherwise skip those rows.
2862: ----------------------------------------------------------------------*/
2863: void HandleColalignAttribute (Attribute attr, Element el, Document doc,
2864: ThotBool delete, ThotBool allRows)
2865: {
2866: char *value, *localValue;
2867: char *ptr;
2868: int length, val;
2869: ElementType elType;
2870: Element cell, row;
2871: Attribute localAttr;
2872: ThotBool fullTable;
2873:
2874: elType = TtaGetElementType (el);
2875: if ((elType.ElTypeNum != MathML_EL_MTABLE &&
2876: elType.ElTypeNum != MathML_EL_MTR &&
2877: elType.ElTypeNum != MathML_EL_MLABELEDTR) ||
2878: strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
2879: /* ignore columnalign attribute on mstyle elements */
2880: /* process it only on mtable elements */
2881: return;
2882:
2883: fullTable = (elType.ElTypeNum == MathML_EL_MTABLE);
2884: value = NULL;
2885: localValue = NULL;
2886: if (!delete)
2887: {
2888: length = TtaGetTextAttributeLength (attr);
2889: if (length > 0)
2890: {
2891: value = TtaGetMemory (length+1);
2892: value[0] = EOS;
2893: TtaGiveTextAttributeValue (attr, value, &length);
2894: }
2895: }
2896: /* if attribute columnalign is created or updated but has no value, don't
2897: do anything */
2898: if (!delete && !value)
2899: return;
2900:
2901: ptr = value;
2902: val = 0;
2903: /* get the first cell within the element */
2904: elType.ElTypeNum = MathML_EL_MTD;
2905: cell = TtaSearchTypedElement (elType, SearchInTree, el);
2906: if (cell && fullTable)
2907: {
2908: elType.ElTypeNum = MathML_EL_TableRow;
2909: row = TtaGetTypedAncestor (cell, elType);
2910: RowWithoutColalignAttr (&row, &cell, &localAttr, !allRows);
2911: if (localAttr)
2912: {
2913: length = TtaGetTextAttributeLength (localAttr);
2914: if (length > 0)
2915: {
2916: if (localValue)
2917: TtaFreeMemory (localValue);
2918: localValue = TtaGetMemory (length+1);
2919: localValue[0] = EOS;
2920: TtaGiveTextAttributeValue (localAttr, localValue, &length);
2921: ptr = localValue;
2922: }
2923: }
2924: }
2925: while (cell)
2926: {
2927: elType = TtaGetElementType (cell);
2928: /* skip comments and other non cell elements */
2929: if (elType.ElTypeNum == MathML_EL_MTD &&
2930: strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
2931: {
2932: if (delete)
2933: DeleteIntColAlign (cell, doc);
2934: else
2935: {
2936: if (*ptr != EOS)
2937: {
2938: /* get next word in the attribute value */
2939: ptr = TtaSkipBlanks (ptr);
2940: /* process that word */
2941: if (*ptr != EOS && *ptr != ' ')
2942: {
2943: if (!strncasecmp (ptr, "left", 4))
2944: val = MathML_ATTR_IntColAlign_VAL_IntLeft;
2945: else if (!strncasecmp (ptr, "center", 6))
2946: val = MathML_ATTR_IntColAlign_VAL_IntCenter;
2947: else if (!strncasecmp (ptr, "right", 5))
2948: val = MathML_ATTR_IntColAlign_VAL_IntRight;
2949: else
2950: val = 0;
2951: /* skip the word that has been processed */
2952: while (*ptr != EOS && *ptr != ' ')
2953: ptr++;
2954: }
2955: }
2956: if (val > 0)
2957: SetIntColAlign (cell, val, doc);
2958: }
2959: }
2960: TtaNextSibling (&cell);
2961: if (!cell && fullTable && row)
2962: /* no more sibling cell. If the columnalign attribute is for the
2963: full table, get the first cell in the next row */
2964: {
2965: TtaNextSibling (&row);
2966: if (row)
2967: {
2968: /* parse value of columnalign attribute again from the beginning */
2969: ptr = value;
2970: RowWithoutColalignAttr (&row, &cell, &localAttr, !allRows);
2971: if (localAttr)
2972: {
2973: length = TtaGetTextAttributeLength (localAttr);
2974: if (length > 0)
2975: {
2976: if (localValue)
2977: TtaFreeMemory (localValue);
2978: localValue = TtaGetMemory (length+1);
2979: localValue[0] = EOS;
2980: TtaGiveTextAttributeValue (localAttr, localValue, &length);
2981: ptr = localValue;
2982: }
2983: }
2984: }
2985: }
2986: }
2987: if (value)
2988: TtaFreeMemory (value);
2989: if (localValue)
2990: TtaFreeMemory (localValue);
2991: }
2992:
2993: /*----------------------------------------------------------------------
1.167 quint 2994: HandleRowspacingAttribute
2995: An attribute rowspacing has been created, updated or deleted (if delete
2996: is TRUE) for element el in document doc. Update the top and bottom padding
2997: of all cells accordingly.
2998: ----------------------------------------------------------------------*/
2999: void HandleRowspacingAttribute (Attribute attr, Element el, Document doc,
3000: ThotBool delete)
3001: {
3002: ElementType elType, rowType, cellType;
3003: int length, val, topVal, topValUnit, bottomVal,
3004: bottomValUnit, rowspan, cellBottomVal, i;
3005: char *value, *ptr, *spanPtr;
3006: PresentationValue pval;
3007: PresentationContext ctxt;
3008: Element row, nextRow, cell;
3009: ThotBool stop, firstRow;
3010: AttributeType rowspanType;
3011: Attribute rowspanAttr;
3012:
3013: elType = TtaGetElementType (el);
3014: if (elType.ElTypeNum != MathML_EL_MTABLE ||
3015: strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
3016: /* ignore rowspacing attribute on mstyle elements */
3017: /* process it only on mtable elements */
3018: return;
3019:
3020: value = NULL;
3021: if (!delete && attr)
3022: {
3023: length = TtaGetTextAttributeLength (attr);
3024: if (length > 0)
3025: {
3026: value = TtaGetMemory (length+1);
3027: value[0] = EOS;
3028: TtaGiveTextAttributeValue (attr, value, &length);
3029: }
3030: }
3031:
3032: ctxt = TtaGetSpecificStyleContext (doc);
3033: /* the specific presentation to be created is not a CSS rule */
3034: ctxt->cssSpecificity = 0;
3035: ptr = value;
3036: rowspanType.AttrSSchema = elType.ElSSchema;
3037: rowspanType.AttrTypeNum = MathML_ATTR_rowspan_;
3038:
3039: /* check all rows within the table */
3040: firstRow = TRUE;
3041: bottomVal = 0;
1.184 vatton 3042: bottomValUnit = UNIT_PT;
1.167 quint 3043: elType.ElTypeNum = MathML_EL_TableRow;
3044: row = TtaSearchTypedElement (elType, SearchInTree, el);
3045: while (row)
3046: {
3047: /* get the next row to check if the current row is the last one */
3048: nextRow = row;
3049: stop = FALSE;
3050: do
3051: {
3052: TtaNextSibling (&nextRow);
3053: if (!nextRow)
3054: stop = TRUE;
3055: else
3056: {
3057: rowType = TtaGetElementType (nextRow);
3058: /* skip comments and other non mrow elements */
3059: if ((rowType.ElTypeNum == MathML_EL_MTR ||
3060: rowType.ElTypeNum == MathML_EL_MLABELEDTR) &&
3061: !strcmp (TtaGetSSchemaName (rowType.ElSSchema), "MathML"))
3062: /* it's the next mrow */
3063: stop = TRUE;
3064: }
3065: }
3066: while (!stop);
3067:
3068: /* prepare the value of the padding to be associated with the cells
3069: of that row */
1.182 quint 3070: val = 0;
1.167 quint 3071: if (delete)
3072: /* remove the presentation rules */
1.182 quint 3073: pval.typed_data.value = 0;
1.167 quint 3074: else
3075: {
3076: if (!value)
3077: {
1.184 vatton 3078: pval.typed_data.unit = UNIT_PT;
1.167 quint 3079: pval.typed_data.value = 0;
3080: pval.typed_data.real = FALSE;
3081: }
3082: else
3083: {
3084: /* get the next field in the attribute value (a number followed
3085: by a unit) */
3086: ptr = TtaSkipBlanks (ptr);
3087: if (*ptr != EOS)
3088: {
3089: ptr = ParseCSSUnit (ptr, &pval);
1.184 vatton 3090: if (pval.typed_data.unit != UNIT_INVALID)
1.167 quint 3091: {
1.184 vatton 3092: if (pval.typed_data.unit == UNIT_BOX)
3093: pval.typed_data.unit = UNIT_EM;
1.167 quint 3094: /* if the value is an integer, make it a real to avoid
3095: errors in dividing small integers, such as "1cm" */
3096: if (!pval.typed_data.real)
3097: {
3098: pval.typed_data.value *= 1000;
3099: pval.typed_data.real = TRUE;
3100: }
3101: val = pval.typed_data.value / 2;
3102: }
1.173 vatton 3103: else
3104: val = pval.typed_data.value;
1.167 quint 3105: }
3106: }
3107: }
3108:
3109: /* initialize the padding to be set at the top and at the bottom
3110: of each cell */
3111: /* the top padding of a row is the same as the bottom padding of the
3112: previous row */
3113: topVal = bottomVal;
3114: topValUnit = bottomValUnit;
3115: if (!nextRow)
3116: /* row is the last in the table. It must not have any padding
3117: at the bottom */
3118: bottomVal = 0;
3119: else
3120: {
3121: bottomVal = val;
3122: bottomValUnit = pval.typed_data.unit;
3123: }
3124:
3125: /* get the first cell of that row (ignoring Label cells) */
3126: elType.ElTypeNum = MathML_EL_MTD;
3127: cell = TtaSearchTypedElement (elType, SearchInTree, row);
3128: /* update attribute MLineBelowtop padding and bottom padding for all
3129: cells in that row */
3130: while (cell)
3131: {
3132: cellType = TtaGetElementType (cell);
3133: /* skip comments and other non mtd elements */
3134: if (cellType.ElTypeNum == MathML_EL_MTD &&
3135: !strcmp (TtaGetSSchemaName (cellType.ElSSchema), "MathML"))
3136: /* that's a mtd element. Process it */
3137: {
3138: /* by default, use the value for the current row */
3139: cellBottomVal = bottomVal;
3140: if (!delete && value)
3141: /* take row spanning into account */
3142: {
3143: /* is there a rowspan attribute on that cell? */
3144: rowspanAttr = TtaGetAttribute (cell, rowspanType);
3145: if (!rowspanAttr)
3146: rowspan = 1;
3147: else
3148: rowspan = TtaGetAttributeValue (rowspanAttr);
3149: if (!delete)
3150: {
3151: /* skip rowspan-1 words in the value of attribute
3152: rowlines */
3153: if (rowspan > 1)
3154: {
3155: spanPtr = ptr;
3156: for (i = 1; i < rowspan && *spanPtr != EOS; i++)
3157: {
3158: spanPtr = TtaSkipBlanks (spanPtr);
3159: spanPtr = ParseCSSUnit (spanPtr, &pval);
3160: }
1.184 vatton 3161: if (pval.typed_data.unit == UNIT_INVALID)
1.167 quint 3162: {
3163: val = 0;
3164: cellBottomVal = 0;
1.184 vatton 3165: bottomValUnit = UNIT_PT;
1.167 quint 3166: }
3167: else
3168: {
1.184 vatton 3169: if (pval.typed_data.unit == UNIT_BOX)
3170: pval.typed_data.unit = UNIT_EM;
1.167 quint 3171: /* if the value is an integer, make it a real to
3172: avoid errors in dividing small integers,
3173: such as "1cm" */
3174: if (!pval.typed_data.real)
3175: {
3176: pval.typed_data.value *= 1000;
3177: pval.typed_data.real = TRUE;
3178: }
3179: val = pval.typed_data.value / 2;
3180: cellBottomVal = val;
3181: bottomValUnit = pval.typed_data.unit;
3182: }
3183: }
3184: }
3185: }
3186:
3187: if ((delete || !value) && !firstRow)
3188: ctxt->destroy = TRUE;
3189: else
3190: {
3191: pval.typed_data.value = topVal;
3192: pval.typed_data.unit = topValUnit;
3193: ctxt->destroy = FALSE;
3194: }
3195: TtaSetStylePresentation (PRPaddingTop, cell, NULL, ctxt, pval);
3196: if ((delete || !value) && nextRow)
3197: ctxt->destroy = TRUE;
3198: else
3199: {
3200: pval.typed_data.value = cellBottomVal;
3201: pval.typed_data.unit = bottomValUnit;
3202: ctxt->destroy = FALSE;
3203: }
3204: TtaSetStylePresentation (PRPaddingBottom, cell, NULL, ctxt,pval);
3205: }
3206: TtaNextSibling (&cell);
3207: }
3208: row = nextRow;
3209: firstRow = FALSE;
3210: }
3211:
3212: TtaFreeMemory (ctxt);
3213: if (value)
3214: TtaFreeMemory (value);
3215: }
3216:
3217: /*----------------------------------------------------------------------
3218: ConvertNamedSpace
3219: if name is the name of a space, return the value of this space
3220: in value, otherwise return an empty string in value.
3221: -----------------------------------------------------------------------*/
3222: static char* ConvertNamedSpace (char *name, char *value)
3223: {
3224: if (strcmp (name, "veryverythinmathspace") == 0)
3225: {
3226: strcpy (value, "0.0555556em");
3227: return (name + strlen("veryverythinmathspace"));
3228: }
3229: else if (strcmp (name, "verythinmathspace") == 0)
3230: {
3231: strcpy (value, "0.111111em");
3232: return (name + strlen("verythinmathspace"));
3233: }
3234: else if (strcmp (name, "thinmathspace") == 0)
3235: {
3236: strcpy (value, "0.166667em");
3237: return (name + strlen("thinmathspace"));
3238: }
3239: else if (strcmp (name, "mediummathspace") == 0)
3240: {
3241: strcpy (value, "0.222222em");
3242: return (name + strlen("mediummathspace"));
3243: }
3244: else if (strcmp (name, "thickmathspace") == 0)
3245: {
3246: strcpy (value, "0.277778em");
3247: return (name + strlen("thickmathspace"));
3248: }
3249: else if (strcmp (name, "verythickmathspace") == 0)
3250: {
3251: strcpy (value, "0.333333em");
3252: return (name + strlen("verythickmathspace"));
3253: }
3254: else if (strcmp (name, "veryverythickmathspace") == 0)
3255: {
3256: strcpy (value, "0.388889em");
3257: return (name + strlen("veryverythickmathspace"));
3258: }
3259: else
3260: {
3261: value[0] = EOS;
3262: return name;
3263: }
3264: }
3265:
3266: /*----------------------------------------------------------------------
3267: HandleColumnspacingAttribute
3268: An attribute columnspacing has been created, updated or deleted (if delete
3269: is TRUE) for element el in document doc. Update the left and right padding
3270: of all cells accordingly.
3271: ----------------------------------------------------------------------*/
3272: void HandleColumnspacingAttribute (Attribute attr, Element el, Document doc,
3273: ThotBool delete)
3274: {
3275: ElementType elType;
3276: int length, val, valUnit, leftVal, leftValUnit,
3277: rightVal, rightValUnit, colspan, i;
3278: char *value, *ptr, valueOfNamedSpace[20];
3279: PresentationValue pval;
3280: PresentationContext ctxt;
3281: Element row, cell, nextCell;
3282: ThotBool stop, firstCell;
1.168 quint 3283: Attribute spanAttr;
1.167 quint 3284: AttributeType colspanType;
3285:
3286: elType = TtaGetElementType (el);
3287: if (elType.ElTypeNum != MathML_EL_MTABLE ||
3288: strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
3289: /* ignore columnspacing attribute on mstyle elements */
3290: /* process it only on mtable elements */
3291: return;
3292:
3293: value = NULL;
3294: if (!delete && attr)
3295: {
3296: length = TtaGetTextAttributeLength (attr);
3297: if (length > 0)
3298: {
3299: value = TtaGetMemory (length+1);
3300: value[0] = EOS;
3301: TtaGiveTextAttributeValue (attr, value, &length);
3302: }
3303: }
3304:
3305: ctxt = TtaGetSpecificStyleContext (doc);
3306: /* the specific presentation to be created is not a CSS rule */
3307: ctxt->cssSpecificity = 0;
3308: val = 0;
3309: colspanType.AttrSSchema = elType.ElSSchema;
3310: colspanType.AttrTypeNum = MathML_ATTR_columnspan;
3311:
3312: /* check all cells in all rows within the table */
3313: elType.ElTypeNum = MathML_EL_TableRow;
3314: row = TtaSearchTypedElement (elType, SearchInTree, el);
3315: while (row)
3316: {
3317: elType = TtaGetElementType (row);
3318: if ((elType.ElTypeNum == MathML_EL_MTR ||
3319: elType.ElTypeNum == MathML_EL_MLABELEDTR) &&
3320: strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
3321: /* that's a table row. check all its cells */
3322: {
3323: firstCell = TRUE;
3324: rightVal = 0;
3325: val = 0;
1.184 vatton 3326: valUnit = UNIT_PT;
1.167 quint 3327: ptr = value;
3328: /* get the first cell of that row (ignoring Label cells) */
3329: elType.ElTypeNum = MathML_EL_MTD;
3330: cell = TtaSearchTypedElement (elType, SearchInTree, row);
3331: while (cell)
3332: {
3333: /* prepare the value of the padding to be associated with the
3334: cells */
3335: if (delete)
3336: /* remove the presentation rules */
3337: {
3338: pval.typed_data.value = 0;
3339: val = 0;
1.184 vatton 3340: valUnit = UNIT_PT;
1.167 quint 3341: }
3342: else
3343: {
3344: if (!value)
3345: {
1.184 vatton 3346: pval.typed_data.unit = UNIT_PT;
1.167 quint 3347: pval.typed_data.value = 0;
3348: pval.typed_data.real = FALSE;
3349: val = 0;
1.184 vatton 3350: valUnit = UNIT_PT;
1.167 quint 3351: }
3352: else
3353: {
3354: /* parse the next field in the attribute value (a number
3355: followed by a unit or a named space) */
3356: ptr = TtaSkipBlanks (ptr);
3357: if (*ptr != EOS)
3358: {
3359: /* is there a columnspan attribute on that cell? */
3360: spanAttr = TtaGetAttribute (cell, colspanType);
3361: if (!spanAttr)
3362: colspan = 1;
3363: else
3364: colspan = TtaGetAttributeValue (spanAttr);
3365: /* skip (colspan - 1) words in the attribute */
3366: for (i = 1; i <= colspan && *ptr != EOS; i++)
3367: {
3368: ptr = TtaSkipBlanks (ptr);
3369: ptr = ConvertNamedSpace (ptr, valueOfNamedSpace);
3370: if (valueOfNamedSpace[0] != EOS)
3371: /* it's a named space */
3372: ptr = ParseCSSUnit (valueOfNamedSpace, &pval);
3373: else
3374: ptr = ParseCSSUnit (ptr, &pval);
1.184 vatton 3375: if (pval.typed_data.unit == UNIT_INVALID)
1.167 quint 3376: {
3377: val = 0;
1.184 vatton 3378: valUnit = UNIT_PT;
1.167 quint 3379: }
3380: else
3381: {
1.184 vatton 3382: if (pval.typed_data.unit == UNIT_BOX)
3383: pval.typed_data.unit = UNIT_EM;
1.167 quint 3384: /* if the value is an integer, make it a real
3385: to avoid errors in dividing small
3386: integers, such as "1cm" */
3387: if (!pval.typed_data.real)
3388: {
3389: pval.typed_data.value *= 1000;
3390: pval.typed_data.real = TRUE;
3391: }
3392: val = pval.typed_data.value / 2;
3393: valUnit = pval.typed_data.unit;
3394: }
3395: }
3396: }
3397: }
3398: }
3399:
3400: /* get the next cell in the current row to check if the current
3401: cell is the last one in the row */
3402: nextCell = cell;
3403: stop = FALSE;
3404: do
3405: {
3406: TtaNextSibling (&nextCell);
3407: if (!nextCell)
3408: stop = TRUE;
3409: else
3410: {
3411: elType = TtaGetElementType (nextCell);
3412: /* skip comments and other non mtd elements */
3413: if (elType.ElTypeNum == MathML_EL_MTD &&
3414: strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
3415: /* it's the next cell */
3416: stop = TRUE;
3417: }
3418: }
3419: while (!stop);
3420:
3421: /* initialize the padding to be set at the right and at the left
3422: of each cell */
3423: /* the leftPadding of a cell is the same as the right padding
3424: of the previous cell */
3425: leftVal = rightVal;
1.174 vatton 3426: leftValUnit = rightValUnit = valUnit;
1.167 quint 3427: if (!nextCell)
3428: /* it's the last cell in the row. It must not have any
3429: padding on the right */
3430: {
3431: rightVal = 0;
1.184 vatton 3432: rightValUnit = UNIT_PT;
1.167 quint 3433: }
3434: else
3435: {
3436: rightVal = val;
3437: rightValUnit = valUnit;
3438: }
3439:
3440: /* set the left and right padding for this cell */
3441: if ((delete || !value) && !firstCell)
3442: ctxt->destroy = TRUE;
3443: else
3444: {
3445: pval.typed_data.value = leftVal;
3446: pval.typed_data.unit = leftValUnit;
3447: ctxt->destroy = FALSE;
3448: }
3449: TtaSetStylePresentation (PRPaddingLeft, cell, NULL, ctxt, pval);
3450: if ((delete || !value) && nextCell)
3451: ctxt->destroy = TRUE;
3452: else
3453: {
3454: pval.typed_data.value = rightVal;
3455: pval.typed_data.unit = rightValUnit;
3456: ctxt->destroy = FALSE;
3457: }
3458: TtaSetStylePresentation (PRPaddingRight, cell, NULL, ctxt, pval);
3459: cell = nextCell;
3460: firstCell = FALSE;
3461: }
3462: }
3463: TtaNextSibling (&row);
3464: }
3465:
3466: if (value)
3467: TtaFreeMemory (value);
3468: }
3469:
3470: /*----------------------------------------------------------------------
1.159 quint 3471: HandleRowlinesAttribute
3472: An attribute rowlines has been created, updated or deleted (if delete
3473: is TRUE) for element el in document doc. Update attribute MLineBelow
3474: of all cells accordingly.
3475: ----------------------------------------------------------------------*/
3476: void HandleRowlinesAttribute (Attribute attr, Element el, Document doc,
3477: ThotBool delete)
3478: {
3479: char *value;
1.160 quint 3480: char *ptr, *spanPtr;
3481: int length, val, rowspan, i, cellVal;
1.159 quint 3482: ElementType elType, rowType, cellType;
3483: Element row, nextRow, cell;
3484: ThotBool stop;
1.160 quint 3485: AttributeType attrType, rowspanType;
3486: Attribute intAttr, rowspanAttr;
1.159 quint 3487:
3488: elType = TtaGetElementType (el);
3489: if (elType.ElTypeNum != MathML_EL_MTABLE ||
3490: strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
3491: /* ignore rowlines attribute on mstyle elements */
3492: /* process it only on mtable elements */
3493: return;
3494:
3495: value = NULL;
3496: if (!delete)
3497: {
3498: length = TtaGetTextAttributeLength (attr);
3499: if (length > 0)
3500: {
3501: value = TtaGetMemory (length+1);
3502: value[0] = EOS;
3503: TtaGiveTextAttributeValue (attr, value, &length);
3504: }
3505: }
3506: /* if attribute rowlines is created or updated but has no value, don't
3507: do anything */
3508: if (!delete && !value)
3509: return;
3510:
3511: ptr = value;
3512: val = 0;
3513: attrType.AttrSSchema = elType.ElSSchema;
1.160 quint 3514: rowspanType.AttrSSchema = elType.ElSSchema;
3515: rowspanType.AttrTypeNum = MathML_ATTR_rowspan_;
1.159 quint 3516:
3517: /* check all rows within the table */
3518: elType.ElTypeNum = MathML_EL_TableRow;
3519: row = TtaSearchTypedElement (elType, SearchInTree, el);
3520: while (row)
3521: {
3522: /* get the next row to check if the current row is the last one */
3523: nextRow = row;
3524: stop = FALSE;
3525: do
3526: {
3527: TtaNextSibling (&nextRow);
3528: if (!nextRow)
3529: stop = TRUE;
3530: else
3531: {
3532: rowType = TtaGetElementType (nextRow);
3533: /* skip comments and other non mrow elements */
3534: if ((rowType.ElTypeNum == MathML_EL_MTR ||
3535: rowType.ElTypeNum == MathML_EL_MLABELEDTR) &&
3536: !strcmp (TtaGetSSchemaName (rowType.ElSSchema), "MathML"))
3537: /* it's the next mrow */
3538: stop = TRUE;
3539: }
3540: }
3541: while (!stop);
3542:
3543: if (!nextRow)
3544: /* row is the last in the table. It must not have a line
3545: at the bottom. Delete it if there is one */
3546: val = 0;
3547: else
3548: {
3549: if (delete)
3550: val = 0;
3551: else
3552: if (*ptr != EOS)
3553: {
3554: /* get next word in the attribute value */
3555: ptr = TtaSkipBlanks (ptr);
3556: /* process that word */
3557: if (*ptr != EOS && *ptr != ' ')
3558: {
3559: if (!strncasecmp (ptr, "none", 4))
3560: val = 0;
3561: else if (!strncasecmp (ptr, "solid", 5))
3562: val = MathML_ATTR_MLineBelow_VAL_solid_;
3563: else if (!strncasecmp (ptr, "dashed", 6))
3564: val = MathML_ATTR_MLineBelow_VAL_dashed_;
3565: else
3566: val = 0;
3567: /* skip the word that has been processed */
3568: while (*ptr != EOS && *ptr != ' ')
3569: ptr++;
3570: }
3571: }
3572: }
3573: /* get the first cell of that row (ignoring Label cells) */
3574: elType.ElTypeNum = MathML_EL_MTD;
3575: cell = TtaSearchTypedElement (elType, SearchInTree, row);
3576: /* update attribute MLineBelow for all cells in that row */
3577: while (cell)
3578: {
3579: cellType = TtaGetElementType (cell);
3580: /* skip comments and other non mtd elements */
3581: if (cellType.ElTypeNum == MathML_EL_MTD &&
3582: !strcmp (TtaGetSSchemaName (cellType.ElSSchema), "MathML"))
3583: /* that's a mtd element. Process it */
3584: {
1.160 quint 3585: /* is there a rowspan attribute on that cell? */
3586: rowspanAttr = TtaGetAttribute (cell, rowspanType);
3587: if (!rowspanAttr)
3588: rowspan = 1;
3589: else
3590: rowspan = TtaGetAttributeValue (rowspanAttr);
1.161 quint 3591: /* by default, use the value for the current row */
3592: cellVal = val;
3593: if (!delete)
1.160 quint 3594: {
1.161 quint 3595: /* skip rowspan-1 words in the value of attribute rowlines */
3596: if (rowspan > 1)
1.160 quint 3597: {
1.161 quint 3598: spanPtr = ptr;
3599: for (i = 1; i < rowspan && *spanPtr != EOS; i++)
1.160 quint 3600: {
1.161 quint 3601: spanPtr = TtaSkipBlanks (spanPtr);
3602: if (*spanPtr != EOS && *spanPtr != ' ')
3603: {
3604: if (!strncasecmp (spanPtr, "none", 4))
3605: cellVal = 0;
3606: else if (!strncasecmp (spanPtr, "solid", 5))
3607: cellVal = MathML_ATTR_MLineBelow_VAL_solid_;
3608: else if (!strncasecmp (spanPtr, "dashed", 6))
3609: cellVal = MathML_ATTR_MLineBelow_VAL_dashed_;
3610: else
3611: cellVal = 0;
3612: }
3613: /* skip the word that has been processed */
3614: while (*spanPtr != EOS && *spanPtr != ' ')
3615: spanPtr++;
1.160 quint 3616: }
3617: }
3618: }
1.161 quint 3619: if (rowspan == 1)
3620: attrType.AttrTypeNum = MathML_ATTR_MLineBelow;
3621: else
3622: attrType.AttrTypeNum = MathML_ATTR_MLineBelowExt;
1.159 quint 3623: intAttr = TtaGetAttribute (cell, attrType);
1.160 quint 3624: if (cellVal == 0)
1.159 quint 3625: {
3626: if (intAttr)
3627: /* remove attribute MLineBelow */
3628: TtaRemoveAttribute (cell, intAttr, doc);
3629: }
3630: else
3631: /* set attribute MLineBelow */
3632: {
3633: if (!intAttr)
3634: {
3635: intAttr = TtaNewAttribute (attrType);
3636: TtaAttachAttribute (cell, intAttr, doc);
3637: }
1.160 quint 3638: TtaSetAttributeValue (intAttr, cellVal, cell, doc);
1.159 quint 3639: }
3640: }
3641: TtaNextSibling (&cell);
3642: }
3643: row = nextRow;
3644: }
3645: if (value)
3646: TtaFreeMemory (value);
3647: }
3648:
3649: /*----------------------------------------------------------------------
3650: HandleColumnlinesAttribute
3651: An attribute columnlines has been created, updated or deleted (if delete
3652: is TRUE) for element el in document doc. Update attribute MLineOnTheRight
3653: of all cells accordingly.
3654: ----------------------------------------------------------------------*/
3655: void HandleColumnlinesAttribute (Attribute attr, Element el, Document doc,
3656: ThotBool delete)
3657: {
3658: char *value;
3659: char *ptr;
1.161 quint 3660: int length, val, colspan, rowspan, i;
1.159 quint 3661: ElementType elType;
3662: Element row, cell, nextCell;
3663: ThotBool stop;
1.161 quint 3664: AttributeType attrType, colspanType, rowspanType;
3665: Attribute intAttr, spanAttr;
1.159 quint 3666:
3667: elType = TtaGetElementType (el);
3668: if (elType.ElTypeNum != MathML_EL_MTABLE ||
3669: strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
3670: /* ignore rowlines attribute on mstyle elements */
3671: /* process it only on mtable elements */
3672: return;
3673:
3674: value = NULL;
3675: if (!delete)
3676: {
3677: length = TtaGetTextAttributeLength (attr);
3678: if (length > 0)
3679: {
3680: value = TtaGetMemory (length+1);
3681: value[0] = EOS;
3682: TtaGiveTextAttributeValue (attr, value, &length);
3683: }
3684: }
3685: /* if attribute columnlines is created or updated but has no value, don't
3686: do anything */
3687: if (!delete && !value)
3688: return;
3689:
3690: val = 0;
3691: attrType.AttrSSchema = elType.ElSSchema;
1.160 quint 3692: colspanType.AttrSSchema = elType.ElSSchema;
3693: colspanType.AttrTypeNum = MathML_ATTR_columnspan;
1.161 quint 3694: rowspanType.AttrSSchema = elType.ElSSchema;
3695: rowspanType.AttrTypeNum = MathML_ATTR_rowspan_;
1.159 quint 3696:
3697: /* check all cells in all rows in the table */
3698: elType.ElTypeNum = MathML_EL_TableRow;
3699: row = TtaSearchTypedElement (elType, SearchInTree, el);
3700: while (row)
3701: {
3702: elType = TtaGetElementType (row);
3703: if ((elType.ElTypeNum == MathML_EL_MTR ||
3704: elType.ElTypeNum == MathML_EL_MLABELEDTR) &&
3705: strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
3706: /* that's a table row. check all its cells */
3707: {
3708: /* start from the beginning of the columnlines attribute */
3709: ptr = value;
3710: val = 0;
3711: /* get the first cell of that row (ignoring Label cells) */
3712: elType.ElTypeNum = MathML_EL_MTD;
3713: cell = TtaSearchTypedElement (elType, SearchInTree, row);
3714: while (cell)
3715: {
3716: /* get the next cell in the current row to check if the current
3717: cell is the last one in the row */
3718: nextCell = cell;
3719: stop = FALSE;
3720: do
3721: {
3722: TtaNextSibling (&nextCell);
3723: if (!nextCell)
3724: stop = TRUE;
3725: else
3726: {
3727: elType = TtaGetElementType (nextCell);
3728: /* skip comments and other non mtd elements */
3729: if (elType.ElTypeNum == MathML_EL_MTD &&
3730: strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
3731: /* it's the next cell */
3732: stop = TRUE;
3733: }
3734: }
3735: while (!stop);
3736:
1.161 quint 3737: /* is there a rowspan attribute on that cell? */
3738: spanAttr = TtaGetAttribute (cell, rowspanType);
3739: if (!spanAttr)
3740: rowspan = 1;
3741: else
3742: rowspan = TtaGetAttributeValue (spanAttr);
3743:
1.159 quint 3744: if (!nextCell)
3745: /* it's the last cell in the row. It must not have a line
3746: on its right edge. Delete it if there is noe. */
3747: val = 0;
3748: else
3749: /* set the attribute MLineOnTheRight for this cell */
3750: {
3751: if (delete)
3752: val = 0;
3753: else
3754: if (*ptr != EOS)
3755: {
1.161 quint 3756: /* is there a columnspan attribute on that cell? */
3757: spanAttr = TtaGetAttribute (cell, colspanType);
3758: if (!spanAttr)
1.160 quint 3759: colspan = 1;
3760: else
1.161 quint 3761: colspan = TtaGetAttributeValue (spanAttr);
1.160 quint 3762: /* skip (colspan - 1) words in the attribute */
3763: for (i = 1; i <= colspan && *ptr != EOS; i++)
1.159 quint 3764: {
1.160 quint 3765: /* get next word in the attribute value */
3766: ptr = TtaSkipBlanks (ptr);
3767: /* process that word */
3768: if (*ptr != EOS && *ptr != ' ')
3769: {
3770: if (!strncasecmp (ptr, "none", 4))
3771: val = 0;
3772: else if (!strncasecmp (ptr, "solid", 5))
3773: val = MathML_ATTR_MLineOnTheRight_VAL_solid_;
3774: else if (!strncasecmp (ptr, "dashed", 6))
3775: val = MathML_ATTR_MLineOnTheRight_VAL_dashed_;
3776: else
3777: val = 0;
3778: /* skip the word that has been processed */
3779: while (*ptr != EOS && *ptr != ' ')
3780: ptr++;
3781: }
1.159 quint 3782: }
3783: }
3784: }
1.161 quint 3785: if (rowspan == 1)
3786: attrType.AttrTypeNum = MathML_ATTR_MLineOnTheRight;
3787: else
3788: attrType.AttrTypeNum = MathML_ATTR_MLineOnTheRightExt;
1.159 quint 3789: intAttr = TtaGetAttribute (cell, attrType);
3790: if (val == 0)
3791: {
3792: if (intAttr)
3793: /* remove attribute MLineOnTheRight */
3794: TtaRemoveAttribute (cell, intAttr, doc);
3795: }
3796: else
3797: /* set attribute MLineOnTheRight */
3798: {
3799: if (!intAttr)
3800: {
3801: intAttr = TtaNewAttribute (attrType);
3802: TtaAttachAttribute (cell, intAttr, doc);
3803: }
3804: TtaSetAttributeValue (intAttr, val, cell, doc);
3805: }
3806: cell = nextCell;
3807: }
3808: }
3809: TtaNextSibling (&row);
3810: }
3811: if (value)
3812: TtaFreeMemory (value);
3813: }
3814:
3815: /*----------------------------------------------------------------------
1.168 quint 3816: HandleFramespacingAttribute
3817: An attribute framespacing has been created, updated or deleted (if delete
3818: is TRUE) for element el in document doc. Update attribute the padding
3819: properties of the concerned table(s).
3820: ----------------------------------------------------------------------*/
3821: void HandleFramespacingAttribute (Attribute attr, Element el, Document doc,
3822: ThotBool delete)
3823: {
3824: ElementType elType;
3825: char *value, *ptr, valueOfNamedSpace[20];
3826: int length, vertPadding, horizPadding, vertPaddingUnit,
3827: horizPaddingUnit;
3828: Attribute attrFrame;
3829: AttributeType attrType;
3830: PresentationValue pval;
3831: PresentationContext ctxt;
3832: ThotBool vertPaddingReal, horizPaddingReal;
3833:
3834: if ((!delete && !attr) || !el)
3835: return;
3836: elType = TtaGetElementType (el);
3837: if (elType.ElTypeNum != MathML_EL_MTABLE ||
3838: strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
3839: /* ignore framespacing attribute on mstyle elements */
3840: /* process it only on mtable elements */
3841: return;
3842:
3843: value = NULL;
3844: if (!delete)
3845: {
3846: length = TtaGetTextAttributeLength (attr);
3847: if (length > 0)
3848: {
3849: value = TtaGetMemory (length+1);
3850: value[0] = EOS;
3851: TtaGiveTextAttributeValue (attr, value, &length);
3852: }
3853: }
3854: ctxt = TtaGetSpecificStyleContext (doc);
3855: /* the specific presentation to be created is not a CSS rule */
3856: ctxt->cssSpecificity = 0;
3857: vertPadding = 0;
3858: horizPadding = 0;
1.184 vatton 3859: vertPaddingUnit = UNIT_PT;
3860: horizPaddingUnit = UNIT_PT;
1.168 quint 3861: vertPaddingReal = FALSE;
3862: horizPaddingReal = FALSE;
3863: /* is there a frame attribute? */
3864: attrType.AttrSSchema = elType.ElSSchema;
3865: attrType.AttrTypeNum = MathML_ATTR_frame;
3866: attrFrame = TtaGetAttribute (el, attrType);
3867: if (!delete && value && attrFrame)
3868: {
3869: ptr = value;
3870: /* parse the first part: horizontal spacing */
3871: ptr = TtaSkipBlanks (ptr);
3872: if (*ptr != EOS)
3873: {
3874: ptr = ConvertNamedSpace (ptr, valueOfNamedSpace);
3875: if (valueOfNamedSpace[0] != EOS)
3876: /* it's a named space */
3877: ptr = ParseCSSUnit (valueOfNamedSpace, &pval);
3878: else
3879: ptr = ParseCSSUnit (ptr, &pval);
1.184 vatton 3880: if (pval.typed_data.unit != UNIT_INVALID)
1.168 quint 3881: {
1.184 vatton 3882: if (pval.typed_data.unit == UNIT_BOX)
3883: pval.typed_data.unit = UNIT_EM;
1.168 quint 3884: horizPadding = pval.typed_data.value;
3885: horizPaddingUnit = pval.typed_data.unit;
3886: horizPaddingReal = pval.typed_data.real;
3887: /* if there is no second part, the vertical spacing is the same
3888: as the horizontal spacing */
3889: vertPadding = horizPadding;
3890: vertPaddingUnit = horizPaddingUnit;
3891: vertPaddingReal = horizPaddingReal;
3892: /* parse the second part, if any */
3893: ptr = TtaSkipBlanks (ptr);
3894: if (*ptr != EOS)
3895: {
3896: ptr = ConvertNamedSpace (ptr, valueOfNamedSpace);
3897: if (valueOfNamedSpace[0] != EOS)
3898: /* it's a named space */
3899: ptr = ParseCSSUnit (valueOfNamedSpace, &pval);
3900: else
3901: ptr = ParseCSSUnit (ptr, &pval);
1.184 vatton 3902: if (pval.typed_data.unit != UNIT_INVALID)
1.168 quint 3903: {
1.184 vatton 3904: if (pval.typed_data.unit == UNIT_BOX)
3905: pval.typed_data.unit = UNIT_EM;
1.168 quint 3906: vertPadding = pval.typed_data.value;
3907: vertPaddingUnit = pval.typed_data.unit;
3908: vertPaddingReal = pval.typed_data.real;
3909: }
3910: }
3911: }
3912: }
3913: }
3914: if (delete)
3915: ctxt->destroy = TRUE;
3916: else
3917: {
3918: ctxt->destroy = FALSE;
3919: pval.typed_data.value = horizPadding;
3920: pval.typed_data.unit = horizPaddingUnit;
3921: pval.typed_data.real = horizPaddingReal;
3922: }
3923: TtaSetStylePresentation (PRPaddingLeft, el, NULL, ctxt, pval);
3924: TtaSetStylePresentation (PRPaddingRight, el, NULL, ctxt, pval);
3925: if (!delete)
3926: {
3927: pval.typed_data.value = vertPadding;
3928: pval.typed_data.unit = vertPaddingUnit;
3929: pval.typed_data.real = vertPaddingReal;
3930: }
3931: TtaSetStylePresentation (PRPaddingTop, el, NULL, ctxt, pval);
3932: TtaSetStylePresentation (PRPaddingBottom, el, NULL, ctxt, pval);
3933:
3934: if (value)
3935: TtaFreeMemory (value);
1.175 quint 3936: }
3937:
3938: /*----------------------------------------------------------------------
1.169 quint 3939: SetDisplaystyleMathElement
3940: Associate a IntDisplaystyle attribute with element el (which is a
3941: <math> element), and set its value depending on the surrounding context.
3942: ----------------------------------------------------------------------*/
3943: void SetDisplaystyleMathElement (Element el, Document doc)
3944: {
3945: Element parent, sibling;
3946: ElementType elType, parentType;
3947: Attribute attr;
3948: AttributeType attrType;
3949: int display, val;
3950:
3951: display = MathML_ATTR_IntDisplaystyle_VAL_true;
3952: /* is there an attribute display? */
3953: elType = TtaGetElementType (el);
3954: attrType.AttrSSchema = elType.ElSSchema;
3955: attrType.AttrTypeNum = MathML_ATTR_display;
3956: attr = TtaGetAttribute (el, attrType);
3957: if (attr)
3958: /* there is an attribute display. Take its value */
3959: {
3960: val = TtaGetAttributeValue (attr);
3961: if (val == MathML_ATTR_display_VAL_block)
3962: display = MathML_ATTR_IntDisplaystyle_VAL_true;
3963: else
3964: display = MathML_ATTR_IntDisplaystyle_VAL_false;
3965: }
3966: else
3967: /* no attribute display. Look at the context */
3968: {
3969: parent = TtaGetParent (el);
3970: parentType = TtaGetElementType (parent);
3971: if (elType.ElSSchema == parentType.ElSSchema)
3972: /* it's the only <math> element in a MathML document */
3973: display = MathML_ATTR_IntDisplaystyle_VAL_true;
3974: else
3975: /* it's a MathML expression within another vocabulary */
3976: {
3977: if (!strcmp (TtaGetSSchemaName (parentType.ElSSchema), "SVG"))
3978: /* a <math> element in a SVG element */
3979: display = MathML_ATTR_IntDisplaystyle_VAL_true;
3980: else if (!strcmp (TtaGetSSchemaName (parentType.ElSSchema), "HTML"))
3981: /* a <math> element in a HTML element */
3982: {
3983: display = MathML_ATTR_IntDisplaystyle_VAL_false;
3984: if (parentType.ElTypeNum == HTML_EL_BODY ||
3985: parentType.ElTypeNum == HTML_EL_Division)
3986: display = MathML_ATTR_IntDisplaystyle_VAL_true;
3987: else if (parentType.ElTypeNum == HTML_EL_Pseudo_paragraph ||
3988: parentType.ElTypeNum == HTML_EL_Paragraph)
3989: {
3990: sibling = el;
3991: TtaPreviousSibling (&sibling);
3992: if (!sibling)
3993: {
3994: sibling = el;
3995: TtaNextSibling (&sibling);
3996: if (!sibling)
3997: display = MathML_ATTR_IntDisplaystyle_VAL_true;
3998: }
3999: }
4000: }
4001: }
4002: }
4003: /* create the IntDisplastyle attribute and set its value */
4004: attrType.AttrTypeNum = MathML_ATTR_IntDisplaystyle;
4005: attr = TtaGetAttribute (el, attrType);
4006: if (!attr)
4007: {
4008: attr = TtaNewAttribute (attrType);
4009: TtaAttachAttribute (el, attr, doc);
4010: }
4011: TtaSetAttributeValue (attr, display, el, doc);
1.175 quint 4012: ApplyDisplaystyle (el, doc);
1.169 quint 4013: }
4014:
4015: /*----------------------------------------------------------------------
4016: MathMLElementCreated
4017: The XML parser has just inserted a new element in the abstract tree.
4018: ----------------------------------------------------------------------*/
4019: void MathMLElementCreated (Element el, Document doc)
4020: {
4021: ElementType elType;
4022:
4023: elType = TtaGetElementType (el);
4024: if (elType.ElTypeNum == MathML_EL_MathML)
4025: /* associate a IntDisplaystyle attribute with the element depending
4026: on its context */
4027: SetDisplaystyleMathElement (el, doc);
4028: }
4029:
4030: /*----------------------------------------------------------------------
1.186 vatton 4031: EvaluateChildRendering tests what children should be displayed
4032: ----------------------------------------------------------------------*/
4033: void EvaluateChildRendering (Element el, Document doc)
4034: {
4035: ElementType elType;
4036: Element child, renderedChild;
1.187 vatton 4037: SSchema MathMLSSchema;
4038: AttributeType attrType;
4039: Attribute attr;
1.186 vatton 4040: PresentationValue pval;
4041: PresentationContext ctxt;
1.187 vatton 4042: char *value;
4043: int length;
1.186 vatton 4044:
4045: ctxt = TtaGetSpecificStyleContext (doc);
4046: ctxt->cssSpecificity = 0; /* the presentation rule to be set is not a CSS rule */
4047: pval.typed_data.unit = UNIT_PX;
4048: pval.typed_data.value = 0;
4049: pval.typed_data.real = FALSE;
1.187 vatton 4050: MathMLSSchema = TtaGetElementType(el).ElSSchema;
1.186 vatton 4051: /* process all children in order */
4052: child = TtaGetFirstChild (el);
4053: renderedChild = NULL;
4054: while (child)
4055: {
4056: /* if this child is a comment or a processing instruction, skip it */
4057: elType = TtaGetElementType (child);
1.187 vatton 4058: ctxt->destroy = FALSE; /* we will most probably create a PRule
4059: Visibility: 0; for this child */
4060: if (elType.ElSSchema == MathMLSSchema &&
4061: elType.ElTypeNum != MathML_EL_XMLcomment &&
4062: elType.ElTypeNum != MathML_EL_XMLPI &&
4063: elType.ElTypeNum != MathML_EL_Unknown_namespace &&
4064: elType.ElTypeNum != MathML_EL_ANNOTATION)
1.186 vatton 4065: {
1.187 vatton 4066: if (!renderedChild && elType.ElTypeNum == MathML_EL_ANNOTATION_XML)
1.186 vatton 4067: {
1.187 vatton 4068: /* check if the mime type is known */
4069: attrType.AttrSSchema = MathMLSSchema;
4070: attrType.AttrTypeNum = MathML_ATTR_encoding;
4071: attr = TtaGetAttribute (child, attrType);
4072: if (attr)
4073: {
4074: length = TtaGetTextAttributeLength (attr);
4075: if (length > 0)
4076: {
4077: value = TtaGetMemory (length+1);
4078: value[0] = EOS;
4079: TtaGiveTextAttributeValue (attr, value, &length);
4080: if (!strncmp (value, "image/svg", 9) ||
4081: !strcmp (value, AM_SVG_MIME_TYPE) ||
4082: !strncmp (value, "text/htm", 8) ||
4083: !strcmp (value, AM_XHTML_MIME_TYPE))
4084: {
4085: /* display that child */
4086: renderedChild = child;
4087: ctxt->destroy = TRUE;
4088: }
4089: }
4090: }
1.186 vatton 4091: }
4092: /* set or remove a visibility PRule for this child */
4093: TtaSetStylePresentation (PRVisibility, child, NULL, ctxt, pval);
4094: }
4095: TtaNextSibling (&child);
4096: }
4097: }
4098:
4099: /*----------------------------------------------------------------------
1.1 cvs 4100: MathMLElementComplete
1.169 quint 4101: Element el has just been completed by the XML parser.
1.1 cvs 4102: Check the Thot structure of the MathML element el.
4103: ----------------------------------------------------------------------*/
1.156 cvs 4104: void MathMLElementComplete (ParserData *context, Element el, int *error)
1.1 cvs 4105: {
1.156 cvs 4106: Document doc;
1.74 cvs 4107: ElementType elType, parentType;
1.1 cvs 4108: Element child, parent, new, prev, next;
1.101 cvs 4109: AttributeType attrType;
4110: Attribute attr;
1.56 cvs 4111: SSchema MathMLSSchema;
4112: ThotBool ok;
1.1 cvs 4113:
1.56 cvs 4114: ok = TRUE;
4115: *error = 0;
1.156 cvs 4116: doc = context->doc;
1.1 cvs 4117: elType = TtaGetElementType (el);
1.2 cvs 4118: MathMLSSchema = GetMathMLSSchema (doc);
1.1 cvs 4119:
1.76 cvs 4120: if (elType.ElSSchema == MathMLSSchema)
1.1 cvs 4121: {
4122: switch (elType.ElTypeNum)
4123: {
1.76 cvs 4124: case MathML_EL_MathML:
4125: /* Create placeholders within the MathML element */
4126: CreatePlaceholders (TtaGetFirstChild (el), doc);
1.132 cvs 4127: break;
1.188 quint 4128: case MathML_EL_MTEXT:
4129: if (TtaGetFirstChild (el) == NULL)
4130: /* empty <mtext>. It will have to be parsed when the user enters
4131: some content */
4132: SetAttrParseMe (el, doc);
1.1 cvs 4133: case MathML_EL_MI:
1.188 quint 4134: if (TtaGetFirstChild (el) == NULL)
4135: /* empty <mi> Replace it by an empty Construct */
4136: ChangeTypeOfElement (el, doc, MathML_EL_Construct);
4137: else
4138: SetFontstyleAttr (el, doc);
1.1 cvs 4139: break;
4140: case MathML_EL_MO:
1.22 cvs 4141: SetIntAddSpaceAttr (el, doc);
4142: SetIntVertStretchAttr (el, doc, 0, NULL);
1.58 cvs 4143: /* if the MO element is a child of a MROW (or equivalent) and if it
4144: contains a fence character, transform this MO into MF and
4145: transform the fence character into a Thot SYMBOL */
1.175 quint 4146: CheckFence (el, doc);
4147: /* if the MO element contains an operator that should be
4148: large (∑ for instance), enlarge it */
4149: CheckLargeOp (el, doc);
1.1 cvs 4150: break;
1.60 cvs 4151: case MathML_EL_MSPACE:
4152: break;
1.39 cvs 4153: case MathML_EL_MROW:
1.55 cvs 4154: /* Create placeholders within the MROW */
4155: CreatePlaceholders (TtaGetFirstChild (el), doc);
1.39 cvs 4156: break;
4157: case MathML_EL_MFRAC:
1.54 cvs 4158: case MathML_EL_BevelledMFRAC:
1.39 cvs 4159: /* end of a fraction. Create a Numerator and a Denominator */
1.56 cvs 4160: ok = CheckMathSubExpressions (el, MathML_EL_Numerator,
4161: MathML_EL_Denominator, 0, doc);
1.39 cvs 4162: break;
4163: case MathML_EL_MSQRT:
1.50 cvs 4164: /* end of a Square Root */
4165: /* Create placeholders within the element */
4166: CreatePlaceholders (TtaGetFirstChild (el), doc);
4167: /* Create a SqrtBase that contains all children of the MSQRT */
1.39 cvs 4168: CreateWrapper (el, MathML_EL_SqrtBase, doc);
4169: break;
1.1 cvs 4170: case MathML_EL_MROOT:
4171: /* end of a Root. Create a RootBase and an Index */
1.56 cvs 4172: ok = CheckMathSubExpressions (el, MathML_EL_RootBase,
4173: MathML_EL_Index, 0, doc);
1.1 cvs 4174: break;
1.50 cvs 4175: case MathML_EL_MENCLOSE:
4176: /* Create placeholders within the element */
4177: CreatePlaceholders (TtaGetFirstChild (el), doc);
4178: break;
1.39 cvs 4179: case MathML_EL_MSTYLE:
4180: case MathML_EL_MERROR:
4181: case MathML_EL_MPADDED:
4182: case MathML_EL_MPHANTOM:
4183: /* Create placeholders within the element */
4184: CreatePlaceholders (TtaGetFirstChild (el), doc);
1.1 cvs 4185: break;
4186: case MathML_EL_MFENCED:
4187: TransformMFENCED (el, doc);
4188: break;
4189: case MathML_EL_MSUB:
4190: /* end of a MSUB. Create Base and Subscript */
1.56 cvs 4191: ok = CheckMathSubExpressions (el, MathML_EL_Base,
4192: MathML_EL_Subscript, 0, doc);
1.59 cvs 4193: SetScriptShift (el, doc, MathML_ATTR_subscriptshift);
1.22 cvs 4194: SetIntVertStretchAttr (el, doc, MathML_EL_Base, NULL);
1.1 cvs 4195: break;
4196: case MathML_EL_MSUP:
4197: /* end of a MSUP. Create Base and Superscript */
1.56 cvs 4198: ok = CheckMathSubExpressions (el, MathML_EL_Base,
4199: MathML_EL_Superscript, 0, doc);
1.59 cvs 4200: SetScriptShift (el, doc, MathML_ATTR_superscriptshift);
1.22 cvs 4201: SetIntVertStretchAttr (el, doc, MathML_EL_Base, NULL);
1.1 cvs 4202: break;
1.39 cvs 4203: case MathML_EL_MSUBSUP:
4204: /* end of a MSUBSUP. Create Base, Subscript, and Superscript */
1.56 cvs 4205: ok = CheckMathSubExpressions (el, MathML_EL_Base,
4206: MathML_EL_Subscript,
4207: MathML_EL_Superscript, doc);
1.59 cvs 4208: SetScriptShift (el, doc, MathML_ATTR_subscriptshift);
4209: SetScriptShift (el, doc, MathML_ATTR_superscriptshift);
1.39 cvs 4210: SetIntVertStretchAttr (el, doc, MathML_EL_Base, NULL);
1.1 cvs 4211: break;
4212: case MathML_EL_MUNDER:
4213: /* end of a MUNDER. Create UnderOverBase, and Underscript */
1.56 cvs 4214: ok = CheckMathSubExpressions (el, MathML_EL_UnderOverBase,
4215: MathML_EL_Underscript, 0, doc);
1.22 cvs 4216: SetIntHorizStretchAttr (el, doc);
4217: SetIntVertStretchAttr (el, doc, MathML_EL_UnderOverBase, NULL);
1.169 quint 4218: SetIntMovelimitsAttr (el, doc);
1.1 cvs 4219: break;
4220: case MathML_EL_MOVER:
4221: /* end of a MOVER. Create UnderOverBase, and Overscript */
1.56 cvs 4222: ok = CheckMathSubExpressions (el, MathML_EL_UnderOverBase,
4223: MathML_EL_Overscript, 0, doc);
1.22 cvs 4224: SetIntHorizStretchAttr (el, doc);
4225: SetIntVertStretchAttr (el, doc, MathML_EL_UnderOverBase, NULL);
1.169 quint 4226: SetIntMovelimitsAttr (el, doc);
1.1 cvs 4227: break;
1.39 cvs 4228: case MathML_EL_MUNDEROVER:
4229: /* end of a MUNDEROVER. Create UnderOverBase, Underscript, and
4230: Overscript */
1.56 cvs 4231: ok = CheckMathSubExpressions (el, MathML_EL_UnderOverBase,
4232: MathML_EL_Underscript,
4233: MathML_EL_Overscript, doc);
1.39 cvs 4234: SetIntHorizStretchAttr (el, doc);
4235: SetIntVertStretchAttr (el, doc, MathML_EL_UnderOverBase, NULL);
1.169 quint 4236: SetIntMovelimitsAttr (el, doc);
1.39 cvs 4237: break;
1.1 cvs 4238: case MathML_EL_MMULTISCRIPTS:
4239: /* end of a MMULTISCRIPTS. Create all elements defined in the
4240: MathML S schema */
4241: BuildMultiscript (el, doc);
1.5 cvs 4242: break;
4243: case MathML_EL_MTABLE:
4244: /* end of a MTABLE. Create all elements defined in the MathML S
4245: schema */
1.64 cvs 4246: CheckMTable (el, doc, TRUE);
1.101 cvs 4247: /* if the table has a rowalign attribute, process it */
4248: attrType.AttrSSchema = MathMLSSchema;
4249: attrType.AttrTypeNum = MathML_ATTR_rowalign;
4250: attr = TtaGetAttribute (el, attrType);
4251: if (attr)
4252: HandleRowalignAttribute (attr, el, doc, FALSE);
4253: /* if the table has a columnalign attribute, process it */
4254: attrType.AttrTypeNum = MathML_ATTR_columnalign;
4255: attr = TtaGetAttribute (el, attrType);
4256: if (attr)
1.108 cvs 4257: HandleColalignAttribute (attr, el, doc, FALSE, FALSE);
1.167 quint 4258: /* process the rowspacing attribute, or set the top padding of the
4259: first row and the bottom padding of the last row to 0. */
4260: attrType.AttrSSchema = MathMLSSchema;
4261: attrType.AttrTypeNum = MathML_ATTR_rowspacing;
4262: attr = TtaGetAttribute (el, attrType);
4263: HandleRowspacingAttribute (attr, el, doc, FALSE);
4264: /* process the columnspacing attribute, or set the left padding of
4265: the first column and the right padding of the last column to 0 */
4266: attrType.AttrSSchema = MathMLSSchema;
4267: attrType.AttrTypeNum = MathML_ATTR_columnspacing;
4268: attr = TtaGetAttribute (el, attrType);
4269: HandleColumnspacingAttribute (attr, el, doc, FALSE);
1.159 quint 4270: /* if the table has a rowlines attribute, process it */
4271: attrType.AttrSSchema = MathMLSSchema;
4272: attrType.AttrTypeNum = MathML_ATTR_rowlines;
4273: attr = TtaGetAttribute (el, attrType);
4274: if (attr)
1.167 quint 4275: HandleRowlinesAttribute (attr, el, doc, FALSE);
1.159 quint 4276: /* if the table has a columnlines attribute, process it */
4277: attrType.AttrTypeNum = MathML_ATTR_columnlines;
4278: attr = TtaGetAttribute (el, attrType);
4279: if (attr)
4280: HandleColumnlinesAttribute (attr, el, doc, FALSE);
1.101 cvs 4281: break;
4282: case MathML_EL_MTR:
4283: /* if the row has a columnalign attribute, process it */
4284: attrType.AttrSSchema = MathMLSSchema;
4285: attrType.AttrTypeNum = MathML_ATTR_columnalign;
4286: attr = TtaGetAttribute (el, attrType);
4287: if (attr)
1.108 cvs 4288: HandleColalignAttribute (attr, el, doc, FALSE, TRUE);
1.101 cvs 4289: break;
4290: case MathML_EL_MLABELEDTR:
4291: /* if the row has a columnalign attribute, process it */
4292: attrType.AttrSSchema = MathMLSSchema;
4293: attrType.AttrTypeNum = MathML_ATTR_columnalign;
4294: attr = TtaGetAttribute (el, attrType);
4295: if (attr)
1.108 cvs 4296: HandleColalignAttribute (attr, el, doc, FALSE, TRUE);
1.1 cvs 4297: break;
1.39 cvs 4298: case MathML_EL_MTD:
4299: /* Create placeholders within the table cell */
4300: CreatePlaceholders (TtaGetFirstChild (el), doc);
1.46 cvs 4301: break;
1.39 cvs 4302: case MathML_EL_MACTION:
4303: /* Create placeholders within the MACTION element */
4304: CreatePlaceholders (TtaGetFirstChild (el), doc);
1.1 cvs 4305: break;
1.187 vatton 4306: case MathML_EL_SEMANTICS:
1.186 vatton 4307: /* it's a ANNOTATION_XML element */
4308: /* Evaluate what direct child element to be rendered */
4309: EvaluateChildRendering (el, doc);
4310: break;
1.1 cvs 4311: default:
4312: break;
4313: }
4314: parent = TtaGetParent (el);
1.118 cvs 4315: if (parent)
4316: {
4317: parentType = TtaGetElementType (parent);
4318: if (parentType.ElSSchema != elType.ElSSchema)
1.175 quint 4319: /* root of a MathML (sub-)tree, Create a MathML element if it is
4320: not present */
1.118 cvs 4321: if (elType.ElTypeNum != MathML_EL_MathML)
4322: {
4323: elType.ElSSchema = MathMLSSchema;
4324: elType.ElTypeNum = MathML_EL_MathML;
4325: new = TtaNewElement (doc, elType);
4326: TtaInsertSibling (new, el, TRUE, doc);
4327: next = el;
4328: TtaNextSibling (&next);
4329: TtaRemoveTree (el, doc);
4330: TtaInsertFirstChild (&el, new, doc);
4331: prev = el;
4332: while (next != NULL)
4333: {
4334: child = next;
4335: TtaNextSibling (&next);
4336: TtaRemoveTree (child, doc);
4337: TtaInsertSibling (child, prev, FALSE, doc);
4338: prev = child;
4339: }
1.169 quint 4340: /* associate a IntDisplaystyle attribute with the element
4341: depending on its context */
4342: SetDisplaystyleMathElement (new, doc);
1.118 cvs 4343: /* Create placeholders within the MathML element */
1.169 quint 4344: CreatePlaceholders (new, doc);
1.118 cvs 4345: }
4346: }
1.1 cvs 4347: }
1.56 cvs 4348: if (!ok)
4349: /* send an error message */
4350: *error = 1;
1.1 cvs 4351: }
4352:
4353: /*----------------------------------------------------------------------
1.126 cvs 4354: UnknownMathMLNameSpace
1.149 cvs 4355: The element doesn't belong to a supported namespace
1.126 cvs 4356: ----------------------------------------------------------------------*/
1.149 cvs 4357: void UnknownMathMLNameSpace (ParserData *context,
4358: Element *unknownEl,
4359: char* content)
1.126 cvs 4360: {
4361: ElementType elType;
1.149 cvs 4362: Element elText;
1.126 cvs 4363:
4364: /* Create a new Invalid_element */
4365: elType.ElSSchema = GetXMLSSchema (MATH_TYPE, context->doc);
4366: elType.ElTypeNum = MathML_EL_Unknown_namespace;
1.149 cvs 4367: *unknownEl = TtaNewElement (context->doc, elType);
4368: if (*unknownEl != NULL)
1.126 cvs 4369: {
1.149 cvs 4370: XmlSetElemLineNumber (*unknownEl);
4371: InsertXmlElement (unknownEl);
1.126 cvs 4372: context->lastElementClosed = TRUE;
4373: elType.ElTypeNum = MathML_EL_TEXT_UNIT;
4374: elText = TtaNewElement (context->doc, elType);
4375: XmlSetElemLineNumber (elText);
1.149 cvs 4376: TtaInsertFirstChild (&elText, *unknownEl, context->doc);
1.126 cvs 4377: TtaSetTextContent (elText, content, context->language, context->doc);
4378: TtaSetAccessRight (elText, ReadOnly, context->doc);
4379: }
4380: }
4381:
4382: /*----------------------------------------------------------------------
1.24 cvs 4383: SetFontfamily
4384: -----------------------------------------------------------------------*/
1.120 cvs 4385: void SetFontfamily (Document doc, Element el, char *value)
1.24 cvs 4386: {
4387: #define buflen 50
1.116 cvs 4388: char css_command[buflen+20];
1.24 cvs 4389:
1.116 cvs 4390: sprintf (css_command, "font-family: %s", value);
1.72 cvs 4391: ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
1.24 cvs 4392: }
4393:
4394: /*----------------------------------------------------------------------
1.83 cvs 4395: MathMLlinethickness
4396: The MathML attribute linthickness is associated with element el. Generate
4397: the corresponding style property for this element.
4398: -----------------------------------------------------------------------*/
1.120 cvs 4399: void MathMLlinethickness (Document doc, Element el, char *value)
1.83 cvs 4400: {
4401: #define buflen 50
1.116 cvs 4402: char css_command[buflen+20];
1.83 cvs 4403:
1.116 cvs 4404: if (strcmp (value, "thin") == 0)
4405: strcpy (value, "1pt");
4406: else if (strcmp (value, "medium") == 0)
4407: strcpy (value, "1pt");
4408: else if (strcmp (value, "thick") == 0)
4409: strcpy (value, "2pt");
4410: sprintf (css_command, "stroke-width: %s", value);
1.83 cvs 4411: ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
4412: }
4413:
4414: /*----------------------------------------------------------------------
1.58 cvs 4415: MathMLAttrToStyleProperty
4416: The MathML attribute attr is associated with element el. Generate
4417: the corresponding style property for this element.
1.24 cvs 4418: -----------------------------------------------------------------------*/
1.138 cvs 4419: void MathMLAttrToStyleProperty (Document doc, Element el, char *value,
4420: int attr)
1.24 cvs 4421: {
1.167 quint 4422: char css_command[buflen+20], namedSpaceVal[20];
1.141 quint 4423: int i;
1.58 cvs 4424:
4425: switch (attr)
4426: {
4427: case MathML_ATTR_fontsize:
1.116 cvs 4428: sprintf (css_command, "font-size: %s", value);
1.58 cvs 4429: break;
1.93 cvs 4430: case MathML_ATTR_mathsize:
1.116 cvs 4431: if (strcmp (value, "small") == 0)
4432: strcpy (value, "80%");
4433: else if (strcmp (value, "normal") == 0)
4434: strcpy (value, "100%");
4435: else if (strcmp (value, "big") == 0)
4436: strcpy (value, "125%");
4437: sprintf (css_command, "font-size: %s", value);
1.93 cvs 4438: break;
1.58 cvs 4439: case MathML_ATTR_lspace:
4440: case MathML_ATTR_rspace:
1.141 quint 4441: if (attr == MathML_ATTR_lspace)
4442: strcpy (css_command, "padding-left: ");
4443: else
4444: strcpy (css_command, "padding-right: ");
1.167 quint 4445: ConvertNamedSpace (value, namedSpaceVal);
4446: if (namedSpaceVal[0] != EOS)
4447: /* it's a named space */
4448: strcat (css_command, namedSpaceVal);
1.141 quint 4449: else
4450: {
4451: strcat (css_command, value);
4452: /* does the value contain an unit at the end? */
4453: i = strlen (value) - 1;
4454: if ((value[i] <= '9' && value[i] >= '0') ||
4455: value[i] == '.')
4456: /* it's just a number. Add the (implicit) unit: em */
4457: strcat (css_command, "em");
4458: }
1.58 cvs 4459: break;
4460: }
1.72 cvs 4461: ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
1.24 cvs 4462: }
4463:
4464: /*----------------------------------------------------------------------
1.60 cvs 4465: MathMLSetScriptLevel
4466: A scriptlevel attribute with value value is associated with element el.
4467: Generate the corresponding style property for this element.
4468: -----------------------------------------------------------------------*/
1.120 cvs 4469: void MathMLSetScriptLevel (Document doc, Element el, char *value)
1.60 cvs 4470: {
4471: PresentationValue pval;
4472: PresentationContext ctxt;
4473: ThotBool relative;
4474: int percentage;
4475:
4476: ctxt = TtaGetSpecificStyleContext (doc);
4477: if (!value)
4478: /* remove the presentation rule */
4479: {
4480: ctxt->destroy = TRUE;
1.75 cvs 4481: pval.typed_data.value = 0;
1.60 cvs 4482: TtaSetStylePresentation (PRSize, el, NULL, ctxt, pval);
4483: }
4484: else
4485: {
4486: ctxt->destroy = FALSE;
4487: /* parse the attribute value (an optional sign and an integer) */
1.119 cvs 4488: value = TtaSkipBlanks (value);
1.60 cvs 4489: relative = (value[0] == '-' || value[0] == '+');
4490: value = ParseCSSUnit (value, &pval);
1.184 vatton 4491: if (pval.typed_data.unit != UNIT_REL &&
1.60 cvs 4492: pval.typed_data.real)
4493: /* this is an error: it should be an integer without any unit name */
4494: /* error */;
4495: else
4496: {
4497: if (relative)
4498: {
1.63 cvs 4499: percentage = 100;
1.60 cvs 4500: if (pval.typed_data.value == 0)
4501: /* scriptlevel="+0" */
4502: percentage = 100;
4503: else if (pval.typed_data.value == 1)
4504: /* scriptlevel="+1" */
4505: percentage = 71;
4506: else if (pval.typed_data.value == 2)
4507: /* scriptlevel="+2" */
4508: percentage = 50;
4509: else if (pval.typed_data.value >= 3)
4510: /* scriptlevel="+3" or more */
4511: percentage = 35;
4512: else if (pval.typed_data.value == -1)
4513: /* scriptlevel="-1" */
4514: percentage = 141;
4515: else if (pval.typed_data.value == -2)
4516: /* scriptlevel="-2" */
4517: percentage = 200;
4518: else if (pval.typed_data.value <= -3)
4519: /* scriptlevel="-3" or less */
4520: percentage = 282;
4521: pval.typed_data.value = percentage;
1.184 vatton 4522: pval.typed_data.unit = UNIT_PERCENT;
1.78 cvs 4523: /* the specific presentation to be created is not a CSS rule */
1.147 quint 4524: ctxt->cssSpecificity = 0;
1.60 cvs 4525: TtaSetStylePresentation (PRSize, el, NULL, ctxt, pval);
4526: }
4527: else
4528: /* absolute value */
4529: {
4530: /**** ****/;
4531: }
4532: }
4533: }
4534: TtaFreeMemory (ctxt);
4535: }
4536:
4537: /*----------------------------------------------------------------------
4538: MathMLSpacingAttr
4539: The MathML attribute attr (height, width or depth) is associated
4540: with element el (a mspace or mpadding).
4541: If value is not NULL, generate the corresponding Thot presentation rule for
4542: the element.
4543: If value is NULL, remove the corresponding Thot presentation rule.
4544: -----------------------------------------------------------------------*/
1.120 cvs 4545: void MathMLSpacingAttr (Document doc, Element el, char *value, int attr)
1.60 cvs 4546: {
4547: ElementType elType;
4548: PresentationValue pval;
4549: PresentationContext ctxt;
4550: int ruleType;
4551:
4552: /* provisionally, handles only mspace elements */
4553: elType = TtaGetElementType (el);
1.96 cvs 4554: if (elType.ElTypeNum != MathML_EL_MSPACE &&
1.97 cvs 4555: elType.ElTypeNum != MathML_EL_MPADDED &&
4556: elType.ElTypeNum != MathML_EL_MTABLE)
1.60 cvs 4557: return;
4558: switch (attr)
4559: {
4560: case MathML_ATTR_width_:
4561: ruleType = PRWidth;
4562: break;
4563: case MathML_ATTR_height_:
4564: ruleType = PRPaddingTop;
4565: break;
4566: case MathML_ATTR_depth_:
4567: ruleType = PRPaddingBottom;
4568: break;
4569: default:
4570: return;
4571: }
4572: ctxt = TtaGetSpecificStyleContext (doc);
1.116 cvs 4573: if (!value || (strcmp (value, "auto") == 0))
1.60 cvs 4574: /* remove the presentation rule */
4575: {
4576: ctxt->destroy = TRUE;
1.75 cvs 4577: pval.typed_data.value = 0;
1.60 cvs 4578: TtaSetStylePresentation (ruleType, el, NULL, ctxt, pval);
4579: }
4580: else
4581: {
4582: ctxt->destroy = FALSE;
4583: /* parse the attribute value (a number followed by a unit) */
1.119 cvs 4584: value = TtaSkipBlanks (value);
1.60 cvs 4585: value = ParseCSSUnit (value, &pval);
4586: /***** we should accept namedspace for width *****/
1.184 vatton 4587: if (pval.typed_data.unit != UNIT_INVALID)
1.78 cvs 4588: {
1.184 vatton 4589: if (pval.typed_data.unit == UNIT_BOX)
4590: pval.typed_data.unit = UNIT_PX;
1.78 cvs 4591: /* the specific presentation to be created is not a CSS rule */
1.147 quint 4592: ctxt->cssSpecificity = 0;
1.78 cvs 4593: TtaSetStylePresentation (ruleType, el, NULL, ctxt, pval);
4594: }
1.60 cvs 4595: }
4596: TtaFreeMemory (ctxt);
4597: }
4598:
4599: /*----------------------------------------------------------------------
1.169 quint 4600: MathMLSetDisplaystyleAttr
4601: The attribute displaystyle is associated with element el (which
4602: should be a <mstyle> or a <mtable> element).
1.175 quint 4603: Generate or set the corresponding internal attribute accordingly.
1.169 quint 4604: ----------------------------------------------------------------------*/
4605: void MathMLSetDisplaystyleAttr (Element el, Attribute attr, Document doc,
4606: ThotBool delete)
4607: {
4608: int val, intVal;
4609: ElementType elType;
4610: AttributeType attrType;
4611: Attribute intAttr;
1.153 quint 4612:
1.175 quint 4613: intVal = 0;
1.169 quint 4614: /* get the internal attribute */
4615: elType = TtaGetElementType (el);
4616: attrType.AttrSSchema = elType.ElSSchema;
4617: attrType.AttrTypeNum = MathML_ATTR_IntDisplaystyle;
4618: intAttr = TtaGetAttribute (el, attrType);
4619: if (delete)
4620: /* attribute displaystyle has been deleted */
4621: {
4622: if (elType.ElTypeNum == MathML_EL_MSTYLE)
4623: /* it's a mstyle element. Just remove the internal attribute */
4624: {
4625: if (intAttr)
4626: TtaRemoveAttribute (el, intAttr, doc);
4627: }
4628: else if (elType.ElTypeNum == MathML_EL_MTABLE)
4629: /* it's a matable element, set the default value (false) */
4630: intVal = MathML_ATTR_IntDisplaystyle_VAL_false;
4631: }
4632: else
4633: {
4634: val = TtaGetAttributeValue (attr);
4635: if (val == MathML_ATTR_displaystyle_VAL_true)
4636: intVal = MathML_ATTR_IntDisplaystyle_VAL_true;
4637: else
4638: intVal = MathML_ATTR_IntDisplaystyle_VAL_false;
4639: }
4640: /* create the IntDisplaystyle attribute if needed and set its value */
1.175 quint 4641: if (intVal)
1.169 quint 4642: {
1.175 quint 4643: if (!intAttr)
4644: {
4645: intAttr = TtaNewAttribute (attrType);
4646: TtaAttachAttribute (el, intAttr, doc);
4647: }
4648: TtaSetAttributeValue (intAttr, intVal, el, doc);
1.169 quint 4649: }
1.175 quint 4650: ApplyDisplaystyle (el, doc);
1.153 quint 4651: }
4652:
4653: /*----------------------------------------------------------------------
1.1 cvs 4654: MathMLAttributeComplete
1.58 cvs 4655: The XML parser has completed parsing attribute attr (as well as its value)
4656: that is associated with element el in document doc.
1.1 cvs 4657: ----------------------------------------------------------------------*/
1.120 cvs 4658: void MathMLAttributeComplete (Attribute attr, Element el, Document doc)
1.1 cvs 4659: {
1.134 cvs 4660: AttributeType attrType, depAttrType;
1.23 cvs 4661: int attrKind;
1.50 cvs 4662: ElementType elType;
1.120 cvs 4663: char *value;
1.50 cvs 4664: int val, length;
1.101 cvs 4665: Attribute intAttr;
1.169 quint 4666:
1.58 cvs 4667: /* first get the type of that attribute */
1.23 cvs 4668: TtaGiveAttributeType (attr, &attrType, &attrKind);
1.153 quint 4669:
1.54 cvs 4670: if (attrType.AttrTypeNum == MathML_ATTR_bevelled)
1.58 cvs 4671: /* it's a bevelled attribute */
1.50 cvs 4672: {
4673: val = TtaGetAttributeValue (attr);
1.54 cvs 4674: if (val == MathML_ATTR_bevelled_VAL_true)
4675: /* bevelled = true. Transform MFRAC into BevelledMFRAC */
1.50 cvs 4676: {
4677: elType = TtaGetElementType (el);
4678: if (elType.ElTypeNum == MathML_EL_MFRAC)
1.54 cvs 4679: ChangeTypeOfElement (el, doc, MathML_EL_BevelledMFRAC);
1.50 cvs 4680: }
4681: }
1.101 cvs 4682:
4683: else if (attrType.AttrTypeNum == MathML_ATTR_rowalign_mtr)
4684: {
4685: /* create an equivalent IntRowAlign attribute on the same element */
4686: attrType.AttrTypeNum = MathML_ATTR_IntRowAlign;
4687: intAttr = TtaGetAttribute (el, attrType);
4688: if (!intAttr)
4689: /* no IntRowAlign attribute, create one */
4690: {
4691: intAttr = TtaNewAttribute (attrType);
4692: TtaAttachAttribute (el, intAttr, doc);
4693: }
4694: val = TtaGetAttributeValue (attr);
4695: TtaSetAttributeValue (intAttr, val, el, doc);
4696: }
4697:
4698: else if (attrType.AttrTypeNum == MathML_ATTR_columnalign_mtd)
4699: {
4700: /* create an equivalent IntColAlign attribute on the same element */
4701: attrType.AttrTypeNum = MathML_ATTR_IntColAlign;
4702: intAttr = TtaGetAttribute (el, attrType);
4703: if (!intAttr)
4704: /* no IntColAlign attribute, create one */
4705: {
4706: intAttr = TtaNewAttribute (attrType);
4707: TtaAttachAttribute (el, intAttr, doc);
4708: }
4709: val = TtaGetAttributeValue (attr);
4710: TtaSetAttributeValue (intAttr, val, el, doc);
4711: }
4712:
1.159 quint 4713: /* don't handle attributes columnalign, rowalign, columnlines and rowlines
4714: now: the table or the row is not complete yet. Handle them when the
4715: element is complete.
1.104 cvs 4716: */
1.153 quint 4717:
4718: else if (attrType.AttrTypeNum == MathML_ATTR_display)
1.175 quint 4719: /* it's a display attribute on element <math>, set the corresponding
4720: internal attribute IntDisplaystyle */
4721: SetDisplaystyleMathElement (el, doc);
1.169 quint 4722:
4723: else if (attrType.AttrTypeNum == MathML_ATTR_displaystyle)
4724: /* it's a displaystyle attribute */
4725: MathMLSetDisplaystyleAttr (el, attr, doc, FALSE);
1.138 cvs 4726:
1.168 quint 4727: else if (attrType.AttrTypeNum == MathML_ATTR_framespacing)
4728: /* it's a framespacing attribute */
4729: HandleFramespacingAttribute (attr, el, doc, FALSE);
4730:
1.138 cvs 4731: else if (attrType.AttrTypeNum == MathML_ATTR_Language)
4732: {
4733: if (el == TtaGetRootElement (doc))
4734: /* it's the lang attribute on the root element */
4735: /* set the RealLang attribute */
4736: {
4737: depAttrType.AttrSSchema = attrType.AttrSSchema ;
4738: depAttrType.AttrTypeNum = MathML_ATTR_RealLang;
4739: if (!TtaGetAttribute (el, depAttrType))
4740: /* it's not present. Add it */
4741: {
4742: intAttr = TtaNewAttribute (depAttrType);
4743: TtaAttachAttribute (el, intAttr, doc);
4744: TtaSetAttributeValue (intAttr, MathML_ATTR_RealLang_VAL_Yes_,
4745: el, doc);
4746: }
4747: }
4748: }
1.101 cvs 4749:
1.50 cvs 4750: else if (attrType.AttrTypeNum == MathML_ATTR_color ||
1.93 cvs 4751: attrType.AttrTypeNum == MathML_ATTR_mathcolor ||
4752: attrType.AttrTypeNum == MathML_ATTR_background_ ||
4753: attrType.AttrTypeNum == MathML_ATTR_mathbackground ||
4754: attrType.AttrTypeNum == MathML_ATTR_fontsize ||
4755: attrType.AttrTypeNum == MathML_ATTR_mathsize ||
4756: attrType.AttrTypeNum == MathML_ATTR_fontfamily ||
4757: attrType.AttrTypeNum == MathML_ATTR_linethickness ||
4758: attrType.AttrTypeNum == MathML_ATTR_lspace ||
4759: attrType.AttrTypeNum == MathML_ATTR_rspace ||
4760: attrType.AttrTypeNum == MathML_ATTR_scriptlevel ||
4761: attrType.AttrTypeNum == MathML_ATTR_width_ ||
4762: attrType.AttrTypeNum == MathML_ATTR_height_ ||
1.168 quint 4763: attrType.AttrTypeNum == MathML_ATTR_depth_)
1.93 cvs 4764: {
1.23 cvs 4765: length = TtaGetTextAttributeLength (attr);
4766: if (length >= buflen)
4767: length = buflen - 1;
4768: if (length > 0)
4769: {
1.116 cvs 4770: value = TtaGetMemory (buflen);
1.33 cvs 4771: value[0] = EOS;
4772: TtaGiveTextAttributeValue (attr, value, &length);
4773: switch (attrType.AttrTypeNum)
4774: {
4775: case MathML_ATTR_color:
1.134 cvs 4776: /* deprecated attribute */
4777: /* if the same element has a mathcolor attribute, ignore
4778: the color attribute */
4779: depAttrType.AttrSSchema = attrType.AttrSSchema ;
4780: depAttrType.AttrTypeNum = MathML_ATTR_mathcolor;
4781: if (!TtaGetAttribute (el, depAttrType))
4782: HTMLSetForegroundColor (doc, el, value);
4783: break;
1.93 cvs 4784: case MathML_ATTR_mathcolor:
1.24 cvs 4785: HTMLSetForegroundColor (doc, el, value);
4786: break;
1.33 cvs 4787: case MathML_ATTR_background_:
1.134 cvs 4788: /* deprecated attribute */
4789: /* if the same element has a mathbackground attribute, ignore
4790: the background attribute */
4791: depAttrType.AttrSSchema = attrType.AttrSSchema;
4792: depAttrType.AttrTypeNum = MathML_ATTR_mathbackground;
4793: if (!TtaGetAttribute (el, depAttrType))
4794: HTMLSetBackgroundColor (doc, el, value);
4795: break;
1.93 cvs 4796: case MathML_ATTR_mathbackground:
1.24 cvs 4797: HTMLSetBackgroundColor (doc, el, value);
4798: break;
1.33 cvs 4799: case MathML_ATTR_fontfamily:
1.24 cvs 4800: SetFontfamily (doc, el, value);
1.83 cvs 4801: break;
4802: case MathML_ATTR_linethickness:
4803: MathMLlinethickness (doc, el, value);
1.58 cvs 4804: break;
4805: case MathML_ATTR_fontsize:
1.134 cvs 4806: /* deprecated attribute */
4807: /* if the same element has a mathsize attribute, ignore
4808: the fontsize attribute */
4809: depAttrType.AttrSSchema = attrType.AttrSSchema;
4810: depAttrType.AttrTypeNum = MathML_ATTR_mathsize;
4811: if (!TtaGetAttribute (el, depAttrType))
4812: MathMLAttrToStyleProperty (doc, el, value,
4813: attrType.AttrTypeNum);
4814: break;
1.93 cvs 4815: case MathML_ATTR_mathsize:
1.58 cvs 4816: case MathML_ATTR_lspace:
4817: case MathML_ATTR_rspace:
1.60 cvs 4818: MathMLAttrToStyleProperty (doc, el, value,attrType.AttrTypeNum);
4819: break;
4820: case MathML_ATTR_scriptlevel:
4821: MathMLSetScriptLevel (doc, el, value);
4822: break;
4823: case MathML_ATTR_width_:
4824: case MathML_ATTR_height_:
4825: case MathML_ATTR_depth_:
4826: MathMLSpacingAttr (doc, el, value, attrType.AttrTypeNum);
1.59 cvs 4827: break;
4828: default:
1.24 cvs 4829: break;
1.33 cvs 4830: }
4831: TtaFreeMemory (value);
1.23 cvs 4832: }
4833: }
1.1 cvs 4834: }
4835:
4836: /*----------------------------------------------------------------------
4837: MathMLGetDTDName
4838: ----------------------------------------------------------------------*/
1.120 cvs 4839: void MathMLGetDTDName (char *DTDname, char *elementName)
1.1 cvs 4840: {
4841: /* no other DTD allowed within MathML elements */
1.116 cvs 4842: strcpy (DTDname, "");
1.1 cvs 4843: }
4844:
4845: /* end of module */
Webmaster