2016-04-25 18:20:57 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2016 Google, Inc.
|
2018-02-27 20:26:17 +01:00
|
|
|
* Copyright © 2018 Ebrahim Byagowi
|
2016-04-25 18:20:57 +02:00
|
|
|
*
|
|
|
|
* 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): Sascha Brawer
|
|
|
|
*/
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb-open-type.hh"
|
2018-03-03 20:13:23 +01:00
|
|
|
#include "hb-ot-color-colr-table.hh"
|
|
|
|
#include "hb-ot-color-cpal-table.hh"
|
2018-05-01 17:16:46 +02:00
|
|
|
#include "hb-ot-face.hh"
|
2016-04-25 18:20:57 +02:00
|
|
|
#include "hb-ot.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb-ot-layout.hh"
|
2016-04-25 18:20:57 +02:00
|
|
|
|
|
|
|
|
2018-02-28 10:49:40 +01:00
|
|
|
static inline const OT::COLR&
|
|
|
|
_get_colr (hb_face_t *face)
|
|
|
|
{
|
2018-05-08 11:23:36 +02:00
|
|
|
if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::COLR);
|
2018-05-01 17:16:46 +02:00
|
|
|
return *(hb_ot_face_data (face)->COLR.get ());
|
2018-02-28 10:49:40 +01:00
|
|
|
}
|
|
|
|
|
2016-04-25 18:20:57 +02:00
|
|
|
static inline const OT::CPAL&
|
|
|
|
_get_cpal (hb_face_t *face)
|
|
|
|
{
|
2018-05-08 11:23:36 +02:00
|
|
|
if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::CPAL);
|
2018-05-01 17:16:46 +02:00
|
|
|
return *(hb_ot_face_data (face)->CPAL.get ());
|
2016-04-25 18:20:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-21 06:56:40 +02:00
|
|
|
* hb_ot_color_has_cpal_data:
|
2016-04-25 18:20:57 +02:00
|
|
|
* @face: a font face.
|
|
|
|
*
|
|
|
|
* Returns: the number of color palettes in @face, or zero if @face has
|
|
|
|
* no colors.
|
|
|
|
*
|
2018-02-27 20:26:17 +01:00
|
|
|
* Since: REPLACEME
|
2016-04-25 18:20:57 +02:00
|
|
|
*/
|
2018-10-21 06:56:40 +02:00
|
|
|
hb_bool_t
|
|
|
|
hb_ot_color_has_cpal_data (hb_face_t *face)
|
2016-04-25 18:20:57 +02:00
|
|
|
{
|
2018-10-21 06:56:40 +02:00
|
|
|
return &_get_cpal (face) != &Null(OT::CPAL);
|
2016-04-25 18:20:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-21 06:56:40 +02:00
|
|
|
* hb_ot_color_has_colr_data:
|
2016-04-25 18:20:57 +02:00
|
|
|
* @face: a font face.
|
|
|
|
*
|
2018-10-21 06:56:40 +02:00
|
|
|
* Returns: whether COLR table available
|
2016-04-25 18:20:57 +02:00
|
|
|
*
|
2018-10-21 06:56:40 +02:00
|
|
|
* Since: REPLACEME
|
2016-04-25 18:20:57 +02:00
|
|
|
*/
|
2018-10-21 06:56:40 +02:00
|
|
|
hb_bool_t
|
|
|
|
hb_ot_color_has_colr_data (hb_face_t *face)
|
2016-04-25 18:20:57 +02:00
|
|
|
{
|
2018-10-21 06:56:40 +02:00
|
|
|
return &_get_colr (face) != &Null(OT::COLR);
|
2016-04-25 18:20:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-21 06:56:40 +02:00
|
|
|
* hb_ot_color_get_palette_count:
|
|
|
|
* @face: a font face.
|
2016-04-25 18:20:57 +02:00
|
|
|
*
|
2018-10-21 06:56:40 +02:00
|
|
|
* Returns: whether CPAL table available
|
2016-04-25 18:20:57 +02:00
|
|
|
*
|
2018-10-21 06:56:40 +02:00
|
|
|
* Since: REPLACEME
|
2016-04-25 18:20:57 +02:00
|
|
|
*/
|
2018-10-21 06:56:40 +02:00
|
|
|
unsigned int
|
|
|
|
hb_ot_color_get_palette_count (hb_face_t *face)
|
2016-04-25 18:20:57 +02:00
|
|
|
{
|
2018-10-21 06:56:40 +02:00
|
|
|
return _get_cpal (face).get_palette_count ();
|
2016-04-25 18:20:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hb_ot_color_get_palette_colors:
|
|
|
|
* @face: a font face.
|
|
|
|
* @palette: the index of the color palette whose colors
|
|
|
|
* are being requested.
|
|
|
|
* @start_offset: the index of the first color being requested.
|
|
|
|
* @color_count: (inout) (optional): on input, how many colors
|
|
|
|
* can be maximally stored into the @colors array;
|
|
|
|
* on output, how many colors were actually stored.
|
2018-05-01 17:16:46 +02:00
|
|
|
* @colors: (array length=color_count) (out) (optional):
|
2018-10-21 06:56:40 +02:00
|
|
|
* an array of #hb_color_t records. After calling
|
2016-04-25 18:20:57 +02:00
|
|
|
* this function, @colors will be filled with
|
|
|
|
* the palette colors. If @colors is NULL, the function
|
|
|
|
* will just return the number of total colors
|
|
|
|
* without storing any actual colors; this can be used
|
|
|
|
* for allocating a buffer of suitable size before calling
|
|
|
|
* hb_ot_color_get_palette_colors() a second time.
|
|
|
|
*
|
|
|
|
* Retrieves the colors in a color palette.
|
|
|
|
*
|
|
|
|
* Returns: the total number of colors in the palette. All palettes in
|
|
|
|
* a font have the same number of colors. If @face has no colors, or if
|
|
|
|
* @palette is not between 0 and hb_ot_color_get_palette_count(),
|
|
|
|
* the result is zero.
|
|
|
|
*
|
2018-02-27 20:26:17 +01:00
|
|
|
* Since: REPLACEME
|
2016-04-25 18:20:57 +02:00
|
|
|
*/
|
|
|
|
unsigned int
|
2018-05-01 17:16:46 +02:00
|
|
|
hb_ot_color_get_palette_colors (hb_face_t *face,
|
2018-10-20 16:20:39 +02:00
|
|
|
unsigned int palette, /* default=0 */
|
2018-05-01 17:16:46 +02:00
|
|
|
unsigned int start_offset,
|
2018-10-20 16:20:39 +02:00
|
|
|
unsigned int *count /* IN/OUT */,
|
2018-10-21 06:56:40 +02:00
|
|
|
hb_color_t *colors /* OUT */)
|
2016-04-25 18:20:57 +02:00
|
|
|
{
|
|
|
|
const OT::CPAL& cpal = _get_cpal(face);
|
2018-05-01 17:16:46 +02:00
|
|
|
if (unlikely (palette >= cpal.get_palette_count ()))
|
2016-04-25 18:20:57 +02:00
|
|
|
{
|
2018-05-01 17:16:46 +02:00
|
|
|
if (count) *count = 0;
|
2016-04-25 18:20:57 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-05-01 17:16:46 +02:00
|
|
|
unsigned int num_results = 0;
|
|
|
|
if (count)
|
|
|
|
{
|
|
|
|
unsigned int platte_count = MIN<unsigned int>(*count, cpal.get_palette_entries_count () - start_offset);
|
|
|
|
for (unsigned int i = 0; i < platte_count; i++)
|
|
|
|
{
|
|
|
|
if (cpal.get_color_record_argb(start_offset + i, palette, &colors[num_results]))
|
|
|
|
++num_results;
|
|
|
|
}
|
|
|
|
}
|
2016-04-25 18:20:57 +02:00
|
|
|
|
2018-05-01 17:16:46 +02:00
|
|
|
if (likely (count)) *count = num_results;
|
|
|
|
return cpal.get_palette_entries_count ();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int
|
|
|
|
hb_ot_color_get_color_layers (hb_face_t *face,
|
|
|
|
hb_codepoint_t gid,
|
|
|
|
unsigned int start_offset,
|
|
|
|
unsigned int *count, /* IN/OUT. May be NULL. */
|
|
|
|
hb_codepoint_t *gids, /* OUT. May be NULL. */
|
|
|
|
unsigned int *color_indices /* OUT. May be NULL. */)
|
|
|
|
{
|
|
|
|
const OT::COLR& colr = _get_colr (face);
|
2016-04-25 18:20:57 +02:00
|
|
|
unsigned int num_results = 0;
|
2018-05-01 17:16:46 +02:00
|
|
|
unsigned int start_layer_index, num_layers = 0;
|
|
|
|
if (colr.get_base_glyph_record (gid, &start_layer_index, &num_layers))
|
2016-04-25 18:20:57 +02:00
|
|
|
{
|
2018-05-01 17:16:46 +02:00
|
|
|
if (count)
|
2016-04-25 18:20:57 +02:00
|
|
|
{
|
2018-05-01 17:16:46 +02:00
|
|
|
unsigned int layer_count = MIN<unsigned int>(*count, num_layers - start_offset);
|
|
|
|
for (unsigned int i = 0; i < layer_count; i++)
|
|
|
|
{
|
|
|
|
if (colr.get_layer_record (start_layer_index + start_offset + i,
|
|
|
|
&gids[num_results], &color_indices[num_results]))
|
|
|
|
++num_results;
|
|
|
|
}
|
2016-04-25 18:20:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-01 17:16:46 +02:00
|
|
|
if (likely (count)) *count = num_results;
|
|
|
|
return num_layers;
|
2016-04-25 18:20:57 +02:00
|
|
|
}
|
2018-10-21 06:56:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* hb_ot_color_get_palette_name_id:
|
|
|
|
* @face: a font face.
|
|
|
|
* @palette: the index of the color palette whose name is being requested.
|
|
|
|
*
|
|
|
|
* Retrieves the name id of a color palette. For example, a color font can
|
|
|
|
* have themed palettes like "Spring", "Summer", "Fall", and "Winter".
|
|
|
|
*
|
|
|
|
* Returns: an identifier within @face's `name` table.
|
|
|
|
* If the requested palette has no name, or if @face has no colors,
|
|
|
|
* or if @palette is not between 0 and hb_ot_color_get_palette_count(),
|
|
|
|
* the result is 0xFFFF. The implementation does not check whether
|
|
|
|
* the returned palette name id is actually in @face's `name` table.
|
|
|
|
*
|
|
|
|
* Since: REPLACEME
|
|
|
|
*/
|
|
|
|
hb_name_id_t
|
|
|
|
hb_ot_color_get_palette_name_id (hb_face_t *face, unsigned int palette)
|
|
|
|
{
|
|
|
|
return _get_cpal (face).get_palette_name_id (palette);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/**
|
|
|
|
* hb_ot_color_get_palette_flags:
|
|
|
|
* @face: a font face
|
|
|
|
* @palette: the index of the color palette whose flags are being requested
|
|
|
|
*
|
|
|
|
* Returns: the flags for the requested color palette. If @face has no colors,
|
|
|
|
* or if @palette is not between 0 and hb_ot_color_get_palette_count(),
|
|
|
|
* the result is #HB_OT_COLOR_PALETTE_FLAG_DEFAULT.
|
|
|
|
*
|
|
|
|
* Since: DONTREPLACEME
|
|
|
|
*/
|
|
|
|
hb_ot_color_palette_flags_t
|
|
|
|
hb_ot_color_get_palette_flags (hb_face_t *face, unsigned int palette)
|
|
|
|
{
|
|
|
|
const OT::CPAL& cpal = _get_cpal(face);
|
|
|
|
return cpal.get_palette_flags (palette);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Following parts to be moved to a public header.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hb_ot_color_palette_flags_t:
|
|
|
|
* @HB_OT_COLOR_PALETTE_FLAG_DEFAULT: default indicating that there is nothing special to note about a color palette.
|
|
|
|
* @HB_OT_COLOR_PALETTE_FLAG_FOR_LIGHT_BACKGROUND: flag indicating that the color palette is suitable for rendering text on light background.
|
|
|
|
* @HB_OT_COLOR_PALETTE_FLAG_FOR_DARK_BACKGROUND: flag indicating that the color palette is suitable for rendering text on dark background.
|
|
|
|
*
|
2018-10-21 07:18:07 +02:00
|
|
|
* Since: DONTREPLACEME
|
2018-10-21 06:56:40 +02:00
|
|
|
*/
|
|
|
|
typedef enum { /*< flags >*/
|
|
|
|
HB_OT_COLOR_PALETTE_FLAG_DEFAULT = 0x00000000u,
|
|
|
|
HB_OT_COLOR_PALETTE_FLAG_FOR_LIGHT_BACKGROUND = 0x00000001u,
|
|
|
|
HB_OT_COLOR_PALETTE_FLAG_FOR_DARK_BACKGROUND = 0x00000002u,
|
|
|
|
} hb_ot_color_palette_flags_t;
|
|
|
|
|
|
|
|
HB_EXTERN hb_ot_color_palette_flags_t
|
|
|
|
hb_ot_color_get_palette_flags (hb_face_t *face, unsigned int palette);
|
|
|
|
#endif
|