com.aspose.words

  • java.lang.Object
    • com.aspose.words.Fill
public class Fill 
extends java.lang.Object

Represents fill formatting for an object.

Use the ShapeBase.Fill or Font.Fill property to access fill properties of an object. You do not create instances of the Fill class directly.

Although the Fill class provides properties to specify solid color fill only, all of the more complex fill types, including as gradient, pattern and texture are fully preserved during document open-save cycles.

Example:

Shows how to fill a shape with a solid color.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Write some text, and then cover it with a floating shape.
builder.getFont().setSize(32.0);
builder.writeln("Hello world!");

Shape shape = builder.insertShape(ShapeType.CLOUD_CALLOUT, RelativeHorizontalPosition.LEFT_MARGIN, 25.0,
        RelativeVerticalPosition.TOP_MARGIN, 25.0, 250.0, 150.0, WrapType.NONE);

// Use the "StrokeColor" property to set the color of the outline of the shape.
shape.setStrokeColor(Color.BLUE);

// Use the "FillColor" property to set the color of the inside area of the shape.
shape.setFillColor(Color.BLACK);

// The "Opacity" property determines how transparent the color is on a 0-1 scale,
// with 1 being fully opaque, and 0 being invisible.
// The shape fill by default is fully opaque, so we cannot see the text that this shape is on top of.
Assert.assertEquals(1.0d, shape.getFill().getOpacity());

// Set the shape fill color's opacity to a lower value so that we can see the text underneath it.
shape.getFill().setOpacity(0.3);

doc.save(getArtifactsDir() + "Shape.Fill.docx");

Property Getters/Setters Summary
java.awt.ColorgetBackColor()
void
setBackColor(java.awt.Colorvalue)
           Gets or sets a Color object that represents the background color for the fill.
java.awt.ColorgetColor()
void
setColor(java.awt.Colorvalue)
          Deprecated. Gets or sets a Color object that represents the foreground color for the fill.
intgetFillType()
Gets a fill type. The value of the property is FillType integer constant.
java.awt.ColorgetForeColor()
void
setForeColor(java.awt.Colorvalue)
           Gets or sets a Color object that represents the foreground color for the fill.
byte[]getImageBytes()
Gets the raw bytes of the fill texture or pattern.
booleangetOn()
void
setOn(booleanvalue)
          Deprecated. Gets or sets value that is true if the formatting applied to this instance, is visible.
doublegetOpacity()
void
setOpacity(doublevalue)
           Gets or sets the degree of opacity of the specified fill as a value between 0.0 (clear) and 1.0 (opaque).
booleangetRotateWithObject()
void
setRotateWithObject(booleanvalue)
           Gets or sets whether the fill rotates with the specified object.
doublegetTransparency()
void
setTransparency(doublevalue)
           Gets or sets the degree of transparency of the specified fill as a value between 0.0 (opaque) and 1.0 (clear).
booleangetVisible()
void
setVisible(booleanvalue)
           Gets or sets value that is true if the formatting applied to this instance, is visible.
 
