void setTNGfont(HPS hps) { LONG cFonts; LONG lTemp = 0L; CHAR fontName[25]; FATTRS fattrs; SIZEF sizfCharBox; fattrs.usRecordLength = sizeof(FATTRS); fattrs.fsSelection = 0; fattrs.lMatch = 0L; fattrs.idRegistry = 0; fattrs.usCodePage = 850; fattrs.lMaxBaselineExt = 0L; fattrs.lAveCharWidth = 0L; fattrs.fsType = 0; fattrs.fsFontUse = FATTR_FONTUSE_OUTLINE; strcpy(fattrs.szFacename,TNG_FONT); cFonts = GpiQueryFonts(hps, QF_PUBLIC,fattrs.szFacename, &lTemp, (LONG) sizeof(FONTMETRICS), (PFONTMETRICS)NULL); if (cFonts==0) { strcpy(fattrs.szFacename,"Helvetica"); } GpiCreateLogFont(hps, (PSTR8)NULL, fontId, &fattrs); GpiSetCharSet(hps,fontId); sizfCharBox.cx=MAKEFIXED(14,0); sizfCharBox.cy=MAKEFIXED(20,0); GpiSetCharBox(hps,&sizfCharBox); GpiSetTextAlignment(hps,TA_CENTER,TA_TOP); }
LONG ScaleFont(HPS hPS, CHAR *pszFacename, LONG lSize) { FATTRS fat; /* Font Attributes */ SIZEF sizfxBox; /* Character Size Holder */ /* Complete the font attributes structure to */ /* allow the selection of the font requested */ /* within the print file dialogue box */ memset(&fat, 0, sizeof(FATTRS)); fat.usRecordLength = (USHORT)sizeof(FATTRS); fat.lMatch = SelectScalableFont(hPS, strcpy(fat.szFacename, pszFacename)); fat.usCodePage = (USHORT)850; /* Create the required font and set the */ /* character size by changing the character box */ /* size. The sizing in TWIPS for a 12 pt font */ /* is 240, therefore a 10 pt font would be 200. */ GpiCreateLogFont(hPS, (PSTR8)NULL, 2L, &fat); GpiSetCharSet(hPS, 2L); sizfxBox.cx = sizfxBox.cy = MAKEFIXED(lSize * 2, 0); GpiSetCharBox(hPS, &sizfxBox); return(2L); }
/**************************************************************** DefaultOutlineFont: Set an outline font which is sizeable. ****************************************************************/ void SetOutlineFont(HPS hps, short height) {FONTMETRICS fm[80]; static FATTRS fat; static LONG cFonts=0; LONG ltemp=0; SIZEF size; int i; if (height<=2) return; if (cFonts==0) { GpiLoadFonts(WinQueryAnchorBlock(HWND_DESKTOP),"helv"); cFonts= GpiQueryFonts(hps,QF_PUBLIC|QF_PRIVATE,"Helv",<emp, sizeof(FONTMETRICS),(PFONTMETRICS)0); if (cFonts>sizeof(fm)/sizeof(FONTMETRICS)) cFonts=sizeof(fm)/sizeof(FONTMETRICS); GpiQueryFonts(hps,QF_PUBLIC|QF_PRIVATE,"Helv",&cFonts, sizeof(FONTMETRICS),fm); for (i=0; (!(fm[i].fsDefn&FM_DEFN_OUTLINE)) && //find outline and (!(fm[i].fsType&FM_TYPE_KERNING)) && //kerned if can (i<cFonts); i++); if (i==cFonts) for (i=0; (!(fm[i].fsDefn&FM_DEFN_OUTLINE))&& // Find outline atleast (i<cFonts); i++); if (i==cFonts) i=0; fat.usRecordLength =sizeof(FATTRS); fat.lMatch =fm[i].lMatch; fat.lMatch =0; fat.fsFontUse = FATTR_FONTUSE_OUTLINE; strcpy(fat.szFacename,fm[i].szFacename); } GpiCreateLogFont(hps,(PSTR8)0,1,&fat); GpiSetBackMix(hps,(LONG)BM_LEAVEALONE); GpiSetCharSet(hps,1); size.cx = MAKEFIXED(height,0); size.cy = MAKEFIXED(height,0); GpiSetCharBox(hps,&size); GpiSetTextAlignment(hps,TA_NORMAL_HORIZ,TA_BOTTOM); }
VOID DrawDigitalTime(HWND hwnd) { RECTL rcl; RECTL rclChar; RECTL rclCharOld; RECTL rclTime; RECTL rclAmPm; RECTL rclDate; HPS hpsWnd; SIZEF sizef; USHORT usi; ULONG ulCharWidth,ulCharModulu; char achTime[9]; char achFinalDate[9]; time_t tTime; struct tm *pLocalTime; WinQueryWindowRect (hwnd, &rcl); hpsWnd = WinGetPS (hwnd); memset(achTime,0,sizeof(achTime) ); memset(achFinalDate,0,sizeof(achFinalDate) ); GpiCreateLogColorTable (hpsWnd, LCOL_RESET, LCOLF_RGB, 0, 0, (PLONG) NULL); /* *if black hands and black background *selected force the background to *blue */ if( !cp.clrMinuteHand && !cp.clrBackground ) { cp.clrBackground = RGB_BLUE; } switch (cp.usDispMode & (DM_TIME | DM_DATE)) { case DM_DATE: rclDate = rcl; break; case DM_TIME | DM_DATE: if (!fIconic) { rclTime = rclDate = rcl; rclTime.yBottom = rclDate.yTop = rcl.yTop / 2; break; } /*else fall through*/ case DM_TIME: rclTime = rcl; break; } if (cp.usDispMode & DM_TIME) { rclAmPm = rclTime; time(&tTime); pLocalTime = localtime(&tTime); if (bTwelveHourFormat) { strftime(achTime, sizeof(achTime), "%I %M %S", pLocalTime); } else { strftime(achTime, sizeof(achTime), "%H %M %S", pLocalTime); } /*insert country time separator*/ achTime[2] = achTime[5] = szTimeSep[0]; achTime[8] = '\000'; /*Process 12 hours mode*/ if (bTwelveHourFormat) { if (fIconic) { rclTime.yBottom = rclAmPm.yTop = rclTime.yTop / 2; } else { rclTime.xRight = rcl.xRight * 8 / 11; rclAmPm.xLeft = rclTime.xRight; } strcpy(achAmPm,szAnteMeridian); if (pLocalTime->tm_hour >= 12) { strcpy(achAmPm,szPostMeridian); } } GpiSetCharMode(hpsWnd, CM_MODE3); if (fIconic) { sizef.cx = MAKEFIXED(LOUSHORT((rclTime.xRight - rclTime.xLeft) / 3), 0); sizef.cy = MAKEFIXED(LOUSHORT((rclTime.yTop - rclTime.yBottom) * 1400 / 1000), 0); } else { sizef.cx = MAKEFIXED(LOUSHORT((rclTime.xRight - rclTime.xLeft) / 6), 8000); sizef.cy = MAKEFIXED(LOUSHORT((rclTime.yTop - rclTime.yBottom) * 1000 / 1500), 0); } GpiSetCharBox(hpsWnd, &sizef); if (bTwelveHourFormat) { if( strcmp(achAmPm,achOldAmPm) ) { WinFillRect(hpsWnd, &rclAmPm, cp.clrBackground); WinDrawText(hpsWnd, sizeof(achAmPm) - 1, (PSZ)achAmPm, (PRECTL)&rclAmPm, cp.clrMinuteHand, cp.clrBackground, DT_CENTER | DT_VCENTER ); } } if (!fIconic) { WinDrawText(hpsWnd, sizeof(achTime) - 1 , (PSZ)achTime, (PRECTL)&rclTime, cp.clrMinuteHand, cp.clrBackground, DT_CENTER | DT_VCENTER | DT_QUERYEXTENT); ulCharWidth = (rclTime.xRight - rclTime.xLeft) / (sizeof(achTime) - 1 ); ulCharModulu = (rclTime.xRight - rclTime.xLeft) % (sizeof(achTime) - 1 ); rclCharOld.xRight = rclTime.xLeft; rclChar.yTop = rclTime.yTop; rclChar.yBottom = rclTime.yBottom; for (usi = 0; usi < (sizeof(achTime)); usi++) { rclChar.xLeft = rclCharOld.xRight + (ULONG)1; rclChar.xRight = rclChar.xLeft + ulCharWidth + ((ulCharModulu > 0L) ? 1L : 0L); if (ulCharModulu) ulCharModulu--; if (achTime[usi] == szTimeSep[0]) { rclChar.xRight -= 3; } else { rclChar.xRight += 1; } rclCharOld = rclChar; if (achTime[usi] != achOldTime[usi]) { WinFillRect (hpsWnd, &rclChar, cp.clrBackground); if (!((usi == 0) && (achTime[0] == '0') && (bTwelveHourFormat))) WinDrawText (hpsWnd, 1, (PSZ)&achTime[usi], &rclChar, cp.clrMinuteHand, cp.clrBackground, DT_CENTER | DT_VCENTER); } } } else { /*Iconic. just draw if minute changed*/ if (strncmp(achTime,achOldTime,5)) { WinFillRect(hpsWnd,&rclTime,cp.clrBackground); WinDrawText(hpsWnd, sizeof(achTime) - 4 , (PSZ)achTime, (PRECTL)&rclTime, cp.clrMinuteHand, cp.clrBackground, DT_CENTER | DT_VCENTER); } } } if ((!(cp.usDispMode & DM_TIME)) || ((cp.usDispMode & DM_DATE) && (!fIconic))) { GetArrangedDate(achFinalDate); if (strncmp(achFinalDate, achOldDate, sizeof(achFinalDate) - fIconic ? 4 : 1)) { WinFillRect (hpsWnd, &rclDate, cp.clrBackground); GpiSetCharMode (hpsWnd, CM_MODE3); sizef.cx = MAKEFIXED(LOUSHORT( (rclDate.xRight - rclDate.xLeft) / 5), 0); sizef.cy = MAKEFIXED(LOUSHORT( (rclDate.yTop - rclDate.yBottom) * 1000 / 1500), 0); GpiSetCharBox(hpsWnd, &sizef); WinDrawText(hpsWnd, (sizeof(achFinalDate) - (fIconic ? 4 : 1) ), (PSZ)achFinalDate,(PRECTL)&rclDate, (LONG)cp.clrMinuteHand, (LONG)cp.clrBackground, (ULONG )(DT_CENTER | DT_VCENTER ) ); } } WinReleasePS(hpsWnd); strncpy(achOldTime,achTime,sizeof(achOldTime)); strncpy(achOldAmPm,achAmPm,sizeof(achOldAmPm)); strncpy(achOldDate,achFinalDate,sizeof(achOldDate)); }
/****************************************************************\ * *-------------------------------------------------------------- * * Name: ClkSize() * * Purpose:When the window has been sized, we calculate a page * rectangle which: (a) fills the window rectangle in either * the x or y dimension, (b) appears square, and (c) is centered * in the window rectangle * Usage: * * Method: * - * * - * - * * - * - * * Returns: * * \****************************************************************/ VOID ClkSize (HWND hwnd) { RECTL rclWindow; SIZEF sizef; LONG cxSquare, cySquare, cxEdge, cyEdge; LONG cyHeight; LONG cxWidth; HBITMAP hbm; BITMAPINFOHEADER bmp; /* * First get rid of any buffer bitmap already there. */ hbm = GpiSetBitmap (hpsBuffer, NULLHANDLE); if (hbm != NULLHANDLE) GpiDeleteBitmap (hbm); /* * Get the width and height of the window rectangle. */ WinQueryWindowRect (hwnd, &rclWindow); cxWidth = rclWindow.xRight - rclWindow.xLeft - 2; cyHeight = rclWindow.yTop - rclWindow.yBottom - 2; /* * Now create a bitmap the size of the window. */ bmp.cbFix = sizeof(BITMAPINFOHEADER); bmp.cx = (SHORT)cxWidth; bmp.cy = (SHORT)cyHeight; bmp.cPlanes = (SHORT)cColorPlanes; bmp.cBitCount = (SHORT)cColorBitcount; hbm = GpiCreateBitmap(hpsBuffer, (PBITMAPINFOHEADER2)&bmp, 0x0000, (PBYTE)NULL, (PBITMAPINFO2)NULL); GpiSetBitmap (hpsBuffer, hbm); /* * Assume the size of the page rectangle is constrained in the y * dimension,compute the x size which would make the rectangle appear * square, then check the assumption and do the reverse calculation * if necessary. */ cySquare = cyHeight - 2; cxSquare = ( cyHeight * cxRes ) / cyRes; if (cxWidth < cxSquare) { cxSquare = cxWidth - 2; cySquare = (cxWidth * cyRes) / cxRes; } /* * Fill in the page rectangle and set the page viewport. */ cxEdge = (cxWidth - cxSquare ) / 2; cyEdge = (cyHeight - cySquare ) / 2; rclPage.xLeft = cxEdge; rclPage.xRight = cxWidth - cxEdge; rclPage.yBottom = cyEdge; rclPage.yTop = cyHeight - cyEdge; /* * Determine where to put the date. If we have room under the clock, we * put it there. If we have more room on the left we put it there. If we * have more room in the midlle, it goes there. */ if (cp.usDispMode & DM_DATE) { vclrDate[SURFACE] = vclrBG[SHADE]; vclrDate[LIGHT] = vclrBG[LIGHT]; vclrDate[SHADE] = vclrBG[SHADE]; vclrDate[BACKGROUND] = vclrBG[SURFACE]; if (cyHeight > (cySquare*6/5)) { /*Goes under*/ vmatlfDateTrans.lM31 = (LONG)15; /*Horizontal*/ vmatlfDateTrans.lM32 = -(LONG)17; /*vertical*/ vmatlfDateScale.fxM11 = MAKEFIXED(2,0x8000); vmatlfDateScale.fxM22 = MAKEFIXED(2,0x8000); rclPage. yTop += cyEdge; rclPage. yBottom += cyEdge; vusDatePos = DP_UNDER; } else { if (cxWidth > (cxSquare * 31/10 )) { vmatlfDateTrans.lM31 = -(LONG)53 ; /*Horizontal*/ vmatlfDateTrans.lM32 = (LONG)04; /*vertical*/ vmatlfDateScale.fxM11 = MAKEFIXED(7,0xe000); vmatlfDateScale.fxM22 = MAKEFIXED(7,0xe000); rclPage.xRight += cxEdge; rclPage.xLeft += cxEdge; vusDatePos = DP_LEFTMIDDLE; } else { if (cxWidth > (cxSquare * 2)) { /*Goes on the left*/ vmatlfDateTrans.lM31 = -(LONG)52 ; /*Horizontal*/ vmatlfDateTrans.lM32 = (LONG)2; /*vertical*/ vmatlfDateScale.fxM11 = MAKEFIXED(3,0xd000); vmatlfDateScale.fxM22 = MAKEFIXED(3,0xd000); rclPage.xRight += cxEdge; rclPage.xLeft += cxEdge; vusDatePos = DP_LEFTDOWN ; } else { /*Goes inside*/ vmatlfDateTrans.lM31 = (LONG)24 ; /*Horizontal*/ vmatlfDateTrans.lM32 = (LONG)23; /*vertical*/ vmatlfDateScale.fxM11 = MAKEFIXED(2,0); vmatlfDateScale.fxM22 = MAKEFIXED(2,0); vclrDate[SURFACE] = vclrFace[SHADE] ; vclrDate[LIGHT] = vclrFace[LIGHT] ; vclrDate[SHADE] = vclrFace[SHADE]; vclrDate[BACKGROUND] = vclrFace[SURFACE]; vusDatePos = DP_INSIDE; } } } } f = GpiSetPageViewport (hps, &rclPage); f = GpiSetPageViewport (hpsBuffer, &rclPage); /* * Are we iconic? */ f = WinQueryWindowPos (hwndFrame, &swp); fIconic = (BOOL)(swp.fl & SWP_MINIMIZE ); fShowSecondHand = (BOOL) !(fIconic); GpiQueryCharBox(hpsBuffer, &sizef); GpiSetCharBox(hpsBuffer, &sizef); fBufferDirty = TRUE; }