source: trunk/dll/fonts.c@ 1304

Last change on this file since 1304 was 1304, checked in by Gregg Young, 17 years ago

Move DosEnterCritSec into SetMask Replace 2 more with semaphore(Ticket 308)

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