Example #1
0
 internal bool SetField(String field, PdfObject value) {
     Dictionary<String, Object> map = fields;
     StringTokenizer tk = new StringTokenizer(field, ".");
     if (!tk.HasMoreTokens())
         return false;
     while (true) {
         String s = tk.NextToken();
         Object obj;
         map.TryGetValue(s, out obj);
         if (tk.HasMoreTokens()) {
             if (obj == null) {
                 obj = new Dictionary<String, Object>();
                 map[s] = obj;
                 map = (Dictionary<string,object>)obj;
                 continue;
             }
             else if (obj is Dictionary<String, Object>)
                 map = (Dictionary<String, Object>)obj;
             else
                 return false;
         }
         else {
             if (!(obj is Dictionary<String, Object>)) {
                 map[s] = value;
                 return true;
             }
             else
                 return false;
         }
     }
 }
Example #2
0
        public void drawMultiLineOfText(PdfFormField field, string text, BaseFont font, float fontSize, float llx, float lly, float urx, float ury)
        {
            PdfContentByte da = new PdfContentByte(writer);

            da.setFontAndSize(font, fontSize);
            da.resetRGBColorFill();
            field.DefaultAppearancestring = da;
            PdfContentByte cb = writer.DirectContent;

            cb.moveTo(0, 0);
            PdfAppearance tp = cb.createAppearance(urx - llx, ury - lly);

            tp.drawTextField(0f, 0f, urx - llx, ury - lly);
            tp.beginVariableText();
            tp.saveState();
            tp.rectangle(3f, 3f, urx - llx - 6f, ury - lly - 6f);
            tp.clip();
            tp.newPath();
            tp.beginText();
            tp.setFontAndSize(font, fontSize);
            tp.resetRGBColorFill();
            tp.setTextMatrix(4, 5);
            System.util.StringTokenizer tokenizer = new System.util.StringTokenizer(text, "\n");
            float yPos = ury - lly;

            while (tokenizer.hasMoreTokens())
            {
                yPos -= fontSize * 1.2f;
                tp.showTextAligned(PdfContentByte.ALIGN_LEFT, tokenizer.nextToken(), 3, yPos, 0);
            }
            tp.endText();
            tp.restoreState();
            tp.endVariableText();
            field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
        }
Example #3
0
        public void DrawMultiLineOfText(PdfFormField field, string text, BaseFont font, float fontSize, float llx, float lly, float urx, float ury)
        {
            PdfAppearance tp  = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly);
            PdfAppearance tp2 = (PdfAppearance)tp.Duplicate;

            tp2.SetFontAndSize(font, fontSize);
            tp2.ResetRGBColorFill();
            field.DefaultAppearanceString = tp2;
            tp.DrawTextField(0f, 0f, urx - llx, ury - lly);
            tp.BeginVariableText();
            tp.SaveState();
            tp.Rectangle(3f, 3f, urx - llx - 6f, ury - lly - 6f);
            tp.Clip();
            tp.NewPath();
            tp.BeginText();
            tp.SetFontAndSize(font, fontSize);
            tp.ResetRGBColorFill();
            tp.SetTextMatrix(4, 5);
            System.util.StringTokenizer tokenizer = new System.util.StringTokenizer(text, "\n");
            float yPos = ury - lly;

            while (tokenizer.HasMoreTokens())
            {
                yPos -= fontSize * 1.2f;
                tp.ShowTextAligned(PdfContentByte.ALIGN_LEFT, tokenizer.NextToken(), 3, yPos, 0);
            }
            tp.EndText();
            tp.RestoreState();
            tp.EndVariableText();
            field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
        }
Example #4
0
 internal bool SetField(String field, PdfObject value) {
     Hashtable map = fields;
     StringTokenizer tk = new StringTokenizer(field, ".");
     if (!tk.HasMoreTokens())
         return false;
     while (true) {
         String s = tk.NextToken();
         Object obj = map[s];
         if (tk.HasMoreTokens()) {
             if (obj == null) {
                 obj = new Hashtable();
                 map[s] = obj;
                 map = (Hashtable)obj;
                 continue;
             }
             else if (obj is Hashtable)
                 map = (Hashtable)obj;
             else
                 return false;
         }
         else {
             if (!(obj is Hashtable)) {
                 map[s] = value;
                 return true;
             }
             else
                 return false;
         }
     }
 }
Example #5
0
        public override IList<IElement> End(IWorkerContext ctx, Tag tag,
                    IList<IElement> currentContent)
        {

            IList<IElement> elems = new List<IElement>();

            IDictionary<String, String> attributes = tag.Attributes;

            if (attributes != null && attributes.ContainsKey(POINTS))
            {
                String str = attributes[POINTS];

                StringTokenizer tokenizer = new StringTokenizer(CleanPath(str), ", \t\n\r\f");
                IList<String> values = new List<String>();
                while (tokenizer.HasMoreTokens())
                {
                    String value = tokenizer.NextToken().Trim();
                    //System.out.Println(value);
                    values.Add(value);
                }
                PathBean.Builder pathBuilder = new PathBean.Builder();
                if (values.Count % 2 == 1)
                {
                    values.RemoveAt(values.Count - 1);
                }

                if (values.Count % 2 == 0)
                {
                    for (int i = 0; i < (values.Count / 2); i++)
                    {
                        PathItem.Builder itemBuilder = new PathItem.Builder();
                        if (i == 0)
                        {
                            itemBuilder.SetType('M');
                        }
                        else
                        {
                            itemBuilder.SetType('L');
                        }
                        itemBuilder.AddCoordinate(values[i * 2]);
                        itemBuilder.AddCoordinate(values[(i * 2) + 1]);
                        pathBuilder.SetPathItem(itemBuilder.Build());
                    }
                }
                if (tag.Name.Equals(SvgTagNames.POLYGON))
                {
                    PathItem.Builder itemBuilder = new PathItem.Builder();
                    itemBuilder.SetType('z');
                    pathBuilder.SetPathItem(itemBuilder.Build());
                }

                elems.Add(new Path(pathBuilder.Build(), tag.CSS));
                return elems;
            } else {
                return new List<IElement>(0);
            }
        }
Example #6
0
 static IList<String> SplitString(String transform)
 {
     List<String> list = new List<String>();
     StringTokenizer tokenizer = new StringTokenizer(transform, ")", false);
     while (tokenizer.HasMoreTokens())
     {
         list.Add(tokenizer.NextToken().Trim() + ")");
     }
     return list;
 }
