source: trunk/dll/fonts.c@ 1392

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

Move nontranslated strings to init.c and codepage.c; use those strings in place of GetPString calls. Move other strings to a StringTable; minor cleanup and code changes to codepage.c to use a string array instead of GetPString calls. Ticket 340

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