lout-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using fonts with Lout


From: Valeriy E. Ushakov
Subject: Using fonts with Lout
Date: Wed, 20 Oct 1999 18:51:26 +0400

[Thanks for the reminder, Hanus]

NB: I only discuss the PostScript case.  PDF font embedding is a
different matter and, alas, is not currently implemented in Lout.

Ok, so you have that Fooney-Regular font that you want to use in your
Lout document(s).  How to proceed?  It's really simple, simpler than
it might seem.

* Bits and pieces

    You will need two files for each font.

    . AFM - Adobe Font Metrics

      This is the only file that Lout needs.  As name suggests, this
      file describes metrics of the font, e.g. glyph size, ligatures,
      kerning &c.

      AFM is documented in Adobe's Tech Note #5004, "Adobe Font
      Metrics File Format Specification".

      In PC land Type1 metrics are usually in PFM (Printer Metrics
      Format).  I don't know of any good convertor from PFM to AFM.
      The one at CTAN, from afm2pfm package, is little-endian specific
      and assumes that unaligned data are ok, and so requires quite a
      bit of work to use on a big-endian RISC system (e.g. sparc).

      Fortunately, font vendors provide metrics in both AFM and PFM,
      so this should not be a problem.

      PFM format is documented in documentation for Microsoft
      Windows3.x DDK.


    . PFA - Printer Format ASCII

      This is the actual Type1 font program for the font.

      You need font in PFA format to embed it into your document or to
      download it to the printer.

      In PC land Type1 fonts are usually in PFB (Printer Format
      Binary) format.  Use pfbtops(1) from groff distribution or
      t1ascii(1) from t1utils distribution to convert PFB to PFA.

      GhostScript can use both PFA and PFB (PFB takes less space), but
      since you will need PFA anyway, it's simpler to use PFA
      throughout.


