コード例 #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);
        }
コード例 #2
0
ファイル: SymbolAtomRenderer.cs プロジェクト: olesar/Altaxo
    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;
    }