[ 
https://issues.apache.org/jira/browse/PDFBOX-2946?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14725624#comment-14725624
 ] 

Tilman Hausherr commented on PDFBOX-2946:
-----------------------------------------

It's the leftsidebearing.

I did have some suspicion because of the "contradiction" between 
leftsidebearing and the bbox (see table below) after reading the TT font 
specification but wasn't sure what to do. So I had a look at the ghostscript 
sources (base/ttfmain.c), because it displays the file correctly, and these 
guys are usually 10 years ahead of us :-)
{code}
        /*  Lets do X */
        {   short coord = (self->bVertical ? 0 : sideBearing - 
subglyph.bbox.xMin);
            F26Dot6* x = pts->org_x;
            onCurve = pts->touch;
            while (onCurve < stop) {
                if ((flag = *onCurve++) & XSHORT) {
                    if (flag & SHORT_X_IS_POS)
                        coord += ttfReader__Byte(r);
                    else
                    coord -= ttfReader__Byte(r);
                } else if (!(flag & NEXT_X_IS_ZERO))
                    coord += ttfReader__Short(r);
                *x++ = Scale_X(&exec->metrics, coord);
            }
        }
{code}
Our code for "Lets do X" is in GlyfSimpleDescript.java:
{code}
        short x = 0;
        short y = 0;
        for (int i = 0; i < count; i++)
        {
            if ((flags[i] & X_DUAL) != 0)
            {
                if ((flags[i] & X_SHORT_VECTOR) != 0)
                {
                    x += (short) bais.readUnsignedByte();
                }
            }
            else
            {
                if ((flags[i] & X_SHORT_VECTOR) != 0)
                {
                    x += (short) -((short) bais.readUnsignedByte());
                }
                else
                {
                    x += bais.readSignedShort();
                }
            }
            xCoordinates[i] = x;
        }
{code}
The main difference is this line:
{code}
short coord = (self->bVertical ? 0 : sideBearing - subglyph.bbox.xMin);
{code}
some font data for the test file:
{code}
leftSideBearing   boundingBox
bracelefttp: 420  [0.0,-167.0,490.0,1897.0]
braceleftmid: 28  [0.0,-166.0,490.0,1897.0]
braceleftbt: 420  [420.0,-167.0,910.0,1897.0]
{code}
bracelefttp is the "wrong" one, drawing starts at 0 despire having a left side 
bearing of 420.

(Btw fontforge -sucks- is not helpful. It shows the (correct) path without 
showing the raw data leading to it).

Proposed patch attached.

> Symbol glyphs not aligned
> -------------------------
>
>                 Key: PDFBOX-2946
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2946
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Rendering
>    Affects Versions: 2.0.0
>         Environment: W7, JDK7
>            Reporter: Tilman Hausherr
>            Assignee: John Hewson
>             Fix For: 2.0.0
>
>         Attachments: PDFJS-3599.pdf-1-bad.png, PDFJS-3599.pdf-1-good.png, 
> PDFJS-3599_reduced.pdf, PDFJS-3599_reduced1.png, leftsidebearing.diff
>
>
> Symbol glyphs not aligned in rendering



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to