Merge branch 'master' of github.com:patriciogonzalezvivo/thebookofshaders

This commit is contained in:
Patricio Gonzalez Vivo 2015-07-29 08:47:30 -04:00
commit 667304edbc
16 changed files with 26 additions and 13 deletions

6
.gitignore vendored
View File

@ -1,3 +1,7 @@
.DS_Store
.dropbox
*Icon*
*Icon*
tmp.md
tmp*.png
book.tex
book.pdf

Binary file not shown.

Before

Width:  |  Height:  |  Size: 263 KiB

After

Width:  |  Height:  |  Size: 263 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 269 KiB

After

Width:  |  Height:  |  Size: 269 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 340 KiB

After

Width:  |  Height:  |  Size: 301 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 149 KiB

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 217 KiB

After

Width:  |  Height:  |  Size: 217 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 271 KiB

After

Width:  |  Height:  |  Size: 270 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 270 KiB

After

Width:  |  Height:  |  Size: 270 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 370 KiB

After

Width:  |  Height:  |  Size: 367 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 171 KiB

After

Width:  |  Height:  |  Size: 170 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 217 KiB

After

Width:  |  Height:  |  Size: 215 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

BIN
15/03.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 177 KiB

After

Width:  |  Height:  |  Size: 177 KiB

View File

@ -9,8 +9,8 @@ latexEngine = "xelatex"
outputPath = "."
if not os.path.exists(outputPath): os.makedirs(outputPath)
pdfBookPath = os.path.join(outputPath, "book.pdf")
texBookPath = os.path.join(outputPath, "book.tex")
pdfBookPath = os.path.join(outputPath, "book.pdf")
texBookPath = os.path.join(outputPath, "book.tex")
chapters = []
@ -19,17 +19,26 @@ def injectShaderBlocks( _folder, _text ):
lines = _text.split('\n');
for line in lines:
if line.find('<div class=\"codeAndCanvas\"') >= 0:
shaderFile = re.sub(r'<div class=\"codeAndCanvas\" data=\"(.*)\"></div>', r'\1', line.rstrip())
shaderTextureResults = re.findall(r'<div class=\"codeAndCanvas\" data=\".*\" data-imgs=\"(.*)\"></div>', line.rstrip())
shaderFile = re.sub(r'<div class=\"codeAndCanvas\" data=\"(.*?)\"(>| .+>)</div>', r'\1', line.rstrip())
shaderName,shaderExt = os.path.splitext(shaderFile)
shaderPath = folder+"/"+shaderFile;
if shaderTextureResults:
shaderTexturePaths = map (lambda f: folder+"/"+f, shaderTextureResults[0].split(","))
else:
shaderTexturePaths = []
shaderString = open(shaderPath, 'r').read()
rta += '```glsl\n'+shaderString.rstrip('\n')+'\n```\n'
shaderImage = folder+"/tmp-"+shaderName+".png"
shaderCommand = "glslViewer " + shaderPath + " -s 0.5 -o " + shaderImage
shaderCommand = "glslViewer " + shaderPath + " " + \
" ".join(shaderTexturePaths) + \
" -s 0.5 -o " + shaderImage
print shaderCommand
returnCode = subprocess.call(shaderCommand, shell=True)
rta += "!["+shaderPath+"]("+shaderImage+")\n"
rta += "![]("+shaderImage+")\n"
else:
rta += line+'\n'
return rta
@ -43,19 +52,19 @@ for folder in folders:
fileString = originalChapter.read()
# Correct path for images
imgPattern = r'(\!\[(.*)\]\()'
subPattern = r'\1{0}/'.format(folder)
imgPattern = r'(\!\[.*?\]\()(.*)'
subPattern = r'\1' + folder + r'/\2'
modifiedChapterString = re.sub(imgPattern, subPattern, fileString)
modifiedChapterString = injectShaderBlocks(folder,modifiedChapterString)
modifiedChapterPath = folder+'/tmp.md'
with open(modifiedChapterPath, "w") as modifiedChapter:
modifiedChapter.write(modifiedChapterString)
modifiedChapter.write(modifiedChapterString)
chapters.append(modifiedChapterPath)
# # Set up the appropriate options for the pandoc command
inputOptions = chapters
generalOptions = ["-N", "--smart", "--no-tex-ligatures", "--toc", "--standalone", "--preserve-tabs", "-V documentclass=scrbook", "-V papersize=a4", "-V links-as-note", "-S"] #
generalOptions = ["-N", "--smart", "--no-tex-ligatures", "--toc", "--standalone", "--preserve-tabs", "-V documentclass=scrbook", "-V papersize=a4", "-V links-as-note", "-S"] #
latexOptions = ["--latex-engine="+latexEngine]
outputOptions = ["--output={0}".format(pdfBookPath)]
pandocCommand = ["pandoc"] + outputOptions + inputOptions + generalOptions + latexOptions
@ -74,14 +83,14 @@ for flag in generalOptions+latexOptions:
texOutputOptions = ["--output={0}".format(texBookPath)]
texPandocCommand = ["pandoc"] + texOutputOptions + inputOptions + generalOptions + latexOptions
returnCode = subprocess.call(texPandocCommand)
if returnCode == 0:
if returnCode == 0:
print "Successful building of {0}".format(texBookPath)
else:
print "Error in building of {0}".format(texBookPath)
# Call pandoc
returnCode = subprocess.call(pandocCommand)
if returnCode == 0:
if returnCode == 0:
print "Successful building of {0}".format(pdfBookPath)
else:
print "Error in building of {0}".format(pdfBookPath)
print "Error in building of {0}".format(pdfBookPath)