示例#1
0
        public void visit(TableData element)
        {
            // Opening tag.
            mStringBuilder.Append("<td");

            // Add colour if required.
            Color original = this.mCurrentBackground;
            if (element.BackgroundColour.Equals (this.mCurrentBackground) == false) {
                mStringBuilder.AppendFormat(" bgcolor={0}", ColorTranslator.ToHtml(element.BackgroundColour));

                this.mCurrentBackground = element.BackgroundColour;
            }

            // If no nested tag add width and height.
            if (element.ChildElement == null) {
                mStringBuilder.AppendFormat(" width={0} height={1}", element.Width, element.Height);
            }

            if (element.ColumnSpan > 1) {
                mStringBuilder.AppendFormat (" colspan={0}", element.ColumnSpan);
            }

            mStringBuilder.Append (">");

            // If this is a nested tag, recurse.
            if (element.ChildElement != null) {
                element.ChildElement.accept(this);
            }

            // Closing tag.
            mStringBuilder.Append ( "</td>");

            // Reset background colour.
            this.mCurrentBackground = original;
        }
示例#2
0
        public void generateTable(Image img, Table tbl)
        {
            Tree tree = BuildQuadtree (img);

            // Create initial row and cell.
            TableRow tbr = new TableRow();
            TableData tbd = new TableData();
            tbr.Cells.Add(tbd);
            tbl.Rows.Add(tbr);

            // Generate into cell.
            recursivelyGenerateTable(tree.RootNode, tbd);
        }
示例#3
0
        private void recursivelyGenerateTable(Node current, TableData tbd)
        {
            if (current.IsLeaf == false) {

                // If not a leaf, introduce a nested table.
                Table tbl = new Table();
                tbl.BackgroundColour = tbd.BackgroundColour;
                tbd.ChildElement = tbl;

                // Add children to this nested table in NW, NE, SW, SE order.
                TableRow tbr = null;
                for (int i = 0; i < 4; ++i) {

                    if (i % 2 == 0) {
                        tbr = new TableRow();
                        tbl.Rows.Add(tbr);
                    }

                    TableData tbdd = new TableData();
                    tbr.Cells.Add(tbdd);

                    recursivelyGenerateTable(current.ChildNodes[i], tbdd);

                }

            }
            else {

                // If a leaf, simply set the colour on the current element.
                tbd.BackgroundColour = current.Colour;
                tbd.Height = current.Height;
                tbd.Width = current.Width;
                tbd.ColumnSpan = 1;
            }
        }
示例#4
0
        public void generateTable(Image img, Table tbl)
        {
            // Downsample image.
            int newHeight = (img.Size.Height / this.mSize) + 1;
            int newWidth = (img.Size.Width / this.mSize) + 1;

            Bitmap newImg = new Bitmap(newWidth, newHeight);

            using (Graphics g = Graphics.FromImage (newImg))
            {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

                g.DrawImage(img, new Rectangle(0, 0, newWidth, newHeight));

            }

            // Now iterate over down-sampled image to generate mosaic.
            for (int y = 0; y < newHeight; ++y) {

                TableRow tbr = new TableRow();
                tbl.Rows.Add (tbr);

                for(int x = 0; x < newWidth; ++x) {
                    TableData tbd = new TableData();

                    tbd.BackgroundColour = newImg.GetPixel (x, y);
                    tbd.Height = this.Size;
                    tbd.Width = this.Size;
                    tbd.ChildElement = null;

                    tbr.Cells.Add(tbd);
                }
            }
        }