| 1 | 
 | 
|---|
| 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 | 
 | 
|---|
| 17 | #define INCL_DOS
 | 
|---|
| 18 | #define INCL_WIN
 | 
|---|
| 19 | #define INCL_GPI
 | 
|---|
| 20 | #define INCL_LONGLONG                   // dircnrs.h
 | 
|---|
| 21 | 
 | 
|---|
| 22 | #include "fm3str.h"
 | 
|---|
| 23 | #include "errutil.h"                    // Dos_Error...
 | 
|---|
| 24 | #include "strutil.h"                    // GetPString
 | 
|---|
| 25 | #include "fm3dll.h"
 | 
|---|
| 26 | 
 | 
|---|
| 27 | #pragma data_seg(DATA1)
 | 
|---|
| 28 | 
 | 
|---|
| 29 | static INT counter = 0;
 | 
|---|
| 30 | 
 | 
|---|
| 31 | /*
 | 
|---|
| 32 |  *   Convert vector font size using point size and fAttrs structure and
 | 
|---|
| 33 |  *   return it in that structure.
 | 
|---|
| 34 |  */
 | 
|---|
| 35 | 
 | 
|---|
| 36 | VOID ConvertVectorFontSize(FIXED fxPointSize, PFATTRS pfattrs)
 | 
|---|
| 37 | {
 | 
|---|
| 38 | 
 | 
|---|
| 39 |   HPS hps;
 | 
|---|
| 40 |   HDC hDC;
 | 
|---|
| 41 |   LONG lxFontResolution;
 | 
|---|
| 42 |   LONG lyFontResolution;
 | 
|---|
| 43 |   SIZEF sizef;
 | 
|---|
| 44 | 
 | 
|---|
| 45 |   hps = WinGetScreenPS(HWND_DESKTOP);   /* Screen presentation space */
 | 
|---|
| 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);
 | 
|---|
| 53 |   DevQueryCaps(hDC, CAPS_HORIZONTAL_FONT_RES, (LONG) 1, &lxFontResolution);
 | 
|---|
| 54 |   DevQueryCaps(hDC, CAPS_VERTICAL_FONT_RES, (LONG) 1, &lyFontResolution);
 | 
|---|
| 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 | 
 | 
|---|
| 63 |   sizef.cx = (FIXED) (((fxPointSize) / 72) * lxFontResolution);
 | 
|---|
| 64 |   sizef.cy = (FIXED) (((fxPointSize) / 72) * lyFontResolution);
 | 
|---|
| 65 | 
 | 
|---|
| 66 |   pfattrs->lMaxBaselineExt = MAKELONG(HIUSHORT(sizef.cy), 0);
 | 
|---|
| 67 |   pfattrs->lAveCharWidth = MAKELONG(HIUSHORT(sizef.cx), 0);
 | 
|---|
| 68 |   WinReleasePS(hps);
 | 
|---|
| 69 | 
 | 
|---|
| 70 | }                                       /* end ConvertVectorPointSize() */
 | 
|---|
| 71 | 
 | 
|---|
| 72 | VOID SetPresParamFromFattrs(HWND hwnd, FATTRS * fattrs,
 | 
|---|
| 73 |                             SHORT sNominalPointSize, FIXED fxPointSize)
 | 
|---|
| 74 | {
 | 
|---|
| 75 | 
 | 
|---|
| 76 |   CHAR s[CCHMAXPATH * 2];
 | 
|---|
| 77 | 
 | 
|---|
| 78 |   if (fattrs->fsFontUse != FATTR_FONTUSE_OUTLINE)
 | 
|---|
| 79 |     sprintf(s, "%hd.", sNominalPointSize / 10);
 | 
|---|
| 80 |   else {
 | 
|---|
| 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);
 | 
|---|
| 85 |   }
 | 
|---|
| 86 |   strcat(s, fattrs->szFacename);
 | 
