asciidoctor-ldl 0.1.0 → 0.1.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 +4 -4
- data/CHANGELOG.md +26 -1
- data/README.adoc +42 -2
- data/lib/asciidoctor/ldl/extension.rb +10 -1
- data/lib/asciidoctor/ldl/js/ldl_render.mjs +16 -2
- data/lib/asciidoctor/ldl/renderer.rb +0 -0
- data/lib/asciidoctor/ldl/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: 20802d92a457bdb984de019c20d9d44f26a325c0c511704c2d574e5f201fa4c3
|
|
4
|
+
data.tar.gz: 2572f3ff4960d43f228854f35005877f5cd28e6f6f57c621746b8fa3750f905d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0cb60bae5692c098502337f8cc4aaec5c69ada73b6df5b9d5a614a32b3a0a4653e39b60e78ca03101f68bf45778c0a322aa4eb9299fa1726d943b43c34a8a5c8
|
|
7
|
+
data.tar.gz: a4b1228d7ce234a33fd7b18b48a54739791de5d2089736d70d5b84e184b8ccd355f7e9b34195824d1e177fdc4a353e49d6cc24254721df6a4b6a1c5ec2162020
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,29 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.1.2] - 2026-07-23
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `font-family` / `ldl-font-family` attribute controlling the font used for
|
|
14
|
+
diagram text, and a cross-platform default
|
|
15
|
+
(`DejaVu Sans, Bitstream Vera Sans, Liberation Sans, Arial, sans-serif`).
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- Gate/comparator glyphs `−` (U+2212) and `≥` (U+2265) no longer disappear in
|
|
20
|
+
asciidoctor-pdf. The renderer's generic `sans-serif` was mapped by prawn-svg
|
|
21
|
+
to the built-in Helvetica, which lacks those glyphs; the new default names
|
|
22
|
+
real fonts first (register one — e.g. DejaVu Sans — in your PDF theme).
|
|
23
|
+
|
|
24
|
+
## [0.1.1] - 2026-07-23
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- Pass the `pdfwidth` and `scaledwidth` image attributes through to the
|
|
29
|
+
generated image, so diagram size can be controlled in asciidoctor-pdf (and
|
|
30
|
+
`scaledwidth`/`width` elsewhere). Also forwards `window`, `opts` and `fit`.
|
|
31
|
+
|
|
9
32
|
## [0.1.0] - 2026-07-23
|
|
10
33
|
|
|
11
34
|
### Added
|
|
@@ -23,5 +46,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
23
46
|
- Content-addressed caching with a digest sidecar so unchanged diagrams are not
|
|
24
47
|
re-rendered.
|
|
25
48
|
|
|
26
|
-
[Unreleased]: https://github.com/OpenPowerShift/asciidoctor-ldl/compare/v0.1.
|
|
49
|
+
[Unreleased]: https://github.com/OpenPowerShift/asciidoctor-ldl/compare/v0.1.2...HEAD
|
|
50
|
+
[0.1.2]: https://github.com/OpenPowerShift/asciidoctor-ldl/compare/v0.1.1...v0.1.2
|
|
51
|
+
[0.1.1]: https://github.com/OpenPowerShift/asciidoctor-ldl/compare/v0.1.0...v0.1.1
|
|
27
52
|
[0.1.0]: https://github.com/OpenPowerShift/asciidoctor-ldl/releases/tag/v0.1.0
|
data/README.adoc
CHANGED
|
@@ -181,6 +181,13 @@ header or on the command line (`-a ldl-format=png`).
|
|
|
181
181
|
| `true`
|
|
182
182
|
| Draw `.Name`/`.Description` labels.
|
|
183
183
|
|
|
184
|
+
| font-family
|
|
185
|
+
| ldl-font-family
|
|
186
|
+
| _(see below)_
|
|
187
|
+
| Font family for diagram text. Defaults to a cross-platform stack
|
|
188
|
+
(`DejaVu Sans, Bitstream Vera Sans, Liberation Sans, Arial, sans-serif`). Set
|
|
189
|
+
to `sans-serif` (or `none`) to keep the renderer's plain generic family.
|
|
190
|
+
|
|
184
191
|
| target
|
|
185
192
|
| —
|
|
186
193
|
| _(hash)_
|
|
@@ -204,8 +211,18 @@ header or on the command line (`-a ldl-format=png`).
|
|
|
204
211
|
| Set to `false` to always re-render, ignoring the cache.
|
|
205
212
|
|===
|
|
206
213
|
|
|
207
|
-
Standard image attributes — `alt`, `title`, `width`, `height`, `
|
|
208
|
-
`float`, `id`, `link`, `role` — pass straight through to
|
|
214
|
+
Standard image attributes — `alt`, `title`, `width`, `height`, `pdfwidth`,
|
|
215
|
+
`scaledwidth`, `align`, `float`, `id`, `link`, `role` — pass straight through to
|
|
216
|
+
the generated image. To control the rendered size, use `width` for HTML and
|
|
217
|
+
`pdfwidth` (or `scaledwidth`) for `asciidoctor-pdf`, e.g.:
|
|
218
|
+
|
|
219
|
+
[source]
|
|
220
|
+
----
|
|
221
|
+
ldl::diagrams/trip.ldl[pdfwidth=80%]
|
|
222
|
+
----
|
|
223
|
+
|
|
224
|
+
Without a sizing attribute, a diagram renders at its intrinsic size and
|
|
225
|
+
`asciidoctor-pdf` scales an over-wide one down to the content width.
|
|
209
226
|
|
|
210
227
|
TIP: Most *diagram* styling (inversion bubbles vs NOT gates, input bars,
|
|
211
228
|
compactness, stroke width, margins, …) is authored in the LDL source itself with
|
|
@@ -251,6 +268,29 @@ For `asciidoctor-pdf`, prefer `svg`: it keeps PDFs small and crisp. If you must
|
|
|
251
268
|
raster for PDF, `png` with `scale=2` or higher gives good print quality at the
|
|
252
269
|
cost of size.
|
|
253
270
|
|
|
271
|
+
=== Fonts (asciidoctor-pdf)
|
|
272
|
+
|
|
273
|
+
Gate and comparator symbols use `−` (U+2212) and `≥` (U+2265). In
|
|
274
|
+
`asciidoctor-pdf`, `prawn-svg` maps the generic `sans-serif` family to the
|
|
275
|
+
built-in Helvetica, which lacks those glyphs — so by default this extension
|
|
276
|
+
names real fonts first (see `font-family` above). For them to take effect in a
|
|
277
|
+
PDF, *register a matching font in your theme* and it will be used automatically:
|
|
278
|
+
|
|
279
|
+
[source,yaml]
|
|
280
|
+
----
|
|
281
|
+
# in your -theme.yml (font files under a directory on :pdf-fontsdir:)
|
|
282
|
+
font:
|
|
283
|
+
catalog:
|
|
284
|
+
merge: true
|
|
285
|
+
DejaVu Sans:
|
|
286
|
+
normal: DejaVuSans.ttf
|
|
287
|
+
bold: DejaVuSans-Bold.ttf
|
|
288
|
+
italic: DejaVuSans-Oblique.ttf
|
|
289
|
+
bold_italic: DejaVuSans-BoldOblique.ttf
|
|
290
|
+
----
|
|
291
|
+
|
|
292
|
+
HTML and PNG output already resolve the glyphs without any setup.
|
|
293
|
+
|
|
254
294
|
== Styling with roles
|
|
255
295
|
|
|
256
296
|
Every generated image is tagged with roles so it can be targeted from CSS or an
|
|
@@ -35,6 +35,7 @@ module Asciidoctor
|
|
|
35
35
|
theme: attr(attrs, doc, 'theme', 'ldl-theme', 'light'),
|
|
36
36
|
show_ids: attr(attrs, doc, 'show-ids', 'ldl-show-ids', nil),
|
|
37
37
|
show_labels: attr(attrs, doc, 'show-labels', 'ldl-show-labels', nil),
|
|
38
|
+
font_family: attr(attrs, doc, 'font-family', 'ldl-font-family', nil),
|
|
38
39
|
node: doc.attr('ldl-node', 'node'),
|
|
39
40
|
package_dir: doc.attr('ldl-package-dir') || doc.attr('ldl-node-modules'),
|
|
40
41
|
out_dir: image_output_dir(doc),
|
|
@@ -78,9 +79,17 @@ module Asciidoctor
|
|
|
78
79
|
(images_dir && !images_dir.to_s.empty?) ? File.join(base, images_dir) : base
|
|
79
80
|
end
|
|
80
81
|
|
|
82
|
+
# Image attributes passed straight through to the generated image block.
|
|
83
|
+
# Includes the sizing attributes for every backend: +width+ (HTML),
|
|
84
|
+
# +pdfwidth+/+scaledwidth+ (asciidoctor-pdf).
|
|
85
|
+
IMAGE_PASSTHROUGH = %w[
|
|
86
|
+
alt title width height pdfwidth scaledwidth align float id link
|
|
87
|
+
window opts fit
|
|
88
|
+
].freeze
|
|
89
|
+
|
|
81
90
|
def create_ldl_image(parent, attrs, filename, renderer, _doc)
|
|
82
91
|
image_attrs = { 'target' => filename }
|
|
83
|
-
|
|
92
|
+
IMAGE_PASSTHROUGH.each do |key|
|
|
84
93
|
image_attrs[key] = attrs[key] if attrs.key?(key)
|
|
85
94
|
end
|
|
86
95
|
image_attrs['alt'] ||= (attrs['target'] || 'LDL logic diagram')
|
|
@@ -64,6 +64,7 @@ function parseArgs(argv) {
|
|
|
64
64
|
showLabels: true,
|
|
65
65
|
out: null,
|
|
66
66
|
packageDir: null,
|
|
67
|
+
fontFamily: null,
|
|
67
68
|
};
|
|
68
69
|
for (let i = 0; i < argv.length; i++) {
|
|
69
70
|
const arg = argv[i];
|
|
@@ -78,6 +79,7 @@ function parseArgs(argv) {
|
|
|
78
79
|
case '--no-show-labels': opts.showLabels = false; break;
|
|
79
80
|
case '--out': opts.out = next(); break;
|
|
80
81
|
case '--package-dir': opts.packageDir = next(); break;
|
|
82
|
+
case '--font-family': opts.fontFamily = next(); break;
|
|
81
83
|
default:
|
|
82
84
|
throw new Error(`unknown argument: ${arg}`);
|
|
83
85
|
}
|
|
@@ -150,6 +152,18 @@ function sizeFromViewBox(svg) {
|
|
|
150
152
|
return { width: parseFloat(m[1]), height: parseFloat(m[2]) };
|
|
151
153
|
}
|
|
152
154
|
|
|
155
|
+
// The renderer tags diagram text with font-family="sans-serif". Some consumers
|
|
156
|
+
// map that generic family to a glyph-poor built-in font (e.g. prawn-svg in
|
|
157
|
+
// asciidoctor-pdf uses Helvetica, which lacks − U+2212 and ≥ U+2265). Rewriting
|
|
158
|
+
// it to a named font that the consumer has registered fixes those glyphs.
|
|
159
|
+
function applyFontFamily(svg, family) {
|
|
160
|
+
if (!family) return svg;
|
|
161
|
+
const q = family.replace(/"/g, '"');
|
|
162
|
+
return svg
|
|
163
|
+
.replace(/font-family="sans-serif"/g, `font-family="${q}"`)
|
|
164
|
+
.replace(/font-family:\s*sans-serif/g, `font-family:${family}`);
|
|
165
|
+
}
|
|
166
|
+
|
|
153
167
|
function applySvgScale(svg, scale) {
|
|
154
168
|
const size = sizeFromViewBox(svg);
|
|
155
169
|
if (!size) return { svg, size };
|
|
@@ -184,7 +198,7 @@ async function main() {
|
|
|
184
198
|
renderOptions.showLabels = opts.showLabels;
|
|
185
199
|
const theme = opts.theme === 'dark' ? DARK_DIAGRAM : LIGHT_DIAGRAM;
|
|
186
200
|
|
|
187
|
-
let svg = renderDiagram(diagram, renderOptions, theme);
|
|
201
|
+
let svg = applyFontFamily(renderDiagram(diagram, renderOptions, theme), opts.fontFamily);
|
|
188
202
|
const scaled = applySvgScale(svg, opts.scale);
|
|
189
203
|
svg = scaled.svg;
|
|
190
204
|
const size = scaled.size || { width: 0, height: 0 };
|
|
@@ -201,7 +215,7 @@ async function main() {
|
|
|
201
215
|
const { Resvg } = await loadResvg(opts.packageDir);
|
|
202
216
|
// Rasterise from the *unscaled* viewBox using resvg's own zoom, so the scale
|
|
203
217
|
// multiplies device pixels crisply rather than baking a size into the SVG.
|
|
204
|
-
const base = renderDiagram(diagram, renderOptions, theme);
|
|
218
|
+
const base = applyFontFamily(renderDiagram(diagram, renderOptions, theme), opts.fontFamily);
|
|
205
219
|
const resvg = new Resvg(base, {
|
|
206
220
|
fitTo: { mode: 'zoom', value: opts.scale },
|
|
207
221
|
background: 'white',
|
|
Binary file
|