public PxMatrix CalcMatrix(PxSize viewPort, PxRectangle imageSize) { if (Option == PreserveAspectRatioOption.None) { return(PxMatrix.Translation( viewPort.Width / imageSize.Width, viewPort.Height / imageSize.Height, 0, 0 )); } var scale = Option == PreserveAspectRatioOption.Meet ? Math.Min( viewPort.Height / imageSize.Height, viewPort.Width / imageSize.Width ) : Math.Max( viewPort.Height / imageSize.Height, viewPort.Width / imageSize.Width ); var scaledW = imageSize.Width * scale; var scaledH = imageSize.Height * scale; var scaleX = scaledW / imageSize.Width; var scaleY = scaledH / imageSize.Height; return(PxMatrix.Translation( scaleX, scaleY, imageSize.X + CalcOffset(AlignX, viewPort.Width, scaledW), // / scaleX, imageSize.Y + CalcOffset(AlignY, viewPort.Height, scaledH) // / scaleY )); }
public static Task Render(IElement element, IFrameContext context, RendererDirect2D render) { if (TransformHelper.IsHidden(element)) { return(Task.CompletedTask); } using (TransformHelper.Create(render, element, context)) using (LayerHelper.Create(render, element, context)) { var font = element.GetFont(context); var fill = element.GetFill(context); var fillBrush = render.CreateBrush(element, context, fill.Brush, fill.Opacity); if (fillBrush == null) { return(Task.CompletedTask); } foreach (var text in element.Children.OfType <ITextContent>()) { using (var textLayout = render.CreateTextLayout(font, text.Content, 999999)) { var frameSize = context.Size; var textSize = new PxSize(textLayout.Metrics.WidthIncludingTrailingWhitespace, textLayout.Metrics.Height); var scale = CalcScale(frameSize, textSize); var matrix = PxMatrix.Translation( scale, scale, (frameSize.Width - (scale * textSize.Width)) / 2f, (frameSize.Height - (scale * textSize.Height)) / 2f ); using (TransformHelper.Create(render, matrix)) { render.Target.DrawTextLayout( new DXM.RawVector2(0, 0), textLayout, fillBrush, D2D1.DrawTextOptions.EnableColorFont ); } } } return(Task.CompletedTask); } }