def test_07(self): """TestSVGlWriter.test_07(): text. Based on http://www.w3.org/TR/2003/REC-SVG11-20030114/text.html#TextElement""" myF = io.StringIO() myViewPort = Coord.Box( Coord.Dim(12, 'cm'), Coord.Dim(4, 'cm'), ) with SVGWriter.SVGWriter(myF, myViewPort, {'viewBox': "0 0 1000 300"}) as xS: with XmlWrite.Element(xS, 'desc'): xS.characters("Example text01 - 'Hello, out there' in blue") myPt = Coord.Pt(Coord.baseUnitsDim(250), Coord.baseUnitsDim(150)) with SVGWriter.SVGText(xS, myPt, "Verdans", 55, {'fill': "blue"}): xS.characters('Hello, out there') #xS.comment(" Show outline of canvas using 'rect' element ") myPt = Coord.Pt(Coord.baseUnitsDim(1), Coord.baseUnitsDim(1)) myBx = Coord.Box(Coord.baseUnitsDim(998), Coord.baseUnitsDim(298)) with SVGWriter.SVGRect(xS, myPt, myBx, { 'fill': "none", 'stroke': "blue", 'stroke-width': "2" }): pass # print() # print(myF.getvalue()) self.assertEqual( myF.getvalue(), """<?xml version='1.0' encoding="utf-8"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg height="4.000cm" version="1.1" viewBox="0 0 1000 300" width="12.000cm" xmlns="http://www.w3.org/2000/svg"> <desc>Example text01 - 'Hello, out there' in blue</desc> <text fill="blue" font-family="Verdans" font-size="55" x="250.000px" y="150.000px">Hello, out there</text> <rect fill="none" height="298.000px" stroke="blue" stroke-width="2" width="998.000px" x="1.000px" y="1.000px"/> </svg> """)
def plotText(self, thePoint, theFont, theSize, theText): """Plots text. thePoint - Coord.Pt theFont - string. theSize - integer. theText - string""" with SVGWriter.SVGText(self._svg, thePoint, theFont, theSize): self._svg.characters(theText)
def _plotCONS(self, xS, st, theValStr): """Print a Static() object with an value as a string e.g. EngVal.pStr().""" # No Rectangle myTAttr = st.tAttr myTAttr.update({ 'font-weight': "bold", }) with SVGWriter.SVGText( xS, self._pt(st.x + 0.05 + st.xMnem, st.y + st.d * 3 / 4), st.font, st.size, myTAttr, ): xS.characters(theValStr)
def _plotStatic(self, xS, st): if st.rAttr is not None: # Write the box with SVGWriter.SVGRect( xS, self._pt(st.x, st.y), Coord.Box(Coord.Dim(st.w, HEADER_PLOT_UNITS), Coord.Dim(st.d, HEADER_PLOT_UNITS)), st.rAttr, ): pass # Write the text if st.text is not None: with SVGWriter.SVGText( xS, self._pt(st.x + 0.05, st.y + st.d * 3 / 4), st.font, st.size, st.tAttr, ): xS.characters(st.text)
def _plotLogo(self, xS): """Plots the TotalDepth logo.""" myLogoColour = "blue" with SVGWriter.SVGRect(xS, self._pt(1.2, 2.05), self._box(2.0, 0.3), { 'fill': "none", 'stroke': myLogoColour, 'stroke-width': "2.0", }): pass with SVGWriter.SVGRect(xS, self._pt(1.2, 2.05 + 0.3), self._box(2.0, 0.3), { 'fill': myLogoColour, 'stroke': myLogoColour, 'stroke-width': "2.0", }): pass with SVGWriter.SVGText(xS, self._pt(1.2 + 1.0, 2.05 + 0.3 + 0.25), FONT_PROP, 24, { 'text-anchor': 'middle', 'font-weight': "bold", 'fill': "white", }): xS.characters('TotalDepth')
def test_00(self): """TestPlotTrack.test_00(): Construct a lin/log/log track with FEET 1/200 and plot it in SVG.""" myCnv = Plot.Canvas(Coord.Dim(8.5, 'in'), Coord.Dim(12, 'in'), PlotConstants.MarginQtrInch) myViewPort = Coord.Box( width=myCnv.width, depth=myCnv.depth, ) myTopLeft = Coord.Pt(Coord.Dim(0.25, 'in'), Coord.Dim(0.25, 'in')) myF = io.StringIO() myTracks = [ Track.Track(leftPos=Coord.Dim(0.0, 'in'), rightPos=Coord.Dim(2.4, 'in'), gridGn=Track.genLinear10), Track.Track( leftPos=Coord.Dim(2.4, 'in'), rightPos=Coord.Dim(3.2, 'in'), gridGn=None, plotXAxis=True, ), Track.Track(leftPos=Coord.Dim(3.2, 'in'), rightPos=Coord.Dim(5.6, 'in'), gridGn=Track.genLog10Decade2Start2), Track.Track(leftPos=Coord.Dim(5.6, 'in'), rightPos=Coord.Dim(8, 'in'), gridGn=Track.genLog10Decade2Start2), ] with SVGWriter.SVGWriter(myF, myViewPort) as xS: # Do tracks first for t in myTracks: #xS.comment(str(t)) if t.hasGrid: t.plotSVG( myTopLeft, myCnv.depth - myCnv.margins.top - myCnv.margins.bottom, xS, ) # Now XGrid # We are plotting up so xPosStart is at bottom myXposStart = myCnv.depth - myCnv.margins.bottom myXposStop = myCnv.margins.top myXg = XGrid.XGrid(200) # Plot depth lines for pos, stroke in myXg.genXPosStroke(xFrom=4307.5, xInc=False, units=b'FEET'): myXpos = myXposStart + pos if myXpos < myXposStop: break for t in myTracks: if t.hasGrid: with SVGWriter.SVGLine( xS, Coord.Pt(t.left + myCnv.margins.left, myXpos), Coord.Pt(t.right + myCnv.margins.left, myXpos), attrs=Stroke.retSVGAttrsFromStroke(stroke)): pass # Plot depth text textAttrs = { 'text-anchor': 'end', 'dominant-baseline': 'middle', } for pos, val in myXg.genXPosText(xFrom=4307.5, xInc=False, units=b'FEET'): myXpos = myXposStart + pos if myXpos < myXposStop: break for t in myTracks: if t.plotXAxis: myPt = Coord.Pt( t.right + myCnv.margins.left - Coord.Dim(0.05, 'in'), myXpos) with SVGWriter.SVGText(xS, myPt, 'Courier', 16, textAttrs): xS.characters(str(val)) print() print(myF.getvalue())