Skip to content

Commit

Permalink
cuti:0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
csimide committed Nov 23, 2024
1 parent 78fedda commit 0a6db73
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 0 deletions.
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}])", 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)
}
66 changes: 66 additions & 0 deletions packages/preview/cuti/0.3.0/tests/fakebold.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#import "../lib.typ": *

Check warning on line 1 in packages/preview/cuti/0.3.0/tests/fakebold.typ

View check run for this annotation

Typst package check / @preview/cuti:0.3.0

packages/preview/cuti/0.3.0/tests/fakebold.typ#L1

This import should use the package specification, not a relative path.
#set page(margin: 2cm)
#show table.cell.where(y: 0): it => {strong(it)}

// Please add `set text(font: ...)` to test how text appears in different fonts when testing typography layouts.

// Functional tests

#[
*Regex `[aik]` Fakebold*: #regex-fakebold(reg-exp: "[aik]", lorem(10)) \
*Fakebold based on `bold`*: #fakebold(base-weight: "bold", lorem(10)) \
]
// English
#[
#let en-test(s) = table(
columns: (1fr, ) * 3,
stroke: 0.5pt,
table.header(
[Original],
[Bold - Font],
[Fakebold - `cuti`]
),
s,
strong(s),
fakebold(s)
)
#en-test(lorem(30))
#set par(justify: true)
#en-test(lorem(30))
]
// Chinese + English
#[
#let cn-test(s) = table(
columns: (1fr, ) * 3,
stroke: 0.5pt,
table.header(
[Original],
[Fakebold - `cuti`],
[zh Fakebold + en Font Bold]
),
s,
fakebold(s),
show-cn-fakebold(strong(s))
)
#set par(justify: true)
// zh-CN
#set text(lang: "cn", region: "zh")
#cn-test[你说得对,但是《Typst》是一款由 Typst GmbH 与众多贡献者开发的一款开放世界冒险排版游戏。游戏发生在一个被称作「typst.app」的线上世界。在这里,后面忘了——同时,逐步发掘排版的真相。Typst,启动!]
// zh-HK
#set text(lang: "cn", region: "hk")
#cn-test[你說得對,但是《Typst》係一款由 Typst GmbH 同眾多貢獻者開發嘅開放世界冒險排版遊戲。遊戲發生喺一個叫做「typst.app」嘅線上世界。喺呢度,後面唔記得咗——同時,逐步發掘排版嘅真相。Typst,啟動!]
// zh-TW
#set text(lang: "cn", region: "tw")
#cn-test[你說得對,但是《Typst》是一款由 Typst GmbH 與眾多貢獻者開發的開放世界冒險排版遊戲。遊戲發生在一個被稱作「typst.app」的線上世界。在這裡,後面忘記了——同時,逐步發掘排版的真相。Typst,啟動!]
]
66 changes: 66 additions & 0 deletions packages/preview/cuti/0.3.0/tests/fakeitalic.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#import "../lib.typ": *

Check warning on line 1 in packages/preview/cuti/0.3.0/tests/fakeitalic.typ

View check run for this annotation

Typst package check / @preview/cuti:0.3.0

packages/preview/cuti/0.3.0/tests/fakeitalic.typ#L1

This import should use the package specification, not a relative path.
#set page(margin: 2cm)
#show table.cell.where(y: 0): it => {strong(it)}

// Please add `set text(font: ...)` to test how text appears in different fonts when testing typography layouts.

// Functional tests

#[
*Fakeitalic*: #fakeitalic(lorem(10))
]

// English

#[
#let en-test(s) = table(
columns: (1fr, ) * 3,
stroke: 0.5pt,
table.header(
[Original],
[Italic - Font],
[Fakeitalic -18.4deg - `cuti`]
),
s,
emph(s),
fakeitalic(s)
)

#en-test(lorem(30))

#set par(justify: true)

#en-test(lorem(30))
]


// Chinese + English

#[
#let cn-test(s) = table(
columns: (1fr, ) * 3,
stroke: 0.5pt,
table.header(
[Original],
[Fakebold - `cuti`],
[zh Fakebold + en Font Bold]
),
s,
emph(s),
fakeitalic(s)
)

#set par(justify: true)

// zh-CN
#set text(lang: "cn", region: "zh")
#cn-test[你说得对,但是《Typst》是一款由 Typst GmbH 与众多贡献者开发的一款开放世界冒险排版游戏。游戏发生在一个被称作「typst.app」的线上世界。在这里,后面忘了——同时,逐步发掘排版的真相。Typst,启动!]

// zh-HK
#set text(lang: "cn", region: "hk")
#cn-test[你說得對,但是《Typst》係一款由 Typst GmbH 同眾多貢獻者開發嘅開放世界冒險排版遊戲。遊戲發生喺一個叫做「typst.app」嘅線上世界。喺呢度,後面唔記得咗——同時,逐步發掘排版嘅真相。Typst,啟動!]

// zh-TW
#set text(lang: "cn", region: "tw")
#cn-test[你說得對,但是《Typst》是一款由 Typst GmbH 與眾多貢獻者開發的開放世界冒險排版遊戲。遊戲發生在一個被稱作「typst.app」的線上世界。在這裡,後面忘記了——同時,逐步發掘排版的真相。Typst,啟動!]
]
26 changes: 26 additions & 0 deletions packages/preview/cuti/0.3.0/tests/fakesc.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#import "../lib.typ": *

Check warning on line 1 in packages/preview/cuti/0.3.0/tests/fakesc.typ

View check run for this annotation

Typst package check / @preview/cuti:0.3.0

packages/preview/cuti/0.3.0/tests/fakesc.typ#L1

This import should use the package specification, not a relative path.
#set page(margin: 2cm)
#show table.cell.where(y: 0): it => {strong(it)}

// Please add `set text(font: ...)` to test how text appears in different fonts when testing typography layouts.

#[
#let en-test(s) = table(
columns: (1fr, ) * 3,
stroke: 0.5pt,
table.header(
[Original],
[Small Capitals - Font],
[FakeSC - `cuti`]
),
s,
smallcaps(s),
fakesc(s)
)

#en-test(lorem(30))

#set par(justify: true)

#en-test(lorem(30))
]
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 = ["demo-and-doc"]

0 comments on commit 0a6db73

Please sign in to comment.