예제 #1
0
        private async Task CacheImages(T2d.Project project)
        {
            var images = T2d.Editor.GetAllShapes <T2d.XImage>(project);

            if (images != null)
            {
                foreach (var image in images)
                {
                    await CacheImage(image.Path);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="project"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private Container CreateGridTemplate(Project project, string name)
        {
            var container = GetTemplate(project, name);

            CreateGrid(project, container);

            return container;
        }
예제 #3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="project"></param>
 /// <param name="container"></param>
 private void CreateGrid(Project project, Container container)
 {
     var style = project
         .StyleLibraries.FirstOrDefault(g => g.Name == "Template")
         .Styles.FirstOrDefault(s => s.Name == "Grid");
     var layer = container.Layers.FirstOrDefault();
     var builder = layer.Shapes.ToBuilder();
     var grid = XRectangle.Create(
         0, 0,
         container.Width, container.Height,
         style,
         project.Options.PointShape);
     grid.IsStroked = false;
     grid.IsFilled = false;
     grid.IsGrid = true;
     grid.OffsetX = 30.0;
     grid.OffsetY = 30.0;
     grid.CellWidth = 30.0;
     grid.CellHeight = 30.0;
     grid.State &= ~ShapeState.Printable;
     builder.Add(grid);
     layer.Shapes = builder.ToImmutable();
 }
예제 #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="project"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public Container GetTemplate(Project project, string name)
        {
            var container = Container.Create(name);

            container.IsTemplate = true;
            container.Background = ArgbColor.Create(0xFF, 0xFF, 0xFF, 0xFF);

            foreach (var layer in container.Layers)
            {
                layer.Name = string.Concat("Template", layer.Name);
            }

            return container;
        }
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="project"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 public Document GetDocument(Project project, string name)
 {
     var document = Document.Create(name);
     return document;
 }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="project"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public Container GetContainer(Project project, string name)
        {
            var container = Container.Create(name);

            if (project.CurrentTemplate == null)
            {
                var template = GetTemplate(project, "Empty");
                var templateBuilder = project.Templates.ToBuilder();
                templateBuilder.Add(template);
                project.Templates = templateBuilder.ToImmutable();
                project.CurrentTemplate = template;
            }

            container.Template = project.CurrentTemplate;
            container.Width = container.Template.Width;
            container.Height = container.Template.Height;
            return container;
        }
예제 #7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="project"></param>
        public void Remove(Project project)
        {
            if (project == null)
                return;

            project.PropertyChanged -= ProjectObserver;

            Verbose("Remove Project: " + project.Name);

            Remove(project.Options);

            if (project.Databases != null)
            {
                foreach (var database in project.Databases)
                {
                    Remove(database);
                }
            }

            if (project.Documents != null)
            {
                foreach (var document in project.Documents)
                {
                    Remove(document);
                }
            }

            if (project.Templates != null)
            {
                foreach (var template in project.Templates)
                {
                    Remove(template);
                }
            }

            if (project.StyleLibraries != null)
            {
                foreach (var sg in project.StyleLibraries)
                {
                    Remove(sg);
                }
            }
        }
예제 #8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="project"></param>
        /// <param name="serializer"></param>
        public static void Save(Stream stream, Project project, ISerializer serializer)
        {
            using (var archive = new ZipArchive(stream, ZipArchiveMode.Create))
            {
                // First step is to write project entry.
                var jsonEntry = archive.CreateEntry(ProjectEntryName);
                using (var jsonStream = jsonEntry.Open())
                {
                    var json = serializer.Serialize(project);
                    WriteUtf8Text(jsonStream, json);
                }

                // Second step is to write (if any) project images.
                var keys = Editor.GetAllShapes<XImage>(project).Select(i => i.Path).Distinct();
                foreach (var key in keys)
                {
                    var bytes = project.GetImage(key);
                    if (bytes != null)
                    {
                        var imageEntry = archive.CreateEntry(key);
                        using (var imageStream = imageEntry.Open())
                        {
                            WriteBinary(imageStream, bytes);
                        }
                    }
                }

                // NOTE: Purge deleted images from memory is not called here to enable Undo/Redo.
                //project.PurgeUnusedImages(new HashSet<string>(keys));
            }
        }
예제 #9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="path"></param>
 /// <param name="project"></param>
 /// <param name="serializer"></param>
 /// <returns></returns>
 public static void Save(string path, Project project, ISerializer serializer)
 {
     using (var stream = new FileStream(path, FileMode.Create))
     {
         Save(stream, project, serializer);
     }
 }
예제 #10
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public static Project Create(string name = "Project")
 {
     var p = new Project()
     {
         Name = name,
         Options = Options.Create(),
         Databases = ImmutableArray.Create<Database>(),
         StyleLibraries = ImmutableArray.Create<StyleLibrary>(),
         GroupLibraries = ImmutableArray.Create<GroupLibrary>(),
         Templates = ImmutableArray.Create<Container>(),
         Documents = ImmutableArray.Create<Document>(),
     };
     return p;
 }