Exemplo n.º 1
0
        /// <summary>
        /// Transform Photoshop's layer tree to Paint.NET's flat layer list.
        /// Indicate where layer sections begin and end, and hide all layers within
        /// hidden layer sections.
        /// </summary>
        private static void ApplyLayerSections(List <PhotoshopFile.Layer> layers)
        {
            // BUG: PsdPluginResources.GetString will always return English resource,
            // because Paint.NET does not set the CurrentUICulture when OnLoad is
            // called.  This situation should be resolved with Paint.NET 4.0, which
            // will provide an alternative mechanism to retrieve the UI language.

            // Cache layer section strings
            var beginSectionWrapper = PsdPluginResources.GetString("LayersPalette_LayerGroupBegin");
            var endSectionWrapper   = PsdPluginResources.GetString("LayersPalette_LayerGroupEnd");

            // Track the depth of the topmost hidden section.  Any nested sections
            // will be hidden, whether or not they themselves have the flag set.
            int topHiddenSectionDepth = Int32.MaxValue;
            var layerSectionNames     = new Stack <string>();

            // Layers are stored bottom-to-top, but layer sections are specified
            // top-to-bottom.
            foreach (var layer in Enumerable.Reverse(layers))
            {
                // Apply to all layers within the layer section, as well as the
                // closing layer.
                if (layerSectionNames.Count > topHiddenSectionDepth)
                {
                    layer.Visible = false;
                }

                var sectionInfo = (LayerSectionInfo)layer.AdditionalInfo
                                  .SingleOrDefault(x => x is LayerSectionInfo);
                if (sectionInfo == null)
                {
                    continue;
                }

                switch (sectionInfo.SectionType)
                {
                case LayerSectionType.OpenFolder:
                case LayerSectionType.ClosedFolder:
                    // Start a new layer section
                    if ((!layer.Visible) && (topHiddenSectionDepth == Int32.MaxValue))
                    {
                        topHiddenSectionDepth = layerSectionNames.Count;
                    }
                    layerSectionNames.Push(layer.Name);
                    layer.Name = String.Format(beginSectionWrapper, layer.Name);
                    break;

                case LayerSectionType.SectionDivider:
                    // End the current layer section
                    var layerSectionName = layerSectionNames.Pop();
                    if (layerSectionNames.Count == topHiddenSectionDepth)
                    {
                        topHiddenSectionDepth = Int32.MaxValue;
                    }
                    layer.Name = String.Format(endSectionWrapper, layerSectionName);
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public static bool CheckIsGroupLayer(BitmapLayer layer, out bool isStart, out string groupName)
        {
            isStart   = true;
            groupName = null;
            if (layer == null || string.IsNullOrEmpty(layer.Name) || !layer.Name.Contains(':'))
            {
                return(false);
            }

            var splited     = layer.Name.Split(':');
            var layerPrefix = splited.FirstOrDefault().ToLower().Trim();

            if (string.IsNullOrEmpty(layerPrefix))
            {
                return(false);
            }

            var nameOfTheGroup = string.Join(":", splited.Range(1, splited.Length - 1));

            // This is part of the
            if (!string.IsNullOrEmpty(nameOfTheGroup) && nameOfTheGroup.StartsWith(" "))
            {
                nameOfTheGroup = nameOfTheGroup.Substring(1, nameOfTheGroup.Length - 1);
            }

            var startGroupPrefixes = PsdPluginResources.GetAllLayerGroupNames(PsdPluginResources.LayersPalette_LayerGroupBegin);

            if (startGroupPrefixes.Any(p => p == layerPrefix || p.StartsWith(layerPrefix)))
            {
                isStart   = true;
                groupName = nameOfTheGroup;
                return(true);
            }

            var endGroupPrefixes = PsdPluginResources.GetAllLayerGroupNames(PsdPluginResources.LayersPalette_LayerGroupEnd);

            if (endGroupPrefixes.Any(p => p == layerPrefix || p.StartsWith(layerPrefix)))
            {
                isStart   = false;
                groupName = nameOfTheGroup;
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     this.rleCompressCheckBox = new System.Windows.Forms.CheckBox();
     this.SuspendLayout();
     //
     // rleCompressCheckBox
     //
     this.rleCompressCheckBox.Location        = new System.Drawing.Point(0, 0);
     this.rleCompressCheckBox.Name            = "rleCompressCheckBox";
     this.rleCompressCheckBox.Size            = new System.Drawing.Size(184, 24);
     this.rleCompressCheckBox.TabIndex        = 0;
     this.rleCompressCheckBox.Text            = PsdPluginResources.GetString("SaveDialog_RleCompression");
     this.rleCompressCheckBox.CheckedChanged += new System.EventHandler(this.OnCheckedChanged);
     //
     // PsdSaveConfigWidget
     //
     this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
     this.AutoScaleMode       = System.Windows.Forms.AutoScaleMode.Dpi;
     this.Controls.Add(this.rleCompressCheckBox);
     this.Name = "PsdSaveConfigWidget";
     this.Size = new System.Drawing.Size(180, 104);
     this.ResumeLayout(false);
 }