nbk2pdf 1.3.1 → 1.3.2

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: 9ccec0cdb3e5ca8a449dd015d8e720d3e198d6e9e531f49099930f2330aa3032
4
- data.tar.gz: daf75cccf961cd53bbca9556e77f29144fdd3e6ad8a639d350d03fb1a743d6f2
3
+ metadata.gz: cae6562263eb8906556769aad7b8ecb5b70e5f07a305c9898a3b7ddc192f306c
4
+ data.tar.gz: e3d9e7a6087eb7b70daf805150a1a1263aae18e9c67a01c0803596e67af09ccf
5
5
  SHA512:
6
- metadata.gz: 417d4e2d331a69dd88abfe57187a192f12fa9011f7ac016954ab9ca2bebd580d8e3bd2be92a21a0e0310bf3c34481a40e7a622cac52c679effab54ae68d41d98
7
- data.tar.gz: 130afb0068cc4cf40d04e139f9bea52ef2dc407690cabfd6eaae6e9e60db6ca2b26ca5473eb5ee8d265bbaa3afb9b29dda70cae269cd9d6f0f8aeb209761be58
6
+ metadata.gz: 337fb011c64b8ab1d163a037a9672dd4346adceace697819ac0ba6c03f79aa75732e7ed1d2f20fada82ee9c9c96e4ea506cdb410e23c81ce0648a2a3de951896
7
+ data.tar.gz: bc187d384008cb127fc42c5e7253e63f2d1e64769848723cb6a782fa5b76a532a1fdf486a574e81ca7cdc8adfca82edc125f9e267b877a0b38455f3e6296f2ee
data/CHANGELOG.md CHANGED
@@ -4,6 +4,20 @@ All notable changes to this project are documented here. The format follows
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
5
5
  adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [1.3.2] - 2026-11-05
8
+
9
+ ### Changed
10
+
11
+ - The ruled or squared background is drawn 20% thinner and lighter than
12
+ stored (`#A0A0A0`) instead of 50% (`#C4C4C4`), since the lines from 1.3.0
13
+ vanished on some printers.
14
+
15
+ ### Added
16
+
17
+ - `--template-fade PERCENT` sets how much thinner and lighter the background
18
+ is drawn: 0 draws it as stored, 50 as in 1.3.0. A fade other than the
19
+ default tags the file name, e.g. `NAME.fade50.pdf`.
20
+
7
21
  ## [1.3.1] - 2026-11-04
8
22
 
9
23
  ### Changed
data/README.md CHANGED
@@ -105,6 +105,7 @@ the same directory with different options keeps each output side by side:
105
105
  | `--flip-on-edge short` | `short-edge` |
106
106
  | `--paper SIZE`, other than `letter` | the size, e.g. `a4` |
107
107
  | `--no-template` | `no-template` |
108
+ | `--template-fade N`, other than 20 | `fadeN` |
108
109
  | `--no-page-numbers` | `no-page-numbers` |
109
110
  | `--annotations`, on documents only | `annotations` |
110
111
 
@@ -276,6 +277,7 @@ Options:
276
277
  --verbose With sync, report each source and its output in full
277
278
  -t, --titles FILE JSON/YAML map of notebook uuid to the name you gave it
278
279
  --[no-]template Draw the notebook's ruled background (default: yes)
280
+ --template-fade PERCENT Draw the background PERCENT thinner and lighter (default: 20)
279
281
  -p, --paper SIZE Page size: letter (default), a4, native, ...
280
282
  -2, --two-up Put notebook pages in pairs side by side on landscape paper
281
283
  -b, --booklet Lay notebook pages out to fold into a booklet
@@ -393,11 +395,11 @@ It can be:
393
395
 
394
396
  A template draws itself in its own 1860 x 2480 space with a flat op list --
395
397
  `0 x y` to move, `1 x y` to draw, `4` to close -- plus an ARGB colour and a line
396
- width. The converter scales that space onto the page. At the stored colour and
397
- width (`#888888`, 4 units) the lines print about as heavy as the ink, where the
398
- e-ink screen shows them faint, so they are drawn at half the width and halfway
399
- to white (`#C4C4C4`). `TEMPLATE_WIDTH` and `TEMPLATE_LIGHTEN` in
400
- `pdf_renderer.rb` set both.
398
+ width. The converter scales that space onto the page. `--template-fade PERCENT`
399
+ draws the lines that much thinner than stored and that far towards white. The
400
+ default, 20, turns the stored `#888888` at 4 units into `#A0A0A0` at 3.2. At 0
401
+ a grid prints about as heavy as the ink; at 50 (`#C4C4C4`, half the width) it
402
+ can vanish on a printer.
401
403
 
402
404
  ### 5. Rendering (`pdf_renderer.rb`)
403
405
 
@@ -53,7 +53,7 @@ module KindleNotebook
53
53
  @err = err
54
54
  @device = device
55
55
  @options = { template: true, quiet: false, annotations: false, two_up: false, page_numbers: true,
56
- revisions: true }
56
+ revisions: true, template_fade: PdfRenderer::TEMPLATE_FADE }
57
57
  end
58
58
 
59
59
  # Runs the command and returns the process exit status.
@@ -105,6 +105,12 @@ module KindleNotebook
105
105
  opts.on("--[no-]template", "Draw the notebook's ruled background (default: yes)") do |draw|
106
106
  options[:template] = draw
107
107
  end
108
+ opts.on("--template-fade PERCENT", Integer,
109
+ "Draw the background PERCENT thinner and lighter (default: #{PdfRenderer::TEMPLATE_FADE})") do |percent|
110
+ raise OptionParser::InvalidArgument, "--template-fade #{percent}" unless (0..100).cover?(percent)
111
+
112
+ options[:template_fade] = percent
113
+ end
108
114
  opts.on("-p", "--paper SIZE", "Page size: letter (default), a4, native, ...") do |size|
109
115
  options[:paper] = size
110
116
  end
@@ -272,7 +278,7 @@ module KindleNotebook
272
278
  end
273
279
 
274
280
  def converter
275
- @converter ||= Converter.new(titles: titles, render_template: options[:template],
281
+ @converter ||= Converter.new(titles: titles, template: template_fade,
276
282
  paper: PdfRenderer.paper(options[:paper]),
277
283
  annotations: options[:annotations],
278
284
  two_up: options[:two_up], page_numbers: options[:page_numbers],
@@ -280,6 +286,9 @@ module KindleNotebook
280
286
  variant: options)
281
287
  end
282
288
 
289
+ # The renderer's fade, or nil for no template.
290
+ def template_fade = (options[:template_fade] / 100.0 if options[:template])
291
+
283
292
  # Sync keeps its own, in its destination, unless told otherwise.
284
293
  def titles = @titles ||= Titles.load(options[:titles] || (File.join(@destination, TITLES_FILE) if @destination))
285
294
 
@@ -39,8 +39,7 @@ module KindleNotebook
39
39
  return options[:annotations] ? %w[annotations] : [] if document
40
40
 
41
41
  [*layout_tags(options), paper_tag(options[:paper]),
42
- ("no-template" if options[:template] == false),
43
- ("no-page-numbers" if options[:page_numbers] == false)].compact
42
+ template_tag(options), ("no-page-numbers" if options[:page_numbers] == false)].compact
44
43
  end
45
44
 
46
45
  def self.layout_tags(options)
@@ -50,8 +49,15 @@ module KindleNotebook
50
49
  ["booklet", ("sig#{booklet[:signature]}" if booklet[:signature]), ("short-edge" if booklet[:flip] == :short)]
51
50
  end
52
51
 
52
+ def self.template_tag(options)
53
+ return "no-template" if options[:template] == false
54
+
55
+ fade = options[:template_fade]
56
+ "fade#{fade}" if fade && fade != PdfRenderer::TEMPLATE_FADE
57
+ end
58
+
53
59
  def self.paper_tag(paper) = (paper.to_s.downcase if paper && PdfRenderer.paper(paper) != PdfRenderer.paper)
54
- private_class_method :layout_tags, :paper_tag
60
+ private_class_method :layout_tags, :template_tag, :paper_tag
55
61
 
56
62
  # Converts one notebook, or annotates one PDF. +output+ may be a file path
57
63
  # or a directory.
@@ -18,7 +18,7 @@ module KindleNotebook
18
18
 
19
19
  def initialize(annotations: false)
20
20
  @annotations = annotations
