SaveState() public method

public SaveState ( ) : void
return void
 /** Shows a line of text. Only the first line is written.
  * @param canvas where the text is to be written to
  * @param alignment the alignment. It is not influenced by the run direction
  * @param phrase the <CODE>Phrase</CODE> with the text
  * @param x the x reference position
  * @param y the y reference position
  * @param rotation the rotation to be applied in degrees counterclockwise
  * @param runDirection the run direction
  * @param arabicOptions the options for the arabic shaping
  */    
 public static void ShowTextAligned(PdfContentByte canvas, int alignment, Phrase phrase, float x, float y, float rotation, int runDirection, int arabicOptions) {
     if (alignment != Element.ALIGN_LEFT && alignment != Element.ALIGN_CENTER
         && alignment != Element.ALIGN_RIGHT)
         alignment = Element.ALIGN_LEFT;
     canvas.SaveState();
     ColumnText ct = new ColumnText(canvas);
     float lly = -1;
     float ury = 2;
     float llx;
     float urx;
     switch (alignment) {
         case Element.ALIGN_LEFT:
             llx = 0;
             urx = 20000;
             break;
         case Element.ALIGN_RIGHT:
             llx = -20000;
             urx = 0;
             break;
         default:
             llx = -20000;
             urx = 20000;
             break;
     }
     if (rotation == 0) {
         llx += x;
         lly += y;
         urx += x;
         ury += y;
     }
     else {
         double alpha = rotation * Math.PI / 180.0;
         float cos = (float)Math.Cos(alpha);
         float sin = (float)Math.Sin(alpha);
         canvas.ConcatCTM(cos, sin, -sin, cos, x, y);
     }
     ct.SetSimpleColumn(phrase, llx, lly, urx, ury, 2, alignment);
     if (runDirection == PdfWriter.RUN_DIRECTION_RTL) {
         if (alignment == Element.ALIGN_LEFT)
             alignment = Element.ALIGN_RIGHT;
         else if (alignment == Element.ALIGN_RIGHT)
             alignment = Element.ALIGN_LEFT;
     }
     ct.Alignment = alignment;
     ct.ArabicOptions = arabicOptions;
     ct.RunDirection = runDirection;
     ct.Go();
     canvas.RestoreState();
 }
 // ---------------------------------------------------------------------------
 /**
  * Draws a row of stars and circles.
  * @param canvas the canvas to which the shapes have to be drawn
  * @param x      X coordinate to position the row
  * @param y      Y coordinate to position the row
  * @param radius the radius of the circles
  * @param gutter the space between the shapes
  */
 public static void CreateStarsAndCircles(PdfContentByte canvas,
 float x, float y, float radius, float gutter)
 {
     canvas.SaveState();
       canvas.SetColorStroke(new GrayColor(0.2f));
       canvas.SetColorFill(new GrayColor(0.9f));
       CreateStar(canvas, x, y);
       CreateCircle(canvas, x + radius, y - 70, radius, true);
       CreateCircle(canvas, x + radius, y - 70, radius / 2, true);
       canvas.Fill();
       x += 2 * radius + gutter;
       CreateStar(canvas, x, y);
       CreateCircle(canvas, x + radius, y - 70, radius, true);
       CreateCircle(canvas, x + radius, y - 70, radius / 2, true);
       canvas.EoFill();
       x += 2 * radius + gutter;
       CreateStar(canvas, x, y);
       canvas.NewPath();
       CreateCircle(canvas, x + radius, y - 70, radius, true);
       CreateCircle(canvas, x + radius, y - 70, radius / 2, true);
       x += 2 * radius + gutter;
       CreateStar(canvas, x, y);
       CreateCircle(canvas, x + radius, y - 70, radius, true);
       CreateCircle(canvas, x + radius, y - 70, radius / 2, false);
       canvas.FillStroke();
       x += 2 * radius + gutter;
       CreateStar(canvas, x, y);
       CreateCircle(canvas, x + radius, y - 70, radius, true);
       CreateCircle(canvas, x + radius, y - 70, radius / 2, true);
       canvas.EoFillStroke();
       canvas.RestoreState();
 }
 /**
 * @see com.lowagie.text.pdf.draw.DrawInterface#draw(com.lowagie.text.pdf.PdfContentByte, float, float, float, float, float)
 */
 public override void Draw(PdfContentByte canvas, float llx, float lly, float urx, float ury, float y) {
     canvas.SaveState();
     canvas.SetLineWidth(lineWidth);
     canvas.SetLineCap(PdfContentByte.LINE_CAP_ROUND);
     canvas.SetLineDash(0, gap, gap / 2);
     DrawLine(canvas, llx, urx, y);
     canvas.RestoreState();
 }
Beispiel #4
1
// ---------------------------------------------------------------------------    
    /**
     * Draws three rectangles
     * @param canvas
     */
    public void DrawRectangles(PdfContentByte canvas) {
      canvas.SaveState();
      canvas.SetGrayFill(0.9f);
      canvas.Rectangle(33, 592, 72, 72);
      canvas.Rectangle(263, 406, 72, 72);
      canvas.Rectangle(491, 168, 72, 72);
      canvas.FillStroke();
      canvas.RestoreState();
    }    
Beispiel #5
1
 public void Ellipse(PdfContentByte content, Rectangle rect) {
   content.SaveState();
   content.SetRGBColorFill(0x00, 0x00, 0xFF);
   content.Ellipse(
     rect.Left - 3f, rect.Bottom - 5f,
     rect.Right + 3f, rect.Top + 3f
   );
   content.Fill();
   content.RestoreState();
 }
        // ---------------------------------------------------------------------------    
        /**
         * Draws the time table for a day at the film festival.
         * @param directcontent a canvas to which the time table has to be drawn.
         */
        protected void DrawTimeTable(PdfContentByte directcontent)
        {
            directcontent.SaveState();
            directcontent.SetLineWidth(1.2f);
            float llx, lly, urx, ury;

            llx = OFFSET_LEFT;
            lly = OFFSET_BOTTOM;
            urx = OFFSET_LEFT + WIDTH;
            ury = OFFSET_BOTTOM + HEIGHT;
            directcontent.MoveTo(llx, lly);
            directcontent.LineTo(urx, lly);
            directcontent.LineTo(urx, ury);
            directcontent.LineTo(llx, ury);
            directcontent.ClosePath();
            directcontent.Stroke();

            llx = OFFSET_LOCATION;
            lly = OFFSET_BOTTOM;
            urx = OFFSET_LOCATION + WIDTH_LOCATION;
            ury = OFFSET_BOTTOM + HEIGHT;
            directcontent.MoveTo(llx, lly);
            directcontent.LineTo(urx, lly);
            directcontent.LineTo(urx, ury);
            directcontent.LineTo(llx, ury);
            directcontent.ClosePathStroke();

            directcontent.SetLineWidth(1);
            directcontent.MoveTo(
              OFFSET_LOCATION + WIDTH_LOCATION / 2, OFFSET_BOTTOM
            );
            directcontent.LineTo(
              OFFSET_LOCATION + WIDTH_LOCATION / 2, OFFSET_BOTTOM + HEIGHT
            );
            float y;
            for (int i = 1; i < LOCATIONS; i++)
            {
                y = OFFSET_BOTTOM + (i * HEIGHT_LOCATION);
                if (i == 2 || i == 6)
                {
                    directcontent.MoveTo(OFFSET_LOCATION, y);
                    directcontent.LineTo(OFFSET_LOCATION + WIDTH_LOCATION, y);
                }
                else
                {
                    directcontent.MoveTo(OFFSET_LOCATION + WIDTH_LOCATION / 2, y);
                    directcontent.LineTo(OFFSET_LOCATION + WIDTH_LOCATION, y);
                }
                directcontent.MoveTo(OFFSET_LEFT, y);
                directcontent.LineTo(OFFSET_LEFT + WIDTH, y);
            }
            directcontent.Stroke();
            directcontent.RestoreState();
        }
        private static void Render_FrontBase(PdfContentByte under, DateTime expiration)
        {
            float BORDER_WIDTH = 1.5f;

            // Draw background stripes and bars
            under.SaveState();
            under.SetRGBColorFill(0xff, 0x45, 0x00);
            under.Rectangle(0, CARD_HEIGHT - (UPPER_BAR_HEIGHT + PHOTO_BAR_HEIGHT + LOWER_BAR_HEIGHT), CARD_WIDTH, (UPPER_BAR_HEIGHT + PHOTO_BAR_HEIGHT + LOWER_BAR_HEIGHT));
            under.Fill();
            under.SetRGBColorFill(0x0, 0x0, 0x0);
            under.Rectangle(0, CARD_HEIGHT - (UPPER_BAR_HEIGHT + PHOTO_BAR_HEIGHT) - BORDER_WIDTH, CARD_WIDTH, PHOTO_BAR_HEIGHT + 2 * BORDER_WIDTH);
            under.Fill();
            under.SetRGBColorFill(0xff, 0xff, 0xff);
            under.Rectangle(0, CARD_HEIGHT - (UPPER_BAR_HEIGHT + PHOTO_BAR_HEIGHT), CARD_WIDTH, PHOTO_BAR_HEIGHT);
            under.Fill();
            under.RestoreState();

            var img = Image.GetInstance(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content", "images", "sheriff.png"));
            img.ScaleToFit(CARD_WIDTH - PHOTO_WIDTH - 8, PHOTO_BAR_HEIGHT);
            img.SetAbsolutePosition(
                ((CARD_WIDTH - PHOTO_WIDTH) - img.ScaledWidth) / 2,
                CARD_HEIGHT - (UPPER_BAR_HEIGHT + img.ScaledHeight) - 4);

            under.AddImage(img);

            Font f = new Font(baseFont, 8) { Color = BaseColor.WHITE };

            Phrase p = new Phrase("Expiration:", f);
            ColumnText.ShowTextAligned(under, Element.ALIGN_LEFT, p, 4, CARD_HEIGHT - 10, 0);
            p = new Phrase(expiration.ToString("MM/dd/yyyy"), f);
            ColumnText.ShowTextAligned(under, Element.ALIGN_RIGHT, p, CARD_WIDTH - 4, CARD_HEIGHT - 10, 0);

            f = new Font(baseFont, 11) { Color = BaseColor.WHITE };
            p = new Phrase("King County", f);
            ColumnText.ShowTextAligned(under, Element.ALIGN_CENTER, p, CARD_WIDTH / 2, CARD_HEIGHT - 34, 0);

            f = new Font(baseFont, 14, Font.BOLD) { Color = BaseColor.WHITE };

            p = new Phrase("Search & Rescue", f);
            ColumnText.ShowTextAligned(under, Element.ALIGN_CENTER, p, CARD_WIDTH / 2, CARD_HEIGHT - 49, 0);
        }
Beispiel #8
1
        private static void AddWaterMarkText(PdfContentByte directContent, string textWatermark, BaseFont font, float fontSize, float angle, BaseColor color, Rectangle realPageSize)
        {
            var gstate = new PdfGState { FillOpacity = 0.2f, StrokeOpacity = 0.2f };

            directContent.SaveState();
            directContent.SetGState(gstate);
            directContent.SetColorFill(color);
            directContent.BeginText();
            directContent.SetFontAndSize(font, fontSize);

            var x = (realPageSize.Right + realPageSize.Left) / 2;
            var y = (realPageSize.Bottom + realPageSize.Top) / 2;

            directContent.ShowTextAligned(Element.ALIGN_CENTER, textWatermark, x, y, angle);
            directContent.EndText();
            directContent.RestoreState();
        }
        private void DirectDrawReport(PdfContentByte canvas)
        {
            //画线
            canvas.SaveState();
            canvas.SetLineWidth(2f);
            canvas.MoveTo(100, 100);
            canvas.LineTo(200, 200);
            canvas.Stroke();
            canvas.RestoreState();

            //文本
            ColumnText.ShowTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("JulyLuo测试", new Font(BF_Light, 10)), 100, 20, 0);
        }
Beispiel #10
0
        }     //  end setGraphTitle

        private void AddWatermarkText(string sourceFile, string outputFile, string watermarkText, float watermarkFontSize, float watermarkFontOpacity, float watermarkRotation)
        {
            iTextSharp.text.pdf.PdfReader      reader       = null;
            iTextSharp.text.pdf.PdfStamper     stamper      = null;
            iTextSharp.text.pdf.PdfGState      gstate       = null;
            iTextSharp.text.pdf.PdfContentByte underContent = null;
            iTextSharp.text.Rectangle          rect         = null;

            int pageCount = 0;

            try
            {
                reader  = new iTextSharp.text.pdf.PdfReader(sourceFile);
                rect    = reader.GetPageSizeWithRotation(1);
                stamper = new PdfStamper(reader, new System.IO.FileStream(outputFile, System.IO.FileMode.CreateNew), '\0', true);

                iTextSharp.text.pdf.BaseFont watermarkFont = iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.COURIER,
                                                                                                     iTextSharp.text.pdf.BaseFont.CP1252, iTextSharp.text.pdf.BaseFont.NOT_EMBEDDED);
                gstate               = new iTextSharp.text.pdf.PdfGState();
                gstate.FillOpacity   = watermarkFontOpacity;
                gstate.StrokeOpacity = watermarkFontOpacity;
                pageCount            = reader.NumberOfPages;
                for (int i = 1; i <= pageCount; i++)
                {
                    underContent = stamper.GetUnderContent(i);
                    underContent.SaveState();
                    underContent.SetGState(gstate);
                    underContent.SetColorFill(iTextSharp.text.BaseColor.DARK_GRAY);
                    underContent.BeginText();
                    underContent.SetFontAndSize(watermarkFont, watermarkFontSize);
                    underContent.SetTextMatrix(30, 30);
                    underContent.ShowTextAligned(iTextSharp.text.Element.ALIGN_CENTER, watermarkText, rect.Width / 2, rect.Height / 2, watermarkRotation);
                    underContent.EndText();
                    underContent.RestoreState();
                }   //  end for i loop

                stamper.Close();
                reader.Close();
            }   //  end try
            catch (Exception ex)
            {
                throw ex;
            } //  end
            return;
        }     //  end AddWatermark
Beispiel #11
0
// ---------------------------------------------------------------------------        
    /**
     * Draws a colored block on the time table, corresponding with
     * the screening of a specific movie.
     * @param    screening    a screening POJO, contains a movie and a category
     * @param    under    the canvas to which the block is drawn
     */
    protected void DrawBlock(
      Screening screening, PdfContentByte under, PdfContentByte over
    ) {
      under.SaveState();
      BaseColor color = WebColors.GetRGBColor(
        "#" + screening.movie.entry.category.color
      );
      under.SetColorFill(color);
      Rectangle rect = GetPosition(screening);
      under.Rectangle(
        rect.Left, rect.Bottom, rect.Width, rect.Height
      );
      under.Fill();
      over.Rectangle(
        rect.Left, rect.Bottom, rect.Width, rect.Height
      );
      over.Stroke();
      under.RestoreState();
    }
Beispiel #12
0
        private static void Render_BackBase(PdfContentByte under)
        {
            // Y relative to card top, line width, <repeat>
            float[] measures = new[] { 37, 3f, 144, 1.5f };

            under.SaveState();
            for (int i = 0; i < measures.Length / 2; i++)
            {
                under.SetLineWidth(measures[i * 2 + 1]);
                under.MoveTo(0, CARD_HEIGHT - measures[i * 2]);
                under.LineTo(CARD_WIDTH, CARD_HEIGHT - measures[i * 2]);
                under.Stroke();
            }

            under.SetFontAndSize(baseFont, 7);
            under.ShowTextAlignedKerned(Element.ALIGN_CENTER, "If found, please call KCSAR at (206) 205-8226", CARD_WIDTH / 2, 7, 0);

            under.RestoreState();
        }
Beispiel #13
0
// ---------------------------------------------------------------------------    
    /**
     * Draws a row of squares.
     * @param canvas the canvas to which the squares have to be drawn
     * @param x      X coordinate to position the row
     * @param y      Y coordinate to position the row
     * @param side   the side of the square
     * @param gutter the space between the squares
     */
    public void CreateSquares(PdfContentByte canvas,
      float x, float y, float side, float gutter) {
      canvas.SaveState();
      canvas.SetColorStroke(new GrayColor(0.2f));
      canvas.SetColorFill(new GrayColor(0.9f));
      canvas.MoveTo(x, y);
      canvas.LineTo(x + side, y);
      canvas.LineTo(x + side, y + side);
      canvas.LineTo(x, y + side);
      canvas.Stroke();
      x = x + side + gutter;
      canvas.MoveTo(x, y);
      canvas.LineTo(x + side, y);
      canvas.LineTo(x + side, y + side);
      canvas.LineTo(x, y + side);
      canvas.ClosePathStroke();
      x = x + side + gutter;
      canvas.MoveTo(x, y);
      canvas.LineTo(x + side, y);
      canvas.LineTo(x + side, y + side);
      canvas.LineTo(x, y + side);
      canvas.Fill();
      x = x + side + gutter;
      canvas.MoveTo(x, y);
      canvas.LineTo(x + side, y);
      canvas.LineTo(x + side, y + side);
      canvas.LineTo(x, y + side);
      canvas.FillStroke();
      x = x + side + gutter;
      canvas.MoveTo(x, y);
      canvas.LineTo(x + side, y);
      canvas.LineTo(x + side, y + side);
      canvas.LineTo(x, y + side);
      canvas.ClosePathFillStroke();
      canvas.RestoreState();
    }
Beispiel #14
0
        virtual public int Layout(PdfContentByte canvas, bool useAscender, bool simulate, float llx, float lly, float urx, float ury)
        {
            float leftX = Math.Min(llx, urx);
            float maxY = Math.Max(lly, ury);
            float minY = Math.Min(lly, ury);
            float rightX = Math.Max(llx, urx);
            yLine = maxY;
            bool contentCutByFixedHeight = false;

            if (width != null && width > 0)
            {
                if (width < rightX - leftX)
                    rightX = leftX + (float) width;
                else if (width > rightX - leftX)
                    return ColumnText.NO_MORE_COLUMN;
            }
            else if (percentageWidth != null)
            {
                contentWidth = (rightX - leftX)*(float) percentageWidth;
                rightX = leftX + contentWidth;
            }
            else if (percentageWidth == null) 
            {
                if (this.floatType == FloatType.NONE && (this.display == DisplayType.DEFAULT_NULL_VALUE ||
                    this.display == DisplayType.BLOCK || this.display == DisplayType.LIST_ITEM ||
                    this.display == DisplayType.RUN_IN)) 
                {
                    contentWidth = rightX - leftX;
                }
            }

            if (height != null && height > 0)
            {
                if (height < maxY - minY)
                {
                    contentCutByFixedHeight = true;
                    minY = maxY - (float) height;
                }
                else if (height > maxY - minY)
                {
                    return ColumnText.NO_MORE_COLUMN;
                }
            }
            else if (percentageHeight != null)
            {
                if (percentageHeight < 1.0)
                    contentCutByFixedHeight = true;
                contentHeight = (maxY - minY)*(float) percentageHeight;
                minY = maxY - contentHeight;
            }

            if (!simulate && position == PdfDiv.PositionType.RELATIVE)
            {
                float? translationX = null;
                if (left != null)
                    translationX = left;
                else if (right != null)
                    translationX = -right;
                else
                    translationX = 0f;

                float? translationY = null;
                if (top != null)
                    translationY = -top;
                else if (bottom != null)
                    translationY = bottom;
                else
                    translationY = 0f;
                canvas.SaveState();
                canvas.Transform(new AffineTransform(1f, 0, 0, 1f, translationX.Value, translationY.Value));
            }

            if (!simulate)
            {
                if ((backgroundColor != null || backgroundImage != null) && getActualWidth() > 0 && getActualHeight() > 0)
                {
                    float backgroundWidth = getActualWidth();
                    float backgroundHeight = getActualHeight();
                    if (width != null)
                        backgroundWidth = width > 0 ? (float) width : 0;
                    if (height != null)
                        backgroundHeight = height > 0 ? (float) height : 0;
                    if (backgroundWidth > 0 && backgroundHeight > 0)
                    {
                        Rectangle background = new Rectangle(leftX, maxY - backgroundHeight, leftX + backgroundWidth, maxY);
                        if (backgroundColor != null) {
                            background.BackgroundColor = backgroundColor;
                            PdfArtifact artifact = new PdfArtifact();
                            canvas.OpenMCBlock(artifact);
                            canvas.Rectangle(background);
                            canvas.CloseMCBlock(artifact);
                        }
                        if (backgroundImage != null) {
                            if (backgroundImageWidth == null) {
                                backgroundImage.ScaleToFit(background);
                            }
                            else {
                                backgroundImage.ScaleAbsolute((float)backgroundImageWidth, backgroundImageHeight);
                            }
                            backgroundImage.SetAbsolutePosition(background.Left, background.Bottom);
                            canvas.OpenMCBlock(backgroundImage);
                            canvas.AddImage(backgroundImage);
                            canvas.CloseMCBlock(backgroundImage);
                        }
                    }
                }
            }

            if (percentageWidth == null)
                contentWidth = 0;
            if (percentageHeight == null)
                contentHeight = 0;

            minY += paddingBottom;
            leftX += paddingLeft;
            rightX -= paddingRight;

            yLine -= paddingTop;

            int status = ColumnText.NO_MORE_TEXT;

            if (content.Count > 0) {
                if (floatLayout == null) {
                    List<IElement> floatingElements = new List<IElement>(content);
                    floatLayout = new FloatLayout(floatingElements, useAscender);
                    floatLayout.RunDirection = runDirection;
                }

                floatLayout.SetSimpleColumn(leftX, minY, rightX, yLine);
                if (borderTopStyle != BorderTopStyle.NONE)
                    floatLayout.compositeColumn.IgnoreSpacingBefore = false;
                status = floatLayout.Layout(canvas, simulate);
                yLine = floatLayout.YLine;

                if (percentageWidth == null && contentWidth < floatLayout.FilledWidth) {
                    contentWidth = floatLayout.FilledWidth;
                }
            }


            if (!simulate && position == PdfDiv.PositionType.RELATIVE)
                canvas.RestoreState();

            yLine -= paddingBottom;
            if (percentageHeight == null)
                contentHeight = maxY - yLine;

            if (percentageWidth == null)
                contentWidth += paddingLeft + paddingRight;

            return contentCutByFixedHeight ? ColumnText.NO_MORE_TEXT : status;
        }
