Skip to content

CLIP_RECT ​

Restrict drawing to an area by setting or modifying the clipping region with a rectangular shape.

Syntax ​

leo-grammar
CLIP_RECT [ x:measureValue ] [ y:measureValue ] [ w:measureValue ] [ h:measureValue ]
    [ combine-mode: CombineMode ] .

CombineMode :  copy | and | or | diff | xor .

Parameters ​

  • x (measureValue, optional) - The x-coordinate of the top-left corner of the rectangle. The default is 0cm.
  • y (measureValue, optional) - The y-coordinate of the top-left corner of the rectangle. The default is 0cm.
  • w (measureValue, optional) - The width of the rectangle. The default is 0cm.
  • h (measureValue, optional) - The height of the rectangle. The default is 0cm.
  • combine-mode (modifier, optional) - Whether and how to combine the clipping region with an existing clipping region. Should be one of copy, and, or, diff or xor. The default is copy.

Details ​

This command restricts the area in which anything is drawn by setting a clipping region or modifying an existing clipping region. All drawing which lies outside the current clipping region is ineffective, while all parts of elements inside are visible. The clipping region can be of any shape by combining several basic shapes. A clipping region can even consist of disjoint parts.

The CLIP_RECT command sets / modifies the clipping region with a rectangular shape. For additional details about rectangles and their parameters see the RECTANGLE command.

At the beginning of a GraphRep drawing, no clipping is active. When reaching a clipping command, the current clipping region is set to the given shape. If clipping is already active, the new region can either replace the current clipping region (combine-mode:copy, which is the default) or can be combined with the current clipping region with one of the following combine-mode operators:

  • and: The resulting clipping region includes everything which belongs to both regions (intersection).
  • or: The resulting clipping region includes everything which belongs at least to one of both regions (union).
  • diff: The resulting clipping region is the current clipping region with the given region removed from it (difference, subtraction).
  • xor: The resulting clipping region includes everything which belongs to exactly one of both regions (symmetric difference).

The current clipping region can be deactivated with the CLIP_OFF command.

The combine-mode:and, combine-mode:diff and combine-mode:xor are not fully supported in SVG Graphics. Instead of combinations, separate clippings have to be defined.

See Also ​

Examples ​

Draw only part of the image accessible at the URL https://www.omilab.org/assets/images/omilab_logo_.png (scaled down to 3cm by 1.5cm).
The top of the OMiLAB logo

leo
GRAPHREP

CLIP_RECT w:3cm h:0.9cm
BITMAP ("https://www.omilab.org/assets/images/omilab_logo_.png") w:3cm h:1.5cm
# The bottom 0.6cm are cut off due to the CLIP_RECT command.

Draw a circle which is filled with with a red color and a white stripe going horizontally through the middle.
A red circle with a white stripe going horizontally through the middle

leo
GRAPHREP
# Note: SHADOW is on by default.

# Draw the red ball.
FILL color:"red"
ELLIPSE rx:0.9cm ry:0.9cm

# Overlay a white stripe on top using a clipping region.
CLIP_RECT x:-1cm y:-0.3cm w:2cm h:0.6cm
FILL color:"white"
ELLIPSE rx:0.9cm ry:0.9cm

A complex collection of various shapes showing the combination of CLIP_ELLIPSE and CLIP_RECT.
Too complex to describe

leo
GRAPHREP
SHADOW off

# Drawing without a clipping region.
PEN style:null
FILL color:"green"
RECTANGLE x:0cm y:0cm w:2cm h:2cm
FONT "Arial" h:60pt line-orientation:10 bold underline
TEXT "TestTest" x:-3.5cm y:1cm

# Setting and modifying the clipping region.
CLIP_ELLIPSE x:0cm y:2cm rx:1.5cm ry:1.5cm
CLIP_ELLIPSE x:2cm y:2cm rx:1.5cm ry:1.5cm combine-mode:xor
CLIP_RECT x:-0.5cm y:1.3cm w:3cm h:0.2cm combine-mode:diff
CLIP_RECT x:-0.5cm y:1.9cm w:3cm h:0.2cm combine-mode:diff
CLIP_RECT x:-0.5cm y:2.5cm w:3cm h:0.2cm combine-mode:diff

# Drawing a rectangle that will end up looking like two blue circles with parts cut out.
FILL color:"dodgerblue"
RECTANGLE x:-2cm y:0cm w:6cm h:4cm

Versions and Changes ​

Available since ADOxx 1.3