def write(self, filename, debug=False): if Image is None: raise JasyError("Missing PIL to create sprite sheets") img = Image.new('RGBA', (self.width, self.height)) draw = ImageDraw.Draw(img) #draw.rectangle((0, 0, self.width, self.height), fill=(255, 255, 0, 255)) # Load images and pack them in for block in self.blocks: res = Image.open(block.image.src) x, y = block.fit.x, block.fit.y if block.rotated: debug('%s is rotated' % block.image.src) res = res.rotate(90) img.paste(res, (x, y)) del res if debug: x, y, w, h = block.fit.x, block.fit.y, block.w, block.h draw.rectangle((x, y , x + w , y + h), outline=(0, 0, 255, 255) if block.rotated else (255, 0, 0, 255)) if debug: for i, block in enumerate(self.packer.getUnused()): x, y, w, h = block.x, block.y, block.w, block.h draw.rectangle((x, y , x + w , y + h), fill=(255, 255, 0, 255)) img.save(filename)
__all__ = ["markdown", "markdown2html", "code2highlight"] try: import misaka misakaExt = misaka.EXT_AUTOLINK | misaka.EXT_NO_INTRA_EMPHASIS | misaka.EXT_FENCED_CODE misakaRender = misaka.HTML_SKIP_STYLE | misaka.HTML_SMARTYPANTS def markdown2html(markdownStr): return misaka.html(markdownStr, misakaExt, misakaRender) except: debug("Misaka is needed to convert Markdown to HTML!") markdown2html = None # By http://misaka.61924.nl/#toc_3 codeblock = re.compile( r'<pre(?: lang="([a-z0-9]+)")?><code(?: class="([a-z0-9]+).*?")?>(.*?)</code></pre>', re.IGNORECASE | re.DOTALL ) def code2highlight(html): def unescape(html): html = html.replace("<", "<") html = html.replace(">", ">") html = html.replace("&", "&") html = html.replace(""", '"')
def addImageSpriteData(self, id, left, top): debug("Registering sprite location for %s: %s@%sx%s", self.id, id, left, top) self.__imageSpriteData = [id, left, top]
from jasy.core.Logging import debug __all__ = ["markdown", "markdown2html", "code2highlight"] try: import misaka misakaExt = misaka.EXT_AUTOLINK | misaka.EXT_NO_INTRA_EMPHASIS | misaka.EXT_FENCED_CODE misakaRender = misaka.HTML_SKIP_STYLE | misaka.HTML_SMARTYPANTS def markdown2html(markdownStr): return misaka.html(markdownStr, misakaExt, misakaRender) except: debug("Misaka is needed to convert Markdown to HTML! Markdown support is disabled.") markdown2html = None try: from pygments import highlight from pygments.formatters import HtmlFormatter from pygments.lexers import get_lexer_by_name # By http://misaka.61924.nl/#toc_3 codeblock = re.compile(r'<pre(?: lang="([a-z0-9]+)")?><code(?: class="([a-z0-9]+).*?")?>(.*?)</code></pre>', re.IGNORECASE | re.DOTALL) def code2highlight(html): def unescape(html): html = html.replace('<', '<') html = html.replace('>', '>')
def addImageDimensionData(self, width, height): debug("Adding dimension data for %s: %sx%s", self.id, width, height) self.__imageDimensionData = [width, height]