Beispiel #15
0
        /**
        * Writes a text line to the document. It takes care of all the attributes.
        * <P>
        * Before entering the line position must have been established and the
        * <CODE>text</CODE> argument must be in text object scope (<CODE>beginText()</CODE>).
        * @param line the line to be written
        * @param text the <CODE>PdfContentByte</CODE> where the text will be written to
        * @param graphics the <CODE>PdfContentByte</CODE> where the graphics will be written to
        * @param currentValues the current font and extra spacing values
        * @param ratio
        * @throws DocumentException on error
        */
        internal float WriteLineToContent(PdfLine line, PdfContentByte text, PdfContentByte graphics, Object[] currentValues, float ratio)  {
            PdfFont currentFont = (PdfFont)(currentValues[0]);
            float lastBaseFactor = (float)currentValues[1];
            //PdfChunk chunkz;
            int numberOfSpaces;
            int lineLen;
            bool isJustified;
            float hangingCorrection = 0;
            float hScale = 1;
            float lastHScale = float.NaN;
            float baseWordSpacing = 0;
            float baseCharacterSpacing = 0;
            float glueWidth = 0;
            float lastX = text.XTLM + line.OriginalWidth;
            
            numberOfSpaces = line.NumberOfSpaces;
            lineLen = line.GetLineLengthUtf32();
            // does the line need to be justified?
            isJustified = line.HasToBeJustified() && (numberOfSpaces != 0 || lineLen > 1);
            int separatorCount = line.GetSeparatorCount();
            if (separatorCount > 0) {
                glueWidth = line.WidthLeft / separatorCount;
            }
            else if (isJustified && separatorCount == 0) {
                if (line.NewlineSplit && line.WidthLeft >= (lastBaseFactor * (ratio * numberOfSpaces + lineLen - 1))) {
                    if (line.RTL) {
                        text.MoveText(line.WidthLeft - lastBaseFactor * (ratio * numberOfSpaces + lineLen - 1), 0);
                    }
                    baseWordSpacing = ratio * lastBaseFactor;
                    baseCharacterSpacing = lastBaseFactor;
                }
                else {
                    float width = line.WidthLeft;
                    PdfChunk last = line.GetChunk(line.Size - 1);
                    if (last != null) {
                        String s = last.ToString();
                        char c;
                        if (s.Length > 0 && hangingPunctuation.IndexOf((c = s[s.Length - 1])) >= 0) {
                            float oldWidth = width;
                            width += last.Font.Width(c) * 0.4f;
                            hangingCorrection = width - oldWidth;
                        }
                    }
                    float baseFactor = width / (ratio * numberOfSpaces + lineLen - 1);
                    baseWordSpacing = ratio * baseFactor;
                    baseCharacterSpacing = baseFactor;
                    lastBaseFactor = baseFactor;
                }
            } else if (line.alignment == Element.ALIGN_LEFT || line.alignment == Element.ALIGN_UNDEFINED) {
                lastX -= line.WidthLeft;
            }
            
            int lastChunkStroke = line.LastStrokeChunk;
            int chunkStrokeIdx = 0;
            float xMarker = text.XTLM;
            float baseXMarker = xMarker;
            float yMarker = text.YTLM;
            bool adjustMatrix = false;
            float tabPosition = 0;

            bool isMCBlockOpened = false;
            // looping over all the chunks in 1 line
            foreach (PdfChunk chunk in line) {
                if (IsTagged(writer) && chunk.accessibleElement != null) {
                    text.OpenMCBlock(chunk.accessibleElement);
                    isMCBlockOpened = true;
                }
                BaseColor color = chunk.Color;
                float fontSize = chunk.Font.Size;
                float ascender;
                float descender;
                if (chunk.IsImage())
                {
                    ascender = chunk.Height();
                    descender = 0;
                }
                else
                {
                    ascender = chunk.Font.Font.GetFontDescriptor(BaseFont.ASCENT, fontSize);
                    descender = chunk.Font.Font.GetFontDescriptor(BaseFont.DESCENT, fontSize);
                }
                hScale = 1;
                
                if (chunkStrokeIdx <= lastChunkStroke) {
                    float width;
                    if (isJustified) {
                        width = chunk.GetWidthCorrected(baseCharacterSpacing, baseWordSpacing);
                    }
                    else {
                        width = chunk.Width();
                    }
                    if (chunk.IsStroked()) {
                        PdfChunk nextChunk = line.GetChunk(chunkStrokeIdx + 1);
                        if (chunk.IsSeparator()) {
                            width = glueWidth;
                            Object[] sep = (Object[])chunk.GetAttribute(Chunk.SEPARATOR);
                            IDrawInterface di = (IDrawInterface)sep[0];
                            bool vertical = (bool)sep[1];
                            if (vertical) {
                                di.Draw(graphics, baseXMarker, yMarker + descender, baseXMarker + line.OriginalWidth, ascender - descender, yMarker);      
                            }
                            else {
                                di.Draw(graphics, xMarker, yMarker + descender, xMarker + width, ascender - descender, yMarker);
                            }
                        }
                        if (chunk.IsTab()) {
                            if (chunk.IsAttribute(Chunk.TABSETTINGS))
                            {
                                TabStop tabStop = chunk.TabStop;
                                if (tabStop != null) {
                                    tabPosition = tabStop.Position + baseXMarker;
                                    if (tabStop.Leader != null)
                                        tabStop.Leader.Draw(graphics, xMarker, yMarker + descender, tabPosition, ascender - descender, yMarker);
                                }
                                else {
                                    tabPosition = xMarker;
                                }
                            } else {
                                //Keep deprecated tab logic for backward compatibility...
                                Object[] tab = (Object[])chunk.GetAttribute(Chunk.TAB);
                                IDrawInterface di = (IDrawInterface)tab[0];
                                tabPosition = (float)tab[1] + (float)tab[3];
                                if (tabPosition > xMarker)
                                    di.Draw(graphics, xMarker, yMarker + descender, tabPosition, ascender - descender, yMarker);
                            }
                            float tmp = xMarker;
                            xMarker = tabPosition;
                            tabPosition = tmp;
                        }
                        if (chunk.IsAttribute(Chunk.BACKGROUND)) {
                             Object[] bgr = (Object[])chunk.GetAttribute(Chunk.BACKGROUND);
                            if (bgr[0] != null) {
                                bool inText = graphics.InText;
                                if (inText && IsTagged(writer)) {
                                    graphics.EndText();
                                }
                                graphics.SaveState();
                                float subtract = lastBaseFactor;
                                if (nextChunk != null && nextChunk.IsAttribute(Chunk.BACKGROUND)) {
                                    subtract = 0;
                                }
                                if (nextChunk == null) {
                                    subtract += hangingCorrection;
                                }
                                BaseColor c = (BaseColor)bgr[0];
                                graphics.SetColorFill(c);
                                float[] extra = (float[]) bgr[1];
                                graphics.Rectangle(xMarker - extra[0],
                                        yMarker + descender - extra[1] + chunk.TextRise,
                                        width - subtract + extra[0] + extra[2],
                                        ascender - descender + extra[1] + extra[3]);
                                graphics.Fill();
                                graphics.SetGrayFill(0);
                                graphics.RestoreState();
                                if (inText && IsTagged(writer)) {
                                    graphics.BeginText(true);
                                }
                        }
                        }
                        if (chunk.IsAttribute(Chunk.UNDERLINE)) {
                            bool inText = graphics.InText;
                            if (inText && IsTagged(writer)) {
                                graphics.EndText();
                            }
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.UNDERLINE))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            Object[][] unders = (Object[][])chunk.GetAttribute(Chunk.UNDERLINE);
                            BaseColor scolor = null;
                            for (int k = 0; k < unders.Length; ++k) {
                                Object[] obj = unders[k];
                                scolor = (BaseColor)obj[0];
                                float[] ps = (float[])obj[1];
                                if (scolor == null)
                                    scolor = color;
                                if (scolor != null)
                                    graphics.SetColorStroke(scolor);
                                graphics.SetLineWidth(ps[0] + fontSize * ps[1]);
                                float shift = ps[2] + fontSize * ps[3];
                                int cap2 = (int)ps[4];
                                if (cap2 != 0)
                                    graphics.SetLineCap(cap2);
                                graphics.MoveTo(xMarker, yMarker + shift);
                                graphics.LineTo(xMarker + width - subtract, yMarker + shift);
                                graphics.Stroke();
                                if (scolor != null)
                                    graphics.ResetGrayStroke();
                                if (cap2 != 0)
                                    graphics.SetLineCap(0);
                            }
                            graphics.SetLineWidth(1);
                            if (inText && IsTagged(writer)) {
                                graphics.BeginText(true);
                            }
                        }
                        if (chunk.IsAttribute(Chunk.ACTION)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.ACTION))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            PdfAnnotation annot = null;
                            if (chunk.IsImage()) {
                                annot = writer.CreateAnnotation(xMarker, yMarker + chunk.ImageOffsetY, xMarker + width - subtract, yMarker + chunk.ImageHeight + chunk.ImageOffsetY, (PdfAction)chunk.GetAttribute(Chunk.ACTION), null);
                            }
                            else {
                                annot = writer.CreateAnnotation(xMarker, yMarker + descender + chunk.TextRise, xMarker + width - subtract, yMarker + ascender + chunk.TextRise, (PdfAction)chunk.GetAttribute(Chunk.ACTION), null);
                            }
                            text.AddAnnotation(annot, true);
                            if (IsTagged(writer) && chunk.accessibleElement != null) {
                                PdfStructureElement strucElem;
                                structElements.TryGetValue(chunk.accessibleElement.ID, out strucElem);
                                if (strucElem != null) {
                                    int structParent = GetStructParentIndex(annot);
                                    annot.Put(PdfName.STRUCTPARENT, new PdfNumber(structParent));
                                    strucElem.SetAnnotation(annot, writer.CurrentPage);
                                    writer.StructureTreeRoot.SetAnnotationMark(structParent, strucElem.Reference);
                                }
                            }
                        }
                        if (chunk.IsAttribute(Chunk.REMOTEGOTO)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.REMOTEGOTO))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            Object[] obj = (Object[])chunk.GetAttribute(Chunk.REMOTEGOTO);
                            String filename = (String)obj[0];
                            if (obj[1] is String)
                                RemoteGoto(filename, (String)obj[1], xMarker, yMarker + descender + chunk.TextRise, xMarker + width - subtract, yMarker + ascender + chunk.TextRise);
                            else
                                RemoteGoto(filename, (int)obj[1], xMarker, yMarker + descender + chunk.TextRise, xMarker + width - subtract, yMarker + ascender + chunk.TextRise);
                        }
                        if (chunk.IsAttribute(Chunk.LOCALGOTO)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.LOCALGOTO))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            LocalGoto((String)chunk.GetAttribute(Chunk.LOCALGOTO), xMarker, yMarker, xMarker + width - subtract, yMarker + fontSize);
                        }
                        if (chunk.IsAttribute(Chunk.LOCALDESTINATION)) {
                            /*float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.LOCALDESTINATION))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;*/
                            LocalDestination((String)chunk.GetAttribute(Chunk.LOCALDESTINATION), new PdfDestination(PdfDestination.XYZ, xMarker, yMarker + fontSize, 0));
                        }
                        if (chunk.IsAttribute(Chunk.GENERICTAG)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.GENERICTAG))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            Rectangle rect = new Rectangle(xMarker, yMarker, xMarker + width - subtract, yMarker + fontSize);
                            IPdfPageEvent pev = writer.PageEvent;
                            if (pev != null)
                                pev.OnGenericTag(writer, this, rect, (String)chunk.GetAttribute(Chunk.GENERICTAG));
                        }
                        if (chunk.IsAttribute(Chunk.PDFANNOTATION)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.PDFANNOTATION))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            PdfAnnotation annot = PdfFormField.ShallowDuplicate((PdfAnnotation)chunk.GetAttribute(Chunk.PDFANNOTATION));
                            annot.Put(PdfName.RECT, new PdfRectangle(xMarker, yMarker + descender, xMarker + width - subtract, yMarker + ascender));
                            text.AddAnnotation(annot, true);
                        }
                        float[] paramsx = (float[])chunk.GetAttribute(Chunk.SKEW);
                        object hs = chunk.GetAttribute(Chunk.HSCALE);
                        if (paramsx != null || hs != null) {
                            float b = 0, c = 0;
                            if (paramsx != null) {
                                b = paramsx[0];
                                c = paramsx[1];
                            }
                            if (hs != null)
                                hScale = (float)hs;
                            text.SetTextMatrix(hScale, b, c, 1, xMarker, yMarker);
                        }
                        if (!isJustified) {
                            if (chunk.IsAttribute(Chunk.WORD_SPACING)) {
                                float ws = (float) chunk.GetAttribute(Chunk.WORD_SPACING);
                                text.SetWordSpacing(ws);
                            }

                            if (chunk.IsAttribute(Chunk.CHAR_SPACING)) {
                                float? cs = (float?) chunk.GetAttribute(Chunk.CHAR_SPACING);
                                text.SetCharacterSpacing(cs.Value);
                            }
                        }
                        if (chunk.IsImage()) {
                            Image image = chunk.Image;
                            width = chunk.ImageWidth;
                            float[] matrix = image.GetMatrix(chunk.ImageScalePercentage);
                            matrix[Image.CX] = xMarker + chunk.ImageOffsetX - matrix[Image.CX];
                            matrix[Image.CY] = yMarker + chunk.ImageOffsetY - matrix[Image.CY];
                            graphics.AddImage(image, matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5], false, isMCBlockOpened);
                            text.MoveText(xMarker + lastBaseFactor + chunk.ImageWidth - text.XTLM, 0);
                        }
                    }

                    xMarker += width;
                    ++chunkStrokeIdx;
                }

                if (!chunk.IsImage() && chunk.Font.CompareTo(currentFont) != 0) {
                    currentFont = chunk.Font;
                    text.SetFontAndSize(currentFont.Font, currentFont.Size);
                }
                float rise = 0;
                Object[] textRender = (Object[])chunk.GetAttribute(Chunk.TEXTRENDERMODE);
                int tr = 0;
                float strokeWidth = 1;
                BaseColor strokeColor = null;
                object fr = chunk.GetAttribute(Chunk.SUBSUPSCRIPT);
                if (textRender != null) {
                    tr = (int)textRender[0] & 3;
                    if (tr != PdfContentByte.TEXT_RENDER_MODE_FILL)
                        text.SetTextRenderingMode(tr);
                    if (tr == PdfContentByte.TEXT_RENDER_MODE_STROKE || tr == PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE) {
                        strokeWidth = (float)textRender[1];
                        if (strokeWidth != 1)
                            text.SetLineWidth(strokeWidth);
                        strokeColor = (BaseColor)textRender[2];
                        if (strokeColor == null)
                            strokeColor = color;
                        if (strokeColor != null)
                            text.SetColorStroke(strokeColor);
                    }
                }
                if (fr != null)
                    rise = (float)fr;
                if (color != null)
                    text.SetColorFill(color);
                if (rise != 0)
                    text.SetTextRise(rise);
                if (chunk.IsImage()) {
                    adjustMatrix = true;
                }
                else if (chunk.IsHorizontalSeparator()) {
                    PdfTextArray array = new PdfTextArray();
                    array.Add(-glueWidth * 1000f / chunk.Font.Size / hScale);
                    text.ShowText(array);
                }
                else if (chunk.IsTab() && tabPosition != xMarker)
                {
                    PdfTextArray array = new PdfTextArray();
                    array.Add((tabPosition - xMarker) * 1000f / chunk.Font.Size / hScale);
                    text.ShowText(array);
                }
                
                // If it is a CJK chunk or Unicode TTF we will have to simulate the
                // space adjustment.
                else if (isJustified && numberOfSpaces > 0 && chunk.IsSpecialEncoding()) {
                    if (hScale != lastHScale) {
                        lastHScale = hScale;
                        text.SetWordSpacing(baseWordSpacing / hScale);
                        text.SetCharacterSpacing(baseCharacterSpacing / hScale + text.CharacterSpacing);
                    }
                    String s = chunk.ToString();
                    int idx = s.IndexOf(' ');
                    if (idx < 0)
                        text.ShowText(s);
                    else {
                        float spaceCorrection = - baseWordSpacing * 1000f / chunk.Font.Size / hScale;
                        PdfTextArray textArray = new PdfTextArray(s.Substring(0, idx));
                        int lastIdx = idx;
                        while ((idx = s.IndexOf(' ', lastIdx + 1)) >= 0) {
                            textArray.Add(spaceCorrection);
                            textArray.Add(s.Substring(lastIdx, idx - lastIdx));
                            lastIdx = idx;
                        }
                        textArray.Add(spaceCorrection);
                        textArray.Add(s.Substring(lastIdx));
                        text.ShowText(textArray);
                    }
                }
                else {
                    if (isJustified && hScale != lastHScale) {
                        lastHScale = hScale;
                        text.SetWordSpacing(baseWordSpacing / hScale);
                        text.SetCharacterSpacing(baseCharacterSpacing / hScale + text.CharacterSpacing);
                    }
                    text.ShowText(chunk.ToString());
                }
                
                if (rise != 0)
                    text.SetTextRise(0);
                if (color != null)
                    text.ResetRGBColorFill();
                if (tr != PdfContentByte.TEXT_RENDER_MODE_FILL)
                    text.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
                if (strokeColor != null)
                    text.ResetRGBColorStroke();
                if (strokeWidth != 1)
                    text.SetLineWidth(1);            
                if (chunk.IsAttribute(Chunk.SKEW) || chunk.IsAttribute(Chunk.HSCALE)) {
                    adjustMatrix = true;
                    text.SetTextMatrix(xMarker, yMarker);
                }
                if (!isJustified) {
                    if (chunk.IsAttribute(Chunk.CHAR_SPACING)) {
                        text.SetCharacterSpacing(baseCharacterSpacing);
                    }
                    if (chunk.IsAttribute(Chunk.WORD_SPACING)) {
                        text.SetWordSpacing(baseWordSpacing);
                    }
                }
                if (IsTagged(writer) && chunk.accessibleElement != null) {
                    text.CloseMCBlock(chunk.accessibleElement);
                }
            }
            if (isJustified) {
                text.SetWordSpacing(0);
                text.SetCharacterSpacing(0);
                if (line.NewlineSplit)
                    lastBaseFactor = 0;
            }
            if (adjustMatrix)
                text.MoveText(baseXMarker - text.XTLM, 0);
            currentValues[0] = currentFont;
            currentValues[1] = lastBaseFactor;
            return lastX;
        }
