def __init__(self, name, data, context=None): self.name = name self.data = data self.context = context # I may need to know the larger context (the model) to resolve types self.iconFile = data.get("icon", "generic.svg") self.customInstantiator = None f = open(common.fileResolver(self.iconFile), "r") self.iconSvg = svg.Svg(f.read(), (256, 128)) f.close() self.buttonFile = data.get("button", "generic_button.svg") f = open(common.fileResolver(self.buttonFile), "r") self.buttonSvg = svg.Svg(f.read(), (32, 32)) f.close()
def convert_svg(inputFilename, outputFilename, dataWriter=None): mySvg = svg.Svg(inputFilename) f = open(outputFilename, 'w') f.write('<svg xmlns="http://www.w3.org/2000/svg" >') bounds = mySvg.bbox() mySvg.translate((-bounds[0].x, -bounds[0].y)) mySvg.scale( min(width / (bounds[1].x - bounds[0].x), height / (bounds[1].y - bounds[0].y))) strokeColor = 'currentcolor' fillColor = 'none' f.write('<path d="') for path in mySvg.flatten(): for stroke in path.simplify(100, 1): data = ''.join([ 'M{:.2f} {:.2f}'.format(stroke[0].x, stroke[0].y), ' '.join( ['L{:.2f} {:.2f}'.format(i.x, i.y) for i in stroke[1:]]) ]) f.write(data) if dataWriter: dataWriter.write(data) f.write('" style="stroke: {}; fill: {}"></path>'.format( strokeColor, fillColor)) f.write('</svg>') f.close() return data
def makeBitmap(self,elem): text = ET.tostring(elem) # Awkward, we have to convert the XML BACK into text so rsvg can convert it back to some object representation! t = svg.Svg(text) bk = self.parent.GetBackgroundColour() # TODO transparent background bkcol = (bk[0],bk[1],bk[2]) bitmap = t.bmp(bkcol=bkcol) return bitmap
def overlay(title, results, inference_time, inference_rate, layout): x0, y0, width, height = layout.window font_size = 0.03 * height defs = svg.Defs() defs += CSS_STYLES doc = svg.Svg(width=width, height=height, viewBox='%s %s %s %s' % layout.window, font_size=font_size, font_family='monospace', font_weight=500) doc += defs ox1, ox2 = x0 + 20, x0 + width - 20 oy1, oy2 = y0 + 20 + font_size, y0 + height - 20 # Classes lines = ['%s (%.2f)' % pair for pair in results] for i, line in enumerate(lines): y = oy2 - i * 1.7 * font_size doc += svg.Rect(x=0, y=0, width=size_em(len(line)), height='1em', transform='translate(%s, %s) scale(-1,-1)' % (ox2, y), _class='back') doc += svg.Text(line, text_anchor='end', x=ox2, y=y, fill='white') # Title if title: doc += svg.Rect(x=0, y=0, width=size_em(len(title)), height='1em', transform='translate(%s, %s) scale(1,-1)' % (ox1, oy1), _class='back') doc += svg.Text(title, x=ox1, y=oy1, fill='white') # Info lines = [ 'Inference time: %.2f ms (%.2f fps)' % (inference_time * 1000, 1.0 / inference_time) ] for i, line in enumerate(reversed(lines)): y = oy2 - i * 1.7 * font_size doc += svg.Rect(x=0, y=0, width=size_em(len(line)), height='1em', transform='translate(%s, %s) scale(1,-1)' % (ox1, y), _class='back') doc += svg.Text(line, x=ox1, y=y, fill='white') return str(doc)
def overlay(title, objs, get_color, inference_time, inference_rate, layout): x0, y0, width, height = layout.window font_size = 0.03 * height defs = svg.Defs() defs += CSS_STYLES doc = svg.Svg(width=width, height=height, viewBox='%s %s %s %s' % layout.window, font_size=font_size, font_family='monospace', font_weight=500) doc += defs for obj in objs: percent = int(100 * obj.score) if obj.label: caption = '%d%% %s' % (percent, obj.label) else: caption = '%d%%' % percent x, y, w, h = obj.bbox.scale(*layout.size) color = get_color(obj.id) doc += svg.Rect(x=x, y=y, width=w, height=h, style='stroke:%s' % color, _class='bbox') doc += svg.Rect(x=x, y=y+h , width=size_em(len(caption)), height='1.2em', fill=color) t = svg.Text(x=x, y=y+h, fill='black') t += svg.TSpan(caption, dy='1em') doc += t ox = x0 + 20 oy1, oy2 = y0 + 20 + font_size, y0 + height - 20 # Title if title: doc += svg.Rect(x=0, y=0, width=size_em(len(title)), height='1em', transform='translate(%s, %s) scale(1,-1)' % (ox, oy1), _class='back') doc += svg.Text(title, x=ox, y=oy1, fill='white') # Info lines = [ 'Objects: %d' % len(objs), 'Inference time: %.2f ms (%.2f fps)' % (inference_time * 1000, 1.0 / inference_time) ] for i, line in enumerate(reversed(lines)): y = oy2 - i * 1.7 * font_size doc += svg.Rect(x=0, y=0, width=size_em(len(line)), height='1em', transform='translate(%s, %s) scale(1,-1)' % (ox, y), _class='back') doc += svg.Text(line, x=ox, y=y, fill='white') return str(doc)
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import argparse import logging import signal from camera import make_camera from gstreamer import Display, run_gen from streaming.server import StreamingServer import svg EMPTY_SVG = str(svg.Svg()) def run_server(add_render_gen_args, render_gen): logging.basicConfig(level=logging.INFO) parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument( '--source', help='/dev/videoN:FMT:WxH:N/D or .mp4 file or image file', default='/dev/video0:YUY2:640x480:30/1') parser.add_argument('--bitrate', type=int, default=1000000, help='Video streaming bitrate (bit/s)')
p_1 = it((0, height), (1, 0), (0.5 * width, 0.5 * height), Vector_p) #交点A,Bを求める A = it(l_0, Vector_lm, (0.5 * width, 0.5 * height), Vector_p) B = it(m_0, Vector_lm, (0.5 * width, 0.5 * height), Vector_p) if angle_x < 0: angle_xx = 180 + angle_x else: angle_xx = angle_x #svgに描画 font = "Ubuntu Mono" angle_poss = math.degrees(0.5 * (180 - angle_x)) d_poss = 14 poss = (abs(d_poss * math.cos(angle_poss)), abs(d_poss * math.sin(angle_poss))) q = svg.Svg() q.create_text("angle_para:{}".format(angle_para), 5, 25, font, 14) q.create_text("angle_cross:{}".format(angle_cross), 5, 40, font, 14) q.create_text("angle_xx:{}".format(angle_xx), 5, 55, font, 14) q.create_text("d_para:{}".format(d_para), 5, 70, font, 14) q.create_text("{}".format(angle_xx), A[0] + poss[0], A[1] - poss[1], font, 12) q.create_text("x", B[0] + poss[0], B[1] - poss[1], font, 12) q.create_line(l_0[0], l_0[1], l_1[0], l_1[1]) #線lの描写 q.create_line(m_0[0], m_0[1], m_1[0], m_1[1]) #線mの描写 q.create_line(p_0[0], p_0[1], p_1[0], p_1[1]) #線pの描写 q.set_svg(0, 0, width, height) #svgファイルに出力 q.save(name="testParallel.svg")
for segment in draw.segments(0.1): pts = [x.coord() for x in segment] pts.reverse() p1 = pts.pop() while pts: p2 = pts.pop() m.draw(kicad.Segment(p1, p2, 0.1524)) p1 = p2 else: print("Unsupported SVG element" + draw) #for s in f.scale(ratio).translate(offset).simplify(0.01): # m.draw(kicad.Polygon([x.coord() for x in s])) fsvg = svg.Svg(sys.argv[1]) name = fsvg.title() print('Scale ' + name + ' to ' + str(sys.argv[2:]) + ' widths') l = kicad.LibModule(name + '.mod') for width in sys.argv[2:]: f = copy.deepcopy(fsvg) m = kicad.Module(name + '-' + width) m.reference('G*') m.value(name) # Scale to 'width' a, b = f.bbox() ratio = int(width) / (b - a).x # Centering offset
import svg import dash from dash.dependencies import Input, Output import dash_html_components as html app = dash.Dash(__name__) app.layout = html.Div([ svg.Svg(id='input', value='my-value', label='my-label'), html.Div(id='output') ]) @app.callback(Output('output', 'children'), [Input('input', 'value')]) def display_output(value): return 'You have entered {}'.format(value) if __name__ == '__main__': app.run_server(debug=True)
def overlay(title, objs, get_color, inference_time, inference_rate, layout): x0, y0, width, height = layout.window defs = svg.Defs() defs += CSS_STYLES doc = svg.Svg(width=width, height=height, viewBox='%s %s %s %s' % layout.window, font_size='1em', font_family='monospace', font_weight=500) doc += defs for obj in objs: percent = int(100 * obj.score) if obj.label: caption = '%d%% %s' % (percent, obj.label) else: caption = '%d%%' % percent x, y, w, h = obj.bbox.scale(*layout.size) color = get_color(obj.id) doc += svg.Rect(x=x, y=y, width=w, height=h, style='stroke:%s' % color, _class='bbox') doc += svg.Rect(x=x, y=y + h, width=size_em(len(caption)), height='1.2em', fill=color) #center center = ((x + w / 2), (y + h / 2)) doc += svg.Circle(cx=center[0], cy=center[1], r=5, style='stroke:%s' % color) centerPts.append(center) for i in range(1, len(centerPts)): doc += svg.Line(x1=centerPts[i - 1][0], y1=centerPts[i - 1][1], x2=centerPts[i][0], y2=centerPts[i][1], style='stroke:%s' % color) #print(centerPts[i-1][0],centerPts[i-1][1]) #print(centerPts) #corner #doc += svg.Circle(cx=x,cy=y,r=10, style='stroke:%s' % color) t = svg.Text(x=x, y=y + h, fill='black') t += svg.TSpan(caption, dy='1em') doc += t ox, oy1, oy2 = x0 + 20, y0 + 20, y0 + height - 20 # Title if title: doc += svg.Rect(x=ox, y=oy1, width=size_em(len(title)), height='1em', _class='back') t = svg.Text(x=ox, y=oy1, fill='white') t += svg.TSpan(title, dy='1em') doc += t # Info lines = [ 'Objects: %d' % len(objs), 'Inference time: %.2f ms (%.2f fps)' % (inference_time * 1000, 1.0 / inference_time) ] text_width = size_em(max(len(line) for line in lines)) doc += svg.Rect(x=0, y=0, width=text_width, height='2.2em', transform='translate(%s, %s) scale(1,-1)' % (ox, oy2), _class='back') t = svg.Text(y=oy2, fill='white') t += svg.TSpan(lines[0], x=ox) t += svg.TSpan(lines[1], x=ox, dy='-1.2em') doc += t return str(doc)
trace_file = 'trazaReal.tr' trace_type = 'ns2' terminal = 'svg' output_file = './out.svg' if trace_type == 'ns2': trace = ns2.Ns2_trace() elif trace_type == 'omnet++': trace = omnet.Omnet_trace() else: raise 'trace type error ' + trace_type if terminal == 'svg': terminal = svg.Svg(output_file) elif terminal == 'tex': terminal = tex.Tex() else: raise 'terminal error ' + terminal trace_fid = open(trace_file, 'r') mycanvas = trace.scan_trace(trace_fid) trace_fid.close() mycanvas.draw(terminal) terminal.close() #time.sleep(1) #drawing = svg2rlg("out.svg") #renderPDF.drawToFile(drawing, "out.pdf")
text1 = [ "AB//CD//EF かつ AE//BF である。", "∠{0} = {1}, ∠{2} = {3}, ∠{4} = {5}".format( "MAO", int(np.round(p.get_angle2lines(m_n[0])[0])), "KLE", int(np.round(q.get_angle2lines(l_n[2])[0])), "DFE", int(np.round(l_n[2].get_angle2lines(m_n[1])[0]))), " のとき、次の角度を求めよ。" ] text2 = [ "(1)∠{} (2)∠{}".format("test", "test"), "(3)∠{} (4)∠{}".format("test", "test"), "(5)∠{} (6)∠{}".format("test", "test"), "(7)∠{} (8)∠{}".format("test", "test"), "(9)∠{} (10)∠{}".format("test", "test"), ] svg = svg.Svg() [frame[i].write_svg(svg, stroke_width=0.5) for i in range(4)] [l_n[l].write_svg(svg) for l in range(3)] [m_n[m].write_svg(svg) for m in range(2)] p.write_svg(svg) q.write_svg(svg) #[svg.create_text("P_{0}{1}:({2},{3})".format(l+1,m+1,int(P_lm[l][m][0]),int(P_lm[l][m][1])),width+150*m+5,25*l+15,font_size=14) for l in range(3) for m in range(2)] #[svg.create_text("Q_l{0}:({1},{2})".format(n+1,int(Q_l[n][0]),int(Q_l[n][1])),width+5,150+12.5*n,font_size=14) for n in (0,2)] #svg.create_text("Q_m:({0},{1})".format(int(Q_m[0][0]),int(Q_m[0][1])),width+5,200,font_size=14) [ svg.create_text(P_names[l][m], P_lm[l][m][0], P_lm[l][m][1], font_size=11) for l in range(3) for m in range(2) ] [ svg.create_text(Q_names[n], Q_l[n][0], Q_l[n][1], font_size=11) for n in range(3)