Example #1
0
 public override void Draw(Node node, PaintMode printMode, Color color)
 {
     if ((printMode == PaintMode.BACKGROUND))
     {
         base.painter_.FillRectangle(node);
     }
 }
Example #2
0
 public override void getSize(Node containerNode)
 {
     int d = 0;
     float dpi = base.painter_.DpiX();
     float f = base.painter_.FontSize(containerNode, containerNode.style_);
     base.rect.width = AttributeBuilder.SizeByAttr(f, dpi, containerNode, "width", this.width);
     base.rect.height = AttributeBuilder.SizeByAttr(f, dpi, containerNode, "height", this.height);
     d = AttributeBuilder.SizeByAttr(f, dpi, containerNode, "depth", this.depth);
     if (base.rect.height == 0)
     {
         base.rect.height = 2;
     }
     if (base.rect.width == 0)
     {
         base.rect.width = 2;
     }
     if (d == 0)
     {
         base.rect.baseline = base.rect.height / 2;
     }
     else if (d > base.rect.height)
     {
         base.rect.height += d;
         base.rect.baseline = 0;
     }
     else
     {
         base.rect.baseline = base.rect.height - d;
     }
 }
Example #3
0
 public override void Draw(Node node, PaintMode printMode, Color color)
 {
     if (((printMode == PaintMode.FOREGROUND)) && ((node.firstChild == null)))
     {
         base.painter_.OutlineRect(node);
     }
 }
Example #4
0
        public static void Main()
        {
            StreamReader reader = new StreamReader("../../input.txt");
            Console.SetIn(reader);

            int treeSize = int.Parse(Console.ReadLine());

            Node[] nodes = new Node[treeSize];
            for (int i = 0; i < nodes.Length; i++)
            {
                nodes[i] = new Node(i);
            }

            for (int i = 0; i < nodes.Length - 1; i++)
            {
                var input = Console.ReadLine().Split(' ');

                int parentNodeValue = int.Parse(input[0]);
                int childNodeValue = int.Parse(input[1]);

                nodes[parentNodeValue].Childrens.Add(nodes[childNodeValue]);
                nodes[childNodeValue].HasParent = true;
            }

            // C : find all middle nodes
            List<Node> middleNodes = FindMiddleNodes(nodes);
            var middleNodesValues = middleNodes.Select(n => n.Value);
            Console.WriteLine("Middle nodes values: {0}", string.Join(", ", middleNodesValues));
        }
Example #5
0
 public override void UpdateChildPosition(Node childNode)
 {
     if (childNode.childIndex == 0)
     {
         this.table.update(this.fontWidth, this.fontHeight);
     }
 }
Example #6
0
        public static void Main()
        {
            StreamReader reader = new StreamReader("../../input.txt");
            Console.SetIn(reader);

            int treeSize = int.Parse(Console.ReadLine());

            Node[] nodes = new Node[treeSize];
            for (int i = 0; i < nodes.Length; i++)
            {
                nodes[i] = new Node(i);
            }

            for (int i = 0; i < nodes.Length - 1; i++)
            {
                var input = Console.ReadLine().Split(' ');

                int parentNodeValue = int.Parse(input[0]);
                int childNodeValue = int.Parse(input[1]);

                nodes[parentNodeValue].Childrens.Add(nodes[childNodeValue]);
                nodes[childNodeValue].HasParent = true;
            }

            int longestPath = LongestPath(FindRoot(nodes));
            Console.Write("Longest path: {0}", longestPath);
        }
Example #7
0
        public static void Main()
        {
            StreamReader reader = new StreamReader("../../input.txt");
            Console.SetIn(reader);

            int treeSize = int.Parse(Console.ReadLine());

            Node[] nodes = new Node[treeSize];
            for (int i = 0; i < nodes.Length; i++)
            {
                nodes[i] = new Node(i);
            }

            for (int i = 0; i < nodes.Length - 1; i++)
            {
                var input = Console.ReadLine().Split(' ');

                int parentNodeValue = int.Parse(input[0]);
                int childNodeValue = int.Parse(input[1]);

                nodes[parentNodeValue].Childrens.Add(nodes[childNodeValue]);
                nodes[childNodeValue].HasParent = true;
            }

            Node root = FindRoot(nodes);
            ProcessPaths(root, 0);
            Console.WriteLine("Paths with S = {0} --> {1}", S, pathsCounter);
        }
