-
Notifications
You must be signed in to change notification settings - Fork 4.8k
C2d #404
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
C2d #404
Conversation
jspdf.js
Outdated
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.
Is this needed? I mean, perhaps strokeOption = ''
is enough?
Well, if it's to clear a previously set stroke state, i'd use an internal flag and only set 0 tr
when flags.stroke
is no longer set (?)
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.
If you don't reset the Tr after setting it to 1, it persists for the rest of the page. So we would have to track it per page.
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 was thinking on something like this:
var stroke_state = false;
API.text = function(...) {
...
var strokeOption = '';
if(!stroke_state && flags.stroke) strokeOption = '1 tr';
else if(stroke_state && !flags.stroke) strokeOption = '0 tr';
stroke_state = !!flags.stroke;
...
}
That way it'd persist as long flags.stroke
is set only, avoiding the need to define the stroke with every .text()
call. (that will save some bytes, specially if the function is used tons of times)
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.
That works for me; Should we store the state in a page/path object instead of main pdf object?
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.
If the stroke can persist across pages, then my code should be fine, otherwise we will need to store it per-page indeed.
goto http://htmlpreview.github.io/?https://github.com/Flamenco/jsPDF/blob/c2d/test/test_context2d.html?src=true |
suggested changes
annotation plugin should use current page (not last page) move c2d context object into plugin scope added missing comma in object definition added c2d test cases
Thanks a lot!! Btw, please note |
HTML5 CanvasRenderingContext2D interface
I am referring to the variable declared in the pdf object on line 202, not global or function scope. Will lastTextWasStroke without this refer to that variable? What am I missing? Ideally this should be something like pageContext.lastTextWasStroke. A page context is not yet available, but is on my todo list. |
In 202 you're declaring a private variable within the jsPDF constructor scope. For API/PlugIns functions, function jsPDF()
{
var something = "priv";
var API = {
publicv : "Doh"
}
API.text = function()
{
console.log(typeof this.something); // undefined
console.log(typeof this.publicv); // string
};
} For that usecase your code wouldn't cause any problem, but i wanted to let you be aware of this. I'd keep that as-is and remove the |
Thanks for the example. I see what you mean. I did not realize that the variable without the object scope would refer to the function var (not the global var). The current version uses a page context variable, so the case is no longer relevant. Here is an expanded example for future reference. Thanks! BTW, The insert, delete, and move page functions have removed my current need to change the rendering processing, as I can insert my TOC and title page. I would like to combine pages[], pagedim{}, and pagesContext{} into a single object now. pageInfo{pageNumber, out[], dim{}, context{}, objId}. Are you ok with that? It will make the mentioned page arrange methods more extensible for plugins (such as the annotation plugin that creates its own pagenumber indexed variable.
|
see documentation: https://github.com/Flamenco/jsPDF/wiki/c2d-Plugin
see test page at: http://htmlpreview.github.io/?https://github.com/Flamenco/jsPDF/blob/c2d/test/test_context2d.html
Notable new features include arcs, stroked text, text baselines, and context stacks. Also css color names.
I feel that by standardizing the API via this interface, more users will be able to understand the usage, convert existing HTML5 canvas code to vector based PDFs, and save time by not requiring the developers to write documentation :)
This is far from complete, but still quite useful.