//.....................................................................
        /// <summary>
        /// 公式中名称是正文样式,没有斜体
        /// </summary>
        /// <param name="mathlin"></param>
        /// <returns></returns>
        public static M.Run MakeMathRun(string mathlin, bool plainstyle = false)
        {
            //M.Style fontstyle = new M.Style( ) { Val = M.StyleValues.Plain };
            //RunFonts fonts = new RunFonts( ) { Ascii = "Cambria Math", HighAnsi = "Cambria Math" };

            RunProperties properties = new RunProperties( );

            properties.Append(OpenDocxMathExprs.MakeMathFont( ));

            if (plainstyle)
            {
                properties.Append(OpenDocxMathExprs.MakeMathFonStyle( ));
            }

            //---------------------------------------------
            M.Text mathtext = new M.Text( );
            mathtext.Text = mathlin;

            //---------------------------------------------
            M.Run mathrun = new M.Run( );
            mathrun.Append(properties);
            mathrun.Append(mathtext);

            return(mathrun);
        }
        //.....................................................................
        /// <summary>
        ///
        /// </summary>
        /// <param name="textln"></param>
        /// <returns></returns>
        private OpxM.Text SimpleMathText(string textln)
        {
            OpxM.Text mathtext = new OpxM.Text( );

            mathtext.Text = textln;

            return(mathtext);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public OXMLMathRunWrap(string text)
        {
            _text = text;

            XMLRun = new M.Run();

                RunProperties runProperties4 = new RunProperties();
                RunFonts runFonts4 = new RunFonts(){ Ascii = "Cambria Math", HighAnsi = "Cambria Math" };
                Languages languages4 = new Languages(){ Val = "en-US" };

                runProperties4.Append(runFonts4);
                runProperties4.Append(languages4);
                M.Text text3 = new M.Text();
                text3.Text = text;

            XMLRun.Append(runProperties4);
            if (text != "") XMLRun.Append(text3);
        }
Ejemplo n.º 5
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;
    }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private static M.Superscript MakeScriptUpper( )
        {
            M.Superscript superscript1 = new M.Superscript( );

            M.SuperscriptProperties superscriptProperties1 = new M.SuperscriptProperties( );

            M.ControlProperties controlProperties3 = new M.ControlProperties( );

            RunProperties runProperties10 = new RunProperties( );
            RunFonts      runFonts8       = new RunFonts( )
            {
                Ascii = "Cambria Math", HighAnsi = "Cambria Math"
            };
            Italic italic2 = new Italic( );

            runProperties10.Append(runFonts8);
            runProperties10.Append(italic2);

            controlProperties3.Append(runProperties10);

            superscriptProperties1.Append(controlProperties3);

            M.Base base2 = new M.Base( );

            M.Run run6 = new M.Run( );

            RunProperties runProperties11 = new RunProperties( );
            RunFonts      runFonts9       = new RunFonts( )
            {
                Ascii = "Cambria Math", HighAnsi = "Cambria Math"
            };

            runProperties11.Append(runFonts9);
            M.Text text6 = new M.Text( );
            text6.Text = "x";

            run6.Append(runProperties11);
            run6.Append(text6);

            base2.Append(run6);

            M.SuperArgument superArgument2 = new M.SuperArgument( );

            M.Run run7 = new M.Run( );

            RunProperties runProperties12 = new RunProperties( );
            RunFonts      runFonts10      = new RunFonts( )
            {
                Ascii = "Cambria Math", HighAnsi = "Cambria Math"
            };

            runProperties12.Append(runFonts10);
            M.Text text7 = new M.Text( );
            text7.Text = "3";

            run7.Append(runProperties12);
            run7.Append(text7);

            superArgument2.Append(run7);

            superscript1.Append(superscriptProperties1);
            superscript1.Append(base2);
            superscript1.Append(superArgument2);
            return(superscript1);
        }