]> git.donarmstrong.com Git - lilypond.git/commitdiff
* input/regression/markup-bidi-pango.ly: new file.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 26 Aug 2005 08:38:38 +0000 (08:38 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 26 Aug 2005 08:38:38 +0000 (08:38 +0000)
* 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.

ChangeLog
THANKS
input/regression/markup-bidi-pango.ly [new file with mode: 0644]
lily/all-font-metrics.cc
lily/include/pango-font.hh
lily/pango-font.cc
scripts/lilypond-book.py

index 5650107b1bd24e264980a10b6b667d2ea17fb2bf..9abe70f21205fcdf6745dd0e9be4011e934b19af 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2005-08-26  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
+       * 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 e4d3fad140ce81715b3bebad680b4fdf2afc2ece..ce2c11aa29c5d40ae1f69f1075faf9d806f2e784 100644 (file)
--- 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 (file)
index 0000000..316d6be
--- /dev/null
@@ -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רר."
+}
index abe7c742bb917bfcdf570feb7320bb3a89b18587..a7b13401cc969c343664e1285ea55f9aaedb70e0 100644 (file)
@@ -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 ();
index b290339f139cd7b7a3a190087c73a23d95ae55ef..b39a6c57a3457735328aea4a539f5207e97c5d6b 100644 (file)
@@ -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;
 };
index 184bf1463fa33d6c2a71e4dc3dd63d29073b56ef..fa81770fced9b893216d8f0fbebb472e0039ae75 100644 (file)
 #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;
     }
 
   /*
index acb6f81dd01f54628885dba4e6f39483a409ad30..504cfa4e0b262281047f74757955ca57b47e88b6 100644 (file)
@@ -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<preamble>\\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)