Beispiel #1
0
        static void Main(string[] cmdArgs)
        {
            // Draw Figure A
            var args = new DivergenceArgs {
                Scale      = DivergenceScale.Medium,
                Spacing    = new DivergenceSpacing(8, 8),
                Background = Color.FromArgb(224, 224, 224),
            };
            string text = "Oslo II";

            using (Bitmap bmp = Divergence.Draw(text, args))
                bmp.Save("OsloII.png");

            // Draw Figure B
            args.Scale   = DivergenceScale.Small;
            args.Spacing = new DivergenceSpacing(5, 5);
            DateTime date = DateTime.Now;

            text = $"{date:MM\\/dd\\/yy}\n{date.TimeOfDay:hh\\:mm\\:ss}";
            using (Bitmap bmp = Divergence.Draw(text, args))
                bmp.Save("DateTime.png");

            // Draw Figure C
            args = new DivergenceArgs {
                Scale      = DivergenceScale.Small,
                Background = "EV_Z02A.PNG",                 // The CG background
            };
            text = "1.130426";
            Divergence.CalculateSpacingFor(1920 / 2, 1080 / 2, text, ref args, left: 5, top: 2);
            using (Bitmap bmp = Divergence.Draw(text, args))
                bmp.Save("Original Worldline.png");

            // Draw Figure D
            args = new DivergenceArgs {
                Scale      = DivergenceScale.Small,
                Background = Color.Black,
                Escape     = DivergenceEscape.NewLines,
            };
            text = @"#1\n#2";
            using (Bitmap bmp = Divergence.Draw(text, args))
                bmp.Save("Command Line Example.png");
        }
Beispiel #2
0
 static void Save(string text, DivergenceArgs args, string path)
 {
     Divergence.Draw(text, args).SaveAndDispose(path);
 }
Beispiel #3
0
 static void Test(string text, DivergenceArgs args)
 {
     Divergence.Draw(text, args).OpenInMSPaint();
 }
        static void Main(string[] args)
        {
            Console.Title           = "Divergence Meter Input";
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("======== Divergence Input ========");
            Console.ResetColor();
            Console.Write("Enter ");
            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.Write("back");
            Console.ResetColor();
            Console.Write(" during any input to go to the previous input. Enter ");
            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.Write("exit");
            Console.ResetColor();
            Console.WriteLine(" to exit. (case-sensitive)");

            string input = null;

            Divergence.EnableLimits = false;
            char[]         invalidNameChars = Path.GetInvalidFileNameChars();
            int            inputIndex       = 0;
            DivergenceArgs dargs            = new DivergenceArgs {
                Alignment    = System.Drawing.StringAlignment.Near,
                Authenticity = DivergenceAuthenticity.Lax,
                Background   = DivergenceBackground.None,
                Escape       = DivergenceEscape.NewLines,
                Scale        = DivergenceScale.Small,
                AlignTubes   = false,
                UsePadding   = false,
            };
            string text = null;
            string file = null;

            WriteHeader();
            while (true)
            {
                try {
                    switch (inputIndex)
                    {
                    case 0:
                        do
                        {
                            input = GetInput("Size (s/m/l)", ConsoleColor.Cyan, "l");
                        } while (input != "s" && input != "m" && input != "l");
                        if (input == "s")
                        {
                            dargs.Scale = DivergenceScale.Small;
                        }
                        if (input == "m")
                        {
                            dargs.Scale = DivergenceScale.Medium;
                        }
                        if (input == "l")
                        {
                            dargs.Scale = DivergenceScale.Large;
                        }
                        break;

                    case 1:
                        do
                        {
                            text = GetInput("  Meter Text", ConsoleColor.Yellow);
                        } while (text.Length == 0);
                        break;

                    case 2:
                        do
                        {
                            file = GetInput("Save to File", ConsoleColor.White, GetNextFile());
                            if (file.Any(c => Array.IndexOf(invalidNameChars, c) != -1))
                            {
                                WriteError("  Invalid path characters!");
                                file = null;
                            }
                        } while (file == null);

                        using (var bitmap = Divergence.Draw(text, dargs))
                            bitmap.Save(file, ImageFormat.Png);
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine($"  Saved text \"{text}\" to file \"{file}\"!");
                        Console.ResetColor();

                        do
                        {
                            input = GetInput(" Open? (y/n)", ConsoleColor.White, "n");
                        } while (input != "y" && input != "yes" && input != "n" && input != "no");
                        if (input == "yes" || input == "y")
                        {
                            ProcessStartInfo startInfo = new ProcessStartInfo {
                                FileName        = file,
                                Verb            = "open",
                                UseShellExecute = true,
                            };
                            Process.Start(startInfo)?.Dispose();
                        }

                        WriteHeader();

                        break;
                    }
                    inputIndex = (inputIndex + 1) % 3;
                } catch (BackException) {
                    inputIndex = Math.Max(0, inputIndex - 1);
                } catch (ExitException) {
                    return;
                } catch (Exception ex) {
                    WriteError("  An error occurred!");
                    WriteError(ex);
                    File.WriteAllText("error.txt", ex.ToString());

                    WriteHeader();
                }
            }
        }