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.
|
|
|
|
*
|
2018-10-22 22:02:04 +02:00
|
|
|
* Google Author(s): Sascha Brawer, Behdad Esfahbod
|
2016-04-25 18:20:57 +02:00
|
|
|
*/
|
|
|
|
|
2019-06-18 22:18:15 +02:00
|
|
|
#include "hb.hh"
|
|
|
|
|
|
|
|
#ifndef HB_NO_COLOR
|
|
|
|
|
|
|
|
#include "hb-ot.h"
|
|
|
|
|
2018-10-22 20:37:59 +02:00
|
|
|
#include "hb-ot-color-cbdt-table.hh"
|
2018-03-03 20:13:23 +01:00
|
|
|
#include "hb-ot-color-colr-table.hh"
|
|
|
|
#include "hb-ot-color-cpal-table.hh"
|
2018-10-22 20:37:59 +02:00
|
|
|
#include "hb-ot-color-sbix-table.hh"
|
|
|
|
#include "hb-ot-color-svg-table.hh"
|
2016-04-25 18:20:57 +02:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
2018-10-27 13:58:32 +02:00
|
|
|
/**
|
|
|
|
* SECTION:hb-ot-color
|
|
|
|
* @title: hb-ot-color
|
|
|
|
* @short_description: OpenType Color Fonts
|
|
|
|
* @include: hb-ot.h
|
|
|
|
*
|
|
|
|
* Functions for fetching color-font information from OpenType font faces.
|
2019-04-14 16:20:56 +02:00
|
|
|
*
|
2019-05-11 21:11:49 +02:00
|
|
|
* HarfBuzz supports `COLR`/`CPAL`, `sbix`, `CBDT`, and `SVG` color fonts.
|
2018-10-27 13:58:32 +02:00
|
|
|
**/
|
|
|
|
|
|
|
|
|
2018-10-22 04:23:11 +02:00
|
|
|
/*
|
|
|
|
* CPAL
|
2016-04-25 18:20:57 +02:00
|
|
|
*/
|
2018-10-22 04:23:11 +02:00
|
|
|
|
2016-04-25 18:20:57 +02:00
|
|
|
|
|
|
|
/**
|
2018-10-22 04:23:11 +02:00
|
|
|
* hb_ot_color_has_palettes:
|
2019-04-14 16:20:56 +02:00
|
|
|
* @face: #hb_face_t to work upon
|
|
|
|
*
|
2019-05-11 15:06:56 +02:00
|
|
|
* Tests whether a face includes a `CPAL` color-palette table.
|
2016-04-25 18:20:57 +02:00
|
|
|
*
|
2019-04-14 16:20:56 +02:00
|
|
|
* Return value: true if data found, false otherwise
|
2016-04-25 18:20:57 +02:00
|
|
|
*
|
2018-10-27 11:35:06 +02:00
|
|
|
* Since: 2.1.0
|
2016-04-25 18:20:57 +02:00
|
|
|
*/
|
2018-10-21 06:56:40 +02:00
|
|
|
hb_bool_t
|
2018-10-22 04:23:11 +02:00
|
|
|
hb_ot_color_has_palettes (hb_face_t *face)
|
2016-04-25 18:20:57 +02:00
|
|
|
{
|
2018-11-06 04:58:43 +01:00
|
|
|
return face->table.CPAL->has_data ();
|
2016-04-25 18:20:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-22 22:02:04 +02:00
|
|
|
* hb_ot_color_palette_get_count:
|
2019-04-14 16:20:56 +02:00
|
|
|
* @face: #hb_face_t to work upon
|
|
|
|
*
|
|
|
|
* Fetches the number of color palettes in a face.
|
2016-04-25 18:20:57 +02:00
|
|
|
*
|
2019-04-14 16:20:56 +02:00
|
|
|
* Return value: the number of palettes found
|
2016-04-25 18:20:57 +02:00
|
|
|
*
|
2018-10-27 11:35:06 +02:00
|
|
|
* Since: 2.1.0
|
2016-04-25 18:20:57 +02:00
|
|
|
*/
|
2018-10-21 06:56:40 +02:00
|
|
|
unsigned int
|
2018-10-22 22:02:04 +02:00
|
|
|
hb_ot_color_palette_get_count (hb_face_t *face)
|
2016-04-25 18:20:57 +02:00
|
|
|
{
|
2018-11-06 04:58:43 +01:00
|
|
|
return face->table.CPAL->get_palette_count ();
|
2016-04-25 18:20:57 +02:00
|
|
|
}
|
|
|
|
|
2018-10-21 08:14:16 +02:00
|
|
|
/**
|
2018-10-22 22:02:04 +02:00
|
|
|
* hb_ot_color_palette_get_name_id:
|
2019-04-14 16:20:56 +02:00
|
|
|
* @face: #hb_face_t to work upon
|
|
|
|
* @palette_index: The index of the color palette
|
2018-10-21 08:14:16 +02:00
|
|
|
*
|
2019-05-11 15:07:38 +02:00
|
|
|
* Fetches the `name` table Name ID that provides display names for
|
2019-05-11 21:11:49 +02:00
|
|
|
* a `CPAL` color palette.
|
2018-10-21 08:14:16 +02:00
|
|
|
*
|
2019-04-14 16:20:56 +02:00
|
|
|
* Palette display names can be generic (e.g., "Default") or provide
|
|
|
|
* specific, themed names (e.g., "Spring", "Summer", "Fall", and "Winter").
|
|
|
|
*
|
|
|
|
* Return value: the Named ID found for the palette.
|
2018-10-30 22:04:09 +01:00
|
|
|
* If the requested palette has no name the result is #HB_OT_NAME_ID_INVALID.
|
2018-10-21 08:14:16 +02:00
|
|
|
*
|
2018-10-27 11:35:06 +02:00
|
|
|
* Since: 2.1.0
|
2018-10-21 08:14:16 +02:00
|
|
|
*/
|
2018-10-30 22:04:09 +01:00
|
|
|
hb_ot_name_id_t
|
2018-10-22 22:02:04 +02:00
|
|
|
hb_ot_color_palette_get_name_id (hb_face_t *face,
|
|
|
|
unsigned int palette_index)
|
2018-10-21 08:14:16 +02:00
|
|
|
{
|
2018-11-06 04:58:43 +01:00
|
|
|
return face->table.CPAL->get_palette_name_id (palette_index);
|
2018-10-21 08:14:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-22 22:02:04 +02:00
|
|
|
* hb_ot_color_palette_color_get_name_id:
|
2019-04-14 16:20:56 +02:00
|
|
|
* @face: #hb_face_t to work upon
|
|
|
|
* @color_index: The index of the color
|
|
|
|
*
|
2019-05-11 15:08:40 +02:00
|
|
|
* Fetches the `name` table Name ID that provides display names for
|
2019-05-11 15:09:26 +02:00
|
|
|
* the specificed color in a face's `CPAL` color palette.
|
2019-04-14 16:20:56 +02:00
|
|
|
*
|
|
|
|
* Display names can be generic (e.g., "Background") or specific
|
|
|
|
* (e.g., "Eye color").
|
2018-10-21 08:14:16 +02:00
|
|
|
*
|
2019-04-14 16:20:56 +02:00
|
|
|
* Return value: the Name ID found for the color.
|
2018-10-21 08:14:16 +02:00
|
|
|
*
|
2018-10-27 11:35:06 +02:00
|
|
|
* Since: 2.1.0
|
2018-10-21 08:14:16 +02:00
|
|
|
*/
|
2018-10-30 22:04:09 +01:00
|
|
|
hb_ot_name_id_t
|
2018-10-22 22:02:04 +02:00
|
|
|
hb_ot_color_palette_color_get_name_id (hb_face_t *face,
|
|
|
|
unsigned int color_index)
|
2018-10-21 08:14:16 +02:00
|
|
|
{
|
2018-11-06 04:58:43 +01:00
|
|
|
return face->table.CPAL->get_color_name_id (color_index);
|
2018-10-21 08:14:16 +02:00
|
|
|
}
|
|
|
|
|
2016-04-25 18:20:57 +02:00
|
|
|
/**
|
2018-10-22 22:02:04 +02:00
|
|
|
* hb_ot_color_palette_get_flags:
|
2019-04-14 16:20:56 +02:00
|
|
|
* @face: #hb_face_t to work upon
|
|
|
|
* @palette_index: The index of the color palette
|
2018-10-22 22:02:04 +02:00
|
|
|
*
|
2019-04-14 16:20:56 +02:00
|
|
|
* Fetches the flags defined for a color palette.
|
|
|
|
*
|
|
|
|
* Return value: the #hb_ot_color_palette_flags_t of the requested color palette
|
2018-10-22 22:02:04 +02:00
|
|
|
*
|
2018-10-27 11:35:06 +02:00
|
|
|
* Since: 2.1.0
|
2018-10-22 22:02:04 +02:00
|
|
|
*/
|
|
|
|
hb_ot_color_palette_flags_t
|
|
|
|
hb_ot_color_palette_get_flags (hb_face_t *face,
|
|
|
|
unsigned int palette_index)
|
|
|
|
{
|
2018-11-06 04:58:43 +01:00
|
|
|
return face->table.CPAL->get_palette_flags (palette_index);
|
2018-10-22 22:02:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hb_ot_color_palette_get_colors:
|
2019-04-14 16:20:56 +02:00
|
|
|
* @face: #hb_face_t to work upon
|
|
|
|
* @palette_index: the index of the color palette to query
|
|
|
|
* @start_offset: offset of the first color to retrieve
|
|
|
|
* @color_count: (inout) (optional): Input = the maximum number of colors to return;
|
|
|
|
* Output = the actual number of colors returned (may be zero)
|
2019-05-11 21:11:49 +02:00
|
|
|
* @colors: (out) (array length=color_count) (nullable): The array of #hb_color_t records found
|
2019-04-14 16:20:56 +02:00
|
|
|
*
|
|
|
|
* Fetches a list of the colors in a color palette.
|
|
|
|
*
|
|
|
|
* After calling 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
|
2019-05-11 15:09:52 +02:00
|
|
|
* hb_ot_color_palette_get_colors() a second time.
|
2019-04-14 16:20:56 +02:00
|
|
|
*
|
|
|
|
* Return value: the total number of colors in the palette
|
2016-04-25 18:20:57 +02:00
|
|
|
*
|
2018-10-27 11:35:06 +02:00
|
|
|
* Since: 2.1.0
|
2016-04-25 18:20:57 +02:00
|
|
|
*/
|
|
|
|
unsigned int
|
2018-10-23 01:55:12 +02:00
|
|
|
hb_ot_color_palette_get_colors (hb_face_t *face,
|
|
|
|
unsigned int palette_index,
|
|
|
|
unsigned int start_offset,
|
|
|
|
unsigned int *colors_count /* IN/OUT. May be NULL. */,
|
|
|
|
hb_color_t *colors /* OUT. May be NULL. */)
|
2016-04-25 18:20:57 +02:00
|
|
|
{
|
2018-11-06 04:58:43 +01:00
|
|
|
return face->table.CPAL->get_palette_colors (palette_index, start_offset, colors_count, colors);
|
2018-05-01 17:16:46 +02:00
|
|
|
}
|
|
|
|
|
2018-10-22 04:23:11 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* COLR
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hb_ot_color_has_layers:
|
2019-04-14 16:20:56 +02:00
|
|
|
* @face: #hb_face_t to work upon
|
|
|
|
*
|
2019-05-11 20:51:24 +02:00
|
|
|
* Tests whether a face includes any `COLR` color layers.
|
2018-10-22 04:23:11 +02:00
|
|
|
*
|
2019-04-14 16:20:56 +02:00
|
|
|
* Return value: true if data found, false otherwise
|
2018-10-22 04:23:11 +02:00
|
|
|
*
|
2018-10-27 11:35:06 +02:00
|
|
|
* Since: 2.1.0
|
2018-10-22 04:23:11 +02:00
|
|
|
*/
|
|
|
|
hb_bool_t
|
|
|
|
hb_ot_color_has_layers (hb_face_t *face)
|
|
|
|
{
|
2018-11-06 04:58:43 +01:00
|
|
|
return face->table.COLR->has_data ();
|
2018-10-22 04:23:11 +02:00
|
|
|
}
|
|
|
|
|
2018-10-21 08:14:16 +02:00
|
|
|
/**
|
2018-10-22 19:29:01 +02:00
|
|
|
* hb_ot_color_glyph_get_layers:
|
2019-04-14 16:20:56 +02:00
|
|
|
* @face: #hb_face_t to work upon
|
|
|
|
* @glyph: The glyph index to query
|
|
|
|
* @start_offset: offset of the first layer to retrieve
|
2019-05-11 21:16:57 +02:00
|
|
|
* @layer_count: (inout) (optional): Input = the maximum number of layers to return;
|
2019-04-14 16:20:56 +02:00
|
|
|
* Output = the actual number of layers returned (may be zero)
|
2019-05-11 21:16:57 +02:00
|
|
|
* @layers: (out) (array length=layer_count) (nullable): The array of layers found
|
2019-04-14 16:20:56 +02:00
|
|
|
*
|
|
|
|
* Fetches a list of all color layers for the specified glyph index in the specified
|
|
|
|
* face. The list returned will begin at the offset provided.
|
2018-10-21 08:14:16 +02:00
|
|
|
*
|
2019-04-14 16:20:56 +02:00
|
|
|
* Return value: Total number of layers available for the glyph index queried
|
2018-10-21 08:14:16 +02:00
|
|
|
*
|
2018-10-27 11:35:06 +02:00
|
|
|
* Since: 2.1.0
|
2018-10-21 08:14:16 +02:00
|
|
|
*/
|
2018-05-01 17:16:46 +02:00
|
|
|
unsigned int
|
2018-10-22 19:29:01 +02:00
|
|
|
hb_ot_color_glyph_get_layers (hb_face_t *face,
|
|
|
|
hb_codepoint_t glyph,
|
|
|
|
unsigned int start_offset,
|
2019-05-11 09:53:52 +02:00
|
|
|
unsigned int *layer_count, /* IN/OUT. May be NULL. */
|
2018-10-22 19:29:01 +02:00
|
|
|
hb_ot_color_layer_t *layers /* OUT. May be NULL. */)
|
2018-05-01 17:16:46 +02:00
|
|
|
{
|
2019-05-11 09:53:52 +02:00
|
|
|
return face->table.COLR->get_glyph_layers (glyph, start_offset, layer_count, layers);
|
2016-04-25 18:20:57 +02:00
|
|
|
}
|
2018-10-23 16:30:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SVG
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hb_ot_color_has_svg:
|
2019-04-14 16:20:56 +02:00
|
|
|
* @face: #hb_face_t to work upon.
|
2018-10-23 16:30:48 +02:00
|
|
|
*
|
2019-05-11 21:11:49 +02:00
|
|
|
* Tests whether a face includes any `SVG` glyph images.
|
2018-10-23 16:30:48 +02:00
|
|
|
*
|
2019-04-14 16:20:56 +02:00
|
|
|
* Return value: true if data found, false otherwise.
|
2018-10-30 23:52:26 +01:00
|
|
|
*
|
|
|
|
* Since: 2.1.0
|
2018-10-23 16:30:48 +02:00
|
|
|
*/
|
|
|
|
hb_bool_t
|
|
|
|
hb_ot_color_has_svg (hb_face_t *face)
|
|
|
|
{
|
2018-11-06 04:58:43 +01:00
|
|
|
return face->table.SVG->has_data ();
|
2018-10-23 16:30:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-28 19:08:56 +01:00
|
|
|
* hb_ot_color_glyph_reference_svg:
|
2019-04-14 16:20:56 +02:00
|
|
|
* @face: #hb_face_t to work upon
|
|
|
|
* @glyph: a svg glyph index
|
2018-10-23 16:30:48 +02:00
|
|
|
*
|
2019-04-14 16:20:56 +02:00
|
|
|
* Fetches the SVG document for a glyph. The blob may be either plain text or gzip-encoded.
|
2018-10-30 23:52:26 +01:00
|
|
|
*
|
2019-04-14 16:20:56 +02:00
|
|
|
* Return value: (transfer full): An #hb_blob_t containing the SVG document of the glyph, if available
|
2018-10-23 16:30:48 +02:00
|
|
|
*
|
2018-10-30 23:52:26 +01:00
|
|
|
* Since: 2.1.0
|
2018-10-23 16:30:48 +02:00
|
|
|
*/
|
|
|
|
hb_blob_t *
|
2018-10-28 19:08:56 +01:00
|
|
|
hb_ot_color_glyph_reference_svg (hb_face_t *face, hb_codepoint_t glyph)
|
2018-10-23 16:30:48 +02:00
|
|
|
{
|
2018-11-06 04:58:43 +01:00
|
|
|
return face->table.SVG->reference_blob_for_glyph (glyph);
|
2018-10-23 16:30:48 +02:00
|
|
|
}
|
2018-10-26 22:25:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2018-10-27 12:02:14 +02:00
|
|
|
* PNG: CBDT or sbix
|
2018-10-26 22:25:11 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hb_ot_color_has_png:
|
2019-04-14 16:20:56 +02:00
|
|
|
* @face: #hb_face_t to work upon
|
2018-10-26 22:25:11 +02:00
|
|
|
*
|
2019-05-11 21:11:49 +02:00
|
|
|
* Tests whether a face has PNG glyph images (either in `CBDT` or `sbix` tables).
|
2018-10-26 22:25:11 +02:00
|
|
|
*
|
2019-04-14 16:20:56 +02:00
|
|
|
* Return value: true if data found, false otherwise
|
2018-10-30 23:52:26 +01:00
|
|
|
*
|
|
|
|
* Since: 2.1.0
|
2018-10-26 22:25:11 +02:00
|
|
|
*/
|
|
|
|
hb_bool_t
|
|
|
|
hb_ot_color_has_png (hb_face_t *face)
|
|
|
|
{
|
2018-11-06 04:58:43 +01:00
|
|
|
return face->table.CBDT->has_data () || face->table.sbix->has_data ();
|
2018-10-26 22:25:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-28 19:08:56 +01:00
|
|
|
* hb_ot_color_glyph_reference_png:
|
2019-04-14 16:20:56 +02:00
|
|
|
* @font: #hb_font_t to work upon
|
2019-05-11 21:11:49 +02:00
|
|
|
* @glyph: a glyph index
|
2018-10-26 22:25:11 +02:00
|
|
|
*
|
2019-04-14 16:20:56 +02:00
|
|
|
* Fetches the PNG image for a glyph. This function takes a font object, not a face object,
|
|
|
|
* as input. To get an optimally sized PNG blob, the UPEM value must be set on the @font
|
|
|
|
* object. If UPEM is unset, the blob returned will be the largest PNG available.
|
2018-10-26 22:25:11 +02:00
|
|
|
*
|
2019-04-14 16:20:56 +02:00
|
|
|
* Return value: (transfer full): An #hb_blob_t containing the PNG image for the glyph, if available
|
2018-10-30 23:52:26 +01:00
|
|
|
*
|
|
|
|
* Since: 2.1.0
|
2018-10-26 22:25:11 +02:00
|
|
|
*/
|
|
|
|
hb_blob_t *
|
2018-10-28 19:08:56 +01:00
|
|
|
hb_ot_color_glyph_reference_png (hb_font_t *font, hb_codepoint_t glyph)
|
2018-10-26 22:25:11 +02:00
|
|
|
{
|
2018-10-27 12:54:58 +02:00
|
|
|
hb_blob_t *blob = hb_blob_get_empty ();
|
2018-10-26 22:25:11 +02:00
|
|
|
|
2018-11-06 04:58:43 +01:00
|
|
|
if (font->face->table.sbix->has_data ())
|
|
|
|
blob = font->face->table.sbix->reference_png (font, glyph, nullptr, nullptr, nullptr);
|
2018-10-26 22:25:11 +02:00
|
|
|
|
2018-11-06 04:58:43 +01:00
|
|
|
if (!blob->length && font->face->table.CBDT->has_data ())
|
|
|
|
blob = font->face->table.CBDT->reference_png (font, glyph);
|
2018-10-27 12:54:58 +02:00
|
|
|
|
|
|
|
return blob;
|
2018-10-26 22:25:11 +02:00
|
|
|
}
|
2019-06-18 22:18:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|