/* test ttrender */

#define __NOLIBBASE__

#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/ttrender.h>

// #include <libraries/ttrender.h>

extern struct Library *SysBase, *DOSBase;

STRPTR family_table[] = {"default", NULL};
STRPTR family_table2[] = {"Tahoma", "Verdana", "Arial", "sans-serif", "default", NULL};

int Main (void)
  {
    struct Library *TTRenderBase, *IntuitionBase, *GfxBase;
    struct Window *win;
    STRPTR fontname;

    if (GfxBase = OpenLibrary("graphics.library", 39))
      {
        if (IntuitionBase = OpenLibrary("intuition.library", 39))
          {
            if (TTRenderBase = OpenLibrary("ttrender.library", 3))
              {
                if (win = OpenWindowTags(NULL,
                  WA_Top, 25,
                  WA_Left, 0,
                  WA_Width, 640,
                  WA_Height, 250,
                  WA_CloseGadget, TRUE,
                  WA_DragBar, TRUE,
                  WA_DepthGadget, TRUE,
                  WA_IDCMP, IDCMP_CLOSEWINDOW,
                  WA_Title, (ULONG)"TT_OpenFontTagList() test",
                  TAG_END))
                  {
                    ULONG sigmask, signals;
                    BOOL running = TRUE;
                    struct RastPort *rp = win->RPort;

                    TT_SetModesTags(TTA_Window, (ULONG)win, TAG_END);
                    SetAPen(rp, 1);
                    SetDrMd(rp, JAM1);

                    /* test 'all defaults' case */

                    Move(rp, 10, 30);
                    TT_OpenFontTags(TAG_END);
                    TT_PutStr("This is a text printed with default font.");

                    /* 'default' italic, bold, bigger size */

                    Move(rp, 10, 50);
                    TT_OpenFontTags(
                      TTFA_Style,       TTFA_Style_Italic,
                      TTFA_Weight,      TTFA_Weight_Bold,
                      TTFA_Size,        20,
                      TAG_END);
                    TT_PutStr("Default bold italic size 20.");

                    /* 'sans-serif' bold, size 16 pixels */

                    family_table[0] = "sans-serif";
                    Move(rp, 10, 66);
                    TT_OpenFontTags(
                      TTFA_FamilyTable, (ULONG)family_table,
                      TTFA_Weight,      TTFA_Weight_Bold,
                      TTFA_Size,        16,
                      TAG_END);
                    TT_PutStr("Sans-serif fallback, bold, 16 pixels.");

                    /* 'monospaced', size 24 pixels */

                    family_table[0] = "monospaced";
                    Move(rp, 10, 90);
                    TT_OpenFontTags(
                      TTFA_FamilyTable, (ULONG)family_table,
                      TTFA_Size,        24,
                      TAG_END);
                    TT_PutStr("Monospaced fallback, 24 pixels.");

                    /* test font family "cascade": Tahoma, Verdana, Arial, sans-serif, default */

                    Move(rp, 10, 106);
                    TT_OpenFontTags(
                      TTFA_FamilyTable, (ULONG)family_table2,
                      TAG_END);
                    TT_PutStr("Best matching font from following cascade: Tahoma, Verdana, Arial, sans-serif, default.");

                    /* the same for italic - note that because there is no Tahoma Italic, probably Verdana will be used. */

                    Move(rp, 10, 120);
                    TT_OpenFontTags(
                      TTFA_FamilyTable, (ULONG)family_table2,
                      TTFA_Style, TTFA_Style_Italic,
                      TAG_END);
                    TT_PutStr("For italic probably Verdana will be used because ttrender.library does not yet support");
                    Move(rp, 10, 134);
                    TT_PutStr("algorhytmic font shearing.");

                    sigmask = SIGBREAKF_CTRL_C | (1 << win->UserPort->mp_SigBit);
                    while (running)
                      {
                        signals = Wait(sigmask);
                        if (signals & SIGBREAKF_CTRL_C) running = FALSE;
                        if (signals & (1 << win->UserPort->mp_SigBit))
                          {
                            struct IntuiMessage *imsg;

                            while (imsg = (struct IntuiMessage*)GetMsg(win->UserPort))
                              {
                                if (imsg->Class == IDCMP_CLOSEWINDOW) running = FALSE;
                                ReplyMsg((struct Message*)imsg);
                              }
                          }
                      }
                    CloseWindow(win);
                  }
                CloseLibrary(TTRenderBase);
              }
            else PutStr("Can't open ttrender.library v3.0+.\n");
            CloseLibrary(IntuitionBase);
          }
        CloseLibrary(GfxBase);
      }
    return 0;
  }