Beispiel #16
0
 /**
 * Writes the selected rows to the document.
 * This method clips the columns; this is only important
 * if there are columns with colspan at boundaries.
 * <P>
 * The table event is only fired for complete rows.
 *
 * @param colStart the first column to be written, zero index
 * @param colEnd the last column to be written + 1. If it is -1 all the
 * @param rowStart the first row to be written, zero index
 * @param rowEnd the last row to be written + 1. If it is -1 all the
 * rows to the end are written
 * @param xPos the x write coodinate
 * @param yPos the y write coodinate
 * @param canvas the <CODE>PdfContentByte</CODE> where the rows will
 * be written to
 * @return the y coordinate position of the bottom of the last row
 */
 public float WriteSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte canvas)
 {
     if (colEnd < 0)
         colEnd = absoluteWidths.Length;
     colEnd = Math.Min(colEnd, absoluteWidths.Length);
     if (colStart < 0)
         colStart = 0;
     colStart = Math.Min(colStart, absoluteWidths.Length);
     if (colStart != 0 || colEnd != absoluteWidths.Length) {
         float w = 0;
         for (int k = colStart; k < colEnd; ++k)
             w += absoluteWidths[k];
         canvas.SaveState();
         float lx = 0;
         float rx = 0;
         if (colStart == 0)
             lx = 10000;
         if (colEnd == absoluteWidths.Length)
             rx = 10000;
         canvas.Rectangle(xPos - lx, -10000, w + lx + rx, 20000);
         canvas.Clip();
         canvas.NewPath();
     }
     PdfContentByte[] canvases = BeginWritingRows(canvas);
     float y = WriteSelectedRows(colStart, colEnd, rowStart, rowEnd, xPos, yPos, canvases);
     EndWritingRows(canvases);
     if (colStart != 0 || colEnd != absoluteWidths.Length)
         canvas.RestoreState();
     return y;
 }
        private void DrawOverlayText(PdfContentByte canvas, IList<Rectangle> textRectangles, PdfString overlayText, 
                                     PdfString otDA, PdfNumber otQ, PdfBoolean otRepeat) {
            ColumnText ct = new ColumnText(canvas);
            ct.SetLeading(0, 1.2F);
            ct.UseAscender = true;

            String otStr = overlayText.ToUnicodeString();

            canvas.SaveState();
            IDictionary<string, IList<object>> parsedDA = ParseDAParam(otDA);

            Font font = null;

            if (parsedDA.ContainsKey(STROKE_COLOR)) {
                IList<object> strokeColorArgs = parsedDA[STROKE_COLOR];
                SetStrokeColor(canvas, strokeColorArgs);
            }

            if (parsedDA.ContainsKey(FILL_COLOR)) {
                IList<object> fillColorArgs = parsedDA[FILL_COLOR];
                SetFillColor(canvas, fillColorArgs);
            }

            if (parsedDA.ContainsKey("Tf")) {
                IList<object> tfArgs = parsedDA["Tf"];
                font = RetrieveFontFromAcroForm((PdfName) tfArgs[0], (PdfNumber) tfArgs[1]);
            }

            foreach (Rectangle textRect in textRectangles) {
                ct.SetSimpleColumn(textRect);

                if (otQ != null) {
                    ct.Alignment = otQ.IntValue;
                }

                Phrase otPhrase;

                if (font != null) {
                    otPhrase = new Phrase(otStr, font);
                } else {
                    otPhrase = new Phrase(otStr);
                }

                float y = ct.YLine;

                if (otRepeat != null && otRepeat.BooleanValue) {
                    int status = ct.Go(true);

                    while (!ColumnText.HasMoreText(status)) {
                        otPhrase.Add(otStr);
                        ct.SetText(otPhrase);
                        ct.YLine = y;
                        status = ct.Go(true);
                    }
                }

                ct.SetText(otPhrase);
                ct.YLine = y;
                ct.Go();
            }

            canvas.RestoreState();
        }
 // ---------------------------------------------------------------------------
 /**
  * Draws the image of the month to the calendar.
  * @param canvas the direct content layer
  * @param dt the DateTime (to know which picture to use)
  */
 public void DrawImageAndText(PdfContentByte canvas, DateTime dt)
 {
     string MM = dt.ToString("MM");
     // get the image
     Image img = Image.GetInstance(Path.Combine(
       RESOURCE, MM + ".jpg"
     ));
     img.ScaleToFit(PageSize.A4.Height, PageSize.A4.Width);
     img.SetAbsolutePosition(
       (PageSize.A4.Height - img.ScaledWidth) / 2,
       (PageSize.A4.Width - img.ScaledHeight) / 2
     );
     canvas.AddImage(img);
     // add metadata
     canvas.SaveState();
     canvas.SetCMYKColorFill(0x00, 0x00, 0x00, 0x80);
     Phrase p = new Phrase(string.Format(
         "{0} - \u00a9 Katharine Osborne",
         content[string.Format("{0}.jpg", dt.ToString("MM"))]
       ),
       small
     );
     ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, p, 5, 5, 0);
     p = new Phrase(
       "Calendar generated using iText - example for the book iText in Action 2nd Edition",
       small
     );
     ColumnText.ShowTextAligned(canvas, Element.ALIGN_RIGHT, p, 839, 5, 0);
     canvas.RestoreState();
 }
        public static Point DrawUpperRectangle(PdfContentByte content, Rectangle pageRect, float barSize)
        {
            content.SaveState();
            var state = new PdfGState {FillOpacity = FillOpacity};
            content.SetGState(state);
            content.SetColorFill(BaseColor.BLACK);

            content.SetLineWidth(0);
            var result = new Point(SideBorder + BorderPage,
                                   pageRect.Height - (BorderPage + LeaderEdge + BarHeight + 1));
            content.Rectangle(result.X, result.Y, barSize, BarHeight);
            content.ClosePathFillStroke();
            content.RestoreState();
            return result;
        }
        /// <summary>
        /// Draws the diamont.
        /// </summary>
        /// <param name="content">The content.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        public static void DrawDiamont(PdfContentByte content, float x, float y)
        {
            content.SaveState();
            var state = new PdfGState();
            content.SetGState(state);
            content.SetColorFill(BaseColor.BLACK);
            content.MoveTo(x, y);
            var sPoint = new Point(x, y);
            var uMPoint = new Point(x + WPosMarkerMid, y + HPosMarkerMid);
            var rPoint = new Point(uMPoint.X + WPosMarkerMid, uMPoint.Y - HPosMarkerMid);
            var mPoint = new Point(rPoint.X - WPosMarkerMid, rPoint.Y - HPosMarkerMid);

            DrawLines(content, uMPoint, rPoint, mPoint, sPoint);

            content.ClosePathFillStroke();
            content.RestoreState();
        }
Beispiel #21
0
// ---------------------------------------------------------------------------    
    /**
     * Draws the time slots for a day at the film festival.
     * @param directcontent the canvas to which the time table has to be drawn.
     */
    protected void DrawTimeSlots(PdfContentByte directcontent) {
      directcontent.SaveState();
      float x;
      for (int i = 1; i < TIMESLOTS; i++) {
        x = OFFSET_LEFT + (i * WIDTH_TIMESLOT);
        directcontent.MoveTo(x, OFFSET_BOTTOM);
        directcontent.LineTo(x, OFFSET_BOTTOM + HEIGHT);
      }
      directcontent.SetLineWidth(0.3f);
      directcontent.SetColorStroke(BaseColor.GRAY);
      directcontent.SetLineDash(3, 1);
      directcontent.Stroke();
      directcontent.RestoreState();
    }    
        public static void DrawSquare(PdfContentByte content, Point point, System.Data.IDataReader reader)
        {
            content.SaveState();
            var state = new PdfGState {FillOpacity = FillOpacity};
            content.SetGState(state);
            var color = new CMYKColor(reader.GetFloat(1), reader.GetFloat(2), reader.GetFloat(3), reader.GetFloat(4));
            content.SetColorFill(color);

            content.SetLineWidth(0);
            content.Rectangle(point.X, point.Y, PatchSize, PatchSize);
            content.Fill();
            content.RestoreState();
        }
        private void AddColoredRectangle(PdfContentByte canvas, PdfCleanUpLocation cleanUpLocation) {
            Rectangle cleanUpRegion = cleanUpLocation.Region;

            canvas.SaveState();
            canvas.SetColorFill(cleanUpLocation.CleanUpColor);
            canvas.MoveTo(cleanUpRegion.Left, cleanUpRegion.Bottom);
            canvas.LineTo(cleanUpRegion.Right, cleanUpRegion.Bottom);
            canvas.LineTo(cleanUpRegion.Right, cleanUpRegion.Top);
            canvas.LineTo(cleanUpRegion.Left, cleanUpRegion.Top);
            canvas.ClosePath();
            canvas.Fill();
            canvas.RestoreState();
        }
 public virtual void ColorRectangle(PdfContentByte canvas,
     BaseColor color, float x, float y, float width, float height) {
     canvas.SaveState();
     canvas.SetColorFill(color);
     canvas.Rectangle(x, y, width, height);
     canvas.FillStroke();
     canvas.RestoreState();
 }
