[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-2d-dev
Subject:    Re: [OpenJDK 2D-Dev] [PATCH] Make automatic font substitution on macOS work for surrogate pairs
From:       Dmitry Batrak <dmitry.batrak () jetbrains ! com>
Date:       2016-10-27 8:56:43
Message-ID: CAET5FPuJcKGY4XHQ_j=CUNyVVDwgbbDF14KoLxPmvAfmz0xMMQ () mail ! gmail ! com
[Download RAW message or body]

Sure, here's the simplest test, that can be used for visual inspection:

import javax.swing.*;
import java.awt.*;

public class SurrogatesFallbackTest {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            JFrame frame = new JFrame();
            JLabel label = new JLabel(new
String(Character.toChars(0x1d400))); // MATHEMATICAL BOLD CAPITAL A
            label.setFont(new Font("Menlo", Font.PLAIN, 36)); // expected
to fallback to STIXGeneral
            frame.add(label);
            frame.pack();
            frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        });
    }
}

I can convert it to an automatic test (rendering to a bitmap and comparing
the result to rendering of 'missing' glyph), and add it to the webrev, if
that makes sense.

Best regards,
Dmitry Batrak

On Thu, Oct 27, 2016 at 2:17 AM, Philip Race <philip.race@oracle.com> wrote:

> Hi,
>
> I can file a bug on this if I can't find one.
> If you can email me the test it will help even if it is not checked in.
>
> -phil.
>
> On 10/26/16, 6:28 AM, Dmitry Batrak wrote:
>
> Hello,
>
> I'd like to propose a patch to make automatic font substitution on macOS
> work for surrogate pairs.
> I have a Contributor status via agreement signed by JetBrains, hope
> someone can sponsor the patch.
>
> Currently, if requested font cannot render a Unicode character represented
> by a surrogate pair,
> no substitution is performed - Font.canDisplay will return false, and the
> character will be
> rendered as a 'missing' glyph. This behaviour doesn't violate any
> specification, but it looks like
> it can be easily improved, as underlying OS framework used under the hood
> does support surrogate pairs.
>
> The proposed change consists of two parts. First part is adjusting the
> code in CoreTextSupport.m
> to handle surrogate pairs while performing char-to-glyph mapping, by
> encoding non-displayable
> surrogate pairs using negative values of the codepoint, similar to how
> non-displayable BMP characters
> are encoded. Second part is fixing the rendering code (in
> CGGlyphImages.m), where wrong type was used
> to pass character values around, so that code for surrogate pairs
> handling, already present there,
> could work.
>
> I didn't include a test for this change, as it would depend on OS-specific
> font fallback mechanism
> and fonts installed, but I can create one that will work on a latest
> version of macOS with default
> fonts, if needed.
>
> Webrev for the fix is available at
> http://cr.openjdk.java.net/~avu/rfe_surrogates/webrev.00/
> (kindly posted by my colleague, having access to cr.openjdk.java.net).
>
> To my knowledge, there's no ticket in OpenJDK issue tracker for the
> proposed enhancement.
> I can submit it via http://bugs.java.com/, if that's an obstacle.
>
> Best regards,
> Dmitry Batrak
>
>


-- 
Dmitry Batrak
Senior Software Developer
JetBrains
http://www.jetbrains.com
The Drive to Develop

