Пример #1
0
        protected override void CheckLayer(PdfWriter writer, int key, Object obj1) {
            if (obj1 is IPdfOCG) {

            } else if (obj1 is PdfOCProperties) {
                PdfOCProperties properties = (PdfOCProperties)obj1;
                List<PdfDictionary> configsList = new List<PdfDictionary>();
                PdfDictionary d = GetDirectDictionary(properties.Get(PdfName.D));
                if (d != null)
                    configsList.Add(d);
                PdfArray configs = GetDirectArray(properties.Get(PdfName.CONFIGS));
                if (configs != null) {
                    for (int i = 0; i < configs.Size; i++) {
                        PdfDictionary config = GetDirectDictionary(configs[i]);
                        if (config != null)
                            configsList.Add(config);
                    }
                }
                HashSet2<PdfObject> ocgs = new HashSet2<PdfObject>();
                PdfArray ocgsArray = GetDirectArray(properties.Get(PdfName.OCGS));
                if (ocgsArray != null)
                    for (int i = 0; i < ocgsArray.Size; i++)
                        ocgs.Add(ocgsArray[i]);
                HashSet2<String> names = new HashSet2<String>();
                HashSet2<PdfObject> order = new HashSet2<PdfObject>();
                foreach (PdfDictionary config in configsList) {
                    PdfString name = config.GetAsString(PdfName.NAME);
                    if (name == null) {
                        throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("optional.content.configuration.dictionary.shall.contain.name.entry"));
                    }
                    String name1 = name.ToUnicodeString();
                    if (names.Contains(name1)) {
                        throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("value.of.name.entry.shall.be.unique.amongst.all.optional.content.configuration.dictionaries"));
                    }
                    names.Add(name1);
                    if (config.Contains(PdfName.AS)) {
                        throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("the.as.key.shall.not.appear.in.any.optional.content.configuration.dictionary"));
                    }
                    PdfArray orderArray = GetDirectArray(config.Get(PdfName.ORDER));
                    if (orderArray != null)
                        FillOrderRecursively(orderArray, order);
                }
                if (order.Count != ocgs.Count) {
                    throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("order.array.shall.contain.references.to.all.ocgs"));
                }
                ocgs.RetainAll(order);
                if (order.Count != ocgs.Count) {
                    throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("order.array.shall.contain.references.to.all.ocgs"));
                }
            } else {

            }
        }
Пример #2
0
 protected override void CheckLayer(PdfWriter writer, int key, Object obj1)
 {
     if (obj1 is IPdfOCG)
     {
     }
     else if (obj1 is PdfOCProperties)
     {
         PdfOCProperties      properties  = (PdfOCProperties)obj1;
         List <PdfDictionary> configsList = new List <PdfDictionary>();
         PdfDictionary        d           = properties.GetAsDict(PdfName.D);
         if (d != null)
         {
             configsList.Add(d);
         }
         PdfArray configs = properties.GetAsArray(PdfName.CONFIGS);
         if (configs != null)
         {
             for (int i = 0; i < configs.Size; i++)
             {
                 PdfDictionary config = configs.GetAsDict(i);
                 if (config != null)
                 {
                     configsList.Add(config);
                 }
             }
         }
         HashSet2 <PdfObject> ocgs      = new HashSet2 <PdfObject>();
         PdfArray             ocgsArray = properties.GetAsArray(PdfName.OCGS);
         if (ocgsArray != null)
         {
             for (int i = 0; i < ocgsArray.Size; i++)
             {
                 ocgs.Add(ocgsArray[i]);
             }
         }
         HashSet2 <String>    names = new HashSet2 <String>();
         HashSet2 <PdfObject> order = new HashSet2 <PdfObject>();
         foreach (PdfDictionary config in configsList)
         {
             PdfString name = config.GetAsString(PdfName.NAME);
             if (name == null)
             {
                 throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("optional.content.configuration.dictionary.shall.contain.name.entry"));
             }
             String name1 = name.ToUnicodeString();
             if (names.Contains(name1))
             {
                 throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("value.of.name.entry.shall.be.unique.amongst.all.optional.content.configuration.dictionaries"));
             }
             names.Add(name1);
             if (config.Contains(PdfName.AS))
             {
                 throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("the.as.key.shall.not.appear.in.any.optional.content.configuration.dictionary"));
             }
             PdfArray orderArray = config.GetAsArray(PdfName.ORDER);
             if (orderArray != null)
             {
                 fillOrderRecursively(orderArray, order);
             }
         }
         if (order.Count != ocgs.Count)
         {
             throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("order.array.shall.contain.references.to.all.ocgs"));
         }
         ocgs.RetainAll(order);
         if (order.Count != ocgs.Count)
         {
             throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("order.array.shall.contain.references.to.all.ocgs"));
         }
     }
     else
     {
     }
 }