-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Superscript and subscript #36
Comments
I'm adding it to "more building blocks" milestone, however I'll have to update the deadlines :) I've been off for a loong time |
Can I ask what happened to this feature request? Any chance we're gonna see superscript in the future? |
I would need this feature as well... any information about it? |
PdfKit issue: foliojs/pdfkit#15 |
I am trying to do some engineering documents and superscripts/subscripts are everywhere. This would be a really useful feature. |
In case someone was looking for superscript workaround, this works pretty well for me: |
That
Notice the 2nd line is left-justified. I found that using the
The |
I found one way of including the superscript as a style property, just like you'd change the font size. E.g., I added the
This is a relatively slow way, and we need to add in some automated fontSize resizing (make the fontSize to 75% original font size?). This code prints the text normally, but moves the y-position up (toward the top of the page) a little bit. The text is moved up proportionally to the fontSize property, which helps with consistency. Maybe this vertical offset should be |
@rabraha3 Thanks for that info! It appears you also want to modify the following couple of draws with the updated Y value as well, otherwise text decorations won't draw in the proper place. |
The approach from #36 (comment) does work with inline superscripting when you specify 'line 1',
{
columns: [
{text: 'line 2 before superscript', width: 'auto'},
{text: 'superscript', width: 'auto', fontSize: 8},
{text: 'line 2 after superscript', width: 'auto'}
]
} |
Awesome! I agree that the inline solution doesn't play well with line wrapping. I think the columns idea is great! Using columns may go towards the final solution. Do you know why the y-position for the text is aligned at or near the ascender (as opposed to the baseline) within the columns object? The thing about using columns is spacing; there doesn't seems to be any whitespace between the "superscript" and the text on either side. If we put a "spacer" object in between: e.g., I'm note sure the exact size to use -- a single space ( In addition, we need to worry about the length of the line. If we have too much text, we can get very squished text; try:
Noting the small space between the "superscript" and the following text. Maybe combining the inline solution outlined above with the columns ... ? There'd need to be a much better way of vertically-aligning the superscripted (and then also subscripted) text. The way that Word handles it -- there is a default height, and the user can specify the vertical offset, as a percentage of the font size. |
I've tried out both superscript and subscripting: (image taken in the dev-playground) There is also the ability to add a custom offset / font size within the superscript / subscript config options. The image shows the offset in percentage (percentage of given font size). Instead of style "sup: true" or "sub: true", we can pass a more complex object:
The The code is a bit messy, un-tested, and not really documented. So that needs to be worked on. @mkorcha do you know how to change the text decorators? I couldn't get it working for the on inline element ... |
@rabraha3 I figure you mean the modifications I made to keep the decorations at the right position. Here are the changes I made for my use case, not sure how this will translate for you. I figure you mean the drawing portion. If you meant something else, sorry! I haven't really messed with this much since. |
Can you tell me for some example? My code not working
|
Unfortunately, non of the suggested solutions above worked for me, because I needed to use superscript in table header that is centered . But I found another one - to use Unicode superscript characters: Here is the object with superscripts that I use, but you can take the codes for subscripts too from the Wikipedia page above.
Unfortunately, the default (which is included already) Roboto font supports only superscript numbers from 1 to 4. I solved this by setting my font to OpenSans (font and how-to). P.S. Here is vfs_fonts.js with OpenSans whoever needs it: vfs_fonts.zip |
Sorry for the late reply; I haven't paid much attention to these updates. The code for the general offset is not up yet; it was on a branch on my fork. So the Is it worth having an offset that can be specified? Or is a default fine? |
As a feature, what do people want? Just a default height-offset for superscript and subscript? Or do you want more fine-grained control, like in MS Word -- where you can specify % offsets? Do you want to manually shrink the font size, or have a default? (again, fine-grained control or no control)? The fine-grained control requires more changes than the default option. |
It's always nice to have extra flexibility, but if it's more work than simply exposing aditional parameters I'd be more than happy with defaults option on this one. |
Note that if using things like |
I'm try with text: ['some', {text:'sub', offset: '30%}, 'text] but it did not work, any one help for this please |
Hello can you show code for us to practice. Thank |
* Add simple superscript to the 0.1 branch -- move text baseline up when inline.sup is true * Add simple subscript, with default offsets. Works the same way as superscript, only it moves the baseline DOWN. * Build fail because I used 'let' instead of 'var' * Update examples/styling_properties.js with one superscript and one subscript example. * Fix parasite white space left after supscript or subscript and next character and enable default font size reduction. Co-authored-by: Ryan Abrahams <rabraha3@gmail.com> Co-authored-by: Nikita Moshensky <]=[poikj-0o98u7hy;6lkjhgfdx>
@liborm85 |
|
I have a document that uses a lot of superscripted numbers (verse markings for scripture text). If it isn't possible, I could make them smaller and italicized, but the ability to make them superscript would be great.
The text was updated successfully, but these errors were encountered: