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#getColor1() */ public Color getColor1() { return paint.getColor1(); }
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"); } }
/** * Sets the paint for this graphics context. For now, this graphics * context only supports instances of {@link Color} or * {@link GradientPaint} (in the latter case there is no real gradient * support, the paint used is the {@code Color} returned by * {@code getColor1()}). * * @param paint the paint ({@code null} permitted, ignored). * * @see #getPaint() * @see #setColor(Color) */ @Override public void setPaint(Paint paint) { if (paint == null) { return; // to be consistent with other Graphics2D implementations } if (paint instanceof Color) { setColor((Color) paint); } else if (paint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) paint; setColor(gp.getColor1()); } else { throw new RuntimeException("Can only handle 'Color' at present."); } }
@Override public void setPaint(Paint paint) { if (paint instanceof Color) { setColor((Color) paint); } else if (paint instanceof GradientPaint) { // TODO setColor(((GradientPaint) paint).getColor1()); notImplemented("setPaint(Paint) with GradientPaint"); } else { notImplemented("setPaint(Paint) with " + paint.getClass().getSimpleName()); // TODO // This will probably be easier to handle with a fragment shader // in the shader pipeline, not sure how to handle it in the fixed- // function pipeline. } }
/** * 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; }
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()); }
@Override public void setPaint(Paint paint) { if (paint instanceof Color) { setColor((Color) paint); } else if (paint instanceof GradientPaint) { setColor(((GradientPaint) paint).getColor1()); notImplemented("setPaint(Paint) with GradientPaint"); } else if (paint instanceof MultipleGradientPaint) { setColor(((MultipleGradientPaint) paint).getColors()[0]); notImplemented("setPaint(Paint) with MultipleGradientPaint"); } else { notImplemented("setPaint(Paint) with " + paint.getClass().getSimpleName()); // This will probably be easier to handle with a fragment shader // in the shader pipeline, not sure how to handle it in the fixed- // function pipeline. } }
GradientPaint gp = (GradientPaint) p; result = 193; result = 37 * result + gp.getColor1().hashCode(); result = 37 * result + gp.getPoint1().hashCode(); result = 37 * result + gp.getColor2().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(")"); }