comparison libass/ass_font.c @ 34011:88eebbbbd6a0

Update included libass copy to 0.9.13 release. Besides a license change to BSD license and other (minor?) fixes, this fixes possible crashes with the latest (2.4.6?) freetype release.
author reimar
date Sun, 11 Sep 2011 10:33:13 +0000
parents ac6e48baa03d
children 6e7f60f6f9d4
comparison
equal deleted inserted replaced
34010:1930c0a745df 34011:88eebbbbd6a0
1 /* 1 /*
2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com> 2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
3 * 3 *
4 * This file is part of libass. 4 * This file is part of libass.
5 * 5 *
6 * libass is free software; you can redistribute it and/or modify 6 * Permission to use, copy, modify, and distribute this software for any
7 * it under the terms of the GNU General Public License as published by 7 * purpose with or without fee is hereby granted, provided that the above
8 * the Free Software Foundation; either version 2 of the License, or 8 * copyright notice and this permission notice appear in all copies.
9 * (at your option) any later version.
10 * 9 *
11 * libass is distributed in the hope that it will be useful, 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * GNU General Public License for more details. 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * You should have received a copy of the GNU General Public License along 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * with libass; if not, write to the Free Software Foundation, Inc., 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */ 17 */
20 18
21 #include "config.h" 19 #include "config.h"
22 20
23 #include <inttypes.h> 21 #include <inttypes.h>
446 face_idx = add_face(fontconfig_priv, font, ch); 444 face_idx = add_face(fontconfig_priv, font, ch);
447 if (face_idx >= 0) { 445 if (face_idx >= 0) {
448 face = font->faces[face_idx]; 446 face = font->faces[face_idx];
449 index = FT_Get_Char_Index(face, ch); 447 index = FT_Get_Char_Index(face, ch);
450 if (index == 0 && face->num_charmaps > 0) { 448 if (index == 0 && face->num_charmaps > 0) {
449 int i;
451 ass_msg(font->library, MSGL_WARN, 450 ass_msg(font->library, MSGL_WARN,
452 "Glyph 0x%X not found, falling back to first charmap", ch); 451 "Glyph 0x%X not found, broken font? Trying all charmaps", ch);
453 FT_CharMap cur = face->charmap; 452 for (i = 0; i < face->num_charmaps; i++) {
454 FT_Set_Charmap(face, face->charmaps[0]); 453 FT_Set_Charmap(face, face->charmaps[i]);
455 index = FT_Get_Char_Index(face, ch); 454 if ((index = FT_Get_Char_Index(face, ch)) != 0) break;
456 FT_Set_Charmap(face, cur); 455 }
457 } 456 }
458 if (index == 0) { 457 if (index == 0) {
459 ass_msg(font->library, MSGL_ERR, 458 ass_msg(font->library, MSGL_ERR,
460 "Glyph 0x%X not found in font for (%s, %d, %d)", 459 "Glyph 0x%X not found in font for (%s, %d, %d)",
461 ch, font->desc.family, font->desc.bold, 460 ch, font->desc.family, font->desc.bold,
602 sum += x * (points[start].y - y) - y * (points[start].x - x); 601 sum += x * (points[start].y - y) - y * (points[start].x - x);
603 return sum > 0; 602 return sum > 0;
604 } 603 }
605 604
606 /** 605 /**
607 * \brief Fix-up stroker result for huge borders by removing inside contours 606 * \brief Apply fixups to please the FreeType stroker and improve the
608 * that would reverse in size 607 * rendering result, especially in case the outline has some anomalies.
608 * At the moment, the following fixes are done:
609 *
610 * 1. Reverse contours that have "inside" winding direction but are not
611 * contained in any other contours' cbox.
612 * 2. Remove "inside" contours depending on border size, so that large
613 * borders do not reverse the winding direction, which leads to "holes"
614 * inside the border. The inside will be filled by the border of the
615 * outside contour anyway in this case.
616 *
617 * \param outline FreeType outline, modified in-place
618 * \param border_x border size, x direction, d6 format
619 * \param border_x border size, y direction, d6 format
609 */ 620 */
610 void fix_freetype_stroker(FT_OutlineGlyph glyph, int border_x, int border_y) 621 void fix_freetype_stroker(FT_OutlineGlyph glyph, int border_x, int border_y)
611 { 622 {
612 int nc = glyph->outline.n_contours; 623 int nc = glyph->outline.n_contours;
613 int begin, stop; 624 int begin, stop;
671 modified = 1; 682 modified = 1;
672 } 683 }
673 } 684 }
674 } 685 }
675 686
676 // zero-out contours that can be removed; much simpler than copying 687 // if we need to modify the outline, rewrite it and skip
688 // the contours that we determined should be removed.
677 if (modified) { 689 if (modified) {
690 FT_Outline *outline = &glyph->outline;
691 int p = 0, c = 0;
678 for (i = 0; i < nc; i++) { 692 for (i = 0; i < nc; i++) {
679 if (valid_cont[i]) 693 if (!valid_cont[i])
680 continue; 694 continue;
681 begin = (i == 0) ? 0 : glyph->outline.contours[i - 1] + 1; 695 begin = (i == 0) ? 0 : glyph->outline.contours[i - 1] + 1;
682 stop = glyph->outline.contours[i]; 696 stop = glyph->outline.contours[i];
683 for (j = begin; j <= stop; j++) { 697 for (j = begin; j <= stop; j++) {
684 glyph->outline.points[j].x = 0; 698 outline->points[p].x = outline->points[j].x;
685 glyph->outline.points[j].y = 0; 699 outline->points[p].y = outline->points[j].y;
686 glyph->outline.tags[j] = 0; 700 outline->tags[p] = outline->tags[j];
687 } 701 p++;
688 } 702 }
703 outline->contours[c] = p - 1;
704 c++;
705 }
706 outline->n_points = p;
707 outline->n_contours = c;
689 } 708 }
690 709
691 free(boxes); 710 free(boxes);
692 free(valid_cont); 711 free(valid_cont);
693 } 712 }