Example #1
0
        protected override WriteResult Write(OpenXMLWpfMathRenderer renderer, OverlinedAtom item)
        {
            var bar = renderer.Push(new Bar());

            var barProperties = new BarProperties();

            barProperties.AppendChild(
                new Position()
            {
                Val = VerticalJustificationValues.Top
            }
                );

            barProperties.AppendChild(
                new ControlProperties(
                    new W.RunProperties(
                        new W.RunFonts()
            {
                Ascii = "Cambria Math", HighAnsi = "Cambria Math"
            },
                        new W.Italic()
                        )
                    )
                );

            bar.AppendChild(barProperties);

            renderer.Push(new Base());

            renderer.Write(item.BaseAtom);

            renderer.PopTo(bar);

            return(WriteResult.Completed);
        }
Example #2
0
        protected override WriteResult Write(OpenXMLWpfMathRenderer renderer, WpfMath.Radical item)
        {
            var radicalEle = renderer.Push(new Radical());

            var radicalProperties = new RadicalProperties(
                new ControlProperties(
                    new W.RunProperties(
                        new W.RunFonts()
            {
                Ascii = "Cambria Math", HighAnsi = "Cambria Math"
            },
                        new W.Italic()
                        )
                    )
                );

            if (null == item.DegreeAtom)
            {
                radicalProperties.PrependChild(new HideDegree()
                {
                    Val = BooleanValues.One
                });
            }
            radicalEle.AppendChild(radicalProperties);

            // note we need a Degree element even if no degree text is present
            // (but note that in this case we have a HideDegree element in RadicalProperties)
            var degreeEle = renderer.Push(new Degree());

            if (null != item.DegreeAtom)
            {
                renderer.Write(item.DegreeAtom);
            }
            renderer.PopTo(degreeEle);


            if (null != item.BaseAtom)
            {
                var baseEle = renderer.Push(new Base());
                renderer.Write(item.BaseAtom);
                renderer.PopTo(baseEle);
            }

            renderer.PopTo(radicalEle);

            return(WriteResult.Completed);
        }
Example #3
0
        protected override WriteResult Write(OpenXMLWpfMathRenderer renderer, FractionAtom item)
        {
            var frac = renderer.Push(new Fraction());

            var numerator = renderer.Push(new Numerator());

            renderer.Write(item.Numerator);
            renderer.PopTo(numerator);

            var denominator = renderer.Push(new Denominator());

            renderer.Write(item.Denominator);
            renderer.PopTo(denominator);

            renderer.PopTo(frac);

            return(WriteResult.Completed);
        }
Example #4
0
        protected override WriteResult Write(OpenXMLWpfMathRenderer renderer, CharAtom item)
        {
            bool runCreated = false;
            var  run        = renderer.Peek() as Run;

            if (run == null)
            {
                runCreated = true;
                run        = (Run)renderer.Push(new Run());

                var runProperties = new W.RunProperties();
                runProperties.AppendChild(new W.RunFonts()
                {
                    Ascii = "Cambria Math", HighAnsi = "Cambria Math"
                });

                // Foreground color
                var cf = renderer.PeekForegroundColor();
                if (cf.R != 0 || cf.G != 0 || cf.B != 0)
                {
                    runProperties.AppendChild(new W.Color()
                    {
                        Val = string.Format("{0:X2}{1:X2}{2:X2}", cf.R, cf.G, cf.B)
                    });
                }

                // Background color
                var cb = renderer.PeekBackgroundColor();
                if (cb.R != 255 || cb.G != 255 || cb.B != 255)
                {
                    runProperties.AppendChild(new W.Shading()
                    {
                        Color = "Auto", Fill = string.Format("{0:X2}{1:X2}{2:X2}", cb.R, cb.G, cb.B)
                    });
                }


                run.AppendChild(runProperties);
            }

            var text = new DocumentFormat.OpenXml.Math.Text()
            {
                Text = string.Empty + item.Character
            };

            run.AppendChild(text);


            if (runCreated)
            {
                renderer.PopTo(run);
            }

            return(WriteResult.Completed);
        }
