2018-10-16 07:53:40 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2018 Google, Inc.
|
|
|
|
*
|
|
|
|
* This is part of HarfBuzz, a text shaping 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.
|
|
|
|
*
|
|
|
|
* Google Author(s): Behdad Esfahbod
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hb.hh"
|
|
|
|
|
2019-06-18 22:11:41 +02:00
|
|
|
#ifndef HB_NO_NAME
|
|
|
|
|
2018-10-16 07:53:40 +02:00
|
|
|
#include "hb-ot-name-table.hh"
|
|
|
|
|
2018-10-16 08:32:08 +02:00
|
|
|
#include "hb-utf.hh"
|
2018-10-16 07:53:40 +02:00
|
|
|
|
|
|
|
|
2018-10-27 13:58:32 +02:00
|
|
|
/**
|
|
|
|
* SECTION:hb-ot-name
|
|
|
|
* @title: hb-ot-name
|
|
|
|
* @short_description: OpenType font name information
|
|
|
|
* @include: hb-ot.h
|
|
|
|
*
|
|
|
|
* Functions for fetching name strings from OpenType fonts.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2018-10-27 11:35:06 +02:00
|
|
|
/**
|
2018-10-27 11:39:20 +02:00
|
|
|
* hb_ot_name_list_names:
|
2018-10-27 11:35:06 +02:00
|
|
|
* @face: font face.
|
2020-12-30 23:28:27 +01:00
|
|
|
* @num_entries: (out) (optional): number of returned entries.
|
2018-10-27 11:35:06 +02:00
|
|
|
*
|
|
|
|
* Enumerates all available name IDs and language combinations. Returned
|
|
|
|
* array is owned by the @face and should not be modified. It can be
|
|
|
|
* used as long as @face is alive.
|
|
|
|
*
|
2022-02-12 23:00:01 +01:00
|
|
|
* Returns: (transfer none) (array length=num_entries): Array of available name entries.
|
2018-10-27 11:35:06 +02:00
|
|
|
* Since: 2.1.0
|
|
|
|
**/
|
2018-10-27 11:39:20 +02:00
|
|
|
const hb_ot_name_entry_t *
|
|
|
|
hb_ot_name_list_names (hb_face_t *face,
|
|
|
|
unsigned int *num_entries /* OUT */)
|
2018-10-16 07:53:40 +02:00
|
|
|
{
|
2018-11-06 04:58:43 +01:00
|
|
|
const OT::name_accelerator_t &name = *face->table.name;
|
2018-12-22 00:46:51 +01:00
|
|
|
if (num_entries) *num_entries = name.names.length;
|
2018-12-28 00:01:06 +01:00
|
|
|
return (const hb_ot_name_entry_t *) name.names;
|
2018-10-16 07:53:40 +02:00
|
|
|
}
|
2018-10-16 08:09:28 +02:00
|
|
|
|
2018-10-16 08:32:08 +02:00
|
|
|
template <typename utf_t>
|
2018-10-17 04:55:17 +02:00
|
|
|
static inline unsigned int
|
2018-10-30 22:04:09 +01:00
|
|
|
hb_ot_name_get_utf (hb_face_t *face,
|
|
|
|
hb_ot_name_id_t name_id,
|
|
|
|
hb_language_t language,
|
|
|
|
unsigned int *text_size /* IN/OUT */,
|
2018-10-16 08:32:08 +02:00
|
|
|
typename utf_t::codepoint_t *text /* OUT */)
|
2018-10-16 08:09:28 +02:00
|
|
|
{
|
2018-11-06 04:58:43 +01:00
|
|
|
const OT::name_accelerator_t &name = *face->table.name;
|
2018-10-17 14:42:23 +02:00
|
|
|
|
2018-10-25 22:43:25 +02:00
|
|
|
if (!language)
|
|
|
|
language = hb_language_from_string ("en", 2);
|
|
|
|
|
2018-10-24 05:51:53 +02:00
|
|
|
unsigned int width;
|
|
|
|
int idx = name.get_index (name_id, language, &width);
|
2018-10-24 05:30:40 +02:00
|
|
|
if (idx != -1)
|
|
|
|
{
|
2018-10-24 08:16:06 +02:00
|
|
|
hb_bytes_t bytes = name.get_name (idx);
|
2018-10-24 05:30:40 +02:00
|
|
|
|
2018-10-24 05:51:53 +02:00
|
|
|
if (width == 2) /* UTF16-BE */
|
2022-10-28 19:44:48 +02:00
|
|
|
return OT::hb_ot_name_convert_utf<hb_utf16_be_t, utf_t> (bytes, text_size, text);
|
2018-10-24 05:51:53 +02:00
|
|
|
|
|
|
|
if (width == 1) /* ASCII */
|
2022-10-28 19:44:48 +02:00
|
|
|
return OT::hb_ot_name_convert_utf<hb_ascii_t, utf_t> (bytes, text_size, text);
|
2018-10-24 05:30:40 +02:00
|
|
|
}
|
2018-10-17 14:42:23 +02:00
|
|
|
|
2018-10-24 05:04:05 +02:00
|
|
|
if (text_size)
|
2018-10-16 08:09:28 +02:00
|
|
|
{
|
2018-10-24 05:04:05 +02:00
|
|
|
if (*text_size)
|
|
|
|
*text = 0;
|
|
|
|
*text_size = 0;
|
2018-10-16 08:09:28 +02:00
|
|
|
}
|
2018-10-24 05:04:05 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2018-10-17 14:42:23 +02:00
|
|
|
|
2018-10-27 11:35:06 +02:00
|
|
|
/**
|
|
|
|
* hb_ot_name_get_utf8:
|
|
|
|
* @face: font face.
|
|
|
|
* @name_id: OpenType name identifier to fetch.
|
|
|
|
* @language: language to fetch the name for.
|
2020-12-30 23:28:27 +01:00
|
|
|
* @text_size: (inout) (optional): input size of @text buffer, and output size of
|
2018-10-27 11:35:06 +02:00
|
|
|
* text written to buffer.
|
|
|
|
* @text: (out caller-allocates) (array length=text_size): buffer to write fetched name into.
|
|
|
|
*
|
|
|
|
* Fetches a font name from the OpenType 'name' table.
|
|
|
|
* If @language is #HB_LANGUAGE_INVALID, English ("en") is assumed.
|
2021-09-01 14:38:01 +02:00
|
|
|
* Returns string in UTF-8 encoding. A NUL terminator is always written
|
|
|
|
* for convenience, and isn't included in the output @text_size.
|
2018-10-27 11:35:06 +02:00
|
|
|
*
|
|
|
|
* Returns: full length of the requested string, or 0 if not found.
|
|
|
|
* Since: 2.1.0
|
|
|
|
**/
|
2018-10-24 05:04:05 +02:00
|
|
|
unsigned int
|
2018-10-30 22:04:09 +01:00
|
|
|
hb_ot_name_get_utf8 (hb_face_t *face,
|
|
|
|
hb_ot_name_id_t name_id,
|
|
|
|
hb_language_t language,
|
|
|
|
unsigned int *text_size /* IN/OUT */,
|
|
|
|
char *text /* OUT */)
|
2018-10-24 05:04:05 +02:00
|
|
|
{
|
|
|
|
return hb_ot_name_get_utf<hb_utf8_t> (face, name_id, language, text_size,
|
|
|
|
(hb_utf8_t::codepoint_t *) text);
|
2018-10-16 08:09:28 +02:00
|
|
|
}
|
2018-10-16 08:32:08 +02:00
|
|
|
|
2018-10-27 11:35:06 +02:00
|
|
|
/**
|
|
|
|
* hb_ot_name_get_utf16:
|
|
|
|
* @face: font face.
|
|
|
|
* @name_id: OpenType name identifier to fetch.
|
|
|
|
* @language: language to fetch the name for.
|
2020-12-30 23:28:27 +01:00
|
|
|
* @text_size: (inout) (optional): input size of @text buffer, and output size of
|
2018-10-27 11:35:06 +02:00
|
|
|
* text written to buffer.
|
|
|
|
* @text: (out caller-allocates) (array length=text_size): buffer to write fetched name into.
|
|
|
|
*
|
|
|
|
* Fetches a font name from the OpenType 'name' table.
|
|
|
|
* If @language is #HB_LANGUAGE_INVALID, English ("en") is assumed.
|
2021-09-01 14:38:01 +02:00
|
|
|
* Returns string in UTF-16 encoding. A NUL terminator is always written
|
|
|
|
* for convenience, and isn't included in the output @text_size.
|
2018-10-27 11:35:06 +02:00
|
|
|
*
|
|
|
|
* Returns: full length of the requested string, or 0 if not found.
|
|
|
|
* Since: 2.1.0
|
|
|
|
**/
|
2018-10-17 04:55:17 +02:00
|
|
|
unsigned int
|
2018-10-30 22:04:09 +01:00
|
|
|
hb_ot_name_get_utf16 (hb_face_t *face,
|
|
|
|
hb_ot_name_id_t name_id,
|
|
|
|
hb_language_t language,
|
|
|
|
unsigned int *text_size /* IN/OUT */,
|
|
|
|
uint16_t *text /* OUT */)
|
2018-10-16 08:32:08 +02:00
|
|
|
{
|
|
|
|
return hb_ot_name_get_utf<hb_utf16_t> (face, name_id, language, text_size, text);
|
|
|
|
}
|
2018-10-24 05:04:05 +02:00
|
|
|
|
2018-10-27 11:35:06 +02:00
|
|
|
/**
|
|
|
|
* hb_ot_name_get_utf32:
|
|
|
|
* @face: font face.
|
|
|
|
* @name_id: OpenType name identifier to fetch.
|
|
|
|
* @language: language to fetch the name for.
|
2020-12-30 23:28:27 +01:00
|
|
|
* @text_size: (inout) (optional): input size of @text buffer, and output size of
|
2018-10-27 11:35:06 +02:00
|
|
|
* text written to buffer.
|
|
|
|
* @text: (out caller-allocates) (array length=text_size): buffer to write fetched name into.
|
|
|
|
*
|
|
|
|
* Fetches a font name from the OpenType 'name' table.
|
|
|
|
* If @language is #HB_LANGUAGE_INVALID, English ("en") is assumed.
|
2021-09-01 14:38:01 +02:00
|
|
|
* Returns string in UTF-32 encoding. A NUL terminator is always written
|
|
|
|
* for convenience, and isn't included in the output @text_size.
|
2018-10-27 11:35:06 +02:00
|
|
|
*
|
|
|
|
* Returns: full length of the requested string, or 0 if not found.
|
|
|
|
* Since: 2.1.0
|
|
|
|
**/
|
2018-10-24 05:04:05 +02:00
|
|
|
unsigned int
|
2018-10-30 22:04:09 +01:00
|
|
|
hb_ot_name_get_utf32 (hb_face_t *face,
|
|
|
|
hb_ot_name_id_t name_id,
|
|
|
|
hb_language_t language,
|
|
|
|
unsigned int *text_size /* IN/OUT */,
|
|
|
|
uint32_t *text /* OUT */)
|
2018-10-24 05:04:05 +02:00
|
|
|
{
|
|
|
|
return hb_ot_name_get_utf<hb_utf32_t> (face, name_id, language, text_size, text);
|
|
|
|
}
|
2019-06-18 22:11:41 +02:00
|
|
|
|
|
|
|
#endif
|