Back to index

texmacs  1.0.7.15
Functions
tt_aux.h File Reference
#include "pdfobj.h"
#include "sfnt.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

ULONG ttc_read_offset (sfnt *sfont, int ttc_idx)
pdf_objtt_get_fontdesc (sfnt *sfont, int *embed, int stemv, int type)

Function Documentation

pdf_obj* tt_get_fontdesc ( sfnt sfont,
int *  embed,
int  stemv,
int  type 
)

Definition at line 132 of file tt_aux.c.

{
  pdf_obj *descriptor = NULL;
  pdf_obj *bbox = NULL;
  int flag = SYMBOLIC;
  /* TrueType tables */
  struct tt_head_table *head;
  struct tt_os2__table *os2;
  struct tt_post_table *post;

  if (!sfont) {
    ERROR("font file not opened");
  }

  os2  = tt_read_os2__table(sfont);
  head = tt_read_head_table(sfont);
  post = tt_read_post_table(sfont);
  if (!post) {
    RELEASE(os2);
    RELEASE(head);
    return NULL;
  }

  descriptor = pdf_new_dict();
  pdf_add_dict (descriptor,
              pdf_new_name ("Type"),
              pdf_new_name ("FontDescriptor"));

  if (*embed) {
    /*
      License:

       "Preview & Print embedding" (0x004) requires the document containing
       Preview & Print font to be opened in read-only mode. However, licensing
       information are lost when fonts are embedded in PDF document and
       the only way to make the PDF document "read-only" is to encrypt it.
       But we have no support for encryption yet. We do not embed any fonts
       with "Preview & Print embedding" setting.

       2001/11/22: Changed to allow `Preview & Print' only fonts embedding
    */
    if (os2->fsType == 0x0000 || (os2->fsType & 0x0008)) {
      /* the least restrictive license granted takes precedence. */
      *embed = 1;
    } else if (os2->fsType & 0x0004) {
      fprintf(stderr,
              "\n** NOTICE: This document contains `Preview & Print' only");
      fprintf(stderr, " licensed font **\n");
      *embed = 1;
    } else {
      fprintf(stderr,
              "\n*** Embedding disabled due to licensing restriction ***\n");
      *embed = 0;
    }
  }

  pdf_add_dict (descriptor,
              pdf_new_name ("Ascent"),
              pdf_new_number (PDFUNIT(os2->sTypoAscender)));
  pdf_add_dict (descriptor,
              pdf_new_name ("Descent"),
              pdf_new_number (PDFUNIT(os2->sTypoDescender)));
  if (stemv < 0) /* if not given by the option '-v' */
    stemv = (os2->usWeightClass/65.)*(os2->usWeightClass/65.)+50;
  pdf_add_dict (descriptor,
              pdf_new_name ("StemV"),
              pdf_new_number (stemv));
  if (os2->version == 0x0002) {
    pdf_add_dict (descriptor,
                pdf_new_name("CapHeight"),
                pdf_new_number(PDFUNIT(os2->sCapHeight))
                );
    /* optional */
    pdf_add_dict (descriptor,
                pdf_new_name("XHeight"),
                pdf_new_number(PDFUNIT(os2->sxHeight))
                );
  } else { /* arbitrary */
    pdf_add_dict (descriptor,
                pdf_new_name("CapHeight"),
                pdf_new_number(PDFUNIT(os2->sTypoAscender))
                );
  }
  /* optional */
  if (os2->xAvgCharWidth != 0) {
    pdf_add_dict (descriptor,
                pdf_new_name ("AvgWidth"),
                pdf_new_number (PDFUNIT(os2->xAvgCharWidth)));
  }

  /* BoundingBox (array) */
  bbox = pdf_new_array ();
  pdf_add_array (bbox, pdf_new_number (PDFUNIT(head->xMin)));
  pdf_add_array (bbox, pdf_new_number (PDFUNIT(head->yMin)));
  pdf_add_array (bbox, pdf_new_number (PDFUNIT(head->xMax)));
  pdf_add_array (bbox, pdf_new_number (PDFUNIT(head->yMax)));
  pdf_add_dict (descriptor, pdf_new_name ("FontBBox"), bbox);

  /* post */
  pdf_add_dict (descriptor,
              pdf_new_name ("ItalicAngle"),
              pdf_new_number(fixed(post->italicAngle)));

  /* Flags */
  if (os2->fsSelection & (1 << 0))
    flag |= ITALIC;
  if (os2->fsSelection & (1 << 5))
    flag |= FORCEBOLD;
  if (((os2->sFamilyClass >> 8) & 0xff) != 8)
    flag |= SERIF;
  if (((os2->sFamilyClass >> 8) & 0xff) == 10)
    flag |= SCRIPT;
  if (post->isFixedPitch)
    flag |= FIXEDWIDTH;

  pdf_add_dict (descriptor,
              pdf_new_name ("Flags"),
              pdf_new_number (flag));

  /* insert panose if you want */
  if (type == 0) { /* cid-keyed font - add panose */
    pdf_obj *styledict = NULL;
    unsigned char panose[12];
    
    panose[0] = os2->sFamilyClass >> 8;
    panose[1] = os2->sFamilyClass & 0xff;
    memcpy(panose+2, os2->panose, 10);

    styledict = pdf_new_dict ();
    pdf_add_dict (styledict, pdf_new_name ("Panose"),
                pdf_new_string (panose, 12));
    pdf_add_dict (descriptor, pdf_new_name ("Style"), styledict);
  }

  RELEASE(head);
  RELEASE(os2);
  tt_release_post_table(post);

  return descriptor;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ULONG ttc_read_offset ( sfnt sfont,
int  ttc_idx 
)

Definition at line 39 of file tt_aux.c.

{
  LONG version;
  ULONG offset = 0, num_dirs = 0;
  
  if (sfont == NULL || sfont->stream == NULL)
    ERROR("file not opened");

  if (sfont->type != SFNT_TYPE_TTC)
    ERROR("ttc_read_offset(): invalid font type");

  sfnt_seek_set (sfont, 4); /* skip version tag */

  version = sfnt_get_ulong(sfont);
  num_dirs = sfnt_get_ulong(sfont);
  if (ttc_idx < 0 || ttc_idx > num_dirs - 1)
    ERROR("Invalid TTC index number");

  sfnt_seek_set (sfont, 12 + ttc_idx * 4);
  offset = sfnt_get_ulong (sfont);

  return offset;
}

Here is the caller graph for this function: