lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Set indent based on instrument name (issue 6457049)


From: PhilEHolmes
Subject: Set indent based on instrument name (issue 6457049)
Date: Sun, 29 Jul 2012 18:20:16 +0000

Reviewers: dak, Graham Percival,

Message:
My first attempt at coding in LilyPond.  Treat me gently...

Description:
An attempt to set the line indent based upon the instrument name.  The
simple use of instrumentName.length() to add to the indent seems odd,
but works in practice.  Not tested with different fonts, and can be
improved a lot with more font heuristics, but it's a _lot_ better than
before.  Please review my approach and coding.

Please review this at http://codereview.appspot.com/6457049/

Affected files:
  M lily/include/output-def.hh
  M lily/instrument-name-engraver.cc
  M lily/output-def.cc


Index: lily/include/output-def.hh
diff --git a/lily/include/output-def.hh b/lily/include/output-def.hh
index 3f44061513064044bf173a496e43c332ac8f8bcc..5613bdb36a426550a3b9ba0e764261c98caa4998 100644
--- a/lily/include/output-def.hh
+++ b/lily/include/output-def.hh
@@ -76,7 +76,7 @@ void assign_context_def (Output_def *m, SCM transdef);
 SCM find_context_def (Output_def const *m, SCM name);

 Interval line_dimensions_int (Output_def *def, int);
-
+void set_inst_name_len (int, int);

 Font_metric *select_encoded_font (Output_def *layout, SCM chain);
 Font_metric *select_font (Output_def *layout, SCM chain);
Index: lily/instrument-name-engraver.cc
diff --git a/lily/instrument-name-engraver.cc b/lily/instrument-name-engraver.cc index 0abc7e432955bf8306b9f7f6704b02f9e4bdd766..b752c177bfcca484c70922223465816aac4e2f0f 100644
--- a/lily/instrument-name-engraver.cc
+++ b/lily/instrument-name-engraver.cc
@@ -20,6 +20,7 @@
 #include "align-interface.hh"
 #include "axis-group-interface.hh"
 #include "engraver.hh"
+#include "output-def.hh"
 #include "page-layout-problem.hh"
 #include "pointer-group-interface.hh"
 #include "side-position-interface.hh"
@@ -112,6 +113,10 @@ Instrument_name_engraver::start_spanner ()
   text_spanner_->set_property ("text", short_text_);
   text_spanner_->set_property ("long-text", long_text_);

+  string short_inst = ly_scm2string (short_text_);
+  string long_inst = ly_scm2string (long_text_);
+  set_inst_name_len (long_inst.length(), short_inst.length());
+
   /*
     UGH, should handle this in Score_engraver.
   */
Index: lily/output-def.cc
diff --git a/lily/output-def.cc b/lily/output-def.cc
index e425dbf4f93cd2dba5fc03172017a02f04ff63b4..2a7ef91e28be1c3b3118374d5ee21722569a496e 100644
--- a/lily/output-def.cc
+++ b/lily/output-def.cc
@@ -35,6 +35,9 @@

 #include "string-convert.hh"

+int long_name_len = 0;
+int short_name_len = 0;
+
 Output_def::Output_def ()
 {
   scope_ = SCM_EOL;
@@ -254,10 +257,23 @@ Interval
 line_dimensions_int (Output_def *def, int n)
 {
   Real lw = def->get_dimension (ly_symbol2scm ("line-width"));
-  Real ind = n
-    ? def->get_dimension (ly_symbol2scm ("short-indent"))
-    : def->get_dimension (ly_symbol2scm ("indent"));
+  Real ind = 0.0;
+  if (n == 0)
+  {
+    ind = def->get_dimension (ly_symbol2scm ("indent"));
+    ind += long_name_len;
+  }
+  else
+  {
+    ind = def->get_dimension (ly_symbol2scm ("short-indent"));
+    ind += short_name_len;
+  }
   return Interval (ind, lw);
 }

-
+void
+set_inst_name_len (int long_inst_name_len, int short_inst_name_len)
+{
+    long_name_len = max (long_inst_name_len, long_name_len);
+    short_name_len = max (short_inst_name_len, short_name_len);
+}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]