source: git/src/printwin.c @ dc639a8

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 dc639a8 was 9d46af2, checked in by Olly Betts <olly@…>, 23 years ago

Fixed most compiler warnings in cross-builds to djgpp and mingw.

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

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