source: git/src/printwin.c @ fe652bf

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 fe652bf was 5824d76, checked in by Olly Betts <olly@…>, 23 years ago

Added code to try to track down printwin problems.

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

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