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 = '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.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 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 = '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.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()
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' for i in range(5): g = gr.text("Howdy!", 5, i) g.style = 'st2' g = GramText('xXy') g.cA = GramCoord() g.textSize = 'Large' g.textFamily = 'rmfamily' g.textShape = 'scshape' g.color = 'red' g.draw = None
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 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 = '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 = '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()
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) g.style = 'bunny1' g.myStyle = 'bunny2' g = gr.text("Peter", 3, 0) g.style = 'bunny1' g.anchor = 'south west' g.textShape = 'itshape' g.draw = True g.color = 'blue!85'
from gram import TreeGram,TreeGramRadial,Gram read("((A,B)ab,C,(D,E)de)m;") t = var.trees[0] t.node(1).br.uName = 'X' t.node(5).br.uName = 'Y' tg = TreeGram(t, scale=7.) print "a", tg.internalNodeLabelSize tg.baseName = 'twoTreesII' t = t.dupe() tgB = TreeGramRadial(t, scale=8., slopedBrLabels=True, rotate=90) print "b", tg.internalNodeLabelSize tgB.tree.root.label.yShift = 0.1 tgB.gX = 4.8 tgB.gY = -1.5 gr = Gram() g = gr.text(r'$\Longleftrightarrow$', 0, 0) # LaTeX symbol gr.text('equivalence', 0, 0.5) gr.gX = 3.5 gr.gY = 1.0 tg.grams.append(tgB) tg.grams.append(gr) tg.png() g.rawText = '⇔' # unicode symbol tg.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 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
from gram import Gram gr = Gram() gr.baseName = 'helloWorld' gr.text("Hello World!", 0, 0) gr.png() gr.svg()
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 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
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) g.fill = "red!30" g.fill.transparent = False g.draw = None
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 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()