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);
            });
        }
Beispiel #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);

            };
        }