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