Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: getnikola/plugins
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2fc1fb6acce4
Choose a base ref
...
head repository: getnikola/plugins
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 702ac4486f4e
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jan 14, 2017

  1. Fixed name.

    felixfontein committed Jan 14, 2017
    Copy the full SHA
    e3e334f View commit details
  2. Copy the full SHA
    702ac44 View commit details
41 changes: 3 additions & 38 deletions v7/latex_formula_renderer/latex_formula_renderer.py
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@

import gzip
import hashlib
import io
import os
import tempfile
import shutil
@@ -507,42 +508,6 @@ def render_formula(self, formula, formula_type, color, scale, base_name, output_
shutil.rmtree(tempdir, True)


class MemoryFile:
"""Turns a bytes array into a read-only file."""

def __init__(self, data):
"""Create memory file."""
self.__data = data
self.__pos = 0

def tell(self):
"""Get position in file."""
return self.__pos

def seek(self, offset, whence=os.SEEK_SET):
"""Set position in file."""
if whence == os.SEEK_SET:
self.__pos = offset
elif whence == os.SEEK_CUR:
self.__pos += offset
elif whence == os.SEEK_END:
self.__pos = len(self.__data) + offset
else:
raise IOError("Invalid 'whence' for seek()")
if self.__pos < 0:
self.__pos = 0
if self.__pos > len(self.__data):
self.__pos = len(self.__data)

def read(self, size=-1):
"""Read bytes from file."""
if size < 0 or self.__pos + size > len(self.__data):
size = len(self.__data) - self.__pos
result = self.__data[self.__pos:self.__pos + size]
self.__pos += size
return result


def _parse_svg_unit_as_pixels(unit):
"""Parse a unit from a SVG file."""
if unit.endswith('pt'):
@@ -558,7 +523,7 @@ def _get_image_size_from_memory(data, output_format):
"""Return a tuple (width, height) for the image of format output_format stored in the byte array data."""
if output_format == 'png':
# We use PIL
with Image.open(MemoryFile(data)) as img:
with Image.open(io.BytesIO(data)) as img:
result = img.size
return result
elif output_format == 'svg':
@@ -567,7 +532,7 @@ def _get_image_size_from_memory(data, output_format):
return _parse_svg_unit_as_pixels(e.get('width')), _parse_svg_unit_as_pixels(e.get('height'))
elif output_format == 'svgz':
# We use ElementTree to parse the decompressed SVG as XML
f = gzip.GzipFile(fileobj=MemoryFile(data))
f = gzip.GzipFile(fileobj=io.BytesIO(data))
e = xml.etree.ElementTree.parse(f).getroot()
return _parse_svg_unit_as_pixels(e.get('width')), _parse_svg_unit_as_pixels(e.get('height'))
else: