source: trunk/dll/fonts.c@ 689

Last change on this file since 689 was 551, checked in by Gregg Young, 19 years ago

Indentation cleanup

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