Printing problem

Hi, All.

I have written a simple programm which prints a grid.
Everything is fine when I print it with equal horizontal and
vertical resolution.

But if horizontal and vertical resolution are different then
calculated source size is less then real.

It seems that the Photon sets equal maximun resolution.

So, what do I have to do for correct printing?


Source:
#include <stdio.h>
#include <stdlib.h>
#include <Pt.h>

PtWidget_t *pane, *window;

int quit_cb ( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo) {
exit (EXIT_SUCCESS);
return (Pt_CONTINUE);
}

int print_cb ( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo) {
PpPrintContext_t *pc = PpCreatePC();
PhDrawContext_t *dc;
char *orientation;
PhDim_t size, *paper_size, *resolution;
PhRect_t *rect;
PhArea_t area;
int action, x, y;

action = PtPrintSelection(window, NULL, “Demo Print Selector”, pc,
Pt_PRINTSEL_DFLT_LOOK);
if (action == Pt_PRINTSEL_CANCEL) return Pt_CONTINUE;

// init
PpGetPC(pc, Pp_PC_PAPER_SIZE, &paper_size); // it returns paper
size in 1/1000 inch
PpGetPC(pc, Pp_PC_PRINTER_RESOLUTION, &resolution);
PpGetPC(pc, Pp_PC_NONPRINT_MARGINS, &rect);
PpGetPC(pc, Pp_PC_ORIENTATION, &orientation);

if (orientation == 0) { // portrait
size.w = (paper_size->w - rect->ul.x - rect->lr.x)
resolution->w /
1000;
size.h = (paper_size->h - rect->ul.y - rect->lr.y)* resolution->h /
1000;
}
else {
size.h = (paper_size->w - rect->ul.x - rect->lr.x)* resolution->w /
1000;
size.w = (paper_size->h - rect->ul.y - rect->lr.y)* resolution->h /
1000;
}
area.size = size;
area.pos.x = area.pos.y = 0;

PpSetPC(pc, Pp_PC_SOURCE_SIZE, &size, 0);
PpSetPC(pc, Pp_PC_SOURCE_RESOLUTION, resolution, 0);

dc = PhDCSetCurrent(pc);

PpStartJob(pc);
PpContinueJob(pc);

PgSetStrokeColor(Pg_BLACK);
PgSetStrokeWidth(4);
for(x = 0; x < size.w; x += resolution->w) PgDrawILine(x, 0, x, size.h);
PgDrawILine(size.w - 1, 0, size.w -1, size.h);

for(y = 0; y < size.h; y += resolution->h) PgDrawILine(0, y, size.w, y);
PgDrawILine(0, size.h - 1 , size.w, size.h -1);

PpSuspendJob(pc);
PpEndJob(pc);
PhDCSetCurrent(dc);

PpReleasePC (pc);
return Pt_CONTINUE;
}

int main(int argc, char *argv[]) {
PtArg_t args[4];
PtWidget_t *print, *quit;
PhDim_t win_dim = { 200, 200 };
PhArea_t print_area = { {30, 170}, {60, 20} };
PhArea_t quit_area = { {110, 170}, {60, 20} };
PtCallback_t callbacks[2] = { {print_cb, NULL}, {quit_cb, NULL} };

if (PtInit(NULL) == -1)
PtExit(EXIT_FAILURE);

/* Create the main window. */
PtSetArg (&args[0], Pt_ARG_DIM, &win_dim, 0);
PtSetArg (&args[1], Pt_ARG_WINDOW_TITLE, “Print Example”, 0);
if ((window = PtCreateWidget(PtWindow, Pt_NO_PARENT, 2, args)) == NULL)
PtExit(EXIT_FAILURE);

/* Create the print button. */
PtSetArg(&args[0], Pt_ARG_AREA, &print_area, 0);
PtSetArg(&args[1], Pt_ARG_TEXT_STRING, “Print”, 0);
PtSetArg(&args[2], Pt_CB_ACTIVATE, &callbacks[0], 0);
print = PtCreateWidget (PtButton, window, 3, args);

/* Create the quit button. */
PtSetArg(&args[0], Pt_ARG_AREA, &quit_area, 0);
PtSetArg(&args[1], Pt_ARG_TEXT_STRING, “Quit”, 0);
PtSetArg(&args[2], Pt_CB_ACTIVATE, &callbacks[1], 0);
quit = PtCreateWidget (PtButton, window, 3, args);

PtRealizeWidget(window);
PtMainLoop();
return (EXIT_SUCCESS);
}