public final byte[] encode(String text) throws IOException
    {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int offset = 0;
        while (offset < text.length())
        {
            int codePoint = text.codePointAt(offset);

            // multi-byte encoding with 1 to 4 bytes
            byte[] bytes = encode(codePoint);
            out.write(bytes);

            offset += Character.charCount(codePoint);
        }
        return out.toByteArray();
    }
@Test
    void testPDFox4318() throws IOException
    {
        PDType1Font helveticaBold = new PDType1Font(FontName.HELVETICA_BOLD);
        assertThrows(IllegalArgumentException.class,
                () -> helveticaBold.encode("\u0080"),
                "should have thrown IllegalArgumentException");
        helveticaBold.encode("€");
        assertThrows(IllegalArgumentException.class,
                () -> helveticaBold.encode("\u0080"),
                "should have thrown IllegalArgumentException");
    }