@@ -61,44 +61,61 @@ class TypstCompilerDriver {
61
61
62
62
export function generateTypst ( team : string , location : string , filename : string , lang : string , codeColor : boolean ) {
63
63
return `
64
- #let print(
65
- team: "",
66
- location: "",
67
- filename: "",
68
- lang: "",
69
- body
70
- ) = {
71
- set document(author: (team), title: filename)
72
- set text(font: ("Linux Libertine"), lang: "zh")
73
- set page(
74
- paper: "a4",
75
- header: [
76
- #if (location != "") {
77
- [[#location]]
78
- }
79
- #team
80
- #h(1fr)
81
- By Hydro/XCPC-TOOLS
82
-
83
- filename: #filename
84
- #h(1fr)
85
- Page #counter(page).display("1 of 1", both: true)
86
- ]
87
- )
88
-
89
- raw(read(filename), lang: lang, block: true${ codeColor ? '' : ', theme: "BW.tmtheme"' } )
90
- body
64
+ #let fit(name: "", width: 147mm) = {
65
+ context {
66
+ if measure(text(name)).width < width {
67
+ return name
68
+ }
69
+ for len in range(name.codepoints().len() - 1, 5, step: -1) {
70
+ if measure(text(name
71
+ .codepoints()
72
+ .slice(0, len)
73
+ .join() + " ...")).width < width {
74
+ return name.codepoints().slice(0, len).join() + " ..."
75
+ }
76
+ }
77
+ panic("Error")
78
+ }
91
79
}
92
80
93
- #show raw.line: it => {
94
- box(stack(
95
- dir: ltr,
96
- box(width: 18pt)[#it.number],
97
- it.body,
98
- ))
81
+ #let print(
82
+ team: "",
83
+ location: "",
84
+ filename: "",
85
+ lang: "",
86
+ ) = {
87
+ set document(author: (team), title: filename)
88
+ set text(lang: "zh")
89
+ set page(
90
+ paper: "a4",
91
+ header: [
92
+ #if (location != "") {
93
+ text(weight: "black", size: 10pt)[[#location]]
94
+ }
95
+ #fit(name: team)
96
+ #linebreak()
97
+ filename: #filename
98
+ #h(1fr)
99
+ By Hydro/XCPC-TOOLS | Page #counter(page).display("1 of 1", both: true)
100
+ ],
101
+ )
102
+ show raw.where(block: true): code => {
103
+ show raw.line: it => {
104
+ box(
105
+ stack(
106
+ dir: ltr,
107
+ box(width: 0em, align(right, text(fill: gray)[#it.number])),
108
+ h(1em),
109
+ it.body,
110
+ ),
111
+ )
112
+ }
113
+ code
114
+ }
115
+ raw(read(filename), lang: lang, block: true${ codeColor ? '' : ', theme: "BW.tmtheme"' } )
99
116
}
100
117
101
- #show: print.with (
118
+ #print(
102
119
team: ${ JSON . stringify ( team || '' ) } ,
103
120
location: ${ JSON . stringify ( location || '' ) } ,
104
121
filename: ${ JSON . stringify ( filename || '' ) } ,
0 commit comments