Beispiel #25
0
        private void ShowText(PdfContentByte cb, float x, float y, float xPrevious, float yPrevious, double xmidden, double ymidden, String character)
        {
            double corner = CalculateCorner(x, y, xPrevious, yPrevious);
            cb.SaveState();
            PdfTemplate template2 = cb.CreateTemplate(1000, 1000);

            template2.BeginText();
            template2.SetColorFill(BaseColor.BLACK);
            BaseFont bf = BaseFont.CreateFont();
            template2.SetFontAndSize(bf, fontsize);
            //template2.SetTextRise(10);
            //double halfWidthOfCharacter = cb.GetEffectiveStringWidth(character+"", true) / 2.0;  
            template2.SetTextMatrix(0, 0);
            template2.ShowText(character + "");
            template2.EndText();
            Matrix translation = new Matrix();
            translation.Translate((float)xmidden, (float)ymidden);
            cb.ConcatCTM(translation);
            Matrix rotation = new Matrix();
            rotation.Rotate((float)corner);
            cb.ConcatCTM(rotation);
            cb.ConcatCTM(1, 0, 0, -1, 0, 0);
            cb.AddTemplate(template2, 0, 0);
            cb.RestoreState();
        }
Beispiel #26
0
        virtual public int Layout(PdfContentByte canvas, bool useAscender, bool simulate, float llx, float lly, float urx, float ury)
        {
            float leftX = Math.Min(llx, urx);
            float maxY = Math.Max(lly, ury);
            float minY = Math.Min(lly, ury);
            float rightX = Math.Max(llx, urx);
            yLine = maxY;
            bool contentCutByFixedHeight = false;

            if (width != null && width > 0)
            {
                if (width < rightX - leftX)
                    rightX = leftX + (float) width;
                else if (width > rightX - leftX)
                    return ColumnText.NO_MORE_COLUMN;
            }
            else if (percentageWidth != null)
            {
                contentWidth = (rightX - leftX)*(float) percentageWidth;
                rightX = leftX + contentWidth;
            }

            if (height != null && height > 0)
            {
                if (height < maxY - minY)
                {
                    contentCutByFixedHeight = true;
                    minY = maxY - (float) height;
                }
                else if (height > maxY - minY)
                {
                    return ColumnText.NO_MORE_COLUMN;
                }
            }
            else if (percentageHeight != null)
            {
                if (percentageHeight < 1.0)
                    contentCutByFixedHeight = true;
                contentHeight = (maxY - minY)*(float) percentageHeight;
                minY = maxY - contentHeight;
            }

            if (!simulate && position == PdfDiv.PositionType.RELATIVE)
            {
                float? translationX = null;
                if (left != null)
                    translationX = left;
                else if (right != null)
                    translationX = -right;
                else
                    translationX = 0f;

                float? translationY = null;
                if (top != null)
                    translationY = -top;
                else if (bottom != null)
                    translationY = bottom;
                else
                    translationY = 0f;
                canvas.SaveState();
                canvas.Transform(new AffineTransform(1f, 0, 0, 1f, translationX.Value, translationY.Value));
            }

            if (!simulate)
            {
                if (backgroundColor != null && getActualWidth() > 0 && getActualHeight() > 0)
                {
                    float backgroundWidth = getActualWidth();
                    float backgroundHeight = getActualHeight();
                    if (width != null)
                        backgroundWidth = width > 0 ? (float) width : 0;
                    if (height != null)
                        backgroundHeight = height > 0 ? (float) height : 0;
                    if (backgroundWidth > 0 && backgroundHeight > 0)
                    {
                        Rectangle background = new Rectangle(leftX, maxY - backgroundHeight, leftX + backgroundWidth, maxY);
                        background.BackgroundColor = backgroundColor;
                        PdfArtifact artifact = new PdfArtifact();
                        canvas.OpenMCBlock(artifact);
                        canvas.Rectangle(background);
                        canvas.CloseMCBlock(artifact);
                    }
                }
            }

            if (percentageWidth == null)
                contentWidth = 0;
            if (percentageHeight == null)
                contentHeight = 0;

            minY += paddingBottom;
            leftX += paddingLeft;
            rightX -= paddingRight;

            yLine -= paddingTop;

            int status = ColumnText.NO_MORE_TEXT;

            if (content.Count > 0) {
                if (floatLayout == null) {
                    List<IElement> floatingElements = new List<IElement>(content);
                    floatLayout = new FloatLayout(floatingElements, useAscender);
                }

                floatLayout.SetSimpleColumn(leftX, minY, rightX, yLine);
                status = floatLayout.Layout(canvas, simulate);
                yLine = floatLayout.YLine;
                if (percentageWidth == null && contentWidth < floatLayout.FilledWidth)
                    contentWidth = floatLayout.FilledWidth;
            }


            if (!simulate && position == PdfDiv.PositionType.RELATIVE)
                canvas.RestoreState();

            yLine -= paddingBottom;
            if (percentageHeight == null)
                contentHeight = maxY - yLine;

            if (percentageWidth == null)
                contentWidth += paddingLeft + paddingRight;

            return contentCutByFixedHeight ? ColumnText.NO_MORE_TEXT : status;
        }
