1077 long ry2 = ry1 + r2.height; 1078 1079 if (tx1 < rx1) tx1 = rx1; 1080 if (ty1 < ry1) ty1 = ry1; 1081 if (tx2 > rx2) tx2 = rx2; 1082 if (ty2 > ry2) ty2 = ry2; 1083 1084 tx2 -= tx1; 1085 ty2 -= ty1; 1086 1087 // tx2,ty2 will never overflow (they will never be 1088 // larger than the smallest of the two source w,h) 1089 // they might underflow, though... 1090 if (tx2 < Integer.MIN_VALUE) tx2 = Integer.MIN_VALUE; 1091 if (ty2 < Integer.MIN_VALUE) ty2 = Integer.MIN_VALUE; 1092 1093 r3.setBounds(tx1, ty1, (int) tx2, (int) ty2); 1094 } 1095 1096 /** 1097 * Clips the copy area to the heavywieght bounds and returns the cliped rectangle. The tricky part here is the 1098 * passed arguments x, y are in the coordinate space of the sg2d/lightweight comp. In order to do the clipping we 1099 * translate them to the coordinate space of the surface, and the returned clipped rectangle is in the coordinate 1100 * space of the surface. 1101 */ 1102 protected Rectangle clipCopyArea(SunGraphics2D sg2d, int x, int y, int w, int h, int dx, int dy) { 1103 // we need to clip against the heavyweight bounds 1104 copyAreaBounds.setBounds(sg2d.devClip.getLoX(), sg2d.devClip.getLoY(), sg2d.devClip.getWidth(), sg2d.devClip.getHeight()); 1105 1106 // put src rect into surface coordinate space 1107 x += sg2d.transX; 1108 y += sg2d.transY; 1109 1110 // clip src rect 1111 srcCopyAreaRect.setBounds(x, y, w, h); 1112 intersection(srcCopyAreaRect, copyAreaBounds, srcCopyAreaRect); 1113 if ((srcCopyAreaRect.width <= 0) || (srcCopyAreaRect.height <= 0)) { 1114 // src rect outside bounds 1115 return null; 1116 } 1117 1118 // clip dst rect 1119 dstCopyAreaRect.setBounds(srcCopyAreaRect.x + dx, srcCopyAreaRect.y + dy, srcCopyAreaRect.width, srcCopyAreaRect.height); 1120 intersection(dstCopyAreaRect, copyAreaBounds, dstCopyAreaRect); 1121 if ((dstCopyAreaRect.width <= 0) || (dstCopyAreaRect.height <= 0)) { 1122 // dst rect outside clip 1123 return null; 1124 } 1125 1126 x = dstCopyAreaRect.x - dx; 1127 y = dstCopyAreaRect.y - dy; 1128 w = dstCopyAreaRect.width; 1129 h = dstCopyAreaRect.height; | 1077 long ry2 = ry1 + r2.height; 1078 1079 if (tx1 < rx1) tx1 = rx1; 1080 if (ty1 < ry1) ty1 = ry1; 1081 if (tx2 > rx2) tx2 = rx2; 1082 if (ty2 > ry2) ty2 = ry2; 1083 1084 tx2 -= tx1; 1085 ty2 -= ty1; 1086 1087 // tx2,ty2 will never overflow (they will never be 1088 // larger than the smallest of the two source w,h) 1089 // they might underflow, though... 1090 if (tx2 < Integer.MIN_VALUE) tx2 = Integer.MIN_VALUE; 1091 if (ty2 < Integer.MIN_VALUE) ty2 = Integer.MIN_VALUE; 1092 1093 r3.setBounds(tx1, ty1, (int) tx2, (int) ty2); 1094 } 1095 1096 /** 1097 * Clips the copy area to the heavywieght bounds and returns the cliped rectangle. 1098 * The returned clipped rectangle is in the coordinate space of the surface. 1099 */ 1100 protected Rectangle clipCopyArea(SunGraphics2D sg2d, int x, int y, int w, int h, int dx, int dy) { 1101 // we need to clip against the heavyweight bounds 1102 copyAreaBounds.setBounds(sg2d.devClip.getLoX(), sg2d.devClip.getLoY(), sg2d.devClip.getWidth(), sg2d.devClip.getHeight()); 1103 1104 // clip src rect 1105 srcCopyAreaRect.setBounds(x, y, w, h); 1106 intersection(srcCopyAreaRect, copyAreaBounds, srcCopyAreaRect); 1107 if ((srcCopyAreaRect.width <= 0) || (srcCopyAreaRect.height <= 0)) { 1108 // src rect outside bounds 1109 return null; 1110 } 1111 1112 // clip dst rect 1113 dstCopyAreaRect.setBounds(srcCopyAreaRect.x + dx, srcCopyAreaRect.y + dy, srcCopyAreaRect.width, srcCopyAreaRect.height); 1114 intersection(dstCopyAreaRect, copyAreaBounds, dstCopyAreaRect); 1115 if ((dstCopyAreaRect.width <= 0) || (dstCopyAreaRect.height <= 0)) { 1116 // dst rect outside clip 1117 return null; 1118 } 1119 1120 x = dstCopyAreaRect.x - dx; 1121 y = dstCopyAreaRect.y - dy; 1122 w = dstCopyAreaRect.width; 1123 h = dstCopyAreaRect.height; |