Esempio n. 1
0
        private void StyleRun(Run Run, Scope Scope)
        {
            string foreground = null;
            string background = null;
            bool   italic     = false;
            bool   bold       = false;

            if (Styles.Contains(Scope.Name))
            {
                Styling.Style style = Styles[Scope.Name];

                foreground = style.Foreground;
                background = style.Background;
                italic     = style.Italic;
                bold       = style.Bold;
            }

            if (!string.IsNullOrWhiteSpace(foreground))
            {
                Run.Foreground = foreground.GetSolidColorBrush();
            }

            //Background isn't supported, but a workaround could be created.

            if (italic)
            {
                Run.FontStyle = FontStyle.Italic;
            }

            if (bold)
            {
                Run.FontWeight = FontWeights.Bold;
            }
        }
Esempio n. 2
0
 public virtual void RemoveStyle(IStyle style)
 {
     if (Styles.Contains(style))
     {
         Styles.Remove(style);
     }
 }
Esempio n. 3
0
 public virtual void AddStyle(IStyle style)
 {
     if (!Styles.Contains(style))
     {
         Styles.Add(style);
     }
 }
        private void BuildSpanForCapturedStyle(Scope scope)
        {
            string cssClassName = "";

            if (Styles.Contains(scope.Name))
            {
                Style style = Styles[scope.Name];

                cssClassName = style.ReferenceName;
            }

            WriteElementStart("span", cssClassName);
        }
Esempio n. 5
0
        private void WriteHeaderDivStart()
        {
            string foreground = string.Empty;
            string background = string.Empty;

            if (Styles.Contains(ScopeName.PlainText))
            {
                Style plainTextStyle = Styles[ScopeName.PlainText];

                foreground = plainTextStyle.Foreground;
                background = plainTextStyle.Background;
            }

            WriteElementStart("div", foreground, background);
        }
Esempio n. 6
0
        private void UpdatePropertyValues()
        {
            Id    = NodeBehind.Id;
            Label = WpfHelper.IdToText(
                NodeBehind.HasAttribute("label")
                    ? NodeBehind.GetAttribute("label")
                    : NodeBehind.Id);

            Styles = WpfHelper.IdToStyles(
                NodeBehind.HasAttribute("style", true)
                    ? NodeBehind.GetAttribute("style", true)
                    : null);

            NodeShapeData = WpfHelper.ConvertToShapeData(
                NodeBehind.HasAttribute("shape", true)
                    ? NodeBehind.GetAttribute("shape", true)
                    : "ellipse",
                NodeBehind.HasAttribute("sides", true)
                    ? NodeBehind.GetAttribute("sides", true)
                    : "4",
                Styles.Contains("diagonals"));

            //Dot extends the border in both directions but wpf only inwards
            //so we compensate this by increasing the Width/Height by StrokeThickness.
            //Side note: Thickness is set to 0 in case of a plain shape
            StrokeThickness = GetNodeStrokeThickness();

            CenterX = WpfHelper.StringToPixel(WpfHelper.IdToText(
                                                  NodeBehind.GetAttribute("pos")).Split(',')[0] + "pt");
            CenterY = WpfHelper.StringToPixel(WpfHelper.IdToText(
                                                  NodeBehind.GetAttribute("pos")).Split(',')[1] + "pt");
            Width = WpfHelper.StringToPixel(WpfHelper.IdToText(
                                                NodeBehind.GetAttribute("width", true)) + "in")
                    + StrokeThickness;
            Height = WpfHelper.StringToPixel(WpfHelper.IdToText(
                                                 NodeBehind.GetAttribute("height", true)) + "in")
                     + StrokeThickness;
            X      = CenterX - Width / 2;
            Y      = CenterY - Height / 2;
            Margin = FormattableString.Invariant($"{X},{Y},0,0");

            FillColor      = GetNodeFillColor();
            StrokeColor    = GetNodeStrokeColor();
            StrokeDashList = WpfHelper.AbsoluteStrokeDash(Styles, StrokeThickness);
            //FontFamily = GetFontFamily();
            FontColor = GetFontColor();
            FontSize  = GetFontSize();
        }
Esempio n. 7
0
 private string GetNodeFillColor()
 {
     if (Styles.Contains("filled"))
     {
         var color = WpfHelper.IdToText(
             NodeBehind.HasAttribute("color", true)
                 ? NodeBehind.GetAttribute("color", true)
                 : null);
         var fillcolor = WpfHelper.IdToText(
             NodeBehind.HasAttribute("fillcolor", true)
                 ? NodeBehind.GetAttribute("fillcolor", true)
                 : null);
         return(fillcolor ?? color ?? "lightgray");
     }
     return("Transparent");
 }
