Exemple #1
0
        private static RichTextRunFont CreateRichTextRun(ReadOnlyTextProperties tp)
        {
            var runFont = new RichTextRunFont(tp.FontName, tp.DoubleFontSize / 2, tp.ForeColor)
            {
                Bold          = tp.FontBold,
                Italic        = tp.FontItalic,
                Strikethrough = tp.StrikeoutType == StrikeoutType.Single
            };

            runFont.Script = tp.Script switch
            {
                DevExpress.Office.CharacterFormattingScript.Subscript => ScriptType.Subscript,
                DevExpress.Office.CharacterFormattingScript.Superscript => ScriptType.Superscript,
                _ => ScriptType.None
            };
            runFont.UnderlineType = tp.UnderlineType switch
            {
                DevExpress.XtraRichEdit.API.Native.UnderlineType.Single => DevExpress.Spreadsheet.UnderlineType.Single,
                DevExpress.XtraRichEdit.API.Native.UnderlineType.Double => DevExpress.Spreadsheet.UnderlineType.Double,
                _ => DevExpress.Spreadsheet.UnderlineType.None
            };
            return(runFont);
        }
    }
}
Exemple #2
0
        public override void Visit(DocumentText text)
        {
            base.Visit(text);
            RichTextRunFont runFont = CreateRichTextRun(text.TextProperties);

            richTextString.AddTextRun(text.Text, runFont);
        }
Exemple #3
0
 public override void Visit(DocumentParagraphEnd paragraphEnd)
 {
     base.Visit(paragraphEnd);
     if (endPosition - 1 != paragraphEnd.Position)
     {
         RichTextRunFont runFont = CreateRichTextRun(paragraphEnd.TextProperties);
         richTextString.AddTextRun(paragraphEnd.Text, runFont);
     }
 }
Exemple #4
0
        public RichTextString tietToRich(TietHoc element, string type, int fontSize)
        {
            RichTextString richText = new RichTextString();

            if (element.diaDiem != null && element.diaDiem != "" && element.diaDiem != Lop.giangDuong.ToString())
            {
                RichTextRunFont font = new RichTextRunFont("Times New Roman", size - 2);
                font.Script = ScriptType.Superscript;
                font.Bold   = true;
                richText.AddTextRun(element.diaDiem, font);
                richText.AddTextRun(" ", new RichTextRunFont("Times New Roman", 2));
            }

            RichTextRunFont font2;

            if (element.mon.ten.Contains("|"))
            {   //Nếu là dạng môn có mã phức tạp
                string[] arr   = element.mon.ten.Split(new char[] { '|' });
                string[] maMon = arr[1].Split(new char[] { '_' });
                foreach (string ma in maMon)
                {
                    if (ma[0] == '^')
                    {
                        font2        = new RichTextRunFont("Times New Roman", size - 2);
                        font2.Script = ScriptType.None;
                    }
                    else
                    {
                        font2        = new RichTextRunFont("Times New Roman", size - 2);
                        font2.Script = ScriptType.Subscript;
                    }
                    font2.Bold = true;
                    richText.AddTextRun(ma.Substring(1), font2);
                }
            }
            else
            {   //Nếu là dạng môn có mã mặc định
                font2        = new RichTextRunFont("Times New Roman", size);
                font2.Script = ScriptType.None;
                font2.Bold   = true;
                richText.AddTextRun(element.mon.ma, font2);
            }
            //Thêm kc ngắn sau mã môn
            richText.AddTextRun(" ", new RichTextRunFont("Times New Roman", 2));

            if (element.bai != "" && element.bai != null && type != "tuan" && type != "ngay")
            {
                RichTextRunFont font3 = new RichTextRunFont("Times New Roman", size - 2);
                font3.Script = ScriptType.Superscript;
                font3.Bold   = true;
                richText.AddTextRun(element.bai, font3);
                richText.AddTextRun(" ", new RichTextRunFont("Times New Roman", 2));
            }

            if (element.hinhThuc != "" && element.hinhThuc != "LT" && element.hinhThuc != null)
            {
                RichTextRunFont font4 = new RichTextRunFont("Times New Roman", size - 2);
                font4.Bold = true;
                if (element.hinhThuc == "+" || element.hinhThuc == ".")
                {
                    if (element.hinhThuc == ".")
                    {
                        font4.Size = 13;
                    }
                    else
                    {
                        font4.Size = 9;
                    }
                }
                else
                {
                    font4.Script = ScriptType.Subscript;
                }
                richText.AddTextRun(element.hinhThuc, font4);
            }

            return(richText);
        }