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

[PATCH] SVG tspan content is displayed out of place

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 2.10
    • image/svg
    • None

    Description

      We have found an issue in FOP when transforming PDFs with SVGs containing <tspan> with multiple @x and/or @y attributes values.
      The problem is located in org.apache.fop.svg.PDFTextPainter.writeGlyphs(FOPGVTGlyphVector, GeneralPath), the positions given by x and y are never used when set.
      A possible fix for this issue is the following:

          for (int i = 0, n = gv.getNumGlyphs(); i < n; i++) {
              int     gc              = gv.getGlyphCode(i);
              int[]   pa              = ((i > dp.length) || (dp[i] == null)) ? paZero : dp[i];
              if (gv.getGlyphPosition(i) != null) {
                  Point2D gp              = gv.getGlyphPosition(i);
                  double x                = gp.getX() - initialPos.getX();
                  double y                = -(gp.getY() - initialPos.getY());
                  double xd               = x - xoLast;
                  double yd               = y - yoLast;
      
                  textUtil.writeTd(xd, yd);
                  textUtil.writeTj((char) gc, true, false);
                  xc = x + pa[2];
                  yc = y + pa[3];
                  xoLast = x;
                  yoLast = y;
              } else {
                  double  xo              = xc + pa[0];
                  double  yo              = yc + pa[1];
                  double  xa              = f.getWidth(gc);
                  double  ya              = 0;
                  double  xd              = (xo - xoLast) / 1000f;
                  double  yd              = (yo - yoLast) / 1000f;
                 
                  textUtil.writeTd(xd, yd);
                  textUtil.writeTj((char) gc, true, false);
                  xc += xa + pa[2];
                  yc += ya + pa[3];
                  xoLast = xo;
                  yoLast = yo;
              }
          }
      

      I also attached an example for testing, it can be opened in Batik for comparison.

      Attachments

        1. batik.patch
          12 kB
          Joao Goncalves
        2. commons.patch
          6 kB
          Joao Goncalves
        3. fop.patch
          13 kB
          Joao Goncalves
        4. MI.patch
          2 kB
          Dave Roxburgh
        5. MI-Calibri-test.pdf
          17 kB
          Julien Lacour
        6. MI-out.pdf
          5 kB
          Dave Roxburgh
        7. MI-out-patch.pdf
          5 kB
          Dave Roxburgh
        8. MI-test.fo
          0.9 kB
          Dave Roxburgh
        9. MI-tspan.svg
          0.6 kB
          Dave Roxburgh
        10. tspan.svg
          0.6 kB
          Julien Lacour
        11. WIP.patch
          2 kB
          Dave Roxburgh
        12. WIP-out.pdf
          5 kB
          Dave Roxburgh

        Issue Links

          Activity

            People

              ssteiner Simon Steiner
              julienlacour31 Julien Lacour
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: