提交 8a3511ac 编写于 作者: B Behdad Esfahbod

Add hb_language_t as well as language/script conversion to OT tags

上级 4591753a
......@@ -18,6 +18,7 @@ HBSOURCES = \
hb-object-private.h \
hb-open-file-private.hh \
hb-open-type-private.hh \
hb-language.c \
hb-private.h \
hb-shape.c \
hb-unicode.c \
......@@ -29,6 +30,7 @@ HBHEADERS = \
hb-buffer.h \
hb-common.h \
hb-font.h \
hb-language.h \
hb-shape.h \
hb-unicode.h \
$(NULL)
......@@ -41,10 +43,12 @@ HBSOURCES += \
hb-ot-layout-gsubgpos-private.hh \
hb-ot-layout-gsub-private.hh \
hb-ot-layout-private.h \
hb-ot-tag.c \
$(NULL)
HBHEADERS += \
hb-ot.h \
hb-ot-layout.h \
hb-ot-tag.h \
$(NULL)
if HAVE_GLIB
......
/*
* Copyright (C) 2009 Red Hat, Inc.
*
* This is part of HarfBuzz, an OpenType Layout engine library.
*
* 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
*/
#include "hb-private.h"
#include "hb-language.h"
static const char canon_map[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', 0, 0,
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 0, 0, 0, 0, 0, 0,
'-', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0, 0, 0, 0, '-',
0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0, 0, 0, 0, 0
};
static hb_bool_t
lang_equal (const void *v1,
const void *v2)
{
const unsigned char *p1 = v1;
const unsigned char *p2 = v2;
while (canon_map[*p1] && canon_map[*p1] == canon_map[*p2])
{
p1++, p2++;
}
return (canon_map[*p1] == canon_map[*p2]);
}
#if 0
static unsigned int
lang_hash (const void *key)
{
const unsigned char *p = key;
unsigned int h = 0;
while (canon_map[*p])
{
h = (h << 5) - h + canon_map[*p];
p++;
}
return h;
}
#endif
hb_language_t
hb_language_from_string (const char *str)
{
static unsigned int num_langs;
static unsigned int num_alloced;
static const char **langs;
unsigned int i;
unsigned char *p;
/* TODO Use a hash table or something */
if (!str)
return NULL;
for (i = 0; i < num_langs; i++)
if (lang_equal (str, langs[i]))
return langs[i];
if (HB_UNLIKELY (num_langs == num_alloced)) {
unsigned int new_alloced = 2 * (8 + num_alloced);
const char **new_langs = realloc (langs, new_alloced * sizeof (langs[0]));
if (!new_langs)
return NULL;
num_alloced = new_alloced;
langs = new_langs;
}
langs[i] = strdup (str);
for (p = (unsigned char *) langs[i]; *p; p++)
*p = canon_map[*p];
return (hb_language_t) langs[i];
}
const char *
hb_language_to_string (hb_language_t language)
{
return (const char *) language;
}
/*
* Copyright (C) 2009 Red Hat, Inc.
*
* This is part of HarfBuzz, an OpenType Layout engine library.
*
* 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
*/
#ifndef HB_LANGUAGE_H
#define HB_LANGUAGE_H
#include "hb-common.h"
HB_BEGIN_DECLS
typedef const void *hb_language_t;
hb_language_t
hb_language_from_string (const char *str);
const char *
hb_language_to_string (hb_language_t language);
HB_END_DECLS
#endif /* HB_LANGUAGE_H */
......@@ -366,11 +366,11 @@ hb_ot_layout_table_find_script (hb_face_t *face,
return TRUE;
/* try finding 'DFLT' */
if (g.find_script_index (HB_OT_LAYOUT_TAG_DEFAULT_SCRIPT, script_index))
if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index))
return FALSE;
/* try with 'dflt'; MS site has had typos and many fonts use it now :( */
if (g.find_script_index (HB_OT_LAYOUT_TAG_DEFAULT_LANGUAGE, script_index))
if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index))
return FALSE;
if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX;
......@@ -417,7 +417,7 @@ hb_ot_layout_script_find_language (hb_face_t *face,
return TRUE;
/* try with 'dflt'; MS site has had typos and many fonts use it now :( */
if (s.find_lang_sys_index (HB_OT_LAYOUT_TAG_DEFAULT_LANGUAGE, language_index))
if (s.find_lang_sys_index (HB_OT_TAG_DEFAULT_LANGUAGE, language_index))
return FALSE;
if (language_index) *language_index = HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX;
......
......@@ -31,6 +31,8 @@
#include "hb-buffer.h"
#include "hb-font.h"
#include "hb-ot-tag.h"
HB_BEGIN_DECLS
#define HB_OT_TAG_GDEF HB_TAG('G','D','E','F')
......@@ -97,8 +99,6 @@ hb_ot_layout_get_lig_carets (hb_face_t *face,
#define HB_OT_LAYOUT_NO_SCRIPT_INDEX ((unsigned int) 0xFFFF)
#define HB_OT_LAYOUT_NO_FEATURE_INDEX ((unsigned int) 0xFFFF)
#define HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX ((unsigned int) 0xFFFF)
#define HB_OT_LAYOUT_TAG_DEFAULT_SCRIPT HB_TAG ('D', 'F', 'L', 'T')
#define HB_OT_LAYOUT_TAG_DEFAULT_LANGUAGE HB_TAG ('d', 'f', 'l', 't')
unsigned int
hb_ot_layout_table_get_script_tags (hb_face_t *face,
......
此差异已折叠。
/*
* Copyright (C) 2009 Red Hat, Inc.
*
* This is part of HarfBuzz, an OpenType Layout engine library.
*
* 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
*/
#ifndef HB_OT_TAG_H
#define HB_OT_TAG_H
#include "hb-common.h"
#include "hb-language.h"
HB_BEGIN_DECLS
#define HB_OT_TAG_DEFAULT_SCRIPT HB_TAG ('D', 'F', 'L', 'T')
#define HB_OT_TAG_DEFAULT_LANGUAGE HB_TAG ('d', 'f', 'l', 't')
const hb_tag_t *
hb_ot_tags_from_script (hb_script_t script);
hb_tag_t
hb_ot_tag_from_language (hb_language_t language);
hb_language_t
hb_ot_tag_to_language (hb_tag_t tag);
HB_END_DECLS
#endif /* HB_OT_TAG_H */
......@@ -30,5 +30,6 @@
#include "hb.h"
#include "hb-ot-layout.h"
#include "hb-ot-tag.h"
#endif /* HB_OT_H */
......@@ -119,6 +119,9 @@ typedef int hb_mutex_t;
#undef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#undef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#ifndef HB_INTERNAL
# define HB_INTERNAL extern
#endif
......
......@@ -31,6 +31,7 @@
#include "hb-buffer.h"
#include "hb-common.h"
#include "hb-font.h"
#include "hb-language.h"
#include "hb-shape.h"
#include "hb-unicode.h"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册