View Javadoc
1   /*
2    * Copyright (c) 2002-2026 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.platform.canvas.rendering;
16  
17  import java.io.IOException;
18  import java.nio.ByteBuffer;
19  
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  
23  /**
24   * The default implementation of {@link RenderingBackend}.
25   *
26   * @author Ronald Brill
27   */
28  public class NoOpRenderingBackend implements RenderingBackend {
29  
30      private static final Log LOG = LogFactory.getLog(NoOpRenderingBackend.class);
31  
32      private static int ID_GENERATOR_;
33      private final int id_;
34  
35      private static synchronized int nextId() {
36          return ID_GENERATOR_++;
37      }
38  
39      /**
40       * Constructor.
41       * @param imageWidth the width
42       * @param imageHeight the height
43       */
44      public NoOpRenderingBackend(final int imageWidth, final int imageHeight) {
45          id_ = nextId();
46      }
47  
48      /**
49       * {@inheritDoc}
50       */
51      @Override
52      public double getGlobalAlpha() {
53          return 1.0;
54      }
55  
56      /**
57       * {@inheritDoc}
58       */
59      @Override
60      public void setGlobalAlpha(final double globalAlpha) {
61          if (LOG.isDebugEnabled()) {
62              LOG.debug("[" + id_ + "] setGlobalAlpha(" + globalAlpha + ")");
63          }
64      }
65  
66      /**
67       * {@inheritDoc}
68       */
69      @Override
70      public void beginPath() {
71          if (LOG.isDebugEnabled()) {
72              LOG.debug("[" + id_ + "] beginPath()");
73          }
74      }
75  
76      /**
77       * {@inheritDoc}
78       */
79      @Override
80      public void ellipse(final double x, final double y,
81              final double radiusX, final double radiusY,
82              final double rotation, final double startAngle, final double endAngle,
83              final boolean anticlockwise) {
84          if (LOG.isDebugEnabled()) {
85              LOG.debug("[" + id_ + "] ellipse()");
86          }
87      }
88  
89      /**
90       * {@inheritDoc}
91       */
92      @Override
93      public void bezierCurveTo(final double cp1x, final double cp1y,
94              final double cp2x, final double cp2y, final double x, final double y) {
95          if (LOG.isDebugEnabled()) {
96              LOG.debug("[" + id_ + "] bezierCurveTo()");
97          }
98      }
99  
100     /**
101      * {@inheritDoc}
102      */
103     @Override
104     public void arc(final double x, final double y, final double radius, final double startAngle,
105             final double endAngle, final boolean anticlockwise) {
106         if (LOG.isDebugEnabled()) {
107             LOG.debug("[" + id_ + "] arc()");
108         }
109     }
110 
111     /**
112      * {@inheritDoc}
113      */
114     @Override
115     public void clearRect(final double x, final double y, final double w, final double h) {
116         if (LOG.isDebugEnabled()) {
117             LOG.debug("[" + id_ + "] clearRect(" + x + ", " + y + ", " + w + ", " + h + ")");
118         }
119     }
120 
121     /**
122      * {@inheritDoc}
123      */
124     @Override
125     public void drawImage(final org.htmlunit.platform.image.ImageData imageData,
126             final int sx, final int sy, final Integer sWidth, final Integer sHeight,
127             final int dx, final int dy, final Integer dWidth, final Integer dHeight) throws IOException {
128         if (LOG.isDebugEnabled()) {
129             LOG.debug("[" + id_ + "] drawImage(" + sx + ", " + sy + ", " + sWidth + ", " + sHeight
130                     + "," + dx + ", " + dy + ", " + dWidth + ", " + dHeight + ")");
131         }
132     }
133 
134     /**
135      * {@inheritDoc}
136      */
137     @Override
138     public String encodeToString(final String type) throws IOException {
139         return null;
140     }
141 
142     /**
143      * {@inheritDoc}
144      */
145     @Override
146     public void fill(final WindingRule windingRule) {
147         if (LOG.isDebugEnabled()) {
148             LOG.debug("[" + id_ + "] fill()");
149         }
150     }
151 
152     /**
153      * {@inheritDoc}
154      */
155     @Override
156     public void fillRect(final double x, final double y, final double w, final double h) {
157         if (LOG.isDebugEnabled()) {
158             LOG.debug("[" + id_ + "] fillRect(" + x + ", "  + y + ", "  + w + ", "  + h + ")");
159         }
160     }
161 
162     /**
163      * {@inheritDoc}
164      */
165     @Override
166     public void fillText(final String text, final double x, final double y) {
167         if (LOG.isDebugEnabled()) {
168             LOG.debug("[" + id_ + "] fillText('" + text + "', "  + x + ", "  + y + ")");
169         }
170     }
171 
172     /**
173      * {@inheritDoc}
174      */
175     @Override
176     public byte[] getBytes(final int width, final int height, final int sx, final int sy) {
177         if (LOG.isDebugEnabled()) {
178             LOG.debug("[" + id_ + "] getBytes(" + width + ", " + height + ", " + sx + ", " + sy + ")");
179         }
180 
181         return null;
182     }
183 
184     /**
185      * {@inheritDoc}
186      */
187     @Override
188     public void lineTo(final double x, final double y) {
189         if (LOG.isDebugEnabled()) {
190             LOG.debug("[" + id_ + "] lineTo(" + x + ", " + y + ")");
191         }
192     }
193 
194     /**
195      * {@inheritDoc}
196      */
197     @Override
198     public void moveTo(final double x, final double y) {
199         if (LOG.isDebugEnabled()) {
200             LOG.debug("[" + id_ + "] moveTo(" + x + ", " + y + ")");
201         }
202     }
203 
204     /**
205      * {@inheritDoc}
206      */
207     @Override
208     public void putImageData(
209             final ByteBuffer imageDataBytes, final int imageDataHeight, final int imageDataWidth,
210             final int dx, final int dy, final int dirtyX, final int dirtyY,
211             final int dirtyWidth, final int dirtyHeight) {
212 
213         if (LOG.isDebugEnabled()) {
214             LOG.debug("[" + id_ + "] putImageData()");
215         }
216     }
217 
218     /**
219      * {@inheritDoc}
220      */
221     @Override
222     public void quadraticCurveTo(final double cpx, final double cpy,
223                     final double x, final double y) {
224         if (LOG.isDebugEnabled()) {
225             LOG.debug("[" + id_ + "] quadraticCurveTo()");
226         }
227     }
228 
229     /**
230      * {@inheritDoc}
231      */
232     @Override
233     public void rect(final double x, final double y, final double w, final double h) {
234         if (LOG.isDebugEnabled()) {
235             LOG.debug("[" + id_ + "] rect()");
236         }
237     }
238 
239     /**
240      * {@inheritDoc}
241      */
242     @Override
243     public void setFillStyle(final String fillStyle) {
244         if (LOG.isDebugEnabled()) {
245             LOG.debug("[" + id_ + "] setFillStyle(" + fillStyle + ")");
246         }
247     }
248 
249     /**
250      * {@inheritDoc}
251      */
252     @Override
253     public void setStrokeStyle(final String strokeStyle) {
254         if (LOG.isDebugEnabled()) {
255             LOG.debug("[" + id_ + "] setStrokeStyle(" + strokeStyle + ")");
256         }
257     }
258 
259     /**
260      * {@inheritDoc}
261      */
262     @Override
263     public float getLineWidth() {
264         return 1f;
265     }
266 
267     /**
268      * {@inheritDoc}
269      */
270     @Override
271     public void restore() {
272         if (LOG.isDebugEnabled()) {
273             LOG.debug("[" + id_ + "] restore()");
274         }
275     }
276 
277     /**
278      * {@inheritDoc}
279      */
280     @Override
281     public void rotate(final double angle) {
282         if (LOG.isDebugEnabled()) {
283             LOG.debug("[" + id_ + "] rotate()");
284         }
285     }
286 
287     /**
288      * {@inheritDoc}
289      */
290     @Override
291     public void save() {
292         if (LOG.isDebugEnabled()) {
293             LOG.debug("[" + id_ + "] save()");
294         }
295     }
296 
297     /**
298      * {@inheritDoc}
299      */
300     @Override
301     public void setLineWidth(final float lineWidth) {
302         if (LOG.isDebugEnabled()) {
303             LOG.debug("[" + id_ + "] setLineWidth(" + lineWidth + ")");
304         }
305     }
306 
307     /**
308      * {@inheritDoc}
309      */
310     @Override
311     public void setTransform(final double m11, final double m12,
312                     final double m21, final double m22, final double dx, final double dy) {
313         if (LOG.isDebugEnabled()) {
314             LOG.debug("[" + id_ + "] setTransform("
315                         + m11 + ", "  + m12 + ", "  + m21 + ", "  + m22 + ", "  + dx + ", "  + dy + ")");
316         }
317     }
318 
319     /**
320      * {@inheritDoc}
321      */
322     @Override
323     public void stroke() {
324         if (LOG.isDebugEnabled()) {
325             LOG.debug("[" + id_ + "] stroke()");
326         }
327     }
328 
329     /**
330      * {@inheritDoc}
331      */
332     @Override
333     public void strokeRect(final double x, final double y, final double w, final double h) {
334         if (LOG.isDebugEnabled()) {
335             LOG.debug("[" + id_ + "] strokeRect(" + x + ", "  + y + ", "  + w + ", "  + h + ")");
336         }
337     }
338 
339     /**
340      * {@inheritDoc}
341      */
342     @Override
343     public void transform(final double m11, final double m12,
344                     final double m21, final double m22, final double dx, final double dy) {
345         if (LOG.isDebugEnabled()) {
346             LOG.debug("[" + id_ + "] transform()");
347         }
348     }
349 
350     /**
351      * {@inheritDoc}
352      */
353     @Override
354     public void translate(final double x, final double y) {
355         if (LOG.isDebugEnabled()) {
356             LOG.debug("[" + id_ + "] translate()");
357         }
358     }
359 
360     /**
361      * {@inheritDoc}
362      */
363     @Override
364     public void clip(final RenderingBackend.WindingRule windingRule,
365             final org.htmlunit.javascript.host.canvas.Path2D path) {
366         if (LOG.isDebugEnabled()) {
367             LOG.debug("[" + id_ + "] clip(" + windingRule + ", " + path + ")");
368         }
369     }
370 
371     /**
372      * {@inheritDoc}
373      */
374     @Override
375     public void closePath() {
376         if (LOG.isDebugEnabled()) {
377             LOG.debug("[" + id_ + "] closePath()");
378         }
379     }
380 
381     /**
382      * {@inheritDoc}
383      */
384     @Override
385     public LineJoin getLineJoin() {
386         if (LOG.isDebugEnabled()) {
387             LOG.debug("[" + id_ + "] getLineJoin()");
388         }
389         return LineJoin.MITER;
390     }
391 
392     /**
393      * {@inheritDoc}
394      */
395     @Override
396     public void setLineJoin(final LineJoin lineJoin) {
397         if (LOG.isDebugEnabled()) {
398             LOG.debug("[" + id_ + "] setLineJoin(" + lineJoin + ")");
399         }
400     }
401 
402     /**
403      * {@inheritDoc}
404      */
405     @Override
406     public LineCap getLineCap() {
407         if (LOG.isDebugEnabled()) {
408             LOG.debug("[" + id_ + "] getLineCap()");
409         }
410         return LineCap.BUTT;
411     }
412 
413     /**
414      * {@inheritDoc}
415      */
416     @Override
417     public void setLineCap(final LineCap lineCap) {
418         if (LOG.isDebugEnabled()) {
419             LOG.debug("[" + id_ + "] setLineCap(" + lineCap + ")");
420         }
421     }
422 }