bare-x-to-pdf 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core/Cargo.lock CHANGED
@@ -17,15 +17,6 @@ dependencies = [
17
17
  "memchr",
18
18
  ]
19
19
 
20
- [[package]]
21
- name = "android_system_properties"
22
- version = "0.1.6"
23
- source = "registry+https://github.com/rust-lang/crates.io-index"
24
- checksum = "ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc"
25
- dependencies = [
26
- "libc",
27
- ]
28
-
29
20
  [[package]]
30
21
  name = "approx"
31
22
  version = "0.5.1"
@@ -159,24 +150,12 @@ dependencies = [
159
150
  "syn 3.0.5",
160
151
  ]
161
152
 
162
- [[package]]
163
- name = "byteorder"
164
- version = "1.5.0"
165
- source = "registry+https://github.com/rust-lang/crates.io-index"
166
- checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
167
-
168
153
  [[package]]
169
154
  name = "byteorder-lite"
170
155
  version = "0.1.0"
171
156
  source = "registry+https://github.com/rust-lang/crates.io-index"
172
157
  checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
173
158
 
174
- [[package]]
175
- name = "bytes"
176
- version = "1.12.1"
177
- source = "registry+https://github.com/rust-lang/crates.io-index"
178
- checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
179
-
180
159
  [[package]]
181
160
  name = "cc"
182
161
  version = "1.4.6"
@@ -222,19 +201,6 @@ version = "1.1.6"
222
201
  source = "registry+https://github.com/rust-lang/crates.io-index"
223
202
  checksum = "0d1275808335c5583ea45a4141d631dafcb36b79fa8a5e10b00e356b6af3e08a"
224
203
 
225
- [[package]]
226
- name = "chrono"
227
- version = "0.4.45"
228
- source = "registry+https://github.com/rust-lang/crates.io-index"
229
- checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327"
230
- dependencies = [
231
- "iana-time-zone",
232
- "js-sys",
233
- "num-traits",
234
- "wasm-bindgen",
235
- "windows-link",
236
- ]
237
-
238
204
  [[package]]
239
205
  name = "ciborium"
240
206
  version = "0.2.2"
@@ -330,32 +296,6 @@ dependencies = [
330
296
  "syn 2.0.119",
331
297
  ]
332
298
 
333
- [[package]]
334
- name = "console_error_panic_hook"
335
- version = "0.1.7"
336
- source = "registry+https://github.com/rust-lang/crates.io-index"
337
- checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
338
- dependencies = [
339
- "cfg-if",
340
- "wasm-bindgen",
341
- ]
342
-
343
- [[package]]
344
- name = "console_log"
345
- version = "1.1.0"
346
- source = "registry+https://github.com/rust-lang/crates.io-index"
347
- checksum = "86919cef3e37b9356ccf54d4421208c17ecfda01beae61393e7ffd72916c0ef1"
348
- dependencies = [
349
- "log",
350
- "web-sys",
351
- ]
352
-
353
- [[package]]
354
- name = "core-foundation-sys"
355
- version = "0.8.7"
356
- source = "registry+https://github.com/rust-lang/crates.io-index"
357
- checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
358
-
359
299
  [[package]]
360
300
  name = "core_detect"
361
301
  version = "1.0.0"
@@ -866,30 +806,6 @@ version = "0.1.7"
866
806
  source = "registry+https://github.com/rust-lang/crates.io-index"
867
807
  checksum = "bef68590049bab63a464eee1a1158ac04c6f6613a546d8d90f78636b8b94f171"
868
808
 
869
- [[package]]
870
- name = "iana-time-zone"
871
- version = "0.1.65"
872
- source = "registry+https://github.com/rust-lang/crates.io-index"
873
- checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470"
874
- dependencies = [
875
- "android_system_properties",
876
- "core-foundation-sys",
877
- "iana-time-zone-haiku",
878
- "js-sys",
879
- "log",
880
- "wasm-bindgen",
881
- "windows-core",
882
- ]
883
-
884
- [[package]]
885
- name = "iana-time-zone-haiku"
886
- version = "0.1.2"
887
- source = "registry+https://github.com/rust-lang/crates.io-index"
888
- checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
889
- dependencies = [
890
- "cc",
891
- ]
892
-
893
809
  [[package]]
894
810
  name = "icu_collator"
895
811
  version = "2.3.1"
@@ -1160,15 +1076,6 @@ version = "0.19.0"
1160
1076
  source = "registry+https://github.com/rust-lang/crates.io-index"
