On Mon, Jan 18, 2016 at 10:37 AM, Jay Anderson <horndud...@gmail.com> wrote:
> On Mon, Jan 18, 2016 at 9:59 AM, Jay Anderson <horndud...@gmail.com> wrote:
>> First issue: It appears that lilypond is dependent on pango 1.6
>> (pangoft2 - required 1.6.0, INSTALL.txt says pango 1.12 or newer so
>> I'm not totally sure what to believe.). OpenType features were added
>> in pango 1.18 (assuming I'm reading this correctly:
>> https://developer.gnome.org/pango/unstable/api-index-1-18.html). Are
>> there known issues with making this the new minimum version?
>
> I was a little wrong here. Those OpenType feature methods are
> deprecated. The supported way to set them is through PangoAttributes
> using the PANGO_ATTR_FONT_FEATURES attribute type
> (https://developer.gnome.org/pango/unstable/pango-Text-Attributes.html#PangoAttrType).
> This was added in 1.38 which was released in 2015 September
> (https://github.com/GNOME/pango/releases/tag/1.38.0). This is rather
> new (newer than my operating system includes - 1.36.3). So the minimum
> version would need to be _much_ newer than 1.18.

An update for those interested. I got something working. The attached
patch is certainly not ready to be merged, but I'm curious if the
chosen interface seems reasonable (see smallcaps.ly which is
attached). It adds a new 'font-features' property to the
font-interface (at least that's what I think I'm doing
http://www.lilypond.org/doc/v2.18/Documentation/internals/font_002dinterface).

This is using a method from pango 1.38. I'm not sure this issues
surrounding using such a new version. (It's newer than the version
included in ubuntu 15.10 for instance.)

I haven't tested it much yet, but I'm pleased with the output (tested
with Cardo - http://scholarsfonts.net/cardofnt.html).

Thanks!

-----Jay
From 51b2a6eacacf32b7adca130ebd9243ca72cbde8e Mon Sep 17 00:00:00 2001
From: Jay Anderson <horndud...@gmail.com>
Date: Sat, 30 Jan 2016 22:45:32 -0700
Subject: [PATCH] Initial work to support opentype font features.

---
 lily/font-interface.cc               |  1 +
 lily/font-metric.cc                  |  4 +++-
 lily/include/font-metric.hh          |  4 +++-
 lily/include/modified-font-metric.hh |  2 +-
 lily/include/pango-font.hh           |  4 +++-
 lily/modified-font-metric.cc         |  8 +++++---
 lily/pango-font.cc                   | 14 +++++++++++++-
 lily/text-interface.cc               | 15 ++++++++++++++-
 scm/define-grob-properties.scm       |  1 +
 9 files changed, 44 insertions(+), 9 deletions(-)

diff --git a/lily/font-interface.cc b/lily/font-interface.cc
index de787fd..5e5f18c 100644
--- a/lily/font-interface.cc
+++ b/lily/font-interface.cc
@@ -72,4 +72,5 @@ ADD_INTERFACE (Font_interface,
                "font-series "
                "font-shape "
                "font-size "
+               "font-features "
               );
diff --git a/lily/font-metric.cc b/lily/font-metric.cc
index f2b6a0e..6236a87 100644
--- a/lily/font-metric.cc
+++ b/lily/font-metric.cc
@@ -147,7 +147,9 @@ Font_metric::sub_fonts () const
 
 Stencil
 Font_metric::text_stencil (Output_def *state,
-                           const string&, bool) const
+                           const string&,
+                           bool,
+                           const string&) const
 {
   (void) state;
 
diff --git a/lily/include/font-metric.hh b/lily/include/font-metric.hh
index d74c815..0e2d15c 100644
--- a/lily/include/font-metric.hh
+++ b/lily/include/font-metric.hh
@@ -47,7 +47,9 @@ public:
   // Return stencil for given string. output_state may be modified to
   // record the font.
   virtual Stencil text_stencil (Output_def *output_state,
-                                const string &text, bool music) const;
+                                const string &text,
+                                bool music,
+                                const string &features_str) const;
 
   virtual string font_name () const;
   virtual size_t count () const;
diff --git a/lily/include/modified-font-metric.hh b/lily/include/modified-font-metric.hh
index c63c532..eab1836 100644
--- a/lily/include/modified-font-metric.hh
+++ b/lily/include/modified-font-metric.hh
@@ -26,7 +26,7 @@
 struct Modified_font_metric : public Font_metric
 {
 public:
-  Stencil text_stencil (Output_def *output_state, const string&, bool) const;
+  Stencil text_stencil (Output_def *output_state, const string&, bool, const string&) const;
   Real get_magnification () const;
 
   static SCM make_scaled_font_metric (Font_metric *fm, Real magnification);
diff --git a/lily/include/pango-font.hh b/lily/include/pango-font.hh
index ff5e630..eeaa4dd 100644
--- a/lily/include/pango-font.hh
+++ b/lily/include/pango-font.hh
@@ -59,7 +59,9 @@ public:
   Stencil pango_item_string_stencil (PangoGlyphItem const *) const;
 
   virtual Stencil text_stencil (Output_def *output_state,
-                                const string &text, bool music) const;
+                                const string &text,
+                                bool music,
+                                const string &features_str) const;
   virtual void derived_mark () const;
 };
 
diff --git a/lily/modified-font-metric.cc b/lily/modified-font-metric.cc
index d1c80b6..668f011 100644
--- a/lily/modified-font-metric.cc
+++ b/lily/modified-font-metric.cc
@@ -106,12 +106,14 @@ Modified_font_metric::derived_mark () const
 
 Stencil
 Modified_font_metric::text_stencil (Output_def *state,
-                                    const string &text, bool feta) const
+                                    const string &text,
+                                    bool feta,
+                                    const string &features_str) const
 {
   Box b;
   if (Pango_font *pf = dynamic_cast<Pango_font *> (orig_))
     {
-      Stencil stc = pf->text_stencil (state, text, feta);
+      Stencil stc = pf->text_stencil (state, text, feta, features_str);
 
       Box b = stc.extent_box ();
 
@@ -120,7 +122,7 @@ Modified_font_metric::text_stencil (Output_def *state,
       return scaled;
     }
 
-  return Font_metric::text_stencil (state, text, feta);
+  return Font_metric::text_stencil (state, text, feta, features_str);
 }
 
 Font_metric *
diff --git a/lily/pango-font.cc b/lily/pango-font.cc
index 9e3a2d3..563bc08 100644
--- a/lily/pango-font.cc
+++ b/lily/pango-font.cc
@@ -385,7 +385,9 @@ extern bool music_strings_to_paths;
 
 Stencil
 Pango_font::text_stencil (Output_def * /* state */,
-                          const string &str, bool music_string) const
+                          const string &str,
+                          bool music_string,
+                          const string &features_str) const
 {
   /*
     The text assigned to a PangoLayout is automatically divided
@@ -393,6 +395,16 @@ Pango_font::text_stencil (Output_def * /* state */,
     Bidirectional Algorithm, if necessary.
   */
   PangoLayout *layout = pango_layout_new (context_);
+
+  if (!features_str.empty())
+    {
+      PangoAttrList *list = pango_attr_list_new();
+      PangoAttribute *features_attr = pango_attr_font_features_new(features_str.c_str());
+      pango_attr_list_insert(list, features_attr);
+      pango_layout_set_attributes(layout, list);
+      pango_attr_list_unref(list);
+    }
+
   pango_layout_set_text (layout, str.c_str (), -1);
   GSList *lines = pango_layout_get_lines (layout);
 
diff --git a/lily/text-interface.cc b/lily/text-interface.cc
index 4598246..07ad6c4 100644
--- a/lily/text-interface.cc
+++ b/lily/text-interface.cc
@@ -92,8 +92,21 @@ Text_interface::interpret_string (SCM layout_smob,
                                      SCM_BOOL_F);
   SCM music_encodings = Lily::all_music_font_encodings;
 
+  SCM features = ly_chain_assoc_get (ly_symbol2scm ("font-features"),
+                                     props,
+                                     SCM_BOOL_F);
+  string features_str;
+  if (scm_is_string (features))
+    {
+      features_str = ly_scm2string (features);
+    }
+  else
+    {
+      features_str = string();
+    }
+
   bool is_music = scm_is_true (scm_memq (encoding, music_encodings));
-  return fm->text_stencil (layout, str, is_music).smobbed_copy ();
+  return fm->text_stencil (layout, str, is_music, features_str).smobbed_copy ();
 }
 
 static size_t markup_depth = 0;
diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm
index e54bdaf..f08a170 100644
--- a/scm/define-grob-properties.scm
+++ b/scm/define-grob-properties.scm
@@ -327,6 +327,7 @@ approximately 12% larger; 6@tie{}steps are exactly a factor@tie{}2
 larger.  If the context property @code{fontSize} is set, its value is
 added to this before the glyph is printed.  Fractional values are
 allowed.")
+     (font-features ,string? "Opentype features.")
      (footnote ,boolean? "Should this be a footnote or in-note?")
      (footnote-music ,ly:music? "Music creating a footnote.")
      (footnote-text ,markup? "A footnote for the grob.")
-- 
2.5.0

\version "2.19.36"

\no-point-and-click

\paper {
  #(define fonts
    (set-global-fonts
      #:music "emmentaler"
      #:brace "emmentaler"
      #:roman "Cardo"
      #:sans "sans-serif"
      #:typewriter "monospace"
      #:factor (/ staff-height pt 20)))
  tagline = ##f
}

\markup { Hello HELLO \caps Hello \fontCaps Hello }
\markup { \override #'(font-features . "smcp") Hello }
\markup { 0123456789 }
\markup { \override #'(font-features . "onum") 0123456789 }

Attachment: smallcaps.pdf
Description: Adobe PDF document

_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to