修复签章浮动靠左问题
This commit is contained in:
@@ -68,6 +68,8 @@ def sign_word(docx_data, params, log_source='前端操作', trace_id=None, clien
|
||||
global_rotate_min = params.get('rotate_min', 0)
|
||||
global_rotate_max = params.get('rotate_max', 0)
|
||||
relax_layout = params.get('relax_layout', True)
|
||||
signature_mode = params.get('signature_mode', 'inline') # 'inline' | 'anchor'
|
||||
stamp_mode = params.get('stamp_mode', 'anchor') # 'inline' | 'anchor'
|
||||
|
||||
if match_mode == 'auto':
|
||||
stamps = [s for s in stamps if (s.get('marker') or '').strip()]
|
||||
@@ -202,6 +204,8 @@ def sign_word(docx_data, params, log_source='前端操作', trace_id=None, clien
|
||||
continue
|
||||
|
||||
is_sig = stamp.get('is_signature', stamp_is_signature)
|
||||
# 按图片类型选模式:签名用 signature_mode,盖章用 stamp_mode
|
||||
image_mode = signature_mode if is_sig else stamp_mode
|
||||
h = _resolve_height(stamp, use_global_height, global_height)
|
||||
noise = _resolve_noise(stamp, use_global_noise, global_noise)
|
||||
rot_min, rot_max = _resolve_rotate(stamp, use_global_rotate, global_rotate_min, global_rotate_max)
|
||||
@@ -243,6 +247,7 @@ def sign_word(docx_data, params, log_source='前端操作', trace_id=None, clien
|
||||
inserted = _insert_signature_image(doc, marker, processed, s_align_h, s_align_v,
|
||||
height_cm=h,
|
||||
relax_layout=relax_layout,
|
||||
image_mode=image_mode,
|
||||
log_source=log_source, trace_id=trace_id)
|
||||
if inserted > 0:
|
||||
success_count += inserted
|
||||
@@ -283,7 +288,7 @@ def sign_word(docx_data, params, log_source='前端操作', trace_id=None, clien
|
||||
|
||||
|
||||
def _insert_signature_image(doc, marker, image_data, align_h, align_v, height_cm=None,
|
||||
relax_layout=True,
|
||||
relax_layout=True, image_mode='inline',
|
||||
log_source='前端操作', trace_id=None):
|
||||
"""插入签名图片到 marker 对应的 SET 域后。
|
||||
|
||||
@@ -293,6 +298,10 @@ def _insert_signature_image(doc, marker, image_data, align_h, align_v, height_cm
|
||||
|
||||
``relax_layout`` 透传给 :func:`field_codes.insert_image_after_field`,
|
||||
控制是否自动放宽段落 / 表格行的固定高度约束以避免签名被裁剪。
|
||||
|
||||
``image_mode`` 透传给 :func:`field_codes.insert_image_after_field`:
|
||||
``'inline'`` 嵌入式(默认,撑大当前行)或 ``'anchor'`` 浮动覆盖(不撑大,
|
||||
浮在文字上方)。
|
||||
"""
|
||||
with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as tmp:
|
||||
tmp.write(image_data)
|
||||
@@ -309,6 +318,7 @@ def _insert_signature_image(doc, marker, image_data, align_h, align_v, height_cm
|
||||
count = field_codes.insert_image_after_field(
|
||||
doc, marker, tmp_path, width_cm, height_cm,
|
||||
log_source=log_source, relax_layout=relax_layout,
|
||||
mode=image_mode,
|
||||
)
|
||||
return count
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user