1 /*
2  * Copyright (C) 2017 Kovid Goyal <kovid at kovidgoyal.net>
3  *
4  * Distributed under terms of the GPL3 license.
5  */
6 
7 #pragma once
8 
9 #include "lineops.h"
10 #include "state.h"
11 #pragma GCC diagnostic push
12 #pragma GCC diagnostic ignored "-Wpedantic"
13 #include <hb.h>
14 #pragma GCC diagnostic pop
15 
16 typedef struct {
17     uint8_t *canvas;
18     size_t width, height;
19 } StringCanvas;
20 
21 // API that font backends need to implement
22 unsigned int glyph_id_for_codepoint(PyObject *, char_type);
23 int get_glyph_width(PyObject *, glyph_index);
24 bool is_glyph_empty(PyObject *, glyph_index);
25 hb_font_t* harfbuzz_font_for_face(PyObject*);
26 bool set_size_for_face(PyObject*, unsigned int, bool, FONTS_DATA_HANDLE);
27 void cell_metrics(PyObject*, unsigned int*, unsigned int*, unsigned int*, unsigned int*, unsigned int*, unsigned int*, unsigned int*);
28 bool render_glyphs_in_cells(PyObject *f, bool bold, bool italic, hb_glyph_info_t *info, hb_glyph_position_t *positions, unsigned int num_glyphs, pixel *canvas, unsigned int cell_width, unsigned int cell_height, unsigned int num_cells, unsigned int baseline, bool *was_colored, FONTS_DATA_HANDLE, bool center_glyph);
29 PyObject* create_fallback_face(PyObject *base_face, CPUCell* cell, bool bold, bool italic, bool emoji_presentation, FONTS_DATA_HANDLE fg);
30 PyObject* specialize_font_descriptor(PyObject *base_descriptor, FONTS_DATA_HANDLE);
31 PyObject* face_from_path(const char *path, int index, FONTS_DATA_HANDLE);
32 PyObject* face_from_descriptor(PyObject*, FONTS_DATA_HANDLE);
33 const char* postscript_name_for_face(const PyObject*);
34 
35 void sprite_tracker_current_layout(FONTS_DATA_HANDLE data, unsigned int *x, unsigned int *y, unsigned int *z);
36 void render_alpha_mask(const uint8_t *alpha_mask, pixel* dest, Region *src_rect, Region *dest_rect, size_t src_stride, size_t dest_stride);
37 void render_line(FONTS_DATA_HANDLE, Line *line, index_type lnum, Cursor *cursor, DisableLigature);
38 void sprite_tracker_set_limits(size_t max_texture_size, size_t max_array_len);
39 typedef void (*free_extra_data_func)(void*);
40 StringCanvas render_simple_text_impl(PyObject *s, const char *text, unsigned int baseline);
41 StringCanvas render_simple_text(FONTS_DATA_HANDLE fg_, const char *text);
42 
43 static inline void
right_shift_canvas(pixel * canvas,size_t width,size_t height,size_t amt)44 right_shift_canvas(pixel *canvas, size_t width, size_t height, size_t amt) {
45     pixel *src;
46     size_t r;
47     for (r = 0, src = canvas; r < height; r++, src += width) {
48         memmove(src + amt, src, sizeof(pixel) * (width - amt));
49         zero_at_ptr_count(src, amt);
50     }
51 }
52