Beispiel #27
0
 /**
 * @see com.lowagie.text.pdf.draw.DrawInterface#draw(com.lowagie.text.pdf.PdfContentByte, float, float, float, float, float)
 */
 public override void Draw(PdfContentByte canvas, float llx, float lly, float urx, float ury, float y)
 {
     canvas.SaveState();
     DrawLine(canvas, llx, urx, y);
     canvas.RestoreState();
 }
Beispiel #28
0
        /**
         * Writes the selected rows and columns to the document.
         * This method clips the columns; this is only important
         * if there are columns with colspan at boundaries.
         * The table event is only fired for complete rows.
         *
         * @param colStart  the first column to be written, zero index
         * @param colEnd    the last column to be written + 1. If it is -1 all the
         *                  columns to the end are written
         * @param rowStart  the first row to be written, zero index
         * @param rowEnd    the last row to be written + 1. If it is -1 all the
         *                  rows to the end are written
         * @param xPos      the x write coordinate
         * @param yPos      the y write coordinate
         * @param canvas    the <CODE>PdfContentByte</CODE> where the rows will
         *                  be written to     
         * @return the y coordinate position of the bottom of the last row
         * @param   reusable if set to false, the content in the cells is "consumed";
         * if true, you can reuse the cells, the row, the parent table as many times you want.
         * @since 5.1.0 added the reusable parameter
         */

        virtual public float WriteSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos,
                                       PdfContentByte canvas, bool reusable)
        {
            int totalCols = NumberOfColumns;
            if (colStart < 0)
                colStart = 0;
            else
                colStart = Math.Min(colStart, totalCols);

            if (colEnd < 0)
                colEnd = totalCols;
            else
                colEnd = Math.Min(colEnd, totalCols);

            bool clip = (colStart != 0 || colEnd != totalCols);

            if (clip)
            {
                float w = 0;
                for (int k = colStart; k < colEnd; ++k)
                    w += absoluteWidths[k];
                canvas.SaveState();
                float lx = (colStart == 0) ? 10000 : 0;
                float rx = (colEnd == totalCols) ? 10000 : 0;
                canvas.Rectangle(xPos - lx, -10000, w + lx + rx, PdfPRow.RIGHT_LIMIT);
                canvas.Clip();
                canvas.NewPath();
            }

            PdfContentByte[] canvases = BeginWritingRows(canvas);
            float y = WriteSelectedRows(colStart, colEnd, rowStart, rowEnd, xPos, yPos, canvases, reusable);
            EndWritingRows(canvases);

            if (clip)
                canvas.RestoreState();

            return y;
        }
 /** Places the barcode in a <CODE>PdfContentByte</CODE>. The
  * barcode is always placed at coodinates (0, 0). Use the
  * translation matrix to move it elsewhere.<p>
  * The bars and text are written in the following colors:<p>
  * <P><TABLE BORDER=1>
  * <TR>
  *   <TH><P><CODE>barColor</CODE></TH>
  *   <TH><P><CODE>textColor</CODE></TH>
  *   <TH><P>Result</TH>
  *   </TR>
  * <TR>
  *   <TD><P><CODE>null</CODE></TD>
  *   <TD><P><CODE>null</CODE></TD>
  *   <TD><P>bars and text painted with current fill color</TD>
  *   </TR>
  * <TR>
  *   <TD><P><CODE>barColor</CODE></TD>
  *   <TD><P><CODE>null</CODE></TD>
  *   <TD><P>bars and text painted with <CODE>barColor</CODE></TD>
  *   </TR>
  * <TR>
  *   <TD><P><CODE>null</CODE></TD>
  *   <TD><P><CODE>textColor</CODE></TD>
  *   <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD>
  *   </TR>
  * <TR>
  *   <TD><P><CODE>barColor</CODE></TD>
  *   <TD><P><CODE>textColor</CODE></TD>
  *   <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD>
  *   </TR>
  * </TABLE>
  * @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed
  * @param barColor the color of the bars. It can be <CODE>null</CODE>
  * @param textColor the color of the text. It can be <CODE>null</CODE>
  * @return the dimensions the barcode occupies
  */
 public override Rectangle PlaceBarcode(PdfContentByte cb, BaseColor barColor, BaseColor textColor) {
     if (supp.Font != null)
         supp.BarHeight = ean.BarHeight + supp.Baseline - supp.Font.GetFontDescriptor(BaseFont.CAPHEIGHT, supp.Size);
     else
         supp.BarHeight = ean.BarHeight;
     Rectangle eanR = ean.BarcodeSize;
     cb.SaveState();
     ean.PlaceBarcode(cb, barColor, textColor);
     cb.RestoreState();
     cb.SaveState();
     cb.ConcatCTM(1, 0, 0, 1, eanR.Width + n, eanR.Height - ean.BarHeight);
     supp.PlaceBarcode(cb, barColor, textColor);
     cb.RestoreState();
     return this.BarcodeSize;
 }
        private void InsertFormXObj(PdfContentByte canvas, PdfDictionary pageDict, PdfStream formXObj, IList<Rectangle> clippingRects, Rectangle annotRect) {
            PdfName xobjName = GenerateNameForXObj(pageDict);
            canvas.SaveState();

            foreach (Rectangle rect in clippingRects) {
                canvas.Rectangle(rect.Left, rect.Bottom, rect.Width, rect.Height);
            }

            canvas.Clip();
            canvas.NewPath();

            canvas.AddFormXObj(formXObj, xobjName, 1, 0, 0, 1, annotRect.Left, annotRect.Bottom);

            canvas.RestoreState();
        }
Beispiel #31
-9
 // ---------------------------------------------------------------------------    
 /**
  * Draws a rectangle
  * @param content the direct content layer
  * @param width the width of the rectangle
  * @param height the height of the rectangle
  */
 public static void DrawRectangle(
   PdfContentByte content, float width, float height)
 {
     content.SaveState();
     PdfGState state = new PdfGState();
     state.FillOpacity = 0.6f;
     content.SetGState(state);
     content.SetRGBColorFill(0xFF, 0xFF, 0xFF);
     content.SetLineWidth(3);
     content.Rectangle(0, 0, width, height);
     content.FillStroke();
     content.RestoreState();
 }