]> granicus.if.org Git - libass/blob - libass/ass_cache.h
Move fonts-related code to a separate file.
[libass] / libass / ass_cache.h
1 // -*- c-basic-offset: 8; indent-tabs-mode: t -*-
2 // vim:ts=8:sw=8:noet:ai:
3 /*
4   Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2 of the License, or
9   (at your option) any later version.
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with this program; if not, write to the Free Software
18   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef __ASS_CACHE_H__
22 #define __ASS_CACHE_H__
23
24 #include <ft2build.h>
25 #include FT_FREETYPE_H
26 #include FT_STROKER_H
27 #include FT_GLYPH_H
28
29 // font cache
30 typedef struct ass_font_desc_s {
31         char* family;
32         unsigned bold;
33         unsigned italic;
34 } ass_font_desc_t;
35
36 typedef struct ass_font_s {
37         ass_font_desc_t desc;
38         char* path;
39         int index;
40         FT_Face face;
41         FT_Matrix m; // current transformation
42         FT_Vector v; // current shift
43         int size;
44 } ass_font_t;
45
46 void ass_font_cache_init(void);
47 ass_font_t* ass_new_font(FT_Library library, void* fontconfig_priv, ass_font_desc_t* desc);
48 void ass_font_cache_done(void);
49
50
51 // describes a glyph; glyphs with equivalents structs are considered identical
52 typedef struct glyph_hash_key_s {
53         char bitmap; // bool : true = bitmap, false = outline
54         FT_Face face;
55         int size; // font size
56         int index; // glyph index in the face
57         unsigned outline; // border width, 16.16 fixed point value
58         int bold, italic;
59         char be; // blur edges
60
61         // the following affects bitmap glyphs only
62         unsigned scale_x, scale_y; // 16.16
63         int angle; // signed 16.16
64         
65         FT_Vector advance; // subpixel shift vector
66 } glyph_hash_key_t;
67
68 typedef struct glyph_hash_val_s {
69         bitmap_t* bm; // the actual glyph bitmaps
70         bitmap_t* bm_o;
71         bitmap_t* bm_s;
72         FT_BBox bbox_scaled; // bbox after scaling, but before rotation
73         FT_Vector advance; // 26.6, advance distance to the next glyph in line
74 } glyph_hash_val_t;
75
76 void ass_glyph_cache_init(void);
77 void cache_add_glyph(glyph_hash_key_t* key, glyph_hash_val_t* val);
78 glyph_hash_val_t* cache_find_glyph(glyph_hash_key_t* key);
79 void ass_glyph_cache_reset(void);
80 void ass_glyph_cache_done(void);
81
82 #endif
83