* Printer resident fonts (a short digression)

    If you are not going to distribute your document and only going to
    print it locally, you can configure your printing software so that
    it knows about your font.   If you take this option, you will be
    able to print your document without embedding the font, since the
    font will be already available to your PostScript interpreter.

    For GhostScript you simply put your font (PFA or PFB) into
    GhostScript `fonts' directory and add an entry to GhostScript
    Fontmap file.  If you use GhostScript for previewing and printing
    (e.g. on a non-PS printer), then you are done, your font is
    printer (i.e. GhostScript) resident.

    If you print on a PostScript printer, you will need to download
    the font to printer.  See Adobe's Tech Note #5040, "Supporting
    Downloadable PostScript Language Fonts".


* Making font known to Lout.

    . Where to put AFM

      As I've said, Lout only need an AFM file for the font.  You have
      to put the AFM somewhere where Lout can find it.  Lout looks for
      fonts in the $LOUTLIB/font and directories specified with -F
      option (e.g. "-F .").


    . Which LCM to use

      Then you have to decide which encoding you will use with this
      font.  If this is something unusual you will have to write an
      LCM (Lout Character Mapping) file for the encoding you want to
      use, but people predominantly want to use standard text fonts so
      one of existing LCM's will do, e.g. LtLatin1.LCM or LtLatin2.LCM
      &c.  See $LOUTLIB/maps, where Lout looks for LCM files.


    . Writing a "fontdef" statement for the font

      The "fontdef" statement is used to declare the font.  You can
      put fontdef anywhere you can put a definition, e.g. in your
      mydefs.lt file or before the @Include of your document setup.

      Invocation of fontdef is documented in the Expert's Guide.  See
      also comments in $LOUTLIB/include/fontdefs.

      For your Fooney-Regular font a fontdef might look like this:

          fontdef Fooney Base {
              Fooney-Regular            # font name, see FontName in the AFM
              Fooney-Regular.AFM        # AFM file
              LtLatin1.LCM              # LCM file
              Recode                    # Recode (or NoRecode if you
                                        #         know what you're doing)
          }

      Here "fontdef Fooney Base" declares Lout's "Base" face of
      family "Fooney".  The name "Base" is a matter of convention,
      standard setups use "Base" to denote the regular, or roman or
      upright or whatever-the-base-face-is-called.

      See $LOUTLIB/include/fontdefs for examples of how complete
      families are defined.  You just repeat the same steps for all
      the fonts in the family, only using "Slope" (i.e. italic) "Bold"
      and "BoldSlope" instead of "Base".


    . That's it!

      Well, I told you it's simple.  After this simple steps you can
      use the Fooney Base font in your documents.  Lout knows all the
      bits it needs to format them.


* Embedding fonts in PS documents

    . A little bit of internals

      PostScript is a fully blown *programming* language.  A well
      behaved PostScript *document* should obey some restrictions and
      follow some conventions to ease the processing of the PostScript
      *program* as the *document*.

      E.g. for previewer to be able to display an arbitrary page in
      the document all the pages in the document must be independent
      from others, this is called page independence and MS PostScript
      drivers are infamous for violating it.  Page independence is also
      important for doing impositions, like printing n-up or
      reordering pages into reverse order or making books signatures.

      This is what DSC (Document Structuring Conventions) is for.
      DSC is documented in Appendix G of the PSRM2 (PostScript
      Reference Manual, 2nd edition).  Recently published PSRM3 don't
      have this appendix and refers instead to Adobe Tech Note #5001,
      "PostScript Language Document Structuring Conventions
      Specification".

      Lout follows DSC quite strictly, see file notes.dsc in the Lout
      source distribution.


    . Polemic digression

      For each font that Lout encounters it emits an appropriate
      %%IncludeResource DSC comment.  Since Lout generates PS output
      in one pass, it will emit %%IncludeResource comments for the
      fonts, used by the first page of your Lout document, in the PS
      document setup section.  For fonts used by other pages Lout will
      emit %%IncludeResource comments in the PS page setup section.
      Given the one-pass approach, it's the best Lout can do.

      In fact it's arguable (and I have already discussed this on the
      list) that this approach is even better then placing all the
      %%IncludeResource comments into PS document setup section.

      I would even dare to insist on emitting them in the page setup
      section even for the first page as well.

      The logic behind this is simple.  When resource comments are
      confined to their respective pages, document management system
      (whatever it is, e.g. you or your spooler) has *exact*
      information about resource usage on a page per page basis.

      When you embed fonts into your PS document and print it, you
      might will to trade bigger (a lot bigger ;-) file size for
      reduced printer memory consumption, especially if you use lots
      of fonts and have a printer with small memory.

      For the first page, it's natural to imagine a situation where
      you use a lot of accidental fonts on your book title page and
      never use any of them further in your document.  With current
      strategy all this fonts will end up in the document setup and
      will clutter printer's memory while your whole document is
      printed.  So moving them into page setup for the first page will
      treat them uniformly.  Also, you will need to reorder resource
      comments anyway if you prefer smaller file size, so having fonts
      for the first page in the document setup doesn't really buys you
      much.

      Also, if you select only a subset of pages from your document
      (e.g. for printing on both sides using non-duplex printer), the
      first page can be omitted from the selection and thus its fonts
      (in document setup section) will be completely a waste.

      So I propose to treat the first page uniformly and put resource
      comments for it into its page setup section, like we do for all
      subsequent pages.


    . Including resources

      PSUtils distribution includes a simple perl script,
      includeres(1), that processes DSC conformant PS document and
      replaces %%IncludeResource comments with actual resources,
      making your document self-contained.

      In a nutshell, includeres(1) looks for a file which name is the
      name of the included resource and replaces the %%IncludeResource
      line with the contents of the file.

      It looks for these files in a specific directory, typically
      /usr/local/share/psutils.

      So for your Fooney-Regular font you just create in this
      directory a symbolic link to the PFA file for the font.
      E.g.

          $ cd /usr/local/share/psutils
          $ ln -s ../ghostscript/fonts/fooreg.pfa Fooney-Regular

      Note that no .pfa suffix should be used.  includeres(1) looks for
      literal resource names.  So for

          %%IncludeResource: font Fooney-Regular

      it will look for /usr/local/share/psutils/Fooney-Regular

      After you have created all the symlinks (or simply put the files
      in there) you can

          $ includeres < myloutdoc.ps | lp
          $ includeres < myloutdoc.ps > ~/public_html/myloutdoc.ps



    . Why is it so big?

      As I have already explained, Lout will write resource comments
      into page setup section of each page.  So if you use
      Fooney-Regular on many pages, includeres(1) will include a copy
      of the PFA file in every page the font is used on.  If the PFA
      file is about 100K and you have 100 pages that use this font,
      the output from includeres(1) will be, well, huge.

      This might be what you want, if you want to keep printer memory
      consumption low.  But if you want to publish the document on the
      web site or send it to you friend, this is not appropriate.

      The solution is to reorder resource comments to make all
      references to font resources appear in the document setup.
      I'm not aware of any tool that does this, but anyone with some
      perl skills should be able to write it in an hour or so.

      Suppose the script is called reorderres(1), then you can do:

          $ lout -o mydoc.ps mydoc.lt
          $ psselect -o mydoc.ps | includeres | lp
          $ psselect -e mydoc.ps | includeres | lp
          # Compact document with fonts included once in the document setup
          $ reorderres mydoc.ps | includeres > ~/public_html/mydoc.ps

Hope this helps.

SY, Uwe
-- 
address@hidden                         |       Zu Grunde kommen
http://www.ptc.spbu.ru/~uwe/            |       Ist zu Grunde gehen


reply via email to

[Prev in Thread] Current Thread [Next in Thread]