Tgif Home
About Tgif
Current Release & Download
Copyright Info
A Screendump of Tgif
Release History
Tools That Tgif Uses
Tools That Work with Tgif
Author of Tgif
Miscellaneous Info
Return to Tgif's Home Page
William Chia-Wei Cheng

Tgif FAQ - Tgif File Format

(Polish version of this page)
Is the specification of tgif's obj/sym file format published anywhere?
The only ``specification'' of the tgif file (obj/sym) format is in a file called "" which is part of the tgif source distribution. This is not a Perl file; instead, it's a file containing Prolog code. If you know Prolog, it should be fairly easy to figure things out. If you don't know Prolog, below is a brief description on how to read "". The size of "" is big because it contains information about all versions of tgif objects. This also makes the description about file format a little big involved.

Notation, Notation, Notation...

Each tgif object is represented as a Prolog 'term' which has the form


where N is called the 'arity' of the term. Every top-level object is terminated with a period immediately after the term specifying the object. Another important construct is a Prolog 'list' which has the following form:


where K is the length of the list (which can be 0). Please note that an argument in a term can be a list.

Finally, a line that begins with % is a comment and variables in Prolog do not need to be declared. A name that begins with either a capitalized letter or a underscore character is a variable.

File Version...

The first line in a tgif file is a comment that contains the version information about the tgif that writes the file. The second line (which is the first object) in a tgif file is a state object (a term whose functor is state). The 2nd argument of the state term is called the file version of the file. Let's look at a sample file generated by tgif:

    %TGIF 2.16-p12
    % @(#)$Header: /mm2/home/william/cvs/bc-src/tgif/httpd/faq/RCS/format.html,v 1.5 2022/03/16 23:09:34 william Exp william $
    % %W%
            "Hello World"]).
(Actually, there's no wrap-around in the state line. It's wrapped around here so it's easier to read.)

The file version is 32. There are 3 top-level objects (including the state object) in the file above. You can tell that they are top-level objects because if you match the paranthesis immediately follow either the name state, page, or text, the closing paranthesis is immediately followed by a period.

Text Object Example...

Let's see how you can parse the text object using the information in "".

First, find the section in "" with clauses that start with tgif_text. The clauses that contain the string "FileVersion" are relevant. You will see that the first such clause contains the following line:

    FileVersion =< 2, !,
This means, use this clause for file versions 1 and 2. And the second such clause contains:
    FileVersion =< 6, !,
This means, use this clause for file versions 3 through 6; etc. For file version 32, you will find a clause that contains the following line:
    FileVersion =< 32, !,
In this case, this clause is for file version 30 through 32. And it looks like the following:
    tgif_text(Obj,Parms) :-
        FileVersion =< 32, !,
        % From version 30 on, the FontSize is the actual size;
        %    the TextSize in older versions is a size index.
        ( var(Obj) -> OutputObj = true ; OutputObj = false ),
        Obj = text(_Color,_X,_Y,_FontName,_TextStyle,_FontSize,_NumLines,
        Parms = [color=_Color,x=_X,y=_Y,font_name=_FontName,

The most important part of the above clause is:

        Obj = text(_Color,_X,_Y,_FontName,_TextStyle,_FontSize,_NumLines,
This is what you need to use to match against a text object in a tgif file. Recall from the above example:
            "Hello World"]).

It's not hard to see that _Color matches 'blue', _X matches 96, _Y matches 64, _FontName matches 'Times-Roman', ..., and finally, StrList matches ["Hello World"]. In this example, ["Hello World"] is a list contain a single term which is a string. (In Prolog, a string is a list of characters, but let's not get into that.)

Tabs and Line Breaks in a Tgif File...

In the above example, ["Hello World"] is broken up in the tgif file. the [ is followed by a line break and "Hello World"] is preceeded with a character. It's very important to note that the line break and the character are significant to the tgif parser (although they are ignored by a Prolog parser). The rules for them are somewhat difficult to explain. If you are generating a tgif file (either by hand or by code), please experiment with tgif with the objects you are trying to generate. Save the file and look at the file with a text editor and try to match the line breaks and tabs. And of couse, test it with tgif and check for missing objects after you've created your own tgif file.