text utils for RTL
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
<style>
|
<style>
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body dir="<%= yield&.match?(/[\p{Hebrew}\p{Arabic}]/) ? 'rtl' : 'auto' %>">
|
<body dir="<%= yield&.match?(TextUtils::RTL_REGEXP) ? 'rtl' : 'auto' %>">
|
||||||
<%= yield %>
|
<%= yield %>
|
||||||
<%= render partial: 'shared/mailer_attribution' %>
|
<%= render partial: 'shared/mailer_attribution' %>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
Rails.application.config.filter_parameters += %i[password token otp_attempt passw secret token _key crypt salt
|
Rails.application.config.filter_parameters += %i[password token otp_attempt passw secret token _key crypt salt
|
||||||
certificate otp ssn]
|
certificate otp ssn file]
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ module Submissions
|
|||||||
'GBP' => '£'
|
'GBP' => '£'
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
RTL_REGEXP = Submissions::GenerateResultAttachments::RTL_REGEXP
|
RTL_REGEXP = TextUtils::RTL_REGEXP
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
@@ -149,7 +149,7 @@ module Submissions
|
|||||||
[
|
[
|
||||||
submission.template_submitters.size > 1 && { text: "#{item['name']}\n" },
|
submission.template_submitters.size > 1 && { text: "#{item['name']}\n" },
|
||||||
submitter.email && { text: "#{submitter.email}\n", font: [FONT_BOLD_NAME, { variant: :bold }] },
|
submitter.email && { text: "#{submitter.email}\n", font: [FONT_BOLD_NAME, { variant: :bold }] },
|
||||||
submitter.name && { text: "#{maybe_rtl_reverse(submitter.name)}\n" },
|
submitter.name && { text: "#{TextUtils.maybe_rtl_reverse(submitter.name)}\n" },
|
||||||
submitter.phone && { text: "#{submitter.phone}\n" }
|
submitter.phone && { text: "#{submitter.phone}\n" }
|
||||||
].compact_blank, line_spacing: 1.8, padding: [0, 20, 0, 0]
|
].compact_blank, line_spacing: 1.8, padding: [0, 20, 0, 0]
|
||||||
)
|
)
|
||||||
@@ -187,7 +187,7 @@ module Submissions
|
|||||||
composer.formatted_text_box(
|
composer.formatted_text_box(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
text: maybe_rtl_reverse(field['name'].to_s).upcase.presence ||
|
text: TextUtils.maybe_rtl_reverse(field['name'].to_s).upcase.presence ||
|
||||||
"#{field['type']} Field #{submitter_field_counters[field['type']]}\n".upcase,
|
"#{field['type']} Field #{submitter_field_counters[field['type']]}\n".upcase,
|
||||||
font_size: 6
|
font_size: 6
|
||||||
}
|
}
|
||||||
@@ -237,7 +237,7 @@ module Submissions
|
|||||||
|
|
||||||
value = value.join(', ') if value.is_a?(Array)
|
value = value.join(', ') if value.is_a?(Array)
|
||||||
|
|
||||||
composer.formatted_text_box([{ text: maybe_rtl_reverse(value.to_s.presence || 'n/a') }],
|
composer.formatted_text_box([{ text: TextUtils.maybe_rtl_reverse(value.to_s.presence || 'n/a') }],
|
||||||
align: value.to_s.match?(RTL_REGEXP) ? :right : :left,
|
align: value.to_s.match?(RTL_REGEXP) ? :right : :left,
|
||||||
padding: [0, 0, 10, 0])
|
padding: [0, 0, 10, 0])
|
||||||
end
|
end
|
||||||
@@ -298,16 +298,6 @@ module Submissions
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def maybe_rtl_reverse(text)
|
|
||||||
if text.match?(RTL_REGEXP)
|
|
||||||
TwitterCldr::Shared::Bidi
|
|
||||||
.from_string(ArabicLetterConnector.transform(text), direction: :RTL)
|
|
||||||
.reorder_visually!.to_s
|
|
||||||
else
|
|
||||||
text
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def add_logo(column, _submission = nil)
|
def add_logo(column, _submission = nil)
|
||||||
column.image(PdfIcons.logo_io, width: 40, height: 40, position: :float)
|
column.image(PdfIcons.logo_io, width: 40, height: 40, position: :float)
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ module Submissions
|
|||||||
SIGN_REASON = 'Signed by %<name>s with DocuSeal.co'
|
SIGN_REASON = 'Signed by %<name>s with DocuSeal.co'
|
||||||
SIGN_SIGNLE_REASON = 'Digitally signed with DocuSeal.co'
|
SIGN_SIGNLE_REASON = 'Digitally signed with DocuSeal.co'
|
||||||
|
|
||||||
RTL_REGEXP = /[\p{Hebrew}\p{Arabic}]/
|
RTL_REGEXP = TextUtils::RTL_REGEXP
|
||||||
|
|
||||||
TEXT_LEFT_MARGIN = 1
|
TEXT_LEFT_MARGIN = 1
|
||||||
TEXT_TOP_MARGIN = 1
|
TEXT_TOP_MARGIN = 1
|
||||||
@@ -159,7 +159,7 @@ module Submissions
|
|||||||
when 'cells'
|
when 'cells'
|
||||||
cell_width = area['cell_w'] * width
|
cell_width = area['cell_w'] * width
|
||||||
|
|
||||||
maybe_rtl_reverse(value).chars.each_with_index do |char, index|
|
TextUtils.maybe_rtl_reverse(value).chars.each_with_index do |char, index|
|
||||||
text = HexaPDF::Layout::TextFragment.create(char, font: pdf.fonts.add(FONT_NAME),
|
text = HexaPDF::Layout::TextFragment.create(char, font: pdf.fonts.add(FONT_NAME),
|
||||||
font_size:)
|
font_size:)
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ module Submissions
|
|||||||
value = TimeUtils.format_date_string(value, field.dig('preferences', 'format'), account.locale)
|
value = TimeUtils.format_date_string(value, field.dig('preferences', 'format'), account.locale)
|
||||||
end
|
end
|
||||||
|
|
||||||
value = maybe_rtl_reverse(Array.wrap(value).join(', '))
|
value = TextUtils.maybe_rtl_reverse(Array.wrap(value).join(', '))
|
||||||
|
|
||||||
text = HexaPDF::Layout::TextFragment.create(value, font: pdf.fonts.add(FONT_NAME),
|
text = HexaPDF::Layout::TextFragment.create(value, font: pdf.fonts.add(FONT_NAME),
|
||||||
font_size:)
|
font_size:)
|
||||||
@@ -318,16 +318,6 @@ module Submissions
|
|||||||
pdf
|
pdf
|
||||||
end
|
end
|
||||||
|
|
||||||
def maybe_rtl_reverse(text)
|
|
||||||
if text.match?(RTL_REGEXP)
|
|
||||||
TwitterCldr::Shared::Bidi
|
|
||||||
.from_string(ArabicLetterConnector.transform(text), direction: :RTL)
|
|
||||||
.reorder_visually!.to_s
|
|
||||||
else
|
|
||||||
text
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def sign_reason(name)
|
def sign_reason(name)
|
||||||
format(SIGN_REASON, name:)
|
format(SIGN_REASON, name:)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module TextUtils
|
||||||
|
RTL_REGEXP = /[\p{Hebrew}\p{Arabic}]/
|
||||||
|
|
||||||
|
module_function
|
||||||
|
|
||||||
|
def maybe_rtl_reverse(text)
|
||||||
|
if text.match?(RTL_REGEXP)
|
||||||
|
TwitterCldr::Shared::Bidi
|
||||||
|
.from_string(ArabicLetterConnector.transform(text), direction: :RTL)
|
||||||
|
.reorder_visually!.to_s
|
||||||
|
else
|
||||||
|
text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user