QtBase  v6.3.1
hb-ot-name.cc
Go to the documentation of this file.
1 /*
2  * Copyright © 2018 Google, Inc.
3  *
4  * This is part of HarfBuzz, a text shaping library.
5  *
6  * Permission is hereby granted, without written agreement and without
7  * license or royalty fees, to use, copy, modify, and distribute this
8  * software and its documentation for any purpose, provided that the
9  * above copyright notice and the following two paragraphs appear in
10  * all copies of this software.
11  *
12  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16  * DAMAGE.
17  *
18  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23  *
24  * Google Author(s): Behdad Esfahbod
25  */
26 
27 #include "hb.hh"
28 
29 #ifndef HB_NO_NAME
30 
31 #include "hb-ot-name-table.hh"
32 
33 #include "hb-utf.hh"
34 
35 
58 const hb_ot_name_entry_t *
60  unsigned int *num_entries /* OUT */)
61 {
62  const OT::name_accelerator_t &name = *face->table.name;
63  if (num_entries) *num_entries = name.names.length;
64  return (const hb_ot_name_entry_t *) name.names;
65 }
66 
67 
68 template <typename in_utf_t, typename out_utf_t>
69 static inline unsigned int
70 hb_ot_name_convert_utf (hb_bytes_t bytes,
71  unsigned int *text_size /* IN/OUT */,
72  typename out_utf_t::codepoint_t *text /* OUT */)
73 {
74  unsigned int src_len = bytes.length / sizeof (typename in_utf_t::codepoint_t);
75  const typename in_utf_t::codepoint_t *src = (const typename in_utf_t::codepoint_t *) bytes.arrayZ;
76  const typename in_utf_t::codepoint_t *src_end = src + src_len;
77 
78  typename out_utf_t::codepoint_t *dst = text;
79 
80  hb_codepoint_t unicode;
82 
83  if (text_size && *text_size)
84  {
85  (*text_size)--; /* Same room for NUL-termination. */
86  const typename out_utf_t::codepoint_t *dst_end = text + *text_size;
87 
88  while (src < src_end && dst < dst_end)
89  {
90  const typename in_utf_t::codepoint_t *src_next = in_utf_t::next (src, src_end, &unicode, replacement);
91  typename out_utf_t::codepoint_t *dst_next = out_utf_t::encode (dst, dst_end, unicode);
92  if (dst_next == dst)
93  break; /* Out-of-room. */
94 
95  dst = dst_next;
96  src = src_next;
97  }
98 
99  *text_size = dst - text;
100  *dst = 0; /* NUL-terminate. */
101  }
102 
103  /* Accumulate length of rest. */
104  unsigned int dst_len = dst - text;
105  while (src < src_end)
106  {
107  src = in_utf_t::next (src, src_end, &unicode, replacement);
108  dst_len += out_utf_t::encode_len (unicode);
109  }
110  return dst_len;
111 }
112 
113 template <typename utf_t>
114 static inline unsigned int
115 hb_ot_name_get_utf (hb_face_t *face,
116  hb_ot_name_id_t name_id,
118  unsigned int *text_size /* IN/OUT */,
119  typename utf_t::codepoint_t *text /* OUT */)
120 {
121  const OT::name_accelerator_t &name = *face->table.name;
122 
123  if (!language)
124  language = hb_language_from_string ("en", 2);
125 
126  unsigned int width;
127  int idx = name.get_index (name_id, language, &width);
128  if (idx != -1)
129  {
130  hb_bytes_t bytes = name.get_name (idx);
131 
132  if (width == 2) /* UTF16-BE */
133  return hb_ot_name_convert_utf<hb_utf16_be_t, utf_t> (bytes, text_size, text);
134 
135  if (width == 1) /* ASCII */
136  return hb_ot_name_convert_utf<hb_ascii_t, utf_t> (bytes, text_size, text);
137  }
138 
139  if (text_size)
140  {
141  if (*text_size)
142  *text = 0;
143  *text_size = 0;
144  }
145  return 0;
146 }
147 
165 unsigned int
167  hb_ot_name_id_t name_id,
169  unsigned int *text_size /* IN/OUT */,
170  char *text /* OUT */)
171 {
172  return hb_ot_name_get_utf<hb_utf8_t> (face, name_id, language, text_size,
174 }
175 
193 unsigned int
195  hb_ot_name_id_t name_id,
197  unsigned int *text_size /* IN/OUT */,
198  uint16_t *text /* OUT */)
199 {
200  return hb_ot_name_get_utf<hb_utf16_t> (face, name_id, language, text_size, text);
201 }
202 
220 unsigned int
222  hb_ot_name_id_t name_id,
224  unsigned int *text_size /* IN/OUT */,
225  uint32_t *text /* OUT */)
226 {
227  return hb_ot_name_get_utf<hb_utf32_t> (face, name_id, language, text_size, text);
228 }
229 
230 
231 #endif
FT_UInt idx
Definition: cffcmap.c:135
QString text
[meta data]
hb_language_t hb_language_from_string(const char *str, int len)
Definition: hb-common.cc:371
const hb_ot_name_entry_t * hb_ot_name_list_names(hb_face_t *face, unsigned int *num_entries)
Definition: hb-ot-name.cc:59
unsigned int hb_ot_name_get_utf8(hb_face_t *face, hb_ot_name_id_t name_id, hb_language_t language, unsigned int *text_size, char *text)
Definition: hb-ot-name.cc:166
unsigned int hb_ot_name_get_utf16(hb_face_t *face, hb_ot_name_id_t name_id, hb_language_t language, unsigned int *text_size, uint16_t *text)
Definition: hb-ot-name.cc:194
unsigned int hb_ot_name_get_utf32(hb_face_t *face, hb_ot_name_id_t name_id, hb_language_t language, unsigned int *text_size, uint32_t *text)
Definition: hb-ot-name.cc:221
unsigned int hb_ot_name_id_t
Definition: hb-ot-name.h:109
short next
Definition: keywords.cpp:454
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
[3]
GLenum face
GLenum src
GLint GLsizei width
GLenum GLenum dst
GLuint name
#define encode(x)
Definition: qurlquery.cpp:244
#define HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT
Definition: hb-buffer.h:449
uint32_t hb_codepoint_t
Definition: hb-common.h:106
hb_blob_ptr_t< name > table
Type * arrayZ
Definition: hb-array.hh:290
unsigned int length
Definition: hb-array.hh:291
Definition: hb-ot-name.h:121
uint8_t codepoint_t
Definition: hb-utf.hh:37