gamba 4.3.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -1
- data/README.md +2 -1
- data/lib/gamba/native/layout.rb +34 -5
- data/lib/gamba/native/table.rb +13 -2
- data/lib/gamba/table/cell.rb +5 -2
- data/lib/gamba/tagging.rb +25 -5
- data/lib/gamba/text/formatted/box.rb +10 -1
- data/lib/gamba/text/formatted/fragment.rb +18 -1
- data/lib/gamba/text/formatted/wrap.rb +14 -0
- data/lib/gamba/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5cdf68ba5c1ba16c79c26ec86abf101ef7abfb49e6ed6b05e82a9406462162b0
|
|
4
|
+
data.tar.gz: 0cf6b671e29e63e73775ae37c4b8125c67dafe4c3dcbfe6f289d473ff180070f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 77f64a8055d9083d18436d99b774e41e19cdd290aa99d7d2fd0a8b1a66cc95d5e42daa91181c584e3cbb506991291322d1740c4c63e5044edd5710b98835a5c8
|
|
7
|
+
data.tar.gz: 6a368a15d0e61819588c97cce2d3ad881d20a2a30200ebc268995b8264f71a887fd29d334d160dc38454348a75e6146753e47588ca7f751c7045d188016c9dcd
|
data/CHANGELOG.md
CHANGED
|
@@ -2,12 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [4.4.0] — 2026-12-04
|
|
6
|
+
|
|
7
|
+
A tagged document reads aloud as it reads on the page: words apart at the end of a line, list markers as labels, totals under their row's header.
|
|
8
|
+
|
|
9
|
+
**New**
|
|
10
|
+
- `role: :list_label` tags a text directly inside a `role: :list_item` container as the item's label (`Lbl`), its bullet or number, the rest of the item going in its body (`LBody`). `numbering:` on a `role: :list` container (`:decimal`, `:lower_alpha`, `:upper_alpha`, `:lower_roman`, `:upper_roman`, `:disc`, `:circle`, `:square`, `:none`) says how its items are numbered (`ListNumbering`). A label elsewhere raises.
|
|
11
|
+
- A native table column takes `header: true`: in a tagged document, its cells are row headers (`TH`, scope `Row`), so a screen reader reads each value with its row's label, as "Total: 319.00".
|
|
12
|
+
|
|
13
|
+
**Changed**
|
|
14
|
+
- CI tests CRuby only, every maintained version: JRuby and `ruby-head` left it.
|
|
15
|
+
|
|
16
|
+
**Fixed**
|
|
17
|
+
- In a PDF/UA or PDF/A-3a document, the last word of a line and the first of the next were read as one ("theSite") where a text wrapped or broke on "\n": a space now ends such a line, past its last glyph, so pages draw as before. Untagged documents are unchanged.
|
|
18
|
+
|
|
5
19
|
## [4.3.0] — 2026-12-03
|
|
6
20
|
|
|
7
21
|
A list that runs over several pages keeps its title on each of them.
|
|
8
22
|
|
|
9
23
|
**New**
|
|
10
24
|
- `stack(header: true)` draws the stack's first box again at the top of each page the stack goes on to, as a table does its header row, with the stack's `gap` below it. The header goes to the next page with the start of what follows it; in a tagged document its copies are artifacts and its headings are bookmarked once. A header leaving no room under it raises `CannotFit`.
|
|
25
|
+
- A span's `link` is tagged in a PDF/UA or PDF/A-3a document, where it raised: its words are read as a link in their paragraph or cell, with the annotation that opens it, described by those words, and a link wrapped over several lines is one. A link in a header, a footer or a figure, and any other annotation, still raise.
|
|
11
26
|
|
|
12
27
|
## [4.2.0] — 2026-12-03
|
|
13
28
|
|
|
@@ -315,7 +330,8 @@ speed. Same API and same pages as Prawn, pixel for pixel, in lighter files.
|
|
|
315
330
|
place of combine_pdf.
|
|
316
331
|
- `Gamba::VERSION` is the gem's; `Prawn::VERSION` stays 2.5.0, the API reproduced.
|
|
317
332
|
|
|
318
|
-
[Unreleased]: https://github.com/levups/gamba/compare/v4.
|
|
333
|
+
[Unreleased]: https://github.com/levups/gamba/compare/v4.4.0...HEAD
|
|
334
|
+
[4.4.0]: https://github.com/levups/gamba/compare/v4.3.0...v4.4.0
|
|
319
335
|
[4.3.0]: https://github.com/levups/gamba/compare/v4.2.0...v4.3.0
|
|
320
336
|
[4.2.0]: https://github.com/levups/gamba/compare/v4.1.1...v4.2.0
|
|
321
337
|
[4.1.1]: https://github.com/levups/gamba/compare/v4.1.0...v4.1.1
|
data/README.md
CHANGED
|
@@ -157,7 +157,8 @@ of France's e-invoicing reform too; `Gamba::Invoice::RuleViolation` names each r
|
|
|
157
157
|
`BR-CO-25: an invoice with an amount due needs due_on or payment_terms`.
|
|
158
158
|
|
|
159
159
|
Tagged PDF for screen readers: `pdf: :ua` (PDF/UA-1) and `pdf_a: :a` (PDF/A-3a) tag the boxes of Gamba's own API
|
|
160
|
-
from their roles
|
|
160
|
+
from their roles (a list item's bullet or number is its `role: :list_label`, and `numbering: :decimal` says how a
|
|
161
|
+
`role: :list` counts), and raise where a rule is broken (a figure without `alt`, a list item outside a list; under `pdf: :ua`
|
|
161
162
|
also no `lang`, no title, a skipped heading level).
|
|
162
163
|
|
|
163
164
|
```ruby
|
data/lib/gamba/native/layout.rb
CHANGED
|
@@ -341,12 +341,14 @@ module Gamba
|
|
|
341
341
|
(role && role != self.class::DEFAULT_ROLE) ? "#{description} (role #{role.inspect})" : description
|
|
342
342
|
end
|
|
343
343
|
|
|
344
|
-
# Without a role, a box makes no element unless it says its language; a list item's content goes in its body
|
|
344
|
+
# Without a role, a box makes no element unless it says its language; a list item's content goes in its body,
|
|
345
|
+
# but for its label.
|
|
345
346
|
def tag(prawn, &)
|
|
346
347
|
return prawn.tag_artifact(&) if role == :artifact
|
|
347
348
|
return (lang ? prawn.tag_structure(:Div, Lang: lang, &) : yield) if role.nil?
|
|
349
|
+
return prawn.tag_list_label(Lang: lang) { tag_body(prawn, &) } if role == :list_label
|
|
348
350
|
|
|
349
|
-
prawn.tag_structure(STRUCTURE_TYPES.fetch(role), Alt: alt, Lang: lang) do
|
|
351
|
+
prawn.tag_structure(STRUCTURE_TYPES.fetch(role), Alt: alt, Lang: lang, A: list_attributes) do
|
|
350
352
|
next prawn.tag_structure(:LBody) { tag_body(prawn, &) } if role == :list_item
|
|
351
353
|
|
|
352
354
|
tag_body(prawn, &)
|
|
@@ -357,6 +359,10 @@ module Gamba
|
|
|
357
359
|
def tag_body(prawn, &)
|
|
358
360
|
prawn.tag_content(&)
|
|
359
361
|
end
|
|
362
|
+
|
|
363
|
+
# Only a list numbers its items.
|
|
364
|
+
def list_attributes
|
|
365
|
+
end
|
|
360
366
|
end
|
|
361
367
|
|
|
362
368
|
# A paragraph: its lines fill the page and the rest goes on to the next ones, never leaving fewer than
|
|
@@ -365,7 +371,7 @@ module Gamba
|
|
|
365
371
|
DEFAULT_WIDOWS = 2
|
|
366
372
|
DEFAULT_ORPHANS = 2
|
|
367
373
|
HEADINGS = %i[h1 h2 h3 h4 h5 h6].freeze
|
|
368
|
-
ROLES = (%i[p] + HEADINGS + %i[list_item artifact]).freeze
|
|
374
|
+
ROLES = (%i[p] + HEADINGS + %i[list_item list_label artifact]).freeze
|
|
369
375
|
DEFAULT_ROLE = :p
|
|
370
376
|
KIND = "a text"
|
|
371
377
|
|
|
@@ -1163,7 +1169,7 @@ module Gamba
|
|
|
1163
1169
|
class Container < Node
|
|
1164
1170
|
include Builder
|
|
1165
1171
|
|
|
1166
|
-
OPTIONS = (Node::OPTIONS + %i[height min_height valign gap padding background border_width border_color radius]).freeze
|
|
1172
|
+
OPTIONS = (Node::OPTIONS + %i[height min_height valign gap padding background border_width border_color radius numbering]).freeze
|
|
1167
1173
|
DEFAULT_BORDER_COLOR = "000000"
|
|
1168
1174
|
# The share of the room left by the content that goes above it, by vertical alignment.
|
|
1169
1175
|
VERTICAL_SHARES = {top: 0, center: 0.5, bottom: 1}.freeze
|
|
@@ -1171,9 +1177,17 @@ module Gamba
|
|
|
1171
1177
|
# Without a role, a container only groups its children.
|
|
1172
1178
|
ROLES = %i[list list_item figure artifact].freeze
|
|
1173
1179
|
KIND = "a container"
|
|
1180
|
+
# The ListNumbering of a list's labels (ISO 32000-1 §14.8.5.5, Table 347): what an ordered list numbers its
|
|
1181
|
+
# items with, or the bullet of an unordered one.
|
|
1182
|
+
LIST_NUMBERINGS = {
|
|
1183
|
+
decimal: :Decimal, upper_roman: :UpperRoman, lower_roman: :LowerRoman, upper_alpha: :UpperAlpha, lower_alpha: :LowerAlpha,
|
|
1184
|
+
disc: :Disc, circle: :Circle, square: :Square, none: :None
|
|
1185
|
+
}.freeze
|
|
1174
1186
|
|
|
1175
|
-
def initialize(styles, height: nil, min_height: nil, valign: :top, gap: 0, padding: 0, background: nil, border_width: nil, border_color: nil, radius: nil,
|
|
1187
|
+
def initialize(styles, height: nil, min_height: nil, valign: :top, gap: 0, padding: 0, background: nil, border_width: nil, border_color: nil, radius: nil,
|
|
1188
|
+
numbering: nil, **)
|
|
1176
1189
|
super(**)
|
|
1190
|
+
check_numbering(numbering)
|
|
1177
1191
|
raise ArgumentError, "height is #{height.inspect}: give a height in points, above 0" if height && !(height.is_a?(Numeric) && height.finite? && height.positive?)
|
|
1178
1192
|
raise ArgumentError, "min_height is #{min_height.inspect}: give a height in points, above 0" if min_height && !(min_height.is_a?(Numeric) && min_height.finite? && min_height.positive?)
|
|
1179
1193
|
raise ArgumentError, "height and min_height exclude each other: a box keeps its height, or grows past its least one" if height && min_height
|
|
@@ -1196,6 +1210,7 @@ module Gamba
|
|
|
1196
1210
|
@border_width = border_width || (0.5 if border_color)
|
|
1197
1211
|
@border_color = border_color || DEFAULT_BORDER_COLOR
|
|
1198
1212
|
@radius = radius
|
|
1213
|
+
@numbering = numbering
|
|
1199
1214
|
@children = []
|
|
1200
1215
|
end
|
|
1201
1216
|
|
|
@@ -1269,6 +1284,20 @@ module Gamba
|
|
|
1269
1284
|
yield
|
|
1270
1285
|
end
|
|
1271
1286
|
|
|
1287
|
+
def list_attributes
|
|
1288
|
+
{O: :List, ListNumbering: LIST_NUMBERINGS.fetch(@numbering)} if @numbering
|
|
1289
|
+
end
|
|
1290
|
+
|
|
1291
|
+
def check_numbering(numbering)
|
|
1292
|
+
return if numbering.nil?
|
|
1293
|
+
|
|
1294
|
+
numberings = LIST_NUMBERINGS.keys
|
|
1295
|
+
unless numberings.include?(numbering)
|
|
1296
|
+
raise ArgumentError, "numbering is #{numbering.inspect}#{Gamba::Suggestion.for(numbering, numberings)}: accepted numberings are #{numberings.map(&:inspect).join(", ")}"
|
|
1297
|
+
end
|
|
1298
|
+
raise ArgumentError, "numbering says how a list numbers its items: give it with role: :list, not #{role.inspect}" unless role == :list
|
|
1299
|
+
end
|
|
1300
|
+
|
|
1272
1301
|
def inner_width(width)
|
|
1273
1302
|
width - @padding_left - @padding_right
|
|
1274
1303
|
end
|
data/lib/gamba/native/table.rb
CHANGED
|
@@ -6,7 +6,7 @@ module Gamba
|
|
|
6
6
|
# flows it. Prawn's table lays it out and draws it.
|
|
7
7
|
class Table < Node
|
|
8
8
|
OPTIONS = (Node::OPTIONS + %i[columns header stripes cell]).freeze
|
|
9
|
-
COLUMN_OPTIONS = %i[title width min_width align weight italic size color].freeze
|
|
9
|
+
COLUMN_OPTIONS = %i[title width min_width align weight italic size color header].freeze
|
|
10
10
|
HEADER_OPTIONS = %i[align weight italic size color background].freeze
|
|
11
11
|
CELL_OPTIONS = %i[padding size font color background borders border_width border_color hyphenate].freeze
|
|
12
12
|
DEFAULT_HEADER = {weight: :bold}.freeze
|
|
@@ -106,6 +106,8 @@ module Gamba
|
|
|
106
106
|
Styles.check_options(options, COLUMN_OPTIONS)
|
|
107
107
|
Styles.check_cell(options)
|
|
108
108
|
check_column_width(name, options)
|
|
109
|
+
header = options[:header]
|
|
110
|
+
raise ArgumentError, "column #{name.inspect}: header is #{header.inspect}: give true for a column that heads its rows" unless header.nil? || header == true || header == false
|
|
109
111
|
end
|
|
110
112
|
raise ArgumentError, "a table needs at least one column" if columns.empty?
|
|
111
113
|
|
|
@@ -183,6 +185,7 @@ module Gamba
|
|
|
183
185
|
prawn.make_table(data, options) do |table|
|
|
184
186
|
table.cells.each { |cell| cell.automatic_fallback! if cell.is_a?(Prawn::Table::Cell::Text) }
|
|
185
187
|
style_columns(table)
|
|
188
|
+
mark_row_headers(table)
|
|
186
189
|
style(table.row(0), @header) if @header
|
|
187
190
|
@styling&.call(table)
|
|
188
191
|
check_faces(table)
|
|
@@ -246,7 +249,15 @@ module Gamba
|
|
|
246
249
|
end
|
|
247
250
|
|
|
248
251
|
def style_columns(table)
|
|
249
|
-
@columns.each_value.with_index { |options, index| style(table.column(index), options.except(:title, :width, :min_width)) }
|
|
252
|
+
@columns.each_value.with_index { |options, index| style(table.column(index), options.except(:title, :width, :min_width, :header)) }
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
# A tagged document reads the cells of a header: true column as their rows' headers; its title stays the
|
|
256
|
+
# header of its column (Prawn::Table#mark_header_cells).
|
|
257
|
+
def mark_row_headers(table)
|
|
258
|
+
@columns.each_value.with_index do |options, index|
|
|
259
|
+
table.column(index).each { |cell| cell.tag_role = :row_header } if options[:header]
|
|
260
|
+
end
|
|
250
261
|
end
|
|
251
262
|
|
|
252
263
|
def style(cells, options)
|
data/lib/gamba/table/cell.rb
CHANGED
|
@@ -28,11 +28,14 @@ module Gamba
|
|
|
28
28
|
# Extra width given to a cell's content box, so text measured to fit exactly is not wrapped.
|
|
29
29
|
FPTolerance = 1 # rubocop:disable Naming/ConstantName -- Prawn::Table's public name
|
|
30
30
|
SIDE_INDEX = {top: 0, right: 1, bottom: 2, left: 3}.freeze
|
|
31
|
+
# What the header cell of each tag role heads, as a TH element's Scope says it (ISO 32000-1 §14.8.5.7).
|
|
32
|
+
HEADER_SCOPES = {header: :Column, row_header: :Row}.freeze
|
|
31
33
|
|
|
32
34
|
attr_reader :padding, :colspan, :rowspan, :dummy_cells, :border_widths, :border_colors, :border_lines
|
|
33
35
|
attr_writer :height
|
|
34
36
|
attr_accessor :borders, :content, :background_color
|
|
35
|
-
# In a tagged document, :header for a cell of the table header, :repeated for its copy atop a later page
|
|
37
|
+
# In a tagged document, :header for a cell of the table header, :repeated for its copy atop a later page,
|
|
38
|
+
# :row_header for a cell of a column that heads its rows.
|
|
36
39
|
attr_writer :tag_role
|
|
37
40
|
# Set by Gamba's own tables: a text cell is measured in the font it is drawn in. prawn-table measures it in the
|
|
38
41
|
# document's, and Prawn's tables keep that.
|
|
@@ -100,7 +103,7 @@ module Gamba
|
|
|
100
103
|
return @pdf.tag_artifact(&) if @tag_role == :repeated
|
|
101
104
|
return yield unless respond_to?(:row)
|
|
102
105
|
|
|
103
|
-
@pdf.tag_table_cell(row,
|
|
106
|
+
@pdf.tag_table_cell(row, scope: HEADER_SCOPES[@tag_role], colspan:, rowspan:, &)
|
|
104
107
|
end
|
|
105
108
|
|
|
106
109
|
def initialize(pdf, point, options = {})
|
data/lib/gamba/tagging.rb
CHANGED
|
@@ -115,18 +115,19 @@ module Gamba
|
|
|
115
115
|
end
|
|
116
116
|
end
|
|
117
117
|
|
|
118
|
-
# A cell of the table element being drawn, in the row element of its row index: a header cell for
|
|
119
|
-
# or a data cell. In a figure, the cell is part of it; outside a table element,
|
|
120
|
-
|
|
118
|
+
# A cell of the table element being drawn, in the row element of its row index: a header cell for the :Column
|
|
119
|
+
# or the :Row its scope says, or a data cell. In a figure, the cell is part of it; outside a table element,
|
|
120
|
+
# nothing is made.
|
|
121
|
+
def tag_table_cell(row, scope:, colspan:, rowspan:, &)
|
|
121
122
|
return yield unless tagging_structure?
|
|
122
123
|
return tag_content(&) if @tagging.last.whole?
|
|
123
124
|
return yield unless (table = @tagging.last).type == :Table
|
|
124
125
|
|
|
125
126
|
attributes = {}
|
|
126
|
-
attributes[:Scope] =
|
|
127
|
+
attributes[:Scope] = scope if scope
|
|
127
128
|
attributes[:ColSpan] = colspan if colspan > 1
|
|
128
129
|
attributes[:RowSpan] = rowspan if rowspan > 1
|
|
129
|
-
cell = Tagging::Element.new(
|
|
130
|
+
cell = Tagging::Element.new(scope ? :TH : :TD, table.row(row), attributes.empty? ? {} : {A: {O: :Table, **attributes}})
|
|
130
131
|
within_element(cell) { within_mark(Tagging::Mark.new(cell), &) }
|
|
131
132
|
end
|
|
132
133
|
|
|
@@ -138,6 +139,25 @@ module Gamba
|
|
|
138
139
|
within_mark(Tagging::Mark.new(@tagging.last), &)
|
|
139
140
|
end
|
|
140
141
|
|
|
142
|
+
# What the block draws is the label of the list item being drawn, its bullet or its number: an Lbl element of
|
|
143
|
+
# the item, beside the body that holds the rest of its content (ISO 32000-1 §14.8.4.3.3).
|
|
144
|
+
def tag_list_label(**attributes, &)
|
|
145
|
+
return yield unless tagging_structure? && !@tagging.last.whole?
|
|
146
|
+
|
|
147
|
+
body = @tagging[-1]
|
|
148
|
+
item = @tagging[-2]
|
|
149
|
+
unless body.type == :LBody && item&.type == :LI
|
|
150
|
+
raise tagging_violation, "#{tagging_standard} reads a list label as the label of its list item: give role: :list_label to a " \
|
|
151
|
+
"text directly in a box of role: :list_item"
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
label = Tagging::Element.new(:Lbl, nil, attributes.compact)
|
|
155
|
+
item.kids.insert(item.kids.index(body), label)
|
|
156
|
+
within_element(label, &)
|
|
157
|
+
ensure
|
|
158
|
+
item.kids.delete(label) if label&.kids&.empty?
|
|
159
|
+
end
|
|
160
|
+
|
|
141
161
|
# What the block draws only decorates the page, as a header or a footer of type :Pagination and subtype
|
|
142
162
|
# :Header or :Footer: readers skip it. Elements and content within it are neither made nor marked.
|
|
143
163
|
def tag_artifact(type = nil, subtype = nil, &)
|
|
@@ -170,12 +170,21 @@ module Gamba
|
|
|
170
170
|
if @draw_text_callback
|
|
171
171
|
@draw_text_callback.call(fragment.text, at: [x, y], kerning: @kerning)
|
|
172
172
|
else
|
|
173
|
-
@document.draw_text!(fragment
|
|
173
|
+
@document.draw_text!(text_with_word_break(fragment), at: [x, y], kerning: @kerning)
|
|
174
174
|
end
|
|
175
175
|
end
|
|
176
176
|
draw_fragment_overlays(fragment)
|
|
177
177
|
end
|
|
178
178
|
|
|
179
|
+
# A space past the end of the line, where it paints nothing, for the line's last word and the next one's to
|
|
180
|
+
# read apart. A font without a space glyph would draw .notdef there, which PDF/UA forbids: its words stay
|
|
181
|
+
# joined.
|
|
182
|
+
def text_with_word_break(fragment)
|
|
183
|
+
return fragment.text unless fragment.word_break_after? && @document.font.glyph_present?(" ")
|
|
184
|
+
|
|
185
|
+
fragment.text + " "
|
|
186
|
+
end
|
|
187
|
+
|
|
179
188
|
def with_text_settings(&)
|
|
180
189
|
@document.save_font do
|
|
181
190
|
@document.character_spacing(@character_spacing) do
|
|
@@ -6,8 +6,10 @@ module Gamba
|
|
|
6
6
|
module Formatted
|
|
7
7
|
# A run of text sharing one format on one line, with its measurements and, once drawn, its position.
|
|
8
8
|
class Fragment
|
|
9
|
+
TRAILING_WHITE_SPACE = /[ \t]\z/
|
|
10
|
+
|
|
9
11
|
attr_reader :format_state, :text
|
|
10
|
-
attr_writer :width
|
|
12
|
+
attr_writer :width, :word_break_after
|
|
11
13
|
attr_accessor :line_height, :descender, :ascender, :word_spacing, :left, :baseline
|
|
12
14
|
|
|
13
15
|
def initialize(text, format_state, document)
|
|
@@ -113,6 +115,21 @@ module Gamba
|
|
|
113
115
|
@text.count(" ")
|
|
114
116
|
end
|
|
115
117
|
|
|
118
|
+
# Whether its line wraps after this fragment between two words, which the text a tagged PDF reads must
|
|
119
|
+
# separate with a space (ISO 32000-1 §14.8.2.5).
|
|
120
|
+
def word_break_after?
|
|
121
|
+
@word_break_after == true
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def trailing_white_space?
|
|
125
|
+
@original_text.match?(TRAILING_WHITE_SPACE)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# White space at its end is drawn: its line breaks on a newline after it, not on that white space.
|
|
129
|
+
def trailing_white_space_drawn?
|
|
130
|
+
!@format_state[:exclude_trailing_white_space] && trailing_white_space?
|
|
131
|
+
end
|
|
132
|
+
|
|
116
133
|
def callback_objects
|
|
117
134
|
callback = @format_state[:callback]
|
|
118
135
|
callback.nil? ? [] : Array(callback)
|
|
@@ -35,10 +35,12 @@ module Gamba
|
|
|
35
35
|
printed_fragments = []
|
|
36
36
|
fragments_this_line = []
|
|
37
37
|
word_spacing = word_spacing_for_this_line
|
|
38
|
+
newline = false
|
|
38
39
|
@arranger.fragments.each do |fragment|
|
|
39
40
|
fragment.word_spacing = word_spacing
|
|
40
41
|
if fragment.text == "\n"
|
|
41
42
|
printed_fragments << "\n" if @printed_lines.last == ""
|
|
43
|
+
newline = true
|
|
42
44
|
break
|
|
43
45
|
end
|
|
44
46
|
printed_fragments << fragment.text
|
|
@@ -48,7 +50,9 @@ module Gamba
|
|
|
48
50
|
|
|
49
51
|
accumulated_width = 0
|
|
50
52
|
drawn_fragments = []
|
|
53
|
+
word_break = @document.tagged? && line_ends_between_words?(fragments_this_line.last, newline)
|
|
51
54
|
fragments_this_line.reverse! if @direction == :rtl
|
|
55
|
+
fragments_this_line.last.word_break_after = true if word_break
|
|
52
56
|
fragments_this_line.each do |fragment|
|
|
53
57
|
fragment.default_direction = @direction
|
|
54
58
|
drawn_fragment = [fragment, accumulated_width, @line_wrap.width, word_spacing]
|
|
@@ -60,6 +64,16 @@ module Gamba
|
|
|
60
64
|
@printed_lines << printed_fragments.map { _1.dup.force_encoding(::Encoding::UTF_8) }.join
|
|
61
65
|
end
|
|
62
66
|
|
|
67
|
+
NEXT_LINE_AFTER_A_WORD_BREAK = /\A[ \t\n]/
|
|
68
|
+
|
|
69
|
+
# A line breaks between two words on a newline or on the white space wrapping dropped, its own or the
|
|
70
|
+
# next line's; not within a word, at a hyphen or a long word's character, nor when the text ends.
|
|
71
|
+
def line_ends_between_words?(last_fragment, newline)
|
|
72
|
+
return false if last_fragment.nil? || last_fragment.trailing_white_space_drawn? || @arranger.finished?
|
|
73
|
+
|
|
74
|
+
newline || last_fragment.trailing_white_space? || @arranger.preview_next_string.match?(NEXT_LINE_AFTER_A_WORD_BREAK)
|
|
75
|
+
end
|
|
76
|
+
|
|
63
77
|
def word_spacing_for_this_line
|
|
64
78
|
return 0 unless @align == :justify && @line_wrap.space_count.positive? && !@line_wrap.paragraph_finished?
|
|
65
79
|
|
data/lib/gamba/version.rb
CHANGED