add strikethrough

This commit is contained in:
Pete Matsyburka
2025-09-26 20:52:44 +03:00
parent e0469b10a7
commit 9cc92b59b3
17 changed files with 311 additions and 58 deletions
+1 -1
View File
@@ -329,7 +329,7 @@ module Submissions
submitter_field_counters[field['type']] += 1
next if field['submitter_uuid'] != submitter.uuid
next if field['type'] == 'heading'
next if field['type'] == 'heading' || field['type'] == 'strikethrough'
next if !with_audit_values && !field['type'].in?(%w[signature initials])
next if skip_grouped_field_uuids[field['uuid']]
+45 -7
View File
@@ -206,15 +206,16 @@ module Submissions
submission = submitter.submission
return pdfs_index if submission.template_fields.blank?
with_headings = find_last_submitter(submission, submitter:).blank? if with_headings.nil?
locale = submitter.metadata.fetch('lang', account.locale)
submission.template_fields.each do |field|
next if field['type'] == 'heading' && !with_headings
next if field['submitter_uuid'] != submitter.uuid && field['type'] != 'heading'
(submission.template_fields || submission.template.fields).each do |field|
next if !with_headings &&
(field['type'] == 'heading' || (field['type'] == 'strikethrough' && field['conditions'].blank?))
next if field['submitter_uuid'] != submitter.uuid && field['type'] != 'heading' &&
(field['type'] != 'strikethrough' || field['conditions'].present?)
field.fetch('areas', []).each do |area|
pdf = pdfs_index[area['attachment_uuid']]
@@ -258,6 +259,7 @@ module Submissions
value = submitter.values[field['uuid']]
value = field['default_value'] if field['type'] == 'heading'
value = field['default_value'] if field['type'] == 'strikethrough' && value.nil? && field['conditions'].blank?
text_align = field.dig('preferences', 'align').to_s.to_sym.presence ||
(value.to_s.match?(RTL_REGEXP) ? :right : :left)
@@ -448,8 +450,7 @@ module Submissions
cv.image(PdfIcons.paperclip_io, at: [0, 0], width: box.content_width)
end
acc << HexaPDF::Layout::TextFragment.create("#{attachment.filename}\n", font:,
font_size:)
acc << HexaPDF::Layout::TextFragment.create("#{attachment.filename}\n", font:, font_size:)
end
lines = layouter.fit(items, area['w'] * width, height).lines
@@ -567,6 +568,43 @@ module Submissions
cell_layouter.fit([text], cell_width, [line_height, area['h'] * height].max)
.draw(canvas, x, height - (area['y'] * height))
end
when 'strikethrough'
scale = 1000.0 / width
line_width = 6.0 / scale
area_height = area['h'] * height
if area_height * scale < 40.0
canvas.tap do |c|
c.stroke_color(field.dig('preferences', 'color').presence || 'red')
c.line_width(line_width)
c.line(width * area['x'],
height - (height * area['y']) - (area_height / 2),
(width * area['x']) + (width * area['w']),
height - (height * area['y']) - (area_height / 2))
c.stroke
end
else
canvas.tap do |c|
c.stroke_color(field.dig('preferences', 'color').presence || 'red')
c.line_width(line_width)
c.line((width * area['x']) + (line_width / 2),
height - (height * area['y']) - (line_width / 2),
(width * area['x']) + (width * area['w']) - (line_width / 2),
height - (height * area['y']) - area_height + (line_width / 2))
c.stroke
end
canvas.tap do |c|
c.stroke_color(field.dig('preferences', 'color').presence || 'red')
c.line_width(line_width)
c.line((width * area['x']) + (line_width / 2),
height - (height * area['y']) - area_height + (line_width / 2),
(width * area['x']) + (width * area['w']) - (line_width / 2),
height - (height * area['y']) - (line_width / 2))
c.stroke
end
end
else
if field['type'] == 'date'
value = TimeUtils.format_date_string(value, field.dig('preferences', 'format'), locale)
+1 -1
View File
@@ -6,7 +6,7 @@ module Submitters
RequiredFieldError = Class.new(StandardError)
VARIABLE_REGEXP = /\{\{?(\w+)\}\}?/
NONEDITABLE_FIELD_TYPES = %w[stamp heading].freeze
NONEDITABLE_FIELD_TYPES = %w[stamp heading strikethrough].freeze
STRFTIME_MAP = {
'hour' => '%-k',