SCOUG Logo


Next Meeting: Sat, TBD
Meeting Directions


Be a Member
Join SCOUG

Navigation:


Help with Searching

20 Most Recent Documents
Search Archives
Index by date, title, author, category.


Features:

Mr. Know-It-All
Ink
Download!










SCOUG:

Home

Email Lists

SIGs (Internet, General Interest, Programming, Network, more..)

Online Chats

Business

Past Presentations

Credits

Submissions

Contact SCOUG

Copyright SCOUG



warp expowest
Pictures from Sept. 1999

The views expressed in articles on this site are those of their authors.

warptech
SCOUG was there!


Copyright 1998-2024, Southern California OS/2 User Group. ALL RIGHTS RESERVED.

SCOUG, Warp Expo West, and Warpfest are trademarks of the Southern California OS/2 User Group. OS/2, Workplace Shell, and IBM are registered trademarks of International Business Machines Corporation. All other trademarks remain the property of their respective owners.

The Southern California OS/2 User Group
USA

SCOUG-Programming Mailing List Archives

Return to [ 21 | May | 2006 ]

<< Previous Message << >> Next Message >>


Date: Sun, 21 May 2006 06:23:55 -0700
From: Nathan Woodruff <n_woodruff@bellsouth.net >
Reply-To: scoug-programming@scoug.com
To: scoug-programming@scoug.com
Subject: SCOUG-Programming: Logical Font Tables

Content Type: text/plain

Steven Levine wrote:

> In <20060521025716.D45C18287B@smtp3.pacifier.net>, on 05/20/06
> at 07:57 PM, "Bob" said:
>
> >Steven here is the code I use to save and restore the presentation
> >parameters.
>
> I suspect once you get your font code working to support multiple
> typefaces, you will need to do something similar.
>
> Regards,
>
> Steven

Well, maybe is a good time to explain Logical font tables. Think of it as a list of
pointers that point to different fonts. I don't think there is a limit to the number of
pointers that you can have either. Well, maybe the limit is the amount of memory you
have in your computer. Just think of it as say a list of 10 pointers pointing to 10
different fonts.

On your WM_CREATE message you need to have your own Presentation Space to play around
with. You can't directly play with the programs Presentation Space. So..., to create
your own have this in your WM_CREATE message...

HDC hdc;
SIZEL sizlPSPage;

hdc = WinQueryWindowDC(hwnd);
if (hdc == (HDC) NULL)
hdc = WinOpenWindowDC(hwnd);

sizlPSPage.cx = 0L;
sizlPSPage.cy = 0L;
hPS = GpiCreatePS(WinQueryAnchorBlock(hwnd),
hdc, &sizlPSPage,
PU_ARBITRARY | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);

This will create your very own Presentation space to play with. The hwnd in this
case is the HWND defined in your WindowProc(HWND, LONG, MPARAM, MPARAM) procedure.

First to use the system fonts you need to query the system font table to make sure that
the font you want to use is loaded in the system. To find out how many fonts are in your
system table,

ulCount = GpiQueryFonts (hPS,QF_PUBLIC | QF_PRIVATE,0,
(LONG *)&ulCount,(LONG)sizeof(FONTMETRICS),0);

ulCount is an unsigned long.

This lists the number of fonts that are loaded in OS/2. Use the hPS returned from your
own Presentation Space create. All system font are available to your newly created
space. Using the handle to the HWND_DESKTOP will also work too, but not recommended.

Now you need to allocate memory because you can't directly fool around with the system
font table. You have to copy them into your own space.

if (ulCount)
{
DosAllocMem ((PPVOID)&pFontMetrics,sizeof(FONTMETRICS) * (USHORT)ulCount,
OBJ_TILE | PAG_READ | PAG_WRITE | PAG_COMMIT);
GpiQueryFonts (hPS,QF_PUBLIC | QF_PRIVATE,0,
(LONG *)&ulCount,(LONG)sizeof(FONTMETRICS),pFontMetrics);

pFontMetrics is a pointer to a FONTMETRICS or a PFONTMETRICS. The QueryFonts call
copies the system fonts into the memory that you have allocated.

Next is to search through the font list table just copied for the font that you would
like to use....

for (i = 0; i < (int)ulCount; i++)
{
/* If the facename has been truncated query the atom text */
if ( ((pFontMetrics+i)->fsType & FM_TYPE_FACETRUNC) &&
(ulSize =
WinQueryAtomLength(hAtomTable,(pFontMetrics+i)->FaceNameAtom)) )
{
ulSize++;
DosSubAlloc(pMem,(PPVOID)&pData,ulSize);
if (WinQueryAtomName
(hAtomTable,(pFontMetrics+i)->FaceNameAtom,pData,ulSize))
pFace = pData;
else
pFace = (pFontMetrics+i)->szFacename;
}
else
pFace = (pFontMetrics+i)->szFacename;

This may look like a lot but all it is doing is querying the long face name if it
has been truncated. I think font names are limited to 12 characters. I think names like
"Times New Roman" gets truncated to something like "Times NR".

So now if you have found the font that you want to use, save it to your own font metrics
space. Font is defined as FONTMETRICS.

if (strcmp("WarpSans Bold",pFace) == 0) -- or any other font you would like to
use --
{
FontNumber = i;
memcpy(&Font,(pFontMetrics+i), sizeof(FONTMETRICS));
}

If you allocated more memory for the truncated name, de allocate it.

if (ulSize)
DosSubFree(pMem,pData,ulSize);

End the for loop...

}

free the allocated memory that held your system font table.

DosFreeMem((PVOID)pFontMetrics);

Now to use the font that you have just found in the font system list create a logical
font table in your own Presentation Space.....

FATTRS fat;

strcpy(fat.szFacename ,"WarpSans Bold");
fat.usRecordLength = sizeof(FATTRS);
fat.fsSelection = Font.fsSelection;
fat.lMatch = Font.lMatch;
fat.idRegistry = Font.idRegistry;
fat.usCodePage = Font.usCodePage;
fat.lMaxBaselineExt = Font.lMaxBaselineExt;
fat.lAveCharWidth = Font.lAveCharWidth;
fat.fsType = Font.fsType;
fat.fsFontUse = FATTR_FONTUSE_NOMIX;
fat.fsFontUse = 0;
GpiCreateLogFont(hPS, NULL, 1, &fat);

if you have pointers to multiple System fonts, you can copy it again to the
above FATTRS and copy that to a different logical font number.

GpiCreateLogFont(hPS, NULL, 2, &fat);
and...
GpiCreateLogFont(hPS, NULL, 3, &fat);
and....
GpiCreateLogFont(hPS, NULL, 4, &fat);
You get the idea.

To use your font selected, in the WM_PAINT message, the only place that you should be
writing text to a window client space, select the font that you want to use from your
created logical fonts...

GpiSetCharSet(hps, 1);

or which ever font,

GpiSetCharSet(hps, 4); -- if you like the 4th font in the table --

Next set the point size of the font that you are using. You can set the height and width
point size, something I don't think you can do in windoze. To set the point size...,

SIZEF sf;

sf.cy = MAKEFIXED(14, 0);
sf.cx = MAKEFIXED(12, 0);
GpiSetCharBox (hps,&sf);

This will make your font 14 points tall and 12 points wide.

Lastly draw text to your client window at will and be fascinated how easy it is to use
so many different fonts in your program.
RECTL rClient;

rClient.xLeft = 0;
rClient.xRight = 150;
rClient.yBottom = 0;
rClient.yTop = 20;

GpiSetCharSet(hps, 1);
WinDrawText(hps, 15 , "Wow! This Works", &rClient, 0L, 0L, DT_CENTER |
DT_VCENTER | DT_TEXTATTRS);

rClient.yBottom = 30;
rClient.yTop = 50;
GpiSetCharSet(hps, 2);
WinDrawText(hps, 13 , "Wow! New Font", &rClient, 0L, 0L, DT_CENTER |
DT_VCENTER | DT_TEXTATTRS);

It is that simple. Have fun and Good Luck!

Nathan

=====================================================

To unsubscribe from this list, send an email message
to "steward@scoug.com". In the body of the message,
put the command "unsubscribe scoug-programming".

For problems, contact the list owner at
"postmaster@scoug.com".

=====================================================


<< Previous Message << >> Next Message >>

Return to [ 21 | May | 2006 ]



The Southern California OS/2 User Group
P.O. Box 26904
Santa Ana, CA 92799-6904, USA

Copyright 2001 the Southern California OS/2 User Group. ALL RIGHTS RESERVED.

SCOUG, Warp Expo West, and Warpfest are trademarks of the Southern California OS/2 User Group. OS/2, Workplace Shell, and IBM are registered trademarks of International Business Machines Corporation. All other trademarks remain the property of their respective owners.