Skip to content

Commit 4a7b280

Browse files
committed
fix: set underline border style depending writing mode
1 parent 7305af6 commit 4a7b280

File tree

3 files changed

+37
-20
lines changed

3 files changed

+37
-20
lines changed

readium/navigator/src/main/assets/readium/scripts/readium-fixed.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readium/navigator/src/main/assets/readium/scripts/readium-reflowable.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readium/navigator/src/main/java/org/readium/r2/navigator/html/HtmlDecorationTemplate.kt

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,32 +131,49 @@ public data class HtmlDecorationTemplate(
131131
): HtmlDecorationTemplate {
132132
val className = createUniqueClassName(if (asHighlight) "highlight" else "underline")
133133
val padding = Padding(left = 1, right = 1)
134+
134135
return HtmlDecorationTemplate(
135136
layout = Layout.BOXES,
136137
element = { decoration ->
137138
val tint = (decoration.style as? Style.Tinted)?.tint ?: defaultTint
138139
val isActive = (decoration.style as? Style.Activable)?.isActive ?: false
139-
var css = ""
140-
if (asHighlight || isActive) {
141-
css += "background-color: ${tint.toCss(alpha = alpha)} !important;"
142-
}
143-
if (!asHighlight || isActive) {
144-
css += "border-bottom: ${lineWeight}px solid ${tint.toCss()};"
140+
buildString {
141+
if (asHighlight || isActive) {
142+
append("background-color: ${tint.toCss(alpha = alpha)} !important;")
143+
}
144+
if (!asHighlight || isActive) {
145+
append("--underline-color: ${tint.toCss()};")
146+
}
147+
}.let { css ->
148+
"""<div class="$className" style="$css"/>"""
145149
}
146-
"""
147-
<div class="$className" style="$css"/>"
148-
"""
149150
},
150151
stylesheet = """
151-
.$className {
152-
margin-left: ${-padding.left}px;
153-
padding-right: ${padding.left + padding.right}px;
154-
margin-top: ${-padding.top}px;
155-
padding-bottom: ${padding.top + padding.bottom}px;
156-
border-radius: ${cornerRadius}px;
157-
box-sizing: border-box;
158-
}
159-
"""
152+
.$className {
153+
margin: ${-padding.top}px ${-padding.left}px 0 0;
154+
padding: 0 ${padding.left + padding.right}px ${padding.top + padding.bottom}px 0;
155+
border-radius: ${cornerRadius}px;
156+
box-sizing: border-box;
157+
border: 0 solid var(--underline-color);
158+
}
159+
160+
/* Horizontal (default) */
161+
[data-writing-mode="horizontal-tb"].$className {
162+
border-bottom-width: ${lineWeight}px;
163+
}
164+
165+
/* Vertical right-to-left */
166+
[data-writing-mode="vertical-rl"].$className,
167+
[data-writing-mode="sideways-rl"].$className {
168+
border-left-width: ${lineWeight}px;
169+
}
170+
171+
/* Vertical left-to-right */
172+
[data-writing-mode="vertical-lr"].$className,
173+
[data-writing-mode="sideways-lr"].$className {
174+
border-right-width: ${lineWeight}px;
175+
}
176+
"""
160177
)
161178
}
162179

0 commit comments

Comments
 (0)