CAPS Universe documentation  1.0.4
All you need to know to be successful
Data Structures | Macros | Functions
doc-page-preparation.c File Reference

Routines to configure the rasterizing process. More...

Data Structures

struct  internal_adaption
 

Macros

#define CAPS_RSTR_DEFAULT_ROTATION   (-90)
 

Functions

static void print_area (const char *s, struct caps_area a)
 
static void print_rect (const char *s, struct caps_rect r)
 
static int check_less_or_equal (double v, double t)
 
static struct caps_rect rect_scale (const struct caps_rect r, double scale_x, double scale_y)
 
static struct caps_rect area_to_sz (struct caps_area a)
 
static struct caps_area area_scale (const struct caps_area a, double scale_x, double scale_y)
 
static struct caps_area margins_rotate (struct caps_area *mi, int rotation)
 
static struct caps_area select_area_from_source (struct caps_rect source_sz, struct caps_rect media, struct caps_rect ptr, struct caps_area m)
 
static void new_alignment (struct internal_adaption *i, enum caps_rstr_alignment alignment)
 
static void new_rotated_print (struct internal_adaption *i, int rot, int imageable_area)
 
static int orientation_differs (const struct caps_rect *src, const struct caps_rect *dst)
 
static int page_auto_rotation_fit (struct internal_adaption *i, const struct caps_rstr_page *medium)
 
static int page_auto_rotation_straight (struct internal_adaption *i, const struct caps_rstr_page *medium)
 
static int page_rotation_guess (struct internal_adaption *i, const struct caps_rstr_page *medium, unsigned fit)
 
static int page_rotation_on_orientation (struct internal_adaption *i, const struct caps_rstr_page *medium, enum caps_rstr_orientation orient)
 
static void check_preconditions (const struct document_desc *job)
 
static void scale_with_aspect_ratio (struct internal_adaption *i, int rotation)
 
void page_setup (struct document_desc *job, struct raster_adapt_preparation *setup, const struct caps_rstr_page *page)
 

Detailed Description

Author
Jürgen Borleis
Version
1.0.0
Warning
Use as experimental

These routines herein configure the rasterizing process according to printer driver settings, user settings and printig parameter settings. This includes content rotation, content scaling or cropping to ensure the best printing experience.

Macro Definition Documentation

◆ CAPS_RSTR_DEFAULT_ROTATION

#define CAPS_RSTR_DEFAULT_ROTATION   (-90)

The default rotation direction if FAV_ROTATION_NONE and no user overwrite is defined Used whenever some kind of auto-rotation is required. This rotation defines a counter-clockwise rotation by -90 ° as the default (like all images show).
It corresponds to FAV_ROTATION_COUNTERCLOCKWISE

Function Documentation

◆ print_area()

static void print_area ( const char *  s,
struct caps_area  a 
)
static

◆ print_rect()

static void print_rect ( const char *  s,
struct caps_rect  r 
)
static

◆ check_less_or_equal()

static int check_less_or_equal ( double  v,
double  t 
)
static

Check if v is less or equal t

Parameters
[in]vThe value which should be less or equal to t
[in]tThe value to check v against
Return values
1v <= t
0v > t

Due to rounding imprecisions a less/equal check is not that trivial

Note
I added this function since "islessequal(v, t + 0.000001)" seems not working as expected (?????????).

◆ rect_scale()

static struct caps_rect rect_scale ( const struct caps_rect  r,
double  scale_x,
double  scale_y 
)
static

Scale the rectangle information

Parameters
[in]rThe rectangle information to scale
[in]scale_xScale factor in horizontal direction
[in]scale_yScale factor in vertical direction
Returns
The scaled rectangle information

◆ area_to_sz()

static struct caps_rect area_to_sz ( struct caps_area  a)
static

Convert the rectangle formed by an area into a simple rectangle

Parameters
[in]aThe area to convert
Returns
The rectangle information

◆ area_scale()

static struct caps_area area_scale ( const struct caps_area  a,
double  scale_x,
double  scale_y 
)
static

Scale an area information

Parameters
[in]aThe area information to scale
[in]scale_xScale factor in horizontal direction
[in]scale_yScale factor in vertical direction
Returns
The scaled area information

◆ margins_rotate()

static struct caps_area margins_rotate ( struct caps_area mi,
int  rotation 
)
static

Rotate the raw margin information

Parameters
[in]miMargins (not coordinates!)
[in]rotationHow to rotate, 0 °, 90 °, 180 °, 270 °, -90 °, -180 ° (from source to destination)
Returns
Rotated margins (from destination to source orientation)
Note
"raw" means, the four values aren't coordinates, they are margins instead.

If the source should be rotated by +90 °, then the destination margins must be rotated by -90 ° to be used on the source.

From "source to destination" means the user's expectation. Since this function is intended to rotate the margins from destination to source, we need to rotate the four margins into the opposite direction.

◆ select_area_from_source()

static struct caps_area select_area_from_source ( struct caps_rect  source_sz,
struct caps_rect  media,
struct caps_rect  ptr,
struct caps_area  m 
)
static

Locate and/or crop a given rectangle in the source area as the part which should be print

Parameters
[in]source_szReal size and orientation of the source
[in]mediaRotated size of media (destination)
[in]ptrRotated size of printable area (destination)
[in]mRotated raw margins (destination)
Returns
The crop area of the source, in the same orientation as media and ptr, which means in source orientation
Precondition
Both media, ptr and margins have the same orientation (the one of the source)

