def test_set_bg_true_color(layout): mtext = layout.add_mtext("TEST").set_bg_color((10, 20, 30), scale=2) assert mtext.dxf.bg_fill == 1 assert mtext.dxf.bg_fill_true_color == ezdxf.rgb2int((10, 20, 30)) assert mtext.dxf.box_fill_scale == 2 assert mtext.dxf.hasattr( 'bg_fill_color' ) is True, "bg_fill_color must exists, else AutoCAD complains"
def ctx(self): doc = ezdxf.new() doc.layers.new( 'TrueColor', dxfattribs={'true_color': ezdxf.rgb2int((0xB0, 0xB0, 0xB0))}) context = RenderContext(doc) context.set_current_layout(doc.modelspace()) return context
def lwpolyline_with_true_color(): doc = ezdxf.new('AC1018') # for true color and transparency is DXF version AC1018 (ACAD R2004) or newer necessary msp = doc.modelspace() points = [(0, 0), (3, 0), (6, 3), (6, 6)] msp.add_lwpolyline(points, dxfattribs={ 'color': 2, 'true_color': ezdxf.rgb2int((38, 140, 89)) # true color has higher priority than the color attribute }) doc.saveas("true_color_lwpolyline.dxf")
def test_add_layer(self, tables: TablesSection): layer = tables.layers.add( "NEW_LAYER", color=2, true_color=ezdxf.rgb2int((0x10, 0x20, 0x30)), linetype="DASHED", lineweight=18, plot=True, ) assert layer.dxf.name == "NEW_LAYER" assert layer.dxf.color == 2 assert layer.dxf.true_color == 0x00102030 assert layer.dxf.linetype == "DASHED", "no check if line type exist!" assert layer.dxf.lineweight == 18 assert layer.dxf.plot == 1
def set_bg_color(self, color: Union[int, str, Tuple[int, int, int], None], scale: float = 1.5): self.dxf.box_fill_scale = scale if color is None: self.del_dxf_attrib('bg_fill') self.del_dxf_attrib('box_fill_scale') self.del_dxf_attrib('bg_fill_color') self.del_dxf_attrib('bg_fill_true_color') self.del_dxf_attrib('bg_fill_color_name') elif color == 'canvas': # special case for use background color self.dxf.bg_fill = const.MTEXT_BG_CANVAS_COLOR self.dxf.bg_fill_color = 0 # required but ignored else: self.dxf.bg_fill = const.MTEXT_BG_COLOR if isinstance(color, int): self.dxf.bg_fill_color = color elif isinstance(color, str): self.dxf.bg_fill_color = 0 # required but ignored self.dxf.bg_fill_color_name = color elif isinstance(color, tuple): self.dxf.bg_fill_color = 0 # required but ignored self.dxf.bg_fill_true_color = rgb2int(color) return self # fluent interface
def get_color_attribs(ctx: MTextContext) -> Dict: attribs = {"color": ctx.aci} if ctx.rgb is not None: attribs["true_color"] = ezdxf.rgb2int(ctx.rgb) return attribs