Uploaded image for project: 'FOP'
  1. FOP
  2. FOP-2884

Rendering emoji doesn't work

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 2.3
    • None
    • font/unqualified
    • None
    • oracle-jdk-11, ubuntu Linux

    Description

      The following code (in Scala, but it's easy enough to understand for Java-devs) renders the smiley-emoji 😃 as '#'-character.

       

      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)
         }
      }
      
      

      The output in the PDF is "Hi # smile!" instead of "Hi 😃 smile!"

       

      Attachments

        1. pdf_with_smiley_test.pdf
          5 kB
          Andreas Joseph Krogh

        Activity

          People

            Unassigned Unassigned
            andreak Andreas Joseph Krogh
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: