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