Beispiel #1
0
        public static string GetStyleSheet(string path)
        {
            string       value;
            object       obj          = CssValue.DetectSource(path);
            FileInfo     fileInfo     = obj as FileInfo;
            PropertyInfo propertyInfo = obj as PropertyInfo;
            MethodInfo   methodInfo   = obj as MethodInfo;

            try
            {
                if (fileInfo != null)
                {
                    if (fileInfo.Exists)
                    {
                        StreamReader streamReader = new StreamReader(fileInfo.FullName);
                        string       end          = streamReader.ReadToEnd();
                        streamReader.Dispose();
                        value = end;
                    }
                    else
                    {
                        value = null;
                    }
                }
                else if (propertyInfo != null)
                {
                    if (propertyInfo.PropertyType.Equals(typeof(string)))
                    {
                        value = propertyInfo.GetValue(null, null) as string;
                    }
                    else
                    {
                        value = null;
                    }
                }
                else if (methodInfo == null)
                {
                    value = string.Empty;
                }
                else if (methodInfo.ReturnType.Equals(typeof(string)))
                {
                    value = methodInfo.Invoke(null, null) as string;
                }
                else
                {
                    value = null;
                }
            }
            catch
            {
                value = string.Empty;
            }
            return(value);
        }
 protected override void OnMouseClick(MouseEventArgs e)
 {
     base.OnMouseClick(e);
     foreach (CssBox key in this.htmlContainer.LinkRegions.Keys)
     {
         if (!Rectangle.Round(this.htmlContainer.LinkRegions[key]).Contains(e.X, e.Y))
         {
             continue;
         }
         CssValue.GoLink(key.GetAttribute("href", string.Empty));
         return;
     }
 }
Beispiel #3
0
        public static Image GetImage(string path)
        {
            Image        value;
            object       obj          = CssValue.DetectSource(path);
            FileInfo     fileInfo     = obj as FileInfo;
            PropertyInfo propertyInfo = obj as PropertyInfo;
            MethodInfo   methodInfo   = obj as MethodInfo;

            try
            {
                if (fileInfo != null)
                {
                    if (fileInfo.Exists)
                    {
                        value = Image.FromFile(fileInfo.FullName);
                    }
                    else
                    {
                        value = null;
                    }
                }
                else if (propertyInfo != null)
                {
                    if (propertyInfo.PropertyType.IsSubclassOf(typeof(Image)) || propertyInfo.PropertyType.Equals(typeof(Image)))
                    {
                        value = propertyInfo.GetValue(null, null) as Image;
                    }
                    else
                    {
                        value = null;
                    }
                }
                else if (methodInfo == null)
                {
                    value = null;
                }
                else if (methodInfo.ReturnType.IsSubclassOf(typeof(Image)))
                {
                    value = methodInfo.Invoke(null, null) as Image;
                }
                else
                {
                    value = null;
                }
            }
            catch
            {
                value = new Bitmap(50, 50);
            }
            return(value);
        }
        protected override void OnMouseClick(MouseEventArgs e)
        {
            base.OnMouseClick(e);

            foreach (CssBox box in htmlContainer.LinkRegions.Keys)
            {
                RectangleF rect = htmlContainer.LinkRegions[box];
                if (Rectangle.Round(rect).Contains(e.X, e.Y))
                {
                    CssValue.GoLink(box.GetAttribute("href", string.Empty));
                    return;
                }
            }
        }
        private float GetAvailableWidth()
        {
            CssLength cssLength = new CssLength(this.TableBox.Width);

            if (cssLength.Number <= 0f)
            {
                return(this.TableBox.ParentBox.AvailableWidth);
            }
            this._widthSpecified = true;
            if (!cssLength.IsPercentage)
            {
                return(cssLength.Number);
            }
            return(CssValue.ParseNumber(cssLength.Length, this.TableBox.ParentBox.AvailableWidth));
        }
Beispiel #6
0
        /// <summary>
        ///     Gets the available width for the whole table.
        ///     It also sets the value of <see cref="WidthSpecified" />
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        ///     The table's width can be larger than the result of this method, because of the minimum
        ///     size that individual boxes.
        /// </remarks>
        private float GetAvailableWidth()
        {
            var tblen = new CssLength(TableBox.Width);

            if (tblen.Number > 0)
            {
                WidthSpecified = true;

                if (tblen.IsPercentage)
                {
                    return(CssValue.ParseNumber(tblen.Length, TableBox.ParentBox.AvailableWidth));
                }
                return(tblen.Number);
            }

            return(TableBox.ParentBox.AvailableWidth);
        }
        private void CascadeStyles(CssBox startBox)
        {
            bool flag = false;

            foreach (CssBox box in startBox.Boxes)
            {
                box.InheritStyle();
                if (box.HtmlTag != null)
                {
                    if (this.MediaBlocks["all"].ContainsKey(box.HtmlTag.TagName))
                    {
                        this.MediaBlocks["all"][box.HtmlTag.TagName].AssignTo(box);
                    }
                    if (box.HtmlTag.HasAttribute("class") && this.MediaBlocks["all"].ContainsKey(string.Concat(".", box.HtmlTag.Attributes["class"])))
                    {
                        this.MediaBlocks["all"][string.Concat(".", box.HtmlTag.Attributes["class"])].AssignTo(box);
                    }
                    box.HtmlTag.TranslateAttributes(box);
                    if (box.HtmlTag.HasAttribute("style"))
                    {
                        CssBlock cssBlock = new CssBlock(box.HtmlTag.Attributes["style"]);
                        cssBlock.AssignTo(box);
                    }
                    if (box.HtmlTag.TagName.Equals("style", StringComparison.CurrentCultureIgnoreCase) && box.Boxes.Count == 1)
                    {
                        this.FeedStyleSheet(box.Boxes[0].Text);
                    }
                    if (box.HtmlTag.TagName.Equals("link", StringComparison.CurrentCultureIgnoreCase) && box.GetAttribute("rel", string.Empty).Equals("stylesheet", StringComparison.CurrentCultureIgnoreCase))
                    {
                        this.FeedStyleSheet(CssValue.GetStyleSheet(box.GetAttribute("href", string.Empty)));
                    }
                }
                this.CascadeStyles(box);
            }
            if (flag)
            {
                foreach (CssBox cssBox in startBox.Boxes)
                {
                    cssBox.Display = "block";
                }
            }
        }
Beispiel #8
0
        public static float WhiteSpace(Graphics g, CssBox b)
        {
            string       str          = " .";
            float        width        = 0f;
            float        single       = 5f;
            StringFormat stringFormat = new StringFormat();

            CharacterRange[] characterRange = new CharacterRange[] { new CharacterRange(0, 1) };
            stringFormat.SetMeasurableCharacterRanges(characterRange);
            Region[] regionArray = g.MeasureCharacterRanges(str, b.ActualFont, new RectangleF(0f, 0f, float.MaxValue, float.MaxValue), stringFormat);
            if (regionArray == null || (int)regionArray.Length == 0)
            {
                return(single);
            }
            width = regionArray[0].GetBounds(g).Width;
            if (!string.IsNullOrEmpty(b.WordSpacing) && !(b.WordSpacing == "normal"))
            {
                width = width + CssValue.ParseLength(b.WordSpacing, 0f, b);
            }
            return(width);
        }
Beispiel #9
0
        /// <summary>
        /// Gets the white space width of the specified box
        /// </summary>
        /// <param name="g"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static float WhiteSpace(Graphics g, CssBox b)
        {
            string space   = " .";
            float  w       = 0f;
            float  onError = 5f;

            StringFormat sf = new StringFormat();

            sf.SetMeasurableCharacterRanges(new CharacterRange[] { new CharacterRange(0, 1) });
            Region[] regs = g.MeasureCharacterRanges(space, b.ActualFont, new RectangleF(0, 0, float.MaxValue, float.MaxValue), sf);

            if (regs == null || regs.Length == 0)
            {
                return(onError);
            }

            w = regs[0].GetBounds(g).Width;

            if (!(string.IsNullOrEmpty(b.WordSpacing) || b.WordSpacing == CssConstants.Normal))
            {
                w += CssValue.ParseLength(b.WordSpacing, 0, b);
            }
            return(w);
        }
Beispiel #10
0
 public static string[] SplitValues(string value)
 {
     return(CssValue.SplitValues(value, ' '));
 }
Beispiel #11
0
        public CssLength(string length)
        {
            this._length       = length;
            this._number       = 0f;
            this._unit         = CssLength.CssUnit.None;
            this._isPercentage = false;
            if (string.IsNullOrEmpty(length) || length == "0")
            {
                return;
            }
            if (length.EndsWith("%"))
            {
                this._number       = CssValue.ParseNumber(length, 1f);
                this._isPercentage = true;
                return;
            }
            if (length.Length < 3)
            {
                float.TryParse(length, out this._number);
                this._hasError = true;
                return;
            }
            string str  = length.Substring(length.Length - 2, 2);
            string str1 = length.Substring(0, length.Length - 2);
            string str2 = str;
            string str3 = str2;

            if (str2 != null)
            {
                switch (str3)
                {
                case "em":
                {
                    this._unit       = CssLength.CssUnit.Ems;
                    this._isRelative = true;
                    break;
                }

                case "ex":
                {
                    this._unit       = CssLength.CssUnit.Ex;
                    this._isRelative = true;
                    break;
                }

                case "px":
                {
                    this._unit       = CssLength.CssUnit.Pixels;
                    this._isRelative = true;
                    break;
                }

                case "mm":
                {
                    this._unit = CssLength.CssUnit.Milimeters;
                    break;
                }

                case "cm":
                {
                    this._unit = CssLength.CssUnit.Centimeters;
                    break;
                }

                case "in":
                {
                    this._unit = CssLength.CssUnit.Inches;
                    break;
                }

                case "pt":
                {
                    this._unit = CssLength.CssUnit.Points;
                    break;
                }

                case "pc":
                {
                    this._unit = CssLength.CssUnit.Picas;
                    break;
                }

                default:
                {
                    this._hasError = true;
                    return;
                }
                }
                if (!float.TryParse(str1, NumberStyles.Number, (IFormatProvider)NumberFormatInfo.InvariantInfo, out this._number))
                {
                    this._hasError = true;
                }
                return;
            }
            this._hasError = true;
        }
