コード例 #1
0
        public static int CountNormalLayer(IEnumerable <Layer> layers)
        {
            //leyersのうち、フォルダ以外の通常レイヤをカウントする
            int normal_layer_count = layers.Count((x) =>
            {
                LayerSectionInfo _sec = x.AdditionalInfo
                                        .OfType <LayerSectionInfo>().FirstOrDefault();

                if (_sec == null)
                {
                    return(true);
                }

                switch (_sec.SectionType)
                {
                case LayerSectionType.OpenFolder:
                case LayerSectionType.ClosedFolder:
                case LayerSectionType.SectionDivider:

                    return(false);
                }

                return(true);
            });


            return(normal_layer_count);
        }
コード例 #2
0
        private static void ParseLayerTree(IEnumerator <Layer> layers, LayerNode parentNode)
        {
            while (layers.MoveNext())
            {
                Layer currentLayer = layers.Current;

                //ノード作成&追加
                LayerNode newNode = new LayerNode(currentLayer);
                parentNode.AddChildNode(newNode);


                //レイヤ種類を取得
                LayerSectionInfo sec = currentLayer.AdditionalInfo
                                       .OfType <LayerSectionInfo>().FirstOrDefault();

                LayerSectionType secType = LayerSectionType.Layer;
                if (sec != null)
                {
                    secType = sec.SectionType;
                }

                //レイヤ種類別処理
                switch (secType)
                {
                case LayerSectionType.SectionDivider:
                    //フォルダ終了(逆順に並んでいるため、こちらが先に来る)


                    //ひとつ下の階層として以降のレイヤーを処理
                    newNode.Layer = null;
                    newNode.AddChildNode(new LayerNode(currentLayer));
                    ParseLayerTree(layers, newNode);


                    break;

                case LayerSectionType.OpenFolder:
                case LayerSectionType.ClosedFolder:
                    //フォルダ開始(逆順に並んでいるため、こちらが後に来る)

                    parentNode.Name = currentLayer.Name;

                    //処理終了(再帰脱出条件)
                    return;

                case LayerSectionType.Layer:
                default:
                    //通常レイヤ

                    break;
                }
            }
        }
コード例 #3
0
        public static LayerSectionType GetSectionType(this Layer layer)
        {
            LayerSectionInfo sec = layer.AdditionalInfo
                                   .OfType <LayerSectionInfo>().FirstOrDefault();

            LayerSectionType secType = LayerSectionType.Layer;

            if (sec != null)
            {
                secType = sec.SectionType;
            }

            return(secType);
        }
コード例 #4
0
        public PsdFileInfo(PsdFile psd)
        {
            List <LayerGroupInfo> layerGroups     = new List <LayerGroupInfo>();
            List <LayerGroupInfo> openGroupStack  = new List <LayerGroupInfo>();
            List <bool>           layerVisibility = new List <bool>();

            for (int i = psd.Layers.Count - 1; i >= 0; i--)
            {
                Layer layer = psd.Layers[i];

                layerVisibility.Add(layer.Visible);

                // Get the section info for this layer
                var secInfo = layer.AdditionalInfo
                              .Where(info => info.GetType() == typeof(LayerSectionInfo))
                              .ToArray();
                bool isOpen     = false;
                bool isGroup    = false;
                bool closeGroup = false;
                if (secInfo.Any())
                {
                    foreach (var layerSecInfo in secInfo)
                    {
                        LayerSectionInfo info = (LayerSectionInfo)layerSecInfo;
                        isOpen     = info.SectionType == LayerSectionType.OpenFolder;
                        isGroup    = info.SectionType == LayerSectionType.ClosedFolder | isOpen;
                        closeGroup = info.SectionType == LayerSectionType.SectionDivider;
                        if (isGroup || closeGroup)
                        {
                            break;
                        }
                    }
                }

                if (isGroup)
                {
                    // Open a new layer group info
                    openGroupStack.Add(new LayerGroupInfo(layer.Name, i, layer.Visible, isOpen));
                }
                else if (closeGroup)
                {
                    // Set the end index of the latest LayerGroupInfo
                    var closeInfo = openGroupStack.Last();
                    closeInfo.start = i;
                    // Add it to the layerGroup list
                    layerGroups.Add(closeInfo);
                    // And remove it from the open group stack
                    openGroupStack.RemoveAt(openGroupStack.Count - 1);
                }
                else
                {
                    // Normal layer, look for instances
                    if (layer.Name.Contains(" Copy"))
                    {
                    }
                }
            }             // End layer loop

            layerVisibility.Reverse();
            LayerVisibility = layerVisibility.ToArray();

            LayerGroups = layerGroups.ToArray();
        }
コード例 #5
0
    PsdLayer[] ReadLayers(PsdFile psdFile)
    {
        List <PsdLayer>     result        = new List <PsdLayer>();
        Stack <PsdLayerSet> layerSetStack = new Stack <PsdLayerSet>();

        PsdLayerSet parentSet = null;

        foreach (Layer layer in psdFile.Layers)
        {
            // Get the section info for this layer
            var secInfo = layer.AdditionalInfo
                          .Where(info => info.GetType() == typeof(LayerSectionInfo))
                          .ToArray();

            // Section info is basically layer group info
            bool isOpen     = false;
            bool isGroup    = false;
            bool closeGroup = false;
            if (secInfo.Any())
            {
                foreach (var layerSecInfo in secInfo)
                {
                    LayerSectionInfo info = (LayerSectionInfo)layerSecInfo;
                    isOpen     = info.SectionType == LayerSectionType.OpenFolder;
                    isGroup    = info.SectionType == LayerSectionType.ClosedFolder | isOpen;
                    closeGroup = info.SectionType == LayerSectionType.SectionDivider;
                    if (isGroup || closeGroup)
                    {
                        break;
                    }
                }
            }

            if (isGroup)
            {
                PsdLayerSet layerSet = layerSetStack.Pop();
                layerSet.name = layer.Name;
                parentSet     = layerSetStack.Count > 0 ? layerSetStack.Peek() : null;
            }
            else if (closeGroup)
            {
                PsdLayerSet layerSet = new PsdLayerSet(this, "", layer.Rect);
                layerSet.visible = layer.Visible;
                if (parentSet != null)
                {
                    parentSet.AddLayer(layerSet);
                }
                else
                {
                    result.Add(layerSet);
                }
                layerSetStack.Push(layerSet);
                parentSet = layerSet;
            }
            else // art layer
            {
                PsdLayer psdLayer;

                PsdShape[] shapes = layer.GetShapes();
                if (shapes != null)
                {
                    psdLayer = new PsdShapeLayer(this, layer.Name, layer.Rect, shapes);
                }
                else
                {
                    psdLayer = new PsdArtLayer(this, layer.Name, layer.Rect, layer.ReadPixels());
                }

                psdLayer.visible = layer.Visible;
                if (parentSet != null)
                {
                    parentSet.AddLayer(psdLayer);
                }
                else
                {
                    result.Add(psdLayer);
                }
            }
        }

        return(result.ToArray());
    }
コード例 #6
0
        public PsdFileInfo(PsdFile psd)
        {
            m_Width  = psd.BaseLayer.Rect.width;
            m_Height = psd.BaseLayer.Rect.height;

            List <int> layerIndices = new List <int>();
            List <PSDLayerGroupInfo> layerGroups    = new List <PSDLayerGroupInfo>();
            List <PSDLayerGroupInfo> openGroupStack = new List <PSDLayerGroupInfo>();
            List <bool> layerVisibility             = new List <bool>();

            // Reverse loop through layers to get the layers in the
            // same way they are displayed in Photoshop
            for (int i = psd.Layers.Count - 1; i >= 0; i--)
            {
                Layer layer = psd.Layers[i];

                layerVisibility.Add(layer.Visible);

                // Get the section info for this layer
                var secInfo = layer.AdditionalInfo
                              .Where(info => info.GetType() == typeof(LayerSectionInfo))
                              .ToArray();
                // Section info is basically layer group info
                bool isOpen     = false;
                bool isGroup    = false;
                bool closeGroup = false;
                if (secInfo.Any())
                {
                    foreach (var layerSecInfo in secInfo)
                    {
                        LayerSectionInfo info = (LayerSectionInfo)layerSecInfo;
                        isOpen     = info.SectionType == LayerSectionType.OpenFolder;
                        isGroup    = info.SectionType == LayerSectionType.ClosedFolder | isOpen;
                        closeGroup = info.SectionType == LayerSectionType.SectionDivider;
                        if (isGroup || closeGroup)
                        {
                            break;
                        }
                    }
                }

                if (isGroup)
                {
                    // Open a new layer group info, because we're iterating
                    // through layers backwards, this layer number is the last logical layer
                    openGroupStack.Add(new PSDLayerGroupInfo(layer.Name, i, layer.Visible, isOpen));
                }
                else if (closeGroup)
                {
                    // Set the start index of the last LayerGroupInfo
                    var closeInfo = openGroupStack.Last();
                    closeInfo.start = i;
                    // Add it to the layerGroup list
                    layerGroups.Add(closeInfo);
                    // And remove it from the open group stack
                    openGroupStack.RemoveAt(openGroupStack.Count - 1);
                }
                else
                {
                    // Normal layer
                    layerIndices.Add(i);
                    // look for instances
                    if (layer.Name.Contains(" Copy"))
                    {
                    }
                }
            }             // End layer loop

            // Since loop was reversed...
            layerVisibility.Reverse();
            LayerVisibility = layerVisibility.ToArray();

            LayerIndices = layerIndices.ToArray();

            LayerGroups = layerGroups.ToArray();
        }