1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/harfbuzz/src/test-would-substitute.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,106 @@ 1.4 +/* 1.5 + * Copyright © 2010,2011 Google, 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 + * Google Author(s): Behdad Esfahbod 1.28 + */ 1.29 + 1.30 +#ifdef HAVE_CONFIG_H 1.31 +#include "config.h" 1.32 +#endif 1.33 + 1.34 +#include "hb.h" 1.35 +#include "hb-ot.h" 1.36 + 1.37 +#ifdef HAVE_GLIB 1.38 +# include <glib.h> 1.39 +# if !GLIB_CHECK_VERSION (2, 22, 0) 1.40 +# define g_mapped_file_unref g_mapped_file_free 1.41 +# endif 1.42 +#endif 1.43 +#include <stdlib.h> 1.44 +#include <stdio.h> 1.45 + 1.46 +#ifdef HAVE_FREETYPE 1.47 +#include "hb-ft.h" 1.48 +#endif 1.49 + 1.50 +int 1.51 +main (int argc, char **argv) 1.52 +{ 1.53 + hb_blob_t *blob = NULL; 1.54 + 1.55 + if (argc != 4 && argc != 5) { 1.56 + fprintf (stderr, "usage: %s font-file lookup-index first-glyph [second-glyph]\n", argv[0]); 1.57 + exit (1); 1.58 + } 1.59 + 1.60 + /* Create the blob */ 1.61 + { 1.62 + const char *font_data; 1.63 + unsigned int len; 1.64 + hb_destroy_func_t destroy; 1.65 + void *user_data; 1.66 + hb_memory_mode_t mm; 1.67 + 1.68 +#ifdef HAVE_GLIB 1.69 + GMappedFile *mf = g_mapped_file_new (argv[1], false, NULL); 1.70 + font_data = g_mapped_file_get_contents (mf); 1.71 + len = g_mapped_file_get_length (mf); 1.72 + destroy = (hb_destroy_func_t) g_mapped_file_unref; 1.73 + user_data = (void *) mf; 1.74 + mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE; 1.75 +#else 1.76 + FILE *f = fopen (argv[1], "rb"); 1.77 + fseek (f, 0, SEEK_END); 1.78 + len = ftell (f); 1.79 + fseek (f, 0, SEEK_SET); 1.80 + font_data = (const char *) malloc (len); 1.81 + if (!font_data) len = 0; 1.82 + len = fread ((char *) font_data, 1, len, f); 1.83 + destroy = free; 1.84 + user_data = (void *) font_data; 1.85 + fclose (f); 1.86 + mm = HB_MEMORY_MODE_WRITABLE; 1.87 +#endif 1.88 + 1.89 + blob = hb_blob_create (font_data, len, mm, user_data, destroy); 1.90 + } 1.91 + 1.92 + /* Create the face */ 1.93 + hb_face_t *face = hb_face_create (blob, 0 /* first face */); 1.94 + hb_blob_destroy (blob); 1.95 + blob = NULL; 1.96 + 1.97 + hb_font_t *font = hb_font_create (face); 1.98 +#ifdef HAVE_FREETYPE 1.99 + hb_ft_font_set_funcs (font); 1.100 +#endif 1.101 + 1.102 + unsigned int len = argc - 3; 1.103 + hb_codepoint_t glyphs[2]; 1.104 + if (!hb_font_glyph_from_string (font, argv[3], -1, &glyphs[0]) || 1.105 + (argc > 4 && 1.106 + !hb_font_glyph_from_string (font, argv[4], -1, &glyphs[1]))) 1.107 + return 2; 1.108 + return !hb_ot_layout_lookup_would_substitute (face, strtol (argv[2], NULL, 0), glyphs, len, false); 1.109 +}