Skip to content

Commit

Permalink
Merge pull request #43 from missla/printer
Browse files Browse the repository at this point in the history
Improve several aspect
  • Loading branch information
agalakhov committed Apr 9, 2022
2 parents fdc3315 + e114d1d commit fdb2321
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 63 deletions.
21 changes: 14 additions & 7 deletions src/paper.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,24 @@

#include "paper.h"
#include <cups/raster.h>
#include <stdio.h>

void page_set_dims(struct page_dims_s *dims, const struct cups_page_header2_s *header)
{
dims->media_type = header->cupsMediaType;
dims->paper_width = header->PageSize[0] * header->HWResolution[0] / 72;
dims->paper_height = header->PageSize[1] * header->HWResolution[1] / 72;
/*
The use of cupsCompression to toggle toner save was inspired by the
use of the same attribute to control darkness in label printer drivers.
*/
dims->toner_save = header->cupsCompression;
strncpy(dims->media_size, header->MediaType, 64);
dims->paper_width = header->cupsWidth; //header->PageSize[0] * header->HWResolution[0] / 72;
dims->paper_height = header->cupsHeight; //header->PageSize[1] * header->HWResolution[1] / 72;
dims->toner_save = header->cupsInteger[0];
dims->ink_k = header->cupsInteger[1];
dims->line_size = header->PageSize[0];
dims->num_lines = header->cupsHeight;
dims->band_size = header->cupsRowCount;
dims->margin_height = header->Margins[0];
dims->margin_width = header->Margins[1];

if (header->HWResolution[1] == 400)
dims->media_adapt = 0x81;
else
dims->media_adapt = 0x11;
}
3 changes: 3 additions & 0 deletions src/paper.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ struct cups_page_header2_s;
struct page_dims_s {
/* set by CUPS */
unsigned media_type;
unsigned media_adapt;
char media_size[0x40];
unsigned paper_width;
unsigned paper_height;
unsigned toner_save;
unsigned ink_k;
unsigned margin_height;
unsigned margin_width;
/* set by printer ops */
Expand Down
Loading

0 comments on commit fdb2321

Please sign in to comment.