public TextDetail(string templateDir, JObject text, CustomJPrototypeResolver resolver)
 {
     _templateDir              = templateDir;
     _resolver                 = resolver;
     Content                   = resolver.GetString(text, "Content");
     Font                      = resolver.GetString(text, "Font");
     FontSize                  = resolver.GetIntOrDefault(text, "FontSize", 0);
     FontStyle                 = resolver.GetFlagsEnumOrDefault(text, "FontStyle", FontStyle.Regular);
     Color                     = resolver.GetColorOrDefault(text, "Color", Color.Black);
     BackgroundColor           = resolver.GetColorOrDefault(text, "BackgroundColor", Color.Transparent);
     BackgroundBorderColor     = resolver.GetColorOrDefault(text, "BackgroundBorderColor", Color.Transparent);
     BackgroundBorderThickness = resolver.GetIntOrDefault(text, "BackgroundBorderThickness", 0);
     OutlineColor              = resolver.GetColorOrDefault(text, "OutlineColor", Color.Transparent);
     OutlineThickness          = resolver.GetIntOrDefault(text, "OutlineThickness", 0);
     X      = resolver.GetInt(text, "X");
     Y      = resolver.GetInt(text, "Y");
     Width  = resolver.GetInt(text, "Width");
     Height = resolver.GetInt(text, "Height");
     HorizontalAlignment          = resolver.GetEnumOrDefault(text, "HorizontalAlignment", HorizontalAlignment.Center);
     LineAlignment                = resolver.GetEnumOrDefault(text, "LineAlignment", HorizontalAlignment.Center);
     VerticalAlignment            = resolver.GetEnumOrDefault(text, "VerticalAlignment", VerticalAlignment.Center);
     WordAlignment                = resolver.GetEnumOrDefault(text, "WordAlignment", VerticalAlignment.Bottom);
     FlawedRotation               = resolver.GetIntOrDefault(text, "FlawedRotation", 0);
     FlawedDynamicFontSizeEnabled = resolver.GetBoolOrDefault(text, "FlawedDynamicSizeEnabled", false);
 }
Exemplo n.º 2
0
        public void Run(string instructionsPath)
        {
            Console.WriteLine("");
            var instructionsDir = Path.GetDirectoryName(instructionsPath);
            var instructions    = JObjectX.FromFile(instructionsPath);
            var savePath        = instructions.GetPropertyValue("SavePath");
            var saveName        = instructions.GetPropertyValue("SaveName");
            var items           = GetItems(instructions, instructionsDir);
            var constants       = GetConstants(instructions, instructionsDir);
            var prototypes      = GetPrototypes(instructions, instructionsDir);
            var savePaths       = new HashSet <string>();

            var applyType = new Dictionary <string, Action <JObject, CustomJPrototypeResolver, Graphics> >
            {
                { "Border", (obj, interpreter, graphics) => new BorderDetail(obj, interpreter).Apply(graphics) },
                { "Text", (obj, interpreter, graphics) => new TextDetail(instructionsDir, obj, interpreter).Apply(graphics) },
                { "Image", (obj, interpreter, graphics) => new ImageDetail(instructionsDir, obj, interpreter).Apply(graphics) },
                { "Rectangle", (obj, interpreter, graphics) => new RectangleDetail(obj, interpreter).Apply(graphics) },
                { "Circle", (obj, interpreter, graphics) => new CircleDetail(obj, interpreter).Apply(graphics) },
                { "CircleBorder", (obj, interpreter, graphics) => new CircleBorderDetail(obj, interpreter).Apply(graphics) },
            };

            for (var i = 0; i < items.Count; i++)
            {
                try
                {
                    var resolver =
                        new CustomJPrototypeResolver(prototypes, new CustomJInterpreter(items[i], constants));
                    var blueprint = (JObject)instructions["Blueprint"];
                    var canvas    = new Canvas(blueprint, resolver);
                    var elements  = ((JArray)blueprint["Elements"]).Children <JObject>()
                                    .Where(x => resolver.GetBoolOrDefault(x, "Enabled", true)).ToList();
                    var bitmap = new Bitmap(canvas.Width, canvas.Height);
                    WithGraphics(bitmap, graphics =>
                    {
                        using (var brush = new SolidBrush(canvas.Background))
                            graphics.FillRectangle(brush, 0, 0, canvas.Width, canvas.Height);
                        elements.ForEach(x =>
                        {
                            try
                            {
                                applyType[resolver.GetString(x, "Type")](x, resolver, graphics);
                            }
                            catch
                            {
                                Console.WriteLine($"Error Adding Element: {x.ToString(Formatting.None)}");
                                throw;
                            }
                        });
                        graphics.Flush();
                        SaveTrimmedImage(resolver, instructions, blueprint, bitmap, instructionsDir, savePath, saveName, i, canvas, savePaths);
                    });
                }
                catch
                {
                    Console.WriteLine($"Error On Item {i}: {items[i].ToString(Formatting.None)}");
                    Console.Read();
                    throw;
                }
            }
        }