[jira] [Created] (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] [Created] (FOP-2884) Rendering emoji doesn't work

Andreas Joseph Krogh (Jira)
Andreas Joseph Krogh created FOP-2884:
-----------------------------------------

             Summary: 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
         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)