IsString() public method

public IsString ( ) : bool
return bool
Ejemplo n.º 1
0
 private void SerObject(PdfObject obj, int level, ByteBuffer bb)
 {
     if (level <= 0)
         return;
     if (obj == null) {
         bb.Append("$Lnull");
         return;
     }
     obj = PdfReader.GetPdfObject(obj);
     if (obj.IsStream()) {
         bb.Append("$B");
         SerDic((PdfDictionary)obj, level - 1, bb);
         if (level > 0) {
             bb.Append(PdfEncryption.DigestComputeHash("MD5", PdfReader.GetStreamBytesRaw((PRStream)obj)));
         }
     }
     else if (obj.IsDictionary()) {
         SerDic((PdfDictionary)obj, level - 1, bb);
     }
     else if (obj.IsArray()) {
         SerArray((PdfArray)obj, level - 1, bb);
     }
     else if (obj.IsString()) {
         bb.Append("$S").Append(obj.ToString());
     }
     else if (obj.IsName()) {
         bb.Append("$N").Append(obj.ToString());
     }
     else
         bb.Append("$L").Append(obj.ToString());
 }
Ejemplo n.º 2
0
 private static void MapGotoBookmark(Dictionary<String, Object> map, PdfObject dest, IntHashtable pages) 
 {
     if (dest.IsString())
         map["Named"] = dest.ToString();
     else if (dest.IsName())
         map["Named"] = PdfName.DecodeName(dest.ToString());
     else if (dest.IsArray()) 
         map["Page"] = MakeBookmarkParam((PdfArray)dest, pages); //changed by ujihara 2004-06-13
     map["Action"] = "GoTo";
 }
Ejemplo n.º 3
0
            private void SerObject(PdfObject obj, int level, ByteBuffer bb, Dictionary<RefKey, int> serialized)
            {
                if (level <= 0)
                    return;
                if (obj == null) {
                    bb.Append("$Lnull");
                    return;
                }

                PdfIndirectReference refe = null;
                ByteBuffer savedBb = null;

                if (obj.IsIndirect()) {
                    refe = (PdfIndirectReference)obj;
                    RefKey key = new RefKey(refe);
                    if (serialized.ContainsKey(key)) {
                        bb.Append(serialized[key]);
                        return;
                    }
                    else {
                        savedBb = bb;
                        bb = new ByteBuffer();
                    }
                }
                obj = PdfReader.GetPdfObject(obj);
                if (obj.IsStream()) {
                    bb.Append("$B");
                    SerDic((PdfDictionary)obj, level - 1, bb, serialized);
                    if (level > 0) {
                        bb.Append(DigestAlgorithms.Digest("MD5", PdfReader.GetStreamBytesRaw((PRStream)obj)));
                    }
                }
                else if (obj.IsDictionary()) {
                    SerDic((PdfDictionary)obj, level - 1, bb,serialized);
                }
                else if (obj.IsArray()) {
                    SerArray((PdfArray)obj, level - 1, bb,serialized);
                }
                else if (obj.IsString()) {
                    bb.Append("$S").Append(obj.ToString());
                }
                else if (obj.IsName()) {
                    bb.Append("$N").Append(obj.ToString());
                }
                else
                    bb.Append("$L").Append(obj.ToString());

                if (savedBb != null) {
                    RefKey key = new RefKey(refe);
                    if (!serialized.ContainsKey(key))
                        serialized[key] = CalculateHash(bb.Buffer);
                    savedBb.Append(bb);
                }
            }
Ejemplo n.º 4
0
        public static bool CompareObjects(PdfObject value1, PdfObject value2) {
            value2 = GetDirectObject(value2);
            if (value2 == null)
                return false;
            if (value1.Type != value2.Type)
                return false;

            if (value1.IsBoolean()){
                if (value1 == value2)
                    return true;
                if (value2 is PdfBoolean) {
                    return ((PdfBoolean)value1).BooleanValue == ((PdfBoolean)value2).BooleanValue;
                }
                return false;
            } else if (value1.IsName()) {
                return value1.Equals(value2);
            } else if (value1.IsNumber()){
                if (value1 == value2)
                    return true;
                if (value2 is PdfNumber) {
                    return ((PdfNumber)value1).DoubleValue == ((PdfNumber)value2).DoubleValue;
                }
                return false;
            } else if (value1.IsNull()){
                if (value1 == value2)
                    return true;
                if (value2 is PdfNull)
                    return true;
                return false;
            } else if (value1.IsString()){
                if (value1 == value2)
                    return true;
                if (value2 is PdfString) {
                    return ((value2 == null && value1.ToString() == null)
                        || value1.ToString() == value2.ToString());
                }
                return false;
            }
            if (value1.IsArray()) {
                PdfArray array1 = (PdfArray)value1;
                PdfArray array2 = (PdfArray)value2;
                if (array1.Size != array2.Size)
                    return false;
                for (int i = 0; i < array1.Size; ++i)
                    if (!CompareObjects(array1[i],array2[i]))
                        return false;
                return true;
            }
            if (value1.IsDictionary()) {
                PdfDictionary first = (PdfDictionary)value1;
                PdfDictionary second = (PdfDictionary)value2;
                if (first.Size != second.Size)
                    return false;
                foreach (PdfName name in first.hashMap.Keys) {
                    if (!CompareObjects(first.Get(name),second.Get(name)))
                        return false;
                }
                return true;
            }
            return false;
        }
Ejemplo n.º 5
0
 private void SerObject(PdfObject obj, int level, ByteBuffer bb) {
     if (level <= 0)
         return;
     if (obj == null) {
         bb.Append("$Lnull");
         return;
     }
     if (obj.IsIndirect()) {
         if (serialized.Contains(obj))
             return;
         else
             serialized.Add(obj);
     }
     obj = PdfReader.GetPdfObject(obj);
     if (obj.IsStream()) {
         bb.Append("$B");
         SerDic((PdfDictionary)obj, level - 1, bb);
         if (level > 0) {
             bb.Append(DigestAlgorithms.Digest("MD5", PdfReader.GetStreamBytesRaw((PRStream)obj)));
         }
     }
     else if (obj.IsDictionary()) {
         SerDic((PdfDictionary)obj, level - 1, bb);
     }
     else if (obj.IsArray()) {
         SerArray((PdfArray)obj, level - 1, bb);
     }
     else if (obj.IsString()) {
         bb.Append("$S").Append(obj.ToString());
     }
     else if (obj.IsName()) {
         bb.Append("$N").Append(obj.ToString());
     }
     else
         bb.Append("$L").Append(obj.ToString());
 }
Ejemplo n.º 6
0
        private void FillMetrics(byte[] touni, IntHashtable widths, int dw)
        {
            PdfContentParser ps       = new PdfContentParser(new PRTokeniser(touni));
            PdfObject        ob       = null;
            bool             notFound = true;
            int nestLevel             = 0;

            while ((notFound || nestLevel > 0) && (ob = ps.ReadPRObject()) != null)
            {
                if (ob.Type == PdfContentParser.COMMAND_TYPE)
                {
                    if (ob.ToString().Equals("begin"))
                    {
                        notFound = false;
                        nestLevel++;
                    }
                    else if (ob.ToString().Equals("end"))
                    {
                        nestLevel--;
                    }
                    else if (ob.ToString().Equals("beginbfchar"))
                    {
                        while (true)
                        {
                            PdfObject nx = ps.ReadPRObject();
                            if (nx.ToString().Equals("endbfchar"))
                            {
                                break;
                            }
                            String cid = DecodeString((PdfString)nx);
                            String uni = DecodeString((PdfString)ps.ReadPRObject());
                            if (uni.Length == 1)
                            {
                                int cidc = (int)cid[0];
                                int unic = (int)uni[uni.Length - 1];
                                int w    = dw;
                                if (widths.ContainsKey(cidc))
                                {
                                    w = widths[cidc];
                                }
                                metrics[unic] = new int[] { cidc, w };
                            }
                        }
                    }
                    else if (ob.ToString().Equals("beginbfrange"))
                    {
                        while (true)
                        {
                            PdfObject nx = ps.ReadPRObject();
                            if (nx.ToString().Equals("endbfrange"))
                            {
                                break;
                            }
                            String    cid1  = DecodeString((PdfString)nx);
                            String    cid2  = DecodeString((PdfString)ps.ReadPRObject());
                            int       cid1c = (int)cid1[0];
                            int       cid2c = (int)cid2[0];
                            PdfObject ob2   = ps.ReadPRObject();
                            if (ob2.IsString())
                            {
                                String uni = DecodeString((PdfString)ob2);
                                if (uni.Length == 1)
                                {
                                    int unic = (int)uni[uni.Length - 1];
                                    for (; cid1c <= cid2c; cid1c++, unic++)
                                    {
                                        int w = dw;
                                        if (widths.ContainsKey(cid1c))
                                        {
                                            w = widths[cid1c];
                                        }
                                        metrics[unic] = new int[] { cid1c, w };
                                    }
                                }
                            }
                            else
                            {
                                PdfArray a = (PdfArray)ob2;
                                for (int j = 0; j < a.Size; ++j, ++cid1c)
                                {
                                    String uni = DecodeString(a.GetAsString(j));
                                    if (uni.Length == 1)
                                    {
                                        int unic = (int)uni[uni.Length - 1];
                                        int w    = dw;
                                        if (widths.ContainsKey(cid1c))
                                        {
                                            w = widths[cid1c];
                                        }
                                        metrics[unic] = new int[] { cid1c, w };
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }