/// <summary> /// Creates the helper method source code /// </summary> private void CreateSecondaryCreationMethod(StringBuilder code, NormalizeGeometrySourceAspect normalizeAspect, string methodName, string mainMethodName, string parameterName, string offsetMethodParameterString, string offsetParameterString) { var indent1 = Indent1; var indent2 = Indent2; code.AppendLine($"{indent1}/// <summary>"); code.AppendLine($"{indent1}/// Create the geometry from the given {parameterName} and keep the original aspect ratio"); code.AppendLine($"{indent1}/// </summary>"); code.AppendLine(string.Format("{0}/// <param name=\"{1}\">the {1} in WPF units</param>", indent1, parameterName)); code.AppendLine(" /// <returns>Returns the geometry</returns>"); code.AppendLine($"{indent1}public static Geometry {methodName}({offsetMethodParameterString}double {parameterName})"); code.AppendLine($"{indent1}{{"); if (normalizeAspect == NormalizeGeometrySourceAspect.Height) { code.AppendLine($"{indent2}return {mainMethodName}({offsetParameterString}height / AspectRatio, height);"); } else { code.AppendLine($"{indent2}return {mainMethodName}({offsetParameterString}width, width * AspectRatio);"); } code.AppendLine($"{indent1}}}"); code.AppendLine(""); }
/// <summary> /// Generates geometry source code /// </summary> public string GenerateSource(GraphicVisual visual, NormalizeGeometrySourceAspect normalizeGeometrySourceAspect, bool includeOffset, string filename) { this.normalizeAspect = normalizeGeometrySourceAspect; this.includeOffset = includeOffset; this.filename = filename; Code = new StringBuilder(); var normalizer = new NormalizeVisual(); NormalizeAspect normalizeType; switch (normalizeAspect) { case NormalizeGeometrySourceAspect.Width: normalizeType = NormalizeAspect.Width; scaleWidthVariableName = "scale"; scaleHeightVariableName = "scale"; break; case NormalizeGeometrySourceAspect.Height: normalizeType = NormalizeAspect.Height; scaleWidthVariableName = "scale"; scaleHeightVariableName = "scale"; break; default: normalizeType = NormalizeAspect.Individual; scaleWidthVariableName = "width"; scaleHeightVariableName = "height"; break; } var normalizedVisual = normalizer.Normalize(visual, normalizeType, 1.0); aspectRatio = normalizer.AspectRatio; InitCode(visual); Init(visual); GenerateSourceRecursive(normalizedVisual); Terminate(); FinalizeCode(); return Code.ToString(); }
/// <summary> /// Generates geometry C# source code /// </summary> public static string GenerateSource(GraphicVisual visual, GeometryGeneratorType geometryGeneratorType, NormalizeGeometrySourceAspect normalizeGeometrySourceAspect, bool includeOffset, string filename) { GeometryCSharpSourceGeneratorBase geometrySourceGenerator; if (geometryGeneratorType == GeometryGeneratorType.Stream) { geometrySourceGenerator = new StreamGeometryCSharpSourceGenerator(); } else { geometrySourceGenerator = new PathGeometryCSharpSourceGenerator(); } return(geometrySourceGenerator.GenerateSource(visual, normalizeGeometrySourceAspect, includeOffset, filename)); }