Blame src/main.cc

Packit 874993
/*
Packit 874993
 * Copyright © 2007,2008,2009  Red Hat, Inc.
Packit 874993
 *
Packit 874993
 *  This is part of HarfBuzz, a text shaping library.
Packit 874993
 *
Packit 874993
 * Permission is hereby granted, without written agreement and without
Packit 874993
 * license or royalty fees, to use, copy, modify, and distribute this
Packit 874993
 * software and its documentation for any purpose, provided that the
Packit 874993
 * above copyright notice and the following two paragraphs appear in
Packit 874993
 * all copies of this software.
Packit 874993
 *
Packit 874993
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
Packit 874993
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
Packit 874993
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
Packit 874993
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
Packit 874993
 * DAMAGE.
Packit 874993
 *
Packit 874993
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
Packit 874993
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
Packit 874993
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
Packit 874993
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
Packit 874993
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
Packit 874993
 *
Packit 874993
 * Red Hat Author(s): Behdad Esfahbod
Packit 874993
 */
Packit 874993
Packit 874993
#include "hb-mutex-private.hh"
Packit 874993
#include "hb-open-file-private.hh"
Packit 874993
#include "hb-ot-layout-gdef-table.hh"
Packit 874993
#include "hb-ot-layout-gsubgpos-private.hh"
Packit 874993
Packit 874993
#ifdef HAVE_GLIB
Packit 874993
#include <glib.h>
Packit 874993
#endif
Packit 874993
#include <stdlib.h>
Packit 874993
#include <stdio.h>
Packit 874993
Packit 874993
Packit 874993
using namespace OT;
Packit 874993
Packit 874993
Packit 874993
int
Packit 874993
main (int argc, char **argv)
Packit 874993
{
Packit 874993
  if (argc != 2) {
Packit 874993
    fprintf (stderr, "usage: %s font-file.ttf\n", argv[0]);
Packit 874993
    exit (1);
Packit 874993
  }
Packit 874993
Packit 874993
  const char *font_data = NULL;
Packit 874993
  int len = 0;
Packit 874993
Packit 874993
#ifdef HAVE_GLIB
Packit 874993
  GMappedFile *mf = g_mapped_file_new (argv[1], false, NULL);
Packit 874993
  font_data = g_mapped_file_get_contents (mf);
Packit 874993
  len = g_mapped_file_get_length (mf);
Packit 874993
#else
Packit 874993
  FILE *f = fopen (argv[1], "rb");
Packit 874993
  fseek (f, 0, SEEK_END);
Packit 874993
  len = ftell (f);
Packit 874993
  fseek (f, 0, SEEK_SET);
Packit 874993
  font_data = (const char *) malloc (len);
Packit 874993
  len = fread ((char *) font_data, 1, len, f);
Packit 874993
#endif
Packit 874993
Packit 874993
  printf ("Opened font file %s: %d bytes long\n", argv[1], len);
Packit 874993
Packit 874993
  const OpenTypeFontFile &ot = *CastP<OpenTypeFontFile> (font_data);
Packit 874993
Packit 874993
  switch (ot.get_tag ()) {
Packit 874993
  case OpenTypeFontFile::TrueTypeTag:
Packit 874993
    printf ("OpenType font with TrueType outlines\n");
Packit 874993
    break;
Packit 874993
  case OpenTypeFontFile::CFFTag:
Packit 874993
    printf ("OpenType font with CFF (Type1) outlines\n");
Packit 874993
    break;
Packit 874993
  case OpenTypeFontFile::TTCTag:
Packit 874993
    printf ("TrueType Collection of OpenType fonts\n");
Packit 874993
    break;
Packit 874993
  case OpenTypeFontFile::TrueTag:
Packit 874993
    printf ("Obsolete Apple TrueType font\n");
Packit 874993
    break;
Packit 874993
  case OpenTypeFontFile::Typ1Tag:
Packit 874993
    printf ("Obsolete Apple Type1 font in SFNT container\n");
Packit 874993
    break;
Packit 874993
  default:
Packit 874993
    printf ("Unknown font format\n");
Packit 874993
    break;
Packit 874993
  }
Packit 874993
Packit 874993
  int num_fonts = ot.get_face_count ();
Packit 874993
  printf ("%d font(s) found in file\n", num_fonts);
Packit 874993
  for (int n_font = 0; n_font < num_fonts; n_font++) {
Packit 874993
    const OpenTypeFontFace &font = ot.get_face (n_font);
Packit 874993
    printf ("Font %d of %d:\n", n_font, num_fonts);
Packit 874993
Packit 874993
    int num_tables = font.get_table_count ();
Packit 874993
    printf ("  %d table(s) found in font\n", num_tables);
Packit 874993
    for (int n_table = 0; n_table < num_tables; n_table++) {
Packit 874993
      const OpenTypeTable &table = font.get_table (n_table);
Packit 874993
      printf ("  Table %2d of %2d: %.4s (0x%08x+0x%08x)\n", n_table, num_tables,
Packit 874993
	      (const char *)table.tag,
Packit 874993
	      (unsigned int) table.offset,
Packit 874993
	      (unsigned int) table.length);
Packit 874993
Packit 874993
      switch (table.tag) {
Packit 874993
Packit 874993
      case GSUBGPOS::GSUBTag:
Packit 874993
      case GSUBGPOS::GPOSTag:
Packit 874993
	{
Packit 874993
Packit 874993
	const GSUBGPOS &g = *CastP<GSUBGPOS> (font_data + table.offset);
Packit 874993
Packit 874993
	int num_scripts = g.get_script_count ();
Packit 874993
	printf ("    %d script(s) found in table\n", num_scripts);
Packit 874993
	for (int n_script = 0; n_script < num_scripts; n_script++) {
Packit 874993
	  const Script &script = g.get_script (n_script);
Packit 874993
	  printf ("    Script %2d of %2d: %.4s\n", n_script, num_scripts,
Packit 874993
	          (const char *)g.get_script_tag(n_script));
Packit 874993
Packit 874993
	  if (!script.has_default_lang_sys())
Packit 874993
	    printf ("      No default language system\n");
Packit 874993
	  int num_langsys = script.get_lang_sys_count ();
Packit 874993
	  printf ("      %d language system(s) found in script\n", num_langsys);
Packit 874993
	  for (int n_langsys = script.has_default_lang_sys() ? -1 : 0; n_langsys < num_langsys; n_langsys++) {
Packit 874993
	    const LangSys &langsys = n_langsys == -1
Packit 874993
				   ? script.get_default_lang_sys ()
Packit 874993
				   : script.get_lang_sys (n_langsys);
Packit 874993
	    if (n_langsys == -1)
Packit 874993
	      printf ("      Default Language System\n");
Packit 874993
	    else
Packit 874993
	      printf ("      Language System %2d of %2d: %.4s\n", n_langsys, num_langsys,
Packit 874993
		      (const char *)script.get_lang_sys_tag (n_langsys));
Packit 874993
	    if (!langsys.has_required_feature ())
Packit 874993
	      printf ("        No required feature\n");
Packit 874993
	    else
Packit 874993
	      printf ("        Required feature index: %d\n",
Packit 874993
		      langsys.get_required_feature_index ());
Packit 874993
Packit 874993
	    int num_features = langsys.get_feature_count ();
Packit 874993
	    printf ("        %d feature(s) found in language system\n", num_features);
Packit 874993
	    for (int n_feature = 0; n_feature < num_features; n_feature++) {
Packit 874993
	      printf ("        Feature index %2d of %2d: %d\n", n_feature, num_features,
Packit 874993
	              langsys.get_feature_index (n_feature));
Packit 874993
	    }
Packit 874993
	  }
Packit 874993
	}
Packit 874993
Packit 874993
	int num_features = g.get_feature_count ();
Packit 874993
	printf ("    %d feature(s) found in table\n", num_features);
Packit 874993
	for (int n_feature = 0; n_feature < num_features; n_feature++) {
Packit 874993
	  const Feature &feature = g.get_feature (n_feature);
Packit 874993
	  int num_lookups = feature.get_lookup_count ();
Packit 874993
	  printf ("    Feature %2d of %2d: %c%c%c%c\n", n_feature, num_features,
Packit 874993
	          HB_UNTAG(g.get_feature_tag(n_feature)));
Packit 874993
Packit 874993
	  printf ("        %d lookup(s) found in feature\n", num_lookups);
Packit 874993
	  for (int n_lookup = 0; n_lookup < num_lookups; n_lookup++) {
Packit 874993
	    printf ("        Lookup index %2d of %2d: %d\n", n_lookup, num_lookups,
Packit 874993
	            feature.get_lookup_index (n_lookup));
Packit 874993
	  }
Packit 874993
	}
Packit 874993
Packit 874993
	int num_lookups = g.get_lookup_count ();
Packit 874993
	printf ("    %d lookup(s) found in table\n", num_lookups);
Packit 874993
	for (int n_lookup = 0; n_lookup < num_lookups; n_lookup++) {
Packit 874993
	  const Lookup &lookup = g.get_lookup (n_lookup);
Packit 874993
	  printf ("    Lookup %2d of %2d: type %d, props 0x%04X\n", n_lookup, num_lookups,
Packit 874993
	          lookup.get_type(), lookup.get_props());
Packit 874993
	}
Packit 874993
Packit 874993
	}
Packit 874993
	break;
Packit 874993
Packit 874993
      case GDEF::tableTag:
Packit 874993
	{
Packit 874993
Packit 874993
	const GDEF &gdef = *CastP<GDEF> (font_data + table.offset);
Packit 874993
Packit 874993
	printf ("    Has %sglyph classes\n",
Packit 874993
		  gdef.has_glyph_classes () ? "" : "no ");
Packit 874993
	printf ("    Has %smark attachment types\n",
Packit 874993
		  gdef.has_mark_attachment_types () ? "" : "no ");
Packit 874993
	printf ("    Has %sattach points\n",
Packit 874993
		  gdef.has_attach_points () ? "" : "no ");
Packit 874993
	printf ("    Has %slig carets\n",
Packit 874993
		  gdef.has_lig_carets () ? "" : "no ");
Packit 874993
	printf ("    Has %smark sets\n",
Packit 874993
		  gdef.has_mark_sets () ? "" : "no ");
Packit 874993
	break;
Packit 874993
	}
Packit 874993
      }
Packit 874993
    }
Packit 874993
  }
Packit 874993
Packit 874993
  return 0;
Packit 874993
}
Packit 874993
Packit 874993