protected override Box __AddSubscript(Expr e, Box nuc, Box sub) { if (nuc is StringBox || nuc is CharBox) { return(new AtomBox(null, nuc, sub, new NullBox(), GetTType(nuc))); // for 'log' function's base, really } else { // XXX Having to edit existing boxes this way here means that the box system is almost certainly misdesigned. List <Box> lb = new List <Box>(new Box[] { nuc }); /* Find parent of last real atomic thing */ List <Box> pb = lb; while (pb[pb.Count - 1] is HBox) { pb = ((HBox)pb[pb.Count - 1]).Boxes; } /* the last real thing itself */ Box b = pb[pb.Count - 1]; AtomBox ab = b as AtomBox; if (ab != null) { Trace.Assert(ab.Sup is NullBox && ab.Sub is NullBox); // shouldn't happen given 1st if of our caller ab.Sub = sub; } else { Box bb = new AtomBox(null, b, sub, new NullBox(), GetTType(b)); pb[pb.Count - 1] = bb; } return(new HBox(e, lb)); } }
protected override Box __AddSuperscript(Expr e, Box nuc, Box sup) { // XXX Having to edit existing boxes this way here means that the box system is almost certainly misdesigned. List <Box> lb = new List <Box>(new Box[] { nuc }); /* Find parent of last real atomic thing (which can have a superscript) */ List <Box> pb = lb; while (pb[pb.Count - 1] is HBox) { pb = ((HBox)pb[pb.Count - 1]).Boxes; } /* the last real thing itself */ Box b = pb[pb.Count - 1]; AtomBox ab = b as AtomBox; if (ab != null) { Trace.Assert(ab.Sup is NullBox); // shouldn't happen given 1st if of our caller ab.Sup = sup; } else { Box bb = new AtomBox(null, b, new NullBox(), sup, GetTType(b)); pb[pb.Count - 1] = bb; } return(new HBox(e, lb)); }
public static object[] tour(object graph, List<string> ns, Dictionary<string, string> aliases) { Guide guide = new Guide(); AtomBox outbox = new AtomBox(); ListBox collection = new ListBox(); Dictionary<object, object> symtab = new Dictionary<object, object>(); add_namespace_directives(ns, aliases, collection); ConstructSiteseer construct = new ConstructSiteseer(outbox, collection, ns, symtab, aliases); guide.tour(graph, construct); return ((object[])outbox.value); }
private void _Traverse(AtomBox ab) { EWPF.Fixup(ab.Sub, _traverseType); if (!(ab.Nucleus is CharBox || ab.Nucleus is StringBox)) { EWPF.Fixup(ab.Nucleus, _traverseType); } EWPF.Fixup(ab.Sup, _traverseType); Leaf(); }
public override AtomVisitor visit_Atom_car() { m_atom = new AtomBox(); return new AtomBuilder(m_atom); }
private void ConsiderPairSpacing() { if (A == null || B == null) { return; } Box a = A.Final.Target; Box b = B.Final.Target; /* Do TeX atom type and spacing fixup rules from p 170 and appendix G */ Syntax.TType atype = GetTType(a), btype = GetTType(b); /* rule 20 */ int spacing = IBSpacing[(int)atype, (int)btype]; Trace.Assert(spacing != 5); Box space = null; switch (spacing) { case 0: // all the code for this case is *not* part of TeX's rule 20. It comes from p 169 and applies specifically to factorial // operators, so won't be correct for other possible uses of '!' if (atype == Syntax.TType.Ord && a is CharBox && ((CharBox)a).C == '!') { CharBox cb = b as CharBox; StringBox sb = b as StringBox; AtomBox ab = b as AtomBox; if ((btype == Syntax.TType.Ord && ((cb != null && (Char.IsLetter(cb.C) || Char.IsDigit(cb.C))) || (sb != null && (Char.IsLetter(sb.S, 0) || Char.IsDigit(sb.S, 0))))) || btype == Syntax.TType.Open) { space = ThinSkip(); } else if (btype == Syntax.TType.Ord && ab != null) { cb = ab.Nucleus as CharBox; sb = ab.Nucleus as StringBox; if ((cb != null && (Char.IsLetter(cb.C) || Char.IsDigit(cb.C))) || (sb != null && (Char.IsLetter(sb.S, 0) || Char.IsDigit(sb.S, 0)))) { space = ThinSkip(); } } } break; case 1: space = ThinSkip(); break; case 2: space = MedSkip(); break; case 3: space = ThickSkip(); break; case -1: space = DTThinSkip(); break; case -2: space = DTMedSkip(); break; case -3: space = DTThickSkip(); break; } /* apply the spacing */ if (space != null) { /* Find the lowest common ancestor */ int found = -1; for (int i = 0; i < A.P.Count && i < B.P.Count; i++) { if (A.P[i].Target != B.P[i].Target) { found = i; break; } } Trace.Assert(found != -1, "adjacent boxes are the same?"); Trace.Assert(A.P[found].B == B.P[found].B); Trace.Assert(A.P[found].GetType() == B.P[found].GetType()); List <Box> boxes; int ix; if (A.P[found] is HBoxLink) { HBoxLink hba = (HBoxLink)A.P[found]; HBoxLink hbb = (HBoxLink)B.P[found]; Trace.Assert(hba.I < hbb.I); for (int i = hba.I + 1; i < hbb.I; i++) { Trace.Assert(hba.HB.Boxes[i] is MuSkipBox || hba.HB.Boxes[i] is DTMuSkipBox); } boxes = hba.HB.Boxes; ix = hbb.I; } else { DelimitedBoxLink dba = (DelimitedBoxLink)A.P[found]; DelimitedBoxLink dbb = (DelimitedBoxLink)B.P[found]; boxes = dba.DB.Contents.Boxes; if (dba.Piece == DelimitedBoxLink.Which.Left) { Trace.Assert(dbb.Piece != DelimitedBoxLink.Which.Left); ix = 0; } else { Trace.Assert(dba.Piece == DelimitedBoxLink.Which.Contents); Trace.Assert(dbb.Piece == DelimitedBoxLink.Which.Right); ix = boxes.Count; } } SortedDictionary <int, Box> inserts; if (!_listBoxInserts.TryGetValue(boxes, out inserts)) { inserts = new SortedDictionary <int, Box>(); _listBoxInserts[boxes] = inserts; } inserts.Add(ix, space); } }