-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce the Buf
type
#47
Open
LaurenzV
wants to merge
26
commits into
typst:main
Choose a base branch
from
LaurenzV:buf-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
26cb3ed
Introduce Buf type
LaurenzV ba1c728
Return content by default
LaurenzV 2d3cf45
First version
LaurenzV 18b779a
re=exprt
LaurenzV 8974609
more fixes
LaurenzV 0345d52
make to_bytes public
LaurenzV 9e99c77
Add limits getter
LaurenzV 2202232
Add limits to chunk
LaurenzV 1f70211
add getters
LaurenzV 664c270
add getters
LaurenzV 8294635
integrate postscript changes
LaurenzV 31565d1
Change separators
LaurenzV ea782ea
revert push float change
LaurenzV cf042eb
revert changes
LaurenzV ccb54f4
Merge branch 'main' into buf-tests
LaurenzV 71b7593
tidy up a bit
LaurenzV 803ef27
do not implement DerefMut
LaurenzV 8af675d
format
LaurenzV ddae285
merge limits in renumber as well
LaurenzV 2c80827
Fix test
LaurenzV f95a19c
Fix clippy
LaurenzV e32816a
Apply some code review
LaurenzV 749fe13
Add some documentation
LaurenzV 34f6b8c
Add two test cases and fix two bugs
LaurenzV 9dcf56b
Reformat
LaurenzV 33052e2
Add an exmaple for tracking limits
LaurenzV File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//! This example shows how you can track PDF limits of your chunks. | ||
|
||
use pdf_writer::{Chunk, Content, Limits, Name, Ref}; | ||
|
||
fn main() { | ||
let mut limits = Limits::new(); | ||
|
||
let mut content = Content::new(); | ||
content.transform([-3.4, 0.0, 0.0, 3.1, 100.0, 100.0]); | ||
content.line_to(15.0, -26.1); | ||
let buf = content.finish(); | ||
// This will have the limits: | ||
// - Max real number: 26.1 (for negative values we use their absolute value) | ||
// - Max int number 100 (even though above 100.0 is a float number, it will be coerced into an | ||
// integer, and thus counts towards the int limit) | ||
limits.merge(buf.limits()); | ||
|
||
let mut chunk = Chunk::new(); | ||
chunk.stream(Ref::new(1), &buf.into_bytes()); | ||
chunk.type3_font(Ref::new(2)).name(Name(b"A_long_font_name")); | ||
// This will update the limit for the maximum name and dictionary length. | ||
limits.merge(chunk.limits()); | ||
|
||
// This is what the final PDF will look like. | ||
assert_eq!( | ||
chunk.as_bytes(), | ||
b"1 0 obj | ||
<< | ||
/Length 34 | ||
>> | ||
stream | ||
-3.4 0 0 3.1 100 100 cm | ||
15 -26.1 l | ||
endstream | ||
endobj | ||
|
||
2 0 obj | ||
<< | ||
/Type /Font | ||
/Subtype /Type3 | ||
/Name /A_long_font_name | ||
>> | ||
endobj | ||
|
||
" | ||
); | ||
|
||
// And the limits should match, as well! | ||
assert_eq!(limits.int(), 100); | ||
assert_eq!(limits.real(), 26.1); | ||
assert_eq!(limits.name_len(), 16); | ||
assert_eq!(limits.dict_entries(), 3); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Asserting the PDF in the example is a bit unconventional. Do you think we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Print it instead? Or just remove it completely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other examples write it to a file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm yeah but the other examples also create an actually valid PDF file. :p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change it so it’s a valid PDF too, but maybe a bit unnecessary if it’s just about showing how to use the Limits API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Maybe we can just completely ignore it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So remove all asserts? Or just the one from the PDF buffer?