protected override void DoSetNativeValue(object value, IPDFComponent owner) { if (!string.IsNullOrEmpty(this.ObjectType)) { var t = Type.GetType(this.ObjectType); if (null == t) { throw new NullReferenceException("The object type '" + this.ObjectType + "' could not be found"); } if (null == value) { this.Value = null; } else if (t.IsAssignableFrom(value.GetType())) { this.Value = value; } else { throw new InvalidCastException("The value cannot be assigned to the parameter as the types are not compatible"); } } else { this.Value = value; } }
public PDFImageData LoadImageData(IPDFDocument document, IPDFComponent owner, string path) { try { var uri = new Uri(path); var param = uri.GetComponents(UriComponents.Path, UriFormat.Unescaped); var name = System.IO.Path.GetFileNameWithoutExtension(param); // Standard System.Drawing routines to draw a bitmap // could load an image from SQL, use parameters, whatever is needed Bitmap bmp = new Bitmap(300, 100); using (Graphics graphics = Graphics.FromImage(bmp)) { graphics.FillRectangle(new SolidBrush(Color.LightBlue), new Rectangle(0, 0, 300, 100)); graphics.DrawString(name, new Font("Times", 12), new SolidBrush(Color.Blue), PointF.Empty); graphics.Flush(); } var dir = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal); var png = System.IO.Path.Combine(dir, "Temp.png"); bmp.Save(png); PDFImageData data = PDFImageData.LoadImageFromBitmap(path, bmp, false); return(data); } catch (Exception ex) { throw new ArgumentException("The image creation failed", ex); } }
protected override void DoSetNativeValue(object value, IPDFComponent owner) { if (null == value) { this.XmlData = null; } else if (value is System.Xml.Linq.XNode) { using (var reader = ((System.Xml.Linq.XNode)value).CreateReader()) { var doc = new System.Xml.XmlDocument(); doc.Load(reader); this.XmlData = doc.DocumentElement; } } else if (value is System.Xml.XPath.XPathNavigator) { using (var reader = ((System.Xml.XPath.XPathNavigator)value).ReadSubtree()) { var doc = new System.Xml.XmlDocument(); doc.Load(reader); this.XmlData = doc.DocumentElement; } } else if (value is XmlNode) { this.XmlData = (XmlNode)value; } else { throw new InvalidCastException("Could not convert the value to an XmlNode, value should be provided as an XmlNode, XPathNavigator or a Linq XNode"); } }
// // style base overrides // #region public override void MergeInto(PDFStyle style, IPDFComponent Component, ComponentState state) /// <summary> /// Overrides the base implementation to call MergeInto on all the inner styles in this group /// </summary> /// <param name="style"></param> /// <param name="Component"></param> /// <param name="state"></param> public override void MergeInto(Style style, IPDFComponent Component, ComponentState state) { foreach (StyleBase def in this.InnerItems) { def.MergeInto(style, Component, state); } }
public bool IsMatchedTo(IPDFComponent component) { if (null == this.Selectors) { return(true); } else if (component is IPDFStyledComponent) { var styled = component as IPDFStyledComponent; var val = styled.StyleClass; if (string.IsNullOrEmpty(val)) { return(false); } else { foreach (var sel in Selectors) { if (sel == val) { return(true); } } } } return(false); }
/// <summary> /// <inheritdoc/> /// </summary> public void AttachedTo(IPDFComponent mainComponent) { var mc = mainComponent as PDFComponent; _mainComponent = mc ?? throw new ArgumentException( string.Format(CultureInfo.InvariantCulture, "The parameter {0} is not of expected type.", nameof(mainComponent))); }
public override void MergeInto(Style style, IPDFComponent Component, ComponentState state) { if (null == this.Media || this.Media.IsMatchedTo(this._format)) { base.MergeInto(style, Component, state); } }
// // methods // #region public IPDFComponent GetComponent(IContentParser parser, string name) /// <summary> /// Returns a new component for the parser based on the specified tag name. /// </summary> /// <param name="parser"></param> /// <param name="name"></param> /// <returns>The instaniated component or null if the name is not recognised</returns> public IPDFComponent GetComponent(IHtmlContentParser parser, string name, out HtmlComponentType type) { IPDFComponent proxy = null; IParserComponentFactory innerfact; if (null != _last && _lastName == name) { proxy = _last.GetComponent(parser, name, out type); } else if (_knowntags.TryGetValue(name, out innerfact)) { _last = innerfact; _lastName = name; proxy = innerfact.GetComponent(parser, name, out type); } else { _last = null; _lastName = null; type = HtmlComponentType.Unknown; proxy = GetUnknownComponent(parser, name); } if (proxy is Component) { ((Component)proxy).Tag = name; } return(proxy); }
protected IPDFRemoteComponent GetRemoteComponent(IPDFComponent owner) { IPDFComponent comp = owner; while (null != comp) { if (comp is IPDFRemoteComponent && !String.IsNullOrEmpty(((IPDFRemoteComponent)comp).LoadedSource)) { return((IPDFRemoteComponent)comp); } else { comp = comp.Parent; } } IPDFDocument doc = owner.Document; if (doc is IPDFRemoteComponent) { return((IPDFRemoteComponent)doc); } else { return(null); } }
/// <summary> /// Creates a new PDFTextReplacementOp /// </summary> /// <param name="owner"></param> /// <param name="key"></param> /// <param name="text"></param> public PDFTextProxyOp(IPDFComponent owner, string key, string text) : base() { this.Owner = owner; this.Key = key; this.Text = text; }
public PDFLayoutInlineBegin AddInlineRunStart(IPDFLayoutEngine engine, IPDFComponent component, PDFPositionOptions options, Style full) { PDFLayoutInlineBegin begin = new PDFLayoutInlineBegin(this, component, options, full); this.Runs.Add(begin); return(begin); }
protected virtual bool ExtractRawContent() { var end = "</" + this.ParsedPath.Peek().Value + ">"; this.Buffer.Clear(); var start = this.Source.Offset; while (this.Source.EOS == false && !this.Source.Matches(end)) { this.Source.MoveNext(); } var len = this.Source.Offset - start; var content = this.Source.Substring(start, len); IPDFComponent text = _owner.ComponentFactory.GetTextComponent(this.Parser, content); ((IPDFTextLiteral)text).ReaderFormat = TextFormat.XML; HTMLParserResult result = new HTMLParserResult(text, HtmlComponentType.Text, null, start, this.Source.Offset - 1, true); this.TagsToClose.Push(result); this.Current = result; //Set the start back to the </code> or </pre> this.Source.Offset -= 1; return(true); }
public PDFLayoutInlineEnd AddInlineRunEnd(IPDFLayoutEngine engine, IPDFComponent component, PDFLayoutInlineBegin start, PDFPositionOptions options) { PDFLayoutInlineEnd end = new PDFLayoutInlineEnd(this, start, component, options); this.Runs.Add(end); return(end); }
// // .ctor(s) // #region public PDFLayoutComponentRun(PDFLayoutLine line, IPDFComponent component, PDFStyle style) /// <summary> /// Creates a new Component Run /// </summary> /// <param name="line"></param> /// <param name="component"></param> /// <param name="style"></param> public PDFLayoutComponentRun(PDFLayoutLine line, IPDFComponent component, Style style) : base(line, component) { System.Diagnostics.Debug.Assert(null != component); System.Diagnostics.Debug.Assert(null != style); this.FullStyle = style; }
public PDFLayoutXObject AddXObjectRun(IPDFLayoutEngine engine, IPDFComponent component, PDFLayoutRegion container, PDFPositionOptions options, Style full) { PDFLayoutXObject xobject = new PDFLayoutXObject(this, container, options, component); this.Runs.Add(xobject); return(xobject); }
public void MergeInto(Style style, IPDFComponent forComponent, ComponentState state) { for (int i = 0; i < this.Count; i++) { StyleBase inner = this[i]; inner.MergeInto(style, forComponent, state); } }
public PDFRemoteFileRequest(string path, RemoteRequestCallback callback, IPDFComponent owner = null, object args = null) { this.FilePath = path ?? throw new ArgumentNullException(nameof(path)); this.Callback = callback ?? throw new ArgumentNullException(nameof(callback)); this.Owner = owner; this.Arguments = args; this.IsCompleted = false; }
internal void Pop(IPDFComponent comp) { PDFOutlineRef last = _stack.Pop(); if (last.Outline.BelongsTo != comp) { throw RecordAndRaise.Operation(Errors.UnbalancedOutlineStack); } }
/// <summary> /// Ensures that this resource is registered in the resource list. /// </summary> /// <param name="resourcelist"></param> /// <param name="Component"></param> public virtual void RegisterUse(PDFResourceList resourcelist, IPDFComponent Component) { if (resourcelist != null) { resourcelist.EnsureInList(this); this.Container = resourcelist.Container; this._registered = true; } }
/// <summary> /// If this style definition should be applied to the specified component (in the state) then /// merges all the assigned properties into the provided style /// </summary> /// <param name="style"></param> /// <param name="forComponent"></param> /// <param name="state"></param> public override void MergeInto(Style style, IPDFComponent forComponent, ComponentState state) { int priority; if (this.IsMatchedTo(forComponent, out priority)) { this.MergeInto(style, priority); } }
public void SetValue(string key, string value, IPDFComponent owner) { if (key != this.ID) { throw new InvalidOperationException("The keys do not match"); } this.DoSetNativeValueFromString(value, owner); }
//public PDFStyle MatchClass(string classname) //{ // PDFStyle style = new PDFStyle(); // foreach (PDFStyleBase stylebase in this) // { // PDFStyle matched = stylebase.MatchClass(classname); // if (matched != null) // matched.MergeInto(style); // } // return style; //} private void UpdateAllParents(IPDFComponent parent) { foreach (StyleBase item in this) { if (item is IPDFComponent) { ((IPDFComponent)item).Parent = parent; } } }
protected override object DoGetNativeValue(string key, string qsValue, IPDFComponent comp) { PDFThickness val; if (string.IsNullOrEmpty(qsValue) || !PDFThickness.TryParse(qsValue, out val)) { val = this.Value; } return(val); }
/// <summary> /// Creates a new PDFLayoutRegion. /// </summary> /// <param name="block"></param> /// <param name="columnindex"></param> /// <param name="contentbounds"></param> public PDFLayoutRegion(PDFLayoutBlock block, IPDFComponent owner, PDFRect contentbounds, int columnindex, HorizontalAlignment halign, VerticalAlignment valign, PositionMode mode) : base(block, owner) { this.UsedSize = PDFSize.Empty; this.ColumnIndex = columnindex; this.TotalBounds = contentbounds; this.HAlignment = halign; this.VAlignment = valign; this.PositionMode = mode; }
/// <summary> /// Creates a new instance of of the ParserResult struct /// </summary> /// <param name="parsed"></param> /// <param name="offsetStart"></param> /// <param name="offsetEnd"></param> /// <param name="start"></param> public HTMLParserResult(IPDFComponent parsed, HtmlComponentType type, string value, int offsetStart, int offsetEnd, bool start) { _value = value; _parsed = parsed; _type = type; _start = offsetStart; _end = offsetEnd; _isStart = start; _valid = true; }
public override void MergeInto(Style style, IPDFComponent Component, ComponentState state) { if (null == this.Matcher) { base.MergeInto(style, Component, state); } else if (this.Matcher.IsMatchedTo(Component)) { base.MergeInto(style, Component, state); } }
public override void SetAttribute(IHtmlContentParser parser, IPDFComponent parsed, string componentName, string attrName, string attrValue) { if (attrName == "src") { ((Image)parsed).Source = attrValue; } else { base.SetAttribute(parser, parsed, componentName, attrName, attrValue); } }
/// <summary> /// Raises the ItemDataBound event /// </summary> /// <param name="context"></param> /// <param name="item"></param> protected virtual void OnItemDataBound(PDFDataContext context, IPDFComponent item) { if (this.HasRegisteredEvents) { PDFTemplateItemDataBoundHandler handler = this.Events[ItemBoundEventKey] as PDFTemplateItemDataBoundHandler; if (null != handler) { handler(this, new PDFTemplateItemDataBoundArgs(item, context)); } } }
// // ctor(s) // #region public PDFImageTilingPattern(IPDFComponent container, string key, PDFImageXObject image) /// <summary> /// Creates a new PDFImageTilingPattern that will render an image as a tile pattern /// </summary> /// <param name="container"></param> /// <param name="key"></param> public PDFImageTilingPattern(IPDFComponent container, string key, PDFImageXObject image) : base(container, key) { if (null == image) { throw new ArgumentNullException("image"); } this.Resources = new PDFResourceList(this); this.Image = image; }
/// <summary> /// Returns true if the specified component is a match (should have applied) this style defintions styles /// </summary> /// <param name="component"></param> /// <returns></returns> /// <remarks>There is one exception to the rule. If this is a catch all style (no applied-xxx) then /// it is applied to the top level document only</remarks> public virtual bool IsMatchedTo(IPDFComponent component, out int priority) { if (null == component) { priority = 0; return(false); } var match = this.AssertMatcher(); return(match.IsMatchedTo(component, ComponentState.Normal, out priority)); }