java.lang.Objectcom.aspose.words.Fill
public class Fill
Use the Example:
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.Color | getBackColor() | |
void | setBackColor(java.awt.Color value) | |
Gets or sets a Color object that represents the background color for the fill. | ||
java.awt.Color | getColor() | |
void | setColor(java.awt.Color value) | |
|
||
int | getFillType() | |
Gets a fill type. The value of the property is FillType integer constant. | ||
java.awt.Color | getForeColor() | |
void | setForeColor(java.awt.Color value) | |
Gets or sets a Color object that represents the foreground color for the fill. | ||
double | getGradientAngle() | |
void | setGradientAngle(double value) | |
Gets or sets the angle of the gradient fill. | ||
GradientStopCollection | getGradientStops() | |
Gets a collection of |
||
int | getGradientStyle() | |
Gets the gradient style |
||
int | getGradientVariant() | |
Gets the gradient variant |
||
byte[] | getImageBytes() | |
Gets the raw bytes of the fill texture or pattern. | ||
boolean | getOn() | |
void | setOn(boolean value) | |
true if the formatting applied to this instance, is visible.
|
||
double | getOpacity() | |
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). | ||
int | getPattern() | |
Gets a |
||
int | getPresetTexture() | |
Gets a |
||
boolean | getRotateWithObject() | |
void | setRotateWithObject(boolean value) | |
Gets or sets whether the fill rotates with the specified object. | ||
int | getTextureAlignment() | |
void | setTextureAlignment(int value) | |
Gets or sets the alignment for tile texture fill. The value of the property is TextureAlignment integer constant. | ||
double | getTransparency() | |
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). | ||
boolean | getVisible() | |
void | setVisible(boolean value) | |
Gets or sets value that is true if the formatting applied to this instance, is visible.
|
Method Summary | ||
---|---|---|
void | oneColorGradient(int style, int variant, double degree) | |
Sets the specified fill to a one-color gradient. | ||
void | oneColorGradient(java.awt.Color color, int style, int variant, double degree) | |
Sets the specified fill to a one-color gradient and applies a specified color to the |
||
void | patterned(int patternType) | |
Sets the specified fill to a pattern. | ||
void | patterned(int patternType, java.awt.Color foreColor, java.awt.Color backColor) | |
Sets the specified fill to a pattern. | ||
void | presetTextured(int presetTexture) | |
Sets the fill to a preset texture. | ||
void | setImage(byte[] imageBytes) | |
Changes the fill type to single image. | ||
void | setImage(java.lang.String fileName) | |
Changes the fill type to single image. | ||
void | solid() | |
Sets the fill to a uniform color. | ||
void | solid(java.awt.Color color) | |
Sets the fill to a specified uniform color. | ||
void | twoColorGradient(int style, int variant) | |
Sets the specified fill to a two-color gradient. | ||
void | twoColorGradient(java.awt.Color color1, java.awt.Color color2, int style, int variant) | |
Sets the specified fill to a two-color gradient. |
Property Getters/Setters Detail |
---|
getBackColor/setBackColor | |
public java.awt.Color getBackColor() / public void setBackColor(java.awt.Color value) |
getColor/setColor | |
@Deprecated public java.awt.Color getColor() / public void setColor(java.awt.Color value) |
Example:
Shows how to convert any of the fills back to solid fill.Document doc = new Document(getMyDir() + "Two color gradient.docx"); // Get Fill object for Font of the first Run. Fill fill = doc.getFirstSection().getBody().getParagraphs().get(0).getRuns().get(0).getFont().getFill(); // Check Fill properties of the Font. System.out.println(MessageFormat.format("The type of the fill is: {0}",fill.getFillType())); System.out.println(MessageFormat.format("The foreground color of the fill is: {0}",fill.getForeColor())); System.out.println(MessageFormat.format("The fill is transparent at {0}%",fill.getTransparency() * 100.0)); // Change type of the fill to Solid with uniform green color. fill.solid(Color.GREEN); System.out.println("\nThe fill is changed:"); System.out.println(MessageFormat.format("The type of the fill is: {0}",fill.getFillType())); System.out.println(MessageFormat.format("The foreground color of the fill is: {0}",fill.getForeColor())); System.out.println(MessageFormat.format("The fill transparency is {0}%",fill.getTransparency() * 100.0)); doc.save(getArtifactsDir() + "Drawing.FillSolid.docx");
getFillType | |
public int getFillType() |
getForeColor/setForeColor | |
public java.awt.Color getForeColor() / public void setForeColor(java.awt.Color value) |
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");
getGradientAngle/setGradientAngle | |
public double getGradientAngle() / public void setGradientAngle(double value) |
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);
getGradientStops | |
public GradientStopCollection getGradientStops() |
Example:
Shows how to add gradient stops to the gradient fill.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Shape shape = builder.insertShape(ShapeType.RECTANGLE, 80.0, 80.0); shape.getFill().twoColorGradient(Color.green, Color.RED, GradientStyle.HORIZONTAL, GradientVariant.VARIANT_2); // Get gradient stops collection. GradientStopCollection gradientStops = shape.getFill().getGradientStops(); // Change first gradient stop. gradientStops.get(0).setColor(Color.yellow); gradientStops.get(0).setPosition(0.1); gradientStops.get(0).setTransparency(0.25); // Add new gradient stop to the end of collection. GradientStop gradientStop = new GradientStop(Color.blue, 0.5); gradientStops.add(gradientStop); // Remove gradient stop at index 1. gradientStops.removeAt(1); // And insert new gradient stop at the same index 1. gradientStops.insert(1, new GradientStop(Color.pink, 0.75, 0.3)); // Remove last gradient stop in the collection. gradientStop = gradientStops.get(2); gradientStops.remove(gradientStop); Assert.assertEquals(2, gradientStops.getCount()); Assert.assertEquals(Color.yellow.getRGB(), gradientStops.get(0).getColor().getRGB()); Assert.assertEquals(0.1d, gradientStops.get(0).getPosition(), 0.01d); Assert.assertEquals(0.25d, gradientStops.get(0).getTransparency(), 0.01d); Assert.assertEquals(Color.pink.getRGB(), gradientStops.get(1).getColor().getRGB()); Assert.assertEquals(0.75d, gradientStops.get(1).getPosition(), 0.01d); Assert.assertEquals(0.3d, gradientStops.get(1).getTransparency(), 0.01d); // Use the compliance option to define the shape using DML // if you want to get "GradientStops" property after the document saves. OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(); { saveOptions.setCompliance(OoxmlCompliance.ISO_29500_2008_STRICT); } doc.save(getArtifactsDir() + "Shape.GradientStops.docx", saveOptions);
getGradientStyle | |
public int getGradientStyle() |
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);
getGradientVariant | |
public int getGradientVariant() |
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);
getImageBytes | |
public byte[] getImageBytes() |
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) |
true
if the formatting applied to this instance, is visible.
getOpacity/setOpacity | |
public double getOpacity() / public void setOpacity(double value) |
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");
getPattern | |
public int getPattern() |
getPresetTexture | |
public int getPresetTexture() |
getRotateWithObject/setRotateWithObject | |
public boolean getRotateWithObject() / public void setRotateWithObject(boolean value) |
getTextureAlignment/setTextureAlignment | |
public int getTextureAlignment() / public void setTextureAlignment(int value) |
Example:
Shows how to fill and tiling the texture inside the shape.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Shape shape = builder.insertShape(ShapeType.RECTANGLE, 80.0, 80.0); // Apply texture alignment to the shape fill. shape.getFill().presetTextured(PresetTexture.CANVAS); shape.getFill().setTextureAlignment(TextureAlignment.TOP_RIGHT); // Use the compliance option to define the shape using DML if you want to get "TextureAlignment" // property after the document saves. OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(); { saveOptions.setCompliance(OoxmlCompliance.ISO_29500_2008_STRICT); } doc.save(getArtifactsDir() + "Shape.TextureFill.docx", saveOptions);
getTransparency/setTransparency | |
public double getTransparency() / public void setTransparency(double value) |
getVisible/setVisible | |
public boolean getVisible() / public void setVisible(boolean value) |
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 |
---|
oneColorGradient | |
public void oneColorGradient(int style, int variant, double degree) |
style
- A variant
- A degree
- The gradient degree. Can be a value from 0.0 (dark) to 1.0 (light).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);
oneColorGradient | |
public void oneColorGradient(java.awt.Color color, int style, int variant, double degree) |
color
- The color to apply to style
- A variant
- A degree
- The gradient degree. Can be a value from 0.0 (dark) to 1.0 (light).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);
patterned | |
public void patterned(int patternType) |
patternType
- A Example:
Shows how to set pattern for a shape.Document doc = new Document(getMyDir() + "Shape stroke pattern border.docx"); Shape shape = (Shape)doc.getChild(NodeType.SHAPE, 0, true); Fill fill = shape.getFill(); System.out.println(MessageFormat.format("Pattern value is: {0}",fill.getPattern())); // There are several ways specified fill to a pattern. // 1 - Apply pattern to the shape fill: fill.patterned(PatternType.DIAGONAL_BRICK); // 2 - Apply pattern with foreground and background colors to the shape fill: fill.patterned(PatternType.DIAGONAL_BRICK, Color.yellow, Color.blue); doc.save(getArtifactsDir() + "Shape.FillPattern.docx");
patterned | |
public void patterned(int patternType, java.awt.Color foreColor, java.awt.Color backColor) |
patternType
- A foreColor
- The color of the foreground fill.backColor
- The color of the background fill.Example:
Shows how to set pattern for a shape.Document doc = new Document(getMyDir() + "Shape stroke pattern border.docx"); Shape shape = (Shape)doc.getChild(NodeType.SHAPE, 0, true); Fill fill = shape.getFill(); System.out.println(MessageFormat.format("Pattern value is: {0}",fill.getPattern())); // There are several ways specified fill to a pattern. // 1 - Apply pattern to the shape fill: fill.patterned(PatternType.DIAGONAL_BRICK); // 2 - Apply pattern with foreground and background colors to the shape fill: fill.patterned(PatternType.DIAGONAL_BRICK, Color.yellow, Color.blue); doc.save(getArtifactsDir() + "Shape.FillPattern.docx");
presetTextured | |
public void presetTextured(int presetTexture) |
presetTexture
- A Example:
Show how to set marker formatting.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Shape shape = builder.insertChart(ChartType.SCATTER, 432.0, 252.0); Chart chart = shape.getChart(); // Delete default generated series. chart.getSeries().clear(); ChartSeries series = chart.getSeries().add("AW Series 1", new double[] { 0.7, 1.8, 2.6, 3.9 }, new double[] { 2.7, 3.2, 0.8, 1.7 }); // Set marker formatting. series.getMarker().setSize(40); series.getMarker().setSymbol(MarkerSymbol.SQUARE); ChartDataPointCollection dataPoints = series.getDataPoints(); dataPoints.get(0).getMarker().getFormat().getFill().presetTextured(PresetTexture.DENIM); dataPoints.get(0).getMarker().getFormat().getStroke().setForeColor(Color.YELLOW); dataPoints.get(0).getMarker().getFormat().getStroke().setBackColor(Color.RED); dataPoints.get(1).getMarker().getFormat().getFill().presetTextured(PresetTexture.WATER_DROPLETS); dataPoints.get(1).getMarker().getFormat().getStroke().setForeColor(Color.YELLOW); dataPoints.get(1).getMarker().getFormat().getStroke().setVisible(false); dataPoints.get(2).getMarker().getFormat().getFill().presetTextured(PresetTexture.GREEN_MARBLE); dataPoints.get(2).getMarker().getFormat().getStroke().setForeColor(Color.YELLOW); dataPoints.get(3).getMarker().getFormat().getFill().presetTextured(PresetTexture.OAK); dataPoints.get(3).getMarker().getFormat().getStroke().setForeColor(Color.YELLOW); dataPoints.get(3).getMarker().getFormat().getStroke().setTransparency(0.5); doc.save(getArtifactsDir() + "Charts.MarkerFormatting.docx");
setImage | |
public void setImage(byte[] imageBytes) |
imageBytes
- The image bytes array.setImage | |
public void setImage(java.lang.String fileName) throws java.lang.Exception |
fileName
- The path to the image file.solid | |
public void solid() |
solid | |
public void solid(java.awt.Color color) |
Example:
Shows how to convert any of the fills back to solid fill.Document doc = new Document(getMyDir() + "Two color gradient.docx"); // Get Fill object for Font of the first Run. Fill fill = doc.getFirstSection().getBody().getParagraphs().get(0).getRuns().get(0).getFont().getFill(); // Check Fill properties of the Font. System.out.println(MessageFormat.format("The type of the fill is: {0}",fill.getFillType())); System.out.println(MessageFormat.format("The foreground color of the fill is: {0}",fill.getForeColor())); System.out.println(MessageFormat.format("The fill is transparent at {0}%",fill.getTransparency() * 100.0)); // Change type of the fill to Solid with uniform green color. fill.solid(Color.GREEN); System.out.println("\nThe fill is changed:"); System.out.println(MessageFormat.format("The type of the fill is: {0}",fill.getFillType())); System.out.println(MessageFormat.format("The foreground color of the fill is: {0}",fill.getForeColor())); System.out.println(MessageFormat.format("The fill transparency is {0}%",fill.getTransparency() * 100.0)); doc.save(getArtifactsDir() + "Drawing.FillSolid.docx");
twoColorGradient | |
public void twoColorGradient(int style, int variant) |
style
- A variant
- A 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);
twoColorGradient | |
public void twoColorGradient(java.awt.Color color1, java.awt.Color color2, int style, int variant) |
color1
- The first gradient color,
which will be set to color2
- The second gradient color,
which will be set to style
- A variant
- A 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);