cells align

pull/414/head
Pete Matsyburka 11 months ago
parent 5340af0bc6
commit 29fbdfbe2f

@ -168,6 +168,7 @@
<div <div
v-else-if="field.type === 'cells'" v-else-if="field.type === 'cells'"
class="w-full flex items-center" class="w-full flex items-center"
:class="{ 'justify-end': field.preferences?.align === 'right' }"
> >
<div <div
v-for="(char, index) in modelValue" v-for="(char, index) in modelValue"

@ -27,7 +27,7 @@
</label> </label>
</div> </div>
<div <div
v-if="['number'].includes(field.type)" v-if="['number', 'cells'].includes(field.type)"
class="py-1.5 px-1 relative" class="py-1.5 px-1 relative"
@click.stop @click.stop
> >
@ -36,7 +36,7 @@
@change="[field.preferences ||= {}, field.preferences.align = $event.target.value, save()]" @change="[field.preferences ||= {}, field.preferences.align = $event.target.value, save()]"
> >
<option <option
v-for="value in ['left', 'right', 'center']" v-for="value in ['left', 'right', field.type === 'cells' ? null : 'center'].filter(Boolean)"
:key="value" :key="value"
:selected="field.preferences?.align ? value === field.preferences.align : value === 'left'" :selected="field.preferences?.align ? value === field.preferences.align : value === 'left'"
:value="value" :value="value"

@ -50,7 +50,7 @@
<% end %> <% end %>
<% elsif field['type'] == 'cells' && area['cell_w'].to_f > 0.0 %> <% elsif field['type'] == 'cells' && area['cell_w'].to_f > 0.0 %>
<% cell_width = area['cell_w'] / area['w'] * 100 %> <% cell_width = area['cell_w'] / area['w'] * 100 %>
<div class="w-full flex items-center"> <div class="w-full flex items-center <%= 'justify-end' if align == 'right' %>">
<% (0..(area['w'] / area['cell_w']).ceil).each do |index| %> <% (0..(area['w'] / area['cell_w']).ceil).each do |index| %>
<% if value[index] %> <% if value[index] %>
<div class="text-center flex-none" style="width: <%= cell_width %>%;"><%= value[index] %></div> <div class="text-center flex-none" style="width: <%= cell_width %>%;"><%= value[index] %></div>

@ -382,7 +382,10 @@ module Submissions
when ->(type) { type == 'cells' && !area['cell_w'].to_f.zero? } when ->(type) { type == 'cells' && !area['cell_w'].to_f.zero? }
cell_width = area['cell_w'] * width cell_width = area['cell_w'] * width
TextUtils.maybe_rtl_reverse(value).chars.each_with_index do |char, index| chars = TextUtils.maybe_rtl_reverse(value).chars
chars = chars.reverse if field.dig('preferences', 'align') == 'right'
chars.each_with_index do |char, index|
next if char.blank? next if char.blank?
text = HexaPDF::Layout::TextFragment.create(char, font:, text = HexaPDF::Layout::TextFragment.create(char, font:,
@ -409,9 +412,15 @@ module Submissions
line_height = layouter.fit([text], cell_width, height).lines.first.height line_height = layouter.fit([text], cell_width, height).lines.first.height
end end
x =
if field.dig('preferences', 'align') == 'right'
((area['x'] + area['w']) * width) - (cell_width * (index + 1))
else
(area['x'] * width) + (cell_width * index)
end
cell_layouter.fit([text], cell_width, [line_height, area['h'] * height].max) cell_layouter.fit([text], cell_width, [line_height, area['h'] * height].max)
.draw(canvas, ((area['x'] * width) + (cell_width * index)), .draw(canvas, x, height - (area['y'] * height))
height - (area['y'] * height))
end end
else else
if field['type'] == 'date' if field['type'] == 'date'

Loading…
Cancel
Save