/** * <summary>Finds the location of the sublayers object in the specified configuration; in case no * sublayers object is associated to this object, its virtual position is indicated.</summary> * <param name="configuration">Configuration context.</param> * <returns><code>null</code>, if this layer is outside the specified configuration.</returns> */ private LayersLocation FindLayersLocation( LayerConfiguration configuration ) { /* * NOTE: As layers are only weakly tied to configurations, their sublayers have to be sought * through the configuration structure tree. */ PdfDirectObject levelLayerObject = null; PdfArray levelObject = configuration.UILayers.BaseDataObject; IEnumerator <PdfDirectObject> levelIterator = levelObject.GetEnumerator(); Stack <object[]> levelIterators = new Stack <object[]>(); PdfDirectObject thisObject = BaseObject; PdfDirectObject currentLayerObject = null; while (true) { if (!levelIterator.MoveNext()) { if (levelIterators.Count == 0) { break; } object[] levelItems = levelIterators.Pop(); levelObject = (PdfArray)levelItems[0]; levelIterator = (IEnumerator <PdfDirectObject>)levelItems[1]; levelLayerObject = (PdfDirectObject)levelItems[2]; currentLayerObject = null; } else { PdfDirectObject nodeObject = levelIterator.Current; PdfDataObject nodeDataObject = PdfObject.Resolve(nodeObject); if (nodeDataObject is PdfDictionary) { if (nodeObject.Equals(thisObject)) { /* * NOTE: Sublayers are expressed as an array immediately following the parent layer node. */ return(new LayersLocation(levelLayerObject, levelObject, levelObject.IndexOf(thisObject) + 1, levelIterators)); } currentLayerObject = nodeObject; } else if (nodeDataObject is PdfArray) { levelIterators.Push(new object[] { levelObject, levelIterator, levelLayerObject }); levelObject = (PdfArray)nodeDataObject; levelIterator = levelObject.GetEnumerator(); levelLayerObject = currentLayerObject; currentLayerObject = null; } } } return(null); }
/** * <summary>Gets the position of the initial base item corresponding to the specified layer * state.</summary> * <param name="item">Layer state.</param> * <returns>-1, in case <code>item</code> has no match.</returns> */ internal int GetBaseIndex( LayerState item ) { int baseIndex = -1; { PdfArray baseDataObject = BaseDataObject; for ( int baseItemIndex = 0, baseItemCount = baseDataObject.Count; baseItemIndex < baseItemCount; baseItemIndex++ ) { PdfDirectObject baseItem = baseDataObject[baseItemIndex]; if (baseItem is PdfName && baseItem.Equals(item.Mode.GetName())) { foreach (Layer layer in item.Layers) { if (++baseItemIndex >= baseItemCount) { break; } baseItem = baseDataObject[baseItemIndex]; if (baseItem is PdfName || !baseItem.Equals(layer.BaseObject)) { break; } } } } } return(baseIndex); }