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  import java.util.concurrent.atomic.AtomicInteger;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  
24  /**
25   * The default implementation of {@link RenderingBackend}.
26   *
27   * @author Ronald Brill
28   */
29  public class NoOpRenderingBackend implements RenderingBackend {
30  
31      private static final Log LOG = LogFactory.getLog(NoOpRenderingBackend.class);
32  
33      private static final AtomicInteger ID_GENERATOR = new AtomicInteger();
34      private final int id_;
35  
36      /**
37       * Constructor.
38       * @param imageWidth the width
39       * @param imageHeight the height
40       */
41      public NoOpRenderingBackend(final int imageWidth, final int imageHeight) {
42          id_ = ID_GENERATOR.getAndIncrement();
43      }
44  
45      /**
46       * {@inheritDoc}
47       */
48      @Override
49      public double getGlobalAlpha() {
50          return 1.0;
51      }
52  
53      /**
54       * {@inheritDoc}
55       */
56      @Override
57      public void setGlobalAlpha(final double globalAlpha) {
58          if (LOG.isDebugEnabled()) {
59              LOG.debug("[" + id_ + "] setGlobalAlpha(" + globalAlpha + ")");
60          }
61      }
62  
63      /**
64       * {@inheritDoc}
65       */
66      @Override
67      public void beginPath() {
68          if (LOG.isDebugEnabled()) {
69              LOG.debug("[" + id_ + "] beginPath()");
70          }
71      }
72  
73      /**
74       * {@inheritDoc}
75       */
76      @Override
77      public void ellipse(final double x, final double y,
78              final double radiusX, final double radiusY,
79              final double rotation, final double startAngle, final double endAngle,
80              final boolean anticlockwise) {
81          if (LOG.isDebugEnabled()) {
82              LOG.debug("[" + id_ + "] ellipse()");
83          }
84      }
85  
86      /**
87       * {@inheritDoc}
88       */
89      @Override
90      public void bezierCurveTo(final double cp1x, final double cp1y,
91              final double cp2x, final double cp2y, final double x, final double y) {
92          if (LOG.isDebugEnabled()) {
93              LOG.debug("[" + id_ + "] bezierCurveTo()");
94          }
95      }
96  
97      /**
98       * {@inheritDoc}
99       */
100     @Override
101     public void arc(final double x, final double y, final double radius, final double startAngle,
102             final double endAngle, final boolean anticlockwise) {
103         if (LOG.isDebugEnabled()) {
104             LOG.debug("[" + id_ + "] arc()");
105         }
106     }
107 
108     /**
109      * {@inheritDoc}
110      */
111     @Override
112     public void clearRect(final double x, final double y, final double w, final double h) {
113         if (LOG.isDebugEnabled()) {
114             LOG.debug("[" + id_ + "] clearRect(" + x + ", " + y + ", " + w + ", " + h + ")");
115         }
116     }
117 
118     /**
119      * {@inheritDoc}
120      */
121     @Override
122     public void drawImage(final org.htmlunit.platform.image.ImageData imageData,
123             final int sx, final int sy, final Integer sWidth, final Integer sHeight,
124             final int dx, final int dy, final Integer dWidth, final Integer dHeight) throws IOException {
125         if (LOG.isDebugEnabled()) {
126             LOG.debug("[" + id_ + "] drawImage(" + sx + ", " + sy + ", " + sWidth + ", " + sHeight
127                     + "," + dx + ", " + dy + ", " + dWidth + ", " + dHeight + ")");
128         }
129     }
130 
131     /**
132      * {@inheritDoc}
133      */
134     @Override
135     public String encodeToString(final String type) throws IOException {
136         return null;
137     }
138 
139     /**
140      * {@inheritDoc}
141      */
142     @Override
143     public void fill(final WindingRule windingRule) {
144         if (LOG.isDebugEnabled()) {
145             LOG.debug("[" + id_ + "] fill()");
146         }
147     }
148 
149     /**
150      * {@inheritDoc}
151      */
152     @Override
153     public void fillRect(final double x, final double y, final double w, final double h) {
154         if (LOG.isDebugEnabled()) {
155             LOG.debug("[" + id_ + "] fillRect(" + x + ", "  + y + ", "  + w + ", "  + h + ")");
156         }
157     }
158 
159     /**
160      * {@inheritDoc}
161      */
162     @Override
163     public void fillText(final String text, final double x, final double y) {
164         if (LOG.isDebugEnabled()) {
165             LOG.debug("[" + id_ + "] fillText('" + text + "', "  + x + ", "  + y + ")");
166         }
167     }
168 
169     /**
170      * {@inheritDoc}
171      */
172     @Override
173     public byte[] getBytes(final int width, final int height, final int sx, final int sy) {
174         if (LOG.isDebugEnabled()) {
175             LOG.debug("[" + id_ + "] getBytes(" + width + ", " + height + ", " + sx + ", " + sy + ")");
176         }
177 
178         return null;
179     }
180 
181     /**
182      * {@inheritDoc}
183      */
184     @Override
185     public void lineTo(final double x, final double y) {
186         if (LOG.isDebugEnabled()) {
187             LOG.debug("[" + id_ + "] lineTo(" + x + ", " + y + ")");
188         }
189     }
190 
191     /**
192      * {@inheritDoc}
193      */
194     @Override
195     public void moveTo(final double x, final double y) {
196         if (LOG.isDebugEnabled()) {
197             LOG.debug("[" + id_ + "] moveTo(" + x + ", " + y + ")");
198         }
199     }
200 
201     /**
202      * {@inheritDoc}
203      */
204     @Override
205     public void putImageData(
206             final ByteBuffer imageDataBytes, final int imageDataHeight, final int imageDataWidth,
207             final int dx, final int dy, final int dirtyX, final int dirtyY,
208             final int dirtyWidth, final int dirtyHeight) {
209 
210         if (LOG.isDebugEnabled()) {
211             LOG.debug("[" + id_ + "] putImageData()");
212         }
213     }
214 
215     /**
216      * {@inheritDoc}
217      */
218     @Override
219     public void quadraticCurveTo(final double cpx, final double cpy,
220                     final double x, final double y) {
221         if (LOG.isDebugEnabled()) {
222             LOG.debug("[" + id_ + "] quadraticCurveTo()");
223         }
224     }
225 
226     /**
227      * {@inheritDoc}
228      */
229     @Override
230     public void rect(final double x, final double y, final double w, final double h) {
231         if (LOG.isDebugEnabled()) {
232             LOG.debug("[" + id_ + "] rect()");
233         }
234     }
235 
236     /**
237      * {@inheritDoc}
238      */
239     @Override
240     public void setFillStyle(final String fillStyle) {
241         if (LOG.isDebugEnabled()) {
242             LOG.debug("[" + id_ + "] setFillStyle(" + fillStyle + ")");
243         }
244     }
245 
246     /**
247      * {@inheritDoc}
248      */
249     @Override
250     public void setStrokeStyle(final String strokeStyle) {
251         if (LOG.isDebugEnabled()) {
252             LOG.debug("[" + id_ + "] setStrokeStyle(" + strokeStyle + ")");
253         }
254     }
255 
256     /**
257      * {@inheritDoc}
258      */
259     @Override
260     public float getLineWidth() {
261         return 1f;
262     }
263 
264     /**
265      * {@inheritDoc}
266      */
267     @Override
268     public void restore() {
269         if (LOG.isDebugEnabled()) {
270             LOG.debug("[" + id_ + "] restore()");
271         }
272     }
273 
274     /**
275      * {@inheritDoc}
276      */
277     @Override
278     public void rotate(final double angle) {
279         if (LOG.isDebugEnabled()) {
280             LOG.debug("[" + id_ + "] rotate()");
281         }
282     }
283 
284     /**
285      * {@inheritDoc}
286      */
287     @Override
288     public void save() {
289         if (LOG.isDebugEnabled()) {
290             LOG.debug("[" + id_ + "] save()");
291         }
292     }
293 
294     /**
295      * {@inheritDoc}
296      */
297     @Override
298     public void setLineWidth(final float lineWidth) {
299         if (LOG.isDebugEnabled()) {
300             LOG.debug("[" + id_ + "] setLineWidth(" + lineWidth + ")");
301         }
302     }
303 
304     /**
305      * {@inheritDoc}
306      */
307     @Override
308     public void setTransform(final double m11, final double m12,
309                     final double m21, final double m22, final double dx, final double dy) {
310         if (LOG.isDebugEnabled()) {
311             LOG.debug("[" + id_ + "] setTransform("
312                         + m11 + ", "  + m12 + ", "  + m21 + ", "  + m22 + ", "  + dx + ", "  + dy + ")");
313         }
314     }
315 
316     /**
317      * {@inheritDoc}
318      */
319     @Override
320     public void stroke() {
321         if (LOG.isDebugEnabled()) {
322             LOG.debug("[" + id_ + "] stroke()");
323         }
324     }
325 
326     /**
327      * {@inheritDoc}
328      */
329     @Override
330     public void strokeRect(final double x, final double y, final double w, final double h) {
331         if (LOG.isDebugEnabled()) {
332             LOG.debug("[" + id_ + "] strokeRect(" + x + ", "  + y + ", "  + w + ", "  + h + ")");
333         }
334     }
335 
336     /**
337      * {@inheritDoc}
338      */
339     @Override
340     public void transform(final double m11, final double m12,
341                     final double m21, final double m22, final double dx, final double dy) {
342         if (LOG.isDebugEnabled()) {
343             LOG.debug("[" + id_ + "] transform()");
344         }
345     }
346 
347     /**
348      * {@inheritDoc}
349      */
350     @Override
351     public void translate(final double x, final double y) {
352         if (LOG.isDebugEnabled()) {
353             LOG.debug("[" + id_ + "] translate()");
354         }
355     }
356 
357     /**
358      * {@inheritDoc}
359      */
360     @Override
361     public void clip(final RenderingBackend.WindingRule windingRule,
362             final org.htmlunit.javascript.host.canvas.Path2D path) {
363         if (LOG.isDebugEnabled()) {
364             LOG.debug("[" + id_ + "] clip(" + windingRule + ", " + path + ")");
365         }
366     }
367 
368     /**
369      * {@inheritDoc}
370      */
371     @Override
372     public void closePath() {
373         if (LOG.isDebugEnabled()) {
374             LOG.debug("[" + id_ + "] closePath()");
375         }
376     }
377 
378     /**
379      * {@inheritDoc}
380      */
381     @Override
382     public LineJoin getLineJoin() {
383         if (LOG.isDebugEnabled()) {
384             LOG.debug("[" + id_ + "] getLineJoin()");
385         }
386         return LineJoin.MITER;
387     }
388 
389     /**
390      * {@inheritDoc}
391      */
392     @Override
393     public void setLineJoin(final LineJoin lineJoin) {
394         if (LOG.isDebugEnabled()) {
395             LOG.debug("[" + id_ + "] setLineJoin(" + lineJoin + ")");
396         }
397     }
398 
399     /**
400      * {@inheritDoc}
401      */
402     @Override
403     public LineCap getLineCap() {
404         if (LOG.isDebugEnabled()) {
405             LOG.debug("[" + id_ + "] getLineCap()");
406         }
407         return LineCap.BUTT;
408     }
409 
410     /**
411      * {@inheritDoc}
412      */
413     @Override
414     public void setLineCap(final LineCap lineCap) {
415         if (LOG.isDebugEnabled()) {
416             LOG.debug("[" + id_ + "] setLineCap(" + lineCap + ")");
417         }
418     }
419 
420     /**
421      * {@inheritDoc}
422      */
423     @Override
424     public TextAlign getTextAlign() {
425         if (LOG.isDebugEnabled()) {
426             LOG.debug("[" + id_ + "] getTextAlign()");
427         }
428         return TextAlign.START;
429     }
430 
431     /**
432      * {@inheritDoc}
433      */
434     @Override
435     public void setTextAlign(final TextAlign textAlign) {
436         if (LOG.isDebugEnabled()) {
437             LOG.debug("[" + id_ + "] setTextAlign(" + textAlign + ")");
438         }
439     }
440 
441     /**
442      * {@inheritDoc}
443      */
444     @Override
445     public TextBaseline getTextBaseline() {
446         if (LOG.isDebugEnabled()) {
447             LOG.debug("[" + id_ + "] getTextBaseline()");
448         }
449         return TextBaseline.ALPHABETIC;
450     }
451 
452     /**
453      * {@inheritDoc}
454      */
455     @Override
456     public void setTextBaseline(final TextBaseline textBaseline) {
457         if (LOG.isDebugEnabled()) {
458             LOG.debug("[" + id_ + "] setTextBaseline(" + textBaseline + ")");
459         }
460     }
461 }