source: branches/ticket_150/dll/fonts.c@ 1036

Last change on this file since 1036 was 793, checked in by Gregg Young, 18 years ago

Move #pragma alloc_text to end for OpenWatcom compat

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.6 KB
Line 
1/* handles setting fonts */
2
3#define INCL_DOS
4#define INCL_WIN
5#define INCL_GPI
6
7#include <os2.h>
8#include <stdlib.h>
9#include <stdio.h>
10#include <string.h>
11#include "fm3dll.h"
12#include "fm3str.h"
13
14#pragma data_seg(DATA1)
15
16static INT counter = 0;
17
18/*
19 * Convert vector font size using point size and fAttrs structure and
20 * return it in that structure.
21 */
22
23VOID ConvertVectorFontSize(FIXED fxPointSize, PFATTRS pfattrs)
24{
25
26 HPS hps;
27 HDC hDC;
28 LONG lxFontResolution;
29 LONG lyFontResolution;
30 SIZEF sizef;
31
32 hps = WinGetScreenPS(HWND_DESKTOP); /* Screen presentation space */
33
34 /*
35 * Query device context for the screen and then query
36 * the resolution of the device for the device context.
37 */
38
39 hDC = GpiQueryDevice(hps);
40 DevQueryCaps(hDC, CAPS_HORIZONTAL_FONT_RES, (LONG) 1, &lxFontResolution);
41 DevQueryCaps(hDC, CAPS_VERTICAL_FONT_RES, (LONG) 1, &lyFontResolution);
42
43 /*
44 * Calculate the size of the character box, based on the
45 * point size selected and the resolution of the device.
46 * The size parameters are of type FIXED, NOT int.
47 * NOTE: 1 point == 1/72 of an inch.
48 */
49
50 sizef.cx = (FIXED) (((fxPointSize) / 72) * lxFontResolution);
51 sizef.cy = (FIXED) (((fxPointSize) / 72) * lyFontResolution);
52
53 pfattrs->lMaxBaselineExt = MAKELONG(HIUSHORT(sizef.cy), 0);
54 pfattrs->lAveCharWidth = MAKELONG(HIUSHORT(sizef.cx), 0);
55 WinReleasePS(hps);
56
57} /* end ConvertVectorPointSize() */
58
59VOID SetPresParamFromFattrs(HWND hwnd, FATTRS * fattrs,
60 SHORT sNominalPointSize, FIXED fxPointSize)
61{
62
63 CHAR s[CCHMAXPATH * 2];
64
65 if (fattrs->fsFontUse != FATTR_FONTUSE_OUTLINE)
66 sprintf(s, "%hd.", sNominalPointSize / 10);
67 else {
68 sprintf(s, "%hd.", FIXEDINT(fxPointSize));
69 if ((((USHORT) FIXEDFRAC(fxPointSize) * 100) / 65536) > 0)
70 sprintf(&s[strlen(s)], "%hd.",
71 ((USHORT) FIXEDFRAC(fxPointSize) * 100) / 65536);
72 }
73 strcat(s, fattrs->szFacename);
74 if (fattrs->fsSelection & FATTR_SEL_ITALIC) {
75 strcat(s, ".");
76 strcat(s, GetPString(IDS_ITALICTEXT));
77 }
78 if (fattrs->fsSelection & FATTR_SEL_OUTLINE) {
79 strcat(s, ".");
80 strcat(s, GetPString(IDS_OUTLINETEXT));
81 }
82 if (fattrs->fsSelection & FATTR_SEL_BOLD) {
83 strcat(s, ".");
84 strcat(s, GetPString(IDS_BOLDTEXT));
85 }
86 if (fattrs->fsSelection & FATTR_SEL_UNDERSCORE) {
87 strcat(s, ".");
88 strcat(s, GetPString(IDS_UNDERSCORETEXT));
89 }
90 if (fattrs->fsSelection & FATTR_SEL_STRIKEOUT) {
91 strcat(s, ".");
92 strcat(s, GetPString(IDS_STRIKEOUTTEXT));
93 }
94 WinSetPresParam(hwnd, PP_FONTNAMESIZE, strlen(s) + 1, s);
95}
96
97VOID SetFont(HWND hwnd)
98{
99
100 FONTDLG fontdlg;
101 HPS hps;
102 FONTMETRICS fm;
103 CHAR szFamily[CCHMAXPATH],
104 *szTitle = GetPString(IDS_SETFONTTITLETEXT), *szPreview;
105
106 DosEnterCritSec();
107 szPreview = GetPString(IDS_BLURB1TEXT + counter++);
108 if (strcmp(szPreview, "0")) {
109 counter = 0;
110 szPreview = GetPString(IDS_BLURB1TEXT + counter++);
111 }
112 DosExitCritSec();
113 memset(&fontdlg, 0, sizeof(fontdlg)); /* initialize all fields */
114 hps = WinGetPS(hwnd);
115 GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &fm);
116 WinReleasePS(hps);
117 fontdlg.cbSize = sizeof(FONTDLG);
118 fontdlg.hpsScreen = WinGetScreenPS(HWND_DESKTOP);
119 fontdlg.hpsPrinter = NULLHANDLE;
120 fontdlg.pszTitle = szTitle;
121 fontdlg.pszPreview = szPreview;
122 fontdlg.pfnDlgProc = NULL;
123 strcpy(szFamily, fm.szFamilyname);
124 fontdlg.pszFamilyname = szFamily;
125 fontdlg.usFamilyBufLen = sizeof(szFamily);
126 fontdlg.fxPointSize = MAKEFIXED(fm.sNominalPointSize / 10, 0);
127 fontdlg.fl = FNTS_CENTER | FNTS_INITFROMFATTRS;
128 fontdlg.sNominalPointSize = fm.sNominalPointSize;
129 fontdlg.flType = (LONG) fm.fsType;
130 fontdlg.clrFore = CLR_NEUTRAL;
131 fontdlg.clrBack = CLR_BACKGROUND;
132 fontdlg.usWeight = fm.usWeightClass;
133 fontdlg.usWidth = fm.usWidthClass;
134 if (!WinFontDlg(HWND_DESKTOP, hwnd, &fontdlg) || fontdlg.lReturn != DID_OK) {
135 WinReleasePS(fontdlg.hpsScreen);
136 return;
137 }
138 if (fontdlg.fAttrs.fsFontUse == FATTR_FONTUSE_OUTLINE)
139 ConvertVectorFontSize(fontdlg.fxPointSize, &fontdlg.fAttrs);
140 WinReleasePS(fontdlg.hpsScreen);
141 SetPresParamFromFattrs(hwnd, &fontdlg.fAttrs, fontdlg.sNominalPointSize,
142 fontdlg.fxPointSize);
143}
144
145FATTRS *SetMLEFont(HWND hwndMLE, FATTRS * fattrs, ULONG flags)
146{
147
148 /* Flags:
149 *
150 * 1 = Don't assume MLE (no MLM_* messages, use fattrs only
151 * 2 = Fixed width fonts only
152 * 4 = No synthesized fonts
153 * 8 = No vector fonts
154 * 16 = No bitmapped fonts
155 *
156 */
157
158 FONTDLG fontDlg;
159 HPS hps;
160 FONTMETRICS fontMetrics;
161 CHAR szFamily[CCHMAXPATH], *szPreview;
162 static FIXED fxPointSize = 0; /* keep track of this for vector fonts */
163
164 if ((flags & 1) && !fattrs)
165 return fattrs;
166 DosEnterCritSec();
167 szPreview = GetPString(IDS_BLURB1TEXT + counter++);
168 if (strcmp(szPreview, "0")) {
169 counter = 0;
170 szPreview = GetPString(IDS_BLURB1TEXT + counter++);
171 }
172 DosExitCritSec();
173 memset(&fontDlg, 0, sizeof(fontDlg)); /* initialize all fields */
174 /*
175 * Get the current font attributes
176 */
177 hps = WinGetPS(hwndMLE);
178 if (!(flags & 1))
179 WinSendMsg(hwndMLE, MLM_QUERYFONT,
180 MPFROMP((PFATTRS) & (fontDlg.fAttrs)), NULL);
181 else
182 memcpy(&fontDlg.fAttrs, fattrs, sizeof(FATTRS));
183
184 /* create system default font */
185
186 GpiCreateLogFont(hps, (PSTR8) fontDlg.fAttrs.szFacename, 1,
187 &(fontDlg.fAttrs));
188 GpiSetCharSet(hps, 1);
189 GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &fontMetrics);
190 GpiSetCharSet(hps, LCID_DEFAULT);
191 GpiDeleteSetId(hps, 1);
192 WinReleasePS(hps);
193
194 /*
195 * Initialize the FONTDLG structure with the current font
196 */
197 fontDlg.cbSize = sizeof(FONTDLG); /* sizeof(FONTDLG) */
198 fontDlg.hpsScreen = WinGetScreenPS(HWND_DESKTOP); /* Screen presentation space */
199 fontDlg.hpsPrinter = NULLHANDLE; /* Printer presentation space */
200
201 fontDlg.pszTitle = GetPString(IDS_SETVIEWERFONTTITLETEXT);
202 fontDlg.pszPreview = szPreview;
203 fontDlg.pszPtSizeList = NULL; /* Application provided size list */
204 fontDlg.pfnDlgProc = NULL; /* Dialog subclass procedure */
205 strcpy(szFamily, fontMetrics.szFamilyname); /* Family name of font */
206 fontDlg.pszFamilyname = szFamily; /* point to Family name of font */
207 fontDlg.fxPointSize = fxPointSize; /* Point size the user selected */
208 fontDlg.fl = FNTS_CENTER | /* FNTS_* flags - dialog styles */
209 FNTS_INITFROMFATTRS;
210 if (flags & 2)
211 fontDlg.fl |= FNTS_FIXEDWIDTHONLY;
212 if (flags & 4)
213 fontDlg.fl |= FNTS_NOSYNTHESIZEDFONTS;
214 if (flags & 8)
215 fontDlg.fl |= FNTS_BITMAPONLY;
216 else if (flags & 16)
217 fontDlg.fl |= FNTS_VECTORONLY;
218 fontDlg.flFlags = 0; /* FNTF_* state flags */
219 /* Font type option bits */
220 fontDlg.flType = (LONG) fontMetrics.fsType;
221 fontDlg.flTypeMask = 0; /* Mask of which font types to use */
222 fontDlg.flStyle = 0; /* The selected style bits */
223 fontDlg.flStyleMask = 0; /* Mask of which style bits to use */
224 fontDlg.clrFore = CLR_NEUTRAL; /* Selected foreground color */
225 fontDlg.clrBack = CLR_BACKGROUND; /* Selected background color */
226 fontDlg.ulUser = 0; /* Blank field for application */
227 fontDlg.lReturn = 0; /* Return Value of the Dialog */
228 fontDlg.lEmHeight = 0; /* Em height of the current font */
229 fontDlg.lXHeight = 0; /* X height of the current font */
230 fontDlg.lExternalLeading = 0; /* External Leading of font */
231 /* Nominal Point Size of font */
232 fontDlg.sNominalPointSize = fontMetrics.sNominalPointSize;
233 fontDlg.usWeight = fontMetrics.usWeightClass; /* The boldness of the font */
234 fontDlg.usWidth = fontMetrics.usWidthClass; /* The width of the font */
235 fontDlg.x = 0; /* X coordinate of the dialog */
236 fontDlg.y = 0; /* Y coordinate of the dialog */
237// fontDlg.usDlgId = IDD_FONT; /* ID of a custom dialog template */
238 fontDlg.usFamilyBufLen = sizeof(szFamily); /*Length of family name buffer */
239
240 /*
241 * Bring up the standard Font Dialog
242 */
243
244 if (!WinFontDlg(HWND_DESKTOP, hwndMLE, &fontDlg)
245 || fontDlg.lReturn != DID_OK) {
246 WinReleasePS(fontDlg.hpsScreen);
247 return NULL;
248 }
249 fxPointSize = fontDlg.fxPointSize; /* save point size for next dialog */
250
251 /*
252 * If outline font, calculate the maxbaselineext and
253 * avecharwidth for the point size selected
254 */
255
256 if (fontDlg.fAttrs.fsFontUse == FATTR_FONTUSE_OUTLINE)
257 ConvertVectorFontSize(fontDlg.fxPointSize, &fontDlg.fAttrs);
258
259 WinReleasePS(fontDlg.hpsScreen);
260 if (!(flags & 1))
261 WinSendMsg(hwndMLE, MLM_SETFONT, MPFROMP(&(fontDlg.fAttrs)), MPVOID);
262 if (fattrs)
263 memcpy(fattrs, &fontDlg.fAttrs, sizeof(FATTRS));
264 return fattrs;
265
266} /* End of SetMLEFont() */
267
268#pragma alloc_text(FONTS,ConvertVectorFontSize,SetFont,SetMLEFont)
269#pragma alloc_text(FONTS,SetPresParamFromFattrs)
Note: See TracBrowser for help on using the repository browser.