[Attachment #3 (text/html)]

<div dir="ltr">Sure, here&#39;s the simplest test, that can be used for visual \
inspection:<div><br></div><div><div>import javax.swing.*;</div><div>import \
java.awt.*;</div><div><br></div><div>public class SurrogatesFallbackTest {</div><div> \
public static void main(String[] args) {</div><div>            \
SwingUtilities.invokeLater(() -&gt; {</div><div>                  JFrame frame = new \
JFrame();</div><div>                  JLabel label = new JLabel(new \
String(Character.toChars(0x1d400))); // MATHEMATICAL BOLD CAPITAL A</div><div>        \
label.setFont(new Font(&quot;Menlo&quot;, Font.PLAIN, 36)); // expected to fallback \
to STIXGeneral</div><div>                  frame.add(label);</div><div>               \
frame.pack();</div><div>                  \
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);</div><div>             \
frame.setLocationRelativeTo(null);</div><div>                  \
frame.setVisible(true);</div><div>            });</div><div>      \
}</div><div>}</div></div><div><br></div><div>I can convert it to an automatic test \
(rendering to a bitmap and comparing the result to rendering of &#39;missing&#39; \
glyph), and add it to the webrev, if that makes sense.</div><div><br></div><div>Best \
regards,</div><div>Dmitry Batrak</div></div><div class="gmail_extra"><br><div \
class="gmail_quote">On Thu, Oct 27, 2016 at 2:17 AM, Philip Race <span \
dir="ltr">&lt;<a href="mailto:philip.race@oracle.com" \
target="_blank">philip.race@oracle.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    Hi,<br>
    <br>
    I can file a bug on this if I can&#39;t find one.<br>
    If you can email me the test it will help even if it is not checked
    in.<br>
    <br>
    -phil.<br>
    <br>
    On 10/26/16, 6:28 AM, Dmitry Batrak wrote:
    <blockquote type="cite">
      <div dir="ltr">Hello,<br>
        <br>
        I&#39;d like to propose a patch to make automatic font substitution
        on macOS work for surrogate pairs.<br>
        I have a Contributor status via agreement signed by JetBrains,
        hope someone can sponsor the patch.<br>
        <br>
        Currently, if requested font cannot render a Unicode character
        represented by a surrogate pair,<br>
        no substitution is performed - Font.canDisplay will return
        false, and the character will be<br>
        rendered as a &#39;missing&#39; glyph. This behaviour doesn&#39;t violate
        any specification, but it looks like<br>
        it can be easily improved, as underlying OS framework used under
        the hood does support surrogate pairs.<br>
        <br>
        The proposed change consists of two parts. First part is
        adjusting the code in CoreTextSupport.m <br>
        to handle surrogate pairs while performing char-to-glyph
        mapping, by encoding non-displayable <br>
        surrogate pairs using negative values of the codepoint, similar
        to how non-displayable BMP characters<br>
        are encoded. Second part is fixing the rendering code (in
        CGGlyphImages.m), where wrong type was used<br>
        to pass character values around, so that code for surrogate
        pairs handling, already present there, <br>
        could work.<br>
        <br>
        I didn&#39;t include a test for this change, as it would depend on
        OS-specific font fallback mechanism<br>
        and fonts installed, but I can create one that will work on a
        latest version of macOS with default<br>
        fonts, if needed.<br>
        <br>
        Webrev for the fix is available at<br>
        <a href="http://cr.openjdk.java.net/%7Eavu/rfe_surrogates/webrev.00/" \
target="_blank">http://cr.openjdk.java.net/~<wbr>avu/rfe_surrogates/webrev.00/</a><br>
                
        (kindly posted by my colleague, having access to <a \
href="http://cr.openjdk.java.net" target="_blank">cr.openjdk.java.net</a>).<br>  <br>
        To my knowledge, there&#39;s no ticket in OpenJDK issue tracker for
        the proposed enhancement. <br>
        I can submit it via <a href="http://bugs.java.com/" \
target="_blank">http://bugs.java.com/</a>, if  that&#39;s an obstacle.<br>
        <br>
        Best regards,<br>
        Dmitry Batrak</div>
    </blockquote>
  </div>

</blockquote></div><br><br clear="all"><div><br></div>-- <br><div \
class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div \
dir="ltr">Dmitry Batrak<br>Senior Software Developer<br>JetBrains<br><a \
href="http://www.jetbrains.com" target="_blank">http://www.jetbrains.com</a><br>The \
Drive to Develop<br></div></div></div></div> </div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic