예제 #1
0
        /// <summary>
        /// Applies special vertical alignment for table-cells
        /// </summary>
        /// <param name="g"></param>
        /// <param name="cell"></param>
        public static void ApplyCellVerticalAlignment(RGraphics g, CssBox cell)
        {
            ArgChecker.AssertArgNotNull(g, "g");
            ArgChecker.AssertArgNotNull(cell, "cell");

            if (cell.VerticalAlign == CssConstants.Top || cell.VerticalAlign == CssConstants.Baseline)
            {
                return;
            }

            double cellbot = cell.ClientBottom;
            double bottom  = cell.GetMaximumBottom(cell, 0f);
            double dist    = 0f;

            if (cell.VerticalAlign == CssConstants.Bottom)
            {
                dist = cellbot - bottom;
            }
            else if (cell.VerticalAlign == CssConstants.Middle)
            {
                dist = (cellbot - bottom) / 2;
            }

            foreach (CssBox b in cell.Boxes)
            {
                b.OffsetTop(dist);
            }

            //float top = cell.ClientTop;
            //float bottom = cell.ClientBottom;
            //bool middle = cell.VerticalAlign == CssConstants.Middle;

            //foreach (LineBox line in cell.LineBoxes)
            //{
            //    for (int i = 0; i < line.RelatedBoxes.Count; i++)
            //    {

            //        double diff = bottom - line.RelatedBoxes[i].Rectangles[line].Bottom;
            //        if (middle) diff /= 2f;
            //        RectangleF r = line.RelatedBoxes[i].Rectangles[line];
            //        line.RelatedBoxes[i].Rectangles[line] = new RectangleF(r.X, r.Y + diff, r.Width, r.Height);

            //    }

            //    foreach (BoxWord word in line.Words)
            //    {
            //        double gap = word.Top - top;
            //        word.Top = bottom - gap - word.Height;
            //    }
            //}
        }
예제 #2
0
        public static void ApplyCellVerticalAlignment(Graphics g, CssBox cell)
        {
            if (cell.VerticalAlign == "top" || cell.VerticalAlign == "baseline")
            {
                return;
            }
            float clientTop     = cell.ClientTop;
            float clientBottom  = cell.ClientBottom;
            float maximumBottom = cell.GetMaximumBottom(cell, 0f);
            float single        = 0f;

            if (cell.VerticalAlign == "bottom")
            {
                single = clientBottom - maximumBottom;
            }
            else if (cell.VerticalAlign == "middle")
            {
                single = (clientBottom - maximumBottom) / 2f;
            }
            foreach (CssBox box in cell.Boxes)
            {
                box.OffsetTop(single);
            }
        }