Пример #1
0
        /**
         * render inline space
         *
         * @param space space to render
         */

        public void RenderInlineSpace(InlineSpace space)
        {
            this.currentXPosition += space.getSize();
            if (space.getUnderlined())
            {
                if (prevUnderlineColor != null)
                {
                    AddLine(prevUnderlineXEndPos, prevUnderlineYEndPos,
                            prevUnderlineXEndPos + space.getSize(),
                            prevUnderlineYEndPos, prevUnderlineSize,
                            prevUnderlineColor.Value);
                    // save position for a following InlineSpace
                    prevUnderlineXEndPos = prevUnderlineXEndPos + space.getSize();
                }
            }
            if (space.getOverlined())
            {
                if (prevOverlineColor != null)
                {
                    AddLine(prevOverlineXEndPos, prevOverlineYEndPos,
                            prevOverlineXEndPos + space.getSize(),
                            prevOverlineYEndPos, prevOverlineSize,
                            prevOverlineColor.Value);
                    prevOverlineXEndPos = prevOverlineXEndPos + space.getSize();
                }
            }
            if (space.getLineThrough())
            {
                if (prevLineThroughColor != null)
                {
                    AddLine(prevLineThroughXEndPos, prevLineThroughYEndPos,
                            prevLineThroughXEndPos + space.getSize(),
                            prevLineThroughYEndPos, prevLineThroughSize,
                            prevLineThroughColor.Value);
                    prevLineThroughXEndPos = prevLineThroughXEndPos + space.getSize();
                }
            }
        }
Пример #2
0
        public void align(int type)
        {
            int padding = 0;

            switch (type)
            {
            case TextAlign.START:
                padding    = this.getContentWidth() - finalWidth;
                endIndent += padding;
                break;

            case TextAlign.END:
                padding      = this.getContentWidth() - finalWidth;
                startIndent += padding;
                break;

            case TextAlign.CENTER:
                padding      = (this.getContentWidth() - finalWidth) / 2;
                startIndent += padding;
                endIndent   += padding;
                break;

            case TextAlign.JUSTIFY:
                int spaceCount = 0;
                foreach (Box b in children)
                {
                    if (b is InlineSpace)
                    {
                        InlineSpace space = (InlineSpace)b;
                        if (space.getResizeable())
                        {
                            spaceCount++;
                        }
                    }
                }
                if (spaceCount > 0)
                {
                    padding = (this.getContentWidth() - finalWidth) / spaceCount;
                }
                else
                {
                    padding = 0;
                }
                spaceCount = 0;
                foreach (Box b in children)
                {
                    if (b is InlineSpace)
                    {
                        InlineSpace space = (InlineSpace)b;
                        if (space.getResizeable())
                        {
                            space.setSize(space.getSize() + padding);
                            spaceCount++;
                        }
                    }
                    else if (b is InlineArea)
                    {
                        ((InlineArea)b).setXOffset(spaceCount * padding);
                    }
                }
                break;
            }
        }
Пример #3
0
        public LineArea(FontState fontState, int lineHeight, int halfLeading,
                        int allocationWidth, int startIndent, int endIndent,
                        LineArea prevLineArea)
            : base(fontState)
        {
            this.currentFontState   = fontState;
            this.lineHeight         = lineHeight;
            this.nominalFontSize    = fontState.FontSize;
            this.nominalGlyphHeight = fontState.Ascender - fontState.Descender;

            this.placementOffset       = fontState.Ascender;
            this.contentRectangleWidth = allocationWidth - startIndent
                                         - endIndent;
            this.fontState = fontState;

            this.allocationHeight = this.nominalGlyphHeight;
            this.halfLeading      = this.lineHeight - this.allocationHeight;

            this.startIndent = startIndent;
            this.endIndent   = endIndent;

            if (prevLineArea != null)
            {
                IEnumerator e            = prevLineArea.pendingAreas.GetEnumerator();
                Box         b            = null;
                bool        eatMoreSpace = true;
                int         eatenWidth   = 0;

                while (eatMoreSpace)
                {
                    if (e.MoveNext())
                    {
                        b = (Box)e.Current;
                        if (b is InlineSpace)
                        {
                            InlineSpace isp = (InlineSpace)b;
                            if (isp.isEatable())
                            {
                                eatenWidth += isp.getSize();
                            }
                            else
                            {
                                eatMoreSpace = false;
                            }
                        }
                        else
                        {
                            eatMoreSpace = false;
                        }
                    }
                    else
                    {
                        eatMoreSpace = false;
                        b            = null;
                    }
                }

                while (b != null)
                {
                    pendingAreas.Add(b);
                    if (e.MoveNext())
                    {
                        b = (Box)e.Current;
                    }
                    else
                    {
                        b = null;
                    }
                }
                pendingWidth = prevLineArea.getPendingWidth() - eatenWidth;
            }
        }