コード例 #1
0
 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;
 }
コード例 #2
0
ファイル: WebColors.cs プロジェクト: pixelia-es/RazorPDF2
 /**
 * 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]);
 }
コード例 #3
0
 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),
                                 (ArrayList)exception.Clone());
             exception.Clear();
             break;
         case ELEM_PATTERNS:
             consumer.AddPattern(GetPattern(word),
                                 GetInterletterValues(word));
             break;
         }
     }
 }
コード例 #4
0
ファイル: Type1Font.cs プロジェクト: pixelia-es/RazorPDF2
        /** 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
         */
        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(), 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(), NumberFormatInfo.InvariantInfo);
                    lly = (int)float.Parse(tok.NextToken(), NumberFormatInfo.InvariantInfo);
                    urx = (int)float.Parse(tok.NextToken(), NumberFormatInfo.InvariantInfo);
                    ury = (int)float.Parse(tok.NextToken(), NumberFormatInfo.InvariantInfo);
                }
                else if (ident.Equals("UnderlinePosition"))
                    UnderlinePosition = (int)float.Parse(tok.NextToken(), NumberFormatInfo.InvariantInfo);
                else if (ident.Equals("UnderlineThickness"))
                    UnderlineThickness = (int)float.Parse(tok.NextToken(), NumberFormatInfo.InvariantInfo);
                else if (ident.Equals("EncodingScheme"))
                    EncodingScheme = tok.NextToken("\u00ff").Substring(1);
                else if (ident.Equals("CapHeight"))
                    CapHeight = (int)float.Parse(tok.NextToken(), NumberFormatInfo.InvariantInfo);
                else if (ident.Equals("XHeight"))
                    XHeight = (int)float.Parse(tok.NextToken(), NumberFormatInfo.InvariantInfo);
                else if (ident.Equals("Ascender"))
                    Ascender = (int)float.Parse(tok.NextToken(), NumberFormatInfo.InvariantInfo);
                else if (ident.Equals("Descender"))
                    Descender = (int)float.Parse(tok.NextToken(), NumberFormatInfo.InvariantInfo);
                else if (ident.Equals("StdHW"))
                    StdHW = (int)float.Parse(tok.NextToken(), NumberFormatInfo.InvariantInfo);
                else if (ident.Equals("StdVW"))
                    StdVW = (int)float.Parse(tok.NextToken(), NumberFormatInfo.InvariantInfo);
                else if (ident.Equals("StartCharMetrics")) {
                    isMetrics = true;
                    break;
                }
            }
            if (!isMetrics)
                throw new DocumentException("Missing StartCharMetrics in " + 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(), 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("Missing EndCharMetrics in " + fileName);
            if (!CharMetrics.ContainsKey("nonbreakingspace")) {
                Object[] space = (Object[])CharMetrics["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("Missing EndFontMetrics in " + 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(), NumberFormatInfo.InvariantInfo);
                    Object[] relates = (Object[])KernPairs[first];
                    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("Missing EndKernPairs in " + fileName);
            rf.Close();
        }
コード例 #5
0
 public static Object[] IterateOutlines(PdfWriter writer, PdfIndirectReference parent, ArrayList 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 (Hashtable map in kids) {
         Object[] lower = null;
         ArrayList subKid = (ArrayList)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 ("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 = (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(), 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 = (String)map["Style"];
         if (style != null) {
             style = style.ToLower(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};
 }
コード例 #6
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, 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, NumberFormatInfo.InvariantInfo);
            }
            value = attributes[ElementTags.CELLPADDING];
            if (value != null) {
                table.Padding = float.Parse(value, NumberFormatInfo.InvariantInfo);
            }
            value = attributes[ElementTags.OFFSET];
            if (value != null) {
                table.Offset = float.Parse(value, NumberFormatInfo.InvariantInfo);
            }
            value = attributes[ElementTags.WIDTH];
            if (value != null) {
                if (value.EndsWith("%"))
                    table.Width = float.Parse(value.Substring(0, value.Length - 1), NumberFormatInfo.InvariantInfo);
                else {
                    table.Width = float.Parse(value, 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;
        }
コード例 #7
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, NumberFormatInfo.InvariantInfo);
         if (!tk.HasMoreTokens()) {
             p.SetLeading(v1, 0);
             return;
         }
         v = tk.NextToken();
         float v2 = float.Parse(v, NumberFormatInfo.InvariantInfo);
         p.SetLeading(v1, v2);
     }
     catch {
         p.SetLeading(0, 1.5f);
     }
 }
コード例 #8
0
ファイル: CJKFont.cs プロジェクト: pixelia-es/RazorPDF2
 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);
 }
