protected override void OnEnteredLayout(LayoutContext layoutContext, ILayout previousLayout) { Tick(); }
public override LayoutResult Layout(LayoutContext layoutContext) { int pageNumber = layoutContext.GetArea().GetPageNumber(); Rectangle parentBBox = layoutContext.GetArea().GetBBox().Clone(); if (this.GetProperty <float?>(Property.ROTATION_ANGLE) != null) { parentBBox.MoveDown(AbstractRenderer.INF - parentBBox.GetHeight()).SetHeight(AbstractRenderer.INF); } float[] margins = GetMargins(); ApplyMargins(parentBBox, margins, false); Border[] borders = GetBorders(); ApplyBorderBox(parentBBox, borders, false); bool isPositioned = IsPositioned(); if (isPositioned) { float x = (float)this.GetPropertyAsFloat(Property.X); float relativeX = IsFixedLayout() ? 0 : parentBBox.GetX(); parentBBox.SetX(relativeX + x); } float?blockWidth = RetrieveWidth(parentBBox.GetWidth()); if (blockWidth != null && (blockWidth < parentBBox.GetWidth() || isPositioned)) { parentBBox.SetWidth((float)blockWidth); } float[] paddings = GetPaddings(); ApplyPaddings(parentBBox, paddings, false); IList <Rectangle> areas; if (isPositioned) { areas = JavaCollectionsUtil.SingletonList(parentBBox); } else { areas = InitElementAreas(new LayoutArea(pageNumber, parentBBox)); } occupiedArea = new LayoutArea(pageNumber, new Rectangle(parentBBox.GetX(), parentBBox.GetY() + parentBBox. GetHeight(), parentBBox.GetWidth(), 0)); int currentAreaPos = 0; Rectangle layoutBox = areas[0].Clone(); bool anythingPlaced = false; bool firstLineInBox = true; lines = new List <LineRenderer>(); LineRenderer currentRenderer = (LineRenderer) new LineRenderer().SetParent(this); foreach (IRenderer child in childRenderers) { currentRenderer.AddChild(child); } if (0 == childRenderers.Count) { anythingPlaced = true; currentRenderer = null; // TODO is this really needed?? SetProperty(Property.MARGIN_TOP, 0); SetProperty(Property.MARGIN_RIGHT, 0); SetProperty(Property.MARGIN_BOTTOM, 0); SetProperty(Property.MARGIN_LEFT, 0); SetProperty(Property.PADDING_TOP, 0); SetProperty(Property.PADDING_RIGHT, 0); SetProperty(Property.PADDING_BOTTOM, 0); SetProperty(Property.PADDING_LEFT, 0); SetProperty(Property.BORDER, Border.NO_BORDER); margins = GetMargins(); borders = GetBorders(); paddings = GetPaddings(); } float lastYLine = layoutBox.GetY() + layoutBox.GetHeight(); Leading leading = this.GetProperty <Leading>(Property.LEADING); float leadingValue = 0; float lastLineHeight = 0; while (currentRenderer != null) { currentRenderer.SetProperty(Property.TAB_DEFAULT, this.GetPropertyAsFloat(Property.TAB_DEFAULT)); currentRenderer.SetProperty(Property.TAB_STOPS, this.GetProperty <Object>(Property.TAB_STOPS)); float lineIndent = anythingPlaced ? 0 : (float)this.GetPropertyAsFloat(Property.FIRST_LINE_INDENT); float availableWidth = layoutBox.GetWidth() - lineIndent; Rectangle childLayoutBox = new Rectangle(layoutBox.GetX() + lineIndent, layoutBox.GetY(), availableWidth, layoutBox.GetHeight()); LineLayoutResult result = ((LineLayoutResult)((LineRenderer)currentRenderer.SetParent(this)).Layout(new LayoutContext (new LayoutArea(pageNumber, childLayoutBox)))); LineRenderer processedRenderer = null; if (result.GetStatus() == LayoutResult.FULL) { processedRenderer = currentRenderer; } else { if (result.GetStatus() == LayoutResult.PARTIAL) { processedRenderer = (LineRenderer)result.GetSplitRenderer(); } } TextAlignment?textAlignment = (TextAlignment?)this.GetProperty <TextAlignment?>(Property.TEXT_ALIGNMENT, TextAlignment .LEFT); if (result.GetStatus() == LayoutResult.PARTIAL && textAlignment == TextAlignment.JUSTIFIED && !result.IsSplitForcedByNewline () || textAlignment == TextAlignment.JUSTIFIED_ALL) { if (processedRenderer != null) { processedRenderer.Justify(layoutBox.GetWidth() - lineIndent); } } else { if (textAlignment != TextAlignment.LEFT && processedRenderer != null) { float deltaX = availableWidth - processedRenderer.GetOccupiedArea().GetBBox().GetWidth(); switch (textAlignment) { case TextAlignment.RIGHT: { processedRenderer.Move(deltaX, 0); break; } case TextAlignment.CENTER: { processedRenderer.Move(deltaX / 2, 0); break; } } } } leadingValue = processedRenderer != null && leading != null?processedRenderer.GetLeadingValue(leading) : 0; if (processedRenderer != null && processedRenderer.ContainsImage()) { leadingValue -= previousDescent; } bool doesNotFit = result.GetStatus() == LayoutResult.NOTHING; float deltaY = 0; if (!doesNotFit) { lastLineHeight = processedRenderer.GetOccupiedArea().GetBBox().GetHeight(); deltaY = lastYLine - leadingValue - processedRenderer.GetYLine(); // for the first and last line in a paragraph, leading is smaller if (firstLineInBox) { deltaY = -(leadingValue - lastLineHeight) / 2; } doesNotFit = leading != null && processedRenderer.GetOccupiedArea().GetBBox().GetY() + deltaY < layoutBox. GetY(); } if (doesNotFit) { if (currentAreaPos + 1 < areas.Count) { layoutBox = areas[++currentAreaPos].Clone(); lastYLine = layoutBox.GetY() + layoutBox.GetHeight(); firstLineInBox = true; } else { bool keepTogether = IsKeepTogether(); if (keepTogether) { return(new LayoutResult(LayoutResult.NOTHING, occupiedArea, null, this)); } else { ApplyPaddings(occupiedArea.GetBBox(), paddings, true); ApplyBorderBox(occupiedArea.GetBBox(), borders, true); ApplyMargins(occupiedArea.GetBBox(), margins, true); iText.Layout.Renderer.ParagraphRenderer[] split = Split(); split[0].lines = lines; foreach (LineRenderer line in lines) { split[0].childRenderers.AddAll(line.GetChildRenderers()); } if (processedRenderer != null) { split[1].childRenderers.AddAll(processedRenderer.GetChildRenderers()); } if (result.GetOverflowRenderer() != null) { split[1].childRenderers.AddAll(result.GetOverflowRenderer().GetChildRenderers()); } if (anythingPlaced) { return(new LayoutResult(LayoutResult.PARTIAL, occupiedArea, split[0], split[1])); } else { if (true.Equals(GetPropertyAsBoolean(Property.FORCED_PLACEMENT))) { parent.SetProperty(Property.FULL, true); lines.Add(currentRenderer); return(new LayoutResult(LayoutResult.FULL, occupiedArea, null, this)); } else { return(new LayoutResult(LayoutResult.NOTHING, occupiedArea, null, this)); } } } } } else { if (leading != null) { processedRenderer.Move(0, deltaY); lastYLine = processedRenderer.GetYLine(); } occupiedArea.SetBBox(Rectangle.GetCommonRectangle(occupiedArea.GetBBox(), processedRenderer.GetOccupiedArea ().GetBBox())); layoutBox.SetHeight(processedRenderer.GetOccupiedArea().GetBBox().GetY() - layoutBox.GetY()); lines.Add(processedRenderer); anythingPlaced = true; firstLineInBox = false; currentRenderer = (LineRenderer)result.GetOverflowRenderer(); previousDescent = processedRenderer.GetMaxDescent(); } } if (!isPositioned) { float moveDown = Math.Min((leadingValue - lastLineHeight) / 2, occupiedArea.GetBBox().GetY() - layoutBox.GetY ()); occupiedArea.GetBBox().MoveDown(moveDown); occupiedArea.GetBBox().SetHeight(occupiedArea.GetBBox().GetHeight() + moveDown); } float?blockHeight = this.GetPropertyAsFloat(Property.HEIGHT); ApplyPaddings(occupiedArea.GetBBox(), paddings, true); if (blockHeight != null && blockHeight > occupiedArea.GetBBox().GetHeight()) { occupiedArea.GetBBox().MoveDown((float)blockHeight - occupiedArea.GetBBox().GetHeight()).SetHeight((float) blockHeight); ApplyVerticalAlignment(); } if (isPositioned) { float y = (float)this.GetPropertyAsFloat(Property.Y); float relativeY = IsFixedLayout() ? 0 : layoutBox.GetY(); Move(0, relativeY + y - occupiedArea.GetBBox().GetY()); } ApplyBorderBox(occupiedArea.GetBBox(), borders, true); ApplyMargins(occupiedArea.GetBBox(), margins, true); if (this.GetProperty <float?>(Property.ROTATION_ANGLE) != null) { ApplyRotationLayout(layoutContext.GetArea().GetBBox().Clone()); if (IsNotFittingHeight(layoutContext.GetArea())) { if (!layoutContext.GetArea().IsEmptyArea()) { return(new LayoutResult(LayoutResult.NOTHING, occupiedArea, null, this)); } } } return(new LayoutResult(LayoutResult.FULL, occupiedArea, null, null)); }
public override LayoutResult Layout(LayoutContext layoutContext) { LayoutArea area = layoutContext.GetArea().Clone(); Rectangle layoutBox = area.GetBBox().Clone(); AffineTransform t = new AffineTransform(); Image modelElement = (Image)(GetModelElement()); PdfXObject xObject = modelElement.GetXObject(); imageWidth = modelElement.GetImageWidth(); imageHeight = modelElement.GetImageHeight(); CalculateImageDimensions(layoutBox, t, xObject); OverflowPropertyValue?overflowX = null != parent?parent.GetProperty <OverflowPropertyValue?>(Property.OVERFLOW_X ) : OverflowPropertyValue.FIT; bool nowrap = false; if (parent is LineRenderer) { nowrap = true.Equals(this.parent.GetOwnProperty <bool?>(Property.NO_SOFT_WRAP_INLINE)); } IList <Rectangle> floatRendererAreas = layoutContext.GetFloatRendererAreas(); float clearHeightCorrection = FloatingHelper.CalculateClearHeightCorrection(this, floatRendererAreas, layoutBox ); FloatPropertyValue?floatPropertyValue = this.GetProperty <FloatPropertyValue?>(Property.FLOAT); if (FloatingHelper.IsRendererFloating(this, floatPropertyValue)) { layoutBox.DecreaseHeight(clearHeightCorrection); FloatingHelper.AdjustFloatedBlockLayoutBox(this, layoutBox, width, floatRendererAreas, floatPropertyValue, overflowX); } else { clearHeightCorrection = FloatingHelper.AdjustLayoutBoxAccordingToFloats(floatRendererAreas, layoutBox, width , clearHeightCorrection, null); } ApplyMargins(layoutBox, false); Border[] borders = GetBorders(); ApplyBorderBox(layoutBox, borders, false); float?declaredMaxHeight = RetrieveMaxHeight(); OverflowPropertyValue?overflowY = null == parent || ((null == declaredMaxHeight || declaredMaxHeight > layoutBox .GetHeight()) && !layoutContext.IsClippedHeight()) ? OverflowPropertyValue.FIT : parent.GetProperty <OverflowPropertyValue? >(Property.OVERFLOW_Y); bool processOverflowX = !IsOverflowFit(overflowX) || nowrap; bool processOverflowY = !IsOverflowFit(overflowY); if (IsAbsolutePosition()) { ApplyAbsolutePosition(layoutBox); } occupiedArea = new LayoutArea(area.GetPageNumber(), new Rectangle(layoutBox.GetX(), layoutBox.GetY() + layoutBox .GetHeight(), 0, 0)); float imageItselfScaledWidth = (float)width; float imageItselfScaledHeight = (float)height; if (IsFixedLayout()) { fixedXPosition = this.GetPropertyAsFloat(Property.LEFT); fixedYPosition = this.GetPropertyAsFloat(Property.BOTTOM); } float?angle = this.GetPropertyAsFloat(Property.ROTATION_ANGLE); // See in adjustPositionAfterRotation why angle = 0 is necessary if (null == angle) { angle = 0f; } t.Rotate((float)angle); initialOccupiedAreaBBox = GetOccupiedAreaBBox().Clone(); float scaleCoef = AdjustPositionAfterRotation((float)angle, layoutBox.GetWidth(), layoutBox.GetHeight()); imageItselfScaledHeight *= scaleCoef; imageItselfScaledWidth *= scaleCoef; initialOccupiedAreaBBox.MoveDown(imageItselfScaledHeight); initialOccupiedAreaBBox.SetHeight(imageItselfScaledHeight); initialOccupiedAreaBBox.SetWidth(imageItselfScaledWidth); if (xObject is PdfFormXObject) { t.Scale(scaleCoef, scaleCoef); } GetMatrix(t, imageItselfScaledWidth, imageItselfScaledHeight); // indicates whether the placement is forced bool isPlacingForced = false; if (width > layoutBox.GetWidth() || height > layoutBox.GetHeight()) { if (true.Equals(GetPropertyAsBoolean(Property.FORCED_PLACEMENT)) || (width > layoutBox.GetWidth() && processOverflowX ) || (height > layoutBox.GetHeight() && processOverflowY)) { isPlacingForced = true; } else { ApplyMargins(initialOccupiedAreaBBox, true); ApplyBorderBox(initialOccupiedAreaBBox, true); occupiedArea.GetBBox().SetHeight(initialOccupiedAreaBBox.GetHeight()); return(new MinMaxWidthLayoutResult(LayoutResult.NOTHING, occupiedArea, null, this, this)); } } occupiedArea.GetBBox().MoveDown((float)height); if (borders[3] != null) { height += (float)Math.Sin((float)angle) * borders[3].GetWidth(); } occupiedArea.GetBBox().SetHeight((float)height); occupiedArea.GetBBox().SetWidth((float)width); UnitValue leftMargin = this.GetPropertyAsUnitValue(Property.MARGIN_LEFT); if (!leftMargin.IsPointValue()) { ILog logger = LogManager.GetLogger(typeof(iText.Layout.Renderer.ImageRenderer)); logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property .MARGIN_LEFT)); } UnitValue topMargin = this.GetPropertyAsUnitValue(Property.MARGIN_TOP); if (!topMargin.IsPointValue()) { ILog logger = LogManager.GetLogger(typeof(iText.Layout.Renderer.ImageRenderer)); logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property .MARGIN_TOP)); } if (0 != leftMargin.GetValue() || 0 != topMargin.GetValue()) { TranslateImage(leftMargin.GetValue(), topMargin.GetValue(), t); GetMatrix(t, imageItselfScaledWidth, imageItselfScaledHeight); } ApplyBorderBox(occupiedArea.GetBBox(), borders, true); ApplyMargins(occupiedArea.GetBBox(), true); if (angle != 0) { ApplyRotationLayout((float)angle); } float unscaledWidth = occupiedArea.GetBBox().GetWidth() / scaleCoef; MinMaxWidth minMaxWidth = new MinMaxWidth(unscaledWidth, unscaledWidth, 0); UnitValue rendererWidth = this.GetProperty <UnitValue>(Property.WIDTH); if (rendererWidth != null && rendererWidth.IsPercentValue()) { minMaxWidth.SetChildrenMinWidth(0); float coeff = imageWidth / (float)RetrieveWidth(area.GetBBox().GetWidth()); minMaxWidth.SetChildrenMaxWidth(unscaledWidth * coeff); } else { bool autoScale = HasProperty(Property.AUTO_SCALE) && (bool)this.GetProperty <bool?>(Property.AUTO_SCALE); bool autoScaleWidth = HasProperty(Property.AUTO_SCALE_WIDTH) && (bool)this.GetProperty <bool?>(Property.AUTO_SCALE_WIDTH ); if (autoScale || autoScaleWidth) { minMaxWidth.SetChildrenMinWidth(0); } } FloatingHelper.RemoveFloatsAboveRendererBottom(floatRendererAreas, this); LayoutArea editedArea = FloatingHelper.AdjustResultOccupiedAreaForFloatAndClear(this, floatRendererAreas, layoutContext.GetArea().GetBBox(), clearHeightCorrection, false); ApplyAbsolutePositionIfNeeded(layoutContext); return(new MinMaxWidthLayoutResult(LayoutResult.FULL, editedArea, null, null, isPlacingForced ? this : null ).SetMinMaxWidth(minMaxWidth)); }
/// <summary> /// When overridden in a derived class, removes any state the layout previously stored on /// the ILayoutable container. /// </summary> /// <param name="context"> /// The context object that facilitates communication between the layout and its host /// container. /// </param> protected virtual void UninitializeForContextCore(LayoutContext context) { }
// TODO underlying should not be applied // https://jira.itextsupport.com/browse/SUP-952 public override LayoutResult Layout(LayoutContext layoutContext) { if (!HasOwnProperty(Property.LIST_SYMBOLS_INITIALIZED)) { IList <IRenderer> symbolRenderers = new List <IRenderer>(); int listItemNum = (int)this.GetProperty <int?>(Property.LIST_START, 1); for (int i = 0; i < childRenderers.Count; i++) { if (childRenderers[i].GetModelElement() is ListItem) { childRenderers[i].SetParent(this); IRenderer currentSymbolRenderer = MakeListSymbolRenderer(listItemNum++, childRenderers[i]); childRenderers[i].SetParent(null); symbolRenderers.Add(currentSymbolRenderer); LayoutResult listSymbolLayoutResult = currentSymbolRenderer.SetParent(this).Layout(layoutContext); currentSymbolRenderer.SetParent(null); if (listSymbolLayoutResult.GetStatus() != LayoutResult.FULL) { return(new LayoutResult(LayoutResult.NOTHING, null, null, this, listSymbolLayoutResult.GetCauseOfNothing() )); } } } float maxSymbolWidth = 0; foreach (IRenderer symbolRenderer in symbolRenderers) { maxSymbolWidth = Math.Max(maxSymbolWidth, symbolRenderer.GetOccupiedArea().GetBBox().GetWidth()); } float?symbolIndent = modelElement.GetProperty <float?>(Property.LIST_SYMBOL_INDENT); listItemNum = 0; foreach (IRenderer childRenderer in childRenderers) { childRenderer.DeleteOwnProperty(Property.MARGIN_LEFT); childRenderer.SetProperty(Property.MARGIN_LEFT, childRenderer.GetProperty(Property.MARGIN_LEFT, (float?)0f ) + maxSymbolWidth + (symbolIndent != null ? symbolIndent : 0f)); if (childRenderer.GetModelElement() is ListItem) { IRenderer symbolRenderer_1 = symbolRenderers[listItemNum++]; ((ListItemRenderer)childRenderer).AddSymbolRenderer(symbolRenderer_1, maxSymbolWidth); } } } LayoutResult result = base.Layout(layoutContext); // cannot place even the first ListItemRenderer if (true.Equals(GetPropertyAsBoolean(Property.FORCED_PLACEMENT)) && null != result.GetCauseOfNothing()) { if (LayoutResult.FULL == result.GetStatus()) { result = CorrectListSplitting(this, null, result.GetCauseOfNothing(), result.GetOccupiedArea()); } else { if (LayoutResult.PARTIAL == result.GetStatus()) { result = CorrectListSplitting(result.GetSplitRenderer(), result.GetOverflowRenderer(), result.GetCauseOfNothing (), result.GetOccupiedArea()); } } } return(result); }
protected override void Compile(LayoutContext layoutContext) { base.Compile(layoutContext); BuildActions(); }
/// <inheritdoc/> public sealed override Size Measure(LayoutContext context, Size availableSize) { return(MeasureOverride((NonVirtualizingLayoutContext)context, availableSize)); }
public LocalizedString DisplayLayout(LayoutContext context) { return(T("Renders list of items as a Project Dashboard portlet")); }
protected override void OnDisplaying(TenantProjection element, ElementDisplayingContext context) { var wc = _multiTenancyService.GetContext(element.TenantName); var _services = wc.Resolve <IOrchardServices>(); var _layoutRepository = wc.Resolve <IRepository <LayoutRecord> >(); var _tokenizer = wc.Resolve <ITokenizer>(); var _displayHelperFactory = wc.Resolve <IDisplayHelperFactory>(); var _contentManager = wc.Resolve <IContentManager>(); var _projectionManager = wc.Resolve <IProjectionManager>(); var queryId = element.QueryId; var layoutId = element.LayoutId; if (queryId == null || layoutId == null) { return; } var query = _contentManager.Get <QueryPart>(queryId.Value); // Retrieving paging parameters. var queryString = _services.WorkContext.HttpContext.Request.QueryString; var pageKey = String.IsNullOrWhiteSpace(element.PagerSuffix) ? "page" : "page-" + element.PagerSuffix; var page = 0; // Default page size. var pageSize = element.ItemsToDisplay; // Don't try to page if not necessary. if (element.DisplayPager && queryString.AllKeys.Contains(pageKey)) { Int32.TryParse(queryString[pageKey], out page); } // If 0, then assume "All", limit to 128 by default. if (pageSize == 128) { pageSize = Int32.MaxValue; } // If pageSize is provided on the query string, ensure it is compatible within allowed limits. var pageSizeKey = "pageSize" + element.PagerSuffix; if (queryString.AllKeys.Contains(pageSizeKey)) { int qsPageSize; if (Int32.TryParse(queryString[pageSizeKey], out qsPageSize)) { if (element.MaxItems == 0 || qsPageSize <= element.MaxItems) { pageSize = qsPageSize; } } } var pager = new Pager(_services.WorkContext.CurrentSite, page, pageSize); // TODO: Investigate this further and see if it makes sense to implement for a Projection Element. //// Generates a link to the RSS feed for this term. //var metaData = _services.ContentManager.GetItemMetadata(part.ContentItem); //_feedManager.Register(metaData.DisplayText, "rss", new RouteValueDictionary { { "projection", part.Id } }); // Execute the query. var contentItems = _projectionManager.GetContentItems(query.Id, pager.GetStartIndex() + element.Skip, pager.PageSize).ToList(); // TODO: Figure out if we need this for a Projection Element, and if so, how. //// Sanity check so that content items with ProjectionPart can't be added here, or it will result in an infinite loop. //contentItems = contentItems.Where(x => !x.Has<ProjectionPart>()).ToList(); // Applying layout. var layout = _layoutRepository.Get(layoutId.Value); var layoutDescriptor = layout == null ? null : _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == layout.Category && x.Type == layout.Type); // Create pager shape. if (element.DisplayPager) { var contentItemsCount = Math.Max(0, _projectionManager.GetCount(query.Id) - element.Skip); var pagerShape = _services.New.Pager(pager) .Element(element) .PagerId(pageKey) .TotalItemCount(contentItemsCount); context.ElementShape.Pager = pagerShape; } // Renders in a standard List shape if no specific layout could be found. if (layoutDescriptor == null) { var contentShapes = contentItems.Select(item => _contentManager.BuildDisplay(item, "Summary")); var list = context.ElementShape.List = _services.New.List(); list.AddRange(contentShapes); return; } var allFielDescriptors = _projectionManager.DescribeProperties().ToList(); var fieldDescriptors = layout.Properties.OrderBy(p => p.Position).Select(p => allFielDescriptors.SelectMany(x => x.Descriptors).Select(d => new { Descriptor = d, Property = p }).FirstOrDefault(x => x.Descriptor.Category == p.Category && x.Descriptor.Type == p.Type)).ToList(); var layoutComponents = contentItems.Select(contentItem => { var contentItemMetadata = _contentManager.GetItemMetadata(contentItem); var propertyDescriptors = fieldDescriptors.Select(d => { var fieldContext = new PropertyContext { State = FormParametersHelper.ToDynamic(d.Property.State), Tokens = new Dictionary <string, object> { { "Content", contentItem } } }; return(new { d.Property, Shape = d.Descriptor.Property(fieldContext, contentItem) }); }); // Apply all settings to the field content, wrapping it in a FieldWrapper shape. var properties = _services.New.Properties( Items: propertyDescriptors.Select( pd => _services.New.PropertyWrapper( Item: pd.Shape, Property: pd.Property, ContentItem: contentItem, ContentItemMetadata: contentItemMetadata ) ) ); return(new LayoutComponentResult { ContentItem = contentItem, ContentItemMetadata = contentItemMetadata, Properties = properties }); }).ToList(); var tokenizedState = _tokenizer.Replace(layout.State, new Dictionary <string, object> { { "Content", context.Content.ContentItem } }); var renderLayoutContext = new LayoutContext { State = FormParametersHelper.ToDynamic(tokenizedState), LayoutRecord = layout, }; if (layout.GroupProperty != null) { var groupPropertyId = layout.GroupProperty.Id; var display = _displayHelperFactory.CreateHelper(new ViewContext { HttpContext = _services.WorkContext.HttpContext }, new ViewDataContainer()); // Index by PropertyWrapper shape. var groups = layoutComponents.GroupBy(x => { var propertyShape = ((IEnumerable <dynamic>)x.Properties.Items).First(p => ((PropertyRecord)p.Property).Id == groupPropertyId); // clear the wrappers, as they shouldn't be needed to generate the grouping key itself // otherwise the DisplayContext.View is null, and throws an exception if a wrapper is rendered (#18558) ((IShape)propertyShape).Metadata.Wrappers.Clear(); string key = Convert.ToString(display(propertyShape)); return(key); }).Select(x => new { Key = x.Key, Components = x }); var list = context.ElementShape.List = _services.New.List(); foreach (var group in groups) { var localResult = layoutDescriptor.Render(renderLayoutContext, group.Components); // Add the Context to the shape. localResult.Context(renderLayoutContext); list.Add(_services.New.LayoutGroup(Key: new MvcHtmlString(group.Key), List: localResult)); } return; } var layoutResult = layoutDescriptor.Render(renderLayoutContext, layoutComponents); // Add the Context to the shape. layoutResult.Context(renderLayoutContext); // Set the List shape to be the layout result. context.ElementShape.List = layoutResult; }
public abstract LayoutResult Layout(LayoutContext layoutContext);
/// <summary> /// Create a collection from a specified enumeration of <see cref="IElement"/> instances. /// </summary> /// <typeparam name="TControl"></typeparam> /// <param name="context"></param> /// <param name="children"></param> /// <param name="control"></param> /// <returns></returns> public static TControl From <TControl>(LayoutContext context, IEnumerable <IElement> children, TControl control) where TControl : BasePrimitive { control.Attributes.SetAttribute(Group.ChildrenAttribute, children.Layout(context)); return(control); }
public override LayoutResult Layout(LayoutContext layoutContext) { LayoutResult result = base.Layout(layoutContext); return(result); }
public LayoutResult Layout(LayoutContext ctx) { var content = ctx.ContentRange as RtfControlContentRange; return(new LayoutResult(content, _status, _computedSize)); }
public void EnterLayout(LayoutContext layoutContext, ILayout previousLayout) { _layoutContext = layoutContext; ProcessDraw(); _timerToken.Start(); }
protected abstract IPrimitive PerformLayout(LayoutContext layoutContext);
/// <summary> /// Méthode statique de Layout /// </summary> /// <param name="graphe">Graphe entrée</param> /// <param name="rectangle">Zone de dessin</param> /// <param name="layout">Type de layout</param> /// <returns>Le graphe repositionné</returns> public static Graph LayoutGraph(Graph graphe, Rectangle rectangle, GraphLayoutType layout) { Microsoft.Chung.Core.Graph mcg = new Microsoft.Chung.Core.Graph(); #region Copy the graph foreach (Noeud n in graphe.Noeuds) { if (!n.Supprimé) { Microsoft.Chung.Core.Vertex v = new Microsoft.Chung.Core.Vertex(); v.SetValue("ID", n.ID); v.Name = n.Texte; mcg.Vertices.Add(v); } } foreach (Trait e in graphe.Traits) { Microsoft.Chung.Core.IVertex vs; Microsoft.Chung.Core.IVertex vt; mcg.Vertices.Find(e.Source.Texte, out vs); mcg.Vertices.Find(e.Destination.Texte, out vt); if ((vs != null) && (vt != null)) { Microsoft.Chung.Core.Edge mce = new Microsoft.Chung.Core.Edge(vs, vt, true); mcg.Edges.Add(mce); } } #endregion ILayout fr = ChooseLayout(layout); rectangle = new Rectangle(100, 100, rectangle.Width - 150, rectangle.Height - 150); LayoutContext t = new LayoutContext(rectangle, gd); fr.LayOutGraph(mcg, t); gd.Layout = fr; #region Update initialgraph foreach (Noeud n in graphe.Noeuds) { lock (graphe) { Microsoft.Chung.Core.IVertex vs; mcg.Vertices.Find(n.Texte, out vs); n.Déplace(new Point((int)vs.Location.X, (int)vs.Location.Y)); } } #endregion return graphe; }
private LayoutResult LayoutContentRange(CalendarContentRange range, CalendarData calendarData, LayoutContext context) { LayoutResult result = MeasureContentRange(range, calendarData, new SizeF(float.MaxValue, float.MaxValue)); SizeF completeSize = GetCompleteSize(calendarData); if (range.EndHorzRange <= 0) { range.EndHorzRange = completeSize.Width; } if (range.EndVertRange <= 0) { range.EndVertRange = completeSize.Height; } SizeF size = new SizeF(range.EndHorzRange - range.StartHorzRange, range.EndVertRange - range.StartVertRange); if (context.AvailableSize.Width > 0 && size.Width > context.AvailableSize.Width) { size.Width = context.AvailableSize.Width; range.EndHorzRange = range.StartHorzRange + context.AvailableSize.Width; } if (context.LayoutDirection != LayoutDirection.Horizontal) { range.EndHorzRange = -1; } else { range.EndVertRange = -1; } if (context.AvailableSize.Height > 0 && size.Height > context.AvailableSize.Height) { size.Height = context.AvailableSize.Height; range.EndVertRange = range.StartVertRange + context.AvailableSize.Height + CalendarData.MonthsSpace; } if (Utils.ApproxGreaterOrEquals(range.EndHorzRange, completeSize.Width)) { if (context.LayoutDirection == LayoutDirection.Horizontal && range.EndVertRange > 0) { CalendarContentRange.StaticRange staticRange = new CalendarContentRange.StaticRange(range.EndVertRange); range = new CalendarContentRange(staticRange, range.Owner, range.MonthFrom, range.MonthTo); // so the layout will continue in a vertical direction } else { range.EndHorzRange = -1; } } if (Utils.ApproxGreaterOrEquals(range.EndVertRange, completeSize.Height)) { range.EndVertRange = -1; } return(result); }
/// <summary><inheritDoc/></summary> public override LayoutResult Layout(LayoutContext layoutContext) { bool wasHeightClipped = false; bool wasParentsHeightClipped = layoutContext.IsClippedHeight(); int pageNumber = layoutContext.GetArea().GetPageNumber(); bool anythingPlaced = false; bool firstLineInBox = true; LineRenderer currentRenderer = (LineRenderer) new LineRenderer().SetParent(this); Rectangle parentBBox = layoutContext.GetArea().GetBBox().Clone(); MarginsCollapseHandler marginsCollapseHandler = null; bool marginsCollapsingEnabled = true.Equals(GetPropertyAsBoolean(Property.COLLAPSING_MARGINS)); if (marginsCollapsingEnabled) { marginsCollapseHandler = new MarginsCollapseHandler(this, layoutContext.GetMarginsCollapseInfo()); } OverflowPropertyValue?overflowX = this.GetProperty <OverflowPropertyValue?>(Property.OVERFLOW_X); bool?nowrapProp = this.GetPropertyAsBoolean(Property.NO_SOFT_WRAP_INLINE); currentRenderer.SetProperty(Property.NO_SOFT_WRAP_INLINE, nowrapProp); bool notAllKidsAreFloats = false; IList <Rectangle> floatRendererAreas = layoutContext.GetFloatRendererAreas(); FloatPropertyValue?floatPropertyValue = this.GetProperty <FloatPropertyValue?>(Property.FLOAT); float clearHeightCorrection = FloatingHelper.CalculateClearHeightCorrection(this, floatRendererAreas, parentBBox ); FloatingHelper.ApplyClearance(parentBBox, marginsCollapseHandler, clearHeightCorrection, FloatingHelper.IsRendererFloating (this)); float?blockWidth = RetrieveWidth(parentBBox.GetWidth()); if (FloatingHelper.IsRendererFloating(this, floatPropertyValue)) { blockWidth = FloatingHelper.AdjustFloatedBlockLayoutBox(this, parentBBox, blockWidth, floatRendererAreas, floatPropertyValue, overflowX); floatRendererAreas = new List <Rectangle>(); } if (0 == childRenderers.Count) { anythingPlaced = true; currentRenderer = null; } bool isPositioned = IsPositioned(); float?rotation = this.GetPropertyAsFloat(Property.ROTATION_ANGLE); float?blockMaxHeight = RetrieveMaxHeight(); OverflowPropertyValue?overflowY = (null == blockMaxHeight || blockMaxHeight > parentBBox.GetHeight()) && !wasParentsHeightClipped ? OverflowPropertyValue.FIT : this.GetProperty <OverflowPropertyValue?>(Property .OVERFLOW_Y); if (rotation != null || IsFixedLayout()) { parentBBox.MoveDown(AbstractRenderer.INF - parentBBox.GetHeight()).SetHeight(AbstractRenderer.INF); } if (rotation != null && !FloatingHelper.IsRendererFloating(this)) { blockWidth = RotationUtils.RetrieveRotatedLayoutWidth(parentBBox.GetWidth(), this); } if (marginsCollapsingEnabled) { marginsCollapseHandler.StartMarginsCollapse(parentBBox); } Border[] borders = GetBorders(); UnitValue[] paddings = GetPaddings(); float additionalWidth = ApplyBordersPaddingsMargins(parentBBox, borders, paddings); ApplyWidth(parentBBox, blockWidth, overflowX); wasHeightClipped = ApplyMaxHeight(parentBBox, blockMaxHeight, marginsCollapseHandler, false, wasParentsHeightClipped , overflowY); MinMaxWidth minMaxWidth = new MinMaxWidth(additionalWidth); AbstractWidthHandler widthHandler = new MaxMaxWidthHandler(minMaxWidth); IList <Rectangle> areas; if (isPositioned) { areas = JavaCollectionsUtil.SingletonList(parentBBox); } else { areas = InitElementAreas(new LayoutArea(pageNumber, parentBBox)); } occupiedArea = new LayoutArea(pageNumber, new Rectangle(parentBBox.GetX(), parentBBox.GetY() + parentBBox. GetHeight(), parentBBox.GetWidth(), 0)); ShrinkOccupiedAreaForAbsolutePosition(); int currentAreaPos = 0; Rectangle layoutBox = areas[0].Clone(); lines = new List <LineRenderer>(); foreach (IRenderer child in childRenderers) { notAllKidsAreFloats = notAllKidsAreFloats || !FloatingHelper.IsRendererFloating(child); currentRenderer.AddChild(child); } float lastYLine = layoutBox.GetY() + layoutBox.GetHeight(); Leading leading = this.GetProperty <Leading>(Property.LEADING); float lastLineBottomLeadingIndent = 0; bool onlyOverflowedFloatsLeft = false; IList <IRenderer> inlineFloatsOverflowedToNextPage = new List <IRenderer>(); bool floatOverflowedToNextPageWithNothing = false; // rectangles are compared by instances ICollection <Rectangle> nonChildFloatingRendererAreas = new HashSet <Rectangle>(floatRendererAreas); if (marginsCollapsingEnabled && childRenderers.Count > 0) { // passing null is sufficient to notify that there is a kid, however we don't care about it and it's margins marginsCollapseHandler.StartChildMarginsHandling(null, layoutBox); } bool includeFloatsInOccupiedArea = BlockFormattingContextUtil.IsRendererCreateBfc(this); while (currentRenderer != null) { currentRenderer.SetProperty(Property.TAB_DEFAULT, this.GetPropertyAsFloat(Property.TAB_DEFAULT)); currentRenderer.SetProperty(Property.TAB_STOPS, this.GetProperty <Object>(Property.TAB_STOPS)); float lineIndent = anythingPlaced ? 0 : (float)this.GetPropertyAsFloat(Property.FIRST_LINE_INDENT); Rectangle childLayoutBox = new Rectangle(layoutBox.GetX(), layoutBox.GetY(), layoutBox.GetWidth(), layoutBox .GetHeight()); currentRenderer.SetProperty(Property.OVERFLOW_X, overflowX); currentRenderer.SetProperty(Property.OVERFLOW_Y, overflowY); LineLayoutContext lineLayoutContext = new LineLayoutContext(new LayoutArea(pageNumber, childLayoutBox), null , floatRendererAreas, wasHeightClipped || wasParentsHeightClipped).SetTextIndent(lineIndent).SetFloatOverflowedToNextPageWithNothing (floatOverflowedToNextPageWithNothing); LineLayoutResult result = (LineLayoutResult)((LineRenderer)currentRenderer.SetParent(this)).Layout(lineLayoutContext ); if (result.GetStatus() == LayoutResult.NOTHING) { float?lineShiftUnderFloats = FloatingHelper.CalculateLineShiftUnderFloats(floatRendererAreas, layoutBox); if (lineShiftUnderFloats != null) { layoutBox.DecreaseHeight((float)lineShiftUnderFloats); firstLineInBox = true; continue; } bool allRemainingKidsAreFloats = !currentRenderer.childRenderers.IsEmpty(); foreach (IRenderer renderer in currentRenderer.childRenderers) { allRemainingKidsAreFloats = allRemainingKidsAreFloats && FloatingHelper.IsRendererFloating(renderer); } if (allRemainingKidsAreFloats) { onlyOverflowedFloatsLeft = true; } } floatOverflowedToNextPageWithNothing = lineLayoutContext.IsFloatOverflowedToNextPageWithNothing(); if (result.GetFloatsOverflowedToNextPage() != null) { inlineFloatsOverflowedToNextPage.AddAll(result.GetFloatsOverflowedToNextPage()); } float minChildWidth = 0; float maxChildWidth = 0; if (result is MinMaxWidthLayoutResult) { minChildWidth = ((MinMaxWidthLayoutResult)result).GetMinMaxWidth().GetMinWidth(); maxChildWidth = ((MinMaxWidthLayoutResult)result).GetMinMaxWidth().GetMaxWidth(); } widthHandler.UpdateMinChildWidth(minChildWidth); widthHandler.UpdateMaxChildWidth(maxChildWidth); LineRenderer processedRenderer = null; if (result.GetStatus() == LayoutResult.FULL) { processedRenderer = currentRenderer; } else { if (result.GetStatus() == LayoutResult.PARTIAL) { processedRenderer = (LineRenderer)result.GetSplitRenderer(); } } if (onlyOverflowedFloatsLeft) { // This is done to trick ParagraphRenderer to break rendering and to overflow to the next page. // The `onlyOverflowedFloatsLeft` is set to true only when no other content is left except // overflowed floating elements. processedRenderer = null; } TextAlignment?textAlignment = (TextAlignment?)this.GetProperty <TextAlignment?>(Property.TEXT_ALIGNMENT, TextAlignment .LEFT); ApplyTextAlignment(textAlignment, result, processedRenderer, layoutBox, floatRendererAreas, onlyOverflowedFloatsLeft , lineIndent); // could be false if e.g. line contains only floats bool lineHasContent = processedRenderer != null && processedRenderer.GetOccupiedArea().GetBBox().GetHeight () > 0; bool doesNotFit = processedRenderer == null; float deltaY = 0; if (!doesNotFit) { if (lineHasContent) { float indentFromLastLine = previousDescent - lastLineBottomLeadingIndent - (leading != null ? processedRenderer .GetTopLeadingIndent(leading) : 0) - processedRenderer.GetMaxAscent(); // TODO this is a workaround. To be refactored if (processedRenderer != null && processedRenderer.ContainsImage()) { indentFromLastLine += previousDescent; } deltaY = lastYLine + indentFromLastLine - processedRenderer.GetYLine(); lastLineBottomLeadingIndent = leading != null?processedRenderer.GetBottomLeadingIndent(leading) : 0; // TODO this is a workaround. To be refactored if (lastLineBottomLeadingIndent < 0 && processedRenderer.ContainsImage()) { lastLineBottomLeadingIndent = 0; } } // for the first and last line in a paragraph, leading is smaller if (firstLineInBox) { deltaY = processedRenderer != null && leading != null ? -processedRenderer.GetTopLeadingIndent(leading) : 0; } doesNotFit = leading != null && processedRenderer.GetOccupiedArea().GetBBox().GetY() + deltaY < layoutBox. GetY(); } if (doesNotFit && (null == processedRenderer || IsOverflowFit(overflowY))) { if (currentAreaPos + 1 < areas.Count) { layoutBox = areas[++currentAreaPos].Clone(); lastYLine = layoutBox.GetY() + layoutBox.GetHeight(); firstLineInBox = true; } else { bool keepTogether = IsKeepTogether(); if (keepTogether) { return(new MinMaxWidthLayoutResult(LayoutResult.NOTHING, null, null, this, null == result.GetCauseOfNothing () ? this : result.GetCauseOfNothing())); } else { if (marginsCollapsingEnabled) { if (anythingPlaced && notAllKidsAreFloats) { marginsCollapseHandler.EndChildMarginsHandling(layoutBox); } } // On page split, if not only overflowed floats left, content will be drawn on next page, i.e. under all floats on this page bool includeFloatsInOccupiedAreaOnSplit = !onlyOverflowedFloatsLeft || includeFloatsInOccupiedArea; if (includeFloatsInOccupiedAreaOnSplit) { FloatingHelper.IncludeChildFloatsInOccupiedArea(floatRendererAreas, this, nonChildFloatingRendererAreas); FixOccupiedAreaIfOverflowedX(overflowX, layoutBox); } if (marginsCollapsingEnabled) { marginsCollapseHandler.EndMarginsCollapse(layoutBox); } bool minHeightOverflowed = false; if (!includeFloatsInOccupiedAreaOnSplit) { AbstractRenderer minHeightOverflow = ApplyMinHeight(overflowY, layoutBox); minHeightOverflowed = minHeightOverflow != null; ApplyVerticalAlignment(); } iText.Layout.Renderer.ParagraphRenderer[] split = Split(); split[0].lines = lines; foreach (LineRenderer line in lines) { split[0].childRenderers.AddAll(line.GetChildRenderers()); } split[1].childRenderers.AddAll(inlineFloatsOverflowedToNextPage); if (processedRenderer != null) { split[1].childRenderers.AddAll(processedRenderer.GetChildRenderers()); } if (result.GetOverflowRenderer() != null) { split[1].childRenderers.AddAll(result.GetOverflowRenderer().GetChildRenderers()); } if (onlyOverflowedFloatsLeft && !includeFloatsInOccupiedArea && !minHeightOverflowed) { FloatingHelper.RemoveParentArtifactsOnPageSplitIfOnlyFloatsOverflow(split[1]); } float usedHeight = occupiedArea.GetBBox().GetHeight(); if (!includeFloatsInOccupiedAreaOnSplit) { Rectangle commonRectangle = Rectangle.GetCommonRectangle(layoutBox, occupiedArea.GetBBox()); usedHeight = commonRectangle.GetHeight(); } UpdateHeightsOnSplit(usedHeight, wasHeightClipped, this, split[1], includeFloatsInOccupiedAreaOnSplit); CorrectFixedLayout(layoutBox); ApplyPaddings(occupiedArea.GetBBox(), paddings, true); ApplyBorderBox(occupiedArea.GetBBox(), borders, true); ApplyMargins(occupiedArea.GetBBox(), true); ApplyAbsolutePositionIfNeeded(layoutContext); LayoutArea editedArea = FloatingHelper.AdjustResultOccupiedAreaForFloatAndClear(this, layoutContext.GetFloatRendererAreas (), layoutContext.GetArea().GetBBox(), clearHeightCorrection, marginsCollapsingEnabled); if (wasHeightClipped) { return(new MinMaxWidthLayoutResult(LayoutResult.FULL, editedArea, split[0], null).SetMinMaxWidth(minMaxWidth )); } else { if (anythingPlaced) { return(new MinMaxWidthLayoutResult(LayoutResult.PARTIAL, editedArea, split[0], split[1]).SetMinMaxWidth(minMaxWidth )); } else { if (true.Equals(GetPropertyAsBoolean(Property.FORCED_PLACEMENT))) { occupiedArea.SetBBox(Rectangle.GetCommonRectangle(occupiedArea.GetBBox(), currentRenderer.GetOccupiedArea( ).GetBBox())); FixOccupiedAreaIfOverflowedX(overflowX, layoutBox); parent.SetProperty(Property.FULL, true); lines.Add(currentRenderer); // Force placement of children we have and do not force placement of the others if (LayoutResult.PARTIAL == result.GetStatus()) { IRenderer childNotRendered = result.GetCauseOfNothing(); int firstNotRendered = currentRenderer.childRenderers.IndexOf(childNotRendered); currentRenderer.childRenderers.RetainAll(currentRenderer.childRenderers.SubList(0, firstNotRendered)); split[1].childRenderers.RemoveAll(split[1].childRenderers.SubList(0, firstNotRendered)); return(new MinMaxWidthLayoutResult(LayoutResult.PARTIAL, editedArea, this, split[1], null).SetMinMaxWidth( minMaxWidth)); } else { return(new MinMaxWidthLayoutResult(LayoutResult.FULL, editedArea, null, null, this).SetMinMaxWidth(minMaxWidth )); } } else { return(new MinMaxWidthLayoutResult(LayoutResult.NOTHING, null, null, this, null == result.GetCauseOfNothing () ? this : result.GetCauseOfNothing())); } } } } } } else { if (leading != null) { processedRenderer.ApplyLeading(deltaY); if (lineHasContent) { lastYLine = processedRenderer.GetYLine(); } } if (lineHasContent) { occupiedArea.SetBBox(Rectangle.GetCommonRectangle(occupiedArea.GetBBox(), processedRenderer.GetOccupiedArea ().GetBBox())); FixOccupiedAreaIfOverflowedX(overflowX, layoutBox); } firstLineInBox = false; layoutBox.SetHeight(processedRenderer.GetOccupiedArea().GetBBox().GetY() - layoutBox.GetY()); lines.Add(processedRenderer); anythingPlaced = true; currentRenderer = (LineRenderer)result.GetOverflowRenderer(); previousDescent = processedRenderer.GetMaxDescent(); if (!inlineFloatsOverflowedToNextPage.IsEmpty() && result.GetOverflowRenderer() == null) { onlyOverflowedFloatsLeft = true; // dummy renderer to trick paragraph renderer to continue kids loop currentRenderer = new LineRenderer(); } } } float moveDown = lastLineBottomLeadingIndent; if (IsOverflowFit(overflowY) && moveDown > occupiedArea.GetBBox().GetY() - layoutBox.GetY()) { moveDown = occupiedArea.GetBBox().GetY() - layoutBox.GetY(); } occupiedArea.GetBBox().MoveDown(moveDown); occupiedArea.GetBBox().SetHeight(occupiedArea.GetBBox().GetHeight() + moveDown); if (marginsCollapsingEnabled) { if (childRenderers.Count > 0 && notAllKidsAreFloats) { marginsCollapseHandler.EndChildMarginsHandling(layoutBox); } } if (includeFloatsInOccupiedArea) { FloatingHelper.IncludeChildFloatsInOccupiedArea(floatRendererAreas, this, nonChildFloatingRendererAreas); FixOccupiedAreaIfOverflowedX(overflowX, layoutBox); } if (wasHeightClipped) { FixOccupiedAreaIfOverflowedY(overflowY, layoutBox); } if (marginsCollapsingEnabled) { marginsCollapseHandler.EndMarginsCollapse(layoutBox); } AbstractRenderer overflowRenderer = ApplyMinHeight(overflowY, layoutBox); if (overflowRenderer != null && IsKeepTogether()) { return(new LayoutResult(LayoutResult.NOTHING, null, null, this, this)); } CorrectFixedLayout(layoutBox); ApplyPaddings(occupiedArea.GetBBox(), paddings, true); ApplyBorderBox(occupiedArea.GetBBox(), borders, true); ApplyMargins(occupiedArea.GetBBox(), true); ApplyAbsolutePositionIfNeeded(layoutContext); if (rotation != null) { ApplyRotationLayout(layoutContext.GetArea().GetBBox().Clone()); if (IsNotFittingLayoutArea(layoutContext.GetArea())) { if (IsNotFittingWidth(layoutContext.GetArea()) && !IsNotFittingHeight(layoutContext.GetArea())) { LogManager.GetLogger(GetType()).Warn(MessageFormatUtil.Format(iText.IO.LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA , "It fits by height so it will be forced placed")); } else { if (!true.Equals(GetPropertyAsBoolean(Property.FORCED_PLACEMENT))) { return(new MinMaxWidthLayoutResult(LayoutResult.NOTHING, null, null, this, this)); } } } } ApplyVerticalAlignment(); FloatingHelper.RemoveFloatsAboveRendererBottom(floatRendererAreas, this); LayoutArea editedArea_1 = FloatingHelper.AdjustResultOccupiedAreaForFloatAndClear(this, layoutContext.GetFloatRendererAreas (), layoutContext.GetArea().GetBBox(), clearHeightCorrection, marginsCollapsingEnabled); if (null == overflowRenderer) { return(new MinMaxWidthLayoutResult(LayoutResult.FULL, editedArea_1, null, null, null).SetMinMaxWidth(minMaxWidth )); } else { return(new MinMaxWidthLayoutResult(LayoutResult.PARTIAL, editedArea_1, this, overflowRenderer, null).SetMinMaxWidth (minMaxWidth)); } }
/// <inheritdoc/> public sealed override void UninitializeForContext(LayoutContext context) { UninitializeForContextCore((NonVirtualizingLayoutContext)context); }
/* (non-Javadoc) * @see com.itextpdf.layout.renderer.BlockRenderer#layout(com.itextpdf.layout.layout.LayoutContext) */ public override LayoutResult Layout(LayoutContext layoutContext) { childRenderers.Clear(); flatRenderer = null; float parentWidth = layoutContext.GetArea().GetBBox().GetWidth(); float parentHeight = layoutContext.GetArea().GetBBox().GetHeight(); IRenderer renderer = CreateFlatRenderer(); renderer.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.VISIBLE); renderer.SetProperty(Property.OVERFLOW_Y, OverflowPropertyValue.VISIBLE); AddChild(renderer); Rectangle bBox = layoutContext.GetArea().GetBBox().Clone().MoveDown(INF - parentHeight).SetHeight(INF); layoutContext.GetArea().SetBBox(bBox); LayoutResult result = base.Layout(layoutContext); if (!true.Equals(GetPropertyAsBoolean(Property.FORCED_PLACEMENT)) && (result.GetStatus() != LayoutResult.FULL )) { //@TODO investigate this tricky code a little more. FloatPropertyValue?floatPropertyValue = this.GetProperty <FloatPropertyValue?>(Property.FLOAT); if (floatPropertyValue == null || floatPropertyValue == FloatPropertyValue.NONE) { SetProperty(Property.FORCED_PLACEMENT, true); } else { flatRenderer = childRenderers[0]; ProcessLangAttribute(); childRenderers.Clear(); childRenderers.Add(flatRenderer); AdjustFieldLayout(layoutContext); if (IsLayoutBasedOnFlatRenderer()) { Rectangle fBox = flatRenderer.GetOccupiedArea().GetBBox(); occupiedArea.GetBBox().SetX(fBox.GetX()).SetY(fBox.GetY()).SetWidth(fBox.GetWidth()).SetHeight(fBox.GetHeight ()); ApplyPaddings(occupiedArea.GetBBox(), true); ApplyBorderBox(occupiedArea.GetBBox(), true); ApplyMargins(occupiedArea.GetBBox(), true); } } return(new MinMaxWidthLayoutResult(LayoutResult.NOTHING, occupiedArea, null, this, this).SetMinMaxWidth(new MinMaxWidth())); } if (!childRenderers.IsEmpty()) { flatRenderer = childRenderers[0]; ProcessLangAttribute(); childRenderers.Clear(); childRenderers.Add(flatRenderer); AdjustFieldLayout(layoutContext); if (IsLayoutBasedOnFlatRenderer()) { Rectangle fBox = flatRenderer.GetOccupiedArea().GetBBox(); occupiedArea.GetBBox().SetX(fBox.GetX()).SetY(fBox.GetY()).SetWidth(fBox.GetWidth()).SetHeight(fBox.GetHeight ()); ApplyPaddings(occupiedArea.GetBBox(), true); ApplyBorderBox(occupiedArea.GetBBox(), true); ApplyMargins(occupiedArea.GetBBox(), true); } } else { LogManager.GetLogger(GetType()).Error(iText.Html2pdf.LogMessageConstant.ERROR_WHILE_LAYOUT_OF_FORM_FIELD); occupiedArea.GetBBox().SetWidth(0).SetHeight(0); } if (!true.Equals(GetPropertyAsBoolean(Property.FORCED_PLACEMENT)) && !IsRendererFit(parentWidth, parentHeight )) { occupiedArea.GetBBox().SetWidth(0).SetHeight(0); return(new MinMaxWidthLayoutResult(LayoutResult.NOTHING, occupiedArea, null, this, this).SetMinMaxWidth(new MinMaxWidth())); } if (result.GetStatus() != LayoutResult.FULL || !IsRendererFit(parentWidth, parentHeight)) { LogManager.GetLogger(GetType()).Warn(iText.Html2pdf.LogMessageConstant.INPUT_FIELD_DOES_NOT_FIT); } return(new MinMaxWidthLayoutResult(LayoutResult.FULL, occupiedArea, this, null).SetMinMaxWidth(new MinMaxWidth (occupiedArea.GetBBox().GetWidth(), occupiedArea.GetBBox().GetWidth(), 0))); }
/// <inheritdoc/> public sealed override Size Arrange(LayoutContext context, Size finalSize) { return(ArrangeOverride((NonVirtualizingLayoutContext)context, finalSize)); }
//NOTE: should be abstract in 3.0.0 protected internal virtual void AdjustFieldLayout(LayoutContext layoutContext) { AdjustFieldLayout(); }
protected override IPrimitive PerformLayout(LayoutContext layoutContext) { return(_lists.PerformLayout(layoutContext)); }
/// <summary> /// Default layout call. /// </summary> /// <param name="layoutContext"></param> /// <param name="model"></param> /// <returns></returns> protected abstract IPrimitive PerformLayout(LayoutContext layoutContext, TModel model);
/* (non-Javadoc) * @see com.itextpdf.html2pdf.attach.impl.layout.form.renderer.AbstractFormFieldRenderer#adjustFieldLayout() */ protected internal override void AdjustFieldLayout(LayoutContext layoutContext) { this.SetProperty(Property.BACKGROUND, null); }
/// <summary> /// Default layout call, calls <see cref="PerformContentLayout"/> /// </summary> /// <param name="layoutContext"></param> /// <param name="model"></param> /// <returns></returns> protected virtual IPrimitive PerformContentLayout(LayoutContext layoutContext, TModel model) { return(ContentPage(this, PerformLayout(layoutContext, model))); }
/// <summary><inheritDoc/></summary> public override LayoutResult Layout(LayoutContext layoutContext) { throw new InvalidOperationException("Layout is not supported for root renderers."); }
public override void ButtonPressed(Location location, ButtonEvent buttonEvent) { base.ButtonPressed(location, buttonEvent); LayoutContext.SetPreviousLayout(); }
protected override DriverResult Display(ProjectionPart part, string displayType, dynamic shapeHelper) { var query = part.Record.QueryPartRecord; // retrieving paging parameters var queryString = Services.WorkContext.HttpContext.Request.QueryString; var pageKey = String.IsNullOrWhiteSpace(part.Record.PagerSuffix) ? "page" : "page-" + part.Record.PagerSuffix; var page = 0; // default page size int pageSize = part.Record.Items; // don't try to page if not necessary if (part.Record.DisplayPager && queryString.AllKeys.Contains(pageKey)) { Int32.TryParse(queryString[pageKey], out page); } // if 0, then assume "All", limit to 128 by default if (pageSize == 128) { pageSize = Int32.MaxValue; } // if pageSize is provided on the query string, ensure it is compatible with allowed limits var pageSizeKey = "pageSize" + part.Record.PagerSuffix; if (queryString.AllKeys.Contains(pageSizeKey)) { int qsPageSize; if (Int32.TryParse(queryString[pageSizeKey], out qsPageSize)) { if (part.Record.MaxItems == 0 || qsPageSize <= part.Record.MaxItems) { pageSize = qsPageSize; } } } var pager = new Pager(Services.WorkContext.CurrentSite, page, pageSize); var pagerShape = shapeHelper.Pager(pager) .ContentPart(part) .PagerId(pageKey); return(Combined( ContentShape("Parts_ProjectionPart_Pager", shape => { if (!part.Record.DisplayPager) { return null; } return pagerShape; }), ContentShape("Parts_ProjectionPart_List", shape => { // generates a link to the RSS feed for this term var metaData = Services.ContentManager.GetItemMetadata(part.ContentItem); _feedManager.Register(metaData.DisplayText, "rss", new RouteValueDictionary { { "projection", part.Id } }); // execute the query var contentItems = _projectionManager.GetContentItems(query.Id, part, pager.GetStartIndex() + part.Record.Skip, pager.PageSize).ToList(); // sanity check so that content items with ProjectionPart can't be added here, or it will result in an infinite loop contentItems = contentItems.Where(x => !x.Has <ProjectionPart>()).ToList(); // applying layout var layout = part.Record.LayoutRecord; LayoutDescriptor layoutDescriptor = layout == null ? null : _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == layout.Category && x.Type == layout.Type); // create pager shape if (part.Record.DisplayPager) { var contentItemsCount = _projectionManager.GetCount(query.Id, part) - part.Record.Skip; contentItemsCount = Math.Max(0, contentItemsCount); pagerShape.TotalItemCount(contentItemsCount); } // renders in a standard List shape if no specific layout could be found if (layoutDescriptor == null) { var list = Services.New.List(); var contentShapes = contentItems.Select(item => Services.ContentManager.BuildDisplay(item, "Summary")); list.AddRange(contentShapes); return list; } var allFielDescriptors = _projectionManager.DescribeProperties().ToList(); var fieldDescriptors = layout.Properties.OrderBy(p => p.Position).Select(p => allFielDescriptors.SelectMany(x => x.Descriptors).Select(d => new { Descriptor = d, Property = p }).FirstOrDefault(x => x.Descriptor.Category == p.Category && x.Descriptor.Type == p.Type)).ToList(); var layoutComponents = contentItems.Select( contentItem => { var contentItemMetadata = Services.ContentManager.GetItemMetadata(contentItem); var propertyDescriptors = fieldDescriptors.Select( d => { var fieldContext = new PropertyContext { State = FormParametersHelper.ToDynamic(d.Property.State), Tokens = new Dictionary <string, object> { { "Content", contentItem } } }; return new { d.Property, Shape = d.Descriptor.Property(fieldContext, contentItem) }; }); // apply all settings to the field content, wrapping it in a FieldWrapper shape var properties = Services.New.Properties( Items: propertyDescriptors.Select( pd => Services.New.PropertyWrapper( Item: pd.Shape, Property: pd.Property, ContentItem: contentItem, ContentItemMetadata: contentItemMetadata ) ) ); return new LayoutComponentResult { ContentItem = contentItem, ContentItemMetadata = contentItemMetadata, Properties = properties }; }).ToList(); var tokenizedState = _tokenizer.Replace(layout.State, new Dictionary <string, object> { { "Content", part.ContentItem } }); var renderLayoutContext = new LayoutContext { State = FormParametersHelper.ToDynamic(tokenizedState), LayoutRecord = layout, }; if (layout.GroupProperty != null) { var groupPropertyId = layout.GroupProperty.Id; var display = _displayHelperFactory.CreateHelper(new ViewContext { HttpContext = _workContextAccessor.GetContext().HttpContext }, new ViewDataContainer()); // index by PropertyWrapper shape var groups = layoutComponents.GroupBy( x => { var propertyShape = ((IEnumerable <dynamic>)x.Properties.Items).First(p => ((PropertyRecord)p.Property).Id == groupPropertyId); // clear the wrappers, as they shouldn't be needed to generate the grouping key itself // otherwise the DisplayContext.View is null, and throws an exception if a wrapper is rendered (#18558) ((IShape)propertyShape).Metadata.Wrappers.Clear(); string key = Convert.ToString(display(propertyShape)); return key; }).Select(x => new { Key = x.Key, Components = x }); var list = Services.New.List(); foreach (var group in groups) { var localResult = layoutDescriptor.Render(renderLayoutContext, group.Components); // add the Context to the shape localResult.Context(renderLayoutContext); list.Add(Services.New.LayoutGroup(Key: new MvcHtmlString(group.Key), List: localResult)); } return list; } var layoutResult = layoutDescriptor.Render(renderLayoutContext, layoutComponents); // add the Context to the shape layoutResult.Context(renderLayoutContext); return layoutResult; }))); }
public virtual LayoutResult Layout(LayoutContext layoutContext) { return(new LayoutResult(LayoutResult.NOTHING, null, null, null, this).SetAreaBreak(areaBreak)); }
public void RefineLayout(int iterations) { // Prepare state for algorithm. BidirectionalGraph<string, IEdge<string>> graph = new BidirectionalGraph<string, IEdge<string>>(false); Dictionary<string, Point> positions = new Dictionary<string, Point>(); // Anything to do? if (BayesianNetwork.VariablesOrdered.Any() == false) { this.Positions = new Dictionary<string, Point>(); IterationCount += iterations; return; } Random random = new Random(0); foreach (var rv in BayesianNetwork.VariablesOrdered) { graph.AddVertex(rv.Name); foreach (var child in rv.Children.Select(c => BayesianNetwork.GetVariable(c))) { graph.AddVertex(child.Name); graph.AddEdge(new Edge<string>(rv.Name, child.Name)); } // If we have no existing layout yet, lets try to prime the // alg by putting pure parents at top and pure children at // bottom. if (Positions.Count != 0) { // We have existing layout. Start with it but add slight // randomness. Point positionNoised; if (Positions.ContainsKey(rv.Name)) { positionNoised = Positions[rv.Name]; } else { positionNoised = new Point(); } positionNoised.X += (random.NextDouble() - 0.5) * 0.01; positionNoised.Y += (random.NextDouble() - 0.5) * 0.01; positions[rv.Name] = positionNoised; } } // Initialize algorithm. var layoutAlgorithms = new StandardLayoutAlgorithmFactory<string, IEdge<string>, IBidirectionalGraph<string, IEdge<string>>>(); var layoutContext = new LayoutContext<string, IEdge<string>, IBidirectionalGraph<string, IEdge<string>>>( graph, positions, _sizes, LayoutMode.Simple); ILayoutAlgorithm<string, IEdge<string>, IBidirectionalGraph<string, IEdge<string>>> layoutAlgorithm; var algorithm = this._options.Algorithm; // Hack: SugiyamaEfficient breaks if no edges. if (algorithm == NetworkLayoutOptions.AlgorithmEnum.KK || graph.Edges.Count() == 0) { var layoutParameters = new KKLayoutParameters(); layoutParameters.Height = 1000; layoutParameters.Width = 1000; layoutParameters.MaxIterations = iterations; layoutParameters.LengthFactor = 1.35; layoutParameters.K *= 10.1; layoutParameters.AdjustForGravity = false; layoutAlgorithm = layoutAlgorithms.CreateAlgorithm("KK", layoutContext, layoutParameters); } else if (algorithm == NetworkLayoutOptions.AlgorithmEnum.SugiyamaEfficient) { var layoutParameters = new EfficientSugiyamaLayoutParameters(); layoutParameters.MinimizeEdgeLength = true; layoutParameters.OptimizeWidth = true; layoutParameters.WidthPerHeight = 1.65; layoutParameters.VertexDistance = this._options.NodeSeparationTarget; layoutParameters.LayerDistance = 5.0; layoutAlgorithm = layoutAlgorithms.CreateAlgorithm("EfficientSugiyama", layoutContext, layoutParameters); } else if (algorithm == NetworkLayoutOptions.AlgorithmEnum.Sugiyama) { var layoutParameters = new SugiyamaLayoutParameters(); layoutParameters.MaxWidth = 1024; layoutParameters.VerticalGap = 1.0f; layoutParameters.DirtyRound = true; layoutAlgorithm = layoutAlgorithms.CreateAlgorithm("Sugiyama", layoutContext, layoutParameters); } else if (algorithm == NetworkLayoutOptions.AlgorithmEnum.CompoundFDP) { var layoutParameters = new CompoundFDPLayoutParameters(); layoutParameters.GravitationFactor = 0.8; layoutParameters.IdealEdgeLength = 30; layoutParameters.RepulsionConstant = 300; layoutAlgorithm = layoutAlgorithms.CreateAlgorithm("CompoundFDP", layoutContext, layoutParameters); } else { throw new InvalidOperationException("Unknown layout."); } // Compute. layoutAlgorithm.Compute(); // Store Results. this.Positions = layoutAlgorithm.VertexPositions.ToDictionary( (kvp) => kvp.Key, (kvp) => kvp.Value ); // Done. IterationCount += iterations; }
protected override IPrimitive PerformLayout(LayoutContext layoutContext, Unit model) => this.PerformLayout(layoutContext);