From: Han-Wen Nienhuys Date: Fri, 26 Aug 2005 08:38:38 +0000 (+0000) Subject: * input/regression/markup-bidi-pango.ly: new file. X-Git-Tag: release/2.7.8~9 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=af978acdd78dce84f3867b80695dc4622fa0cd06;p=lilypond.git * input/regression/markup-bidi-pango.ly: new file. * lily/pango-font.cc (pango_item_string_stencil): make Mingw code standard. Remove #ifdef. Remove memleak. (text_stencil): use text_dir to decide how to composite items. (text_stencil): determine uniform text direction for the entire string. * scripts/lilypond-book.py (output_name): remove latex_filter_cmd. Non-portable to non-Unix systems. (get_latex_textwidth): use File.write and os.unlink() instead. * THANKS: add Vicente & Trevor. --- diff --git a/ChangeLog b/ChangeLog index 5650107b1b..9abe70f212 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2005-08-26 Han-Wen Nienhuys + * input/regression/markup-bidi-pango.ly: new file. + + * lily/pango-font.cc (pango_item_string_stencil): make Mingw code + standard. Remove #ifdef. Remove memleak. + (text_stencil): use text_dir to decide how to composite items. + (text_stencil): determine uniform text direction for the entire + string. + + * scripts/lilypond-book.py (output_name): remove + latex_filter_cmd. Non-portable to non-Unix systems. + (get_latex_textwidth): use File.write and os.unlink() instead. + * THANKS: add Vicente & Trevor. * lily/grob.cc (discretionary_processing): look up origin for diff --git a/THANKS b/THANKS index e4d3fad140..ce2c11aa29 100644 --- a/THANKS +++ b/THANKS @@ -38,6 +38,7 @@ Vicente Solsona Dellá BUG HUNTERS/SUGGESTIONS Bob Broadus +Darius Blasband Donald Axel Erlend Aasland Trevor Bača diff --git a/input/regression/markup-bidi-pango.ly b/input/regression/markup-bidi-pango.ly new file mode 100644 index 0000000000..316d6bead4 --- /dev/null +++ b/input/regression/markup-bidi-pango.ly @@ -0,0 +1,13 @@ +\version "2.7.8" + +\header { + + texidoc = "A single pango string is considered to have one +direction. The hebrew in this example (including punctuation) is set +right-to-left, with the first word (containing 1) on the right." + +} + +\markup { + "לל1ללל, רר2רר." +} diff --git a/lily/all-font-metrics.cc b/lily/all-font-metrics.cc index abe7c742bb..a7b13401cc 100644 --- a/lily/all-font-metrics.cc +++ b/lily/all-font-metrics.cc @@ -62,7 +62,8 @@ All_font_metrics::All_font_metrics (All_font_metrics const &) Pango_font * All_font_metrics::find_pango_font (PangoFontDescription *description, Real magnification, - Real output_scale) + Real output_scale + ) { pango_font_description_set_size (description, gint (magnification * @@ -78,9 +79,10 @@ All_font_metrics::find_pango_font (PangoFontDescription *description, progress_indication ("[" + String (pango_fn)); Pango_font *pf = new Pango_font (pango_ft2_fontmap_, - RIGHT, description, - output_scale); + output_scale + ); + val = pf->self_scm (); pango_dict_->set (key, val); pf->unprotect (); diff --git a/lily/include/pango-font.hh b/lily/include/pango-font.hh index b290339f13..b39a6c57a3 100644 --- a/lily/include/pango-font.hh +++ b/lily/include/pango-font.hh @@ -27,11 +27,10 @@ class Pango_font : public Font_metric Real scale_; Real output_scale_; SCM physical_font_tab_; - + Direction text_direction_; public: SCM physical_font_tab () const; Pango_font (PangoFT2FontMap *, - Direction leftright, PangoFontDescription *, Real); ~Pango_font (); @@ -39,7 +38,7 @@ public: SCM font_file_name () const; void register_font_file (String, String); Stencil text_stencil (String) const; - Stencil pango_item_string_stencil (PangoItem *, String) const; + Stencil pango_item_string_stencil (PangoItem const *, String) const; virtual void derived_mark () const; }; diff --git a/lily/pango-font.cc b/lily/pango-font.cc index 184bf1463f..fa81770fce 100644 --- a/lily/pango-font.cc +++ b/lily/pango-font.cc @@ -22,15 +22,12 @@ #include "stencil.hh" Pango_font::Pango_font (PangoFT2FontMap *fontmap, - Direction dir, PangoFontDescription *description, Real output_scale) { (void) fontmap; physical_font_tab_ = scm_c_make_hash_table (11); - PangoDirection pango_dir = (dir == RIGHT) - ? PANGO_DIRECTION_LTR - : PANGO_DIRECTION_RTL; + PangoDirection pango_dir = PANGO_DIRECTION_LTR; context_ = pango_ft2_get_context (PANGO_RESOLUTION, PANGO_RESOLUTION); // context_ = pango_ft2_font_map_create_context (fontmap); @@ -77,15 +74,15 @@ Pango_font::derived_mark () const } Stencil -Pango_font::pango_item_string_stencil (PangoItem *item, String str) const +Pango_font::pango_item_string_stencil (PangoItem const *item, String str) const { const int GLYPH_NAME_LEN = 256; char glyph_name[GLYPH_NAME_LEN]; - PangoAnalysis *pa = &(item->analysis); + PangoAnalysis const *pa = &(item->analysis); PangoGlyphString *pgs = pango_glyph_string_new (); pango_shape (str.to_str0 () + item->offset, - item->length, pa, pgs); + item->length, (PangoAnalysis*) pa, pgs); PangoRectangle logical_rect; PangoRectangle ink_rect; @@ -140,14 +137,16 @@ Pango_font::pango_item_string_stencil (PangoItem *item, String str) const / (Real (PANGO_SCALE)); FcPattern *fcpat = fcfont->font_pattern; - char *file_name = 0; - FcPatternGetString (fcpat, FC_FILE, 0, (FcChar8 **) & file_name); -#ifdef __MINGW32__ - /* Normalize file name. */ - // FIXME: memleak(s?), drop the #ifdef? - file_name = File_name (file_name).to_string ().get_copy_str0 (); -#endif + char *file_name_as_ptr = 0; + FcPatternGetString (fcpat, FC_FILE, 0, (FcChar8 **) & file_name_as_ptr); + String file_name; + if (file_name_as_ptr) + { + /* Normalize file name. */ + file_name = File_name (file_name_as_ptr).to_string (); + } + char const *ps_name_str0 = FT_Get_Postscript_Name (ftface); if (!ps_name_str0) @@ -155,15 +154,15 @@ Pango_font::pango_item_string_stencil (PangoItem *item, String str) const String ps_name; if (!ps_name_str0 - && file_name - && (String (file_name).index (".otf") >= 0 - || String (file_name).index (".cff") >= 0)) + && file_name != "" + && (file_name.index (".otf") >= 0 + || file_name.index (".cff") >= 0)) { /* UGH: kludge a PS name for OTF/CFF fonts. */ String name = file_name; - int idx = max (String (file_name).index (".otf"), - String (file_name).index (".cff")); + int idx = max (file_name.index (".otf"), + file_name.index (".cff")); name = name.left_string (idx); @@ -207,23 +206,41 @@ Pango_font::physical_font_tab () const Stencil Pango_font::text_stencil (String str) const { - GList *items = pango_itemize (context_, - str.to_str0 (), - 0, str.length (), attribute_list_, - NULL); + GList *items + = pango_itemize (context_, + str.to_str0 (), + 0, str.length (), attribute_list_, + NULL); - GList *ptr = items; Stencil dest; Real last_x = 0.0; - while (ptr) + + Direction text_dir = RIGHT; + for (GList *p = items; p; p = p->next) + { + PangoItem *item = (PangoItem *) p->data; + if (item->analysis.level == PANGO_DIRECTION_RTL) + text_dir = LEFT; + } + + for (GList *ptr = items; ptr; ptr = ptr->next) { PangoItem *item = (PangoItem *) ptr->data; Stencil item_stencil = pango_item_string_stencil (item, str); - item_stencil.translate_axis (last_x, X_AXIS); - last_x = item_stencil.extent (X_AXIS)[RIGHT]; + if (text_dir == RIGHT) + { + item_stencil.translate_axis (last_x, X_AXIS); + last_x = item_stencil.extent (X_AXIS)[RIGHT]; + } + else if (text_dir == LEFT) + { + dest.translate_axis (item_stencil.extent (X_AXIS)[RIGHT], X_AXIS); + } + + #if 0 /* Check extents. */ if (!item_stencil.extent_box ()[X_AXIS].is_empty ()) { @@ -236,8 +253,6 @@ Pango_font::text_stencil (String str) const #endif dest.add_stencil (item_stencil); - - ptr = ptr->next; } /* diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index acb6f81dd0..504cfa4e0b 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -117,7 +117,6 @@ psfonts_p = 0 use_hash_p = 1 format = 0 output_name = '' -latex_filter_cmd = 'cat > %(tmpfile)s && latex "\\nonstopmode \input %(tmpfile)s" && rm %(tmpfile)s' filter_cmd = 0 process_cmd = '' default_ly_options = { 'alt': "[image of music]" } @@ -1276,7 +1275,8 @@ def process_snippets (cmd, ly_snippets, texstr_snippets, png_snippets): if ly_names: my_system (string.join ([cmd, 'snippet-map.ly'] + ly_names)) -LATEX_DOCUMENT = r''' +LATEX_INSPECTION_DOCUMENT = r''' +\nonstopmode %(preamble)s \begin{document} \typeout{textwidth=\the\textwidth} @@ -1289,12 +1289,16 @@ LATEX_DOCUMENT = r''' def get_latex_textwidth (source): m = re.search (r'''(?P\\begin\s*{document})''', source) preamble = source[:m.start (0)] - latex_document = LATEX_DOCUMENT % vars () + latex_document = LATEX_INSPECTION_DOCUMENT % vars () # Workaround problems with unusable $TMP on Cygwin: tempfile.tempdir = '' tmpfile = tempfile.mktemp('.tex') - cmd = latex_filter_cmd % vars () - parameter_string = filter_pipe (latex_document, cmd) + logfile = os.path.splitext (tmpfile) + '.log' + open (tmpfile,'w').write (latex_document) + ly.system ('latex %s' % tmpfile) + parameter_string = open (logfile).read() + os.unlink (tmpfile) + os.unlink (logfile) columns = 0 m = re.search ('columns=([0-9.]*)', parameter_string)