/* * \brief Finish a drawing. This only sets the horizontal advance according * to the outline's bbox at the moment. */ static void drawing_finish(ASS_Drawing *drawing, int raw_mode) { int i, offset; FT_BBox bbox = drawing->cbox; FT_Outline *ol = &drawing->outline; // Close the last contour drawing_close_shape(drawing); if (drawing->library) ass_msg(drawing->library, MSGL_V, "Parsed drawing with %d points and %d contours", ol->n_points, ol->n_contours); if (raw_mode) return; drawing->advance.x = bbox.xMax - bbox.xMin; drawing->desc = double_to_d6(-drawing->pbo * drawing->scale_y); drawing->asc = bbox.yMax - bbox.yMin + drawing->desc; // Place it onto the baseline offset = (bbox.yMax - bbox.yMin) + double_to_d6(-drawing->pbo * drawing->scale_y); for (i = 0; i < ol->n_points; i++) ol->points[i].y += offset; }
static void face_set_size(FT_Face face, double size) { #if (FREETYPE_MAJOR > 2) || ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR > 1)) TT_HoriHeader *hori = FT_Get_Sfnt_Table(face, ft_sfnt_hhea); TT_OS2 *os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2); double mscale = 1.; FT_Size_RequestRec rq; FT_Size_Metrics *m = &face->size->metrics; // VSFilter uses metrics from TrueType OS/2 table // The idea was borrowed from asa (http://asa.diac24.net) if (hori && os2) { int hori_height = hori->Ascender - hori->Descender; int os2_height = os2->usWinAscent + os2->usWinDescent; if (hori_height && os2_height) mscale = (double)hori_height / os2_height; } memset(&rq, 0, sizeof(rq)); rq.type = FT_SIZE_REQUEST_TYPE_REAL_DIM; rq.width = 0; rq.height = double_to_d6(size * mscale); rq.horiResolution = rq.vertResolution = 0; FT_Request_Size(face, &rq); m->ascender /= mscale; m->descender /= mscale; m->height /= mscale; #else FT_Set_Char_Size(face, 0, double_to_d6(size), 0, 0); #endif }
void ass_face_set_size(FT_Face face, double size) { TT_HoriHeader *hori = FT_Get_Sfnt_Table(face, ft_sfnt_hhea); TT_OS2 *os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2); double mscale = 1.; FT_Size_RequestRec rq; FT_Size_Metrics *m = &face->size->metrics; // VSFilter uses metrics from TrueType OS/2 table // The idea was borrowed from asa (http://asa.diac24.net) if (os2) { int ft_height = 0; if (hori) ft_height = hori->Ascender - hori->Descender; if (!ft_height) ft_height = os2->sTypoAscender - os2->sTypoDescender; /* sometimes used for signed values despite unsigned in spec */ int os2_height = (short)os2->usWinAscent + (short)os2->usWinDescent; if (ft_height && os2_height) mscale = (double) ft_height / os2_height; } memset(&rq, 0, sizeof(rq)); rq.type = FT_SIZE_REQUEST_TYPE_REAL_DIM; rq.width = 0; rq.height = double_to_d6(size * mscale); rq.horiResolution = rq.vertResolution = 0; FT_Request_Size(face, &rq); m->ascender /= mscale; m->descender /= mscale; m->height /= mscale; }
/* * \brief Finish a drawing. This only sets the horizontal advance according * to the glyph's bbox at the moment. */ static void drawing_finish(ASS_Drawing *drawing, int raw_mode) { int i, offset; FT_BBox bbox; FT_Outline *ol = &drawing->glyph->outline; // Close the last contour drawing_close_shape(drawing); #if 0 // Dump points for (i = 0; i < ol->n_points; i++) { printf("point (%d, %d)\n", (int) ol->points[i].x, (int) ol->points[i].y); } // Dump contours for (i = 0; i < ol->n_contours; i++) printf("contour %d\n", ol->contours[i]); #endif ass_msg(drawing->library, MSGL_V, "Parsed drawing with %d points and %d contours", ol->n_points, ol->n_contours); if (raw_mode) return; FT_Outline_Get_CBox(&drawing->glyph->outline, &bbox); drawing->glyph->root.advance.x = d6_to_d16(bbox.xMax - bbox.xMin); drawing->desc = double_to_d6(-drawing->pbo * drawing->scale_y); drawing->asc = bbox.yMax - bbox.yMin + drawing->desc; // Place it onto the baseline offset = (bbox.yMax - bbox.yMin) + double_to_d6(-drawing->pbo * drawing->scale_y); for (i = 0; i < ol->n_points; i++) ol->points[i].y += offset; }