Blame src/hb-shape.cc

Packit 874993
/*
Packit 874993
 * Copyright © 2009  Red Hat, Inc.
Packit 874993
 * Copyright © 2012  Google, Inc.
Packit 874993
 *
Packit 874993
 *  This is part of HarfBuzz, a text shaping library.
Packit 874993
 *
Packit 874993
 * Permission is hereby granted, without written agreement and without
Packit 874993
 * license or royalty fees, to use, copy, modify, and distribute this
Packit 874993
 * software and its documentation for any purpose, provided that the
Packit 874993
 * above copyright notice and the following two paragraphs appear in
Packit 874993
 * all copies of this software.
Packit 874993
 *
Packit 874993
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
Packit 874993
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
Packit 874993
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
Packit 874993
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
Packit 874993
 * DAMAGE.
Packit 874993
 *
Packit 874993
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
Packit 874993
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
Packit 874993
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
Packit 874993
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
Packit 874993
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
Packit 874993
 *
Packit 874993
 * Red Hat Author(s): Behdad Esfahbod
Packit 874993
 * Google Author(s): Behdad Esfahbod
Packit 874993
 */
Packit 874993
Packit 874993
#include "hb-private.hh"
Packit 874993
Packit 874993
#include "hb-shaper-private.hh"
Packit 874993
#include "hb-shape-plan-private.hh"
Packit 874993
#include "hb-buffer-private.hh"
Packit 874993
#include "hb-font-private.hh"
Packit 874993
Packit 874993
/**
Packit 874993
 * SECTION:hb-shape
Packit 874993
 * @title: Shaping
Packit 874993
 * @short_description: Conversion of text strings into positioned glyphs
Packit 874993
 * @include: hb.h
Packit 874993
 *
Packit 874993
 * Shaping is the central operation of HarfBuzz. Shaping operates on buffers,
Packit 874993
 * which are sequences of Unicode characters that use the same font and have
Packit 874993
 * the same text direction, script and language. After shaping the buffer
Packit 874993
 * contains the output glyphs and their positions.
Packit 874993
 **/
Packit 874993
Packit 874993
static const char **static_shaper_list;
Packit 874993
Packit 874993
#ifdef HB_USE_ATEXIT
Packit 874993
static
Packit 874993
void free_static_shaper_list (void)
Packit 874993
{
Packit 874993
  free (static_shaper_list);
Packit 874993
}
Packit 874993
#endif
Packit 874993
Packit 874993
/**
Packit 874993
 * hb_shape_list_shapers:
Packit 874993
 *
Packit 874993
 * Retrieves the list of shapers supported by HarfBuzz.
Packit 874993
 *
Packit 874993
 * Return value: (transfer none) (array zero-terminated=1): an array of
Packit 874993
 *    constant strings
Packit 874993
 *
Packit 874993
 * Since: 0.9.2
Packit 874993
 **/
Packit 874993
const char **
Packit 874993
hb_shape_list_shapers (void)
Packit 874993
{
Packit 874993
retry:
Packit 874993
  const char **shaper_list = (const char **) hb_atomic_ptr_get (&static_shaper_list);
Packit 874993
Packit 874993
  if (unlikely (!shaper_list))
Packit 874993
  {
Packit 874993
    /* Not found; allocate one. */
Packit 874993
    shaper_list = (const char **) calloc (1 + HB_SHAPERS_COUNT, sizeof (const char *));
Packit 874993
    if (unlikely (!shaper_list)) {
Packit 874993
      static const char *nil_shaper_list[] = {NULL};
Packit 874993
      return nil_shaper_list;
Packit 874993
    }
Packit 874993
Packit 874993
    const hb_shaper_pair_t *shapers = _hb_shapers_get ();
Packit 874993
    unsigned int i;
Packit 874993
    for (i = 0; i < HB_SHAPERS_COUNT; i++)
Packit 874993
      shaper_list[i] = shapers[i].name;
Packit 874993
    shaper_list[i] = NULL;
Packit 874993
Packit 874993
    if (!hb_atomic_ptr_cmpexch (&static_shaper_list, NULL, shaper_list)) {
Packit 874993
      free (shaper_list);
Packit 874993
      goto retry;
Packit 874993
    }
Packit 874993
Packit 874993
#ifdef HB_USE_ATEXIT
Packit 874993
    atexit (free_static_shaper_list); /* First person registers atexit() callback. */
Packit 874993
#endif
Packit 874993
  }
Packit 874993
Packit 874993
  return shaper_list;
Packit 874993
}
Packit 874993
Packit 874993
Packit 874993
/**
Packit 874993
 * hb_shape_full:
Packit 874993
 * @font: an #hb_font_t to use for shaping
Packit 874993
 * @buffer: an #hb_buffer_t to shape
Packit 874993
 * @features: (array length=num_features) (allow-none): an array of user
Packit 874993
 *    specified #hb_feature_t or %NULL
Packit 874993
 * @num_features: the length of @features array
Packit 874993
 * @shaper_list: (array zero-terminated=1) (allow-none): a %NULL-terminated
Packit 874993
 *    array of shapers to use or %NULL
Packit 874993
 *
Packit 874993
 * See hb_shape() for details. If @shaper_list is not %NULL, the specified
Packit 874993
 * shapers will be used in the given order, otherwise the default shapers list
Packit 874993
 * will be used.
Packit 874993
 *
Packit 874993
 * Return value: false if all shapers failed, true otherwise
Packit 874993
 *
Packit 874993
 * Since: 0.9.2
Packit 874993
 **/
Packit 874993
hb_bool_t
Packit 874993
hb_shape_full (hb_font_t          *font,
Packit 874993
	       hb_buffer_t        *buffer,
Packit 874993
	       const hb_feature_t *features,
Packit 874993
	       unsigned int        num_features,
Packit 874993
	       const char * const *shaper_list)
Packit 874993
{
Packit 874993
  hb_shape_plan_t *shape_plan = hb_shape_plan_create_cached2 (font->face, &buffer->props,
Packit 874993
							      features, num_features,
Packit 874993
							      font->coords, font->num_coords,
Packit 874993
							      shaper_list);
Packit 874993
  hb_bool_t res = hb_shape_plan_execute (shape_plan, font, buffer, features, num_features);
Packit 874993
  hb_shape_plan_destroy (shape_plan);
Packit 874993
Packit 874993
  if (res)
Packit 874993
    buffer->content_type = HB_BUFFER_CONTENT_TYPE_GLYPHS;
Packit 874993
  return res;
Packit 874993
}
Packit 874993
Packit 874993
/**
Packit 874993
 * hb_shape:
Packit 874993
 * @font: an #hb_font_t to use for shaping
Packit 874993
 * @buffer: an #hb_buffer_t to shape
Packit 874993
 * @features: (array length=num_features) (allow-none): an array of user
Packit 874993
 *    specified #hb_feature_t or %NULL
Packit 874993
 * @num_features: the length of @features array
Packit 874993
 *
Packit 874993
 * Shapes @buffer using @font turning its Unicode characters content to
Packit 874993
 * positioned glyphs. If @features is not %NULL, it will be used to control the
Packit 874993
 * features applied during shaping.
Packit 874993
 *
Packit 874993
 * Since: 0.9.2
Packit 874993
 **/
Packit 874993
void
Packit 874993
hb_shape (hb_font_t           *font,
Packit 874993
	  hb_buffer_t         *buffer,
Packit 874993
	  const hb_feature_t  *features,
Packit 874993
	  unsigned int         num_features)
Packit 874993
{
Packit 874993
  hb_shape_full (font, buffer, features, num_features, NULL);
Packit 874993
}