|---|
| 87 |   if (fattrs->fsSelection & FATTR_SEL_ITALIC) {
 | 
|---|
| 88 |     strcat(s, ".");
 | 
|---|
| 89 |     strcat(s, GetPString(IDS_ITALICTEXT));
 | 
|---|
| 90 |   }
 | 
|---|
| 91 |   if (fattrs->fsSelection & FATTR_SEL_OUTLINE) {
 | 
|---|
| 92 |     strcat(s, ".");
 | 
|---|
| 93 |     strcat(s, GetPString(IDS_OUTLINETEXT));
 | 
|---|
| 94 |   }
 | 
|---|
| 95 |   if (fattrs->fsSelection & FATTR_SEL_BOLD) {
 | 
|---|
| 96 |     strcat(s, ".");
 | 
|---|
| 97 |     strcat(s, GetPString(IDS_BOLDTEXT));
 | 
|---|
| 98 |   }
 | 
|---|
| 99 |   if (fattrs->fsSelection & FATTR_SEL_UNDERSCORE) {
 | 
|---|
| 100 |     strcat(s, ".");
 | 
|---|
| 101 |     strcat(s, GetPString(IDS_UNDERSCORETEXT));
 | 
|---|
| 102 |   }
 | 
|---|
| 103 |   if (fattrs->fsSelection & FATTR_SEL_STRIKEOUT) {
 | 
|---|
| 104 |     strcat(s, ".");
 | 
|---|
| 105 |     strcat(s, GetPString(IDS_STRIKEOUTTEXT));
 | 
|---|
| 106 |   }
 | 
|---|
| 107 |   WinSetPresParam(hwnd, PP_FONTNAMESIZE, strlen(s) + 1, s);
 | 
|---|
| 108 | }
 | 
|---|
| 109 | 
 | 
|---|
| 110 | VOID SetFont(HWND hwnd)
 | 
|---|
| 111 | {
 | 
|---|
| 112 | 
 | 
|---|
| 113 |   FONTDLG fontdlg;
 | 
|---|
| 114 |   HPS hps;
 | 
|---|
| 115 |   FONTMETRICS fm;
 | 
|---|
| 116 |   CHAR szFamily[CCHMAXPATH],
 | 
|---|
| 117 |     *szTitle = GetPString(IDS_SETFONTTITLETEXT), *szPreview;
 | 
|---|
| 118 | 
 | 
|---|
| 119 |   DosEnterCritSec();
 | 
|---|
| 120 |   szPreview = GetPString(IDS_BLURB1TEXT + counter++);
 | 
|---|
| 121 |   if (strcmp(szPreview, "0")) {
 | 
|---|
| 122 |     counter = 0;
 | 
|---|
| 123 |     szPreview = GetPString(IDS_BLURB1TEXT + counter++);
 | 
|---|
| 124 |   }
 | 
|---|
| 125 |   DosExitCritSec();
 | 
|---|
| 126 |   memset(&fontdlg, 0, sizeof(fontdlg)); /* initialize all fields */
 | 
|---|
| 127 |   hps = WinGetPS(hwnd);
 | 
|---|
| 128 |   GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &fm);
 | 
|---|
| 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;
 | 
|---|
| 136 |   strcpy(szFamily, fm.szFamilyname);
 | 
|---|
| 137 |   fontdlg.pszFamilyname = szFamily;
 | 
|---|
| 138 |   fontdlg.usFamilyBufLen = sizeof(szFamily);
 | 
|---|
| 139 |   fontdlg.fxPointSize = MAKEFIXED(fm.sNominalPointSize / 10, 0);
 | 
|---|
| 140 |   fontdlg.fl = FNTS_CENTER | FNTS_INITFROMFATTRS;
 | 
|---|
| 141 |   fontdlg.sNominalPointSize = fm.sNominalPointSize;
 | 
|---|
| 142 |   fontdlg.flType = (LONG) fm.fsType;
 | 
|---|
| 143 |   fontdlg.clrFore = CLR_NEUTRAL;
 | 
|---|
| 144 |   fontdlg.clrBack = CLR_BACKGROUND;
 | 
