- added consistency to PDFGraphicStateCol

This commit is contained in:
ari committed 2018-11-29 15:39:16 -05:00
1 parent 2ea0b717f9
commit 924596e38d
6 files changed
+32 -36

No files matched your search

+1 -1
View File
@@ -1 +1 @@
v1.1.11 v1.1.12
+1 -1
View File
@@ -86,7 +86,7 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
""" """
__version__ = (1, 1, 11) __version__ = (1, 1, 12)
if __name__ == '__main__': if __name__ == '__main__':
print( print(
+28 -32
View File
@@ -25,7 +25,7 @@ def get_color(col: PDFGraphicStateColor):
elif color_type == 'cmyk': elif color_type == 'cmyk':
return f"cmyk({','.join(map(str, color_val))})" return f"cmyk({','.join(map(str, color_val))})"
elif color_type == 'gray': elif color_type == 'gray':
return f'rgba(0,0,0,{1-color_val})' return f'rgba(0,0,0,{1-color_val[0]})'
elif color_type == "custom": elif color_type == "custom":
# Todo: convert these to more friendly color types # Todo: convert these to more friendly color types
return f"custom({col.custom['type']})" return f"custom({col.custom['type']})"
@@ -134,6 +134,8 @@ class HTMLConverter(PDFConverter):
'position': 'absolute', 'position': 'absolute',
'left': f'{item.x0}px', 'left': f'{item.x0}px',
'bottom': f'{item.y0}px', 'bottom': f'{item.y0}px',
'width': f'{item.width}px',
'height': f'{item.height}px',
} }
path = "" path = ""
svg_attr = { svg_attr = {
@@ -141,42 +143,36 @@ class HTMLConverter(PDFConverter):
'z-index': 2 'z-index': 2
} }
if item.height > 0: p_vals = { "x": [], "y": [] }
dy = 1.0/item.height
dx = (item.width/item.height)/(item.x1-item.x0)
svg_attr.update({
"viewBox": "0 0 %s %s" % ( item.width/item.height, 1 )
})
else:
dx = 1.0/(item.x1-item.x0)
dy = 1.0
svg_attr.update({
"viewBox": "0 0 1 1"
})
if item.height > 1: for p in item.paths:
svg_attr.update({ for pt in p.points:
'height': f'{item.height}px', p_vals['x'].append(pt.x)
}) p_vals['y'].append(pt.y)
else:
svg_attr.update({ mx_x = max([*p_vals['x'], 1])
'height': '1px', mn_x = min([*p_vals['x'], 0])
}) mx_y = max([*p_vals['y'], 1])
mn_y = min([*p_vals['y'], 0])
if item.width > 1:
svg_attr.update({ if mx_x == mn_x:
'width': f'{item.width}px', mn_x -= 1
}) if mx_y == mn_y:
else: mn_y -= 1
svg_attr.update({
'width': '1px', dx = 1/( mx_x - mn_x )
}) dy = (item.height/item.width)/( mx_y - mn_y )
ROUND_VAL = 5
svg_attr.update({
# "viewBox": f"{min(p_vals['x'])} {min(p_vals['y'])} {max(p_vals['x'])} {max(p_vals['y'])}",
"viewBox": f"{round(mn_x*dx, ROUND_VAL)} {round(mn_y*dy, ROUND_VAL)} {round(mx_x*dx , ROUND_VAL)} {round(mx_y*dy, ROUND_VAL)}",
})
for p in item.paths: for p in item.paths:
if p.method == CurvePath.METHOD.MOVE_TO: if p.method == CurvePath.METHOD.MOVE_TO:
path += f'M{" ".join( f"{(item.width - (p.x-item.x0) )*dx} {(item.height- (p.y-item.y0) )*dy}" for p in p.points )} ' path += f'M{" ".join( f"{round(dx*pt.x, ROUND_VAL)} {round(dy*pt.y, ROUND_VAL)}" for pt in p.points )} '
if p.method == CurvePath.METHOD.LINE_TO: if p.method == CurvePath.METHOD.LINE_TO:
path += f'L{" ".join( f"{(item.width - (p.x-item.x0) )*dx} {( item.height - (p.y-item.y0) )*dy}" for p in p.points )} ' path += f'L{" ".join( f"{round(dx*pt.x, ROUND_VAL)} {round(dy*pt.y, ROUND_VAL)}" for pt in p.points )} '
if p.method == CurvePath.METHOD.CLOSE_PATH: if p.method == CurvePath.METHOD.CLOSE_PATH:
path += 'Z' path += 'Z'
with self.place_elm_with_child('svg', svg_attr, css): with self.place_elm_with_child('svg', svg_attr, css):
@@ -34,7 +34,7 @@ class PDFGraphicStateColor:
@property @property
def gray(self): def gray(self):
if self.__gray is not None: return float(self.__gray) if self.__gray is not None: return [float(self.__gray)]
else: raise self.NotSet else: raise self.NotSet
@property @property
Binary file not shown.
+1 -1
View File
@@ -10,7 +10,7 @@ import sys
with open('README.md') as readme_file: with open('README.md') as readme_file:
SETUP = { SETUP = {
"name": "pdfmajor", "name": "pdfmajor",
"version": "1.1.11", "version": "1.1.12",
"packages": find_packages(include=['pdfmajor*']), "packages": find_packages(include=['pdfmajor*']),
"install_requires": [ "install_requires": [
'pycryptodome', 'pycryptodome',