Method Summary
voidsolid()
Sets the fill to a uniform color.
voidsolid(java.awt.Color color)
Sets the fill to a specified uniform color.
 

    • Property Getters/Setters Detail

      • getBackColor/setBackColor

        public java.awt.Color getBackColor() / public void setBackColor(java.awt.Color value)
        
        Gets or sets a Color object that represents the background color for the fill.
      • getColor/setColor

        @Deprecated
        public java.awt.Color getColor() / public void setColor(java.awt.Color value)
        
        Deprecated. Gets or sets a Color object that represents the foreground color for the fill.
      • getFillType

        public int getFillType()
        
        Gets a fill type. The value of the property is FillType integer constant.
      • getForeColor/setForeColor

        public java.awt.Color getForeColor() / public void setForeColor(java.awt.Color value)
        
        Gets or sets a Color object that represents the foreground color for the fill.

        Example:

        Shows to create a variety of shapes.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Below are four examples of shapes that we can insert into our documents.
        // 1 -  Dotted, horizontal, half-transparent red line
        // with an arrow on the left end and a diamond on the right end:
        Shape arrow = new Shape(doc, ShapeType.LINE);
        arrow.setWidth(200.0);
        arrow.getStroke().setColor(Color.RED);
        arrow.getStroke().setStartArrowType(ArrowType.ARROW);
        arrow.getStroke().setStartArrowLength(ArrowLength.LONG);
        arrow.getStroke().setStartArrowWidth(ArrowWidth.WIDE);
        arrow.getStroke().setEndArrowType(ArrowType.DIAMOND);
        arrow.getStroke().setEndArrowLength(ArrowLength.LONG);
        arrow.getStroke().setEndArrowWidth(ArrowWidth.WIDE);
        arrow.getStroke().setDashStyle(DashStyle.DASH);
        arrow.getStroke().setOpacity(0.5);
        
        Assert.assertEquals(arrow.getStroke().getJoinStyle(), JoinStyle.MITER);
        
        builder.insertNode(arrow);
        
        // 2 -  Thick black diagonal line with rounded ends:
        Shape line = new Shape(doc, ShapeType.LINE);
        line.setTop(40.0);
        line.setWidth(200.0);
        line.setHeight(20.0);
        line.setStrokeWeight(5.0);
        line.getStroke().setEndCap(EndCap.ROUND);
        
        builder.insertNode(line);
        
        // 3 -  Arrow with a green fill:
        Shape filledInArrow = new Shape(doc, ShapeType.ARROW);
        filledInArrow.setWidth(200.0);
        filledInArrow.setHeight(40.0);
        filledInArrow.setTop(100.0);
        filledInArrow.getFill().setForeColor(Color.GREEN);
        filledInArrow.getFill().setVisible(true);
        
        builder.insertNode(filledInArrow);
        
        // 4 -  Arrow with a flipped orientation filled in with the Aspose logo:
        Shape filledInArrowImg = new Shape(doc, ShapeType.ARROW);
        filledInArrowImg.setWidth(200.0);
        filledInArrowImg.setHeight(40.0);
        filledInArrowImg.setTop(160.0);
        filledInArrowImg.setFlipOrientation(FlipOrientation.BOTH);
        
        BufferedImage image = ImageIO.read(getAsposelogoUri().toURL().openStream());
        Graphics2D graphics2D = image.createGraphics();
        
        // When we flip the orientation of our arrow, we also flip the image that the arrow contains.
        // Flip the image the other way to cancel this out before getting the shape to display it.
        AffineTransform at = new AffineTransform();
        at.concatenate(AffineTransform.getScaleInstance(1, -1));
        at.concatenate(AffineTransform.getTranslateInstance(0, -image.getHeight()));
        graphics2D.transform(at);
        graphics2D.drawImage(image, 0, 0, null);
        graphics2D.dispose();
        
        filledInArrowImg.getImageData().setImage(image);
        builder.insertNode(filledInArrowImg);
        
        doc.save(getArtifactsDir() + "Drawing.VariousShapes.docx");
      • getImageBytes

        public byte[] getImageBytes()
        
        Gets the raw bytes of the fill texture or pattern.

        The default value is null.

        Example:

        Shows to create a variety of shapes.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Below are four examples of shapes that we can insert into our documents.
        // 1 -  Dotted, horizontal, half-transparent red line
        // with an arrow on the left end and a diamond on the right end:
        Shape arrow = new Shape(doc, ShapeType.LINE);
        arrow.setWidth(200.0);
        arrow.getStroke().setColor(Color.RED);
        arrow.getStroke().setStartArrowType(ArrowType.ARROW);
        arrow.getStroke().setStartArrowLength(ArrowLength.LONG);
        arrow.getStroke().setStartArrowWidth(ArrowWidth.WIDE);
        arrow.getStroke().setEndArrowType(ArrowType.DIAMOND);
        arrow.getStroke().setEndArrowLength(ArrowLength.LONG);
        arrow.getStroke().setEndArrowWidth(ArrowWidth.WIDE);
        arrow.getStroke().setDashStyle(DashStyle.DASH);
        arrow.getStroke().setOpacity(0.5);
        
        Assert.assertEquals(arrow.getStroke().getJoinStyle(), JoinStyle.MITER);
        
        builder.insertNode(arrow);
        
        // 2 -  Thick black diagonal line with rounded ends:
        Shape line = new Shape(doc, ShapeType.LINE);
        line.setTop(40.0);
        line.setWidth(200.0);
        line.setHeight(20.0);
        line.setStrokeWeight(5.0);
        line.getStroke().setEndCap(EndCap.ROUND);
        
        builder.insertNode(line);
        
        // 3 -  Arrow with a green fill:
        Shape filledInArrow = new Shape(doc, ShapeType.ARROW);
        filledInArrow.setWidth(200.0);
        filledInArrow.setHeight(40.0);
        filledInArrow.setTop(100.0);
        filledInArrow.getFill().setForeColor(Color.GREEN);
        filledInArrow.getFill().setVisible(true);
        
        builder.insertNode(filledInArrow);
        
        // 4 -  Arrow with a flipped orientation filled in with the Aspose logo:
        Shape filledInArrowImg = new Shape(doc, ShapeType.ARROW);
        filledInArrowImg.setWidth(200.0);
        filledInArrowImg.setHeight(40.0);
        filledInArrowImg.setTop(160.0);
        filledInArrowImg.setFlipOrientation(FlipOrientation.BOTH);
        
        BufferedImage image = ImageIO.read(getAsposelogoUri().toURL().openStream());
        Graphics2D graphics2D = image.createGraphics();
        
        // When we flip the orientation of our arrow, we also flip the image that the arrow contains.
        // Flip the image the other way to cancel this out before getting the shape to display it.
        AffineTransform at = new AffineTransform();
        at.concatenate(AffineTransform.getScaleInstance(1, -1));
        at.concatenate(AffineTransform.getTranslateInstance(0, -image.getHeight()));
        graphics2D.transform(at);
        graphics2D.drawImage(image, 0, 0, null);
        graphics2D.dispose();
        
        filledInArrowImg.getImageData().setImage(image);
        builder.insertNode(filledInArrowImg);
        
        doc.save(getArtifactsDir() + "Drawing.VariousShapes.docx");
      • getOn/setOn

        @Deprecated
        public boolean getOn() / public void setOn(boolean value)
        
        Deprecated. Gets or sets value that is true if the formatting applied to this instance, is visible.
      • getOpacity/setOpacity

        public double getOpacity() / public void setOpacity(double value)
        
        Gets or sets the degree of opacity of the specified fill as a value between 0.0 (clear) and 1.0 (opaque). This property is the opposite of property Transparency.

        Example:

        Shows how to fill a shape with a solid color.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Write some text, and then cover it with a floating shape.
        builder.getFont().setSize(32.0);
        builder.writeln("Hello world!");
        
        Shape shape = builder.insertShape(ShapeType.CLOUD_CALLOUT, RelativeHorizontalPosition.LEFT_MARGIN, 25.0,
                RelativeVerticalPosition.TOP_MARGIN, 25.0, 250.0, 150.0, WrapType.NONE);
        
        // Use the "StrokeColor" property to set the color of the outline of the shape.
        shape.setStrokeColor(Color.BLUE);
        
        // Use the "FillColor" property to set the color of the inside area of the shape.
        shape.setFillColor(Color.BLACK);
        
        // The "Opacity" property determines how transparent the color is on a 0-1 scale,
        // with 1 being fully opaque, and 0 being invisible.
        // The shape fill by default is fully opaque, so we cannot see the text that this shape is on top of.
        Assert.assertEquals(1.0d, shape.getFill().getOpacity());
        
        // Set the shape fill color's opacity to a lower value so that we can see the text underneath it.
        shape.getFill().setOpacity(0.3);
        
        doc.save(getArtifactsDir() + "Shape.Fill.docx");
      • getRotateWithObject/setRotateWithObject

        public boolean getRotateWithObject() / public void setRotateWithObject(boolean value)
        
        Gets or sets whether the fill rotates with the specified object.
      • getTransparency/setTransparency

        public double getTransparency() / public void setTransparency(double value)
        
        Gets or sets the degree of transparency of the specified fill as a value between 0.0 (opaque) and 1.0 (clear). This property is the opposite of property Opacity.
      • getVisible/setVisible

        public boolean getVisible() / public void setVisible(boolean value)
        
        Gets or sets value that is true if the formatting applied to this instance, is visible.

        Example:

        Shows to create a variety of shapes.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Below are four examples of shapes that we can insert into our documents.
        // 1 -  Dotted, horizontal, half-transparent red line
        // with an arrow on the left end and a diamond on the right end:
        Shape arrow = new Shape(doc, ShapeType.LINE);
        arrow.setWidth(200.0);
        arrow.getStroke().setColor(Color.RED);
        arrow.getStroke().setStartArrowType(ArrowType.ARROW);
        arrow.getStroke().setStartArrowLength(ArrowLength.LONG);
        arrow.getStroke().setStartArrowWidth(ArrowWidth.WIDE);
        arrow.getStroke().setEndArrowType(ArrowType.DIAMOND);
        arrow.getStroke().setEndArrowLength(ArrowLength.LONG);
        arrow.getStroke().setEndArrowWidth(ArrowWidth.WIDE);
        arrow.getStroke().setDashStyle(DashStyle.DASH);
        arrow.getStroke().setOpacity(0.5);
        
        Assert.assertEquals(arrow.getStroke().getJoinStyle(), JoinStyle.MITER);
        
        builder.insertNode(arrow);
        
        // 2 -  Thick black diagonal line with rounded ends:
        Shape line = new Shape(doc, ShapeType.LINE);
        line.setTop(40.0);
        line.setWidth(200.0);
        line.setHeight(20.0);
        line.setStrokeWeight(5.0);
        line.getStroke().setEndCap(EndCap.ROUND);
        
        builder.insertNode(line);
        
        // 3 -  Arrow with a green fill:
        Shape filledInArrow = new Shape(doc, ShapeType.ARROW);
        filledInArrow.setWidth(200.0);
        filledInArrow.setHeight(40.0);
        filledInArrow.setTop(100.0);
        filledInArrow.getFill().setForeColor(Color.GREEN);
        filledInArrow.getFill().setVisible(true);
        
        builder.insertNode(filledInArrow);
        
        // 4 -  Arrow with a flipped orientation filled in with the Aspose logo:
        Shape filledInArrowImg = new Shape(doc, ShapeType.ARROW);
        filledInArrowImg.setWidth(200.0);
        filledInArrowImg.setHeight(40.0);
        filledInArrowImg.setTop(160.0);
        filledInArrowImg.setFlipOrientation(FlipOrientation.BOTH);
        
        BufferedImage image = ImageIO.read(getAsposelogoUri().toURL().openStream());
        Graphics2D graphics2D = image.createGraphics();
        
        // When we flip the orientation of our arrow, we also flip the image that the arrow contains.
        // Flip the image the other way to cancel this out before getting the shape to display it.
        AffineTransform at = new AffineTransform();
        at.concatenate(AffineTransform.getScaleInstance(1, -1));
        at.concatenate(AffineTransform.getTranslateInstance(0, -image.getHeight()));
        graphics2D.transform(at);
        graphics2D.drawImage(image, 0, 0, null);
        graphics2D.dispose();
        
        filledInArrowImg.getImageData().setImage(image);
        builder.insertNode(filledInArrowImg);
        
        doc.save(getArtifactsDir() + "Drawing.VariousShapes.docx");
    • Method Detail

      • solid

        public void solid()
        Sets the fill to a uniform color. Use this method to convert any of the fills back to solid fill.
      • solid

        public void solid(java.awt.Color color)
        Sets the fill to a specified uniform color. Use this method to convert any of the fills back to solid fill.