Example #5
0
        protected override WriteResult Write(OpenXMLWpfMathRenderer renderer, AccentedAtom item)
        {
            string accentString = string.Empty;

            if (item.AccentAtom is SymbolAtom symAtom)
            {
                if (SymbolAtomRenderer.TryConvert(symAtom.Name, out var text))
                {
                    accentString = text;
                }

                if (symAtom.Name == "widehat")
                {
                    accentString = null;
                }
            }

            var accent = new Accent();

            renderer.Push(accent);

            var accentProperties = new AccentProperties();

            if (accentString != null) // for widehat, it seems that Word don't even have an accent char (and for widetilde, it is an empty string !)
            {
                accentProperties.AppendChild(new AccentChar()
                {
                    Val = accentString
                });
            }

            accentProperties.AppendChild(
                new ControlProperties(
                    new W.RunProperties(
                        new W.RunFonts()
            {
                Ascii = "Cambria Math", HighAnsi = "Cambria Math"
            },
                        new W.Italic()
                        )
                    )
                );

            accent.AppendChild(accentProperties);

            renderer.Push(new Base());

            renderer.Write(item.BaseAtom);

            renderer.PopTo(accent);

            return(WriteResult.Completed);
        }
Example #6
0
        protected override WriteResult Write(OpenXMLWpfMathRenderer renderer, FencedAtom item)
        {
            var delimiter = renderer.Push(new Delimiter());


            string leftDelimiterString  = "|";
            string rightDelimiterString = "|";

            if (item.LeftDelimeter is SymbolAtom symLeft)
            {
                if (SymbolAtomRenderer.TryConvert(symLeft.Name, out var text))
                {
                    leftDelimiterString = text;
                }
            }

            if (item.RightDelimeter is SymbolAtom symRight)
            {
                if (SymbolAtomRenderer.TryConvert(symRight.Name, out var text))
                {
                    rightDelimiterString = text;
                }
            }

            var delimiterProp = new DelimiterProperties(
                new BeginChar {
                Val = leftDelimiterString
            },
                new EndChar {
                Val = rightDelimiterString
            },
                new ControlProperties(
                    new W.RunProperties(
                        new W.RunFonts()
            {
                Ascii = "Cambria Math", HighAnsi = "Cambria Math"
            },
                        new W.Italic()
                        )
                    )
                );

            delimiter.AppendChild(delimiterProp);

            var baseEle = renderer.Push(new Base());

            renderer.Write(item.BaseAtom);

            renderer.PopTo(delimiter);

            return(WriteResult.Completed);
        }
Example #7
0
    protected override WriteResult Write(OpenXMLWpfMathRenderer renderer, SymbolAtom item)
    {
      bool runCreated = false;
      var run = renderer.Peek() as Run;

      if (run == null)
      {
        runCreated = true;
        run = (Run)renderer.Push(new Run());
      }

      if (!_nameToSymbol.TryGetValue(item.Name, out var textString))
        textString = item.Name;

      var text = new DocumentFormat.OpenXml.Math.Text() { Text = textString };
      run.AppendChild(text);


      if (runCreated)
        renderer.PopTo(run);

      return WriteResult.Completed;
    }
Example #8
0
        protected override WriteResult Write(OpenXMLWpfMathRenderer renderer, ScriptsAtom item)
        {
            if (item.SubscriptAtom != null && item.SuperscriptAtom != null)
            {
                var subscript = renderer.Push(new SubSuperscript());

                var baseM = renderer.Push(new Base());

                renderer.Write(item.BaseAtom);

                renderer.PopTo(baseM);

                var subArgument = renderer.Push(new SubArgument());

                renderer.Write(item.SubscriptAtom);

                renderer.PopTo(subArgument);

                var superArgument = renderer.Push(new SuperArgument());

                renderer.Write(item.SuperscriptAtom);

                renderer.PopTo(superArgument);

                renderer.PopTo(subscript);
            }
            else if (item.SubscriptAtom != null)
            {
                var subscript = renderer.Push(new Subscript());

                var baseM = renderer.Push(new Base());

                renderer.Write(item.BaseAtom);

                renderer.PopTo(baseM);

                var subArgument = renderer.Push(new SubArgument());

                renderer.Write(item.SubscriptAtom);

                renderer.PopTo(subArgument);

                renderer.PopTo(subscript);
            }
            else if (item.SuperscriptAtom != null)
            {
                var subscript = renderer.Push(new Superscript());

                var baseM = renderer.Push(new Base());

                renderer.Write(item.BaseAtom);

                renderer.PopTo(baseM);

                var superArgument = renderer.Push(new SuperArgument());

                renderer.Write(item.SuperscriptAtom);

                renderer.PopTo(superArgument);

                renderer.PopTo(subscript);
            }

            return(WriteResult.Completed);
        }
