Skip to content

Commit

Permalink
droplet:0.1.0 (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicEricEE authored Dec 10, 2023
1 parent f90de1e commit 12bd286
Show file tree
Hide file tree
Showing 9 changed files with 1,371 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/preview/droplet/0.1.0/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2023 Eric Biedert

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
72 changes: 72 additions & 0 deletions packages/preview/droplet/0.1.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# droplet
A package for creating dropped capitals in typst.

## Usage
The package comes with a single `dropcap` function that takes content and a few optional parameters. The first letter of the content will be shown as a dropped capital, while the rest of the content will be wrapped around it. The parameters are as follows:

| Parameter | Description | Default |
|------------------|----------------------------------------------------------|---------|
| `height` | The height of the dropped capital in lines or as length. | `2` |
| `justify` | Whether the text should be justified. | `false` |
| `gap` | The space between the first letter and the text. | `0pt` |
| `hanging-indent` | The indent of lines after the first. | `0pt` |
| `transform` | A function to be applied to the first letter. | `none` |
| `..text-args` | Arguments to be passed to the text function. | `(:)` |

> [!NOTE]
> Show and set rules applied inside the content passed to the `dropcap` function do not work!
```typ
#import "@preview/droplet:0.1.0": dropcap
#dropcap(
height: 3,
justify: true,
gap: 4pt,
hanging-indent: 1em,
font: "Curlz MT",
)[
*Typst* is a new markup-based typesetting system that is designed to be as
_powerful_ as LaTeX while being _much easier_ to learn and use. Typst has:
- Built-in markup for the most common formatting tasks
- Flexible functions for everything else
- A tightly integrated scripting system
- Math typesetting, bibliography management, and more
- Fast compile times thanks to incremental compilation
- Friendly error messages in case something goes wrong
]
```

![Result of example code.](assets/example.svg)

## Extended Customization
To further customize the appearance of the dropped capital, you can apply a `transform` function, which takes the first letter as a string and returns the content to be shown. The font size of the letter is then scaled so that the height of the transformed content matches the given height.

```typ
#import "@preview/droplet:0.1.0": dropcap
#dropcap(
height: 2,
justify: true,
gap: 6pt,
transform: letter => style(styles => {
let height = measure(letter, styles).height
grid(columns: 2, gutter: 6pt,
align(center + horizon, text(blue, letter)),
// Use "place" to ignore the line's height when
// the font size is calculated later on.
place(horizon, line(
angle: 90deg,
length: height + 6pt,
stroke: blue.lighten(40%) + 1pt
)),
)
}),
lorem(21)
)
```

![Result of example code.](assets/example-transform.svg)
239 changes: 239 additions & 0 deletions packages/preview/droplet/0.1.0/assets/example-transform.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions packages/preview/droplet/0.1.0/assets/example-transform.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#import "../src/lib.typ": dropcap

#set text(size: 14pt)
#set page(
width: 8cm,
height: auto,
margin: 1em,
background: box(
width: 100%,
height: 100%,
radius: 4pt,
fill: white,
),
)

#dropcap(
height: 2,
justify: true,
gap: 6pt,
transform: letter => style(styles => {
let height = measure(letter, styles).height

grid(columns: 2, gutter: 6pt,
align(center + horizon, text(blue, letter)),
// Use "place" to ignore the line's height when
// the font size is calculated later on.
place(horizon, line(
angle: 90deg,
length: height + 6pt,
stroke: blue.lighten(40%) + 1pt
)),
)
}),
lorem(21)
)
Loading

0 comments on commit 12bd286

Please sign in to comment.