def __init__(self): self.ctm = Matrix.identity_matrix() self.text_matrix = Matrix.identity_matrix() self.text_line_matrix = Matrix.identity_matrix() self.text_rise = Decimal(0) self.character_spacing = Decimal(0) self.word_spacing = Decimal(0) self.horizontal_scaling = Decimal(100) self.leading = Decimal(0) self.font = None self.font_size = None self.path: typing.List["LineSegment"] = [] self.clipping_path: typing.List["LineSegment"] = [] self.non_stroke_color_space = None self.non_stroke_color = RGBColor(Decimal(0), Decimal(0), Decimal(0)) self.stroke_color_space = None self.stroke_color = RGBColor(Decimal(0), Decimal(0), Decimal(0)) self.line_width = Decimal(1) self.line_cap = None self.line_join = None self.miter_limit = Decimal(10) self.dash_pattern = None self.rendering_intent = None self.stroke_adjustment = None self.blend_mode = None self.soft_mask = None self.alpha_constant = None self.alpha_source = None
def invoke(self, canvas: "Canvas", operands: List[AnyPDFType] = []): # type: ignore [name-defined] """ Invoke the BT operator """ canvas.graphics_state.text_matrix = Matrix.identity_matrix() canvas.graphics_state.text_line_matrix = Matrix.identity_matrix() canvas._event_occurred(BeginTextEvent())
def test_matrix_determinant_002(self): # 0.453486 0.286607 0.803428 # 0.69059 0.877364 0.555546 # 0.00726739 0.0278032 0.421974 m0 = Matrix.identity_matrix() m0[0][0] = Decimal(0.453486) m0[0][1] = Decimal(0.286607) m0[0][2] = Decimal(0.803428) m0[1][0] = Decimal(0.69059) m0[1][1] = Decimal(0.877364) m0[1][2] = Decimal(0.555546) m0[2][0] = Decimal(0.00726739) m0[2][1] = Decimal(0.0278032) m0[2][2] = Decimal(0.421974) # print matrix print(m0) # calculate determinant det = m0.determinant() print(det) # test assert round(det, 10) == round(Decimal(0.08882747052120038238163180078), 10)
def test_matrix_determinant_001(self): m0 = Matrix.identity_matrix() # print matrix print(m0) # test assert m0.determinant() == Decimal(1)
def get_font_matrix(self) -> Matrix: """ Character glyphs in a font shall be defined in glyph space (see 9.2.4, "Glyph Positioning and Metrics"). The transformation from glyph space to text space shall be defined by the font matrix. For most types of fonts, this matrix shall be predefined to map 1000 units of glyph space to 1 unit of text space; for Type 3 fonts, the font matrix shall be given explicitly in the font dictionary (see 9.6.5, "Type 3 Fonts"). """ return Matrix.identity_matrix()
def transform_by(self, matrix: Matrix) -> "LineSegment": """ This function transforms the start and end of this LineSegment by a given Matrix, it returns the transformed LineSegment """ p0 = matrix.cross(self.x0, self.y0, Decimal(1)) p1 = matrix.cross(self.x1, self.y1, Decimal(1)) return LineSegment(p0[0], p0[1], p1[0], p1[1])
def invoke(self, canvas: "Canvas", operands: List[AnyPDFType] = []): assert isinstance(operands[0], Decimal) assert isinstance(operands[1], Decimal) assert isinstance(operands[2], Decimal) assert isinstance(operands[3], Decimal) assert isinstance(operands[4], Decimal) assert isinstance(operands[5], Decimal) mtx = Matrix.matrix_from_six_values( operands[0], operands[1], operands[2], operands[3], operands[4], operands[5], ) canvas.graphics_state.ctm = mtx.mul(canvas.graphics_state.ctm)
def invoke(self, canvas: "Canvas", operands: List[AnyPDFType] = []): # type: ignore [name-defined] assert isinstance(operands[0], Decimal) assert isinstance(operands[1], Decimal) tx = operands[0] ty = operands[1] m = Matrix.identity_matrix() m[2][0] = tx m[2][1] = ty canvas.graphics_state.text_matrix = m.mul( canvas.graphics_state.text_line_matrix) canvas.graphics_state.text_line_matrix = copy.deepcopy( canvas.graphics_state.text_matrix)
def invoke(self, canvas: "Canvas", operands: List[AnyPDFType] = []): # type: ignore [name-defined] assert isinstance(operands[0], Decimal) assert isinstance(operands[1], Decimal) assert isinstance(operands[2], Decimal) assert isinstance(operands[3], Decimal) assert isinstance(operands[4], Decimal) assert isinstance(operands[5], Decimal) mtx = Matrix.matrix_from_six_values( operands[0], operands[1], operands[2], operands[3], operands[4], operands[5], ) canvas.graphics_state.text_matrix = mtx canvas.graphics_state.text_line_matrix = copy.deepcopy(mtx)
def invoke( self, canvas: "Canvas", operands: List[AnyPDFType] = [] ) -> None: # type: ignore [name-defined] """ Invoke the cm operator """ assert isinstance(operands[0], Decimal) assert isinstance(operands[1], Decimal) assert isinstance(operands[2], Decimal) assert isinstance(operands[3], Decimal) assert isinstance(operands[4], Decimal) assert isinstance(operands[5], Decimal) mtx = Matrix.matrix_from_six_values( operands[0], operands[1], operands[2], operands[3], operands[4], operands[5], ) canvas.graphics_state.ctm = mtx.mul(canvas.graphics_state.ctm)
def invoke(self, canvas: "Canvas", operands: List[AnyPDFType] = []): if not isinstance(operands[0], Decimal): raise PDFTypeError( expected_type=Decimal, received_type=operands[0].__class__ ) if not isinstance(operands[1], Decimal): raise PDFTypeError( expected_type=Decimal, received_type=operands[1].__class__ ) tx = operands[0] ty = operands[1] m = Matrix.identity_matrix() m[2][0] = tx m[2][1] = ty canvas.graphics_state.text_matrix = m.mul( canvas.graphics_state.text_line_matrix ) canvas.graphics_state.text_line_matrix = copy.deepcopy( canvas.graphics_state.text_matrix )
def get_font_matrix(self) -> Matrix: return Matrix.identity_matrix()
def transform_by(self, matrix: Matrix) -> "LineSegment": p0 = matrix.cross(self.x0, self.y0, Decimal(1)) p1 = matrix.cross(self.x1, self.y1, Decimal(1)) return LineSegment(p0[0], p0[1], p1[0], p1[1])
def invoke(self, canvas: "Canvas", operands: List[AnyPDFType] = []): canvas.graphics_state.text_matrix = Matrix.identity_matrix() canvas.graphics_state.text_line_matrix = Matrix.identity_matrix() canvas.event_occurred(BeginTextEvent())