Browse Source

[WIP] Image size: write tests

pull/218/head
Louis 9 years ago
parent
commit
8cfe6becf8
  1. 2
      patacrep/data/templates/songs/chordpro/latex/content_image
  2. 1
      patacrep/data/templates/styles/patacrep.sty
  3. 20
      patacrep/songs/chordpro/ast.py
  4. 39
      patacrep/songs/chordpro/syntax.py
  5. 4
      test/test_book/syntax.tex.control
  6. BIN
      test/test_book/syntax_datadir/img/dices.png
  7. BIN
      test/test_book/syntax_datadir/img/image with spaces.png
  8. 24
      test/test_book/syntax_datadir/songs/images.csg
  9. 22
      test/test_song/image.csg
  10. 18
      test/test_song/image.csg.source
  11. 1
      test/test_song/image.tsg

2
patacrep/data/templates/songs/chordpro/latex/content_image

@ -1,5 +1,5 @@
(* block image *)
(* set image = content.argument|search_image|path2posix *)
(* set image = content.filename|search_image|path2posix *)
(* if image *)
\image{(( image ))}
(*- endif *)

1
patacrep/data/templates/styles/patacrep.sty

@ -7,6 +7,7 @@
\ProvidesPackage{patacrep}[2014/06/17 Patacrep Package, version 1]
\RequirePackage{graphicx,xcolor} %
\RequirePackage[space]{grffile}
\RequirePackage{epstopdf} %
\RequirePackage{fancybox}
\RequirePackage{xstring}

20
patacrep/songs/chordpro/ast.py

@ -405,6 +405,26 @@ class Define(Directive):
def __str__(self):
return None
class Image(Directive):
"""An image
.. attribute:: filename
The filename of the image.
.. attribute:: size
A tuple of ``(width, height)`` of the image. Both can be ``None``.
"""
def __init__(self, filename, size=None):
self.filename = filename
if size is None:
self.size = (None, None)
else:
self.size = size
super().__init__("image", None)
def __str__(self):
raise NotImplementedError("TODO4")
class Tab(AST):
"""Tablature"""

39
patacrep/songs/chordpro/syntax.py

@ -2,6 +2,7 @@
import logging
import re
import shlex
import ply.yacc as yacc
@ -171,7 +172,43 @@ class ChordproParser(Parser):
symbols[0] = ast.Error()
return
self._directives.append(define)
elif keyword == "image":
splitted = shlex.split(argument)
if len(splitted) == 1:
symbols[0] = ast.Image(splitted[0])
elif len(splitted) == 2:
match = re.compile(
r"""
^
size=
((?P<widthvalue>\d*\.\d+|\d+)(?P<widthunit>%|cm|em|pt))?
x
((?P<heightvalue>\d*\.\d+|\d+)(?P<heightunit>%|cm|em|pt))?
$
""",
re.VERBOSE
).match(splitted[1])
if match is None:
self.error(
line=symbols.lexer.lineno,
message="TODO1",
)
symbols[0] = ast.Error()
else:
groupdict = match.groupdict()
symbols[0] = ast.Image(
splitted[0],
(
(groupdict['widthvalue'], groupdict['widthunit']),
(groupdict['heightvalue'], groupdict['heightunit']),
),
)
else:
self.error(
line=symbols.lexer.lineno,
message="TODO3",
)
symbols[0] = ast.Error()
else:
directive = ast.Directive(keyword, argument)
if directive.inline:

4
test/test_book/syntax.tex.control

@ -112,6 +112,10 @@ guitar,
\endsong
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% songs/./musicnote.csg
TODO Test image sizes
\end{songs}

BIN
test/test_book/syntax_datadir/img/dices.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

BIN
test/test_book/syntax_datadir/img/image with spaces.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

24
test/test_book/syntax_datadir/songs/images.csg

@ -0,0 +1,24 @@
{title : Test of image sizes}
{image: dices.png}
{image: "image with spaces.png"}
{image: dices.png size=20%x}
{image: "image with spaces.png" size=x20%}
{image: dices.png size=20%x10%}
{image: dices.png size=20%x}
{image: "image with spaces.png" size=x20%}
{image: dices.png size=20%x10%}
{image: dices.png size=2cmx}
{image: "image with spaces.png" size=x2cm}
{image: dices.png size=2cmx1cm}
{image: dices.png size=2emx}
{image: "image with spaces.png" size=x2em}
{image: dices.png size=2emx1em}
{image: dices.png size=50ptx}
{image: "image with spaces.png" size=x50pt}
{image: dices.png size=50ptx100pt}

22
test/test_song/image.csg

@ -0,0 +1,22 @@
{image: dices.png}
{image: "image with spaces.png"}
{image: dices.png size=20%x}
{image: "image with spaces.png" size=x20%}
{image: dices.png size=20%x10%}
{image: dices.png size=20%x}
{image: "image with spaces.png" size=x20%}
{image: dices.png size=20%x10%}
{image: dices.png size=2cmx}
{image: "image with spaces.png" size=x2cm}
{image: dices.png size=2cmx1cm}
{image: dices.png size=2emx}
{image: "image with spaces.png" size=x2em}
{image: dices.png size=2emx1em}
{image: dices.png size=50ptx}
{image: "image with spaces.png" size=x50pt}
{image: dices.png size=50ptx100pt}

18
test/test_song/image.csg.source

@ -0,0 +1,18 @@
{image: dices.png}
{image: "image with spaces.png"}
{image: dices.png size=20%x}
{image: "image with spaces.png" size=x20%}
{image: dices.png size=20%x10%}
{image: dices.png size=2cmx}
{image: "image with spaces.png" size=x2cm}
{image: dices.png size=2cmx1cm}
{image: dices.png size=2emx}
{image: "image with spaces.png" size=x2em}
{image: dices.png size=2emx1em}
{image: dices.png size=50ptx}
{image: "image with spaces.png" size=x50pt}
{image: dices.png size=50ptx100pt}

1
test/test_song/image.tsg

@ -0,0 +1 @@
TODO
Loading…
Cancel
Save