Skip to content

Commit

Permalink
Merge pull request #109 from Omikhleia/fix-dropcap-styling
Browse files Browse the repository at this point in the history
Fix dropcap styling
  • Loading branch information
Omikhleia authored Dec 21, 2024
2 parents 17ba03d + 2e5ef06 commit e44ea88
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
17 changes: 13 additions & 4 deletions classes/resilient/book.lua
Original file line number Diff line number Diff line change
Expand Up @@ -688,11 +688,20 @@ function class:registerCommands ()
local letter = content[1]

local dropcapSty = self.styles:resolveStyle(style)
local family = dropcapSty.font and dropcapSty.font.family
local lines = dropcapSty.special and dropcapSty.special.lines

SILE.call("use", { module = "packages.dropcaps" })
SILE.call("dropcap", { family = family, lines = lines, join = join }, { letter })
if not lines then
-- Fallback to regular style
SILE.call('style:apply', { name = style }, { letter })
else
local color = dropcapSty.color
local family = dropcapSty.font and dropcapSty.font.family
if dropcapSty.properties or dropcapSty.decoration then
-- I am not convinced the extra complexity is worth it for such an edge case.
SU.warn("Dropcap style does not support properties and decoration")
end
SILE.call("use", { module = "packages.dropcaps" })
SILE.call("dropcap", { family = family, lines = lines, join = join, color = color }, { letter })
end
end, "Style-aware initial capital letter (normally and internal command)")

self:registerCommand("initial-joined", function (options, content)
Expand Down
29 changes: 29 additions & 0 deletions examples/manual-styling/advanced/dropcap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Styling initial capitals

Initial capitals (also known as drop caps) are a typographic feature where the first letter of a paragraph is enlarged and styled differently from the rest of the text.
The **resilient.book** class defines two commands for this purpose: `initial-joined` and `initial-unjoined`.
The former should be used when the initial capital is part of the first word of the paragraph, and the latter when it is a separate character.

In Markdown or Djot, you may use one or the other directly as a style (although they are rather pseudo-styles, strictly speaking).

By default, these commands rely on the `dropcap` style, which is a regular character style with an additional `special` property that specifies the number of lines to drop.
The color and font family of the drop cap can be customized as well, but other properties from character styles are ignored.
For instance, here is how a drop cap style using the Zallman Caps font and a somewhat "cerulean" color can be defined.

```yaml
dropcap:
style:
color: "#66a0b3"
font:
family: "Zallman Caps"
special:
lines: 3
```
Note that the style is supposed to be used on the initial letter of a paragraph.
The implementation does not make any attempt to enforce this, and the result may be unexpected if the style is applied to other characters.
Likewise, you are on your own if you want to style subsequent characters in a certain way --- such as using small capitals for a word or a group of words, as is common in some typographic traditions. Here is a typical example of how to use the `initial-joined` style in a Markdown or Djot document.

```
[L]{custom-style=initial-joined}[orem ipsum]{.smallcaps} dolor sit amet...
```
1 change: 1 addition & 0 deletions examples/sile-resilient-manual.silm
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ parts:
- manual-styling/advanced/toclevels.md
- manual-styling/advanced/liststyles.md
- manual-styling/advanced/eqno.md
- manual-styling/advanced/dropcap.md
- manual-styling/advanced/other.md
# unfinished
# - manual-styling/captioned.md
Expand Down

0 comments on commit e44ea88

Please sign in to comment.