hb-shape.cc 2.7 KB
Newer Older
B
Behdad Esfahbod 已提交
1
/*
B
Behdad Esfahbod 已提交
2
 * Copyright © 2009  Red Hat, Inc.
B
Behdad Esfahbod 已提交
3
 *
B
Behdad Esfahbod 已提交
4
 *  This is part of HarfBuzz, a text shaping library.
B
Behdad Esfahbod 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Red Hat Author(s): Behdad Esfahbod
 */

27
#include "hb-private.hh"
B
Behdad Esfahbod 已提交
28 29 30

#include "hb-shape.h"

31
#include "hb-buffer-private.hh"
B
Behdad Esfahbod 已提交
32

33
#include "hb-ot-shape.h"
B
Behdad Esfahbod 已提交
34

35 36 37
#ifdef HAVE_GRAPHITE
#include "hb-graphite.h"
#endif
B
Behdad Esfahbod 已提交
38

B
Behdad Esfahbod 已提交
39

B
Behdad Esfahbod 已提交
40

41
static void
B
Behdad Esfahbod 已提交
42 43 44 45
hb_shape_internal (hb_font_t          *font,
		   hb_buffer_t        *buffer,
		   const hb_feature_t *features,
		   unsigned int        num_features)
B
Behdad Esfahbod 已提交
46
{
47
  hb_ot_shape (font, buffer, features, num_features);
B
Behdad Esfahbod 已提交
48
}
B
Behdad Esfahbod 已提交
49

50
void
B
Behdad Esfahbod 已提交
51 52 53 54
hb_shape (hb_font_t          *font,
	  hb_buffer_t        *buffer,
	  const hb_feature_t *features,
	  unsigned int        num_features)
55 56 57 58 59 60 61
{
  hb_segment_properties_t orig_props;

  orig_props = buffer->props;

  /* If script is set to INVALID, guess from buffer contents */
  if (buffer->props.script == HB_SCRIPT_INVALID) {
62
    hb_unicode_funcs_t *unicode = buffer->unicode;
63 64
    unsigned int count = buffer->len;
    for (unsigned int i = 0; i < count; i++) {
65
      hb_script_t script = hb_unicode_script (unicode, buffer->info[i].codepoint);
66 67 68
      if (likely (script != HB_SCRIPT_COMMON &&
		  script != HB_SCRIPT_INHERITED &&
		  script != HB_SCRIPT_UNKNOWN)) {
69 70 71 72 73 74 75 76 77 78 79 80
        buffer->props.script = script;
        break;
      }
    }
  }

  /* If direction is set to INVALID, guess from script */
  if (buffer->props.direction == HB_DIRECTION_INVALID) {
    buffer->props.direction = hb_script_get_horizontal_direction (buffer->props.script);
  }

  /* If language is not set, use default language from locale */
B
Behdad Esfahbod 已提交
81
  if (buffer->props.language == HB_LANGUAGE_INVALID) {
82
    /* TODO get_default_for_script? using $LANGUAGE */
83
    buffer->props.language = hb_language_get_default ();
84 85
  }

86
  hb_shape_internal (font, buffer, features, num_features);
87 88 89 90

  buffer->props = orig_props;
}

B
Behdad Esfahbod 已提交
91