Beispiel #12
0
        /// <summary>
        /// Creates a new CssLength from a length specified on a CSS style sheet or fragment
        /// </summary>
        /// <param name="length">Length as specified in the Style Sheet or style fragment</param>
        public CssLength(string length)
        {
            _length       = length;
            _number       = 0f;
            _unit         = CssUnit.None;
            _isPercentage = false;

            //Return zero if no length specified, zero specified
            if (string.IsNullOrEmpty(length) || length == "0")
            {
                return;
            }

            //If percentage, use ParseNumber
            if (length.EndsWith("%"))
            {
                _number       = CssValue.ParseNumber(length, 1);
                _isPercentage = true;
                return;
            }

            //If no units, has error
            if (length.Length < 3)
            {
                float.TryParse(length, out _number);
                _hasError = true;
                return;
            }

            //Get units of the length
            string u = length.Substring(length.Length - 2, 2);

            //Number of the length
            string number = length.Substring(0, length.Length - 2);

            //TODO: Units behave different in paper and in screen!
            switch (u)
            {
            case CssConstants.Em:
                _unit       = CssUnit.Ems;
                _isRelative = true;
                break;

            case CssConstants.Ex:
                _unit       = CssUnit.Ex;
                _isRelative = true;
                break;

            case CssConstants.Px:
                _unit       = CssUnit.Pixels;
                _isRelative = true;
                break;

            case CssConstants.Mm:
                _unit = CssUnit.Milimeters;
                break;

            case CssConstants.Cm:
                _unit = CssUnit.Centimeters;
                break;

            case CssConstants.In:
                _unit = CssUnit.Inches;
                break;

            case CssConstants.Pt:
                _unit = CssUnit.Points;
                break;

            case CssConstants.Pc:
                _unit = CssUnit.Picas;
                break;

            default:
                _hasError = true;
                return;
            }

            if (!float.TryParse(number, System.Globalization.NumberStyles.Number, NumberFormatInfo.InvariantInfo, out _number))
            {
                _hasError = true;
            }
        }
