Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _set_gradient(self, gradient_data: 'GradientData') -> None:
gradient_data.name = gradient_data.name.upper()
if gradient_data.name not in const.GRADIENT_TYPES:
raise DXFValueError('Invalid gradient type name: %s' % gradient_data.name)
self._remove_pattern_data()
self._remove_gradient_data()
self.dxf.solid_fill = 1
self.dxf.pattern_name = 'SOLID'
self.dxf.pattern_type = const.HATCH_TYPE_PREDEFINED
self.AcDbHatch.extend(gradient_data.dxftags())
def mesh(self, data: bytes):
logger.warning('Untested proxy graphic entity: MESH - Need examples!')
bs = ByteStream(data)
rows, columns = bs.read_struct('2L')
attribs = self._build_dxf_attribs()
attribs['m_count'] = rows
attribs['n_count'] = columns
attribs['flags'] = const.POLYLINE_3D_POLYMESH
polymesh = cast('Polymesh', self._factory('POLYLINE', dxfattribs=attribs))
polymesh.append_vertices(Vector(bs.read_vertex()) for _ in range(rows * columns))
return polymesh
def get_entity_color(self, entity: DXFGraphic, *, default_hatch_transparency: float = 0.8) -> Color:
if not entity.dxf.hasattr('color'):
return self.layout_default_color # unknown
color_code = entity.dxf.color # defaults to BYLAYER
if color_code == DXFConstants.BYLAYER:
entity_layer = entity.dxf.layer.lower()
# AutoCAD appears to treat layer 0 differently to other layers in this case.
if self._insert_layer is not None and entity_layer == '0':
color = self.layer_colors[self._insert_layer]
else:
color = self.layer_colors[entity_layer]
elif color_code == DXFConstants.BYBLOCK:
if self._block_color is None:
color = self.layout_default_color
else:
color = self._block_color
else: # BYOBJECT
color = self._get_color(entity.rgb, color_code)
if isinstance(entity, DXFEntity.Hatch):
transparency = default_hatch_transparency
else:
transparency = entity.transparency
alpha_float = 1.0 - transparency
alpha = int(round(alpha_float * 255))
if alpha == 255:
def _dxfattribs(self, alignpoint: 'Vertex') -> dict:
"""
Build keyword arguments for TEXT entity creation.
"""
halign, valign = const.TEXT_ALIGN_FLAGS.get(self.align)
return {
'insert': alignpoint,
'align_point': alignpoint,
'layer': self.layer,
'color': self.color,
'style': self.style,
'height': self.height,
'width': self.xscale,
'text_generation_flag': self.mirror,
'rotation': self.rotation,
'oblique': self.oblique,
'halign': halign,
'valign': valign,
}
def resolve_lineweight(self, entity: 'DXFGraphic', *, resolved_layer: str = None):
# Line weight in mm times 100 (e.g. 0.13mm = 13).
# Smallest line weight is 0 and biggest line weight is 211
# The DWG format is limited to a fixed value table: 0, 5, 9, ... 200, 211
# DEFAULT: The LAYOUT entity has no explicit graphic properties.
# BLOCK and BLOCK_RECORD entities also have no graphic properties.
# Maybe XDATA or ExtensionDict in any of this entities.
aci = entity.dxf.color
# Not sure if plotstyle table overrides actual entity setting?
if (0 < aci < 256) and self.plot_styles[aci].lineweight != acadctb.OBJECT_LINEWEIGHT:
# overriding lineweight by plotstyle table
return self.plot_styles.get_lineweight(aci)
lineweight = entity.dxf.lineweight # default is BYLAYER
if lineweight == const.LINEWEIGHT_BYLAYER:
entity_layer = resolved_layer or layer_key(self.resolve_layer(entity))
return self.layers.get(entity_layer, DEFAULT_LAYER_PROPERTIES).lineweight
elif lineweight == const.LINEWEIGHT_BYBLOCK:
if self.inside_block_reference:
return self.current_block_reference.lineweight
else:
# There is no default layout lineweight
return self.default_lineweight()
elif lineweight == const.LINEWEIGHT_DEFAULT:
return self.default_lineweight()
else:
return float(lineweight) / 100.0
def add_polyface(self, dxfattribs: dict = None) -> 'Polyface':
"""
Add a :class:`~ezdxf.entities.Polyface` entity, which is a wrapper class for the POLYLINE entity.
Args:
dxfattribs: additional DXF attributes for :class:`~ezdxf.entities.Polyline` entity
"""
dxfattribs = dict(dxfattribs or {})
dxfattribs['flags'] = dxfattribs.get('flags', 0) | const.POLYLINE_POLYFACE
m_close = dxfattribs.pop('m_close', False)
n_close = dxfattribs.pop('n_close', False)
polyface = self.new_entity('POLYLINE', dxfattribs) # type: Polyface
polyface.close(m_close, n_close)
return polyface
def __init__(self):
self.path_type_flags = const.BOUNDARY_PATH_POLYLINE
self.is_closed = 0
self.vertices = [] # type: List[Tuple[float, float, float]] # list of 2D coordinates with bulge values (x, y, bulge); bulge default = 0.0
self.source_boundary_objects = [] # type: List[DXFTag] # (330, handle) tags
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
# Not sure if plotstyle table overrides actual entity setting?
if (0 < aci < 256) and self.plot_styles[aci].lineweight != acadctb.OBJECT_LINEWEIGHT:
# overriding lineweight by plotstyle table
return self.plot_styles.get_lineweight(aci)
lineweight = entity.dxf.lineweight # default is BYLAYER
if lineweight == const.LINEWEIGHT_BYLAYER:
entity_layer = resolved_layer or layer_key(self.resolve_layer(entity))
return self.layers.get(entity_layer, DEFAULT_LAYER_PROPERTIES).lineweight
elif lineweight == const.LINEWEIGHT_BYBLOCK:
if self.inside_block_reference:
return self.current_block_reference.lineweight
else:
# There is no default layout lineweight
return self.default_lineweight()
elif lineweight == const.LINEWEIGHT_DEFAULT:
return self.default_lineweight()
else:
return float(lineweight) / 100.0
from abc import abstractmethod
from ezdxf.lldxf import const
from .mtext import MText
DEFAULT_TABLE_BGLAYER = 'TABLEBACKGROUND'
DEFAULT_TABLE_FGLAYER = 'TABLECONTENT'
DEFAULT_TABLE_GRIDLAYER = 'TABLEGRID'
DEFAULT_TABLE_HEIGHT = 1.0
DEFAULT_TABLE_WIDTH = 2.5
DEFAULT_TEXTSTYLE = 'STANDARD'
DEFAULT_CELL_TEXT_HEIGHT = 0.7
DEFAULT_CELL_LINESPACING = 1.5
DEFAULT_CELL_XSCALE = 1.0
DEFAULT_CELL_YSCALE = 1.0
DEFAULT_CELL_TEXTCOLOR = const.BYLAYER
DEFAULT_CELL_BG_COLOR = None
DEFAULT_CELL_HMARGIN = 0.1
DEFAULT_CELL_VMARGIN = 0.1
DEFAULT_BORDER_COLOR = 5
DEFAULT_BORDER_LINETYPE = "BYLAYER"
DEFAULT_BORDER_STATUS = True
DEFAULT_BORDER_PRIORITY = 50
VISIBLE = 1
HIDDEN = 0
class Table(object):
"""A HTML-table like object.
The table object contains the table data cells.