comparison os2/dw.c @ 9:3383ed751a7e

New font rendering code in dw_draw_text(). Slightly less flexible but works on all systems.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 03 Jul 2001 15:32:38 +0000
parents e22584460709
children 26e2130135b9
comparison
equal deleted inserted replaced
8:e22584460709 9:3383ed751a7e
4583 if(!pixmap) 4583 if(!pixmap)
4584 WinReleasePS(hps); 4584 WinReleasePS(hps);
4585 } 4585 }
4586 4586
4587 4587
4588 void _CopyFontSettings(HPS hpsSrc, HPS hpsDst)
4589 {
4590 FONTMETRICS fm;
4591 FATTRS fat;
4592 SIZEF sizf;
4593
4594 GpiQueryFontMetrics(hpsSrc, sizeof(FONTMETRICS), &fm);
4595
4596 memset(&fat, 0, sizeof(fat));
4597
4598 fat.usRecordLength = sizeof(FATTRS);
4599 fat.lMatch = fm.lMatch;
4600 strcpy(fat.szFacename, fm.szFacename);
4601
4602 GpiCreateLogFont(hpsDst, 0, 1L, &fat);
4603 GpiSetCharSet(hpsDst, 1L);
4604
4605 sizf.cx = MAKEFIXED(fm.lEmInc,0);
4606 sizf.cy = MAKEFIXED(fm.lMaxBaselineExt,0);
4607 GpiSetCharBox(hpsDst, &sizf );
4608 }
4609
4588 /* Draw text on a window (preferably a render window). 4610 /* Draw text on a window (preferably a render window).
4589 * Parameters: 4611 * Parameters:
4590 * handle: Handle to the window. 4612 * handle: Handle to the window.
4591 * pixmap: Handle to the pixmap. (choose only one of these) 4613 * pixmap: Handle to the pixmap. (choose only one of these)
4592 * x: X coordinate. 4614 * x: X coordinate.
4594 * text: Text to be displayed. 4616 * text: Text to be displayed.
4595 */ 4617 */
4596 void dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text) 4618 void dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text)
4597 { 4619 {
4598 HPS hps; 4620 HPS hps;
4599 int size = 9, z, l, height; 4621 int size = 9, z, height;
4600 POINTL ptl; 4622 RECTL rcl;
4601 FATTRS fat;
4602 SIZEF sizfCharBox;
4603 FONTMETRICS *fm;
4604 LONG lHorzRes, lVertRes, lRequestFonts, lNumberFonts;
4605 HDC hdc;
4606 char fontname[128]; 4623 char fontname[128];
4607 4624
4608 if(handle) 4625 if(handle)
4609 { 4626 {
4610 hps = _set_colors(handle); 4627 hps = _set_colors(handle);
4611 height = _get_height(handle); 4628 height = _get_height(handle);
4612 _GetPPFont(handle, fontname); 4629 _GetPPFont(handle, fontname);
4613 } 4630 }
4614 else if(pixmap) 4631 else if(pixmap)
4615 { 4632 {
4633 HPS pixmaphps = WinGetPS(pixmap->handle);
4634
4616 hps = _set_hps(pixmap->hps); 4635 hps = _set_hps(pixmap->hps);
4617 height = pixmap->height; 4636 height = pixmap->height;
4618 _GetPPFont(pixmap->handle, fontname); 4637 _GetPPFont(pixmap->handle, fontname);
4638 _CopyFontSettings(pixmaphps, hps);
4639 WinReleasePS(pixmaphps);
4619 } 4640 }
4620 else 4641 else
4621 return; 4642 return;
4622 4643
4623 ptl.x = x;
4624 ptl.y = height - y - 2;
4625
4626 for(z=0;z<strlen(fontname);z++) 4644 for(z=0;z<strlen(fontname);z++)
4627 { 4645 {
4628 if(fontname[z]=='.') 4646 if(fontname[z]=='.')
4629 break; 4647 break;
4630 } 4648 }
4631 size = atoi(fontname); 4649 size = atoi(fontname);
4632 4650
4633 ptl.y -= size; 4651 rcl.xLeft = x;
4634 4652 rcl.yTop = height - y;
4635 hdc = GpiQueryDevice(hps); 4653 rcl.yBottom = rcl.yTop - (size*2);
4636 4654 rcl.xRight = rcl.xLeft + (size * strlen(text));
4637 DevQueryCaps(hdc, CAPS_HORIZONTAL_FONT_RES, 1L, &lHorzRes); 4655
4638 DevQueryCaps(hdc, CAPS_VERTICAL_FONT_RES, 1L, &lVertRes); 4656 WinDrawText(hps, -1, text, &rcl, DT_TEXTATTRS, DT_TEXTATTRS, DT_VCENTER | DT_LEFT | DT_TEXTATTRS);
4639
4640 lNumberFonts = GpiQueryFonts(hps, QF_PUBLIC | QF_PRIVATE, &fontname[z+1], &lRequestFonts, 0, NULL);
4641
4642 fm = malloc(lNumberFonts * sizeof(FONTMETRICS));
4643
4644 GpiQueryFonts(hps, QF_PUBLIC | QF_PRIVATE, &fontname[z+1], &lNumberFonts, sizeof(FONTMETRICS), fm);
4645
4646 fat.lMatch = 0L;
4647
4648 for(l=0;l<lNumberFonts;l++)
4649 {
4650 if(fm[l].sXDeviceRes == (SHORT)lHorzRes &&
4651 fm[l].sYDeviceRes == (SHORT)lVertRes &&
4652 (fm[l].fsDefn & 1) == 0 &&
4653 fm[l].sNominalPointSize == (size*10))
4654 {
4655 fat.lMatch = fm[l].lMatch;
4656 break;
4657 }
4658 }
4659
4660 fat.usRecordLength = sizeof(FATTRS);
4661 fat.fsSelection = 0;
4662 fat.idRegistry = 0;
4663 fat.usCodePage = GpiQueryCp(hps);
4664 fat.lMaxBaselineExt = 0;
4665 fat.lAveCharWidth = 0;
4666 fat.fsType = 0;
4667 fat.fsFontUse = 0;
4668
4669 strcpy(fat.szFacename , &fontname[z+1]);
4670
4671 GpiCreateLogFont(hps, NULL, 1L, &fat);
4672
4673 GpiSetCharSet(hps, 1L);
4674
4675 if(fm)
4676 free(fm);
4677 else
4678 {
4679 sizfCharBox.cx = MAKEFIXED(size,0);
4680 sizfCharBox.cy = MAKEFIXED(size,0);
4681 GpiSetCharBox(hps, &sizfCharBox);
4682 }
4683
4684 GpiCharStringAt(hps, &ptl, strlen(text), text);
4685 4657
4686 if(!pixmap) 4658 if(!pixmap)
4687 WinReleasePS(hps); 4659 WinReleasePS(hps);
4688 } 4660 }
4689 4661