]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4868/1: Add font-index for embedding OTC fonts
authorMasamichi Hosoda <trueroad@trueroad.jp>
Mon, 30 May 2016 10:02:53 +0000 (19:02 +0900)
committerMasamichi Hosoda <trueroad@trueroad.jp>
Mon, 6 Jun 2016 13:49:04 +0000 (22:49 +0900)
This commit adds support font-index
for OpenType/CFF Collection (OTC) fonts
not only TrueType Collection (TTC) fonts.

lily/pfb-scheme.cc

index 4a1351547230abd68d06c72ad882778c09be4f88..f708c098a09329511805f27a1d6f8db4a1409112 100644 (file)
@@ -1,4 +1,5 @@
 
+#include "international.hh"
 #include "program-option.hh"
 #include "source-file.hh"
 #include "memory-stream.hh"
@@ -29,20 +30,50 @@ LY_DEFINE (ly_pfb_2_pfa, "ly:pfb->pfa",
 }
 
 LY_DEFINE (ly_otf_2_cff, "ly:otf->cff",
-           1, 0, 0, (SCM otf_file_name),
+           1, 1, 0, (SCM otf_file_name, SCM idx),
            "Convert the contents of an OTF file to a CFF file,"
-           " returning it as a string.")
+           " returning it as a string.  The optional"
+           " @var{idx} argument is useful for OpenType/CFF collections (OTC)"
+           " only; it specifies the font index within the OTC.  The default"
+           " value of @var{idx} is@tie{}0.")
 {
   LY_ASSERT_TYPE (scm_is_string, otf_file_name, 1);
 
+  int i = 0;
+  if (!SCM_UNBNDP (idx))
+    {
+      LY_ASSERT_TYPE (scm_is_integer, idx, 2);
+      i = scm_to_int (idx);
+      if (i < 0)
+        {
+          warning (_ ("font index must be non-negative, using index 0"));
+          i = 0;
+        }
+    }
+
   string file_name = ly_scm2string (otf_file_name);
   debug_output ("[" + file_name); // start message on a new line
 
-  FT_Face face = open_ft_face (file_name, 0 /* index */);
+  FT_Face face;
+  /* check whether font index is valid */
+  if (i > 0)
+    {
+      face = open_ft_face (file_name, -1);
+      if (i >= face->num_faces)
+        {
+          warning (_f ("font index %d too large for font `%s', using index 0",
+                       i, file_name.c_str ()));
+          i = 0;
+        }
+      FT_Done_Face (face);
+    }
+
+  face = open_ft_face (file_name, i);
   string table = get_otf_table (face, "CFF ");
 
   SCM asscm = scm_from_latin1_stringn ((char *) table.data (),
                                        table.length ());
+  FT_Done_Face (face);
 
   debug_output ("]", false);