/// <summary> /// Calculates the matrix to transform the content by to fit into the specified viewport dimensions /// </summary> public static SvgMatrix CalculateViewboxFit(this ISvgFitToViewbox fitToViewbox, float viewportWidth, float viewportHeight) { CalculateViewboxFit(fitToViewbox, viewportWidth, viewportHeight, out var scaleX, out var scaleY, out var offsetX, out var offsetY); var translateMatrix = SvgMatrix.CreateTranslate(offsetX, offsetY); var scaleMatrix = SvgMatrix.CreateScale(scaleX, scaleY); return(SvgMatrix.Multiply(translateMatrix, scaleMatrix)); }
private static SvgTransform CreateScaleTransformationFromArgs(string args) { // scale(<sx> [<sy>]), which specifies a scale operation by sx and sy. If <sy> is not provided, it is assumed to be equal to <sx>. var split = SplitStringOfNumbers(args); if (split.Length < 1 || split.Length > 2) { throw new Exception($"Invalid scale transformation arguments '{args}'"); } var x = float.Parse(split[0]); var y = split.Length == 2 ? float.Parse(split[1]) : x; return(new SvgTransform(SvgTransformType.Scale, SvgMatrix.CreateScale(x, y))); }