コード例 #9
0
ファイル: FdfWriter.cs プロジェクト: pixelia-es/RazorPDF2
 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;
         }
     }
 }
コード例 #10
0
        public Font GetFont(ChainedProperties props)
        {
            String face = props[ElementTags.FACE];
            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;
            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, NumberFormatInfo.InvariantInfo);
            Color color = Markup.DecodeColor(props["color"]);
            String encoding = props["encoding"];
            if (encoding == null)
                encoding = BaseFont.WINANSI;
            return fontImp.GetFont(face, encoding, true, size, style, color);
        }
コード例 #11
0
ファイル: FdfWriter.cs プロジェクト: pixelia-es/RazorPDF2
 /** 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)
 {
     Hashtable map = fields;
     StringTokenizer tk = new StringTokenizer(field, ".");
     if (!tk.HasMoreTokens())
         return false;
     ArrayList hist = new ArrayList();
     while (true) {
         String s = tk.NextToken();
         Object obj = map[s];
         if (obj == null)
             return false;
         hist.Add(map);
         hist.Add(s);
         if (tk.HasMoreTokens()) {
             if (obj is Hashtable)
                 map = (Hashtable)obj;
             else
                 return false;
         }
         else {
             if (obj is Hashtable)
                 return false;
             else
                 break;
         }
     }
     for (int k = hist.Count - 2; k >= 0; k -= 2) {
         map = (Hashtable)hist[k];
         String s = (String)hist[k + 1];
         map.Remove(s);
         if (map.Count > 0)
             break;
     }
     return true;
 }
コード例 #12
0
ファイル: FdfWriter.cs プロジェクト: pixelia-es/RazorPDF2
 /** 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)
 {
     Hashtable map = fields;
     StringTokenizer tk = new StringTokenizer(field, ".");
     if (!tk.HasMoreTokens())
         return null;
     while (true) {
         String s = tk.NextToken();
         Object obj = map[s];
         if (obj == null)
             return null;
         if (tk.HasMoreTokens()) {
             if (obj is Hashtable)
                 map = (Hashtable)obj;
             else
                 return null;
         }
         else {
             if (obj is Hashtable)
                 return null;
             else {
                 if (((PdfObject)obj).IsString())
                     return ((PdfString)obj).ToUnicodeString();
                 else
                     return PdfName.DecodeName(obj.ToString());
             }
         }
     }
 }
コード例 #13
0
 internal static void CreateOutlineAction(PdfDictionary outline, Hashtable map, PdfWriter writer, bool namedAsNames)
 {
     try {
         String action = (String)map["Action"];
         if ("GoTo".Equals(action)) {
             String p;
             if ((p = (String)map["Named"]) != null) {
                 if (namedAsNames)
                     outline.Put(PdfName.DEST, new PdfName(p));
                 else
                     outline.Put(PdfName.DEST, new PdfString(p, null));
             }
             else if ((p = (String)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 = (String)map["Named"]) != null)
                 dic.Put(PdfName.D, new PdfString(p, null));
             else if ((p = (String)map["NamedN"]) != null)
                 dic.Put(PdfName.D, new PdfName(p));
             else if ((p = (String)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 = (String)map["File"];
             if (dic.Size > 0 && file != null) {
                 dic.Put(PdfName.S,  PdfName.GOTOR);
                 dic.Put(PdfName.F, new PdfString(file));
                 String nw = (String)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 = (String)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 ("Launch".Equals(action)) {
             String file = (String)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
     }
 }
コード例 #14
0
ファイル: CJKFont.cs プロジェクト: pixelia-es/RazorPDF2
 /** 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"];
 }
コード例 #15
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 = 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));
                 }
                 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;
         }
     }
 }
コード例 #16
0
ファイル: CJKFont.cs プロジェクト: pixelia-es/RazorPDF2
 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;
 }
コード例 #17
0
ファイル: Markup.cs プロジェクト: pixelia-es/RazorPDF2
 /// <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;
 }
コード例 #18
0
ファイル: PdfAcroForm.cs プロジェクト: pixelia-es/RazorPDF2
 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);
     var tokenizer = new 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);
 }
コード例 #19
0
ファイル: GlyphList.cs プロジェクト: pixelia-es/RazorPDF2
 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
             }
         }
     }
 }