Пример #1
0
        private static void ApplyJustifyAlignment(Graphics g, CssLineBox lineBox)
        {
            if (lineBox.Equals(lineBox.OwnerBox.LineBoxes[lineBox.OwnerBox.LineBoxes.Count - 1]))
            {
                return;
            }
            float single  = (lineBox.Equals(lineBox.OwnerBox.LineBoxes[0]) ? lineBox.OwnerBox.ActualTextIndent : 0f);
            float width   = 0f;
            float single1 = 0f;
            float width1  = lineBox.OwnerBox.ClientRectangle.Width - single;

            foreach (CssBoxWord word in lineBox.Words)
            {
                width   = width + word.Width;
                single1 = single1 + 1f;
            }
            if (single1 <= 0f)
            {
                return;
            }
            float single2    = (width1 - width) / single1;
            float clientLeft = lineBox.OwnerBox.ClientLeft + single;

            foreach (CssBoxWord clientRight in lineBox.Words)
            {
                clientRight.Left = clientLeft;
                clientLeft       = clientRight.Right + single2;
                if (clientRight != lineBox.Words[lineBox.Words.Count - 1])
                {
                    continue;
                }
                clientRight.Left = lineBox.OwnerBox.ClientRight - clientRight.Width;
            }
        }
Пример #2
0
        /// <summary>
        ///     Applies centered alignment to the text on the linebox
        /// </summary>
        /// <param name="g"></param>
        /// <param name="lineBox"></param>
        private static void ApplyJustifyAlignment(Graphics g, CssLineBox lineBox)
        {
            if (lineBox.Equals(lineBox.OwnerBox.LineBoxes[lineBox.OwnerBox.LineBoxes.Count - 1]))
            {
                return;
            }

            var indent     = lineBox.Equals(lineBox.OwnerBox.LineBoxes[0]) ? lineBox.OwnerBox.ActualTextIndent : 0f;
            var textSum    = 0f;
            var words      = 0f;
            var availWidth = lineBox.OwnerBox.ClientRectangle.Width - indent;

            #region Gather text sum

            foreach (var w in lineBox.Words)
            {
                textSum += w.Width;
                words   += 1f;
            }

            #endregion

            if (words <= 0f)
            {
                return;                                   //Avoid Zero division
            }
            var spacing = (availWidth - textSum) / words; //Spacing that will be used
            var curx    = lineBox.OwnerBox.ClientLeft + indent;

            foreach (var word in lineBox.Words)
            {
                word.Left = curx;
                curx      = word.Right + spacing;

                if (word == lineBox.Words[lineBox.Words.Count - 1])
                {
                    word.Left = lineBox.OwnerBox.ClientRight - word.Width;
                }

                //TODO: Background rectangles are being deactivated when justifying text.
            }
        }
Пример #3
0
        /// <summary>
        /// Applies centered alignment to the text on the linebox
        /// </summary>
        /// <param name="g"></param>
        /// <param name="lineBox"></param>
        private static void ApplyJustifyAlignment(Graphics g, CssLineBox lineBox)
        {
            if (lineBox.Equals(lineBox.OwnerBox.LineBoxes[lineBox.OwnerBox.LineBoxes.Count - 1])) return;

            float indent = lineBox.Equals(lineBox.OwnerBox.LineBoxes[0]) ? lineBox.OwnerBox.ActualTextIndent : 0f;
            float textSum = 0f;
            float words = 0f;
            float availWidth = lineBox.OwnerBox.ClientRectangle.Width - indent;

            #region Gather text sum
            foreach (CssBoxWord w in lineBox.Words)
            {
                textSum += w.Width;
                words += 1f;
            }
            #endregion

            if (words <= 0f) return; //Avoid Zero division
            float spacing = (availWidth - textSum) / words; //Spacing that will be used
            float curx = lineBox.OwnerBox.ClientLeft + indent;

            foreach (CssBoxWord word in lineBox.Words)
            {
                word.Left = curx;
                curx = word.Right + spacing;

                if (word == lineBox.Words[lineBox.Words.Count - 1])
                {
                    word.Left = lineBox.OwnerBox.ClientRight - word.Width;
                }

                //TODO: Background rectangles are being deactivated when justifying text.
            }

            
            
        }