Esempio n. 8
0
        private void BuildSpanForCapturedStyle(Scope scope)
        {
            string foreground = string.Empty;
            string background = string.Empty;
            bool   italic     = false;
            bool   bold       = false;

            if (Styles.Contains(scope.Name))
            {
                Style style = Styles[scope.Name];

                foreground = style.Foreground;
                background = style.Background;
                italic     = style.Italic;
                bold       = style.Bold;
            }

            WriteElementStart("span", foreground, background, italic, bold);
        }
Esempio n. 9
0
        private string GetSubGraphFillColor()
        {
            var bgColor = WpfHelper.IdToText(
                SubGraphBehind.HasAttribute("bgcolor", true)
                    ? SubGraphBehind.GetAttribute("bgcolor", true)
                    : null);
            var color = WpfHelper.IdToText(
                SubGraphBehind.HasAttribute("color", true)
                    ? SubGraphBehind.GetAttribute("color", true)
                    : null);
            var fillcolor = WpfHelper.IdToText(
                SubGraphBehind.HasAttribute("fillcolor", true)
                    ? SubGraphBehind.GetAttribute("fillcolor", true)
                    : null);

            if (Styles.Contains("filled"))
            {
                return(fillcolor ?? color ?? bgColor ?? "lightgray");
            }
            return(bgColor ?? "Transparent");
        }
        private void StyleRun(Run Run, Scope Scope)
        {
            string foreground = null;
            string background = null;
            bool   italic     = false;
            bool   bold       = false;

            if (Styles.Contains(Scope.Name))
            {
                ColorCode.Styling.Style style = Styles[Scope.Name];

                foreground = style.Foreground;
                background = style.Background;
                italic     = style.Italic;
                bold       = style.Bold;
            }

            if (!string.IsNullOrWhiteSpace(foreground))
            {
                Run.Foreground = foreground.GetSolidColorBrush();
            }

            if (!string.IsNullOrWhiteSpace(background))
            {
                Run.Background = background.GetSolidColorBrush();
            }

            if (italic)
            {
                Run.FontStyle = FontStyles.Italic;
            }

            if (bold)
            {
                Run.FontWeight = FontWeights.Bold;
            }
        }
Esempio n. 11
0
 bool ICollection <KeyValuePair <string, string> > .Contains(KeyValuePair <string, string> item)
 {
     return(HasStyleAttribute ?
            Styles.Contains(new KeyValuePair <ushort, string>(HtmlData.Tokenize(item.Key), item.Value)) :
            false);
 }
Esempio n. 12
0
 bool ICollection <KeyValuePair <string, string> > .Contains(KeyValuePair <string, string> item)
 {
     return(Styles.Contains(new KeyValuePair <ushort, string>(DomData.TokenID(item.Key), item.Value)));
 }
Esempio n. 13
0
        public override void CreatePDF(string input, string output)
        {
            List <BlockElement <IBlockElement> > elements = new List <BlockElement <IBlockElement> >();

            //Initialize writer
            PdfWriter writer = new PdfWriter(output);
            //Initialize document
            PdfDocument pdfDoc = new PdfDocument(writer);
            Document    doc    = new Document(pdfDoc);


            List <string> styles  = new List <string>();
            List <string> formats = new List <string>();
            List <Text>   texts   = new List <Text>();

            if (!File.Exists(input))
            {
                Console.WriteLine("File not found");
                return;
            }

            foreach (var line in File.ReadLines(input, Encoding.Default))
            {
                if (line.First() == '.')
                {
                    var command = line.Remove(0, 1);

                    // A lot of ifs and elses, couldn't find annother approach
                    if (command == "paragraph")
                    {
                        // create a new paragraph with the read text and formatting
                        doc.Add(ParagraphFactory.CreateParagraph(texts, formats));
                        texts.RemoveAll(t => true);
                    }
                    else if (command == "normal" || command == "regular")
                    {
                        styles.RemoveAll(s => true);                                                   // reset the style of text
                    }
                    else if (Styles.Contains(command))
                    {
                        styles.Add(command);
                    }
                    else
                    {
                        formats.Add(command);
                    }
                }

                else
                {
                    var text = new Text(line + " ");
                    text.AddStyle(StyleFactory.CreateStyle(styles));
                    texts.Add(text);
                }
            }


            // final test to assure we didn't miss any text
            // because there must be a .paragraph command at the end of the input file
            if (texts.Count > 0)
            {
                doc.Add(ParagraphFactory.CreateParagraph(texts, formats));
            }

            //Close document
            doc.Close();
        }