tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ft-hb-ft.c (3311B)


      1 /*
      2 * Copyright © 2009, 2023  Red Hat, Inc.
      3 * Copyright © 2015  Google, Inc.
      4 *
      5 * Permission is hereby granted, without written agreement and without
      6 * license or royalty fees, to use, copy, modify, and distribute this
      7 * software and its documentation for any purpose, provided that the
      8 * above copyright notice and the following two paragraphs appear in
      9 * all copies of this software.
     10 *
     11 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
     12 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
     13 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
     14 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
     15 * DAMAGE.
     16 *
     17 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
     18 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
     19 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
     20 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
     21 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
     22 *
     23 * Red Hat Author(s): Behdad Esfahbod, Matthias Clasen
     24 * Google Author(s): Behdad Esfahbod
     25 */
     26 
     27 #include <freetype/freetype.h>
     28 #include <freetype/tttables.h>
     29 
     30 #ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
     31 
     32 #include "ft-hb-ft.h"
     33 
     34 /* The following three functions are a more or less verbatim
     35 * copy of corresponding HarfBuzz code from hb-ft.cc
     36 */
     37 
     38 static hb_blob_t *
     39 ft_hb_ft_reference_table (hb_face_t *face, hb_tag_t tag, void *user_data)
     40 {
     41  AF_FaceGlobals globals = (AF_FaceGlobals) user_data;
     42 
     43  FT_Face ft_face = globals->face;
     44  FT_Byte *buffer;
     45  FT_ULong  length = 0;
     46  FT_Error error;
     47 
     48  FT_UNUSED (face);
     49 
     50  /* Note: FreeType like HarfBuzz uses the NONE tag for fetching the entire blob */
     51 
     52  error = FT_Load_Sfnt_Table (ft_face, tag, 0, NULL, &length);
     53  if (error)
     54    return NULL;
     55 
     56  buffer = (FT_Byte *) ft_smalloc (length);
     57  if (!buffer)
     58    return NULL;
     59 
     60  error = FT_Load_Sfnt_Table (ft_face, tag, 0, buffer, &length);
     61  if (error)
     62  {
     63    free (buffer);
     64    return NULL;
     65  }
     66 
     67  return hb(blob_create) ((const char *) buffer, length,
     68                          HB_MEMORY_MODE_WRITABLE,
     69                          buffer, ft_sfree);
     70 }
     71 
     72 static hb_face_t *
     73 ft_hb_ft_face_create (AF_FaceGlobals globals)
     74 {
     75  FT_Face ft_face = globals->face;
     76 
     77  hb_face_t *face;
     78 
     79  if (!ft_face->stream->read) {
     80    hb_blob_t *blob;
     81 
     82    blob = hb(blob_create) ((const char *) ft_face->stream->base,
     83                            (unsigned int) ft_face->stream->size,
     84                            HB_MEMORY_MODE_READONLY,
     85                            ft_face, NULL);
     86    face = hb(face_create) (blob, ft_face->face_index);
     87    hb(blob_destroy) (blob);
     88  } else {
     89    face = hb(face_create_for_tables) (ft_hb_ft_reference_table, globals, NULL);
     90  }
     91 
     92  hb(face_set_index) (face, ft_face->face_index);
     93  hb(face_set_upem) (face, ft_face->units_per_EM);
     94 
     95  return face;
     96 }
     97 
     98 FT_LOCAL_DEF(hb_font_t *)
     99 ft_hb_ft_font_create (AF_FaceGlobals globals)
    100 {
    101  hb_font_t *font;
    102  hb_face_t *face;
    103 
    104  face = ft_hb_ft_face_create (globals);
    105  font = hb(font_create) (face);
    106  hb(face_destroy) (face);
    107  return font;
    108 }
    109 
    110 #else /* !FT_CONFIG_OPTION_USE_HARFBUZZ */
    111 
    112 /* ANSI C doesn't like empty source files */
    113 typedef int  ft_hb_ft_dummy_;
    114 
    115 #endif /* !FT_CONFIG_OPTION_USE_HARFBUZZ */
    116 
    117 /* END */