/// <summary> /// Creates a new Text character run and adds it to the current line. /// </summary> /// <param name="size">the size of the run in PDFUnits</param> /// <param name="chars">The characters that should be rendered in the run</param> private void AddProxyToCurrentLine(PDFSize size, PDFTextProxyOp op) { this.AssertCurrentLine(); PDFTextRunProxy run = new PDFTextRunProxy(size, op, this.CurrentLine, this.TextComponent); this.CurrentLine.AddRun(run); }
protected virtual double[] GetCoords(PDFPoint offset, PDFSize size, RadialSize radiusSize, PDFUnit?centreX, PDFUnit?centreY) { double[] all = new double[6]; var height = Math.Abs(size.Height.PointsValue); var width = size.Width.PointsValue; //Get the centre and the radius PDFPoint c = CacluateRadialCentre(centreX, centreY, height, width); double radius = CalculateRadiusForSize(radiusSize, height, width, c.X.PointsValue, c.Y.PointsValue); if (radius <= 0) { radius = 0.01; } //apply the centres based on the page location all[0] = c.X.PointsValue + offset.X.PointsValue; all[1] = offset.Y.PointsValue - c.Y.PointsValue; all[2] = 0.0; all[3] = c.X.PointsValue + offset.X.PointsValue; all[4] = offset.Y.PointsValue - c.Y.PointsValue; all[5] = radius; return(all); }
protected override PDFGraphicsPath CreatePath(PDFSize available, Style fullstyle) { var bounds = this.GetBounds(); var xoffset = bounds.X.PointsValue; var yoffset = bounds.Y.PointsValue; PDFGraphicsPath path = new PDFGraphicsPath(); if (null != this.Points) { for (int i = 0; i < this.Points.Count; i++) { var pt = this.Points[i]; pt = pt.Offset(-xoffset, -yoffset); if (i == 0) { path.MoveTo(pt); } else { path.LineTo(pt); } } } return(path); }
public void CompareTo_Test() { PDFUnit width = new PDFUnit(10, PageUnits.Millimeters); PDFUnit height = new PDFUnit(20, PageUnits.Inches); PDFSize target = new PDFSize(width, height); PDFSize other = new PDFSize(width, height); int expected = 0; int actual; actual = target.CompareTo(other); Assert.AreEqual(expected, actual); height = new PDFUnit(10, PageUnits.Inches); target = new PDFSize(width, height); expected = -1; actual = target.CompareTo(other); Assert.AreEqual(expected, actual); height = new PDFUnit(40, PageUnits.Inches); target = new PDFSize(width, height); expected = 1; actual = target.CompareTo(other); Assert.AreEqual(expected, actual); }
public void op_Inequality_Test() { PDFUnit width = new PDFUnit(10, PageUnits.Millimeters); PDFUnit height = new PDFUnit(20, PageUnits.Inches); PDFSize target = new PDFSize(width, height); PDFSize other = new PDFSize(width, height); bool expected = false; bool actual; actual = (target != other); Assert.AreEqual(expected, actual); height = new PDFUnit(40, PageUnits.Inches); other = new PDFSize(width, height); expected = true; actual = (target != other); Assert.AreEqual(expected, actual); width = new PDFUnit(20, PageUnits.Millimeters); height = new PDFUnit(20, PageUnits.Inches); other = new PDFSize(width, height); expected = true; actual = (target != other); Assert.AreEqual(expected, actual); }
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 methods // #region public PDFLayoutPage BeginNewContinuationPage() /// <summary> /// Begins a new page based on the current page's size and content rect. This will then be the current page /// </summary> /// <returns></returns> public PDFLayoutPage BeginNewContinuationPage() { if (CurrentPageIndex < 0) { throw new ArgumentOutOfRangeException("Cannot begin a new page based on previous page if there are no previous pages"); } PDFLayoutPage pg = this.CurrentPage; PDFTraceLog log = this.DocumentComponent.TraceLog; if (log.ShouldLog(TraceLevel.Verbose)) { log.Add(TraceLevel.Verbose, "LAYOUT", "Beginning a new continuation page for '" + pg + "'"); } if (!pg.IsClosed) { pg.Close(); } PDFSize size = pg.Size; Style style = pg.FullStyle; Page owner = pg.Owner as Page; OverflowAction overflow = pg.OverflowAction; PDFLayoutPage newpg = this.BeginNewPage(owner, this.Engine, style, overflow); return(newpg); }
public PDFTextRunPartialCharacter(PDFSize size, string characters, int offset, int count, PDFLayoutLine line, IPDFComponent owner) : base(line, owner) { this._measuredSize = size; this._chars = characters; this._offset = offset; this._count = count; }
/// <summary> /// Creates a new Text character run and adds it to the current line. /// </summary> /// <param name="size">the size of the run in PDFUnits</param> /// <param name="chars">The characters that should be rendered in the run</param> private void AddCharactersToCurrentLine(PDFSize size, string chars) { this.AssertCurrentLine(); PDFTextRunCharacter run = new PDFTextRunCharacter(size, chars, this.CurrentLine, this.TextComponent); this.CurrentLine.AddRun(run); }
/// <summary> /// Creates a new Text character run and adds it to the current line. /// </summary> /// <param name="size">the size of the run in PDFUnits</param> /// <param name="chars">The characters that should be rendered in the run</param> private void AddCharactersToCurrentLine(PDFSize size, string chars, int startOffset, int count) { this.AssertCurrentLine(); PDFTextRunPartialCharacter run = new PDFTextRunPartialCharacter(size, chars, startOffset, count, this.CurrentLine, this.TextComponent); this.CurrentLine.AddRun(run); }
protected override PDFGraphicsPath CreatePath(PDFSize available, Style fullstyle) { PDFGraphicsPath path = base.CreatePath(available, fullstyle); path.ClosePath(true); return(path); }
/// <summary> /// Based on the available size and full style, returns a bounding rectagle the shape should fit into. /// </summary> /// <param name="avail"></param> /// <param name="fullstyle"></param> /// <returns></returns> protected virtual PDFRect GetPrescribedBounds(PDFSize avail, Style fullstyle) { PDFUnit x = fullstyle.GetValue(StyleKeys.PositionXKey, 0); PDFUnit y = fullstyle.GetValue(StyleKeys.PositionYKey, 0); PDFUnit w = fullstyle.GetValue(StyleKeys.SizeWidthKey, avail.Width); PDFUnit h = fullstyle.GetValue(StyleKeys.SizeHeightKey, avail.Height); return(new PDFRect(x, y, w, h)); }
public static PDFSize GetSizeInDeviceIndependentUnits(PaperSize paperSize) { SizeF mm = Papers.GetSizeInMM(paperSize); PDFSize full = new PDFSize( new PDFUnit(mm.Width, PageUnits.Millimeters), new PDFUnit(mm.Height, PageUnits.Millimeters)); return(full); }
// // 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); }
public void PDFSizeConstructor_Test1() { double width = 10F; // TODO: Initialize to an appropriate value double height = 20F; // TODO: Initialize to an appropriate value PDFSize target = new PDFSize(width, height); Assert.AreEqual(width, target.Width.PointsValue); Assert.AreEqual(height, target.Height.PointsValue); }
public void PDFSizeConstructor_Test() { PDFUnit width = new PDFUnit(10, PageUnits.Millimeters); PDFUnit height = new PDFUnit(20, PageUnits.Inches); PDFSize target = new PDFSize(width, height); Assert.AreEqual(width, target.Width); Assert.AreEqual(height, target.Height); }
protected override PDFGraphicsPath CreatePath(PDFSize available, Style fullstyle) { var bounds = this.GetBounds(); var path = new PDFGraphicsPath(); Ellipse.BuildElipse(path, bounds, true, 0); return(path); }
protected override PDFGraphicsPath CreatePath(PDFSize available, Style fullstyle) { PDFRect rect = this.GetBounds(); PDFGraphicsPath path = new PDFGraphicsPath(); Ellipse.BuildElipse(path, rect, true, 0); return(path); }
public void PDFRectConstructor_Test() { PDFPoint location = new PDFPoint(10, 20); PDFSize size = new PDFSize(30, 40); PDFRect target = new PDFRect(location, size); Assert.AreEqual(target.Location, location); Assert.AreEqual(target.Size, size); }
/// <summary> /// Measures all the characters on a specified string returning their size /// 6based on how many fitted in the available space. /// </summary> /// <param name="chars"></param> /// <param name="offset"></param> /// <param name="fitted"></param> /// <param name="availh">The available height in the current region</param> /// <returns></returns> private PDFSize MeasureString(PDFUnit availh, PDFUnit availw, string chars, int offset, out int fitted) { PDFSize available = new PDFSize(availw, availh); PDFTextRenderOptions opts = this.TextRenderOptions; PDFSize measured; measured = this.Context.Graphics.MeasureString(chars, offset, available, opts, out fitted); return(measured); }
protected virtual PDFGraphics CreateGraphics(PDFWriter writer, Styles.StyleStack styles, PDFRenderContext context) { var sz = new PDFSize(this._childContainer.Width, this._childContainer.Height); if (this._position.ViewPort.HasValue) { sz = this._position.ViewPort.Value.Size; } return(PDFGraphics.Create(writer, false, this, DrawingOrigin.TopLeft, sz, context)); }
public void ToPoints_Test() { PDFUnit width = new PDFUnit(10, PageUnits.Millimeters); PDFUnit height = new PDFUnit(20, PageUnits.Millimeters); PDFSize target = new PDFSize(width, height); PDFSize expected = new PDFSize(width.PointsValue, height.PointsValue); PDFSize actual; actual = target.ToPoints(); Assert.AreEqual(expected, actual); }
// // scaling calculations // public static void ApplyMaxNonUniformScaling(PDFTransformationMatrix onmatrix, PDFSize dest, PDFRect viewport) { PDFSize source = viewport.Size; double scalex = dest.Width.PointsValue / source.Width.PointsValue; double scaley = dest.Height.PointsValue / source.Height.PointsValue; double offx = 0; // viewport.X.PointsValue; double offy = 0; // viewport.Y.PointsValue; onmatrix.SetTranslation(offx, offy); onmatrix.SetScale((float)scalex, (float)scaley); }
public void ToDrawing_Test() { PDFUnit width = new PDFUnit(10, PageUnits.Millimeters); PDFUnit height = new PDFUnit(20, PageUnits.Millimeters); PDFSize target = new PDFSize(width, height); SizeF expected = new SizeF((float)width.PointsValue, (float)height.PointsValue); SizeF actual; actual = target.ToDrawing(); Assert.AreEqual(expected, actual); }
protected virtual double[] GetCoords(PDFPoint offset, PDFSize size, double angle) { double[] all = new double[4]; all[0] = offset.X.PointsValue; all[1] = offset.Y.PointsValue; all[2] = offset.X.PointsValue; all[3] = offset.Y.PointsValue; //TODO: Change this to support any angle with sin, cos and tan if (angle < 45) // Top { all[1] += size.Height.PointsValue; } else if (angle < 90) //Top Right { all[2] += size.Width.PointsValue; all[1] += size.Height.PointsValue; } else if (angle < 135) //Right { all[2] += size.Width.PointsValue; } else if (angle < 180) //Bottom Right { all[2] += size.Width.PointsValue; all[3] += size.Height.PointsValue; } else if (angle < 225) //Bottom { all[3] += size.Height.PointsValue; } else if (angle < 270) //Bottom Left { all[0] += size.Width.PointsValue; all[3] += size.Height.PointsValue; } else if (angle < 315) //Left { all[0] += size.Width.PointsValue; } else if (angle < 360) //Top Left { all[0] += size.Width.PointsValue; all[1] += size.Height.PointsValue; } else { all[3] += size.Height.PointsValue; } return(all); }
internal PDFRenderContext(DrawingOrigin origin, int pageCount, PDFOutputFormatting format, Styles.StyleStack stack, PDFItemCollection items, PDFTraceLog log, PDFPerformanceMonitor perfmon, IPDFDocument document) : base(stack, items, log, perfmon, document) { this._origin = origin; this._offset = new PDFPoint(); this._space = new PDFSize(); this._pgCount = pageCount; this._pgindex = 0; this._format = format; }
public void Empty_Test() { PDFUnit width = PDFUnit.Zero; PDFUnit height = PDFUnit.Zero; PDFSize empty = new PDFSize(width, height); PDFSize actual; actual = PDFSize.Empty; Assert.AreEqual(empty, actual); }
public void ToString_Test() { PDFUnit width = new PDFUnit(10, PageUnits.Millimeters); PDFUnit height = new PDFUnit(20, PageUnits.Millimeters); PDFSize target = new PDFSize(width, height); string expected = "[10mm, 20mm]"; string actual; actual = target.ToString(); Assert.AreEqual(expected, actual); }
public void Clone_Test1() { PDFUnit width = new PDFUnit(10, PageUnits.Millimeters); PDFUnit height = new PDFUnit(20, PageUnits.Millimeters); ICloneable target = new PDFSize(width, height); object expected = target; object actual; actual = target.Clone(); Assert.AreEqual(expected, actual); }
/// <summary> /// Increases the size of this region by the size of the layout item /// </summary> /// <param name="item"></param> public void AddToSize(PDFLayoutItem item) { PDFUnit h = item.Height; PDFUnit w = item.Width; //Update the size PDFSize sz = this.UsedSize; sz.Height += h; sz.Width = PDFUnit.Max(sz.Width, w); this.UsedSize = sz; }