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; }
public void PDFTransformationMatrixConstructor_Test1() { float offsetX = 0F; // TODO: Initialize to an appropriate value float offsetY = 0F; // TODO: Initialize to an appropriate value float angle = 0F; // TODO: Initialize to an appropriate value float scaleX = 0F; // TODO: Initialize to an appropriate value float scaleY = 0F; // TODO: Initialize to an appropriate value PDFTransformationMatrix target = new PDFTransformationMatrix(offsetX, offsetY, angle, scaleX, scaleY); //Assert.Inconclusive("TODO: Implement code to verify target"); }
/// <summary> /// Gets the matrix described by this transformation style /// </summary> /// <returns></returns> public PDFTransformationMatrix GetMatrix() { PDFTransformationMatrix current = new PDFTransformationMatrix(); //current.SetTranslation(this.OffsetH, this.OffsetV); current.SetRotation(this.Rotate); current.SetScale(this.ScaleX, this.ScaleY); current.SetSkew(this.SkewX, this.SkewY); return(current); }
// // 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); }
/// <summary> /// This will render the transformation matrix and then the XObject name operation. /// </summary> /// <param name="context"></param> /// <param name="writer"></param> /// <returns></returns> protected virtual bool OutputDrawingContent(PDFRenderContext context, PDFWriter writer) { if (null != this.OutPutName) { context.Graphics.SaveGraphicsState(); var x = context.Offset.X.RealValue; x = context.Graphics.GetXPosition(x); var y = (context.Offset.Y + this.Height).RealValue; y = context.Graphics.GetYPosition(y); if (this.ClipRect.HasValue) { //var rect = this.ClipRect.Value.Offset(context.Offset.X, context.Offset.Y); //context.Graphics.SetClipRect(rect); } var matrix = new PDFTransformationMatrix(); matrix.SetTranslation((float)x, (float)y); //Set the transformation matrix for the current offset context.Graphics.SetTransformationMatrix(matrix, true, true); if (!this.Matrix.IsIdentity) { context.Graphics.SetTransformationMatrix(this.Matrix, true, true); } context.Graphics.PaintXObject(this.OutPutName); context.Graphics.RestoreGraphicsState(); return(true); } else { return(false); } }
private PDFTransformationMatrix CalculateMatrix(PDFSize available, PDFRect view, SVGAspectRatio ratio) { PDFTransformationMatrix matrix = PDFTransformationMatrix.Identity(); if (ratio.Align == AspectRatioAlign.None) { SVGAspectRatio.ApplyMaxNonUniformScaling(matrix, available, view); } else if (ratio.Meet == AspectRatioMeet.Meet) { SVGAspectRatio.ApplyUniformScaling(matrix, available, view, ratio.Align); } else if (ratio.Meet == AspectRatioMeet.Slice) { SVGAspectRatio.ApplyUniformStretching(matrix, available, view, ratio.Align); } else { throw new ArgumentOutOfRangeException(nameof(ratio)); } return(matrix); }
public void PDFTransformationMatrixConstructor_Test() { PDFTransformationMatrix target = new PDFTransformationMatrix(); //Assert.Inconclusive("TODO: Implement code to verify target"); }
public static void ApplyUniformStretching(PDFTransformationMatrix onmatrix, PDFSize dest, PDFRect viewport, AspectRatioAlign align) { 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; float max = (float)Math.Max(scalex, scaley); double w = source.Width.PointsValue * max; double h = source.Height.PointsValue * max; switch (align) { //YMin case (AspectRatioAlign.xMinYMin): //Scale to fit within the size without overflow and show at the top (so no x or y offset) offx = 0; offy = (dest.Height.PointsValue - h); //plus as from the bottom onmatrix.SetTranslation(offx, offy); onmatrix.SetScale(max, max); break; case (AspectRatioAlign.xMidYMin): offx = (dest.Width.PointsValue - w) / 2; offy = (dest.Height.PointsValue - h); //plus as from the bottom onmatrix.SetTranslation(offx, offy); onmatrix.SetScale(max, max); break; case (AspectRatioAlign.xMaxYMin): //Scale to fit within the size without overflow and show at the top (so no x or y offset) offx = dest.Width.PointsValue - w; offy = (dest.Height.PointsValue - h); //plus as from the bottom onmatrix.SetTranslation(offx, offy); onmatrix.SetScale(max, max); break; //YMid case (AspectRatioAlign.xMinYMid): //Scale to fit within the size without overflow and show at the top (so no x or y offset) offx = 0; offy = (dest.Height.PointsValue - h) / 2; //plus as from the bottom onmatrix.SetTranslation(offx, offy); onmatrix.SetScale(max, max); break; case (AspectRatioAlign.xMidYMid): //Scale to fit within the size without overflow and then position in the middle offx = (dest.Width.PointsValue - w) / 2; offy = (dest.Height.PointsValue - h) / 2; //plus as from the bottom onmatrix.SetTranslation(offx, offy); onmatrix.SetScale(max, max); break; case (AspectRatioAlign.xMaxYMid): //Scale to fit within the size without overflow and show at the top (so no x or y offset) offx = dest.Width.PointsValue - w; offy = (dest.Height.PointsValue - h) / 2; //plus as from the bottom onmatrix.SetTranslation(offx, offy); onmatrix.SetScale(max, max); break; //YMax case (AspectRatioAlign.xMinYMax): //Scale to fit within the size without overflow and show at the top (so no x or y offset) offx = 0; offy = 0; //plus as from the bottom onmatrix.SetTranslation(offx, offy); onmatrix.SetScale(max, max); break; case (AspectRatioAlign.xMidYMax): //Scale to fit within the size without overflow and then position in the middle offx = (dest.Width.PointsValue - w) / 2; offy = 0; //plus as from the bottom onmatrix.SetTranslation(offx, offy); onmatrix.SetScale(max, max); break; case (AspectRatioAlign.xMaxYMax): //Scale to fit within the size without overflow and show at the top (so no x or y offset) offx = dest.Width.PointsValue - w; offy = 0; //plus as from the bottom onmatrix.SetTranslation(offx, offy); onmatrix.SetScale(max, max); break; default: break; } }
private void WriteXObjectDictionaryContent(PDFRenderContext context, PDFWriter writer, long len, IStreamFilter[] filters) { writer.WriteDictionaryNameEntry("Type", "XObject"); if (!string.IsNullOrEmpty(this.SubType)) { writer.WriteDictionaryNameEntry("Subtype", "Form"); } writer.BeginDictionaryEntry("Matrix"); writer.WriteArrayRealEntries(PDFTransformationMatrix.Identity().Components); // this.Matrix.Components); writer.EndDictionaryEntry(); writer.BeginDictionaryEntry("BBox"); writer.BeginArrayS(); if (this._position.ViewPort.HasValue) { PDFRect vp = this._position.ViewPort.Value; writer.WriteReal(vp.X.PointsValue); writer.WriteRealS(vp.Y.PointsValue); writer.WriteRealS(vp.Width.PointsValue); writer.WriteRealS(vp.Height.PointsValue); } else { writer.WriteReal(0.0F); writer.WriteRealS(0.0F); writer.WriteRealS(this._childContainer.Height.PointsValue); writer.WriteRealS(this._childContainer.Height.PointsValue); } writer.EndArray(); writer.EndDictionaryEntry(); PDFObjectRef res = this._resources.WriteResourceList(context, writer); if (null != res) { writer.WriteDictionaryObjectRefEntry("Resources", res); } if (null != filters && filters.Length > 0) { writer.BeginDictionaryEntry("Length"); writer.WriteNumberS(len); writer.EndDictionaryEntry(); writer.BeginDictionaryEntry("Filter"); writer.BeginArray(); foreach (IStreamFilter filter in filters) { writer.BeginArrayEntry(); writer.WriteName(filter.FilterName); writer.EndArrayEntry(); } writer.EndArray(); writer.EndDictionaryEntry(); } else { writer.BeginDictionaryEntry("Length"); writer.WriteNumberS(len); writer.EndDictionaryEntry(); } }