Path: blob/master/src/java.desktop/share/native/libharfbuzz/hb-draw.cc
41149 views
/*1* Copyright © 2019-2020 Ebrahim Byagowi2*3* This is part of HarfBuzz, a text shaping library.4*5* Permission is hereby granted, without written agreement and without6* license or royalty fees, to use, copy, modify, and distribute this7* software and its documentation for any purpose, provided that the8* above copyright notice and the following two paragraphs appear in9* all copies of this software.10*11* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR12* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES13* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN14* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH15* DAMAGE.16*17* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,18* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND19* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS20* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO21* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.22*/2324#include "hb.hh"2526#ifndef HB_NO_DRAW27#ifdef HB_EXPERIMENTAL_API2829#include "hb-draw.hh"30#include "hb-ot.h"31#include "hb-ot-glyf-table.hh"32#include "hb-ot-cff1-table.hh"33#include "hb-ot-cff2-table.hh"3435/**36* hb_draw_funcs_set_move_to_func:37* @funcs: draw functions object38* @move_to: move-to callback39*40* Sets move-to callback to the draw functions object.41*42* Since: EXPERIMENTAL43**/44void45hb_draw_funcs_set_move_to_func (hb_draw_funcs_t *funcs,46hb_draw_move_to_func_t move_to)47{48if (unlikely (hb_object_is_immutable (funcs))) return;49funcs->move_to = move_to;50}5152/**53* hb_draw_funcs_set_line_to_func:54* @funcs: draw functions object55* @line_to: line-to callback56*57* Sets line-to callback to the draw functions object.58*59* Since: EXPERIMENTAL60**/61void62hb_draw_funcs_set_line_to_func (hb_draw_funcs_t *funcs,63hb_draw_line_to_func_t line_to)64{65if (unlikely (hb_object_is_immutable (funcs))) return;66funcs->line_to = line_to;67}6869/**70* hb_draw_funcs_set_quadratic_to_func:71* @funcs: draw functions object72* @move_to: quadratic-to callback73*74* Sets quadratic-to callback to the draw functions object.75*76* Since: EXPERIMENTAL77**/78void79hb_draw_funcs_set_quadratic_to_func (hb_draw_funcs_t *funcs,80hb_draw_quadratic_to_func_t quadratic_to)81{82if (unlikely (hb_object_is_immutable (funcs))) return;83funcs->quadratic_to = quadratic_to;84funcs->is_quadratic_to_set = true;85}8687/**88* hb_draw_funcs_set_cubic_to_func:89* @funcs: draw functions90* @cubic_to: cubic-to callback91*92* Sets cubic-to callback to the draw functions object.93*94* Since: EXPERIMENTAL95**/96void97hb_draw_funcs_set_cubic_to_func (hb_draw_funcs_t *funcs,98hb_draw_cubic_to_func_t cubic_to)99{100if (unlikely (hb_object_is_immutable (funcs))) return;101funcs->cubic_to = cubic_to;102}103104/**105* hb_draw_funcs_set_close_path_func:106* @funcs: draw functions object107* @close_path: close-path callback108*109* Sets close-path callback to the draw functions object.110*111* Since: EXPERIMENTAL112**/113void114hb_draw_funcs_set_close_path_func (hb_draw_funcs_t *funcs,115hb_draw_close_path_func_t close_path)116{117if (unlikely (hb_object_is_immutable (funcs))) return;118funcs->close_path = close_path;119}120121static void122_move_to_nil (hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED, void *user_data HB_UNUSED) {}123124static void125_line_to_nil (hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED, void *user_data HB_UNUSED) {}126127static void128_quadratic_to_nil (hb_position_t control_x HB_UNUSED, hb_position_t control_y HB_UNUSED,129hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED,130void *user_data HB_UNUSED) {}131132static void133_cubic_to_nil (hb_position_t control1_x HB_UNUSED, hb_position_t control1_y HB_UNUSED,134hb_position_t control2_x HB_UNUSED, hb_position_t control2_y HB_UNUSED,135hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED,136void *user_data HB_UNUSED) {}137138static void139_close_path_nil (void *user_data HB_UNUSED) {}140141/**142* hb_draw_funcs_create:143*144* Creates a new draw callbacks object.145*146* Since: EXPERIMENTAL147**/148hb_draw_funcs_t *149hb_draw_funcs_create ()150{151hb_draw_funcs_t *funcs;152if (unlikely (!(funcs = hb_object_create<hb_draw_funcs_t> ())))153return const_cast<hb_draw_funcs_t *> (&Null (hb_draw_funcs_t));154155funcs->move_to = (hb_draw_move_to_func_t) _move_to_nil;156funcs->line_to = (hb_draw_line_to_func_t) _line_to_nil;157funcs->quadratic_to = (hb_draw_quadratic_to_func_t) _quadratic_to_nil;158funcs->is_quadratic_to_set = false;159funcs->cubic_to = (hb_draw_cubic_to_func_t) _cubic_to_nil;160funcs->close_path = (hb_draw_close_path_func_t) _close_path_nil;161return funcs;162}163164/**165* hb_draw_funcs_reference:166* @funcs: draw functions167*168* Add to callbacks object refcount.169*170* Returns: The same object.171* Since: EXPERIMENTAL172**/173hb_draw_funcs_t *174hb_draw_funcs_reference (hb_draw_funcs_t *funcs)175{176return hb_object_reference (funcs);177}178179/**180* hb_draw_funcs_destroy:181* @funcs: draw functions182*183* Decreases refcount of callbacks object and deletes the object if it reaches184* to zero.185*186* Since: EXPERIMENTAL187**/188void189hb_draw_funcs_destroy (hb_draw_funcs_t *funcs)190{191if (!hb_object_destroy (funcs)) return;192193free (funcs);194}195196/**197* hb_draw_funcs_make_immutable:198* @funcs: draw functions199*200* Makes funcs object immutable.201*202* Since: EXPERIMENTAL203**/204void205hb_draw_funcs_make_immutable (hb_draw_funcs_t *funcs)206{207if (hb_object_is_immutable (funcs))208return;209210hb_object_make_immutable (funcs);211}212213/**214* hb_draw_funcs_is_immutable:215* @funcs: draw functions216*217* Checks whether funcs is immutable.218*219* Returns: If is immutable.220* Since: EXPERIMENTAL221**/222hb_bool_t223hb_draw_funcs_is_immutable (hb_draw_funcs_t *funcs)224{225return hb_object_is_immutable (funcs);226}227228/**229* hb_font_draw_glyph:230* @font: a font object231* @glyph: a glyph id232* @funcs: draw callbacks object233* @user_data: parameter you like be passed to the callbacks when are called234*235* Draw a glyph.236*237* Returns: Whether the font had the glyph and the operation completed successfully.238* Since: EXPERIMENTAL239**/240hb_bool_t241hb_font_draw_glyph (hb_font_t *font, hb_codepoint_t glyph,242const hb_draw_funcs_t *funcs,243void *user_data)244{245if (unlikely (funcs == &Null (hb_draw_funcs_t) ||246glyph >= font->face->get_num_glyphs ()))247return false;248249draw_helper_t draw_helper (funcs, user_data);250if (font->face->table.glyf->get_path (font, glyph, draw_helper)) return true;251#ifndef HB_NO_CFF252if (font->face->table.cff1->get_path (font, glyph, draw_helper)) return true;253if (font->face->table.cff2->get_path (font, glyph, draw_helper)) return true;254#endif255256return false;257}258259#endif260#endif261262263