protected Paint createPaint(Polygon polygon) { if (fillPaint instanceof GradientPaint) { GradientPaint gradientPaint = (GradientPaint)fillPaint; Point2D point1 = new Point(0, getLowestY(polygon)); Point2D point2 = new Point(0, getHeight()); return new GradientPaint(point1, gradientPaint.getColor1(), point2, gradientPaint.getColor2(), false); } else { return fillPaint; } }
/** * @see java.awt.GradientPaint#getColor2() */ public Color getColor2() { return paint.getColor2(); }
public static Color colorOf(Paint paint) { if (paint instanceof Color) { return (Color) paint; } else if (paint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) paint; return gp.getColor2(); } return Color.black; }
protected Paint createPaint(Polygon polygon) { if (fillPaint instanceof GradientPaint) { GradientPaint gradientPaint = (GradientPaint)fillPaint; Point2D point1 = new Point(0, getLowestY(polygon)); Point2D point2 = new Point(0, getHeight()); return new GradientPaint(point1, gradientPaint.getColor1(), point2, gradientPaint.getColor2(), false); } else { return fillPaint; } }
@Override public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(paint.getColor1()); out.writeObject(paint.getColor2()); out.writeObject(paint.getPoint1()); out.writeObject(paint.getPoint2()); out.writeBoolean(paint.isCyclic()); }
/** * Creates the paint. * * @param polygon the polygon * @return the paint */ protected Paint createPaint(final Polygon polygon) { if (this.fillPaint instanceof GradientPaint) { final GradientPaint gradientPaint = (GradientPaint) this.fillPaint; final Point2D point1 = new Point(0, getLowestY(polygon)); final Point2D point2 = new Point(0, getHeight()); return new GradientPaint(point1, gradientPaint.getColor1(), point2, gradientPaint.getColor2(), false); } else { return this.fillPaint; } }
protected void writePaint(GradientPaint paint) throws IOException { if (postscriptLevel >= LEVEL_3) { float[] rgb1 = paint.getColor1().getRGBColorComponents(null); float[] rgb2 = paint.getColor2().getRGBColorComponents(null); Point2D p1 = paint.getPoint1(); Point2D p2 = paint.getPoint2(); os.println("<< /PatternType 2"); os.println(" /Shading"); os.println(" << /ShadingType 2"); os.println(" /ColorSpace /DeviceRGB"); os.println(" /Coords [" + p1.getX() + " " + p1.getY() + " " + p2.getX() + " " + p2.getY() + "]"); os.println(" /Function"); os.println(" << /FunctionType 2"); os.println(" /Domain [0 1]"); os.println(" /Range [0 1 0 1 0 1]"); os.println(" /C0 [" + rgb1[0] + " " + rgb1[1] + " " + rgb1[2] + "]"); os.println(" /C1 [" + rgb2[0] + " " + rgb2[1] + " " + rgb2[2] + "]"); os.println(" /N 1"); os.println(" >>"); os.println(" /Extend [true true]"); os.println(" >>"); os.println(">>"); os.println("matrix makepattern setpattern"); } }
/** * Writes a serializable object description to the given object output stream. * * @param o the to be serialized object. * @param stream the outputstream that should receive the object. * @throws IOException if an I/O error occured. */ public void writeObject( final Object o, final ObjectOutputStream stream ) throws IOException { final GradientPaint gp = (GradientPaint) o; final Point2D point2D1 = gp.getPoint1(); stream.writeFloat( (float) point2D1.getX() ); stream.writeFloat( (float) point2D1.getY() ); stream.writeObject( gp.getColor1() ); final Point2D point2D = gp.getPoint2(); stream.writeFloat( (float) point2D.getX() ); stream.writeFloat( (float) point2D.getY() ); stream.writeObject( gp.getColor2() ); stream.writeBoolean( gp.isCyclic() ); }
private GradientPaint updateGradientPaintPoints(GradientPaint gp) { int x = (int) getX(); int y = (int) getY(); int h = (int) getHeight(); GradientPaint gradient = new GradientPaint(x, y, gp.getColor1(), x, y + h, gp.getColor2(), gp.isCyclic()); return gradient; }
(float) bounds.getMinY(), paint.getColor1(), (float) bounds.getCenterX(), (float) bounds.getMaxY(), paint.getColor2()); (float) bounds.getCenterY(), paint.getColor1(), (float) bounds.getMaxX(), (float) bounds.getCenterY(), paint.getColor2()); (float) bounds.getCenterY(), paint.getColor2(), (float) bounds.getMaxX(), (float) bounds.getCenterY(), paint.getColor1(), true); (float) bounds.getMinY(), paint.getColor1(), (float) bounds.getCenterX(), (float) bounds.getCenterY(), paint.getColor2(), true);
protected void writePaint(GradientPaint p) throws IOException { Gradient[] gradient = new Gradient[2]; gradient[0] = new Gradient(0, p.getColor1()); gradient[1] = new Gradient(255, p.getColor2()); double x0 = p.getPoint1().getX(); double y0 = p.getPoint1().getY(); double dx = p.getPoint2().getX() - x0; double dy = p.getPoint2().getY() - y0; double scale = p.getPoint1().distance(p.getPoint2()) * TWIPS / 32768; double angle = Math.atan2(dy, dx); AffineTransform transform = new AffineTransform(scale, 0, 0, scale, dx / 2 + x0, dy / 2 + y0); transform.rotate(angle); int spreadMode = p.isCyclic() ? FillStyle.SPREAD_MODE_REFLECT : FillStyle.SPREAD_MODE_PAD; fillStyles = new FillStyleArray(); fillStyles.add(new FillStyle(gradient, FillStyle.LINEAR_GRADIENT, spreadMode, FillStyle.INTERPOLATION_MODE_NORMAL_RGB, 0.0f, transform)); textColor = PrintColor.mixColor(p.getColor1(), p.getColor2()); }
protected void writePaint(GradientPaint p) throws IOException { Gradient[] gradient = new Gradient[2]; gradient[0] = new Gradient(0, p.getColor1()); gradient[1] = new Gradient(255, p.getColor2()); double x0 = p.getPoint1().getX(); double y0 = p.getPoint1().getY(); double dx = p.getPoint2().getX() - x0; double dy = p.getPoint2().getY() - y0; double scale = p.getPoint1().distance(p.getPoint2()) * TWIPS / 32768; double angle = Math.atan2(dy, dx); AffineTransform transform = new AffineTransform(scale, 0, 0, scale, dx / 2 + x0, dy / 2 + y0); transform.rotate(angle); int spreadMode = p.isCyclic() ? FillStyle.SPREAD_MODE_REFLECT : FillStyle.SPREAD_MODE_PAD; fillStyles = new FillStyleArray(); fillStyles.add(new FillStyle(gradient, FillStyle.LINEAR_GRADIENT, spreadMode, FillStyle.INTERPOLATION_MODE_NORMAL_RGB, 0.0f, transform)); textColor = PrintColor.mixColor(p.getColor1(), p.getColor2()); }
/** * Create a new {@code GradientPaint} with its colors darkened. * * @param paint the gradient paint ({@code null} not permitted). * * @return a darker version of the {@code GradientPaint} */ private static GradientPaint darker(GradientPaint paint) { return new GradientPaint( paint.getPoint1(), darker(paint.getColor1()), paint.getPoint2(), darker(paint.getColor2()), paint.isCyclic()); }
result = 37 * result + gp.getColor1().hashCode(); result = 37 * result + gp.getPoint1().hashCode(); result = 37 * result + gp.getColor2().hashCode(); result = 37 * result + gp.getPoint2().hashCode();
/** * Returns a hash code for this instance. * * @return A hash code. */ @Override public int hashCode() { int hash = 5; hash = 47 * hash + this.paint.getPoint1().hashCode(); hash = 47 * hash + this.paint.getPoint2().hashCode(); hash = 47 * hash + this.paint.getColor1().hashCode(); hash = 47 * hash + this.paint.getColor2().hashCode(); return hash; }
/** * Returns a hash code for this instance. * * @return A hash code. */ @Override public int hashCode() { int hash = 5; hash = 47 * hash + this.paint.getPoint1().hashCode(); hash = 47 * hash + this.paint.getPoint2().hashCode(); hash = 47 * hash + this.paint.getColor1().hashCode(); hash = 47 * hash + this.paint.getColor2().hashCode(); return hash; }
/** * Returns a hash code for this instance. * * @return A hash code. */ @Override public int hashCode() { int hash = 5; hash = 47 * hash + this.paint.getPoint1().hashCode(); hash = 47 * hash + this.paint.getPoint2().hashCode(); hash = 47 * hash + this.paint.getColor1().hashCode(); hash = 47 * hash + this.paint.getColor2().hashCode(); return hash; }
private PDShading buildGradientShading(GradientPaint gradientPaint, PaintApplierState state) throws IOException { Color[] colors = new Color[] { gradientPaint.getColor1(), gradientPaint.getColor2() }; Color firstColor = colors[0]; PDColor firstColorMapped = state.colorMapper.mapColor(state.contentStream, firstColor); applyAsStrokingColor(firstColor, state); PDShadingType3 shading = new PDShadingType3(new COSDictionary()); shading.setShadingType(PDShading.SHADING_TYPE2); shading.setColorSpace(firstColorMapped.getColorSpace()); float[] fractions = new float[] { 0, 1 }; Point2D startPoint = gradientPaint.getPoint1(); Point2D endPoint = gradientPaint.getPoint2(); state.tf.transform(startPoint, startPoint); state.tf.transform(endPoint, endPoint); COSArray coords = new COSArray(); coords.add(new COSFloat((float) startPoint.getX())); coords.add(new COSFloat((float) startPoint.getY())); coords.add(new COSFloat((float) endPoint.getX())); coords.add(new COSFloat((float) endPoint.getY())); shading.setCoords(coords); PDFunctionType3 type3 = buildType3Function(colors, fractions, state); COSArray extend = new COSArray(); extend.add(COSBoolean.TRUE); extend.add(COSBoolean.TRUE); shading.setFunction(type3); shading.setExtend(extend); return shading; }
private void write(GradientPaint gp) { if (gp == null) { out.print("null"); return; } imports.add("java.awt.GradientPaint"); out.println("new GradientPaint("); out.indent(); write(gp.getPoint1()); out.print(", "); write(gp.getColor1()); out.println(", "); write(gp.getPoint2()); out.print(", "); write(gp.getColor2()); out.println(", " + gp.isCyclic()); out.outdent(); out.print(")"); }
/** * Performs the writing of a {@link GradientPaint} object. * * @param tagName the tag name. * @param object the {@link GradientPaint} object. * @param writer the writer. * @param mPlexAttribute ??. * @param mPlexValue ??. * * @throws IOException if there is an I/O error. * @throws XMLWriterException if there is a writer error. */ public void write(final String tagName, final Object object, final XMLWriter writer, final String mPlexAttribute, final String mPlexValue) throws IOException, XMLWriterException { final GradientPaint paint = (GradientPaint) object; writer.writeTag(tagName, mPlexAttribute, mPlexValue, false); writer.startBlock(); final RootXmlWriteHandler rootHandler = getRootHandler(); rootHandler.write("color1", paint.getColor1(), Color.class, writer); writer.allowLineBreak(); rootHandler.write("color2", paint.getColor2(), Color.class, writer); writer.allowLineBreak(); rootHandler.write("point1", paint.getPoint1(), Point2D.class, writer); writer.allowLineBreak(); rootHandler.write("point2", paint.getPoint2(), Point2D.class, writer); writer.endBlock(); writer.writeCloseTag(tagName); } }