[reportlab-users] Chinese text (unicode) is not shown in acrobat ( with asian font support ) but is correctly rendered with other interpreters (ghostview)

Marius Gedminas reportlab-users@reportlab.com
Thu, 11 Sep 2003 01:01:59 +0300


--G4iJoqBmSsgzjUCe
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Sep 10, 2003 at 12:16:55PM +0200, Ismael Canales Luis wrote:
> The font that I use is the ttf mingliu.
>=20
> My code is something like.
>=20
> class card( canvas.Canvas ) :
>=20
>=20
> pdfmetrics.registerFont(TTFont('mingliu','mingliu.ttf'))
>=20
> ....
>=20
> canvas.Canvas.setFont("mingliu",14)
> canvas.Canvas.drawString(5.0805*mm,22.5*mm,u'\xE5\xBC\xB5\xE7\xB6\xAD\xE5=
\x8B\x9D')=20

You need to pass a UTF-8 encoded simple string, and not a Unicode
string.  If you really do have a Unicode string, say, in a variable
called `s', you could write

  canvas.Canvas.drawString(5.0805*mm, 22.5*mm, s.encode('UTF-8'))

But the string you used does not look Chinese to me.  It is a sequence
of the following Unicode characters:

  U+00E5  =E5  LATIN SMALL LETTER A WITH RING ABOVE
  U+00BC  =BC  VULGAR FRACTION ONE QUARTER
  U+00B5  =B5  MICRO SIGN
  U+00E7  =E7  LATIN SMALL LETTER C WITH CEDILLA
  ...

If the text is already encoded in UTF-8, just drop the u prefix.  If it
is encoded in some other encoding, you need to recode it to UTF-8.


AFAIU there are plans to support Unicode strings directly in future
versions of Reportlab (once Python 1.5.2 compatibility is dropped).

> Could somebody help me ? what is happen here ?

It would be a good idea to say what results you saw and what your
expectations were.

HTH,
Marius Gedminas
--=20
The *REAL* Y2K is the year 2048.

--G4iJoqBmSsgzjUCe
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/X59XkVdEXeem148RAm9OAJ9AWXpxeMtYSj1na/anO1IFUclVYgCePjxJ
XZSPEtWhTtLRANJ5+9ep2XU=
=rDDU
-----END PGP SIGNATURE-----

--G4iJoqBmSsgzjUCe--