pymupdf / PyMuPDF

PyMuPDF is a high performance Python library for data extraction, analysis, conversion & manipulation of PDF (and other) documents.
https://pymupdf.readthedocs.io
GNU Affero General Public License v3.0
4.49k stars 443 forks source link

Story.fit_width() has a weird line #3599

Closed stickyfinger7 closed 5 days ago

stickyfinger7 commented 1 week ago

Description of the bug

def fit_width(self, height, width_min=0, width_max=None, origin=(0, 0), delta=0.001, verbose=False): ''' Finds smallest width in rangewidth_min..width_maxwhere a rect with size (width, height)is large enough to contain the storyself`.

    Returns a `Story.FitResult` instance.
    Returns a `FitResult` instance.

    :arg height:
        height of rect.
    :arg width_min:
        Minimum width to consider; must be >= 0.
    :arg width_max:
        Maximum width to consider, must be >= width_min or `None` for
        infinite.
    :arg origin:
        `(x0, y0)` of rect.
    :arg delta:
        Maximum error in returned width.
    :arg verbose:
        If true we output diagnostics.
    '''
    x0, y0 = origin
    **y1 = x0 + height**
    def fn(width):
        return Rect(x0, y0, x0+width, y1)
    return self.fit(fn, width_min, width_max, delta, verbose)`

why the y1 is defined by x0 + height?? I think it might be y0 + height.

How to reproduce the bug

See the description

PyMuPDF version

1.24.5

Operating system

MacOS

Python version

3.12

julian-smith-artifex-com commented 1 week ago

Thanks for this, i think you're right.

I've fixed this in my tree, so hopefully this fix will be included in a future release.

julian-smith-artifex-com commented 5 days ago

Fixed in 1.24.6.