35 import java.awt.font.TextLayout;
36
37 import java.awt.image.RenderedImage;
38 import java.awt.image.renderable.RenderableImage;
39
40 /**
41 * Maintain information about the type of drawing
42 * performed by a printing application.
43 */
44 public class PeekMetrics {
45
46 private boolean mHasNonSolidColors;
47
48 private boolean mHasCompositing;
49
50 private boolean mHasText;
51
52 private boolean mHasImages;
53
54 /**
55 * Return <code>true</code> if the application
56 * has done any drawing with a Paint that
57 * is not an instance of <code>Color</code>
58 */
59 public boolean hasNonSolidColors() {
60 return mHasNonSolidColors;
61 }
62
63 /**
64 * Return true if the application has
65 * done any drawing with an alpha other
66 * than 1.0.
67 */
68 public boolean hasCompositing() {
69 return mHasCompositing;
70 }
71
72 /**
73 * Return true if the application has
74 * drawn any text.
75 */
76 public boolean hasText() {
77 return mHasText;
102 }
103
104 /**
105 * The application is performing a clearRect
106 * so record the needed information.
107 */
108 public void clear(Graphics2D g) {
109 checkPaint(g.getBackground());
110 }
111 /**
112 * The application is drawing text
113 * so record the needed information.
114 */
115 public void drawText(Graphics2D g) {
116 mHasText = true;
117 checkDrawingMode(g);
118 }
119
120 /**
121 * The application is drawing text
122 * defined by <code>TextLayout</code>
123 * so record the needed information.
124 */
125 public void drawText(Graphics2D g, TextLayout textLayout) {
126 mHasText = true;
127 checkDrawingMode(g);
128 }
129
130 /**
131 * The application is drawing the passed
132 * in image.
133 */
134 public void drawImage(Graphics2D g, Image image) {
135 mHasImages = true;
136 }
137
138 /**
139 * The application is drawing the passed
140 * in image.
141 */
142 public void drawImage(Graphics2D g, RenderedImage image) {
147 * The application is drawing the passed
148 * in image.
149 */
150 public void drawImage(Graphics2D g, RenderableImage image) {
151 mHasImages = true;
152 }
153
154 /**
155 * Record information about the current paint
156 * and composite.
157 */
158 private void checkDrawingMode(Graphics2D g) {
159
160 checkPaint(g.getPaint());
161 checkAlpha(g.getComposite());
162
163 }
164
165 /**
166 * Record information about drawing done
167 * with the supplied <code>Paint</code>.
168 */
169 private void checkPaint(Paint paint) {
170
171 if (paint instanceof Color) {
172 if (((Color)paint).getAlpha() < 255) {
173 mHasNonSolidColors = true;
174 }
175 } else {
176 mHasNonSolidColors = true;
177 }
178 }
179
180 /**
181 * Record information about drawing done
182 * with the supplied <code>Composite</code>.
183 */
184 private void checkAlpha(Composite composite) {
185
186 if (composite instanceof AlphaComposite) {
187 AlphaComposite alphaComposite = (AlphaComposite) composite;
188 float alpha = alphaComposite.getAlpha();
189 int rule = alphaComposite.getRule();
190
191 if (alpha != 1.0
192 || (rule != AlphaComposite.SRC
193 && rule != AlphaComposite.SRC_OVER)) {
194
195 mHasCompositing = true;
196 }
197
198 } else {
199 mHasCompositing = true;
200 }
201
202 }
|
35 import java.awt.font.TextLayout;
36
37 import java.awt.image.RenderedImage;
38 import java.awt.image.renderable.RenderableImage;
39
40 /**
41 * Maintain information about the type of drawing
42 * performed by a printing application.
43 */
44 public class PeekMetrics {
45
46 private boolean mHasNonSolidColors;
47
48 private boolean mHasCompositing;
49
50 private boolean mHasText;
51
52 private boolean mHasImages;
53
54 /**
55 * Return {@code true} if the application
56 * has done any drawing with a Paint that
57 * is not an instance of {@code Color}
58 */
59 public boolean hasNonSolidColors() {
60 return mHasNonSolidColors;
61 }
62
63 /**
64 * Return true if the application has
65 * done any drawing with an alpha other
66 * than 1.0.
67 */
68 public boolean hasCompositing() {
69 return mHasCompositing;
70 }
71
72 /**
73 * Return true if the application has
74 * drawn any text.
75 */
76 public boolean hasText() {
77 return mHasText;
102 }
103
104 /**
105 * The application is performing a clearRect
106 * so record the needed information.
107 */
108 public void clear(Graphics2D g) {
109 checkPaint(g.getBackground());
110 }
111 /**
112 * The application is drawing text
113 * so record the needed information.
114 */
115 public void drawText(Graphics2D g) {
116 mHasText = true;
117 checkDrawingMode(g);
118 }
119
120 /**
121 * The application is drawing text
122 * defined by {@code TextLayout}
123 * so record the needed information.
124 */
125 public void drawText(Graphics2D g, TextLayout textLayout) {
126 mHasText = true;
127 checkDrawingMode(g);
128 }
129
130 /**
131 * The application is drawing the passed
132 * in image.
133 */
134 public void drawImage(Graphics2D g, Image image) {
135 mHasImages = true;
136 }
137
138 /**
139 * The application is drawing the passed
140 * in image.
141 */
142 public void drawImage(Graphics2D g, RenderedImage image) {
147 * The application is drawing the passed
148 * in image.
149 */
150 public void drawImage(Graphics2D g, RenderableImage image) {
151 mHasImages = true;
152 }
153
154 /**
155 * Record information about the current paint
156 * and composite.
157 */
158 private void checkDrawingMode(Graphics2D g) {
159
160 checkPaint(g.getPaint());
161 checkAlpha(g.getComposite());
162
163 }
164
165 /**
166 * Record information about drawing done
167 * with the supplied {@code Paint}.
168 */
169 private void checkPaint(Paint paint) {
170
171 if (paint instanceof Color) {
172 if (((Color)paint).getAlpha() < 255) {
173 mHasNonSolidColors = true;
174 }
175 } else {
176 mHasNonSolidColors = true;
177 }
178 }
179
180 /**
181 * Record information about drawing done
182 * with the supplied {@code Composite}.
183 */
184 private void checkAlpha(Composite composite) {
185
186 if (composite instanceof AlphaComposite) {
187 AlphaComposite alphaComposite = (AlphaComposite) composite;
188 float alpha = alphaComposite.getAlpha();
189 int rule = alphaComposite.getRule();
190
191 if (alpha != 1.0
192 || (rule != AlphaComposite.SRC
193 && rule != AlphaComposite.SRC_OVER)) {
194
195 mHasCompositing = true;
196 }
197
198 } else {
199 mHasCompositing = true;
200 }
201
202 }
|