示例#1
0
 /// <summary>Reads the /Order in the /D entry and initialized the parent-child hierarchy.</summary>
 private void ReadOrderFromDictionary(PdfLayer parent, PdfArray orderArray, IDictionary <PdfIndirectReference
                                                                                         , PdfLayer> layerMap)
 {
     for (int i = 0; i < orderArray.Size(); i++)
     {
         PdfObject item = orderArray.Get(i);
         if (item.GetObjectType() == PdfObject.DICTIONARY)
         {
             PdfLayer layer = layerMap.Get(item.GetIndirectReference());
             if (layer != null)
             {
                 layers.Add(layer);
                 layer.onPanel = true;
                 if (parent != null)
                 {
                     parent.AddChild(layer);
                 }
                 if (i + 1 < orderArray.Size() && orderArray.Get(i + 1).GetObjectType() == PdfObject.ARRAY)
                 {
                     PdfArray nextArray = orderArray.GetAsArray(i + 1);
                     if (nextArray.Size() > 0 && nextArray.Get(0).GetObjectType() != PdfObject.STRING)
                     {
                         ReadOrderFromDictionary(layer, orderArray.GetAsArray(i + 1), layerMap);
                         i++;
                     }
                 }
             }
         }
         else
         {
             if (item.GetObjectType() == PdfObject.ARRAY)
             {
                 PdfArray subArray = (PdfArray)item;
                 if (subArray.IsEmpty())
                 {
                     continue;
                 }
                 PdfObject firstObj = subArray.Get(0);
                 if (firstObj.GetObjectType() == PdfObject.STRING)
                 {
                     PdfLayer titleLayer = PdfLayer.CreateTitleSilent(((PdfString)firstObj).ToUnicodeString(), GetDocument());
                     titleLayer.onPanel = true;
                     layers.Add(titleLayer);
                     if (parent != null)
                     {
                         parent.AddChild(titleLayer);
                     }
                     ReadOrderFromDictionary(titleLayer, new PdfArray(subArray.SubList(1, subArray.Size())), layerMap);
                 }
                 else
                 {
                     ReadOrderFromDictionary(parent, subArray, layerMap);
                 }
             }
         }
     }
 }