adjust signature size
This commit is contained in:
@@ -560,7 +560,7 @@ export default {
|
||||
return style
|
||||
},
|
||||
isNarrow () {
|
||||
return this.area.h > 0 && (this.area.w / this.area.h) > 6
|
||||
return this.area.h > 0 && ((this.area.w * this.pageWidth) / (this.area.h * this.pageHeight)) > 4.5
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<% font_size_px = (field.dig('preferences', 'font_size').presence || Submissions::GenerateResultAttachments::FONT_SIZE).to_i * local_assigns.fetch(:font_scale) { 1000.0 / PdfUtils::US_LETTER_W } %>
|
||||
<field-value dir="auto" class="flex absolute <%= 'font-courier' if font == 'Courier' %> <%= 'font-times' if font == 'Times' %> <%= 'font-bold' if font_type == 'bold' || font_type == 'bold_italic' %> <%= 'italic' if font_type == 'italic' || font_type == 'bold_italic' %> <%= align == 'right' ? 'text-right' : (align == 'center' ? 'text-center' : '') %>" style="<%= "color: #{color}; " if color.present? %><%= "background: #{bg_color}; " if bg_color.present? %>width: <%= area['w'] * 100 %>%; height: <%= area['h'] * 100 %>%; left: <%= area['x'] * 100 %>%; top: <%= area['y'] * 100 %>%; font-size: <%= fs = "clamp(1pt, #{font_size_px / 10}vw, #{font_size_px}px)" %>; line-height: calc(<%= fs %> * 1.3); font-size: <%= fs = "#{font_size_px / 10}cqmin" %>; line-height: calc(<%= fs %> * 1.3)">
|
||||
<% if field['type'] == 'signature' %>
|
||||
<% is_narrow = area['h']&.positive? && (area['w'].to_f / area['h']) > 6 %>
|
||||
<% is_narrow = area['h'].positive? && ((area['w'] * local_assigns[:page_width]).to_f / (area['h'] * local_assigns[:page_height])) > 4.5 %>
|
||||
<div class="flex justify-between w-full h-full gap-1 <%= is_narrow && (local_assigns[:with_signature_id] || field.dig('preferences', 'reason_field_uuid').present?) ? 'flex-row' : 'flex-col' %>">
|
||||
<div class="flex overflow-hidden <%= is_narrow && (local_assigns[:with_signature_id] || field.dig('preferences', 'reason_field_uuid').present?) ? 'w-1/2' : 'flex-grow' %>" style="min-height: 50%">
|
||||
<img class="object-contain mx-auto" src="<%= attachments_index[value].url %>">
|
||||
|
||||
@@ -333,12 +333,12 @@ module Submissions
|
||||
|
||||
result = nil
|
||||
|
||||
if area['h']&.positive? && (area['w'].to_f / area['h']) > 6
|
||||
area_x = area['x'] * width
|
||||
area_y = area['y'] * height
|
||||
area_w = area['w'] * width
|
||||
area_h = area['h'] * height
|
||||
area_x = area['x'] * width
|
||||
area_y = area['y'] * height
|
||||
area_w = area['w'] * width
|
||||
area_h = area['h'] * height
|
||||
|
||||
if area_h.positive? && (area_w.to_f / area_h) > 4.5
|
||||
half_width = area_w / 2.0
|
||||
scale = [half_width / image.width, area_h / image.height].min
|
||||
image_width = image.width * scale
|
||||
@@ -396,7 +396,7 @@ module Submissions
|
||||
font:,
|
||||
font_size: base_font_size)
|
||||
|
||||
result = layouter.fit([text], area['w'] * width, base_font_size / 0.65)
|
||||
result = layouter.fit([text], area_w, base_font_size / 0.65)
|
||||
|
||||
break if result.status == :success
|
||||
|
||||
@@ -405,30 +405,30 @@ module Submissions
|
||||
break if id_string.length < 8
|
||||
end
|
||||
|
||||
reason_result = layouter.fit([reason_text], area['w'] * width, height)
|
||||
reason_result = layouter.fit([reason_text], area_w, height)
|
||||
text_height = result.lines.sum(&:height) + reason_result.lines.sum(&:height)
|
||||
|
||||
image_height = (area['h'] * height) - text_height
|
||||
image_height = (area['h'] * height) / 2 if image_height < (area['h'] * height) / 2
|
||||
image_height = area_h - text_height
|
||||
image_height = area_h / 2 if image_height < area_h / 2
|
||||
|
||||
scale = [(area['w'] * width) / image.width, image_height / image.height].min
|
||||
scale = [area_w / image.width, image_height / image.height].min
|
||||
|
||||
io = StringIO.new(image.resize([scale * 4, 1].select(&:positive?).min).write_to_buffer('.png'))
|
||||
|
||||
layouter.fit([text], area['w'] * width, base_font_size / 0.65)
|
||||
.draw(canvas, (area['x'] * width) + TEXT_LEFT_MARGIN,
|
||||
height - (area['y'] * height) - TEXT_TOP_MARGIN - image_height)
|
||||
layouter.fit([text], area_w, base_font_size / 0.65)
|
||||
.draw(canvas, area_x + TEXT_LEFT_MARGIN,
|
||||
height - area_y - TEXT_TOP_MARGIN - image_height)
|
||||
|
||||
layouter.fit([reason_text], area['w'] * width, reason_result.lines.sum(&:height))
|
||||
.draw(canvas, (area['x'] * width) + TEXT_LEFT_MARGIN,
|
||||
height - (area['y'] * height) - TEXT_TOP_MARGIN -
|
||||
layouter.fit([reason_text], area_w, reason_result.lines.sum(&:height))
|
||||
.draw(canvas, area_x + TEXT_LEFT_MARGIN,
|
||||
height - area_y - TEXT_TOP_MARGIN -
|
||||
result.lines.sum(&:height) - image_height)
|
||||
|
||||
canvas.image(
|
||||
io,
|
||||
at: [
|
||||
(area['x'] * width) + (area['w'] * width / 2) - ((image.width * scale) / 2),
|
||||
height - (area['y'] * height) - (image.height * scale / 2) - (image_height / 2)
|
||||
area_x + (area_w / 2) - ((image.width * scale) / 2),
|
||||
height - area_y - (image.height * scale / 2) - (image_height / 2)
|
||||
],
|
||||
width: image.width * scale,
|
||||
height: image.height * scale
|
||||
|
||||
Reference in New Issue
Block a user