summaryrefslogtreecommitdiff
path: root/crates/typst-pdf
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2024-10-27 19:04:55 +0100
committerGitHub <noreply@github.com>2024-10-27 18:04:55 +0000
commitbe7cfc85d08c545abfac08098b7b33b4bd71f37e (patch)
treef4137fa2aaa57babae1f7603a9b2ed7e688f43d8 /crates/typst-pdf
parentb8034a343831e8609aec2ec81eb7eeda57aa5d81 (diff)
Split out four new crates (#5302)
Diffstat (limited to 'crates/typst-pdf')
-rw-r--r--crates/typst-pdf/Cargo.toml7
-rw-r--r--crates/typst-pdf/src/catalog.rs10
-rw-r--r--crates/typst-pdf/src/color.rs6
-rw-r--r--crates/typst-pdf/src/color_font.rs13
-rw-r--r--crates/typst-pdf/src/content.rs18
-rw-r--r--crates/typst-pdf/src/extg.rs2
-rw-r--r--crates/typst-pdf/src/font.rs10
-rw-r--r--crates/typst-pdf/src/gradient.rs11
-rw-r--r--crates/typst-pdf/src/image.rs6
-rw-r--r--crates/typst-pdf/src/lib.rs18
-rw-r--r--crates/typst-pdf/src/named_destination.rs10
-rw-r--r--crates/typst-pdf/src/outline.rs6
-rw-r--r--crates/typst-pdf/src/page.rs17
-rw-r--r--crates/typst-pdf/src/pattern.rs11
-rw-r--r--crates/typst-pdf/src/resources.rs10
15 files changed, 77 insertions, 78 deletions
diff --git a/crates/typst-pdf/Cargo.toml b/crates/typst-pdf/Cargo.toml
index 64229945..4cef14bd 100644
--- a/crates/typst-pdf/Cargo.toml
+++ b/crates/typst-pdf/Cargo.toml
@@ -13,10 +13,13 @@ keywords = { workspace = true }
readme = { workspace = true }
[dependencies]
-typst = { workspace = true }
typst-assets = { workspace = true }
+typst-library = { workspace = true }
typst-macros = { workspace = true }
+typst-syntax = { workspace = true }
typst-timing = { workspace = true }
+typst-utils = { workspace = true }
+arrayvec = { workspace = true }
base64 = { workspace = true }
bytemuck = { workspace = true }
comemo = { workspace = true }
@@ -26,12 +29,10 @@ indexmap = { workspace = true }
miniz_oxide = { workspace = true }
once_cell = { workspace = true }
pdf-writer = { workspace = true }
-arrayvec = { workspace = true }
serde = { workspace = true }
subsetter = { workspace = true }
svg2pdf = { workspace = true }
ttf-parser = { workspace = true }
-unscanny = { workspace = true }
xmp-writer = { workspace = true }
[lints]
diff --git a/crates/typst-pdf/src/catalog.rs b/crates/typst-pdf/src/catalog.rs
index 7aba0eb6..1412afe6 100644
--- a/crates/typst-pdf/src/catalog.rs
+++ b/crates/typst-pdf/src/catalog.rs
@@ -4,11 +4,11 @@ use ecow::eco_format;
use pdf_writer::types::Direction;
use pdf_writer::writers::PageLabel;
use pdf_writer::{Finish, Name, Pdf, Ref, Str, TextStr};
-use typst::diag::{bail, SourceResult};
-use typst::foundations::{Datetime, Smart};
-use typst::layout::Dir;
-use typst::syntax::Span;
-use typst::text::Lang;
+use typst_library::diag::{bail, SourceResult};
+use typst_library::foundations::{Datetime, Smart};
+use typst_library::layout::Dir;
+use typst_library::text::Lang;
+use typst_syntax::Span;
use xmp_writer::{DateTime, LangId, RenditionClass, Timezone, XmpWriter};
use crate::page::PdfPageLabel;
diff --git a/crates/typst-pdf/src/color.rs b/crates/typst-pdf/src/color.rs
index a19d776a..26f2044c 100644
--- a/crates/typst-pdf/src/color.rs
+++ b/crates/typst-pdf/src/color.rs
@@ -1,9 +1,9 @@
use arrayvec::ArrayVec;
use once_cell::sync::Lazy;
use pdf_writer::{writers, Chunk, Dict, Filter, Name, Ref};
-use typst::diag::{bail, SourceResult};
-use typst::syntax::Span;
-use typst::visualize::{Color, ColorSpace, Paint};
+use typst_library::diag::{bail, SourceResult};
+use typst_library::visualize::{Color, ColorSpace, Paint};
+use typst_syntax::Span;
use crate::{content, deflate, PdfChunk, PdfOptions, Renumber, WithResources};
diff --git a/crates/typst-pdf/src/color_font.rs b/crates/typst-pdf/src/color_font.rs
index f6fea396..1183e966 100644
--- a/crates/typst-pdf/src/color_font.rs
+++ b/crates/typst-pdf/src/color_font.rs
@@ -12,16 +12,15 @@ use indexmap::IndexMap;
use pdf_writer::types::UnicodeCmap;
use pdf_writer::writers::WMode;
use pdf_writer::{Filter, Finish, Name, Rect, Ref};
-use typst::diag::{bail, error, SourceDiagnostic, SourceResult};
-use typst::foundations::Repr;
-use typst::layout::Em;
-use typst::text::color::glyph_frame;
-use typst::text::{Font, Glyph, TextItemView};
+use typst_library::diag::{bail, error, SourceDiagnostic, SourceResult};
+use typst_library::foundations::Repr;
+use typst_library::layout::Em;
+use typst_library::text::color::glyph_frame;
+use typst_library::text::{Font, Glyph, TextItemView};
-use crate::content;
use crate::font::{base_font_name, write_font_descriptor, CMAP_NAME, SYSTEM_INFO};
use crate::resources::{Resources, ResourcesRefs};
-use crate::{EmExt, PdfChunk, PdfOptions, WithGlobalRefs};
+use crate::{content, EmExt, PdfChunk, PdfOptions, WithGlobalRefs};
/// Write color fonts in the PDF document.
///
diff --git a/crates/typst-pdf/src/content.rs b/crates/typst-pdf/src/content.rs
index babb3e57..ce72365d 100644
--- a/crates/typst-pdf/src/content.rs
+++ b/crates/typst-pdf/src/content.rs
@@ -10,20 +10,20 @@ use pdf_writer::types::{
};
use pdf_writer::writers::PositionedItems;
use pdf_writer::{Content, Finish, Name, Rect, Str};
-use typst::diag::{bail, error, SourceDiagnostic, SourceResult};
-use typst::foundations::Repr;
-use typst::layout::{
+use typst_library::diag::{bail, error, SourceDiagnostic, SourceResult};
+use typst_library::foundations::Repr;
+use typst_library::layout::{
Abs, Em, Frame, FrameItem, GroupItem, Point, Ratio, Size, Transform,
};
-use typst::model::Destination;
-use typst::syntax::Span;
-use typst::text::color::should_outline;
-use typst::text::{Font, Glyph, TextItem, TextItemView};
-use typst::utils::{Deferred, Numeric, SliceExt};
-use typst::visualize::{
+use typst_library::model::Destination;
+use typst_library::text::color::should_outline;
+use typst_library::text::{Font, Glyph, TextItem, TextItemView};
+use typst_library::visualize::{
FillRule, FixedStroke, Geometry, Image, LineCap, LineJoin, Paint, Path, PathItem,
Shape,
};
+use typst_syntax::Span;
+use typst_utils::{Deferred, Numeric, SliceExt};
use crate::color::PaintEncode;
use crate::color_font::ColorFontMap;
diff --git a/crates/typst-pdf/src/extg.rs b/crates/typst-pdf/src/extg.rs
index 12bfa26a..06617d8d 100644
--- a/crates/typst-pdf/src/extg.rs
+++ b/crates/typst-pdf/src/extg.rs
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use pdf_writer::Ref;
-use typst::diag::SourceResult;
+use typst_library::diag::SourceResult;
use crate::{PdfChunk, WithGlobalRefs};
diff --git a/crates/typst-pdf/src/font.rs b/crates/typst-pdf/src/font.rs
index c870d32a..93d75e50 100644
--- a/crates/typst-pdf/src/font.rs
+++ b/crates/typst-pdf/src/font.rs
@@ -8,10 +8,10 @@ use pdf_writer::writers::{FontDescriptor, WMode};
use pdf_writer::{Chunk, Filter, Finish, Name, Rect, Ref, Str};
use subsetter::GlyphRemapper;
use ttf_parser::{name_id, GlyphId, Tag};
-use typst::diag::{At, SourceResult};
-use typst::syntax::Span;
-use typst::text::Font;
-use typst::utils::SliceExt;
+use typst_library::diag::{At, SourceResult};
+use typst_library::text::Font;
+use typst_syntax::Span;
+use typst_utils::SliceExt;
use crate::{deflate, EmExt, NameExt, PdfChunk, WithGlobalRefs};
@@ -249,7 +249,7 @@ pub(crate) fn base_font_name<T: Hash>(font: &Font, glyphs: &T) -> EcoString {
/// Produce a unique 6 letter tag for a glyph set.
pub(crate) fn subset_tag<T: Hash>(glyphs: &T) -> EcoString {
const BASE: u128 = 26;
- let mut hash = typst::utils::hash128(&glyphs);
+ let mut hash = typst_utils::hash128(&glyphs);
let mut letter = [b'A'; SUBSET_TAG_LEN];
for l in letter.iter_mut() {
*l = b'A' + (hash % BASE) as u8;
diff --git a/crates/typst-pdf/src/gradient.rs b/crates/typst-pdf/src/gradient.rs
index be0a3ea0..6cd4c1ae 100644
--- a/crates/typst-pdf/src/gradient.rs
+++ b/crates/typst-pdf/src/gradient.rs
@@ -6,18 +6,17 @@ use ecow::eco_format;
use pdf_writer::types::{ColorSpaceOperand, FunctionShadingType};
use pdf_writer::writers::StreamShadingType;
use pdf_writer::{Filter, Finish, Name, Ref};
-use typst::diag::SourceResult;
-use typst::layout::{Abs, Angle, Point, Quadrant, Ratio, Transform};
-use typst::utils::Numeric;
-use typst::visualize::{
+use typst_library::diag::SourceResult;
+use typst_library::layout::{Abs, Angle, Point, Quadrant, Ratio, Transform};
+use typst_library::visualize::{
Color, ColorSpace, Gradient, RatioOrAngle, RelativeTo, WeightedColor,
};
+use typst_utils::Numeric;
use crate::color::{
self, check_cmyk_allowed, ColorSpaceExt, PaintEncode, QuantizedColor,
};
-use crate::{content, WithGlobalRefs};
-use crate::{deflate, transform_to_array, AbsExt, PdfChunk};
+use crate::{content, deflate, transform_to_array, AbsExt, PdfChunk, WithGlobalRefs};
/// A unique-transform-aspect-ratio combination that will be encoded into the
/// PDF.
diff --git a/crates/typst-pdf/src/image.rs b/crates/typst-pdf/src/image.rs
index bff09e09..9651d31b 100644
--- a/crates/typst-pdf/src/image.rs
+++ b/crates/typst-pdf/src/image.rs
@@ -4,11 +4,11 @@ use std::io::Cursor;
use ecow::eco_format;
use image::{DynamicImage, GenericImageView, Rgba};
use pdf_writer::{Chunk, Filter, Finish, Ref};
-use typst::diag::{At, SourceResult, StrResult};
-use typst::utils::Deferred;
-use typst::visualize::{
+use typst_library::diag::{At, SourceResult, StrResult};
+use typst_library::visualize::{
ColorSpace, Image, ImageKind, RasterFormat, RasterImage, SvgImage,
};
+use typst_utils::Deferred;
use crate::{color, deflate, PdfChunk, WithGlobalRefs};
diff --git a/crates/typst-pdf/src/lib.rs b/crates/typst-pdf/src/lib.rs
index 7df77f10..efc99b74 100644
--- a/crates/typst-pdf/src/lib.rs
+++ b/crates/typst-pdf/src/lib.rs
@@ -22,14 +22,14 @@ use std::ops::{Deref, DerefMut};
use base64::Engine;
use pdf_writer::{Chunk, Name, Pdf, Ref, Str, TextStr};
use serde::{Deserialize, Serialize};
-use typst::diag::{bail, SourceResult, StrResult};
-use typst::foundations::{Datetime, Smart};
-use typst::layout::{Abs, Em, PageRanges, Transform};
-use typst::model::Document;
-use typst::syntax::Span;
-use typst::text::Font;
-use typst::utils::Deferred;
-use typst::visualize::Image;
+use typst_library::diag::{bail, SourceResult, StrResult};
+use typst_library::foundations::{Datetime, Smart};
+use typst_library::layout::{Abs, Em, PageRanges, Transform};
+use typst_library::model::Document;
+use typst_library::text::Font;
+use typst_library::visualize::Image;
+use typst_syntax::Span;
+use typst_utils::Deferred;
use crate::catalog::write_catalog;
use crate::color::{alloc_color_functions_refs, ColorFunctionRefs};
@@ -518,7 +518,7 @@ fn deflate_deferred(content: Vec<u8>) -> Deferred<Vec<u8>> {
/// Create a base64-encoded hash of the value.
fn hash_base64<T: Hash>(value: &T) -> String {
base64::engine::general_purpose::STANDARD
- .encode(typst::utils::hash128(value).to_be_bytes())
+ .encode(typst_utils::hash128(value).to_be_bytes())
}
/// Additional methods for [`Abs`].
diff --git a/crates/typst-pdf/src/named_destination.rs b/crates/typst-pdf/src/named_destination.rs
index 2d893526..90552335 100644
--- a/crates/typst-pdf/src/named_destination.rs
+++ b/crates/typst-pdf/src/named_destination.rs
@@ -2,11 +2,11 @@ use std::collections::{HashMap, HashSet};
use pdf_writer::writers::Destination;
use pdf_writer::{Ref, Str};
-use typst::diag::SourceResult;
-use typst::foundations::{Label, NativeElement};
-use typst::introspection::Location;
-use typst::layout::Abs;
-use typst::model::HeadingElem;
+use typst_library::diag::SourceResult;
+use typst_library::foundations::{Label, NativeElement};
+use typst_library::introspection::Location;
+use typst_library::layout::Abs;
+use typst_library::model::HeadingElem;
use crate::{AbsExt, PdfChunk, Renumber, StrExt, WithGlobalRefs};
diff --git a/crates/typst-pdf/src/outline.rs b/crates/typst-pdf/src/outline.rs
index 5c099b89..b9e71319 100644
--- a/crates/typst-pdf/src/outline.rs
+++ b/crates/typst-pdf/src/outline.rs
@@ -1,9 +1,9 @@
use std::num::NonZeroUsize;
use pdf_writer::{Finish, Pdf, Ref, TextStr};
-use typst::foundations::{NativeElement, Packed, StyleChain};
-use typst::layout::Abs;
-use typst::model::HeadingElem;
+use typst_library::foundations::{NativeElement, Packed, StyleChain};
+use typst_library::layout::Abs;
+use typst_library::model::HeadingElem;
use crate::{AbsExt, TextStrExt, WithEverything};
diff --git a/crates/typst-pdf/src/page.rs b/crates/typst-pdf/src/page.rs
index 631eec11..27daf6c9 100644
--- a/crates/typst-pdf/src/page.rs
+++ b/crates/typst-pdf/src/page.rs
@@ -4,15 +4,15 @@ use std::num::NonZeroUsize;
use ecow::EcoString;
use pdf_writer::types::{ActionType, AnnotationFlags, AnnotationType, NumberingStyle};
use pdf_writer::{Filter, Finish, Name, Rect, Ref, Str};
-use typst::diag::SourceResult;
-use typst::foundations::Label;
-use typst::introspection::Location;
-use typst::layout::{Abs, Page};
-use typst::model::{Destination, Numbering};
+use typst_library::diag::SourceResult;
+use typst_library::foundations::Label;
+use typst_library::introspection::Location;
+use typst_library::layout::{Abs, Page};
+use typst_library::model::{Destination, Numbering};
-use crate::content;
use crate::{
- AbsExt, PdfChunk, PdfOptions, Resources, WithDocument, WithRefs, WithResources,
+ content, AbsExt, PdfChunk, PdfOptions, Resources, WithDocument, WithRefs,
+ WithResources,
};
/// Construct page objects.
@@ -252,7 +252,8 @@ impl PdfPageLabel {
// If there is a suffix, we cannot use the common style optimisation,
// since PDF does not provide a suffix field.
let style = if pat.suffix.is_empty() {
- use {typst::model::NumberingKind as Kind, PdfPageLabelStyle as Style};
+ use typst_library::model::NumberingKind as Kind;
+ use PdfPageLabelStyle as Style;
match kind {
Kind::Arabic => Some(Style::Arabic),
Kind::LowerRoman => Some(Style::LowerRoman),
diff --git a/crates/typst-pdf/src/pattern.rs b/crates/typst-pdf/src/pattern.rs
index fd9d9dbb..ddc22fbd 100644
--- a/crates/typst-pdf/src/pattern.rs
+++ b/crates/typst-pdf/src/pattern.rs
@@ -3,15 +3,14 @@ use std::collections::HashMap;
use ecow::eco_format;
use pdf_writer::types::{ColorSpaceOperand, PaintType, TilingType};
use pdf_writer::{Filter, Name, Rect, Ref};
-use typst::diag::SourceResult;
-use typst::layout::{Abs, Ratio, Transform};
-use typst::utils::Numeric;
-use typst::visualize::{Pattern, RelativeTo};
+use typst_library::diag::SourceResult;
+use typst_library::layout::{Abs, Ratio, Transform};
+use typst_library::visualize::{Pattern, RelativeTo};
+use typst_utils::Numeric;
use crate::color::PaintEncode;
-use crate::content;
use crate::resources::{Remapper, ResourcesRefs};
-use crate::{transform_to_array, PdfChunk, Resources, WithGlobalRefs};
+use crate::{content, transform_to_array, PdfChunk, Resources, WithGlobalRefs};
/// Writes the actual patterns (tiling patterns) to the PDF.
/// This is performed once after writing all pages.
diff --git a/crates/typst-pdf/src/resources.rs b/crates/typst-pdf/src/resources.rs
index fabf0b3f..d3fde5dd 100644
--- a/crates/typst-pdf/src/resources.rs
+++ b/crates/typst-pdf/src/resources.rs
@@ -12,11 +12,11 @@ use std::hash::Hash;
use ecow::{eco_format, EcoString};
use pdf_writer::{Dict, Finish, Name, Ref};
use subsetter::GlyphRemapper;
-use typst::diag::{SourceResult, StrResult};
-use typst::syntax::Span;
-use typst::text::{Font, Lang};
-use typst::utils::Deferred;
-use typst::visualize::Image;
+use typst_library::diag::{SourceResult, StrResult};
+use typst_library::text::{Font, Lang};
+use typst_library::visualize::Image;
+use typst_syntax::Span;
+use typst_utils::Deferred;
use crate::color::ColorSpaces;
use crate::color_font::ColorFontMap;