1 // -*- c-basic-offset: 8; indent-tabs-mode: t -*-
2 // vim:ts=8:sw=8:noet:ai:
4 Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
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.
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.
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
25 #include FT_FREETYPE_H
26 #include FT_SYNTHESIS_H
30 #include "ass_fontconfig.h"
33 extern int no_more_font_messages;
36 * Select Microfost Unicode CharMap, if the font has one.
37 * Otherwise, let FreeType decide.
39 static void charmap_magic(FT_Face face)
42 for (i = 0; i < face->num_charmaps; ++i) {
43 FT_CharMap cmap = face->charmaps[i];
44 unsigned pid = cmap->platform_id;
45 unsigned eid = cmap->encoding_id;
46 if (pid == 3 /*microsoft*/ && (eid == 1 /*unicode bmp*/ || eid == 10 /*full unicode*/)) {
47 FT_Set_Charmap(face, cmap);
53 int ass_font_init(FT_Library ftlibrary, void* fc_priv, ass_font_t* font, ass_font_desc_t* desc)
60 path = fontconfig_select(fc_priv, desc->family, desc->bold, desc->italic, &index);
62 error = FT_New_Face(ftlibrary, path, index, &face);
64 if (!no_more_font_messages)
65 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorOpeningFont, path, index);
66 no_more_font_messages = 1;
72 font->path = strdup(path);
75 font->desc.family = strdup(desc->family);
76 font->desc.bold = desc->bold;
77 font->desc.italic = desc->italic;
79 font->m.xx = font->m.yy = (FT_Fixed)0x10000L;
80 font->m.xy = font->m.yy = 0;
81 font->v.x = font->v.y = 0;
86 void ass_font_set_transform(ass_font_t* font, FT_Matrix* m, FT_Vector* v)
94 FT_Set_Transform(font->face, &font->m, &font->v);
97 void ass_font_set_size(ass_font_t* font, int size)
100 FT_Set_Pixel_Sizes(font->face, 0, size);
103 FT_Glyph ass_font_get_glyph(void* fontconfig_priv, ass_font_t* font, uint32_t ch)
109 index = FT_Get_Char_Index(font->face, ch);
110 error = FT_Load_Glyph(font->face, index, FT_LOAD_NO_BITMAP );
112 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorLoadingGlyph);
116 #if (FREETYPE_MAJOR > 2) || \
117 ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR >= 2)) || \
118 ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 1) && (FREETYPE_PATCH >= 10))
119 // FreeType >= 2.1.10 required
120 if (!(font->face->style_flags & FT_STYLE_FLAG_ITALIC) &&
121 (font->desc.italic > 55)) {
122 FT_GlyphSlot_Oblique(font->face->glyph);
125 error = FT_Get_Glyph(font->face->glyph, &glyph);
127 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorLoadingGlyph);
134 void ass_font_free(ass_font_t* font)
136 if (font->face) FT_Done_Face(font->face);
137 if (font->path) free(font->path);
138 if (font->desc.family) free(font->desc.family);