/// <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 CreateTranslateTransformationFromArgs(string args) { // translate(<tx> [<ty>]), which specifies a translation by tx and ty. If <ty> is not provided, it is assumed to be zero. var split = SplitStringOfNumbers(args); if (split.Length < 1 || split.Length > 2) { throw new Exception($"Invalid translate transformation arguments '{args}'"); } var tx = float.Parse(split[0], CultureInfo.InvariantCulture); var ty = split.Length == 2 ? float.Parse(split[1], CultureInfo.InvariantCulture) : tx; return(new SvgTransform(SvgTransformType.Translate, SvgMatrix.CreateTranslate(tx, ty))); }