X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fttf.cc;h=9f5fbfb8a29a408fe75d8c380a839900c5854e62;hb=6eeb079ba4ed77997316262c842b215016dfe1e7;hp=78530d00da6ae666984bd5d0e5c07773d9356aad;hpb=b0660cc03f592bdd191e59b8b3f9cabc534dddfb;p=lilypond.git diff --git a/lily/ttf.cc b/lily/ttf.cc index 78530d00da..9f5fbfb8a2 100644 --- a/lily/ttf.cc +++ b/lily/ttf.cc @@ -15,6 +15,25 @@ #include "warn.hh" #include "lily-guile.hh" #include "main.hh" +#include "open-type-font.hh" + + +Index_to_charcode_map +make_index_to_charcode_map (FT_Face face) +{ + Index_to_charcode_map m; + FT_ULong charcode; + FT_UInt gindex; + + FT_CharMap current_cmap = face->charmap; + FT_Select_Charmap(face, FT_ENCODING_UNICODE); + for (charcode = FT_Get_First_Char (face, &gindex); gindex != 0; + charcode = FT_Get_Next_Char (face, charcode, &gindex)) + m[gindex] = charcode; + FT_Set_Charmap (face, current_cmap); + + return m; +} /* Based on ttfps by Juliusz Chroboczek @@ -86,9 +105,9 @@ print_header (void *out, FT_Face face) #define CHUNKSIZE 65534 static void -print_body (void *out, String name) +print_body (void *out, string name) { - FILE *fd = fopen (name.to_str0 (), "rb"); + FILE *fd = fopen (name.c_str (), "rb"); static char xdigits[] = "0123456789ABCDEF"; @@ -132,27 +151,45 @@ print_trailer (void *out, lily_cookie_fprintf (out, "/CharStrings %d dict dup begin\n", mp->numGlyphs); + Index_to_charcode_map ic_map (make_index_to_charcode_map (face)); - if (face->face_flags & FT_FACE_FLAG_GLYPH_NAMES) - for (int i = 0; i < mp->numGlyphs; i++) - { - FT_Error error = FT_Get_Glyph_Name (face, i, glyph_name, - GLYPH_NAME_LEN); - if (error) - programming_error ("print_trailer(): FT_Get_Glyph_Name() returned error"); - else - lily_cookie_fprintf (out, "/%s %d def ", glyph_name, i); + int output_count = 0; + for (int i = 0; i < mp->numGlyphs; i++) + { + glyph_name[0] = 0; + if (face->face_flags & FT_FACE_FLAG_GLYPH_NAMES) + { + FT_Error error = FT_Get_Glyph_Name (face, i, glyph_name, + GLYPH_NAME_LEN); + if (error) + { + programming_error ("print_trailer(): FT_Get_Glyph_Name() returned error"); + glyph_name[0] = 0; + } + } - if (! (i % 5)) - lily_cookie_fprintf (out, "\n"); - } + if (!glyph_name[0] && ic_map.find (i) != ic_map.end ()) + { + FT_ULong ucode = ic_map[i]; + get_unicode_name (glyph_name, ucode); + } + + if (glyph_name[0]) + { + lily_cookie_fprintf (out, "/%s %d def ", glyph_name, i); + output_count ++; + } + + if (! (output_count % 5)) + lily_cookie_fprintf (out, "\n"); + } lily_cookie_fprintf (out, "end readonly def\n"); lily_cookie_fprintf (out, "FontName currentdict end definefont pop\n"); } static void -create_type42_font (void *out, String name) +create_type42_font (void *out, string name) { FT_Face face = open_ft_face (name); @@ -163,39 +200,6 @@ create_type42_font (void *out, String name) FT_Done_Face (face); } -LY_DEFINE (ly_font_glyph_list, "ly:font-glyph-list", - 1, 0, 0, (SCM font_file_name), - "Return a list of glyphnames for @var{font-file-name}.") -{ - SCM_ASSERT_TYPE (scm_is_string (font_file_name), font_file_name, - SCM_ARG1, __FUNCTION__, "string"); - - String file_name = ly_scm2string (font_file_name); - if (be_verbose_global) - progress_indication ("[" + file_name); - - SCM retval = SCM_EOL; - SCM *tail = &retval; - - FT_Face face = open_ft_face (file_name); - for (int i = 0; i < face->num_glyphs; i++) - { - const int len = 256; - char name[len]; - int code = FT_Get_Glyph_Name (face, i, name, len); - if (code) - warning (_f ("FT_Get_Glyph_Name() returned error: %d", code)); - - *tail = scm_cons (scm_makfrom0str (name), SCM_EOL); - tail = SCM_CDRLOC (*tail); - } - - FT_Done_Face (face); - - if (be_verbose_global) - progress_indication ("]"); - return retval; -} LY_DEFINE (ly_ttf_ps_name, "ly:ttf-ps-name", 1, 0, 0, (SCM ttf_file_name), @@ -203,19 +207,20 @@ LY_DEFINE (ly_ttf_ps_name, "ly:ttf-ps-name", { SCM_ASSERT_TYPE (scm_is_string (ttf_file_name), ttf_file_name, SCM_ARG1, __FUNCTION__, "string"); - String file_name = ly_scm2string (ttf_file_name); + string file_name = ly_scm2string (ttf_file_name); if (be_verbose_global) progress_indication ("[" + file_name); FT_Face face = open_ft_face (file_name); char const *ps_name_str0 = FT_Get_Postscript_Name (face); + SCM ps_name = scm_makfrom0str (ps_name_str0 ? ps_name_str0 : ""); FT_Done_Face (face); if (be_verbose_global) progress_indication ("]"); - - return scm_makfrom0str (ps_name_str0 ? ps_name_str0 : ""); + + return ps_name; } @@ -228,7 +233,7 @@ LY_DEFINE (ly_ttf_to_pfa, "ly:ttf->pfa", SCM_ASSERT_TYPE (scm_is_string (ttf_file_name), ttf_file_name, SCM_ARG1, __FUNCTION__, "string"); - String file_name = ly_scm2string (ttf_file_name); + string file_name = ly_scm2string (ttf_file_name); if (be_verbose_global) progress_indication ("[" + file_name);