Layer mask/clip

Bug #172123 reported by naught101
40
This bug affects 7 people
Affects Status Importance Assigned to Milestone
Inkscape
Triaged
Wishlist
Unassigned

Bug Description

It would be very useful to be able to clip and/or mask layers, while
leaving the objects in that layer editable.

Illustrator has this function, there's a description here:
http://www.bittbox.com/illustrator/improve-your-illustrator-workflow-with-l
ayer-masking/

Revision history for this message
Amphi-users (amphi-users) wrote :

Originator: NO

It's already possible with Inkscape.

-draw something in layer 1 (just for making it visible)
-create a new layer
-draw a rect
-open the xml editor
-click on layer 1 (this will select it)
-hold shift and click on the rect
-object->clip->set

And well, that's it. If you draw new stuff in layer 1 it will be
automatically clipped (as soon as the editing stops).

Revision history for this message
naught101 (naught101) wrote :

Originator: YES

true, I hadn't tried that, thought it's pretty obvious now that you
mention it.

BUT, it would be good to have a GUI way of doing it, for example:
- draw a shape
- select it
- right click on the layer you want to clip
- clip > set (or mask > set)
Or something similar from the Layers menu.

thanks for the pointer

nightrow (jb-benoit)
Changed in inkscape:
importance: Undecided → Wishlist
status: New → Confirmed
Revision history for this message
Martin Andersen (msandersen) wrote :

Even if I could reproduce Amphi-user's example, which I can't in 0.46 Dev, it is obviously not what he was asking for; if you have to resort to a hack involving the XML editor, it is hardly convenient or intuitive, unlike a button on the Layers palette which allowed you to clip and unclip the layer with the topmost shape.

Revision history for this message
WanderingVillager (ovek) wrote :

Doesn't seem like I can attach a clip/mask to layer myself either. It would be useful to have, but in the meantime, remember that you can enter a group.
First, draw stuff, make a group of it, and then set a clip/mask on it. To edit objects in the group almost as if it was a layer, select the group and press Ctrl-Enter. Now you can edit and create objects within the group. When you're done, hit Ctrl-Backspace.

Revision history for this message
PomCompot (pomme-compote-launchpad) wrote :

In some other graphical creation tools (Gimp, PaintShop, …), the layer mask is clearly display beside the layer in the layers view. You can generally see a small black and white view of the mask and it's quite convenient. You can also deal with basic operations on the mask through right clic. Perhaps a way for Inkscape ?

More globally, there are two main defaults on mask operations under Inkscape :
- it's not trivial to put a mask on a whole layer as said above, and when the mask is set the layer appears with some pastel colors which make difficult to see the real final result of the creation.
- it's difficult to see which object are masked, only the statusbar when the object is selected give the information, it's not sufficient.

No idea on what is the best ergonomic choice to achieve good resolution of those problems.

Revision history for this message
Nathaniel Gray (n8gray-n8gray) wrote :

Can has layar maskz pleez?

Seriously, it's killing me not to have this feature. I've been doing lots of icons and logos in Inkscape lately and It would have saved soo much time.

Also, if somebody does implement this please also implement a "document mask" feature so that, for example, if I'm working on an icon with rounded corners I can just round the corners by masking the whole document. And yes, my documents tend to have lots of layers, so masking each one individually would be annoying.

su_v (suv-lp)
tags: added: clipping layers ui
removed: transformations
Revision history for this message
Nathaniel Gray (n8gray-n8gray) wrote :

Oh, and I wanted to mention that the tip described in comment #1 *does* still work, but the wording is ambiguous. The last few steps should go like this:

-click on layer 1 in the XML editor (this will select it)
-hold shift and click on the rect in the canvas, NOT the XML editor or it will deselect the layer
-object->clip->set

The same thing works for masks, BTW.

It's nice to have this as a last resort, but there really should be a proper UI for it.

Thanks!

Revision history for this message
PomCompot (pomme-compote-launchpad) wrote :

In Inkscape 0.48, the workaround doesn't seem to work anymore, sad.

Revision history for this message
su_v (suv-lp) wrote :

PomCompot wrote:
> In Inkscape 0.48, the workaround doesn't seem to work anymore, sad.

You can still clip or mask layers in Inkscape 0.48.x using the described workaround involving the XML Editor. But - as in older versions - you might have to watch out for different transforms on the layer groups (the clipped layer as well as the layer with the clip-path) used for masking or clipping the layer (see bug #569281).

Revision history for this message
ThM82 (thm82) wrote :

On a Mac, it is not possible in the newest version to use the aforementioned method, as it is not possible to have the layer and the shape selected both. I assume the reason is the window management.

However, you can do it in the xml editor by hand. Its not not that difficult:

- Create a layer
- Create two objects.
- Select both and hit object->clip->set (therefore, create a clipping of the one object via the other)
- Open the xml editor:
  - Search the clipped rectangle, there will be an attribute / value pair: "clip-path / url(#clipPathXYXY)"
  - Add the exact same pair to the layer.
  - Delete the pair from the rectangle.
- You are done, your layer is clipped, instead of the rectangle :-)
- You can modifiy the clipping rectangle by searching the clipPathXYXY in the top-level "defs" svg node in the xml editor. The clipping rectangle is a child of the clipPath.

Inkscape needs a way to add such a clipping mask via the gui to a layer!
Especially, a way to select and modify the clipping path after it was added.

Greetings,
Thomas

PS: An example svg looks as follows:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   width="210mm"
   height="297mm"
   id="svg2"
   version="1.1"
   inkscape:version="0.48.0 r9654"
   sodipodi:docname="test.svg"
   enable-background="new">
  <defs
     id="defs4">
    <clipPath
       clipPathUnits="userSpaceOnUse"
       id="clipPath_Layer1">
      <rect
         style="opacity:0.9;fill:#999999;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
         id="clippingRect"
         width="400"
         height="288.10587"
         x="200"
         y="235.33832"
         clip-path="none" />
    </clipPath>
  </defs>
  <g
     inkscape:label="Ebene 1"
     inkscape:groupmode="layer"
     id="layer1"
     style="display:inline;opacity:1"
     clip-path="url(#clipPath_Layer1)">
    <rect
       style="opacity:0.9;fill:#ff0000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.99999994;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
       id="TestRect1"
       width="134.28572"
       height="299.05441"
       x="184.70923"
       y="226.93507"
       rx="62.426407"
       ry="58.385796" />
    <rect
       style="opacity:0.9;fill:#999999;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
       id="TestRect2"
       width="218.19295"
       height="317.1879"
       x="440.42654"
       y="219.99651"
       rx="106.87312"
       ry="106.87312" />
  </g>
</svg>

Revision history for this message
ThM82 (thm82) wrote :

Another trick:

- Add a layer that contains your clipping mask objects.
- Use the "use" svg-tag to link the object into the "clipPath" tag
- Use the clip path to clip your layer as described in the previous post

Example clipPath:

<clipPath
       clipPathUnits="userSpaceOnUse"
       id="clipPath_Layer1">
      <use
         x="0"
         y="0"
         xlink:href="#clipRect1"
         id="use3050"
         height="1"
         width="1" />
</clipPath>

where clipRect1 is the id of the clipping rectangle in the clipping objects layer.

The advantage: You can modify the shape of the clipping object this way easily.
However, if you move the clipping object, the cloned object is not moved, but a "transform" attribute is added to the cloned object (the "use" tag) to keep it in place. Dig into the xml editor and delete the transform tag to get the clipping mask to the same position as your editable clipping object. Not nice, but the best solution I was able to find.

Best regards,
Thomas

Revision history for this message
ThM82 (thm82) wrote :

A short comment: If somebody considers to write a GUI extension for this, an own layer containing the clipping objects is probably no bad idea: This way, it is possible to create clipping objects with complex boundaries that play nice with each other. For example, if you want to split the image area into two regions that show a separate layer each.

Such an implementation would only need a mechanism that moves the cloned object ("use" tag) as soon as the clipping object in the layer is moved.

Oh, another wish. A method to temporarily disable the layer clipping would be awesome. This would enable to edit a layer without the clipping occupying parts of the objets.

Revision history for this message
Emmet McPoland (emcpoland) wrote :

An extension has been created to provide the required functionality for clipping only.
Works well, just ensure the clip layer is unlocked when applying the extension. It is a good idea to lock it after.

http://www.pernsteiner.org/inkscape/layerclip/

Revision history for this message
SasQ (sasq1) wrote :

I tried to use this extension, but it throws me an error:

-----
Traceback (most recent call last):
  File "clip_below.py", line 26, in <module>
    import clip
  File "/usr/share/inkscape/extensions/clip.py", line 27, in <module>
    import inkex
  File "/usr/share/inkscape/extensions/inkex.py", line 29
    u'sodipodi' :u'http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd',
              ^
SyntaxError: invalid syntax
-----

Also I tried to add the <clipPath> in the defs section by hand, with <use xlink:href="url(#g5678)"> and use that clipPath's ID for the clip-path attribute of my clipped layer. But it doesn't work also. I mean, it works for normal pahts inside the <clipPath> tag, but not for <use> tags. All <use> tags are treated as if they weren't be there :-/

It's very frustrating, because I want to have some object on one layer to cut a hole inside all objects on some other layer, and be able to move that hole interactively by moving the hole's shape on that other layer (and hide it when I don't need to edit it). Switching the clip/mask on/off on and on is very irritating, especially that when it's on, all those clip/mask objects disappear and I cannot edit them further until I swith clip/mask off again :/

Any other solutions to that?
The extension cited below could at least walk-around this problem, if only it didn't throw an error ;-/

Revision history for this message
DC2013 (chalon-didier) wrote :

Hello,

I just wanted to mention that I am using the extension suggested above successfully (in Inkscape 0.48.4).

Small note: if your clipping mask is to be made of several paths, an error message is received saying that you should select a
single path. An easy workaround is to group them together, select that group, then use the extension.

I find this a lot more user-friendly than the present standard method. Would it be possible to formally incorporate this extension in a next release of Inkscape?

jazzynico (jazzynico)
Changed in inkscape:
status: Confirmed → Triaged
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.