protected virtual void CreateBlockRegions(PDFLayoutBlock containerBlock, PDFPositionOptions position, PDFColumnOptions columnOptions) { PDFRect unused = containerBlock.CurrentRegion.UnusedBounds; PDFUnit yoffset = containerBlock.CurrentRegion.Height; PDFRect total = new PDFRect(PDFUnit.Zero, yoffset, unused.Width, unused.Height); if (position.Width.HasValue) { total.Width = position.Width.Value; } //ADDED for min/max sizes. Include the margins as we are making this the available width. else if (position.MaximumWidth.HasValue) { total.Width = position.MaximumWidth.Value + position.Margins.Left + position.Margins.Right; } if (position.Height.HasValue) { total.Height = position.Height.Value; } //ADDED for min/max sizes. Include the margins as we are making this the available height. else if (position.MaximumHeight.HasValue) { total.Height = position.MaximumHeight.Value + position.Margins.Top + position.Margins.Bottom; } CurrentBlock.InitRegions(total, position, columnOptions, this.Context); }
protected override void DoLayoutComponent() { if (this.Context.ShouldLogVerbose) { this.Context.TraceLog.Begin(TraceLevel.Verbose, "Panel Layout Engine", "Beginning layout of component '" + this.Component + "' as a viewport component"); } PDFPositionOptions pos = this.FullStyle.CreatePostionOptions(); PDFColumnOptions columns = this.FullStyle.CreateColumnOptions(); if (pos.PositionMode != Drawing.PositionMode.Inline) { this.DoLayoutBlockComponent(pos, columns); } else { PDFLayoutInlineBegin begin = CreateAndAddInlineBegin(pos); this.DoLayoutChildren(); this.CreateAndAddInlineEnd(pos, begin); } if (this.Context.ShouldLogVerbose) { this.Context.TraceLog.End(TraceLevel.Verbose, "Panel Layout Engine", "Completed layout of component '" + this.Component + "' as a viewport component"); } }
// // methods // #region public void InitSize(PDFRect total ...) /// <summary> /// Initializes all the sizes in a PDFLayoutComponentRun. /// It is not nescessary, as each property can be set individually, /// but this makes sure everything has been provided /// </summary> /// <param name="total"></param> /// <param name="border"></param> /// <param name="content"></param> /// <param name="margins"></param> /// <param name="padding"></param> /// <param name="options"></param> public void InitSize(PDFRect total, PDFRect border, PDFRect content, PDFPositionOptions options) { this.TotalBounds = total; this.BorderRect = border; this.ContentRect = content; this.PositionOptions = options; }
protected override void DoLayoutChildren() { PDFPositionOptions position = this.FullStyle.CreatePostionOptions(); PDFLayoutXObject canvas = null; if (position.ViewPort.HasValue) { canvas = this.ApplyViewPort(position, position.ViewPort.Value); } base.DoLayoutChildren(); if (null != canvas) { canvas.Close(); this.CloseCurrentLine(); canvas.OutPutName = (PDFName)this.Context.Document.GetIncrementID(PDFObjectTypes.CanvasXObject); var rsrc = new PDFCanvasResource(this.Component as Canvas, canvas, position.ViewPort.Value); var ratio = this.FullStyle.GetValue(SVGAspectRatio.AspectRatioStyleKey, SVGAspectRatio.Default); var size = new PDFSize(canvas.Width, canvas.Height); canvas.Matrix = CalculateMatrix(size, position.ViewPort.Value, ratio); canvas.ClipRect = new PDFRect(position.X.HasValue ? position.X.Value : PDFUnit.Zero, position.Y.HasValue ? position.Y.Value : PDFUnit.Zero, canvas.Width, canvas.Height); this.Context.DocumentLayout.CurrentPage.PageOwner.Register(rsrc); this.Context.Document.EnsureResource(rsrc.ResourceType, rsrc.ResourceKey, rsrc); } }
public PDFLayoutXObject(PDFLayoutLine parent, PDFLayoutRegion childContainer, PDFPositionOptions position, IPDFComponent owner) : base(parent, owner as IPDFComponent) { this._childContainer = childContainer; this._resources = new PDFResourceList(this, false); this.SubType = "Form"; this.Matrix = PDFTransformationMatrix.Identity(); this._position = position; }
// // support methods // #region protected virtual void BuildNewPage(PDFPageSize pgsize, PDFPositionOptions options ...) /// <summary> /// Creates a new page with the specified options and adds it to the current layout /// </summary> /// <param name="pgsize"></param> /// <param name="options"></param> /// <param name="alley"></param> /// <param name="colcount"></param> /// <param name="action"></param> protected virtual PDFLayoutPage BuildNewPage(PDFSize pgsize, PDFPositionOptions options, PDFColumnOptions colOpts, OverflowAction action) { PDFLayoutDocument doclayout = this.DocumentLayout; PDFLayoutPage pg = doclayout.BeginNewPage(this.Page, this, this.FullStyle, action); pg.InitPage(pgsize, options, colOpts, this.Context); return(pg); }
private PDFLayoutInlineEnd CreateAndAddInlineEnd(PDFPositionOptions pos, PDFLayoutInlineBegin begin) { PDFLayoutBlock containerBlock = this.DocumentLayout.CurrentPage.LastOpenBlock(); PDFLayoutRegion containerRegion = containerBlock.CurrentRegion; if (containerRegion.HasOpenItem == false) { containerRegion.BeginNewLine(); } PDFLayoutLine currline = containerRegion.CurrentItem as PDFLayoutLine; PDFLayoutInlineEnd end = currline.AddInlineRunEnd(this, this.Component, begin, pos); return(end); }
private PDFLayoutInlineBegin CreateAndAddInlineBegin(PDFPositionOptions pos) { PDFLayoutBlock containerBlock = this.DocumentLayout.CurrentPage.LastOpenBlock(); PDFLayoutRegion containerRegion = containerBlock.CurrentRegion; if (containerRegion.HasOpenItem == false) { containerRegion.BeginNewLine(); } PDFLayoutLine currline = containerRegion.CurrentItem as PDFLayoutLine; PDFLayoutInlineBegin begin = currline.AddInlineRunStart(this, this.Component, pos, this.FullStyle); return(begin); }
/// <summary> /// Lays out all the content of this panel /// </summary> /// <param name="position"></param> protected virtual void DoLayoutBlockComponent(PDFPositionOptions position, PDFColumnOptions columnOptions) { PDFLayoutBlock containerBlock = CreateContinerBlock(position); if (null == containerBlock) { return; } CreateBlockRegions(containerBlock, position, columnOptions); this.DoLayoutChildren(); EnsureContentsFit(); }
protected virtual PDFLayoutXObject ApplyViewPort(PDFPositionOptions oldpos, PDFRect viewPort) { //Set the size to the viewport size var newpos = oldpos.Clone(); newpos.X = viewPort.X; newpos.Y = viewPort.Y; //update to new widths newpos.Width = viewPort.Width; newpos.Height = viewPort.Height; //Set the style values to the viewport too. (and reset the cache) this.FullStyle.Size.Width = newpos.Width.Value; this.FullStyle.Size.Height = newpos.Height.Value; if (this.FullStyle is Scryber.Styles.StyleFull) { (this.FullStyle as StyleFull).ClearFullRefs(); } PDFLayoutBlock containerBlock = this.DocumentLayout.CurrentPage.LastOpenBlock(); PDFLayoutRegion containerRegion = containerBlock.CurrentRegion; if (containerRegion.HasOpenItem == false) { containerRegion.BeginNewLine(); } //pos.Y = 200; PDFLayoutRegion container = containerBlock.BeginNewPositionedRegion(newpos, this.DocumentLayout.CurrentPage, this.Component, this.FullStyle, false); this.Line = containerRegion.CurrentItem as PDFLayoutLine; PDFLayoutXObject begin = this.Line.AddXObjectRun(this, this.Component, container, newpos, this.FullStyle); begin.SetOutputSize(oldpos.Width, oldpos.Height); //this.CurrentBlock.IsFormXObject = true; //this.CurrentBlock.XObjectViewPort = pos.ViewPort.Value; return(begin); }
private PDFLayoutXObject CreateAndAddInput(PDFPositionOptions pos) { PDFLayoutBlock containerBlock = this.DocumentLayout.CurrentPage.LastOpenBlock(); PDFLayoutRegion containerRegion = containerBlock.CurrentRegion; if (containerRegion.HasOpenItem == false) { containerRegion.BeginNewLine(); } //pos.Y = 200; PDFLayoutRegion container = containerBlock.BeginNewPositionedRegion(pos, this.DocumentLayout.CurrentPage, this.Component, this.FullStyle, false); this.Line = containerRegion.CurrentItem as PDFLayoutLine; PDFLayoutXObject begin = this.Line.AddXObjectRun(this, this.Field, container, pos, this.FullStyle); return(begin); }
/// <summary> /// Adds the component to the line using <i>all</i> the provided options /// </summary> /// <param name="comp">the component to add to the line</param> /// <param name="total">the total bounds of the component</param> /// <param name="border">the border rectangle wrt the total bounds</param> /// <param name="content">the content rectangle wrt the total bounds</param> /// <param name="baselineOffset">The required offset of the baseline of this line from it's top</param> /// <param name="options">the positioning options</param> /// <param name="style">the full style of the component</param> /// <returns>The created run</returns> public virtual PDFLayoutRun AddComponentRun(IPDFComponent comp, PDFRect total, PDFRect border, PDFRect content, PDFUnit baselineOffset, PDFPositionOptions options, Style style) { PDFLayoutComponentRun comprun = new PDFLayoutComponentRun(this, comp, style); this.Runs.Add(comprun); total = total.Offset(this.Width, this.OffsetY); comprun.InitSize(total, border, content, options); comprun.Close(); //Added 13th June 2016 this.BaseLineOffset = PDFUnit.Max(this.BaseLineOffset, baselineOffset); return(comprun); }
protected virtual void AdjustContainerForTextBaseline(PDFPositionOptions pos, IPDFComponent comp, Style full) { var text = full.CreateTextOptions(); if (text.DrawTextFromTop == false) { PDFUnit y; var font = full.CreateFont(); if (pos.Y.HasValue) { y = pos.Y.Value; } else { y = 0; } var doc = this.Component.Document; var frsrc = doc.GetFontResource(font, true); var metrics = frsrc.Definition.GetFontMetrics(font.Size); //TODO: Register the font so that we can get the metrics. Or call later on and move // But for now it works (sort of). if (null != metrics) { y -= metrics.Ascent; } else { y -= font.Size * 0.8; } pos.Y = y; full.Position.Y = y; if (full is StyleFull) { (full as StyleFull).ClearFullRefs(); } } }
// // item layout // #region private void LayoutListItems(PDFPositionOptions listPosOpts) /// <summary> /// Lays out all the list item entries in sequence /// </summary> /// <param name="listPosOpts"></param> private void LayoutListItems(PDFPositionOptions listPosOpts) { int index = 1; _itemoffset = 0; foreach (ListNumberEntry entry in this._entries) { PDFUnit h = this.LayoutAnItem(index, entry, listPosOpts); _itemoffset += h; index++; if (this.ContinueLayout == false || this.DocumentLayout.CurrentPage.IsClosed || this.DocumentLayout.CurrentPage.CurrentBlock == null) { break; } } }
protected override void DoLayoutComponent() { PDFPositionOptions pos = this.FullStyle.CreatePostionOptions(); PDFLayoutXObject xObject = this.CreateAndAddInput(pos); _addedProxyText = false; if (string.IsNullOrEmpty(this.Field.Value)) { this.Field.Value = "Proxy Text"; _addedProxyText = true; } base.DoLayoutComponent(); xObject.Close(); if (pos.PositionMode == Drawing.PositionMode.Block) { this.CloseCurrentLine(); } this.LayoutPage = this.Context.DocumentLayout.CurrentPage; IArtefactCollection annots; if (!this.LayoutPage.Artefacts.TryGetCollection(PDFArtefactTypes.Annotations, out annots)) { annots = new PDFAnnotationCollection(PDFArtefactTypes.Annotations); this.LayoutPage.Artefacts.Add(annots); } this.LayoutPage = this.Context.DocumentLayout.CurrentPage; annots.Register(this.Field.Widget); this.Field.Widget.SetAppearance(FormFieldAppearanceState.Normal, xObject, this.LayoutPage, this.FullStyle); this.Field.Widget.SetAppearance(FormFieldAppearanceState.Down, xObject, this.LayoutPage, this.FullStyle); this.Field.Widget.SetAppearance(FormFieldAppearanceState.Over, xObject, this.LayoutPage, this.FullStyle); }
// // layout methods // #region public void Layout(PDFLayoutContext context, Styles.PDFStyle fullstyle) /// <summary> /// Measures and lay's out the TextComponent that this engine references. /// </summary> /// <param name="context"></param> /// <param name="fullstyle"></param> public void Layout(PDFLayoutContext context, Styles.Style fullstyle) { if (null == context) { throw new ArgumentNullException("context"); } if (null == fullstyle) { throw new ArgumentNullException("fullstyle"); } this._ctx = context; this._fullstyle = fullstyle; this._posopts = fullstyle.CreatePostionOptions(); this._textopts = fullstyle.CreateTextOptions(); if (this._posopts.PositionMode == PositionMode.Invisible) { if (context.ShouldLogDebug) { context.TraceLog.Add(TraceLevel.Debug, "Layout", "Skipping the layout of the text component " + this.TextComponent.ID + " as it is invisible"); } return; } this._frsrc = ((Document)this.TextComponent.Document).GetFontResource(this.TextRenderOptions.Font, true); this.Context.PerformanceMonitor.Begin(PerformanceMonitorType.Text_Layout); this._reader = this.TextComponent.CreateReader(context, fullstyle); if (null != this._reader) { this.ContinueLayout = true; this.DoLayoutText(); } this.Context.PerformanceMonitor.End(PerformanceMonitorType.Text_Layout); }
// // methods // #region public void InitPage(int index, PDFSize size, PDFThickness margthick ...) /// <summary> /// Initializes this page with the required top block size and other measurements /// </summary> /// <param name="size"></param> /// <param name="margthick"></param> /// <param name="padthick"></param> /// <param name="available"></param> /// <param name="mode"></param> /// <param name="cansplit"></param> /// <param name="colcount"></param> /// <param name="alley"></param> public virtual void InitPage(PDFSize size, PDFPositionOptions options, PDFColumnOptions columns, PDFLayoutContext context) { this.Size = size; this.PositionOptions = options; OverflowSplit split = options.OverflowSplit; PDFLayoutBlock block = new PDFLayoutBlock(this, this.Owner, this.Engine, this.FullStyle, split); PDFRect totalbounds = new PDFRect(PDFPoint.Empty, this.Size); block.InitRegions(totalbounds, options, columns, context); //We need to set the bounds of the page block to the total for a page //(as margins are taken off from the size of the page // - this is different to a block where margins increase any explicit sizes). block.TotalBounds = totalbounds; this.ContentBlock = block; this.CurrentBlock = block; }
protected virtual PDFLayoutBlock CreateContinerBlock(PDFPositionOptions position) { bool newPage = false; PDFLayoutBlock containerBlock = this.DocumentLayout.CurrentPage.LastOpenBlock(); PDFLayoutRegion containerRegion = containerBlock.CurrentRegion; if (containerRegion.HasOpenItem) { containerRegion.CloseCurrentItem(); } PDFUnit required = PDFUnit.Zero; if (position.Height.HasValue) { required = position.Height.Value; } //ADDED for min/max sizes. else if (position.MinimumHeight.HasValue) { required = position.MinimumHeight.Value; } //Do we have space if (containerRegion.AvailableHeight <= 0 || (containerRegion.AvailableHeight < required)) { if (this.MoveToNextRegion(required, ref containerRegion, ref containerBlock, out newPage) == false) { this.Context.TraceLog.Add(TraceLevel.Warning, LOG_CATEGORY, "Cannot fit the block for component " + this.Component.UniqueID + " in the avilable height (required = '" + position.Height + "', available = '" + containerRegion.AvailableHeight + "'), and we cannot overflow to a new region. Layout of component stopped and returning."); this.ContinueLayout = false; return(null); } } CurrentBlock = containerBlock.BeginNewContainerBlock(this.Component, this, this.FullStyle, position.PositionMode); CurrentBlock.BlockRepeatIndex = 0; return(containerBlock); }
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 PDFLayoutInlineEnd AddInlineRunEnd(IPDFLayoutEngine engine, IPDFComponent component, PDFLayoutInlineBegin start, PDFPositionOptions options) { PDFLayoutInlineEnd end = new PDFLayoutInlineEnd(this, start, component, options); this.Runs.Add(end); return(end); }
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); }
public void CreatePostionOptionsTest() { Style target = new Style(); //Default (empty) position options PDFPositionOptions actual = target.CreatePostionOptions(); Assert.AreEqual(false, actual.FillWidth); Assert.AreEqual(HorizontalAlignment.Left, actual.HAlign); Assert.AreEqual(false, actual.Height.HasValue); Assert.AreEqual(false, actual.Width.HasValue); Assert.AreEqual(false, actual.X.HasValue); Assert.AreEqual(false, actual.Y.HasValue); Assert.AreEqual(PDFThickness.Empty(), actual.Margins); Assert.AreEqual(OverflowAction.NewPage, actual.OverflowAction); Assert.AreEqual(OverflowSplit.Any, actual.OverflowSplit); Assert.AreEqual(PDFThickness.Empty(), actual.Padding); Assert.AreEqual(PositionMode.Block, actual.PositionMode); Assert.AreEqual(VerticalAlignment.Top, actual.VAlign); Assert.AreEqual(Visibility.Visible, actual.Visibility); Assert.AreEqual(null, actual.Height); Assert.AreEqual(null, actual.Width); Assert.AreEqual(null, actual.X); Assert.AreEqual(null, actual.Y); Assert.AreEqual(false, actual.MinimumHeight.HasValue); Assert.AreEqual(false, actual.MinimumWidth.HasValue); Assert.AreEqual(false, actual.MaximumHeight.HasValue); Assert.AreEqual(false, actual.MaximumWidth.HasValue); Assert.AreEqual(null, actual.MinimumHeight); Assert.AreEqual(null, actual.MinimumWidth); Assert.AreEqual(null, actual.MaximumHeight); Assert.AreEqual(null, actual.MaximumWidth); target = new Style(); target.Position.PositionMode = PositionMode.Inline; target.Size.FullWidth = true; target.Position.HAlign = HorizontalAlignment.Center; target.Position.VAlign = VerticalAlignment.Middle; target.Position.X = 20; target.Position.Y = 50; target.Size.Width = 100; //Don't define height target.Size.MaximumHeight = 90; target.Size.MinimumHeight = 50; target.Size.MaximumWidth = 200; target.Size.MinimumWidth = 150; target.Overflow.Action = OverflowAction.Truncate; target.Overflow.Split = OverflowSplit.Never; target.Margins.All = 10; target.Margins.Bottom = 20; target.Padding.All = 20; target.Padding.Right = 40; actual = target.CreatePostionOptions(); Assert.AreEqual(false, actual.FillWidth); //false because a width has been set Assert.AreEqual(HorizontalAlignment.Center, actual.HAlign); Assert.AreEqual(VerticalAlignment.Middle, actual.VAlign); Assert.AreEqual(false, actual.Height.HasValue); Assert.AreEqual(true, actual.Width.HasValue); Assert.AreEqual(true, actual.X.HasValue); Assert.AreEqual(true, actual.Y.HasValue); Assert.AreEqual((PDFUnit)100, actual.Width); Assert.AreEqual((PDFUnit)20, actual.X); Assert.AreEqual((PDFUnit)50, actual.Y); Assert.AreEqual(null, actual.Height); Assert.AreEqual((PDFUnit)200, actual.MaximumWidth); Assert.AreEqual((PDFUnit)150, actual.MinimumWidth); Assert.AreEqual((PDFUnit)90, actual.MaximumHeight); Assert.AreEqual((PDFUnit)50, actual.MinimumHeight); Assert.AreEqual(OverflowAction.Truncate, actual.OverflowAction); Assert.AreEqual(OverflowSplit.Never, actual.OverflowSplit); Assert.AreEqual((PDFUnit)10, actual.Margins.Left); Assert.AreEqual((PDFUnit)20, actual.Margins.Bottom); Assert.AreEqual((PDFUnit)20, actual.Padding.Left); Assert.AreEqual((PDFUnit)40, actual.Padding.Right); Assert.AreEqual(PositionMode.Relative, actual.PositionMode); //mode is relative (because we have an xand a y) Assert.AreEqual(VerticalAlignment.Middle, actual.VAlign); Assert.AreEqual(Visibility.Visible, actual.Visibility); }
protected override PDFGraphicsPath CreatePath(PDFSize available, Style fullstyle) { PDFPositionOptions pos = fullstyle.CreatePostionOptions(); PDFPoint start = PDFPoint.Empty; PDFPoint end = new PDFPoint(available.Width, start.Y); if (pos.X.HasValue) { start.X = pos.X.Value; } if (pos.Y.HasValue) { start.Y = pos.Y.Value; end.Y = pos.Y.Value; } if (pos.Width.HasValue) { end.X = pos.Width.Value + start.X; if (pos.Height.HasValue) { end.Y = pos.Height.Value - start.Y; } else // no hight so this is a horizontal line { end.Y = start.Y; } } else if (pos.FillWidth) { end.X = available.Width - start.X; if (pos.Height.HasValue) { end.Y = pos.Height.Value - start.Y; } else // no hight so this is a horizontal line { end.Y = start.Y; } } //no width so if we have a height this is a vertical line else if (pos.Height.HasValue) { end.Y = pos.Height.Value + start.Y; end.X = start.X; } else //default is a horizontal line { end.X = available.Width - start.X; end.Y = start.Y; } PDFGraphicsPath path = new PDFGraphicsPath(); path.MoveTo(start); path.LineTo(end); return(path); }
// // overrides // /// <summary> /// Main overridden method /// </summary> protected override void DoLayoutComponent() { IDisposable record = this.Context.PerformanceMonitor.Record(PerformanceMonitorType.Layout_Pages, "Page " + this.Component.ID); //Take a copy of the style stack for the header and footer this.PageStyleStack = this.Context.StyleStack.Clone(); //Get the page size and position options PageSize pgsize = this.FullStyle.CreatePageSize(); pgsize.Size = this.GetNextPageSize(this.Component, this.FullStyle, pgsize.Size); PDFPositionOptions options = this.FullStyle.CreatePostionOptions(); //Graphics PDFGraphics g = this.Page.CreateGraphics(this.StyleStack, this.Context); this.Context.Graphics = g; //Size, border, margins PDFRect bounds = new PDFRect(PDFPoint.Empty, pgsize.Size); PDFRect contentrect = GetContentRectFromBounds(bounds, options.Margins, options.Padding); //Columns PDFColumnOptions colOpts = this.FullStyle.CreateColumnOptions(); //Overflow OverflowAction action = options.OverflowAction; PDFLayoutPage pg = BuildNewPage(pgsize.Size, options, colOpts, action); //Register page numbering PDFPageNumberOptions numbers = this.GetPageNumbering(this.FullStyle); this.RegisterPageNumbering(pg, numbers); this.LayoutPageContent(); //close the last page PDFLayoutPage last = this.DocumentLayout.CurrentPage; if (last.IsClosed == false) { last.Close(); } //Unregister the page numbers. this.UnRegisterPageNumbering(last, numbers); //release graphics this.Context.Graphics = null; g.Dispose(); record.Dispose(); }
/// <summary> /// Lays out a single list item based on the entry, and the list position options /// </summary> /// <param name="index"></param> /// <param name="entry"></param> /// <param name="listPosOpts"></param> /// <returns></returns> private PDFUnit LayoutAnItem(int index, ListNumberEntry entry, PDFPositionOptions listPosOpts) { //restore the items applied style onto the stack this.StyleStack.Push(entry.AppliedStyle); Style full = entry.FullStyle; PDFUnit numberWidth = entry.NumberWidth; PDFArtefactRegistrationSet artefacts = entry.ListItem.RegisterLayoutArtefacts(this.Context, full); PDFPositionOptions itemopts = full.CreatePostionOptions(); PDFUnit pageHeight = this.Context.DocumentLayout.CurrentPage.Height; PDFUnit h = pageHeight; PDFUnit w = _listBlock.AvailableBounds.Width; PDFUnit y = _itemoffset; PDFUnit alley = DefaultListItemAlley; if (itemopts.HasAlleyWidth) { alley = itemopts.AlleyWidth; } else if (listPosOpts.HasAlleyWidth) { alley = listPosOpts.AlleyWidth; } if (itemopts.Height.HasValue) { h = itemopts.Height.Value; } else if (itemopts.Margins.IsEmpty == false) { h -= itemopts.Margins.Top + itemopts.Margins.Bottom; } h -= itemopts.Padding.Top + itemopts.Padding.Bottom; if (itemopts.Width.HasValue) { w = itemopts.Width.Value; } else if (itemopts.Margins.IsEmpty == false) { w -= itemopts.Margins.Left + itemopts.Margins.Right; } w -= itemopts.Padding.Left + itemopts.Padding.Right; PDFRect totalBounds = new PDFRect(PDFUnit.Zero, y, w, h); this._itemblock = _listBlock.BeginNewContainerBlock(entry.ListItem, this, full, itemopts.PositionMode); PDFColumnOptions colOpts = new PDFColumnOptions() { AlleyWidth = alley, AutoFlow = false, ColumnCount = 2 }; this._itemblock.InitRegions(totalBounds, itemopts, colOpts, this.Context); //Alter the widths of the regions to allow for only the number width PDFRect region1bounds = this._itemblock.Columns[0].TotalBounds; PDFUnit difference = region1bounds.Width - numberWidth; region1bounds.Width = numberWidth; this._itemblock.Columns[0].TotalBounds = region1bounds; this._itemblock.Columns[0].HAlignment = entry.NumberAlignment; PDFRect region2Bounds = this._itemblock.Columns[1].TotalBounds; if (region2Bounds.X > 0) { region2Bounds.X -= difference; } region2Bounds.Width += difference; this._itemblock.Columns[1].TotalBounds = region2Bounds; PDFUnit numberHeight = this.LayoutItemNumber(entry, full); this._itemblock.CurrentRegion.Close(); bool success = this._itemblock.MoveToNextRegion(true, PDFUnit.Zero, this.Context); //Pass Zero as we are not interested in overflowing yet PDFUnit contentHeight = this.LayoutItemContent(entry); //check that we can fit - addind the margins and padding back in. PDFUnit itemHeight = PDFUnit.Max(numberHeight, contentHeight); if (itemopts.Height.HasValue) { itemHeight = itemopts.Height.Value; } else if (itemopts.Margins.IsEmpty == false) { itemHeight += itemopts.Margins.Top + itemopts.Margins.Bottom; } itemHeight += itemopts.Padding.Top + itemopts.Padding.Bottom; if (itemHeight > this._listBlock.AvailableBounds.Height - _itemoffset) { PDFLayoutBlock origparent = this.CurrentBlock; PDFLayoutRegion origregion = this.CurrentBlock.CurrentRegion; PDFLayoutBlock origlist = this._listBlock; PDFLayoutBlock origItem = this._itemblock; if (this._listBlock.Position.OverflowSplit == OverflowSplit.Never) { if (this.MoveFullListToNextRegion(_itemoffset + itemHeight)) { //_itemoffset += itemHeight; //PDFRect avail = _listBlock.AvailableBounds; //avail.Height = avail.Height - _itemoffset; } else { this.Context.TraceLog.Add(TraceLevel.Warning, LOG_CATEGORY, "List '" + this.List.UniqueID + "' has filled the available space, and cannot overflow onto a new region. Layout has stopped at item index " + index); this.ContinueLayout = false; return(0); } } else if (this.StartListInAnotherRegion(itemHeight, origItem, index)) { //origregion.AddToSize(origlist); _itemoffset = 0; origItem.Offset(0, 0); } else { (origItem.Parent as PDFLayoutBlock).CurrentRegion.RemoveItem(origItem); this.Context.TraceLog.Add(TraceLevel.Warning, LOG_CATEGORY, "List '" + this.List.UniqueID + "' has filled the available space, and cannot overflow onto a new region. Layout has stopped at item index " + index); this.ContinueLayout = false; } } else if (this._itemblock.CurrentRegion.IsClosed) { this._itemblock = this.CurrentBlock.LastOpenBlock(); this._listBlock = this._itemblock.Parent as PDFLayoutBlock; } if (null != this._itemblock) { if (this._itemblock.CurrentRegion.IsClosed == false) { this._itemblock.CurrentRegion.Close(); } if (this._itemblock.IsClosed == false) { this._itemblock.Close(); this._listBlock.CurrentRegion.AddToSize(this._itemblock); } } if (this.ContinueLayout) { RegisterChildLayout(entry.ListItem); } if (null != artefacts) { entry.ListItem.CloseLayoutArtefacts(this.Context, artefacts, full); } this.StyleStack.Pop(); return(itemHeight); }
public PDFSize GetRequiredSizeForLayout(PDFSize available, PDFLayoutContext context, Style appliedstyle) { PDFPositionOptions pos = appliedstyle.CreatePostionOptions(); PDFTextRenderOptions opts = appliedstyle.CreateTextOptions(); PDFImageXObject xobj = this.GetImageObject(context, appliedstyle); PDFSize naturalSize = xobj.GetImageSize(); PDFUnit h; PDFUnit w; if (pos.Height.HasValue && pos.Width.HasValue) { w = pos.Width.Value; h = pos.Height.Value; } else if (pos.Width.HasValue) { w = pos.Width.Value; h = naturalSize.Height * (pos.Width.Value.PointsValue / naturalSize.Width.PointsValue); } else if (pos.Height.HasValue) { h = pos.Height.Value; w = naturalSize.Width * (pos.Height.Value.PointsValue / naturalSize.Height.PointsValue); } else if (pos.PositionMode == PositionMode.Inline) { //We dont have an explicit size //So set it to the line height. if (opts.Font != null && opts.Font.FontMetrics != null) { h = opts.Font.FontMetrics.Ascent; } else { h = opts.Font.Size * 0.75; } w = naturalSize.Width * (h.PointsValue / naturalSize.Height.PointsValue); } else //We are in a block on our own line { h = naturalSize.Height; w = naturalSize.Width; if (w > available.Width) { w = available.Width; h = naturalSize.Height * (available.Width.PointsValue / naturalSize.Width.PointsValue); if (h < naturalSize.Height * this.MinimumScaleReduction) { //exceeded our maximum - so reverting back. h = naturalSize.Height; w = naturalSize.Width; } } if (h > available.Height) { h = available.Height; w = naturalSize.Width * (available.Height.PointsValue / naturalSize.Height.PointsValue); if (w < naturalSize.Width * this.MinimumScaleReduction) { h = naturalSize.Height; w = naturalSize.Width; } } } return(new PDFSize(w, h)); }
public PDFLayoutInlineBegin(PDFLayoutLine line, IPDFComponent owner, PDFPositionOptions pos, Style fullStyle) : base(line, owner) { this.InlinePosition = pos; this.FullStyle = fullStyle; }
protected override PDFLayoutRegion BeginNewRelativeRegionForChild(PDFPositionOptions pos, IPDFComponent comp, Style full) { this.AdjustContainerForTextBaseline(pos, comp, full); return(base.BeginNewRelativeRegionForChild(pos, comp, full)); }
// // main override // #region protected override void DoLayoutComponent() /// <summary> /// Performs the actual layout of the list and items in it. /// </summary> protected override void DoLayoutComponent() { if (this.Context.ShouldLogDebug) { this.Context.TraceLog.Begin(TraceLevel.Debug, ListEngineLogCategory, string.Format("Starting the layout of the list {0}", this.List.ID)); } this.ContinueLayout = true; this.CurrentBlock = this.Context.DocumentLayout.CurrentPage.LastOpenBlock(); if (this.CurrentBlock.CurrentRegion != null && this.CurrentBlock.CurrentRegion.HasOpenItem) { this.CurrentBlock.CurrentRegion.CloseCurrentItem(); } PDFPositionOptions pos = this.FullStyle.CreatePostionOptions(); //Set up the outer container block that will hold the list and all it's items _listBlock = this.CurrentBlock.BeginNewContainerBlock(this.List, this, this.FullStyle, pos.PositionMode); PDFRect bounds = this.CurrentBlock.CurrentRegion.UnusedBounds; if (bounds.X > 0) { bounds.X = PDFUnit.Zero; } if (pos.Width.HasValue) { bounds.Width = pos.Width.Value; } else if (pos.Margins.IsEmpty == false) { bounds.Width -= pos.Margins.Left + pos.Margins.Right; } if (pos.Height.HasValue) { bounds.Height = pos.Height.Value; } else if (pos.Margins.IsEmpty == false) { bounds.Height -= pos.Margins.Top + pos.Margins.Bottom; } PDFColumnOptions columnOptions = new PDFColumnOptions() { AlleyWidth = PDFUnit.Zero, AutoFlow = false, ColumnCount = 1 }; _listBlock.InitRegions(bounds, pos, columnOptions, this.Context); this.OpenListNumbering(); this.BuildListEntries(out _itemNumberWidth); this.LayoutListItems(pos); _listBlock.CurrentRegion.CloseCurrentItem(); _listBlock.CurrentRegion.Close(); _listBlock.Close(); this.CurrentBlock.CurrentRegion.AddToSize(_listBlock); if (this.Context.ShouldLogDebug) { this.Context.TraceLog.End(TraceLevel.Debug, ListEngineLogCategory, string.Format("Completed the layout of the list {0}", this.List.ID)); } this.CloseListNumbering(); }
public PDFLayoutInlineEnd(PDFLayoutLine line, PDFLayoutInlineBegin begin, IPDFComponent owner, PDFPositionOptions pos) : base(line, owner) { this.BeginMarker = begin; }