X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Foutput-def-scheme.cc;h=65673c8a9ec71a6238104e70621f1313b224f810;hb=a6a51abfd0195a3cf7d6ea095cf69808852f21ce;hp=fbd32e9230d6b759ab8f7d50205f3926187cf4be;hpb=75eebcb49e52d296b1da3e1074e0825d2c780db4;p=lilypond.git diff --git a/lily/output-def-scheme.cc b/lily/output-def-scheme.cc index fbd32e9230..65673c8a9e 100644 --- a/lily/output-def-scheme.cc +++ b/lily/output-def-scheme.cc @@ -1,34 +1,47 @@ /* - output-def-scheme.cc -- implement Output_def bindings + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 2005--2015 Han-Wen Nienhuys - (c) 2005--2006 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 "font-metric.hh" +#include "output-def.hh" + #include "pango-font.hh" #include "modified-font-metric.hh" -#include "output-def.hh" #include "ly-module.hh" #include "context-def.hh" +#include "lily-parser.hh" -LY_DEFINE (ly_layout_lookup, "ly:output-def-lookup", - 2, 1, 0, (SCM pap, SCM sym, SCM def), - "Lookup @var{sym} in @var{pap}. " - "Return the value or @var{def} (which defaults to @code{'()}) if undefined.") +LY_DEFINE (ly_output_def_lookup, "ly:output-def-lookup", + 2, 1, 0, (SCM def, SCM sym, SCM val), + "Return the value of @var{sym} in output definition @var{def}" + " (e.g., @code{\\paper}). If no value is found, return" + " @var{val} or @code{'()} if @var{val} is undefined.") { - Output_def *op = unsmob_output_def (pap); - SCM_ASSERT_TYPE (op, pap, SCM_ARG1, __FUNCTION__, "Output_def"); - SCM_ASSERT_TYPE (scm_is_symbol (sym), sym, SCM_ARG2, __FUNCTION__, "symbol"); + LY_ASSERT_SMOB (Output_def, def, 1); + Output_def *op = unsmob (def); + LY_ASSERT_TYPE (ly_is_symbol, sym, 2); SCM answer = op->lookup_variable (sym); - if (answer == SCM_UNDEFINED) + if (SCM_UNBNDP (answer)) { - if (def == SCM_UNDEFINED) - def = SCM_EOL; + if (SCM_UNBNDP (val)) + val = SCM_EOL; - answer = def; + answer = val; } return answer; @@ -36,28 +49,39 @@ LY_DEFINE (ly_layout_lookup, "ly:output-def-lookup", LY_DEFINE (ly_output_def_scope, "ly:output-def-scope", 1, 0, 0, (SCM def), - "Get the variable scope inside @var{def}.") + "Return the variable scope inside @var{def}.") { - Output_def *op = unsmob_output_def (def); - SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition"); + LY_ASSERT_SMOB (Output_def, def, 1); + Output_def *op = unsmob (def); return op->scope_; } LY_DEFINE (ly_output_def_parent, "ly:output-def-parent", 1, 0, 0, (SCM def), - "Get the parent output-def of @var{def}.") + "Return the parent output definition of @var{def}.") { - Output_def *op = unsmob_output_def (def); - SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition"); + LY_ASSERT_SMOB (Output_def, def, 1); + Output_def *op = unsmob (def); return op->parent_ ? op->parent_->self_scm () : SCM_EOL; } +LY_DEFINE (ly_output_def_set_variable_x, "ly:output-def-set-variable!", + 3, 0, 0, (SCM def, SCM sym, SCM val), + "Set an output definition @var{def} variable @var{sym} to @var{val}.") +{ + LY_ASSERT_SMOB (Output_def, def, 1); + Output_def *output_def = unsmob (def); + LY_ASSERT_TYPE (ly_is_symbol, sym, 2); + output_def->set_variable (sym, val); + return SCM_UNSPECIFIED; +} + LY_DEFINE (ly_output_def_clone, "ly:output-def-clone", 1, 0, 0, (SCM def), - "Clone @var{def}.") + "Clone output definition @var{def}.") { - Output_def *op = unsmob_output_def (def); - SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition"); + LY_ASSERT_SMOB (Output_def, def, 1); + Output_def *op = unsmob (def); Output_def *clone = op->clone (); return clone->unprotect (); @@ -67,85 +91,103 @@ LY_DEFINE (ly_output_description, "ly:output-description", 1, 0, 0, (SCM output_def), "Return the description of translators in @var{output-def}.") { - Output_def *id = unsmob_output_def (output_def); + LY_ASSERT_SMOB (Output_def, output_def, 1); - SCM al = ly_module2alist (id->scope_); + Output_def *id = unsmob (output_def); + SCM al = ly_module_2_alist (id->scope_); SCM ell = SCM_EOL; for (SCM s = al; scm_is_pair (s); s = scm_cdr (s)) { - Context_def *td = unsmob_context_def (scm_cdar (s)); + Context_def *td = unsmob (scm_cdar (s)); SCM key = scm_caar (s); - if (td && key == td->get_context_name ()) - ell = scm_cons (scm_cons (key, td->to_alist ()), ell); + if (td && scm_is_eq (key, td->get_context_name ())) + ell = scm_cons (scm_cons (key, td->to_alist ()), ell); } return ell; } -LY_DEFINE (ly_layout_def_p, "ly:layout-def?", - 1, 0, 0, (SCM def), - "Is @var{def} a layout definition?") +LY_DEFINE (ly_output_find_context_def, "ly:output-find-context-def", + 1, 1, 0, (SCM output_def, SCM context_name), + "Return an alist of all context defs (matching @var{context-name}" + "if given) in @var{output-def}.") { - return ly_bool2scm (unsmob_output_def (def)); + LY_ASSERT_SMOB (Output_def, output_def, 1); + if (!SCM_UNBNDP (context_name)) + LY_ASSERT_TYPE (ly_is_symbol, context_name, 2); + + Output_def *id = unsmob (output_def); + + SCM al = ly_module_2_alist (id->scope_); + SCM ell = SCM_EOL; + for (SCM s = al; scm_is_pair (s); s = scm_cdr (s)) + { + SCM p = scm_car (s); + Context_def *td = unsmob (scm_cdr (p)); + if (td && scm_is_eq (scm_car (p), td->get_context_name ()) + && (SCM_UNBNDP (context_name) || td->is_alias (context_name))) + ell = scm_cons (p, ell); + } + return ell; } +const char +* const Output_def::type_p_name_ = "ly:output-def?"; + LY_DEFINE (ly_paper_outputscale, "ly:paper-outputscale", - 1, 0, 0, (SCM bp), - "Get outputscale for BP.") + 1, 0, 0, (SCM def), + "Return the output-scale for output definition @var{def}.") { - Output_def *b = unsmob_output_def (bp); - SCM_ASSERT_TYPE (b, bp, SCM_ARG1, __FUNCTION__, "paper"); + LY_ASSERT_SMOB (Output_def, def, 1); + Output_def *b = unsmob (def); return scm_from_double (output_scale (b)); } LY_DEFINE (ly_make_output_def, "ly:make-output-def", 0, 0, 0, (), - "Make a output def.") + "Make an output definition.") { Output_def *bp = new Output_def; return bp->unprotect (); } -LY_DEFINE (ly_paper_get_font, "ly:paper-get-font", 2, 0, 0, - (SCM paper_smob, SCM chain), - - "Return a font metric satisfying the font-qualifiers " - "in the alist chain @var{chain}.\n" - "(An alist chain is a list of alists, " - "containing grob properties).\n") +LY_DEFINE (ly_paper_get_font, "ly:paper-get-font", + 2, 0, 0, (SCM def, SCM chain), + "Find a font metric in output definition @var{def} satisfying" + " the font-qualifiers in alist chain @var{chain}, and return" + " it. (An alist chain is a list of alists, containing grob" + " properties.)") { - Output_def *paper = unsmob_output_def (paper_smob); - SCM_ASSERT_TYPE (paper, paper_smob, SCM_ARG1, - __FUNCTION__, "paper definition"); + LY_ASSERT_SMOB (Output_def, def, 1); + Output_def *paper = unsmob (def); Font_metric *fm = select_font (paper, chain); return fm->self_scm (); } -LY_DEFINE (ly_paper_get_number, "ly:paper-get-number", 2, 0, 0, - (SCM layout_smob, SCM name), - "Return the layout variable @var{name}.") +LY_DEFINE (ly_paper_get_number, "ly:paper-get-number", + 2, 0, 0, (SCM def, SCM sym), + "Return the value of variable @var{sym} in output definition" + " @var{def} as a double.") { - Output_def *layout = unsmob_output_def (layout_smob); - SCM_ASSERT_TYPE (layout, layout_smob, SCM_ARG1, - __FUNCTION__, "layout definition"); - return scm_from_double (layout->get_dimension (name)); + LY_ASSERT_SMOB (Output_def, def, 1); + Output_def *layout = unsmob (def); + return scm_from_double (layout->get_dimension (sym)); } LY_DEFINE (ly_paper_fonts, "ly:paper-fonts", - 1, 0, 0, - (SCM bp), - "Return fonts from the @code{\\paper} block @var{bp}.") + 1, 0, 0, (SCM def), + "Return a list containing the fonts from output definition" + " @var{def} (e.g., @code{\\paper}).") { - Output_def *b = unsmob_output_def (bp); - - SCM_ASSERT_TYPE (b, bp, SCM_ARG1, __FUNCTION__, "paper"); + LY_ASSERT_SMOB (Output_def, def, 1); + Output_def *b = unsmob (def); SCM tab1 = b->lookup_variable (ly_symbol2scm ("scaled-fonts")); SCM tab2 = b->lookup_variable (ly_symbol2scm ("pango-fonts")); SCM alist1 = SCM_EOL; - if (scm_hash_table_p (tab1) == SCM_BOOL_T) + if (to_boolean (scm_hash_table_p (tab1))) { alist1 = scm_append (ly_alist_vals (ly_hash2alist (tab1))); @@ -153,7 +195,7 @@ LY_DEFINE (ly_paper_fonts, "ly:paper-fonts", } SCM alist2 = SCM_EOL; - if (scm_hash_table_p (tab2) == SCM_BOOL_T) + if (scm_is_true (scm_hash_table_p (tab2))) { // strip original-fonts/pango-font-descriptions alist2 = scm_append (ly_alist_vals (ly_hash2alist (tab2))); @@ -168,7 +210,7 @@ LY_DEFINE (ly_paper_fonts, "ly:paper-fonts", { SCM entry = scm_car (s); - Font_metric *fm = unsmob_metrics (entry); + Font_metric *fm = unsmob (entry); if (dynamic_cast (fm) || dynamic_cast (fm))