Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  * Copyright (C) 2016 Mopria Alliance, Inc.
      4  * Copyright (C) 2013 Hewlett-Packard Development Company, L.P.
      5  *
      6  * Licensed under the Apache License, Version 2.0 (the "License");
      7  * you may not use this file except in compliance with the License.
      8  * You may obtain a copy of the License at
      9  *
     10  *      http://www.apache.org/licenses/LICENSE-2.0
     11  *
     12  * Unless required by applicable law or agreed to in writing, software
     13  * distributed under the License is distributed on an "AS IS" BASIS,
     14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15  * See the License for the specific language governing permissions and
     16  * limitations under the License.
     17  */
     18 
     19 #ifndef __LIB_WPRINT_H__
     20 #define __LIB_WPRINT_H__
     21 
     22 #include "wtypes.h"
     23 #include "wprint_df_types.h"
     24 #include "mime_types.h"
     25 #include "printer_capabilities_types.h"
     26 #include "wprint_status_types.h"
     27 #include "ifc_wprint.h"
     28 #include <dlfcn.h>
     29 #include <ctype.h>
     30 #include <stdlib.h>
     31 
     32 #define WPRINT_BAD_JOB_HANDLE ((wJob_t) ERROR)
     33 
     34 #define _INTERFACE_MAJOR_VERSION  1
     35 #define _INTERFACE_MINOR_VERSION  0
     36 
     37 #define _PLUGIN_MAJOR_VERSION 1
     38 
     39 #define WPRINT_INTERFACE_VERSION ((uint32)((_INTERFACE_MAJOR_VERSION << 16) | \
     40     (_INTERFACE_MINOR_VERSION & 0xffff)))
     41 #define WPRINT_PLUGIN_VERSION(X) ((uint32)((_PLUGIN_MAJOR_VERSION << 16) | (X & 0xffff)))
     42 
     43 #define major_version(X) ((X >> 16) & 0xffff)
     44 #define minor_version(X) ((X >> 0) & 0xffff)
     45 
     46 #define STRIPE_HEIGHT           (16)
     47 #define BUFFERED_ROWS           (STRIPE_HEIGHT * 8)
     48 
     49 #define MAX_MIME_LENGTH         (64)
     50 #define MAX_PRINTER_ADDR_LENGTH (64)
     51 #define MAX_FILENAME_LENGTH     (32)
     52 #define MAX_PATHNAME_LENGTH     (255)
     53 #define MAX_ID_STRING_LENGTH    (64)
     54 #define MAX_NAME_LENGTH         (255)
     55 
     56 #ifdef __cplusplus
     57 extern "C"
     58 {
     59 #endif
     60 
     61 typedef enum {
     62     DUPLEX_DRY_TIME_NORMAL, // 18 seconds
     63     DUPLEX_DRY_TIME_LOWER, // 10 seconds
     64     DUPLEX_DRY_TIME_MINIMUM     // 5 seconds
     65 } duplex_dry_time_t;
     66 
     67 typedef enum {
     68     PORT_INVALID = -1,
     69     PORT_FILE = 0,
     70     PORT_IPP = 631,
     71 } port_t;
     72 
     73 typedef enum {
     74     PCLNONE,
     75     PCLm,
     76     PCLJPEG,
     77     PCLPWG,
     78 
     79     PCL_NUM_TYPES
     80 } pcl_t;
     81 
     82 typedef enum {
     83     AUTO_ROTATE,
     84     CENTER_VERTICAL,
     85     CENTER_HORIZONTAL,
     86     ROTATE_BACK_PAGE,
     87     BACK_PAGE_PREROTATED,
     88     AUTO_SCALE,
     89     AUTO_FIT,
     90     PORTRAIT_MODE,
     91     LANDSCAPE_MODE,
     92     CENTER_ON_ORIENTATION,
     93     DOCUMENT_SCALING,
     94 } render_flags_t;
     95 
     96 #define RENDER_FLAG_AUTO_ROTATE           (1 << AUTO_ROTATE)
     97 #define RENDER_FLAG_ROTATE_BACK_PAGE      (1 << ROTATE_BACK_PAGE)
     98 #define RENDER_FLAG_BACK_PAGE_PREROTATED  (1 << BACK_PAGE_PREROTATED)
     99 #define RENDER_FLAG_CENTER_VERTICAL       (1 << CENTER_VERTICAL)
    100 #define RENDER_FLAG_CENTER_HORIZONTAL     (1 << CENTER_HORIZONTAL)
    101 #define RENDER_FLAG_AUTO_SCALE            (1 << AUTO_SCALE)
    102 #define RENDER_FLAG_AUTO_FIT              (1 << AUTO_FIT)
    103 #define RENDER_FLAG_PORTRAIT_MODE         (1 << PORTRAIT_MODE)
    104 #define RENDER_FLAG_LANDSCAPE_MODE        (1 << LANDSCAPE_MODE)
    105 #define RENDER_FLAG_CENTER_ON_ORIENTATION (1 << CENTER_ON_ORIENTATION)
    106 #define RENDER_FLAG_DOCUMENT_SCALING      (1 << DOCUMENT_SCALING)
    107 
    108 #define AUTO_SCALE_RENDER_FLAGS          (RENDER_FLAG_AUTO_SCALE | \
    109                                           RENDER_FLAG_AUTO_ROTATE | \
    110                                           RENDER_FLAG_CENTER_VERTICAL | \
    111                                           RENDER_FLAG_CENTER_HORIZONTAL)
    112 
    113 #define AUTO_FIT_RENDER_FLAGS            (RENDER_FLAG_AUTO_FIT | \
    114                                           RENDER_FLAG_AUTO_ROTATE | \
    115                                           RENDER_FLAG_CENTER_ON_ORIENTATION)
    116 
    117 #define ORIENTATION_RENDER_FLAGS         (RENDER_FLAG_AUTO_ROTATE | \
    118                                           RENDER_FLAG_PORTRAIT_MODE | \
    119                                           RENDER_FLAG_LANDSCAPE_MODE | \
    120                                           RENDER_FLAG_CENTER_ON_ORIENTATION)
    121 
    122 typedef void (*wprint_status_cb_t)(wJob_t job_id, void *parm);
    123 
    124 /*
    125  * Parameters describing a job request
    126  */
    127 typedef struct {
    128     media_size_t media_size;
    129     media_type_t media_type;
    130     duplex_t duplex;
    131     duplex_dry_time_t dry_time;
    132     color_space_t color_space;
    133     media_tray_t media_tray;
    134     unsigned int num_copies;
    135     bool borderless;
    136     unsigned int render_flags;
    137     float job_top_margin;
    138     float job_left_margin;
    139     float job_right_margin;
    140     float job_bottom_margin;
    141 
    142     bool renderInReverseOrder;
    143 
    144     // these values are pixels
    145     unsigned int print_top_margin;
    146     unsigned int print_left_margin;
    147     unsigned int print_right_margin;
    148     unsigned int print_bottom_margin;
    149 
    150     // these values are in pixels
    151     unsigned int pixel_units;
    152     unsigned int width;
    153     unsigned int height;
    154     unsigned int printable_area_width;
    155     unsigned int printable_area_height;
    156     unsigned int strip_height;
    157 
    158     bool cancelled;
    159     bool last_page;
    160     int page_num;
    161     int copy_num;
    162     int copy_page_num;
    163     int page_corrupted;
    164     bool page_printing;
    165     bool page_backside;
    166 
    167     bool media_size_name;
    168 
    169     // these values are in inches
    170     float page_width;
    171     float page_height;
    172     float page_top_margin;
    173     float page_left_margin;
    174     float page_right_margin;
    175     float page_bottom_margin;
    176 
    177     const char *print_format;
    178     char *page_range;
    179     pcl_t pcl_type;
    180     void *plugin_data;
    181     bool ipp_1_0_supported;
    182     bool ipp_2_0_supported;
    183     bool epcl_ipp_supported;
    184     bool accepts_pclm;
    185     bool accepts_pdf;
    186     bool copies_supported;
    187     const char *useragent;
    188     char docCategory[10];
    189     const char *media_default;
    190 
    191     // IPP max job-name is 2**31 - 1, we set a shorter limit
    192     char job_name[MAX_ID_STRING_LENGTH + 1];
    193     char job_originating_user_name[MAX_NAME_LENGTH + 1];
    194     int pdf_render_resolution;
    195     bool accepts_app_name;
    196     bool accepts_app_version;
    197     bool accepts_os_name;
    198     bool accepts_os_version;
    199 } wprint_job_params_t;
    200 
    201 /*
    202  * Parameters defining how to reach a remote printing service
    203  */
    204 typedef struct {
    205     const char *printer_addr;
    206     const char *uri_path;
    207     const char *uri_scheme;
    208     int port_num;
    209 } wprint_connect_info_t;
    210 
    211 /*
    212  * Current state of a queued job
    213  */
    214 typedef enum {
    215     JOB_QUEUED = 1,
    216     JOB_RUNNING,
    217     JOB_BLOCKED,
    218     JOB_DONE
    219 } wprint_job_state_t;
    220 
    221 typedef struct {
    222     wprint_job_state_t state;
    223     unsigned int blocked_reasons;
    224     int job_done_result;
    225 } wprint_job_callback_params_t;
    226 
    227 typedef enum {
    228     PRIORITY_PASSTHRU = 1,
    229     PRIORITY_LOCAL,
    230 } wprint_priority_t;
    231 
    232 /* Forward declaration (actual definition in ifc_print_job.h) */
    233 struct ifc_print_job_st;
    234 
    235 /*
    236  * Defines an interface for delivering print jobs
    237  */
    238 typedef struct {
    239     uint32 version;
    240     wprint_priority_t priority;
    241 
    242     char const **(*get_mime_types)(void);
    243 
    244     char const **(*get_print_formats)(void);
    245 
    246     status_t (*start_job)(wJob_t job_handle, const ifc_wprint_t *wprint_ifc,
    247             const struct ifc_print_job_st *job_ifc, wprint_job_params_t *job_params);
    248 
    249     status_t (*print_page)(wprint_job_params_t *job_params, const char *mime_type,
    250             const char *pathname);
    251 
    252     status_t (*print_blank_page)(wJob_t job_handle,
    253             wprint_job_params_t *job_params);
    254 
    255     status_t (*end_job)(wprint_job_params_t *job_params);
    256 } wprint_plugin_t;
    257 
    258 /*
    259  * Initialize the wprint system. Identify and gather capabilities of available plug-ins.
    260  * Returns the number of plugins found or ERROR.
    261  */
    262 int wprintInit(void);
    263 
    264 /*
    265  * Call to test if wprint is running or has been shut down.
    266  */
    267 bool wprintIsRunning();
    268 
    269 /*
    270  * Gets the capabilities of the specified printer.
    271  */
    272 status_t wprintGetCapabilities(const wprint_connect_info_t *connect_info,
    273         printer_capabilities_t *printer_cap);
    274 
    275 /*
    276  * Fills in the job params structure with default values.
    277  */
    278 status_t wprintGetDefaultJobParams(wprint_job_params_t *job_params);
    279 
    280 /*
    281  * Fills in the job params structure with values in accordance with printer capabilities.
    282  */
    283 status_t wprintGetFinalJobParams(wprint_job_params_t *job_param,
    284         const printer_capabilities_t *printer_cap);
    285 
    286 /*
    287  * Called once per job at the start of the job. Returns a print job handle that is used in
    288  * other functions of this library. Returns WPRINT_BAD_JOB_HANDLE for errors.
    289  */
    290 wJob_t wprintStartJob(const char *printer_addr, port_t port_num,
    291         const wprint_job_params_t *job_params, const printer_capabilities_t *printer_cap,
    292         const char *mime_type, const char *pathname, wprint_status_cb_t cb_fn,
    293         const char *debugDir);
    294 
    295 /*
    296  * Sent once per job at the end of the job. A current print job must end for the next one
    297  * to start.
    298  */
    299 status_t wprintEndJob(wJob_t job_handle);
    300 
    301 /*
    302  * Sent once per page of a multi-page job to deliver a page image in a previously
    303  * specified MIME type. The page_number must increment from 1. last_page flag is true if it
    304  * is the last page of the job.
    305  *
    306  * top/left/right/bottom margin are the incremental per page margins in pixels
    307  * at the current print resolution that are added on top of the physical page
    308  * page margins, passing in 0 results in the default page margins being used.
    309  */
    310 status_t wprintPage(wJob_t job_handle, int page_number, const char *filename, bool last_page,
    311         bool pdf_page, unsigned int top_margin, unsigned int left_margin,
    312         unsigned int right_margin, unsigned int bottom_margin);
    313 
    314 /*
    315  * Cancels a spooled or running job. Returns OK or ERROR
    316  */
    317 status_t wprintCancelJob(wJob_t job_handle);
    318 
    319 /*
    320  * Exits the print subsystem
    321  */
    322 status_t wprintExit(void);
    323 
    324 /*
    325  * Supplies info about the sending application and OS name
    326  */
    327 void wprintSetSourceInfo(const char *appName, const char *appVersion, const char *osName);
    328 
    329 /* Global variables to hold API, application, and OS details */
    330 extern int g_API_version;
    331 extern char g_osName[MAX_ID_STRING_LENGTH + 1];
    332 extern char g_appName[MAX_ID_STRING_LENGTH + 1];
    333 extern char g_appVersion[MAX_ID_STRING_LENGTH + 1];
    334 
    335 #ifdef __cplusplus
    336 }
    337 #endif
    338 
    339 #endif // __LIB_WPRINT_H__