universal unicode font for reportlab

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Laszlo Nagy

    universal unicode font for reportlab

    I need to create multi lingual invoices from reportlab. I think it is
    possible to use UTF 8 strings but there is a problem with the font. I
    could not find any free TTF font that can do latin1, latin2, arabic,
    chinese and other languages at the same time. Is there a single font
    that is able to handle these languages? (Most of our invoices will be
    for EN, FR, DE, HU, SK, CZ, RO but some of them needs to be in Chinese.)

    Thanks,

    Laszlo

  • Ben Finney

    #2
    Re: universal unicode font for reportlab

    Laszlo Nagy <gandalf@shopze us.comwrites:
    I could not find any free TTF font that can do latin1, latin2,
    arabic, chinese and other languages at the same time. Is there a
    single font that is able to handle these languages?
    The GNU Unifont <URL:http://en.wikipedia.or g/wiki/GNU_Unifont>
    <URL:http://unifoundry.com/unifont.htmlcov ers an impressive range of
    the Unicode Basic Multilingual Plane.

    Unifont is originally a bitmap font, but was recently made available
    in TrueType format
    <URL:http://www.lgm.cl/trabajos/unifont/index.en.html>.

    Both are available in Debian 'lenny'; the 'unifont' and 'ttf-unifont'
    packages, respectively.

    --
    \ “Science doesn't work by vote and it doesn't work by |
    `\ authority.” —Richard Dawkins, _Big Mistake_ (The Guardian, |
    _o__) 2006-12-27) |
    Ben Finney

    Comment

    • Laszlo Nagy

      #3
      Re: universal unicode font for reportlab

      Laszlo Nagy <gandalf@shopze us.comwrites:
      >
      >
      >I could not find any free TTF font that can do latin1, latin2,
      >arabic, chinese and other languages at the same time. Is there a
      >single font that is able to handle these languages?
      >>
      >
      The GNU Unifont <URL:http://en.wikipedia.or g/wiki/GNU_Unifont>
      <URL:http://unifoundry.com/unifont.htmlcov ers an impressive range of
      the Unicode Basic Multilingual Plane.
      >
      Unifont is originally a bitmap font, but was recently made available
      in TrueType format
      <URL:http://www.lgm.cl/trabajos/unifont/index.en.html>.
      >
      Both are available in Debian 'lenny'; the 'unifont' and 'ttf-unifont'
      packages, respectively.
      >
      I found out that dejavu is what I need. It covers the languages I need
      and more:

      Download DejaVu fonts for free. The DejaVu fonts are a font family based on the Bitstream Vera Fonts. Its purpose is to provide a wider range of characters while maintaining the original look and feel.



      Thanks four your help!

      L

      Comment

      • Laszlo Nagy

        #4
        Re: universal unicode font for reportlab

        >>
        >The GNU Unifont <URL:http://en.wikipedia.or g/wiki/GNU_Unifont>
        ><URL:http://unifoundry.com/unifont.htmlcov ers an impressive range of
        >the Unicode Basic Multilingual Plane.
        >>
        >Unifont is originally a bitmap font, but was recently made available
        >in TrueType format
        ><URL:http://www.lgm.cl/trabajos/unifont/index.en.html>.
        >>
        >Both are available in Debian 'lenny'; the 'unifont' and 'ttf-unifont'
        >packages, respectively.
        I found out that dejavu is what I need. It covers the languages I need
        and more:
        >
        http://dejavu.svn.sourceforge.net/vi.../langcover.txt
        Sorry, this did not work either. Dejavu does support cyrillic and greek
        characters but I have to load a different ttf for that. They are no
        unified. :-( The only one that worked so far was "unifont.tf f" but it is
        very ugly above point size=10.

        Can you tell me what kind of font Geany is using on my Ubuntu system?
        The preferences tells that it is "monospace" but when I load
        VeraMono.ttf in reportlab, it will not even display latin2 characters.
        In contrast, please look at this example that show my test program in Geany:



        It is a real scalable truetype font, displaying latin 1, latin2,
        chinese, russian and japanese characters. Is it the same font? Does this
        mean that reportlab is buggy? If I could load the same font that geany
        uses, it would probably solve my problem forever.

        Thanks,

        Laszlo


        Comment

        • Laszlo Nagy

          #5
          Re: universal unicode font for reportlab

          Iain Dalton wrote:
          Why don't you want to use multiple typefaces? Many programs that deal
          with multilingual strings use multiple fonts (cf. any Web browser and
          Emacs).
          >
          You are right, but these PDF documents will show mixed strings. The end
          user can enter arbitrary strings into the database, and they must be
          presented. For example, the name of a product can be arabic or german.
          It might be possible to guess the language used from the unicode string,
          and then select a different font. But I don't want to go into that trouble.

          It would be a great idea to use pango. Apparently pango is able to
          change fonts on the fly and render the requested glyph. However, if I
          use pango then I loose the much higher level of abstraction that comes
          with reportlab and platypus: I need automatic page headers and footers,
          I need to be able to repeat table headers on each page automatically
          (when the table doesn't fit one page) etc. Developing my own "platypus"
          like engine for pango and PDF rendering is a nightmare.

          Better than that, I can develop my own flowable object for platypus: a
          special paragraph that changes the used true type font on the fly.
          (Split input string into parts, determine language for the parts and
          display each part with its own font.) But of course this is a lot of
          extra programming.

          The simplest solution would be to use a font that is able to handle all
          encodings that I need.

          Thanks,

          Laszlo

          Comment

          • Terry Reedy

            #6
            Re: universal unicode font for reportlab

            The simplest solution would be to use a font that is able to handle all
            encodings that I need.
            My OpenOffice on WinXP uses a unicode font, I believe Lucida Sans
            Unicode, that seems to cover the entire BMP. I don't know whether it
            was already installed or installed by OO or how one would get to it to
            extract it.

            Comment

            • Ross Ridge

              #7
              Re: universal unicode font for reportlab

              Terry Reedy <tjreedy@udel.e duwrote:
              >My OpenOffice on WinXP uses a unicode font, I believe Lucida Sans
              >Unicode, that seems to cover the entire BMP.
              Lucida Sans Unicode only covers a small subset of Unicode. It may seem
              to cover a wider range because Windows (and possibly OpenOffice) will
              automatically substitute characters from other fonts, if necessary.
              >I don't know whether it was already installed or installed by OO or
              >how one would get to it to extract it.
              It's a standard Windows font.

              Ross Ridge

              --
              l/ // Ross Ridge -- The Great HTMU
              [oo][oo] rridge@csclub.u waterloo.ca
              -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/
              db //

              Comment

              • Terry Reedy

                #8
                Re: universal unicode font for reportlab



                Ross Ridge wrote:
                Terry Reedy <tjreedy@udel.e duwrote:
                >My OpenOffice on WinXP uses a unicode font, I believe Lucida Sans
                >Unicode, that seems to cover the entire BMP.
                >
                Lucida Sans Unicode only covers a small subset of Unicode. It may seem
                to cover a wider range because Windows (and possibly OpenOffice) will
                automatically substitute characters from other fonts, if necessary.
                Sorry, I posted the wrong name.
                Ariel Unicode MS is the one that seems pretty complete.

                >I don't know whether it was already installed or installed by OO or
                >how one would get to it to extract it.
                >
                It's a standard Windows font.
                From the MS, I would guess that is a Windows font too ;-).

                Comment

                • Ross Ridge

                  #9
                  Re: universal unicode font for reportlab

                  Terry Reedy <tjreedy@udel.e duwrote:
                  >Sorry, I posted the wrong name.
                  >Ariel Unicode MS is the one that seems pretty complete.
                  ....
                  From the MS, I would guess that is a Windows font too ;-).
                  It's made by Microsoft, but it's not a standard Windows font. I think
                  it comes with Microsoft Office.

                  Ross Ridge

                  --
                  l/ // Ross Ridge -- The Great HTMU
                  [oo][oo] rridge@csclub.u waterloo.ca
                  -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/
                  db //

                  Comment

                  • Terry Reedy

                    #10
                    Re: universal unicode font for reportlab



                    Jeroen Ruigrok van der Werven wrote:
                    -On [20080909 05:23], Terry Reedy (tjreedy@udel.e du) wrote:
                    >Ariel Unicode MS is the one that seems pretty complete.
                    >
                    Not really. It misses a lot of characters.
                    Well, it has Latin, Greek, Cyrillic, Hebrew, Arabic, several south
                    Asian, Tibetan, CJK, Japanese, Korean, and numerous symbols and special
                    forms. I don't know what it misses, but I think that covers what the OP
                    asked for.

                    Comment

                    • Laszlo Nagy

                      #11
                      Re: universal unicode font for reportlab

                      Ross Ridge wrote:
                      Terry Reedy <tjreedy@udel.e duwrote:
                      >
                      >Sorry, I posted the wrong name.
                      >Ariel Unicode MS is the one that seems pretty complete.
                      >>
                      ...
                      >
                      >From the MS, I would guess that is a Windows font too ;-).
                      >>
                      >
                      It's made by Microsoft, but it's not a standard Windows font. I think
                      it comes with Microsoft Office.
                      >
                      I need to use HTML anyway. I realized that universal unicode fonts are
                      above 5MB in size. The report would be a 10KB PDF, but I need to embed
                      the font before I can send it to anyone. Since some reports needs to be
                      sent in emails, I need to use something else. I cannot be sending 10MB
                      emails for "one page" reports.

                      I ended up implementing the reports in HTML. I'm assuming that the
                      user's browser is capable of displaying any characters needed. Now there
                      is another problem: how to print an HTML without page header/footer
                      information, from a browser? But that is another problem and probably
                      has nothing to do with Python.

                      Thanks for your help anyway.

                      Best,

                      Laszlo

                      Comment

                      • Duncan Booth

                        #12
                        Re: universal unicode font for reportlab

                        Laszlo Nagy <gandalf@shopze us.comwrote:
                        I need to use HTML anyway. I realized that universal unicode fonts are
                        above 5MB in size. The report would be a 10KB PDF, but I need to embed
                        the font before I can send it to anyone. Since some reports needs to be
                        sent in emails, I need to use something else. I cannot be sending 10MB
                        emails for "one page" reports.
                        >
                        I thought that usually when you embed a font in a PDF only the glyphs which
                        are actually used in the document get embedded. Unfortunately a quick test
                        with reportlab seems to show that it doesn't do that optimisation: it looks
                        as though it just embeds the entire font.

                        --
                        Duncan Booth http://kupuguy.blogspot.com

                        Comment

                        • Ross Ridge

                          #13
                          Re: universal unicode font for reportlab

                          Duncan Booth <duncan.booth@s uttoncourtenay. org.ukwrote:
                          >I thought that usually when you embed a font in a PDF only the glyphs which
                          >are actually used in the document get embedded. Unfortunately a quick test
                          >with reportlab seems to show that it doesn't do that optimisation: it looks
                          >as though it just embeds the entire font.
                          Yah, PDF files normally only contain an embedded subset of the fonts used.
                          It might possible to use Ghostscript's ps2pdf command (which can take a
                          PDF file as input) to strip out the unused glyphs from the embedded fonts.

                          Ross Ridge

                          --
                          l/ // Ross Ridge -- The Great HTMU
                          [oo][oo] rridge@csclub.u waterloo.ca
                          -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/
                          db //

                          Comment

                          • Tim Roberts

                            #14
                            Re: universal unicode font for reportlab

                            Duncan Booth <duncan.booth@i nvalid.invalidw rote:
                            >
                            >Laszlo Nagy <gandalf@shopze us.comwrote:
                            >
                            >I need to use HTML anyway. I realized that universal unicode fonts are
                            >above 5MB in size. The report would be a 10KB PDF, but I need to embed
                            >the font before I can send it to anyone. Since some reports needs to be
                            >sent in emails, I need to use something else. I cannot be sending 10MB
                            >emails for "one page" reports.
                            >>
                            >I thought that usually when you embed a font in a PDF only the glyphs which
                            >are actually used in the document get embedded. Unfortunately a quick test
                            >with reportlab seems to show that it doesn't do that optimisation: it looks
                            >as though it just embeds the entire font.
                            No, it does subsetting. There was a debate a year or two ago on the
                            reportlab list about how the font subset should be named in the resulting
                            PDF file.

                            Is it possible you have an older release?
                            --
                            Tim Roberts, timr@probo.com
                            Providenza & Boekelheide, Inc.

                            Comment

                            • Duncan Booth

                              #15
                              Re: universal unicode font for reportlab

                              Tim Roberts <timr@probo.com wrote:
                              Duncan Booth <duncan.booth@i nvalid.invalidw rote:
                              >>
                              >>Laszlo Nagy <gandalf@shopze us.comwrote:
                              >>
                              >>I need to use HTML anyway. I realized that universal unicode fonts
                              >>are above 5MB in size. The report would be a 10KB PDF, but I need to
                              >>embed the font before I can send it to anyone. Since some reports
                              >>needs to be sent in emails, I need to use something else. I cannot
                              >>be sending 10MB emails for "one page" reports.
                              >>>
                              >>I thought that usually when you embed a font in a PDF only the glyphs
                              >>which are actually used in the document get embedded. Unfortunately a
                              >>quick test with reportlab seems to show that it doesn't do that
                              >>optimisatio n: it looks as though it just embeds the entire font.
                              >
                              No, it does subsetting. There was a debate a year or two ago on the
                              reportlab list about how the font subset should be named in the
                              resulting PDF file.
                              >
                              Is it possible you have an older release?
                              It was 2.1 downloaded about 30 minutes before my post.

                              The not too scientific test I did was to copy the font embedding example
                              from the Reportlab documentation, modify it enough to make it actually
                              run, and then change the output to have only one glyph. The resulting
                              PDF is virtually identical. I'm not a reportlab expert though so I may
                              have made some blindingly obvious beginners mistake (or maybe it only
                              subsets fonts over a certain size or glyphs outside the ascii range?).


                              ---------- rlab.py ------------
                              import os, sys
                              import reportlab
                              folder = os.path.dirname (reportlab.__fi le__) + os.sep + 'fonts'
                              afmFile = os.path.join(fo lder, 'LeERC___.AFM')
                              pfbFile = os.path.join(fo lder, 'LeERC___.PFB')
                              from reportlab.pdfba se import pdfmetrics
                              justFace = pdfmetrics.Embe ddedType1Face(a fmFile, pfbFile)
                              faceName = 'LettErrorRobot-Chrome' # pulled from AFM file
                              pdfmetrics.regi sterTypeFace(ju stFace)
                              justFont = pdfmetrics.Font ('LettErrorRobo t-Chrome',faceNam e,'WinAnsiEncod ing')
                              pdfmetrics.regi sterFont(justFo nt)
                              from reportlab.pdfge n.canvas import Canvas
                              canvas = Canvas('temp.pd f')
                              canvas.setFont( 'LettErrorRobot-Chrome', 32)
                              if sys.argv:
                              canvas.drawStri ng(10, 150, 'TTTT TTTTTT TT TT')
                              canvas.drawStri ng(10, 100, 'TTTTTTTTTTTTTT TTTTTTT')
                              else:
                              canvas.drawStri ng(10, 150, 'This should be in')
                              canvas.drawStri ng(10, 100, 'LettErrorRobot-Chrome')
                              canvas.save()
                              -------------------------------

                              --
                              Duncan Booth http://kupuguy.blogspot.com

                              Comment

                              Working...