From aeba1aa3fb93c1ac5dbe25ffdbc45ca28e7cce74 Mon Sep 17 00:00:00 2001 From: David Nalesnik Date: Wed, 26 Aug 2015 09:46:07 -0500 Subject: [PATCH] Scheme function to draw lines based on grob layout A number of C++ stencil callbacks use Line_interface::line to draw lines based on line-interface properties defining a particular grob. This allows control of aspects such as line style (based on the setting of Grob.style) and fine-tuning of dashed lines through dash-fraction and dash-period. This patch gives access to Line_interface::line in Scheme through the callback ly:line-interface::line. (The simpler name ly:line was ruled out in an effort to distinguish it from other functions such as ly:bracket and ly:circle which do not take a grob argument.) Users will be able to create custom stencils with more functionality (including rewriting certain C++ callbacks--such as Hairpin::print--to allow for easy modifications without loss of capability.) --- lily/line-interface-scheme.cc | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 lily/line-interface-scheme.cc diff --git a/lily/line-interface-scheme.cc b/lily/line-interface-scheme.cc new file mode 100644 index 0000000..dee6a15 --- /dev/null +++ b/lily/line-interface-scheme.cc @@ -0,0 +1,44 @@ +/* + This file is part of LilyPond, the GNU music typesetter. + + Copyright (C) 2010--2015 Han-Wen Nienhuys + + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . +*/ + +#include "line-interface.hh" + +#include "stencil.hh" +#include "grob.hh" + +LY_DEFINE (ly_line_interface__line, "ly:line-interface::line", + 5, 0, 0, (SCM grob, SCM startx, SCM starty, SCM endx, SCM endy), + "Make a line using layout information from grob @var{grob}.") +{ + LY_ASSERT_SMOB (Grob, grob, 1); + + Grob *me = unsmob (grob); + + LY_ASSERT_TYPE (scm_is_number, startx, 2); + LY_ASSERT_TYPE (scm_is_number, starty, 3); + LY_ASSERT_TYPE (scm_is_number, endx, 4); + LY_ASSERT_TYPE (scm_is_number, endy, 5); + + Offset from = Offset (scm_to_double (startx), scm_to_double (starty)); + Offset to = Offset (scm_to_double (endx), scm_to_double (endy)); + + Stencil stil = Line_interface::line (me, from, to); + + return stil.smobbed_copy (); +} -- 1.9.1