[jira] [Commented] (FOP-2884) Rendering emoji doesn't work

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (FOP-2884) Rendering emoji doesn't work

Andreas Joseph Krogh (Jira)

    [ https://issues.apache.org/jira/browse/FOP-2884?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16938883#comment-16938883 ]

Andreas Joseph Krogh commented on FOP-2884:
-------------------------------------------

It works when I embed the font explicitly (is that what this is doing?) with this config:

 
{code:java}
<?xml version="1.0" encoding="UTF-8"?>
<fop version="1.0">  <renderers>
    <renderer mime="application/pdf">
      <fonts>
        <font embed-url="/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf">
          <font-triplet name="DejaVuSans" style="normal" weight="normal"/>
        </font>
      </fonts>
    </renderer>
  </renderers>
</fop>
{code}
And have this test.fo

 

 
{code:java}
<?xml version="1.0" encoding="utf-8"?><?xml version="1.0" encoding="utf-8"?><fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"  xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">  <fo:layout-master-set>    <fo:simple-page-master master-name="simple" page-height="27.9cm" page-width="21.6cm">      <fo:region-body margin="1cm"/>    </fo:simple-page-master>  </fo:layout-master-set>  <fo:page-sequence master-reference="simple">    <fo:flow flow-name="xsl-region-body">      <fo:block font-family="DejaVuSans" font-size="30pt">Smile 😃</fo:block>       </fo:flow>  </fo:page-sequence></fo:root>
{code}
Then generate with:
{code:java}
./fop test.fo -c fop.xconf smile.pdf
{code}
Thanks for pointing me in the right direction!

 

> Rendering emoji doesn't work
> ----------------------------
>
>                 Key: FOP-2884
>                 URL: https://issues.apache.org/jira/browse/FOP-2884
>             Project: FOP
>          Issue Type: Bug
>          Components: font/unqualified
>    Affects Versions: 2.3
>         Environment: oracle-jdk-11, ubuntu Linux
>            Reporter: Andreas Joseph Krogh
>            Priority: Major
>         Attachments: pdf_with_smiley_test.pdf
>
>
> The following code (in Scala, but it's easy enough to understand for Java-devs) renders the smiley-emoji 😃 as '#'-character.
>  
> {code:java}
> import java.io.ByteArrayInputStream
> import java.nio.file.{Files, Paths, StandardOpenOption}
> import javax.xml.transform.sax.SAXResult
> import javax.xml.transform.stream.StreamSource
> import javax.xml.transform.{Result, Transformer, TransformerFactory}
> import org.apache.fop.apps.{Fop, FopFactoryBuilder}
> import org.apache.xmlgraphics.util.MimeConstants
> import org.testng.annotations.Test
> class PdfWithSmileyTest {
>    @Test
>    def generatePdfWithSmileyTets(): Unit = {
>       val xml =
>          """<?xml version="1.0" encoding="utf-8"?>
>            |<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
>            |<fo:layout-master-set>
>            |    <fo:simple-page-master
>            |          margin-right="17mm"
>            |          margin-left="17mm"
>            |          margin-bottom="0cm"
>            |          margin-top="14mm"
>            |          page-width="29.1cm"
>            |          page-height="21cm"
>            |          master-name="document">
>            |       <fo:region-body margin-top="13mm" margin-bottom="20mm" background-color="#ffffff"/>
>            |       <fo:region-before extent="10mm" region-name="header" background-color="#ffffff"/>
>            |       <fo:region-after extent="15mm" region-name="footer" background-color="#ffffff"/>
>            |    </fo:simple-page-master>
>            |</fo:layout-master-set>
>            |<fo:page-sequence master-reference="document">
>            |<fo:flow flow-name="xsl-region-body" font-family="Times">
>            |<fo:block linefeed-treatment="preserve">Hi 😃 smile!</fo:block>
>            |</fo:flow>
>            |</fo:page-sequence>
>            |</fo:root>
>            |""".stripMargin
>       val tmpFilePath = Paths.get("/tmp/pdf_with_smiley_test.pdf")
>       val out = Files.newOutputStream(tmpFilePath, StandardOpenOption.TRUNCATE_EXISTING)
>       val fopFactory = new FopFactoryBuilder(getClass.getResource("/").toURI).build
>       val agent = fopFactory.newFOUserAgent()
>       val fop: Fop = fopFactory.newFop(MimeConstants.MIME_PDF, agent, out)
>       val transformer: Transformer = TransformerFactory.newInstance.newTransformer
>       val res: Result = new SAXResult(fop.getDefaultHandler)
>       val source = new StreamSource(new ByteArrayInputStream(xml.getBytes()))
>       transformer.transform(source, res)
>    }
> }
> {code}
> The output in the PDF is "Hi # smile!" instead of "Hi 😃 smile!"
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)