/** * <summary>Wraps a destination base object into a destination object.</summary> * <param name="baseObject">Destination base object.</param> * <returns>Destination object associated to the base object.</returns> */ public static Destination Wrap( PdfDirectObject baseObject ) { if (baseObject == null) { return(null); } PdfArray dataObject = (PdfArray)baseObject.Resolve(); PdfDirectObject pageObject = dataObject[0]; if (pageObject is PdfReference) { return(new LocalDestination(baseObject)); } else if (pageObject is PdfInteger) { return(new RemoteDestination(baseObject)); } else { throw new ArgumentException("Not a valid destination object.", "baseObject"); } }
public IPdfObjectWrapper Wrap( PdfDirectObject baseObject ) { if (baseObject.Resolve() is PdfArray) { return(VisibilityExpression.Wrap(baseObject)); } else { return(Layer.Wrap(baseObject)); } }
public bool MoveNext() { if (nextObject == null) { return(false); } currentObject = nextObject; nextObject = ((PdfDictionary)currentObject.Resolve())[PdfName.N]; if (nextObject == firstObject) // Looping back. { nextObject = null; } return(true); }
public IPdfObjectWrapper Wrap(PdfDirectObject baseObject) { if (baseObject.Wrapper is IPdfObjectWrapper wrapper) { return(wrapper); } if (baseObject.Resolve() is PdfArray) { return(Wrap <VisibilityExpression>(baseObject)); } else { return(Wrap <Layer>(baseObject)); } }
public static ILayerNode Wrap( PdfDirectObject baseObject ) { if(baseObject == null) return null; PdfDataObject baseDataObject = baseObject.Resolve(); if(baseDataObject is PdfDictionary) return Layer.Wrap(baseObject); else if(baseDataObject is PdfArray) return Layers.Wrap(baseObject); else throw new ArgumentException(baseDataObject.GetType().Name + " is NOT a valid layer node."); }
/** * <summary>Wraps a font reference into a font object.</summary> * <param name="baseObject">Font base object.</param> * <returns>Font object associated to the reference.</returns> */ public static Font Wrap(PdfDirectObject baseObject) { if (baseObject == null) { return(null); } if (baseObject.Wrapper is Font font) { return(font); } if (baseObject is PdfReference pdfReference && pdfReference.DataObject?.Wrapper is Font referenceFont) { baseObject.Wrapper = referenceFont; return(referenceFont); } // Has the font been already instantiated? /* * NOTE: Font structures are reified as complex objects, both IO- and CPU-intensive to load. * So, it's convenient to retrieve them from a common cache whenever possible. */ if (baseObject.File.Document.Cache.TryGetValue(baseObject, out var cache)) { return((Font)cache); } PdfDictionary fontDictionary = (PdfDictionary)baseObject.Resolve(); PdfName fontType = (PdfName)fontDictionary[PdfName.Subtype]; if (fontType == null) { throw new Exception("Font type undefined (reference: " + baseObject + ")"); } if (fontType.Equals(PdfName.Type1)) // Type 1. { var fd = fontDictionary.Resolve(PdfName.FontDescriptor); if (fd is PdfDictionary fdDictionary && fdDictionary.ContainsKey(PdfName.FontFile3)) { return(new PdfType1CFont(baseObject)); } else { return(new PdfType1Font(baseObject)); } }
IEnumerator <Bookmark> IEnumerable <Bookmark> .GetEnumerator( ) { PdfDirectObject bookmarkObject = BaseDataObject[PdfName.First]; if (bookmarkObject == null) { yield break; } do { yield return(new Bookmark(bookmarkObject)); bookmarkObject = ((PdfDictionary)bookmarkObject.Resolve())[PdfName.Next]; }while(bookmarkObject != null); }
/** * <summary>Wraps a language identifier base object into a language identifier object.</summary> */ public static LanguageIdentifier Wrap( PdfDirectObject baseObject ) { if (baseObject == null) { return(null); } if (baseObject.Resolve() is PdfTextString) { return(new LanguageIdentifier(baseObject)); } else { throw new ArgumentException("It doesn't represent a valid language identifier object.", "baseObject"); } }
/** * <summary>Wraps a function base object into a function object.</summary> * <param name="baseObject">Function base object.</param> * <returns>Function object associated to the base object.</returns> */ public static Function Wrap(PdfDirectObject baseObject) { if (baseObject == null) { return(null); } if (baseObject.Wrapper is Function function) { return(function); } if (baseObject is PdfReference pdfReference && pdfReference.DataObject?.Wrapper is Function referenceFunction) { baseObject.Wrapper = referenceFunction; return(referenceFunction); } var dataObject = baseObject.Resolve(); var dictionary = GetDictionary(dataObject); int functionType = ((PdfInteger)dictionary[PdfName.FunctionType]).RawValue; switch (functionType) { case FunctionType0: return(new Type0Function(baseObject)); case FunctionType2: return(new Type2Function(baseObject)); case FunctionType3: return(new Type3Function(baseObject)); case FunctionType4: return(new Type4Function(baseObject)); default: throw new NotSupportedException("Function type " + functionType + " unknown."); } }
//TODO:shading types! #region static #region interface #region public public static Shading Wrap(PdfDirectObject baseObject) { if (baseObject == null) { return(null); } if (baseObject.Wrapper is Shading shading) { return(shading); } if (baseObject is PdfReference reference && reference.DataObject?.Wrapper is Shading referenceShading) { baseObject.Wrapper = referenceShading; return(referenceShading); } var dataObject = baseObject.Resolve(); var dictionary = TryGetDictionary(dataObject); var type = ((PdfInteger)dictionary.Resolve(PdfName.ShadingType))?.RawValue; switch (type) { case 1: return(new FunctionBasedShading(baseObject)); case 2: return(new AxialShading(baseObject)); case 3: return(new RadialShading(baseObject)); case 4: return(new FreeFormShading(baseObject)); case 5: return(new LatticeFormShading(baseObject)); case 6: return(new CoonsFormShading(baseObject)); case 7: return(new TensorProductShading(baseObject)); } return(new Shading(baseObject)); } //TODO:shading types!
public static MediaOffset Wrap( PdfDirectObject baseObject ) { if (baseObject == null) { return(null); } PdfDictionary dataObject = (PdfDictionary)baseObject.Resolve(); PdfName offsetType = (PdfName)dataObject[PdfName.S]; if (offsetType == null || (dataObject.ContainsKey(PdfName.Type) && !dataObject[PdfName.Type].Equals(PdfName.MediaOffset))) { return(null); } if (offsetType.Equals(PdfName.F)) { return(new Frame(baseObject)); } else if (offsetType.Equals(PdfName.M)) { return(new Marker(baseObject)); } else if (offsetType.Equals(PdfName.T)) { return(new Time(baseObject)); } else { throw new NotSupportedException(); } }
/** * <summary>Wraps a language identifier base object into a language identifier object.</summary> */ public static LanguageIdentifier Wrap(PdfDirectObject baseObject) { if (baseObject == null) { return(null); } if (baseObject.Wrapper is LanguageIdentifier identifier) { return(identifier); } if (baseObject is PdfReference pdfReference && pdfReference.DataObject?.Wrapper is LanguageIdentifier referenceIdentifier) { baseObject.Wrapper = referenceIdentifier; return(referenceIdentifier); } if (baseObject.Resolve() is PdfTextString) { return(new LanguageIdentifier(baseObject)); } else { throw new ArgumentException("It doesn't represent a valid language identifier object.", "baseObject"); } }
/** * <summary>Wraps an external object reference into an external object.</summary> * <param name="baseObject">External object base object.</param> * <returns>External object associated to the reference.</returns> */ public static XObject Wrap( PdfDirectObject baseObject ) { if (baseObject == null) { return(null); } PdfName subtype = (PdfName)((PdfStream)baseObject.Resolve()).Header[PdfName.Subtype]; if (PdfName.Form.Equals(subtype)) { return(FormXObject.Wrap(baseObject)); } else if (PdfName.Image.Equals(subtype)) { return(ImageXObject.Wrap(baseObject)); } else { return(null); } }
/** * <summary>Wraps the specified base object into a property list object.</summary> * <param name="baseObject">Base object of a property list object.</param> * <returns>Property list object corresponding to the base object.</returns> */ public static PropertyList Wrap( PdfDirectObject baseObject ) { if (baseObject == null) { return(null); } PdfName type = (PdfName)((PdfDictionary)baseObject.Resolve())[PdfName.Type]; if (Layer.TypeName.Equals(type)) { return(Layer.Wrap(baseObject)); } else if (LayerMembership.TypeName.Equals(type)) { return(LayerMembership.Wrap(baseObject)); } else { return(new PropertyList(baseObject)); } }
/** * <summary>Wraps a rendition base object into a rendition object.</summary> * <param name="baseObject">Rendition base object.</param> * <returns>Rendition object associated to the base object.</returns> */ public static Rendition Wrap( PdfDirectObject baseObject ) { if (baseObject == null) { return(null); } PdfName subtype = (PdfName)((PdfDictionary)baseObject.Resolve())[PdfName.S]; if (PdfName.MR.Equals(subtype)) { return(new MediaRendition(baseObject)); } else if (PdfName.SR.Equals(subtype)) { return(new SelectorRendition(baseObject)); } else { throw new ArgumentException("It doesn't represent a valid clip object.", "baseObject"); } }
public static ILayerNode Wrap( PdfDirectObject baseObject ) { if (baseObject == null) { return(null); } PdfDataObject baseDataObject = baseObject.Resolve(); if (baseDataObject is PdfDictionary) { return(Layer.Wrap(baseObject)); } else if (baseDataObject is PdfArray) { return(Layers.Wrap(baseObject)); } else { throw new ArgumentException(baseDataObject.GetType().Name + " is NOT a valid layer node."); } }
/** * <summary>Wraps an annotation base object into an annotation object.</summary> * <param name="baseObject">Annotation base object.</param> * <returns>Annotation object associated to the base object.</returns> */ public static Annotation Wrap(PdfDirectObject baseObject) { if (baseObject == null) { return(null); } if (baseObject.Wrapper is Annotation annotation) { return(annotation); } if (baseObject is PdfReference reference && reference.DataObject?.Wrapper is Annotation referenceAnnotation) { baseObject.Wrapper = referenceAnnotation; return(referenceAnnotation); } var dictionary = baseObject.Resolve() as PdfDictionary; if (dictionary == null) { return(null); } PdfName annotationType = (PdfName)dictionary[PdfName.Subtype]; if (annotationType.Equals(PdfName.Text)) { return(new StickyNote(baseObject)); } else if (annotationType.Equals(PdfName.Link)) { return(new Link(baseObject)); } else if (annotationType.Equals(PdfName.FreeText)) { return(new FreeText(baseObject)); } else if (annotationType.Equals(PdfName.Line)) { return(new Line(baseObject)); } else if (annotationType.Equals(PdfName.Square)) { return(new Rectangle(baseObject)); } else if (annotationType.Equals(PdfName.Circle)) { return(new Ellipse(baseObject)); } else if (annotationType.Equals(PdfName.Polygon)) { return(new Polygon(baseObject)); } else if (annotationType.Equals(PdfName.PolyLine)) { return(new Polyline(baseObject)); } else if (annotationType.Equals(PdfName.Highlight) || annotationType.Equals(PdfName.Underline) || annotationType.Equals(PdfName.Squiggly) || annotationType.Equals(PdfName.StrikeOut)) { return(new TextMarkup(baseObject)); } else if (annotationType.Equals(PdfName.Stamp)) { return(new Stamp(baseObject)); } else if (annotationType.Equals(PdfName.Caret)) { return(new Caret(baseObject)); } else if (annotationType.Equals(PdfName.Ink)) { return(new Scribble(baseObject)); } else if (annotationType.Equals(PdfName.Popup)) { return(new Popup(baseObject)); } else if (annotationType.Equals(PdfName.FileAttachment)) { return(new FileAttachment(baseObject)); } else if (annotationType.Equals(PdfName.Sound)) { return(new Sound(baseObject)); } else if (annotationType.Equals(PdfName.Movie)) { return(new Movie(baseObject)); } else if (annotationType.Equals(PdfName.Widget)) { return(new Widget(baseObject)); } else if (annotationType.Equals(PdfName.Screen)) { return(new Screen(baseObject)); } //TODO // else if(annotationType.Equals(PdfName.PrinterMark)) return new PrinterMark(baseObject); // else if(annotationType.Equals(PdfName.TrapNet)) return new TrapNet(baseObject); // else if(annotationType.Equals(PdfName.Watermark)) return new Watermark(baseObject); // else if(annotationType.Equals(PdfName.3DAnnotation)) return new 3DAnnotation(baseObject); else // Other annotation type. { return(new GenericAnnotation(baseObject)); } }
/** * <summary>Wraps an annotation base object into an annotation object.</summary> * <param name="baseObject">Annotation base object.</param> * <returns>Annotation object associated to the base object.</returns> */ public static Annotation Wrap( PdfDirectObject baseObject ) { if (baseObject == null) { return(null); } PdfName annotationType = (PdfName)((PdfDictionary)baseObject.Resolve())[PdfName.Subtype]; if (annotationType.Equals(PdfName.Text)) { return(new Note(baseObject)); } else if (annotationType.Equals(PdfName.Link)) { return(new Link(baseObject)); } else if (annotationType.Equals(PdfName.FreeText)) { return(new CalloutNote(baseObject)); } else if (annotationType.Equals(PdfName.Line)) { return(new Line(baseObject)); } else if (annotationType.Equals(PdfName.Square)) { return(new Rectangle(baseObject)); } else if (annotationType.Equals(PdfName.Circle)) { return(new Ellipse(baseObject)); } else if (annotationType.Equals(PdfName.Polygon)) { return(new Polygon(baseObject)); } else if (annotationType.Equals(PdfName.PolyLine)) { return(new Polyline(baseObject)); } else if (annotationType.Equals(PdfName.Highlight) || annotationType.Equals(PdfName.Underline) || annotationType.Equals(PdfName.Squiggly) || annotationType.Equals(PdfName.StrikeOut)) { return(new TextMarkup(baseObject)); } else if (annotationType.Equals(PdfName.Stamp)) { return(new RubberStamp(baseObject)); } else if (annotationType.Equals(PdfName.Caret)) { return(new Caret(baseObject)); } else if (annotationType.Equals(PdfName.Ink)) { return(new Scribble(baseObject)); } else if (annotationType.Equals(PdfName.Popup)) { return(new Popup(baseObject)); } else if (annotationType.Equals(PdfName.FileAttachment)) { return(new FileAttachment(baseObject)); } else if (annotationType.Equals(PdfName.Sound)) { return(new Sound(baseObject)); } else if (annotationType.Equals(PdfName.Movie)) { return(new Movie(baseObject)); } else if (annotationType.Equals(PdfName.Widget)) { return(new Widget(baseObject)); } else if (annotationType.Equals(PdfName.Screen)) { return(new Screen(baseObject)); } //TODO // else if(annotationType.Equals(PdfName.PrinterMark)) return new PrinterMark(baseObject); // else if(annotationType.Equals(PdfName.TrapNet)) return new TrapNet(baseObject); // else if(annotationType.Equals(PdfName.Watermark)) return new Watermark(baseObject); // else if(annotationType.Equals(PdfName.3DAnnotation)) return new 3DAnnotation(baseObject); else // Other annotation type. { return(new Annotation(baseObject)); } }
/** <summary>Wraps the specified base object into a pattern object.</summary> <param name="baseObject">Base object of a pattern object.</param> <returns>Pattern object corresponding to the base object.</returns> */ public static Pattern Wrap( PdfDirectObject baseObject ) { if(baseObject == null) return null; PdfDataObject dataObject = baseObject.Resolve(); PdfDictionary dictionary = GetDictionary(dataObject); int patternType = ((PdfInteger)dictionary[PdfName.PatternType]).RawValue; switch(patternType) { case PatternType1: return new TilingPattern(baseObject); case PatternType2: return new ShadingPattern(baseObject); default: throw new NotSupportedException("Pattern type " + patternType + " unknown."); } }
public override void AfterClone( Cloner cloner, PdfArray parent, int index, PdfDirectObject item ) { PdfDictionary annotation = (PdfDictionary)item.Resolve(); if(annotation.ContainsKey(PdfName.FT)) {cloner.context.Document.Form.Fields.Add(Field.Wrap(annotation.Reference));} }
/** * <summary>Wraps an action base object into an action object.</summary> * <param name="baseObject">Action base object.</param> * <returns>Action object associated to the base object.</returns> */ public static Action Wrap(PdfDirectObject baseObject) { if (baseObject == null) { return(null); } if (baseObject.Wrapper is Action action) { return(action); } if (baseObject is PdfReference pdfReference && pdfReference.DataObject?.Wrapper is Action referenceAction) { baseObject.Wrapper = referenceAction; return(referenceAction); } PdfDictionary dataObject = (PdfDictionary)baseObject.Resolve(); PdfName actionType = (PdfName)dataObject[PdfName.S]; if (actionType == null || (dataObject.ContainsKey(PdfName.Type) && !dataObject[PdfName.Type].Equals(PdfName.Action))) { return(null); } if (actionType.Equals(PdfName.GoTo)) { return(new GoToLocal(baseObject)); } else if (actionType.Equals(PdfName.GoToR)) { return(new GoToRemote(baseObject)); } else if (actionType.Equals(PdfName.GoToE)) { return(new GoToEmbedded(baseObject)); } else if (actionType.Equals(PdfName.Launch)) { return(new Launch(baseObject)); } else if (actionType.Equals(PdfName.Thread)) { return(new GoToThread(baseObject)); } else if (actionType.Equals(PdfName.URI)) { return(new GoToURI(baseObject)); } else if (actionType.Equals(PdfName.Sound)) { return(new PlaySound(baseObject)); } else if (actionType.Equals(PdfName.Movie)) { return(new PlayMovie(baseObject)); } else if (actionType.Equals(PdfName.Hide)) { return(new ToggleVisibility(baseObject)); } else if (actionType.Equals(PdfName.Named)) { PdfName actionName = (PdfName)dataObject[PdfName.N]; if (actionName.Equals(PdfName.NextPage)) { return(new GoToNextPage(baseObject)); } else if (actionName.Equals(PdfName.PrevPage)) { return(new GoToPreviousPage(baseObject)); } else if (actionName.Equals(PdfName.FirstPage)) { return(new GoToFirstPage(baseObject)); } else if (actionName.Equals(PdfName.LastPage)) { return(new GoToLastPage(baseObject)); } else // Custom named action. { return(new NamedAction(baseObject)); } } else if (actionType.Equals(PdfName.SubmitForm)) { return(new SubmitForm(baseObject)); } else if (actionType.Equals(PdfName.ResetForm)) { return(new ResetForm(baseObject)); } else if (actionType.Equals(PdfName.ImportData)) { return(new ImportData(baseObject)); } else if (actionType.Equals(PdfName.JavaScript)) { return(new JavaScript(baseObject)); } else if (actionType.Equals(PdfName.SetOCGState)) { return(new SetLayerState(baseObject)); } else if (actionType.Equals(PdfName.Rendition)) { return(new Render(baseObject)); } else if (actionType.Equals(PdfName.Trans)) { return(new DoTransition(baseObject)); } else if (actionType.Equals(PdfName.GoTo3DView)) { return(new GoTo3dView(baseObject)); } else // Custom action. { return(new Action(baseObject)); } }