[55b7334] | 1 | /* > printwin.c */ |
---|
| 2 | /* Device dependent part of Survex Win32 driver */ |
---|
| 3 | /* Copyright (C) 1993-2000 Olly Betts |
---|
[08e95aa] | 4 | * Copyright (C) 2001 Philip Underwood, Olly Betts |
---|
[55b7334] | 5 | * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify |
---|
| 7 | * it under the terms of the GNU General Public License as published by |
---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 9 | * (at your option) any later version. |
---|
| 10 | * |
---|
| 11 | * This program is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | * GNU General Public License for more details. |
---|
| 15 | * |
---|
| 16 | * You should have received a copy of the GNU General Public License |
---|
| 17 | * along with this program; if not, write to the Free Software |
---|
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | #ifdef HAVE_CONFIG_H |
---|
| 22 | # include <config.h> |
---|
| 23 | #endif |
---|
| 24 | |
---|
| 25 | #include <stdio.h> |
---|
| 26 | #include <stdlib.h> |
---|
| 27 | #include <math.h> |
---|
| 28 | #include <string.h> |
---|
| 29 | #include <time.h> |
---|
| 30 | #include <ctype.h> |
---|
| 31 | #include <float.h> |
---|
| 32 | #include <limits.h> |
---|
| 33 | |
---|
| 34 | #include "useful.h" |
---|
| 35 | #include "filename.h" |
---|
| 36 | #include "message.h" |
---|
| 37 | #include "prio.h" |
---|
| 38 | #include "filelist.h" |
---|
| 39 | #include "debug.h" /* for BUG and ASSERT */ |
---|
| 40 | #include "prcore.h" |
---|
| 41 | #include <windows.h> |
---|
| 42 | |
---|
| 43 | static float MarginLeft, MarginRight, MarginTop, MarginBottom; |
---|
| 44 | static int fontsize, fontsize_labels; |
---|
| 45 | static float LineWidth; |
---|
| 46 | |
---|
| 47 | static char *fontname, *fontname_labels; |
---|
| 48 | |
---|
| 49 | #define WIN_TS 9 /* size of alignment 'ticks' on multipage printouts */ |
---|
| 50 | #define WIN_CROSS_SIZE 2 /* length of cross arms (in points!) */ |
---|
| 51 | |
---|
| 52 | #define fontname_symbol "Symbol" |
---|
| 53 | |
---|
| 54 | static const char *win_Name(void); |
---|
| 55 | static int win_Pre(int pagesToPrint, const char *title); |
---|
| 56 | static void win_NewPage(int pg, int pass, int pagesX, int pagesY); |
---|
[498c347] | 57 | static void win_Init(FILE **fh_list, const char *pth, float *pscX, float *pscY); |
---|
[08e95aa] | 58 | static int win_Charset(void); |
---|
[55b7334] | 59 | static void win_MoveTo(long x, long y); |
---|
| 60 | static void win_DrawTo(long x, long y); |
---|
| 61 | static void win_DrawCross(long x, long y); |
---|
| 62 | static void win_WriteString(const char *s); |
---|
| 63 | static void win_DrawCircle(long x, long y, long r); |
---|
| 64 | static void win_ShowPage(const char *szPageDetails); |
---|
| 65 | static void win_Quit(void); |
---|
| 66 | |
---|
| 67 | device printer = { |
---|
| 68 | win_Name, |
---|
| 69 | win_Init, |
---|
[08e95aa] | 70 | win_Charset, |
---|
[55b7334] | 71 | win_Pre, |
---|
| 72 | win_NewPage, |
---|
| 73 | win_MoveTo, |
---|
| 74 | win_DrawTo, |
---|
| 75 | win_DrawCross, |
---|
| 76 | NULL, |
---|
| 77 | win_WriteString, |
---|
| 78 | win_DrawCircle, |
---|
| 79 | win_ShowPage, |
---|
[9d46af2] | 80 | NULL, /* win_Post */ |
---|
[55b7334] | 81 | win_Quit |
---|
| 82 | }; |
---|
| 83 | |
---|
[d0ffc05] | 84 | static HDC pd; /* printer context */ |
---|
[55b7334] | 85 | |
---|
[d0ffc05] | 86 | static int midtextheight; /*height of text*/ |
---|
[55b7334] | 87 | |
---|
[d0ffc05] | 88 | static float scX, scY; |
---|
[55b7334] | 89 | |
---|
| 90 | static border clip; |
---|
| 91 | |
---|
| 92 | static long xpPageWidth, ypPageDepth; |
---|
| 93 | |
---|
| 94 | static const char * |
---|
| 95 | win_Name(void) |
---|
| 96 | { |
---|
| 97 | return "Win32 Printer"; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | static long x_t, y_t; |
---|
| 101 | |
---|
| 102 | static void |
---|
| 103 | win_MoveTo(long x, long y) |
---|
| 104 | { |
---|
| 105 | x_t = x - clip.x_min; |
---|
| 106 | y_t = clip.y_max - y; |
---|
[d0ffc05] | 107 | MoveToEx(pd, x_t, y_t, NULL); |
---|
[55b7334] | 108 | } |
---|
| 109 | |
---|
| 110 | static void |
---|
| 111 | win_DrawTo(long x, long y) |
---|
| 112 | { |
---|
| 113 | x_t = x - clip.x_min; |
---|
| 114 | y_t = clip.y_max - y; |
---|
[d0ffc05] | 115 | LineTo(pd, x_t, y_t); |
---|
[55b7334] | 116 | } |
---|
| 117 | |
---|
| 118 | static void |
---|
| 119 | win_DrawCross(long x, long y) |
---|
| 120 | { |
---|
[d0ffc05] | 121 | win_MoveTo(x - WIN_CROSS_SIZE, y); |
---|
| 122 | win_DrawTo(x + WIN_CROSS_SIZE, y); |
---|
| 123 | win_MoveTo(x, y - WIN_CROSS_SIZE); |
---|
| 124 | win_DrawTo(x, y + WIN_CROSS_SIZE); |
---|
| 125 | win_MoveTo(x, y); |
---|
[55b7334] | 126 | } |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | static void |
---|
| 130 | win_WriteString(const char *s) |
---|
| 131 | { |
---|
[d0ffc05] | 132 | TextOut(pd, x_t, y_t - midtextheight, s, strlen(s)); |
---|
[55b7334] | 133 | } |
---|
| 134 | |
---|
| 135 | static void |
---|
| 136 | win_DrawCircle(long x, long y, long r) |
---|
| 137 | { |
---|
[d0ffc05] | 138 | x_t = x - clip.x_min; |
---|
| 139 | y_t = clip.y_max - y; |
---|
| 140 | Ellipse(pd, x_t - r, y_t - r, x_t + r, y_t + r); |
---|
[55b7334] | 141 | } |
---|
| 142 | |
---|
[08e95aa] | 143 | static int |
---|
| 144 | win_Charset(void) |
---|
| 145 | { |
---|
| 146 | return CHARSET_ISO_8859_1; |
---|
| 147 | } |
---|
| 148 | |
---|
[55b7334] | 149 | static int |
---|
| 150 | win_Pre(int pagesToPrint, const char *title) |
---|
| 151 | { |
---|
[d0ffc05] | 152 | PRINTDLGA psd = {0}; |
---|
| 153 | DOCINFO info = {0}; |
---|
[9d46af2] | 154 | |
---|
| 155 | pagesToPrint = pagesToPrint; |
---|
| 156 | |
---|
[d0ffc05] | 157 | psd.lStructSize = 66; |
---|
| 158 | psd.hwndOwner = NULL; |
---|
| 159 | psd.hDevMode = NULL; |
---|
| 160 | psd.hDevNames = NULL; |
---|
| 161 | psd.hDC = NULL; |
---|
| 162 | psd.Flags = PD_RETURNDC + PD_RETURNDEFAULT; |
---|
| 163 | psd.hInstance = NULL; |
---|
| 164 | PrintDlgA(&psd); |
---|
| 165 | pd = psd.hDC; |
---|
| 166 | info.lpszDocName = title; |
---|
| 167 | info.cbSize = sizeof(DOCINFO); |
---|
| 168 | StartDoc(pd, &info); |
---|
| 169 | return 1; /* only need 1 pass */ |
---|
[55b7334] | 170 | } |
---|
| 171 | |
---|
| 172 | static void |
---|
| 173 | win_NewPage(int pg, int pass, int pagesX, int pagesY) |
---|
| 174 | { |
---|
| 175 | int x, y; |
---|
| 176 | |
---|
| 177 | if (pass == -1) { |
---|
| 178 | fBlankPage = fFalse; /* hack for now */ |
---|
| 179 | return; |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | x = (pg - 1) % pagesX; |
---|
| 183 | y = pagesY - 1 - ((pg - 1) / pagesX); |
---|
| 184 | |
---|
| 185 | clip.x_min = (long)x * xpPageWidth; |
---|
| 186 | clip.y_min = (long)y * ypPageDepth; |
---|
| 187 | clip.x_max = clip.x_min + xpPageWidth; /* dm/pcl/ps had -1; */ |
---|
| 188 | clip.y_max = clip.y_min + ypPageDepth; /* dm/pcl/ps had -1; */ |
---|
| 189 | StartPage(pd); |
---|
| 190 | drawticks(clip, WIN_TS, x, y); |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | static void |
---|
| 194 | win_ShowPage(const char *szPageDetails) |
---|
| 195 | { |
---|
[d0ffc05] | 196 | win_MoveTo((long)(6 * scX) + clip.x_min, clip.y_min - (long)(7 * scY)); |
---|
| 197 | win_WriteString(szPageDetails); |
---|
| 198 | EndPage(pd); |
---|
[55b7334] | 199 | } |
---|
| 200 | |
---|
[9d46af2] | 201 | /* Initialise printer routines */ |
---|
[55b7334] | 202 | static void |
---|
[498c347] | 203 | win_Init(FILE **fh_list, const char *pth, float *pscX, float *pscY) |
---|
[55b7334] | 204 | { |
---|
| 205 | /* name and size of font to use for text */ |
---|
[d0ffc05] | 206 | TEXTMETRIC temp; |
---|
| 207 | PRINTDLGA psd = {0}; |
---|
[9d46af2] | 208 | |
---|
| 209 | fh_list = fh_list; |
---|
| 210 | pth = pth; |
---|
| 211 | |
---|
[d0ffc05] | 212 | psd.lStructSize = 66; |
---|
| 213 | psd.hwndOwner = NULL; |
---|
| 214 | psd.hDevMode = NULL; |
---|
| 215 | psd.hDevNames = NULL; |
---|
| 216 | psd.hDC = NULL; |
---|
| 217 | psd.Flags = PD_RETURNDC + PD_RETURNDEFAULT; |
---|
| 218 | psd.hInstance = NULL; |
---|
| 219 | PrintDlgA(&psd); |
---|
| 220 | fontsize = 12; |
---|
[55b7334] | 221 | |
---|
[d0ffc05] | 222 | PaperWidth = GetDeviceCaps(psd.hDC, HORZSIZE); |
---|
| 223 | PaperDepth = GetDeviceCaps(psd.hDC, VERTSIZE); |
---|
| 224 | xpPageWidth = GetDeviceCaps(psd.hDC, HORZRES); |
---|
| 225 | ypPageDepth = GetDeviceCaps(psd.hDC, VERTRES); |
---|
| 226 | MarginLeft = MarginBottom = 0; |
---|
| 227 | MarginRight = PaperWidth; |
---|
| 228 | MarginTop = PaperDepth; |
---|
| 229 | LineWidth = 0; |
---|
| 230 | scX = *pscX = xpPageWidth / PaperWidth; |
---|
| 231 | scY = *pscY = ypPageDepth / PaperDepth; |
---|
| 232 | xpPageWidth--; |
---|
| 233 | ypPageDepth = ypPageDepth - (int)(10 * *pscY); |
---|
| 234 | GetTextMetrics(psd.hDC, &temp); |
---|
| 235 | midtextheight = temp.tmAscent; |
---|
| 236 | DeleteDC(psd.hDC); |
---|
[55b7334] | 237 | |
---|
| 238 | /* name and size of font to use for station labels (default to text font) */ |
---|
[d0ffc05] | 239 | fontname_labels = fontname; |
---|
| 240 | fontsize_labels = fontsize; |
---|
[55b7334] | 241 | } |
---|
| 242 | |
---|
| 243 | static void |
---|
| 244 | win_Quit(void) |
---|
| 245 | { |
---|
[d0ffc05] | 246 | EndDoc(pd); |
---|
| 247 | DeleteDC(pd); |
---|
[55b7334] | 248 | } |
---|