hb-benchmark.hh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright © 2024 Google, Inc.
  3. *
  4. * This is part of HarfBuzz, a text shaping library.
  5. *
  6. * Permission is hereby granted, without written agreement and without
  7. * license or royalty fees, to use, copy, modify, and distribute this
  8. * software and its documentation for any purpose, provided that the
  9. * above copyright notice and the following two paragraphs appear in
  10. * all copies of this software.
  11. *
  12. * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
  13. * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  14. * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
  15. * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
  16. * DAMAGE.
  17. *
  18. * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
  19. * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  20. * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
  21. * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
  22. * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  23. *
  24. * Author(s): Behdad Esfahbod
  25. */
  26. #ifndef HB_BENCHMARK_HH
  27. #define HB_BENCHMARK_HH
  28. #include <hb-config.hh>
  29. #include <hb.h>
  30. #include <hb-subset.h>
  31. #include <hb-ot.h>
  32. #ifdef HAVE_FREETYPE
  33. #include <hb-ft.h>
  34. #endif
  35. #ifdef HAVE_CORETEXT
  36. #include <hb-coretext.h>
  37. #endif
  38. #include <benchmark/benchmark.h>
  39. #include <cassert>
  40. #include <cstdlib>
  41. #include <cstring>
  42. HB_BEGIN_DECLS
  43. static inline hb_face_t *
  44. hb_benchmark_face_create_from_file_or_fail (const char *font_path,
  45. unsigned face_index)
  46. {
  47. const char *loader = getenv ("HB_FACE_LOADER");
  48. if (loader && !*loader)
  49. loader = nullptr;
  50. #ifdef HAVE_FREETYPE
  51. if (loader && !strcmp (loader, "ft"))
  52. return hb_ft_face_create_from_file_or_fail (font_path, face_index);
  53. #endif
  54. #ifdef HAVE_CORETEXT
  55. if (loader && !strcmp (loader, "coretext"))
  56. return hb_coretext_face_create_from_file_or_fail (font_path, face_index);
  57. #endif
  58. if (!loader || !strcmp (loader, "ot"))
  59. return hb_face_create_from_file_or_fail (font_path, face_index);
  60. assert (false);
  61. }
  62. HB_END_DECLS
  63. #endif /* HB_BENCHMARK_HH */