source: git/src/printwin.c @ 947a5c3

RELEASE/1.0RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernloglog-selectstereowalls-datawalls-data-hanging-as-warningwarn-only-for-hanging-survey
Last change on this file since 947a5c3 was e1fb3cb, checked in by Olly Betts <olly@…>, 23 years ago

Updated printwin Init to accept output_fnm - should fix internal error.

git-svn-id: file:///home/survex-svn/survex/trunk@1181 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

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