Example #9
0
        protected override WriteResult Write(OpenXMLWpfMathRenderer renderer, BigOperatorAtom item)
        {
            var writeResult = WriteResult.Completed;

            if (item.Type == TexAtomType.BigOperator && item.BaseAtom is SymbolAtom symAtom)
            {
                // something like \int, \sum, \prod etc.

                LimitLocationValues?limitLocation = null;
                switch (symAtom.Name)
                {
                case "int":
                case "iint":
                case "iiint":
                case "iiiint":
                case "idotsint":
                case "oint":
                    limitLocation = LimitLocationValues.SubscriptSuperscript;
                    break;

                default:
                    limitLocation = LimitLocationValues.UnderOver;
                    break;
                }

                if (!_nameToBigOperatorSymbol.TryGetValue(symAtom.Name, out var accentString))
                {
                    accentString = null;
                }


                var nary      = renderer.Push(new Nary());
                var naryProps = nary.AppendChild(new NaryProperties());
                if (accentString != null)
                {
                    naryProps.AppendChild(new AccentChar {
                        Val = accentString
                    });
                }
                if (limitLocation.HasValue)
                {
                    naryProps.AppendChild(new LimitLocation {
                        Val = limitLocation.Value
                    });
                }

                var controlProperties = new ControlProperties(
                    new W.RunProperties(
                        new W.RunFonts()
                {
                    Ascii = "Cambria Math", HighAnsi = "Cambria Math"
                },
                        new W.Italic()
                        )
                    );
                naryProps.AppendChild(controlProperties);

                if (item.LowerLimitAtom != null)
                {
                    var sub = renderer.Push(new SubArgument());
                    renderer.Write(item.LowerLimitAtom);
                    renderer.PopTo(sub);
                }
                if (item.UpperLimitAtom != null)
                {
                    var super = renderer.Push(new SuperArgument());
                    renderer.Write(item.UpperLimitAtom);
                    renderer.PopTo(super);
                }

                var baseA    = renderer.Push(new Base());
                var callback = new CallbackPopAfterNextElement(renderer, item, elementToPopTo: nary);
                // renderer.PopTo(nary); we don't pop here, the pop is done after the next element was written (see line before)
                writeResult = WriteResult.CompletionDeferred;
            }
            else if (item.Type == TexAtomType.BigOperator && item.BaseAtom is RowAtom rowAtom)
            {
                // this is treated as a function if rowAtom contains character elements
                if (rowAtom.Elements.Any(a => !(a is CharAtom)))
                {
                    throw new NotImplementedException(); // then we have to look what this is?
                }
                else
                {
                    // all childs of RowAtom are CharAtoms,
                    // we put them together to get the function name
                    string functionName = string.Empty;
                    foreach (CharAtom ca in rowAtom.Elements)
                    {
                        functionName += ca.Character;
                    }

                    var functionProperties = new FunctionProperties(
                        new ControlProperties(
                            new W.RunProperties(
                                new W.RunFonts()
                    {
                        Ascii = "Cambria Math", HighAnsi = "Cambria Math"
                    },
                                new W.Italic()
                                )
                            )
                        );

                    var mathFunction    = renderer.Push(new MathFunction(functionProperties));
                    var functionNameEle = renderer.Push(new FunctionName());
                    var runEle          = renderer.Push(new Run());
                    runEle.AppendChild(
                        new RunProperties(
                            new Style()
                    {
                        Val = StyleValues.Plain
                    }
                            )
                        );
                    runEle.AppendChild(
                        new W.RunProperties(
                            new W.RunFonts()
                    {
                        Ascii = "Cambria Math", HighAnsi = "Cambria Math"
                    },
                            new W.Italic()
                            )
                        );
                    runEle.AppendChild(new DocumentFormat.OpenXml.Math.Text {
                        Text = functionName
                    });
                    renderer.PopTo(functionNameEle);

                    renderer.Push(new Base());
                    var callback = new CallbackPopAfterNextElement(renderer, item, elementToPopTo: mathFunction);
                    // renderer.PopTo(mathFunction);  we don't pop here, the pop is done after the next element was written (see line before)
                    writeResult = WriteResult.CompletionDeferred;
                }
            }
            else
            {
                renderer.Write(item.BaseAtom);
                writeResult = WriteResult.Completed;
            }
            return(writeResult);
        }