Path: blob/master/src/java.desktop/share/native/libharfbuzz/hb-draw.cc
66644 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_DRAW2728#include "hb-draw.hh"2930/**31* SECTION:hb-draw32* @title: hb-draw33* @short_description: Glyph drawing34* @include: hb.h35*36* Functions for drawing (extracting) glyph shapes.37**/3839static void40hb_draw_move_to_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED,41hb_draw_state_t *st HB_UNUSED,42float to_x HB_UNUSED, float to_y HB_UNUSED,43void *user_data HB_UNUSED) {}4445static void46hb_draw_line_to_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED,47hb_draw_state_t *st HB_UNUSED,48float to_x HB_UNUSED, float to_y HB_UNUSED,49void *user_data HB_UNUSED) {}5051static void52hb_draw_quadratic_to_nil (hb_draw_funcs_t *dfuncs, void *draw_data,53hb_draw_state_t *st,54float control_x, float control_y,55float to_x, float to_y,56void *user_data HB_UNUSED)57{58#define HB_ONE_THIRD 0.33333333f59dfuncs->emit_cubic_to (draw_data, *st,60(st->current_x + 2.f * control_x) * HB_ONE_THIRD,61(st->current_y + 2.f * control_y) * HB_ONE_THIRD,62(to_x + 2.f * control_x) * HB_ONE_THIRD,63(to_y + 2.f * control_y) * HB_ONE_THIRD,64to_x, to_y);65#undef HB_ONE_THIRD66}6768static void69hb_draw_cubic_to_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED,70hb_draw_state_t *st HB_UNUSED,71float control1_x HB_UNUSED, float control1_y HB_UNUSED,72float control2_x HB_UNUSED, float control2_y HB_UNUSED,73float to_x HB_UNUSED, float to_y HB_UNUSED,74void *user_data HB_UNUSED) {}7576static void77hb_draw_close_path_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED,78hb_draw_state_t *st HB_UNUSED,79void *user_data HB_UNUSED) {}808182#define HB_DRAW_FUNC_IMPLEMENT(name) \83\84void \85hb_draw_funcs_set_##name##_func (hb_draw_funcs_t *dfuncs, \86hb_draw_##name##_func_t func, \87void *user_data, \88hb_destroy_func_t destroy) \89{ \90if (hb_object_is_immutable (dfuncs)) \91return; \92\93if (dfuncs->destroy && dfuncs->destroy->name) \94dfuncs->destroy->name (!dfuncs->user_data ? nullptr : dfuncs->user_data->name); \95\96if (user_data && !dfuncs->user_data) \97{ \98dfuncs->user_data = (decltype (dfuncs->user_data)) hb_calloc (1, sizeof (*dfuncs->user_data)); \99if (unlikely (!dfuncs->user_data)) \100goto fail; \101} \102if (destroy && !dfuncs->destroy) \103{ \104dfuncs->destroy = (decltype (dfuncs->destroy)) hb_calloc (1, sizeof (*dfuncs->destroy)); \105if (unlikely (!dfuncs->destroy)) \106goto fail; \107} \108\109if (func) { \110dfuncs->func.name = func; \111if (dfuncs->user_data) \112dfuncs->user_data->name = user_data; \113if (dfuncs->destroy) \114dfuncs->destroy->name = destroy; \115} else { \116dfuncs->func.name = hb_draw_##name##_nil; \117if (dfuncs->user_data) \118dfuncs->user_data->name = nullptr; \119if (dfuncs->destroy) \120dfuncs->destroy->name = nullptr; \121} \122\123fail: \124if (destroy) \125destroy (user_data); \126}127128HB_DRAW_FUNCS_IMPLEMENT_CALLBACKS129#undef HB_DRAW_FUNC_IMPLEMENT130131/**132* hb_draw_funcs_create:133*134* Creates a new draw callbacks object.135*136* Return value: (transfer full):137* A newly allocated #hb_draw_funcs_t with a reference count of 1. The initial138* reference count should be released with hb_draw_funcs_destroy when you are139* done using the #hb_draw_funcs_t. This function never returns %NULL. If140* memory cannot be allocated, a special singleton #hb_draw_funcs_t object will141* be returned.142*143* Since: 4.0.0144**/145hb_draw_funcs_t *146hb_draw_funcs_create ()147{148hb_draw_funcs_t *dfuncs;149if (unlikely (!(dfuncs = hb_object_create<hb_draw_funcs_t> ())))150return const_cast<hb_draw_funcs_t *> (&Null (hb_draw_funcs_t));151152dfuncs->func = Null (hb_draw_funcs_t).func;153154return dfuncs;155}156157DEFINE_NULL_INSTANCE (hb_draw_funcs_t) =158{159HB_OBJECT_HEADER_STATIC,160161{162#define HB_DRAW_FUNC_IMPLEMENT(name) hb_draw_##name##_nil,163HB_DRAW_FUNCS_IMPLEMENT_CALLBACKS164#undef HB_DRAW_FUNC_IMPLEMENT165}166};167168169/**170* hb_draw_funcs_reference: (skip)171* @dfuncs: draw functions172*173* Increases the reference count on @dfuncs by one. This prevents @buffer from174* being destroyed until a matching call to hb_draw_funcs_destroy() is made.175*176* Return value: (transfer full):177* The referenced #hb_draw_funcs_t.178*179* Since: 4.0.0180**/181hb_draw_funcs_t *182hb_draw_funcs_reference (hb_draw_funcs_t *dfuncs)183{184return hb_object_reference (dfuncs);185}186187/**188* hb_draw_funcs_destroy: (skip)189* @dfuncs: draw functions190*191* Deallocate the @dfuncs.192* Decreases the reference count on @dfuncs by one. If the result is zero, then193* @dfuncs and all associated resources are freed. See hb_draw_funcs_reference().194*195* Since: 4.0.0196**/197void198hb_draw_funcs_destroy (hb_draw_funcs_t *dfuncs)199{200if (!hb_object_destroy (dfuncs)) return;201202if (dfuncs->destroy)203{204#define HB_DRAW_FUNC_IMPLEMENT(name) \205if (dfuncs->destroy->name) dfuncs->destroy->name (!dfuncs->user_data ? nullptr : dfuncs->user_data->name);206HB_DRAW_FUNCS_IMPLEMENT_CALLBACKS207#undef HB_DRAW_FUNC_IMPLEMENT208}209210hb_free (dfuncs);211}212213/**214* hb_draw_funcs_make_immutable:215* @dfuncs: draw functions216*217* Makes @dfuncs object immutable.218*219* Since: 4.0.0220**/221void222hb_draw_funcs_make_immutable (hb_draw_funcs_t *dfuncs)223{224if (hb_object_is_immutable (dfuncs))225return;226227hb_object_make_immutable (dfuncs);228}229230/**231* hb_draw_funcs_is_immutable:232* @dfuncs: draw functions233*234* Checks whether @dfuncs is immutable.235*236* Return value: %true if @dfuncs is immutable, %false otherwise237*238* Since: 4.0.0239**/240hb_bool_t241hb_draw_funcs_is_immutable (hb_draw_funcs_t *dfuncs)242{243return hb_object_is_immutable (dfuncs);244}245246247/**248* hb_draw_move_to:249* @dfuncs: draw functions250* @draw_data: associated draw data passed by the caller251* @st: current draw state252* @to_x: X component of target point253* @to_y: Y component of target point254*255* Perform a "move-to" draw operation.256*257* Since: 4.0.0258**/259void260hb_draw_move_to (hb_draw_funcs_t *dfuncs, void *draw_data,261hb_draw_state_t *st,262float to_x, float to_y)263{264dfuncs->move_to (draw_data, *st,265to_x, to_y);266}267268/**269* hb_draw_line_to:270* @dfuncs: draw functions271* @draw_data: associated draw data passed by the caller272* @st: current draw state273* @to_x: X component of target point274* @to_y: Y component of target point275*276* Perform a "line-to" draw operation.277*278* Since: 4.0.0279**/280void281hb_draw_line_to (hb_draw_funcs_t *dfuncs, void *draw_data,282hb_draw_state_t *st,283float to_x, float to_y)284{285dfuncs->line_to (draw_data, *st,286to_x, to_y);287}288289/**290* hb_draw_quadratic_to:291* @dfuncs: draw functions292* @draw_data: associated draw data passed by the caller293* @st: current draw state294* @control_x: X component of control point295* @control_y: Y component of control point296* @to_x: X component of target point297* @to_y: Y component of target point298*299* Perform a "quadratic-to" draw operation.300*301* Since: 4.0.0302**/303void304hb_draw_quadratic_to (hb_draw_funcs_t *dfuncs, void *draw_data,305hb_draw_state_t *st,306float control_x, float control_y,307float to_x, float to_y)308{309dfuncs->quadratic_to (draw_data, *st,310control_x, control_y,311to_x, to_y);312}313314/**315* hb_draw_cubic_to:316* @dfuncs: draw functions317* @draw_data: associated draw data passed by the caller318* @st: current draw state319* @control1_x: X component of first control point320* @control1_y: Y component of first control point321* @control2_x: X component of second control point322* @control2_y: Y component of second control point323* @to_x: X component of target point324* @to_y: Y component of target point325*326* Perform a "cubic-to" draw operation.327*328* Since: 4.0.0329**/330void331hb_draw_cubic_to (hb_draw_funcs_t *dfuncs, void *draw_data,332hb_draw_state_t *st,333float control1_x, float control1_y,334float control2_x, float control2_y,335float to_x, float to_y)336{337dfuncs->cubic_to (draw_data, *st,338control1_x, control1_y,339control2_x, control2_y,340to_x, to_y);341}342343/**344* hb_draw_close_path:345* @dfuncs: draw functions346* @draw_data: associated draw data passed by the caller347* @st: current draw state348*349* Perform a "close-path" draw operation.350*351* Since: 4.0.0352**/353void354hb_draw_close_path (hb_draw_funcs_t *dfuncs, void *draw_data,355hb_draw_state_t *st)356{357dfuncs->close_path (draw_data, *st);358}359360361#endif362363364