示例#1
0
 def load_tags(cls, tags: Tags) -> "Gradient":
     gdata = cls()
     assert tags[0].code == 450
     gdata.kind = tags[0].value  # 0 = solid; 1 = gradient
     first_color_value = True
     first_aci_value = True
     for code, value in tags:
         if code == 460:
             gdata.rotation = math.degrees(value)
         elif code == 461:
             gdata.centered = value
         elif code == 452:
             gdata.one_color = value
         elif code == 462:
             gdata.tint = value
         elif code == 470:
             gdata.name = value
         elif code == 453:
             gdata.number_of_colors = value
         elif code == 63:
             if first_aci_value:
                 gdata.aci1 = value
                 first_aci_value = False
             else:
                 gdata.aci2 = value
         elif code == 421:
             if first_color_value:
                 gdata.color1 = int2rgb(value)
                 first_color_value = False
             else:
                 gdata.color2 = int2rgb(value)
     return gdata
示例#2
0
 def rgb(self) -> Optional[Tuple[int, int, int]]:
     """ Returns RGB true color as (r, g, b)-tuple or None if attribute
     dxf.true_color is not set.
     """
     if self.dxf.hasattr('true_color'):
         return clr.int2rgb(self.dxf.get('true_color'))
     else:
         return None
示例#3
0
 def rgb(self) -> Optional[clr.RGB]:
     """Returns RGB true color as (r, g, b) tuple or None if true_color is
     not set.
     """
     if self.dxf.hasattr("true_color"):
         return clr.int2rgb(self.dxf.get("true_color"))
     else:
         return None
示例#4
0
 def new_bg_properties(self, aci: Optional[int],
                       true_color: Optional[int]) -> Properties:
     new_properties = copy.copy(self._properties)
     new_properties.color = (  # canvas background color
         self._render_ctx.current_layout_properties.background_color)
     if true_color is None:
         if aci is not None:
             new_properties.color = self.resolve_aci_color(aci)
         # else canvas background color
     else:
         new_properties.color = rgb_to_hex(colors.int2rgb(true_color))
     return new_properties
示例#5
0
    def _load_plot_style_table(filename: str):
        # Each layout can have a different plot style table stored in
        # Layout.dxf.current_style_sheet.
        # HEADER var $STYLESHEET stores the default ctb-file name.
        try:
            ctb = acadctb.load(filename)
        except IOError:
            ctb = acadctb.new_ctb()

        # Colors in CTB files can be RGB colors but don't have to,
        # therefore initialize color without RGB values by the
        # default AutoCAD palette:
        for aci in range(1, 256):
            entry = ctb[aci]
            if entry.has_object_color():
                # initialize with default AutoCAD palette
                entry.color = int2rgb(DXF_DEFAULT_COLORS[aci])
        return ctb
示例#6
0
 def from_entity(cls, entity: "DXFEntity") -> "GfxAttribs":
     """Get the graphical attributes of an `entity` as :class:`GfxAttribs`
     object.
     """
     attribs = cls()
     dxf = entity.dxf
     for name in ["layer", "color", "linetype", "lineweight", "ltscale"]:
         if dxf.hasattr(name):
             setattr(attribs, name, dxf.get(name))
     if dxf.hasattr("true_color"):
         attribs.rgb = colors.int2rgb(dxf.true_color)
     if dxf.hasattr("transparency"):
         if dxf.transparency == colors.TRANSPARENCY_BYBLOCK:
             attribs.transparency = TRANSPARENCY_BYBLOCK
         else:
             attribs.transparency = colors.transparency2float(
                 dxf.transparency
             )
     return attribs
示例#7
0
    def bgcolor(self) -> Optional[RGB]:
        """
        Set pattern fill background color as (r, g, b)-tuple, rgb values
        in the range [0, 255] (read/write/del)

        usage::

            r, g, b = entity.bgcolor  # get pattern fill background color
            entity.bgcolor = (10, 20, 30)  # set pattern fill background color
            del entity.bgcolor  # delete pattern fill background color

        """
        try:
            xdata_bgcolor = self.get_xdata("HATCHBACKGROUNDCOLOR")
        except const.DXFValueError:
            return None
        color = xdata_bgcolor.get_first_value(1071, 0)
        try:
            return colors.int2rgb(int(color))  # type: ignore
        except ValueError:  # invalid data type
            return 0, 0, 0
示例#8
0
def test_rgb():
    r, g, b = int2rgb(0xA0B0C0)
    assert 0xA0 == r
    assert 0xB0 == g
    assert 0xC0 == b