]> git.cworth.org Git - scherzo/commitdiff
Make the brace and clef symbols scale with the staff.
authorCarl Worth <cworth@cworth.org>
Sat, 17 Sep 2011 18:48:25 +0000 (11:48 -0700)
committerCarl Worth <cworth@cworth.org>
Sat, 17 Sep 2011 18:48:25 +0000 (11:48 -0700)
All looks much better now, (even if the size calculations are simply
empirically-derived linear fits to what looks good to me).

scherzo.c
score.c

index f6669edc3fda5194149cd72d88883c963b5cc076..ae8ea3284760ba900b6dfdb07f8ba72a2c01fd4b 100644 (file)
--- a/scherzo.c
+++ b/scherzo.c
@@ -62,8 +62,8 @@ on_expose_event_draw (GtkWidget *widget,
     cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
     cairo_paint (cr);
 
-    /* Add some padding on the left/right */
-    cairo_translate (cr, pad, pad);
+    /* Add some padding on the sides and top */
+    cairo_translate (cr, pad, (int) scherzo->staff_height / 2);
     score_set_staff_height (score, scherzo->staff_height);
     score_set_width (score, widget_width - 2 * pad);
 
diff --git a/score.c b/score.c
index 5bb79096c394a45741810d3cb3b22e6ebeeeb552..290059196853bd86cbbcabd870e2dd47df9101f9 100644 (file)
--- a/score.c
+++ b/score.c
@@ -52,7 +52,7 @@ score_set_staff_height (score_t *score, int height)
     score->space_height = (int) height / 4;
     score->staff_height = score->space_height * 4;
 
-    score->line_width = score->space_height / 15;
+    score->line_width = score->space_height / 10;
     if (score->line_width == 0)
        score->line_width = 1;
 
@@ -81,9 +81,7 @@ _draw_staff (score_t *score, cairo_t *cr, score_clef_t clef)
 
     cairo_select_font_face (cr, "Gonville-26", 0, 0);
 
-    /* XXX: This font size is a rough guess at best. We should figure
-     * out to correctly measure, size, and place clefs. */
-    cairo_set_font_size (cr, 24);
+    cairo_set_font_size (cr, score->staff_height);
 
     /* XXX: The hard-coded glyph indices here are very ugly. We should
      * figure out how to lookup glyphs by name from this font. */
@@ -98,7 +96,8 @@ _draw_staff (score_t *score, cairo_t *cr, score_clef_t clef)
        glyph.y = 1 * score->space_height;
        break;
     }
-    glyph.x = 2;
+    glyph.x = 3 * score->line_width;
+    glyph.y += 1;
 
     cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
     cairo_show_glyphs (cr, &glyph, 1);
@@ -127,28 +126,31 @@ _draw_grand_staff (score_t *score, cairo_t *cr)
 {
 #define BRACE_GLYPHS 1
     cairo_glyph_t brace;
+    cairo_text_extents_t brace_extents;
     cairo_save (cr);
 
     /* Brace test */
     cairo_select_font_face (cr, "Gonville-Brace", 0, 0);
 
-    /* XXX: This font size (in conjunction with the glyph selection)
-     * is a rough guess at best. We should figure out how the brace
-     * font is intended to be used and actually measure to find the
-     * correctly sized glyph. */
-    cairo_set_font_size (cr, 40);
-
-    cairo_translate (cr, 5, 0);
-    score->width -= 5;
-
     /* XXX: This hard-coded glyph index is pretty ugly. We should
      * figure out how to lookup the glyph we want, (though, as it
      * turns out, this brace font pretty much just has numbered glyph
      * names for different sizes, so it wouldn't be all that different
      * than just the bare index here). */
-    brace.index = 185;
+    brace.index = 300;
     brace.x = 0;
-    brace.y = score->staff_height * 1.5;
+    brace.y = (score->staff_height * 3) / 2 + 1;
+
+    /* XXX: This font size (in conjunction with the glyph selection)
+     * is a rough guess at best. We should figure out how the brace
+     * font is intended to be used and actually measure to find the
+     * correctly-sized glyph. */
+    cairo_set_font_size (cr, (score->staff_height * 3) / 3.85);
+
+    cairo_glyph_extents (cr, &brace, 1, &brace_extents);
+
+    cairo_translate (cr, -brace_extents.x_bearing, 0);
+    score->width += brace_extents.x_bearing;
 
     cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
     cairo_show_glyphs (cr, &brace, 1);