Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix layout inversion bug #33

Merged
merged 5 commits into from
Sep 24, 2024
Merged

Fix layout inversion bug #33

merged 5 commits into from
Sep 24, 2024

Conversation

ic-xu
Copy link
Contributor

@ic-xu ic-xu commented Apr 25, 2024

description:

Fixed the bug that when parsing PDF, when the PDF content is converted from PPT to a file, the layout of the content is found to be reversed. As shown in the picture below, if calculated from the lower right corner of bbox, rectangle A should be ranked behind B, but if the rectangle has text, the text of rectangle A should be read first in front of rectangle B, so I think Maybe using the upper left corner of the rectangle as the basis for bbox sorting will be more suitable for most people's reading habits.

                ^
            Y  |
               |
               |
               |
               |     +----------------------------------------------+(x1,y1)
               |     |                                              |
               |     |   A                                          |
               |     |                                         (x1,y1)
               |     |            +----------------------------+    |
               |     |            |                            |    |
               |     |            |     B                      |    |
               |     |            |                            |    |
               |     |            |                            |    |
               |     |            +----------------------------+    |
               |     |            (x0,y0)                           |
               |     +----------------------------------------------+
               |    (x0,y0)
       +------------------------------------------------------------------------------------------------>
               +                                                                                       X
                                           +
                                           |
                                           |
                                           |
                                           |
                                           |
                                           |
                                           v
          ^
      Y   |          (x0,y0)
          |          +------------------------------------------------+
          |          |                                                |
          |          |                                                |
          |          |   A           (x0,y0)                          |
          |          |               +--------------------------+     |
          |          |               |                          |     |
          |          |               |   B                      |     |
          |          |               |                          |     |
          |          |               |                          |     |
          |          |               +--------------------------+     |
          |          |                                          (x1,y1)
          |          +------------------------------------------------+
          |                                                           (x1,y,)
          |
+--------------------------------------------------------------------------------->
          |                                                                     X
          |
          +

So I think when switching the coordinate system, (x0, y0) should be kept as the upper left corner point of the rectangle

@Filimoa
Copy link
Owner

Filimoa commented Apr 25, 2024

PyMyPdf uses a top-left coordinate system while the rest of our code uses bottom-left. As a result we need to swap these for everything to work. Do you have an example PDF?

@ic-xu
Copy link
Contributor Author

ic-xu commented Apr 25, 2024 via email

@Filimoa Filimoa merged commit f970b64 into Filimoa:main Sep 24, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants