Example #1
0
 /**
 * Adds a <CODE>BaseFont</CODE> to the document but not to the page resources.
 * It is used for templates.
 * @param bf the <CODE>BaseFont</CODE> to add
 * @return an <CODE>Object[]</CODE> where position 0 is a <CODE>PdfName</CODE>
 * and position 1 is an <CODE>PdfIndirectReference</CODE>
 */
 internal FontDetails AddSimple(BaseFont bf) {
     FontDetails ret;
     if (!documentFonts.TryGetValue(bf, out ret)) {
         PdfWriter.CheckPdfIsoConformance(this, PdfIsoKeys.PDFISOKEY_FONT, bf);
         if (bf.FontType == BaseFont.FONT_TYPE_DOCUMENT) {
             ret = new FontDetails(new PdfName("F" + fontNumber++), ((DocumentFont)bf).IndirectReference, bf);
         } else {
             ret = new FontDetails(new PdfName("F" + fontNumber++), body.PdfIndirectReference, bf);
         }
         documentFonts[bf] = ret;
     }
     return ret;
 }
 internal GraphicState(GraphicState cp)
 {
     fontDetails = cp.fontDetails;
     colorDetails = cp.colorDetails;
     size = cp.size;
     xTLM = cp.xTLM;
     yTLM = cp.yTLM;
     aTLM = cp.aTLM;
     bTLM = cp.bTLM;
     cTLM = cp.cTLM;
     dTLM = cp.dTLM;
     tx = cp.tx;
     leading = cp.leading;
     scale = cp.scale;
     charSpace = cp.charSpace;
     wordSpace = cp.wordSpace;
 }
 internal void CopyParameters(GraphicState cp) {
     fontDetails = cp.fontDetails;
     colorDetails = cp.colorDetails;
     size = cp.size;
     xTLM = cp.xTLM;
     yTLM = cp.yTLM;
     aTLM = cp.aTLM;
     bTLM = cp.bTLM;
     cTLM = cp.cTLM;
     dTLM = cp.dTLM;
     tx = cp.tx;
     leading = cp.leading;
     scale = cp.scale;
     charSpace = cp.charSpace;
     wordSpace = cp.wordSpace;
     textColorFill = cp.textColorFill;
     colorFill = cp.colorFill;
     textColorStroke = cp.textColorStroke;
     colorStroke = cp.colorStroke;
     CTM = (AffineTransform)cp.CTM.Clone();
     textRenderMode = cp.textRenderMode;
     extGState = cp.extGState;
 }
 /**
 * Sets a field property. Valid property names are:
 * <p>
 * <ul>
 * <li>textfont - sets the text font. The value for this entry is a <CODE>BaseFont</CODE>.<br>
 * <li>textcolor - sets the text color. The value for this entry is a <CODE>java.awt.Color</CODE>.<br>
 * <li>textsize - sets the text size. The value for this entry is a <CODE>Float</CODE>.
 * <li>bgcolor - sets the background color. The value for this entry is a <CODE>java.awt.Color</CODE>.
 *     If <code>null</code> removes the background.<br>
 * <li>bordercolor - sets the border color. The value for this entry is a <CODE>java.awt.Color</CODE>.
 *     If <code>null</code> removes the border.<br>
 * </ul>
 * @param field the field name
 * @param name the property name
 * @param value the property value
 * @param inst an array of <CODE>int</CODE> indexing into <CODE>AcroField.Item.merged</CODE> elements to process.
 * Set to <CODE>null</CODE> to process all
 * @return <CODE>true</CODE> if the property exists, <CODE>false</CODE> otherwise
 */
 public bool SetFieldProperty(String field, String name, Object value, int[] inst)
 {
     if (writer == null)
         throw new Exception("This AcroFields instance is read-only.");
     Item item = (Item)fields[field];
     if (item == null)
         return false;
     InstHit hit = new InstHit(inst);
     PdfDictionary merged;
     PdfString da;
     if (Util.EqualsIgnoreCase(name, "textfont")) {
         for (int k = 0; k < item.Size; ++k) {
             if (hit.IsHit(k)) {
                 merged = item.GetMerged( k );
                 da = merged.GetAsString(PdfName.DA);
                 PdfDictionary dr = merged.GetAsDict(PdfName.DR);
                 if (da != null && dr != null) {
                     Object[] dao = SplitDAelements(da.ToUnicodeString());
                     PdfAppearance cb = new PdfAppearance();
                     if (dao[DA_FONT] != null) {
                         BaseFont bf = (BaseFont)value;
                         PdfName psn = (PdfName)PdfAppearance.stdFieldFontNames[bf.PostscriptFontName];
                         if (psn == null) {
                             psn = new PdfName(bf.PostscriptFontName);
                         }
                         PdfDictionary fonts = dr.GetAsDict(PdfName.FONT);
                         if (fonts == null) {
                             fonts = new PdfDictionary();
                             dr.Put(PdfName.FONT, fonts);
                         }
                         PdfIndirectReference fref = (PdfIndirectReference)fonts.Get(psn);
                         PdfDictionary top = reader.Catalog.GetAsDict(PdfName.ACROFORM);
                         MarkUsed(top);
                         dr = top.GetAsDict(PdfName.DR);
                         if (dr == null) {
                             dr = new PdfDictionary();
                             top.Put(PdfName.DR, dr);
                         }
                         MarkUsed(dr);
                         PdfDictionary fontsTop = dr.GetAsDict(PdfName.FONT);
                         if (fontsTop == null) {
                             fontsTop = new PdfDictionary();
                             dr.Put(PdfName.FONT, fontsTop);
                         }
                         MarkUsed(fontsTop);
                         PdfIndirectReference frefTop = (PdfIndirectReference)fontsTop.Get(psn);
                         if (frefTop != null) {
                             if (fref == null)
                                 fonts.Put(psn, frefTop);
                         }
                         else if (fref == null) {
                             FontDetails fd;
                             if (bf.FontType == BaseFont.FONT_TYPE_DOCUMENT) {
                                 fd = new FontDetails(null, ((DocumentFont)bf).IndirectReference, bf);
                             }
                             else {
                                 bf.Subset = false;
                                 fd = writer.AddSimple(bf);
                                 localFonts[psn.ToString().Substring(1)] = bf;
                             }
                             fontsTop.Put(psn, fd.IndirectReference);
                             fonts.Put(psn, fd.IndirectReference);
                         }
                         ByteBuffer buf = cb.InternalBuffer;
                         buf.Append(psn.GetBytes()).Append(' ').Append((float)dao[DA_SIZE]).Append(" Tf ");
                         if (dao[DA_COLOR] != null)
                             cb.SetColorFill((Color)dao[DA_COLOR]);
                         PdfString s = new PdfString(cb.ToString());
                         item.GetMerged(k).Put(PdfName.DA, s);
                         item.GetWidget(k).Put(PdfName.DA, s);
                         MarkUsed(item.GetWidget(k));
                     }
                 }
             }
         }
     }
     else if (Util.EqualsIgnoreCase(name, "textcolor")) {
         for (int k = 0; k < item.Size; ++k) {
             if (hit.IsHit(k)) {
                 merged = item.GetMerged( k );
                 da = merged.GetAsString(PdfName.DA);
                 if (da != null) {
                     Object[] dao = SplitDAelements(da.ToUnicodeString());
                     PdfAppearance cb = new PdfAppearance();
                     if (dao[DA_FONT] != null) {
                         ByteBuffer buf = cb.InternalBuffer;
                         buf.Append(new PdfName((String)dao[DA_FONT]).GetBytes()).Append(' ').Append((float)dao[DA_SIZE]).Append(" Tf ");
                         cb.SetColorFill((Color)value);
                         PdfString s = new PdfString(cb.ToString());
                         item.GetMerged(k).Put(PdfName.DA, s);
                         item.GetWidget(k).Put(PdfName.DA, s);
                         MarkUsed(item.GetWidget(k));
                     }
                 }
             }
         }
     }
     else if (Util.EqualsIgnoreCase(name, "textsize")) {
         for (int k = 0; k < item.Size; ++k) {
             if (hit.IsHit(k)) {
                 merged = item.GetMerged( k );
                 da = merged.GetAsString(PdfName.DA);
                 if (da != null) {
                     Object[] dao = SplitDAelements(da.ToUnicodeString());
                     PdfAppearance cb = new PdfAppearance();
                     if (dao[DA_FONT] != null) {
                         ByteBuffer buf = cb.InternalBuffer;
                         buf.Append(new PdfName((String)dao[DA_FONT]).GetBytes()).Append(' ').Append((float)value).Append(" Tf ");
                         if (dao[DA_COLOR] != null)
                             cb.SetColorFill((Color)dao[DA_COLOR]);
                         PdfString s = new PdfString(cb.ToString());
                         item.GetMerged(k).Put(PdfName.DA, s);
                         item.GetWidget(k).Put(PdfName.DA, s);
                         MarkUsed(item.GetWidget(k));
                     }
                 }
             }
         }
     }
     else if (Util.EqualsIgnoreCase(name, "bgcolor") || Util.EqualsIgnoreCase(name, "bordercolor")) {
         PdfName dname = (Util.EqualsIgnoreCase(name, "bgcolor") ? PdfName.BG : PdfName.BC);
         for (int k = 0; k < item.Size; ++k) {
             if (hit.IsHit(k)) {
                 merged = item.GetMerged( k );
                 PdfDictionary mk = merged.GetAsDict(PdfName.MK);
                 if (mk == null) {
                     if (value == null)
                         return true;
                     mk = new PdfDictionary();
                     item.GetMerged(k).Put(PdfName.MK, mk);
                     item.GetWidget(k).Put(PdfName.MK, mk);
                     MarkUsed(item.GetWidget(k));
                 } else {
                     MarkUsed( mk );
                 }
                 if (value == null)
                     mk.Remove(dname);
                 else
                     mk.Put(dname, PdfFormField.GetMKColor((Color)value));
             }
         }
     }
     else
         return false;
     return true;
 }
