| [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 |  | 
|---|
|  | 18 | static INT counter = 0L; | 
|---|
|  | 19 |  | 
|---|
|  | 20 | /* | 
|---|
|  | 21 | *   Convert vector font size using point size and fAttrs structure and | 
|---|
|  | 22 | *   return it in that structure. | 
|---|
|  | 23 | */ | 
|---|
|  | 24 |  | 
|---|
|  | 25 | VOID ConvertVectorFontSize (FIXED fxPointSize, PFATTRS pfattrs) { | 
|---|
|  | 26 |  | 
|---|
|  | 27 | HPS   hps; | 
|---|
|  | 28 | HDC   hDC; | 
|---|
|  | 29 | LONG  lxFontResolution; | 
|---|
|  | 30 | LONG  lyFontResolution; | 
|---|
|  | 31 | SIZEF sizef; | 
|---|
|  | 32 |  | 
|---|
|  | 33 | hps = WinGetScreenPS(HWND_DESKTOP);        /* Screen presentation space */ | 
|---|
|  | 34 |  | 
|---|
|  | 35 | /* | 
|---|
|  | 36 | *   Query device context for the screen and then query | 
|---|
|  | 37 | *   the resolution of the device for the device context. | 
|---|
|  | 38 | */ | 
|---|
|  | 39 |  | 
|---|
|  | 40 | hDC = GpiQueryDevice(hps); | 
|---|
|  | 41 | DevQueryCaps( hDC, CAPS_HORIZONTAL_FONT_RES, (LONG)1, &lxFontResolution); | 
|---|
|  | 42 | DevQueryCaps( hDC, CAPS_VERTICAL_FONT_RES, (LONG)1, &lyFontResolution); | 
|---|
|  | 43 |  | 
|---|
|  | 44 | /* | 
|---|
|  | 45 | *   Calculate the size of the character box, based on the | 
|---|
|  | 46 | *   point size selected and the resolution of the device. | 
|---|
|  | 47 | *   The size parameters are of type FIXED, NOT int. | 
|---|
|  | 48 | *   NOTE: 1 point == 1/72 of an inch. | 
|---|
|  | 49 | */ | 
|---|
|  | 50 |  | 
|---|
|  | 51 | sizef.cx = (FIXED)(((fxPointSize) / 72 ) * lxFontResolution ); | 
|---|
|  | 52 | sizef.cy = (FIXED)(((fxPointSize) / 72 ) * lyFontResolution ); | 
|---|
|  | 53 |  | 
|---|
|  | 54 | pfattrs->lMaxBaselineExt = MAKELONG( HIUSHORT( sizef.cy ), 0 ); | 
|---|
|  | 55 | pfattrs->lAveCharWidth   = MAKELONG( HIUSHORT( sizef.cx ), 0 ); | 
|---|
|  | 56 | WinReleasePS(hps); | 
|---|
|  | 57 |  | 
|---|
|  | 58 | } /* end ConvertVectorPointSize() */ | 
|---|
|  | 59 |  | 
|---|
|  | 60 |  | 
|---|
|  | 61 | VOID SetPresParamFromFattrs (HWND hwnd,FATTRS *fattrs, | 
|---|
|  | 62 | SHORT sNominalPointSize, | 
|---|
|  | 63 | FIXED fxPointSize) { | 
|---|
|  | 64 |  | 
|---|
|  | 65 | CHAR s[CCHMAXPATH * 2]; | 
|---|
|  | 66 |  | 
|---|
|  | 67 | if(fattrs->fsFontUse != FATTR_FONTUSE_OUTLINE) | 
|---|
|  | 68 | sprintf(s,"%hd.",sNominalPointSize / 10); | 
|---|
|  | 69 | else { | 
|---|
|  | 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); | 
|---|
|  | 74 | } | 
|---|
|  | 75 | strcat(s,fattrs->szFacename); | 
|---|
|  | 76 | if(fattrs->fsSelection & FATTR_SEL_ITALIC) { | 
|---|
|  | 77 | strcat(s,"."); | 
|---|
|  | 78 | strcat(s,GetPString(IDS_ITALICTEXT)); | 
|---|
|  | 79 | } | 
|---|
|  | 80 | if(fattrs->fsSelection & FATTR_SEL_OUTLINE) { | 
|---|
|  | 81 | strcat(s,"."); | 
|---|
|  | 82 | strcat(s,GetPString(IDS_OUTLINETEXT)); | 
|---|
|  | 83 | } | 
|---|
|  | 84 | if(fattrs->fsSelection & FATTR_SEL_BOLD) { | 
|---|
|  | 85 | strcat(s,"."); | 
|---|
|  | 86 | strcat(s,GetPString(IDS_BOLDTEXT)); | 
|---|
|  | 87 | } | 
|---|
|  | 88 | if(fattrs->fsSelection & FATTR_SEL_UNDERSCORE) { | 
|---|
|  | 89 | strcat(s,"."); | 
|---|
|  | 90 | strcat(s,GetPString(IDS_UNDERSCORETEXT)); | 
|---|
|  | 91 | } | 
|---|
|  | 92 | if(fattrs->fsSelection & FATTR_SEL_STRIKEOUT) { | 
|---|
|  | 93 | strcat(s,"."); | 
|---|
|  | 94 | strcat(s,GetPString(IDS_STRIKEOUTTEXT)); | 
|---|
|  | 95 | } | 
|---|
|  | 96 | WinSetPresParam(hwnd,PP_FONTNAMESIZE,strlen(s) + 1,s); | 
|---|
|  | 97 | } | 
|---|
|  | 98 |  | 
|---|
|  | 99 |  | 
|---|
|  | 100 | VOID SetFont (HWND hwnd) { | 
|---|
|  | 101 |  | 
|---|
|  | 102 | FONTDLG        fontdlg; | 
|---|
|  | 103 | HPS            hps; | 
|---|
|  | 104 | FONTMETRICS    fm; | 
|---|
|  | 105 | CHAR           szFamily[CCHMAXPATH], | 
|---|
|  | 106 | *szTitle = GetPString(IDS_SETFONTTITLETEXT), | 
|---|
|  | 107 | *szPreview; | 
|---|
|  | 108 |  | 
|---|
|  | 109 | DosEnterCritSec(); | 
|---|
|  | 110 | szPreview = GetPString(IDS_BLURB1TEXT + counter++); | 
|---|
|  | 111 | if(strcmp(szPreview,"0")) { | 
|---|
|  | 112 | counter = 0; | 
|---|
|  | 113 | szPreview = GetPString(IDS_BLURB1TEXT + counter++); | 
|---|
|  | 114 | } | 
|---|
|  | 115 | DosExitCritSec(); | 
|---|
|  | 116 | memset(&fontdlg,0,sizeof(fontdlg));            /* initialize all fields */ | 
|---|
|  | 117 | hps = WinGetPS(hwnd); | 
|---|
|  | 118 | GpiQueryFontMetrics(hps,sizeof(FONTMETRICS),&fm); | 
|---|
|  | 119 | WinReleasePS(hps); | 
|---|
|  | 120 | fontdlg.cbSize = sizeof(FONTDLG); | 
|---|
|  | 121 | fontdlg.hpsScreen = WinGetScreenPS(HWND_DESKTOP); | 
|---|
|  | 122 | fontdlg.hpsPrinter = NULLHANDLE; | 
|---|
|  | 123 | fontdlg.pszTitle = szTitle; | 
|---|
|  | 124 | fontdlg.pszPreview = szPreview; | 
|---|
|  | 125 | fontdlg.pfnDlgProc = NULL; | 
|---|
|  | 126 | strcpy(szFamily,fm.szFamilyname); | 
|---|
|  | 127 | fontdlg.pszFamilyname = szFamily; | 
|---|
|  | 128 | fontdlg.usFamilyBufLen = sizeof(szFamily); | 
|---|
|  | 129 | fontdlg.fxPointSize = MAKEFIXED(fm.sNominalPointSize / 10,0); | 
|---|
|  | 130 | fontdlg.fl = FNTS_CENTER | FNTS_INITFROMFATTRS; | 
|---|
|  | 131 | fontdlg.sNominalPointSize = fm.sNominalPointSize; | 
|---|
|  | 132 | fontdlg.flType = (LONG)fm.fsType; | 
|---|
|  | 133 | fontdlg.clrFore = CLR_NEUTRAL; | 
|---|
|  | 134 | fontdlg.clrBack = CLR_BACKGROUND; | 
|---|
|  | 135 | fontdlg.usWeight = fm.usWeightClass; | 
|---|
|  | 136 | fontdlg.usWidth = fm.usWidthClass; | 
|---|
|  | 137 | if(!WinFontDlg(HWND_DESKTOP,hwnd,&fontdlg) || fontdlg.lReturn != DID_OK) { | 
|---|
|  | 138 | WinReleasePS(fontdlg.hpsScreen); | 
|---|
|  | 139 | return; | 
|---|
|  | 140 | } | 
|---|
|  | 141 | if(fontdlg.fAttrs.fsFontUse == FATTR_FONTUSE_OUTLINE ) | 
|---|
|  | 142 | ConvertVectorFontSize(fontdlg.fxPointSize,&fontdlg.fAttrs); | 
|---|
|  | 143 | WinReleasePS(fontdlg.hpsScreen); | 
|---|
|  | 144 | SetPresParamFromFattrs(hwnd,&fontdlg.fAttrs,fontdlg.sNominalPointSize, | 
|---|
|  | 145 | fontdlg.fxPointSize); | 
|---|
|  | 146 | } | 
|---|
|  | 147 |  | 
|---|
|  | 148 |  | 
|---|
|  | 149 | FATTRS * SetMLEFont (HWND hwndMLE, FATTRS *fattrs, ULONG flags) { | 
|---|
|  | 150 |  | 
|---|
|  | 151 | /* Flags: | 
|---|
|  | 152 | * | 
|---|
|  | 153 | * 1 = Don't assume MLE (no MLM_* messages, use fattrs only | 
|---|
|  | 154 | * 2 = Fixed width fonts only | 
|---|
|  | 155 | * 4 = No synthesized fonts | 
|---|
|  | 156 | * 8 = No vector fonts | 
|---|
|  | 157 | * 16 = No bitmapped fonts | 
|---|
|  | 158 | * | 
|---|
|  | 159 | */ | 
|---|
|  | 160 |  | 
|---|
|  | 161 | FONTDLG        fontDlg; | 
|---|
|  | 162 | HPS            hps; | 
|---|
|  | 163 | FONTMETRICS    fontMetrics; | 
|---|
|  | 164 | CHAR           szFamily[CCHMAXPATH],*szPreview; | 
|---|
|  | 165 | static FIXED   fxPointSize = 0;  /* keep track of this for vector fonts */ | 
|---|
|  | 166 |  | 
|---|
|  | 167 | if((flags & 1) && !fattrs) | 
|---|
|  | 168 | return fattrs; | 
|---|
|  | 169 | DosEnterCritSec(); | 
|---|
|  | 170 | szPreview = GetPString(IDS_BLURB1TEXT + counter++); | 
|---|
|  | 171 | if(strcmp(szPreview,"0")) { | 
|---|
|  | 172 | counter = 0; | 
|---|
|  | 173 | szPreview = GetPString(IDS_BLURB1TEXT + counter++); | 
|---|
|  | 174 | } | 
|---|
|  | 175 | DosExitCritSec(); | 
|---|
|  | 176 | memset(&fontDlg, 0, sizeof(fontDlg));            /* initialize all fields */ | 
|---|
|  | 177 | /* | 
|---|
|  | 178 | * Get the current font attributes | 
|---|
|  | 179 | */ | 
|---|
|  | 180 | hps = WinGetPS(hwndMLE); | 
|---|
|  | 181 | if(!(flags & 1)) | 
|---|
|  | 182 | WinSendMsg(hwndMLE, MLM_QUERYFONT, | 
|---|
|  | 183 | MPFROMP((PFATTRS)&(fontDlg.fAttrs)), NULL); | 
|---|
|  | 184 | else | 
|---|
|  | 185 | memcpy(&fontDlg.fAttrs,fattrs,sizeof(FATTRS)); | 
|---|
|  | 186 |  | 
|---|
|  | 187 | /* create system default font */ | 
|---|
|  | 188 |  | 
|---|
|  | 189 | GpiCreateLogFont(hps,(PSTR8)fontDlg.fAttrs.szFacename,1,&(fontDlg.fAttrs)); | 
|---|
|  | 190 | GpiSetCharSet(hps, 1); | 
|---|
|  | 191 | GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &fontMetrics); | 
|---|
|  | 192 | GpiSetCharSet(hps, LCID_DEFAULT); | 
|---|
|  | 193 | GpiDeleteSetId(hps, 1); | 
|---|
|  | 194 | WinReleasePS(hps); | 
|---|
|  | 195 |  | 
|---|
|  | 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 */ | 
|---|
|  | 202 |  | 
|---|
|  | 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      */ | 
|---|
|  | 239 | //   fontDlg.usDlgId      = IDD_FONT;       /* ID of a custom dialog template  */ | 
|---|
|  | 240 | fontDlg.usFamilyBufLen = sizeof(szFamily); /*Length of family name buffer */ | 
|---|
|  | 241 |  | 
|---|
|  | 242 | /* | 
|---|
|  | 243 | *   Bring up the standard Font Dialog | 
|---|
|  | 244 | */ | 
|---|
|  | 245 |  | 
|---|
|  | 246 | if(!WinFontDlg(HWND_DESKTOP, hwndMLE, &fontDlg) || fontDlg.lReturn != DID_OK) { | 
|---|
|  | 247 | WinReleasePS(fontDlg.hpsScreen); | 
|---|
|  | 248 | return NULL; | 
|---|
|  | 249 | } | 
|---|
|  | 250 | fxPointSize = fontDlg.fxPointSize;     /* save point size for next dialog */ | 
|---|
|  | 251 |  | 
|---|
|  | 252 | /* | 
|---|
|  | 253 | *   If outline font, calculate the maxbaselineext and | 
|---|
|  | 254 | *   avecharwidth for the point size selected | 
|---|
|  | 255 | */ | 
|---|
|  | 256 |  | 
|---|
|  | 257 | if (fontDlg.fAttrs.fsFontUse == FATTR_FONTUSE_OUTLINE ) | 
|---|
|  | 258 | ConvertVectorFontSize(fontDlg.fxPointSize, &fontDlg.fAttrs); | 
|---|
|  | 259 |  | 
|---|
|  | 260 | WinReleasePS(fontDlg.hpsScreen); | 
|---|
|  | 261 | if(!(flags & 1)) | 
|---|
|  | 262 | WinSendMsg(hwndMLE, MLM_SETFONT, MPFROMP(&(fontDlg.fAttrs)), MPVOID); | 
|---|
|  | 263 | if(fattrs) | 
|---|
|  | 264 | memcpy(fattrs,&fontDlg.fAttrs,sizeof(FATTRS)); | 
|---|
|  | 265 | return fattrs; | 
|---|
|  | 266 |  | 
|---|
|  | 267 | }   /* End of SetMLEFont() */ | 
|---|
|  | 268 |  | 
|---|