output: Cache the script ltr versus rtl direction.
[pspp] / src / output / render.h
index cfba52e967b08616fbb22a39589d13911c9126c9..c10f23716060924897da482dc106128fbd5cdcf3 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2009 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2010, 2011, 2014 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
 #include <stdbool.h>
 #include <stddef.h>
-#include <output/table-provider.h>
+#include "output/table-provider.h"
 
-struct table;
+struct table_item;
 
 enum render_line_style
   {
-    RENDER_LINE_NONE,           /* No line. */
-    RENDER_LINE_SINGLE,         /* Single line. */
-    RENDER_LINE_DOUBLE,         /* Double line. */
+    RENDER_LINE_NONE,
+    RENDER_LINE_SINGLE,
+    RENDER_LINE_DASHED,
+    RENDER_LINE_THICK,
+    RENDER_LINE_THIN,
+    RENDER_LINE_DOUBLE,
     RENDER_N_LINES
   };
 
+/* Parameters for rendering a table_item to a device.
+
+
+   Coordinate system
+   =================
+
+   The rendering code assumes that larger 'x' is to the right and larger 'y'
+   toward the bottom of the page.
+
+   The rendering code assumes that the table being rendered has its upper left
+   corner at (0,0) in device coordinates.  This is usually not the case from
+   the driver's perspective, so the driver should expect to apply its own
+   offset to coordinates passed to callback functions.
+
+
+   Callback functions
+   ==================
+
+   For each of the callback functions, AUX is passed as the 'aux' member of the
+   render_params structure.
+*/
 struct render_params
   {
     /* Measures CELL's width.  Stores in *MIN_WIDTH the minimum width required
        to avoid splitting a single word across multiple lines (normally, this
        is the width of the longest word in the cell) and in *MAX_WIDTH the
-       minimum width required to avoid line breaks other than at new-lines. */
+       minimum width required to avoid line breaks other than at new-lines.
+       */
     void (*measure_cell_width) (void *aux, const struct table_cell *cell,
                                 int *min_width, int *max_width);
 
@@ -44,6 +69,19 @@ struct render_params
     int (*measure_cell_height) (void *aux, const struct table_cell *cell,
                                 int width);
 
+    /* Given that there is space measuring WIDTH by HEIGHT to render CELL,
+       where HEIGHT is insufficient to render the entire height of the cell,
+       returns the largest height less than HEIGHT at which it is appropriate
+       to break the cell.  For example, if breaking at the specified HEIGHT
+       would break in the middle of a line of text, the return value would be
+       just sufficiently less that the breakpoint would be between lines of
+       text.
+
+       Optional.  If NULL, the rendering engine assumes that all breakpoints
+       are acceptable. */
+    int (*adjust_break) (void *aux, const struct table_cell *cell,
+                         int width, int height);
+
     /* Draws a generalized intersection of lines in the rectangle whose
        top-left corner is (BB[TABLE_HORZ][0], BB[TABLE_VERT][0]) and whose
        bottom-right corner is (BB[TABLE_HORZ][1], BB[TABLE_VERT][1]).
@@ -55,14 +93,17 @@ struct render_params
        STYLES[TABLE_VERT][0]: style of line from left of BB to its center.
        STYLES[TABLE_VERT][1]: style of line from right of BB to its center. */
     void (*draw_line) (void *aux, int bb[TABLE_N_AXES][2],
-                       enum render_line_style styles[TABLE_N_AXES][2]);
+                       enum render_line_style styles[TABLE_N_AXES][2],
+                       struct cell_color colors[TABLE_N_AXES][2]);
 
     /* Draws CELL within bounding box BB.  CLIP is the same as BB (the common
        case) or a subregion enclosed by BB.  In the latter case only the part
        of the cell that lies within CLIP should actually be drawn, although BB
        should used to determine the layout of the cell. */
-    void (*draw_cell) (void *aux, const struct table_cell *cell,
-                       int bb[TABLE_N_AXES][2], int clip[TABLE_N_AXES][2]);
+    void (*draw_cell) (void *aux, const struct table_cell *cell, int color_idx,
+                       int bb[TABLE_N_AXES][2],
+                       int spill[TABLE_N_AXES][2],
+                       int clip[TABLE_N_AXES][2]);
 
     /* Auxiliary data passed to each of the above functions. */
     void *aux;
@@ -78,38 +119,38 @@ struct render_params
 
     /* Width of different kinds of lines. */
     int line_widths[TABLE_N_AXES][RENDER_N_LINES];
-  };
-\f
-/* A "page" of content that is ready to be rendered.
 
-   A page's size is not limited to the size passed in as part of render_params.
-   Use render_break (see below) to break a too-big render_page into smaller
-   render_pages that will fit in the available space. */
-struct render_page *render_page_create (const struct render_params *,
-                                        const struct table *);
+    /* Minimum cell width or height before allowing the cell to be broken
+       across two pages.  (Joined cells may always be broken at join
+       points.) */
+    int min_break[TABLE_N_AXES];
 
-struct render_page *render_page_ref (const struct render_page *);
-void render_page_unref (struct render_page *);
+    /* True if the driver supports cell margins.  (If false, the rendering
+       engine will insert a small space betweeen adjacent cells that don't have
+       an intervening rule.)  */
+    bool supports_margins;
 
-int render_page_get_size (const struct render_page *, enum table_axis);
-void render_page_draw (const struct render_page *);
-\f
-/* An iterator for breaking render_pages into smaller chunks. */
-struct render_break
-  {
-    struct render_page *page;   /* Page being broken up. */
-    enum table_axis axis;       /* Axis along which 'page' is being broken. */
-    int cell;                   /* Next cell. */
-    int pixel;                  /* Pixel offset within 'cell' (usually 0). */
-    int hw;                     /* Width of headers of 'page' along 'axis'. */
+    /* True if the local language has a right-to-left direction, otherwise
+       false.  (Use render_direction_rtl() to find out.) */
+    bool rtl;
   };
 
-void render_break_init (struct render_break *, struct render_page *,
-                        enum table_axis);
-void render_break_destroy (struct render_break *);
+/* An iterator for breaking render_pages into smaller chunks. */
+struct render_pager *render_pager_create (const struct render_params *,
+                                          const struct table_item *);
+void render_pager_destroy (struct render_pager *);
+
+bool render_pager_has_next (const struct render_pager *);
+int render_pager_draw_next (struct render_pager *, int space);
+
+void render_pager_draw (const struct render_pager *);
+void render_pager_draw_region (const struct render_pager *,
+                               int x, int y, int w, int h);
+
+int render_pager_get_size (const struct render_pager *, enum table_axis);
+int render_pager_get_best_breakpoint (const struct render_pager *, int height);
+
+bool render_direction_rtl (void);
 
-bool render_break_has_next (const struct render_break *);
-int render_break_next_size (const struct render_break *);
-struct render_page *render_break_next (struct render_break *, int size);
 
 #endif /* output/render.h */