|---|
| 145 |   fontdlg.usWeight = fm.usWeightClass;
 | 
|---|
| 146 |   fontdlg.usWidth = fm.usWidthClass;
 | 
|---|
| 147 |   if (!WinFontDlg(HWND_DESKTOP, hwnd, &fontdlg) || fontdlg.lReturn != DID_OK) {
 | 
|---|
| 148 |     WinReleasePS(fontdlg.hpsScreen);
 | 
|---|
| 149 |     return;
 | 
|---|
| 150 |   }
 | 
|---|
| 151 |   if (fontdlg.fAttrs.fsFontUse == FATTR_FONTUSE_OUTLINE)
 | 
|---|
| 152 |     ConvertVectorFontSize(fontdlg.fxPointSize, &fontdlg.fAttrs);
 | 
|---|
| 153 |   WinReleasePS(fontdlg.hpsScreen);
 | 
|---|
| 154 |   SetPresParamFromFattrs(hwnd, &fontdlg.fAttrs, fontdlg.sNominalPointSize,
 | 
|---|
| 155 |                          fontdlg.fxPointSize);
 | 
|---|
| 156 | }
 | 
|---|
| 157 | 
 | 
|---|
| 158 | FATTRS *SetMLEFont(HWND hwndMLE, FATTRS * fattrs, ULONG flags)
 | 
|---|
| 159 | {
 | 
|---|
| 160 | 
 | 
|---|
| 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 |    */
 | 
|---|
| 170 | 
 | 
|---|
| 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 */
 | 
|---|
| 176 | 
 | 
|---|
| 177 |   if ((flags & 1) && !fattrs)
 | 
|---|
| 178 |     return fattrs;
 | 
|---|
| 179 |   DosEnterCritSec();
 | 
|---|
| 180 |   szPreview = GetPString(IDS_BLURB1TEXT + counter++);
 | 
|---|
| 181 |   if (strcmp(szPreview, "0")) {
 | 
|---|
| 182 |     counter = 0;
 | 
|---|
| 183 |     szPreview = GetPString(IDS_BLURB1TEXT + counter++);
 | 
|---|
| 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));
 | 
|---|
| 196 | 
 | 
|---|
| 197 |   /* create system default font */
 | 
|---|
| 198 | 
 | 
|---|
| 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);
 | 
|---|
| 206 | 
 | 
|---|
| 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 */
 | 
|---|
| 213 | 
 | 
|---|
| 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      */
 | 
|---|
| 250 | //   fontDlg.usDlgId      = IDD_FONT;       /* ID of a custom dialog template  */
 | 
|---|
| 251 |   fontDlg.usFamilyBufLen = sizeof(szFamily);    /*Length of family name buffer */
 | 
|---|
| 252 | 
 | 
|---|
| 253 |   /*
 | 
|---|
| 254 |    *   Bring up the standard Font Dialog
 | 
|---|
| 255 |    */
 | 
|---|
| 256 | 
 | 
|---|
| 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 */
 | 
|---|
| 263 | 
 | 
|---|
| 264 |   /*
 | 
|---|
| 265 |    *   If outline font, calculate the maxbaselineext and
 | 
|---|
| 266 |    *   avecharwidth for the point size selected
 | 
|---|
| 267 |    */
 | 
|---|
| 268 | 
 | 
|---|
| 269 |   if (fontDlg.fAttrs.fsFontUse == FATTR_FONTUSE_OUTLINE)
 | 
|---|
| 270 |     ConvertVectorFontSize(fontDlg.fxPointSize, &fontDlg.fAttrs);
 | 
|---|
| 271 | 
 | 
|---|
| 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;
 | 
|---|
| 278 | 
 | 
|---|
| 279 | }                                       /* End of SetMLEFont() */
 | 
|---|
| 280 | 
 | 
|---|
| 281 | #pragma alloc_text(FONTS,ConvertVectorFontSize,SetFont,SetMLEFont)
 | 
|---|
| 282 | #pragma alloc_text(FONTS,SetPresParamFromFattrs)
 | 
|---|