Fill() public method

public Fill ( ) : void
return void
Esempio n. 1
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();
 }
Esempio n. 2
1
        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);
        }
Esempio n. 3
0
        /// <summary>
        /// This method is used to search for the location words in pdf and update it with the words given from replacingText variable
        /// </summary>
        /// <param name="pSearch">Searchable String</param>
        /// <param name="replacingText">Replacing String</param>
        /// <param name="SC">Case Ignorance</param>
        /// <param name="SourceFile">Path of the source file</param>
        /// <param name="DestinationFile">Path of the destination file</param>
        public static void PDFTextGetter(string pSearch, string replacingText, StringComparison SC, string SourceFile, string DestinationFile)
        {
            try
            {
                iTextSharp.text.pdf.PdfContentByte cb     = null;
                iTextSharp.text.pdf.PdfContentByte cb2    = null;
                iTextSharp.text.pdf.PdfWriter      writer = null;
                iTextSharp.text.pdf.BaseFont       bf     = null;

                if (System.IO.File.Exists(SourceFile))
                {
                    PdfReader pReader = new PdfReader(SourceFile);


                    for (int page = 1; page <= pReader.NumberOfPages; page++)
                    {
                        myLocationTextExtractionStrategy strategy = new myLocationTextExtractionStrategy();
                        cb  = stamper.GetOverContent(page);
                        cb2 = stamper.GetOverContent(page);

                        //Send some data contained in PdfContentByte, looks like the first is always cero for me and the second 100,
                        //but i'm not sure if this could change in some cases
                        strategy.UndercontentCharacterSpacing  = (int)cb.CharacterSpacing;
                        strategy.UndercontentHorizontalScaling = (int)cb.HorizontalScaling;

                        //It's not really needed to get the text back, but we have to call this line ALWAYS,
                        //because it triggers the process that will get all chunks from PDF into our strategy Object
                        string currentText = PdfTextExtractor.GetTextFromPage(pReader, page, strategy);

                        //The real getter process starts in the following line
                        List <iTextSharp.text.Rectangle> MatchesFound = strategy.GetTextLocations(pSearch, SC);

                        //Set the fill color of the shapes, I don't use a border because it would make the rect bigger
                        //but maybe using a thin border could be a solution if you see the currect rect is not big enough to cover all the text it should cover
                        cb.SetColorFill(BaseColor.WHITE);

                        //MatchesFound contains all text with locations, so do whatever you want with it, this highlights them using PINK color:

                        foreach (iTextSharp.text.Rectangle rect in MatchesFound)
                        {
                            //width
                            cb.Rectangle(rect.Left, rect.Bottom, 60, rect.Height);
                            cb.Fill();
                            cb2.SetColorFill(BaseColor.BLACK);
                            bf = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

                            cb2.SetFontAndSize(bf, 9);

                            cb2.BeginText();
                            cb2.ShowTextAligned(0, replacingText, rect.Left, rect.Bottom, 0);
                            cb2.EndText();
                            cb2.Fill();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 4
0
 protected static void FillBackGround(iTextSharp.text.pdf.PdfContentByte contentByte,
                                      IBaseStyleDecorator style,
                                      iTextSharp.text.Rectangle rectangle)
 {
     contentByte.SetColorFill(style.PdfBackColor);
     contentByte.Rectangle(rectangle.Left, rectangle.Top - rectangle.Height, rectangle.Width, rectangle.Height);
     contentByte.Fill();
 }
Esempio n. 5
0
        public void PDFTextGetter(string pSearch, StringComparison SC, string SourceFile, string DestinationFile)
        {
            iTextSharp.text.pdf.PdfStamper     stamper = null;
            iTextSharp.text.pdf.PdfContentByte cb      = null;

            this.Cursor = Cursors.WaitCursor;
            if (File.Exists(SourceFile))
            {
                PdfReader pReader = new PdfReader(SourceFile);

                stamper    = new iTextSharp.text.pdf.PdfStamper(pReader, new System.IO.FileStream(DestinationFile, FileMode.Create));
                PB.Value   = 0;
                PB.Maximum = pReader.NumberOfPages;
                for (int page = 1; page <= pReader.NumberOfPages; page++)
                {
                    myLocationTextExtractionStrategy strategy = new myLocationTextExtractionStrategy();
                    cb = stamper.GetUnderContent(page);

                    //Send some data contained in PdfContentByte, looks like the first is always cero for me and the second 100, but i'm not sure if this could change in some cases
                    strategy.UndercontentCharacterSpacing  = cb.CharacterSpacing;
                    strategy.UndercontentHorizontalScaling = cb.HorizontalScaling;

                    //It's not really needed to get the text back, but we have to call this line ALWAYS,
                    //because it triggers the process that will get all chunks from PDF into our strategy Object
                    string currentText = PdfTextExtractor.GetTextFromPage(pReader, page, strategy);

                    //The real getter process starts in the following line
                    List <iTextSharp.text.Rectangle> MatchesFound = strategy.GetTextLocations(pSearch, SC);

                    //Set the fill color of the shapes, I don't use a border because it would make the rect bigger
                    //but maybe using a thin border could be a solution if you see the currect rect is not big enough to cover all the text it should cover
                    cb.SetColorFill(BaseColor.PINK);

                    //MatchesFound contains all text with locations, so do whatever you want with it, this highlights them using PINK color:

                    foreach (iTextSharp.text.Rectangle rect in MatchesFound)
                    {
                        cb.Rectangle(rect.Left, rect.Bottom, rect.Width, rect.Height);
                    }
                    cb.Fill();

                    PB.Value = PB.Value + 1;
                }
                stamper.Close();
                pReader.Close();
            }
            this.Cursor = Cursors.Default;
        }
Esempio n. 6
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();
    }
Esempio n. 7
0
        /// <summary>
        /// Renders the object in a document using a <see cref="PdfContentByte"/> by invoking the <see cref="Render(ContentWriter, Vector2D)"/> method.
        /// This method can be overridden in derived classes to specify rendering.
        /// </summary>
        /// <param name="cb">The <see cref="PdfContentByte"/> used for rendering.</param>
        /// <param name="offset">The calculated offset for the rendered item.</param>
        protected internal virtual void Render(PdfContentByte cb, Vector2D offset)
        {
            using (var writer = new ContentWriter(cb))
            {
                var stroke = this as StrokeObject;
                var fill = this as FillObject;

                bool hasstroke = stroke?.BorderColor.HasValue ?? false;
                bool hasfill = fill?.FillColor.HasValue ?? false;

                if (hasstroke)
                {
                    cb.SetLineWidth((float)stroke.BorderWidth.Value(UnitsOfMeasure.Points));
                    cb.SetColorStroke(new Color(stroke.BorderColor.Value));
                }
                if (hasfill)
                    cb.SetColorFill(new Color(fill.FillColor.Value));

                Render(writer, offset);

                if (hasstroke && hasfill)
                {
                    if (writer.CloseShape)
                        cb.ClosePathFillStroke();
                    else
                        cb.FillStroke();
                }
                else if (hasstroke)
                {
                    if (writer.CloseShape)
                        cb.ClosePathStroke();
                    else
                        cb.Stroke();
                }
                else if (hasfill)
                    cb.Fill();
            }
        }
Esempio n. 8
0
 /**
  * Prints a square and fills half of it with a gray rectangle.
  *
  * @param x
  * @param y
  * @param cb
  * @throws Exception
  */
 private void PictureBackdrop(float x, float y, PdfContentByte cb) {
     cb.SetColorStroke(BaseColor.BLACK);
     cb.SetColorFill(BaseColor.LIGHT_GRAY);
     cb.Rectangle(x, y, 100, 200);
     cb.Fill();
     cb.SetLineWidth(2);
     cb.Rectangle(x, y, 200, 200);
     cb.Stroke();
 }
Esempio n. 9
0
 /**
  * Prints 3 circles in different colors that intersect with eachother.
  *
  * @param x
  * @param y
  * @param cb
  * @throws Exception
  */
 private void PictureCircles(float x, float y, PdfContentByte cb, PdfWriter writer) {
     PdfGState gs = new PdfGState();
     gs.BlendMode = PdfGState.BM_MULTIPLY;
     gs.FillOpacity = 1f;
     cb.SetGState(gs);
     cb.SetColorFill(BaseColor.LIGHT_GRAY);
     cb.Circle(x + 75, y + 75, 70);
     cb.Fill();
     cb.Circle(x + 75, y + 125, 70);
     cb.Fill();
     cb.Circle(x + 125, y + 75, 70);
     cb.Fill();
     cb.Circle(x + 125, y + 125, 70);
     cb.Fill();
 }
 virtual public void PlaceBarcode(PdfContentByte cb, BaseColor foreground, float moduleHeight, float moduleWidth) {
     int w = width + 2*ws;
     int h = height + 2*ws;
     int stride = (w + 7)/8;
     int ptr = 0;
     cb.SetColorFill(foreground);
     for (int k = 0; k < h; ++k) {
         int p = k*stride;
         for (int j = 0; j < w; ++j) {
             int b = image[p + j/8] & 0xff;
             b <<= j%8;
             if ((b & 0x80) != 0) {
                 cb.Rectangle(j*moduleWidth, (h - k - 1)*moduleHeight, moduleWidth, moduleHeight);
             }
         }
     }
     cb.Fill();
 }
Esempio n. 11
0
 /** 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, Color barColor, Color textColor)
 {
     if (barColor != null)
         cb.SetColorFill(barColor);
     byte[] bars = GetBarsPostnet(code);
     byte flip = 1;
     if (codeType == PLANET) {
         flip = 0;
         bars[0] = 0;
         bars[bars.Length - 1] = 0;
     }
     float startX = 0;
     for (int k = 0; k < bars.Length; ++k) {
         cb.Rectangle(startX, 0, x - inkSpreading, bars[k] == flip ? barHeight : size);
         startX += n;
     }
     cb.Fill();
     return this.BarcodeSize;
 }
Esempio n. 12
0
 /** 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) {
     string fullCode = code;
     float fontX = 0;
     if (font != null) {
         if (generateChecksum && checksumText)
             fullCode += GetChecksum(fullCode);
         fontX = font.GetWidthPoint(fullCode = altText != null ? altText : fullCode, size);
     }
     string bCode = KeepNumbers(code);
     if (generateChecksum)
         bCode += GetChecksum(bCode);
     int len = bCode.Length;
     float fullWidth = len * (3 * x + 2 * x * n) + (6 + n ) * x;
     float barStartX = 0;
     float textStartX = 0;
     switch (textAlignment) {
         case Element.ALIGN_LEFT:
             break;
         case Element.ALIGN_RIGHT:
             if (fontX > fullWidth)
                 barStartX = fontX - fullWidth;
             else
                 textStartX = fullWidth - fontX;
             break;
         default:
             if (fontX > fullWidth)
                 barStartX = (fontX - fullWidth) / 2;
             else
                 textStartX = (fullWidth - fontX) / 2;
             break;
     }
     float barStartY = 0;
     float textStartY = 0;
     if (font != null) {
         if (baseline <= 0)
             textStartY = barHeight - baseline;
         else {
             textStartY = -font.GetFontDescriptor(BaseFont.DESCENT, size);
             barStartY = textStartY + baseline;
         }
     }
     byte[] bars = GetBarsInter25(bCode);
     bool print = true;
     if (barColor != null)
         cb.SetColorFill(barColor);
     for (int k = 0; k < bars.Length; ++k) {
         float w = (bars[k] == 0 ? x : x * n);
         if (print)
             cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight);
         print = !print;
         barStartX += w;
     }
     cb.Fill();
     if (font != null) {
         if (textColor != null)
             cb.SetColorFill(textColor);
         cb.BeginText();
         cb.SetFontAndSize(font, size);
         cb.SetTextMatrix(textStartX, textStartY);
         cb.ShowText(fullCode);
         cb.EndText();
     }
     return this.BarcodeSize;
 }   
Esempio n. 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();
    }
        /**
        * 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;
            
            // looping over all the chunks in 1 line
            foreach (PdfChunk chunk in line) {
                if (IsTagged(writer) && chunk.accessibleElement != null) {
                    text.OpenMCBlock(chunk.accessibleElement);
                }
                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)) {
                            bool inText = graphics.InText;
                            if (inText && IsTagged(writer)) {
                                graphics.EndText();
                            }
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.BACKGROUND))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            Object[] bgr = (Object[])chunk.GetAttribute(Chunk.BACKGROUND);
                            graphics.SetColorFill((BaseColor)bgr[0]);
                            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);
                            if (inText && IsTagged(writer)) {
                                graphics.BeginText(true);
                            }
                        }
                        if (chunk.IsAttribute(Chunk.UNDERLINE) && !chunk.IsNewlineSplit()) {
                            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 = new PdfAnnotation(writer, xMarker, yMarker + chunk.ImageOffsetY, xMarker + width - subtract, yMarker + chunk.ImageHeight + chunk.ImageOffsetY, (PdfAction)chunk.GetAttribute(Chunk.ACTION));
                            }
                            else {
                        	    annot = new PdfAnnotation(writer, xMarker, yMarker + descender + chunk.TextRise, xMarker + width - subtract, yMarker + ascender + chunk.TextRise, (PdfAction)chunk.GetAttribute(Chunk.ACTION));
                            }
                            text.AddAnnotation(annot, true);
                            if (IsTagged(writer) && chunk.accessibleElement != null) {
                                int structParent = GetStructParentIndex(annot);
                                annot.Put(PdfName.STRUCTPARENT, new PdfNumber(structParent));
                                PdfStructureElement strucElem;
                                structElements.TryGetValue(chunk.accessibleElement.ID, out strucElem);
                                if (strucElem != null) {
                                    PdfArray kArray = strucElem.GetAsArray(PdfName.K);
                                    if (kArray == null) {
                                        kArray = new PdfArray();
                                        PdfObject k = strucElem.Get(PdfName.K);
                                        if (k != null) {
                                            kArray.Add(k);
                                        }
                                        strucElem.Put(PdfName.K, kArray);
                                    }
                                    PdfDictionary dict = new PdfDictionary();
                                    dict.Put(PdfName.TYPE, PdfName.OBJR);
                                    dict.Put(PdfName.OBJ, annot.IndirectReference);
                                    kArray.Add(dict);
                                    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);
					    }
                        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]);
                            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 (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;
        }
 /** 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) {
     string fullCode;
     if (codeType == CODE128_RAW) {
         int idx = code.IndexOf('\uffff');
         if (idx < 0)
             fullCode = "";
         else
             fullCode = code.Substring(idx + 1);
     }
     else if (codeType == CODE128_UCC)
         fullCode = GetHumanReadableUCCEAN(code);
     else
         fullCode = RemoveFNC1(code);
     float fontX = 0;
     if (font != null) {
         fontX = font.GetWidthPoint(fullCode = altText != null ? altText : fullCode, size);
     }
     string bCode;
     if (codeType == CODE128_RAW) {
         int idx = code.IndexOf('\uffff');
         if (idx >= 0)
             bCode = code.Substring(0, idx);
         else
             bCode = code;
     }
     else {
         bCode = GetRawText(code, codeType == CODE128_UCC);
     }
     int len = bCode.Length;
     float fullWidth = (len + 2) * 11 * x + 2 * x;
     float barStartX = 0;
     float textStartX = 0;
     switch (textAlignment) {
         case Element.ALIGN_LEFT:
             break;
         case Element.ALIGN_RIGHT:
             if (fontX > fullWidth)
                 barStartX = fontX - fullWidth;
             else
                 textStartX = fullWidth - fontX;
             break;
         default:
             if (fontX > fullWidth)
                 barStartX = (fontX - fullWidth) / 2;
             else
                 textStartX = (fullWidth - fontX) / 2;
             break;
     }
     float barStartY = 0;
     float textStartY = 0;
     if (font != null) {
         if (baseline <= 0)
             textStartY = barHeight - baseline;
         else {
             textStartY = -font.GetFontDescriptor(BaseFont.DESCENT, size);
             barStartY = textStartY + baseline;
         }
     }
     byte[] bars = GetBarsCode128Raw(bCode);
     bool print = true;
     if (barColor != null)
         cb.SetColorFill(barColor);
     for (int k = 0; k < bars.Length; ++k) {
         float w = bars[k] * x;
         if (print)
             cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight);
         print = !print;
         barStartX += w;
     }
     cb.Fill();
     if (font != null) {
         if (textColor != null)
             cb.SetColorFill(textColor);
         cb.BeginText();
         cb.SetFontAndSize(font, size);
         cb.SetTextMatrix(textStartX, textStartY);
         cb.ShowText(fullCode);
         cb.EndText();
     }
     return this.BarcodeSize;
 }    
Esempio n. 16
0
// ---------------------------------------------------------------------------
    /**
     * Prints 3 circles in different colors that intersect with eachother.
     * 
     * @param x
     * @param y
     * @param cb
     * @throws Exception
     */
    public static void PictureCircles(float x, float y, PdfContentByte cb) {
      PdfGState gs = new PdfGState();
      gs.BlendMode = PdfGState.BM_MULTIPLY;
      gs.FillOpacity = 1f;
      cb.SetGState(gs);
      cb.SetColorFill(new CMYKColor(0f, 0f, 0f, 0.15f));
      cb.Circle(x + 75, y + 75, 70);
      cb.Fill();
      cb.Circle(x + 75, y + 125, 70);
      cb.Fill();
      cb.Circle(x + 125, y + 75, 70);
      cb.Fill();
      cb.Circle(x + 125, y + 125, 70);
      cb.Fill();
    }
        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();
        }
Esempio n. 18
0
    //    /** Creates a <CODE>java.awt.Image</CODE>.
    //     * @param foreground the color of the bars
    //     * @param background the color of the background
    //     * @return the image
    //     */
    //    public java.awt.Image CreateAwtImage(java.awt.Color foreground, java.awt.Color background) {
    //    int f = foreground.GetRGB();
    //    int g = background.GetRGB();
    //    Canvas canvas = new Canvas();

    //    int width = bm.GetWidth();
    //    int height = bm.GetHeight();
    //    int[] pix = new int[width * height];
    //    byte[][] mt = bm.GetArray();
    //    for (int y = 0; y < height; ++y) {
    //        byte[] line = mt[y];
    //        for (int x = 0; x < width; ++x) {
    //            pix[y * width + x] = line[x] == 0 ? f : g;
    //        }
    //    }

    //    java.awt.Image img = canvas.CreateImage(new MemoryImageSource(width, height, pix, 0, width));
    //    return img;
    //}

        public void PlaceBarcode(PdfContentByte cb, BaseColor foreground, float moduleSide)
        {
            int width = bm.GetWidth();
            int height = bm.GetHeight();
            sbyte[][] mt = bm.GetArray();

            cb.SetColorFill(foreground);

            for (int y = 0; y < height; ++y)
            {
                sbyte[] line = mt[y];
                for (int x = 0; x < width; ++x)
                {
                    if (line[x] == 0)
                    {
                        cb.Rectangle(x * moduleSide, (height - y - 1) * moduleSide, moduleSide, moduleSide);
                    }
                }
            }
            cb.Fill();
        }
Esempio n. 19
0
        private void DrawArc(PdfContentByte cb, IList<float> numbers)
        {
            EllipseArc ellipse = EllipseArc.CreateEllipseArc(numbers[7], numbers[8], numbers[5], numbers[6], numbers[0], numbers[1], numbers[4], numbers[3]);

            cb.SetColorFill(BaseColor.ORANGE);
            cb.Rectangle(numbers[7], numbers[8], 2, 2); //p1
            cb.Fill();
            cb.SetColorFill(BaseColor.GREEN);
            cb.Rectangle(numbers[5], numbers[6], 2, 2); //p2
            cb.Fill();

            cb.Arc(ellipse.Cx - numbers[0], ellipse.Cy - numbers[1], ellipse.Cx + numbers[0], ellipse.Cy + numbers[1],
                    ellipse.StartAng, ellipse.Extend);
        }
Esempio n. 20
0
        public override Rectangle PlaceBarcode(PdfContentByte cb, BaseColor barColor, BaseColor textColor)
        {
            const float distanceBetweenBars = MmToPoints;
            const float wideBarPoints = MmToPoints;
            const float narrowBarPoints = HalfMmToPoints;
            const float barWidth = DefaultBarWidthInPoints;
            const float fullHeight = DefaultBarHeightInPoints;

            var barStartX = IsisPoint.X - _mmFromPageBorder;
            var barStartY = IsisPoint.Y - _mmFromDrawningBar;
            var bars = GetBarsCode39("123456789012345678901234567890123456789");
            var print = true;
            if (barColor != null)
            {
                cb.SetColorFill(barColor);
                cb.SetColorStroke(barColor);
            }

            const int elementBars = 20;
            var elemBarCount = 1;
            foreach (var vbarHeight in bars.Select(t => (t == 0 ? narrowBarPoints : wideBarPoints)))
            {
                if (print)
                {
                    cb.Rectangle(barStartX, barStartY, barWidth, vbarHeight);
                }
                print = !print;
                barStartY += vbarHeight;

                if (elemBarCount++ != elementBars) continue; // start a new element
                elemBarCount = 1;
                barStartY = IsisPoint.Y - _mmFromDrawningBar;
                barStartX += barWidth + distanceBetweenBars;
            }
            cb.Fill();
            var fullWidth = barStartX + barWidth;
            return new Rectangle(fullWidth, fullHeight);
        }
Esempio n. 21
0
// ---------------------------------------------------------------------------
    /**
     * Prints a square and fills half of it with a gray rectangle.
     * 
     * @param x
     * @param y
     * @param cb
     * @throws Exception
     */
    public static void PictureBackdrop(float x, float y, PdfContentByte cb) {
      cb.SetColorStroke(GrayColor.GRAYBLACK);
      cb.SetColorFill(new GrayColor(0.8f));
      cb.Rectangle(x, y, 100, 200);
      cb.Fill();
      cb.SetLineWidth(2);
      cb.Rectangle(x, y, 200, 200);
      cb.Stroke();
    }
Esempio n. 22
0
	private void CreatePdfBox(PdfContentByte content, Configuration.PrintTemplateContentRow row, bool allowFill)
	{
		if (row.IsFillColorNull() && row.IsOutlineWidthNull() && row.IsOutlineColorNull())
		{
			return;
		}

		bool hasFill = false;
		bool hasStroke = false;

		content.SetLineWidth((1 / PixelsPerInch) * PointsPerInch);

		if (!row.IsFillColorNull() && allowFill)
		{
			System.Drawing.Color c = System.Drawing.ColorTranslator.FromHtml(row.FillColor);
			content.SetRGBColorFill(c.R, c.G, c.B);
			hasFill = true;
		}

		if (!row.IsOutlineWidthNull())
		{
			content.SetLineWidth((Convert.ToSingle(row.OutlineWidth) / PixelsPerInch) * PointsPerInch);
			hasStroke = true;
		}

		if (!row.IsOutlineColorNull())
		{
			System.Drawing.Color c = System.Drawing.ColorTranslator.FromHtml(row.OutlineColor);
			content.SetRGBColorStroke(c.R, c.G, c.B);
			hasStroke = true;
		}

		float originX = Convert.ToSingle(row.OriginX) * PointsPerInch;
		float originY = Convert.ToSingle(row.OriginY) * PointsPerInch;
		float width = Convert.ToSingle(row.Width) * PointsPerInch;
		float height = Convert.ToSingle(row.Height) * PointsPerInch;

		if (hasFill)
		{
			content.Rectangle(originX, originY, width, height);
			content.Fill();
		}

		if (hasStroke)
		{
			content.Rectangle(originX, originY, width, height);
			content.Stroke();
		}
	}
Esempio n. 23
0
// ---------------------------------------------------------------------------
    /**
     * Prints 3 circles in different colors that intersect with eachother.
     * 
     * @param x
     * @param y
     * @param cb
     * @throws Exception
     */
    public static void PictureCircles(float x, float y, PdfContentByte cb) {
      cb.SetColorFill(BaseColor.RED);
      cb.Circle(x + 70, y + 70, 50);
      cb.Fill();
      cb.SetColorFill(BaseColor.YELLOW);
      cb.Circle(x + 100, y + 130, 50);
      cb.Fill();
      cb.SetColorFill(BaseColor.BLUE);
      cb.Circle(x + 130, y + 70, 50);
      cb.Fill();
    }
Esempio n. 24
0
        public void Close(PdfContentByte cb, IDictionary<String, String> css)
        {
            //default is true for both
            String fillValue;
            String strokeValue;

            bool fill = (!css.TryGetValue("fill", out fillValue) || fillValue == null || !fillValue.Equals("none"));
            bool stroke = (!css.TryGetValue("stroke", out strokeValue) || strokeValue == null || !strokeValue.Equals("none"));

            if (fill && stroke) {
                cb.FillStroke();
            } else if (fill) {
                cb.Fill();
            } else if (stroke) {
                cb.Stroke();
            }
        }
 /** 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)
 {
     String fullCode = code;
     if (generateChecksum && checksumText)
         fullCode = CalculateChecksum(code);
     if (!startStopText)
         fullCode = fullCode.Substring(1, fullCode.Length - 2);
     float fontX = 0;
     if (font != null) {
         fontX = font.GetWidthPoint(fullCode = altText != null ? altText : fullCode, size);
     }
     byte[] bars = GetBarsCodabar(generateChecksum ? CalculateChecksum(code) : code);
     int wide = 0;
     for (int k = 0; k < bars.Length; ++k) {
         wide += (int)bars[k];
     }
     int narrow = bars.Length - wide;
     float fullWidth = x * (narrow + wide * n);
     float barStartX = 0;
     float textStartX = 0;
     switch (textAlignment) {
         case Element.ALIGN_LEFT:
             break;
         case Element.ALIGN_RIGHT:
             if (fontX > fullWidth)
                 barStartX = fontX - fullWidth;
             else
                 textStartX = fullWidth - fontX;
             break;
         default:
             if (fontX > fullWidth)
                 barStartX = (fontX - fullWidth) / 2;
             else
                 textStartX = (fullWidth - fontX) / 2;
             break;
     }
     float barStartY = 0;
     float textStartY = 0;
     if (font != null) {
         if (baseline <= 0)
             textStartY = barHeight - baseline;
         else {
             textStartY = -font.GetFontDescriptor(BaseFont.DESCENT, size);
             barStartY = textStartY + baseline;
         }
     }
     bool print = true;
     if (barColor != null)
         cb.SetColorFill(barColor);
     for (int k = 0; k < bars.Length; ++k) {
         float w = (bars[k] == 0 ? x : x * n);
         if (print)
             cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight);
         print = !print;
         barStartX += w;
     }
     cb.Fill();
     if (font != null) {
         if (textColor != null)
             cb.SetColorFill(textColor);
         cb.BeginText();
         cb.SetFontAndSize(font, size);
         cb.SetTextMatrix(textStartX, textStartY);
         cb.ShowText(fullCode);
         cb.EndText();
     }
     return BarcodeSize;
 }
Esempio n. 26
0
        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();
        }
Esempio n. 27
0
 /** 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) {
     Rectangle rect = this.BarcodeSize;
     float barStartX = 0;
     float barStartY = 0;
     float textStartY = 0;
     if (font != null) {
         if (baseline <= 0)
             textStartY = barHeight - baseline;
         else {
             textStartY = -font.GetFontDescriptor(BaseFont.DESCENT, size);
             barStartY = textStartY + baseline;
         }
     }
     switch (codeType) {
         case EAN13:
         case UPCA:
         case UPCE:
             if (font != null)
                 barStartX += font.GetWidthPoint(code[0], size);
             break;
     }
     byte[] bars = null;
     int[] guard = GUARD_EMPTY;
     switch (codeType) {
         case EAN13:
             bars = GetBarsEAN13(code);
             guard = GUARD_EAN13;
             break;
         case EAN8:
             bars = GetBarsEAN8(code);
             guard = GUARD_EAN8;
             break;
         case UPCA:
             bars = GetBarsEAN13("0" + code);
             guard = GUARD_UPCA;
             break;
         case UPCE:
             bars = GetBarsUPCE(code);
             guard = GUARD_UPCE;
             break;
         case SUPP2:
             bars = GetBarsSupplemental2(code);
             break;
         case SUPP5:
             bars = GetBarsSupplemental5(code);
             break;
     }
     float keepBarX = barStartX;
     bool print = true;
     float gd = 0;
     if (font != null && baseline > 0 && guardBars) {
         gd = baseline / 2;
     }
     if (barColor != null)
         cb.SetColorFill(barColor);
     for (int k = 0; k < bars.Length; ++k) {
         float w = bars[k] * x;
         if (print) {
             if (Array.BinarySearch(guard, k) >= 0)
                 cb.Rectangle(barStartX, barStartY - gd, w - inkSpreading, barHeight + gd);
             else
                 cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight);
         }
         print = !print;
         barStartX += w;
     }
     cb.Fill();
     if (font != null) {
         if (textColor != null)
             cb.SetColorFill(textColor);
         cb.BeginText();
         cb.SetFontAndSize(font, size);
         switch (codeType) {
             case EAN13:
                 cb.SetTextMatrix(0, textStartY);
                 cb.ShowText(code.Substring(0, 1));
                 for (int k = 1; k < 13; ++k) {
                     string c = code.Substring(k, 1);
                     float len = font.GetWidthPoint(c, size);
                     float pX = keepBarX + TEXTPOS_EAN13[k - 1] * x - len / 2;
                     cb.SetTextMatrix(pX, textStartY);
                     cb.ShowText(c);
                 }
                 break;
             case EAN8:
                 for (int k = 0; k < 8; ++k) {
                     string c = code.Substring(k, 1);
                     float len = font.GetWidthPoint(c, size);
                     float pX = TEXTPOS_EAN8[k] * x - len / 2;
                     cb.SetTextMatrix(pX, textStartY);
                     cb.ShowText(c);
                 }
                 break;
             case UPCA:
                 cb.SetTextMatrix(0, textStartY);
                 cb.ShowText(code.Substring(0, 1));
                 for (int k = 1; k < 11; ++k) {
                     string c = code.Substring(k, 1);
                     float len = font.GetWidthPoint(c, size);
                     float pX = keepBarX + TEXTPOS_EAN13[k] * x - len / 2;
                     cb.SetTextMatrix(pX, textStartY);
                     cb.ShowText(c);
                 }
                 cb.SetTextMatrix(keepBarX + x * (11 + 12 * 7), textStartY);
                 cb.ShowText(code.Substring(11, 1));
                 break;
             case UPCE:
                 cb.SetTextMatrix(0, textStartY);
                 cb.ShowText(code.Substring(0, 1));
                 for (int k = 1; k < 7; ++k) {
                     string c = code.Substring(k, 1);
                     float len = font.GetWidthPoint(c, size);
                     float pX = keepBarX + TEXTPOS_EAN13[k - 1] * x - len / 2;
                     cb.SetTextMatrix(pX, textStartY);
                     cb.ShowText(c);
                 }
                 cb.SetTextMatrix(keepBarX + x * (9 + 6 * 7), textStartY);
                 cb.ShowText(code.Substring(7, 1));
                 break;
             case SUPP2:
             case SUPP5:
                 for (int k = 0; k < code.Length; ++k) {
                     string c = code.Substring(k, 1);
                     float len = font.GetWidthPoint(c, size);
                     float pX = (7.5f + (9 * k)) * x - len / 2;
                     cb.SetTextMatrix(pX, textStartY);
                     cb.ShowText(c);
                 }
                 break;
         }
         cb.EndText();
     }
     return rect;
 }
Esempio n. 28
0
// ---------------------------------------------------------------------------    
    /**
     * 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();
    }
Esempio n. 29
0
 public virtual void PlaceBarcode(PdfContentByte cb, BaseColor foreground, float moduleHeight, float moduleWidth) {
     PaintCode();
     int stride = (bitColumns + 7)/8;
     cb.SetColorFill(foreground);
     for (int k = 0; k < codeRows; ++k) {
         int p = k*stride;
         for (int j = 0; j < bitColumns; ++j) {
             int b = outBits[p + j/8] & 0xff;
             b <<= j%8;
             if ((b & 0x80) != 0) {
                 cb.Rectangle(j*moduleWidth, (codeRows - k - 1)*moduleHeight, moduleWidth, moduleHeight);
             }
         }
     }
     cb.Fill();
 }
Esempio n. 30
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 void 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;

            numberOfSpaces = line.NumberOfSpaces;
            lineLen = line.ToString().Length;
            // does the line need to be justified?
            isJustified = line.HasToBeJustified() && (numberOfSpaces != 0 || lineLen > 1);
            if (isJustified) {
                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;
                }
            }

            int lastChunkStroke = line.LastStrokeChunk;
            int chunkStrokeIdx = 0;
            float xMarker = text.XTLM;
            float baseXMarker = xMarker;
            float yMarker = text.YTLM;
            bool adjustMatrix = false;

            // looping over all the chunks in 1 line
            foreach (PdfChunk chunk in line) {
                Color color = chunk.Color;
                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.IsAttribute(Chunk.BACKGROUND)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.BACKGROUND))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            float fontSize = chunk.Font.Size;
                            float ascender = chunk.Font.Font.GetFontDescriptor(BaseFont.ASCENT, fontSize);
                            float descender = chunk.Font.Font.GetFontDescriptor(BaseFont.DESCENT, fontSize);
                            Object[] bgr = (Object[])chunk.GetAttribute(Chunk.BACKGROUND);
                            graphics.SetColorFill((Color)bgr[0]);
                            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);
                        }
                        if (chunk.IsAttribute(Chunk.UNDERLINE)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.UNDERLINE))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            Object[][] unders = (Object[][])chunk.GetAttribute(Chunk.UNDERLINE);
                            Color scolor = null;
                            for (int k = 0; k < unders.Length; ++k) {
                                Object[] obj = unders[k];
                                scolor = (Color)obj[0];
                                float[] ps = (float[])obj[1];
                                if (scolor == null)
                                    scolor = color;
                                if (scolor != null)
                                    graphics.SetColorStroke(scolor);
                                float fsize = chunk.Font.Size;
                                graphics.SetLineWidth(ps[0] + fsize * ps[1]);
                                float shift = ps[2] + fsize * 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 (chunk.IsAttribute(Chunk.ACTION)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.ACTION))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            text.AddAnnotation(new PdfAnnotation(writer, xMarker, yMarker, xMarker + width - subtract, yMarker + chunk.Font.Size, (PdfAction)chunk.GetAttribute(Chunk.ACTION)));
                        }
                        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, xMarker + width - subtract, yMarker + chunk.Font.Size);
                            else
                                RemoteGoto(filename, (int)obj[1], xMarker, yMarker, xMarker + width - subtract, yMarker + chunk.Font.Size);
                        }
                        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 + chunk.Font.Size);
                        }
                        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 + chunk.Font.Size, 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 + chunk.Font.Size);
                            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;
                            float fontSize = chunk.Font.Size;
                            float ascender = chunk.Font.Font.GetFontDescriptor(BaseFont.ASCENT, fontSize);
                            float descender = chunk.Font.Font.GetFontDescriptor(BaseFont.DESCENT, fontSize);
                            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);
                        }
                        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 (chunk.IsImage()) {
                            Image image = chunk.Image;
                            float[] matrix = image.Matrix;
                            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]);
                            text.MoveText(xMarker + lastBaseFactor + image.ScaledWidth - text.XTLM, 0);
                        }
                    }
                    xMarker += width;
                    ++chunkStrokeIdx;
                }

                if (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;
                Color 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 = (Color)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;
                }
                // 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);
                    }
                    String s = chunk.ToString();
                    int idx = s.IndexOf(' ');
                    if (idx < 0)
                        text.ShowText(chunk.ToString());
                    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.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) {
                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;
        }