| 1 |
|
|---|
| 2 | /***********************************************************************
|
|---|
| 3 |
|
|---|
| 4 | $Id: fonts.c 1673 2012-12-30 18:51:01Z gyoung $
|
|---|
| 5 |
|
|---|
| 6 | Font support
|
|---|
| 7 |
|
|---|
| 8 | Copyright (c) 1993-98 M. Kimes
|
|---|
| 9 | Copyright (c) 2008, 2009 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 |
|
|---|
| 41 | VOID 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 |
|
|---|
| 77 | VOID 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
|
|---|
| 116 | VOID SetFont(HWND hwnd)
|
|---|
| 117 | {
|
|---|
| 118 |
|
|---|
| 119 | FONTDLG fontdlg;
|
|---|
| 120 | HPS hps;
|
|---|
| 121 | FONTMETRICS fm;
|
|---|
| 122 | CHAR szFamily[CCHMAXPATH], *szTitle = GetPString(IDS_SETFONTTITLETEXT), *szPreview;
|
|---|
| 123 |
|
|---|
| 124 | DosRequestMutexSem(hmtxFM2Globals, SEM_INDEFINITE_WAIT);
|
|---|
| 125 | szPreview = GetPString(IDS_BLURB1TEXT + counter++);
|
|---|
| 126 | if (strcmp(szPreview, "0") == 0) {
|
|---|
| 127 | counter = 0;
|
|---|
| 128 | szPreview = GetPString(IDS_BLURB1TEXT + counter++);
|
|---|
| 129 | }
|
|---|
| 130 | DosReleaseMutexSem(hmtxFM2Globals);
|
|---|
| 131 | memset(&fontdlg, 0, sizeof(fontdlg)); // initialize all fields
|
|---|
| 132 | hps = WinGetPS(hwnd);
|
|---|
| 133 | GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &fm);
|
|---|
| 134 | WinReleasePS(hps);
|
|---|
| 135 | fontdlg.cbSize = sizeof(FONTDLG);
|
|---|
| 136 | fontdlg.hpsScreen = WinGetScreenPS(HWND_DESKTOP);
|
|---|
| 137 | fontdlg.hpsPrinter = NULLHANDLE;
|
|---|
| 138 | fontdlg.pszTitle = szTitle;
|
|---|
| 139 | fontdlg.pszPreview = szPreview;
|
|---|
| 140 | fontdlg.pfnDlgProc = NULL;
|
|---|
| 141 | strcpy(szFamily, fm.szFamilyname);
|
|---|
| 142 | fontdlg.pszFamilyname = szFamily;
|
|---|
| 143 | fontdlg.usFamilyBufLen = sizeof(szFamily);
|
|---|
| 144 | fontdlg.fxPointSize = MAKEFIXED(fm.sNominalPointSize / 10, 0);
|
|---|
| 145 | fontdlg.fl = FNTS_CENTER | FNTS_INITFROMFATTRS;
|
|---|
| 146 | fontdlg.sNominalPointSize = fm.sNominalPointSize;
|
|---|
| 147 | fontdlg.flType = (LONG) fm.fsType;
|
|---|
| 148 | fontdlg.clrFore = CLR_NEUTRAL;
|
|---|
| 149 | fontdlg.clrBack = CLR_BACKGROUND;
|
|---|
| 150 | fontdlg.usWeight = fm.usWeightClass;
|
|---|
| 151 | fontdlg.usWidth = fm.usWidthClass;
|
|---|
| 152 | if (!WinFontDlg(HWND_DESKTOP, hwnd, &fontdlg) || fontdlg.lReturn != DID_OK) {
|
|---|
| 153 | WinReleasePS(fontdlg.hpsScreen);
|
|---|
| 154 | return;
|
|---|
| 155 | }
|
|---|
| 156 | if (fontdlg.fAttrs.fsFontUse == FATTR_FONTUSE_OUTLINE)
|
|---|
| 157 | ConvertVectorFontSize(fontdlg.fxPointSize, &fontdlg.fAttrs);
|
|---|
| 158 | WinReleasePS(fontdlg.hpsScreen);
|
|---|
| 159 | SetPresParamFromFattrs(hwnd, &fontdlg.fAttrs, fontdlg.sNominalPointSize,
|
|---|
| 160 | fontdlg.fxPointSize);
|
|---|
| 161 | }
|
|---|
| 162 | #endif
|
|---|
| 163 |
|
|---|
| 164 | FATTRS *SetMLEFont(HWND hwndMLE, FATTRS * fattrs, ULONG flags)
|
|---|
| 165 | {
|
|---|
| 166 |
|
|---|
| 167 | /**
|
|---|
| 168 | * Flags:
|
|---|
| 169 | *
|
|---|
| 170 | * 1 = Don't assume MLE (no MLM_* messages, use fattrs only
|
|---|
| 171 | * 2 = Fixed width fonts only
|
|---|
| 172 | * 4 = No synthesized fonts
|
|---|
| 173 | * 8 = No vector fonts
|
|---|
| 174 | * 16 = No bitmapped fonts
|
|---|
| 175 | *
|
|---|
| 176 | */
|
|---|
| 177 |
|
|---|
| 178 | FONTDLG fontDlg;
|
|---|
| 179 | HPS hps;
|
|---|
| 180 | FONTMETRICS fontMetrics;
|
|---|
| 181 | CHAR szFamily[CCHMAXPATH];
|
|---|
| 182 | PCSZ pcszPreview;
|
|---|
| 183 | static FIXED fxPointSize = 0; // keep track of this for vector fonts
|
|---|
| 184 |
|
|---|
| 185 | if ((flags & 1) && !fattrs)
|
|---|
| 186 | return fattrs;
|
|---|
| 187 | DosRequestMutexSem(hmtxFM2Globals, SEM_INDEFINITE_WAIT);
|
|---|
| 188 | // 12 Jan 09 SHL fixme to do multiple previews or rename to IDS_BLURBTEXT
|
|---|
| 189 | pcszPreview = GetPString(IDS_BLURB1TEXT);
|
|---|
| 190 | DosReleaseMutexSem(hmtxFM2Globals);
|
|---|
| 191 | memset(&fontDlg, 0, sizeof(fontDlg)); // initialize all fields
|
|---|
| 192 | // Get the current font attributes
|
|---|
| 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 | GpiCreateLogFont(hps, (PSTR8) fontDlg.fAttrs.szFacename, 1,
|
|---|
| 202 | &(fontDlg.fAttrs));
|
|---|
| 203 | GpiSetCharSet(hps, 1);
|
|---|
| 204 | GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &fontMetrics);
|
|---|
| 205 | GpiSetCharSet(hps, LCID_DEFAULT);
|
|---|
| 206 | GpiDeleteSetId(hps, 1);
|
|---|
| 207 | WinReleasePS(hps);
|
|---|
| 208 |
|
|---|
| 209 | // Initialize the FONTDLG structure with the current font
|
|---|
| 210 | fontDlg.cbSize = sizeof(FONTDLG);
|
|---|
| 211 | fontDlg.hpsScreen = WinGetScreenPS(HWND_DESKTOP); // Screen presentation space
|
|---|
| 212 | fontDlg.hpsPrinter = NULLHANDLE; // Printer presentation space
|
|---|
| 213 |
|
|---|
| 214 | fontDlg.pszTitle = (PSZ)GetPString(IDS_SETVIEWERFONTTITLETEXT);
|
|---|
| 215 | fontDlg.pszPreview = (PSZ)pcszPreview;
|
|---|
| 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
|
|---|
| 250 | fontDlg.usFamilyBufLen = sizeof(szFamily); // Length of family name buffer
|
|---|
| 251 |
|
|---|
| 252 | // Bring up the standard Font Dialog
|
|---|
| 253 |
|
|---|
| 254 | if (!WinFontDlg(HWND_DESKTOP, hwndMLE, &fontDlg)
|
|---|
| 255 | || fontDlg.lReturn != DID_OK) {
|
|---|
| 256 | WinReleasePS(fontDlg.hpsScreen);
|
|---|
| 257 | return NULL;
|
|---|
| 258 | }
|
|---|
| 259 | fxPointSize = fontDlg.fxPointSize; // save point size for next dialog
|
|---|
| 260 |
|
|---|
| 261 | /**
|
|---|
| 262 | * If outline font, calculate the maxbaselineext and
|
|---|
| 263 | * avecharwidth for the point size selected
|
|---|
| 264 | */
|
|---|
| 265 |
|
|---|
| 266 | if (fontDlg.fAttrs.fsFontUse == FATTR_FONTUSE_OUTLINE)
|
|---|
| 267 | ConvertVectorFontSize(fontDlg.fxPointSize, &fontDlg.fAttrs);
|
|---|
| 268 |
|
|---|
| 269 | WinReleasePS(fontDlg.hpsScreen);
|
|---|
| 270 | if (!(flags & 1))
|
|---|
| 271 | WinSendMsg(hwndMLE, MLM_SETFONT, MPFROMP(&(fontDlg.fAttrs)), MPVOID);
|
|---|
| 272 | if (fattrs)
|
|---|
| 273 | memcpy(fattrs, &fontDlg.fAttrs, sizeof(FATTRS));
|
|---|
| 274 | return fattrs;
|
|---|
| 275 |
|
|---|
| 276 | } // End of SetMLEFont()
|
|---|
| 277 |
|
|---|
| 278 | #pragma alloc_text(FONTS,ConvertVectorFontSize,SetFont,SetMLEFont)
|
|---|
| 279 | #pragma alloc_text(FONTS,SetPresParamFromFattrs)
|
|---|