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 == rgb2int((10, 20, 30)) assert mtext.dxf.box_fill_scale == 2 assert mtext.dxf.hasattr('bg_fill_color') is True, \ "bg_fill_color attribute must exists, else AutoCAD complains"
def dxftags(self) -> List[DXFTag]: return [ DXFTag(450, 1), # gradient DXFTag(451, 0), # reserved for the future DXFTag(452, self.one_color), # one (1) or two (0) color gradient DXFTag(453, 2), # number of colors DXFTag(460, (self.rotation / 180.) * math.pi), # rotation angle in radians DXFTag(461, self.centered), # see DXF standard DXFTag(462, self.tint), # see DXF standard DXFTag(463, 0), # first value, see DXF standard # code == 63 "color as ACI" can be left off DXFTag(421, rgb2int(self.color1)), # first color DXFTag(463, 1), # second value, see DXF standard # code == 63 "color as ACI" can be left off DXFTag(421, rgb2int(self.color2)), # second color DXFTag(470, self.name), ]
def export_dxf(self, tagwriter: 'TagWriter') -> None: # order matters! write_tag = tagwriter.write_tag2 write_tag(450, self.kind) # gradient or solid write_tag(451, 0) # reserved for the future write_tag(460, math.radians(self.rotation)) # rotation angle in radians write_tag(461, self.centered) # see DXF standard write_tag(452, self.one_color) # one (1) or two (0) color gradient write_tag(462, self.tint) # see DXF standard write_tag(453, 2) # number of colors write_tag(463, 0) # first value, see DXF standard if self.aci1 is not None: write_tag(63, self.aci1) # code == 63 "color as ACI" can be left off write_tag(421, rgb2int(self.color1)) # first color write_tag(463, 1) # second value, see DXF standard if self.aci2 is not None: write_tag(63, self.aci2) # code 63 "color as ACI" could be left off write_tag(421, rgb2int(self.color2)) # second color write_tag(470, self.name)
def bgcolor(self, rgb: 'RGB') -> None: color_value = rgb2int(rgb) | -0b111110000000000000000000000000 # it's magic try: xdata_bgcolor = self.tags.get_xdata('HATCHBACKGROUNDCOLOR') except DXFValueError: # no xdata for background color found self.tags.xdata.append(Tags([ DXFTag(1001, 'HATCHBACKGROUNDCOLOR'), DXFTag(1071, color_value), ])) else: xdata_bgcolor.set_first(DXFTag(1071, color_value))
def set_bg_color(self, color: Union[int, str, Tuple[int, int, int], None], scale: float = 1.5): """ Set background color as :ref:`ACI` value or as name string or as RGB tuple ``(r, g, b)``. Use special color name ``canvas``, to set background color to canvas background color. Args: color: color as :ref:`ACI`, string or RGB tuple scale: determines how much border there is around the text, the value is based on the text height, and should be in the range of [1, 5], where 1 fits exact the MText entity. """ if 1 <= scale <= 5: self.dxf.box_fill_scale = scale else: raise ValueError('argument scale has to be in range from 1 to 5.') if color is None: self.dxf.discard('bg_fill') self.dxf.discard('box_fill_scale') self.dxf.discard('bg_fill_color') self.dxf.discard('bg_fill_true_color') self.dxf.discard('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 rgb(self, rgb): self.set_dxf_attrib('true_color', rgb2int(rgb))
def rgb(self, rgb: Tuple[int, int, int]) -> None: """ Set RGB true color as (r, g , b) tuple e.g. (12, 34, 56). """ self.dxf.set('true_color', rgb2int(rgb))
def rgb(self, rgb: Tuple[int, int, int]) -> None: self.set_dxf_attrib('true_color', rgb2int(rgb))
def bgcolor(self, rgb: 'RGB') -> None: color_value = rgb2int( rgb) | -0b111110000000000000000000000000 # it's magic self.discard_xdata('HATCHBACKGROUNDCOLOR') self.set_xdata('HATCHBACKGROUNDCOLOR', [(1071, color_value)])
def test_from_rgb(self): self.assertEqual(0xA0B0C0, rgb2int((0xA0, 0xB0, 0xC0)))
def test_from_rgb(): assert 0xA0B0C0 == rgb2int((0xA0, 0xB0, 0xC0))