1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/harfbuzz/src/main.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,197 @@ 1.4 +/* 1.5 + * Copyright © 2007,2008,2009 Red Hat, Inc. 1.6 + * 1.7 + * This is part of HarfBuzz, a text shaping library. 1.8 + * 1.9 + * Permission is hereby granted, without written agreement and without 1.10 + * license or royalty fees, to use, copy, modify, and distribute this 1.11 + * software and its documentation for any purpose, provided that the 1.12 + * above copyright notice and the following two paragraphs appear in 1.13 + * all copies of this software. 1.14 + * 1.15 + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 1.16 + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 1.17 + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 1.18 + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 1.19 + * DAMAGE. 1.20 + * 1.21 + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 1.22 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 1.23 + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 1.24 + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 1.25 + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 1.26 + * 1.27 + * Red Hat Author(s): Behdad Esfahbod 1.28 + */ 1.29 + 1.30 +#include "hb-mutex-private.hh" 1.31 +#include "hb-open-file-private.hh" 1.32 +#include "hb-ot-layout-gdef-table.hh" 1.33 +#include "hb-ot-layout-gsubgpos-private.hh" 1.34 + 1.35 +#ifdef HAVE_GLIB 1.36 +#include <glib.h> 1.37 +#endif 1.38 +#include <stdlib.h> 1.39 +#include <stdio.h> 1.40 + 1.41 + 1.42 +using namespace OT; 1.43 + 1.44 + 1.45 +int 1.46 +main (int argc, char **argv) 1.47 +{ 1.48 + if (argc != 2) { 1.49 + fprintf (stderr, "usage: %s font-file.ttf\n", argv[0]); 1.50 + exit (1); 1.51 + } 1.52 + 1.53 + const char *font_data = NULL; 1.54 + int len = 0; 1.55 + 1.56 +#ifdef HAVE_GLIB 1.57 + GMappedFile *mf = g_mapped_file_new (argv[1], false, NULL); 1.58 + font_data = g_mapped_file_get_contents (mf); 1.59 + len = g_mapped_file_get_length (mf); 1.60 +#else 1.61 + FILE *f = fopen (argv[1], "rb"); 1.62 + fseek (f, 0, SEEK_END); 1.63 + len = ftell (f); 1.64 + fseek (f, 0, SEEK_SET); 1.65 + font_data = (const char *) malloc (len); 1.66 + len = fread ((char *) font_data, 1, len, f); 1.67 +#endif 1.68 + 1.69 + printf ("Opened font file %s: %d bytes long\n", argv[1], len); 1.70 + 1.71 + const OpenTypeFontFile &ot = *CastP<OpenTypeFontFile> (font_data); 1.72 + 1.73 + switch (ot.get_tag ()) { 1.74 + case OpenTypeFontFile::TrueTypeTag: 1.75 + printf ("OpenType font with TrueType outlines\n"); 1.76 + break; 1.77 + case OpenTypeFontFile::CFFTag: 1.78 + printf ("OpenType font with CFF (Type1) outlines\n"); 1.79 + break; 1.80 + case OpenTypeFontFile::TTCTag: 1.81 + printf ("TrueType Collection of OpenType fonts\n"); 1.82 + break; 1.83 + case OpenTypeFontFile::TrueTag: 1.84 + printf ("Obsolete Apple TrueType font\n"); 1.85 + break; 1.86 + case OpenTypeFontFile::Typ1Tag: 1.87 + printf ("Obsolete Apple Type1 font in SFNT container\n"); 1.88 + break; 1.89 + default: 1.90 + printf ("Unknown font format\n"); 1.91 + break; 1.92 + } 1.93 + 1.94 + int num_fonts = ot.get_face_count (); 1.95 + printf ("%d font(s) found in file\n", num_fonts); 1.96 + for (int n_font = 0; n_font < num_fonts; n_font++) { 1.97 + const OpenTypeFontFace &font = ot.get_face (n_font); 1.98 + printf ("Font %d of %d:\n", n_font, num_fonts); 1.99 + 1.100 + int num_tables = font.get_table_count (); 1.101 + printf (" %d table(s) found in font\n", num_tables); 1.102 + for (int n_table = 0; n_table < num_tables; n_table++) { 1.103 + const OpenTypeTable &table = font.get_table (n_table); 1.104 + printf (" Table %2d of %2d: %.4s (0x%08x+0x%08x)\n", n_table, num_tables, 1.105 + (const char *)table.tag, 1.106 + (unsigned int) table.offset, 1.107 + (unsigned int) table.length); 1.108 + 1.109 + switch (table.tag) { 1.110 + 1.111 + case GSUBGPOS::GSUBTag: 1.112 + case GSUBGPOS::GPOSTag: 1.113 + { 1.114 + 1.115 + const GSUBGPOS &g = *CastP<GSUBGPOS> (font_data + table.offset); 1.116 + 1.117 + int num_scripts = g.get_script_count (); 1.118 + printf (" %d script(s) found in table\n", num_scripts); 1.119 + for (int n_script = 0; n_script < num_scripts; n_script++) { 1.120 + const Script &script = g.get_script (n_script); 1.121 + printf (" Script %2d of %2d: %.4s\n", n_script, num_scripts, 1.122 + (const char *)g.get_script_tag(n_script)); 1.123 + 1.124 + if (!script.has_default_lang_sys()) 1.125 + printf (" No default language system\n"); 1.126 + int num_langsys = script.get_lang_sys_count (); 1.127 + printf (" %d language system(s) found in script\n", num_langsys); 1.128 + for (int n_langsys = script.has_default_lang_sys() ? -1 : 0; n_langsys < num_langsys; n_langsys++) { 1.129 + const LangSys &langsys = n_langsys == -1 1.130 + ? script.get_default_lang_sys () 1.131 + : script.get_lang_sys (n_langsys); 1.132 + if (n_langsys == -1) 1.133 + printf (" Default Language System\n"); 1.134 + else 1.135 + printf (" Language System %2d of %2d: %.4s\n", n_langsys, num_langsys, 1.136 + (const char *)script.get_lang_sys_tag (n_langsys)); 1.137 + if (langsys.get_required_feature_index () == Index::NOT_FOUND_INDEX) 1.138 + printf (" No required feature\n"); 1.139 + 1.140 + int num_features = langsys.get_feature_count (); 1.141 + printf (" %d feature(s) found in language system\n", num_features); 1.142 + for (int n_feature = 0; n_feature < num_features; n_feature++) { 1.143 + printf (" Feature index %2d of %2d: %d\n", n_feature, num_features, 1.144 + langsys.get_feature_index (n_feature)); 1.145 + } 1.146 + } 1.147 + } 1.148 + 1.149 + int num_features = g.get_feature_count (); 1.150 + printf (" %d feature(s) found in table\n", num_features); 1.151 + for (int n_feature = 0; n_feature < num_features; n_feature++) { 1.152 + const Feature &feature = g.get_feature (n_feature); 1.153 + printf (" Feature %2d of %2d: %.4s; %d lookup(s)\n", n_feature, num_features, 1.154 + (const char *)g.get_feature_tag(n_feature), 1.155 + feature.get_lookup_count()); 1.156 + 1.157 + int num_lookups = feature.get_lookup_count (); 1.158 + printf (" %d lookup(s) found in feature\n", num_lookups); 1.159 + for (int n_lookup = 0; n_lookup < num_lookups; n_lookup++) { 1.160 + printf (" Lookup index %2d of %2d: %d\n", n_lookup, num_lookups, 1.161 + feature.get_lookup_index (n_lookup)); 1.162 + } 1.163 + } 1.164 + 1.165 + int num_lookups = g.get_lookup_count (); 1.166 + printf (" %d lookup(s) found in table\n", num_lookups); 1.167 + for (int n_lookup = 0; n_lookup < num_lookups; n_lookup++) { 1.168 + const Lookup &lookup = g.get_lookup (n_lookup); 1.169 + printf (" Lookup %2d of %2d: type %d, props 0x%04X\n", n_lookup, num_lookups, 1.170 + lookup.get_type(), lookup.get_props()); 1.171 + } 1.172 + 1.173 + } 1.174 + break; 1.175 + 1.176 + case GDEF::tableTag: 1.177 + { 1.178 + 1.179 + const GDEF &gdef = *CastP<GDEF> (font_data + table.offset); 1.180 + 1.181 + printf (" Has %sglyph classes\n", 1.182 + gdef.has_glyph_classes () ? "" : "no "); 1.183 + printf (" Has %smark attachment types\n", 1.184 + gdef.has_mark_attachment_types () ? "" : "no "); 1.185 + printf (" Has %sattach points\n", 1.186 + gdef.has_attach_points () ? "" : "no "); 1.187 + printf (" Has %slig carets\n", 1.188 + gdef.has_lig_carets () ? "" : "no "); 1.189 + printf (" Has %smark sets\n", 1.190 + gdef.has_mark_sets () ? "" : "no "); 1.191 + break; 1.192 + } 1.193 + } 1.194 + } 1.195 + } 1.196 + 1.197 + return 0; 1.198 +} 1.199 + 1.200 +