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 RectangleDetail(JObject border, CustomJPrototypeResolver resolver)
 {
     Color  = resolver.GetColorOrDefault(border, "Color", Color.Black);
     X      = resolver.GetInt(border, "X");
     Y      = resolver.GetInt(border, "Y");
     Width  = resolver.GetInt(border, "Width");
     Height = resolver.GetInt(border, "Height");
 }
 public Glyph(string symbol, string templateDir, Graphics graphics, CustomJPrototypeResolver resolver, Color opacity, FontTool font)
 {
     _image    = Path.GetFullPath(Path.Combine(templateDir, resolver.GetRootValue(symbol)));
     _graphics = graphics;
     _opacity  = (decimal)opacity.A / 255;
     Width     = font.GlyphHeight;
     Height    = font.GlyphHeight;
 }
Exemplo n.º 4
0
 public BorderDetail(JObject border, CustomJPrototypeResolver resolver)
 {
     Color     = resolver.GetColorOrDefault(border, "Color", Color.Black);
     X         = resolver.GetInt(border, "X");
     Y         = resolver.GetInt(border, "Y");
     Width     = resolver.GetInt(border, "Width");
     Height    = resolver.GetInt(border, "Height");
     Thickness = resolver.GetInt(border, "Thickness");
     Alignment = resolver.GetEnum <BorderAlignment>(border, "Alignment");
 }
 public ImageDetail(string templateDir, JObject image, CustomJPrototypeResolver resolver)
 {
     _templateDir = templateDir;
     Source       = resolver.GetString(image, "Source");
     Opacity      = resolver.GetDecimalOrDefault(image, "Opacity", 1);
     X            = resolver.GetInt(image, "X");
     Y            = resolver.GetInt(image, "Y");
     Width        = resolver.GetInt(image, "Width");
     Height       = resolver.GetInt(image, "Height");
 }
 public TextStyling(Graphics graphics, TextStyling previousStyle, CustomJPrototypeResolver resolver, JObject prototype)
     : this(graphics,
            resolver.GetStringOrDefault(prototype, "Font", previousStyle.FontName),
            resolver.GetIntOrDefault(prototype, "FontSize", previousStyle.FontSize),
            resolver.GetFlagsEnumOrDefault(prototype, "FontStyle", previousStyle.FontStyle),
            resolver.GetColorOrDefault(prototype, "Color", previousStyle.Color),
            resolver.GetColorOrDefault(prototype, "BackgroundColor", previousStyle.BackgroundColor),
            resolver.GetColorOrDefault(prototype, "BackgroundBorderColor", previousStyle.BackgroundBorderColor),
            resolver.GetIntOrDefault(prototype, "BackgroundBorderThickness", previousStyle.BackgroundBorderThickness),
            resolver.GetColorOrDefault(prototype, "OutlineColor", previousStyle.OutlineColor),
            resolver.GetIntOrDefault(prototype, "OutlineThickness", previousStyle.OutlineThickness))
 {
 }
Exemplo n.º 7
0
        private string GetSavePath(CustomJPrototypeResolver resolver, JObject instructions, JObject blueprint, string instructionsDir, string savePath, string saveName, int item, HashSet <string> savedPaths)
        {
            var extension = resolver.GetStringOrDefault(blueprint, "SavePathExtension", "");
            var path      = saveName.Contains("~")
                ? PathX.Build(instructionsDir, savePath + extension, $"{resolver.GetString(instructions, "SaveName")}.png")
                : PathX.Build(instructionsDir, savePath + extension, $"{saveName}{item}.png");

            if (savedPaths.Contains(path))
            {
                Console.WriteLine($"Duplicate Save Path Detected: {path}");
                throw new ArgumentException();
            }
            savedPaths.Add(path);
            return(path);
        }
Exemplo n.º 8
0
        private void SaveTrimmedImage(CustomJPrototypeResolver resolver, JObject instructions, JObject blueprint, Bitmap bitmap, string instructionsDir, string savePath, string saveName, int item, Canvas canvas, HashSet <string> savedPaths)
        {
            var trim = resolver.GetIntOrDefault(blueprint, "PostTrim", 0);
            var path = GetSavePath(resolver, instructions, blueprint, instructionsDir, savePath, saveName, item, savedPaths);

            if (trim == 0)
            {
                bitmap.Save(path, ImageFormat.Png);
            }
            else
            {
                var trimmedBitmap = new Bitmap(canvas.Width - trim * 2, canvas.Height - trim * 2);
                WithGraphics(trimmedBitmap, g =>
                {
                    g.DrawImage(bitmap,
                                new Rectangle(0, 0, trimmedBitmap.Width, trimmedBitmap.Height),
                                new Rectangle(trim, trim, trimmedBitmap.Width, trimmedBitmap.Height), GraphicsUnit.Pixel);
                    trimmedBitmap.Save(path, ImageFormat.Png);
                });
            }
        }
Exemplo n.º 9
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;
                }
            }
        }
 public GlyphedCharacterSequence CreateInStyle(string content, string symbol, string templateDir, Graphics graphics, CustomJPrototypeResolver resolver, VerticalAlignment wordAlignment) =>
 new GlyphedCharacterSequence(CreateInStyle(content), CreateInStyle(symbol, templateDir, graphics, resolver), wordAlignment);
 public Glyph CreateInStyle(string symbol, string templateDir, Graphics graphics, CustomJPrototypeResolver resolver) =>
 new Glyph(symbol, templateDir, graphics, resolver, Color, FontTool);
Exemplo n.º 12
0
 public Canvas(JObject canvas, CustomJPrototypeResolver resolver)
 {
     Height     = resolver.GetInt(canvas, "Height");
     Width      = resolver.GetInt(canvas, "Width");
     Background = resolver.GetColorOrDefault(canvas, "Background", Color.White);
 }