21
- @renderer = PdfRenderer.new(render_template: false, paper: nil)
21
+ @renderer = PdfRenderer.new(template: nil, paper: nil)
22
22
  @grains = {}
23
23
  end
24
24
 
@@ -24,7 +24,7 @@ module KindleNotebook
24
24
  SUPERSEDED = File.join(".nbk2pdf", "superseded")
25
25
 
26
26
  # The options that change what is rendered.
27
- RENDERING = %i[template paper annotations two_up page_numbers booklet revisions].freeze
27
+ RENDERING = %i[template template_fade paper annotations two_up page_numbers booklet revisions].freeze
28
28
 
29
29
  # ponytail: an unreadable manifest is treated as empty; the cost is one
30
30
  # full render, which rewrites it.
@@ -30,12 +30,10 @@ module KindleNotebook
30
30
  class PdfRenderer
31
31
  MIN_LINE_WIDTH = 0.15
32
32
 
33
- # A template's lines at the colour and width it stores come out about as
34
- # heavy as the ink on paper, where the e-ink screen shows them faint. They
35
- # are drawn this much thinner, and this far towards white: #888888 comes
36
- # out as #C4C4C4.
37
- TEMPLATE_WIDTH = 0.5
38
- TEMPLATE_LIGHTEN = 0.5
33
+ # Percent by which a template's lines are drawn thinner and lighter than
34
+ # stored. At 0 a grid prints about as heavy as the ink; at 50 it can
35
+ # vanish on a printer.
36
+ TEMPLATE_FADE = 20
39
37
 
40
38
  # The device paints the highlighter an opaque light grey and keeps the
41
39
  # darker of it and whatever is underneath, so overlapping bands stay one
@@ -88,9 +86,12 @@ module KindleNotebook
88
86
  # +two_up+ puts pages in pairs side by side on the paper turned landscape.
89
87
  # +page_numbers+ numbers each page. +booklet+, when given, is a
90
88
  # hash of the options PdfRenderer.booklet takes; it implies +two_up+.
91
- def initialize(render_template: true, paper: self.class.paper, two_up: false, page_numbers: true,
89
+ # +template+ is nil to leave the template out, or a fade from 0 to 1 that
90
+ # draws its lines that much thinner and that far towards white: 0 draws
91
+ # them as stored, 0.5 turns #888888 into #C4C4C4 at half the width.
92
+ def initialize(template: TEMPLATE_FADE / 100.0, paper: self.class.paper, two_up: false, page_numbers: true,
92
93
  booklet: nil)
93
- @render_template = render_template
94
+ @template_fade = template
94
95
  @paper = paper
95
96
  @two_up = two_up || !booklet.nil?
96
97
  @page_numbers = page_numbers
@@ -311,7 +312,7 @@ module KindleNotebook
311
312
  document.cap_style(:round)
312
313
  document.join_style(:round)
313
314
  fitted(document, page, box) do
314
- draw_template(document, page) if @render_template
315
+ draw_template(document, page) if @template_fade
315
316
  page.strokes.each { |stroke| @layers.around(document, stroke) { draw_stroke(document, page, stroke) } }
316
317
  end
317
318
  end
@@ -350,8 +351,8 @@ module KindleNotebook
350
351
 
351
352
  scale_x, scale_y = scale
352
353
  height = page.height_in_points
353
- document.stroke_color(Colour.hex(Colour.lighten(shape.color, TEMPLATE_LIGHTEN)))
354
- document.line_width([shape.width * scale_x * TEMPLATE_WIDTH, MIN_LINE_WIDTH].max)
354
+ document.stroke_color(Colour.hex(Colour.lighten(shape.color, @template_fade)))
355
+ document.line_width([shape.width * scale_x * (1 - @template_fade), MIN_LINE_WIDTH].max)
355
356
  with_alpha(document, alpha) do
356
357
  shape.segments.each do |segment|
357
358
  polyline(document, segment.map { |x, y| [x * scale_x, height - (y * scale_y)] })
@@ -3,7 +3,7 @@
3
3
  # frozen_string_literal: true
4
4
 
5
5
  module KindleNotebook
6
- VERSION = "1.3.1"
6
+ VERSION = "1.3.2"
7
7
 
8
8
  # The name this library is published and invoked under.
9
9
  PROGRAM = "nbk2pdf"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nbk2pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Avseyev