com.aspose.words

Class GradientVariant

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

Utility class containing constants. Specifies the variant for a gradient fill.
Corresponds to the four variants on the Gradient tab in the Fill Effects dialog box in Word.

Example:

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

Shape shape = builder.insertShape(ShapeType.RECTANGLE, 80.0, 80.0);
// Apply One-color gradient fill to the shape with ForeColor of gradient fill.
shape.getFill().oneColorGradient(Color.RED, GradientStyle.HORIZONTAL, GradientVariant.VARIANT_2, 0.1);

Assert.assertEquals(Color.RED.getRGB(), shape.getFill().getForeColor().getRGB());
Assert.assertEquals(GradientStyle.HORIZONTAL, shape.getFill().getGradientStyle());
Assert.assertEquals(GradientVariant.VARIANT_2, shape.getFill().getGradientVariant());
Assert.assertEquals(270, shape.getFill().getGradientAngle());

shape = builder.insertShape(ShapeType.RECTANGLE, 80.0, 80.0);
// Apply Two-color gradient fill to the shape.
shape.getFill().twoColorGradient(GradientStyle.FROM_CORNER, GradientVariant.VARIANT_4);
// Change BackColor of gradient fill.
shape.getFill().setBackColor(Color.YELLOW);
// Note that changes "GradientAngle" for "GradientStyle.FromCorner/GradientStyle.FromCenter"
// gradient fill don't get any effect, it will work only for linear gradient.
shape.getFill().setGradientAngle(15.0);

Assert.assertEquals(Color.YELLOW.getRGB(), shape.getFill().getBackColor().getRGB());
Assert.assertEquals(GradientStyle.FROM_CORNER, shape.getFill().getGradientStyle());
Assert.assertEquals(GradientVariant.VARIANT_4, shape.getFill().getGradientVariant());
Assert.assertEquals(0, shape.getFill().getGradientAngle());

// Use the compliance option to define the shape using DML if you want to get "GradientStyle",
// "GradientVariant" and "GradientAngle" properties after the document saves.
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(); { saveOptions.setCompliance(OoxmlCompliance.ISO_29500_2008_STRICT); }

doc.save(getArtifactsDir() + "Shape.GradientFill.docx", saveOptions);

Field Summary
static final intNONE = 0
Gradient variant 'None'.
static final intVARIANT_1 = 1
Gradient variant 1.
static final intVARIANT_2 = 2
Gradient variant 2.
static final intVARIANT_3 = 3
Gradient variant 3.
static final intVARIANT_4 = 4
Gradient variant 4.
 

    • Field Detail

      • NONE = 0

        public static final int NONE
        Gradient variant 'None'.
      • VARIANT_1 = 1

        public static final int VARIANT_1
        Gradient variant 1.
      • VARIANT_2 = 2

        public static final int VARIANT_2
        Gradient variant 2.