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