◆ new_alignment()

static void new_alignment ( struct internal_adaption i,
enum caps_rstr_alignment  alignment 
)
static

Put the raster into the printable area of the medium

Parameters
[in,out]iThe whole extraction and print information
[in]alignmentAlignment of the raster inside the printable area of the medium

Where to locate the raster:

  • if the raster is smaller than the printable destination area and CAPS_RSTR_ALIGN_CENTER is set?
    • in the center of the printable destination area?
    • in the center of the destination medium?
  • if the raster is equal to the printable destination area and CAPS_RSTR_ALIGN_CENTER is set
    • the margins are already considered
Note
: Currently the raster gets centered into the printable destination area if it is smaller
Precondition
The raster size must fit into the destination area, e.g. the printable area of the medium

◆ new_rotated_print()

static void new_rotated_print ( struct internal_adaption i,
int  rot,
int  imageable_area 
)
static

Calculate the area from the source and locate it on the destination

Parameters
[in,out]iThe whole extraction and print information
[in]rotRotation from the source point of view
[in]imageable_area1 if the print should scale to the imageable area

In case of success, the internal_adaption::src_crop_area, internal_adaption::offset_y and internal_adaption::offset_y are filled and valid.

◆ orientation_differs()

static int orientation_differs ( const struct caps_rect src,
const struct caps_rect dst 
)
static

Check if both size rectangles have a different orientation (portrait versus landscape)

Parameters
[in]srcThe source rectangle
[in]dstThe destination rectangle
Return values
0Both rectangles have the same orientation
1Both rectangles have a different orientation

◆ page_auto_rotation_fit()

static int page_auto_rotation_fit ( struct internal_adaption i,
const struct caps_rstr_page medium 
)
static

Find best rotation if the page should be printed in a scaled manner

Parameters
[in,out]iThe whole extraction and print information
[in]mediumThe crude print configuration from the printer driver
Returns
Rotation value (0, 90, -90)

The algorithm selects the rotation with the largest possible scale.

Todo:
Create some images to explain
Precondition
internal_adaption::src_full_sz differs from internal_adaption::dst_full_sz in its ortientation

◆ page_auto_rotation_straight()

static int page_auto_rotation_straight ( struct internal_adaption i,
const struct caps_rstr_page medium 
)
static

Find best rotation if the page should be printed as-is

Parameters
[in,out]iThe whole extraction and print information
[in]mediumThe crude print configuration from the printer driver
Returns
Rotation value (0, 90, -90)

The algorithm finds the least lost when cropping.

Todo:
Create some images to explain
Precondition
internal_adaption::src_full_sz differs from internal_adaption::dst_full_sz in its ortientation

◆ page_rotation_guess()

static int page_rotation_guess ( struct internal_adaption i,
const struct caps_rstr_page medium,
unsigned  fit 
)
static

Try the best to image most of the source page to the destination medium (if not otherwise defined)

Parameters
[in,out]iThe whole extraction and print information
[in]mediumThe crude print configuration from the printer driver
[in]fitNot 0 if the print should fit the destination.
Returns
Rotation value (0, 90, -90)
Todo:
Do we need to honor fit_to_page or fit_to_imageable_area here?

◆ page_rotation_on_orientation()

static int page_rotation_on_orientation ( struct internal_adaption i,
const struct caps_rstr_page medium,
enum caps_rstr_orientation  orient 
)
static

Rotate on demand to force the given orient

Parameters
[in,out]iThe whole extraction and print information
[in]mediumThe crude print configuration from the printer driver
[in]orientThe user's orientation selection
Returns
Rotation value (0, 90, -90, 180)
Todo:
Do we need to honor fit_to_page or fit_to_imageable_area here?
Note
Adds a rotation on demand.

◆ check_preconditions()

static void check_preconditions ( const struct document_desc job)
static

◆ scale_with_aspect_ratio()

static void scale_with_aspect_ratio ( struct internal_adaption i,
int  rotation 
)
static

Scale up or down the source to the destination while keeping the aspect ratio

Parameters
[in,out]iThe whole extraction and print information
[in]rotationRotation of the source to consider (0, 90, 180, 270, -90, -180)

Both axis are scaled with the same value to keep the aspect ratio.

Todo:
Think about predicable rounding the scale values.

◆ page_setup()

void page_setup ( struct document_desc job,
struct raster_adapt_preparation setup,
const struct caps_rstr_page page 
)

Setup all required parameters for the current page in order to rasterize it in the next step

Parameters
[in,out]jobCollected job info
[out]setupSetup how to raster the page
[in]pageThe crude print configuration from the printer driver

The calculations here are made when the printer driver calls caps_rstr_page_rasterize().

What we have:

  • the size and orientation of the source page (from the current document's page)
  • the settings from the user's printing parameters
  • the size and orientation of the target medium (from the printer driver)

What we calculate here:

  • how to convert the source page into the destination page
    • depending on various flags this includes:
      • rotation
      • scaling
      • cropping
    • the flags are
      • some defaults if no related user's printing parameters are given
      • the user's printing parameters itself
      • restrictions the printer has
Note
Called by caps_rstr_page_rasterize()
Todo:
Deal with fidelity