Re: Font names using multi-byte strings

Luca Bellonda <[email protected]> Thu, 29 Jan 2026 20:53:18 +0100
Newsgroups gmane.text.xml.fop.user
Message-ID <CAK+9=OYryicHkz6x9edTgyWwMWzu0TAt2Q-hvcgnZv2WGER1Bg@mail.gmail.com>
--000000000000fbb77306498c3547
Content-Type: text/plain; charset="UTF-8"

I was able to get the same name and I suggest this method:
1- Translate the string to UTF-8 bytes representation.
2- Get the bytes and encode them instead of characters.

This way the UTF-8 statement should be respected.
In code (beware: not efficient and without error management):

in escapeName of PDFName:

   byte[] characters ;
 // get UTF-8 bytes
   try {
        characters = name.substring((skipFirst ? 1 : 0)).getBytes("UTF-8");
      } catch (UnsupportedEncodingException e) {
          throw new RuntimeException("Invalid Name:"+name);
      }

// encode bytes
        for (int i = 0, c = characters.length; i < c; i++) {
        int ch = (0x00FF&characters[i]);

            if (ch < 33 || ch > 126 || ESCAPED_NAME_CHARS.indexOf(ch) >= 0)
{
                sb.append('#');
                toHex(ch, sb);
            } else {
            char cxc = (char)ch ;
                sb.append(cxc);
            }
        }
        return sb.toString();

where toHex() manages an int

Best regards.

Il giorno gio 29 gen 2026 alle ore 01:28 Joao Andre Goncalves <
[email protected]> ha scritto:

> I tried that earlier but while the PDF is valid, the font name would not
> match the original PDF. I did find the following on the ISO document:
>
> c) Any character that is not a regular character shall be written using
> its 2-digit hexadecimal code, preceded by the NUMBER SIGN only.
>
>
>

--000000000000fbb77306498c3547
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I was able to get the same name and I suggest this me=
thod:</div><div>1- Translate the string to UTF-8 bytes representation.</div=
><div>2- Get the bytes and encode them instead of characters.</div><div><br=
></div><div>This way the UTF-8 statement should be respected.</div><div>In =
code (beware: not efficient and without error management):</div><div><br></=
div><div>in escapeName of PDFName:</div><div><br></div><div>=C2=A0 =C2=A0by=
te[] characters ;</div><div>=C2=A0// get UTF-8 bytes</div><div>=C2=A0 =C2=
=A0try {<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 characters =3D name.substring((skip=
First ? 1 : 0)).getBytes(&quot;UTF-8&quot;);<br>=C2=A0 =C2=A0 =C2=A0 } catc=
h (UnsupportedEncodingException e) {<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
throw new RuntimeException(&quot;Invalid Name:&quot;+name);<br>=C2=A0 =C2=
=A0 =C2=A0 }<br><br></div><div>// encode bytes</div><div>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 for (int i =3D 0, c =3D characters.length; i &lt; c; i++) {<br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 	int ch =3D (0x00FF&amp;characters[i]);<br>=C2=
=A0<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ch &lt; 33 || ch &gt; =
126 || ESCAPED_NAME_CHARS.indexOf(ch) &gt;=3D 0) {<br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 sb.append(&#39;#&#39;);<br>=C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 toHex(ch, sb);<br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else {<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 	char cxc =3D (char)ch ;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 sb.append(cxc);<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 }<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 retur=
n sb.toString();</div><div><br></div><div>where toHex() manages an int</div=
><div dir=3D"ltr"><br></div><div>Best regards.</div><br><div class=3D"gmail=
_quote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">Il gior=
no gio 29 gen 2026 alle ore 01:28 Joao Andre Goncalves &lt;<a href=3D"mailt=
o:[email protected]">[email protected]</a=
>&gt; ha scritto:<br></div><blockquote class=3D"gmail_quote" style=3D"margi=
n:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex=
"><div class=3D"msg2745103359603172787">





<div lang=3D"EN-GB" style=3D"overflow-wrap: break-word;">
<div class=3D"m_2745103359603172787WordSection1">
<p class=3D"MsoNormal"><span style=3D"font-size:11pt">I tried that earlier =
but while the PDF is valid, the font name would not match the original PDF.=
 I did find the following on the ISO document:<br>
<br>
<u></u><u></u></span></p>
<p class=3D"MsoNormal" style=3D"margin-left:36pt"><span style=3D"font-size:=
11pt">c) Any character that is not a regular character shall be written usi=
ng its 2-digit hexadecimal code, preceded by the NUMBER SIGN only.
<br>
<br>
<u></u><u></u></span></p>
<p class=3D"MsoNormal"><br></p><div><div><blockquote style=3D"border-width:=
medium medium medium 1pt;border-style:none none none solid;border-color:cur=
rentcolor currentcolor currentcolor rgb(204,204,204);padding:0cm 0cm 0cm 6p=
t;margin-left:4.8pt;margin-right:0cm">
</blockquote>
</div>
</div>
</div>
</div>

</div></blockquote></div></div>

--000000000000fbb77306498c3547--