[PATCH] Issue 3778: Use bounding box as skylines for markup in svg backend

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Issue 3778: Use bounding box as skylines for markup in svg backend

Kevin Barry
As there is no routine for determining skylines for utf-8-string
stencils, they normally fall back to the grob's bounding box, which is
fine. However, when there is a mixture of utf-8-string and other types
of stencil (which have associated skyline functions) in a single grob,
the entire grob gets a skyline determined only from the non-utf-8-string
stencils. This sometimes causes the text portion of such mixed grobs
(e.g.  metronome marks) to collide with other grobs.

While looping over the stencils, check for utf-8-string and if found,
clear the skylines and break out of the loop. Empty skylines forces a
fallback to the grob's bounding box, which restores the behaviour from
before the patch to improve skyline approximations (issue 2148). This
does not fix the issue that there is no routine for determining skylines
for utf-8-strings when the backend is svg, but it does at least remove
the collisions without changing the behaviour in non-broken situations.
---
 lily/stencil-integral.cc | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lily/stencil-integral.cc b/lily/stencil-integral.cc
index 7b12eaf17b..47179148cd 100644
--- a/lily/stencil-integral.cc
+++ b/lily/stencil-integral.cc
@@ -1097,7 +1097,14 @@ Stencil::skylines_from_stencil (SCM sten, Real pad, SCM rot, Axis a)
   vector<Box> boxes;
   vector<Drul_array<Offset> > buildings;
   for (SCM s = scm_reverse_x (data, SCM_EOL); scm_is_pair (s); s = scm_cdr (s))
-    stencil_dispatcher (boxes, buildings, scm_caar (s), scm_cdar (s));
+    {
+      // If any stencils are utf-8-string, fall back on the bounding box
+      if (scm_is_eq (scm_cadar (s), ly_symbol2scm ("utf-8-string"))) {
+          boxes.clear();
+          break;
+      }
+      stencil_dispatcher (boxes, buildings, scm_caar (s), scm_cdar (s));
+    }
 
   // we use the bounding box if there are no boxes
   // FIXME: Rotation?
--
2.25.3


Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Issue 3778: Use bounding box as skylines for markup in svg backend

Han-Wen Nienhuys-3
Can you add  a regression test that shows the problem?

On Fri, Apr 24, 2020 at 8:50 PM Kevin Barry <[hidden email]> wrote:

>
> As there is no routine for determining skylines for utf-8-string
> stencils, they normally fall back to the grob's bounding box, which is
> fine. However, when there is a mixture of utf-8-string and other types
> of stencil (which have associated skyline functions) in a single grob,
> the entire grob gets a skyline determined only from the non-utf-8-string
> stencils. This sometimes causes the text portion of such mixed grobs
> (e.g.  metronome marks) to collide with other grobs.
>
> While looping over the stencils, check for utf-8-string and if found,
> clear the skylines and break out of the loop. Empty skylines forces a
> fallback to the grob's bounding box, which restores the behaviour from
> before the patch to improve skyline approximations (issue 2148). This
> does not fix the issue that there is no routine for determining skylines
> for utf-8-strings when the backend is svg, but it does at least remove
> the collisions without changing the behaviour in non-broken situations.
> ---
>  lily/stencil-integral.cc | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/lily/stencil-integral.cc b/lily/stencil-integral.cc
> index 7b12eaf17b..47179148cd 100644
> --- a/lily/stencil-integral.cc
> +++ b/lily/stencil-integral.cc
> @@ -1097,7 +1097,14 @@ Stencil::skylines_from_stencil (SCM sten, Real pad, SCM rot, Axis a)
>    vector<Box> boxes;
>    vector<Drul_array<Offset> > buildings;
>    for (SCM s = scm_reverse_x (data, SCM_EOL); scm_is_pair (s); s = scm_cdr (s))
> -    stencil_dispatcher (boxes, buildings, scm_caar (s), scm_cdar (s));
> +    {
> +      // If any stencils are utf-8-string, fall back on the bounding box
> +      if (scm_is_eq (scm_cadar (s), ly_symbol2scm ("utf-8-string"))) {
> +          boxes.clear();
> +          break;
> +      }
> +      stencil_dispatcher (boxes, buildings, scm_caar (s), scm_cdar (s));
> +    }
>
>    // we use the bounding box if there are no boxes
>    // FIXME: Rotation?
> --
> 2.25.3
>
>


--
Han-Wen Nienhuys - [hidden email] - http://www.xs4all.nl/~hanwen

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Issue 3778: Use bounding box as skylines for markup in svg backend

Kevin Barry
On Fri, Apr 24, 2020 at 09:18:10PM +0200, Han-Wen Nienhuys wrote:
> Can you add  a regression test that shows the problem?

Yes. I'll go read the docs to see how to do that and do one up (but feel
free to point me in the right direction...)

Kevin

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Issue 3778: Use bounding box as skylines for markup in svg backend

Han-Wen Nienhuys-3
On Fri, Apr 24, 2020 at 9:21 PM Kevin Barry <[hidden email]> wrote:
>
> On Fri, Apr 24, 2020 at 09:18:10PM +0200, Han-Wen Nienhuys wrote:
> > Can you add  a regression test that shows the problem?
>
> Yes. I'll go read the docs to see how to do that and do one up (but feel
> free to point me in the right direction...)

Just add a test file under input/regression/ , following the style of
other files there.

--
Han-Wen Nienhuys - [hidden email] - http://www.xs4all.nl/~hanwen

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Issue 3778: Use bounding box as skylines for markup in svg backend

Kevin Barry
On Fri, Apr 24, 2020 at 09:25:19PM +0200, Han-Wen Nienhuys wrote:
> Just add a test file under input/regression/ , following the style of
> other files there.

Thanks for the pointer. The only other svg backend file there looks like
it has been deliberately disabled, so apologies if I have done this
wrong. A revised patch will follow with an added regression test.

Kevin