X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fpango-select.cc;h=a0832d4369292e081e3f09df5ec133d2c6df55bb;hb=9b5bd8f54b358e725566bae515ccc6f74f292398;hp=402f7881464f677512184057523b740e0195fa29;hpb=cccee40bb3a13b6c230fa98a8ca61f7c526d5f66;p=lilypond.git diff --git a/lily/pango-select.cc b/lily/pango-select.cc index 402f788146..a0832d4369 100644 --- a/lily/pango-select.cc +++ b/lily/pango-select.cc @@ -1,28 +1,37 @@ /* - pango-select.cc -- implement lily font selection for Pango_fonts. + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 2004--2011 Han-Wen Nienhuys - (c) 2004 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 #include "dimensions.hh" #include "all-font-metrics.hh" #include "output-def.hh" #include "pango-font.hh" -Font_metric * -select_pango_font (Output_def *layout, SCM chain) +PangoFontDescription * +properties_to_pango_description (SCM chain, Real text_size) { - SCM name = ly_chain_assoc (ly_symbol2scm ("font-name"), chain); + SCM name = ly_chain_assoc_get (ly_symbol2scm ("font-name"), chain, SCM_BOOL_F); PangoFontDescription *description = 0; - if (scm_is_pair (name) && scm_is_string (scm_cdr (name))) + if (scm_is_string (name)) { - String name_str = ly_scm2string (scm_cdr (name)); - description = pango_font_description_from_string (name_str.to_str0 ()); + string name_str = ly_scm2string (name); + description = pango_font_description_from_string (name_str.c_str ()); } else { @@ -30,45 +39,50 @@ select_pango_font (Output_def *layout, SCM chain) SCM_BOOL_F); SCM variant = ly_chain_assoc_get (ly_symbol2scm ("font-shape"), chain, SCM_BOOL_F); - + SCM style = ly_chain_assoc_get (ly_symbol2scm ("font-shape"), chain, SCM_BOOL_F); SCM weight = ly_chain_assoc_get (ly_symbol2scm ("font-series"), chain, SCM_BOOL_F); - + description = symbols_to_pango_font_description (family, style, variant, weight, SCM_BOOL_F); } - Real step = robust_scm2double (ly_symbol2scm ("font-size"), 0.0); - Real size = layout->get_dimension (ly_symbol2scm ("text-font-size")) - * pow (2.0, step / 6.0) * point_constant; - pango_font_description_set_size (description, - gint (size * PANGO_SCALE)); - - Font_metric * fm = all_fonts_global->find_pango_font (description); + Real step = robust_scm2double (ly_chain_assoc_get (ly_symbol2scm ("font-size"), chain, SCM_BOOL_F), + 0.0); + Real size = text_size * pow (2.0, step / 6.0); - return find_scaled_font (layout, fm, 1.0, - ly_symbol2scm ("latin1"), - ly_symbol2scm ("latin1")); + pango_font_description_set_size (description, gint (size * PANGO_SCALE)); + return description; } +Font_metric * +select_pango_font (Output_def *layout, SCM chain) +{ + PangoFontDescription *pfd + = properties_to_pango_description (chain, + point_constant + * layout->get_dimension (ly_symbol2scm ("text-font-size"))); + + char *str = pango_font_description_to_string (pfd); + SCM scm_str = scm_from_locale_string (str); + g_free (str); + pango_font_description_free (pfd); + + return find_pango_font (layout, scm_str, 1.0); +} PangoStyle symbol_to_pango_style (SCM style) { PangoStyle pstyle = PANGO_STYLE_NORMAL; if (style == ly_symbol2scm ("italic")) - { - pstyle = PANGO_STYLE_NORMAL; - } + pstyle = PANGO_STYLE_ITALIC; else if (style == ly_symbol2scm ("oblique") - || style == ly_symbol2scm ("slanted") - ) - { - pstyle = PANGO_STYLE_OBLIQUE; - } + || style == ly_symbol2scm ("slanted")) + pstyle = PANGO_STYLE_OBLIQUE; return pstyle; } @@ -76,39 +90,26 @@ symbol_to_pango_style (SCM style) PangoVariant symbol_to_pango_variant (SCM variant) { - PangoVariant pvariant; + PangoVariant pvariant = PANGO_VARIANT_NORMAL; if (variant == ly_symbol2scm ("caps")) - { - pvariant = PANGO_VARIANT_SMALL_CAPS; - } + pvariant = PANGO_VARIANT_SMALL_CAPS; return pvariant; } - PangoWeight symbol_to_pango_weight (SCM weight) { PangoWeight pw = PANGO_WEIGHT_NORMAL; if (weight == ly_symbol2scm ("bold")) - { - pw = PANGO_WEIGHT_BOLD; - } + pw = PANGO_WEIGHT_BOLD; if (weight == ly_symbol2scm ("heavy")) - { - pw = PANGO_WEIGHT_HEAVY; - } + pw = PANGO_WEIGHT_HEAVY; if (weight == ly_symbol2scm ("ultrabold")) - { - pw = PANGO_WEIGHT_ULTRABOLD; - } + pw = PANGO_WEIGHT_ULTRABOLD; if (weight == ly_symbol2scm ("light")) - { - pw = PANGO_WEIGHT_LIGHT; - } + pw = PANGO_WEIGHT_LIGHT; if (weight == ly_symbol2scm ("ultralight")) - { - pw = PANGO_WEIGHT_ULTRALIGHT; - } + pw = PANGO_WEIGHT_ULTRALIGHT; return pw; } @@ -119,37 +120,38 @@ symbol_to_pango_stretch (SCM) // stretch) PangoStretch ps = PANGO_STRETCH_NORMAL; /* - // TODO - + // TODO + PANGO_STRETCH_ULTRA_CONDENSED, PANGO_STRETCH_EXTRA_CONDENSED, PANGO_STRETCH_CONDENSED, PANGO_STRETCH_SEMI_CONDENSED, - + PANGO_STRETCH_SEMI_EXPANDED, PANGO_STRETCH_EXPANDED, PANGO_STRETCH_EXTRA_EXPANDED, PANGO_STRETCH_ULTRA_EXPANDED - */ + */ return ps; } - - -PangoFontDescription* -symbols_to_pango_font_description(SCM family, - SCM style, - SCM variant, - SCM weight, - SCM stretch) +PangoFontDescription * +symbols_to_pango_font_description (SCM family, + SCM style, + SCM variant, + SCM weight, + SCM stretch) { - PangoFontDescription * description = pango_font_description_new (); + PangoFontDescription *description = pango_font_description_new (); + + string family_str = "roman"; + if (scm_is_symbol (family)) + family_str = ly_symbol2string (family); + else if (scm_is_string (family)) + family_str = ly_scm2string (family); - String family_str = scm_is_symbol (family) - ? ly_symbol2string (family) - : String("roman"); pango_font_description_set_family (description, - family_str.to_str0 ()); + family_str.c_str ()); pango_font_description_set_style (description, symbol_to_pango_style (style)); pango_font_description_set_variant (description,