Summary: | get_text_layout introspection mismatch | ||
---|---|---|---|
Product: | poppler | Reporter: | Marcus Brinkmann <marcus.brinkmann> |
Component: | glib frontend | Assignee: | poppler-bugs <poppler-bugs> |
Status: | RESOLVED MOVED | QA Contact: | |
Severity: | normal | ||
Priority: | medium | ||
Version: | unspecified | ||
Hardware: | Other | ||
OS: | All | ||
Whiteboard: | |||
i915 platform: | i915 features: |
Description
Marcus Brinkmann
2014-04-23 03:35:51 UTC
I have exactly the same issue with python. I was able to work around problem using the ctypes foreign function interface of Python. The code is for Python 2.7. It should be possible create a gi.overrides.Poppler module based on this code. This would fix the issue for Python. from gi.repository import Poppler, GLib import ctypes lib_poppler = ctypes.cdll.LoadLibrary("libpoppler-glib-8") ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object, ctypes.c_char_p] PyCapsule_GetPointer = ctypes.pythonapi.PyCapsule_GetPointer class Poppler_Rectangle(ctypes.Structure): _fields_ = [ ("x1", ctypes.c_double), ("y1", ctypes.c_double), ("x2", ctypes.c_double), ("y2", ctypes.c_double) ] LP_Poppler_Rectangle = ctypes.POINTER(Poppler_Rectangle) poppler_page_get_text_layout = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_void_p, ctypes.POINTER(LP_Poppler_Rectangle), ctypes.POINTER(ctypes.c_uint) )(lib_poppler.poppler_page_get_text_layout) def get_page_layout(page): assert isinstance(page, Poppler.Page) capsule = page.__gpointer__ page_addr = PyCapsule_GetPointer(capsule, None) rectangles = LP_Poppler_Rectangle() n_rectangles = ctypes.c_uint(0) has_text = poppler_page_get_text_layout(page_addr, ctypes.byref(rectangles), ctypes.byref(n_rectangles)) try: result = [] if has_text: assert n_rectangles.value > 0, "n_rectangles.value > 0: {}".format(n_rectangles.value) assert rectangles, "rectangles: {}".format(rectangles) for i in range(n_rectangles.value): r = rectangles[i] result.append((r.x1, r.y1, r.x2, r.y2)) return result finally: if rectangles: GLib.free(ctypes.addressof(rectangles.contents)) I still have this issues with poppler v 0.40. in python. (or assume that it's caused by this issue). get_text_layout is returning nonsence numbers like 5.77367485245e-317 1.44295714099e-312 2.56761490707e-312 2.60372595358e-321 Any chance to get this fixed? I. -- GitLab Migration Automatic Message -- This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/poppler/poppler/issues/612. |
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.