javaquery/canvas/src/main/java/net/java/html/canvas/spi/GraphicsEnvironment.java
author Anton Epple <toni.epple@eppleton.de>
Wed, 12 Feb 2014 09:14:20 +0100
branchcanvas
changeset 1447 3e3fb431d2b7
parent 1303 3d62ad46d744
child 1450 0726c9779524
permissions -rw-r--r--
More JavaDoc improvements.
     1 /**
     2  * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
     3  * <jaroslav.tulach@apidesign.org>
     4  *
     5  * This program is free software: you can redistribute it and/or modify it under
     6  * the terms of the GNU General Public License as published by the Free Software
     7  * Foundation, version 2 of the License.
     8  *
     9  * This program is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    12  * details.
    13  *
    14  * You should have received a copy of the GNU General Public License along with
    15  * this program. Look for COPYING file in the top folder. If not, see
    16  * http://opensource.org/licenses/GPL-2.0.
    17  */
    18 package net.java.html.canvas.spi;
    19 
    20 import net.java.html.canvas.Dimension;
    21 import net.java.html.canvas.Image;
    22 import net.java.html.canvas.Style;
    23 
    24 /**
    25  * Provider API for Canvas. Implement this to add support for your platform.
    26  *
    27  * @author antonepple
    28  */
    29 public interface GraphicsEnvironment {
    30 
    31     /**
    32      * Adds path elements to the current path to make an arc.
    33      *
    34      * @param centerX the center x position of the arc.
    35      * @param centerY the center y position of the arc.
    36      * @param startAngle the startAngle of the arc
    37      * @param radius the radius of the arc.
    38      * @param endAngle the endAngle of the arc
    39      * @param ccw the direction of the arc (counterclockwise)
    40      */
    41     public void arc(double centerX,
    42             double centerY,
    43             double startAngle,
    44             double radius,
    45             double endAngle,
    46             boolean ccw);
    47 
    48     /**
    49      * Adds segments to the current path to make an arc.
    50      *
    51      * @param x1 the X coordinate of the first point of the arc.
    52      * @param y1 the Y coordinate of the first point of the arc.
    53      * @param x2 the X coordinate of the second point of the arc.
    54      * @param y2 the Y coordinate of the second point of the arc.
    55      * @param radius the radius of the arc in the range {0.0-positive infinity}.
    56      */
    57     public void arcTo(double x1,
    58             double y1,
    59             double x2,
    60             double y2,
    61             double radius);
    62 
    63     /**
    64      * Returns true if the the given x,y point is inside the path.
    65      *
    66      * @param x the X coordinate to use for the check.
    67      * @param y the Y coordinate to use for the check.
    68      * @return true if the point given is inside the path, false otherwise.
    69      */
    70     public boolean isPointInPath(double x, double y);
    71 
    72     /**
    73      * Fills the path with the current fill paint.
    74      */
    75     public void fill();
    76 
    77     /**
    78      * Strokes the path with the current stroke paint.
    79      */
    80     public void stroke();
    81 
    82     /**
    83      * Starts a Path
    84      */
    85     public void beginPath();
    86 
    87     /**
    88      * Closes the path.
    89      */
    90     public void closePath();
    91 
    92     /**
    93      * Clips using the current path
    94      */
    95     public void clip();
    96 
    97     /**
    98      * Issues a move command for the current path to the given x,y coordinate.
    99      *
   100      * @param x the X position for the move to command.
   101      * @param y the Y position for the move to command.
   102      */
   103     public void moveTo(double x, double y);
   104 
   105     /**
   106      * Adds segments to the current path to make a line at the given x,y
   107      * coordinate.
   108      *
   109      * @param x the X coordinate of the ending point of the line.
   110      * @param y the Y coordinate of the ending point of the line.
   111      */
   112     public void lineTo(double x, double y);
   113 
   114     /**
   115      * Adds segments to the current path to make a quadratic curve.
   116      *
   117      * @param cpx the X coordinate of the control point
   118      * @param cpy the Y coordinate of the control point
   119      * @param x the X coordinate of the end point
   120      * @param y the Y coordinate of the end point
   121      */
   122     public void quadraticCurveTo(double cpx, double cpy, double x, double y);
   123 
   124     /**
   125      * Adds segments to the current path to make a cubic bezier curve.
   126      *
   127      * @param cp1x the X coordinate of first bezier control point.
   128      * @param cp1y the Y coordinate of the first bezier control point.
   129      * @param cp2x the X coordinate of the second bezier control point.
   130      * @param cp2y the Y coordinate of the second bezier control point.
   131      * @param x the X coordinate of the end point.
   132      * @param y the Y coordinate of the end point.
   133      */
   134     public void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
   135 
   136     /**
   137      * Fills a rectangle using the current fill paint.
   138      *
   139      * @param x the X position of the upper left corner of the rectangle.
   140      * @param y the Y position of the upper left corner of the rectangle.
   141      * @param width the width of the rectangle.
   142      * @param height the height of the rectangle.
   143      */
   144     public void fillRect(double x, double y, double width, double height);
   145 
   146     /**
   147      * Strokes a rectangle using the current stroke paint.
   148      *
   149      * @param x the X position of the upper left corner of the rectangle.
   150      * @param y the Y position of the upper left corner of the rectangle.
   151      * @param width the width of the rectangle.
   152      * @param height the height of the rectangle.
   153      */
   154     public void strokeRect(double x, double y, double width, double height);
   155 
   156     /**
   157      * Clears a portion of the canvas with a transparent color value.
   158      *
   159      * @param x X position of the upper left corner of the rectangle.
   160      * @param y Y position of the upper left corner of the rectangle.
   161      * @param width width of the rectangle.
   162      * @param height height of the rectangle.
   163      */
   164     public void clearRect(double x, double y, double width, double height);
   165 
   166     /**
   167      * Clears a portion of the canvas with a transparent color value.
   168      *
   169      * @param x X position of the upper left corner of the rectangle.
   170      * @param y Y position of the upper left corner of the rectangle.
   171      * @param width width of the rectangle.
   172      * @param height height of the rectangle.
   173      */
   174     public void rect(double x, double y, double width, double height);
   175 
   176     /**
   177      * Saves the following attributes onto a stack.
   178      * <ul>
   179      * <li>Global Alpha</li>
   180      * <li>Global Blend Operation</li>
   181      * <li>Transform</li>
   182      * <li>Fill Paint</li>
   183      * <li>Stroke Paint</li>
   184      * <li>Line Width</li>
   185      * <li>Line Cap</li>
   186      * <li>Line Join</li>
   187      * <li>Miter Limit</li>
   188      * <li>Number of Clip Paths</li>
   189      * <li>Font</li>
   190      * <li>Text Align</li>
   191      * <li>Text Baseline</li>
   192      * <li>Effect</li>
   193      * <li>Fill Rule</li>
   194      * </ul>
   195      * This method does NOT alter the current state in any way. Also, not that
   196      * the current path is not saved.
   197      */
   198     public void save();
   199 
   200     /**
   201      * Pops the state off of the stack, setting the following attributes to
   202      * their value at the time when that state was pushed onto the stack. If the
   203      * stack is empty then nothing is changed.
   204      *
   205      * <ul>
   206      * <li>Global Alpha</li>
   207      * <li>Global Blend Operation</li>
   208      * <li>Transform</li>
   209      * <li>Fill Paint</li>
   210      * <li>Stroke Paint</li>
   211      * <li>Line Width</li>
   212      * <li>Line Cap</li>
   213      * <li>Line Join</li>
   214      * <li>Miter Limit</li>
   215      * <li>Number of Clip Paths</li>
   216      * <li>Font</li>
   217      * <li>Text Align</li>
   218      * <li>Text Baseline</li>
   219      * <li>Effect</li>
   220      * <li>Fill Rule</li>
   221      * </ul>
   222      */
   223     public void restore();
   224 
   225     /**
   226      * Rotates the current transform in degrees.
   227      *
   228      * @param angle value in degrees to rotate the current transform.
   229      */
   230     public void rotate(double angle);
   231 
   232     /**
   233      * Concatenates the input with the current transform.
   234      *
   235      * @param a - the X coordinate scaling element of the 3x4 matrix
   236      * @param b - the Y coordinate shearing element of the 3x4 matrix
   237      * @param c - the X coordinate shearing element of the 3x4 matrix
   238      * @param d - the Y coordinate scaling element of the 3x4 matrix
   239      * @param e - the X coordinate translation element of the 3x4 matrix
   240      * @param f - the Y coordinate translation element of the 3x4 matrix
   241      */
   242     public void transform(double a, double b, double c, double d, double e, double f);
   243 
   244     /**
   245      * Concatenates the input with the current transform.
   246      *
   247      * @param a - the X coordinate scaling element of the 3x4 matrix
   248      * @param b - the Y coordinate shearing element of the 3x4 matrix
   249      * @param c - the X coordinate shearing element of the 3x4 matrix
   250      * @param d - the Y coordinate scaling element of the 3x4 matrix
   251      * @param e - the X coordinate translation element of the 3x4 matrix
   252      * @param f - the Y coordinate translation element of the 3x4 matrix
   253      */
   254     public void setTransform(double a, double b, double c, double d, double e, double f);
   255 
   256     /**
   257      * Translates the current transform by x, y.
   258      *
   259      * @param x value to translate along the x axis.
   260      * @param y value to translate along the y axis.
   261      */
   262     public void translate(double x, double y);
   263 
   264     /**
   265      * Scales the current transform by x, y.
   266      *
   267      * @param x value to scale in the x axis.
   268      * @param y value to scale in the y axis.
   269      */
   270     public void scale(double x, double y);
   271 
   272     /**
   273      * Draws an image at the given x, y position using the width and height of
   274      * the given image.
   275      *
   276      * @param image the image to be drawn.
   277      * @param x the X coordinate on the destination for the upper left of the
   278      * image.
   279      * @param y the Y coordinate on the destination for the upper left of the
   280      * image.
   281      * @return the native Image for caching.
   282      */
   283     public Object drawImage(Image image, double x, double y, Object nativeImage);
   284 
   285     /**
   286      * Draws an image into the given destination rectangle of the canvas. The
   287      * Image is scaled to fit into the destination rectagnle.
   288      *
   289      * @param image the image to be drawn.
   290      * @param x the X coordinate on the destination for the upper left of the
   291      * image.
   292      * @param y the Y coordinate on the destination for the upper left of the
   293      * image.
   294      * @param width the width of the destination rectangle.
   295      * @param height the height of the destination rectangle.
   296      * @return the native Image for caching.
   297      *
   298      */
   299     public Object drawImage(Image image, double x, double y, double width, double height, Object nativeImage);
   300 
   301     /**
   302      * Draws the current source rectangle of the given image to the given
   303      * destination rectangle of the Canvas.
   304      *
   305      * @param image the image to be drawn.
   306      * @param sx the source rectangle's X coordinate position.
   307      * @param sy the source rectangle's Y coordinate position.
   308      * @param sWidth the source rectangle's width.
   309      * @param sHeight the source rectangle's height.
   310      * @param x the destination rectangle's X coordinate position.
   311      * @param y the destination rectangle's Y coordinate position.
   312      * @param width the destination rectangle's width.
   313      * @param height the destination rectangle's height.
   314      * @return the native Image for caching.
   315      */
   316     public Object drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height, Object nativeImage);
   317 
   318     /**
   319      * Get the width of this Image
   320      *
   321      * @param image the image to measure
   322      * @param nativeImage the cached native Image or null
   323      * @return the width of the image
   324      */
   325     public int getWidth(Image image, Object nativeImage);
   326 
   327     /**
   328      * Get the height of this Image
   329      *
   330      * @param image the image to measure
   331      * @param nativeImage the cached native Image or null
   332      * @return the height of the image
   333      */
   334     public int getHeight(Image image, Object nativeImage);
   335 
   336     /**
   337      * When implementing you can return an Object of your choice to enable
   338      * caching. Returning null means no caching. When caching is enabled, and
   339      * the cache hasn't been invalidated, the Object you returned will be passed
   340      * as a parameter.
   341      *
   342      * @param style The style object you should use to create your native style
   343      * @param nativeStyle your native object if cached, null otherwise
   344      * @return return native Object for caching
   345      *
   346      */
   347     public Object setFillStyle(Style style, Object nativeStyle);
   348 
   349     /**
   350      * When implementing you can return an Object of your choice to enable
   351      * caching. Returning null means no caching. When caching is enabled, and
   352      * the cache hasn't been invalidated, the Object you returned will be passed
   353      * as a parameter.
   354      *
   355      * @param style The style object you should use to create your native style
   356      * @param nativeStyle your native object if cached, null otherwise
   357      * @return return native Object for caching
   358      *
   359      */
   360     public Object setStrokeStyle(Style style, Object nativeStyle);
   361 
   362 //    public void setShadowColor(String color);
   363 //
   364 //    public void setShadowBlur(double blur);
   365 //
   366 //    public void setShadowOffsetX(double x);
   367 //
   368 //    public void setShadowOffsetY(double y);
   369 //    
   370 //    public String getShadowColor();
   371 //
   372 //    public double getShadowBlur();
   373 //
   374 //    public double getShadowOffsetX();
   375 //
   376 //    public double getShadowOffsetY();
   377     /**
   378      * Gets the current stroke line cap.
   379      *
   380      * @return {@code StrokeLineCap} with a value of Butt, Round, or Square.
   381      */
   382     public String getLineCap();
   383 
   384     /**
   385      * Sets the current stroke line cap.
   386      *
   387      * @param style a value of Butt, Round, or Square.
   388      */
   389     public void setLineCap(String style);
   390 
   391     /**
   392      * Gets the current stroke line join.
   393      *
   394      * @return a value of Miter, Bevel, or Round.
   395      */
   396     public String getLineJoin();
   397 
   398     /**
   399      * Sets the current stroke line join.
   400      *
   401      * @param style with a value of Miter, Bevel, or Round.
   402      */
   403     public void setLineJoin(String style);
   404 
   405     /**
   406      * Gets the current line width.
   407      *
   408      * @return value between 0 and infinity.
   409      */
   410     public double getLineWidth();
   411 
   412     /**
   413      * Sets the current line width.
   414      *
   415      * @param width value in the range {0-positive infinity}, with any other
   416      * value being ignored and leaving the value unchanged.
   417      */
   418     public void setLineWidth(double width);
   419 
   420     /**
   421      * Gets the current miter limit. v
   422      *
   423      * @return the miter limit value in the range {@code 0.0-positive infinity}
   424      */
   425     public double getMiterLimit();
   426 
   427     /**
   428      * Sets the current miter limit.
   429      *
   430      * @param limit miter limit value between 0 and positive infinity with any
   431      * other value being ignored and leaving the value unchanged.
   432      */
   433     public void setMiterLimit(double limit);
   434 
   435     /**
   436      * Gets the current Font.
   437      *
   438      * @return the Font
   439      */
   440     public String getFont();
   441 
   442     /**
   443      * Sets the current Font.
   444      *
   445      */
   446     public void setFont(String font);
   447 
   448     /**
   449      * Gets the current {@code TextAlignment}.
   450      *
   451      * @return TextAlignment with values of Left, Center, Right, or Justify.
   452      */
   453     public String getTextAlign();
   454 
   455     /**
   456      * Defines horizontal text alignment, relative to the text origin.
   457      *
   458      * @param textAlign with values of Left, Center, Right.
   459      */
   460     public void setTextAlign(String textAlign);
   461 
   462     /**
   463      * Sets the current Text Baseline.
   464      *
   465      * @param baseline with values of Top, Center, Baseline, or Bottom
   466      */
   467     public String getTextBaseline();
   468 
   469     /**
   470      * Sets the current Text Baseline.
   471      *
   472      * @param baseline with values of Top, Center, Baseline, or Bottom
   473      */
   474     public void setTextBaseline(String baseline);
   475 
   476     /**
   477      * Fills the given string of text at position x, y (0,0 at top left) with
   478      * the current fill paint attribute.
   479      *
   480      * @param text the string of text.
   481      * @param x position on the x axis.
   482      * @param y position on the y axis.
   483      */
   484     public void fillText(String text, double x, double y);
   485 
   486     /**
   487      * Fills text and includes a maximum width of the string.
   488      *
   489      * If the width of the text extends past max width, then it will be sized to
   490      * fit.
   491      *
   492      * @param text the string of text.
   493      * @param x position on the x axis.
   494      * @param y position on the y axis.
   495      * @param maxWidth maximum width the text string can have.
   496      */
   497     public void fillText(String text, double x, double y, double maxWidth);
   498 
   499     /**
   500      * The Dimension of this text using the current Font settings
   501      *
   502      * @param text
   503      * @return the Dimension of this text using the current Font settings
   504      */
   505     public Dimension measureText(String text);
   506 
   507     /**
   508      * draws the given string of text at position x, y (0,0 at top left) with
   509      * the current stroke paint attribute.
   510      *
   511      * @param text the string of text.
   512      * @param x position on the x axis.
   513      * @param y position on the y axis.
   514      */
   515     public void strokeText(String text, double x, double y);
   516 
   517     /**
   518      * Draws text with stroke paint and includes a maximum width of the string.
   519      *
   520      * If the width of the text extends past max width, then it will be sized to
   521      * fit.
   522      *
   523      * @param text the string of text.
   524      * @param x position on the x axis.
   525      * @param y position on the y axis.
   526      * @param maxWidth maximum width the text string can have.
   527      */
   528     public void strokeText(String text, double x, double y, double maxWidth);
   529 
   530 //    public ImageData createPixelMap(double x, double y);
   531 //
   532 //    public ImageData createPixelMap(ImageData imageData);
   533 //
   534 //    public ImageData getPixelMap(double x, double y, double width, double height);
   535 //
   536 //    public void putPixelMap(ImageData imageData, double x, double y);
   537 //
   538 //    public void putPixelMap(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
   539     /**
   540      * Sets the global alpha of the current state.
   541      *
   542      * @param alpha value in the range {@code 0.0-1.0}. The value is clamped if
   543      * it is out of range.
   544      */
   545     public void setGlobalAlpha(double alpha);
   546 
   547     /**
   548      * Get the global alpha of the current state.
   549      *
   550      * @return alpha value in the range {@code 0.0-1.0}.
   551      */
   552     public double getGlobalAlpha();
   553 
   554     /**
   555      * Sets the global blend mode.
   556      *
   557      * @param operation the BlendMode that will be set.
   558      */
   559     public void setGlobalCompositeOperation(String operation);
   560 
   561     /**
   562      * Gets the global blend mode.
   563      *
   564      * @return the global BlendMode of the current state.
   565      */
   566     public String getGlobalCompositeOperation();
   567 
   568     /**
   569      * Get the height of this GraphicsContext (which should be the same as the
   570      * enclosing canvas height)
   571      *
   572      * @return the height of this GraphicsContext
   573      */
   574     public int getHeight();
   575 
   576     /**
   577      * Get the width of this GraphicsContext (which should be the same as the
   578      * enclosing canvas height)
   579      *
   580      * @return the width of this GraphicsContext
   581      */
   582     public int getWidth();
   583 
   584 //    public void setHeight(int height);
   585 //
   586 //    public void setWidth(int width);
   587      /**
   588      * Merges two images drawing one on top of the other and returning the
   589      * result.
   590      *
   591      * @param a the lower Image
   592      * @param b the upper Image
   593      * @param cachedA the native cached Image, if available, or null.
   594      * @param cachedB the native cached Image, if available, or null.
   595      * @return
   596      */  
   597     public Object mergeImages(Image a, Image b, Object cachedA, Object cachedB);
   598 }