1 | /* Pango |
2 | * pango-ot-tag.h: |
3 | * |
4 | * Copyright (C) 2007 Red Hat Software |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Library General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2 of the License, or (at your option) any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Library General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Library General Public |
17 | * License along with this library; if not, write to the |
18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | * Boston, MA 02111-1307, USA. |
20 | */ |
21 | |
22 | #include "config.h" |
23 | |
24 | #include "pango-ot-private.h" |
25 | |
26 | /** |
27 | * pango_ot_tag_from_script: |
28 | * @script: A `PangoScript` |
29 | * |
30 | * Finds the OpenType script tag corresponding to @script. |
31 | * |
32 | * The %PANGO_SCRIPT_COMMON, %PANGO_SCRIPT_INHERITED, and |
33 | * %PANGO_SCRIPT_UNKNOWN scripts are mapped to the OpenType |
34 | * 'DFLT' script tag that is also defined as |
35 | * %PANGO_OT_TAG_DEFAULT_SCRIPT. |
36 | * |
37 | * Note that multiple `PangoScript` values may map to the same |
38 | * OpenType script tag. In particular, %PANGO_SCRIPT_HIRAGANA |
39 | * and %PANGO_SCRIPT_KATAKANA both map to the OT tag 'kana'. |
40 | * |
41 | * Return value: `PangoOTTag` corresponding to @script or |
42 | * %PANGO_OT_TAG_DEFAULT_SCRIPT if none found. |
43 | * |
44 | * Since: 1.18 |
45 | **/ |
46 | PangoOTTag |
47 | pango_ot_tag_from_script (PangoScript script) |
48 | { |
49 | unsigned int count = 1; |
50 | hb_tag_t tags[1]; |
51 | |
52 | hb_ot_tags_from_script_and_language (script: (hb_script_t) g_unicode_script_to_iso15924 (script: (GUnicodeScript) script), |
53 | HB_LANGUAGE_INVALID, |
54 | script_count: &count, |
55 | script_tags: tags, |
56 | NULL, NULL); |
57 | if (count > 0) |
58 | return (PangoOTTag) tags[0]; |
59 | |
60 | return PANGO_OT_TAG_DEFAULT_SCRIPT; |
61 | } |
62 | |
63 | /** |
64 | * pango_ot_tag_to_script: |
65 | * @script_tag: A `PangoOTTag` OpenType script tag |
66 | * |
67 | * Finds the `PangoScript` corresponding to @script_tag. |
68 | * |
69 | * The 'DFLT' script tag is mapped to %PANGO_SCRIPT_COMMON. |
70 | * |
71 | * Note that an OpenType script tag may correspond to multiple |
72 | * `PangoScript` values. In such cases, the `PangoScript` value |
73 | * with the smallest value is returned. |
74 | * In particular, %PANGO_SCRIPT_HIRAGANA |
75 | * and %PANGO_SCRIPT_KATAKANA both map to the OT tag 'kana'. |
76 | * This function will return %PANGO_SCRIPT_HIRAGANA for |
77 | * 'kana'. |
78 | * |
79 | * Return value: `PangoScript` corresponding to @script_tag or |
80 | * %PANGO_SCRIPT_UNKNOWN if none found. |
81 | * |
82 | * Since: 1.18 |
83 | **/ |
84 | PangoScript |
85 | pango_ot_tag_to_script (PangoOTTag script_tag) |
86 | { |
87 | return (PangoScript) g_unicode_script_from_iso15924 (iso15924: hb_ot_tag_to_script (tag: (hb_tag_t) script_tag)); |
88 | } |
89 | |
90 | |
91 | /** |
92 | * pango_ot_tag_from_language: |
93 | * @language: (nullable): A `PangoLanguage` |
94 | * |
95 | * Finds the OpenType language-system tag best describing @language. |
96 | * |
97 | * Return value: `PangoOTTag` best matching @language or |
98 | * %PANGO_OT_TAG_DEFAULT_LANGUAGE if none found or if @language |
99 | * is %NULL. |
100 | * |
101 | * Since: 1.18 |
102 | **/ |
103 | PangoOTTag |
104 | pango_ot_tag_from_language (PangoLanguage *language) |
105 | { |
106 | unsigned int count = 1; |
107 | hb_tag_t tags[1]; |
108 | |
109 | hb_ot_tags_from_script_and_language (script: HB_SCRIPT_UNKNOWN, |
110 | language: hb_language_from_string (pango_language_to_string (language), len: -1), |
111 | NULL, NULL, |
112 | language_count: &count, language_tags: tags); |
113 | |
114 | if (count > 0) |
115 | return (PangoOTTag) tags[0]; |
116 | |
117 | return PANGO_OT_TAG_DEFAULT_LANGUAGE; |
118 | } |
119 | |
120 | /** |
121 | * pango_ot_tag_to_language: |
122 | * @language_tag: A `PangoOTTag` OpenType language-system tag |
123 | * |
124 | * Finds a `PangoLanguage` corresponding to @language_tag. |
125 | * |
126 | * Return value: `PangoLanguage` best matching @language_tag or |
127 | * `PangoLanguage` corresponding to the string "xx" if none found. |
128 | * |
129 | * Since: 1.18 |
130 | **/ |
131 | PangoLanguage * |
132 | pango_ot_tag_to_language (PangoOTTag language_tag) |
133 | { |
134 | return pango_language_from_string (language: hb_language_to_string (language: hb_ot_tag_to_language (tag: (hb_tag_t) language_tag))); |
135 | } |
136 | |