Beispiel #13
0
        /// <summary>
        /// Analyzes the Table and assigns values to this CssTable object.
        /// To be called from the constructor
        /// </summary>
        private void Analyze(Graphics g)
        {
            float availSpace     = GetAvailableWidth();
            float availCellSpace = float.NaN; //Will be set later

            #region Assign box kinds
            foreach (CssBox b in TableBox.Boxes)
            {
                b.RemoveAnonymousSpaces();
                switch (b.Display)
                {
                case CssConstants.TableCaption:
                    _caption = b;
                    break;

                case CssConstants.TableColumn:
                    for (int i = 0; i < GetSpan(b); i++)
                    {
                        Columns.Add(CreateColumn(b));
                    }
                    break;

                case CssConstants.TableColumnGroup:
                    if (b.Boxes.Count == 0)
                    {
                        int gspan = GetSpan(b);
                        for (int i = 0; i < gspan; i++)
                        {
                            Columns.Add(CreateColumn(b));
                        }
                    }
                    else
                    {
                        foreach (CssBox bb in b.Boxes)
                        {
                            int bbspan = GetSpan(bb);
                            for (int i = 0; i < bbspan; i++)
                            {
                                Columns.Add(CreateColumn(bb));
                            }
                        }
                    }
                    break;

                case CssConstants.TableFooterGroup:
                    if (FooterBox != null)
                    {
                        BodyRows.Add(b);
                    }
                    else
                    {
                        _footerBox = b;
                    }
                    break;

                case CssConstants.TableHeaderGroup:
                    if (HeaderBox != null)
                    {
                        BodyRows.Add(b);
                    }
                    else
                    {
                        _headerBox = b;
                    }
                    break;

                case CssConstants.TableRow:
                    BodyRows.Add(b);
                    break;

                case CssConstants.TableRowGroup:
                    foreach (CssBox bb in b.Boxes)
                    {
                        if (b.Display == CssConstants.TableRow)
                        {
                            BodyRows.Add(b);
                        }
                    }
                    break;

                default:
                    break;
                }
            }
            #endregion

            #region Gather AllRows

            if (HeaderBox != null)
            {
                _allRows.AddRange(HeaderBox.Boxes);
            }
            _allRows.AddRange(BodyRows);
            if (FooterBox != null)
            {
                _allRows.AddRange(FooterBox.Boxes);
            }

            #endregion

            #region Insert EmptyBoxes for vertical cell spanning

            if (!TableBox.TableFixed)
            {
                int           currow = 0;
                int           curcol = 0;
                List <CssBox> rows   = BodyRows;

                foreach (CssBox row in rows)
                {
                    row.RemoveAnonymousSpaces();
                    curcol = 0;
                    for (int k = 0; k < row.Boxes.Count; k++)
                    {
                        CssBox cell    = row.Boxes[k];
                        int    rowspan = GetRowSpan(cell);
                        int    realcol = GetCellRealColumnIndex(row, cell); //Real column of the cell

                        for (int i = currow + 1; i < currow + rowspan; i++)
                        {
                            int colcount = 0;
                            for (int j = 0; j <= rows[i].Boxes.Count; j++)
                            {
                                if (colcount == realcol)
                                {
                                    rows[i].Boxes.Insert(colcount, new SpacingBox(TableBox, ref cell, currow));
                                    break;
                                }
                                colcount++;
                                realcol -= GetColSpan(rows[i].Boxes[j]) - 1;
                            }
                        } // End for (int i = currow + 1; i < currow + rowspan; i++)
                        curcol++;
                    }     /// End foreach (Box cell in row.Boxes)
                    currow++;
                }         /// End foreach (Box row in rows)

                TableBox.TableFixed = true;
            } /// End if (!TableBox.TableFixed)

            #endregion

            #region Determine Row and Column Count, and ColumnWidths

            //Rows
            _rowCount = BodyRows.Count +
                        (HeaderBox != null ? HeaderBox.Boxes.Count : 0) +
                        (FooterBox != null ? FooterBox.Boxes.Count : 0);

            //Columns
            if (Columns.Count > 0)
            {
                _columnCount = Columns.Count;
            }
            else
            {
                foreach (CssBox b in AllRows) //Check trhough rows
                {
                    _columnCount = Math.Max(_columnCount, b.Boxes.Count);
                }
            }

            //Initialize column widths array
            _columnWidths = new float[_columnCount];

            //Fill them with NaNs
            for (int i = 0; i < _columnWidths.Length; i++)
            {
                _columnWidths[i] = float.NaN;
            }

            availCellSpace = GetAvailableCellWidth();

            if (Columns.Count > 0)
            {
                #region Fill ColumnWidths array by scanning column widths

                for (int i = 0; i < Columns.Count; i++)
                {
                    CssLength len = new CssLength(Columns[i].Width); //Get specified width

                    if (len.Number > 0)                              //If some width specified
                    {
                        if (len.IsPercentage)                        //Get width as a percentage
                        {
                            ColumnWidths[i] = CssValue.ParseNumber(Columns[i].Width, availCellSpace);
                        }
                        else if (len.Unit == CssLength.CssUnit.Pixels || len.Unit == CssLength.CssUnit.None)
                        {
                            ColumnWidths[i] = len.Number; //Get width as an absolute-pixel value
                        }
                    }
                }

                #endregion
            }
            else
            {
                #region Fill ColumnWidths array by scanning width in table-cell definitions
                foreach (CssBox row in AllRows)
                {
                    //Check for column width in table-cell definitions
                    for (int i = 0; i < _columnCount; i++)
                    {
                        if (float.IsNaN(ColumnWidths[i]) &&                    //Check if no width specified for column
                            i < row.Boxes.Count &&                             //And there's a box to check
                            row.Boxes[i].Display == CssConstants.TableCell)    //And the box is a table-cell
                        {
                            CssLength len = new CssLength(row.Boxes[i].Width); //Get specified width

                            if (len.Number > 0)                                //If some width specified
                            {
                                int   colspan = GetColSpan(row.Boxes[i]);
                                float flen    = 0f;
                                if (len.IsPercentage)//Get width as a percentage
                                {
                                    flen = CssValue.ParseNumber(row.Boxes[i].Width, availCellSpace);
                                }
                                else if (len.Unit == CssLength.CssUnit.Pixels || len.Unit == CssLength.CssUnit.None)
                                {
                                    flen = len.Number; //Get width as an absolute-pixel value
                                }
                                flen /= Convert.ToSingle(colspan);

                                for (int j = i; j < i + colspan; j++)
                                {
                                    ColumnWidths[j] = flen;
                                }
                            }
                        }
                    }
                }
                #endregion
            }

            #endregion

            #region Determine missing Column widths

            if (WidthSpecified) //If a width was specified,
            {
                //Assign NaNs equally with space left after gathering not-NaNs
                int   numberOfNans = 0;
                float occupedSpace = 0f;

                //Calculate number of NaNs and occuped space
                for (int i = 0; i < ColumnWidths.Length; i++)
                {
                    if (float.IsNaN(ColumnWidths[i]))
                    {
                        numberOfNans++;
                    }
                    else
                    {
                        occupedSpace += ColumnWidths[i];
                    }
                }

                //Determine width that will be assigned to un asigned widths
                float nanWidth = (availCellSpace - occupedSpace) / Convert.ToSingle(numberOfNans);

                for (int i = 0; i < ColumnWidths.Length; i++)
                {
                    if (float.IsNaN(ColumnWidths[i]))
                    {
                        ColumnWidths[i] = nanWidth;
                    }
                }
            }
            else
            {
                //Assign NaNs using full width
                float[] _maxFullWidths = new float[ColumnWidths.Length];

                //Get the maximum full length of NaN boxes
                foreach (CssBox row in AllRows)
                {
                    for (int i = 0; i < row.Boxes.Count; i++)
                    {
                        int col = GetCellRealColumnIndex(row, row.Boxes[i]);

                        if (float.IsNaN(ColumnWidths[col]) &&
                            i < row.Boxes.Count &&
                            GetColSpan(row.Boxes[i]) == 1)
                        {
                            _maxFullWidths[col] = Math.Max(_maxFullWidths[col], row.Boxes[i].GetFullWidth(g));
                        }
                    }
                }

                for (int i = 0; i < ColumnWidths.Length; i++)
                {
                    if (float.IsNaN(ColumnWidths[i]))
                    {
                        ColumnWidths[i] = _maxFullWidths[i];
                    }
                }
            }

            #endregion

            #region Reduce widths if necessary

            int   curCol       = 0;
            float reduceAmount = 1f;

            //While table width is larger than it should, and width is reductable
            while (GetWidthSum() > GetAvailableWidth() && CanReduceWidth())
            {
                while (!CanReduceWidth(curCol))
                {
                    curCol++;
                }

                ColumnWidths[curCol] -= reduceAmount;

                curCol++;

                if (curCol >= ColumnWidths.Length)
                {
                    curCol = 0;
                }
            }

            #endregion

            #region Check for minimum sizes (increment widths if necessary)

            foreach (CssBox row in AllRows)
            {
                foreach (CssBox cell in row.Boxes)
                {
                    int colspan   = GetColSpan(cell);
                    int col       = GetCellRealColumnIndex(row, cell);
                    int affectcol = col + colspan - 1;

                    if (ColumnWidths[col] < ColumnMinWidths[col])
                    {
                        float diff = ColumnMinWidths[col] - ColumnWidths[col];
                        ColumnWidths[affectcol] = ColumnMinWidths[affectcol];

                        if (col < ColumnWidths.Length - 1)
                        {
                            ColumnWidths[col + 1] -= diff;
                        }
                    }
                }
            }

            #endregion

            #region Set table padding

            TableBox.Padding = "0"; //Ensure there's no padding

            #endregion

            #region Layout cells

            //Actually layout cells!
            float startx     = TableBox.ClientLeft + HorizontalSpacing;
            float starty     = TableBox.ClientTop + VerticalSpacing;
            float curx       = startx;
            float cury       = starty;
            float maxRight   = startx;
            float maxBottom  = 0f;
            int   currentrow = 0;

            foreach (CssBox row in AllRows)
            {
                if (row is CssAnonymousSpaceBlockBox || row is CssAnonymousSpaceBox)
                {
                    continue;
                }

                curx   = startx;
                curCol = 0;

                foreach (CssBox cell in row.Boxes)
                {
                    if (curCol >= ColumnWidths.Length)
                    {
                        break;
                    }

                    int   rowspan = GetRowSpan(cell);
                    float width   = GetCellWidth(GetCellRealColumnIndex(row, cell), cell);

                    cell.Location = new PointF(curx, cury);
                    cell.Size     = new SizeF(width, 0f);
                    cell.MeasureBounds(g); //That will automatically set the bottom of the cell

                    //Alter max bottom only if row is cell's row + cell's rowspan - 1
                    SpacingBox sb = cell as SpacingBox;
                    if (sb != null)
                    {
                        if (sb.EndRow == currentrow)
                        {
                            maxBottom = Math.Max(maxBottom, sb.ExtendedBox.ActualBottom);
                        }
                    }
                    else if (rowspan == 1)
                    {
                        maxBottom = Math.Max(maxBottom, cell.ActualBottom);
                    }
                    maxRight = Math.Max(maxRight, cell.ActualRight);
                    curCol++;
                    curx = cell.ActualRight + HorizontalSpacing;
                }

                foreach (CssBox cell in row.Boxes)
                {
                    SpacingBox spacer = cell as SpacingBox;

                    if (spacer == null && GetRowSpan(cell) == 1)
                    {
                        cell.ActualBottom = maxBottom;
                        CssLayoutEngine.ApplyCellVerticalAlignment(g, cell);
                    }
                    else if (spacer != null && spacer.EndRow == currentrow)
                    {
                        spacer.ExtendedBox.ActualBottom = maxBottom;
                        CssLayoutEngine.ApplyCellVerticalAlignment(g, spacer.ExtendedBox);
                    }
                }

                cury = maxBottom + VerticalSpacing;
                currentrow++;
            }

            TableBox.ActualRight  = maxRight + HorizontalSpacing + TableBox.ActualBorderRightWidth;
            TableBox.ActualBottom = maxBottom + VerticalSpacing + TableBox.ActualBorderBottomWidth;

            #endregion
        }