Example #8
0
        public static void Main()
        {
            StreamReader reader = new StreamReader("../../input.txt");
            Console.SetIn(reader);

            int treeSize = int.Parse(Console.ReadLine());

            Node[] nodes = new Node[treeSize];
            for (int i = 0; i < nodes.Length; i++)
            {
                nodes[i] = new Node(i);
            }

            for (int i = 0; i < nodes.Length - 1; i++)
            {
                var input = Console.ReadLine().Split(' ');

                int parentNodeValue = int.Parse(input[0]);
                int childNodeValue = int.Parse(input[1]);

                nodes[parentNodeValue].Childrens.Add(nodes[childNodeValue]);
                nodes[childNodeValue].HasParent = true;
            }

            // A : find root node
            Node root = FindRoot(nodes);
            Console.WriteLine("Root with value: {0}", root.Value);
        }
Example #9
0
 public override void getSize(Node containerNode)
 {
     if (this.target == null)
     {
         base.painter_.MeasureBox(containerNode, containerNode.style_, "X");
     }
 }
Example #10
0
 public override void Draw(Node node, PaintMode printMode, Color color)
 {
     if (((printMode != PaintMode.BACKGROUND)) && ((printMode == PaintMode.FOREGROUND)))
     {
         if ((node.isVisible && (node.literalText != null)) && (node.literalText.Length > 0))
         {
             if (node.parent_ != null)
             {
                 bool notInBrackets = true;
                 try
                 {
                     if ((node.parent_.type_.type == ElementType.Mo) && ((Box_Mo) node.parent_.box).isBracketed)
                     {
                         notInBrackets = false;
                     }
                 }
                 catch
                 {
                 }
                 if (notInBrackets)
                 {
                     base.painter_.DrawString(node, node.parent_.style_, color);
                 }
             }
             else
             {
                 base.painter_.DrawString(node, null, color);
             }
         }
     }
 }
Example #11
0
        public static void Main()
        {
            StreamReader reader = new StreamReader("../../input.txt");
            Console.SetIn(reader);

            int treeSize = int.Parse(Console.ReadLine());

            Node[] nodes = new Node[treeSize];
            for (int i = 0; i < nodes.Length; i++)
            {
                nodes[i] = new Node(i);
            }

            for (int i = 0; i < nodes.Length - 1; i++)
            {
                var input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                int parentNodeValue = int.Parse(input[0]);
                int childNodeValue = int.Parse(input[1]);

                nodes[parentNodeValue].Childrens.Add(nodes[childNodeValue]);
                nodes[childNodeValue].HasParent = true;
            }

            List<Node> leafs = FindLeafNodes(nodes);
            var leafValues = leafs.Select(n => n.Value);
            Console.WriteLine("Leaf nodes values: {0}", string.Join(", ", leafValues));
        }
Example #12
0
 public override void getSize(Node containerNode)
 {
     BoxRect boxRect;
     this.attrs = AttributeBuilder.QuoteAttributes(containerNode);
     if (containerNode.numChildren <= 0)
     {
         if ((containerNode.literalText != null) && (containerNode.literalText.Length > 0))
         {
             base.painter_.MeasureBox(containerNode, containerNode.style_);
         }
         else
         {
             base.painter_.MeasureBox(containerNode, containerNode.style_, "X");
         }
     }
     if (this.attrs != null)
     {
         if (this.attrs.lquote != "NONE")
         {
             this.leftQuote = this.attrs.lquote;
         }
         else
         {
             this.leftQuote = "";
         }
         if (this.attrs.rquote != "NONE")
         {
             this.rightQuote = this.attrs.rquote;
         }
         else
         {
             this.rightQuote = "";
         }
     }
     else
     {
         this.leftQuote = "\"";
         this.rightQuote = "\"";
     }
     if (this.leftQuote.Length > 0)
     {
         boxRect = base.painter_.MeasureTextRect(containerNode, this.leftQuote, containerNode.scriptLevel_, containerNode.style_);
         this.leftQuoteWidth = boxRect.width;
     }
     else
     {
         this.leftQuoteWidth = 0;
     }
     if (this.leftQuote.Length > 0)
     {
         boxRect = base.painter_.MeasureTextRect(containerNode, this.rightQuote, containerNode.scriptLevel_, containerNode.style_);
         this.rightQuoteWidth = boxRect.width;
     }
     else
     {
         this.rightQuoteWidth = 0;
     }
     base.rect.width += this.leftQuoteWidth + this.rightQuoteWidth;
 }
