Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions easyofd/draw/draw_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from reportlab.lib.pagesizes import A4
from reportlab.lib.utils import ImageReader
from reportlab.pdfgen import canvas

from reportlab.lib.units import mm
from easyofd.draw.font_tools import FontTool
from .find_seal_img import SealExtract

Expand All @@ -32,8 +32,8 @@ def __init__(self, data, *args, **kwargs):
assert data, "未输入ofd解析结果"
self.data = data
self.author = "renoyuan"
self.OP = 200 / 25.4
# self.OP = 1
#self.OP = 200 / 25.4
self.OP = 1*mm
self.pdf_uuid_name = self.data[0]["pdf_name"]
self.pdf_io = BytesIO()
self.SupportImgType = ("JPG", "JPEG", "PNG")
Expand Down Expand Up @@ -187,16 +187,12 @@ def draw_chars(self, canvas, text_list, fonts, page_size):
# print("Y",page_size[3])
# print("x",page_size[2])
# if line_dict.get("Glyphs_d") and FontFilePath.get(line_dict["font"]) and font_f not in FONTS:
if False: # 对于自定义字体 写入字形 drawPath 性能差暂时作废
Glyphs = [int(i) for i in line_dict.get("Glyphs_d").get("Glyphs").split(" ")]
for idx, Glyph_id in enumerate(Glyphs):
_cahr_x = float(x_list[idx]) * self.OP
_cahr_y = (float(page_size[3]) - (float(y_list[idx]))) * self.OP
imageFile = draw_Glyph(FontFilePath.get(line_dict["font"]), Glyph_id, text[idx])

# font_img_info.append((FontFilePath.get(line_dict["font"]), Glyph_id,text[idx],_cahr_x,_cahr_y,-line_dict["size"]*Op*2,line_dict["size"]*Op*2))
c.drawImage(imageFile, _cahr_x, _cahr_y, -line_dict["size"] * self.OP * 2,
line_dict["size"] * self.OP * 2)
if CTM:
#print(f"text: {text}, CTM_info:",CTM_info)
c.saveState()
c.transform(float(CTMS[0]), -1*float(CTMS[1]), -1*float(CTMS[2]), float(CTMS[3]), (pos[0]+float(CTMS[4]))*self.OP, (page_size[3]-pos[1]-float(CTMS[5]))*self.OP)
c.drawString(float(X)*self.OP, -float(Y)*self.OP, text)
c.restoreState()
else:
if len(text) > len(x_list) or len(text) > len(y_list):
text = re.sub("[^\u4e00-\u9fa5]", "", text)
Expand Down Expand Up @@ -551,8 +547,8 @@ def convert_coord(p_list, direction, page_size, pos):
for line in line_list:
path = canvas.beginPath()
Abbr = line.get("AbbreviatedData").split(" ") # AbbreviatedData
color = line.get("FillColor", [0, 0, 0])

#color = line.get("FillColor", [0, 0, 0])
color = line.get("StrokeColor", "").split(" ") #StrokeColor String
relu_list = match_mode(Abbr)
# TODO 组合 relu_list 1 M L 直线 2 M B*n 三次贝塞尔线 3 M Q*n 二次贝塞尔线

Expand Down Expand Up @@ -641,7 +637,8 @@ def draw_annotation(self, canvas, annota_info, images, page_size):
"""
img_list = []
for key, annotation in annota_info.items():
if annotation.get("AnnoType").get("type") == "Stamp":
#if annotation.get("AnnoType").get("type") == "Stamp":
if annotation.get("ImgageObject").get("ResourceID"):
pos = annotation.get("ImgageObject").get("Boundary","").split(" ")
pos = [float(i) for i in pos] if pos else []
wrap_pos = annotation.get("Appearance").get("Boundary","").split(" ")
Expand Down Expand Up @@ -697,15 +694,14 @@ def draw_pdf(self):
if img_list:
self.draw_img(c, img_list, images, page_size)

# 写入文本
if text_list:

self.draw_chars(c, text_list, fonts, page_size)

# 绘制线条
if line_list:
self.draw_line(c, line_list, page_size)

# 写入文本
if text_list:
self.draw_chars(c, text_list, fonts, page_size)

# 绘制签章
if signatures_page_id:
self.draw_signature(c, signatures_page_id.get(pg_no), page_size)
Expand Down
4 changes: 2 additions & 2 deletions easyofd/parser_ofd/file_signature_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class SignatureFileParser(FileParserBase):
签章信息
"""

def __call__(self, prefix=""):
def __call__(self, prefix="", StampAnnot_res_key="ofd:StampAnnot"):
info = {}
StampAnnot_res: list = []
StampAnnot_res_key = "ofd:StampAnnot"
#StampAnnot_res_key = "ofd:StampAnnot"

self.recursion_ext(self.xml_obj, StampAnnot_res, StampAnnot_res_key)

Expand Down
3 changes: 3 additions & 0 deletions easyofd/parser_ofd/ofd_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ def parser(self, ):
# print(BaseLoc)
prefix = BaseLoc.split("/")[0]
signatures_info = SignatureFileParser(signature_xml_obj)(prefix=prefix)
if len(signatures_info)==0:
sign_key = list(signature_xml_obj.keys())[0]
signatures_info = SignatureFileParser(signature_xml_obj)(prefix=prefix, StampAnnot_res_key=sign_key)
# print(signatures_info)
logger.debug(f"signatures_info {signatures_info}")
PageRef = signatures_info.get("PageRef")
Expand Down