[55b7334] | 1 | /* > printwin.c */ |
---|
| 2 | /* Device dependent part of Survex Win32 driver */ |
---|
| 3 | /* Copyright (C) 1993-2000 Olly Betts |
---|
| 4 | * Copyright (C) 2001 Philip Underwood |
---|
| 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); |
---|
[55b7334] | 58 | static void win_MoveTo(long x, long y); |
---|
| 59 | static void win_DrawTo(long x, long y); |
---|
| 60 | static void win_DrawCross(long x, long y); |
---|
| 61 | static void win_WriteString(const char *s); |
---|
| 62 | static void win_DrawCircle(long x, long y, long r); |
---|
| 63 | static void win_ShowPage(const char *szPageDetails); |
---|
| 64 | static void win_Quit(void); |
---|
| 65 | |
---|
| 66 | /*device ps = {*/ |
---|
| 67 | device printer = { |
---|
| 68 | win_Name, |
---|
| 69 | win_Init, |
---|
| 70 | win_Pre, |
---|
| 71 | win_NewPage, |
---|
| 72 | win_MoveTo, |
---|
| 73 | win_DrawTo, |
---|
| 74 | win_DrawCross, |
---|
| 75 | NULL, |
---|
| 76 | win_WriteString, |
---|
| 77 | win_DrawCircle, |
---|
| 78 | win_ShowPage, |
---|
| 79 | NULL, /* ps_Post,*/ |
---|
| 80 | win_Quit |
---|
| 81 | }; |
---|
| 82 | |
---|
[d0ffc05] | 83 | static HDC pd; /* printer context */ |
---|
[55b7334] | 84 | |
---|
[d0ffc05] | 85 | static int midtextheight; /*height of text*/ |
---|
[55b7334] | 86 | |
---|
[d0ffc05] | 87 | static float scX, scY; |
---|
[55b7334] | 88 | |
---|
| 89 | static border clip; |
---|
| 90 | |
---|
| 91 | static long xpPageWidth, ypPageDepth; |
---|
| 92 | |
---|
| 93 | static const char * |
---|
| 94 | win_Name(void) |
---|
| 95 | { |
---|
| 96 | return "Win32 Printer"; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | static long x_t, y_t; |
---|
| 100 | |
---|
| 101 | static void |
---|
| 102 | win_MoveTo(long x, long y) |
---|
| 103 | { |
---|
| 104 | x_t = x - clip.x_min; |
---|
| 105 | y_t = clip.y_max - y; |
---|
[d0ffc05] | 106 | MoveToEx(pd, x_t, y_t, NULL); |
---|
[55b7334] | 107 | } |
---|
| 108 | |
---|
| 109 | static void |
---|
| 110 | win_DrawTo(long x, long y) |
---|
| 111 | { |
---|
| 112 | x_t = x - clip.x_min; |
---|
| 113 | y_t = clip.y_max - y; |
---|
[d0ffc05] | 114 | LineTo(pd, x_t, y_t); |
---|
[55b7334] | 115 | } |
---|
| 116 | |
---|
| 117 | static void |
---|
| 118 | win_DrawCross(long x, long y) |
---|
| 119 | { |
---|
[d0ffc05] | 120 | win_MoveTo(x - WIN_CROSS_SIZE, y); |
---|
| 121 | win_DrawTo(x + WIN_CROSS_SIZE, y); |
---|
| 122 | win_MoveTo(x, y - WIN_CROSS_SIZE); |
---|
| 123 | win_DrawTo(x, y + WIN_CROSS_SIZE); |
---|
| 124 | win_MoveTo(x, y); |
---|
[55b7334] | 125 | } |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | static void |
---|
| 129 | win_WriteString(const char *s) |
---|
| 130 | { |
---|
[d0ffc05] | 131 | TextOut(pd, x_t, y_t - midtextheight, s, strlen(s)); |
---|
[55b7334] | 132 | } |
---|
| 133 | |
---|
| 134 | static void |
---|
| 135 | win_DrawCircle(long x, long y, long r) |
---|
| 136 | { |
---|
[d0ffc05] | 137 | x_t = x - clip.x_min; |
---|
| 138 | y_t = clip.y_max - y; |
---|
| 139 | Ellipse(pd, x_t - r, y_t - r, x_t + r, y_t + r); |
---|
[55b7334] | 140 | } |
---|
| 141 | |
---|
| 142 | static int |
---|
| 143 | win_Pre(int pagesToPrint, const char *title) |
---|
| 144 | { |
---|
[d0ffc05] | 145 | PRINTDLGA psd = {0}; |
---|
| 146 | DOCINFO info = {0}; |
---|
| 147 | psd.lStructSize = 66; |
---|
| 148 | psd.hwndOwner = NULL; |
---|
| 149 | psd.hDevMode = NULL; |
---|
| 150 | psd.hDevNames = NULL; |
---|
| 151 | psd.hDC = NULL; |
---|
| 152 | psd.Flags = PD_RETURNDC + PD_RETURNDEFAULT; |
---|
| 153 | psd.hInstance = NULL; |
---|
| 154 | PrintDlgA(&psd); |
---|
| 155 | pd = psd.hDC; |
---|
| 156 | info.lpszDocName = title; |
---|
| 157 | info.cbSize = sizeof(DOCINFO); |
---|
| 158 | StartDoc(pd, &info); |
---|
| 159 | return 1; /* only need 1 pass */ |
---|
[55b7334] | 160 | } |
---|
| 161 | |
---|
| 162 | static void |
---|
| 163 | win_NewPage(int pg, int pass, int pagesX, int pagesY) |
---|
| 164 | { |
---|
| 165 | int x, y; |
---|
| 166 | |
---|
| 167 | if (pass == -1) { |
---|
| 168 | fBlankPage = fFalse; /* hack for now */ |
---|
| 169 | return; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | x = (pg - 1) % pagesX; |
---|
| 173 | y = pagesY - 1 - ((pg - 1) / pagesX); |
---|
| 174 | |
---|
| 175 | clip.x_min = (long)x * xpPageWidth; |
---|
| 176 | clip.y_min = (long)y * ypPageDepth; |
---|
| 177 | clip.x_max = clip.x_min + xpPageWidth; /* dm/pcl/ps had -1; */ |
---|
| 178 | clip.y_max = clip.y_min + ypPageDepth; /* dm/pcl/ps had -1; */ |
---|
| 179 | StartPage(pd); |
---|
| 180 | drawticks(clip, WIN_TS, x, y); |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | static void |
---|
| 184 | win_ShowPage(const char *szPageDetails) |
---|
| 185 | { |
---|
[d0ffc05] | 186 | win_MoveTo((long)(6 * scX) + clip.x_min, clip.y_min - (long)(7 * scY)); |
---|
| 187 | win_WriteString(szPageDetails); |
---|
| 188 | EndPage(pd); |
---|
[55b7334] | 189 | } |
---|
| 190 | |
---|
| 191 | /* Initialise HPGL/PS printer routines */ |
---|
| 192 | static void |
---|
[498c347] | 193 | win_Init(FILE **fh_list, const char *pth, float *pscX, float *pscY) |
---|
[55b7334] | 194 | { |
---|
| 195 | /* name and size of font to use for text */ |
---|
[d0ffc05] | 196 | TEXTMETRIC temp; |
---|
| 197 | PRINTDLGA psd = {0}; |
---|
| 198 | psd.lStructSize = 66; |
---|
| 199 | psd.hwndOwner = NULL; |
---|
| 200 | psd.hDevMode = NULL; |
---|
| 201 | psd.hDevNames = NULL; |
---|
| 202 | psd.hDC = NULL; |
---|
| 203 | psd.Flags = PD_RETURNDC + PD_RETURNDEFAULT; |
---|
| 204 | psd.hInstance = NULL; |
---|
| 205 | PrintDlgA(&psd); |
---|
| 206 | fontsize = 12; |
---|
[55b7334] | 207 | |
---|
[d0ffc05] | 208 | PaperWidth = GetDeviceCaps(psd.hDC, HORZSIZE); |
---|
| 209 | PaperDepth = GetDeviceCaps(psd.hDC, VERTSIZE); |
---|
| 210 | xpPageWidth = GetDeviceCaps(psd.hDC, HORZRES); |
---|
| 211 | ypPageDepth = GetDeviceCaps(psd.hDC, VERTRES); |
---|
| 212 | MarginLeft = MarginBottom = 0; |
---|
| 213 | MarginRight = PaperWidth; |
---|
| 214 | MarginTop = PaperDepth; |
---|
| 215 | LineWidth = 0; |
---|
| 216 | scX = *pscX = xpPageWidth / PaperWidth; |
---|
| 217 | scY = *pscY = ypPageDepth / PaperDepth; |
---|
| 218 | xpPageWidth--; |
---|
| 219 | ypPageDepth = ypPageDepth - (int)(10 * *pscY); |
---|
| 220 | GetTextMetrics(psd.hDC, &temp); |
---|
| 221 | midtextheight = temp.tmAscent; |
---|
| 222 | DeleteDC(psd.hDC); |
---|
[55b7334] | 223 | |
---|
| 224 | /* name and size of font to use for station labels (default to text font) */ |
---|
[d0ffc05] | 225 | fontname_labels = fontname; |
---|
| 226 | fontsize_labels = fontsize; |
---|
[55b7334] | 227 | } |
---|
| 228 | |
---|
| 229 | static void |
---|
| 230 | win_Quit(void) |
---|
| 231 | { |
---|
[d0ffc05] | 232 | EndDoc(pd); |
---|
| 233 | DeleteDC(pd); |
---|
[55b7334] | 234 | } |
---|