gfx/harfbuzz/src/test-size-params.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/harfbuzz/src/test-size-params.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,96 @@
     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 +int
    1.47 +main (int argc, char **argv)
    1.48 +{
    1.49 +  hb_blob_t *blob = NULL;
    1.50 +
    1.51 +  if (argc != 2) {
    1.52 +    fprintf (stderr, "usage: %s font-file\n", argv[0]);
    1.53 +    exit (1);
    1.54 +  }
    1.55 +
    1.56 +  /* Create the blob */
    1.57 +  {
    1.58 +    const char *font_data;
    1.59 +    unsigned int len;
    1.60 +    hb_destroy_func_t destroy;
    1.61 +    void *user_data;
    1.62 +    hb_memory_mode_t mm;
    1.63 +
    1.64 +#ifdef HAVE_GLIB
    1.65 +    GMappedFile *mf = g_mapped_file_new (argv[1], false, NULL);
    1.66 +    font_data = g_mapped_file_get_contents (mf);
    1.67 +    len = g_mapped_file_get_length (mf);
    1.68 +    destroy = (hb_destroy_func_t) g_mapped_file_unref;
    1.69 +    user_data = (void *) mf;
    1.70 +    mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE;
    1.71 +#else
    1.72 +    FILE *f = fopen (argv[1], "rb");
    1.73 +    fseek (f, 0, SEEK_END);
    1.74 +    len = ftell (f);
    1.75 +    fseek (f, 0, SEEK_SET);
    1.76 +    font_data = (const char *) malloc (len);
    1.77 +    if (!font_data) len = 0;
    1.78 +    len = fread ((char *) font_data, 1, len, f);
    1.79 +    destroy = free;
    1.80 +    user_data = (void *) font_data;
    1.81 +    fclose (f);
    1.82 +    mm = HB_MEMORY_MODE_WRITABLE;
    1.83 +#endif
    1.84 +
    1.85 +    blob = hb_blob_create (font_data, len, mm, user_data, destroy);
    1.86 +  }
    1.87 +
    1.88 +  /* Create the face */
    1.89 +  hb_face_t *face = hb_face_create (blob, 0 /* first face */);
    1.90 +  hb_blob_destroy (blob);
    1.91 +  blob = NULL;
    1.92 +
    1.93 +  unsigned int p[5];
    1.94 +  bool ret = hb_ot_layout_get_size_params (face, p, p+1, p+2, p+3, p+4);
    1.95 +
    1.96 +  printf ("%g %u %u %g %g\n", p[0]/10., p[1], p[2], p[3]/10., p[4]/10.);
    1.97 +
    1.98 +  return !ret;
    1.99 +}

mercurial