示例#1
0
        /** Finishes writing the table.
         * @param canvases the array returned by <CODE>beginWritingRows()</CODE>
         */
        public static void EndWritingRows(PdfContentByte[] canvases)
        {
            PdfContentByte canvas = canvases[BASECANVAS];

            canvas.SaveState();
            canvas.Add(canvases[BACKGROUNDCANVAS]);
            canvas.RestoreState();
            canvas.SaveState();
            canvas.SetLineCap(2);
            canvas.ResetRGBColorStroke();
            canvas.Add(canvases[LINECANVAS]);
            canvas.RestoreState();
            canvas.Add(canvases[TEXTCANVAS]);
        }
示例#2
0
        protected override void Draw(PdfContentByte cb)
        {
            //TODO if width and height not know: what to do
            //PdfTemplate template = cb.CreateTemplate(this.width, this.height);
            PdfTemplate template = cb.CreateTemplate(500, 500);

            //draw the list of elements on the new template
            foreach (IElement elem in this.list)
            {
                Graphic graphic = (Graphic)elem;

                if (applyCSSToElements)
                {
                    graphic.Draw(template, GetCombinedCss(graphic.GetCss(), GetCss()));
                }
                else
                {
                    graphic.Draw(template, graphic.GetCss());
                }
            }
            //add the template at the x, y position
            System.Drawing.Drawing2D.Matrix translation = new System.Drawing.Drawing2D.Matrix();
            translation.Translate(this.x, this.y);
            cb.ConcatCTM(translation);

            cb.Add(template);
        }
示例#3
0
        /**
         * Outputs the lines to the document. The output can be simulated.
         * @param simulate <CODE>true</CODE> to simulate the writting to the document
         * @return returns the result of the operation. It can be <CODE>NO_MORE_TEXT</CODE>
         * and/or <CODE>NO_MORE_COLUMN</CODE>
         * @throws DocumentException on error
         */
        public int go(bool simulate)
        {
            bool           dirty    = false;
            PdfContentByte graphics = null;

            if (text != null)
            {
                graphics = text.Duplicate;
            }
            else if (simulate == false)
            {
                throw new Exception("VerticalText.go with simulate==false and text==null.");
            }
            int status = 0;

            for (;;)
            {
                if (maxLines <= 0)
                {
                    status = NO_MORE_COLUMN;
                    if (chunks.Count == 0)
                    {
                        status |= NO_MORE_TEXT;
                    }
                    break;
                }
                if (chunks.Count == 0)
                {
                    status = NO_MORE_TEXT;
                    break;
                }
                PdfLine line = createLine(height);
                if (!simulate && !dirty)
                {
                    text.beginText();
                    dirty = true;
                }
                shortenChunkArray();
                if (!simulate)
                {
                    text.setTextMatrix(startX, startY - line.IndentLeft);
                    writeLine(line, text, graphics);
                }
                --maxLines;
                startX -= leading;
            }
            if (dirty)
            {
                text.endText();
                text.Add(graphics);
            }
            return(status);
        }
