]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/pango-font.cc
* flower/file-path.cc (find): try to open directly as well, so we
[lilypond.git] / lily / pango-font.cc
index d9944caaab6eb663b310b58dc6bf8d275dcdb570..7529ae8115c40956db79fb4986c26aca906c19db 100644 (file)
 
 */
 
-#include <pango/pangoft2.h>
-
-#include "pango-font.hh"
-#include "stencil.hh" 
-
-PangoStyle
-symbol_to_pango_style (SCM style)
-{
-  PangoStyle pstyle = PANGO_STYLE_NORMAL;
-  if (style == ly_symbol2scm ("italic"))
-    {
-      pstyle = PANGO_STYLE_NORMAL;
-    }
-  else if (style == ly_symbol2scm ("oblique")
-          || style == ly_symbol2scm ("slanted")
-          )
-    {
-      pstyle = PANGO_STYLE_OBLIQUE;
-    }
-
-  return pstyle;
-}
 
-PangoVariant
-symbol_to_pango_variant (SCM variant)
-{
-  PangoVariant pvariant;
-  if (variant == ly_symbol2scm ("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;
-    }
-  if (weight == ly_symbol2scm ("heavy"))
-    {
-      pw = PANGO_WEIGHT_HEAVY;
-    }
-  if (weight == ly_symbol2scm ("ultrabold"))
-    {
-      pw = PANGO_WEIGHT_ULTRABOLD;
-    }
-  if (weight == ly_symbol2scm ("light"))
-    {
-      pw = PANGO_WEIGHT_LIGHT;
-    }
-  if (weight == ly_symbol2scm ("ultralight"))
-    {
-      pw = PANGO_WEIGHT_ULTRALIGHT;
-    }
-
-  return pw;
-}
+#define PANGO_ENABLE_BACKEND // ugh, why necessary?
 
-PangoStretch
-symbol_to_pango_stretch (SCM stretch)
-{
-  PangoStretch ps = PANGO_STRETCH_NORMAL;
-
-  /*
-    // 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;
-}
+#include <pango/pangoft2.h>
 
+#include "pango-font.hh"
 
+#if HAVE_PANGO_FT2
+#include "stencil.hh" 
 
-PangoFontDescription* 
-symbols_to_pango_font_description(SCM family,
-                                 SCM style,
-                                 SCM variant,
-                                 SCM weight,
-                                 SCM stretch,
-                                 SCM size)
-{
-  PangoFontDescription * description = pango_font_description_new ();
-
-  pango_font_description_set_family (description,
-                                    ly_symbol2string (family).to_str0 ());
-  pango_font_description_set_style (description,
-                                   symbol_to_pango_style (style));
-  pango_font_description_set_variant (description,
-                                     symbol_to_pango_variant (variant));
-  pango_font_description_set_weight (description,
-                                    symbol_to_pango_weight (weight));
-  pango_font_description_set_stretch (description,
-                                     symbol_to_pango_stretch (stretch));
-  pango_font_description_set_size (description,
-                                  gint (scm_to_double (size) * PANGO_SCALE));
-
-  return description;
-}
 
 Pango_font::Pango_font (PangoFT2FontMap *fontmap,
                        int resolution,
                        Direction dir,
                        PangoFontDescription * description)
 {
+  subfonts_ = SCM_EOL;
   PangoDirection pango_dir = (dir==RIGHT)
     ? PANGO_DIRECTION_LTR
     : PANGO_DIRECTION_RTL;
   context_ = pango_ft2_font_map_create_context (fontmap);  
   attribute_list_= pango_attr_list_new();
-  scale_ = PANGO_SCALE * resolution * 72.27;
+  scale_ = 1.0 / (PANGO_SCALE * resolution * 72.27);
   
   pango_context_set_language (context_, pango_language_from_string ("en_US"));
   pango_context_set_base_dir (context_, pango_dir);
   pango_context_set_font_description (context_, description);
 }
 
+
 Pango_font::~Pango_font ()
 {
   g_object_unref (context_);
   pango_attr_list_unref (attribute_list_);
 }
 
+void
+Pango_font::register_font_file (String filename, String ps_name) 
+{
+  subfonts_ = scm_cons (//scm_cons (scm_makfrom0str (ps_name.to_str0 ()),
+                       scm_makfrom0str (filename.to_str0 ()),
+                       subfonts_);
+}
 
+void
+Pango_font::derived_mark () const
+{
+  scm_gc_mark (subfonts_);
+}
 Stencil
 Pango_font::text_stencil (String str) const
 {
@@ -154,15 +67,14 @@ Pango_font::text_stencil (String str) const
   const int GLYPH_NAME_LEN = 256;
   char glyph_name[GLYPH_NAME_LEN];
   
-  Box dest_extent;
-  dest_extent.set_empty ();
   GList * ptr = items;
-  SCM glyph_exprs = SCM_EOL;
+  Stencil dest;  
   while (ptr)
     {
       PangoItem *item = (PangoItem*) ptr->data;
       PangoAnalysis *pa = &(item->analysis);
       PangoGlyphString *pgs = pango_glyph_string_new();
+
       pango_shape (str.to_str0 (), str.length (), pa, pgs);
 
       PangoRectangle logical_rect;
@@ -178,8 +90,9 @@ Pango_font::text_stencil (String str) const
       b.translate (Offset (- logical_rect.x, -logical_rect.y));
       
       b.scale (scale_);
-      dest_extent.unite (b);
-      
+
+      SCM glyph_exprs = SCM_EOL;
+      SCM *tail = &glyph_exprs;
       for (int i = 0; i < pgs->num_glyphs; i++)
        {
          PangoGlyphInfo *pgi = pgs->glyphs + i;
@@ -188,19 +101,53 @@ Pango_font::text_stencil (String str) const
          PangoGlyphGeometry ggeo = pgi->geometry;
          
          FT_Get_Glyph_Name (ftface, pg, glyph_name, GLYPH_NAME_LEN);
-         glyph_exprs = scm_cons (scm_list_5 (ly_symbol2scm ("named-ps-glyph"),
-                                             scm_from_int (ggeo.x_offset),
-                                             scm_from_int (ggeo.y_offset),
-                                             scm_makfrom0str (glyph_name),
-                                             scm_makfrom0str (FT_Get_Postscript_Name (ftface))),
-                                 glyph_exprs);
+         *tail = scm_cons (scm_list_3 (scm_from_double (ggeo.x_offset * scale_),
+                                       scm_from_double (ggeo.y_offset * scale_),
+                                       scm_makfrom0str (glyph_name)),
+                           SCM_EOL);
+         tail = SCM_CDRLOC(*tail);
        }
 
+      FcPattern *fcpat = fcfont->font_pattern;
+      char *filename = 0;
+      FcPatternGetString(fcpat, FC_FILE, 0, (FcChar8 **) &filename);
+      char const *ps_name = FT_Get_Postscript_Name (ftface);
+      ((Pango_font *) this)->register_font_file (filename, ps_name);
+      
+      SCM expr = scm_list_3 (ly_symbol2scm ("glyph-string"),
+                            scm_makfrom0str (ps_name),
+                            ly_quote_scm (glyph_exprs));
+
+      Stencil item_stencil (b, expr);
+
+      dest.add_stencil (item_stencil);
+      
+      pango_fc_font_unlock_face (fcfont);
       ptr = ptr->next;      
     }
 
-  Stencil dest (dest_extent,
-               scm_cons (ly_symbol2scm ("combine-stencil"),
-                         glyph_exprs));
   return dest;
 }
+
+SCM
+Pango_font::sub_fonts () const
+{
+  return subfonts_;
+}
+
+SCM 
+Pango_font::font_file_name () const
+{
+  return SCM_BOOL_F;
+}
+
+LY_DEFINE(ly_pango_font_p, "ly:pango-font?",
+         1,0,0,
+         (SCM f),
+         "Is @var{f} a pango font?")
+
+{
+  return scm_from_bool (dynamic_cast<Pango_font*> (unsmob_metrics (f)));
+}
+
+#endif