Exemplo n.º 1
0
        /// <summary>
        /// Creates a callback that can be used to filter layer visibility.
        /// </summary>
        /// <param name="queryString"></param>
        /// <returns></returns>
        private ShowLayerDelegate BuildLayerCallback(NameValueCollection queryString)
        {
            //Which layers do we show?
            PsdCommandSearcher searcher = new PsdCommandSearcher(new PsdCommandBuilder(queryString));

            return(delegate(int index, string name, bool visibleNow)
            {
                //Exclude Layer Group layers,       Name	"</Layer group>"	string
                if ("</Layer group>".Equals(name, StringComparison.OrdinalIgnoreCase))
                {
                    return false;
                }
                if (name.IndexOf('<') > -1)
                {
                    return false;
                }
                Nullable <bool> show = (searcher.getVisibility(name));
                if (show == null)
                {
                    return visibleNow;
                }
                else
                {
                    return show.Value;
                }
            });
        }
Exemplo n.º 2
0
        private ComposeLayerDelegate BuildModifyLayerCallback(NameValueCollection queryString)
        {
            PsdCommandSearcher searcher = new PsdCommandSearcher(new PsdCommandBuilder(queryString));

            return(delegate(Graphics g, Bitmap b, object layer)
            {
                PhotoshopFile.Layer l = (PhotoshopFile.Layer)layer;
                //See if this layer is supposed to be re-colored.
                Nullable <Color> color = searcher.getColor(l.Name);

                if (b == null && l.Rect.X == 0 && l.Rect.Y == 0 && l.Rect.Width == 0 && l.Rect.Height == 0)
                {
                    return; //This layer has no size, it is probably a layer group.
                }

                //See if we need to re-draw this text layer
                Nullable <bool> redraw = searcher.getRedraw(l.Name);
                if (redraw != null && redraw == true)
                {
                    //Verify it has text layer information:
                    bool hasText = false;
                    foreach (PhotoshopFile.Layer.AdjustmentLayerInfo lInfo in  l.AdjustmentInfo)
                    {
                        if (lInfo.Key.Equals("TySh", StringComparison.Ordinal))
                        {
                            hasText = true; break;
                        }
                    }


                    if (hasText)
                    {
                        //Re-draw the text directly, ignoring the bitmap
                        var tlr = new TextLayerRenderer(l);
                        tlr.IgnoreMissingFonts = !isStrictMode();
                        tlr.Render(g, color, searcher.getReplacementText(l.Name));
                        return;
                    }
                }


                if (b == null && !isStrictMode())
                {
                    return;                                   //Skip drawing layers that have no bitmap data.
                }
                if (b == null)
                {
                    throw new Exception("No bitmap data found for layer " + l.Name);
                }
                //Draw the existing bitmap
                //Blend color into bitmap
                if (color != null)
                {
                    ColorBitmap(b, color.Value);
                }
                //Draw image
                g.DrawImage(b, l.Rect);
            });
        }
Exemplo n.º 3
0
        private ComposeLayerDelegate BuildModifyLayerCallback(NameValueCollection queryString)
        {
            PsdCommandSearcher searcher = new PsdCommandSearcher(new PsdCommandBuilder(queryString));

            return delegate(Graphics g, Bitmap b, object layer)
            {
                PhotoshopFile.Layer l = (PhotoshopFile.Layer)layer;
                //See if this layer is supposed to be re-colored.
                Nullable<Color> color = searcher.getColor(l.Name);

                if (b == null && l.Rect.X == 0 && l.Rect.Y == 0 && l.Rect.Width == 0 && l.Rect.Height == 0)
                {
                    return; //This layer has no size, it is probably a layer group.
                }

                //See if we need to re-draw this text layer
                Nullable<bool> redraw = searcher.getRedraw(l.Name);
                if (redraw != null && redraw == true)
                {
                    //Verify it has text layer information:
                    bool hasText = false;
                    foreach (PhotoshopFile.Layer.AdjustmentLayerInfo lInfo in  l.AdjustmentInfo)
                        if (lInfo.Key.Equals("TySh", StringComparison.Ordinal)){ hasText=true; break;}

                    if (hasText) {
                        //Re-draw the text directly, ignoring the bitmap
                        var tlr = new TextLayerRenderer(l);
                        tlr.IgnoreMissingFonts = !isStrictMode();
                        tlr.Render(g, color, searcher.getReplacementText(l.Name));
                        return;
                    }
                }

                    if (b == null && !isStrictMode()) return; //Skip drawing layers that have no bitmap data.
                    if (b == null) throw new Exception("No bitmap data found for layer " + l.Name);
                    //Draw the existing bitmap
                    //Blend color into bitmap
                    if (color != null) ColorBitmap(b, color.Value);
                    //Draw image
                    g.DrawImage(b, l.Rect);

            };
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a callback that can be used to filter layer visibility.
        /// </summary>
        /// <param name="queryString"></param>
        /// <returns></returns>
        private ShowLayerDelegate BuildLayerCallback(NameValueCollection queryString)
        {
            //Which layers do we show?
            PsdCommandSearcher searcher = new PsdCommandSearcher(new PsdCommandBuilder(queryString));

            return delegate(int index, string name, bool visibleNow)
            {
                //Exclude Layer Group layers, 		Name	"</Layer group>"	string
                if ("</Layer group>".Equals(name, StringComparison.OrdinalIgnoreCase)) return false;
                if (name.IndexOf('<') > -1) return false;
                Nullable<bool> show = (searcher.getVisibility(name));
                if (show == null) return visibleNow;
                else return show.Value;
            };
        }