示例#4
0
        /**
         * Outputs the lines to the document. The output can be simulated.
         * @param simulate <CODE>true</CODE> to simulate the writting to the document
         * @return returns the result of the operation. It can be <CODE>NO_MORE_TEXT</CODE>
         * and/or <CODE>NO_MORE_COLUMN</CODE>
         * @throws DocumentException on error
         */
        public int Go(bool simulate)
        {
            bool           dirty    = false;
            PdfContentByte graphics = null;

            if (text != null)
            {
                graphics = text.Duplicate;
            }
            else if (!simulate)
            {
                throw new Exception(MessageLocalization.GetComposedMessage("verticaltext.go.with.simulate.eq.eq.false.and.text.eq.eq.null"));
            }
            int status = 0;

            for (;;)
            {
                if (maxLines <= 0)
                {
                    status = NO_MORE_COLUMN;
                    if (chunks.Count == 0)
                    {
                        status |= NO_MORE_TEXT;
                    }
                    break;
                }
                if (chunks.Count == 0)
                {
                    status = NO_MORE_TEXT;
                    break;
                }
                PdfLine line = CreateLine(height);
                if (!simulate && !dirty)
                {
                    text.BeginText();
                    dirty = true;
                }
                ShortenChunkArray();
                if (!simulate)
                {
                    text.SetTextMatrix(startX, startY - line.IndentLeft);
                    WriteLine(line, text, graphics);
                }
                --maxLines;
                startX -= leading;
            }
            if (dirty)
            {
                text.EndText();
                text.Add(graphics);
            }
            return(status);
        }
        /// <summary>
        /// Outputs the lines to the document. The output can be simulated.
        /// and/or  NO_MORE_COLUMN
        /// @throws DocumentException on error
        /// </summary>
        /// <param name="simulate"> true  to simulate the writting to the document</param>
        /// <returns>returns the result of the operation. It can be  NO_MORE_TEXT </returns>
        public int Go(bool simulate)
        {
            bool           dirty    = false;
            PdfContentByte graphics = null;

            if (Text != null)
            {
                graphics = Text.Duplicate;
            }
            else if (!simulate)
            {
                throw new Exception("VerticalText.go with simulate==false and text==null.");
            }
            int status = 0;

            for (;;)
            {
                if (maxLines <= 0)
                {
                    status = NoMoreColumn;
                    if (Chunks.Count == 0)
                    {
                        status |= NoMoreText;
                    }
                    break;
                }
                if (Chunks.Count == 0)
                {
                    status = NoMoreText;
                    break;
                }
                PdfLine line = CreateLine(height);
                if (!simulate && !dirty)
                {
                    Text.BeginText();
                    dirty = true;
                }
                ShortenChunkArray();
                if (!simulate)
                {
                    Text.SetTextMatrix(StartX, StartY - line.IndentLeft);
                    WriteLine(line, Text, graphics);
                }
                --maxLines;
                StartX -= leading;
            }
            if (dirty)
            {
                Text.EndText();
                Text.Add(graphics);
            }
            return(status);
        }
示例#6
0
        void DrawGroup(PdfContentByte cb)
        {
            //TODO if width and height not know: what to do
            //PdfTemplate template = cb.CreateTemplate(this.width, this.height);
            PdfTemplate template = cb.CreateTemplate(500, 500);
            //draw the list of elements on the new template

            IList <int> xSpacing = null, ySpacing = null;
            float       defaultSpacing = template.CharacterSpacing;
            float       rise           = 0;

            template.BeginText();
            //
            foreach (IElement elem in this.list)
            {
                Text text = (Text)elem;
                //CssSvgAppliers.GetInstance().ApplyForText(, text.GetCss(), text.GetChunk());
                CssSvgAppliers.GetInstance().ApplyForText(template, text.GetCss(), text.GetChunk());

                if (!text.IsRelative())
                {
                    //when there are x,y coordinates in the text or tspan
                    template.SetTextMatrix(text.GetX(), -1 * text.GetY());
                }

                //System.out.Println(text.chunk.GetFont());

                //the spacing
                if (text.Dx != null)
                {
                    xSpacing = text.Dx;
                }
                if (text.Dy != null)
                {
                    ySpacing = text.Dy;
                    rise     = 0;
                }
                if (xSpacing != null || ySpacing != null)
                {
                    String display = text.GetText();
                    for (int i = 0; i < display.Length; i++)
                    {
                        if (xSpacing != null && xSpacing.Count > 0)
                        {
                            template.SetCharacterSpacing(xSpacing[0]);
                            xSpacing.Remove(0);
                        }
                        if (ySpacing != null && ySpacing.Count > 0)
                        {
                            rise = rise - ySpacing[0];
                            template.SetTextRise(rise);
                            ySpacing.Remove(0);
                        }
                        else
                        {
                            template.SetTextRise(rise);
                        }
                        template.ShowText(display.Substring(i, 1));

                        template.SetCharacterSpacing(defaultSpacing);
                    }
                }
                else
                {
                    template.ShowText(text.GetText());
                }
            }
            template.EndText();
            //add the template at the x, y position
            cb.ConcatCTM(1, 0, 0, -1, 0, 0);

            cb.Add(template);
        }
