source: git/src/printwin.c @ 55b7334

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 55b7334 was 55b7334, checked in by Olly Betts <olly@…>, 24 years ago

Added printwin - Phil's MS Windows printer driver.

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

  • Property mode set to 100644
File size: 5.6 KB
RevLine 
[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 "ini.h"
42#include <windows.h>
43
44#define POINTS_PER_INCH 72.0f
45#define POINTS_PER_MM ((float)(POINTS_PER_INCH) / (MM_PER_INCH))
46
47static float MarginLeft, MarginRight, MarginTop, MarginBottom;
48static int fontsize, fontsize_labels;
49static float LineWidth;
50
51static char *fontname, *fontname_labels;
52
53#define WIN_TS 9 /* size of alignment 'ticks' on multipage printouts */
54#define WIN_CROSS_SIZE 2 /* length of cross arms (in points!) */
55
56#define fontname_symbol "Symbol"
57
58static const char *win_Name(void);
59static int win_Pre(int pagesToPrint, const char *title);
60static void win_NewPage(int pg, int pass, int pagesX, int pagesY);
61static void win_Init(FILE *fh, const char *pth, float *pscX, float *pscY);
62static void win_MoveTo(long x, long y);
63static void win_DrawTo(long x, long y);
64static void win_DrawCross(long x, long y);
65static void win_WriteString(const char *s);
66static void win_DrawCircle(long x, long y, long r);
67static void win_ShowPage(const char *szPageDetails);
68static void win_Quit(void);
69
70/*device ps = {*/
71device printer = {
72   win_Name,
73   win_Init,
74   win_Pre,
75   win_NewPage,
76   win_MoveTo,
77   win_DrawTo,
78   win_DrawCross,
79   NULL,
80   win_WriteString,
81   win_DrawCircle,
82   win_ShowPage,
83   NULL, /* ps_Post,*/
84   win_Quit
85};
86
87HDC pd; /* printer context */
88
89int midtextheight; /*height of text*/
90
91float scX,scY;
92
93static border clip;
94
95static long xpPageWidth, ypPageDepth;
96
97
98static const char *
99win_Name(void)
100{
101   return "Win32 Printer";
102}
103
104static long x_t, y_t;
105
106static void
107win_MoveTo(long x, long y)
108{
109   x_t = x - clip.x_min;
110   y_t = clip.y_max - y;
111   MoveToEx(pd,x_t,y_t,NULL);
112}
113
114static void
115win_DrawTo(long x, long y)
116{
117   x_t = x - clip.x_min;
118   y_t = clip.y_max - y;
119   LineTo(pd,x_t,y_t);
120}
121
122static void
123win_DrawCross(long x, long y)
124{
125#define CS WIN_CROSS_SIZE
126#define CS2 (2 * WIN_CROSS_SIZE)
127  win_MoveTo(x-CS,y);
128  win_DrawTo(x+CS,y);
129  win_MoveTo(x,y-CS);
130  win_DrawTo(x,y+CS);
131  win_MoveTo(x,y);
132#undef CS
133#undef CS2
134}
135
136
137static void
138win_WriteString(const char *s)
139{
140  TextOut(pd,x_t,y_t-midtextheight,s,strlen(s));
141}
142
143static void
144win_DrawCircle(long x, long y, long r)
145{
146  x_t = x - clip.x_min;
147  y_t = clip.y_max - y;
148  Ellipse(pd,x_t - r, y_t - r,x_t + r, y_t + r);
149}
150
151
152static int
153win_Pre(int pagesToPrint, const char *title)
154{
155  PRINTDLGA psd = {0};
156  DOCINFO info = {0};
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 */
170}
171
172static void
173win_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
193static void
194win_ShowPage(const char *szPageDetails)
195{
196  win_MoveTo((long)(6 * scX) + clip.x_min,(long) (clip.y_min - (7 * scY)));
197  win_WriteString(szPageDetails);
198  EndPage(pd);
199}
200
201/* Initialise HPGL/PS printer routines */
202static void
203win_Init(FILE *fh, const char *pth, float *pscX, float *pscY)
204{
205   /* name and size of font to use for text */
206  TEXTMETRIC temp;
207  PRINTDLGA psd = {0};
208  psd.lStructSize = 66;
209  psd.hwndOwner = NULL;
210  psd.hDevMode = NULL;
211  psd.hDevNames = NULL;
212  psd.hDC = NULL;
213  psd.Flags = PD_RETURNDC + PD_RETURNDEFAULT;
214  psd.hInstance = NULL;
215  PrintDlgA(&psd);
216  fontsize = 12;
217 
218  PaperWidth = GetDeviceCaps(psd.hDC,HORZSIZE);
219  PaperDepth = GetDeviceCaps(psd.hDC,VERTSIZE);
220  xpPageWidth = GetDeviceCaps(psd.hDC,HORZRES);
221  ypPageDepth = GetDeviceCaps(psd.hDC,VERTRES);
222  MarginLeft = MarginBottom = 0;
223  MarginRight = PaperWidth;
224  MarginTop = PaperDepth;
225  LineWidth = 0;
226  scX = *pscX = xpPageWidth/PaperWidth;
227  scY = *pscY = ypPageDepth/PaperDepth;
228  xpPageWidth--;
229  ypPageDepth = ypPageDepth - (int)(10 * *pscY);
230  GetTextMetrics(psd.hDC,&temp);
231  midtextheight = temp.tmAscent;
232  DeleteDC(psd.hDC);
233 
234   /* name and size of font to use for station labels (default to text font) */
235  fontname_labels = fontname;
236  fontsize_labels = fontsize;
237}
238
239static void
240win_Quit(void)
241{
242  EndDoc(pd);
243  DeleteDC(pd);
244}
Note: See TracBrowser for help on using the repository browser.