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