1161
1077
  checksum = "a588916bfdfd92e71cacef98a63d9b1f0d74d6599980d11894290e7ddefffcf7"
1162
1078
 
1163
- [[package]]
1164
- name = "itertools"
1165
- version = "0.15.0"
1166
- source = "registry+https://github.com/rust-lang/crates.io-index"
1167
- checksum = "8b4baf93f58d4425749ca49a51c50ebab072c5df6994d08fed93541c331481dc"
1168
- dependencies = [
1169
- "either",
1170
- ]
1171
-
1172
1079
  [[package]]
1173
1080
  name = "itoa"
1174
1081
  version = "1.0.18"
@@ -1260,16 +1167,6 @@ version = "0.2.189"
1260
1167
  source = "registry+https://github.com/rust-lang/crates.io-index"
1261
1168
  checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
1262
1169
 
1263
- [[package]]
1264
- name = "libloading"
1265
- version = "0.9.0"
1266
- source = "registry+https://github.com/rust-lang/crates.io-index"
1267
- checksum = "754ca22de805bb5744484a5b151a9e1a8e837d5dc232c2d7d8c2e3492edc8b60"
1268
- dependencies = [
1269
- "cfg-if",
1270
- "windows-link",
1271
- ]
1272
-
1273
1170
  [[package]]
1274
1171
  name = "libm"
1275
1172
  version = "0.2.16"
@@ -1322,12 +1219,6 @@ version = "0.4.34"
1322
1219
  source = "registry+https://github.com/rust-lang/crates.io-index"
1323
1220
  checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"
1324
1221
 
1325
- [[package]]
1326
- name = "maybe-owned"
1327
- version = "0.3.4"
1328
- source = "registry+https://github.com/rust-lang/crates.io-index"
1329
- checksum = "4facc753ae494aeb6e3c22f839b158aebd4f9270f55cd3c79906c45476c47ab4"
1330
-
1331
1222
  [[package]]
1332
1223
  name = "memchr"
1333
1224
  version = "2.8.3"
@@ -1529,32 +1420,6 @@ dependencies = [
1529
1420
  "ryu",
1530
1421
  ]
1531
1422
 
1532
- [[package]]
1533
- name = "pdfium-render"
1534
- version = "0.9.4"
1535
- source = "registry+https://github.com/rust-lang/crates.io-index"
1536
- checksum = "8948a803616a9e936b15a6637af2cd48c5fb8ae0fcdeb3c32eac3a540e255a19"
1537
- dependencies = [
1538
- "bitflags",
1539
- "bytemuck",
1540
- "bytes",
1541
- "chrono",
1542
- "console_error_panic_hook",
1543
- "console_log",
1544
- "image",
1545
- "itertools",
1546
- "js-sys",
1547
- "libloading",
1548
- "log",
1549
- "maybe-owned",
1550
- "once_cell",
1551
- "utf16string",
1552
- "vecmath",
1553
- "wasm-bindgen",
1554
- "wasm-bindgen-futures",
1555
- "web-sys",
1556
- ]
1557
-
1558
1423
  [[package]]
1559
1424
  name = "peniko"
1560
1425
  version = "0.6.1"
@@ -1639,12 +1504,6 @@ version = "0.2.17"
1639
1504
  source = "registry+https://github.com/rust-lang/crates.io-index"
1640
1505
  checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
1641
1506
 
1642
- [[package]]
1643
- name = "piston-float"
1644
- version = "1.0.1"
1645
- source = "registry+https://github.com/rust-lang/crates.io-index"
1646
- checksum = "ad78bf43dcf80e8f950c92b84f938a0fc7590b7f6866fbcbeca781609c115590"
1647
-
1648
1507
  [[package]]
1649
1508
  name = "plist"
1650
1509
  version = "1.10.1"
@@ -1747,6 +1606,17 @@ dependencies = [
1747
1606
  "cc",
1748
1607
  ]
1749
1608
 
1609
+ [[package]]
1610
+ name = "pulldown-cmark"
1611
+ version = "0.13.4"
1612
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1613
+ checksum = "e9f068eba8e7071c5f9511831b44f32c740d5adf574e990f946ddb53db2f314e"
1614
+ dependencies = [
1615
+ "bitflags",
1616
+ "memchr",
1617
+ "unicase",
1618
+ ]
1619
+
1750
1620
  [[package]]
1751
1621
  name = "pxfm"
1752
1622
  version = "0.1.30"
