/*
This file is part of LilyPond, the GNU music typesetter.
- Copyright (C) 2004--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ Copyright (C) 2004--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
LilyPond is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
*/
-#define PANGO_ENABLE_BACKEND // ugh, why necessary?
+// Necessary for supporting pango_context_new() and
+// pango_context_set_font_map() in Pango < 1.22
+#define PANGO_ENABLE_BACKEND
+
#include <pango/pangoft2.h>
#include <freetype/ftxf86.h>
#if HAVE_PANGO_FT2
#include "stencil.hh"
-Pango_font::Pango_font (PangoFT2FontMap * /* fontmap */,
+Pango_font::Pango_font (PangoFT2FontMap *fontmap,
PangoFontDescription const *description,
Real output_scale)
{
physical_font_tab_ = scm_c_make_hash_table (11);
PangoDirection pango_dir = PANGO_DIRECTION_LTR;
- context_ = pango_ft2_get_context (PANGO_RESOLUTION,
- PANGO_RESOLUTION);
+ context_ = pango_context_new ();
+ pango_context_set_font_map (context_, PANGO_FONT_MAP (fontmap));
pango_description_ = pango_font_description_copy (description);
attribute_list_ = pango_attr_list_new ();
PangoRectangle ink_rect;
pango_glyph_string_extents (pgs, pa->font, &ink_rect, &logical_rect);
- PangoFcFont *fcfont = G_TYPE_CHECK_INSTANCE_CAST (pa->font,
- PANGO_TYPE_FC_FONT,
- PangoFcFont);
+ PangoFcFont *fcfont = PANGO_FC_FONT (pa->font);
FT_Face ftface = pango_fc_font_lock_face (fcfont);
PangoGlyph pg = pgi->glyph;
PangoGlyphGeometry ggeo = pgi->geometry;
- /* For zero-width characters, do not perform a glyph lookup */
- if (!ggeo.width)
+ /*
+ Zero-width characters are valid Unicode characters,
+ but glyph lookups need to be skipped.
+ */
+ if (!(pg ^ PANGO_GLYPH_EMPTY))
continue;
glyph_name[0] = '\0';
}
Stencil
-Pango_font::word_stencil (string str, bool feta) const
+Pango_font::word_stencil (string str, bool music_string) const
{
- return text_stencil (str, feta, true);
+ return text_stencil (str, music_string, true);
}
Stencil
-Pango_font::text_stencil (string str, bool feta) const
+Pango_font::text_stencil (string str, bool music_string) const
{
- return text_stencil (str, feta, false);
+ return text_stencil (str, music_string, false);
}
+extern bool music_strings_to_paths;
+
Stencil
Pango_font::text_stencil (string str,
- bool feta,
+ bool music_string,
bool tight) const
{
/*
*/
PangoLayout *layout = pango_layout_new (context_);
pango_layout_set_text (layout, str.c_str (), -1);
- PangoLayoutLine *line = pango_layout_get_line (layout, 0);
- GSList *layout_runs = line->runs;
+ GSList *lines = pango_layout_get_lines (layout);
Stencil dest;
Real last_x = 0.0;
- for (GSList *p = layout_runs; p; p = p->next)
+ for (GSList *l = lines; l; l = l->next)
{
- PangoGlyphItem *item = (PangoGlyphItem *) p->data;
- Stencil item_stencil = pango_item_string_stencil (item, tight);
+ PangoLayoutLine *line = (PangoLayoutLine *) l->data;
+ GSList *layout_runs = line->runs;
+
+ for (GSList *p = layout_runs; p; p = p->next)
+ {
+ PangoGlyphItem *item = (PangoGlyphItem *) p->data;
+ Stencil item_stencil = pango_item_string_stencil (item, tight);
- item_stencil.translate_axis (last_x, X_AXIS);
- last_x = item_stencil.extent (X_AXIS)[RIGHT];
+ item_stencil.translate_axis (last_x, X_AXIS);
+ last_x = item_stencil.extent (X_AXIS)[RIGHT];
#if 0 // Check extents.
- if (!item_stencil.extent_box ()[X_AXIS].is_empty ())
- {
- Stencil frame = Lookup::frame (item_stencil.extent_box (), 0.1, 0.1);
- Box empty;
- empty.set_empty ();
- Stencil dimless_frame (empty, frame.expr ());
- dest.add_stencil (frame);
- }
+ if (!item_stencil.extent_box ()[X_AXIS].is_empty ())
+ {
+ Stencil frame = Lookup::frame (item_stencil.extent_box (), 0.1, 0.1);
+ Box empty;
+ empty.set_empty ();
+ Stencil dimless_frame (empty, frame.expr ());
+ dest.add_stencil (frame);
+ }
#endif
- dest.add_stencil (item_stencil);
+ dest.add_stencil (item_stencil);
+ }
}
string name = get_output_backend_name ();
SCM utf8_string = ly_module_lookup (mod, ly_symbol2scm ("utf-8-string"));
/*
has_utf8_string should only be true when utf8_string is a
- variable that is bound to a *named* procedure.
+ variable that is bound to a *named* procedure, i.e. not a
+ lambda expression.
*/
if (utf8_string != SCM_BOOL_F
&& scm_procedure_name (SCM_VARIABLE_REF (utf8_string)) != SCM_BOOL_F)
has_utf8_string = true;
}
- /*
- The SVG backend only uses utf-8-string for the non-music
- fonts, hence the check here. --pmccarty
+ bool to_paths = music_strings_to_paths;
- TODO: use a program option (-dmusic-strings-to-paths) here
- instead that is enabled only when -dbackend=svg.
+ /*
+ Backends with the utf-8-string expression use it when
+ 1) the -dmusic-strings-to-paths option is set
+ and `str' is not a music string, or
+ 2) the -dmusic-strings-to-paths option is not set.
*/
- if ((name == "svg" && !feta) || (name != "svg" && has_utf8_string))
+ if (has_utf8_string && ((to_paths && !music_string) || !to_paths))
{
// For Pango based backends, we take a shortcut.
SCM exp = scm_list_3 (ly_symbol2scm ("utf-8-string"),