Exemplo n.º 1
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);
        }