Skip to content

Commit 4284b40

Browse files
authored
Merge pull request #11 from h200101/UTF-8 - thanks @h200101!
Added UTF-8 support
2 parents fbeec90 + 9127209 commit 4284b40

13 files changed

Lines changed: 294 additions & 28 deletions

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ require (
1919
go.yaml.in/yaml/v3 v3.0.4 // indirect
2020
golang.org/x/crypto v0.46.0 // indirect
2121
golang.org/x/sys v0.39.0 // indirect
22+
golang.org/x/text v0.33.0 // indirect
2223
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU=
2424
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
2525
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
2626
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
27+
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
28+
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
2729
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2830
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2931
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

internal/bundle/bundle.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import (
99
"regexp"
1010
"strings"
1111
"time"
12+
"unicode"
13+
14+
"golang.org/x/text/unicode/norm"
1215

1316
"github.com/eljojo/rememory/internal/core"
1417
"github.com/eljojo/rememory/internal/html"
@@ -213,10 +216,21 @@ func loadShares(p *project.Project) ([]*core.Share, error) {
213216
return shares, nil
214217
}
215218

216-
// sanitizeName converts a name to a filesystem-safe lowercase string.
219+
// sanitizeName converts a name to a filesystem-safe lowercase ASCII string.
220+
// It transliterates accented/diacritic characters to their ASCII base form
221+
// (e.g. "José" → "jose", "Ñoño" → "nono") so that filenames are always valid.
217222
func sanitizeName(name string) string {
223+
// Decompose to NFD: splits characters like "é" into "e" + combining accent.
224+
// Then drop combining marks to keep only the base letter.
225+
var stripped []rune
226+
for _, r := range norm.NFD.String(name) {
227+
if !unicode.Is(unicode.Mn, r) { // Mn = Mark, Nonspacing (combining diacritics)
228+
stripped = append(stripped, r)
229+
}
230+
}
231+
218232
result := ""
219-
for _, r := range name {
233+
for _, r := range stripped {
220234
if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') {
221235
result += string(r)
222236
} else if r == ' ' || r == '-' || r == '_' {

internal/pdf/fonts.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package pdf
2+
3+
import (
4+
_ "embed"
5+
6+
"github.com/go-pdf/fpdf"
7+
)
8+
9+
// DejaVu Sans font files (Bitstream Vera / DejaVu license - see fonts/LICENSE-DejaVu.txt)
10+
// These provide comprehensive UTF-8 / Unicode coverage including Latin, Cyrillic,
11+
// Greek, Arabic, Hebrew, and many other scripts.
12+
13+
//go:embed fonts/DejaVuSans.ttf
14+
var dejaVuSansRegular []byte
15+
16+
//go:embed fonts/DejaVuSans-Bold.ttf
17+
var dejaVuSansBold []byte
18+
19+
//go:embed fonts/DejaVuSans-Oblique.ttf
20+
var dejaVuSansOblique []byte
21+
22+
//go:embed fonts/DejaVuSans-BoldOblique.ttf
23+
var dejaVuSansBoldOblique []byte
24+
25+
//go:embed fonts/DejaVuSansMono.ttf
26+
var dejaVuSansMonoRegular []byte
27+
28+
//go:embed fonts/DejaVuSansMono-Bold.ttf
29+
var dejaVuSansMonoBold []byte
30+
31+
// Font family names used throughout the PDF generator.
32+
const (
33+
fontSans = "DejaVuSans"
34+
fontMono = "DejaVuSansMono"
35+
)
36+
37+
// registerUTF8Fonts adds the embedded DejaVu Sans UTF-8 fonts to the PDF instance.
38+
// After calling this, use fontSans and fontMono as the family name in SetFont().
39+
func registerUTF8Fonts(pdf *fpdf.Fpdf) {
40+
pdf.AddUTF8FontFromBytes(fontSans, "", dejaVuSansRegular)
41+
pdf.AddUTF8FontFromBytes(fontSans, "B", dejaVuSansBold)
42+
pdf.AddUTF8FontFromBytes(fontSans, "I", dejaVuSansOblique)
43+
pdf.AddUTF8FontFromBytes(fontSans, "BI", dejaVuSansBoldOblique)
44+
45+
pdf.AddUTF8FontFromBytes(fontMono, "", dejaVuSansMonoRegular)
46+
pdf.AddUTF8FontFromBytes(fontMono, "B", dejaVuSansMonoBold)
47+
}
689 KB
Binary file not shown.
628 KB
Binary file not shown.
621 KB
Binary file not shown.

internal/pdf/fonts/DejaVuSans.ttf

739 KB
Binary file not shown.
324 KB
Binary file not shown.
333 KB
Binary file not shown.

0 commit comments

Comments
 (0)