stationery 0.12.2 → 0.12.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a56459cfc65f70dab12835ced22ff09d88d5c7a66b8ea045ccb0776f75da27b6
4
- data.tar.gz: 44889ebe589bed206a1b04940e6b24bad97f3be38f2b53179d8c98522c1ff7f0
3
+ metadata.gz: 43646ec58820f24924dfbcaaf0bdd8170d5251699f8a0e052560b03dde2d343a
4
+ data.tar.gz: 651b72e03ce4cd1d31cf713e729b58024bc9145fe7d3c31ea3732e87436771ae
5
5
  SHA512:
6
- metadata.gz: 7c2af80a6c317cff9cea03b5259c63d6a2bfa74730371713b490713fc0e8cb311d5b644d4a239ff49843f312cbdb20504dc9f363195df1af2784948f5af0250a
7
- data.tar.gz: 2591078b7e474565a8f35338dac311800f5c175576428756ba111fef71dc1e68e4b971efe86e7c64b6458c0b162087b1b32e75da6f4d703df735aee7dc45bafc
6
+ metadata.gz: daf443749aecd4818744fc05248a138b65b14226e318bf5877ff14618b34255b45f5ce1126562aee70722386f83544502bd8769edc5125809d3add8904003146
7
+ data.tar.gz: 72fc71f0732f1e9b202eb5a48cfedf47cf499808bb150dffb67a88f425e200f4bbd6b038aab2e89ab280e0cf9594b2d6e2045de85b27ef3e8c02eee332d4d15b
data/CHANGELOG.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - Text fields and selects take `font_size: :fit` (#218): the size `font_size: :auto` draws (one line, a `comb:` field's cells or a `multiline:` value, within `min_font_size:` and `max_font_size:`), written in `/DA` as that number instead of `0`, so a viewer that redraws the field keeps the size; Firefox's editable input, which showed `:auto` at 9 px, now shows the number, capped at the field's height ÷ 1.35 and set in the browser's own face. A longer value typed afterwards does not shrink, and an empty field is written at its largest size, so a field left empty to be filled in wants `:auto`. A field placed in several places writes its first widget's size. `Inspector#layout` and `stationery inspect` report the number. `text_field "price", value: "4 990 kr", font_size: :fit, max_font_size: 96, height: 110`. The price card example uses it. A field that does not is written as it was. `Forms::Field`, `Forms::Appearance`.
5
6
  - Text fields and selects take `align:`, `color:` and `font_size: :auto` (#216): `align:` (`:left`, `:center`, `:right`) is written as `/Q`, `color:` (any colour the gem takes, black by default) as the colour operator of `/DA`, and `font_size: :auto` as `0 Tf`, within `min_font_size:` (4 by default) and `max_font_size:` (the field's height by default). The gem's own appearance aligns, colours and sizes the value the same way, so a field looks the same before and after a viewer redraws it: one line at the largest tenth of a point that fits the field's height and width, a `comb:` field's widest character in its cell, a `multiline:` value wrapped to the width and fitted to the height. `comb:` ignores `align:`. `text_field "price", value: "4 990 kr", align: :center, color: "#DC2626", font_size: :auto, height: 110`. A field that uses none of them is written as it was. Under `monochrome` a `color:` is checked like any other colour (`Warnings::NotMonochrome`, or black with `snap: true`); `Inspector#layout` and `stationery inspect` report a text field's or choice's `align:`, `font_size:` and `color:`. A price card example (`examples/price_card.rb`). `Forms::Field`, `Forms::Appearance`, `Forms::AutoSize`, `Testing::Layout`. **Behaviour change:** under PDF/A, a CMYK colour in a form field's appearance or `/DA` is reported as `Warnings::ConformanceIssue` (`CMYK colour in form field "price"`), its `border:` and `background:` included, which were not checked before.
6
7
  - The skill (`stationery skill install`) and the README it is written from are corrected (#209): the `max_pages` example renders before it reads `warnings`; a preview reads `params.fetch("id") { … }`, so its default is not looked up when `id` is given; the streamed-table example preloads what its rows read; the invoice recipe computes VAT with `Rational`, not Float, and says when a document may derive its totals; the report recipe escapes the chart labels it writes into SVG (`ERB::Util.html_escape`); the form recipe gives its fields a `tooltip:` and says a field without one is announced by its field name; the label recipe sizes a native QR code by the printer's dpi (a module of at most 720 / dpi points) and says what a barcode left in the picture loses. Statements that overstated are qualified: `encrypt` under a conformance level raises `ArgumentError`, not `ConformanceError`; `NeedAppearances` is left out under a conformance level or a signature; what the untrusted-input guarantees cover; and what a B-T timestamp proves once the certificate has expired. Run `stationery skill install` again to update an installed copy.
7
8
  - A tagged render is written with object streams (#206): its structure elements, and every other object that is not a stream, are packed 200 to a deflated `/Type /ObjStm`, with a cross-reference stream in place of the table and trailer (ISO 32000-1, 7.5.7 and 7.5.8). A table of 300 rows, 8 pages, is 115 KB tagged where it was 501 KB, 36 objects where it was 4,544; the tagged examples are 9 to 65% smaller. It is on by default for a render that is tagged (`tagged`, `to_pdf(tagged: true)`, `conformance :pdf_ua1`), and `object_streams false` at class level or `to_pdf(object_streams: false)` writes the classic table for a reader that cannot read object streams; `to_pdf(object_streams: true)` packs an untagged render too. Streams, the `/Encrypt` dictionary and a signature's dictionary stay out, so an encrypted, a signed and an incremental render are packed too, and PDF/A-2b, PDF/A-3b and PDF/UA-1 pass veraPDF packed. `to_png` and `to_zpl` refuse `object_streams:` as a PDF option. `Document#page_count` is how many pages the last render laid out, which `stationery render` now reports. In `PDF::Writer` (`object_streams:`, `add_unpacked`) and `PDF::ObjectStreams`.
data/README.md CHANGED
@@ -139,7 +139,7 @@ ls "$(bundle show stationery)/examples" # or: gem contents stationery
139
139
  | `keep_with_next: true \| points` | On `text`, `box` or `group`: never end a page with this node; with a number, keep at least that many points of what follows with it. |
140
140
  | `text_style(**style) { }` | Default text style for a block. |
141
141
  | `canvas(height:) { \|canvas, rect\| }` | Draw directly: rectangles, rounded rectangles, circles, lines, Bézier paths, clipping, images, links; `rotate(degrees, around:) { }` and `transform([a, b, c, d, e, f]) { }` blocks. |
142
- | `text_field(name, value:, width:, height:, multiline:, max_length:, comb:, read_only:, required:, font_size:, min_font_size:, max_font_size:, align:, color:, border:, background:, radius:, tooltip:, at:)` | An interactive text input (AcroForm). `width:` is `:full` or points; `font_size:` is points or `:auto`; `align:` is `:left`, `:center` or `:right`; dotted names (`"address.city"`) group fields. See [Forms](#forms). |
142
+ | `text_field(name, value:, width:, height:, multiline:, max_length:, comb:, read_only:, required:, font_size:, min_font_size:, max_font_size:, align:, color:, border:, background:, radius:, tooltip:, at:)` | An interactive text input (AcroForm). `width:` is `:full` or points; `font_size:` is points, `:auto` or `:fit`; `align:` is `:left`, `:center` or `:right`; dotted names (`"address.city"`) group fields. See [Forms](#forms). |
143
143
  | `checkbox(name, checked:, size:, label:, at:)` | An interactive check box, with an optional label drawn to its right. |
144
144
  | `radio(name, value, checked:, size:, label:, at:)` | One choice of a radio group: radios sharing `name` form one field whose value is the checked `value`. |
145
145
  | `select(name, options:, value:, width:, height:, editable:, font_size:, min_font_size:, max_font_size:, align:, color:, at:)` | A drop-down (combo box); `editable: true` also accepts typed values. |
@@ -418,8 +418,12 @@ signature_field "signature", label: "Signature of the applicant"
418
418
  `font_size: :auto` writes `0 Tf` and the appearance draws the largest size, in tenths of a point,
419
419
  at which one line fits the field's height and width (a `comb:` field's cells; a `multiline:`
420
420
  field wrapped to its width and height), within `min_font_size:` (4 by default) and
421
- `max_font_size:` (the height by default). A `comb:` field ignores `align:`, its cells place each
422
- character. Under `monochrome`, `color:` is checked like any other colour; under PDF/A a CMYK one
421
+ `max_font_size:` (the height by default). `font_size: :fit` sizes the value the same way and writes
422
+ the number it chose in `/DA`, so every viewer reads a size, where `0 Tf` showed 9 px in Firefox's
423
+ editable input (which still caps a size at the field's height ÷ 1.35 and sets it in its own face).
424
+ A longer value typed afterwards does not shrink, and an empty field is sized to its bound, so a
425
+ field left empty to be filled in wants `:auto`. `min_font_size:` and `max_font_size:` go with
426
+ either. A `comb:` field ignores `align:`, its cells place each character. Under `monochrome`, `color:` is checked like any other colour; under PDF/A a CMYK one
423
427
  is reported. A field that uses none of them is written as it was.
424
428
  - A radio group's value is its checked choice's `value` (`Off` when none is checked); a select box
425
429
  lists its `options:` and draws the chosen `value`; a signature field is left unsigned for the
@@ -1882,7 +1886,7 @@ own; lines read top to bottom, then left to right. An image is `{ x:, y:, width:
1882
1886
  [w, h] }` in the order drawn (the rectangle it fills, before any clip); a link has its `uri:`, or the
1883
1887
  `page:` and `top:` it goes to; a field has its full `name:`, `type:` (`:text`, `:choice`,
1884
1888
  `:checkbox`, `:radio`, `:button`, `:signature`), `value:`, for a button the `state:` that turns
1885
- it on, and for a text field or a choice the `align:`, `font_size:` (`:auto` for `0 Tf`) and `color:`
1889
+ it on, and for a text field or a choice the `align:`, `font_size:` (`:auto` for `0 Tf`, the number for `:fit`) and `color:`
1886
1890
  (`"#RRGGBB"`) its value is drawn in. `outline` is the bookmarks as `{ title:, page:, top:, children: }`. `metadata` leaves out the
1887
1891
  dates, which change with every render, so two renders of one document have the same layout.
1888
1892
  `warnings` are the render's messages when the subject is a document.
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # A shop-window price card a person fills in on screen and prints: the
4
- # product's name centred and shrunk to fit its line (`font_size: :auto`),
5
- # the price large, centred and red, the price per unit right-aligned in grey
6
- # and a select of units. The fields have no border and no background, so the
7
- # printed card shows the values alone; a viewer that redraws a field after
8
- # an edit keeps its alignment, colour and auto-size (/Q and /DA). Run it to
9
- # write examples/price_card.pdf:
4
+ # product's name centred and shrunk to fit its line, the price large,
5
+ # centred and red, the price per unit right-aligned in grey and a select of
6
+ # units. The name and price are fitted by the gem and the size it chose is
7
+ # written to the file (`font_size: :fit`), so every viewer shows them at
8
+ # that size. The fields have no border and no background, so the printed
9
+ # card shows the values alone; a viewer that redraws a field after an edit
10
+ # keeps its alignment, colour and size (/Q and /DA). Run it to write
11
+ # examples/price_card.pdf:
10
12
  #
11
13
  # ruby -Ilib examples/price_card.rb
12
14
  # ruby -Ilib exe/stationery render examples/price_card.rb
@@ -51,14 +53,14 @@ class ExamplePriceCard < Stationery::Document
51
53
  spacer 10
52
54
  label "Product"
53
55
  text_style(weight: :bold) do
54
- text_field "product", value: @product, height: 44, font_size: :auto, max_font_size: 32, align: :center,
56
+ text_field "product", value: @product, height: 44, font_size: :fit, max_font_size: 32, align: :center,
55
57
  tooltip: "Product", **BARE
56
58
  end
57
59
  rule height: 0.5, color: HAIRLINE
58
60
  spacer 10
59
61
  label "Price"
60
62
  text_style(weight: :bold) do
61
- text_field "price", value: @price, height: 150, font_size: :auto, max_font_size: 120, align: :center,
63
+ text_field "price", value: @price, height: 150, font_size: :fit, max_font_size: 120, align: :center,
62
64
  color: SALE, tooltip: "Price", **BARE
63
65
  end
64
66
  spacer 6
@@ -9,8 +9,8 @@ module Stationery
9
9
  module Elements
10
10
  # A text input. `width:` is :full or points; `multiline:`, `max_length:`,
11
11
  # `comb:` (a cell count, or true with max_length:), `read_only:`,
12
- # `required:`, `font_size:` (points, or :auto with `min_font_size:` and
13
- # `max_font_size:`), `align:` (:left, :center, :right), `color:`,
12
+ # `required:`, `font_size:` (points, or :auto or :fit with `min_font_size:`
13
+ # and `max_font_size:`), `align:` (:left, :center, :right), `color:`,
14
14
  # `border:`, `background:` and `radius:`.
15
15
  def text_field(name, value: "", width: :full, height: 22, at: nil, **)
16
16
  field_node(Forms::Field.new(:text, name, value: value.to_s, typeface: field_typeface, **), width:, height:, at:)
@@ -21,7 +21,7 @@ module Stationery
21
21
  SIGNATURE = { rule: 14, label_size: 7, label_baseline: 4, label_gray: 0.42 }.freeze
22
22
 
23
23
  # The size the value is drawn at: the field's, or what `font_size:
24
- # :auto` fits (see AutoSize).
24
+ # :auto` or `:fit` fits (see AutoSize).
25
25
  attr_reader :size
26
26
 
27
27
  # `resources` are the render's, where the field's fonts get their names.
@@ -30,7 +30,7 @@ module Stationery
30
30
  @width = width
31
31
  @height = height
32
32
  @type = field.typeface.with(resources)
33
- @size = field.auto_size? ? AutoSize.new(field, @type, width, height).size : field.font_size
33
+ @size = field.sized? ? AutoSize.new(field, @type, width, height).size : field.font_size
34
34
  @contents = contents
35
35
  keep
36
36
  end
@@ -41,8 +41,9 @@ module Stationery
41
41
  # The resource names of the fonts it draws with or keeps for editing.
42
42
  def font_names = @type.names
43
43
 
44
- # What the field's /DA says: the font, size (0 for auto) and colour a
45
- # viewer redraws the value with. nil for a field without variable text.
44
+ # What the field's /DA says: the font, size (0 for `:auto`, the fitted
45
+ # number for `:fit`) and colour a viewer redraws the value with. nil for
46
+ # a field without variable text.
46
47
  def default_appearance
47
48
  return unless @field.variable_text?
48
49
 
@@ -17,7 +17,7 @@ module Stationery
17
17
  DEFAULTS = { font_size: 10, read_only: false, required: false, border: "#9CA3AF", background: "#FFFFFF",
18
18
  radius: 2, tooltip: nil }.freeze
19
19
  # What a text field and a select take beyond the defaults: where the
20
- # value sits, its colour, and the bounds of `font_size: :auto`.
20
+ # value sits, its colour, and the bounds of `font_size: :auto` or `:fit`.
21
21
  BOUNDS = %i[min_font_size max_font_size].freeze
22
22
  STYLE = [:align, :color, *BOUNDS].freeze
23
23
  OPTIONS = {
@@ -55,6 +55,10 @@ module Stationery
55
55
  def font_size = @options[:font_size]
56
56
  # Whether the value is drawn at the largest size that fits (`font_size: :auto`).
57
57
  def auto_size? = font_size == :auto
58
+ # Whether it is the size `:auto` would draw, written as a number (`font_size: :fit`).
59
+ def fit? = font_size == :fit
60
+ # Whether the gem chooses the size the value is drawn at (`:auto` or `:fit`).
61
+ def sized? = auto_size? || fit?
58
62
  def min_font_size = @options[:min_font_size]
59
63
  def max_font_size = @options[:max_font_size]
60
64
  def align = @options.fetch(:align, :left)
@@ -150,10 +154,10 @@ module Stationery
150
154
  def validate_style
151
155
  raise ArgumentError, "align: is :left, :center or :right, not #{align.inspect}" unless ALIGNMENTS.key?(align)
152
156
 
153
- points(:font_size, " or :auto") unless auto_size?
157
+ points(:font_size, ", :auto or :fit") unless sized?
154
158
  BOUNDS.each do |key|
155
159
  next unless @options.key?(key)
156
- raise ArgumentError, "#{key}: needs font_size: :auto" unless auto_size?
160
+ raise ArgumentError, "#{key}: needs font_size: :auto or :fit" unless sized?
157
161
 
158
162
  points(key)
159
163
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stationery
4
- VERSION = "0.12.2"
4
+ VERSION = "0.12.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stationery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.2
4
+ version: 0.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson