home *** CD-ROM | disk | FTP | other *** search
- /* test ttrender */
-
- #define __NOLIBBASE__
-
- #include <proto/dos.h>
- #include <proto/exec.h>
- #include <proto/intuition.h>
- #include <proto/graphics.h>
- #include <proto/ttengine.h>
- #include <proto/asl.h>
- #include <proto/datatypes.h>
- #include <proto/mathieeesingbas.h>
- #include <datatypes/pictureclass.h>
- #include <utility/hooks.h>
-
- #include <libraries/ttengine.h>
-
- #define reg(a) __asm(#a)
-
- extern struct Library *SysBase, *DOSBase;
-
- struct ResizeInfo
- {
- WORD oldw, oldh, bline;
- };
-
- struct Library *TTEngineBase, *IntuitionBase, *GfxBase, *AslBase, *DataTypesBase,
- *MathIeeeSingBasBase;
- struct BitMap *PicBitMap;
- Object *Picture;
- struct TextExtent te;
-
- /*----------------------------------------------------------------------------------------------------*/
-
- static STRPTR get_font_name(struct Library *AslBase)
- {
- struct FileRequester *freq;
- STRPTR name = NULL;
-
- if (freq = AllocAslRequestTags(ASL_FileRequest, TAG_END))
- {
- if (AslRequestTags(freq,
- ASLFR_TitleText, (ULONG)"Select TrueType font",
- ASLFR_InitialDrawer, (ULONG)"FONTS:",
- ASLFR_DoPatterns, TRUE,
- ASLFR_InitialPattern, (ULONG)"#?.ttf",
- ASLFR_RejectIcons, TRUE,
- TAG_END))
- {
- ULONG namelen = strlen(freq->fr_File) + strlen(freq->fr_Drawer) + 4;
-
- if (name = AllocVec(namelen + 1, MEMF_ANY | MEMF_CLEAR))
- {
- strncpy(name, freq->fr_Drawer, namelen);
- AddPart(name, freq->fr_File, namelen);
- }
- }
- FreeAslRequest(freq);
- }
- return name;
- }
-
- /*----------------------------------------------------------------------------------------------------*/
-
- static VOID free_font_name(STRPTR name)
- {
- if (name) FreeVec(name);
- }
-
- /*----------------------------------------------------------------------------------------------------*/
-
- BOOL init(VOID)
- {
- if (!(GfxBase = OpenLibrary("graphics.library", 39))) return FALSE;
- if (!(IntuitionBase = OpenLibrary("intuition.library", 39))) return FALSE;
- if (!(AslBase = OpenLibrary("asl.library", 38))) return FALSE;
- if (!(TTEngineBase = OpenLibrary("ttengine.library", 4))) return FALSE;
- if (!(DataTypesBase = OpenLibrary("datatypes.library", 39))) return FALSE;
- if (!(MathIeeeSingBasBase = OpenLibrary("mathieeesingbas.library", 38))) return FALSE;
- return TRUE;
- }
-
- /*----------------------------------------------------------------------------------------------------*/
-
- VOID cleanup(VOID)
- {
- if (MathIeeeSingBasBase) CloseLibrary(MathIeeeSingBasBase);
- if (DataTypesBase) CloseLibrary(DataTypesBase);
- if (TTEngineBase) CloseLibrary(TTEngineBase);
- if (AslBase) CloseLibrary(AslBase);
- if (IntuitionBase) CloseLibrary(IntuitionBase);
- if (GfxBase) CloseLibrary(GfxBase);
- return;
- }
-
- /*----------------------------------------------------------------------------------------------------*/
-
- VOID load_picture(struct Screen *s)
- {
- if (Picture = NewDTObject("PROGDIR:background",
- DTA_GroupID, GID_PICTURE,
- PDTA_Remap, TRUE,
- PDTA_DestMode, PMODE_V43,
- PDTA_Screen, (ULONG)s,
- TAG_END))
- {
- DoDTMethod(Picture, NULL, NULL, DTM_PROCLAYOUT, NULL, DTSIF_NEWSIZE);
- GetDTAttrs(Picture, PDTA_DestBitMap, (ULONG)&PicBitMap, TAG_END);
- }
- return;
- }
-
- /*----------------------------------------------------------------------------------------------------*/
-
- struct BfMsg
- {
- struct Layer *layer;
- struct Rectangle bounds;
- LONG xoffs;
- LONG yoffs;
- };
-
- __saveds LONG bf(struct RastPort *rp reg(a2), struct BfMsg *msg reg(a1))
- {
- WORD lenx, srcx, destx, ix;
- WORD leny, srcy, desty, iy;
-
- for (ix = (msg->bounds.MinX & 0xFFC0); ix <= msg->bounds.MaxX; ix += 64)
- {
- destx = ix;
- srcx = 0;
- lenx = 64;
-
- if (destx < msg->bounds.MinX)
- {
- destx = msg->bounds.MinX;
- srcx = destx & 0x3F;
- lenx = 64 - srcx;
- }
-
- if (destx + 64 > msg->bounds.MaxX)
- {
- lenx = msg->bounds.MaxX - destx + 1;
- }
-
- for (iy = (msg->bounds.MinY & 0xFFC0); iy <= msg->bounds.MaxY; iy += 64)
- {
- desty = iy;
- srcy = 0;
- leny = 64;
-
- if (desty < msg->bounds.MinY)
- {
- desty = msg->bounds.MinY;
- srcy = desty & 0x3F;
- leny = 64 - srcy;
- }
-
- if (desty + 64 > msg->bounds.MaxY)
- {
- leny = msg->bounds.MaxY - desty + 1;
- }
-
- BltBitMap(PicBitMap, srcx, srcy, rp->BitMap, destx, desty, lenx, leny,
- 0xC0, 0xFF, NULL);
- }
-
- }
- return 0;
- }
-
- struct Hook bf_hook = {NULL, NULL, (HOOKFUNC)bf, NULL, NULL};
-
- /*----------------------------------------------------------------------------------------------------*/
-
- ULONG initialize_window(struct Window *win, APTR font, struct TextExtent *te)
- {
- WORD x, y;
- ULONG pen;
-
- x = win->BorderLeft - te->te_Extent.MinX + 5;
- y = win->BorderTop - te->te_Extent.MinY + 5;
-
- pen = ObtainBestPen(win->WScreen->ViewPort.ColorMap, 0xEEEEEEEE, 0xBBBBBBBB, 0,
- OBP_Precision, PRECISION_IMAGE,
- TAG_END);
- TT_SetFont(win->RPort, font);
- TT_SetAttrs(win->RPort,
- TT_Window, (ULONG)win,
- TAG_END);
- Move(win->RPort, x, y);
- SetAPen(win->RPort, pen);
- SetDrMd(win->RPort, JAM1);
- TT_Text(win->RPort, "Font scaling", 12);
- return pen;
- }
-
- /*----------------------------------------------------------------------------------------------------*/
-
- VOID resize_text(struct Window *win)
- {
- WORD x, y;
- WORD neww, newh, newbline, newxdelta;
- FLOAT sclx, scly;
-
- neww = win->Width - win->BorderLeft - win->BorderRight - 10;
- newh = win->Height - win->BorderTop - win->BorderBottom - 10;
-
- sclx = IEEESPDiv(IEEESPFlt(neww),IEEESPFlt(te.te_Extent.MaxX - te.te_Extent.MinX + 1));
- scly = IEEESPDiv(IEEESPFlt(newh),IEEESPFlt(te.te_Extent.MaxY - te.te_Extent.MinY + 1));
- newbline = IEEESPFix(IEEESPMul(IEEESPFlt(-te.te_Extent.MinY), scly));
- newxdelta = IEEESPFix(IEEESPMul(IEEESPFlt(te.te_Extent.MinX), sclx));
-
- TT_SetAttrs(win->RPort,
- TT_ScaleX, *((ULONG*)&sclx),
- TT_ScaleY, *((ULONG*)&scly),
- TAG_END);
-
- EraseRect(win->RPort, win->BorderLeft, win->BorderTop, win->Width - win->BorderRight,
- win->Height - win->BorderBottom);
- Move(win->RPort, win->BorderLeft - newxdelta + 5, win->BorderTop + newbline + 5);
- TT_Text(win->RPort, "Font scaling", 12);
- }
-
- /*----------------------------------------------------------------------------------------------------*/
-
- void main_loop(struct Window *win)
- {
- BOOL running = TRUE;
- ULONG signals, portmask, idcmp_class;
- struct IntuiMessage *msg;
-
- portmask = 1 << win->UserPort->mp_SigBit;
-
- while (running)
- {
- signals = Wait(portmask | SIGBREAKF_CTRL_C);
-
- if (signals & SIGBREAKF_CTRL_C) running = FALSE;
-
- if (signals & portmask)
- {
- while (msg = (struct IntuiMessage*)GetMsg(win->UserPort))
- {
- idcmp_class = msg->Class;
- ReplyMsg((struct Message*)msg);
-
- switch (idcmp_class)
- {
- case IDCMP_CLOSEWINDOW:
- running = FALSE;
- break;
-
- case IDCMP_NEWSIZE:
- resize_text(win);
- break;
- }
- }
- }
- }
- return;
- }
-
- /*----------------------------------------------------------------------------------------------------*/
-
- int Main (void)
- {
- struct Window *win;
- struct Screen *wb;
- STRPTR fontname, text = "Font scaling";
- APTR font;
- WORD ww, wh;
- ULONG pen;
-
- if (init())
- {
- if (fontname = get_font_name(AslBase))
- {
- if (font = TT_OpenFont(
- TT_FontFile, (ULONG)fontname,
- TT_FontSize, 50,
- TAG_END))
- {
- if (wb = LockPubScreen(NULL))
- {
- if (TT_SetFont(&wb->RastPort, font))
- {
- TT_SetAttrs(&wb->RastPort,
- TT_Screen, (ULONG)wb,
- TT_Antialias, TT_Antialias_On,
- TAG_END);
- TT_TextExtent(&wb->RastPort, text, 12, &te);
- ww = te.te_Extent.MaxX - te.te_Extent.MinX + 10;
- wh = te.te_Extent.MaxY - te.te_Extent.MinY + 10;
- load_picture(wb);
- if (win = OpenWindowTags(NULL,
- WA_Top, wb->BarHeight + 1,
- WA_InnerWidth, ww + 1,
- WA_InnerHeight, wh + 1,
- WA_Title, (ULONG)"TTEngine font scaling",
- WA_CloseGadget, TRUE,
- WA_DepthGadget, TRUE,
- WA_DragBar, TRUE,
- WA_SizeGadget, TRUE,
- WA_MinHeight, 50,
- WA_MinWidth, 100,
- WA_MaxHeight, 20000,
- WA_MaxWidth, 20000,
- WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE,
- WA_BackFill, (ULONG)&bf_hook,
- TAG_END))
- {
- pen = initialize_window(win, font, &te);
- main_loop(win);
- TT_DoneRastPort(win->RPort);
- CloseWindow(win);
- ReleasePen(win->WScreen->ViewPort.ColorMap, pen);
- }
- }
- UnlockPubScreen(NULL, wb);
- }
- TT_CloseFont(font);
- }
- free_font_name(fontname);
- }
- }
- cleanup();
- return 0;
- }
-