diff options
Diffstat (limited to 'app/bin/cprint.c')
-rw-r--r-- | app/bin/cprint.c | 1044 |
1 files changed, 565 insertions, 479 deletions
diff --git a/app/bin/cprint.c b/app/bin/cprint.c index 066e649..123ad99 100644 --- a/app/bin/cprint.c +++ b/app/bin/cprint.c @@ -1,5 +1,5 @@ /** \file cprint.c - * Printing functions. + * Printing functions. */ /* XTrkCad - Model Railroad CAD @@ -17,25 +17,16 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include <sys/types.h> -#include <time.h> -#include <string.h> -#include <ctype.h> -#include <math.h> -#include <stdbool.h> - #include "custom.h" #include "dynstring.h" #include "fileio.h" -#include "i18n.h" #include "layout.h" -#include "messages.h" #include "param.h" #include "track.h" -#include "utility.h" +#include "common-ui.h" #define PRINT_GAUDY (0) #define PRINT_PLAIN (1) @@ -46,24 +37,33 @@ #define PRINTOPTION_SNAP (1<<0) typedef struct { - int x0, x1, y0, y1; - char * bm; - int memsize; - coOrd orig; - coOrd size; - ANGLE_T angle; - } bitmap_t; + int x0, x1, y0, y1; + char * bm; + int memsize; + coOrd orig; + coOrd size; + ANGLE_T angle; +} bitmap_t; static bitmap_t bm, bm0; #define BITMAP( BM, X, Y ) \ (BM).bm[ (X)-(BM).x0 + ((Y)-(BM).y0) * ((BM).x1-(BM).x0) ] -struct { - coOrd size; - coOrd orig; - ANGLE_T angle; - } currPrintGrid, newPrintGrid; +static struct { + coOrd size; + coOrd orig; + ANGLE_T angle; +} currPrintGrid, newPrintGrid; +EXPORT coOrd GetPrintOrig() +{ + return currPrintGrid.orig; +} + +EXPORT ANGLE_T GetPrintAngle() +{ + return currPrintGrid.angle; +} /* * GUI VARS */ @@ -72,7 +72,7 @@ struct { static long printGaudy = 1; static long printRegistrationMarks = 1; static long printPageNumbers = 1; -static long printPhysSize = FALSE; +static long bIgnoreMargins = FALSE; static long printFormat = PORTRAIT; static long printOrder = 0; static long printGrid = 0; @@ -89,7 +89,7 @@ static coOrd maxPageSize; static coOrd realPageSize; static wWin_p printWin = NULL; -static wWin_p printMarginWin = NULL; +static wWin_p customMarginWin = NULL; static wMenu_p printGridPopupM; @@ -104,7 +104,7 @@ static void PrintClear( void ); static void PrintMaxPageSize( void ); static void SelectAllPages(void); static void DoPrintMargin(void); -static bool PrintPageNumber( wPos_t x, wPos_t y, DIST_T width, DIST_T height ); +static bool PrintPageNumber( int x, int y, DIST_T width, DIST_T height ); static bool PrintNextPageNumbers(int x, int y, DIST_T pageW, DIST_T pageH); static char * printFormatLabels[] = { N_("Portrait"), N_("Landscape"), NULL }; @@ -112,60 +112,63 @@ static char * printOrderLabels[] = { N_("Normal"), N_("Reverse"), NULL }; static char * printGaudyLabels[] = { N_("Engineering Data"), NULL }; static char * printRegistrationMarksLabels[] = { N_("Registration Marks (in 1:1 scale only)"), NULL }; static char * printPageNumberLabels[] = { N_("Page Numbers"), NULL }; -static char * printPhysSizeLabels[] = { N_("Ignore Page Margins"), NULL }; +static char * sIgnoreMarginsLabels[] = { N_("Ignore Page Margins"), NULL }; static char * printGridLabels[] = { N_("Snap Grid"), NULL }; -static char * printRulerLabels[] = { N_("Rulers"), NULL }; +static char * printRulerLabels[] = { N_("Layout Edge"), N_("Every Page"), N_("None"), NULL }; static char * printRoadbedLabels[] = { N_("Roadbed Outline"), NULL }; static char * printCenterLineLabels[] = { N_("Centerline below Scale 1:1"), NULL }; static paramIntegerRange_t rminScale_999 = { 1, 999, 0, PDO_NORANGECHECK_HIGH }; static paramFloatRange_t r0_ = { 0, 0, 0, PDO_NORANGECHECK_HIGH }; -static paramFloatRange_t r1_ = { 1, 0, 0, PDO_NORANGECHECK_HIGH }; -static paramFloatRange_t r_10_99999 = { -10, 99999, 0, PDO_NORANGECHECK_HIGH }; +static paramFloatRange_t r1_pgsz_x = { 1, 0, 0, 0 }; +static paramFloatRange_t r1_pgsz_y = { 1, 0, 0, 0 }; +static paramFloatRange_t r_100_99999 = { -100, 99999, 0, PDO_NORANGECHECK_HIGH }; static paramFloatRange_t r0_360 = { 0, 360 }; static paramData_t printPLs[] = { -/*0*/ { PD_LONG, &iPrintScale, "scale", 0, &rminScale_999, N_("Print Scale"), 0, (void*)1 }, -/*1*/ { PD_FLOAT, &newPrintGrid.size.x, "pagew", PDO_DIM|PDO_SMALLDIM|PDO_NORECORD|PDO_NOPREF, &r1_, N_("Page Width"), 0, (void*)2 }, -/*2*/ { PD_BUTTON, (void*)PrintMaxPageSize, "max", PDO_DLGHORZ, NULL, N_("Max") }, -/*3*/ { PD_FLOAT, &newPrintGrid.size.y, "pageh", PDO_DIM|PDO_SMALLDIM|PDO_NORECORD|PDO_NOPREF, &r1_, N_("Height"), 0, (void*)2 }, -/*4*/ { PD_BUTTON, (void*)PrintSnapShot, "snapshot", PDO_DLGHORZ, NULL, N_("Snap Shot") }, -/*5*/ { PD_RADIO, &printFormat, "format", 0, printFormatLabels, N_("Page Format"), BC_HORZ|BC_NOBORDER, (void*)1 }, -/*6*/ { PD_RADIO, &printOrder, "order", PDO_DLGBOXEND, printOrderLabels, N_("Print Order"), BC_HORZ|BC_NOBORDER }, -/*7*/ { PD_MESSAGE, N_("Print "), NULL, PDO_DLGRESETMARGIN| PDO_DLGNOLABELALIGN, (void*)0 }, -/*8*/ { PD_TOGGLE, &printGaudy, "style", PDO_DLGNOLABELALIGN, printGaudyLabels, NULL, BC_HORZ|BC_NOBORDER, (void*)1 }, + /*0*/ { PD_LONG, &iPrintScale, "scale", 0, &rminScale_999, N_("Print Scale"), 0, I2VP(1) }, + /*1*/ { PD_FLOAT, &newPrintGrid.size.x, "pagew", PDO_DIM|PDO_SMALLDIM|PDO_NORECORD|PDO_NOPREF, &r1_pgsz_x, N_("Page Width"), 0, I2VP(2) }, + /*2*/ { PD_BUTTON, PrintMaxPageSize, "max", PDO_DLGHORZ, NULL, N_("Max") }, + /*3*/ { PD_FLOAT, &newPrintGrid.size.y, "pageh", PDO_DIM|PDO_SMALLDIM|PDO_NORECORD|PDO_NOPREF, &r1_pgsz_y, N_("Height"), 0, I2VP(2) }, + /*4*/ { PD_BUTTON, PrintSnapShot, "snapshot", PDO_DLGHORZ, NULL, N_("Snap Shot") }, + /*5*/ { PD_RADIO, &printFormat, "format", 0, printFormatLabels, N_("Page Format"), BC_HORZ|BC_NOBORDER, I2VP(1) }, + /*6*/ { PD_RADIO, &printOrder, "order", PDO_DLGBOXEND, printOrderLabels, N_("Print Order"), BC_HORZ|BC_NOBORDER }, + /*7*/ { PD_MESSAGE, N_("Print "), NULL, PDO_DLGRESETMARGIN| PDO_DLGNOLABELALIGN, I2VP(0) }, + /*8*/ { PD_TOGGLE, &printGaudy, "style", PDO_DLGNOLABELALIGN, printGaudyLabels, NULL, BC_HORZ|BC_NOBORDER, I2VP(1) }, #define I_REGMARKS (9) -/*9*/ { PD_TOGGLE, &printRegistrationMarks, "registrationMarks", PDO_DLGNOLABELALIGN, printRegistrationMarksLabels, NULL, BC_HORZ|BC_NOBORDER }, + /*9*/ { PD_TOGGLE, &printRegistrationMarks, "registrationMarks", PDO_DLGNOLABELALIGN, printRegistrationMarksLabels, NULL, BC_HORZ|BC_NOBORDER }, #define I_PAGENUMBERS (10) -/*10*/ { PD_TOGGLE, &printPageNumbers, "pageNumbers", PDO_DLGNOLABELALIGN, printPageNumberLabels, NULL, BC_HORZ | BC_NOBORDER }, + /*10*/ { PD_TOGGLE, &printPageNumbers, "pageNumbers", PDO_DLGNOLABELALIGN, printPageNumberLabels, NULL, BC_HORZ | BC_NOBORDER }, #define I_GRID (11) -/*11*/ { PD_TOGGLE, &printGrid, "grid", PDO_DLGNOLABELALIGN, printGridLabels, NULL, BC_HORZ|BC_NOBORDER }, + /*11*/ { PD_TOGGLE, &printGrid, "grid", PDO_DLGNOLABELALIGN, printGridLabels, NULL, BC_HORZ|BC_NOBORDER }, #define I_RULER (12) -/*12*/ { PD_TOGGLE, &printRuler, "ruler", PDO_DLGNOLABELALIGN, printRulerLabels, NULL, BC_HORZ|BC_NOBORDER }, + /*12*/ { PD_RADIO, &printRuler, "ruler", 0, printRulerLabels, N_("Rulers:"), BC_HORZ|BC_NOBORDER }, #define I_CENTERLINE (13) -/*13*/ { PD_TOGGLE, &printCenterLine, "centerLine", PDO_DLGNOLABELALIGN, printCenterLineLabels, NULL, BC_HORZ|BC_NOBORDER }, + /*13*/ { PD_TOGGLE, &printCenterLine, "centerLine", PDO_DLGNOLABELALIGN, printCenterLineLabels, NULL, BC_HORZ|BC_NOBORDER }, #define I_ROADBED (14) -/*14*/{ PD_TOGGLE, &printRoadbed, "roadbed", PDO_DLGNOLABELALIGN, printRoadbedLabels, NULL, BC_HORZ|BC_NOBORDER }, + /*14*/{ PD_TOGGLE, &printRoadbed, "roadbed", PDO_DLGNOLABELALIGN, printRoadbedLabels, NULL, BC_HORZ|BC_NOBORDER }, #define I_ROADBEDWIDTH (15) -/*15*/{ PD_FLOAT, &printRoadbedWidth, "roadbedWidth", PDO_DIM , &r0_, N_(" Width") }, -/*16*/ { PD_TOGGLE, &printPhysSize, "physsize", PDO_DLGNOLABELALIGN, printPhysSizeLabels, NULL, BC_HORZ | BC_NOBORDER, (void*)1 }, -/*17*/ { PD_BUTTON, (void*)DoPrintMargin, "margin", PDO_DLGHORZ|PDO_DLGBOXEND, NULL, N_("Margins") }, -/*18*/{ PD_FLOAT, &newPrintGrid.orig.x, "origx", PDO_DIM|PDO_DLGRESETMARGIN, &r_10_99999, N_("Origin: X"), 0, (void*)2 }, -/*19*/ { PD_FLOAT, &newPrintGrid.orig.y, "origy", PDO_DIM, &r_10_99999, N_("Y"), 0, (void*)2 }, -/*20*/ { PD_BUTTON, (void*)DoResetGrid, "reset", PDO_DLGHORZ, NULL, N_("Reset") }, -/*21*/ { PD_FLOAT, &newPrintGrid.angle, "origa", PDO_ANGLE|PDO_DLGBOXEND, &r0_360, N_("Angle"), 0, (void*)2 }, -/*22*/ { PD_BUTTON, (void*)DoPrintSetup, "setup", PDO_DLGCMDBUTTON, NULL, N_("Setup") }, -/*23*/ { PD_BUTTON, (void*)SelectAllPages, "selall", 0, NULL, N_("Select All") }, -/*24*/ { PD_BUTTON, (void*)PrintClear, "clear", 0, NULL, N_("Clear") }, + /*15*/{ PD_FLOAT, &printRoadbedWidth, "roadbedWidth", PDO_DIM, &r0_, N_(" Width") }, + /*16*/ { PD_TOGGLE, &bIgnoreMargins, "physsize", PDO_DLGNOLABELALIGN, sIgnoreMarginsLabels, NULL, BC_HORZ | BC_NOBORDER, I2VP(1) }, + /*17*/ { PD_BUTTON, DoPrintMargin, "margin", PDO_DLGHORZ|PDO_DLGBOXEND, NULL, N_("Margins") }, + /*18*/{ PD_FLOAT, &newPrintGrid.orig.x, "origx", PDO_DIM|PDO_DLGRESETMARGIN, &r_100_99999, N_("Origin: X"), 0, I2VP(2) }, + /*19*/ { PD_FLOAT, &newPrintGrid.orig.y, "origy", PDO_DIM, &r_100_99999, N_("Y"), 0, I2VP(2) }, + /*20*/ { PD_BUTTON, DoResetGrid, "reset", PDO_DLGHORZ, NULL, N_("Reset") }, + /*21*/ { PD_FLOAT, &newPrintGrid.angle, "origa", PDO_ANGLE|PDO_DLGBOXEND, &r0_360, N_("Angle"), 0, I2VP(2) }, + /*22*/ { PD_BUTTON, DoPrintSetup, "setup", PDO_DLGCMDBUTTON, NULL, N_("Setup") }, + /*23*/ { PD_BUTTON, SelectAllPages, "selall", 0, NULL, N_("Select All") }, + /*24*/ { PD_BUTTON, PrintClear, "clear", 0, NULL, N_("Clear") }, #define I_PAGECNT (25) -/*25*/ { PD_MESSAGE, N_("0 pages"), NULL, 0, (void*)80 }, -/*26*/ { PD_MESSAGE, N_("selected"), NULL, 0, (void*)80 } + /*25*/ { PD_MESSAGE, N_("0 pages"), NULL, 0, I2VP(80) }, + /*26*/ { PD_MESSAGE, N_("selected"), NULL, 0, I2VP(80) } }; -static paramGroup_t printPG = { "print", PGO_PREFMISCGROUP, printPLs, sizeof printPLs/sizeof printPLs[0] }; +static paramGroup_t printPG = { "print", PGO_PREFMISCGROUP, printPLs, COUNT( printPLs ) }; -static struct { +struct margins_s { double top, right, bottom, left; -} printMargin = { 0.0, 0.0, 0.0, 0.0 }; +}; +static struct margins_s printerMargin = { 0.0, 0.0, 0.0, 0.0 }; +static struct margins_s customMargin = { 0.0, 0.0, 0.0, 0.0 }; /***************************************************************************** * @@ -175,10 +178,10 @@ static struct { /** * Update the dialog with the current number of selected pages. - * + * */ -static void +static void UpdatePageCount() { DynString msg; @@ -187,7 +190,7 @@ UpdatePageCount() DynStringPrintf(&msg, (pageCount == 1?_("%d page"):_("%d pages")), pageCount); ParamLoadMessage(&printPG, I_PAGECNT, DynStringToCStr(&msg)); ParamDialogOkActive(&printPG, pageCount != 0); - + DynStringFree(&msg); } @@ -199,11 +202,13 @@ static void ChangeDim( void ) bitmap_t tmpBm; BOOL_T selected; - MapGrid( zero, mapD.size, 0.0, currPrintGrid.orig, currPrintGrid.angle, currPrintGrid.size.x, currPrintGrid.size.y, - &x0, &x1, &y0, &y1 ); + MapGrid( zero, mapD.size, 0.0, currPrintGrid.orig, currPrintGrid.angle, + currPrintGrid.size.x, currPrintGrid.size.y, + &x0, &x1, &y0, &y1 ); - if ( x0==bm.x0 && x1==bm.x1 && y0==bm.y0 && y1==bm.y1 ) + if ( x0==bm.x0 && x1==bm.x1 && y0==bm.y0 && y1==bm.y1 ) { return; + } size = (x1-x0) * (y1-y0); if (size > bm0.memsize) { bm0.bm = MyRealloc( bm0.bm, size ); @@ -246,15 +251,15 @@ static void ChangeDim( void ) static void MarkPage( - wIndex_t x, - wIndex_t y ) + wIndex_t x, + wIndex_t y ) /* * Hilite a area */ { coOrd p[4]; - -LOG1( log_print, ( "MarkPage( %d, %d )\n", x, y) ) + + LOG1( log_print, ( "MarkPage( %d, %d )\n", x, y) ) if ( x<bm.x0 || x>=bm.x1 || y<bm.y0 || y>=bm.y1) { ErrorMessage( MSG_OUT_OF_BOUNDS ); return; @@ -267,7 +272,8 @@ LOG1( log_print, ( "MarkPage( %d, %d )\n", x, y) ) Rotate( &p[1], currPrintGrid.orig, currPrintGrid.angle ); Rotate( &p[2], currPrintGrid.orig, currPrintGrid.angle ); Rotate( &p[3], currPrintGrid.orig, currPrintGrid.angle ); -LOG( log_print, 2, ( "MP(%d,%d) [%0.3f %0.3f] x [%0.3f %0.3f]\n", x, y, p[0].x, p[0].y, p[2].x, p[2].y ) ) + LOG( log_print, 2, ( "MP(%d,%d) [%0.3f %0.3f] x [%0.3f %0.3f]\n", x, y, p[0].x, + p[0].y, p[2].x, p[2].y ) ) DrawHilightPolygon( &tempD, p, 4 ); } @@ -282,8 +288,9 @@ static void SelectPage( coOrd pos ) Rotate( &pos, zero, -currPrintGrid.angle ); x = (int)floor(pos.x/currPrintGrid.size.x); y = (int)floor(pos.y/currPrintGrid.size.y); - if ( x<bm.x0 || x>=bm.x1 || y<bm.y0 || y>=bm.y1) + if ( x<bm.x0 || x>=bm.x1 || y<bm.y0 || y>=bm.y1) { return; + } selected = BITMAP( bm, x, y ); pageCount += (selected?-1:1); BITMAP( bm, x, y ) = !selected; @@ -300,7 +307,8 @@ static void DrawPrintGrid( void ) { wIndex_t x, y; - DrawGrid( &tempD, &mapD.size, currPrintGrid.size.x, currPrintGrid.size.y, 0, 0, currPrintGrid.orig, currPrintGrid.angle, wDrawColorBlack, TRUE ); + DrawGrid( &tempD, &mapD.size, currPrintGrid.size.x, currPrintGrid.size.y, 0, 0, + currPrintGrid.orig, currPrintGrid.angle, wDrawColorBlack, TRUE ); for (y=bm.y0; y<bm.y1; y++) for (x=bm.x0; x<bm.x1; x++) @@ -317,33 +325,35 @@ static void DrawPrintGrid( void ) static drawCmd_t print_d = { - NULL, - &printDrawFuncs, - DC_PRINT, - 16.0, - 0.0, - {0.0, 0.0}, {1.0, 1.0}, - Pix2CoOrd, CoOrd2Pix }; + NULL, + &printDrawFuncs, + DC_PRINT, + 16.0, + 0.0, + {0.0, 0.0}, {1.0, 1.0}, + Pix2CoOrd, CoOrd2Pix +}; static drawCmd_t page_d = { - NULL, - &printDrawFuncs, - DC_PRINT, - 1.0, - 0.0, - {0.0, 0.0}, {1.0, 1.0}, - Pix2CoOrd, CoOrd2Pix }; + NULL, + &printDrawFuncs, + DC_PRINT, + 1.0, + 0.0, + {0.0, 0.0}, {1.0, 1.0}, + Pix2CoOrd, CoOrd2Pix +}; /** * Print the basic layout for a trackplan. This includes the frame and some * information like room size, print scale etc.. * - * \param roomSize IN size of the layout + * \param roomSize IN size of the layout */ static void PrintGaudyBox( - coOrd roomSize ) + coOrd roomSize ) { coOrd p00, p01, p10, p11; struct tm *tm; @@ -360,8 +370,9 @@ static void PrintGaudyBox( strftime( dat, STR_SIZE, "%x", tm ); smiggin = wDrawGetDPI( print_d.d ); - if (smiggin>4.0) + if (smiggin>4.0) { smiggin = 4.0/smiggin; + } pageW = currPrintGrid.size.x/print_d.scale; pageH = currPrintGrid.size.y/print_d.scale; /* Draw some lines */ @@ -406,19 +417,19 @@ static void PrintGaudyBox( DrawString( &page_d, p00, 0.0, GetLayoutSubtitle(), fp, 12.0, wDrawColorBlack ); sprintf( dat, _("PrintScale 1:%ld Room %s x %s Model Scale %s File %s"), - (long)printScale, - FormatDistance( roomSize.x ), - FormatDistance( roomSize.y ), - curScaleName, GetLayoutFilename() ); + (long)printScale, + FormatDistance( roomSize.x ), + FormatDistance( roomSize.y ), + curScaleName, GetLayoutFilename() ); p00.x = 0.05; p00.y = 0.25+0.05; DrawString( &page_d, p00, 0.0, dat, fp, 14.0, wDrawColorBlack ); } static void PrintPlainBox( - wPos_t x, - wPos_t y, - coOrd *corners ) + int x, + int y, + coOrd *corners ) { coOrd p00, p01, p10, p11; char tmp[30]; @@ -427,8 +438,9 @@ static void PrintPlainBox( DIST_T smiggin; smiggin = wDrawGetDPI( print_d.d ); - if (smiggin>4.0) + if (smiggin>4.0) { smiggin = 4.0/smiggin; + } pageW = currPrintGrid.size.x/print_d.scale; pageH = currPrintGrid.size.y/print_d.scale; @@ -482,7 +494,7 @@ static void PrintEnableControls( void ) printRegistrationMarks = 0; ParamControlActive( &printPG, I_REGMARKS, FALSE ); } - if (printScale <= (twoRailScale*2+1)/2.0) { + if ( DrawTwoRails( &print_d, 1 ) ) { ParamLoadControl( &printPG, I_ROADBED ); ParamControlActive( &printPG, I_ROADBED, TRUE ); ParamControlActive( &printPG, I_ROADBEDWIDTH, TRUE ); @@ -507,11 +519,6 @@ static void PrintUpdate( int inx0 ) ParamLoadData( &printPG ); - if (newPrintGrid.size.x > maxPageSize.x+0.01 || - newPrintGrid.size.y > maxPageSize.y+0.01) { - NoticeMessage( MSG_PRINT_MAX_SIZE, _("Ok"), NULL, - FormatSmallDistance(maxPageSize.x), FormatSmallDistance(maxPageSize.y) ); - } if (newPrintGrid.size.x > maxPageSize.x) { newPrintGrid.size.x = maxPageSize.x; ParamLoadControl( &printPG, 1 ); @@ -521,21 +528,22 @@ static void PrintUpdate( int inx0 ) ParamLoadControl( &printPG, 3 ); } currPrintGrid = newPrintGrid; - for ( inx = 0; inx < sizeof printPLs/sizeof printPLs[0]; inx++ ) { - if ( inx != inx0 && printPLs[inx].context == (void*)2 ) + for ( inx = 0; inx < COUNT( printPLs ); inx++ ) { + if ( inx != inx0 && printPLs[inx].context == I2VP(2) ) { ParamLoadControl( &printPG, inx ); + } } ChangeDim(); } -static void SetPageSize( BOOL_T doScale ) +static void SetMaxPageSize( BOOL_T doScale ) { WDOUBLE_T temp, x, y; wPrintGetPageSize( &x, &y ); - if (!printPhysSize) { - x -= (printMargin.left+printMargin.right); - y -= (printMargin.top+printMargin.bottom); + if (!bIgnoreMargins) { + x -= (customMargin.left+customMargin.right); + y -= (customMargin.top+customMargin.bottom); } maxPageSize.x = x; maxPageSize.y = y; @@ -549,16 +557,19 @@ static void SetPageSize( BOOL_T doScale ) printRotate = FALSE; } if (doScale) { - if (printGaudy) + if (printGaudy) { maxPageSize.y -= 1.0; + } maxPageSize.x *= printScale; maxPageSize.y *= printScale; } + r1_pgsz_x.high = maxPageSize.x+0.0001; + r1_pgsz_y.high = maxPageSize.y+0.0001; } /** * Select all pages for printing. - * + * */ static void SelectAllPages(void) @@ -580,7 +591,7 @@ static void PrintMaxPageSize( void ) * (depending on paper size, scale and orientation) */ { - SetPageSize( TRUE ); + SetMaxPageSize( TRUE ); currPrintGrid.size = maxPageSize; newPrintGrid = currPrintGrid; ParamLoadControls( &printPG ); @@ -595,7 +606,7 @@ static void DoPrintScale( void ) * Called whenever print scale or orientation changes. */ { - printScale = iPrintScale; + print_d.scale = printScale = iPrintScale; PrintMaxPageSize(); PrintEnableControls(); } @@ -607,48 +618,49 @@ static void DoPrintScale( void ) static void PrintMarginReset(); static paramFloatRange_t r0_1 = { 0.0, 1.0, 50 }; -static paramData_t printMarginPLs[] = { +static paramData_t customMarginPLs[] = { #define I_PM_FIRST (0) - { PD_FLOAT, &printMargin.top, "marginT", PDO_DIM|PDO_NOPREF, &r0_1, NULL, 0, NULL }, - { PD_FLOAT, &printMargin.right, "marginR", PDO_DIM|PDO_NOPREF, &r0_1, NULL, 0, NULL }, - { PD_FLOAT, &printMargin.bottom, "marginB", PDO_DIM|PDO_NOPREF, &r0_1, NULL, 0, NULL }, - { PD_FLOAT, &printMargin.left, "marginL", PDO_DIM|PDO_NOPREF, &r0_1, NULL, 0, NULL }, + { PD_FLOAT, &customMargin.top, "marginT", PDO_DIM|PDO_NOPREF, &r0_1, NULL, BO_IGNFOCUS, NULL }, + { PD_FLOAT, &customMargin.right, "marginR", PDO_DIM|PDO_NOPREF, &r0_1, NULL, BO_IGNFOCUS, NULL }, + { PD_FLOAT, &customMargin.bottom, "marginB", PDO_DIM|PDO_NOPREF, &r0_1, NULL, BO_IGNFOCUS, NULL }, + { PD_FLOAT, &customMargin.left, "marginL", PDO_DIM|PDO_NOPREF, &r0_1, NULL, BO_IGNFOCUS, NULL }, #define I_PM_COUNT (4) #define I_PM_MESSAGE (4) { PD_MESSAGE, NULL, NULL, 0, NULL }, #define I_PM_RESET (5) - { PD_BUTTON, (void*) PrintMarginReset, "marginReset", PDO_DLGCMDBUTTON, NULL, N_("Reset") } }; -static paramGroup_t printMarginPG = { "printMargin", PGO_PREFMISCGROUP|PGO_NODEFAULTPROC, printMarginPLs, sizeof printMarginPLs/sizeof printMarginPLs[0] }; + { PD_BUTTON, PrintMarginReset, "marginReset", PDO_DLGCMDBUTTON, NULL, N_("Reset") } +}; +static paramGroup_t customMarginPG = { "printMargin", PGO_PREFMISCGROUP|PGO_NODEFAULTPROC, customMarginPLs, COUNT( customMarginPLs ) }; static wLines_t aPmLines[] = { - { 1, 25, 11, 94, 11 }, - { 1, 94, 11, 94, 111 }, - { 1, 94, 111, 25, 111 }, - { 1, 25, 111, 25, 11 }}; + { 1, 25, 11, 94, 11 }, + { 1, 94, 11, 94, 111 }, + { 1, 94, 111, 25, 111 }, + { 1, 25, 111, 25, 11 } +}; static int pmxoff=14; static int pmyoff=5; static void PrintMarginLayout( - paramData_t * pd, - int index, - wPos_t colX, - wPos_t * w, - wPos_t * h ) + paramData_t * pd, + int index, + wWinPix_t colX, + wWinPix_t * w, + wWinPix_t * h ) { - if ( index < I_PM_FIRST || index > (I_PM_MESSAGE) ) + if ( index < I_PM_FIRST || index > (I_PM_MESSAGE) ) { return; + } if ( index == I_PM_MESSAGE ) { - *h = wControlGetPosY( printMarginPLs[I_PM_FIRST+2].control ) + wControlGetHeight( printMarginPLs[I_PM_FIRST+2].control ); + *h = wControlGetPosY( customMarginPLs[I_PM_FIRST+2].control ) + + wControlGetHeight( customMarginPLs[I_PM_FIRST+2].control ); return; } - wPos_t x0, y0; + wWinPix_t x0, y0; x0 = (aPmLines[index-I_PM_FIRST].x0+aPmLines[index-I_PM_FIRST].x1)/2; y0 = (aPmLines[index-I_PM_FIRST].y0+aPmLines[index-I_PM_FIRST].y1)/2; x0 -= pmxoff; y0 -= pmyoff; -// y0 += wControlGetPosY( printMarginPLs[0].control ) + wControlGetHeight( printMarginPLs[0].control ); -// x0 -= wControlGetWidth( printMarginPLs[index-I_PM_FIRST].control )/2; -// y0 -= wControlGetHeight( printMarginPLs[index-I_PM_FIRST].control )/2; *w = x0; *h = y0; } @@ -656,85 +668,98 @@ static void PrintMarginLayout( static const char * sPrinterName = NULL; -static BOOL_T SetMargins() +/** + * Get saved customMargins (default values = printerMargins) + * Return true is any values differ from default + */ +static void GetMargins() { - double top, right, bottom, left; - wPrintGetMargins( &top, &right, &bottom, &left ); + wPrintGetMargins( &printerMargin.top, &printerMargin.right, + &printerMargin.bottom, &printerMargin.left ); sprintf( message, "%s-marginT", sPrinterName ); - wPrefGetFloat( "printer", message, &printMargin.top, top ); + wPrefGetFloat( "printer", message, &customMargin.top, printerMargin.top ); sprintf( message, "%s-marginR", sPrinterName ); - wPrefGetFloat( "printer", message, &printMargin.right, right ); + wPrefGetFloat( "printer", message, &customMargin.right, printerMargin.right ); sprintf( message, "%s-marginB", sPrinterName ); - wPrefGetFloat( "printer", message, &printMargin.bottom, bottom ); + wPrefGetFloat( "printer", message, &customMargin.bottom, printerMargin.bottom ); sprintf( message, "%s-marginL", sPrinterName ); - wPrefGetFloat( "printer", message, &printMargin.left, left ); - ParamLoadControls( &printMarginPG ); - return - fabs( top - printMargin.top ) >= 0.001 || - fabs( right - printMargin.right ) >= 0.001 || - fabs( bottom - printMargin.bottom ) >= 0.001 || - fabs( left - printMargin.left ) >= 0.001; + wPrefGetFloat( "printer", message, &customMargin.left, printerMargin.left ); + ParamLoadControls( &customMarginPG ); } +/** + * Process PrintMargin Ok button + * Save updates margins + * Recalc page size and update dialog items + */ static void DoPrintMarginOk( void * context ) { - wHide( printMarginWin ); + wHide( customMarginWin ); sprintf( message, "%s-marginT", sPrinterName ); - wPrefSetFloat( "printer", message, printMargin.top ); + wPrefSetFloat( "printer", message, customMargin.top ); sprintf( message, "%s-marginR", sPrinterName ); - wPrefSetFloat( "printer", message, printMargin.right ); + wPrefSetFloat( "printer", message, customMargin.right ); sprintf( message, "%s-marginB", sPrinterName ); - wPrefSetFloat( "printer", message, printMargin.bottom ); + wPrefSetFloat( "printer", message, customMargin.bottom ); sprintf( message, "%s-marginL", sPrinterName ); - wPrefSetFloat( "printer", message, printMargin.left ); - SetPageSize( TRUE ); - for ( int inx = 0; inx < sizeof printPLs/sizeof printPLs[0]; inx++ ) { - if ( printPLs[inx].context == (void*)2 ) + wPrefSetFloat( "printer", message, customMargin.left ); + SetMaxPageSize( TRUE ); + for ( int inx = 0; inx < COUNT( printPLs ); inx++ ) { + if ( printPLs[inx].context == I2VP(2) ) { ParamLoadControl( &printPG, inx ); + } } + ParamLoadControls( &customMarginPG ); DoPrintScale(); } static void PrintMarginDlgUpdate( paramGroup_p pg, int index, void * context ) { - wControlActive( printMarginPLs[I_PM_RESET].control, TRUE ); + wBool_t bEnable = + fabs( printerMargin.top - customMargin.top ) >= 0.001 || + fabs( printerMargin.right - customMargin.right ) >= 0.001 || + fabs( printerMargin.bottom - customMargin.bottom ) >= 0.001 || + fabs( printerMargin.left - customMargin.left ) >= 0.001; + wControlActive( customMarginPLs[I_PM_RESET].control, bEnable ); } +/** + * Reset custom margins to printer margins + */ static void PrintMarginReset() { - wPrintGetMargins( &printMargin.top, &printMargin.right, &printMargin.bottom, &printMargin.left ); - ParamLoadControls( &printMarginPG ); - wControlActive( printMarginPLs[I_PM_RESET].control, FALSE ); + customMargin = printerMargin; + ParamLoadControls( &customMarginPG ); + wControlActive( customMarginPLs[I_PM_RESET].control, FALSE ); } +/** + * Open PrintMargin dialog + */ static void DoPrintMargin( void ) { - sPrinterName = wPrintGetName(); - while ( *sPrinterName == '\0' ) { - int rc = NoticeMessage( MSG_NO_PRINTER_SELECTED, _("Ok"), _("Cancel") ); - if ( rc <= 0 ) + if ( customMarginWin == NULL ) { + int x=10, y=10; + customMarginWin = ParamCreateDialog( &customMarginPG, + MakeWindowTitle(_("Print Margins")), _("Ok"), DoPrintMarginOk, NULL, TRUE, + PrintMarginLayout, F_BLOCK, PrintMarginDlgUpdate ); + if ( customMarginWin == NULL ) { return; - DoPrintSetup(); - } - if ( printMarginWin == NULL ) { - wPos_t x=10, y=10; - printMarginWin = ParamCreateDialog( &printMarginPG, MakeWindowTitle(_("Print Margins")), _("Ok"), DoPrintMarginOk, NULL, TRUE, PrintMarginLayout, F_BLOCK, PrintMarginDlgUpdate ); - if ( printMarginWin == NULL ) - return; - for ( int i=0; i<sizeof aPmLines / sizeof aPmLines[0]; i++ ) { + } + for ( int i=0; i<COUNT( aPmLines ); i++ ) { aPmLines[i].x0 += x; aPmLines[i].x1 += x; aPmLines[i].y0 += y; aPmLines[i].y1 += y; } - wLineCreate( printMarginWin, NULL, sizeof aPmLines / sizeof aPmLines[0], aPmLines ); + wLineCreate( customMarginWin, NULL, COUNT( aPmLines ), aPmLines ); } - wMessageSetValue( (wMessage_p)printMarginPLs[I_PM_MESSAGE].control, sPrinterName ); - // Enable Reset button if we've changed anything - wControlActive( printMarginPLs[I_PM_RESET].control, SetMargins() ); - wShow( printMarginWin ); + wMessageSetValue( (wMessage_p)customMarginPLs[I_PM_MESSAGE].control, + sPrinterName ); + ParamLoadControls( &customMarginPG ); + wShow( customMarginWin ); } @@ -745,7 +770,8 @@ static void DoPrintSetup( void ) { wPrintSetup( (wPrintSetupCallBack_p)DoPrintScale ); sPrinterName = wPrintGetName(); - SetPageSize( TRUE ); + GetMargins(); + SetMaxPageSize( TRUE ); } @@ -782,7 +808,7 @@ static void PrintSnapShot( void ) POS_T t; PrintClear(); - SetPageSize( FALSE ); + SetMaxPageSize( FALSE ); pageSize = realPageSize; if (pageSize.x > pageSize.y) { t = pageSize.x; @@ -792,24 +818,26 @@ static void PrintSnapShot( void ) size = mapD.size; scaleH = 1; - for (i=0;i<3;i++) { + for (i=0; i<3; i++) { size = mapD.size; - size.x += 0.75*scaleH; - size.y += 0.75*scaleH; - if (printGaudy) + size.x += 2*0.5*scaleH; + size.y += 2*0.5*scaleH; + if (printGaudy) { size.y += 1.0*scaleH; + } scaleX = size.x/pageSize.x; scaleY = size.y/pageSize.y; scaleH = (long)ceil(max( scaleX, scaleY )); } scaleV = 1; - for (i=0;i<3;i++) { + for (i=0; i<3; i++) { size = mapD.size; - size.x += 0.75*scaleV; - size.y += 0.75*scaleV; - if (printGaudy) + size.x += 2*0.5*scaleV; + size.y += 2*0.5*scaleV; + if (printGaudy) { size.y += 1.0*scaleV; + } scaleX = size.x/pageSize.y; scaleY = size.y/pageSize.x; scaleV = (long)ceil(max( scaleX, scaleY )); @@ -823,17 +851,17 @@ static void PrintSnapShot( void ) printFormat = LANDSCAPE; } - SetPageSize( TRUE ); -/* - if (printFormat == LANDSCAPE) { - currPrintGrid.orig.x = -0.5*printScale; - currPrintGrid.orig.y = maxPageSize.x-0.5*printScale; - currPrintGrid.angle = 90.0; - } else {*/ - currPrintGrid.orig.x = -0.5*printScale; - currPrintGrid.orig.y = -0.5*printScale; - currPrintGrid.angle = 0.0; -/* }*/ + SetMaxPageSize( TRUE ); + /* + if (printFormat == LANDSCAPE) { + currPrintGrid.orig.x = -0.5*printScale; + currPrintGrid.orig.y = maxPageSize.x-0.5*printScale; + currPrintGrid.angle = 90.0; + } else {*/ + currPrintGrid.orig.x = -0.5*printScale; //Bigger rulers + currPrintGrid.orig.y = -0.5*printScale; //Bigger rules + currPrintGrid.angle = 0.0; + /* }*/ currPrintGrid.size = maxPageSize; newPrintGrid = currPrintGrid; iPrintScale = (long)printScale; @@ -854,7 +882,7 @@ static void DrawRegistrationMarks( drawCmd_p d ) long x, y, delta, divisor; coOrd p0, p1, qq, q0, q1; POS_T len; - char msg[10]; + char msg[STR_SIZE]; wFont_p fp; wFontSize_t fs; fp = wStandardFont( F_TIMES, FALSE, FALSE ); @@ -869,9 +897,11 @@ static void DrawRegistrationMarks( drawCmd_p d ) qq.x = p0.x = p1.x = (POS_T)GetDim(x); p0.y = 0.0; p1.y = mapD.size.y; - if (!ClipLine( &p0, &p1, d->orig, d->angle, d->size )) + if (!ClipLine( &p0, &p1, d->orig, d->angle, d->size )) { continue; - for ( y=(long)(ceil(PutDim(p0.y)/delta)*delta); (POS_T)y<PutDim(p1.y); y+=delta ) { + } + for ( y=(long)(ceil(PutDim(p0.y)/delta)*delta); (POS_T)y<PutDim(p1.y); + y+=delta ) { qq.y = (POS_T)GetDim(y); q0.x = q1.x = qq.x; if ( x%divisor == 0 && y%divisor == 0 ) { @@ -890,16 +920,18 @@ static void DrawRegistrationMarks( drawCmd_p d ) DrawLine( d, q0, q1, 0, wDrawColorBlack ); q0.x = qq.x + len/4;; q0.y = qq.y + len/4;; - if (units == UNITS_METRIC) + if (units == UNITS_METRIC) { sprintf( msg, "%0.1fm", (DOUBLE_T)x/100.0 ); - else + } else { sprintf( msg, "%ld\' %ld\"", x/12, x%12 ); + } DrawString( d, q0, 0.0, msg, fp, fs, wDrawColorBlack ); q0.y = qq.y - len*3/4; - if (units == UNITS_METRIC) + if (units == UNITS_METRIC) { sprintf( msg, "%0.1fm", (DOUBLE_T)y/100.0 ); - else + } else { sprintf( msg, "%ld\' %ld\"", y/12, y%12 ); + } DrawString( d, q0, 0.0, msg, fp, fs, wDrawColorBlack ); } } @@ -917,20 +949,22 @@ static void DrawRegistrationMarks( drawCmd_p d ) static char * FormatPageNumber(int x, int y) { - DynString formatted; - char *result; - - DynStringMalloc(&formatted, 16); - if (x > 0 && x <= bm.x1 && y > 0 && y <= bm.y1) { - DynStringPrintf(&formatted, "(%d/%d)", x, y); - } else { - DynStringCatCStr(&formatted, "(-/-)"); - } + DynString formatted; + char *result; + + DynStringMalloc(&formatted, 16); + x -= bm.x0-1; + y -= bm.y0-1; + if (x > 0 && x <= bm.x1-bm.x0 && y > 0 && y <= bm.y1-bm.y0) { + DynStringPrintf(&formatted, "(%d/%d)", x, y); + } else { + DynStringCatCStr(&formatted, "(-/-)"); + } - result = strdup(DynStringToCStr(&formatted)); - DynStringFree(&formatted); + result = strdup(DynStringToCStr(&formatted)); + DynStringFree(&formatted); - return (result); + return (result); } /** @@ -944,36 +978,39 @@ FormatPageNumber(int x, int y) */ static bool -PrintPageNumber(wPos_t x, wPos_t y, DIST_T width, DIST_T height) +PrintPageNumber(int x, int y, DIST_T width, DIST_T height) { - coOrd printPosition; - coOrd textSize; + coOrd printPosition; + coOrd textSize; - char *positionText; - wFont_p fp = wStandardFont(F_HELV, TRUE, FALSE); - wFontSize_t fs = 64.0; + char *positionText; + wFont_p fp = wStandardFont(F_HELV, TRUE, FALSE); + wFontSize_t fs = 64.0; - positionText = FormatPageNumber(x + 1, y + 1); + positionText = FormatPageNumber(x, y); - // even though we're printing into page_d, mainD must be used here - DrawTextSize(&mainD, positionText, fp, fs, TRUE, &textSize); + if (strcmp(positionText,"(-/-)") != 0) { + // even though we're printing into page_d, mainD must be used here + DrawTextSize(&mainD, positionText, fp, fs, TRUE, &textSize); - if (printFormat == PORTRAIT) { - printPosition.x = (width - textSize.x) / 2; - printPosition.y = (height - textSize.y) / 2; - } else { - printPosition.x = (height - textSize.x) / 2; - printPosition.y = (width - textSize.y) / 2; - } + if (printFormat == PORTRAIT) { + printPosition.x = (width - textSize.x) / 2; + printPosition.y = (height - textSize.y) / 2; + } else { + printPosition.x = (height - textSize.x) / 2; + printPosition.y = (width - textSize.y) / 2; + } - page_d.funcs->options |= wDrawOutlineFont; - DrawString(&page_d, printPosition, 0.0, positionText, fp, fs, - wDrawColorGray(70)); - page_d.funcs->options &= ~wDrawOutlineFont; + unsigned long options = page_d.options; + page_d.options |= DC_OUTLINE; + DrawString(&page_d, printPosition, 0.0, positionText, fp, fs, + wDrawColorGray(70)); + page_d.options = options; + } - free(positionText); + free(positionText); - return (TRUE); + return (TRUE); } /** @@ -987,32 +1024,35 @@ PrintPageNumber(wPos_t x, wPos_t y, DIST_T width, DIST_T height) void PrintNextPageNumberAt(int x, int y, coOrd position) { - char *pageNumber; - wFont_p fp = wStandardFont(F_HELV, FALSE, FALSE); - wFontSize_t fs = 8.0; - - pageNumber = FormatPageNumber(x, y); - DrawString(&page_d, position, 0.0, pageNumber, fp, fs, wDrawColorBlack); - free(pageNumber); + char *pageNumber; + wFont_p fp = wStandardFont(F_HELV, FALSE, FALSE); + wFontSize_t fs = 8.0; + + pageNumber = FormatPageNumber(x, y); + //Suppress garbage page numbers + if (strcmp(pageNumber,"(-/-)") != 0) { + DrawString(&page_d, position, 0.0, pageNumber, fp, fs, wDrawColorBlack); + } + free(pageNumber); } /** * Print the page numbers of all four adjoining pages (left, right, above, below) - * + * * \param x page index of current page x * \param y page index of current page y * \param pageW width of page * \param pageH height of page - * + * * \return TRUE */ static bool PrintNextPageNumbers(int x, int y, DIST_T pageW, DIST_T pageH) { - coOrd p00; + coOrd p00; - // above + // above if (printFormat == PORTRAIT) { p00.x = pageW / 2.0 - 20.0 / 72.0; p00.y = pageH - 10.0 / 72.0; @@ -1020,17 +1060,17 @@ PrintNextPageNumbers(int x, int y, DIST_T pageW, DIST_T pageH) p00.x = pageH / 2.0 - 20.0 / 72.0; p00.y = pageW - 10.0 / 72.0; } - PrintNextPageNumberAt(x + 1, y + 2, p00); + PrintNextPageNumberAt(x, y + 1, p00); - // below + // below if (printFormat == PORTRAIT) { p00.y = 10.0 / 72.0; } else { p00.y = 10.0 / 72.0; } - PrintNextPageNumberAt(x + 1, y, p00); + PrintNextPageNumberAt(x, y-1, p00); - // right + // right if (printFormat == PORTRAIT) { p00.y = pageH / 2 + 10.0 / 72.0; p00.x = pageW - 20.0 / 72.0; @@ -1038,7 +1078,7 @@ PrintNextPageNumbers(int x, int y, DIST_T pageW, DIST_T pageH) p00.y = pageW / 2 + 10.0 / 72.0; p00.x = pageH - 20.0 / 72.0; } - PrintNextPageNumberAt(x + 2, y + 1, p00); + PrintNextPageNumberAt(x+1, y, p00); // left if (printFormat == PORTRAIT) { @@ -1046,187 +1086,212 @@ PrintNextPageNumbers(int x, int y, DIST_T pageW, DIST_T pageH) } else { p00.x = 10.0 / 72.0; } - PrintNextPageNumberAt(x, y + 1, p00); - return (TRUE); + PrintNextPageNumberAt(x-1, y, p00); + return (TRUE); } static BOOL_T PrintPage( - int x, - int y ) + int x, + int y ) { coOrd orig, p[4], psave[4], minP, maxP; int i; coOrd clipOrig, clipSize; coOrd roomSize; - if (BITMAP(bm,x,y)) { - orig.x = currPrintGrid.orig.x + x*currPrintGrid.size.x; - orig.y = currPrintGrid.orig.y + y*currPrintGrid.size.y; - if (printPhysSize) { - orig.x += printMargin.left; - orig.y += printMargin.bottom; - } - Rotate( &orig, currPrintGrid.orig, currPrintGrid.angle ); - p[0] = p[1] = p[2] = p[3] = orig; - p[1].x = p[2].x = orig.x + currPrintGrid.size.x; - p[2].y = p[3].y = orig.y + currPrintGrid.size.y + - ( printGaudy ? printScale : 0.0 ); - Rotate( &p[0], orig, currPrintGrid.angle ); - Rotate( &p[1], orig, currPrintGrid.angle ); - Rotate( &p[2], orig, currPrintGrid.angle ); - Rotate( &p[3], orig, currPrintGrid.angle ); - minP = maxP = p[0]; - for (i=1; i<4; i++) { - if (maxP.x < p[i].x) maxP.x = p[i].x; - if (maxP.y < p[i].y) maxP.y = p[i].y; - if (minP.x > p[i].x) minP.x = p[i].x; - if (minP.y > p[i].y) minP.y = p[i].y; - } - maxP.x -= minP.x; - maxP.y -= minP.y; - print_d.d = page_d.d = wPrintPageStart(); - if (page_d.d == NULL) - return FALSE; - print_d.dpi = page_d.dpi = wDrawGetDPI( print_d.d ); - print_d.angle = currPrintGrid.angle; - print_d.orig = orig; - print_d.size = /*maxP*/ currPrintGrid.size; - page_d.orig = zero; - page_d.angle = 0.0; - if ( printGaudy ) { - Translate( &print_d.orig, orig, currPrintGrid.angle+180.0, printScale ); - print_d.size.y += printScale; - } - for (int i=0;i<4;i++) { - psave[i] = p[i]; - } - if (printRotate) { - rotateCW = (printFormat != PORTRAIT); - if (rotateCW) { - page_d.orig.x = realPageSize.y; - page_d.orig.y = 0.0; - page_d.angle = -90.0; - print_d.angle += -90.0; - Translate( &print_d.orig, print_d.orig, currPrintGrid.angle+90, maxPageSize.x ); - } else { - page_d.orig.x = 0.0; - page_d.orig.y = realPageSize.x; - page_d.angle = 90.0; - print_d.angle += 90.0; - Translate( &print_d.orig, print_d.orig, currPrintGrid.angle, - maxPageSize.y+(printGaudy?printScale:0) ); - } - page_d.size.x = print_d.size.y/printScale; - page_d.size.y = print_d.size.x/printScale; - print_d.size.x = currPrintGrid.size.y; - print_d.size.y = currPrintGrid.size.x; - } else { - page_d.size.x = print_d.size.x/printScale; - page_d.size.y = print_d.size.y/printScale; - } - wSetCursor( mainD.d, wCursorWait ); - print_d.scale = printScale; - if (print_d.d == NULL) - AbortProg( "wPrintPageStart" ); - clipOrig.x = clipOrig.y = 0; - clipSize.x = maxPageSize.x/printScale; - clipSize.y = maxPageSize.y/printScale; - GetRoomSize( &roomSize ); - if (printGaudy) { - PrintGaudyBox( roomSize ); - if ((!printRotate) || rotateCW) { - clipOrig.y = 1.0; - } - if (printRotate && rotateCW) { - print_d.size.x += printScale; - } - } - if (printRotate) { - wPrintClip( (wPos_t)(clipOrig.y*print_d.dpi), (wPos_t)(clipOrig.x*print_d.dpi), - (wPos_t)(clipSize.y*print_d.dpi), (wPos_t)(clipSize.x*print_d.dpi) ); - } else { - wPrintClip( (wPos_t)(clipOrig.x*print_d.dpi), (wPos_t)(clipOrig.y*print_d.dpi), - (wPos_t)(clipSize.x*print_d.dpi), (wPos_t)(clipSize.y*print_d.dpi) ); - } - p[0].x = p[3].x = 0.0; - p[1].x = p[2].x = roomSize.x; - p[0].y = p[1].y = 0.0; - p[2].y = p[3].y = roomSize.y; - - DrawRuler( &print_d, p[0], p[1], 0.0, TRUE, FALSE, wDrawColorBlack ); - DrawRuler( &print_d, p[0], p[3], 0.0, TRUE, TRUE, wDrawColorBlack ); - DrawRuler( &print_d, p[1], p[2], 0.0, FALSE, FALSE, wDrawColorBlack ); - DrawRuler( &print_d, p[3], p[2], 0.0, FALSE, TRUE, wDrawColorBlack ); - if ( printRuler && currPrintGrid.angle == 0 ) { - if ( !printRotate ) { - p[2] = p[3] = print_d.orig; - p[3].x += print_d.size.x; - p[3].y += print_d.size.y; - } else if ( rotateCW ) { - p[2].x = print_d.orig.x - print_d.size.y; - p[2].y = print_d.orig.y; - p[3].x = print_d.orig.x; - p[3].y = print_d.orig.y + print_d.size.x; - } else { - p[2].x = print_d.orig.x; - p[2].y = print_d.orig.y - print_d.size.x; - p[3].x = print_d.orig.x + print_d.size.y; - p[3].y = print_d.orig.y; - } - if ( p[2].x > 0 ) - minP.x = p[2].x + 0.4 * print_d.scale; - else - minP.x = 0.0; - if ( p[3].x < roomSize.x ) - maxP.x = p[3].x - 0.2 * print_d.scale; - else - maxP.x = roomSize.x; - if ( p[2].y > 0 ) - minP.y = p[2].y + 0.4 * print_d.scale; - else - minP.y = 0.0; - if ( p[3].y < roomSize.y ) - maxP.y = p[3].y - 0.2 * print_d.scale; - else - maxP.y = roomSize.y; - p[0].y = 0.0; - p[1].y = maxP.y - minP.y; - if ( p[2].x > 0 ) { - p[0].x = p[1].x = p[2].x + 0.4 * print_d.scale; - DrawRuler( &print_d, p[0], p[1], minP.y, TRUE, TRUE, wDrawColorBlack ); - } - if ( p[3].x < roomSize.x ) { - p[0].x = p[1].x = p[3].x - 0.2 * print_d.scale; - DrawRuler( &print_d, p[0], p[1], minP.y, FALSE, FALSE, wDrawColorBlack ); - } - p[0].x = 0; - p[1].x = maxP.x - minP.x; - if ( p[2].y > 0 ) { - p[0].y = p[1].y = p[2].y + 0.4 * print_d.scale; - DrawRuler( &print_d, p[0], p[1], minP.x, TRUE, FALSE, wDrawColorBlack ); - } - if ( p[3].y < roomSize.y ) { - p[0].y = p[1].y = p[3].y - 0.2 * print_d.scale; - DrawRuler( &print_d, p[0], p[1], minP.x, FALSE, TRUE, wDrawColorBlack ); - } - } + if (BITMAP(bm,x,y)) { + orig.x = currPrintGrid.orig.x + x*currPrintGrid.size.x; + orig.y = currPrintGrid.orig.y + y*currPrintGrid.size.y; + orig.x += printerMargin.left; + orig.y += printerMargin.bottom; + if (!bIgnoreMargins) { + orig.x -= customMargin.left; + orig.y -= customMargin.bottom; + } + Rotate( &orig, currPrintGrid.orig, currPrintGrid.angle ); + p[0] = p[1] = p[2] = p[3] = orig; + p[1].x = p[2].x = orig.x + currPrintGrid.size.x; + p[2].y = p[3].y = orig.y + currPrintGrid.size.y + + ( printGaudy ? printScale : 0.0 ); + Rotate( &p[0], orig, currPrintGrid.angle ); + Rotate( &p[1], orig, currPrintGrid.angle ); + Rotate( &p[2], orig, currPrintGrid.angle ); + Rotate( &p[3], orig, currPrintGrid.angle ); + minP = maxP = p[0]; + for (i=1; i<4; i++) { + if (maxP.x < p[i].x) { maxP.x = p[i].x; } + if (maxP.y < p[i].y) { maxP.y = p[i].y; } + if (minP.x > p[i].x) { minP.x = p[i].x; } + if (minP.y > p[i].y) { minP.y = p[i].y; } + } + maxP.x -= minP.x; + maxP.y -= minP.y; + print_d.d = page_d.d = wPrintPageStart(); + if (page_d.d == NULL) { + return FALSE; + } + print_d.dpi = page_d.dpi = wDrawGetDPI( print_d.d ); + print_d.angle = currPrintGrid.angle; + print_d.orig = orig; + print_d.size = /*maxP*/ currPrintGrid.size; + page_d.orig = zero; + page_d.angle = 0.0; + if ( printGaudy ) { + Translate( &print_d.orig, orig, currPrintGrid.angle+180.0, printScale ); + print_d.size.y += printScale; + } + for (int i=0; i<4; i++) { + psave[i] = p[i]; + } + if (printRotate) { + rotateCW = (printFormat != PORTRAIT); + if (rotateCW) { + page_d.orig.x = realPageSize.y; + page_d.orig.y = 0.0; + page_d.angle = -90.0; + print_d.angle += -90.0; + Translate( &print_d.orig, print_d.orig, currPrintGrid.angle+90, maxPageSize.x ); + } else { + page_d.orig.x = 0.0; + page_d.orig.y = realPageSize.x; + page_d.angle = 90.0; + print_d.angle += 90.0; + Translate( &print_d.orig, print_d.orig, currPrintGrid.angle, + maxPageSize.y+(printGaudy?printScale:0) ); + } + page_d.size.x = print_d.size.y/printScale; + page_d.size.y = print_d.size.x/printScale; + print_d.size.x = currPrintGrid.size.y; + print_d.size.y = currPrintGrid.size.x; + } else { + page_d.size.x = print_d.size.x/printScale; + page_d.size.y = print_d.size.y/printScale; + } + wSetCursor( mainD.d, wCursorWait ); + print_d.scale = printScale; + CHECK(print_d.d); + clipOrig.x = clipOrig.y = 0; + clipSize.x = maxPageSize.x/printScale; + clipSize.y = maxPageSize.y/printScale; + roomSize = mapD.size; + if (printGaudy) { + PrintGaudyBox( roomSize ); + if ((!printRotate) || rotateCW) { + clipOrig.y = 1.0; + } + if (printRotate && rotateCW) { + print_d.size.x += printScale; + } + } + if (printRotate) { + wPrintClip( (clipOrig.y*print_d.dpi), (clipOrig.x*print_d.dpi), + (clipSize.y*print_d.dpi), (clipSize.x*print_d.dpi) ); + } else { + wPrintClip( (clipOrig.x*print_d.dpi), (clipOrig.y*print_d.dpi), + (clipSize.x*print_d.dpi), (clipSize.y*print_d.dpi) ); + } + p[0].x = p[3].x = 0.0; + p[1].x = p[2].x = roomSize.x; + p[0].y = p[1].y = 0.0; + p[2].y = p[3].y = roomSize.y; + + BOOL_T left_clear = FALSE, right_clear = FALSE, base_clear = FALSE, + top_clear = FALSE; + + if (currPrintGrid.orig.x <= -0.5*printScale) { left_clear = TRUE; } + if (currPrintGrid.orig.y <= -0.5*printScale) { base_clear = TRUE; } + if (clipOrig.x + clipSize.x > roomSize.x + 0.5*printScale) { right_clear = TRUE; } + if (clipOrig.y + clipSize.y > roomSize.y + 0.5*printScale) { top_clear = TRUE; } + + if (printRuler != 2) { /* Not None so Edge or Every */ + DrawRuler( &print_d, p[0], p[1], 0.0, TRUE, !base_clear, wDrawColorBlack ); + DrawRuler( &print_d, p[0], p[3], 0.0, TRUE, left_clear, wDrawColorBlack ); + DrawRuler( &print_d, p[1], p[2], 0.0, TRUE, right_clear, wDrawColorBlack ); + DrawRuler( &print_d, p[3], p[2], 0.0, TRUE, !top_clear, wDrawColorBlack ); + } + if ( printRuler==1 + && currPrintGrid.angle == 0 ) { /* Every Page and not rotated origin */ + if ( !printRotate ) { + p[2] = p[3] = print_d.orig; + p[3].x += print_d.size.x; + p[3].y += print_d.size.y; + } else if ( rotateCW ) { + p[2].x = print_d.orig.x - print_d.size.y; + p[2].y = print_d.orig.y; + p[3].x = print_d.orig.x; + p[3].y = print_d.orig.y + print_d.size.x; + } else { + p[2].x = print_d.orig.x; + p[2].y = print_d.orig.y - print_d.size.x; + p[3].x = print_d.orig.x + print_d.size.y; + p[3].y = print_d.orig.y; + } + if ( p[2].x > 0 ) { + minP.x = p[2].x + 0.5 * print_d.scale; + } else { + minP.x = 0.0; + } + if ( p[3].x < roomSize.x ) { + maxP.x = p[3].x - 0.5 * print_d.scale; + } else { + maxP.x = roomSize.x; + } + if ( p[2].y > 0 ) { + minP.y = p[2].y + 0.5 * print_d.scale; + } else { + minP.y = 0.0; + } + if ( p[3].y < roomSize.y ) { + maxP.y = p[3].y - 0.5 * print_d.scale; + } else { + maxP.y = roomSize.y; + } + p[0].y = 0.0; + p[1].y = maxP.y - minP.y; + if ( p[2].x > 0.5* print_d.scale ) { + p[0].x = p[1].x = p[2].x + 0.5* print_d.scale; + DrawRuler( &print_d, p[0], p[1], minP.y, TRUE, TRUE, wDrawColorBlack ); + } + if ( p[3].x < roomSize.x - 0.5 * print_d.scale ) { + p[0].x = p[1].x = p[3].x - 0.5 * print_d.scale; + DrawRuler( &print_d, p[0], p[1], minP.y, TRUE, FALSE, wDrawColorBlack ); + } + p[0].x = 0; + p[1].x = maxP.x - minP.x; + if ( p[2].y > 0.5 * print_d.scale ) { + p[0].y = p[1].y = p[2].y + 0.5 * print_d.scale; + DrawRuler( &print_d, p[0], p[1], minP.x, TRUE, FALSE, wDrawColorBlack ); + } + if ( p[3].y < roomSize.y - 0.5 * print_d.scale) { + p[0].y = p[1].y = p[3].y - 0.5 * print_d.scale; + DrawRuler( &print_d, p[0], p[1], minP.x, TRUE, TRUE, wDrawColorBlack ); + } + } - if (printGrid) - DrawSnapGrid( &print_d, mapD.size, FALSE ); - roadbedWidth = printRoadbed?printRoadbedWidth:0.0; - printCenterLines = printCenterLine; - DrawTracks( &print_d, print_d.scale, minP, maxP ); - if (printRegistrationMarks && printScale == 1) - DrawRegistrationMarks( &print_d ); - if (printRegistrationMarks) - PrintPlainBox( x, y, psave ); - - if (printPageNumbers) { - PrintPageNumber(x, y, page_d.size.x, page_d.size.y); - PrintNextPageNumbers(x, y, page_d.size.x, page_d.size.y); - } - if ( !wPrintPageEnd( print_d.d ) ) - return FALSE; + if (printGrid) { + DrawSnapGrid( &print_d, mapD.size, FALSE ); + } + roadbedWidth = printRoadbed?printRoadbedWidth:0.0; + if (printCenterLine) { + print_d.options |= DC_CENTERLINE; + } else { + print_d.options &= ~DC_CENTERLINE; + } + DrawTracks( &print_d, print_d.scale, minP, maxP ); + if (printRegistrationMarks && printScale == 1) { + DrawRegistrationMarks( &print_d ); + } + if (printRegistrationMarks) { + PrintPlainBox( x, y, psave ); + } + + if (printPageNumbers) { + PrintPageNumber(x, y, page_d.size.x, page_d.size.y); + PrintNextPageNumbers(x, y, page_d.size.x, page_d.size.y); + } + if ( !wPrintPageEnd( print_d.d ) ) { + return FALSE; + } } return TRUE; } @@ -1256,23 +1321,25 @@ static void DoPrintPrint( void * junk ) wSetCursor( mainD.d, defaultCursor ); return; } - if (copies <= 0) + if (copies <= 0) { copies = 1; + } for ( copy=1; copy<=copies; copy++) { if ( printOrder == 0 ) { for (x=bm.x0; x<bm.x1; x++) for (y=bm.y1-1; y>=bm.y0; y--) - if (!PrintPage( x, y )) goto quitPrinting; + if (!PrintPage( x, y )) { goto quitPrinting; } } else { for (y=bm.y0; y<bm.y1; y++) for (x=bm.x0; x<bm.x1; x++) - if (!PrintPage( x, y )) goto quitPrinting; + if (!PrintPage( x, y )) { goto quitPrinting; } } for (y=bm.y0; y<bm.y1; y++) for (x=bm.x0; x<bm.x1; x++) if (BITMAP(bm,x,y)) { - if (copy >= copies) + if (copy >= copies) { BITMAP(bm,x,y) = 0; + } } } @@ -1296,7 +1363,7 @@ static void DoResetGrid( void ) static void PrintGridRotate( void * pangle ) { - ANGLE_T angle = (ANGLE_T)(long)pangle; + ANGLE_T angle = (ANGLE_T)VP2L(pangle); currPrintGrid.orig = cmdMenuPos; currPrintGrid.angle += angle/1000; newPrintGrid = currPrintGrid; @@ -1313,11 +1380,14 @@ static void PrintGridRotate( void * pangle ) static void PrintChange( long changes ) { - if ( (changes&(CHANGE_MAP|CHANGE_UNITS|CHANGE_GRID))==0 || printWin==NULL || !wWinIsVisible(printWin) ) + if ( (changes&(CHANGE_MAP|CHANGE_UNITS|CHANGE_GRID))==0 || printWin==NULL + || !wWinIsVisible(printWin) ) { return; + } newPrintGrid = currPrintGrid; - if (!GridIsVisible()) + if (!GridIsVisible()) { printGrid = 0; + } ParamLoadControls( &printPG ); ParamControlActive( &printPG, I_GRID, GridIsVisible() ); PrintEnableControls(); @@ -1325,22 +1395,23 @@ static void PrintChange( long changes ) static void PrintDlgUpdate( - paramGroup_p pg, - int inx, - void * valueP ) + paramGroup_p pg, + int inx, + void * valueP ) { - if ( inx < 0 ) return; - if ( pg->paramPtr[inx].context == (void*)1 ) + if ( inx < 0 ) { return; } + if ( pg->paramPtr[inx].context == I2VP(1) ) { DoPrintScale(); - else if ( pg->paramPtr[inx].context == (void*)2 ) + } else if ( pg->paramPtr[inx].context == I2VP(2) ) { PrintUpdate( inx ); + } ParamControlActive( &printPG, I_RULER, currPrintGrid.angle == 0 ); TempRedraw(); // PrintDlgUpdate } static STATUS_T CmdPrint( - wAction_t action, - coOrd pos ) + wAction_t action, + coOrd pos ) /* * Print command: * @@ -1356,33 +1427,46 @@ static STATUS_T CmdPrint( switch (action) { case C_START: - if (!wPrintInit()) + if (!wPrintInit()) { return C_TERMINATE; + } printScale = iPrintScale; if (printWin == NULL) { rminScale_999.low = 1; - if (printScale < rminScale_999.low) + if (printScale < rminScale_999.low) { printScale = rminScale_999.low; + } print_d.scale = printScale; - printWin = ParamCreateDialog( &printPG, MakeWindowTitle(_("Print")), _("Print"), DoPrintPrint, (paramActionCancelProc)Reset, TRUE, NULL, 0, PrintDlgUpdate ); + printWin = ParamCreateDialog( &printPG, MakeWindowTitle(_("Print")), _("Print"), + DoPrintPrint, (paramActionCancelProc)Reset, TRUE, NULL, 0, PrintDlgUpdate ); } sPrinterName = wPrintGetName(); - SetMargins(); + while ( *sPrinterName == '\0' ) { + int rc = NoticeMessage( MSG_NO_PRINTER_SELECTED, _("Ok"), _("Cancel") ); + if ( rc <= 0 ) { + return C_TERMINATE; + } + DoPrintSetup(); + } + GetMargins(); wShow( printWin ); - SetPageSize( TRUE ); + SetMaxPageSize( TRUE ); if (currPrintGrid.size.x == 0.0) { currPrintGrid.size.x = maxPageSize.x; currPrintGrid.size.y = maxPageSize.y; } - if (currPrintGrid.size.x >= maxPageSize.x) + if (currPrintGrid.size.x >= maxPageSize.x) { currPrintGrid.size.x = maxPageSize.x; - if (currPrintGrid.size.y >= maxPageSize.y) + } + if (currPrintGrid.size.y >= maxPageSize.y) { currPrintGrid.size.y = maxPageSize.y; + } newPrintGrid = currPrintGrid; ParamLoadControls( &printPG ); pageCount = 0; UpdatePageCount(); -LOG( log_print, 2, ( "Page size = %0.3f %0.3f\n", currPrintGrid.size.x, currPrintGrid.size.y ) ) + LOG( log_print, 2, ( "Page size = %0.3f %0.3f\n", currPrintGrid.size.x, + currPrintGrid.size.y ) ) PrintChange( CHANGE_MAP|CHANGE_UNITS ); ChangeDim(); InfoMessage( _("Select pages to print, or drag to move print grid") ); @@ -1454,8 +1538,9 @@ LOG( log_print, 2, ( "Page size = %0.3f %0.3f\n", currPrintGrid.size.x, currPrin return C_TERMINATE; case C_CANCEL: - if (printWin == NULL) + if (printWin == NULL) { return C_TERMINATE; + } PrintClear(); wHide( printWin ); return C_TERMINATE; @@ -1474,6 +1559,9 @@ LOG( log_print, 2, ( "Page size = %0.3f %0.3f\n", currPrintGrid.size.x, currPrin } } + +#include "bitmaps/doc-print.xpm3" + EXPORT wIndex_t InitCmdPrint( wMenu_p menu ) { ParamRegister( &printPG ); @@ -1482,8 +1570,10 @@ EXPORT wIndex_t InitCmdPrint( wMenu_p menu ) RegisterChangeNotification( PrintChange ); printGridPopupM = MenuRegister( "Print Grid Rotate" ); AddRotateMenu( printGridPopupM, PrintGridRotate ); - ParamRegister( &printMarginPG ); - return InitCommand( menu, CmdPrint, N_("Print..."), NULL, LEVEL0, IC_LCLICK|IC_POPUP3|IC_CMDMENU, ACCL_PRINT ); + ParamRegister( &customMarginPG ); + return AddMenuButton( menu, CmdPrint, "cmdPrint", N_("Print..."), + wIconCreatePixMap(doc_print_xpm3[iconSize]), LEVEL0, + IC_LCLICK|IC_POPUP3|IC_CMDMENU, ACCL_PRINT, NULL ); } /***************************************************************************** @@ -1495,11 +1585,7 @@ EXPORT wIndex_t InitCmdPrint( wMenu_p menu ) wDrawable_t printD, mainD; -void wDrawHilight( void * d, coOrd orig, coOrd size ) -{ - lprintf( "wDrawHilight (%0.3f %0.3f) (%0.3f %0.3f)\n", orig.x, orig.y, size.x, size.y ); -} -void PrintPage( void * d, wIndex_t mode , wIndex_t x, wIndex_t y ) +void PrintPage( void * d, wIndex_t mode, wIndex_t x, wIndex_t y ) { lprintf( "printPage %dx%d at (%0.3f %0.3f)\n", x, y, orig.x, orig.y ); } @@ -1526,7 +1612,7 @@ void DumpMap( char * f, ANGLE_T a, ANGLE_T b ) } else { lprintf( " "); } - lprintf( "\n"); + lprintf( "\n"); } } @@ -1538,24 +1624,24 @@ struct { wAction_t cmd; coOrd pos; } cmds[] = { - { C_START, 0, 0 }, - { C_DOWN, 20.5, 12.4 }, - { C_MOVE, 20.5, 12.5 }, - { C_MOVE, 20.5, 12.3 }, - { C_MOVE, 39.3, 69.4 }, - { C_MOVE, 39.4, 4.5 }, - { C_MOVE, 2.4, 4.5 }, - { C_MOVE, 2.4, 50.3 }, - { C_UP, 0, 0 }, - { C_DOWN, 20.5, 12.4 }, - { C_UP, 0, 0 }, - { C_DOWN, 32.5, 4.4 }, - { C_UP, 0, 0 }, - { C_PRINT, 0, 0, }, - { C_START, 0, 0, }, - { C_DOWN, 45.3, 43.5 }, - { C_CANCEL, 0, 0 } - }; + { C_START, 0, 0 }, + { C_DOWN, 20.5, 12.4 }, + { C_MOVE, 20.5, 12.5 }, + { C_MOVE, 20.5, 12.3 }, + { C_MOVE, 39.3, 69.4 }, + { C_MOVE, 39.4, 4.5 }, + { C_MOVE, 2.4, 4.5 }, + { C_MOVE, 2.4, 50.3 }, + { C_UP, 0, 0 }, + { C_DOWN, 20.5, 12.4 }, + { C_UP, 0, 0 }, + { C_DOWN, 32.5, 4.4 }, + { C_UP, 0, 0 }, + { C_PRINT, 0, 0, }, + { C_START, 0, 0, }, + { C_DOWN, 45.3, 43.5 }, + { C_CANCEL, 0, 0 } +}; main( INT_T argc, char * argv[] ) { @@ -1563,7 +1649,7 @@ main( INT_T argc, char * argv[] ) mapD.size.x = 4*12; mapD.size.y = 3*12; printD.scale = 1.0; - for (i=0; i<(sizeof cmds)/(sizeof cmds[0]); i++) { + for (i=0; i<COUNT( cmds ); i++) { switch (cmds[i].cmd) { case C_START: CmdPrint( cmds[i].cmd ); |