示例#7
0
        /**
         * Outputs the lines to the document. The output can be simulated.
         * @param simulate <CODE>true</CODE> to simulate the writting to the document
         * @return returns the result of the operation. It can be <CODE>NO_MORE_TEXT</CODE>
         * and/or <CODE>NO_MORE_COLUMN</CODE>
         * @throws DocumentException on error
         */
        public int go(bool simulate)
        {
            bool  dirty = false;
            float ratio = spaceCharRatio;

            Object[] currentValues  = new Object[2];
            PdfFont  currentFont    = null;
            float    lastBaseFactor = 0F;

            currentValues[1] = lastBaseFactor;
            PdfDocument    pdf               = null;
            PdfContentByte graphics          = null;
            int            localRunDirection = PdfWriter.RUN_DIRECTION_NO_BIDI;

            if (runDirection != PdfWriter.RUN_DIRECTION_DEFAULT)
            {
                localRunDirection = runDirection;
            }
            if (text != null)
            {
                pdf      = text.PdfDocument;
                graphics = text.Duplicate;
            }
            else if (!simulate)
            {
                throw new Exception("ColumnText.go with simulate==false and text==null.");
            }
            if (!simulate)
            {
                if (ratio == GLOBAL_SPACE_CHAR_RATIO)
                {
                    ratio = text.PdfWriter.SpaceCharRatio;
                }
                else if (ratio < 0.001f)
                {
                    ratio = 0.001f;
                }
            }
            float firstIndent = 0;

            int status = 0;

            if (rectangularWidth > 0)
            {
                for (;;)
                {
                    firstIndent = (lastWasNewline ? indent : followingIndent);
                    if (rectangularWidth <= firstIndent + rightIndent)
                    {
                        status = NO_MORE_COLUMN;
                        if (bidiLine.isEmpty())
                        {
                            status |= NO_MORE_TEXT;
                        }
                        break;
                    }
                    if (bidiLine.isEmpty())
                    {
                        status = NO_MORE_TEXT;
                        break;
                    }
                    float   yTemp   = yLine;
                    PdfLine line    = bidiLine.processLine(rectangularWidth - firstIndent - rightIndent, alignment, localRunDirection);
                    float   maxSize = line.MaxSizeSimple;
                    currentLeading = fixedLeading + maxSize * multipliedLeading;
                    float[] xx = findLimitsTwoLines();
                    if (xx == null)
                    {
                        status = NO_MORE_COLUMN;
                        yLine  = yTemp;
                        bidiLine.restore();
                        break;
                    }
                    float x1 = Math.Max(xx[0], xx[2]);
                    if (!simulate && !dirty)
                    {
                        text.beginText();
                        dirty = true;
                    }
                    if (!simulate)
                    {
                        currentValues[0] = currentFont;
                        text.setTextMatrix(x1 + (line.IsRTL ? rightIndent : firstIndent) + line.IndentLeft, yLine);
                        pdf.writeLineToContent(line, text, graphics, currentValues, ratio);
                        currentFont = (PdfFont)currentValues[0];
                    }
                    lastWasNewline = line.isNewlineSplit();
                    yLine         -= line.isNewlineSplit() ? extraParagraphSpace : 0;
                }
            }
            else
            {
                currentLeading = fixedLeading;
                for (;;)
                {
                    firstIndent = (lastWasNewline ? indent : followingIndent);
                    float   yTemp = yLine;
                    float[] xx    = findLimitsTwoLines();
                    if (xx == null)
                    {
                        status = NO_MORE_COLUMN;
                        if (bidiLine.isEmpty())
                        {
                            status |= NO_MORE_TEXT;
                        }
                        yLine = yTemp;
                        break;
                    }
                    if (bidiLine.isEmpty())
                    {
                        status = NO_MORE_TEXT;
                        yLine  = yTemp;
                        break;
                    }
                    float x1 = Math.Max(xx[0], xx[2]);
                    float x2 = Math.Min(xx[1], xx[3]);
                    if (x2 - x1 <= firstIndent + rightIndent)
                    {
                        continue;
                    }
                    if (!simulate && !dirty)
                    {
                        text.beginText();
                        dirty = true;
                    }
                    PdfLine line = bidiLine.processLine(x2 - x1 - firstIndent - rightIndent, alignment, localRunDirection);
                    if (!simulate)
                    {
                        currentValues[0] = currentFont;
                        text.setTextMatrix(x1 + (line.IsRTL ? rightIndent : firstIndent) + line.IndentLeft, yLine);
                        pdf.writeLineToContent(line, text, graphics, currentValues, ratio);
                        currentFont = (PdfFont)currentValues[0];
                    }
                    lastWasNewline = line.isNewlineSplit();
                    yLine         -= line.isNewlineSplit() ? extraParagraphSpace : 0;
                }
            }
            if (dirty)
            {
                text.endText();
                text.Add(graphics);
            }
            return(status);
        }