+2004-12-13 Jan Nieuwenhuizen <janneke@gnu.org>
+
+ * lily/include/font-metric.hh (index_to_charcode): New function.
+
+ * lily/font-metric.cc (ly:font-glyph-name-to-charcode): Use it in
+ new function.
+ (ly:font-glyp-to-index): Remove.
+
+ * scm/lily-library.scm (char->unicode-index): Remove.
+
2004-12-12 Han-Wen Nienhuys <hanwen@xs4all.nl>
* lily/open-type-font.cc (make_index_to_charcode_map): new method.
return fm->get_ascii_char_stencil (scm_to_int (index)).smobbed_copy ();
}
-LY_DEFINE (ly_font_get_glyph_index, "ly:font-get-glyph-index",
+LY_DEFINE (ly_font_glyph_name_to_index, "ly:font-glyph-name-to-index",
2, 0, 0,
(SCM font, SCM name),
"Return the index for @{name} in @var{font}.")
return scm_from_int (fm->name_to_index (ly_scm2string (name)));
}
+LY_DEFINE (ly_font_index_to_charcode, "ly:font-index-to-charcode",
+ 2, 0, 0,
+ (SCM font, SCM index),
+ "Return the character code for @var{index} @var{font}.")
+{
+ Font_metric *fm = unsmob_metrics (font);
+ SCM_ASSERT_TYPE (fm, font, SCM_ARG1, __FUNCTION__, "font-metric");
+ SCM_ASSERT_TYPE (scm_is_integer (index), index, SCM_ARG2, __FUNCTION__, "index");
+
+ return scm_from_unsigned_integer (fm->index_to_charcode (ly_scm2int (index)));
+}
+
+LY_DEFINE (ly_font_glyph_name_to_charcode, "ly:font-glyph-name-to-charcode",
+ 2, 0, 0,
+ (SCM font, SCM name),
+ "Return the character code for glyph @{name} in @var{font}.")
+{
+ Font_metric *fm = unsmob_metrics (font);
+ SCM_ASSERT_TYPE (fm, font, SCM_ARG1, __FUNCTION__, "font-metric");
+ SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG2, __FUNCTION__, "string");
+
+ return scm_from_unsigned_integer (fm->index_to_charcode (fm->name_to_index (ly_scm2string (name))));
+}
+
LY_DEFINE (ly_text_dimension,"ly:text-dimension",
2, 0, 0,
(SCM font, SCM text),
return i;
}
+unsigned
+Font_metric::index_to_charcode (int i) const
+{
+ return (unsigned) index_to_ascii (i);
+}
+
Stencil
Font_metric::get_ascii_char_stencil (int code) const
{
- SCM at = scm_list_3 (ly_symbol2scm ("char"),
- this->self_scm (),
+ SCM at = scm_list_3 (ly_symbol2scm ("char"), self_scm (),
scm_int2num (code));
Box b = get_ascii_char (code);
return Stencil (b, at);
virtual Box get_indexed_char (int index) const;
virtual Box get_ascii_char (int ascii) const;
virtual int name_to_index (String) const;
+ virtual unsigned index_to_charcode (int) const;
virtual int index_to_ascii (int) const;
virtual Real design_size () const;
virtual Stencil find_by_name (String) const;
#define SCM_VECTOR_REF(v, i) (SCM_VELTS ((v))[(i)])
#define scm_from_bool(x) (x ? SCM_BOOL_T : SCM_BOOL_F)
#define scm_from_int(x) SCM_MAKINUM (x)
+#define scm_from_unsigned_integer(x) scm_uint2num (x)
#define scm_is_integer(x) SCM_INUMP (x)
#define scm_is_string(x) SCM_STRINGP (x)
#define scm_hash_table_p scm_vector_p
virtual Offset attachment_point (String) const;
virtual Box get_indexed_char (int) const;
virtual int name_to_index (String) const;
+ virtual unsigned index_to_charcode (int) const;
virtual void derived_mark () const;
#if 0
virtual int count () const;
#include <stdio.h>
#include <freetype/tttables.h>
-
+
#include "warn.hh"
#include "open-type-font.hh"
#include "dimensions.hh"
-const Real point_constant = 1 PT;
+const Real point_constant = 1 PT;
FT_Byte *
load_table (char const *tag_str, FT_Face face, FT_ULong *length)
{
FT_ULong tag = FT_MAKE_TAG(tag_str[0], tag_str[1], tag_str[2], tag_str[3]);
-
+
int error_code = FT_Load_Sfnt_Table (face, tag, 0, NULL, length);
if (!error_code)
{
- FT_Byte*buffer = (FT_Byte*) malloc (*length);
+ FT_Byte *buffer = (FT_Byte*) malloc (*length);
if (buffer == NULL)
- error ("Not enough memory");
+ error (_f ("Cannot allocate %d bytes", *length));
error_code = FT_Load_Sfnt_Table (face, tag, 0, buffer, length );
if (error_code)
return buffer;
}
-
- return 0 ;
+
+ return 0;
}
SCM
load_scheme_table (char const *tag_str, FT_Face face)
{
FT_ULong length = 0;
- FT_Byte* buffer = load_table (tag_str, face, &length);
+ FT_Byte *buffer = load_table (tag_str, face, &length);
SCM tab = SCM_EOL;
if (buffer)
String contents ((Byte const*)buffer, length);
contents = "(quote (" + contents + "))";
- SCM alist = scm_c_eval_string (contents.to_str0());
+ SCM alist = scm_c_eval_string (contents.to_str0 ());
tab = alist_to_hashq (alist);
free (buffer);
}
return tab;
}
-
+
Index_to_charcode_map
make_index_to_charcode_map (FT_Face face)
{
Index_to_charcode_map m;
- FT_ULong charcode;
- FT_UInt gindex;
-
- charcode = FT_Get_First_Char( face, &gindex );
- while ( gindex != 0 )
+ FT_ULong charcode;
+ FT_UInt gindex;
+
+ charcode = FT_Get_First_Char (face, &gindex);
+ while (gindex != 0)
{
+ printf ("index -> code: %d %d \n", gindex, charcode);
m[gindex] = charcode;
- charcode = FT_Get_Next_Char( face, charcode, &gindex );
+ charcode = FT_Get_Next_Char (face, charcode, &gindex);
}
return m;
-}
+}
+
+Open_type_font::Open_type_font (FT_Face face)
+{
+ face_ = face;
+ lily_character_table_ = SCM_EOL;
+ lily_global_table_ = SCM_EOL;
+
+ lily_character_table_ = load_scheme_table ("LILC", face_);
+ lily_global_table_ = load_scheme_table ("LILY", face_);
+ index_to_charcode_map_ = make_index_to_charcode_map (face_);
+}
+
+Open_type_font::~Open_type_font()
+{
+ FT_Done_Face (face_);
+}
SCM
Open_type_font::make_otf (String str)
{
FT_Face face;
- int error_code = FT_New_Face(freetype2_library, str.to_str0(),
- 0, &face);
-
+ int error_code = FT_New_Face(freetype2_library, str.to_str0 (), 0, &face);
+
if (error_code == FT_Err_Unknown_File_Format)
{
- error("Unsupported font format");
+ error (_f ("Unsupported font format: %s", str.to_str0 ()));
}
else if (error_code)
{
- error ("Unknown error reading font file.");
+ error (_f ("Unknown error: %d reading font file: %s", error_code,
+ str.to_str0 ()));
}
+ Open_type_font *otf = new Open_type_font (face);
- Open_type_font * otf = new Open_type_font (face);
-
-
return otf->self_scm ();
}
-Open_type_font::Open_type_font(FT_Face face)
-{
- face_ = face;
- lily_character_table_ = SCM_EOL;
- lily_global_table_ = SCM_EOL;
-
- lily_character_table_ = load_scheme_table ("LILC", face_);
- lily_global_table_ = load_scheme_table ("LILY", face_);
- index_to_charcode_map_ = make_index_to_charcode_map (face_);
-}
-
void
Open_type_font::derived_mark () const
{
SCM entry = scm_hashq_ref (lily_character_table_, sym, SCM_BOOL_F);
Offset o;
- if (entry == SCM_BOOL_F)
+ if (entry == SCM_BOOL_F)
return o;
SCM char_alist = entry;
SCM att_scm =scm_cdr (scm_assq (ly_symbol2scm ("attachment"), char_alist));
-
- return ly_scm2offset (att_scm);
-}
-
-Open_type_font::~Open_type_font()
-{
- FT_Done_Face (face_);
+ return ly_scm2offset (att_scm);
}
-
Box
Open_type_font::get_indexed_char (int signed_idx) const
{
Box b (Interval (-hb, m.width - hb),
Interval (-vb, m.height - vb));
-
-
- b.scale (design_size() * Real (point_constant) / face_->units_per_EM);
+ b.scale (design_size () * Real (point_constant) / face_->units_per_EM);
return b;
}
int
Open_type_font::name_to_index (String nm) const
{
- char * nm_str = (char * )nm.to_str0 ();
- int idx = FT_Get_Name_Index (face_, nm_str);
-
- if (idx == 0)
- return -1;
- else
+ char *nm_str = (char*) nm.to_str0 ();
+ if (int idx = FT_Get_Name_Index (face_, nm_str))
return idx;
+ return -1;
}
+unsigned
+Open_type_font::index_to_charcode (int i) const
+{
+ return ((Open_type_font*) this)->index_to_charcode_map_[index_to_ascii (i)];
+}
Real
Open_type_font::design_size () const
{
- return point_constant * scm_to_double (scm_hashq_ref (lily_global_table_, ly_symbol2scm ("staffsize"), SCM_BOOL_F));
+ return point_constant
+ * scm_to_double (scm_hashq_ref (lily_global_table_,
+ ly_symbol2scm ("staffsize"), SCM_BOOL_F));
}
(ly:font-file-name font)))))
(define-public (char->unicode-index font char)
- ;; (format (current-error-port) "UNICODE:~S:~S:~S\n"
- ;; font (ly:font-encoding font) (char->integer char))
- ;; (force-output (current-error-port))
- (+ (case (ly:font-encoding font)
- ((fetaMusic) (- #xe000 #x20))
- ((fetaBraces) (- #xe000 #x40))
- ((fetaBraces) (- #xe000 #x40))
- ;;(else 0))
- ;; FIXME: bigcheese says FontSpecific
- (else (if (string=? (font-family font) "bigcheese20")
- ;;#xf000 0)))
- ;; FIXME: hmm, why does name_to_index not return actual
- ;; unicode mapping?
-
- ;; ugh, we must know which font from bigcheese;
- ;; feta-proper starts at 0xefc
- ;; but we cannot display feta-nummer or feta-din characters
- ;; this way
- #xe0fc 0)))
- (char->integer char)))
+ ;;(ly:font-index-to-charcode (char->integer char))
+ (char->integer char))
(define (named-glyph font name)
(debugf "glyph:~S\n" name)
- (debugf "index:~S\n" (ly:font-get-glyph-index font name))
+ (debugf "index:~S\n" (ly:font-glyph-name-to-charcode font name))
(debugf "font:~S\n" (font-family font))
- (text font (integer->char (ly:font-get-glyph-index font name))))
+ (text font (integer->char (ly:font-glyph-name-to-charcode font name))))
(define (polygon coords blotdiameter)
(let*
(define (text font s)
(define (pango-font-name font)
+ (stderr "FONT-NAME:~S\n" (ly:font-name font))
+
(let ((family (font-family font)))
;; Hmm, family is bigcheese20?
(if (string=? family "bigcheese20")
- (begin (debugf "BIGCHEESE\n")
- "LilyPond, 20")
+ (format #f "~S, ~S" (ly:font-name font) (ly:font-design-size font))
family)))
(define (pango-font-size font)
#:size-set #t
#:text (if (char? s)
(char->utf8-string font s)
- (string->utf8-string font s)))))
\ No newline at end of file
+ (string->utf8-string font s)))))