Fix underline in vertical writing mode

Or rather, add the option to fix it. The actual fix is in the reader.
This commit is contained in:
John Factotum
2023-03-14 11:20:21 +08:00
parent f9ce32b913
commit 59971fe343
2 changed files with 13 additions and 4 deletions
+11 -3
View File
@@ -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)
+2 -1
View File
@@ -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)
}
}