1 /*
2 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
588 this.fGraphicsStatesInt.put(kColorRGBValue2Index, color.getColor2().getRGB());
589 this.fGraphicsStatesInt.put(kColorIsCyclicIndex, (color.isCyclic()) ? kColorCyclic : kColorNonCyclic);
590 Point2D p = color.getPoint1();
591 this.fGraphicsStatesFloat.put(kColorx1Index, (float) p.getX());
592 this.fGraphicsStatesFloat.put(kColory1Index, (float) p.getY());
593 p = color.getPoint2();
594 this.fGraphicsStatesFloat.put(kColorx2Index, (float) p.getX());
595 this.fGraphicsStatesFloat.put(kColory2Index, (float) p.getY());
596
597 this.fChangeFlag = (this.fChangeFlag | kColorChangedBit);
598 } else {
599 this.fChangeFlag = (this.fChangeFlag & kColorNotChangedBit);
600 }
601 } else if (sg2d.paint instanceof LinearGradientPaint) {
602 LinearGradientPaint color = (LinearGradientPaint) sg2d.paint;
603 if (color.getCycleMethod() == LinearGradientPaint.CycleMethod.NO_CYCLE) {
604 if ((this.fGraphicsStatesInt.get(kColorStateIndex) != kColorLinearGradient) || (lastPaint != sg2d.paint)) {
605
606 this.fGraphicsStatesInt.put(kColorStateIndex, kColorLinearGradient);
607 int numColor = color.getColors().length;
608 int colorArray[] = new int[numColor];
609 for (int i = 0; i < numColor; i++) {
610 colorArray[i] = color.getColors()[i].getRGB();
611 }
612 this.fGraphicsStatesObject[kColorArrayIndex] = colorArray;
613
614 int numFractions = color.getFractions().length;
615 float fractionArray[] = new float[numFractions];
616 for (int i = 0; i < numFractions; i++) {
617 fractionArray[i] = color.getFractions()[i];
618 }
619 this.fGraphicsStatesObject[kFractionsArrayIndex] = color.getFractions();
620
621 Point2D p = color.getStartPoint();
622 this.fGraphicsStatesFloat.put(kColorx1Index, (float) p.getX());
623 this.fGraphicsStatesFloat.put(kColory1Index, (float) p.getY());
624 p = color.getEndPoint();
625 this.fGraphicsStatesFloat.put(kColorx2Index, (float) p.getX());
626 this.fGraphicsStatesFloat.put(kColory2Index, (float) p.getY());
627
628 this.fChangeFlag = (this.fChangeFlag | kColorChangedBit);
629 } else {
630 this.fChangeFlag = (this.fChangeFlag & kColorNotChangedBit);
631 }
632 } else {
633 setGradientViaRasterPath(sg2d);
634 }
635 } else if (sg2d.paint instanceof RadialGradientPaint) {
636 RadialGradientPaint color = (RadialGradientPaint) sg2d.paint;
637 if (color.getCycleMethod() == RadialGradientPaint.CycleMethod.NO_CYCLE) {
638 if ((this.fGraphicsStatesInt.get(kColorStateIndex) != kColorRadialGradient) || (lastPaint != sg2d.paint)) {
639
640 this.fGraphicsStatesInt.put(kColorStateIndex, kColorRadialGradient);
641 int numColor = color.getColors().length;
642 int colorArray[] = new int[numColor];
643 for (int i = 0; i < numColor; i++) {
644 colorArray[i] = color.getColors()[i].getRGB();
645 }
646 this.fGraphicsStatesObject[kColorArrayIndex] = colorArray;
647
648 int numStops = color.getFractions().length;
649 float stopsArray[] = new float[numStops];
650 for (int i = 0; i < numStops; i++) {
651 stopsArray[i] = color.getFractions()[i];
652 }
653 this.fGraphicsStatesObject[kFractionsArrayIndex] = color.getFractions();
654
655 Point2D p = color.getFocusPoint();
656 this.fGraphicsStatesFloat.put(kColorx1Index, (float) p.getX());
657 this.fGraphicsStatesFloat.put(kColory1Index, (float) p.getY());
658 p = color.getCenterPoint();
659 this.fGraphicsStatesFloat.put(kColorx2Index, (float) p.getX());
660 this.fGraphicsStatesFloat.put(kColory2Index, (float) p.getY());
661 this.fGraphicsStatesFloat.put(kRadiusIndex, color.getRadius());
662
663 this.fChangeFlag = (this.fChangeFlag | kColorChangedBit);
664 } else {
665 this.fChangeFlag = (this.fChangeFlag & kColorNotChangedBit);
666 }
667 } else {
668 setGradientViaRasterPath(sg2d);
669 }
1014 // System.err.println("--- doOval");
1015 if ((isfill) && (isCustomPaint(sg2d))) {
1016 setupGraphicsState(sg2d, kOval, (int) x, (int) y, (int) width, (int) height);
1017 } else {
1018 setupGraphicsState(sg2d, kOval, sg2d.font, 0, 0, fBounds.width, fBounds.height);
1019 }
1020 renderer.doOval(this, x, y, width, height, isfill);
1021 }
1022
1023 public void doArc(CRenderer renderer, SunGraphics2D sg2d, float x, float y, float width, float height, float startAngle, float arcAngle, int type, boolean isfill) {
1024 // System.err.println("--- doArc");
1025 if ((isfill) && (isCustomPaint(sg2d))) {
1026 setupGraphicsState(sg2d, kArc, (int) x, (int) y, (int) width, (int) height);
1027 } else {
1028 setupGraphicsState(sg2d, kArc, sg2d.font, 0, 0, fBounds.width, fBounds.height);
1029 }
1030
1031 renderer.doArc(this, x, y, width, height, startAngle, arcAngle, type, isfill);
1032 }
1033
1034 public void doPolygon(CRenderer renderer, SunGraphics2D sg2d, int xpoints[], int ypoints[], int npoints, boolean ispolygon, boolean isfill) {
1035 // System.err.println("--- doPolygon");
1036
1037 if ((isfill) && (isCustomPaint(sg2d))) {
1038 int minx = xpoints[0];
1039 int miny = ypoints[0];
1040 int maxx = minx;
1041 int maxy = miny;
1042 for (int i = 1; i < npoints; i++) {
1043 int x = xpoints[i];
1044 if (x < minx) {
1045 minx = x;
1046 } else if (x > maxx) {
1047 maxx = x;
1048 }
1049
1050 int y = ypoints[i];
1051 if (y < miny) {
1052 miny = y;
1053 } else if (y > maxy) {
1054 maxy = y;
1110
1111 public interface CGContextDrawable {
1112 public void drawIntoCGContext(final long cgContext);
1113 }
1114
1115 public void drawString(CTextPipe renderer, SunGraphics2D sg2d, long nativeStrikePtr, String str, double x, double y) {
1116 // System.err.println("--- drawString str=\""+str+"\"");
1117 // see <rdar://problem/3825795>. We don't want to call anything if the string is empty!
1118 if (str.length() == 0) { return; }
1119
1120 setupGraphicsState(sg2d, kString, sg2d.font, 0, 0, fBounds.width, fBounds.height);
1121 renderer.doDrawString(this, nativeStrikePtr, str, x, y);
1122 }
1123
1124 public void drawGlyphs(CTextPipe renderer, SunGraphics2D sg2d, long nativeStrikePtr, GlyphVector gv, float x, float y) {
1125 // System.err.println("--- drawGlyphs");
1126 setupGraphicsState(sg2d, kGlyphs, gv.getFont(), 0, 0, fBounds.width, fBounds.height);
1127 renderer.doDrawGlyphs(this, nativeStrikePtr, gv, x, y);
1128 }
1129
1130 public void drawUnicodes(CTextPipe renderer, SunGraphics2D sg2d, long nativeStrikePtr, char unicodes[], int offset, int length, float x, float y) {
1131 // System.err.println("--- drawUnicodes "+(new String(unicodes, offset, length)));
1132 setupGraphicsState(sg2d, kUnicodes, sg2d.font, 0, 0, fBounds.width, fBounds.height);
1133 if (length == 1) {
1134 renderer.doOneUnicode(this, nativeStrikePtr, unicodes[offset], x, y);
1135 } else {
1136 renderer.doUnicodes(this, nativeStrikePtr, unicodes, offset, length, x, y);
1137 }
1138 }
1139
1140 // used by copyArea:
1141
1142 Rectangle srcCopyAreaRect = new Rectangle();
1143 Rectangle dstCopyAreaRect = new Rectangle();
1144 Rectangle finalCopyAreaRect = new Rectangle();
1145 Rectangle copyAreaBounds = new Rectangle();
1146
1147 void intersection(Rectangle r1, Rectangle r2, Rectangle r3) {
1148 // this code is taken from Rectangle.java (modified to put results in r3)
1149 int tx1 = r1.x;
1150 int ty1 = r1.y;
|
1 /*
2 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
588 this.fGraphicsStatesInt.put(kColorRGBValue2Index, color.getColor2().getRGB());
589 this.fGraphicsStatesInt.put(kColorIsCyclicIndex, (color.isCyclic()) ? kColorCyclic : kColorNonCyclic);
590 Point2D p = color.getPoint1();
591 this.fGraphicsStatesFloat.put(kColorx1Index, (float) p.getX());
592 this.fGraphicsStatesFloat.put(kColory1Index, (float) p.getY());
593 p = color.getPoint2();
594 this.fGraphicsStatesFloat.put(kColorx2Index, (float) p.getX());
595 this.fGraphicsStatesFloat.put(kColory2Index, (float) p.getY());
596
597 this.fChangeFlag = (this.fChangeFlag | kColorChangedBit);
598 } else {
599 this.fChangeFlag = (this.fChangeFlag & kColorNotChangedBit);
600 }
601 } else if (sg2d.paint instanceof LinearGradientPaint) {
602 LinearGradientPaint color = (LinearGradientPaint) sg2d.paint;
603 if (color.getCycleMethod() == LinearGradientPaint.CycleMethod.NO_CYCLE) {
604 if ((this.fGraphicsStatesInt.get(kColorStateIndex) != kColorLinearGradient) || (lastPaint != sg2d.paint)) {
605
606 this.fGraphicsStatesInt.put(kColorStateIndex, kColorLinearGradient);
607 int numColor = color.getColors().length;
608 int[] colorArray = new int[numColor];
609 for (int i = 0; i < numColor; i++) {
610 colorArray[i] = color.getColors()[i].getRGB();
611 }
612 this.fGraphicsStatesObject[kColorArrayIndex] = colorArray;
613
614 int numFractions = color.getFractions().length;
615 float[] fractionArray = new float[numFractions];
616 for (int i = 0; i < numFractions; i++) {
617 fractionArray[i] = color.getFractions()[i];
618 }
619 this.fGraphicsStatesObject[kFractionsArrayIndex] = color.getFractions();
620
621 Point2D p = color.getStartPoint();
622 this.fGraphicsStatesFloat.put(kColorx1Index, (float) p.getX());
623 this.fGraphicsStatesFloat.put(kColory1Index, (float) p.getY());
624 p = color.getEndPoint();
625 this.fGraphicsStatesFloat.put(kColorx2Index, (float) p.getX());
626 this.fGraphicsStatesFloat.put(kColory2Index, (float) p.getY());
627
628 this.fChangeFlag = (this.fChangeFlag | kColorChangedBit);
629 } else {
630 this.fChangeFlag = (this.fChangeFlag & kColorNotChangedBit);
631 }
632 } else {
633 setGradientViaRasterPath(sg2d);
634 }
635 } else if (sg2d.paint instanceof RadialGradientPaint) {
636 RadialGradientPaint color = (RadialGradientPaint) sg2d.paint;
637 if (color.getCycleMethod() == RadialGradientPaint.CycleMethod.NO_CYCLE) {
638 if ((this.fGraphicsStatesInt.get(kColorStateIndex) != kColorRadialGradient) || (lastPaint != sg2d.paint)) {
639
640 this.fGraphicsStatesInt.put(kColorStateIndex, kColorRadialGradient);
641 int numColor = color.getColors().length;
642 int[] colorArray = new int[numColor];
643 for (int i = 0; i < numColor; i++) {
644 colorArray[i] = color.getColors()[i].getRGB();
645 }
646 this.fGraphicsStatesObject[kColorArrayIndex] = colorArray;
647
648 int numStops = color.getFractions().length;
649 float[] stopsArray = new float[numStops];
650 for (int i = 0; i < numStops; i++) {
651 stopsArray[i] = color.getFractions()[i];
652 }
653 this.fGraphicsStatesObject[kFractionsArrayIndex] = color.getFractions();
654
655 Point2D p = color.getFocusPoint();
656 this.fGraphicsStatesFloat.put(kColorx1Index, (float) p.getX());
657 this.fGraphicsStatesFloat.put(kColory1Index, (float) p.getY());
658 p = color.getCenterPoint();
659 this.fGraphicsStatesFloat.put(kColorx2Index, (float) p.getX());
660 this.fGraphicsStatesFloat.put(kColory2Index, (float) p.getY());
661 this.fGraphicsStatesFloat.put(kRadiusIndex, color.getRadius());
662
663 this.fChangeFlag = (this.fChangeFlag | kColorChangedBit);
664 } else {
665 this.fChangeFlag = (this.fChangeFlag & kColorNotChangedBit);
666 }
667 } else {
668 setGradientViaRasterPath(sg2d);
669 }
1014 // System.err.println("--- doOval");
1015 if ((isfill) && (isCustomPaint(sg2d))) {
1016 setupGraphicsState(sg2d, kOval, (int) x, (int) y, (int) width, (int) height);
1017 } else {
1018 setupGraphicsState(sg2d, kOval, sg2d.font, 0, 0, fBounds.width, fBounds.height);
1019 }
1020 renderer.doOval(this, x, y, width, height, isfill);
1021 }
1022
1023 public void doArc(CRenderer renderer, SunGraphics2D sg2d, float x, float y, float width, float height, float startAngle, float arcAngle, int type, boolean isfill) {
1024 // System.err.println("--- doArc");
1025 if ((isfill) && (isCustomPaint(sg2d))) {
1026 setupGraphicsState(sg2d, kArc, (int) x, (int) y, (int) width, (int) height);
1027 } else {
1028 setupGraphicsState(sg2d, kArc, sg2d.font, 0, 0, fBounds.width, fBounds.height);
1029 }
1030
1031 renderer.doArc(this, x, y, width, height, startAngle, arcAngle, type, isfill);
1032 }
1033
1034 public void doPolygon(CRenderer renderer, SunGraphics2D sg2d, int[] xpoints, int[] ypoints, int npoints, boolean ispolygon, boolean isfill) {
1035 // System.err.println("--- doPolygon");
1036
1037 if ((isfill) && (isCustomPaint(sg2d))) {
1038 int minx = xpoints[0];
1039 int miny = ypoints[0];
1040 int maxx = minx;
1041 int maxy = miny;
1042 for (int i = 1; i < npoints; i++) {
1043 int x = xpoints[i];
1044 if (x < minx) {
1045 minx = x;
1046 } else if (x > maxx) {
1047 maxx = x;
1048 }
1049
1050 int y = ypoints[i];
1051 if (y < miny) {
1052 miny = y;
1053 } else if (y > maxy) {
1054 maxy = y;
1110
1111 public interface CGContextDrawable {
1112 public void drawIntoCGContext(final long cgContext);
1113 }
1114
1115 public void drawString(CTextPipe renderer, SunGraphics2D sg2d, long nativeStrikePtr, String str, double x, double y) {
1116 // System.err.println("--- drawString str=\""+str+"\"");
1117 // see <rdar://problem/3825795>. We don't want to call anything if the string is empty!
1118 if (str.length() == 0) { return; }
1119
1120 setupGraphicsState(sg2d, kString, sg2d.font, 0, 0, fBounds.width, fBounds.height);
1121 renderer.doDrawString(this, nativeStrikePtr, str, x, y);
1122 }
1123
1124 public void drawGlyphs(CTextPipe renderer, SunGraphics2D sg2d, long nativeStrikePtr, GlyphVector gv, float x, float y) {
1125 // System.err.println("--- drawGlyphs");
1126 setupGraphicsState(sg2d, kGlyphs, gv.getFont(), 0, 0, fBounds.width, fBounds.height);
1127 renderer.doDrawGlyphs(this, nativeStrikePtr, gv, x, y);
1128 }
1129
1130 public void drawUnicodes(CTextPipe renderer, SunGraphics2D sg2d, long nativeStrikePtr, char[] unicodes, int offset, int length, float x, float y) {
1131 // System.err.println("--- drawUnicodes "+(new String(unicodes, offset, length)));
1132 setupGraphicsState(sg2d, kUnicodes, sg2d.font, 0, 0, fBounds.width, fBounds.height);
1133 if (length == 1) {
1134 renderer.doOneUnicode(this, nativeStrikePtr, unicodes[offset], x, y);
1135 } else {
1136 renderer.doUnicodes(this, nativeStrikePtr, unicodes, offset, length, x, y);
1137 }
1138 }
1139
1140 // used by copyArea:
1141
1142 Rectangle srcCopyAreaRect = new Rectangle();
1143 Rectangle dstCopyAreaRect = new Rectangle();
1144 Rectangle finalCopyAreaRect = new Rectangle();
1145 Rectangle copyAreaBounds = new Rectangle();
1146
1147 void intersection(Rectangle r1, Rectangle r2, Rectangle r3) {
1148 // this code is taken from Rectangle.java (modified to put results in r3)
1149 int tx1 = r1.x;
1150 int ty1 = r1.y;
|