Beispiel #14
0
        /// <summary>
        /// Gets the span attribute of the tag of the specified box
        /// </summary>
        /// <param name="b"></param>
        private int GetSpan(CssBox b)
        {
            float f = CssValue.ParseNumber(b.GetAttribute("span"), 1);

            return(Math.Max(1, Convert.ToInt32(f)));
        }
        private void Analyze(Graphics g)
        {
            int num;

            List <CssBox> .Enumerator enumerator;
            this.GetAvailableWidth();
            float availableCellWidth = float.NaN;

            foreach (CssBox box in this.TableBox.Boxes)
            {
                box.RemoveAnonymousSpaces();
                string display = box.Display;
                string str     = display;
                if (display == null)
                {
                    continue;
                }

                if (_method0x6000713_1 == null)
                {
                    _method0x6000713_1 = new Dictionary <string, int>(7)
                    {
                        { "table-caption", 0 },
                        { "table-column", 1 },
                        { "table-column-group", 2 },
                        { "table-footer-group", 3 },
                        { "table-header-group", 4 },
                        { "table-row", 5 },
                        { "table-row-group", 6 }
                    };
                }
                if (!_method0x6000713_1.TryGetValue(str, out num))
                {
                    continue;
                }
                switch (num)
                {
                case 0:
                {
                    this._caption = box;
                    continue;
                }

                case 1:
                {
                    for (int i = 0; i < this.GetSpan(box); i++)
                    {
                        this.Columns.Add(this.CreateColumn(box));
                    }
                    continue;
                }

                case 2:
                {
                    if (box.Boxes.Count != 0)
                    {
                        enumerator = box.Boxes.GetEnumerator();
                        try
                        {
                            while (enumerator.MoveNext())
                            {
                                CssBox current = enumerator.Current;
                                int    span    = this.GetSpan(current);
                                for (int j = 0; j < span; j++)
                                {
                                    this.Columns.Add(this.CreateColumn(current));
                                }
                            }
                            continue;
                        }
                        finally
                        {
                            ((IDisposable)enumerator).Dispose();
                        }
                    }
                    else
                    {
                        int span1 = this.GetSpan(box);
                        for (int k = 0; k < span1; k++)
                        {
                            this.Columns.Add(this.CreateColumn(box));
                        }
                        continue;
                    }
                    break;
                }

                case 3:
                {
                    if (this.FooterBox == null)
                    {
                        this._footerBox = box;
                        continue;
                    }
                    else
                    {
                        this.BodyRows.Add(box);
                        continue;
                    }
                }

                case 4:
                {
                    if (this.HeaderBox == null)
                    {
                        this._headerBox = box;
                        continue;
                    }
                    else
                    {
                        this.BodyRows.Add(box);
                        continue;
                    }
                }

                case 5:
                {
                    this.BodyRows.Add(box);
                    continue;
                }

                case 6:
                {
                    enumerator = box.Boxes.GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext())
                        {
                            CssBox cssBox = enumerator.Current;
                            if (box.Display != "table-row")
                            {
                                continue;
                            }
                            this.BodyRows.Add(box);
                        }
                        continue;
                    }
                    finally
                    {
                        ((IDisposable)enumerator).Dispose();
                    }
                    break;
                }

                default:
                {
                    continue;
                }
                }
            }
            if (this.HeaderBox != null)
            {
                this._allRows.AddRange(this.HeaderBox.Boxes);
            }
            this._allRows.AddRange(this.BodyRows);
            if (this.FooterBox != null)
            {
                this._allRows.AddRange(this.FooterBox.Boxes);
            }
            if (!this.TableBox.TableFixed)
            {
                int           num1     = 0;
                int           num2     = 0;
                List <CssBox> bodyRows = this.BodyRows;
                foreach (CssBox bodyRow in bodyRows)
                {
                    bodyRow.RemoveAnonymousSpaces();
                    num2 = 0;
                    for (int l = 0; l < bodyRow.Boxes.Count; l++)
                    {
                        CssBox item                = bodyRow.Boxes[l];
                        int    rowSpan             = this.GetRowSpan(item);
                        int    cellRealColumnIndex = this.GetCellRealColumnIndex(bodyRow, item);
                        for (int m = num1 + 1; m < num1 + rowSpan; m++)
                        {
                            int num3 = 0;
                            int num4 = 0;
                            while (num4 <= bodyRows[m].Boxes.Count)
                            {
                                if (num3 != cellRealColumnIndex)
                                {
                                    num3++;
                                    cellRealColumnIndex = cellRealColumnIndex - (this.GetColSpan(bodyRows[m].Boxes[num4]) - 1);
                                    num4++;
                                }
                                else
                                {
                                    bodyRows[m].Boxes.Insert(num3, new CssTable.SpacingBox(this.TableBox, ref item, num1));
                                    break;
                                }
                            }
                        }
                        num2++;
                    }
                    num1++;
                }
                this.TableBox.TableFixed = true;
            }
            this._rowCount = this.BodyRows.Count + (this.HeaderBox != null ? this.HeaderBox.Boxes.Count : 0) + (this.FooterBox != null ? this.FooterBox.Boxes.Count : 0);
            if (this.Columns.Count <= 0)
            {
                foreach (CssBox allRow in this.AllRows)
                {
                    this._columnCount = Math.Max(this._columnCount, allRow.Boxes.Count);
                }
            }
            else
            {
                this._columnCount = this.Columns.Count;
            }
            this._columnWidths = new float[this._columnCount];
            for (int n = 0; n < (int)this._columnWidths.Length; n++)
            {
                this._columnWidths[n] = float.NaN;
            }
            availableCellWidth = this.GetAvailableCellWidth();
            if (this.Columns.Count <= 0)
            {
                foreach (CssBox allRow1 in this.AllRows)
                {
                    for (int o = 0; o < this._columnCount; o++)
                    {
                        if (float.IsNaN(this.ColumnWidths[o]) && o < allRow1.Boxes.Count && allRow1.Boxes[o].Display == "table-cell")
                        {
                            CssLength cssLength = new CssLength(allRow1.Boxes[o].Width);
                            if (cssLength.Number > 0f)
                            {
                                int   colSpan = this.GetColSpan(allRow1.Boxes[o]);
                                float number  = 0f;
                                if (cssLength.IsPercentage)
                                {
                                    number = CssValue.ParseNumber(allRow1.Boxes[o].Width, availableCellWidth);
                                }
                                else if (cssLength.Unit == CssLength.CssUnit.Pixels || cssLength.Unit == CssLength.CssUnit.None)
                                {
                                    number = cssLength.Number;
                                }
                                number = number / Convert.ToSingle(colSpan);
                                for (int p = o; p < o + colSpan; p++)
                                {
                                    this.ColumnWidths[p] = number;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                for (int q = 0; q < this.Columns.Count; q++)
                {
                    CssLength cssLength1 = new CssLength(this.Columns[q].Width);
                    if (cssLength1.Number > 0f)
                    {
                        if (cssLength1.IsPercentage)
                        {
                            this.ColumnWidths[q] = CssValue.ParseNumber(this.Columns[q].Width, availableCellWidth);
                        }
                        else if (cssLength1.Unit == CssLength.CssUnit.Pixels || cssLength1.Unit == CssLength.CssUnit.None)
                        {
                            this.ColumnWidths[q] = cssLength1.Number;
                        }
                    }
                }
            }
            if (!this.WidthSpecified)
            {
                float[] singleArray = new float[(int)this.ColumnWidths.Length];
                foreach (CssBox cssBox1 in this.AllRows)
                {
                    for (int r = 0; r < cssBox1.Boxes.Count; r++)
                    {
                        int cellRealColumnIndex1 = this.GetCellRealColumnIndex(cssBox1, cssBox1.Boxes[r]);
                        if (float.IsNaN(this.ColumnWidths[cellRealColumnIndex1]) && r < cssBox1.Boxes.Count && this.GetColSpan(cssBox1.Boxes[r]) == 1)
                        {
                            singleArray[cellRealColumnIndex1] = Math.Max(singleArray[cellRealColumnIndex1], cssBox1.Boxes[r].GetFullWidth(g));
                        }
                    }
                }
                for (int s = 0; s < (int)this.ColumnWidths.Length; s++)
                {
                    if (float.IsNaN(this.ColumnWidths[s]))
                    {
                        this.ColumnWidths[s] = singleArray[s];
                    }
                }
            }
            else
            {
                int   num5         = 0;
                float columnWidths = 0f;
                for (int t = 0; t < (int)this.ColumnWidths.Length; t++)
                {
                    if (!float.IsNaN(this.ColumnWidths[t]))
                    {
                        columnWidths = columnWidths + this.ColumnWidths[t];
                    }
                    else
                    {
                        num5++;
                    }
                }
                float single = (availableCellWidth - columnWidths) / Convert.ToSingle(num5);
                for (int u = 0; u < (int)this.ColumnWidths.Length; u++)
                {
                    if (float.IsNaN(this.ColumnWidths[u]))
                    {
                        this.ColumnWidths[u] = single;
                    }
                }
            }
            int   num6    = 0;
            float single1 = 1f;

            while (this.GetWidthSum() > this.GetAvailableWidth() && this.CanReduceWidth())
            {
                while (!this.CanReduceWidth(num6))
                {
                    num6++;
                }
                this.ColumnWidths[num6] = this.ColumnWidths[num6] - single1;
                num6++;
                if (num6 < (int)this.ColumnWidths.Length)
                {
                    continue;
                }
                num6 = 0;
            }
            foreach (CssBox allRow2 in this.AllRows)
            {
                foreach (CssBox box1 in allRow2.Boxes)
                {
                    int colSpan1             = this.GetColSpan(box1);
                    int cellRealColumnIndex2 = this.GetCellRealColumnIndex(allRow2, box1);
                    int num7 = cellRealColumnIndex2 + colSpan1 - 1;
                    if (this.ColumnWidths[cellRealColumnIndex2] >= this.ColumnMinWidths[cellRealColumnIndex2])
                    {
                        continue;
                    }
                    float columnMinWidths = this.ColumnMinWidths[cellRealColumnIndex2] - this.ColumnWidths[cellRealColumnIndex2];
                    this.ColumnWidths[num7] = this.ColumnMinWidths[num7];
                    if (cellRealColumnIndex2 >= (int)this.ColumnWidths.Length - 1)
                    {
                        continue;
                    }
                    this.ColumnWidths[cellRealColumnIndex2 + 1] = this.ColumnWidths[cellRealColumnIndex2 + 1] - columnMinWidths;
                }
            }
            this.TableBox.Padding = "0";
            float clientLeft      = this.TableBox.ClientLeft + this.HorizontalSpacing;
            float clientTop       = this.TableBox.ClientTop + this.VerticalSpacing;
            float actualRight     = clientLeft;
            float verticalSpacing = clientTop;
            float single2         = clientLeft;
            float single3         = 0f;
            int   num8            = 0;

            foreach (CssBox cssBox2 in this.AllRows)
            {
                if (cssBox2 is CssAnonymousSpaceBlockBox || cssBox2 is CssAnonymousSpaceBox)
                {
                    continue;
                }
                actualRight = clientLeft;
                num6        = 0;
                foreach (CssBox pointF in cssBox2.Boxes)
                {
                    if (num6 >= (int)this.ColumnWidths.Length)
                    {
                        break;
                    }
                    int   rowSpan1  = this.GetRowSpan(pointF);
                    float cellWidth = this.GetCellWidth(this.GetCellRealColumnIndex(cssBox2, pointF), pointF);
                    pointF.Location = new PointF(actualRight, verticalSpacing);
                    pointF.Size     = new SizeF(cellWidth, 0f);
                    pointF.MeasureBounds(g);
                    CssTable.SpacingBox spacingBox = pointF as CssTable.SpacingBox;
                    if (spacingBox != null)
                    {
                        if (spacingBox.EndRow == num8)
                        {
                            single3 = Math.Max(single3, spacingBox.ExtendedBox.ActualBottom);
                        }
                    }
                    else if (rowSpan1 == 1)
                    {
                        single3 = Math.Max(single3, pointF.ActualBottom);
                    }
                    single2 = Math.Max(single2, pointF.ActualRight);
                    num6++;
                    actualRight = pointF.ActualRight + this.HorizontalSpacing;
                }
                foreach (CssBox box2 in cssBox2.Boxes)
                {
                    CssTable.SpacingBox spacingBox1 = box2 as CssTable.SpacingBox;
                    if (spacingBox1 != null || this.GetRowSpan(box2) != 1)
                    {
                        if (spacingBox1 == null || spacingBox1.EndRow != num8)
                        {
                            continue;
                        }
                        spacingBox1.ExtendedBox.ActualBottom = single3;
                        CssLayoutEngine.ApplyCellVerticalAlignment(g, spacingBox1.ExtendedBox);
                    }
                    else
                    {
                        box2.ActualBottom = single3;
                        CssLayoutEngine.ApplyCellVerticalAlignment(g, box2);
                    }
                }
                verticalSpacing = single3 + this.VerticalSpacing;
                num8++;
            }
            this.TableBox.ActualRight  = single2 + this.HorizontalSpacing + this.TableBox.ActualBorderRightWidth;
            this.TableBox.ActualBottom = single3 + this.VerticalSpacing + this.TableBox.ActualBorderBottomWidth;
        }
Beispiel #16
0
        public static Color GetActualColor(string colorValue)
        {
            int   r     = 0;
            int   g     = 0;
            int   b     = 0;
            Color empty = Color.Empty;

            if (string.IsNullOrEmpty(colorValue))
            {
                return(empty);
            }
            colorValue = colorValue.ToLower().Trim();
            if (colorValue.StartsWith("#"))
            {
                string str = colorValue.Substring(1);
                if (str.Length != 6)
                {
                    if (str.Length != 3)
                    {
                        return(empty);
                    }
                    r = int.Parse(new string(str.Substring(0, 1)[0], 2), NumberStyles.HexNumber);
                    g = int.Parse(new string(str.Substring(1, 1)[0], 2), NumberStyles.HexNumber);
                    b = int.Parse(new string(str.Substring(2, 1)[0], 2), NumberStyles.HexNumber);
                }
                else
                {
                    r = int.Parse(str.Substring(0, 2), NumberStyles.HexNumber);
                    g = int.Parse(str.Substring(2, 2), NumberStyles.HexNumber);
                    b = int.Parse(str.Substring(4, 2), NumberStyles.HexNumber);
                }
            }
            else if (!colorValue.StartsWith("rgb(") || !colorValue.EndsWith(")"))
            {
                string empty1 = string.Empty;
                string str1   = colorValue;
                string str2   = str1;
                if (str1 != null)
                {
                    switch (str2)
                    {
                    case "maroon":
                    {
                        empty1 = "#800000";
                        break;
                    }

                    case "red":
                    {
                        empty1 = "#ff0000";
                        break;
                    }

                    case "orange":
                    {
                        empty1 = "#ffA500";
                        break;
                    }

                    case "olive":
                    {
                        empty1 = "#808000";
                        break;
                    }

                    case "purple":
                    {
                        empty1 = "#800080";
                        break;
                    }

                    case "fuchsia":
                    {
                        empty1 = "#ff00ff";
                        break;
                    }

                    case "white":
                    {
                        empty1 = "#ffffff";
                        break;
                    }

                    case "lime":
                    {
                        empty1 = "#00ff00";
                        break;
                    }

                    case "green":
                    {
                        empty1 = "#008000";
                        break;
                    }

                    case "navy":
                    {
                        empty1 = "#000080";
                        break;
                    }

                    case "blue":
                    {
                        empty1 = "#0000ff";
                        break;
                    }

                    case "aqua":
                    {
                        empty1 = "#00ffff";
                        break;
                    }

                    case "teal":
                    {
                        empty1 = "#008080";
                        break;
                    }

                    case "black":
                    {
                        empty1 = "#000000";
                        break;
                    }

                    case "silver":
                    {
                        empty1 = "#c0c0c0";
                        break;
                    }

                    case "gray":
                    {
                        empty1 = "#808080";
                        break;
                    }

                    case "yellow":
                    {
                        empty1 = "#FFFF00";
                        break;
                    }
                    }
                }
                if (string.IsNullOrEmpty(empty1))
                {
                    return(empty);
                }
                Color actualColor = CssValue.GetActualColor(empty1);
                r = actualColor.R;
                g = actualColor.G;
                b = actualColor.B;
            }
            else
            {
                string   str3      = colorValue.Substring(4, colorValue.Length - 5);
                string[] strArrays = str3.Split(new char[] { ',' });
                if ((int)strArrays.Length != 3)
                {
                    return(empty);
                }
                r = Convert.ToInt32(CssValue.ParseNumber(strArrays[0].Trim(), 255f));
                g = Convert.ToInt32(CssValue.ParseNumber(strArrays[1].Trim(), 255f));
                b = Convert.ToInt32(CssValue.ParseNumber(strArrays[2].Trim(), 255f));
            }
            return(Color.FromArgb(r, g, b));
        }
Beispiel #17
0
 public static float ParseLength(string length, float hundredPercent, CssBox box)
 {
     return(CssValue.ParseLength(length, hundredPercent, box, box.GetEmHeight(), false));
 }
Beispiel #18
0
        public static float ParseLength(string length, float hundredPercent, CssBox box, float emFactor, bool returnPoints)
        {
            if (string.IsNullOrEmpty(length) || length == "0")
            {
                return(0f);
            }
            if (length.EndsWith("%"))
            {
                return(CssValue.ParseNumber(length, hundredPercent));
            }
            if (length.Length < 3)
            {
                return(0f);
            }
            string str    = length.Substring(length.Length - 2, 2);
            float  single = 1f;
            string str1   = length.Substring(0, length.Length - 2);
            string str2   = str;
            string str3   = str2;

            if (str2 != null)
            {
                switch (str3)
                {
                case "em":
                {
                    single = emFactor;
                    break;
                }

                case "px":
                {
                    single = 1f;
                    break;
                }

                case "mm":
                {
                    single = 3f;
                    break;
                }

                case "cm":
                {
                    single = 37f;
                    break;
                }

                case "in":
                {
                    single = 96f;
                    break;
                }

                case "pt":
                {
                    single = 1.33333337f;
                    if (!returnPoints)
                    {
                        break;
                    }
                    return(CssValue.ParseNumber(str1, hundredPercent));
                }

                case "pc":
                {
                    single = 16f;
                    break;
                }

                default:
                {
                    single = 0f;
                    return(single * CssValue.ParseNumber(str1, hundredPercent));
                }
                }
            }
            else
            {
                single = 0f;
                return(single * CssValue.ParseNumber(str1, hundredPercent));
            }
            return(single * CssValue.ParseNumber(str1, hundredPercent));
        }