from gram import Gram, GramCoord, GramGrid, GramText gr = Gram() gr.baseName = 'anchors' gr.font = 'helvetica' gr.defaultInnerSep = 0.1 g = GramGrid(0, 1, 8, 7) gr.graphics.append(g) ## _goodAnchors = ['west', 'north west', 'north', 'north east', 'east', ## 'base', 'base west', 'base east', ## 'south west', 'south', 'south east', ## #'mid', 'mid west', 'mid east', ## 'center'] # center seems to be the default nnDict = {} nn = [] for i in range(3): for j in range(4): indx = (i * 4) + j refPt = gr.goodAnchors[indx] print indx, refPt n = GramCoord((2 * j) + 1, (2 * i) + 1, refPt) nnDict[refPt] = n nn.append(n) gr.graphics.append(n) myStr = 'Xxy' theTextSize = 'normalsize' for i in range(12): anch = gr.goodAnchors[i]
from gram import Gram gr = Gram() gr.baseName = 'rotatedText' gr.showTextBB = True gr.showTextAnchor = True g = gr.text("short", 1,2) g.rotate = 30 g.draw = 'blue' g.lineThickness = 'thick' g = gr.grid(0,0, 3, 3) g = gr.text("Another bit of text.", 2,3) g.anchor = 'south west' g.rotate = -120 g.draw = 'cyan' gr.pdf() #gr.svg()
from gram import Gram gr = Gram() gr.font = 'helvetica' gr.baseName = 'size' gr.pngResolution = 90 gr.svgPxForCm = 35.43307 gr.grid(0, 0, 1, 1, color='black') gr.png() gr.svg() gr.baseName = 'sizeB' gr.pngResolution = 200 gr.svgPxForCm = 100 gr.png() gr.svg()
from gram import Gram gr = Gram() gr.baseName = 'line' gr.font = 'Helvetica' gr.grid(0,0,4,4) g = gr.line(1,1,2,3) g.colour = 'black!20' g.colour.transparent = True g.lineThickness = 28. # pts g = gr.line(3, 3.5, 2, 1) g.lineThickness = 'semithick' g.lineStyle = 'dashed' # A default, un-modified line gr.line(1, 3, 1.5, 0.5) g = gr.line(3.5, 1, 3.5, 2) g.lineThickness = 10 g.cap = 'rect' # default butt g = gr.text('some lines', 3,3) g.anchor = 'north west' g.textSize = 'normalsize' gr.png() gr.svg()
from gram import Gram myText = r"""This is some\\ multi-line text that does not work so well.\\ With $\alpha$ unusual $\beta$ characters.""" if 0: # This works gr = Gram() gr.baseName = 'minipage' stuff = r"\begin{minipage}{12cm}%s\end{minipage}" % myText g = gr.text(stuff, 1,2) g.anchor = 'south west' gr.pdflatexOutputGoesToDevNull = False gr.pdf() if 0: # This does not work gr = Gram() gr.baseName = 'varwidth' stuff = r"\begin{varwidth}{12cm}%s\end{varwidth}" % myText g = gr.text(stuff, 1,2) g.anchor = 'south west' gr.latexUsePackages.append("varwidth") gr.pdflatexOutputGoesToDevNull = False gr.pdf() if 0: # This does not work gr = Gram() gr.baseName = 'pbox' stuff = r"\pbox{12cm}{%s}" % myText g = gr.text(stuff, 1,2) g.anchor = 'south west' gr.latexUsePackages.append("pbox") gr.pdflatexOutputGoesToDevNull = False
Gnat & per gram & 13.65 \\ & each & 0.01 \\ Gnu & stuffed & 92.50 \\ Emu & stuffed & 33.33 \\ Armadillo & frozen & 8.99 \\ \addlinespace Total & & 56.23 \\ \bottomrule \end{tabular} \end{center} \end{minipage} """ t5 = r"""\includegraphics[scale = 0.25, angle=32] {../../frownie_tongue.png}""" from gram import Gram gr = Gram() gr.font = "palatino" gr.latexUsePackages.append('mdwlist') gr.latexUsePackages.append('booktabs') gr.latexUsePackages.append('graphicx') bNames = ['t1', 't2', 't3', 't3x', 't4', 't5'] tt = [t1, t2, t3, t3x, t4, t5] for dNum in range(6): gr.graphics = [] gr.baseName = bNames[dNum] gr.text(tt[dNum], 0, 0) print "about to do %s" % tt[dNum] gr.png()
from gram import Gram tt = "xxx xxX xXy xyy".split() xx = [i for i in range(1,5)] gr = Gram() gr.baseName = 'textVerticalAlignment' gr.grid(0,0,5,5) for i in range(4): gr.code(r"\node [anchor=west] at (%.1f,4.0) {%s};" % (xx[i], tt[i])) g = gr.text(tt[i],xx[i],3) g.anchor = 'west' gr.code(r"\node [anchor=west,draw] at (%.1f,2.0) {%s};" % (xx[i], tt[i])) g = gr.text(tt[i],xx[i],1) g.anchor = 'west' g.draw = True gr.png() # gr.svg() tikz code does not work here
from gram import Gram gr = Gram() gr.font = 'helvetica' gr.baseName = 'big' ox = 35 oy = 20 x = ox + 10 y = oy + 55 gr.grid(ox,oy,x,y) g = gr.text("Bottom left", ox,oy) g.anchor = 'south west' g = gr.text("Top right", x, y) g.anchor = 'north east' gr.pdf() gr.svg()
from gram import Gram gr1 = Gram() gr1.font = 'helvetica' gr1.baseName = 'gramInGram' gr1.text("Embedding gram", 0, 0) gr2 = Gram() g = gr2.text("Embedded gram", 0, 0) gr2.gX = 0.3 gr2.gY = 0.5 gr1.grams.append(gr2) gr1.pdf() gr1.svg()
from gram import Gram,GramCode gr = Gram() gr.svgPxForCm = 100 gr.baseName = 'rawcode' gr.grid(0,0,3,3) gr.code("% some tikz code") gr.code(r"""\draw [->] (1,1) .. controls (1.5,3) and (2,0) .. (2.5,2);""") gr.code(r"""\draw [thick, gray, ->] (0,2) parabola bend (0.5, 1) (1, 2.5);""") gr.png() # Wipe out the tikz code toRemove = [g for g in gr.graphics if isinstance(g, GramCode)] for g in toRemove: gr.graphics.remove(g) gr.code(r'<path d="M100 -100 C 150 -300 200 0 250 -200" stroke="black" fill="none" />') gr.code(r'<path d="M 0 -200 Q 50 20 100 -250" stroke="grey" stroke-width="4px" fill="none" />') gr.svg()
from gram import Gram gr = Gram() gr.baseName = 'rotatedText' gr.showTextBB = True gr.showTextAnchor = True g = gr.text("short", 1,2) g.rotate = 30 g.draw = 'blue' g.lineThickness = 'thick' g = gr.grid(0,0, 3, 3) g = gr.text("Another bit of text.", 2,3) g.anchor = 'south west' g.rotate = -120 g.draw = 'cyan' gr.pdf() gr.svg()
from gram import Gram tt = "xxx xxX xXy xyy".split() xx = [i for i in range(1, 5)] gr = Gram() gr.baseName = 'textVerticalAlignment' gr.grid(0, 0, 5, 5) for i in range(4): gr.code(r"\node [anchor=west] at (%.1f,4.0) {%s};" % (xx[i], tt[i])) g = gr.text(tt[i], xx[i], 3) g.anchor = 'west' gr.code(r"\node [anchor=west,draw] at (%.1f,2.0) {%s};" % (xx[i], tt[i])) g = gr.text(tt[i], xx[i], 1) g.anchor = 'west' g.draw = True gr.png() # gr.svg() tikz code does not work here
from gram import Gram gr = Gram() gr.baseName = 'fontWeight' gr.font = 'helvetica' gr.grid(-2, -1, 2, 1) myText = "This is some text" #gr.text("This is a PNG", 0,0) gr.text(myText, 0, 0) gr.png() gr.graphics.pop() gr.text(myText, 0, 0) #gr.text("This is SVG, weight 300", 0, 0) gr.svgTextNormalWeight = 300 gr.baseName = 'fontWeight300' gr.svg() gr.graphics.pop() gr.text(myText, 0, 0) #gr.text("This is SVG, weight 400", 0, 0) gr.svgTextNormalWeight = 400 gr.baseName = 'fontWeight400' gr.svg()
from gram import Gram gr = Gram() gr.font = 'helvetica' gr.baseName = 'rect' gr.grid(2,2,6,5) g = gr.rect(2,3,5,4) g.lineThickness = 5 g.color = 'teal' g.fill = 'cyan!10' g = gr.text("xXy", 4,5) g.textSize = 'Large' gr.pdf() gr.svg()
from gram import Gram gr = Gram() gr.baseName = 'wrapped' gr.font = 'palatino' myText = r"""This is a bit of text, with a \texttt{textWidth}, to show wrapping. You can also set the \texttt{textJustification}, although this one does not, and so uses the default \texttt{ragged} justification.""" g = gr.text(myText, 1, 2.5) g.textWidth = 4.0 gr.text(r'''This text is not wrapped, as it has no \texttt{textWidth}''', 0, 0) gr.png()
from gram import Gram gr = Gram() gr.baseName = 'fontWeight' gr.font = 'helvetica' gr.grid(-2,-1, 2, 1) myText = "This is some text" #gr.text("This is a PNG", 0,0) g = gr.text(myText, 0,0) g.dump() gr.png() gr.graphics.pop() g = gr.text(myText, 0, 0) g.anchor = 'center' g.dump() #gr.text("This is SVG, weight 300", 0, 0) gr.svgTextNormalWeight = 300 gr.baseName = 'fontWeight300' gr.svg() # gr.graphics.pop() # gr.text(myText, 0, 0) # #gr.text("This is SVG, weight 400", 0, 0) # gr.svgTextNormalWeight = 400 # gr.baseName = 'fontWeight400' # gr.svg()
from gram import Gram gr = Gram() # gr.defaultInnerSep = 0.0 gr.grid(0, -1, 4, 2) gr.font = 'palatino' gr.baseName = 'bunnies' # Define a couple of styles from gram import GramText st = GramText('Xy') st.name = 'bunny1' st.textShape = 'scshape' st.color = 'violet' gr.styleDict[st.name] = st st = GramText('Xy') st.name = 'bunny2' st.rotate = 45 st.color = 'darkgray' st.textSize = 'small' st.draw = True #st.shape='circle' gr.styleDict[st.name] = st g = gr.text("Flopsy", 1, 1.2) g.style = 'bunny1' g = gr.text("Mopsy", 3, 1.2) g.style = 'bunny1' g = gr.text("Cottontail", 1, 0)
from gram import Gram,GramCoord,GramText gr = Gram() gr.font = 'times' gr.baseName = 'style' g = GramText('xXy') g.cA = GramCoord() g.textSize = 'Huge' g.textShape = 'itshape' g.color = 'green' g.rotate = '30' g.name = 'st1' g.anchor = 'north west' gr.styleDict[g.name] = g g = GramText('xXy') g.cA = GramCoord() g.textSize = 'footnotesize' g.textFamily = 'sffamily' g.color = 'blue' g.draw = 'violet' g.name = 'st2' g.anchor = 'center' gr.styleDict[g.name] = g for i in range(5): g = gr.text("Howdy!", 1, i) g.style = 'st1' g = gr.styleDict['st2'] g.draw = 'orange'
from gram import Gram gr1 = Gram() gr1.font = 'helvetica' gr1.baseName = 'gramInGram' gr1.text("Embedding gram", 0,0) gr2 = Gram() g = gr2.text("Embedded gram",0,0) gr2.gX = 0.3 gr2.gY = 0.5 gr1.grams.append(gr2) gr1.pdf() gr1.svg()
from gram import Gram gr = Gram() gr.font = 'palatino' gr.baseName = 'little' g = gr.text("A bit of text.", 1, 0) g.draw = True g = gr.text(r"$\sum \alpha\beta$", 2.5, 0) g.anchor = 'west' g = gr.text("0123456789", 3.5, 0) g.anchor = 'west' gr.png() gr = Gram() gr.font = 'palatino' gr.baseName = 'little' g = gr.text("A bit of text.", 1, 0) g.draw = True g = gr.text( '∑<tspan style="font-style: italic;">αβ</tspan>', 2.5, 0) g.anchor = 'west' g = gr.text("0123456789", 3.5, 0) g.anchor = 'west' gr.svg()
from gram import Gram gr = Gram() gr.baseName = 'helloWorld' gr.text("Hello World!", 0, 0) gr.png() gr.svg()
from gram import Gram gr = Gram() gr.font = 'helvetica' gr.baseName = 'rect' gr.grid(2, 2, 6, 5) g = gr.rect(2, 3, 5, 4) g.lineThickness = 5 g.color = 'teal' g.fill = 'cyan!10' g = gr.text("xXy", 4, 5) g.textSize = 'Large' gr.pdf() gr.svg()
from gram import Gram gr = Gram() gr.baseName = 'line' gr.font = 'Helvetica' gr.grid(0, 0, 4, 4) g = gr.line(1, 1, 2, 3) g.colour = 'black!20' g.lineThickness = 28. # pts g = gr.line(3, 3.5, 2, 1) g.lineThickness = 'semithick' g.lineStyle = 'dashed' # A default, un-modified line gr.line(1, 3, 1.5, 0.5) g = gr.line(3.5, 1, 3.5, 2) g.lineThickness = 10 g.cap = 'rect' # default butt g = gr.text('some lines', 3, 3) g.anchor = 'north west' g.textSize = 'normalsize' gr.png() gr.svg()
from gram import Gram myText = r"""This is some\\ multi-line text that does not work so well.\\ With $\alpha$ unusual $\beta$ characters.""" if 1: # This works gr = Gram() gr.baseName = 'minipage' stuff = r"\begin{minipage}{12cm}%s\end{minipage}" % myText g = gr.text(stuff, 1, 2) g.anchor = 'south west' gr.pdflatexOutputGoesToDevNull = False gr.pdf() if 0: # This does not work gr = Gram() gr.baseName = 'varwidth' stuff = r"\begin{varwidth}{12cm}%s\end{varwidth}" % myText g = gr.text(stuff, 1, 2) g.anchor = 'south west' gr.latexUsePackages.append("varwidth") gr.pdflatexOutputGoesToDevNull = False gr.pdf() if 0: # This does not work gr = Gram() gr.baseName = 'pbox' stuff = r"\pbox{12cm}{%s}" % myText g = gr.text(stuff, 1, 2) g.anchor = 'south west' gr.latexUsePackages.append("pbox") gr.pdflatexOutputGoesToDevNull = False
from gram import Gram gr = Gram() gr.baseName = 'colour' gr.grid(0,0,6,4) g = gr.rect(2.6, 2.6, 3.4, 3.4) g.fill = "red!30" g.draw = "blue!50" g.lineThickness = 5 g = gr.rect(2.6, 1.6, 3.4, 2.4) g.fill = "red!30" g.draw = None g = gr.rect(2.6, 0.6, 3.4, 1.4) g.fill = None g.draw = "blue!50" g.lineThickness = 5 g = gr.text("default, transparent", 3.0, 3.75) g.textSize = 'tiny' g.fill = 'white' g = gr.rect(4.6, 2.6, 5.4, 3.4) g.fill = "red!30" g.fill.transparent = False g.draw = "blue!50" g.draw.transparent = False g.lineThickness = 5 g = gr.rect(4.6, 1.6, 5.4, 2.4)
Gnu & stuffed & 92.50 \\ Emu & stuffed & 33.33 \\ Armadillo & frozen & 8.99 \\ \addlinespace Total & & 56.23 \\ \bottomrule \end{tabular} \end{center} \end{minipage} """ t5 = r"""\includegraphics[scale = 0.25, angle=32] {../../frownie_tongue.png}""" from gram import Gram gr = Gram() gr.font = "palatino" gr.latexUsePackages.append('mdwlist') gr.latexUsePackages.append('booktabs') gr.latexUsePackages.append('graphicx') gr.showTextAnchor=True gr.showTextBB=True bNames = ['t1', 't2', 't3', 't3x', 't4', 't5'] tt = [t1, t2, t3, t3x, t4, t5] for dNum in range(6): gr.graphics = [] gr.baseName = bNames[dNum] gr.text(tt[dNum],0,0) print("about to do %s" % tt[dNum]) gr.pdf()
from gram import Gram, GramCode gr = Gram() gr.svgPxForCm = 100 gr.baseName = 'code' gr.grid(0, 0, 3, 3) gr.code("% some tikz code") gr.code(r"""\draw [->] (1,1) .. controls (1.5,3) and (2,0) .. (2.5,2);""") gr.code(r"""\draw [thick, gray, ->] (0,2) parabola bend (0.5, 1) (1, 2.5);""") gr.png() # Wipe out the tikz code toRemove = [g for g in gr.graphics if isinstance(g, GramCode)] for g in toRemove: gr.graphics.remove(g) gr.code( r'<path d="M100 -100 C 150 -300 200 0 250 -200" stroke="black" fill="none" />' ) gr.code( r'<path d="M 0 -200 Q 50 20 100 -250" stroke="grey" stroke-width="4px" fill="none" />' ) gr.svg()
from __future__ import print_function from gram import Gram,GramCoord,GramGrid,GramText Gram.pdflatexOutputGoesToDevNull = True gr = Gram() gr.pdfViewer = 'open' gr.baseName = 'anchors' gr.font = 'helvetica' gr.defaultInnerSep = 0.1 g = GramGrid(0, 1, 8, 7) gr.graphics.append(g) ## _goodAnchors = ['west', 'north west', 'north', 'north east', 'east', ## 'base', 'base west', 'base east', ## 'south west', 'south', 'south east', ## #'mid', 'mid west', 'mid east', ## 'center'] # center seems to be the default nnDict = {} nn = [] for i in range(3): for j in range(4): indx = (i * 4) + j refPt = gr.goodAnchors[indx] print(indx, refPt) n = GramCoord((2 * j) + 1, (2 * i) + 1, refPt) nnDict[refPt] = n nn.append(n)
from gram import Gram gr = Gram() gr.baseName = 'wrapped' gr.font = 'palatino' myText = r"""This is a bit of text, with a \texttt{textWidth}, to show wrapping. You can also set the \texttt{textJustification}, although this one does not, and so uses the default \texttt{ragged} justification.""" g = gr.text(myText, 1,2.5) g.textWidth = 4.0 gr.text(r'''This text is not wrapped, as it has no \texttt{textWidth}''', 0,0) gr.png()