Example #13
0
 private Node create(Node node, Node selectedNode, Node lastSelectedNode)
 {
     Node n = new Node();
     
     n.tagDeleted = node.tagDeleted;
     n.tokenType = node.tokenType;
     n.xmlTagName = node.xmlTagName;
     n.namespaceURI = node.namespaceURI;
     n.isVisible = node.isVisible;
     n.isGlyph = node.isGlyph;
     n.skip = node.skip;
     
     n.literalText = node.literalText;
     n.literalCaret = node.literalCaret;
     n.literalStart = node.literalStart;
     n.yOffset = node.yOffset;
     n.displayStyle = node.displayStyle;
     
     n.glyph = node.glyph;
     
     n.scriptLevel_ = node.scriptLevel_;
     
     n.type_ = node.type_;
     if (node.attrs != null)
     {
         n.attrs = new AttributeList();
         node.attrs.CopyTo(n.attrs);
     }
     n.FontStyle = node.FontStyle;
     if (node.style_ != null)
     {
         n.style_ = new StyleAttributes();
         node.style_.CopyTo(n.style_);
     }
     if (node == selectedNode)
     {
         this.selected_ = n;
     }
     if (node == lastSelectedNode)
     {
         this.lastSel_ = n;
     }
     if (node.HasChildren())
     {
         NodesList list = node.GetChildrenNodes();
         int count = list.Count;
         for (int i = 0; i < count; i++)
         {
             Node c = list.Get(i);
             Node child = this.create(c, selectedNode, lastSelectedNode);
             if (child != null)
             {
                 n.AdoptChild(child);
             }
         }
     }
     return n;
 }
Example #14
0
 public override void getSize(Node containerNode)
 {
     if (containerNode.firstChild == null)
     {
         containerNode.box.Width = 15;
         containerNode.box.Height = 15;
         containerNode.box.Baseline = 10;
     }
 }
Example #15
0
 public NodesInfo(Node rootNode, Node selectedNode, int selectedNode_Caret, Node lastSelectedNode)
 {
     this.selected_ = null;
     this.root_ = null;
     this.lastSel_ = null;
     this.mark_ = 0;
     this.root_ = this.create(rootNode, selectedNode, lastSelectedNode);
     this.root_.UpdateLevel();
     this.mark_ = selectedNode_Caret;
 }
Example #16
0
 public override void getSize(Node tableNode)
 {
     this.table = new MTable(tableNode);
     float height = base.painter_.FontSize(tableNode, tableNode.style_);
     float dpi = base.painter_.DpiX();
     this.table.CalcSize(dpi, height);
     base.rect.width = this.table.totalWidth;
     base.rect.height = this.table.totalVertFrameSpacing;
     base.rect.baseline = this.table.tableAlign + ((this.height - (2 * (this.height - this.baseline))) / 2);
 }
Example #17
0
 public override void Draw(Node node, PaintMode printMode, Color color)
 {
     if (printMode == PaintMode.BACKGROUND)
     {
         DrawBackground(node);
     }
     else if (printMode == PaintMode.FOREGROUND)
     {
         DrawForeground(color, node);
     }
 }
Example #18
0
 public override void Draw(Node node, PaintMode printMode, Color color)
 {
     if ((printMode == PaintMode.BACKGROUND))
     {
         base.painter_.FillRectangle(node);
     }
     else if (((printMode == PaintMode.FOREGROUND)) && ((node.literalText != null) && (node.literalText.Length > 0)))
     {
         base.painter_.DrawString(node, node.style_, color);
     }
 }
Example #19
0
 public override void UpdateChildPosition(Node childNode)
 {
     if (childNode.prevSibling != null)
     {
         childNode.box.X = childNode.prevSibling.box.X + childNode.prevSibling.box.Width;
     }
     else
     {
         childNode.box.X = (base.rect.x + this.ftlineThick_);
     }
     childNode.box.Y = (base.rect.y + base.rect.baseline) - childNode.box.Baseline;
 }
Example #20
0
 public override void UpdateChildPosition(Node childNode)
 {
     if (childNode.prevSibling != null)
     {
         childNode.box.X = (childNode.prevSibling.box.X + childNode.prevSibling.box.Width) + this.SeparatorWidth(childNode);
     }
     else
     {
         childNode.box.X = base.rect.x + this.openWidth;
     }
     childNode.box.Y = (base.rect.y + base.rect.baseline) - childNode.box.Baseline;
 }
Example #21
0
 public override void setChildSize(Node childNode)
 {
     base.rect.width += childNode.box.Width;
     if (childNode.box.Baseline > base.rect.baseline)
     {
         base.rect.baseline = childNode.box.Baseline;
     }
     if ((childNode.box.Height - childNode.box.Baseline) > (base.rect.height - base.rect.baseline))
     {
         base.rect.height = base.rect.baseline + (childNode.box.Height - childNode.box.Baseline);
     }
 }
Example #22
0
 public MCell(MRow row, Node node, int index)
 {
     this.rowAlign = RowAlign.UNKNOWN;
     this.columnAlign = HAlign.UNKNOWN;
     this.columnSpan = 1;
     this.rowSpan = 1;
     this.colSpan = 0;
     this.tableAttrs = AttributeBuilder.FromNode(node);
     this.row_ = row;
     this.node = node;
     this.colSpan = index;
 }
Example #23
0
 public override void UpdateChildPosition(Node childNode)
 {
     if (childNode.childIndex == 0)
     {
         childNode.box.Y = (base.rect.y + base.rect.height) - childNode.box.Height;
     }
     else
     {
         childNode.box.Y = base.rect.y;
     }
     childNode.box.X = base.rect.x + ((base.rect.width - childNode.box.Width) / 2);
 }
Example #24
0
 public override void UpdateChildPosition(Node childNode)
 {
     if (childNode.childIndex == 0)
     {
         childNode.box.X = ((base.rect.x + this.lspace_) + this.w_) + this.thick_;
         childNode.box.Y = (base.rect.y + base.rect.baseline) - childNode.box.Baseline;
     }
     else if (childNode.childIndex == 1)
     {
         childNode.box.X = base.rect.x + this.lspace_;
         childNode.box.Y = (((base.rect.y + base.rect.height) - (this.totalThick_ / 2)) - childNode.box.Height) - (2 * this.lineThickness);
     }
 }
Example #25
0
        private static void ProcessPaths(Node currentNode, int currentSum)
        {
            currentSum += currentNode.Value;
            if(currentSum == S)
            {
                pathsCounter++;
            }

            for (int i = 0; i < currentNode.Childrens.Count; i++)
            {
                ProcessPaths(currentNode.Childrens[i], currentSum);
            }
        }
Example #26
0
        private static Node FindRoot(Node[] nodes)
        {
            Node root = null;
            foreach (var node in nodes)
            {
                if (!node.HasParent)
                {
                    root = node;
                }
            }

            return root;
        }
Example #27
0
 public override void UpdateChildPosition(Node childNode)
 {
     if (childNode == this.target)
     {
         childNode.box.X = base.rect.x;
         childNode.box.Y = (base.rect.y + base.rect.baseline) - childNode.box.Baseline;
         childNode.isVisible = true;
     }
     else
     {
         childNode.isVisible = false;
     }
 }
Example #28
0
 public override void getSize(Node containerNode)
 {
     base.painter_.roundOpFontSize(containerNode, containerNode.style_);
     if (this.attrs == null)
     {
         this.attrs = new FencedAttributes();
     }
     if (containerNode.numChildren == 0)
     {
         base.painter_.MeasureBox(containerNode, containerNode.style_, "X");
     }
     else if (this.isFenced)
     {
         if (this.baseline == 0)
         {
             this.baseline = base.painter_.MeasureBaseline(containerNode, containerNode.style_, "X");
         }
         base.rect.height = 2 * Math.Max((int) (base.rect.accent + base.painter_.CenterHeight(containerNode)), (int) (base.rect.baseline - base.painter_.CenterHeight(containerNode)));
         base.rect.baseline = (2 * Math.Max((int) (base.rect.accent + base.painter_.CenterHeight(containerNode)), (int) (base.rect.baseline - base.painter_.CenterHeight(containerNode))) / 2) + base.painter_.CenterHeight(containerNode);
     }
     if (this.attrs != null)
     {
         if (this.attrs.open.Length > 0)
         {
             if (this.attrs.open != "NONE")
             {
                 this.openWidth = base.painter_.OpWidth(true, containerNode, this.attrs.open);
             }
         }
         else
         {
             this.openWidth = 0;
         }
         if (this.attrs.close.Length > 0)
         {
             if (this.attrs.close == "NONE")
             {
                 this.closeWidth = 0;
             }
             else
             {
                 this.closeWidth = base.painter_.OpWidth(true, containerNode, this.attrs.close);
             }
         }
         else
         {
             this.closeWidth = 0;
         }
     }
     base.rect.width += this.openWidth + this.closeWidth;
 }
Example #29
0
 public MRow(MTable matrix, Node node, int index)
 {
     this.isLabeled = false;
     this.index = 0;
     this.align = RowAlign.UNKNOWN;
     this.spacing = "0.5ex";
     this.lines = TableLineStyle.NONE;
     this.index = index;
     this.attrs = AttributeBuilder.MRowAttributes(node);
     this.colAligns = new HAlign[] { HAlign.UNKNOWN };
     this.matrix = matrix;
     this.node = node;
     this.cells = new ArrayList();
 }
Example #30
0
        private static List<Node> FindLeafNodes(Node[] nodes)
        {
            List<Node> leafs = new List<Node>();

            foreach (var node in nodes)
            {
                if (node.Childrens.Count == 0)
                {
                    leafs.Add(node);
                }
            }

            return leafs;
        }