Example #1
0
        /// <summary>
        /// Paints the text decoration
        /// </summary>
        /// <param name="g"></param>
        /// <param name="rectangle"> </param>
        /// <param name="isFirst"> </param>
        /// <param name="isLast"> </param>
        private void PaintDecoration(Graphics g, RectangleF rectangle, bool isFirst, bool isLast)
        {
            if (string.IsNullOrEmpty(TextDecoration) || TextDecoration == CssConstants.None || IsImage)
            {
                return;
            }

            float desc = CssUtils.GetDescent(ActualFont);
            float asc  = CssUtils.GetAscent(ActualFont);
            float y    = 0f;

            if (TextDecoration == CssConstants.Underline)
            {
                y = rectangle.Bottom - desc + 0.6f;
            }
            else if (TextDecoration == CssConstants.LineThrough)
            {
                y = rectangle.Bottom - desc - asc / 2;
            }
            else if (TextDecoration == CssConstants.Overline)
            {
                y = rectangle.Bottom - desc - asc - 2;
            }

            y -= ActualPaddingBottom - ActualBorderBottomWidth;

            float x1 = rectangle.X;
            float x2 = rectangle.Right;

            if (isFirst)
            {
                x1 += ActualPaddingLeft + ActualBorderLeftWidth;
            }
            if (isLast)
            {
                x2 -= ActualPaddingRight + ActualBorderRightWidth;
                x2 -= ActualWordSpacing + 0.8f * CssUtils.GetWordEndWhitespace(ActualFont);
            }

            g.DrawLine(new Pen(ActualColor), x1, y, x2, y);
        }
Example #2
0
        /// <summary>
        /// Recursively flows the content of the box using the inline model
        /// </summary>
        /// <param name="g">Device Info</param>
        /// <param name="blockbox">Blockbox that contains the text flow</param>
        /// <param name="box">Current box to flow its content</param>
        /// <param name="maxright">Maximum reached right</param>
        /// <param name="linespacing">Space to use between rows of text</param>
        /// <param name="startx">x starting coordinate for when breaking lines of text</param>
        /// <param name="line">Current linebox being used</param>
        /// <param name="curx">Current x coordinate that will be the left of the next word</param>
        /// <param name="cury">Current y coordinate that will be the top of the next word</param>
        /// <param name="maxbottom">Maximum bottom reached so far</param>
        private static void FlowBox(Graphics g, CssBox blockbox, CssBox box, float maxright, float linespacing, float startx, ref CssLineBox line, ref float curx, ref float cury, ref float maxbottom)
        {
            var startY = cury;

            box.FirstHostingLineBox = line;

            foreach (CssBox b in box.Boxes)
            {
                float leftspacing  = b.ActualMarginLeft + b.ActualBorderLeftWidth + b.ActualPaddingLeft;
                float rightspacing = b.ActualMarginRight + b.ActualBorderRightWidth + b.ActualPaddingRight;

                b.RectanglesReset();
                b.MeasureWordsSize(g);

                curx += leftspacing;

                if (b.Words.Count > 0)
                {
                    // fix word space for first word in inline tag
                    if (!b.Words[0].IsImage && b.Words[0].HasSpaceBefore && b.Display == CssConstants.Inline)
                    {
                        var sib = DomUtils.GetPreviousContainingBlockSibling(b);
                        if (sib != null && sib.Display == CssConstants.Inline)
                        {
                            curx += b.ActualWordSpacing;
                        }
                    }

                    foreach (var word in b.Words)
                    {
                        if (maxbottom - cury < box.ActualLineHeight)
                        {
                            maxbottom += box.ActualLineHeight - (maxbottom - cury);
                        }

                        if ((b.WhiteSpace != CssConstants.Nowrap && curx + word.Width + rightspacing > maxright) || word.IsLineBreak)
                        {
                            curx = startx;
                            cury = maxbottom + linespacing;

                            line = new CssLineBox(blockbox);

                            if (word.IsImage || word.Equals(b.FirstWord))
                            {
                                curx += leftspacing;
                            }
                        }

                        // atodo: why?
                        line.ReportExistanceOf(word);

                        word.Left = curx;                                             // -word.LastMeasureOffset.X + 1;
                        word.Top  = cury;                                             // - word.LastMeasureOffset.Y;

                        curx = word.Right + (word.IsImage ? b.ActualWordSpacing : 0); // +word.SpacesAfterWidth;

                        maxbottom = Math.Max(maxbottom, word.Bottom);                 //+ (word.IsImage ? topspacing + bottomspacing : 0));
                    }

                    // fix word space for last word that is right before inline tag
                    var lastWord = b.Words[b.Words.Count - 1];
                    if (!lastWord.IsImage && !lastWord.HasSpaceAfter)
                    {
                        var next = DomUtils.GetNextSibling(b);
                        if (next == null || next.Display == CssConstants.Inline)
                        {
                            curx -= b.ActualWordSpacing + CssUtils.GetWordEndWhitespace(b.ActualFont);
                        }
                    }
                }
                else
                {
                    FlowBox(g, blockbox, b, maxright, linespacing, startx, ref line, ref curx, ref cury, ref maxbottom);
                }

                curx += rightspacing;
            }

            // handle height setting
            if (maxbottom - startY < box.ActualHeight)
            {
                maxbottom += box.ActualHeight - (maxbottom - startY);
            }

            // handle box that is only a whitespace
            if (box.Text == " " && !box.IsImage && box.IsInline && box.Boxes.Count == 0 && box.Words.Count == 0)
            {
                curx += box.ActualWordSpacing;
            }

            box.LastHostingLineBox = line;
        }