Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cuti:0.3.0 #1318

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/preview/cuti/0.3.0/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
MIT License

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.
52 changes: 52 additions & 0 deletions packages/preview/cuti/0.3.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Cuti

Cuti (/kjuːti/) is a package that simulates fake bold / fake italic / fake small captials. This package is typically used on fonts that do not have a `bold` weight, such as "SimSun".

## Usage

Please refer to the [Documentation](https://csimide.github.io/cuti-docs/en/).

本 Package 提供中文文档: [中文文档](https://csimide.github.io/cuti-docs/zh-CN/)

### Getting Started Quickly (For Chinese User)

Please add the following content at the beginning of the document:

```typst
#import "@preview/cuti:0.3.0": show-cn-fakebold
#show: show-cn-fakebold
```

Then, the bolding for SimHei, SimSun, and KaiTi fonts should work correctly.

## Changelog

### `0.3.0`

- feat: Add fake small caps feature by Tetragramm.
- fix: `show-fakebold` may crash on Typst version 0.12.0.

### `0.2.1`

- feat: The stroke of fake bold will use the same color as the text.
- fix: Attempted to fix the issue with the spacing of punctuation in fake italic (#2), but there are still problems.

### `0.2.0`

- feat: Added fake italic functionality.

### `0.1.0`

- Basic fake bold functionality.

## License

MIT License

This package refers to the following content:

- [TeX and Chinese Character Processing: Fake Bold and Fake Italic](https://zhuanlan.zhihu.com/p/19686102)
- Typst issue [#394](https://github.com/typst/typst/issues/394)
- Typst issue [#2749](https://github.com/typst/typst/issues/2749) (The function `_skew` comes from Enivex's code.)

Thanks to Enter-tainer for the assistance.
55 changes: 55 additions & 0 deletions packages/preview/cuti/0.3.0/lib.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#let fakebold(base-weight: auto, weight: auto, s, ..params) = {
let t-weight = if base-weight == auto {weight} else {base-weight}
assert(
t-weight in (auto, none) or type(t-weight) in (str, int),
message: "`base-weight`/`weight` should be `auto`, `none`, `int` or `str` type.",
)
set text(weight: t-weight) if type(t-weight) in (str, int)
set text(weight: "regular") if t-weight == none
set text(..params) if params != ()
context {
set text(stroke: 0.02857em + text.fill)
s
}
}

#let regex-fakebold(reg-exp: ".+", s, ..params) = {
show regex(reg-exp): it => {
fakebold(it, ..params)
}
s
}

#let show-fakebold(reg-exp: ".+", s, weight: none, ..params) = {
show text.where(weight: "bold").or(strong): it => {
regex-fakebold(reg-exp: reg-exp, it, weight: weight, ..params)
}
s
}

#let cn-fakebold(s, ..params) = {
regex-fakebold(reg-exp: "[\p{script=Han}!-・〇-〰—]+", weight: "regular", s, ..params)
}

#let show-cn-fakebold(s, ..params) = {
show-fakebold(reg-exp: "[\p{script=Han}!-・〇-〰—]+", weight: "regular", s, ..params)
}

#let regex-fakeitalic(reg-exp: ".+?", ang: -18.4deg, s) = {
show regex(reg-exp): it => {
box(skew(ax: ang, reflow: false, it))
}
s
}

#let fakeitalic(
ang: -18.4deg,
s,
) = regex-fakeitalic(reg-exp: "(?:\b[^\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}!-・〇-〰—]+?\b|[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}])", ang: ang, s)

#let fakesc(s, scaling: 0.75) = {
show regex("\p{Ll}+"): it => {
context text(scaling * 1em, stroke: 0.01em + text.fill, upper(it))
}
text(s)
}
10 changes: 10 additions & 0 deletions packages/preview/cuti/0.3.0/typst.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "cuti"
version = "0.3.0"
entrypoint = "lib.typ"
authors = ["csimide", "Enivex", "Tetragramm"]
license = "MIT"
description = "Easily simulate (fake) bold, italic and small capital characters."
compiler = "0.12.0"
repository = "https://github.com/csimide/cuti"
exclude = ["tests"]