From f4eab45b0a4d5d1dc607e0f7688ada5b4157e717 Mon Sep 17 00:00:00 2001 From: Ashutosh Varma Date: Thu, 16 Jul 2020 12:20:41 +0000 Subject: [PATCH] fix typos and remove unused variables across codebase --- src/pyxpdf/globalconfig.pxi | 15 +++++---------- src/pyxpdf/imageoutput.pxi | 8 ++++---- src/pyxpdf/xpdf.pyx | 2 +- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/pyxpdf/globalconfig.pxi b/src/pyxpdf/globalconfig.pxi index 7732b3b..a31891b 100644 --- a/src/pyxpdf/globalconfig.pxi +++ b/src/pyxpdf/globalconfig.pxi @@ -4,7 +4,7 @@ from pyxpdf.includes.UnicodeMap cimport UnicodeMap # NOTE: This class should be always a singleton # only one object of this class should exist i.e # global variable `Config` -# This is beacuse xpdf `GlobalParams` class's destructor +# This is because xpdf `GlobalParams` class's destructor # frees global builtin font tables. So more that one # `_GlobalParamsConfig` class will lead to double free # or corruption error. @@ -15,7 +15,7 @@ cdef class _GlobalParamsConfig: public object __doc__ cdef _set_defaults(self): - # only call after initialising self._global + # only call after initializing self._global # default text encoding self._global.setTextEncoding("UTF-8") @@ -159,16 +159,11 @@ cdef class _GlobalParamsConfig: @text_eol.setter def text_eol(self, eol): - cdef EndOfLineKind c_eol - if eol == "unix": - c_eol = EndOfLineKind.eolUnix - elif eol == "dos": - c_eol = EndOfLineKind.eolDOS - elif eol == 'mac': - c_eol = EndOfLineKind.eolMac + # cdef EndOfLineKind c_eol + if eol.lower() in (u'unix', u'mac', u'dos'): + self._global.setTextEOL(_chars(eol)) else: raise XPDFConfigError(f"Invalid EOL type - {eol}.") - self._global.setTextEOL(_chars(eol)) @property diff --git a/src/pyxpdf/imageoutput.pxi b/src/pyxpdf/imageoutput.pxi index a70d8ae..398b4ed 100644 --- a/src/pyxpdf/imageoutput.pxi +++ b/src/pyxpdf/imageoutput.pxi @@ -39,7 +39,7 @@ DEF BITMAP_RESOLUTION = 150 #FIXME: buggy as hell, text does not render properly. cdef bytearray splash_bitmap_to_1bpc_1comp(SplashBitmap *bitmap): cdef: - int idx, x, y, i + int idx, y, i int height = bitmap.getHeight() int width = bitmap.getWidth() SplashBitmapRowSize row_size = bitmap.getRowSize() @@ -49,7 +49,7 @@ cdef bytearray splash_bitmap_to_1bpc_1comp(SplashBitmap *bitmap): for y in range(height): i = 0 - for x in range(0, width, 8): + for _ in range(0, width, 8): p = &data[y * row_size + i] idx = y * row_size + i img[idx] = p[0] @@ -376,13 +376,11 @@ cdef class RawImageOutput(PDFOutputDevice): double scale_y) except NULL: cdef: int rotation = 0 - int total_pages = self.doc.doc.getNumPages() double page_h = 0 double page_w = 0 double tmp double res_x = self.resolution_x double res_y = self.resolution_y - SplashBitmap* bitmap if self.use_cropbox: page_h = self.doc.doc.getPageCropHeight(page_no + 1) @@ -604,6 +602,8 @@ cdef class PDFImage: mode = "L" elif c_img.bitmapColorMode == SplashColorMode.splashModeRGB8: mode = "RGB" + else: + raise XPDFInternalError(f"Unsupported Bitmap SplashColorMode.") buff = splash_bitmap_to_buffer(bmap, mode) img.image = pillow_image_from_buffer(mode, bmap.getHeight(), bmap.getWidth(), buff) diff --git a/src/pyxpdf/xpdf.pyx b/src/pyxpdf/xpdf.pyx index c416395..024dfae 100644 --- a/src/pyxpdf/xpdf.pyx +++ b/src/pyxpdf/xpdf.pyx @@ -101,6 +101,6 @@ include "textoutput.pxi" # Python Objects based on SplashOutputDev.pxd include "imageoutput.pxi" -# Pythonn Objects based on PDFDoc.pxd ,Page.pxd +# Python Objects based on PDFDoc.pxd ,Page.pxd include "document.pxi"