javaquery/canvas/src/main/java/net/java/html/canvas/spi/GraphicsEnvironment.java
author Anton Epple <toni.epple@eppleton.de>
Thu, 26 Sep 2013 14:20:18 -0700
branchcanvas
changeset 1302 e67363288df1
parent 1263 088331d4cb76
child 1303 3d62ad46d744
permissions -rw-r--r--
refactoring for API review
     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     public void arc(double centerX,
    32             double centerY,
    33             double startAngle,
    34             double radius,
    35             double endAngle,
    36             boolean ccw);
    37 
    38     public void arcTo(double x1,
    39             double y1,
    40             double x2,
    41             double y2,
    42             double r);
    43 
    44     public boolean isPointInPath(double x, double y);
    45 
    46     public void fill();
    47 
    48     public void stroke();
    49 
    50     public void beginPath();
    51 
    52     public void closePath();
    53 
    54     public void clip();
    55 
    56     public void moveTo(double x, double y);
    57 
    58     public void lineTo(double x, double y);
    59 
    60     public void quadraticCurveTo(double cpx, double cpy, double x, double y);
    61 
    62     public void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
    63 
    64     public void fillRect(double x, double y, double width, double height);
    65 
    66     public void strokeRect(double x, double y, double width, double height);
    67 
    68     public void clearRect(double x, double y, double width, double height);
    69 
    70     public void rect(double x, double y, double width, double height);
    71 
    72     public void save();
    73 
    74     public void restore();
    75 
    76     public void rotate(double angle);
    77 
    78     public void transform(double a, double b, double c, double d, double e, double f);
    79 
    80     public void setTransform(double a, double b, double c, double d, double e, double f);
    81 
    82     public void translate(double x, double y);
    83 
    84     public void scale(double x, double y);
    85 
    86     public Object drawImage(Image image, double x, double y, Object nativeImage);
    87 
    88     public Object drawImage(Image image, double x, double y, double width, double height, Object nativeImage);
    89 
    90     public Object drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height, Object nativeImage);
    91 
    92     public int getWidth(Image image, Object nativeImage);
    93 
    94     public int getHeight(Image image, Object nativeImage);
    95 
    96     /**
    97      * When implementing you can return an Object of your choice to enable
    98      * caching. Returning null means no caching. When caching is enabled, and
    99      * the cache hasn't been invalidated, the Object you returned will be passed
   100      * as a parameter.
   101      *
   102      * @param style The style object you should use to create your native style
   103      * @param nativeStyle your native object if cached, null otherwise
   104      * @return return native Object for caching
   105      *
   106      */
   107     public Object setFillStyle(Style style, Object nativeStyle);
   108 
   109     /**
   110      * When implementing you can return an Object of your choice to enable
   111      * caching. Returning null means no caching. When caching is enabled, and
   112      * the cache hasn't been invalidated, the Object you returned will be passed
   113      * as a parameter.
   114      *
   115      * @param style The style object you should use to create your native style
   116      * @param nativeStyle your native object if cached, null otherwise
   117      * @return return native Object for caching
   118      *
   119      */
   120     public Object setStrokeStyle(Style style, Object nativeStyle);
   121 
   122 //    public void setShadowColor(String color);
   123 //
   124 //    public void setShadowBlur(double blur);
   125 //
   126 //    public void setShadowOffsetX(double x);
   127 //
   128 //    public void setShadowOffsetY(double y);
   129 //    
   130 //    public String getShadowColor();
   131 //
   132 //    public double getShadowBlur();
   133 //
   134 //    public double getShadowOffsetX();
   135 //
   136 //    public double getShadowOffsetY();
   137     /**
   138      * Gets the current stroke line cap.
   139      *
   140      * @return {@code StrokeLineCap} with a value of Butt, Round, or Square.
   141      */
   142     public String getLineCap();
   143 
   144     /**
   145      * Sets the current stroke line cap.
   146      *
   147      * @param style a value of Butt, Round, or Square.
   148      */
   149     public void setLineCap(String style);
   150 
   151     /**
   152      * Gets the current stroke line join.
   153      *
   154      * @return a value of Miter, Bevel, or Round.
   155      */
   156     public String getLineJoin();
   157 
   158     /**
   159      * Sets the current stroke line join.
   160      *
   161      * @param style with a value of Miter, Bevel, or Round.
   162      */
   163     public void setLineJoin(String style);
   164 
   165     /**
   166      * Gets the current line width.
   167      *
   168      * @return value between 0 and infinity.
   169      */
   170     public double getLineWidth();
   171 
   172     /**
   173      * Sets the current line width.
   174      *
   175      * @param width value in the range {0-positive infinity}, with any other
   176      * value being ignored and leaving the value unchanged.
   177      */
   178     public void setLineWidth(double width);
   179 
   180     /**
   181      * Gets the current miter limit. v
   182      *
   183      * @return the miter limit value in the range {@code 0.0-positive infinity}
   184      */
   185     public double getMiterLimit();
   186 
   187     /**
   188      * Sets the current miter limit.
   189      *
   190      * @param limit miter limit value between 0 and positive infinity with any
   191      * other value being ignored and leaving the value unchanged.
   192      */
   193     public void setMiterLimit(double limit);
   194 
   195     /**
   196      * Gets the current Font.
   197      *
   198      * @return the Font
   199      */
   200     public String getFont();
   201 
   202     /**
   203      * Sets the current Font.
   204      *
   205      */
   206     public void setFont(String font);
   207 
   208     /**
   209      * Gets the current {@code TextAlignment}.
   210      *
   211      * @return TextAlignment with values of Left, Center, Right, or Justify.
   212      */
   213     public String getTextAlign();
   214 
   215     /**
   216      * Defines horizontal text alignment, relative to the text origin.
   217      *
   218      * @param textAlign with values of Left, Center, Right.
   219      */
   220     public void setTextAlign(String textAlign);
   221 
   222     /**
   223      * Sets the current Text Baseline.
   224      *
   225      * @param baseline with values of Top, Center, Baseline, or Bottom
   226      */
   227     public String getTextBaseline();
   228 
   229     /**
   230      * Sets the current Text Baseline.
   231      *
   232      * @param baseline with values of Top, Center, Baseline, or Bottom
   233      */
   234     public void setTextBaseline(String baseline);
   235 
   236     /**
   237      * Fills the given string of text at position x, y (0,0 at top left) with
   238      * the current fill paint attribute.
   239      *
   240      * @param text the string of text.
   241      * @param x position on the x axis.
   242      * @param y position on the y axis.
   243      */
   244     public void fillText(String text, double x, double y);
   245 
   246     /**
   247      * Fills text and includes a maximum width of the string.
   248      *
   249      * If the width of the text extends past max width, then it will be sized to
   250      * fit.
   251      *
   252      * @param text the string of text.
   253      * @param x position on the x axis.
   254      * @param y position on the y axis.
   255      * @param maxWidth maximum width the text string can have.
   256      */
   257     public void fillText(String text, double x, double y, double maxWidth);
   258 
   259     /**
   260      * The Dimension of this text using the current Font settings
   261      *
   262      * @param text
   263      * @return the Dimension of this text using the current Font settings
   264      */
   265     public Dimension measureText(String text);
   266 
   267     /**
   268      * draws the given string of text at position x, y (0,0 at top left) with
   269      * the current stroke paint attribute.
   270      *
   271      * @param text the string of text.
   272      * @param x position on the x axis.
   273      * @param y position on the y axis.
   274      */
   275     public void strokeText(String text, double x, double y);
   276 
   277     /**
   278      * Draws text with stroke paint and includes a maximum width of the string.
   279      *
   280      * If the width of the text extends past max width, then it will be sized to
   281      * fit.
   282      *
   283      * @param text the string of text.
   284      * @param x position on the x axis.
   285      * @param y position on the y axis.
   286      * @param maxWidth maximum width the text string can have.
   287      */
   288     public void strokeText(String text, double x, double y, double maxWidth);
   289 
   290 //    public ImageData createPixelMap(double x, double y);
   291 //
   292 //    public ImageData createPixelMap(ImageData imageData);
   293 //
   294 //    public ImageData getPixelMap(double x, double y, double width, double height);
   295 //
   296 //    public void putPixelMap(ImageData imageData, double x, double y);
   297 //
   298 //    public void putPixelMap(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
   299     /**
   300      * Sets the global alpha of the current state.
   301      *
   302      * @param alpha value in the range {@code 0.0-1.0}. The value is clamped if
   303      * it is out of range.
   304      */
   305     public void setGlobalAlpha(double alpha);
   306 
   307     public double getGlobalAlpha();
   308 
   309     public void setGlobalCompositeOperation(String operation);
   310 
   311     public String getGlobalCompositeOperation();
   312 
   313     public int getHeight();
   314 
   315     public int getWidth();
   316 
   317 //    public void setHeight(int height);
   318 //
   319 //    public void setWidth(int width);
   320 
   321     public Object mergeImages(Image a, Image b, Object cachedA, Object cachedB);
   322 }