Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
  3.  *
  4.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  5.  *
  6.  * NetSurf is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; version 2 of the License.
  9.  *
  10.  * NetSurf is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18.  
  19. /** \file
  20.  * Target independent plotting (interface).
  21.  */
  22.  
  23. #ifndef _NETSURF_DESKTOP_PLOTTERS_H_
  24. #define _NETSURF_DESKTOP_PLOTTERS_H_
  25.  
  26. #include <stdbool.h>
  27. #include "css/css.h"
  28. #include "content/content.h"
  29. #include "desktop/plot_style.h"
  30.  
  31. struct bitmap;
  32.  
  33. typedef unsigned long bitmap_flags_t;
  34. #define BITMAPF_NONE 0
  35. #define BITMAPF_REPEAT_X 1
  36. #define BITMAPF_REPEAT_Y 2
  37.  
  38.  
  39. /** Set of target specific plotting functions.
  40.  *
  41.  * The functions are:
  42.  *  arc         - Plots an arc, around (x,y), from anticlockwise from angle1 to
  43.  *                angle2. Angles are measured anticlockwise from horizontal, in
  44.  *                degrees.
  45.  *  disc        - Plots a circle, centered on (x,y), which is optionally filled.
  46.  *  line        - Plots a line from (x0,y0) to (x1,y1). Coordinates are at
  47.  *                centre of line width/thickness.
  48.  *  path        - Plots a path consisting of cubic Bezier curves. Line colour is
  49.  *                given by c and fill colour is given by fill.
  50.  *  polygon     - Plots a filled polygon with straight lines between points.
  51.  *                The lines around the edge of the ploygon are not plotted. The
  52.  *                polygon is filled with the non-zero winding rule.
  53.  *  rectangle   - Plots a rectangle outline. The line can be solid, dotted or
  54.  *                dashed. Top left corner at (x0,y0) and rectangle has given
  55.  *                width and height.
  56.  *  fill        - Plots a filled rectangle. Top left corner at (x0,y0), bottom
  57.  *                right corner at (x1,y1). Note: (x0,y0) is inside filled area,
  58.  *                but (x1,y1) is below and to the right. See diagram below.
  59.  *  clip        - Sets a clip rectangle for subsequent plots.
  60.  *  text        - Plots text. (x,y) is the coordinate of the left hand side of
  61.  *                the text's baseline. The text is UTF-8 encoded. The colour, c,
  62.  *                is the colour of the text. Background colour, bg, may be used
  63.  *                optionally to attempt to provide anti-aliased text without
  64.  *                screen reads. Font information is provided in the style.
  65.  *  bitmap      - Tiled plot of a bitmap image. (x,y) gives the top left
  66.  *                coordinate of an explicitly placed tile. From this tile the
  67.  *                image can repeat in all four directions -- up, down, left and
  68.  *                right -- to the extents given by the current clip rectangle.
  69.  *                The bitmap_flags say whether to tile in the x and y
  70.  *                directions. If not tiling in x or y directions, the single
  71.  *                image is plotted. The width and height give the dimensions
  72.  *                the image is to be scaled to.
  73.  *  group_start - Start of a group of objects. Used when plotter implements
  74.  *                export to a vector graphics file format. (Optional.)
  75.  *  group_end   - End of the most recently started group. (Optional.)
  76.  *  flush       - Only used internally by the knockout code. Should be NULL in
  77.  *                any front end display plotters or export plotters.
  78.  *
  79.  * Plotter options:
  80.  *  option_knockout     - Optimisation particularly for unaccelerated screen
  81.  *                        redraw. It tries to avoid plotting to the same area
  82.  *                        more than once. See desktop/knockout.c
  83.  *
  84.  * Coordinates are from top left of canvas and (0,0) is the top left grid
  85.  * denomination. If a "fill" is drawn from (0,0) to (4,3), the result is:
  86.  *
  87.  *     0 1 2 3 4 5
  88.  *    +-+-+-+-+-+-
  89.  *  0 |#|#|#|#| |
  90.  *    +-+-+-+-+-+-
  91.  *  1 |#|#|#|#| |
  92.  *    +-+-+-+-+-+-
  93.  *  2 |#|#|#|#| |
  94.  *    +-+-+-+-+-+-
  95.  *  3 | | | | | |
  96.  */
  97. struct plotter_table {
  98.         /* clipping operations */
  99.         bool (*clip)(const struct rect *clip);
  100.  
  101.         /* shape primatives */
  102.         bool (*arc)(int x, int y, int radius, int angle1, int angle2, const plot_style_t *pstyle);
  103.         bool (*disc)(int x, int y, int radius, const plot_style_t *pstyle);
  104.         bool (*line)(int x0, int y0, int x1, int y1, const plot_style_t *pstyle);
  105.         bool (*rectangle)(int x0, int y0, int x1, int y1, const plot_style_t *pstyle);
  106.         bool (*polygon)(const int *p, unsigned int n, const plot_style_t *pstyle);
  107.  
  108.         /* complex path (for SVG) */
  109.         bool (*path)(const float *p, unsigned int n, colour fill, float width,
  110.                         colour c, const float transform[6]);
  111.  
  112.         /* Image */
  113.         bool (*bitmap)(int x, int y, int width, int height,
  114.                         struct bitmap *bitmap, colour bg,
  115.                         bitmap_flags_t flags);
  116.  
  117.         /**
  118.          * Text.
  119.          *
  120.          * \param  x       x coordinate
  121.          * \param  y       y coordinate
  122.          * \param  text    UTF-8 string to plot
  123.          * \param  length  length of string, in bytes
  124.          * \param  fstyle  plot style for this text
  125.          * \return  true on success, false on error and error reported
  126.          */
  127.         bool (*text)(int x, int y, const char *text, size_t length,
  128.                         const plot_font_style_t *fstyle);
  129.  
  130.         /* optional callbacks */
  131.         bool (*group_start)(const char *name);  /**< optional, may be NULL */
  132.         bool (*group_end)(void);                /**< optional, may be NULL */
  133.         bool (*flush)(void);                    /**< optional, may be NULL */
  134.  
  135.         /* flags */
  136.         bool option_knockout;   /**< set if knockout rendering is required */
  137. };
  138.  
  139. enum path_command {
  140.         PLOTTER_PATH_MOVE,
  141.         PLOTTER_PATH_CLOSE,
  142.         PLOTTER_PATH_LINE,
  143.         PLOTTER_PATH_BEZIER,
  144. };
  145.  
  146.  
  147. #endif
  148.