Example #7
0
 static GlyphList()
 {
     Stream istr = null;
     try {
         istr = BaseFont.GetResourceStream(BaseFont.RESOURCE_PATH + "glyphlist.txt");
         if (istr == null) {
             String msg = "glyphlist.txt not found as resource.";
             throw new Exception(msg);
         }
         byte[] buf = new byte[1024];
         MemoryStream outp = new MemoryStream();
         while (true) {
             int size = istr.Read(buf, 0, buf.Length);
             if (size == 0)
                 break;
             outp.Write(buf, 0, size);
         }
         istr.Close();
         istr = null;
         String s = PdfEncodings.ConvertToString(outp.ToArray(), null);
         StringTokenizer tk = new StringTokenizer(s, "\r\n");
         while (tk.HasMoreTokens()) {
             String line = tk.NextToken();
             if (line.StartsWith("#"))
                 continue;
             StringTokenizer t2 = new StringTokenizer(line, " ;\r\n\t\f");
             String name = null;
             String hex = null;
             if (!t2.HasMoreTokens())
                 continue;
             name = t2.NextToken();
             if (!t2.HasMoreTokens())
                 continue;
             hex = t2.NextToken();
             int num = int.Parse(hex, NumberStyles.HexNumber);
             unicode2names[num] = name;
             names2unicode[name] = new int[]{num};
         }
     }
     catch (Exception e) {
         Console.Error.WriteLine("glyphlist.txt loading error: " + e.Message);
     }
     finally {
         if (istr != null) {
             try {
                 istr.Close();
             }
             catch {
                 // empty on purpose
             }
         }
     }
 }
Example #8
0
	    public override IList<IElement> Start(IWorkerContext ctx, Tag tag) {
		    float height = 0; //TODO check viewbox 
		    float width = 0; //TODO check viewbox 
		    Rectangle r = null;
		    String viewbox = "";
		    IDictionary<String, String> attributes = tag.Attributes;
		    if(attributes != null){
			    try {
                    if (attributes.ContainsKey("height")) {
                        height = float.Parse(attributes["height"]);
                    }
			    }catch {
				    //TODO
			    }	
			    try{
                    if (attributes.ContainsKey("width")) {
                        width = float.Parse(attributes["width"]);
                    }
			    }catch {
				    //TODO
			    }		
			    try{
                    if (attributes.TryGetValue("viewBox", out viewbox))
                    {
                        r = new Rectangle(0, 0);
                        StringTokenizer st = new StringTokenizer(viewbox);
                        if (st.HasMoreTokens())
                            r.Right = float.Parse(st.NextToken());
                        if (st.HasMoreTokens())
                            r.Bottom = -float.Parse(st.NextToken());
                        if (st.HasMoreTokens())
                            r.Left = r.Right + float.Parse(st.NextToken());
                        if (st.HasMoreTokens())
                            r.Top = r.Bottom + float.Parse(st.NextToken());
                        r.Normalize();
                    }
			    } catch {
				    //TODO
			    }
		    }
		    if (r == null) {
			    r = new Rectangle(width, height);
		    }
		    else if (width == 0 && height == 0) {
			    width = r.Width;
			    height = r.Height;
		    }
		    IList<IElement> elems = new List<IElement>();
		    elems.Add(new Svg(height, width, r, tag.CSS));
		    return elems;
	    }
Example #9
0
        private static void SetParagraphLeading(Paragraph p, String leading) {
            if (leading == null) {
                p.SetLeading(0, 1.5f);
                return;
            }
            try {
                StringTokenizer tk = new StringTokenizer(leading, " ,");
                String v = tk.NextToken();
                float v1 = float.Parse(v, System.Globalization.NumberFormatInfo.InvariantInfo);
                if (!tk.HasMoreTokens()) {
                    p.SetLeading(v1, 0);
                    return;
                }
                v = tk.NextToken();
                float v2 = float.Parse(v, System.Globalization.NumberFormatInfo.InvariantInfo);
                p.SetLeading(v1, v2);
            }
            catch {
                p.SetLeading(0, 1.5f);
            }

        }
Example #10
0
        public Font GetFont(ChainedProperties props) {
            String face = props[ElementTags.FACE];
            // try again, under the CSS key.  
            //ISSUE: If both are present, we always go with face, even if font-family was  
            //  defined more recently in our ChainedProperties.  One solution would go like this: 
            //    Map all our supported style attributes to the 'normal' tag name, so we could   
            //    look everything up under that one tag, retrieving the most current value.
            if (face == null || face.Trim().Length == 0) {
                face = props[Markup.CSS_KEY_FONTFAMILY];
            }
            if (face != null) {
                StringTokenizer tok = new StringTokenizer(face, ",");
                while (tok.HasMoreTokens()) {
                    face = tok.NextToken().Trim();
                    if (face.StartsWith("\""))
                        face = face.Substring(1);
                    if (face.EndsWith("\""))
                        face = face.Substring(0, face.Length - 1);
                    if (fontImp.IsRegistered(face))
                        break;
                }
            }
            int style = 0;
            String textDec = props[Markup.CSS_KEY_TEXTDECORATION];
            if (textDec != null && textDec.Trim().Length != 0) {
                if (Markup.CSS_VALUE_UNDERLINE.Equals(textDec)) {
                    style |= Font.UNDERLINE;
                }
                else if (Markup.CSS_VALUE_LINETHROUGH.Equals(textDec)) {
                    style |= Font.STRIKETHRU;
                }
            }
            if (props.HasProperty(HtmlTags.I))
                style |= Font.ITALIC;
            if (props.HasProperty(HtmlTags.B))
                style |= Font.BOLD;
            if (props.HasProperty(HtmlTags.U))
                style |= Font.UNDERLINE;
            if (props.HasProperty(HtmlTags.S))
                style |= Font.STRIKETHRU ;

            String value = props[ElementTags.SIZE];
            float size = 12;
            if (value != null)
                size = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
            BaseColor color = Markup.DecodeColor(props["color"]);
            String encoding = props["encoding"];
            if (encoding == null)
                encoding = BaseFont.WINANSI;
            return fontImp.GetFont(face, encoding, true, size, style, color);
        }
 virtual public void Text(String str) {
     StringTokenizer tk = new StringTokenizer(str);
     while (tk.HasMoreTokens()) {
         String word = tk.NextToken();
         // System.out.Println("\"" + word + "\"");
         switch (currElement) {
         case ELEM_CLASSES:
             consumer.AddClass(word);
             break;
         case ELEM_EXCEPTIONS:
             exception.Add(word);
             exception = NormalizeException(exception);
             consumer.AddException(GetExceptionWord(exception), new List<object>(exception));
             exception.Clear();
             break;
         case ELEM_PATTERNS:
             consumer.AddPattern(GetPattern(word),
                                 GetInterletterValues(word));
             break;
         }
     }
 }