Example #5
0
 /**
 * Adds a <CODE>BaseFont</CODE> to the document but not to the page resources.
 * It is used for templates.
 * @param bf the <CODE>BaseFont</CODE> to add
 * @return an <CODE>Object[]</CODE> where position 0 is a <CODE>PdfName</CODE>
 * and position 1 is an <CODE>PdfIndirectReference</CODE>
 */
 internal FontDetails AddSimple(BaseFont bf)
 {
     if (bf.FontType == BaseFont.FONT_TYPE_DOCUMENT) {
         return new FontDetails(new PdfName("F" + (fontNumber++)), ((DocumentFont)bf).IndirectReference, bf);
     }
     FontDetails ret;
     if (!documentFonts.TryGetValue(bf, out ret)) {
         PdfXConformanceImp.CheckPDFXConformance(this, PdfXConformanceImp.PDFXKEY_FONT, bf);
         ret = new FontDetails(new PdfName("F" + (fontNumber++)), body.PdfIndirectReference, bf);
         documentFonts[bf] = ret;
     }
     return ret;
 }
Example #6
0
 internal void CopyParameters(GraphicState cp) {
     fontDetails = cp.fontDetails;
     colorDetails = cp.colorDetails;
     size = cp.size;
     xTLM = cp.xTLM;
     yTLM = cp.yTLM;
     aTLM = cp.aTLM;
     bTLM = cp.bTLM;
     cTLM = cp.cTLM;
     dTLM = cp.dTLM;
     tx = cp.tx;
     leading = cp.leading;
     scale = cp.scale;
     charSpace = cp.charSpace;
     wordSpace = cp.wordSpace;
     textColorFill = cp.textColorFill;
     graphicsColorFill = cp.graphicsColorFill;
     textColorStroke = cp.textColorStroke;
     graphicsColorStroke = cp.graphicsColorStroke;
     CTM = cp.CTM.Clone();
 }