X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fstencil-integral.cc;h=b44258b6b1973c19d117626ba769a232467dd7e4;hb=90e4d7057f3857da049dfda3d130017d4719bd6b;hp=f5e437bced8df0f408905d0b0f548cbdc2f84f20;hpb=8cb9ecce8fe4de67c776603dacc9c7f270b3c8bf;p=lilypond.git diff --git a/lily/stencil-integral.cc b/lily/stencil-integral.cc index f5e437bced..b44258b6b1 100644 --- a/lily/stencil-integral.cc +++ b/lily/stencil-integral.cc @@ -190,8 +190,7 @@ make_draw_line_boxes (vector &boxes, vector > &buildings Offset left (x0, y0); Offset right (x1, y1); Offset dir = (right - left).direction (); - Direction d = DOWN; - do + for (DOWN_and_UP (d)) { Offset outward = d * get_normal ((thick / 2) * dir); Offset inter_l = left + outward; @@ -231,7 +230,6 @@ make_draw_line_boxes (vector &boxes, vector > &buildings } } } - while (flip (&d) != DOWN); if (thick > 0.0) { @@ -254,12 +252,15 @@ make_draw_line_boxes (vector &boxes, vector > &buildings } void -make_partial_ellipse_boxes (vector &boxes, vector > &buildings, PangoMatrix trans, SCM expr) +make_partial_ellipse_boxes (vector &boxes, + vector > &buildings, + PangoMatrix trans, SCM expr) { Real x_rad = robust_scm2double (scm_car (expr), 0.0); expr = scm_cdr (expr); Real y_rad = robust_scm2double (scm_car (expr), 0.0); expr = scm_cdr (expr); + Offset rad (x_rad, y_rad); Real start = robust_scm2double (scm_car (expr), 0.0); expr = scm_cdr (expr); Real end = robust_scm2double (scm_car (expr), 0.0); @@ -270,55 +271,51 @@ make_partial_ellipse_boxes (vector &boxes, vector > &bui expr = scm_cdr (expr); bool fill = to_boolean (scm_car (expr)); ////////////////////// - start = M_PI * start / 180; - end = M_PI * end / 180; if (end == start) - end += (2 * M_PI); - Offset sp (cos (start) * x_rad, sin (start) * y_rad); - Offset ep (cos (end) * x_rad, sin (end) * y_rad); + end += 360; + Offset sp (offset_directed (start).scale (rad)); + Offset ep (offset_directed (end).scale (rad)); ////////////////////// Drul_array > points; - Direction d = DOWN; int quantization = max (1, (int) (((x_rad * trans.xx) + (y_rad * trans.yy)) * M_PI / QUANTIZATION_UNIT)); - do + for (DOWN_and_UP (d)) { for (vsize i = 0; i < 1 + (vsize) quantization; i++) { Real ang = linear_map (start, end, 0, quantization, i); - Offset pt (cos (ang) * x_rad, sin (ang) * y_rad); + Offset pt (offset_directed (ang).scale (rad)); Offset inter = pt + d * get_normal ((th/2) * pt.direction ()); pango_matrix_transform_point (&trans, &inter[X_AXIS], &inter[Y_AXIS]); points[d].push_back (inter); } } - while (flip (&d) != DOWN); for (vsize i = 0; i < points[DOWN].size () - 1; i++) { Box b; - do + for (DOWN_and_UP (d)) { b.add_point (points[d][i]); b.add_point (points[d][i + 1]); } - while (flip (&d) != DOWN); boxes.push_back (b); } if (connect || fill) { - make_draw_line_boxes (boxes, buildings, trans, scm_list_5 (scm_from_double (th), - scm_from_double (sp[X_AXIS]), - scm_from_double (sp[Y_AXIS]), - scm_from_double (ep[X_AXIS]), - scm_from_double (ep[Y_AXIS])), + make_draw_line_boxes (boxes, buildings, trans, + scm_list_5 (scm_from_double (th), + scm_from_double (sp[X_AXIS]), + scm_from_double (sp[Y_AXIS]), + scm_from_double (ep[X_AXIS]), + scm_from_double (ep[Y_AXIS])), false); } if (th > 0.0) { // beg line cap - Offset pt (cos (start) * x_rad, sin (start) * y_rad); + Offset pt (offset_directed (start).scale (rad)); create_path_cap (boxes, buildings, trans, @@ -327,7 +324,7 @@ make_partial_ellipse_boxes (vector &boxes, vector > &bui -get_normal (pt)); // end line cap - pt = Offset (cos (end) * x_rad, sin (end) * y_rad); + pt = offset_directed (end).scale (rad); create_path_cap (boxes, buildings, trans, @@ -372,8 +369,8 @@ create_path_cap (vector &boxes, make_partial_ellipse_boxes (boxes, buildings, new_trans, scm_list_n (scm_from_double (rad), scm_from_double (rad), - scm_from_double (angle-90), - scm_from_double (angle+90), + scm_from_double (angle-90.01), + scm_from_double (angle+90.01), scm_from_double (0.0), SCM_BOOL_F, SCM_BOOL_F, @@ -381,7 +378,9 @@ create_path_cap (vector &boxes, } void -make_draw_bezier_boxes (vector &boxes, vector > &buildings, PangoMatrix trans, SCM expr) +make_draw_bezier_boxes (vector &boxes, + vector > &buildings, + PangoMatrix trans, SCM expr) { Real th = robust_scm2double (scm_car (expr), 0.0); expr = scm_cdr (expr); @@ -416,12 +415,11 @@ make_draw_bezier_boxes (vector &boxes, vector > &buildin pango_matrix_transform_point (&trans, &temp3[X_AXIS], &temp3[Y_AXIS]); ////////////////////// Drul_array > points; - Direction d = DOWN; int quantization = int (((temp1 - temp0).length () + (temp2 - temp1).length () + (temp3 - temp2).length ()) / QUANTIZATION_UNIT); - do + for (DOWN_and_UP (d)) { Offset first = curve.control_[0] + d * get_normal ((th / 2) * curve.dir_at_point (0.0)); @@ -440,17 +438,15 @@ make_draw_bezier_boxes (vector &boxes, vector > &buildin pango_matrix_transform_point (&trans, &last[X_AXIS], &last[Y_AXIS]); points[d].push_back (last); } - while (flip (&d) != DOWN); for (vsize i = 0; i < points[DOWN].size () - 1; i++) { Box b; - do + for (DOWN_and_UP (d)) { b.add_point (points[d][i]); b.add_point (points[d][i + 1]); } - while (flip (&d) != DOWN); boxes.push_back (b); } @@ -477,7 +473,8 @@ make_draw_bezier_boxes (vector &boxes, vector > &buildin /* converts a path into lists of 4 (line) or 8 (curve) absolute coordinates for example: - '(moveto 1 2 lineto 3 4 rlineto -1 -1 curveto 3 3 5 5 6 6 rcurveto -1 -1 -1 -1 -1 -1 closepath) + '(moveto 1 2 lineto 3 4 rlineto -1 -1 curveto + 3 3 5 5 6 6 rcurveto -1 -1 -1 -1 -1 -1 closepath) becomes '((1 2 3 4) (3 4 2 3) @@ -590,7 +587,8 @@ all_commands_to_absolute_and_group (SCM expr) } else if (scm_is_eq (scm_car (expr), ly_symbol2scm ("closepath"))) { - if ((current[X_AXIS] != start[X_AXIS]) || (current[Y_AXIS] != start[Y_AXIS])) + if ((current[X_AXIS] != start[X_AXIS]) + || (current[Y_AXIS] != start[Y_AXIS])) { out = scm_cons (scm_list_4 (scm_from_double (current[X_AXIS]), scm_from_double (current[Y_AXIS]), @@ -612,7 +610,9 @@ all_commands_to_absolute_and_group (SCM expr) } void -internal_make_path_boxes (vector &boxes, vector > &buildings, PangoMatrix trans, SCM expr, bool use_building) +internal_make_path_boxes (vector &boxes, + vector > &buildings, + PangoMatrix trans, SCM expr, bool use_building) { SCM blot = scm_car (expr); expr = scm_cdr (expr); @@ -628,13 +628,17 @@ internal_make_path_boxes (vector &boxes, vector > &build } void -make_path_boxes (vector &boxes, vector > &buildings, PangoMatrix trans, SCM expr) +make_path_boxes (vector &boxes, + vector > &buildings, + PangoMatrix trans, SCM expr) { return internal_make_path_boxes (boxes, buildings, trans, scm_cons (scm_car (expr), get_path_list (scm_cdr (expr))), false); } void -make_polygon_boxes (vector &boxes, vector > &buildings, PangoMatrix trans, SCM expr) +make_polygon_boxes (vector &boxes, + vector > &buildings, + PangoMatrix trans, SCM expr) { SCM coords = get_number_list (scm_car (expr)); expr = scm_cdr (expr); @@ -650,11 +654,14 @@ make_polygon_boxes (vector &boxes, vector > &buildings, first = false; } l = scm_cons (ly_symbol2scm ("closepath"), l); - internal_make_path_boxes (boxes, buildings, trans, scm_cons (blot_diameter, scm_reverse_x (l, SCM_EOL)), true); + internal_make_path_boxes (boxes, buildings, trans, + scm_cons (blot_diameter, scm_reverse_x (l, SCM_EOL)), true); } void -make_named_glyph_boxes (vector &boxes, vector > &buildings, PangoMatrix trans, SCM expr) +make_named_glyph_boxes (vector &boxes, + vector > &buildings, + PangoMatrix trans, SCM expr) { SCM fm_scm = scm_car (expr); Font_metric *fm = unsmob (fm_scm); @@ -672,7 +679,8 @@ make_named_glyph_boxes (vector &boxes, vector > &buildin // Bbox is the best approximation of the width based on how it would be // calculated in open-type-font.cc if it were based on real extents Box bbox = open_fm->get_unscaled_indexed_char_dimensions (gidx); - bbox.scale (dynamic_cast(fm)->get_magnification () * open_fm->design_size () / open_fm->get_units_per_EM ()); + bbox.scale (dynamic_cast (fm)->get_magnification () + * open_fm->design_size () / open_fm->get_units_per_EM ()); // Real bbox is the real bbox of the object Box real_bbox = open_fm->get_glyph_outline_bbox (gidx); @@ -687,13 +695,18 @@ make_named_glyph_boxes (vector &boxes, vector > &buildin s = scm_cdr (s)) { scm_to_int (scm_length (scm_car (s))) == 4 - ? make_draw_line_boxes (boxes, buildings, trans, scm_cons (scm_from_double (0), scm_car (s)), false) - : make_draw_bezier_boxes (boxes, buildings, trans, scm_cons (scm_from_double (0), scm_car (s))); + ? make_draw_line_boxes (boxes, buildings, trans, + scm_cons (scm_from_double (0), scm_car (s)), + false) + : make_draw_bezier_boxes (boxes, buildings, trans, + scm_cons (scm_from_double (0), scm_car (s))); } } void -make_glyph_string_boxes (vector &boxes, vector > &buildings, PangoMatrix trans, SCM expr) +make_glyph_string_boxes (vector &boxes, + vector > &buildings, + PangoMatrix trans, SCM expr) { SCM fm_scm = scm_car (expr); Font_metric *fm = unsmob (fm_scm); @@ -763,10 +776,13 @@ make_glyph_string_boxes (vector &boxes, vector > &buildi Real scale_factor = max (xlen, ylen); // the three operations below move the stencil from its original coordinates to current coordinates - pango_matrix_translate (&transcopy, kerned_bbox[X_AXIS][LEFT], kerned_bbox[Y_AXIS][DOWN] - real_bbox[Y_AXIS][DOWN]); - pango_matrix_translate (&transcopy, real_bbox[X_AXIS][LEFT], real_bbox[Y_AXIS][DOWN]); + pango_matrix_translate (&transcopy, kerned_bbox[X_AXIS][LEFT], + kerned_bbox[Y_AXIS][DOWN] - real_bbox[Y_AXIS][DOWN]); + pango_matrix_translate (&transcopy, real_bbox[X_AXIS][LEFT], + real_bbox[Y_AXIS][DOWN]); pango_matrix_scale (&transcopy, scale_factor, scale_factor); - pango_matrix_translate (&transcopy, -bbox[X_AXIS][LEFT], -bbox[Y_AXIS][DOWN]); + pango_matrix_translate (&transcopy, -bbox[X_AXIS][LEFT], + -bbox[Y_AXIS][DOWN]); } ////////////////////// for (SCM s = outline; @@ -774,8 +790,11 @@ make_glyph_string_boxes (vector &boxes, vector > &buildi s = scm_cdr (s)) { scm_to_int (scm_length (scm_car (s))) == 4 - ? make_draw_line_boxes (boxes, buildings, transcopy, scm_cons (scm_from_double (0), scm_car (s)), false) - : make_draw_bezier_boxes (boxes, buildings, transcopy, scm_cons (scm_from_double (0), scm_car (s))); + ? make_draw_line_boxes (boxes, buildings, transcopy, + scm_cons (scm_from_double (0), scm_car (s)), + false) + : make_draw_bezier_boxes (boxes, buildings, transcopy, + scm_cons (scm_from_double (0), scm_car (s))); } } } @@ -786,7 +805,9 @@ make_glyph_string_boxes (vector &boxes, vector > &buildi */ void -stencil_dispatcher (vector &boxes, vector > &buildings, PangoMatrix trans, SCM expr) +stencil_dispatcher (vector &boxes, + vector > &buildings, + PangoMatrix trans, SCM expr) { if (not scm_is_pair (expr)) return; @@ -802,7 +823,9 @@ stencil_dispatcher (vector &boxes, vector > &buildings, SCM x1 = scm_car (expr); expr = scm_cdr (expr); SCM x2 = scm_car (expr); - make_draw_line_boxes (boxes, buildings, trans, scm_list_5 (th, scm_from_double (0.0), scm_from_double (0.0), x1, x2), true); + make_draw_line_boxes (boxes, buildings, trans, + scm_list_5 (th, scm_from_double (0.0), + scm_from_double (0.0), x1, x2), true); } else if (scm_is_eq (scm_car (expr), ly_symbol2scm ("circle"))) { @@ -871,16 +894,16 @@ stencil_dispatcher (vector &boxes, vector > &buildings, vector stencil_traverser (PangoMatrix trans, SCM expr) { - if (scm_is_null (expr)) - return vector (); - else if (scm_is_eq (expr, ly_string2scm (""))) + if (scm_is_null (expr) + || (scm_is_string (expr) && scm_is_true (scm_string_null_p (expr)))) return vector (); else if (scm_is_eq (scm_car (expr), ly_symbol2scm ("combine-stencil"))) { vector out; for (SCM s = scm_cdr (expr); scm_is_pair (s); s = scm_cdr (s)) { - vector res = stencil_traverser (trans, scm_car (s)); + vector res = + stencil_traverser (trans, scm_car (s)); out.insert (out.end (), res.begin (), res.end ()); } return out; @@ -920,8 +943,10 @@ stencil_traverser (PangoMatrix trans, SCM expr) return stencil_traverser (trans, scm_caddr (expr)); else if (scm_is_eq (scm_car (expr), ly_symbol2scm ("transparent-stencil"))) return stencil_traverser (trans, scm_cadr (expr)); - else if (scm_is_eq (scm_car (expr), ly_symbol2scm ("id"))) + else if (scm_is_eq (scm_car (expr), ly_symbol2scm ("output-attributes"))) return stencil_traverser (trans, scm_caddr (expr)); + else if (scm_is_eq (scm_car (expr), ly_symbol2scm ("with-outline"))) + return stencil_traverser (trans, scm_cadr (expr)); else { vector out;