CAPS Universe documentation  1.0.4
All you need to know to be successful
Macros | Functions | Variables
libcapsppd.c File Reference

Handle the options from a PPD file in a dynamic table/array. More...

Macros

#define INCREMENT_STEP   50
 
#define MARGIN   1.5
 

Functions

static void exit_libpaper (void)
 
void caps_libppd_init (void)
 
void caps_libppd_version_get (unsigned *major, unsigned *minor, unsigned *micro)
 
static void init_caps_ppd_option (struct caps_ppd_option *o)
 
static void free_caps_ppd_option (struct caps_ppd_option *o)
 
static struct caps_ppd_optioncreate_new_option_entry (struct caps_ppd_options_table *pot)
 
static void print_caps_ppd_option (const struct caps_ppd_option *o)
 
struct caps_ppd_optioncaps_ppd_option_get (const struct caps_ppd_options_table *pot, const char *keyword)
 
struct caps_ppd_optioncaps_ppd_option_with_name_get (const struct caps_ppd_options_table *pot, const char *keyword, const char *name)
 
void caps_ppd_option_add (struct caps_ppd_options_table *pot, const char *keyword, const char *name, const char *description, const char *value)
 
struct caps_ppd_options_tablecaps_ppd_options_table_create (void)
 
void caps_ppd_options_table_clean_up (struct caps_ppd_options_table *pot)
 
const struct caps_ppd_optioncaps_ppd_options_table_base_get (const struct caps_ppd_options_table *pot)
 
size_t caps_ppd_options_table_element_count_get (const struct caps_ppd_options_table *pot)
 
struct caps_ppd_options_tablecaps_ppd_options_table_duplicate (const struct caps_ppd_options_table *src)
 
int caps_ppd_paper_format_validate (const char *paper_name)
 
struct caps_rect caps_ppd_paper_format_size_get (const char *paper_name)
 
static int check_one_edge (double has, double expected)
 
static const struct paper * medium_name_and_size_guess (const struct caps_rect *sz)
 
const char * caps_ppd_paper_format_name_get (const struct caps_rect *size)
 
const char * caps_ppd_paper_default_format_get (void)
 

Variables

static const struct caps_table_desc ppd_option_desc
 

Detailed Description

The data extracted from a PPD file will be handled as a simple table of option data. Each element in the table stores the values:

After some experience with this kind of data I found out, there is no need for any special handling of the PPD's data. All the data from the PPD can be stored in the simple table line per line. No magic required.

National Language Support: When creating the PPD all 'descriptive' strings can be translated to the local language by default. This will be done in a server local manner, not locally at client side. In order to do so, mark all your decriptions strings for NLS and provide a .po file in your printing driver using the libcapsppd library. And provide your "domain name" in the struct caps_ppd_base element domain_name.

Macro Definition Documentation

◆ INCREMENT_STEP

#define INCREMENT_STEP   50

Whenever the option elements in the table are exhausted, enlarge it by 50 new elements.

◆ MARGIN

#define MARGIN   1.5

Function Documentation

◆ exit_libpaper()

static void exit_libpaper ( void  )
static

Just a clean up of the external libpaper

◆ init_caps_ppd_option()

static void init_caps_ppd_option ( struct caps_ppd_option o)
static

Every new option structure starts empty

Parameters
[in,out]oThe option to init

◆ free_caps_ppd_option()

static void free_caps_ppd_option ( struct caps_ppd_option o)
static

Free option structure resources

Parameters
[in,out]oThe option to free

All content is dynamically allocated. Simply free it and be paranoid and reset the content as well.

◆ create_new_option_entry()

static struct caps_ppd_option * create_new_option_entry ( struct caps_ppd_options_table pot)
static

"Create" a new option structure

Parameters
[in,out]pot
Return values
pointerNew option element
NULLIn case of an error

The option structure is part of a dynamic array. Usage of options is expected as a growing amount of options, so for each new option the next free array element is used.

Note
Does not return in case of memory failure

◆ print_caps_ppd_option()

static void print_caps_ppd_option ( const struct caps_ppd_option o)
static

◆ check_one_edge()

static int check_one_edge ( double  has,
double  expected 
)
static

Guess if one edge of the medium matches a format definition

Parameters
[in]hasThe value to check
[in]expectedThe expected value
Return values
1has is inside the tolerance band of expected
0No correlation between both sizes

The accepted magin is defined in this function and currently +/- 1.5

Todo:
The margin might be a candidate to be defined in an INI file?

◆ medium_name_and_size_guess()

static const struct paper * medium_name_and_size_guess ( const struct caps_rect sz)
static

Goal is to 'guess' the intended medium, not the really given one. In the wild I saw many size variants of DIN A4 for example in PDF files. This function should try to unify them.

libpaper has such a function, but it only matches, if the sizes are exact. What we need is a little bit more tolerance.

This function also checks the rotated coordinates.

Variable Documentation

◆ ppd_option_desc

const struct caps_table_desc ppd_option_desc
static
Initial value:
= {
.element_sz = sizeof(struct caps_ppd_option),
.increment = 50 ,
}
Structure to keep the information read-in from an external PPD files.
Definition: libcapsppd-api.h:151

Dynamic array handling: we want to manage elemts of struct caps_ppd_option.

Note
Refer Base functions for details.