From 59971fe343873eea3f98d60a88d51571e1f0897b Mon Sep 17 00:00:00 2001 From: John Factotum <50942278+johnfactotum@users.noreply.github.com> Date: Tue, 14 Mar 2023 11:15:56 +0800 Subject: [PATCH] Fix underline in vertical writing mode Or rather, add the option to fix it. The actual fix is in the reader. --- overlayer.js | 14 +++++++++++--- view.js | 3 ++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/overlayer.js b/overlayer.js index 0787bd0..9a3baa2 100644 --- a/overlayer.js +++ b/overlayer.js @@ -50,11 +50,19 @@ export class Overlayer { return [] } static underline(rects, options = {}) { - // TODO: in vertical-rl, the bōsen (sideline) should be on the right - const { color = 'red', width: strokeWidth = 2 } = options + const { color = 'red', width: strokeWidth = 2, writingMode } = options const g = createSVGElement('g') g.setAttribute('fill', color) - for (const { left, bottom, width } of rects) { + if (writingMode === 'vertical-rl' || writingMode === 'vertical-lr') + for (const { right, top, height } of rects) { + const el = createSVGElement('rect') + el.setAttribute('x', right - strokeWidth) + el.setAttribute('y', top) + el.setAttribute('height', height) + el.setAttribute('width', strokeWidth) + g.append(el) + } + else for (const { left, bottom, width } of rects) { const el = createSVGElement('rect') el.setAttribute('x', left) el.setAttribute('y', bottom - strokeWidth) diff --git a/view.js b/view.js index 9fed796..431d286 100644 --- a/view.js +++ b/view.js @@ -188,7 +188,8 @@ export class View { overlayer.remove(value) if (!remove) { const range = doc ? anchor(doc) : anchor - const [func, opts] = this.emit({ type: 'draw-annotation', annotation }) + const [func, opts] = this + .emit({ type: 'draw-annotation', annotation, doc, range }) overlayer.add(value, range, func, opts) } }