Example #12
0
        /**
        * Creates an Table object based on a list of properties.
        * @param attributes
        * @return a Table
        */
        public static Table GetTable(Properties attributes)
        {
            String value;
            Table table;

            value = attributes[ElementTags.WIDTHS];
            if (value != null) {
                StringTokenizer widthTokens = new StringTokenizer(value, ";");
                ArrayList values = new ArrayList();
                while (widthTokens.HasMoreTokens()) {
                    values.Add(widthTokens.NextToken());
                }
                table = new Table(values.Count);
                float[] widths = new float[table.Columns];
                for (int i = 0; i < values.Count; i++) {
                    value = (String)values[i];
                    widths[i] = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
                }
                table.Widths = widths;
            }
            else {
                value = attributes[ElementTags.COLUMNS];
                try {
                    table = new Table(int.Parse(value));
                }
                catch {
                    table = new Table(1);
                }
            }

            table.Border = Table.BOX;
            table.BorderWidth = 1;
            table.DefaultCell.Border = Table.BOX;

            value = attributes[ElementTags.LASTHEADERROW];
            if (value != null) {
                table.LastHeaderRow = int.Parse(value);
            }
            value = attributes[ElementTags.ALIGN];
            if (value != null) {
                table.SetAlignment(value);
            }
            value = attributes[ElementTags.CELLSPACING];
            if (value != null) {
                table.Spacing = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            value = attributes[ElementTags.CELLPADDING];
            if (value != null) {
                table.Padding = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            value = attributes[ElementTags.OFFSET];
            if (value != null) {
                table.Offset = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            value = attributes[ElementTags.WIDTH];
            if (value != null) {
                if (value.EndsWith("%"))
                    table.Width = float.Parse(value.Substring(0, value.Length - 1), System.Globalization.NumberFormatInfo.InvariantInfo);
                else {
                    table.Width = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
                    table.Locked = true;
                }
            }
            table.TableFitsPage = Utilities.CheckTrueOrFalse(attributes, ElementTags.TABLEFITSPAGE);
            table.CellsFitPage = Utilities.CheckTrueOrFalse(attributes, ElementTags.CELLSFITPAGE);
            table.Convert2pdfptable = Utilities.CheckTrueOrFalse(attributes, ElementTags.CONVERT2PDFP);

            SetRectangleProperties(table, attributes);
            return table;
        }
Example #13
0
 private float GetBBox(int idx) {
     string s = (string)fontDesc["FontBBox"];
     StringTokenizer tk = new StringTokenizer(s, " []\r\n\t\f");
     string ret = tk.NextToken();
     for (int k = 0; k < idx; ++k)
         ret = tk.NextToken();
     return int.Parse(ret);
 }
Example #14
0
 /**
  * Creates a Font object based on a chain of properties.
  * @param   chain   chain of properties
  * @return  an iText Font object
  */
 public Font GetFont(ChainedProperties chain) {
     
     // [1] font name
     
     String face = chain[HtmlTags.FACE];
     // try again, under the CSS key.  
     //ISSUE: If both are present, we always go with face, even if font-family was  
     //  defined more recently in our ChainedProperties.  One solution would go like this: 
     //    Map all our supported style attributes to the 'normal' tag name, so we could   
     //    look everything up under that one tag, retrieving the most current value.
     if (face == null || face.Trim().Length == 0) {
         face = chain[HtmlTags.FONTFAMILY];
     }
     // if the font consists of a comma separated list,
     // take the first font that is registered
     if (face != null) {
         StringTokenizer tok = new StringTokenizer(face, ",");
         while (tok.HasMoreTokens()) {
             face = tok.NextToken().Trim();
             if (face.StartsWith("\""))
                 face = face.Substring(1);
             if (face.EndsWith("\""))
                 face = face.Substring(0, face.Length - 1);
             if (provider.IsRegistered(face))
                 break;
         }
     }
     
     // [2] encoding
     String encoding = chain[HtmlTags.ENCODING];
     if (encoding == null)
         encoding = BaseFont.WINANSI;
     
     // [3] embedded
     
     // [4] font size
     String value = chain[HtmlTags.SIZE];
     float size = 12;
     if (value != null)
         size = float.Parse(value, CultureInfo.InvariantCulture);
     
     // [5] font style
     int style = 0;
     
     // text-decoration
     String decoration = chain[HtmlTags.TEXTDECORATION];
     if (decoration != null && decoration.Trim().Length != 0) {
       if (HtmlTags.UNDERLINE.Equals(decoration)) {
         style |= Font.UNDERLINE;
       } else if (HtmlTags.LINETHROUGH.Equals(decoration)) {
         style |= Font.STRIKETHRU;
       }
     }
     // italic
     if (chain.HasProperty(HtmlTags.I))
         style |= Font.ITALIC;
     // bold
     if (chain.HasProperty(HtmlTags.B))
         style |= Font.BOLD;
     // underline
     if (chain.HasProperty(HtmlTags.U))
         style |= Font.UNDERLINE;
     // strikethru
     if (chain.HasProperty(HtmlTags.S))
         style |= Font.STRIKETHRU;
     
     // [6] Color
     BaseColor color = HtmlUtilities.DecodeColor(chain[HtmlTags.COLOR]);
     
     // Get the font object from the provider
     return provider.GetFont(face, encoding, true, size, style, color);
 }
Example #15
0
 virtual public void DrawMultiLineOfText(PdfFormField field, string text, BaseFont font, float fontSize, float llx, float lly, float urx, float ury) {
     PdfAppearance tp = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly);
     PdfAppearance tp2 = (PdfAppearance)tp.Duplicate;
     tp2.SetFontAndSize(font, fontSize);
     tp2.ResetRGBColorFill();
     field.DefaultAppearanceString = tp2;
     tp.DrawTextField(0f, 0f, urx - llx, ury - lly);
     tp.BeginVariableText();
     tp.SaveState();
     tp.Rectangle(3f, 3f, urx - llx - 6f, ury - lly - 6f);
     tp.Clip();
     tp.NewPath();
     tp.BeginText();
     tp.SetFontAndSize(font, fontSize);
     tp.ResetRGBColorFill();
     tp.SetTextMatrix(4, 5);
     System.util.StringTokenizer tokenizer = new System.util.StringTokenizer(text, "\n");
     float yPos = ury - lly;
     while (tokenizer.HasMoreTokens()) {
         yPos -= fontSize * 1.2f;
         tp.ShowTextAligned(PdfContentByte.ALIGN_LEFT, tokenizer.NextToken(), 3, yPos, 0);
     }
     tp.EndText();
     tp.RestoreState();
     tp.EndVariableText();
     field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
 }
 public static Object[] IterateOutlines(PdfWriter writer, PdfIndirectReference parent, IList<Dictionary<String, Object>> kids, bool namedAsNames) {
     PdfIndirectReference[] refs = new PdfIndirectReference[kids.Count];
     for (int k = 0; k < refs.Length; ++k)
         refs[k] = writer.PdfIndirectReference;
     int ptr = 0;
     int count = 0;
     foreach (Dictionary<String, Object> map in kids) {
         Object[] lower = null;
         IList<Dictionary<String, Object>> subKid = null;
         if (map.ContainsKey("Kids"))
             subKid = (IList<Dictionary<String, Object>>)map["Kids"];
         if (subKid != null && subKid.Count > 0)
             lower = IterateOutlines(writer, refs[ptr], subKid, namedAsNames);
         PdfDictionary outline = new PdfDictionary();
         ++count;
         if (lower != null) {
             outline.Put(PdfName.FIRST, (PdfIndirectReference)lower[0]);
             outline.Put(PdfName.LAST, (PdfIndirectReference)lower[1]);
             int n = (int)lower[2];
             if (map.ContainsKey("Open") && "false".Equals(map["Open"])) {
                 outline.Put(PdfName.COUNT, new PdfNumber(-n));
             }
             else {
                 outline.Put(PdfName.COUNT, new PdfNumber(n));
                 count += n;
             }
         }
         outline.Put(PdfName.PARENT, parent);
         if (ptr > 0)
             outline.Put(PdfName.PREV, refs[ptr - 1]);
         if (ptr < refs.Length - 1)
             outline.Put(PdfName.NEXT, refs[ptr + 1]);
         outline.Put(PdfName.TITLE, new PdfString((String)map["Title"], PdfObject.TEXT_UNICODE));
         String color = null;
         if (map.ContainsKey("Color"))
             color = (String)map["Color"];
         if (color != null) {
             try {
                 PdfArray arr = new PdfArray();
                 StringTokenizer tk = new StringTokenizer(color);
                 for (int k = 0; k < 3; ++k) {
                     float f = float.Parse(tk.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                     if (f < 0) f = 0;
                     if (f > 1) f = 1;
                     arr.Add(new PdfNumber(f));
                 }
                 outline.Put(PdfName.C, arr);
             } catch {} //in case it's malformed
         }
         String style = GetVal(map, "Style");
         if (style != null) {
             style = style.ToLower(System.Globalization.CultureInfo.InvariantCulture);
             int bits = 0;
             if (style.IndexOf("italic") >= 0)
                 bits |= 1;
             if (style.IndexOf("bold") >= 0)
                 bits |= 2;
             if (bits != 0)
                 outline.Put(PdfName.F, new PdfNumber(bits));
         }
         CreateOutlineAction(outline, map, writer, namedAsNames);
         writer.AddToBody(outline, refs[ptr]);
         ++ptr;
     }
     return new Object[]{refs[0], refs[refs.Length - 1], count};
 }
Example #17
0
 /** Creates a CJK font.
  * @param fontName the name of the font
  * @param enc the encoding of the font
  * @param emb always <CODE>false</CODE>. CJK font and not embedded
  * @throws DocumentException on error
  * @throws IOException on error
  */
 internal CJKFont(string fontName, string enc, bool emb)
 {
     LoadProperties();
     this.FontType = FONT_TYPE_CJK;
     string nameBase = GetBaseName(fontName);
     if (!IsCJKFont(nameBase, enc))
     throw new DocumentException("Font '" + fontName + "' with '" + enc + "' encoding is not a CJK font.");
     if (nameBase.Length < fontName.Length) {
     style = fontName.Substring(nameBase.Length);
     fontName = nameBase;
     }
     this.fontName = fontName;
     encoding = CJK_ENCODING;
     vertical = enc.EndsWith("V");
     CMap = enc;
     if (enc.StartsWith("Identity-")) {
     cidDirect = true;
     string s = cjkFonts[fontName];
     s = s.Substring(0, s.IndexOf('_'));
     char[] c = (char[])allCMaps[s];
     if (c == null) {
         c = ReadCMap(s);
         if (c == null)
             throw new DocumentException("The cmap " + s + " does not exist as a resource.");
         c[CID_NEWLINE] = '\n';
         allCMaps.Add(s, c);
     }
     translationMap = c;
     }
     else {
     char[] c = (char[])allCMaps[enc];
     if (c == null) {
         string s = cjkEncodings[enc];
         if (s == null)
             throw new DocumentException("The resource cjkencodings.properties does not contain the encoding " + enc);
         StringTokenizer tk = new StringTokenizer(s);
         string nt = tk.NextToken();
         c = (char[])allCMaps[nt];
         if (c == null) {
             c = ReadCMap(nt);
             allCMaps.Add(nt, c);
         }
         if (tk.HasMoreTokens()) {
             string nt2 = tk.NextToken();
             char[] m2 = ReadCMap(nt2);
             for (int k = 0; k < 0x10000; ++k) {
                 if (m2[k] == 0)
                     m2[k] = c[k];
             }
             allCMaps.Add(enc, m2);
             c = m2;
         }
     }
     translationMap = c;
     }
     fontDesc = (Hashtable)allFonts[fontName];
     if (fontDesc == null) {
     fontDesc = ReadFontProperties(fontName);
     allFonts.Add(fontName, fontDesc);
     }
     hMetrics = (IntHashtable)fontDesc["W"];
     vMetrics = (IntHashtable)fontDesc["W2"];
 }
 internal static PdfArray CreateDestinationArray(String value, PdfWriter writer)
 {
     PdfArray ar = new PdfArray();
     StringTokenizer tk = new StringTokenizer(value);
     int n = int.Parse(tk.NextToken());
     ar.Add(writer.GetPageReference(n));
     if (!tk.HasMoreTokens()) {
         ar.Add(PdfName.XYZ);
         ar.Add(new float[]{0, 10000, 0});
     }
     else {
         String fn = tk.NextToken();
         if (fn.StartsWith("/"))
             fn = fn.Substring(1);
         ar.Add(new PdfName(fn));
         for (int k = 0; k < 4 && tk.HasMoreTokens(); ++k) {
             fn = tk.NextToken();
             if (fn.Equals("null"))
                 ar.Add(PdfNull.PDFNULL);
             else
                 ar.Add(new PdfNumber(fn));
         }
     }
     return ar;
 }
Example #19
0
        /** Reads the font metrics
         * @param rf the AFM file
         * @throws DocumentException the AFM file is invalid
         * @throws IOException the AFM file could not be read
         */
        virtual public void Process(RandomAccessFileOrArray rf) {
            string line;
            bool isMetrics = false;
            while ((line = rf.ReadLine()) != null) {
                StringTokenizer tok = new StringTokenizer(line, " ,\n\r\t\f");
                if (!tok.HasMoreTokens())
                    continue;
                string ident = tok.NextToken();
                if (ident.Equals("FontName"))
                    FontName = tok.NextToken("\u00ff").Substring(1);
                else if (ident.Equals("FullName"))
                    FullName = tok.NextToken("\u00ff").Substring(1);
                else if (ident.Equals("FamilyName"))
                    FamilyName = tok.NextToken("\u00ff").Substring(1);
                else if (ident.Equals("Weight"))
                    Weight = tok.NextToken("\u00ff").Substring(1);
                else if (ident.Equals("ItalicAngle"))
                    ItalicAngle = float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                else if (ident.Equals("IsFixedPitch"))
                    IsFixedPitch = tok.NextToken().Equals("true");
                else if (ident.Equals("CharacterSet"))
                    CharacterSet = tok.NextToken("\u00ff").Substring(1);
                else if (ident.Equals("FontBBox")) {
                    llx = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                    lly = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                    urx = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                    ury = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                }
                else if (ident.Equals("UnderlinePosition"))
                    UnderlinePosition = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                else if (ident.Equals("UnderlineThickness"))
                    UnderlineThickness = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                else if (ident.Equals("EncodingScheme"))
                    EncodingScheme = tok.NextToken("\u00ff").Substring(1);
                else if (ident.Equals("CapHeight"))
                    CapHeight = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                else if (ident.Equals("XHeight"))
                    XHeight = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                else if (ident.Equals("Ascender"))
                    Ascender = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                else if (ident.Equals("Descender"))
                    Descender = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                else if (ident.Equals("StdHW"))
                    StdHW = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                else if (ident.Equals("StdVW"))
                    StdVW = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                else if (ident.Equals("StartCharMetrics")) {
                    isMetrics = true;
                    break;
                }
            }
            if (!isMetrics)
                throw new DocumentException(MessageLocalization.GetComposedMessage("missing.startcharmetrics.in.1", fileName));
            while ((line = rf.ReadLine()) != null) {
                StringTokenizer tok = new StringTokenizer(line);
                if (!tok.HasMoreTokens())
                    continue;
                string ident = tok.NextToken();
                if (ident.Equals("EndCharMetrics")) {
                    isMetrics = false;
                    break;
                }
                int C = -1;
                int WX = 250;
                string N = "";
                int[] B = null;

                tok = new StringTokenizer(line, ";");
                while (tok.HasMoreTokens())
                {
                    StringTokenizer tokc = new StringTokenizer(tok.NextToken());
                    if (!tokc.HasMoreTokens())
                        continue;
                    ident = tokc.NextToken();
                    if (ident.Equals("C"))
                        C = int.Parse(tokc.NextToken());
                    else if (ident.Equals("WX"))
                        WX = (int)float.Parse(tokc.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                    else if (ident.Equals("N"))
                        N = tokc.NextToken();
                    else if (ident.Equals("B")) {
                        B = new int[]{int.Parse(tokc.NextToken()), 
                                            int.Parse(tokc.NextToken()),
                                            int.Parse(tokc.NextToken()),
                                            int.Parse(tokc.NextToken())};
                    }
                }
                Object[] metrics = new Object[]{C, WX, N, B};
                if (C >= 0)
                    CharMetrics[C] = metrics;
                CharMetrics[N] = metrics;
            }
            if (isMetrics)
                throw new DocumentException(MessageLocalization.GetComposedMessage("missing.endcharmetrics.in.1", fileName));
            if (!CharMetrics.ContainsKey("nonbreakingspace")) {
                Object[] space;
                CharMetrics.TryGetValue("space", out space);
                if (space != null)
                    CharMetrics["nonbreakingspace"] = space;
            }
            while ((line = rf.ReadLine()) != null) {
                StringTokenizer tok = new StringTokenizer(line);
                if (!tok.HasMoreTokens())
                    continue;
                string ident = tok.NextToken();
                if (ident.Equals("EndFontMetrics"))
                    return;
                if (ident.Equals("StartKernPairs")) {
                    isMetrics = true;
                    break;
                }
            }
            if (!isMetrics)
                throw new DocumentException(MessageLocalization.GetComposedMessage("missing.endfontmetrics.in.1", fileName));
            while ((line = rf.ReadLine()) != null) {
                StringTokenizer tok = new StringTokenizer(line);
                if (!tok.HasMoreTokens())
                    continue;
                string ident = tok.NextToken();
                if (ident.Equals("KPX")) {
                    string first = tok.NextToken();
                    string second = tok.NextToken();
                    int width = (int)float.Parse(tok.NextToken(), System.Globalization.NumberFormatInfo.InvariantInfo);
                    Object[] relates;
                    KernPairs.TryGetValue(first, out relates);
                    if (relates == null)
                        KernPairs[first] = new Object[]{second, width};
                    else {
                        int n = relates.Length;
                        Object[] relates2 = new Object[n + 2];
                        Array.Copy(relates, 0, relates2, 0, n);
                        relates2[n] = second;
                        relates2[n + 1] = width;
                        KernPairs[first] = relates2;
                    }
                }
                else if (ident.Equals("EndKernPairs")) {
                    isMetrics = false;
                    break;
                }
            }
            if (isMetrics)
                throw new DocumentException(MessageLocalization.GetComposedMessage("missing.endkernpairs.in.1", fileName));
            rf.Close();
        }
Example #20
0
 /**
 * Gives you a Color based on a name.
 *
 * @param name
 *            a name such as black, violet, cornflowerblue or #RGB or #RRGGBB
 *            or rgb(R,G,B)
 * @return the corresponding Color object
 * @throws IllegalArgumentException
 *             if the String isn't a know representation of a color.
 */
 public static Color GetRGBColor(String name)
 {
     int[] c = { 0, 0, 0, 0 };
     if (name.StartsWith("#")) {
         if (name.Length == 4) {
             c[0] = int.Parse(name.Substring(1, 1), NumberStyles.HexNumber) * 16;
             c[1] = int.Parse(name.Substring(2, 1), NumberStyles.HexNumber) * 16;
             c[2] = int.Parse(name.Substring(3), NumberStyles.HexNumber) * 16;
             return new Color(c[0], c[1], c[2], c[3]);
         }
         if (name.Length == 7) {
             c[0] = int.Parse(name.Substring(1, 2), NumberStyles.HexNumber);
             c[1] = int.Parse(name.Substring(3, 2), NumberStyles.HexNumber);
             c[2] = int.Parse(name.Substring(5), NumberStyles.HexNumber);
             return new Color(c[0], c[1], c[2], c[3]);
         }
         throw new ArgumentException(
                 "Unknown color format. Must be #RGB or #RRGGBB");
     }
     else if (name.StartsWith("rgb(")) {
         StringTokenizer tok = new StringTokenizer(name, "rgb(), \t\r\n\f");
         for (int k = 0; k < 3; ++k) {
             String v = tok.NextToken();
             if (v.EndsWith("%"))
                 c[k] = int.Parse(v.Substring(0, v.Length - 1)) * 255 / 100;
             else
                 c[k] = int.Parse(v);
             if (c[k] < 0)
                 c[k] = 0;
             else if (c[k] > 255)
                 c[k] = 255;
         }
         return new Color(c[0], c[1], c[2], c[3]);
     }
     name = name.ToLower(CultureInfo.InvariantCulture);
     if (!NAMES.ContainsKey(name))
         throw new ArgumentException("Color '" + name
                 + "' not found.");
     c = (int[]) NAMES[name];
     return new Color(c[0], c[1], c[2], c[3]);
 }
Example #21
0
 static HTMLWorker() {
     StringTokenizer tok = new StringTokenizer(tagsSupportedString);
     while (tok.HasMoreTokens())
         tagsSupported[tok.NextToken()] = null;
 }
Example #22
0
 static IList<float> GetValuesFromStr(String str)
 {
     try
     {
         int index = str.IndexOf('(') + 1;
         int count = str.IndexOf(')') - index;
         String numbers = str.Substring(index, count);
         IList<float> result = new List<float>();
         StringTokenizer tokenizer = new StringTokenizer(numbers, ",");
         while (tokenizer.HasMoreTokens())
         {
             result.Add(float.Parse(tokenizer.NextToken()));
         }
         return result;
     }
     catch 
     {
         throw new SvgParseException("Could not parse the transform");
     }
 }
Example #23
0
 internal static IntHashtable CreateMetric(string s) {
     IntHashtable h = new IntHashtable();
     StringTokenizer tk = new StringTokenizer(s);
     while (tk.HasMoreTokens()) {
         int n1 = int.Parse(tk.NextToken());
         h[n1] = int.Parse(tk.NextToken());
     }
     return h;
 }
Example #24
0
 internal void MergeField(String name, AcroFields.Item item) {
     Dictionary<string,object> map = fieldTree;
     StringTokenizer tk = new StringTokenizer(name, ".");
     if (!tk.HasMoreTokens())
         return;
     while (true) {
         String s = tk.NextToken();
         Object obj;
         map.TryGetValue(s, out obj);
         if (tk.HasMoreTokens()) {
             if (obj == null) {
                 obj = new Dictionary<string,object>();
                 map[s] = obj;
                 map = (Dictionary<string,object>)obj;
                 continue;
             }
             else if (obj is Dictionary<string,object>)
                 map = (Dictionary<string,object>)obj;
             else
                 return;
         }
         else {
             if (obj is Dictionary<string,object>)
                 return;
             PdfDictionary merged = item.GetMerged(0);
             if (obj == null) {
                 PdfDictionary field = new PdfDictionary();
                 if (PdfName.SIG.Equals(merged.Get(PdfName.FT)))
                     hasSignature = true;
                 foreach (PdfName key in merged.Keys) {
                     if (fieldKeys.ContainsKey(key))
                         field.Put(key, merged.Get(key));
                 }
                 List<object> list = new List<object>();
                 list.Add(field);
                 CreateWidgets(list, item);
                 map[s] =  list;
             }
             else {
                 List<object> list = (List<object>)obj;
                 PdfDictionary field = (PdfDictionary)list[0];
                 PdfName type1 = (PdfName)field.Get(PdfName.FT);
                 PdfName type2 = (PdfName)merged.Get(PdfName.FT);
                 if (type1 == null || !type1.Equals(type2))
                     return;
                 int flag1 = 0;
                 PdfObject f1 = field.Get(PdfName.FF);
                 if (f1 != null && f1.IsNumber())
                     flag1 = ((PdfNumber)f1).IntValue;
                 int flag2 = 0;
                 PdfObject f2 = merged.Get(PdfName.FF);
                 if (f2 != null && f2.IsNumber())
                     flag2 = ((PdfNumber)f2).IntValue;
                 if (type1.Equals(PdfName.BTN)) {
                     if (((flag1 ^ flag2) & PdfFormField.FF_PUSHBUTTON) != 0)
                         return;
                     if ((flag1 & PdfFormField.FF_PUSHBUTTON) == 0 && ((flag1 ^ flag2) & PdfFormField.FF_RADIO) != 0)
                         return;
                 }
                 else if (type1.Equals(PdfName.CH)) {
                     if (((flag1 ^ flag2) & PdfFormField.FF_COMBO) != 0)
                         return;
                 }
                 CreateWidgets(list, item);
             }
             return;
         }
     }
 }
 internal static void CreateOutlineAction(PdfDictionary outline, Dictionary<String, Object> map, PdfWriter writer, bool namedAsNames) {
     try {
         String action = GetVal(map, "Action");
         if ("GoTo".Equals(action)) {
             String p;
             if ((p = GetVal(map, "Named")) != null) {
                 if (namedAsNames)
                     outline.Put(PdfName.DEST, new PdfName(p));
                 else
                     outline.Put(PdfName.DEST, new PdfString(p, null));
             }
             else if ((p = GetVal(map, "Page")) != null) {
                 PdfArray ar = new PdfArray();
                 StringTokenizer tk = new StringTokenizer(p);
                 int n = int.Parse(tk.NextToken());
                 ar.Add(writer.GetPageReference(n));
                 if (!tk.HasMoreTokens()) {
                     ar.Add(PdfName.XYZ);
                     ar.Add(new float[]{0, 10000, 0});
                 }
                 else {
                     String fn = tk.NextToken();
                     if (fn.StartsWith("/"))
                         fn = fn.Substring(1);
                     ar.Add(new PdfName(fn));
                     for (int k = 0; k < 4 && tk.HasMoreTokens(); ++k) {
                         fn = tk.NextToken();
                         if (fn.Equals("null"))
                             ar.Add(PdfNull.PDFNULL);
                         else
                             ar.Add(new PdfNumber(fn));
                     }
                 }
                 outline.Put(PdfName.DEST, ar);
             }
         }
         else if ("GoToR".Equals(action)) {
             String p;
             PdfDictionary dic = new PdfDictionary();
             if ((p = GetVal(map, "Named")) != null)
                 dic.Put(PdfName.D, new PdfString(p, null));
             else if ((p = GetVal(map, "NamedN")) != null)
                 dic.Put(PdfName.D, new PdfName(p));
             else if ((p = GetVal(map, "Page")) != null){
                 PdfArray ar = new PdfArray();
                 StringTokenizer tk = new StringTokenizer(p);
                 ar.Add(new PdfNumber(tk.NextToken()));
                 if (!tk.HasMoreTokens()) {
                     ar.Add(PdfName.XYZ);
                     ar.Add(new float[]{0, 10000, 0});
                 }
                 else {
                     String fn = tk.NextToken();
                     if (fn.StartsWith("/"))
                         fn = fn.Substring(1);
                     ar.Add(new PdfName(fn));
                     for (int k = 0; k < 4 && tk.HasMoreTokens(); ++k) {
                         fn = tk.NextToken();
                         if (fn.Equals("null"))
                             ar.Add(PdfNull.PDFNULL);
                         else
                             ar.Add(new PdfNumber(fn));
                     }
                 }
                 dic.Put(PdfName.D, ar);
             }
             String file = GetVal(map, "File");
             if (dic.Size > 0 && file != null) {
                 dic.Put(PdfName.S,  PdfName.GOTOR);
                 dic.Put(PdfName.F, new PdfString(file));
                 String nw = GetVal(map, "NewWindow");
                 if (nw != null) {
                     if (nw.Equals("true"))
                         dic.Put(PdfName.NEWWINDOW, PdfBoolean.PDFTRUE);
                     else if (nw.Equals("false"))
                         dic.Put(PdfName.NEWWINDOW, PdfBoolean.PDFFALSE);
                 }
                 outline.Put(PdfName.A, dic);
             }
         }
         else if ("URI".Equals(action)) {
             String uri = GetVal(map, "URI");
             if (uri != null) {
                 PdfDictionary dic = new PdfDictionary();
                 dic.Put(PdfName.S, PdfName.URI);
                 dic.Put(PdfName.URI, new PdfString(uri));
                 outline.Put(PdfName.A, dic);
             }
         }
         else if ("JS".Equals(action)) {
             String code = GetVal(map, "Code");
             if(code != null) {
                 outline.Put(PdfName.A, PdfAction.JavaScript(code, writer));
             }
         }
         else if ("Launch".Equals(action)) {
             String file = GetVal(map, "File");
             if (file != null) {
                 PdfDictionary dic = new PdfDictionary();
                 dic.Put(PdfName.S, PdfName.LAUNCH);
                 dic.Put(PdfName.F, new PdfString(file));
                 outline.Put(PdfName.A, dic);
             }
         }
     }
     catch  {
         // empty on purpose
     }
 }
Example #26
0
 /** Gets the field value.
 * @param field the field name
 * @return the field value or <CODE>null</CODE> if not found
 */    
 public String GetField(String field) {
     Dictionary<String, Object> map = fields;
     StringTokenizer tk = new StringTokenizer(field, ".");
     if (!tk.HasMoreTokens())
         return null;
     while (true) {
         String s = tk.NextToken();
         Object obj;
         map.TryGetValue(s, out obj);
         if (obj == null)
             return null;
         if (tk.HasMoreTokens()) {
             if (obj is Dictionary<String, Object>)
                 map = (Dictionary<String, Object>)obj;
             else
                 return null;
         }
         else {
             if (obj is Dictionary<String, Object>)
                 return null;
             else {
                 if (((PdfObject)obj).IsString())
                     return ((PdfString)obj).ToUnicodeString();
                 else
                     return PdfName.DecodeName(obj.ToString());
             }
         }
     }
 }
Example #27
0
 /**
  * Creates the <CODE>widths</CODE> and the <CODE>differences</CODE> arrays
  * @throws UnsupportedEncodingException the encoding is not supported
  */
 protected void CreateEncoding() {
     if (encoding.StartsWith("#")) {
         specialMap = new IntHashtable();
         StringTokenizer tok = new StringTokenizer(encoding.Substring(1), " ,\t\n\r\f");
         if (tok.NextToken().Equals("full")) {
             while (tok.HasMoreTokens()) {
                 String order = tok.NextToken();
                 String name = tok.NextToken();
                 char uni = (char)int.Parse(tok.NextToken(), NumberStyles.HexNumber);
                 int orderK;
                 if (order.StartsWith("'"))
                     orderK = (int)order[1];
                 else
                     orderK = int.Parse(order);
                 orderK %= 256;
                 specialMap[(int)uni] = orderK;
                 differences[orderK] = name;
                 unicodeDifferences[orderK] = uni;
                 widths[orderK] = GetRawWidth((int)uni, name);
                 charBBoxes[orderK] = GetRawCharBBox((int)uni, name);
             }
         }
         else {
             int k = 0;
             if (tok.HasMoreTokens())
                 k = int.Parse(tok.NextToken());
             while (tok.HasMoreTokens() && k < 256) {
                 String hex = tok.NextToken();
                 int uni = int.Parse(hex, NumberStyles.HexNumber) % 0x10000;
                 String name = GlyphList.UnicodeToName(uni);
                 if (name != null) {
                     specialMap[uni] = k;
                     differences[k] = name;
                     unicodeDifferences[k] = (char)uni;
                     widths[k] = GetRawWidth(uni, name);
                     charBBoxes[k] = GetRawCharBBox(uni, name);
                     ++k;
                 }
             }
         }
         for (int k = 0; k < 256; ++k) {
             if (differences[k] == null) {
                 differences[k] = notdef;
             }
         }
     }
     else if (fontSpecific) {
         for (int k = 0; k < 256; ++k) {
             widths[k] = GetRawWidth(k, null);
             charBBoxes[k] = GetRawCharBBox(k, null);
         }
     }
     else {
         string s;
         string name;
         char c;
         byte[] b = new byte[1];
         for (int k = 0; k < 256; ++k) {
             b[0] = (byte)k;
             s = PdfEncodings.ConvertToString(b, encoding);
             if (s.Length > 0) {
                 c = s[0];
             }
             else {
                 c = '?';
             }
             name = GlyphList.UnicodeToName((int)c);
             if (name == null)
                 name = notdef;
             differences[k] = name;
             this.UnicodeDifferences[k] = c;
             widths[k] = GetRawWidth((int)c, name);
             charBBoxes[k] = GetRawCharBBox((int)c, name);
         }
     }
 }
Example #28
0
 internal static void EncodeStream(Stream inp, List<char[]> planes) {
     StreamReader rd = new StreamReader(inp, Encoding.ASCII);
     String line = null;
     int state = CIDNONE;
     byte[] seqs = new byte[7];
     while ((line = rd.ReadLine()) != null) {
         if (line.Length < 6)
             continue;
         switch (state) {
             case CIDNONE: {
                 if (line.IndexOf("begincidrange") >= 0)
                     state = CIDRANGE;
                 else if (line.IndexOf("begincidchar") >= 0)
                     state = CIDCHAR;
                 else if (line.IndexOf("usecmap") >= 0) {
                     StringTokenizer tk = new StringTokenizer(line);
                     String t = tk.NextToken();
                     ReadCmap(t.Substring(1), planes);
                 }
                 break;
             }
             case CIDRANGE: {
                 if (line.IndexOf("endcidrange") >= 0) {
                     state = CIDNONE;
                     break;
                 }
                 StringTokenizer tk = new StringTokenizer(line);
                 String t = tk.NextToken();
                 int size = t.Length / 2 - 1;
                 long start = long.Parse(t.Substring(1, t.Length - 2), NumberStyles.HexNumber);
                 t = tk.NextToken();
                 long end = long.Parse(t.Substring(1, t.Length - 2), NumberStyles.HexNumber);
                 t = tk.NextToken();
                 int cid = int.Parse(t);
                 for (long k = start; k <= end; ++k) {
                     BreakLong(k, size, seqs);
                     EncodeSequence(size, seqs, (char)cid, planes);
                     ++cid;
                 }
                 break;
             }
             case CIDCHAR: {
                 if (line.IndexOf("endcidchar") >= 0) {
                     state = CIDNONE;
                     break;
                 }
                 StringTokenizer tk = new StringTokenizer(line);
                 String t = tk.NextToken();
                 int size = t.Length / 2 - 1;
                 long start = long.Parse(t.Substring(1, t.Length - 2), NumberStyles.HexNumber);
                 t = tk.NextToken();
                 int cid = int.Parse(t);
                 BreakLong(start, size, seqs);
                 EncodeSequence(size, seqs, (char)cid, planes);
                 break;
             }
         }
     }
 }
Example #29
0
 /**
  * Sets the leading of a Paragraph object.
  * @param   paragraph   the Paragraph for which we set the leading
  * @param   leading     the String value of the leading
  */
 protected static void SetParagraphLeading(Paragraph paragraph, String leading) {
     // default leading
     if (leading == null) {
         paragraph.SetLeading(0, 1.5f);
         return;
     }
     try {
         StringTokenizer tk = new StringTokenizer(leading, " ,");
         // absolute leading
         String v = tk.NextToken();
         float v1 = float.Parse(v, CultureInfo.InvariantCulture);
         if (!tk.HasMoreTokens()) {
             paragraph.SetLeading(v1, 0);
             return;
         }
         // relative leading
         v = tk.NextToken();
         float v2 = float.Parse(v, CultureInfo.InvariantCulture);
         paragraph.SetLeading(v1, v2);
     } catch {
         // default leading
         paragraph.SetLeading(0, 1.5f);
     }
 }
Example #30
0
 /// <summary>
 /// This method parses a string with attributes and returns a Properties object.
 /// </summary>
 /// <param name="str">a string of this form: 'key1="value1"; key2="value2";... keyN="valueN" '</param>
 /// <returns>a Properties object</returns>
 public static Properties ParseAttributes(string str) {
     Properties result = new Properties();
     if (str == null) return result;
     StringTokenizer keyValuePairs = new StringTokenizer(str, ";");
     StringTokenizer keyValuePair;
     string key;
     string value;
     while (keyValuePairs.HasMoreTokens()) {
         keyValuePair = new StringTokenizer(keyValuePairs.NextToken(), ":");
         if (keyValuePair.HasMoreTokens()) key = keyValuePair.NextToken().Trim().Trim();
         else continue;
         if (keyValuePair.HasMoreTokens()) value = keyValuePair.NextToken().Trim();
         else continue;
         if (value.StartsWith("\"")) value = value.Substring(1);
         if (value.EndsWith("\"")) value = value.Substring(0, value.Length - 1);
         result.Add(key.ToLower(CultureInfo.InvariantCulture), value);
     }
     return result;
 }
Example #31
0
 /** Removes the field value.
 * @param field the field name
 * @return <CODE>true</CODE> if the field was found and removed,
 * <CODE>false</CODE> otherwise
 */    
 public bool RemoveField(String field) {
     Dictionary<String, Object> map = fields;
     StringTokenizer tk = new StringTokenizer(field, ".");
     if (!tk.HasMoreTokens())
         return false;
     List<object> hist = new List<object>();
     while (true) {
         String s = tk.NextToken();
         Object obj;
         map.TryGetValue(s, out obj);
         if (obj == null)
             return false;
         hist.Add(map);
         hist.Add(s);
         if (tk.HasMoreTokens()) {
             if (obj is Dictionary<String, Object>)
                 map = (Dictionary<String, Object>)obj;
             else
                 return false;
         }
         else {
             if (obj is Dictionary<String, Object>)
                 return false;
             else
                 break;
         }
     }
     for (int k = hist.Count - 2; k >= 0; k -= 2) {
         map = (Dictionary<String, Object>)hist[k];
         String s = (String)hist[k + 1];
         map.Remove(s);
         if (map.Count > 0)
             break;
     }
     return true;
 }
Example #32
0
 internal void MergeField(String name, AcroFields.Item item)
 {
     Hashtable map = fieldTree;
     StringTokenizer tk = new StringTokenizer(name, ".");
     if (!tk.HasMoreTokens())
         return;
     while (true) {
         String s = tk.NextToken();
         Object obj = map[s];
         if (tk.HasMoreTokens()) {
             if (obj == null) {
                 obj = new Hashtable();
                 map[s] =  obj;
                 map = (Hashtable)obj;
                 continue;
             }
             else if (obj is Hashtable)
                 map = (Hashtable)obj;
             else
                 return;
         }
         else {
             if (obj is Hashtable)
                 return;
             PdfDictionary merged = (PdfDictionary)item.merged[0];
             if (obj == null) {
                 PdfDictionary field = new PdfDictionary();
                 foreach (PdfName key in merged.Keys) {
                     if (fieldKeys.ContainsKey(key))
                         field.Put(key, merged.Get(key));
                 }
                 ArrayList list = new ArrayList();
                 list.Add(field);
                 CreateWidgets(list, item);
                 map[s] =  list;
             }
             else {
                 ArrayList list = (ArrayList)obj;
                 PdfDictionary field = (PdfDictionary)list[0];
                 PdfName type1 = (PdfName)field.Get(PdfName.FT);
                 PdfName type2 = (PdfName)merged.Get(PdfName.FT);
                 if (type1 == null || !type1.Equals(type2))
                     return;
                 int flag1 = 0;
                 PdfObject f1 = field.Get(PdfName.FF);
                 if (f1 != null && f1.IsNumber())
                     flag1 = ((PdfNumber)f1).IntValue;
                 int flag2 = 0;
                 PdfObject f2 = merged.Get(PdfName.FF);
                 if (f2 != null && f2.IsNumber())
                     flag2 = ((PdfNumber)f2).IntValue;
                 if (type1.Equals(PdfName.BTN)) {
                     if (((flag1 ^ flag2) & PdfFormField.FF_PUSHBUTTON) != 0)
                         return;
                     if ((flag1 & PdfFormField.FF_PUSHBUTTON) == 0 && ((flag1 ^ flag2) & PdfFormField.FF_RADIO) != 0)
                         return;
                 }
                 else if (type1.Equals(PdfName.CH)) {
                     if (((flag1 ^ flag2) & PdfFormField.FF_COMBO) != 0)
                         return;
                 }
                 CreateWidgets(list, item);
             }
             return;
         }
     }
 }