View Raw SPL
/* add a header or footer to a window or worksheet */
texttitler(title, justify, color, target, tfont, marg, tagstr)
{
        local loc, oh, nh = 0;

        if (argc < 7)
        {
                if (argc < 6)
                {
                        if (argc < 5)
                        {
                                if (argc < 4)
                                {
                                        if (argc < 3)
                                        {
                                                if (argc < 2)
                                                {
                                                        if (argc < 1) error("texttitler - title string required");
                        
                                                        /* center */
                                                        justify = 0;
                                                }
                                
                                                color = -1;
                                        }

                                        /* window */
                                        target = 3;
                                }

                                tfont = WINTITLE_FONT;
                        }

                        just = 0;
                }

                tagstr = "";
        }

        /* justify to location */
        loc = _just2loc(justify, marg);

        /* find previous title */
        if (target != GLASS_WSMARGIN)
        {
                /* window text */
                oh = findtext("winnum", getwnum, "target", target, "font", tfont, "margin", marg, "location", loc, "tag", tagstr);

                if (isempty(oh))
                {
                        /* legacy */
                        oh = findtext("winnum", getwnum, "target", target, "margin", marg);
                }
        }
        else
        {
                /* worksheet text */
                oh = findtext("target", target, "font", tfont, "margin", marg, "location", loc, "tag", tagstr);

                if (isempty(oh))
                {
                        /* legacy */
                        oh = findtext("target", target, "margin", marg);
                }
        }

        if (not(isempty(oh)))
        {
                if (oh.annum < 0)
                {
                        /* legacy */
                        deletehandle(oh);
                        oh = {};
                }
        }

        if (isempty(oh))
        {
                /* add text to target */
                nh = text(0.0, 0.0, target, color, -1, tfont, -1, -1, -1, marg, -1, -1, -1, -1, -1, -1, -1,
                  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, loc, caststring(title));

                nh.tag = caststring(tagstr);
        }
        else
        {
                (fname, height, bold, italic) = getfontspec(tfont);

                oh.target   = target;
                oh.font     = tfont;
                oh.margin   = marg;
                oh.location = loc;
                oh.tag      = caststring(tagstr);
                oh.text     = caststring(title);
                oh.color    = color;

                oh.fontsize = height;
                oh.bold     = bold;
                oh.italic   = italic;

        }
}