private void RenderTextLayout(TextLayout layout, Page page) { if (layout == null) { return; } TextStyle style = (TextStyle)layout.Style; if (style.BackColor != null) { page.AddPath(layout.Bounds.Points, 0, null, Convert.Color(style.BackColor)); } // Draw the border after the background so that the background doesn't // overwrite the border. But draw the border before the content so that // if for any reason the text exceeds the bounds (which should be impossible) // then at least the text will still be visible. RenderBorder(layout.Bounds, style.Border, page); foreach (LineDraft line in layout.Lines) { foreach (StrokeDraft stroke in line.Strokes) { string text = stroke.Stroke.Text; int x = stroke.Position.X; int y = stroke.Position.Y; Demon.Report.Style.Font font = stroke.Stroke.Format.Font; Demon.PDF.Color color = Convert.Color(stroke.Stroke.Format.Color); page.AddText(text, x, y, font.FamilyName, font.Bold, font.Italic, font.Size, color); if (font.Underline) { Demon.Font.Font strokeFont = _generator.GetFont(font); int lineY = y + strokeFont.GetUnderlinePosition(font.Size); float thickness = strokeFont.GetUnderlineThickness(font.Size); List <Position> points = new List <Position>(); points.Add(new Position(x, lineY)); points.Add(new Position(x + stroke.Stroke.Width, lineY)); page.AddPath(points, thickness, color, null); } } } }
public Run(string text, s.Font font, s.Color color) { _text = text; _font = font; _color = color; }
public void AddRun(string text, s.Font font, s.Color color) { Run run = new Run(text, font, color); _content.Add(run); }
public static XElement AddRunProperties(XElement run, s.Font font, s.Color color) { XNamespace ns = run.Name.Namespace; XElement rPr = new XElement(ns + "rPr"); run.Add(rPr); XElement rFonts = new XElement( ns + "rFonts", new XAttribute(ns + "ascii", font.FamilyName), new XAttribute(ns + "cs", font.FamilyName)); rPr.Add(rFonts); // Font size is measured in half points in Word XElement size = new XElement( ns + "sz", new XAttribute(ns + "val", font.Size * 2)); rPr.Add(size); if (font.Bold) { XElement bold = new XElement( ns + "b", new XAttribute(ns + "val", "true")); rPr.Add(bold); } if (font.Italic) { XElement italic = new XElement( ns + "i", new XAttribute(ns + "val", "true")); rPr.Add(italic); } if (font.Underline) { XElement underline = new XElement( ns + "u", new XAttribute(ns + "val", "single")); rPr.Add(underline); } if (font.Strikeout) { XElement strikeout = new XElement( ns + "strike", new XAttribute(ns + "val", "true")); rPr.Add(strikeout); } if (color != null) { int red = (int)(color.Red * 255f); int green = (int)(color.Green * 255f); int blue = (int)(color.Blue * 255f); string value = $"{red:X2}{green:X2}{blue:X2}"; XElement colorElem = new XElement( ns + "color", new XAttribute(ns + "val", value)); rPr.Add(colorElem); } return(rPr); }