skip on missing font character error
This commit is contained in:
@@ -41,6 +41,8 @@ module Submissions
|
|||||||
|
|
||||||
composer = HexaPDF::Composer.new(skip_page_creation: true)
|
composer = HexaPDF::Composer.new(skip_page_creation: true)
|
||||||
composer.document.fonts.add(FONT_BOLD_NAME, variant: :bold)
|
composer.document.fonts.add(FONT_BOLD_NAME, variant: :bold)
|
||||||
|
composer.document.config['font.on_missing_glyph'] =
|
||||||
|
Submissions::GenerateResultAttachments.method(:on_missing_glyph).to_proc
|
||||||
|
|
||||||
divider = HexaPDF::Layout::Box.create(
|
divider = HexaPDF::Layout::Box.create(
|
||||||
margin: [0, 0, 15, 0],
|
margin: [0, 0, 15, 0],
|
||||||
@@ -245,7 +247,6 @@ module Submissions
|
|||||||
end
|
end
|
||||||
|
|
||||||
value = value.join(', ') if value.is_a?(Array)
|
value = value.join(', ') if value.is_a?(Array)
|
||||||
value = Submissions::GenerateResultAttachments::REPLACE_EMOJI[value] || value
|
|
||||||
|
|
||||||
composer.formatted_text_box([{ text: TextUtils.maybe_rtl_reverse(value.to_s.presence || 'n/a') }],
|
composer.formatted_text_box([{ text: TextUtils.maybe_rtl_reverse(value.to_s.presence || 'n/a') }],
|
||||||
text_align: value.to_s.match?(RTL_REGEXP) ? :right : :left,
|
text_align: value.to_s.match?(RTL_REGEXP) ? :right : :left,
|
||||||
|
|||||||
@@ -21,9 +21,18 @@ module Submissions
|
|||||||
A4_SIZE = [595, 842].freeze
|
A4_SIZE = [595, 842].freeze
|
||||||
SUPPORTED_IMAGE_TYPES = ['image/png', 'image/jpeg'].freeze
|
SUPPORTED_IMAGE_TYPES = ['image/png', 'image/jpeg'].freeze
|
||||||
|
|
||||||
REPLACE_EMOJI = {
|
MISSING_GLYPH_REPLACE = {
|
||||||
|
'▪' => '-',
|
||||||
'✔️' => 'V',
|
'✔️' => 'V',
|
||||||
'✔' => 'V'
|
'✔' => 'V',
|
||||||
|
'✅' => 'V'
|
||||||
|
}.freeze
|
||||||
|
|
||||||
|
MISSING_GLYPH_REPLACE_TYPE1 = {
|
||||||
|
'▪' => :bullet,
|
||||||
|
'✔️' => :V,
|
||||||
|
'✔' => :V,
|
||||||
|
'✅' => :V
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
@@ -181,7 +190,6 @@ module Submissions
|
|||||||
end
|
end
|
||||||
|
|
||||||
value = TextUtils.maybe_rtl_reverse(Array.wrap(value).join(', '))
|
value = TextUtils.maybe_rtl_reverse(Array.wrap(value).join(', '))
|
||||||
value = REPLACE_EMOJI[value] || value
|
|
||||||
|
|
||||||
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,10 +326,25 @@ module Submissions
|
|||||||
Rollbar.error(e) if defined?(Rollbar)
|
Rollbar.error(e) if defined?(Rollbar)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
pdf.config['font.on_missing_glyph'] = method(:on_missing_glyph).to_proc
|
||||||
|
|
||||||
[attachment.metadata['original_uuid'] || attachment.uuid, pdf]
|
[attachment.metadata['original_uuid'] || attachment.uuid, pdf]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def on_missing_glyph(character, font_wrapper)
|
||||||
|
Rollbar.error("Missing glyph: #{character}") if character.present? && defined?(Rollbar)
|
||||||
|
|
||||||
|
replace_with =
|
||||||
|
if font_wrapper.font_type == :Type1
|
||||||
|
MISSING_GLYPH_REPLACE_TYPE1[character] || :space
|
||||||
|
else
|
||||||
|
(MISSING_GLYPH_REPLACE[character] || ' ').bytes.first - 29
|
||||||
|
end
|
||||||
|
|
||||||
|
font_wrapper.custom_glyph(replace_with, character)
|
||||||
|
end
|
||||||
|
|
||||||
def find_last_submitter(submitter)
|
def find_last_submitter(submitter)
|
||||||
submitter.submission.submitters
|
submitter.submission.submitters
|
||||||
.select(&:completed_at?)
|
.select(&:completed_at?)
|
||||||
|
|||||||
Reference in New Issue
Block a user