@@ -2094,8 +1964,8 @@ version = "0.1.0"
2094
1964
  dependencies = [
2095
1965
  "cfb",
2096
1966
  "encoding_rs",
2097
- "image",
2098
- "pdfium-render",
1967
+ "png",
1968
+ "pulldown-cmark",
2099
1969
  "quick-xml 0.42.0",
2100
1970
  "ttf-parser",
2101
1971
  "typst",
@@ -2808,6 +2678,12 @@ dependencies = [
2808
2678
  "unic-langid-impl",
2809
2679
  ]
2810
2680
 
2681
+ [[package]]
2682
+ name = "unicase"
2683
+ version = "2.9.0"
2684
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2685
+ checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142"
2686
+
2811
2687
  [[package]]
2812
2688
  name = "unicode-bidi"
2813
2689
  version = "0.3.18"
@@ -2930,15 +2806,6 @@ version = "1.0.5"
2930
2806
  source = "registry+https://github.com/rust-lang/crates.io-index"
2931
2807
  checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246"
2932
2808
 
2933
- [[package]]
2934
- name = "utf16string"
2935
- version = "0.2.0"
2936
- source = "registry+https://github.com/rust-lang/crates.io-index"
2937
- checksum = "0b62a1e85e12d5d712bf47a85f426b73d303e2d00a90de5f3004df3596e9d216"
2938
- dependencies = [
2939
- "byteorder",
2940
- ]
2941
-
2942
2809
  [[package]]
2943
2810
  name = "utf8_iter"
2944
2811
  version = "1.0.4"
@@ -2955,15 +2822,6 @@ dependencies = [
2955
2822
  "wasm-bindgen",
2956
2823
  ]
2957
2824
 
2958
- [[package]]
2959
- name = "vecmath"
2960
- version = "1.0.0"
2961
- source = "registry+https://github.com/rust-lang/crates.io-index"
2962
- checksum = "956ae1e0d85bca567dee1dcf87fb1ca2e792792f66f87dced8381f99cd91156a"
2963
- dependencies = [
2964
- "piston-float",
2965
- ]
2966
-
2967
2825
  [[package]]
2968
2826
  name = "vello_common"
2969
2827
  version = "0.0.8"
@@ -3040,16 +2898,6 @@ dependencies = [
3040
2898
  "wasm-bindgen-shared",
3041
2899
  ]
3042
2900
 
3043
- [[package]]
3044
- name = "wasm-bindgen-futures"
3045
- version = "0.4.78"
3046
- source = "registry+https://github.com/rust-lang/crates.io-index"
3047
- checksum = "6ef4c5d3d2cdf5c54f4231181768f5510842e350db025faf1f7163b1030ed928"
3048
- dependencies = [
3049
- "js-sys",
3050
- "wasm-bindgen",
3051
- ]
3052
-
3053
2901
  [[package]]
3054
2902
  name = "wasm-bindgen-macro"
3055
2903
  version = "0.2.128"
@@ -3128,16 +2976,6 @@ dependencies = [
3128
2976
  "bitflags",
3129
2977
  ]
3130
2978
 
3131
- [[package]]
3132
- name = "web-sys"
3133
- version = "0.3.105"
3134
- source = "registry+https://github.com/rust-lang/crates.io-index"
3135
- checksum = "9fbddc4a036f00ec4f18c83445bd3115cb306a91da554919a099d9222fe4a7f8"
3136
- dependencies = [
3137
- "js-sys",
3138
- "wasm-bindgen",
3139
- ]
3140
-
3141
2979
  [[package]]
3142
2980
  name = "web-time"
3143
2981
  version = "1.1.0"
@@ -3163,65 +3001,12 @@ dependencies = [
3163
3001
  "windows-sys",
3164
3002
  ]
3165
3003
 
3166
- [[package]]
3167
- name = "windows-core"
3168
- version = "0.62.2"
3169
- source = "registry+https://github.com/rust-lang/crates.io-index"
3170
- checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb"
3171
- dependencies = [
3172
- "windows-implement",
3173
- "windows-interface",
3174
- "windows-link",
3175
- "windows-result",
3176
- "windows-strings",
3177
- ]
3178
-
3179
- [[package]]
3180
- name = "windows-implement"
3181
- version = "0.60.2"
3182
- source = "registry+https://github.com/rust-lang/crates.io-index"
3183
- checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
3184
- dependencies = [
3185
- "proc-macro2",
3186
- "quote",
3187
- "syn 2.0.119",
3188
- ]
3189
-
3190
- [[package]]
3191
- name = "windows-interface"
3192
- version = "0.59.3"
3193
- source = "registry+https://github.com/rust-lang/crates.io-index"
3194
- checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
3195
- dependencies = [
3196
- "proc-macro2",
3197
- "quote",
3198
- "syn 2.0.119",
3199
- ]
3200
-
3201
3004
  [[package]]
3202
3005
  name = "windows-link"
3203
3006
  version = "0.2.1"
3204
3007
  source = "registry+https://github.com/rust-lang/crates.io-index"
3205
3008
  checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
3206
3009
 
3207
- [[package]]
3208
- name = "windows-result"
3209
- version = "0.4.1"
3210
- source = "registry+https://github.com/rust-lang/crates.io-index"
3211
- checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5"
3212
- dependencies = [
3213
- "windows-link",
3214
- ]
3215
-
3216
- [[package]]
3217
- name = "windows-strings"
3218
- version = "0.5.1"
3219
- source = "registry+https://github.com/rust-lang/crates.io-index"
3220
- checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091"
3221
- dependencies = [
3222
- "windows-link",
3223
- ]
3224
-
3225
3010
  [[package]]
3226
3011
  name = "windows-sys"
3227
3012
  version = "0.61.2"
package/core/Cargo.toml CHANGED
@@ -15,10 +15,10 @@ typst-layout = "0.15"
15
15
  zip = { version = "8", default-features = false, features = ["deflate"] }
16
16
  quick-xml = "0.42"
17
17
  ttf-parser = "0.25"
18
- pdfium-render = "0.9"
19
18
  cfb = "0.14"
20
19
  encoding_rs = "0.8"
21
- image = { version = "0.25", default-features = false, features = ["png"] }
20
+ png = "0.18"
21
+ pulldown-cmark = { version = "0.13", default-features = false }
22
22
 
23
23
  [profile.dev]
24
24
  debug = 0
@@ -20,7 +20,6 @@ sc_convert(
20
20
  const char *from,
21
21
  const char *to,
22
22
  const char *fonts_dir,
23
- const char *pdfium_path,
24
23
  sc_buffer_t *out,
25
24
  sc_buffer_t *error
26
25
  );
@@ -43,6 +43,8 @@ pub fn read(bytes: &[u8]) -> Result<Document, Error> {
43
43
 
44
44
  let mut doc = Document {
45
45
  borders_outside_indent: true,
46
+ table_at_border_center: true,
47
+ writer_text_offset: true,
46
48
  footnote_separator_width: Some(144.0),
47
49
  default_tab: 36.0,
48
50
  additive_spacing: false,
@@ -1,7 +1,6 @@
1
1
  mod numbering;
2
2
  pub use numbering::format_number;
3
3
  mod styles;
4
- pub mod writer;
5
4
 
6
5
  use crate::error::Error;
7
6
  use crate::model::*;
@@ -92,6 +91,8 @@ pub fn read(bytes: &[u8]) -> Result<Document, Error> {
92
91
 
93
92
  let mut doc = Document {
94
93
  borders_outside_indent: true,
94
+ table_at_border_center: true,
95
+ writer_text_offset: true,
95
96
  footnote_separator_width: Some(144.0),
96
97
  default_tab: 36.0,
97
98
  ..Document::default()
@@ -114,6 +115,16 @@ pub fn read(bytes: &[u8]) -> Result<Document, Error> {
114
115
  .and_then(|c| c.child("doNotUseHTMLParagraphAutoSpacing"))
115
116
  .map(flag)
116
117
  .unwrap_or(false);
118
+ let compat_mode = settings
119
+ .child("compat")
120
+ .and_then(|c| {
121
+ c.children("compatSetting")
122
+ .find(|s| s.attr("name") == Some("compatibilityMode"))
123
+ })
124
+ .and_then(|s| s.attr("val"))
125
+ .and_then(|v| v.parse::<u32>().ok())
126
+ .unwrap_or(0);
127
+ doc.table_at_border_center = compat_mode == 0 || compat_mode >= 15;
117
128
  }
118
129
 
119
130
  let mut blocks = Vec::new();
package/core/src/lib.rs CHANGED
@@ -1,9 +1,10 @@
1
1
  pub mod doc;
2
2
  pub mod docx;
3
3
  pub mod error;
4
+ pub mod markdown;
4
5
  pub mod model;
6
+ pub mod odf_chart;
5
7
  pub mod odt;
6
- pub mod pdf;
7
8
  pub mod pptx;
8
9
  pub mod typst_backend;
9
10
  pub mod xlsx;
@@ -17,13 +18,15 @@ use std::path::Path;
17
18
 
18
19
  pub struct Options<'a> {
19
20
  pub fonts_dir: &'a Path,
20
- pub pdfium_path: &'a Path,
21
- pub background_scale: f32,
22
21
  }
23
22
 
24
23
  pub fn convert(input: &[u8], from: &str, to: &str, options: &Options) -> Result<Vec<u8>, Error> {
24
+ let compound = input.starts_with(&[0xD0, 0xCF, 0x11, 0xE0]).then(|| compound_kind(input)).flatten();
25
25
  let from = match from {
26
26
  "doc" | "dot" if input.starts_with(b"PK") => "docx",
27
+ "xls" | "xlt" if input.starts_with(b"PK") => "xlsx",
28
+ "doc" | "dot" | "docx" | "docm" | "dotx" | "dotm" if compound == Some("xls") => "xls",
29
+ "xls" | "xlt" | "xlsx" | "xlsm" | "xltx" | "xltm" if compound == Some("doc") => "doc",
27
30
  "docx" | "docm" | "dotx" | "dotm" if input.starts_with(&[0xD0, 0xCF, 0x11, 0xE0]) => "doc",
28
31
  "odt" | "ott" if input.starts_with(b"<") || input.starts_with(&[0xEF, 0xBB, 0xBF]) => "fodt",
29
32
  other => other,
@@ -45,18 +48,41 @@ pub fn convert(input: &[u8], from: &str, to: &str, options: &Options) -> Result<
45
48
  let document = xlsx::read(input)?;
46
49
  typst_backend::render_pdf(&document, options.fonts_dir)
47
50
  }
51
+ ("odp" | "otp" | "fodp", "pdf") => {
52
+ let document = odt::read_odp(input)?;
53
+ typst_backend::render_pdf(&document, options.fonts_dir)
54
+ }
55
+ ("ods" | "ots" | "fods", "pdf") => {
56
+ let document = xlsx::read_ods(input)?;
57
+ typst_backend::render_pdf(&document, options.fonts_dir)
58
+ }
59
+ ("xls" | "xlt", "pdf") => {
60
+ let document = xlsx::read_xls(input)?;
61
+ typst_backend::render_pdf(&document, options.fonts_dir)
62
+ }
63
+ ("md" | "markdown", "pdf") => {
64
+ let document = markdown::read(input)?;
65
+ typst_backend::render_pdf(&document, options.fonts_dir)
66
+ }
48
67
  ("pptx", "pdf") => {
49
68
  let document = pptx::read(input)?;
50
69
  typst_backend::render_pdf(&document, options.fonts_dir)
51
70
  }
52
- ("pdf", "docx") => {
53
- let document = pdf::read(input, options.pdfium_path, options.background_scale)?;
54
- docx::writer::write_fixed(&document)
55
- }
56
71
  _ => Err(Error::new(format!("conversion from {from} to {to} is not supported"))),
57
72
  }
58
73
  }
59
74
 
75
+ fn compound_kind(input: &[u8]) -> Option<&'static str> {
76
+ let file = cfb::CompoundFile::open(std::io::Cursor::new(input)).ok()?;
77
+ if file.exists("/WordDocument") {
78
+ Some("doc")
79
+ } else if file.exists("/Workbook") || file.exists("/Book") {
80
+ Some("xls")
81
+ } else {
82
+ None
83
+ }
84
+ }
85
+
60
86
  #[repr(C)]
61
87
  pub struct Buffer {
62
88
  pub data: *mut u8,
@@ -96,7 +122,6 @@ pub unsafe extern "C" fn sc_convert(
96
122
  from: *const c_char,
97
123
  to: *const c_char,
98
124
  fonts_dir: *const c_char,
99
- pdfium_path: *const c_char,
100
125
  out: *mut Buffer,
101
126
  error: *mut Buffer,
102
127
  ) -> i32 {
@@ -115,11 +140,8 @@ pub unsafe extern "C" fn sc_convert(
115
140
  let from = c_string(from, "from")?;
116
141
  let to = c_string(to, "to")?;
117
142
  let fonts_dir = c_string(fonts_dir, "fontsDir")?;
118
- let pdfium_path = c_string(pdfium_path, "pdfiumPath")?;
119
143
  let options = Options {
120
144
  fonts_dir: Path::new(&fonts_dir),
121
- pdfium_path: Path::new(&pdfium_path),
122
- background_scale: 2.0,
123
145
  };
124
146
  convert(input, &from, &to, &options)
125
147
  }));